From 2d37460944f54cb474400cba33262fe57facd4c1 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 18 Dec 2015 12:02:45 +0000 Subject: [PATCH] Generate cap ship component names from parent name. --- src/battle/capitalShips.c | 40 +++++++++++++++++++++++++++++++-------- src/battle/capitalShips.h | 1 + src/galaxy/mission.c | 2 ++ src/galaxy/mission.h | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/battle/capitalShips.c b/src/battle/capitalShips.c index e54a695..4a40be0 100644 --- a/src/battle/capitalShips.c +++ b/src/battle/capitalShips.c @@ -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; diff --git a/src/battle/capitalShips.h b/src/battle/capitalShips.h index ca21bd2..c521019 100644 --- a/src/battle/capitalShips.h +++ b/src/battle/capitalShips.h @@ -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; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 908407e..24f901f 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -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; diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 55ec80d..0bbd7e5 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -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;