Draw jumpgate portal in jumpgate.c. Use systemPower instead of ALIVE_SLEEPING to determine status.

This commit is contained in:
Steve 2016-03-08 14:28:11 +00:00
parent 5267b7b559
commit 7118c10648
9 changed files with 192 additions and 169 deletions

View File

@ -421,7 +421,7 @@ static void loadComponents(Entity *parent, cJSON *components)
e->aiFlags = flagsToLong(cJSON_GetObjectItem(component, "aiFlags")->valuestring, NULL); e->aiFlags = flagsToLong(cJSON_GetObjectItem(component, "aiFlags")->valuestring, NULL);
} }
e->systemPower = 100; e->systemPower = MAX_SYSTEM_POWER;
e->die = componentDie; e->die = componentDie;
@ -475,7 +475,7 @@ static void loadGuns(Entity *parent, cJSON *guns)
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
e->systemPower = 100; e->systemPower = MAX_SYSTEM_POWER;
e->action = gunThink; e->action = gunThink;
e->die = gunDie; e->die = gunDie;
@ -518,7 +518,7 @@ static void loadEngines(Entity *parent, cJSON *engines)
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
e->systemPower = 100; e->systemPower = MAX_SYSTEM_POWER;
e->action = engineThink; e->action = engineThink;
e->die = engineDie; e->die = engineDie;

View File

@ -31,8 +31,6 @@ static int drawComparator(const void *a, const void *b);
static void notifyNewArrivals(void); static void notifyNewArrivals(void);
static int isCapitalShipComponent(Entity *e); static int isCapitalShipComponent(Entity *e);
static SDL_Texture *jumpPortal;
static float jumpPortAngle;
static Entity deadHead; static Entity deadHead;
static Entity *deadTail; static Entity *deadTail;
static int disabledGlow; static int disabledGlow;
@ -46,9 +44,6 @@ void initEntities(void)
disabledGlow = DISABLED_GLOW_MAX; disabledGlow = DISABLED_GLOW_MAX;
disabledGlowDir = -DISABLED_GLOW_SPEED; disabledGlowDir = -DISABLED_GLOW_SPEED;
jumpPortal = getTexture("gfx/entities/portal.png");
jumpPortAngle = 0;
} }
Entity *spawnEntity(void) Entity *spawnEntity(void)
@ -139,7 +134,7 @@ void doEntities(void)
break; break;
} }
if (e->alive == ALIVE_ALIVE || e->alive == ALIVE_DYING || e->alive == ALIVE_SLEEPING) if (e->alive == ALIVE_ALIVE || e->alive == ALIVE_DYING)
{ {
if (e->action != NULL) if (e->action != NULL)
{ {
@ -257,12 +252,6 @@ void doEntities(void)
{ {
disabledGlowDir = -DISABLED_GLOW_SPEED; disabledGlowDir = -DISABLED_GLOW_SPEED;
} }
jumpPortAngle += 0.5;
if (jumpPortAngle >= 360)
{
jumpPortAngle -= 360;
}
} }
static void restrictToBattleArea(Entity *e) static void restrictToBattleArea(Entity *e)
@ -378,7 +367,13 @@ void drawEntities(void)
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
{ {
if (e->active) self = e;
if (e->draw)
{
e->draw();
}
else
{ {
drawEntity(e); drawEntity(e);
} }
@ -391,11 +386,6 @@ void drawEntities(void)
static void drawEntity(Entity *e) static void drawEntity(Entity *e)
{ {
if (e->type == ET_JUMPGATE && e->alive == ALIVE_ALIVE)
{
blitRotated(jumpPortal, e->x - battle.camera.x, e->y - battle.camera.y, jumpPortAngle);
}
SDL_SetTextureColorMod(e->texture, 255, 255, 255); SDL_SetTextureColorMod(e->texture, 255, 255, 255);
if (e->armourHit > 0) if (e->armourHit > 0)
@ -494,6 +484,11 @@ void activateEntityGroups(char *groupNames)
if (strcmp(e->groupName, groupName) == 0) if (strcmp(e->groupName, groupName) == 0)
{ {
e->active = 1; e->active = 1;
if (e->type == ET_CAPITAL_SHIP)
{
updateCapitalShipComponentProperties(e);
}
} }
} }

View File

@ -715,8 +715,7 @@ static void loadFighterDef(char *filename)
e->separationRadius = MAX(e->w, e->h) * 3; e->separationRadius = MAX(e->w, e->h) * 3;
/* all craft default to 100 system power */ e->systemPower = MAX_SYSTEM_POWER;
e->systemPower = 100;
cJSON_Delete(root); cJSON_Delete(root);
} }

View File

@ -21,9 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "jumpgate.h" #include "jumpgate.h"
static void think(void); static void think(void);
static void draw(void);
static void handleFleeingEntities(void); static void handleFleeingEntities(void);
static void addEscapeEffect(Entity *ent); static void addEscapeEffect(Entity *ent);
static SDL_Texture *portal;
static float portalAngle;
Entity *spawnJumpgate(void) Entity *spawnJumpgate(void)
{ {
Entity *jumpgate = spawnEntity(); Entity *jumpgate = spawnEntity();
@ -32,8 +36,12 @@ Entity *spawnJumpgate(void)
jumpgate->health = jumpgate->maxHealth = FPS; jumpgate->health = jumpgate->maxHealth = FPS;
jumpgate->texture = getTexture("gfx/entities/jumpgate.png"); jumpgate->texture = getTexture("gfx/entities/jumpgate.png");
jumpgate->action = think; jumpgate->action = think;
jumpgate->draw = draw;
jumpgate->flags |= EF_NO_MT_BOX; jumpgate->flags |= EF_NO_MT_BOX;
portal = getTexture("gfx/entities/portal.png");
portalAngle = 0;
return jumpgate; return jumpgate;
} }
@ -47,14 +55,26 @@ static void think(void)
self->angle -= 360; self->angle -= 360;
} }
if (self->alive == ALIVE_ALIVE) if (self->systemPower)
{ {
handleFleeingEntities(); handleFleeingEntities();
} }
if (!battle.jumpgate)
{
battle.jumpgate = self; battle.jumpgate = self;
} }
if (battle.jumpgate == self)
{
portalAngle += 0.5;
if (portalAngle >= 360)
{
portalAngle -= 360;
}
}
}
static void handleFleeingEntities(void) static void handleFleeingEntities(void)
{ {
Entity *e, **candidates; Entity *e, **candidates;
@ -105,3 +125,13 @@ static void addEscapeEffect(Entity *ent)
e->health = speed; e->health = speed;
} }
} }
static void draw(void)
{
if (self->systemPower)
{
blitRotated(portal, self->x - battle.camera.x, self->y - battle.camera.y, portalAngle);
}
blitRotated(self->texture, self->x - battle.camera.x, self->y - battle.camera.y, self->angle);
}

