2015-10-20 13:51:49 +02:00
|
|
|
/*
|
2016-02-21 16:50:27 +01:00
|
|
|
Copyright (C) 2015-2016 Parallel Realities
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "objectives.h"
|
|
|
|
|
2016-05-22 13:08:48 +02:00
|
|
|
static int fireObjectivesComplete;
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
void doObjectives(void)
|
|
|
|
{
|
2015-10-22 08:08:03 +02:00
|
|
|
int objectiveFailed;
|
2016-04-18 11:54:59 +02:00
|
|
|
int hasHidden;
|
2015-10-20 13:51:49 +02:00
|
|
|
Objective *o;
|
|
|
|
|
2016-03-29 08:19:39 +02:00
|
|
|
battle.numObjectivesComplete = battle.numObjectivesTotal = battle.numConditions = 0;
|
2015-10-22 08:08:03 +02:00
|
|
|
objectiveFailed = 0;
|
2016-04-18 11:54:59 +02:00
|
|
|
hasHidden = 0;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
2015-10-29 12:08:47 +01:00
|
|
|
if (o->active)
|
2015-10-22 08:08:03 +02:00
|
|
|
{
|
2015-10-29 12:08:47 +01:00
|
|
|
if (!o->isCondition)
|
|
|
|
{
|
|
|
|
battle.numObjectivesTotal++;
|
|
|
|
}
|
2016-03-29 08:19:39 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
battle.numConditions++;
|
|
|
|
}
|
2016-05-15 18:28:17 +02:00
|
|
|
|
|
|
|
if (o->isEliminateAll && o->status != OS_COMPLETE && !battle.hasThreats)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.green, _("%s - Objective Complete!"), o->description);
|
|
|
|
|
|
|
|
o->currentValue = o->targetValue;
|
|
|
|
|
|
|
|
o->status = OS_COMPLETE;
|
|
|
|
|
|
|
|
runScriptFunction("OBJECTIVES_COMPLETE %d", battle.numObjectivesComplete + 1);
|
2016-06-07 09:29:52 +02:00
|
|
|
|
|
|
|
playSound(SND_OBJECTIVE_COMPLETE);
|
2016-05-15 18:28:17 +02:00
|
|
|
}
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-18 11:54:59 +02:00
|
|
|
hasHidden = 1;
|
2015-10-22 08:08:03 +02:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
if (o->currentValue == o->targetValue)
|
|
|
|
{
|
2015-10-21 20:21:45 +02:00
|
|
|
switch (o->status)
|
|
|
|
{
|
|
|
|
case OS_COMPLETE:
|
|
|
|
battle.numObjectivesComplete++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OS_FAILED:
|
2015-12-22 18:58:18 +01:00
|
|
|
objectiveFailed = 1;
|
2015-10-21 20:21:45 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 20:21:45 +02:00
|
|
|
if (battle.status == MS_IN_PROGRESS)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-05-22 13:08:48 +02:00
|
|
|
if (!hasHidden && battle.numObjectivesTotal > 0 && battle.numObjectivesComplete == battle.numObjectivesTotal)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2016-05-22 13:08:48 +02:00
|
|
|
if (fireObjectivesComplete)
|
|
|
|
{
|
|
|
|
fireObjectivesComplete = 0;
|
2017-05-29 09:39:37 +02:00
|
|
|
|
|
|
|
runScriptFunction("ALL_OBJECTIVES_COMPLETE");
|
2016-05-22 13:08:48 +02:00
|
|
|
}
|
2016-05-19 10:31:09 +02:00
|
|
|
|
2016-05-22 13:08:48 +02:00
|
|
|
if (!battle.manualComplete)
|
|
|
|
{
|
|
|
|
completeMission();
|
|
|
|
}
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-22 08:08:03 +02:00
|
|
|
if (objectiveFailed)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2015-10-26 09:10:13 +01:00
|
|
|
failMission();
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 08:08:03 +02:00
|
|
|
void updateObjective(char *name, int type)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
Objective *o;
|
2016-04-18 11:54:59 +02:00
|
|
|
int completed, hasHidden;
|
2015-12-22 18:58:18 +01:00
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (strlen(name))
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
completed = battle.numObjectivesComplete;
|
|
|
|
|
|
|
|
hasHidden = 0;
|
|
|
|
|
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (o->active && o->status != OS_COMPLETE)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (!o->isEliminateAll && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
2015-12-22 18:58:18 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
o->currentValue++;
|
|
|
|
|
|
|
|
if (!o->hideNumbers)
|
2016-03-16 20:24:41 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (o->targetValue - o->currentValue <= 10)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
|
|
|
|
}
|
|
|
|
else if (o->currentValue % 10 == 0)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
|
|
|
|
}
|
2016-03-16 20:24:41 +01:00
|
|
|
}
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
if (o->currentValue == o->targetValue)
|
2016-03-16 20:24:41 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
addHudMessage(colors.green, _("%s - Objective Complete!"), o->description);
|
|
|
|
|
|
|
|
runScriptFunction(o->description);
|
|
|
|
|
|
|
|
o->status = OS_COMPLETE;
|
|
|
|
|
|
|
|
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
|
2016-06-07 09:29:52 +02:00
|
|
|
|
|
|
|
playSound(SND_OBJECTIVE_COMPLETE);
|
2016-03-16 20:24:41 +01:00
|
|
|
}
|
2015-12-22 18:58:18 +01:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (!o->active)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
hasHidden = 1;
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-18 11:54:59 +02:00
|
|
|
|
2017-05-29 09:39:37 +02:00
|
|
|
if (completed == battle.numObjectivesTotal && !hasHidden && fireObjectivesComplete)
|
2016-04-18 11:54:59 +02:00
|
|
|
{
|
2016-05-28 12:40:56 +02:00
|
|
|
fireObjectivesComplete = 0;
|
2017-05-29 09:39:37 +02:00
|
|
|
|
|
|
|
runScriptFunction("ALL_OBJECTIVES_COMPLETE");
|
2016-04-18 11:54:59 +02:00
|
|
|
}
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 17:55:49 +01:00
|
|
|
void adjustObjectiveTargetValue(char *name, int type, int amount)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (o->active && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
|
|
|
{
|
|
|
|
o->targetValue += amount;
|
|
|
|
o->currentValue = MIN(o->currentValue, o->targetValue);
|
|
|
|
|
2016-05-17 16:55:18 +02:00
|
|
|
if (o->currentValue >= o->targetValue && o->targetValue > 0)
|
2015-11-13 17:55:49 +01:00
|
|
|
{
|
|
|
|
o->status = OS_COMPLETE;
|
2016-06-07 09:29:52 +02:00
|
|
|
|
2016-02-28 14:45:17 +01:00
|
|
|
addHudMessage(colors.green, _("%s - Objective Complete!"), o->description);
|
2016-06-07 09:29:52 +02:00
|
|
|
|
|
|
|
playSound(SND_OBJECTIVE_COMPLETE);
|
2015-11-13 17:55:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 08:08:03 +02:00
|
|
|
void updateCondition(char *name, int type)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (strlen(name))
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (o->active && o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
|
2016-04-07 13:39:53 +02:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
o->currentValue++;
|
|
|
|
|
|
|
|
if (o->currentValue == o->targetValue)
|
|
|
|
{
|
|
|
|
o->status = OS_FAILED;
|
|
|
|
addHudMessage(colors.red, _("%s - Objective Failed!"), o->description);
|
2016-06-07 09:29:52 +02:00
|
|
|
playSound(SND_OBJECTIVE_FAILED);
|
2016-05-15 09:19:26 +02:00
|
|
|
}
|
|
|
|
else if (!o->hideNumbers)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.red, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
|
|
|
|
}
|
2016-04-07 13:39:53 +02:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 10:11:36 +02:00
|
|
|
void completeAllObjectives(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
o->status = OS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 08:08:03 +02:00
|
|
|
void completeConditions(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (o->isCondition)
|
|
|
|
{
|
2016-05-23 10:18:52 +02:00
|
|
|
o->currentValue = o->targetValue;
|
|
|
|
|
2015-10-22 08:08:03 +02:00
|
|
|
o->status = OS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
void failIncompleteObjectives(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (o->status != OS_COMPLETE)
|
|
|
|
{
|
|
|
|
o->status = OS_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 12:08:47 +01:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
void activateObjectives(char *objectives)
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
2015-11-29 13:55:15 +01:00
|
|
|
char *token;
|
2015-10-29 12:08:47 +01:00
|
|
|
Objective *o;
|
2016-06-05 12:22:19 +02:00
|
|
|
int activated;
|
|
|
|
|
|
|
|
activated = 0;
|
2015-10-29 12:08:47 +01:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
token = strtok(objectives, ";");
|
|
|
|
|
|
|
|
while (token)
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
2015-11-29 13:55:15 +01:00
|
|
|
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
2016-03-16 07:54:34 +01:00
|
|
|
if (strcmp(token, o->id) == 0)
|
2015-11-29 13:55:15 +01:00
|
|
|
{
|
2016-02-28 14:45:17 +01:00
|
|
|
addHudMessage(colors.cyan, _("New Objective : %s"), o->description);
|
2017-06-21 09:41:27 +02:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
o->active = 1;
|
2015-12-31 12:31:36 +01:00
|
|
|
|
2017-06-21 09:41:27 +02:00
|
|
|
/* prevent race condition */
|
|
|
|
doObjectives();
|
|
|
|
|
2016-01-24 10:50:31 +01:00
|
|
|
if (o->isEliminateAll)
|
2015-12-31 12:31:36 +01:00
|
|
|
{
|
|
|
|
updateObjective(o->targetName, o->targetType);
|
|
|
|
}
|
2016-06-05 12:22:19 +02:00
|
|
|
|
|
|
|
activated = 1;
|
2015-11-29 13:55:15 +01:00
|
|
|
}
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
token = strtok(NULL, ";");
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
2016-06-05 12:22:19 +02:00
|
|
|
|
|
|
|
if (activated)
|
|
|
|
{
|
|
|
|
playSound(SND_NEW_OBJECTIVE);
|
|
|
|
}
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
2016-03-17 09:11:52 +01:00
|
|
|
|
|
|
|
void loadObjectives(cJSON *node)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
o = malloc(sizeof(Objective));
|
|
|
|
memset(o, 0, sizeof(Objective));
|
|
|
|
battle.objectiveTail->next = o;
|
|
|
|
battle.objectiveTail = o;
|
|
|
|
|
|
|
|
STRNCPY(o->id, 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);
|
|
|
|
o->targetValue = cJSON_GetObjectItem(node, "targetValue")->valueint;
|
|
|
|
o->targetType = lookup(cJSON_GetObjectItem(node, "targetType")->valuestring);
|
|
|
|
o->active = getJSONValue(node, "active", 1);
|
|
|
|
o->isCondition = getJSONValue(node, "isCondition", 0);
|
|
|
|
o->isEliminateAll = getJSONValue(node, "isEliminateAll", 0);
|
2016-04-07 13:39:53 +02:00
|
|
|
o->hideNumbers = getJSONValue(node, "hideNumbers", o->isCondition);
|
2016-03-17 09:11:52 +01:00
|
|
|
|
|
|
|
if (o->isEliminateAll)
|
|
|
|
{
|
|
|
|
o->targetValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
2016-05-22 13:08:48 +02:00
|
|
|
|
|
|
|
fireObjectivesComplete = 1;
|
2016-03-17 09:11:52 +01:00
|
|
|
}
|
2016-08-20 12:42:10 +02:00
|
|
|
|
|
|
|
void addEpicLivesObjective(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
char id[MAX_DESCRIPTION_LENGTH];
|
|
|
|
|
|
|
|
o = malloc(sizeof(Objective));
|
|
|
|
memset(o, 0, sizeof(Objective));
|
|
|
|
battle.objectiveTail->next = o;
|
|
|
|
battle.objectiveTail = o;
|
|
|
|
|
|
|
|
sprintf(id, _("Do not lose more than %d pilots"), battle.epicLives);
|
|
|
|
|
|
|
|
STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH);
|
|
|
|
STRNCPY(o->description, id, MAX_DESCRIPTION_LENGTH);
|
|
|
|
STRNCPY(o->targetName, "PLAYER", MAX_NAME_LENGTH);
|
|
|
|
o->targetValue = battle.epicLives;
|
|
|
|
o->targetType = TT_DESTROY;
|
|
|
|
o->active = 1;
|
|
|
|
o->isCondition = 1;
|
|
|
|
}
|
2016-08-28 19:48:55 +02:00
|
|
|
|
|
|
|
void addEpicKillsObjective(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
char id[MAX_DESCRIPTION_LENGTH];
|
|
|
|
|
|
|
|
o = malloc(sizeof(Objective));
|
|
|
|
memset(o, 0, sizeof(Objective));
|
|
|
|
battle.objectiveTail->next = o;
|
|
|
|
battle.objectiveTail = o;
|
|
|
|
|
|
|
|
sprintf(id, _("Destroy at least %d enemy fighters"), battle.epicKills);
|
|
|
|
|
|
|
|
STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH);
|
|
|
|
STRNCPY(o->description, id, MAX_DESCRIPTION_LENGTH);
|
|
|
|
STRNCPY(o->targetName, "EPIC_PLAYER_KILLS", MAX_NAME_LENGTH);
|
|
|
|
o->targetValue = battle.epicKills;
|
|
|
|
o->targetType = TT_DESTROY;
|
|
|
|
o->active = 1;
|
|
|
|
}
|