From c3136ea3afd845573f4b69b6ee184d381d382348 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 15 Apr 2016 11:31:39 +0100 Subject: [PATCH] Allow flags of spawned entities to be set. --- src/battle/spawners.c | 57 ++++++++++++++++++++++++++++++++----------- src/battle/spawners.h | 2 ++ src/structs.h | 2 ++ 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/battle/spawners.c b/src/battle/spawners.c index 0c41a3f..6f50dad 100644 --- a/src/battle/spawners.c +++ b/src/battle/spawners.c @@ -25,12 +25,15 @@ void doSpawners(void) Entity *e; Spawner *s; char *type; - int i, num; + int i, num, addFlags, addAIFlags; + long flags, aiFlags; for (s = battle.spawnerHead.next ; s != NULL ; s = s->next) { if (s->active && --s->time <= 0) { + aiFlags = flags = -1; + num = s->step; if (s->total != -1) @@ -45,6 +48,16 @@ void doSpawners(void) battle.numInitialEnemies += num; } + if (strlen(s->flags)) + { + flags = flagsToLong(s->flags, &addFlags); + } + + if (strlen(s->aiFlags)) + { + aiFlags = flagsToLong(s->aiFlags, &addAIFlags); + } + for (i = 0 ; i < num ; i++) { type = s->types[rand() % s->numTypes]; @@ -67,7 +80,29 @@ void doSpawners(void) e->x += (rand() % 2) ? -SCREEN_WIDTH : SCREEN_WIDTH; e->y += (rand() % 2) ? -SCREEN_HEIGHT : SCREEN_HEIGHT; - e->aiFlags |= AIF_UNLIMITED_RANGE; + if (flags != -1) + { + if (addFlags) + { + e->flags |= flags; + } + else + { + e->flags = flags; + } + } + + if (aiFlags != -1) + { + if (addAIFlags) + { + e->aiFlags |= aiFlags; + } + else + { + e->aiFlags = aiFlags; + } + } } s->time = s->interval; @@ -75,24 +110,16 @@ void doSpawners(void) } } -void activateSpawner(char *names, int active) +void activateSpawner(char *name, int active) { Spawner *s; - char *name; - name = strtok(names, ";"); - - while (name) + for (s = battle.spawnerHead.next ; s != NULL ; s = s->next) { - for (s = battle.spawnerHead.next ; s != NULL ; s = s->next) + if (strcmp(s->name, name) == 0) { - if (strcmp(s->name, name) == 0) - { - s->active = active; - } + s->active = active; } - - name = strtok(NULL, ";"); } } @@ -120,6 +147,8 @@ void loadSpawners(cJSON *node) s->step = cJSON_GetObjectItem(node, "step")->valueint; s->offscreen = getJSONValue(node, "offscreen", 0); s->active = active = getJSONValue(node, "active", 1); + STRNCPY(s->flags, getJSONValueStr(node, "flags", ""), MAX_DESCRIPTION_LENGTH); + STRNCPY(s->aiFlags, getJSONValueStr(node, "aiFlags", ""), MAX_DESCRIPTION_LENGTH); node = node->next; } diff --git a/src/battle/spawners.h b/src/battle/spawners.h index cead7c8..af8715b 100644 --- a/src/battle/spawners.h +++ b/src/battle/spawners.h @@ -26,6 +26,8 @@ extern long lookup(char *name); extern Entity *spawnFighter(char *name, int x, int y, int side); extern int getJSONValue(cJSON *node, char *name, int defValue); extern char **toTypeArray(char *types, int *numTypes); +extern char *getJSONValueStr(cJSON *node, char *name, char *defValue); +extern long flagsToLong(char *flags, int *add); extern Battle battle; extern Entity *player; diff --git a/src/structs.h b/src/structs.h index aad74db..a4f92ae 100644 --- a/src/structs.h +++ b/src/structs.h @@ -318,6 +318,8 @@ struct Spawner { int step; int offscreen; int active; + char flags[MAX_DESCRIPTION_LENGTH]; + char aiFlags[MAX_DESCRIPTION_LENGTH]; Spawner *next; };