2015-10-26 18:27:43 +01:00
|
|
|
/*
|
2019-01-01 17:14:11 +01:00
|
|
|
Copyright (C) 2015-2019 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 "entities.h"
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
static void drawEntity(Entity *e);
|
2015-10-29 11:14:21 +01:00
|
|
|
static void doEntity(void);
|
2015-12-07 20:19:41 +01:00
|
|
|
static void alignComponents(void);
|
2016-05-15 09:19:26 +02:00
|
|
|
static void activateEpicFighters(int side);
|
2016-02-21 09:54:14 +01:00
|
|
|
static void restrictToBattleArea(Entity *e);
|
2015-11-13 23:08:59 +01:00
|
|
|
static void drawTargetRects(Entity *e);
|
2016-04-17 12:00:08 +02:00
|
|
|
static void drawHealthBar(Entity *e);
|
2015-11-09 23:48:59 +01:00
|
|
|
static int drawComparator(const void *a, const void *b);
|
2016-01-24 10:49:50 +01:00
|
|
|
static void notifyNewArrivals(void);
|
2016-04-09 14:22:20 +02:00
|
|
|
static int isComponent(Entity *e);
|
2015-10-27 08:24:17 +01:00
|
|
|
|
2016-03-07 23:50:41 +01:00
|
|
|
static Entity deadHead;
|
|
|
|
static Entity *deadTail;
|
|
|
|
static int disabledGlow;
|
|
|
|
static int disabledGlowDir;
|
|
|
|
|
2015-12-10 11:15:27 +01:00
|
|
|
void initEntities(void)
|
|
|
|
{
|
|
|
|
memset(&deadHead, 0, sizeof(Entity));
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-10 11:15:27 +01:00
|
|
|
deadTail = &deadHead;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-14 17:34:11 +01:00
|
|
|
disabledGlow = DISABLED_GLOW_MAX;
|
|
|
|
disabledGlowDir = -DISABLED_GLOW_SPEED;
|
2015-12-10 11:15:27 +01:00
|
|
|
}
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
Entity *spawnEntity(void)
|
|
|
|
{
|
|
|
|
Entity *e = malloc(sizeof(Entity));
|
|
|
|
memset(e, 0, sizeof(Entity));
|
2015-10-28 20:12:58 +01:00
|
|
|
e->active = 1;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
battle.entityTail->next = e;
|
|
|
|
battle.entityTail = e;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
return e;
|
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
void doEntities(void)
|
|
|
|
{
|
2015-10-29 17:18:41 +01:00
|
|
|
int numAllies, numEnemies;
|
2015-11-01 10:25:10 +01:00
|
|
|
int numActiveAllies, numActiveEnemies;
|
2016-03-27 09:55:25 +02:00
|
|
|
int numSpawnedEnemies;
|
2015-10-26 18:27:43 +01:00
|
|
|
Entity *e, *prev;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
prev = &battle.entityHead;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
battle.hasThreats = numAllies = numEnemies = numActiveAllies = numActiveEnemies = numSpawnedEnemies = 0;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-18 11:12:37 +01:00
|
|
|
if (dev.playerImmortal)
|
|
|
|
{
|
|
|
|
player->health = player->maxHealth;
|
|
|
|
player->shield = player->maxShield;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
2016-02-21 10:41:00 +01:00
|
|
|
removeFromQuadtree(e, &battle.quadtree);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-18 11:12:37 +01:00
|
|
|
if (dev.allImmortal)
|
|
|
|
{
|
|
|
|
e->health = e->maxHealth;
|
|
|
|
e->shield = e->maxShield;
|
|
|
|
}
|
2016-05-15 18:28:17 +02:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
if (e->active)
|
2015-10-27 08:24:17 +01:00
|
|
|
{
|
2015-10-29 12:08:47 +01:00
|
|
|
self = e;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
e->reload = MAX(e->reload - 1, 0);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-14 15:04:48 +01:00
|
|
|
if (e->shieldRechargeRate)
|
|
|
|
{
|
|
|
|
if (e->shield >= 0)
|
|
|
|
{
|
|
|
|
if (--e->shieldRecharge <= 0)
|
|
|
|
{
|
|
|
|
e->shield = MIN(e->shield + 1, e->maxShield);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-14 15:04:48 +01:00
|
|
|
e->shieldRecharge = e->shieldRechargeRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->shield++;
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
e->armourHit = MAX(e->armourHit - 25, 0);
|
|
|
|
e->shieldHit = MAX(e->shieldHit - 5, 0);
|
|
|
|
e->systemHit = MAX(e->systemHit - 25, 0);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-20 16:13:41 +01:00
|
|
|
e->aiDamageTimer = MAX(e->aiDamageTimer - 1, 0);
|
|
|
|
if (!e->aiDamageTimer)
|
|
|
|
{
|
|
|
|
e->aiDamagePerSec = 0;
|
|
|
|
e->aiFlags &= ~AIF_EVADE;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
switch (e->type)
|
2015-10-29 11:14:21 +01:00
|
|
|
{
|
2015-10-29 12:08:47 +01:00
|
|
|
case ET_FIGHTER:
|
|
|
|
doFighter();
|
|
|
|
break;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-12 18:12:25 +01:00
|
|
|
case ET_CAPITAL_SHIP:
|
|
|
|
doCapitalShip();
|
|
|
|
break;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
default:
|
|
|
|
doEntity();
|
|
|
|
break;
|
2015-10-29 11:14:21 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
|
|
|
if (e->alive == ALIVE_ALIVE || e->alive == ALIVE_DYING)
|
2015-11-20 23:52:48 +01:00
|
|
|
{
|
|
|
|
if (e->action != NULL)
|
|
|
|
{
|
2015-12-18 11:12:37 +01:00
|
|
|
if (dev.noEntityActions)
|
|
|
|
{
|
|
|
|
e->thinkTime = 2;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-20 23:52:48 +01:00
|
|
|
if (--e->thinkTime <= 0)
|
|
|
|
{
|
|
|
|
e->thinkTime = 0;
|
|
|
|
e->action();
|
|
|
|
}
|
|
|
|
}
|
2016-04-15 14:08:30 +02:00
|
|
|
|
2015-11-20 23:52:48 +01:00
|
|
|
doRope(e);
|
2016-04-15 14:08:30 +02:00
|
|
|
|
2016-02-21 09:54:14 +01:00
|
|
|
restrictToBattleArea(e);
|
2016-04-15 14:08:30 +02:00
|
|
|
|
2015-12-10 12:46:57 +01:00
|
|
|
if (!e->speed)
|
2015-11-29 14:23:27 +01:00
|
|
|
{
|
|
|
|
e->dx = e->dy = 0;
|
|
|
|
}
|
2016-04-15 14:08:30 +02:00
|
|
|
|
2015-11-20 23:52:48 +01:00
|
|
|
e->x += e->dx;
|
|
|
|
e->y += e->dy;
|
2016-04-15 14:08:30 +02:00
|
|
|
|
|
|
|
addToQuadtree(e, &battle.quadtree);
|
2015-11-20 23:52:48 +01:00
|
|
|
}
|
|
|
|
else
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
|
|
|
if (e == battle.entityTail)
|
|
|
|
{
|
|
|
|
battle.entityTail = prev;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
if (e == battle.missionTarget)
|
|
|
|
{
|
|
|
|
battle.missionTarget = NULL;
|
|
|
|
}
|
2016-05-19 09:52:34 +02:00
|
|
|
|
|
|
|
if (e->killedBy == player && battle.hasSuspicionLevel)
|
|
|
|
{
|
2017-06-16 19:34:44 +02:00
|
|
|
if (e->aiFlags & (AIF_AVOIDS_COMBAT|AIF_DEFENSIVE))
|
|
|
|
{
|
|
|
|
battle.suspicionLevel -= (MAX_SUSPICION_LEVEL * 0.5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
battle.suspicionLevel -= (MAX_SUSPICION_LEVEL * 0.12);
|
|
|
|
}
|
2016-05-19 09:52:34 +02:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
if (e == player)
|
|
|
|
{
|
2016-02-28 14:02:57 +01:00
|
|
|
battle.playerSelect = battle.isEpic;
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-15 12:31:30 +01:00
|
|
|
cutRope(e);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
prev->next = e->next;
|
2016-05-29 10:36:10 +02:00
|
|
|
|
2015-12-10 11:15:27 +01:00
|
|
|
e->next = NULL;
|
2016-05-29 10:36:10 +02:00
|
|
|
|
2016-05-30 12:59:31 +02:00
|
|
|
deadTail->next = e;
|
|
|
|
deadTail = e;
|
|
|
|
|
|
|
|
/* actually just creates another fighter in this one's place */
|
|
|
|
if (e->type == ET_FIGHTER && battle.isEpic && e->side != player->side && battle.unlimitedEnemies)
|
2016-05-29 10:36:10 +02:00
|
|
|
{
|
|
|
|
resetFighter(e);
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 12:08:47 +01:00
|
|
|
e = prev;
|
|
|
|
}
|
2015-10-29 11:14:21 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-10 12:11:32 +01:00
|
|
|
if (e->type == ET_FIGHTER || e->type == ET_CAPITAL_SHIP)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (e->side == player->side)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
|
|
|
numAllies++;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-21 17:03:30 +01:00
|
|
|
if (e->health > 0 && e->active)
|
2015-12-10 12:11:32 +01:00
|
|
|
{
|
|
|
|
numActiveAllies++;
|
|
|
|
}
|
2015-11-01 10:25:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
numEnemies++;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-21 17:03:30 +01:00
|
|
|
if (e->health > 0 && e->active)
|
2015-12-10 12:11:32 +01:00
|
|
|
{
|
|
|
|
numActiveEnemies++;
|
2016-03-27 09:55:25 +02:00
|
|
|
|
|
|
|
if (e->spawned)
|
|
|
|
{
|
|
|
|
numSpawnedEnemies++;
|
|
|
|
}
|
2016-05-15 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 09:39:11 +02:00
|
|
|
if (!(e->flags & EF_DISABLED) || battle.isEpic)
|
2016-05-15 18:38:44 +02:00
|
|
|
{
|
|
|
|
battle.hasThreats = 1;
|
2016-05-15 09:19:26 +02:00
|
|
|
}
|
2015-11-01 10:25:10 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-10-29 11:14:21 +01:00
|
|
|
prev = e;
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
battle.numAllies = (battle.isEpic) ? numAllies : numActiveAllies;
|
|
|
|
battle.numEnemies = (battle.isEpic) ? numEnemies : numActiveEnemies;
|
2016-05-18 10:48:18 +02:00
|
|
|
|
2016-06-02 10:49:49 +02:00
|
|
|
if (battle.status == MS_IN_PROGRESS && battle.stats[STAT_TIME] % (FPS * 30) == 0)
|
2016-05-18 10:48:18 +02:00
|
|
|
{
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "numEnemies=%d, numActiveEnemies=%d, hasThreats=%d", numEnemies, numActiveEnemies, battle.hasThreats);
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
if (battle.isEpic && battle.stats[STAT_TIME] % FPS == 0)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (numActiveAllies < battle.epicFighterLimit)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
activateEpicFighters(SIDE_ALLIES);
|
2015-11-01 10:25:10 +01:00
|
|
|
}
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
numActiveEnemies -= numSpawnedEnemies;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (numActiveEnemies < battle.epicFighterLimit)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
activateEpicFighters(SIDE_NONE);
|
2015-11-01 10:25:10 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
alignComponents();
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-14 17:34:11 +01:00
|
|
|
disabledGlow = MAX(DISABLED_GLOW_MIN, MIN(disabledGlow + disabledGlowDir, DISABLED_GLOW_MAX));
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-14 17:34:11 +01:00
|
|
|
if (disabledGlow <= DISABLED_GLOW_MIN)
|
|
|
|
{
|
|
|
|
disabledGlowDir = DISABLED_GLOW_SPEED;
|
|
|
|
}
|
|
|
|
else if (disabledGlow >= DISABLED_GLOW_MAX)
|
|
|
|
{
|
|
|
|
disabledGlowDir = -DISABLED_GLOW_SPEED;
|
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
|
|
|
|
2016-02-21 09:54:14 +01:00
|
|
|
static void restrictToBattleArea(Entity *e)
|
2015-11-02 19:07:26 +01:00
|
|
|
{
|
|
|
|
float force;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-21 08:48:22 +01:00
|
|
|
if (e->x <= BATTLE_AREA_EDGE)
|
2015-11-02 19:07:26 +01:00
|
|
|
{
|
2016-02-21 08:48:22 +01:00
|
|
|
force = BATTLE_AREA_EDGE - e->x;
|
2015-11-02 19:07:26 +01:00
|
|
|
e->dx += force * 0.001;
|
|
|
|
e->dx *= 0.95;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-21 08:48:22 +01:00
|
|
|
if (e->y <= BATTLE_AREA_EDGE)
|
2015-11-02 19:07:26 +01:00
|
|
|
{
|
2016-02-21 08:48:22 +01:00
|
|
|
force = BATTLE_AREA_EDGE - e->y;
|
2015-11-02 19:07:26 +01:00
|
|
|
e->dy += force * 0.001;
|
|
|
|
e->dy *= 0.95;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-21 08:48:22 +01:00
|
|
|
if (e->x >= BATTLE_AREA_WIDTH - BATTLE_AREA_EDGE)
|
2015-11-02 19:07:26 +01:00
|
|
|
{
|
2016-02-21 08:48:22 +01:00
|
|
|
force = e->x - (BATTLE_AREA_WIDTH - BATTLE_AREA_EDGE);
|
2015-11-02 19:07:26 +01:00
|
|
|
e->dx -= force * 0.001;
|
|
|
|
e->dx *= 0.95;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-21 08:48:22 +01:00
|
|
|
if (e->y >= BATTLE_AREA_HEIGHT - BATTLE_AREA_EDGE)
|
2015-11-02 19:07:26 +01:00
|
|
|
{
|
2016-02-21 08:48:22 +01:00
|
|
|
force = e->y - (BATTLE_AREA_HEIGHT - BATTLE_AREA_EDGE);
|
2015-11-02 19:07:26 +01:00
|
|
|
e->dy -= force * 0.001;
|
|
|
|
e->dy *= 0.95;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 11:14:21 +01:00
|
|
|
static void doEntity(void)
|
2015-10-26 20:16:12 +01:00
|
|
|
{
|
2015-12-07 20:19:41 +01:00
|
|
|
if (self->die)
|
2015-10-26 20:16:12 +01:00
|
|
|
{
|
2015-12-12 18:12:25 +01:00
|
|
|
if (self->health <= 0 && self->alive == ALIVE_ALIVE)
|
2015-12-07 20:19:41 +01:00
|
|
|
{
|
|
|
|
self->health = 0;
|
|
|
|
self->alive = ALIVE_DYING;
|
|
|
|
self->die();
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
if (self == battle.missionTarget)
|
|
|
|
{
|
|
|
|
battle.missionTarget = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 18:27:43 +01:00
|
|
|
}
|
2015-12-07 20:19:41 +01:00
|
|
|
else
|
2015-11-18 12:28:19 +01:00
|
|
|
{
|
2015-12-07 20:19:41 +01:00
|
|
|
if (self->alive == ALIVE_DYING)
|
|
|
|
{
|
|
|
|
self->alive = ALIVE_DEAD;
|
|
|
|
}
|
|
|
|
else if (self->health <= 0)
|
|
|
|
{
|
|
|
|
self->alive = ALIVE_DYING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alignComponents(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
float x, y;
|
|
|
|
float c, s;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
2016-04-09 14:22:20 +02:00
|
|
|
if (isComponent(e))
|
2015-12-07 20:19:41 +01:00
|
|
|
{
|
2016-04-15 14:08:30 +02:00
|
|
|
removeFromQuadtree(e, &battle.quadtree);
|
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
s = sin(TO_RAIDANS(e->owner->angle));
|
|
|
|
c = cos(TO_RAIDANS(e->owner->angle));
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
x = (e->offsetX * c) - (e->offsetY * s);
|
|
|
|
y = (e->offsetX * s) + (e->offsetY * c);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
x += e->owner->x;
|
|
|
|
y += e->owner->y;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
e->x = x;
|
|
|
|
e->y = y;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-10 12:46:57 +01:00
|
|
|
if (e->flags & EF_STATIC)
|
2015-12-08 23:42:31 +01:00
|
|
|
{
|
|
|
|
e->angle = e->owner->angle;
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-03-06 18:13:57 +01:00
|
|
|
addToQuadtree(e, &battle.quadtree);
|
2015-12-07 20:19:41 +01:00
|
|
|
}
|
2015-11-18 12:28:19 +01:00
|
|
|
}
|
2015-10-26 18:27:43 +01:00
|
|
|
}
|
|
|
|
|
2016-04-09 14:22:20 +02:00
|
|
|
static int isComponent(Entity *e)
|
2016-03-06 18:13:57 +01:00
|
|
|
{
|
2016-04-09 14:22:20 +02:00
|
|
|
return (e->type == ET_COMPONENT || e->type == ET_COMPONENT_GUN || e->type == ET_COMPONENT_ENGINE);
|
2016-03-06 18:13:57 +01:00
|
|
|
}
|
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
void drawEntities(void)
|
|
|
|
{
|
2015-11-02 14:19:31 +01:00
|
|
|
int i;
|
2016-04-09 19:13:59 +02:00
|
|
|
Entity *e, **candidates;
|
|
|
|
|
2018-12-14 09:00:16 +01:00
|
|
|
candidates = getAllEntsWithin(battle.camera.x, battle.camera.y, app.winWidth, app.winHeight, NULL);
|
2016-04-02 17:37:49 +02:00
|
|
|
|
2016-04-09 19:13:59 +02:00
|
|
|
/* counting entities to draw */
|
|
|
|
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) {};
|
|
|
|
|
|
|
|
qsort(candidates, i, sizeof(Entity*), drawComparator);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-04-09 19:13:59 +02:00
|
|
|
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
2015-10-26 18:27:43 +01:00
|
|
|
{
|
2016-03-08 15:28:11 +01:00
|
|
|
self = e;
|
|
|
|
|
|
|
|
if (e->draw)
|
|
|
|
{
|
|
|
|
e->draw();
|
|
|
|
}
|
|
|
|
else
|
2015-10-26 20:16:12 +01:00
|
|
|
{
|
2015-12-07 20:19:41 +01:00
|
|
|
drawEntity(e);
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2016-04-17 12:00:08 +02:00
|
|
|
|
|
|
|
drawHealthBar(e);
|
|
|
|
|
2015-11-13 23:08:59 +01:00
|
|
|
drawTargetRects(e);
|
2016-04-17 12:00:08 +02:00
|
|
|
|
2015-11-15 00:19:17 +01:00
|
|
|
drawRope(e);
|
2015-10-26 18:27:43 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
|
|
|
|
static void drawEntity(Entity *e)
|
|
|
|
{
|
2018-12-06 17:52:13 +01:00
|
|
|
setAtlasColor(255, 255, 255, 255);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
if (e->armourHit > 0)
|
|
|
|
{
|
2018-12-06 17:52:13 +01:00
|
|
|
setAtlasColor(255, 255 - e->armourHit, 255 - e->armourHit, 255);
|
2015-12-07 20:19:41 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
if (e->systemHit > 0)
|
|
|
|
{
|
2018-12-06 17:52:13 +01:00
|
|
|
setAtlasColor(255 - e->systemHit, 255, 255, 255);
|
2015-12-07 20:19:41 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-02-14 17:34:11 +01:00
|
|
|
if (e->flags & EF_DISABLED)
|
|
|
|
{
|
2018-12-06 17:52:13 +01:00
|
|
|
setAtlasColor(disabledGlow, disabledGlow, 255, 255);
|
2016-02-14 17:34:11 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-01 00:09:43 +01:00
|
|
|
blitRotated(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->angle);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
if (e->shieldHit > 0)
|
|
|
|
{
|
|
|
|
drawShieldHitEffect(e);
|
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2015-10-29 12:08:47 +01:00
|
|
|
|
2016-04-17 12:00:08 +02:00
|
|
|
static void drawHealthBar(Entity *e)
|
|
|
|
{
|
|
|
|
SDL_Rect r;
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (app.gameplay.healthBars && !(e->flags & EF_NO_HEALTH_BAR) && e->health > 0)
|
2016-04-17 12:00:08 +02:00
|
|
|
{
|
|
|
|
r.x = e->x - (e->w / 2) - battle.camera.x;
|
|
|
|
r.y = e->y - e->h - battle.camera.y;
|
|
|
|
r.w = 32;
|
|
|
|
r.h = 1;
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (e->side == player->side || e->flags & EF_FRIENDLY_HEALTH_BAR)
|
2016-04-17 12:00:08 +02:00
|
|
|
{
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 0, 128, 0, 255);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 128, 0, 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_RenderFillRect(app.renderer, &r);
|
|
|
|
|
|
|
|
r.w = 32 * (e->health * 1.0f / e->maxHealth);
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (e->side == player->side || e->flags & EF_FRIENDLY_HEALTH_BAR)
|
2016-04-17 12:00:08 +02:00
|
|
|
{
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_RenderFillRect(app.renderer, &r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 23:08:59 +01:00
|
|
|
static void drawTargetRects(Entity *e)
|
|
|
|
{
|
|
|
|
SDL_Rect r;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-16 15:39:20 +01:00
|
|
|
int size = MAX(e->w, e->h) + 16;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
if (player->alive == ALIVE_ALIVE && e == player->target)
|
2015-11-13 23:08:59 +01:00
|
|
|
{
|
2015-11-16 15:39:20 +01:00
|
|
|
r.x = e->x - (size / 2) - battle.camera.x;
|
|
|
|
r.y = e->y - (size / 2) - battle.camera.y;
|
|
|
|
r.w = size;
|
|
|
|
r.h = size;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-13 23:08:59 +01:00
|
|
|
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255);
|
|
|
|
SDL_RenderDrawRect(app.renderer, &r);
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-13 23:08:59 +01:00
|
|
|
if ((e == battle.missionTarget || e->flags & EF_MISSION_TARGET) && (e->flags & EF_NO_MT_BOX) == 0)
|
|
|
|
{
|
2015-11-22 18:49:38 +01:00
|
|
|
r.x = e->x - (size / 2) - battle.camera.x - 4;
|
|
|
|
r.y = e->y - (size / 2) - battle.camera.y - 4;
|
|
|
|
r.w = size + 8;
|
|
|
|
r.h = size + 8;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-13 23:08:59 +01:00
|
|
|
SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255);
|
|
|
|
SDL_RenderDrawRect(app.renderer, &r);
|
|
|
|
}
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
if (e == battle.messageSpeaker && e != player && battle.stats[STAT_TIME] % 40 < 20)
|
|
|
|
{
|
|
|
|
r.x = e->x - (size / 2) - battle.camera.x;
|
|
|
|
r.y = e->y - (size / 2) - battle.camera.y;
|
|
|
|
r.w = size;
|
|
|
|
r.h = size;
|
|
|
|
|
|
|
|
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
|
|
|
|
SDL_RenderDrawRect(app.renderer, &r);
|
|
|
|
}
|
2015-11-13 23:08:59 +01:00
|
|
|
}
|
|
|
|
|
2015-11-29 14:23:27 +01:00
|
|
|
void activateEntities(char *names)
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
2015-11-29 14:23:27 +01:00
|
|
|
char *name;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-29 14:23:27 +01:00
|
|
|
name = strtok(names, ";");
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-29 14:23:27 +01:00
|
|
|
while (name)
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
2015-11-29 14:23:27 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
2015-10-29 12:08:47 +01:00
|
|
|
{
|
2015-11-29 14:23:27 +01:00
|
|
|
if (strcmp(e->name, name) == 0)
|
|
|
|
{
|
|
|
|
e->active = 1;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-30 19:43:47 +01:00
|
|
|
if (e->type == ET_CAPITAL_SHIP)
|
|
|
|
{
|
2016-04-02 11:47:44 +02:00
|
|
|
updateCapitalShipComponentProperties(e, 0);
|
2015-12-30 19:43:47 +01:00
|
|
|
}
|
2015-11-29 14:23:27 +01:00
|
|
|
}
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-29 14:23:27 +01:00
|
|
|
name = strtok(NULL, ";");
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-01-24 10:49:50 +01:00
|
|
|
notifyNewArrivals();
|
2015-10-29 12:08:47 +01:00
|
|
|
}
|
2015-11-01 10:25:10 +01:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
void activateEntityGroups(char *groupNames)
|
2015-11-14 09:41:07 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
2015-11-29 13:55:15 +01:00
|
|
|
char *groupName;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
groupName = strtok(groupNames, ";");
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
while (groupName)
|
2015-11-14 09:41:07 +01:00
|
|
|
{
|
2015-11-29 13:55:15 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
2015-11-14 09:41:07 +01:00
|
|
|
{
|
2015-11-29 13:55:15 +01:00
|
|
|
if (strcmp(e->groupName, groupName) == 0)
|
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activated %s (%s)", e->name, groupName);
|
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
e->active = 1;
|
2016-05-15 09:19:26 +02:00
|
|
|
|
2016-03-08 15:28:11 +01:00
|
|
|
if (e->type == ET_CAPITAL_SHIP)
|
|
|
|
{
|
2016-04-02 11:47:44 +02:00
|
|
|
updateCapitalShipComponentProperties(e, 0);
|
2016-03-08 15:28:11 +01:00
|
|
|
}
|
2015-11-29 13:55:15 +01:00
|
|
|
}
|
2015-11-14 09:41:07 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-29 13:55:15 +01:00
|
|
|
groupName = strtok(NULL, ";");
|
2015-11-14 09:41:07 +01:00
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-01-24 10:49:50 +01:00
|
|
|
notifyNewArrivals();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-03-08 15:28:11 +01:00
|
|
|
* Some craft, such as capital ships, might be performing a long action and won't notice new craft arrive for well over 30 seconds.
|
2016-01-24 10:49:50 +01:00
|
|
|
* We'll knock the times down to a max of 1 second, so they can react faster.
|
|
|
|
*/
|
|
|
|
static void notifyNewArrivals(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-01-24 10:49:50 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->active && (e->type == ET_FIGHTER || e->type == ET_CAPITAL_SHIP))
|
|
|
|
{
|
|
|
|
e->aiActionTime = MIN(e->aiActionTime, FPS);
|
|
|
|
}
|
|
|
|
}
|
2015-11-14 09:41:07 +01:00
|
|
|
}
|
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
static void activateEpicFighters(int side)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (!e->active && e->type == ET_FIGHTER && !(e->flags & EF_NO_EPIC) && ((side == SIDE_ALLIES && e->side == SIDE_ALLIES) || (side != SIDE_ALLIES && e->side != SIDE_ALLIES)))
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
e->active = 1;
|
|
|
|
|
|
|
|
/* don't spring into existence in front of the player */
|
|
|
|
if (isOnBattleScreen(e->x, e->y, e->w, e->h))
|
2015-11-01 10:25:10 +01:00
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
e->x = player->x;
|
|
|
|
e->y = player->y;
|
|
|
|
|
2018-12-14 09:00:16 +01:00
|
|
|
e->x += (rand() % 2) ? -app.winWidth : app.winWidth;
|
|
|
|
e->y += (rand() % 2) ? -app.winHeight : app.winHeight;
|
2015-11-01 10:25:10 +01:00
|
|
|
}
|
2016-05-15 09:19:26 +02:00
|
|
|
|
|
|
|
return;
|
2015-11-01 10:25:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-09 23:48:59 +01:00
|
|
|
|
2015-12-31 12:25:19 +01:00
|
|
|
void countNumEnemies(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-31 12:25:19 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
2016-05-15 09:19:26 +02:00
|
|
|
if (e->side != SIDE_ALLIES && (e->type == ET_FIGHTER || e->type == ET_CAPITAL_SHIP) && (!(e->flags & EF_NO_THREAT)))
|
2015-12-31 12:25:19 +01:00
|
|
|
{
|
|
|
|
battle.numInitialEnemies++;
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-04-05 10:58:59 +02:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "battle.numInitialEnemies=%d", battle.numInitialEnemies);
|
2015-12-31 12:25:19 +01:00
|
|
|
}
|
|
|
|
|
2016-04-09 19:13:59 +02:00
|
|
|
void addAllToQuadtree(void)
|
2016-03-08 08:12:06 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
2016-04-02 17:37:49 +02:00
|
|
|
|
2016-03-08 08:12:06 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
2016-03-26 19:15:52 +01:00
|
|
|
if (e->active)
|
|
|
|
{
|
2016-04-09 19:13:59 +02:00
|
|
|
addToQuadtree(e, &battle.quadtree);
|
2016-03-26 19:15:52 +01:00
|
|
|
}
|
2016-03-08 08:12:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 23:48:59 +01:00
|
|
|
static int drawComparator(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
Entity *e1 = *((Entity**)a);
|
|
|
|
Entity *e2 = *((Entity**)b);
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-09 23:48:59 +01:00
|
|
|
return e2->type - e1->type;
|
|
|
|
}
|
2015-12-10 11:15:27 +01:00
|
|
|
|
2016-05-15 09:19:26 +02:00
|
|
|
void killEntity(char *name)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
|
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (strcmp(e->name, name) == 0)
|
|
|
|
{
|
|
|
|
e->health = 0;
|
|
|
|
e->deathType = DT_INSTANT;
|
|
|
|
|
|
|
|
/* prevent objectives and conditions from firing */
|
|
|
|
strcpy(e->name, "");
|
|
|
|
strcpy(e->groupName, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 10:51:53 +02:00
|
|
|
void updateEntitySide(char *sideStr, char *name)
|
2016-05-15 15:02:35 +02:00
|
|
|
{
|
2016-05-20 10:51:53 +02:00
|
|
|
Entity *e;
|
|
|
|
int side;
|
|
|
|
|
|
|
|
side = lookup(sideStr);
|
|
|
|
|
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (strcmp(e->name, name) == 0)
|
|
|
|
{
|
|
|
|
e->side = side;
|
2016-05-25 10:43:15 +02:00
|
|
|
|
|
|
|
if (e->side != player->side)
|
|
|
|
{
|
|
|
|
e->flags |= EF_MISSION_TARGET;
|
|
|
|
}
|
2016-05-20 10:51:53 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-15 15:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-05-24 12:46:20 +02:00
|
|
|
void awardPandoranCraftTrophy(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
|
|
|
|
for (e = deadHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->killedBy == player && e->side == SIDE_PANDORAN)
|
|
|
|
{
|
|
|
|
awardTrophy("PANDORAN");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 11:15:27 +01:00
|
|
|
void destroyEntities(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-10 11:15:27 +01:00
|
|
|
while (deadHead.next)
|
|
|
|
{
|
|
|
|
e = deadHead.next;
|
|
|
|
deadHead.next = e->next;
|
|
|
|
free(e);
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-12-10 11:15:27 +01:00
|
|
|
deadTail = &deadHead;
|
|
|
|
}
|