Generate cap ship component names from parent name.

This commit is contained in:
Steve 2015-12-18 12:02:45 +00:00
parent cfc0ed7cc8
commit 2d37460944
4 changed files with 36 additions and 8 deletions

View File

@ -222,7 +222,7 @@ static void componentDie(void)
self->alive = ALIVE_DEAD;
addSmallExplosion();
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
addDebris(self->x, self->y, rand() % 4);
addDebris(self->x, self->y, 3 + rand() % 4);
self->owner->health--;
@ -237,7 +237,7 @@ static void gunDie(void)
self->alive = ALIVE_DEAD;
addSmallExplosion();
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
addDebris(self->x, self->y, rand() % 4);
addDebris(self->x, self->y, 3 + rand() % 4);
}
static void engineThink(void)
@ -288,6 +288,10 @@ static void die(void)
e->health = 0;
}
}
updateObjective(self->name, TT_DESTROY);
updateObjective(self->groupName, TT_DESTROY);
}
void loadCapitalShipDefs(void)
@ -376,8 +380,6 @@ static void loadComponents(Entity *parent, cJSON *components)
e->active = 1;
e->type = ET_CAPITAL_SHIP_COMPONENT;
sprintf(e->name, "%s (Component)", parent->name);
sprintf(e->defName, "%s (Component)", parent->defName);
e->health = e->maxHealth = cJSON_GetObjectItem(component, "health")->valueint;
e->offsetX = cJSON_GetObjectItem(component, "x")->valueint;
e->offsetY = cJSON_GetObjectItem(component, "y")->valueint;
@ -429,8 +431,6 @@ static void loadGuns(Entity *parent, cJSON *guns)
e->active = 1;
e->type = ET_CAPITAL_SHIP_GUN;
sprintf(e->name, "%s (Cannon)", parent->name);
sprintf(e->defName, "%s (Cannon)", parent->defName);
e->health = e->maxHealth = cJSON_GetObjectItem(gun, "health")->valueint;
e->reloadTime = cJSON_GetObjectItem(gun, "reloadTime")->valueint;
e->offsetX = cJSON_GetObjectItem(gun, "x")->valueint;
@ -486,8 +486,6 @@ static void loadEngines(Entity *parent, cJSON *engines)
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;
@ -512,6 +510,32 @@ static void loadEngines(Entity *parent, cJSON *engines)
}
}
void updateCapitalShipComponentNames(Entity *parent)
{
Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{
if (e->owner == parent)
{
switch (e->type)
{
case ET_CAPITAL_SHIP_ENGINE:
sprintf(e->name, "%s (Engine)", parent->name);
break;
case ET_CAPITAL_SHIP_COMPONENT:
sprintf(e->name, "%s (Component)", parent->name);
break;
case ET_CAPITAL_SHIP_GUN:
sprintf(e->name, "%s (Gun)", parent->name);
break;
}
}
}
}
void destroyCapitalShipDefs(void)
{
Entity *e;

View File

@ -43,6 +43,7 @@ extern int getDistance(int x1, int y1, int x2, int y2);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern void addDebris(int x, int y, int amount);
extern void runScriptFunction(char *format, ...);
extern void updateObjective(char *name, int type);
extern Battle battle;
extern Entity *self;

View File

@ -413,6 +413,8 @@ static void loadCapitalShips(cJSON *node)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
}
}
updateCapitalShipComponentNames(e);
}
node = node->next;

View File

@ -45,6 +45,7 @@ extern void completeConditions(void);
extern void retreatEnemies(void);
extern void initScript(cJSON *missionJSON);
extern char *getFileLocation(char *filename);
extern void updateCapitalShipComponentNames(Entity *parent);
extern Battle battle;
extern Entity *player;