2015-10-26 18:27:43 +01:00
|
|
|
/*
|
2018-04-29 11:01:09 +02:00
|
|
|
Copyright (C) 2015-2018 Parallel Realities
|
2015-10-26 18:27:43 +01: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 "waypoints.h"
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
static void think(void);
|
|
|
|
static int teamMatesClose(void);
|
2015-11-28 16:07:12 +01:00
|
|
|
static int isCurrentObjective(void);
|
2016-04-04 12:23:32 +02:00
|
|
|
void activateNextWaypoint(void);
|
2015-10-28 20:12:58 +01:00
|
|
|
|
|
|
|
static int waypointId;
|
2016-04-04 12:23:32 +02:00
|
|
|
static int currentWaypointId;
|
2015-10-28 20:12:58 +01:00
|
|
|
|
|
|
|
void resetWaypoints(void)
|
|
|
|
{
|
|
|
|
waypointId = 1;
|
2016-04-04 12:23:32 +02:00
|
|
|
currentWaypointId = 0;
|
2015-10-28 20:12:58 +01:00
|
|
|
}
|
2015-10-26 18:27:43 +01:00
|
|
|
|
|
|
|
Entity *spawnWaypoint(void)
|
|
|
|
{
|
2015-10-27 08:24:17 +01:00
|
|
|
Entity *waypoint = spawnEntity();
|
2015-10-26 18:27:43 +01:00
|
|
|
|
2016-04-04 12:23:32 +02:00
|
|
|
sprintf(waypoint->name, "Waypoint #%d", waypointId);
|
|
|
|
waypoint->id = waypointId;
|
2015-10-26 20:16:12 +01:00
|
|
|
waypoint->type = ET_WAYPOINT;
|
2015-10-28 20:12:58 +01:00
|
|
|
waypoint->active = 0;
|
2015-10-26 18:27:43 +01:00
|
|
|
waypoint->health = waypoint->maxHealth = FPS;
|
2018-12-06 09:37:19 +01:00
|
|
|
waypoint->texture = getAtlasImage("gfx/entities/waypoint.png");
|
2016-05-15 09:19:26 +02:00
|
|
|
waypoint->flags = EF_NO_MT_BOX+EF_MISSION_TARGET+EF_NO_HEALTH_BAR;
|
2015-10-27 08:24:17 +01:00
|
|
|
waypoint->action = think;
|
2015-10-26 18:27:43 +01:00
|
|
|
|
2018-12-06 09:37:19 +01:00
|
|
|
waypoint->w = waypoint->texture->rect.w;
|
|
|
|
waypoint->h = waypoint->texture->rect.h;
|
2016-04-01 15:20:47 +02:00
|
|
|
|
2016-04-04 12:23:32 +02:00
|
|
|
waypointId++;
|
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
return waypoint;
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
static void think(void)
|
2015-10-26 18:27:43 +01:00
|
|
|
{
|
2016-03-12 13:11:56 +01:00
|
|
|
self->angle += 0.25;
|
2015-10-27 08:24:17 +01:00
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
if (self->angle >= 360)
|
|
|
|
{
|
2015-10-28 20:12:58 +01:00
|
|
|
self->angle -= 360;
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2015-10-27 08:24:17 +01:00
|
|
|
|
2016-03-12 13:11:56 +01:00
|
|
|
if (--self->aiActionTime <= 0)
|
2015-10-27 08:24:17 +01:00
|
|
|
{
|
2016-03-12 13:11:56 +01:00
|
|
|
self->aiActionTime = 0;
|
2015-10-28 20:12:58 +01:00
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (self->health && player->alive == ALIVE_ALIVE && getDistance(player->x, player->y, self->x, self->y) <= 128 && isCurrentObjective() && teamMatesClose())
|
2016-03-12 13:11:56 +01:00
|
|
|
{
|
|
|
|
self->health = 0;
|
|
|
|
|
|
|
|
updateObjective("Waypoint", TT_WAYPOINT);
|
|
|
|
|
|
|
|
runScriptFunction(self->name);
|
|
|
|
|
2016-04-04 12:23:32 +02:00
|
|
|
if (battle.waypointAutoAdvance)
|
|
|
|
{
|
|
|
|
activateNextWaypoint();
|
|
|
|
}
|
2016-03-12 13:11:56 +01:00
|
|
|
|
|
|
|
battle.stats[STAT_WAYPOINTS_VISITED]++;
|
2016-06-07 09:29:52 +02:00
|
|
|
|
|
|
|
playSound(SND_WAYPOINT);
|
2016-03-12 13:11:56 +01:00
|
|
|
}
|
2015-10-27 08:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 16:07:12 +01:00
|
|
|
static int isCurrentObjective(void)
|
|
|
|
{
|
|
|
|
int numActiveObjectives = battle.numObjectivesTotal - battle.numObjectivesComplete;
|
|
|
|
|
|
|
|
if (numActiveObjectives > 1)
|
|
|
|
{
|
2016-02-28 14:45:17 +01:00
|
|
|
addHudMessage(colors.cyan, _("Cannot activate waypoint - outstanding objectives not yet complete"));
|
2016-03-12 13:11:56 +01:00
|
|
|
self->aiActionTime = FPS;
|
2015-11-28 16:07:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (game.currentMission->challengeData.isChallenge && game.currentMission->challengeData.clearWaypointEnemies && battle.numEnemies > 0)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.cyan, _("Cannot activate waypoint - eliminate enemies first"));
|
|
|
|
self->aiActionTime = FPS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-28 16:07:12 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
static int teamMatesClose(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
|
2016-05-20 10:52:23 +02:00
|
|
|
if (player->side != SIDE_PANDORAN)
|
2015-10-27 08:24:17 +01:00
|
|
|
{
|
2016-05-20 10:52:23 +02:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
2015-10-27 08:24:17 +01:00
|
|
|
{
|
2016-05-20 10:52:23 +02:00
|
|
|
if (e->active && e->type == ET_FIGHTER && e->side == SIDE_ALLIES)
|
2015-10-27 08:24:17 +01:00
|
|
|
{
|
2016-05-20 10:52:23 +02:00
|
|
|
if (getDistance(player->x, player->y, e->x, e->y) > 350)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.cyan, _("Cannot activate waypoint - team mates too far away"));
|
|
|
|
self->aiActionTime = FPS;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-27 08:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2015-10-26 18:27:43 +01:00
|
|
|
}
|
2015-10-28 20:12:58 +01:00
|
|
|
|
2016-04-04 12:23:32 +02:00
|
|
|
void activateNextWaypoint(void)
|
2015-10-28 20:12:58 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
Entity *nextWaypoint = NULL;
|
|
|
|
|
2016-04-04 12:23:32 +02:00
|
|
|
currentWaypointId++;
|
|
|
|
|
2015-10-28 20:12:58 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
2016-04-04 12:23:32 +02:00
|
|
|
if (e->type == ET_WAYPOINT && e->id == currentWaypointId)
|
2015-10-28 20:12:58 +01:00
|
|
|
{
|
|
|
|
nextWaypoint = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextWaypoint != NULL)
|
|
|
|
{
|
|
|
|
nextWaypoint->active = 1;
|
2016-04-04 12:23:32 +02:00
|
|
|
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activating %s", nextWaypoint->name);
|
2015-10-28 20:12:58 +01:00
|
|
|
}
|
|
|
|
}
|