Added entity groups, to help with triggers and events.

This commit is contained in:
Steve 2015-11-14 08:41:07 +00:00
parent 83407704c6
commit 1f62eb2564
7 changed files with 48 additions and 2 deletions

View File

@ -276,6 +276,19 @@ void activateEntities(char *name)
} }
} }
void activateEntityGroup(char *groupName)
{
Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{
if (strcmp(e->groupName, groupName) == 0)
{
e->active = 1;
}
}
}
static void activateEpicFighters(int n, int side) static void activateEpicFighters(int n, int side)
{ {
Entity *e; Entity *e;

View File

@ -74,6 +74,10 @@ static void fireTrigger(Trigger *trigger)
activateEntities(trigger->actionValue); activateEntities(trigger->actionValue);
break; break;
case TA_ACTIVE_ENTITY_GROUP:
activateEntityGroup(trigger->actionValue);
break;
case TA_ACTIVE_OBJECTIVE: case TA_ACTIVE_OBJECTIVE:
activateObjective(atoi(trigger->actionValue)); activateObjective(atoi(trigger->actionValue));
break; break;

View File

@ -28,6 +28,7 @@ extern void failMission(void);
extern void addHudMessage(SDL_Color c, char *format, ...); extern void addHudMessage(SDL_Color c, char *format, ...);
extern void activateEntities(char *name); extern void activateEntities(char *name);
extern void activateObjective(int num); extern void activateObjective(int num);
extern void activateEntityGroup(char *groupName);
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;

View File

@ -178,6 +178,7 @@ enum
TA_COMPLETE_MISSION, TA_COMPLETE_MISSION,
TA_FAIL_MISSION, TA_FAIL_MISSION,
TA_ACTIVE_ENTITY, TA_ACTIVE_ENTITY,
TA_ACTIVE_ENTITY_GROUP,
TA_ACTIVE_OBJECTIVE TA_ACTIVE_OBJECTIVE
}; };

View File

@ -115,6 +115,8 @@ void failMission(void)
battle.status = MS_FAILED; battle.status = MS_FAILED;
battle.missionFinishedTimer = FPS; battle.missionFinishedTimer = FPS;
selectWidget("retry", "battleLost"); selectWidget("retry", "battleLost");
failIncompleteObjectives();
} }
} }
@ -242,7 +244,7 @@ static void loadFighters(cJSON *node)
static void loadFighterGroups(cJSON *node) static void loadFighterGroups(cJSON *node)
{ {
Entity *f; Entity *f;
char **types, *name, *type; char **types, *name, *groupName, *type;
int side, scatter, number, active; int side, scatter, number, active;
int i, numTypes; int i, numTypes;
float x, y; float x, y;
@ -256,6 +258,8 @@ static void loadFighterGroups(cJSON *node)
while (node) while (node)
{ {
groupName = NULL;
types = toFighterTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes); types = toFighterTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring); side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
number = cJSON_GetObjectItem(node, "number")->valueint; number = cJSON_GetObjectItem(node, "number")->valueint;
@ -263,6 +267,11 @@ static void loadFighterGroups(cJSON *node)
x = cJSON_GetObjectItem(node, "x")->valuedouble * GRID_CELL_WIDTH; x = cJSON_GetObjectItem(node, "x")->valuedouble * GRID_CELL_WIDTH;
y = cJSON_GetObjectItem(node, "y")->valuedouble * GRID_CELL_HEIGHT; y = cJSON_GetObjectItem(node, "y")->valuedouble * GRID_CELL_HEIGHT;
if (cJSON_GetObjectItem(node, "groupName"))
{
groupName = cJSON_GetObjectItem(node, "groupName")->valuestring;
}
if (cJSON_GetObjectItem(node, "scatter")) if (cJSON_GetObjectItem(node, "scatter"))
{ {
scatter = cJSON_GetObjectItem(node, "scatter")->valueint; scatter = cJSON_GetObjectItem(node, "scatter")->valueint;
@ -285,6 +294,11 @@ static void loadFighterGroups(cJSON *node)
f->active = active; f->active = active;
STRNCPY(f->name, name, MAX_NAME_LENGTH); STRNCPY(f->name, name, MAX_NAME_LENGTH);
if (groupName)
{
STRNCPY(f->groupName, groupName, MAX_NAME_LENGTH);
}
} }
node = node->next; node = node->next;
@ -341,7 +355,7 @@ static void loadEntities(cJSON *node)
static void loadEntityGroups(cJSON *node) static void loadEntityGroups(cJSON *node)
{ {
Entity *e; Entity *e;
char *name; char *name, *groupName;
int i, type, scatter, number; int i, type, scatter, number;
float x, y; float x, y;
@ -358,12 +372,18 @@ static void loadEntityGroups(cJSON *node)
x = cJSON_GetObjectItem(node, "x")->valuedouble * GRID_CELL_WIDTH; x = cJSON_GetObjectItem(node, "x")->valuedouble * GRID_CELL_WIDTH;
y = cJSON_GetObjectItem(node, "y")->valuedouble * GRID_CELL_HEIGHT; y = cJSON_GetObjectItem(node, "y")->valuedouble * GRID_CELL_HEIGHT;
name = NULL; name = NULL;
groupName = NULL;
if (cJSON_GetObjectItem(node, "name")) if (cJSON_GetObjectItem(node, "name"))
{ {
name = cJSON_GetObjectItem(node, "name")->valuestring; name = cJSON_GetObjectItem(node, "name")->valuestring;
} }
if (cJSON_GetObjectItem(node, "groupName"))
{
groupName = cJSON_GetObjectItem(node, "groupName")->valuestring;
}
if (cJSON_GetObjectItem(node, "scatter")) if (cJSON_GetObjectItem(node, "scatter"))
{ {
scatter = cJSON_GetObjectItem(node, "scatter")->valueint; scatter = cJSON_GetObjectItem(node, "scatter")->valueint;
@ -383,6 +403,11 @@ static void loadEntityGroups(cJSON *node)
STRNCPY(e->name, name, MAX_NAME_LENGTH); STRNCPY(e->name, name, MAX_NAME_LENGTH);
} }
if (groupName)
{
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
}
e->id = battle.entId++; e->id = battle.entId++;
e->x = x; e->x = x;
e->y = y; e->y = y;

View File

@ -73,6 +73,7 @@ struct Entity {
int type; int type;
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
char defName[MAX_NAME_LENGTH]; char defName[MAX_NAME_LENGTH];
char groupName[MAX_NAME_LENGTH];
int active; int active;
int id; int id;
int side; int side;

View File

@ -110,6 +110,7 @@ void initLookups(void)
addLookup("TA_FAIL_MISSION", TA_FAIL_MISSION); addLookup("TA_FAIL_MISSION", TA_FAIL_MISSION);
addLookup("TA_ACTIVE_ENTITY", TA_ACTIVE_ENTITY); addLookup("TA_ACTIVE_ENTITY", TA_ACTIVE_ENTITY);
addLookup("TA_ACTIVE_OBJECTIVE", TA_ACTIVE_OBJECTIVE); addLookup("TA_ACTIVE_OBJECTIVE", TA_ACTIVE_OBJECTIVE);
addLookup("TA_ACTIVE_ENTITY_GROUP", TA_ACTIVE_ENTITY_GROUP);
} }
static void addLookup(char *name, long value) static void addLookup(char *name, long value)