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)
{
Entity *e;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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