tbftss/src/battle/objectives.c

225 lines
4.9 KiB
C
Raw Normal View History

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"
void doObjectives(void)
{
int objectiveFailed;
2015-10-29 12:08:47 +01:00
int numHiddenObjectives;
2015-10-20 13:51:49 +02:00
Objective *o;
battle.numObjectivesComplete = battle.numObjectivesTotal = 0;
objectiveFailed = 0;
2015-10-29 12:08:47 +01:00
numHiddenObjectives = 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-29 12:08:47 +01:00
if (!o->isCondition)
{
battle.numObjectivesTotal++;
}
}
else
{
numHiddenObjectives++;
}
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:
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
{
if (!battle.manualComplete && numHiddenObjectives == 0 && battle.numObjectivesTotal > 0 && battle.numObjectivesComplete == battle.numObjectivesTotal)
2015-10-21 20:21:45 +02:00
{
2015-10-26 09:10:13 +01:00
completeMission();
2015-10-21 20:21:45 +02:00
}
2015-10-20 13:51:49 +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
}
}
void updateObjective(char *name, int type)
2015-10-20 13:51:49 +02:00
{
Objective *o;
int completed;
completed = battle.numObjectivesComplete;
2015-10-20 13:51:49 +02:00
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{
if (o->active)
2015-10-20 13:51:49 +02:00
{
if (!o->isEliminateAll && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
2015-10-20 13:51:49 +02:00
{
o->currentValue++;
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);
}
if (o->currentValue == o->targetValue)
{
completed++;
o->status = OS_COMPLETE;
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
runScriptFunction(o->description);
runScriptFunction("OBJECTIVES_COMPLETE %d", completed);
if (completed == battle.numObjectivesTotal)
{
runScriptFunction("ALL_OBJECTIVES_COMPLETE");
}
}
2015-10-20 13:51:49 +02:00
}
2016-01-24 10:50:31 +01:00
if (o->isEliminateAll && o->status != OS_COMPLETE && battle.stats[STAT_ENEMIES_KILLED] == battle.numInitialEnemies)
2015-10-20 13:51:49 +02:00
{
2015-10-21 20:21:45 +02:00
o->status = OS_COMPLETE;
2015-10-21 20:21:45 +02:00
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
2015-11-29 13:55:15 +01:00
o->currentValue = o->targetValue;
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
2015-10-21 20:21:45 +02: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);
if (o->currentValue >= o->targetValue)
{
o->status = OS_COMPLETE;
addHudMessage(colors.green, "%s - Objective Complete!", o->description);
}
}
}
}
void updateCondition(char *name, int type)
2015-10-21 20:21:45 +02:00
{
Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{
2015-10-29 12:08:47 +01:00
if (o->active && o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
2015-10-21 20:21:45 +02:00
{
o->currentValue++;
if (o->currentValue == o->targetValue)
{
o->status = OS_FAILED;
addHudMessage(colors.red, "%s - Objective Failed!", o->description);
2015-10-20 13:51:49 +02:00
}
}
}
}
void completeConditions(void)
{
Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{
if (o->isCondition)
{
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;
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
{
if (strcmp(token, o->description) == 0)
2015-11-29 13:55:15 +01:00
{
addHudMessage(colors.cyan, "New Objective : %s", o->description);
o->active = 1;
2016-01-24 10:50:31 +01:00
if (o->isEliminateAll)
{
updateObjective(o->targetName, o->targetType);
}
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
}
}