Treat capital ship engines differently from components. Will cause vessel to stop moving when they are all destroyed. Don't contribute to ship health.
This commit is contained in:
parent
4358d5b698
commit
09d93f9163
|
@ -6,84 +6,86 @@
|
|||
"texture" : "gfx/capitalShips/test/body.png",
|
||||
"components" : [
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 150,
|
||||
"texture" : "gfx/capitalShips/test/core.png",
|
||||
"x" : 0,
|
||||
"y" : -125,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : -32,
|
||||
"y" : -250,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : 32,
|
||||
"y" : -250,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : -110,
|
||||
"y" : -30,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : 110,
|
||||
"y" : -30,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : 0,
|
||||
"y" : 0,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : 0,
|
||||
"y" : 50,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 350,
|
||||
"health" : 50,
|
||||
"texture" : "gfx/capitalShips/test/component.png",
|
||||
"x" : 0,
|
||||
"y" : 100,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
}
|
||||
],
|
||||
"engines" : [
|
||||
{
|
||||
"health" : 250,
|
||||
"health" : 100,
|
||||
"texture" : "gfx/capitalShips/test/engine1.png",
|
||||
"x" : -112,
|
||||
"y" : 281,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 250,
|
||||
"health" : 100,
|
||||
"texture" : "gfx/capitalShips/test/engine1.png",
|
||||
"x" : 112,
|
||||
"y" : 281,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 250,
|
||||
"health" : 100,
|
||||
"texture" : "gfx/capitalShips/test/engine2.png",
|
||||
"x" : -34,
|
||||
"y" : 268,
|
||||
"flags" : "EF_TAKES_DAMAGE+EF_STATIC"
|
||||
},
|
||||
{
|
||||
"health" : 250,
|
||||
"health" : 100,
|
||||
"texture" : "gfx/capitalShips/test/engine2.png",
|
||||
"x" : 34,
|
||||
"y" : 268,
|
||||
|
|
|
@ -23,9 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
static void think(void);
|
||||
static void gunThink(void);
|
||||
static void componentDie(void);
|
||||
static void engineDie(void);
|
||||
static void loadCapitalShipDef(char *filename);
|
||||
static void loadComponents(Entity *parent, cJSON *components);
|
||||
static void loadGuns(Entity *parent, cJSON *guns);
|
||||
static void loadEngines(Entity *parent, cJSON *engines);
|
||||
|
||||
static Entity defHead, *defTail;
|
||||
|
||||
|
@ -107,10 +109,29 @@ static void componentDie(void)
|
|||
addSmallExplosion();
|
||||
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
||||
|
||||
if (self->type == ET_CAPITAL_SHIP_COMPONENT)
|
||||
{
|
||||
self->owner->health--;
|
||||
}
|
||||
|
||||
static void engineDie(void)
|
||||
{
|
||||
Entity *e;
|
||||
|
||||
self->alive = ALIVE_DEAD;
|
||||
addSmallExplosion();
|
||||
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
||||
|
||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
if (e != self && e->owner == self->owner && e->type == ET_CAPITAL_SHIP_ENGINE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* no more engines - stop moving */
|
||||
self->owner->speed = 0;
|
||||
self->owner->action = NULL;
|
||||
self->owner->dx = self->owner->dy = 0;
|
||||
}
|
||||
|
||||
static void die(void)
|
||||
|
@ -185,6 +206,8 @@ static void loadCapitalShipDef(char *filename)
|
|||
|
||||
loadGuns(e, cJSON_GetObjectItem(root, "guns"));
|
||||
|
||||
loadEngines(e, cJSON_GetObjectItem(root, "engines"));
|
||||
|
||||
cJSON_Delete(root);
|
||||
free(text);
|
||||
}
|
||||
|
@ -294,6 +317,50 @@ static void loadGuns(Entity *parent, cJSON *guns)
|
|||
}
|
||||
}
|
||||
|
||||
static void loadEngines(Entity *parent, cJSON *engines)
|
||||
{
|
||||
Entity *e;
|
||||
cJSON *engine;
|
||||
|
||||
if (engines)
|
||||
{
|
||||
engine = engines->child;
|
||||
|
||||
while (engine)
|
||||
{
|
||||
e = malloc(sizeof(Entity));
|
||||
memset(e, 0, sizeof(Entity));
|
||||
defTail->next = e;
|
||||
defTail = e;
|
||||
|
||||
e->active = 1;
|
||||
|
||||
e->type = ET_CAPITAL_SHIP_ENGINE;
|
||||
sprintf(e->name, "%s (Engine)", parent->name);
|
||||
sprintf(e->defName, "%s (Engine)", parent->defName);
|
||||
e->health = e->maxHealth = cJSON_GetObjectItem(engine, "health")->valueint;
|
||||
e->offsetX = cJSON_GetObjectItem(engine, "x")->valueint;
|
||||
e->offsetY = cJSON_GetObjectItem(engine, "y")->valueint;
|
||||
e->texture = getTexture(cJSON_GetObjectItem(engine, "texture")->valuestring);
|
||||
|
||||
if (cJSON_GetObjectItem(engine, "flags"))
|
||||
{
|
||||
e->flags = flagsToLong(cJSON_GetObjectItem(engine, "flags")->valuestring);
|
||||
}
|
||||
|
||||
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
||||
|
||||
e->systemPower = 100;
|
||||
|
||||
e->die = engineDie;
|
||||
|
||||
e->owner = parent;
|
||||
|
||||
engine = engine->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void destroyCapitalShipDefs(void)
|
||||
{
|
||||
Entity *e;
|
||||
|
|
|
@ -110,6 +110,7 @@ enum
|
|||
ET_EXTRACTION_POINT,
|
||||
ET_CAPITAL_SHIP_COMPONENT,
|
||||
ET_CAPITAL_SHIP_GUN,
|
||||
ET_CAPITAL_SHIP_ENGINE,
|
||||
ET_CAPITAL_SHIP
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue