2018-01-21 13:57:01 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2018 Parallel Realities
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
static int isMissingHeartCell(char *targetName);
|
|
|
|
static int countTargetsInWorld(char *targetName);
|
|
|
|
|
|
|
|
static int missingHeartCell;
|
|
|
|
static int isEliminateAllEnemies;
|
|
|
|
|
|
|
|
void initObjectives(void)
|
|
|
|
{
|
|
|
|
int totalTargets;
|
|
|
|
Objective *o;
|
|
|
|
|
2018-02-21 23:04:01 +01:00
|
|
|
world.isReturnVisit = world.currentStatus == MS_PARTIAL || world.currentStatus == MS_MISSING_HEART_CELL;
|
|
|
|
|
2018-01-21 13:57:01 +01:00
|
|
|
missingHeartCell = world.currentStatus == MS_MISSING_HEART_CELL;
|
2018-02-18 12:53:10 +01:00
|
|
|
|
2018-02-21 23:04:01 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "world.isReturnVisit = %d", world.isReturnVisit);
|
2018-02-18 12:53:10 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "missingHeartCell = %d", missingHeartCell);
|
2018-01-21 13:57:01 +01:00
|
|
|
|
|
|
|
for (o = world.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
totalTargets = countTargetsInWorld(o->targetName);
|
|
|
|
|
|
|
|
if (strcmp(o->targetName, "ENEMY") == 0)
|
|
|
|
{
|
|
|
|
isEliminateAllEnemies = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o->totalValue == 0)
|
|
|
|
{
|
|
|
|
o->totalValue = totalTargets;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o->targetValue == 0)
|
|
|
|
{
|
|
|
|
if (strcmp(o->targetName, "KEY") == 0)
|
|
|
|
{
|
|
|
|
o->targetValue = totalTargets;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
o->targetValue = (int) (totalTargets * AUTO_THRESHOLD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 23:04:01 +01:00
|
|
|
if (o->required && world.isReturnVisit)
|
2018-01-21 13:57:01 +01:00
|
|
|
{
|
|
|
|
o->targetValue = o->totalValue;
|
|
|
|
o->required = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int countTargetsInWorld(char *targetName)
|
|
|
|
{
|
|
|
|
int num, countMIAs, countEnemies, countKeys;
|
|
|
|
Entity *e;
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
countMIAs = strcmp(targetName, "MIA") == 0;
|
|
|
|
countEnemies = strcmp(targetName, "ENEMY") == 0;
|
|
|
|
countKeys = strcmp(targetName, "KEY") == 0;
|
|
|
|
|
|
|
|
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (strcmp(targetName, e->name) == 0)
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (countMIAs && e->type == ET_MIA)
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (countEnemies && e->type == ET_ENEMY)
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (countKeys && e->type == ET_KEY)
|
|
|
|
{
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateObjective(char *targetName)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
if (missingHeartCell && !isMissingHeartCell(targetName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (o = world.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (strcmp(o->targetName, targetName) == 0)
|
|
|
|
{
|
|
|
|
o->currentValue++;
|
|
|
|
|
|
|
|
if (strcmp(o->targetName, "KEY") != 0)
|
|
|
|
{
|
|
|
|
if (o->currentValue == o->targetValue)
|
|
|
|
{
|
2018-01-28 17:33:37 +01:00
|
|
|
setGameplayMessage(MSG_OBJECTIVE, _("%s - Objective Complete!"), o->description);
|
2018-01-21 13:57:01 +01:00
|
|
|
}
|
|
|
|
else if (o->currentValue < o->targetValue)
|
|
|
|
{
|
|
|
|
if (strcmp(o->targetName, "ENEMY") != 0)
|
|
|
|
{
|
|
|
|
setGameplayMessage(MSG_PROGRESS, "%s - (%d / %d)", o->description, o->currentValue, o->targetValue);
|
|
|
|
}
|
|
|
|
else if (o->targetValue - o->currentValue < 10 || o->currentValue % 5 == 0)
|
|
|
|
{
|
|
|
|
setGameplayMessage(MSG_PROGRESS, "%s - (%d / %d)", o->description, o->currentValue, o->targetValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
world.allObjectivesComplete = 1;
|
|
|
|
|
|
|
|
for (o = world.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (o->currentValue < o->targetValue)
|
|
|
|
{
|
2018-02-21 23:04:01 +01:00
|
|
|
if (o->required || world.isReturnVisit)
|
2018-01-21 13:57:01 +01:00
|
|
|
{
|
|
|
|
world.allObjectivesComplete = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.allObjectivesComplete)
|
|
|
|
{
|
2018-01-28 17:33:37 +01:00
|
|
|
setGameplayMessage(MSG_OBJECTIVE, _("Mission Complete!"));
|
2018-01-21 13:57:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int isMissingHeartCell(char *targetName)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
|
|
|
|
if (targetName == NULL || strcmp(targetName, "HEART_CELL") == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->alive == ALIVE_ALIVE)
|
|
|
|
{
|
2018-01-24 20:04:36 +01:00
|
|
|
if (e->type == ET_HEART_CELL)
|
2018-01-21 13:57:01 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2018-02-17 17:53:18 +01:00
|
|
|
|
|
|
|
void destroyObjectives(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
|
|
|
|
|
|
|
while (world.objectiveHead.next)
|
|
|
|
{
|
|
|
|
o = world.objectiveHead.next;
|
|
|
|
|
|
|
|
world.objectiveHead.next = o->next;
|
|
|
|
|
|
|
|
free(o);
|
|
|
|
}
|
|
|
|
}
|