Further capital ship tweaks.
This commit is contained in:
parent
ede17199c3
commit
54ebea7c43
|
@ -64,12 +64,41 @@ Entity *spawnCapitalShip(char *name, int x, int y, int side)
|
||||||
|
|
||||||
static void think(void)
|
static void think(void)
|
||||||
{
|
{
|
||||||
|
float dir;
|
||||||
|
int wantedAngle;
|
||||||
|
|
||||||
|
if (--self->aiActionTime <= 0)
|
||||||
|
{
|
||||||
|
self->targetLocation.x = rand() % GRID_SIZE;
|
||||||
|
self->targetLocation.x *= GRID_CELL_WIDTH;
|
||||||
|
|
||||||
|
self->targetLocation.y = rand() % GRID_SIZE;
|
||||||
|
self->targetLocation.y *= GRID_CELL_HEIGHT;
|
||||||
|
|
||||||
|
self->aiActionTime = FPS * (30 + (rand() % 120));
|
||||||
|
}
|
||||||
|
|
||||||
|
wantedAngle = getAngle(self->x, self->y, self->targetLocation.x, self->targetLocation.y);
|
||||||
|
|
||||||
|
wantedAngle %= 360;
|
||||||
|
|
||||||
|
if (fabs(wantedAngle - self->angle) > TURN_THRESHOLD)
|
||||||
|
{
|
||||||
|
dir = ((int)(wantedAngle - self->angle + 360)) % 360 > 180 ? -1 : 1;
|
||||||
|
|
||||||
|
dir *= TURN_SPEED;
|
||||||
|
|
||||||
|
self->angle += dir;
|
||||||
|
|
||||||
|
self->angle = fmod(self->angle, 360);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyFighterThrust();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gunThink(void)
|
static void gunThink(void)
|
||||||
{
|
{
|
||||||
/*doAI();*/
|
doAI();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void componentDie(void)
|
static void componentDie(void)
|
||||||
|
@ -86,7 +115,17 @@ static void componentDie(void)
|
||||||
|
|
||||||
static void die(void)
|
static void die(void)
|
||||||
{
|
{
|
||||||
|
Entity *e;
|
||||||
|
|
||||||
self->alive = ALIVE_DEAD;
|
self->alive = ALIVE_DEAD;
|
||||||
|
|
||||||
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||||
|
{
|
||||||
|
if (e->owner == self)
|
||||||
|
{
|
||||||
|
e->health = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadCapitalShipDefs(void)
|
void loadCapitalShipDefs(void)
|
||||||
|
@ -135,6 +174,7 @@ static void loadCapitalShipDef(char *filename)
|
||||||
e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
|
e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
|
||||||
e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
|
e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
|
||||||
e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring);
|
e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring);
|
||||||
|
e->speed = 1;
|
||||||
|
|
||||||
e->action = think;
|
e->action = think;
|
||||||
e->die = die;
|
e->die = die;
|
||||||
|
|
|
@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define TURN_SPEED 0.1
|
||||||
|
#define TURN_THRESHOLD 2
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
#include "../json/cJSON.h"
|
#include "../json/cJSON.h"
|
||||||
|
@ -31,6 +34,9 @@ extern char *getFileLocation(char *filename);
|
||||||
extern long flagsToLong(char *flags);
|
extern long flagsToLong(char *flags);
|
||||||
extern long lookup(char *name);
|
extern long lookup(char *name);
|
||||||
extern void doAI(void);
|
extern void doAI(void);
|
||||||
|
extern float getAngle(int x1, int y1, int x2, int y2);
|
||||||
|
extern float mod(float n, float x);
|
||||||
|
extern void applyFighterThrust(void);
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Entity *self;
|
extern Entity *self;
|
||||||
|
|
Loading…
Reference in New Issue