View File

@ -25,6 +25,7 @@ extern Entity *spawnEntity(void);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void playBattleSound(int id, int x, int y); extern void playBattleSound(int id, int x, int y);
extern void blitRotated(SDL_Texture *texture, int x, int y, float angle);
extern Battle battle; extern Battle battle;
extern Entity *self; extern Entity *self;

View File

@ -143,7 +143,7 @@ static void executeNextLine(ScriptRunner *runner)
} }
else if (strcmp(command, "ACTIVATE_JUMPGATE") == 0) else if (strcmp(command, "ACTIVATE_JUMPGATE") == 0)
{ {
battle.jumpgate->alive = ALIVE_ALIVE; battle.jumpgate->systemPower = MAX_SYSTEM_POWER;
} }
else if (strcmp(command, "MSG_BOX") == 0) else if (strcmp(command, "MSG_BOX") == 0)
{ {

View File

@ -66,6 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MAX_FIGHTER_GUNS 12 #define MAX_FIGHTER_GUNS 12
#define MAX_TARGET_RANGE 65536 #define MAX_TARGET_RANGE 65536
#define MAX_SYSTEM_POWER 100
#define BATTLE_AREA_CELLS 50 #define BATTLE_AREA_CELLS 50
#define BATTLE_AREA_WIDTH (640 * BATTLE_AREA_CELLS) #define BATTLE_AREA_WIDTH (640 * BATTLE_AREA_CELLS)
@ -165,8 +166,7 @@ enum
ALIVE_ALIVE, ALIVE_ALIVE,
ALIVE_DYING, ALIVE_DYING,
ALIVE_DEAD, ALIVE_DEAD,
ALIVE_ESCAPED, ALIVE_ESCAPED
ALIVE_SLEEPING /* used by jumpgate */
}; };
enum enum

View File

@ -567,7 +567,7 @@ static void loadEntities(cJSON *node)
{ {
Entity *e; Entity *e;
char *name, *groupName; char *name, *groupName;
int i, type, scatter, number, active, sleeping; int i, type, scatter, number, active, systemPower;
float x, y; float x, y;
if (node) if (node)
@ -588,7 +588,7 @@ static void loadEntities(cJSON *node)
number = getJSONValue(node, "number", 1); number = getJSONValue(node, "number", 1);
active = getJSONValue(node, "active", 1); active = getJSONValue(node, "active", 1);
scatter = getJSONValue(node, "scatter", 1); scatter = getJSONValue(node, "scatter", 1);
sleeping = getJSONValue(node, "sleeping", 0); systemPower = getJSONValue(node, "systemPower", MAX_SYSTEM_POWER);
for (i = 0 ; i < number ; i++) for (i = 0 ; i < number ; i++)
{ {
@ -629,10 +629,7 @@ static void loadEntities(cJSON *node)
e->active = active; e->active = active;
if (sleeping) e->systemPower = systemPower;
{
e->alive = ALIVE_SLEEPING;
}
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
} }

View File

@ -145,6 +145,7 @@ struct Entity {
Entity *leader; Entity *leader;
Entity *owner; Entity *owner;
void (*action)(void); void (*action)(void);
void (*draw)(void);
void (*die)(void); void (*die)(void);
SDL_Texture *texture; SDL_Texture *texture;
Entity *next; Entity *next;