Integrated triggers.
This commit is contained in:
parent
f197d656c4
commit
44818d295a
|
@ -8,8 +8,31 @@
|
||||||
{
|
{
|
||||||
"description" : "Reach Waypoints",
|
"description" : "Reach Waypoints",
|
||||||
"targetName" : "Waypoint",
|
"targetName" : "Waypoint",
|
||||||
"targetValue" : 5,
|
"targetValue" : 1,
|
||||||
"targetType" : "TT_WAYPOINT"
|
"targetType" : "TT_WAYPOINT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description" : "Destroy Fighters",
|
||||||
|
"targetName" : "Dart",
|
||||||
|
"targetValue" : 1,
|
||||||
|
"targetType" : "TT_DESTROY",
|
||||||
|
"active" : 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"triggers" : [
|
||||||
|
{
|
||||||
|
"type" : "TRIGGER_WAYPOINT",
|
||||||
|
"targetName" : "Waypoint #1",
|
||||||
|
"targetValue" : "1",
|
||||||
|
"action" : "TA_ACTIVE_ENTITY",
|
||||||
|
"actionValue" : "Dart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type" : "TRIGGER_WAYPOINT",
|
||||||
|
"targetName" : "Waypoint #1",
|
||||||
|
"targetValue" : "1",
|
||||||
|
"action" : "TA_ACTIVE_OBJECTIVE",
|
||||||
|
"actionValue" : "1"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"player" : {
|
"player" : {
|
||||||
|
@ -18,27 +41,20 @@
|
||||||
},
|
},
|
||||||
"fighters" : [
|
"fighters" : [
|
||||||
{
|
{
|
||||||
"name" : "Sphinx",
|
"name" : "Dart",
|
||||||
"type" : "Sphinx",
|
"type" : "UnarmedDart",
|
||||||
"side" : "SIDE_CSN",
|
"side" : "SIDE_PIRATE",
|
||||||
"x" : 1800,
|
"x" : 640,
|
||||||
"y" : 200
|
"y" : 0,
|
||||||
},
|
"active" : 0
|
||||||
{
|
|
||||||
"name" : "Nymph",
|
|
||||||
"type" : "Nymph",
|
|
||||||
"side" : "SIDE_CSN",
|
|
||||||
"x" : 1800,
|
|
||||||
"y" : 200
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"entityGroups" : [
|
"entityGroups" : [
|
||||||
{
|
{
|
||||||
"type" : "ET_WAYPOINT",
|
"type" : "ET_WAYPOINT",
|
||||||
"number" : 5,
|
"number" : 1,
|
||||||
"x" : 0,
|
"x" : 0,
|
||||||
"y" : 1000,
|
"y" : 1000
|
||||||
"scatter" : 1000
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,9 @@ void doEntities(void)
|
||||||
|
|
||||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||||
{
|
{
|
||||||
self = e;
|
if (e->active)
|
||||||
|
|
||||||
if (!e->active)
|
|
||||||
{
|
{
|
||||||
continue;
|
self = e;
|
||||||
}
|
|
||||||
|
|
||||||
if (e->target != NULL && e->target->health <= 0)
|
if (e->target != NULL && e->target->health <= 0)
|
||||||
{
|
{
|
||||||
|
@ -109,6 +106,7 @@ void doEntities(void)
|
||||||
free(e);
|
free(e);
|
||||||
e = prev;
|
e = prev;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prev = e;
|
prev = e;
|
||||||
}
|
}
|
||||||
|
@ -150,3 +148,16 @@ static void drawEntity(Entity *e)
|
||||||
{
|
{
|
||||||
blitRotated(e->texture, e->x, e->y, e->angle);
|
blitRotated(e->texture, e->x, e->y, e->angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void activateEntities(char *name)
|
||||||
|
{
|
||||||
|
Entity *e;
|
||||||
|
|
||||||
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||||
|
{
|
||||||
|
if (strcmp(e->name, name) == 0)
|
||||||
|
{
|
||||||
|
e->active = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -87,6 +87,8 @@ static void drawMissionSummary(SDL_Texture *header)
|
||||||
y += 10;
|
y += 10;
|
||||||
|
|
||||||
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||||
|
{
|
||||||
|
if (o->active)
|
||||||
{
|
{
|
||||||
y += 50;
|
y += 50;
|
||||||
|
|
||||||
|
@ -112,6 +114,7 @@ static void drawMissionSummary(SDL_Texture *header)
|
||||||
}
|
}
|
||||||
drawText(SCREEN_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]);
|
drawText(SCREEN_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!battle.objectiveHead.next)
|
if (!battle.objectiveHead.next)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,17 +26,26 @@ void failIncompleteObjectives(void);
|
||||||
void doObjectives(void)
|
void doObjectives(void)
|
||||||
{
|
{
|
||||||
int objectiveFailed;
|
int objectiveFailed;
|
||||||
|
int numHiddenObjectives;
|
||||||
Objective *o;
|
Objective *o;
|
||||||
|
|
||||||
battle.numObjectivesComplete = battle.numObjectivesTotal = 0;
|
battle.numObjectivesComplete = battle.numObjectivesTotal = 0;
|
||||||
objectiveFailed = 0;
|
objectiveFailed = 0;
|
||||||
|
numHiddenObjectives = 0;
|
||||||
|
|
||||||
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||||
|
{
|
||||||
|
if (o->active)
|
||||||
{
|
{
|
||||||
if (!o->isCondition)
|
if (!o->isCondition)
|
||||||
{
|
{
|
||||||
battle.numObjectivesTotal++;
|
battle.numObjectivesTotal++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
numHiddenObjectives++;
|
||||||
|
}
|
||||||
|
|
||||||
if (o->currentValue == o->targetValue)
|
if (o->currentValue == o->targetValue)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +67,7 @@ void doObjectives(void)
|
||||||
|
|
||||||
if (battle.status == MS_IN_PROGRESS)
|
if (battle.status == MS_IN_PROGRESS)
|
||||||
{
|
{
|
||||||
if (battle.numObjectivesTotal > 0 && battle.numObjectivesComplete == battle.numObjectivesTotal)
|
if (numHiddenObjectives == 0 && battle.numObjectivesTotal > 0 && battle.numObjectivesComplete == battle.numObjectivesTotal)
|
||||||
{
|
{
|
||||||
completeMission();
|
completeMission();
|
||||||
|
|
||||||
|
@ -82,7 +91,7 @@ void updateObjective(char *name, int type)
|
||||||
|
|
||||||
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||||
{
|
{
|
||||||
if (!o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
if (o->active && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
||||||
{
|
{
|
||||||
o->currentValue++;
|
o->currentValue++;
|
||||||
|
|
||||||
|
@ -110,7 +119,7 @@ void updateCondition(char *name, int type)
|
||||||
|
|
||||||
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||||
{
|
{
|
||||||
if (o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
if (o->active && o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
||||||
{
|
{
|
||||||
o->currentValue++;
|
o->currentValue++;
|
||||||
|
|
||||||
|
@ -149,3 +158,21 @@ void failIncompleteObjectives(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void activateObjective(int num)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
Objective *o;
|
||||||
|
|
||||||
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||||
|
{
|
||||||
|
if (i == num)
|
||||||
|
{
|
||||||
|
addHudMessage(colors.cyan, "New Objectives : %s", o->description);
|
||||||
|
o->active = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ static int conditionMet(Trigger *trigger)
|
||||||
|
|
||||||
case TRIGGER_KILLS:
|
case TRIGGER_KILLS:
|
||||||
return trigger->targetValue == battle.stats[STAT_ENEMIES_KILLED];
|
return trigger->targetValue == battle.stats[STAT_ENEMIES_KILLED];
|
||||||
|
|
||||||
|
case TRIGGER_WAYPOINT:
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -63,5 +66,13 @@ static void fireTrigger(Trigger *trigger)
|
||||||
addHudMessage(colors.red, "Mission Failed!");
|
addHudMessage(colors.red, "Mission Failed!");
|
||||||
failMission();
|
failMission();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TA_ACTIVE_ENTITY:
|
||||||
|
activateEntities(trigger->actionValue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TA_ACTIVE_OBJECTIVE:
|
||||||
|
activateObjective(atoi(trigger->actionValue));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
extern void completeMission(void);
|
extern void completeMission(void);
|
||||||
extern void failMission(void);
|
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 activateObjective(int num);
|
||||||
|
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
|
@ -160,7 +160,9 @@ enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TA_COMPLETE_MISSION,
|
TA_COMPLETE_MISSION,
|
||||||
TA_FAIL_MISSION
|
TA_FAIL_MISSION,
|
||||||
|
TA_ACTIVE_ENTITY,
|
||||||
|
TA_ACTIVE_OBJECTIVE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -119,11 +119,17 @@ static void loadObjectives(cJSON *node)
|
||||||
battle.objectiveTail->next = o;
|
battle.objectiveTail->next = o;
|
||||||
battle.objectiveTail = o;
|
battle.objectiveTail = o;
|
||||||
|
|
||||||
|
o->active = 1;
|
||||||
STRNCPY(o->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
|
STRNCPY(o->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
|
||||||
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
|
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
|
||||||
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||||
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
|
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(node, "active"))
|
||||||
|
{
|
||||||
|
o->active = cJSON_GetObjectItem(node, "active")->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(node, "isCondition"))
|
if (cJSON_GetObjectItem(node, "isCondition"))
|
||||||
{
|
{
|
||||||
o->isCondition = cJSON_GetObjectItem(node, "isCondition")->valueint;
|
o->isCondition = cJSON_GetObjectItem(node, "isCondition")->valueint;
|
||||||
|
@ -159,6 +165,11 @@ static void loadTriggers(cJSON *node)
|
||||||
t->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
t->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||||
t->action = lookup(cJSON_GetObjectItem(node, "action")->valuestring);
|
t->action = lookup(cJSON_GetObjectItem(node, "action")->valuestring);
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(node, "actionValue"))
|
||||||
|
{
|
||||||
|
STRNCPY(t->actionValue, cJSON_GetObjectItem(node, "actionValue")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
node = node->next;
|
node = node->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,6 +213,11 @@ static void loadFighters(cJSON *node)
|
||||||
f->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
|
f->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(node, "active"))
|
||||||
|
{
|
||||||
|
f->active = cJSON_GetObjectItem(node, "active")->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
node = node->next;
|
node = node->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,10 +227,11 @@ static void loadFighterGroups(cJSON *node)
|
||||||
{
|
{
|
||||||
Entity *f;
|
Entity *f;
|
||||||
char **types, *name, *type;
|
char **types, *name, *type;
|
||||||
int side, x, y, scatter, number;
|
int side, x, y, scatter, number, active;
|
||||||
int i, numTypes;
|
int i, numTypes;
|
||||||
|
|
||||||
scatter = 1;
|
scatter = 1;
|
||||||
|
active = 1;
|
||||||
|
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
|
@ -234,6 +251,11 @@ static void loadFighterGroups(cJSON *node)
|
||||||
scatter = cJSON_GetObjectItem(node, "scatter")->valueint;
|
scatter = cJSON_GetObjectItem(node, "scatter")->valueint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(node, "active"))
|
||||||
|
{
|
||||||
|
active = cJSON_GetObjectItem(node, "active")->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0 ; i < number ; i++)
|
for (i = 0 ; i < number ; i++)
|
||||||
{
|
{
|
||||||
type = types[rand() % numTypes];
|
type = types[rand() % numTypes];
|
||||||
|
@ -243,6 +265,8 @@ static void loadFighterGroups(cJSON *node)
|
||||||
f->x += (rand() % scatter) - (rand() % scatter);
|
f->x += (rand() % scatter) - (rand() % scatter);
|
||||||
f->y += (rand() % scatter) - (rand() % scatter);
|
f->y += (rand() % scatter) - (rand() % scatter);
|
||||||
|
|
||||||
|
f->active = active;
|
||||||
|
|
||||||
STRNCPY(f->name, name, MAX_NAME_LENGTH);
|
STRNCPY(f->name, name, MAX_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +333,7 @@ static void loadEntityGroups(cJSON *node)
|
||||||
number = cJSON_GetObjectItem(node, "number")->valueint;
|
number = cJSON_GetObjectItem(node, "number")->valueint;
|
||||||
x = cJSON_GetObjectItem(node, "x")->valueint;
|
x = cJSON_GetObjectItem(node, "x")->valueint;
|
||||||
y = cJSON_GetObjectItem(node, "y")->valueint;
|
y = cJSON_GetObjectItem(node, "y")->valueint;
|
||||||
|
name = NULL;
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(node, "name"))
|
if (cJSON_GetObjectItem(node, "name"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -160,6 +160,7 @@ struct Effect {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Objective {
|
struct Objective {
|
||||||
|
int active;
|
||||||
char description[MAX_DESCRIPTION_LENGTH];
|
char description[MAX_DESCRIPTION_LENGTH];
|
||||||
char targetName[MAX_NAME_LENGTH];
|
char targetName[MAX_NAME_LENGTH];
|
||||||
int targetType;
|
int targetType;
|
||||||
|
@ -183,6 +184,7 @@ struct Trigger {
|
||||||
char targetName[MAX_NAME_LENGTH];
|
char targetName[MAX_NAME_LENGTH];
|
||||||
int targetValue;
|
int targetValue;
|
||||||
int action;
|
int action;
|
||||||
|
char actionValue[MAX_NAME_LENGTH];
|
||||||
Trigger *next;
|
Trigger *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -97,9 +97,12 @@ void initLookups(void)
|
||||||
|
|
||||||
addLookup("TRIGGER_TIME", TRIGGER_TIME);
|
addLookup("TRIGGER_TIME", TRIGGER_TIME);
|
||||||
addLookup("TRIGGER_KILLS", TRIGGER_KILLS);
|
addLookup("TRIGGER_KILLS", TRIGGER_KILLS);
|
||||||
|
addLookup("TRIGGER_WAYPOINT", TRIGGER_WAYPOINT);
|
||||||
|
|
||||||
addLookup("TA_COMPLETE_MISSION", TA_COMPLETE_MISSION);
|
addLookup("TA_COMPLETE_MISSION", TA_COMPLETE_MISSION);
|
||||||
addLookup("TA_FAIL_MISSION", TA_FAIL_MISSION);
|
addLookup("TA_FAIL_MISSION", TA_FAIL_MISSION);
|
||||||
|
addLookup("TA_ACTIVE_ENTITY", TA_ACTIVE_ENTITY);
|
||||||
|
addLookup("TA_ACTIVE_OBJECTIVE", TA_ACTIVE_OBJECTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addLookup(char *name, long value)
|
static void addLookup(char *name, long value)
|
||||||
|
|
Loading…
Reference in New Issue