From 33373457b214ba18f0cc321d39da816ac9662844 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 16 Dec 2015 22:40:14 +0000 Subject: [PATCH] Error when no capital ship found. --- src/battle/capitalShips.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/battle/capitalShips.c b/src/battle/capitalShips.c index 4f3aab7..274888b 100644 --- a/src/battle/capitalShips.c +++ b/src/battle/capitalShips.c @@ -39,6 +39,8 @@ Entity *spawnCapitalShip(char *name, int x, int y, int side) { Entity *def, *e, *capitalShip; + capitalShip = NULL; + for (def = defHead.next ; def != NULL ; def = def->next) { if ((strcmp(def->name, name) == 0) || (def->owner != NULL && strcmp(def->owner->name, name) == 0)) @@ -65,6 +67,12 @@ Entity *spawnCapitalShip(char *name, int x, int y, int side) } } + if (!capitalShip) + { + printf("Error: no such capital ship '%s'\n", name); + exit(1); + } + return capitalShip; } @@ -324,7 +332,6 @@ static void loadCapitalShipDef(char *filename) STRNCPY(e->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); STRNCPY(e->defName, e->name, MAX_NAME_LENGTH); - e->health = e->maxHealth = cJSON_GetObjectItem(root, "health")->valueint; e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint; e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint; e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring); @@ -353,7 +360,7 @@ static void loadComponents(Entity *parent, cJSON *components) Entity *e; cJSON *component; - parent->health = 0; + parent->health = 1; if (components) {