Integrated triggers.
This commit is contained in:
parent
f197d656c4
commit
44818d295a
|
@ -8,8 +8,31 @@
|
|||
{
|
||||
"description" : "Reach Waypoints",
|
||||
"targetName" : "Waypoint",
|
||||
"targetValue" : 5,
|
||||
"targetValue" : 1,
|
||||
"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" : {
|
||||
|
@ -18,27 +41,20 @@
|
|||
},
|
||||
"fighters" : [
|
||||
{
|
||||
"name" : "Sphinx",
|
||||
"type" : "Sphinx",
|
||||
"side" : "SIDE_CSN",
|
||||
"x" : 1800,
|
||||
"y" : 200
|
||||
},
|
||||
{
|
||||
"name" : "Nymph",
|
||||
"type" : "Nymph",
|
||||
"side" : "SIDE_CSN",
|
||||
"x" : 1800,
|
||||
"y" : 200
|
||||
"name" : "Dart",
|
||||
"type" : "UnarmedDart",
|
||||
"side" : "SIDE_PIRATE",
|
||||
"x" : 640,
|
||||
"y" : 0,
|
||||
"active" : 0
|
||||
}
|
||||
],
|
||||
"entityGroups" : [
|
||||
{
|
||||
"type" : "ET_WAYPOINT",
|
||||
"number" : 5,
|
||||
"number" : 1,
|
||||
"x" : 0,
|
||||
"y" : 1000,
|
||||
"scatter" : 1000
|
||||
"y" : 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -46,68 +46,66 @@ void doEntities(void)
|
|||
|
||||
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)
|
||||
{
|
||||
e->action = e->defaultAction;
|
||||
e->target = NULL;
|
||||
}
|
||||
|
||||
e->x += e->dx;
|
||||
e->y += e->dy;
|
||||
|
||||
if (e != player)
|
||||
{
|
||||
e->x -= battle.ssx;
|
||||
e->y -= battle.ssy;
|
||||
}
|
||||
|
||||
if (e->action != NULL)
|
||||
{
|
||||
if (--e->thinkTime <= 0)
|
||||
if (e->target != NULL && e->target->health <= 0)
|
||||
{
|
||||
e->thinkTime = 0;
|
||||
e->action();
|
||||
}
|
||||
}
|
||||
|
||||
switch (e->type)
|
||||
{
|
||||
case ET_FIGHTER:
|
||||
doFighter();
|
||||
break;
|
||||
|
||||
default:
|
||||
doEntity();
|
||||
break;
|
||||
}
|
||||
|
||||
if (e->alive == ALIVE_DEAD)
|
||||
{
|
||||
if (e == battle.entityTail)
|
||||
{
|
||||
battle.entityTail = prev;
|
||||
e->action = e->defaultAction;
|
||||
e->target = NULL;
|
||||
}
|
||||
|
||||
if (e == battle.missionTarget)
|
||||
e->x += e->dx;
|
||||
e->y += e->dy;
|
||||
|
||||
if (e != player)
|
||||
{
|
||||
battle.missionTarget = NULL;
|
||||
e->x -= battle.ssx;
|
||||
e->y -= battle.ssy;
|
||||
}
|
||||
|
||||
if (e == player)
|
||||
if (e->action != NULL)
|
||||
{
|
||||
player = NULL;
|
||||
if (--e->thinkTime <= 0)
|
||||
{
|
||||
e->thinkTime = 0;
|
||||
e->action();
|
||||
}
|
||||
}
|
||||
|
||||
prev->next = e->next;
|
||||
free(e);
|
||||
e = prev;
|
||||
switch (e->type)
|
||||
{
|
||||
case ET_FIGHTER:
|
||||
doFighter();
|
||||
break;
|
||||
|
||||
default:
|
||||
doEntity();
|
||||
break;
|
||||
}
|
||||
|
||||
if (e->alive == ALIVE_DEAD)
|
||||
{
|
||||
if (e == battle.entityTail)
|
||||
{
|
||||
battle.entityTail = prev;
|
||||
}
|
||||
|
||||
if (e == battle.missionTarget)
|
||||
{
|
||||
battle.missionTarget = NULL;
|
||||
}
|
||||
|
||||
if (e == player)
|
||||
{
|
||||
player = NULL;
|
||||
}
|
||||
|
||||
prev->next = e->next;
|
||||
free(e);
|
||||
e = prev;
|
||||
}
|
||||
}
|
||||
|
||||
prev = e;
|
||||
|
@ -150,3 +148,16 @@ static void drawEntity(Entity *e)
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,29 +88,32 @@ static void drawMissionSummary(SDL_Texture *header)
|
|||
|
||||
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||
{
|
||||
y += 50;
|
||||
|
||||
switch (o->status)
|
||||
if (o->active)
|
||||
{
|
||||
case OS_INCOMPLETE:
|
||||
color = colors.white;
|
||||
break;
|
||||
y += 50;
|
||||
|
||||
case OS_COMPLETE:
|
||||
color = colors.green;
|
||||
break;
|
||||
switch (o->status)
|
||||
{
|
||||
case OS_INCOMPLETE:
|
||||
color = colors.white;
|
||||
break;
|
||||
|
||||
case OS_FAILED:
|
||||
color = colors.red;
|
||||
break;
|
||||
case OS_COMPLETE:
|
||||
color = colors.green;
|
||||
break;
|
||||
|
||||
case OS_FAILED:
|
||||
color = colors.red;
|
||||
break;
|
||||
}
|
||||
|
||||
drawText(SCREEN_WIDTH / 2 - 100, y, 22, TA_RIGHT, colors.white, o->description);
|
||||
if (o->targetValue > 1)
|
||||
{
|
||||
drawText(SCREEN_WIDTH / 2, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue);
|
||||
}
|
||||
drawText(SCREEN_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]);
|
||||
}
|
||||
|
||||
drawText(SCREEN_WIDTH / 2 - 100, y, 22, TA_RIGHT, colors.white, o->description);
|
||||
if (o->targetValue > 1)
|
||||
{
|
||||
drawText(SCREEN_WIDTH / 2, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue);
|
||||
}
|
||||
drawText(SCREEN_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]);
|
||||
}
|
||||
|
||||
if (!battle.objectiveHead.next)
|
||||
|
|
|
@ -26,16 +26,25 @@ void failIncompleteObjectives(void);
|
|||
void doObjectives(void)
|
||||
{
|
||||
int objectiveFailed;
|
||||
int numHiddenObjectives;
|
||||
Objective *o;
|
||||
|
||||
battle.numObjectivesComplete = battle.numObjectivesTotal = 0;
|
||||
objectiveFailed = 0;
|
||||
numHiddenObjectives = 0;
|
||||
|
||||
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
||||
{
|
||||
if (!o->isCondition)
|
||||
if (o->active)
|
||||
{
|
||||
battle.numObjectivesTotal++;
|
||||
if (!o->isCondition)
|
||||
{
|
||||
battle.numObjectivesTotal++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
numHiddenObjectives++;
|
||||
}
|
||||
|
||||
if (o->currentValue == o->targetValue)
|
||||
|
@ -58,7 +67,7 @@ void doObjectives(void)
|
|||
|
||||
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();
|
||||
|
||||
|
@ -82,7 +91,7 @@ void updateObjective(char *name, int type)
|
|||
|
||||
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++;
|
||||
|
||||
|
@ -110,7 +119,7 @@ void updateCondition(char *name, int type)
|
|||
|
||||
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++;
|
||||
|
||||
|
@ -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:
|
||||
return trigger->targetValue == battle.stats[STAT_ENEMIES_KILLED];
|
||||
|
||||
case TRIGGER_WAYPOINT:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -63,5 +66,13 @@ static void fireTrigger(Trigger *trigger)
|
|||
addHudMessage(colors.red, "Mission Failed!");
|
||||
failMission();
|
||||
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 failMission(void);
|
||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||
extern void activateEntities(char *name);
|
||||
extern void activateObjective(int num);
|
||||
|
||||
extern Battle battle;
|
||||
extern Colors colors;
|
||||
|
|
|
@ -160,7 +160,9 @@ enum
|
|||
enum
|
||||
{
|
||||
TA_COMPLETE_MISSION,
|
||||
TA_FAIL_MISSION
|
||||
TA_FAIL_MISSION,
|
||||
TA_ACTIVE_ENTITY,
|
||||
TA_ACTIVE_OBJECTIVE
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
|
@ -119,11 +119,17 @@ static void loadObjectives(cJSON *node)
|
|||
battle.objectiveTail->next = o;
|
||||
battle.objectiveTail = o;
|
||||
|
||||
o->active = 1;
|
||||
STRNCPY(o->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
|
||||
STRNCPY(o->targetName, cJSON_GetObjectItem(node, "targetName")->valuestring, MAX_NAME_LENGTH);
|
||||
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||
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"))
|
||||
{
|
||||
o->isCondition = cJSON_GetObjectItem(node, "isCondition")->valueint;
|
||||
|
@ -159,6 +165,11 @@ static void loadTriggers(cJSON *node)
|
|||
t->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +213,11 @@ static void loadFighters(cJSON *node)
|
|||
f->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
|
||||
}
|
||||
|
||||
if (cJSON_GetObjectItem(node, "active"))
|
||||
{
|
||||
f->active = cJSON_GetObjectItem(node, "active")->valueint;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
@ -211,10 +227,11 @@ static void loadFighterGroups(cJSON *node)
|
|||
{
|
||||
Entity *f;
|
||||
char **types, *name, *type;
|
||||
int side, x, y, scatter, number;
|
||||
int side, x, y, scatter, number, active;
|
||||
int i, numTypes;
|
||||
|
||||
scatter = 1;
|
||||
active = 1;
|
||||
|
||||
if (node)
|
||||
{
|
||||
|
@ -234,6 +251,11 @@ static void loadFighterGroups(cJSON *node)
|
|||
scatter = cJSON_GetObjectItem(node, "scatter")->valueint;
|
||||
}
|
||||
|
||||
if (cJSON_GetObjectItem(node, "active"))
|
||||
{
|
||||
active = cJSON_GetObjectItem(node, "active")->valueint;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < number ; i++)
|
||||
{
|
||||
type = types[rand() % numTypes];
|
||||
|
@ -243,6 +265,8 @@ static void loadFighterGroups(cJSON *node)
|
|||
f->x += (rand() % scatter) - (rand() % scatter);
|
||||
f->y += (rand() % scatter) - (rand() % scatter);
|
||||
|
||||
f->active = active;
|
||||
|
||||
STRNCPY(f->name, name, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
|
@ -309,6 +333,7 @@ static void loadEntityGroups(cJSON *node)
|
|||
number = cJSON_GetObjectItem(node, "number")->valueint;
|
||||
x = cJSON_GetObjectItem(node, "x")->valueint;
|
||||
y = cJSON_GetObjectItem(node, "y")->valueint;
|
||||
name = NULL;
|
||||
|
||||
if (cJSON_GetObjectItem(node, "name"))
|
||||
{
|
||||
|
|
|
@ -160,6 +160,7 @@ struct Effect {
|
|||
};
|
||||
|
||||
struct Objective {
|
||||
int active;
|
||||
char description[MAX_DESCRIPTION_LENGTH];
|
||||
char targetName[MAX_NAME_LENGTH];
|
||||
int targetType;
|
||||
|
@ -183,6 +184,7 @@ struct Trigger {
|
|||
char targetName[MAX_NAME_LENGTH];
|
||||
int targetValue;
|
||||
int action;
|
||||
char actionValue[MAX_NAME_LENGTH];
|
||||
Trigger *next;
|
||||
};
|
||||
|
||||
|
|
|
@ -97,9 +97,12 @@ void initLookups(void)
|
|||
|
||||
addLookup("TRIGGER_TIME", TRIGGER_TIME);
|
||||
addLookup("TRIGGER_KILLS", TRIGGER_KILLS);
|
||||
addLookup("TRIGGER_WAYPOINT", TRIGGER_WAYPOINT);
|
||||
|
||||
addLookup("TA_COMPLETE_MISSION", TA_COMPLETE_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)
|
||||
|
|
Loading…
Reference in New Issue