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 "fighters.h"
|
|
|
|
|
|
|
|
static void separate(void);
|
|
|
|
static void die(void);
|
|
|
|
static void immediateDie(void);
|
|
|
|
static void spinDie(void);
|
|
|
|
static void straightDie(void);
|
2016-03-27 12:21:23 +02:00
|
|
|
static void simpleDie(void);
|
2015-10-26 20:16:12 +01:00
|
|
|
static void randomizeDart(Entity *dart);
|
|
|
|
static void randomizeDartGuns(Entity *dart);
|
2015-11-16 18:23:56 +01:00
|
|
|
static void loadFighterDef(char *filename);
|
2015-12-26 22:08:53 +01:00
|
|
|
static void loadFighterDefList(char *filename);
|
2015-12-07 20:19:41 +01:00
|
|
|
static Entity *getFighterDef(char *name);
|
2015-11-16 18:23:56 +01:00
|
|
|
|
|
|
|
static Entity defHead, *defTail;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
Entity *spawnFighter(char *name, int x, int y, int side)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
Entity *e, *def;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e = spawnEntity();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
def = getFighterDef(name);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
memcpy(e, def, sizeof(Entity));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e->next = NULL;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e->x = x;
|
|
|
|
e->y = y;
|
|
|
|
e->side = side;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case SIDE_ALLIES:
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiAggression = 2 + rand() % 2;
|
|
|
|
if (!(e->aiFlags & AIF_FOLLOWS_PLAYER))
|
2015-11-30 13:41:11 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiFlags |= AIF_MOVES_TO_PLAYER;
|
2015-11-30 13:41:11 +01:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
case SIDE_PIRATE:
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiAggression = rand() % 3;
|
2015-10-20 13:51:49 +02:00
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
case SIDE_PANDORAN:
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiAggression = 3 + rand() % 2;
|
2015-10-20 13:51:49 +02:00
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-13 18:56:16 +01:00
|
|
|
case SIDE_REBEL:
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiAggression = 1 + rand() % 3;
|
2015-12-13 18:56:16 +01:00
|
|
|
break;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (strcmp(name, "ATAF") == 0)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiAggression = 4;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (strcmp(name, "Dart") == 0)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
randomizeDart(e);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-13 09:46:06 +01:00
|
|
|
if (strcmp(name, "Civilian") == 0 && rand() % 2 == 0)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->texture = getTexture("gfx/craft/civilian02.png");
|
2015-11-13 09:46:06 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
if (e->aiFlags & AIF_AGGRESSIVE)
|
2015-11-30 12:29:56 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->aiAggression = 4;
|
2015-11-30 12:29:56 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e->action = doAI;
|
|
|
|
e->die = die;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
return e;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
static void randomizeDart(Entity *dart)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-02-13 15:31:45 +01:00
|
|
|
char texture[MAX_DESCRIPTION_LENGTH];
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->health = dart->maxHealth = 5 + (rand() % 21);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->shield = dart->maxShield = 1 + (rand() % 16);
|
|
|
|
dart->shieldRechargeRate = 30 + (rand() % 90);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->speed = 2 + (rand() % 3);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->reloadTime = 24 + (rand() % 11);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
randomizeDartGuns(dart);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-22 00:45:22 +01:00
|
|
|
dart->missiles = rand() % 3;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-13 15:31:45 +01:00
|
|
|
sprintf(texture, "gfx/fighters/dart0%d.png", 1 + rand() % 7);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-13 15:31:45 +01:00
|
|
|
dart->texture = getTexture(texture);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
static void randomizeDartGuns(Entity *dart)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
int i;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
switch (rand() % 4)
|
|
|
|
{
|
|
|
|
/* Single plasma gun */
|
|
|
|
case 0:
|
|
|
|
dart->guns[0].type = BT_PLASMA;
|
|
|
|
dart->guns[0].x = dart->guns[0].y = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
for (i = 1 ; i < MAX_FIGHTER_GUNS ; i++)
|
|
|
|
{
|
|
|
|
if (dart->guns[i].type)
|
|
|
|
{
|
|
|
|
dart->guns[i].type = BT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
/* Dual plasma guns */
|
|
|
|
case 1:
|
|
|
|
dart->guns[0].type = BT_PLASMA;
|
|
|
|
dart->guns[1].type = BT_PLASMA;
|
|
|
|
break;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
/* Triple particle guns */
|
|
|
|
case 2:
|
|
|
|
dart->guns[2].type = BT_PARTICLE;
|
|
|
|
dart->guns[2].y = -10;
|
|
|
|
break;
|
2015-11-18 19:38:00 +01:00
|
|
|
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-18 19:38:00 +01:00
|
|
|
/* Plasma / Laser cannons */
|
|
|
|
case 3:
|
|
|
|
dart->guns[0].type = BT_PLASMA;
|
|
|
|
dart->guns[0].x = dart->guns[0].y = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-18 19:38:00 +01:00
|
|
|
dart->guns[1].type = BT_LASER;
|
|
|
|
dart->guns[1].x = dart->guns[1].y = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Dual Laser cannons */
|
|
|
|
case 4:
|
|
|
|
dart->guns[0].type = BT_LASER;
|
|
|
|
dart->guns[1].type = BT_LASER;
|
|
|
|
break;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 11:14:21 +01:00
|
|
|
void doFighter(void)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-11-01 12:37:12 +01:00
|
|
|
if (self->alive == ALIVE_ALIVE)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-11-01 12:37:12 +01:00
|
|
|
if (self != player)
|
|
|
|
{
|
|
|
|
separate();
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-04-07 13:40:14 +02:00
|
|
|
if (!(self->flags & EF_DISABLED))
|
|
|
|
{
|
|
|
|
attachRope();
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
if (self->thrust > 0.25)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-26 20:16:12 +01:00
|
|
|
addEngineEffect();
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
if (self->health <= 0)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-27 08:24:17 +01:00
|
|
|
self->health = 0;
|
|
|
|
self->alive = ALIVE_DYING;
|
|
|
|
self->die();
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
if (self == battle.missionTarget)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-26 20:16:12 +01:00
|
|
|
battle.missionTarget = NULL;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2015-11-15 00:19:17 +01:00
|
|
|
else if (self->systemPower <= 0 || (self->flags & EF_DISABLED))
|
2015-10-26 20:16:12 +01:00
|
|
|
{
|
2015-10-27 08:24:17 +01:00
|
|
|
self->dx *= 0.99;
|
|
|
|
self->dy *= 0.99;
|
|
|
|
self->thrust = 0;
|
|
|
|
self->shield = self->maxShield = 0;
|
|
|
|
self->action = NULL;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-14 17:14:48 +01:00
|
|
|
if ((self->flags & EF_DISABLED) == 0)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-02-20 15:19:59 +01:00
|
|
|
playBattleSound(SND_POWER_DOWN, self->x, self->y);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-14 17:14:48 +01:00
|
|
|
self->flags |= EF_DISABLED;
|
2016-03-03 12:31:18 +01:00
|
|
|
self->flags |= EF_SECONDARY_TARGET;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-17 08:23:50 +01:00
|
|
|
battle.stats[STAT_ENEMIES_DISABLED]++;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-01-24 10:50:31 +01:00
|
|
|
updateObjective(self->name, TT_DISABLE);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-20 23:52:35 +01:00
|
|
|
if (self->target != NULL && self->target->alive != ALIVE_ALIVE)
|
|
|
|
{
|
|
|
|
self->target = NULL;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-20 23:52:35 +01:00
|
|
|
if (self != player)
|
|
|
|
{
|
|
|
|
self->action = doAI;
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-11 23:34:48 +01:00
|
|
|
if (self->alive == ALIVE_ESCAPED)
|
|
|
|
{
|
2015-11-20 23:52:35 +01:00
|
|
|
if (self == player)
|
|
|
|
{
|
|
|
|
completeMission();
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-27 07:37:08 +01:00
|
|
|
if (self->side != SIDE_ALLIES && (!(self->flags & EF_DISABLED)))
|
2015-11-11 23:34:48 +01:00
|
|
|
{
|
2016-02-28 14:45:17 +01:00
|
|
|
addHudMessage(colors.red, _("Mission target has escaped."));
|
2015-11-11 23:34:48 +01:00
|
|
|
battle.stats[STAT_ENEMIES_ESCAPED]++;
|
|
|
|
}
|
2016-03-12 19:28:43 +01:00
|
|
|
|
2016-03-10 00:20:50 +01:00
|
|
|
if (strcmp(self->defName, "Civilian") == 0)
|
2015-11-11 23:34:48 +01:00
|
|
|
{
|
2015-11-17 08:23:50 +01:00
|
|
|
battle.stats[STAT_CIVILIANS_RESCUED]++;
|
2015-11-11 23:34:48 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-10 00:20:50 +01:00
|
|
|
/* if you did not escape under your own volition, or with the aid of a friend, you've been stolen */
|
|
|
|
if (!self->owner || self->side == self->owner->side)
|
|
|
|
{
|
|
|
|
updateObjective(self->name, TT_ESCAPED);
|
|
|
|
updateCondition(self->name, TT_ESCAPED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updateObjective(self->name, TT_STOLEN);
|
|
|
|
updateCondition(self->name, TT_STOLEN);
|
|
|
|
}
|
2015-11-11 23:34:48 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
if (self->alive == ALIVE_DEAD)
|
2015-10-26 20:16:12 +01:00
|
|
|
{
|
2016-04-04 12:23:32 +02:00
|
|
|
if (player != NULL && self != player)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-26 20:16:12 +01:00
|
|
|
if (player->alive == ALIVE_ALIVE)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2015-10-31 09:03:11 +01:00
|
|
|
if (self->side != SIDE_ALLIES)
|
2015-10-24 17:00:06 +02:00
|
|
|
{
|
2016-03-27 12:21:23 +02:00
|
|
|
if (!(self->flags & EF_NO_KILL_INC))
|
|
|
|
{
|
|
|
|
battle.stats[STAT_ENEMIES_KILLED]++;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-27 12:21:23 +02:00
|
|
|
runScriptFunction("ENEMIES_KILLED %d", battle.stats[STAT_ENEMIES_KILLED]);
|
|
|
|
}
|
2015-10-24 17:00:06 +02:00
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
else
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-11-18 12:27:05 +01:00
|
|
|
if (strcmp(self->name, "Civilian") == 0)
|
2015-11-01 12:37:12 +01:00
|
|
|
{
|
2015-11-17 08:23:50 +01:00
|
|
|
battle.stats[STAT_CIVILIANS_KILLED]++;
|
2016-03-07 13:31:43 +01:00
|
|
|
if (!battle.isEpic || game.currentMission->challengeData.isChallenge)
|
2015-11-13 17:55:49 +01:00
|
|
|
{
|
2016-02-28 14:45:17 +01:00
|
|
|
addHudMessage(colors.red, _("Civilian has been killed"));
|
2015-11-13 17:55:49 +01:00
|
|
|
}
|
2016-04-06 13:56:48 +02:00
|
|
|
|
|
|
|
runScriptFunction("CIVILIANS_KILLED %d", battle.stats[STAT_CIVILIANS_KILLED]);
|
2015-11-17 08:23:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
battle.stats[STAT_ALLIES_KILLED]++;
|
2016-03-07 13:31:43 +01:00
|
|
|
if (!battle.isEpic || game.currentMission->challengeData.isChallenge)
|
2015-11-13 17:55:49 +01:00
|
|
|
{
|
2016-02-28 14:45:17 +01:00
|
|
|
addHudMessage(colors.red, _("Ally has been killed"));
|
2015-11-13 17:55:49 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-28 11:11:20 +01:00
|
|
|
runScriptFunction("ALLIES_KILLED %d", battle.stats[STAT_ALLIES_KILLED]);
|
2015-11-01 12:37:12 +01:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
updateObjective(self->name, TT_DESTROY);
|
2015-11-29 13:57:27 +01:00
|
|
|
updateObjective(self->groupName, TT_DESTROY);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-13 17:55:49 +01:00
|
|
|
adjustObjectiveTargetValue(self->name, TT_ESCAPED, -1);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
updateCondition(self->name, TT_DESTROY);
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void separate(void)
|
|
|
|
{
|
|
|
|
int angle;
|
|
|
|
int distance;
|
|
|
|
float dx, dy, force;
|
|
|
|
int count;
|
2015-11-02 13:14:29 +01:00
|
|
|
Entity *e, **candidates;
|
|
|
|
int i;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
dx = dy = 0;
|
|
|
|
count = 0;
|
|
|
|
force = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-15 13:28:12 +01:00
|
|
|
candidates = getAllEntsWithin(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, self);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-14 00:35:51 +01:00
|
|
|
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-12-08 23:42:31 +01:00
|
|
|
if (e->flags & EF_TAKES_DAMAGE)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-11-11 07:46:58 +01:00
|
|
|
distance = getDistance(e->x, e->y, self->x, self->y);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-11 07:46:58 +01:00
|
|
|
if (distance > 0 && distance < self->separationRadius)
|
|
|
|
{
|
|
|
|
angle = getAngle(self->x, self->y, e->x, e->y);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-11 07:46:58 +01:00
|
|
|
dx += sin(TO_RAIDANS(angle));
|
|
|
|
dy += -cos(TO_RAIDANS(angle));
|
|
|
|
force += (self->separationRadius - distance) * 0.005;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-11 07:46:58 +01:00
|
|
|
count++;
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
dx /= count;
|
|
|
|
dy /= count;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
dx *= force;
|
|
|
|
dy *= force;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
self->dx -= dx;
|
|
|
|
self->dy -= dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyFighterThrust(void)
|
|
|
|
{
|
|
|
|
float v;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
self->dx += sin(TO_RAIDANS(self->angle)) * 0.1;
|
|
|
|
self->dy += -cos(TO_RAIDANS(self->angle)) * 0.1;
|
|
|
|
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 00:23:03 +01:00
|
|
|
if (self->thrust > self->speed * self->speed)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
v = (self->speed / sqrt(self->thrust));
|
|
|
|
self->dx = v * self->dx;
|
|
|
|
self->dy = v * self->dy;
|
2015-11-15 18:12:04 +01:00
|
|
|
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyFighterBrakes(void)
|
|
|
|
{
|
|
|
|
self->dx *= 0.95;
|
|
|
|
self->dy *= 0.95;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
void damageFighter(Entity *e, int amount, long flags)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
int prevShield = e->shield;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-20 16:13:41 +01:00
|
|
|
e->aiDamageTimer = FPS;
|
|
|
|
e->aiDamagePerSec += amount;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-21 20:21:45 +02:00
|
|
|
if (flags & BF_SYSTEM_DAMAGE)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2016-02-20 15:19:59 +01:00
|
|
|
playBattleSound(SND_MAG_HIT, e->x, e->y);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e->systemPower = MAX(0, e->systemPower - amount);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
e->systemHit = 255;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
if (e->systemPower == 0)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->shield = e->maxShield = 0;
|
|
|
|
e->action = NULL;
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2015-11-18 17:04:12 +01:00
|
|
|
else if (flags & BF_SHIELD_DAMAGE)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-12-14 15:04:48 +01:00
|
|
|
e->shield -= amount;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
if (e->shield <= 0 && prevShield > 0)
|
2015-11-18 17:04:12 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
playBattleSound(SND_SHIELD_BREAK, e->x, e->y);
|
|
|
|
addShieldSplinterEffect(e);
|
2015-12-14 15:04:48 +01:00
|
|
|
e->shield = -(FPS * 10);
|
2015-11-18 17:04:12 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 15:04:48 +01:00
|
|
|
e->shield = MAX(-(FPS * 10), e->shield);
|
2015-11-18 17:04:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
if (e->shield > 0)
|
2015-10-21 20:21:45 +02:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->shield -= amount;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
if (e->shield < 0)
|
2015-11-19 09:30:45 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->health += e->shield;
|
|
|
|
e->shield = 0;
|
2015-11-19 09:30:45 +01:00
|
|
|
}
|
2015-11-18 17:04:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->health -= amount;
|
|
|
|
e->armourHit = 255;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
playBattleSound(SND_ARMOUR_HIT, e->x, e->y);
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
2015-11-18 17:04:12 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
if (e->shield > 0)
|
2015-11-18 17:04:12 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e->shieldHit = 255;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 15:04:48 +01:00
|
|
|
/* don't allow the shield to recharge immediately after taking a hit */
|
|
|
|
e->shieldRecharge = e->shieldRechargeRate;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
playBattleSound(SND_SHIELD_HIT, e->x, e->y);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-20 16:13:41 +01:00
|
|
|
/*
|
|
|
|
* Sometimes run away if you take too much damage in a short space of time
|
|
|
|
*/
|
2015-12-20 17:13:49 +01:00
|
|
|
if (e->type == ET_FIGHTER && (!(e->aiFlags & AIF_EVADE)) && e != player && e->aiDamagePerSec >= (e->maxHealth + e->maxShield) * 0.1)
|
2015-12-20 16:13:41 +01:00
|
|
|
{
|
2015-12-22 18:58:53 +01:00
|
|
|
if ((rand() % 10) > 7)
|
2015-12-20 16:13:41 +01:00
|
|
|
{
|
|
|
|
e->action = doAI;
|
|
|
|
e->aiFlags |= AIF_EVADE;
|
2015-12-20 17:13:49 +01:00
|
|
|
e->aiActionTime = e->aiEvadeTimer = FPS * (1 + (rand() % 3));
|
2015-12-20 16:13:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->aiDamagePerSec = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void die(void)
|
|
|
|
{
|
|
|
|
int n = rand() % 3;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-24 13:12:23 +01:00
|
|
|
switch (self->deathType)
|
2015-11-30 12:29:56 +01:00
|
|
|
{
|
2015-12-24 13:12:23 +01:00
|
|
|
case DT_ANY:
|
|
|
|
n = rand() % 3;
|
|
|
|
break;
|
|
|
|
case DT_NO_SPIN:
|
|
|
|
n = 1 + rand() % 2;
|
|
|
|
break;
|
|
|
|
case DT_INSTANT:
|
|
|
|
n = 2;
|
|
|
|
break;
|
2016-03-27 12:21:23 +02:00
|
|
|
case DT_SIMPLE:
|
|
|
|
n = 3;
|
|
|
|
break;
|
2015-11-30 12:29:56 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-28 14:02:57 +01:00
|
|
|
if (self == player && battle.isEpic)
|
2016-01-28 18:03:13 +01:00
|
|
|
{
|
|
|
|
n = 1;
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 0:
|
2015-12-24 13:12:23 +01:00
|
|
|
self->action = spinDie;
|
2015-10-20 13:51:49 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-12-24 13:12:23 +01:00
|
|
|
self->action = straightDie;
|
2015-10-20 13:51:49 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
self->action = immediateDie;
|
|
|
|
break;
|
2016-03-27 12:21:23 +02:00
|
|
|
case 3:
|
|
|
|
self->action = simpleDie;
|
|
|
|
break;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2016-04-03 09:37:31 +02:00
|
|
|
|
|
|
|
if (self->killedBy == player && (!(self->flags & EF_NO_KILL_INC)))
|
|
|
|
{
|
|
|
|
battle.stats[STAT_ENEMIES_KILLED_PLAYER]++;
|
|
|
|
|
|
|
|
if (battle.isEpic)
|
|
|
|
{
|
|
|
|
battle.stats[STAT_EPIC_KILL_STREAK]++;
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void immediateDie(void)
|
|
|
|
{
|
|
|
|
self->alive = ALIVE_DEAD;
|
2015-12-07 20:19:41 +01:00
|
|
|
addSmallExplosion();
|
2015-10-20 13:51:49 +02:00
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
2015-12-16 23:40:26 +01:00
|
|
|
addDebris(self->x, self->y, 3 + rand() % 6);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void spinDie(void)
|
|
|
|
{
|
|
|
|
self->health--;
|
|
|
|
self->thinkTime = 0;
|
|
|
|
self->armourHit = 0;
|
|
|
|
self->shieldHit = 0;
|
2015-10-21 20:21:45 +02:00
|
|
|
self->systemHit = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
self->angle += 8;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (rand() % 2 == 0)
|
|
|
|
{
|
|
|
|
addSmallFighterExplosion();
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-01 00:09:43 +01:00
|
|
|
if (self->health <= -(FPS * 1.5))
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
self->alive = ALIVE_DEAD;
|
2015-12-07 20:19:41 +01:00
|
|
|
addSmallExplosion();
|
2015-10-20 13:51:49 +02:00
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
2015-12-16 23:40:26 +01:00
|
|
|
addDebris(self->x, self->y, 3 + rand() % 6);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void straightDie(void)
|
|
|
|
{
|
|
|
|
self->health--;
|
|
|
|
self->thinkTime = 0;
|
|
|
|
self->armourHit = 0;
|
|
|
|
self->shieldHit = 0;
|
2015-10-21 20:21:45 +02:00
|
|
|
self->systemHit = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
if (rand() % 2 == 0)
|
|
|
|
{
|
|
|
|
addSmallFighterExplosion();
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-01 00:09:43 +01:00
|
|
|
if (self->health <= -(FPS * 1.5))
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
self->alive = ALIVE_DEAD;
|
2015-12-07 20:19:41 +01:00
|
|
|
addSmallExplosion();
|
2015-10-20 13:51:49 +02:00
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
2015-12-16 23:40:26 +01:00
|
|
|
addDebris(self->x, self->y, 3 + rand() % 6);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-15 14:26:34 +01:00
|
|
|
|
2016-03-27 12:21:23 +02:00
|
|
|
static void simpleDie(void)
|
|
|
|
{
|
|
|
|
self->alive = ALIVE_DEAD;
|
|
|
|
addSmallExplosion();
|
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
|
|
|
}
|
|
|
|
|
2015-11-21 18:32:39 +01:00
|
|
|
void retreatEnemies(void)
|
2015-11-15 14:26:34 +01:00
|
|
|
{
|
|
|
|
Entity *e;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-15 14:26:34 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->type == ET_FIGHTER && e->side != SIDE_ALLIES)
|
|
|
|
{
|
2015-11-18 12:27:05 +01:00
|
|
|
e->aiFlags |= AIF_AVOIDS_COMBAT;
|
2015-11-15 14:26:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 18:23:56 +01:00
|
|
|
|
2015-11-20 23:52:35 +01:00
|
|
|
void retreatAllies(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-20 23:52:35 +01:00
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->type == ET_FIGHTER && e->side == SIDE_ALLIES)
|
|
|
|
{
|
2015-11-21 18:32:39 +01:00
|
|
|
e->flags |= EF_RETREATING;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-20 23:52:35 +01:00
|
|
|
e->aiFlags |= AIF_AVOIDS_COMBAT;
|
|
|
|
e->aiFlags |= AIF_UNLIMITED_RANGE;
|
2016-03-07 18:12:21 +01:00
|
|
|
e->aiFlags |= AIF_GOAL_JUMPGATE;
|
2015-11-20 23:52:35 +01:00
|
|
|
e->aiFlags &= ~AIF_FOLLOWS_PLAYER;
|
2015-11-28 15:33:05 +01:00
|
|
|
e->aiFlags &= ~AIF_MOVES_TO_PLAYER;
|
2015-11-20 23:52:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 20:19:41 +01:00
|
|
|
static Entity *getFighterDef(char *name)
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
Entity *e;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-12-14 09:15:41 +01:00
|
|
|
for (e = defHead.next ; e != NULL ; e = e->next)
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
if (strcmp(e->name, name) == 0)
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
return e;
|
2015-11-16 18:23:56 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 18:23:56 +01:00
|
|
|
printf("Error: no such fighter '%s'\n", name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadFighterDefs(void)
|
2015-12-26 22:08:53 +01:00
|
|
|
{
|
|
|
|
memset(&defHead, 0, sizeof(Entity));
|
|
|
|
defTail = &defHead;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:14:14 +01:00
|
|
|
loadFighterDefList("data/fighters");
|
|
|
|
loadFighterDefList("data/craft");
|
|
|
|
loadFighterDefList("data/turrets");
|
2015-12-26 22:08:53 +01:00
|
|
|
}
|
|
|
|
|
2016-02-27 17:14:14 +01:00
|
|
|
static void loadFighterDefList(char *dir)
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2016-02-27 17:14:14 +01:00
|
|
|
char **filenames;
|
|
|
|
char path[MAX_FILENAME_LENGTH];
|
|
|
|
int count, i;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-04 15:29:50 +01:00
|
|
|
filenames = getFileList(dir, &count);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:14:14 +01:00
|
|
|
for (i = 0 ; i < count ; i++)
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2016-02-27 17:14:14 +01:00
|
|
|
sprintf(path, "%s/%s", dir, filenames[i]);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:14:14 +01:00
|
|
|
loadFighterDef(path);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:14:14 +01:00
|
|
|
free(filenames[i]);
|
2015-11-16 18:23:56 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-02-27 17:14:14 +01:00
|
|
|
free(filenames);
|
2015-11-16 18:23:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void loadFighterDef(char *filename)
|
|
|
|
{
|
|
|
|
cJSON *root, *node;
|
|
|
|
char *text;
|
2015-12-14 09:15:41 +01:00
|
|
|
Entity *e;
|
2015-11-16 18:23:56 +01:00
|
|
|
int i;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 18:23:56 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-04 15:29:50 +01:00
|
|
|
text = readFile(filename);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 18:23:56 +01:00
|
|
|
root = cJSON_Parse(text);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
if (root)
|
|
|
|
{
|
|
|
|
e = malloc(sizeof(Entity));
|
|
|
|
memset(e, 0, sizeof(Entity));
|
|
|
|
defTail->next = e;
|
|
|
|
defTail = e;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
e->type = ET_FIGHTER;
|
|
|
|
e->active = 1;
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
STRNCPY(e->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
STRNCPY(e->defName, e->name, MAX_NAME_LENGTH);
|
|
|
|
e->health = e->maxHealth = cJSON_GetObjectItem(root, "health")->valueint;
|
2016-03-27 12:21:23 +02:00
|
|
|
e->shield = e->maxShield = getJSONValue(root, "shield", 0);
|
2016-03-07 20:03:55 +01:00
|
|
|
e->speed = cJSON_GetObjectItem(root, "speed")->valuedouble;
|
2016-03-27 12:21:23 +02:00
|
|
|
e->reloadTime = getJSONValue(root, "reloadTime", 0);
|
|
|
|
e->shieldRechargeRate = getJSONValue(root, "shieldRechargeRate", 0);
|
2016-03-07 20:03:55 +01:00
|
|
|
e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
if (cJSON_GetObjectItem(root, "guns"))
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2016-03-07 20:03:55 +01:00
|
|
|
i = 0;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
for (node = cJSON_GetObjectItem(root, "guns")->child ; node != NULL ; node = node->next)
|
2015-11-16 18:23:56 +01:00
|
|
|
{
|
2016-03-07 20:03:55 +01:00
|
|
|
e->guns[i].type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
|
|
|
e->guns[i].x = cJSON_GetObjectItem(node, "x")->valueint;
|
|
|
|
e->guns[i].y = cJSON_GetObjectItem(node, "y")->valueint;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i >= MAX_FIGHTER_GUNS)
|
|
|
|
{
|
|
|
|
printf("ERROR: cannot assign more than %d guns to a fighter\n", MAX_FIGHTER_GUNS);
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-11-16 18:23:56 +01:00
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
e->combinedGuns = getJSONValue(root, "combinedGuns", 0);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
e->selectedGunType = e->guns[0].type;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
e->missiles = getJSONValue(root, "missiles", 0);
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
if (cJSON_GetObjectItem(root, "flags"))
|
|
|
|
{
|
|
|
|
e->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring, NULL);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
if (cJSON_GetObjectItem(root, "aiFlags"))
|
|
|
|
{
|
|
|
|
e->aiFlags = flagsToLong(cJSON_GetObjectItem(root, "aiFlags")->valuestring, NULL);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
if (cJSON_GetObjectItem(root, "deathType"))
|
|
|
|
{
|
|
|
|
e->deathType = lookup(cJSON_GetObjectItem(root, "deathType")->valuestring);
|
|
|
|
}
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
e->separationRadius = MAX(e->w, e->h) * 3;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-08 15:28:11 +01:00
|
|
|
e->systemPower = MAX_SYSTEM_POWER;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2016-03-07 20:03:55 +01:00
|
|
|
cJSON_Delete(root);
|
|
|
|
}
|
2016-03-12 19:22:48 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to load '%s'", filename);
|
|
|
|
}
|
2016-03-08 15:28:11 +01:00
|
|
|
|
2015-11-16 18:23:56 +01:00
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
2016-03-27 12:21:23 +02:00
|
|
|
void loadFighters(cJSON *node)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
char **types, *name, *groupName, *type;
|
|
|
|
int side, scatter, number, active;
|
|
|
|
int i, numTypes, addFlags, addAIFlags;
|
|
|
|
long flags, aiFlags;
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
name = NULL;
|
|
|
|
groupName = NULL;
|
|
|
|
flags = -1;
|
|
|
|
aiFlags = -1;
|
|
|
|
|
|
|
|
types = toTypeArray(cJSON_GetObjectItem(node, "types")->valuestring, &numTypes);
|
|
|
|
side = lookup(cJSON_GetObjectItem(node, "side")->valuestring);
|
|
|
|
x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
|
|
|
|
y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
|
|
|
|
name = getJSONValueStr(node, "name", NULL);
|
|
|
|
groupName = getJSONValueStr(node, "groupName", NULL);
|
|
|
|
number = getJSONValue(node, "number", 1);
|
|
|
|
scatter = getJSONValue(node, "scatter", 1);
|
|
|
|
active = getJSONValue(node, "active", 1);
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(node, "flags"))
|
|
|
|
{
|
|
|
|
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(node, "aiFlags"))
|
|
|
|
{
|
|
|
|
aiFlags = flagsToLong(cJSON_GetObjectItem(node, "aiFlags")->valuestring, &addAIFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < number ; i++)
|
|
|
|
{
|
|
|
|
type = types[rand() % numTypes];
|
|
|
|
|
|
|
|
e = spawnFighter(type, x, y, side);
|
|
|
|
|
|
|
|
if (scatter > 1)
|
|
|
|
{
|
|
|
|
e->x += (rand() % scatter) - (rand() % scatter);
|
|
|
|
e->y += (rand() % scatter) - (rand() % scatter);
|
|
|
|
}
|
|
|
|
|
|
|
|
e->active = active;
|
|
|
|
|
|
|
|
if (flags != -1)
|
|
|
|
{
|
|
|
|
if (addFlags)
|
|
|
|
{
|
|
|
|
e->flags |= flags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->flags = flags;
|
|
|
|
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
|
|
|
|
}
|
2016-04-07 13:40:14 +02:00
|
|
|
|
|
|
|
if (e->flags & EF_DISABLED)
|
|
|
|
{
|
|
|
|
e->speed = 0;
|
|
|
|
}
|
2016-03-27 12:21:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aiFlags != -1)
|
|
|
|
{
|
|
|
|
if (addAIFlags)
|
|
|
|
{
|
|
|
|
e->aiFlags |= aiFlags;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->aiFlags = aiFlags;
|
|
|
|
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "AI Flags for '%s' (%s) replaced", e->name, e->defName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
STRNCPY(e->name, name, MAX_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groupName)
|
|
|
|
{
|
|
|
|
STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
|
|
|
|
for (i = 0 ; i < numTypes ; i++)
|
|
|
|
{
|
|
|
|
free(types[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 18:23:56 +01:00
|
|
|
void destroyFighterDefs(void)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
Entity *e;
|
2016-03-04 15:14:04 +01:00
|
|
|
|
2015-11-16 18:23:56 +01:00
|
|
|
while (defHead.next)
|
|
|
|
{
|
2015-12-14 09:15:41 +01:00
|
|
|
e = defHead.next;
|
|
|
|
defHead.next = e->next;
|
|
|
|
free(e);
|
2015-11-16 18:23:56 +01:00
|
|
|
}
|
|
|
|
}
|