Allow flags of spawned entities to be set.

This commit is contained in:
Steve 2016-04-15 11:31:39 +01:00
parent a49817ba2e
commit c3136ea3af
3 changed files with 47 additions and 14 deletions

View File

@ -25,12 +25,15 @@ void doSpawners(void)
Entity *e; Entity *e;
Spawner *s; Spawner *s;
char *type; char *type;
int i, num; int i, num, addFlags, addAIFlags;
long flags, aiFlags;
for (s = battle.spawnerHead.next ; s != NULL ; s = s->next) for (s = battle.spawnerHead.next ; s != NULL ; s = s->next)
{ {
if (s->active && --s->time <= 0) if (s->active && --s->time <= 0)
{ {
aiFlags = flags = -1;
num = s->step; num = s->step;
if (s->total != -1) if (s->total != -1)
@ -45,6 +48,16 @@ void doSpawners(void)
battle.numInitialEnemies += num; 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++) for (i = 0 ; i < num ; i++)
{ {
type = s->types[rand() % s->numTypes]; type = s->types[rand() % s->numTypes];
@ -67,7 +80,29 @@ void doSpawners(void)
e->x += (rand() % 2) ? -SCREEN_WIDTH : SCREEN_WIDTH; e->x += (rand() % 2) ? -SCREEN_WIDTH : SCREEN_WIDTH;
e->y += (rand() % 2) ? -SCREEN_HEIGHT : SCREEN_HEIGHT; 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; 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; Spawner *s;
char *name;
name = strtok(names, ";"); for (s = battle.spawnerHead.next ; s != NULL ; s = s->next)
while (name)
{ {
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->step = cJSON_GetObjectItem(node, "step")->valueint;
s->offscreen = getJSONValue(node, "offscreen", 0); s->offscreen = getJSONValue(node, "offscreen", 0);
s->active = active = getJSONValue(node, "active", 1); 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; node = node->next;
} }

View File

@ -26,6 +26,8 @@ extern long lookup(char *name);
extern Entity *spawnFighter(char *name, int x, int y, int side); extern Entity *spawnFighter(char *name, int x, int y, int side);
extern int getJSONValue(cJSON *node, char *name, int defValue); extern int getJSONValue(cJSON *node, char *name, int defValue);
extern char **toTypeArray(char *types, int *numTypes); 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 Battle battle;
extern Entity *player; extern Entity *player;

View File

@ -318,6 +318,8 @@ struct Spawner {
int step; int step;
int offscreen; int offscreen;
int active; int active;
char flags[MAX_DESCRIPTION_LENGTH];
char aiFlags[MAX_DESCRIPTION_LENGTH];
Spawner *next; Spawner *next;
}; };