2015-10-20 13:51:49 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2015 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 "fighters.h"
|
|
|
|
|
|
|
|
static void separate(void);
|
|
|
|
static void die(void);
|
|
|
|
static void immediateDie(void);
|
|
|
|
static void spinDie(void);
|
|
|
|
static void straightDie(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);
|
|
|
|
|
|
|
|
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-10-26 20:16:12 +01:00
|
|
|
Entity *f, *def;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
f = spawnEntity();
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
def = getFighterDef(name);
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
memcpy(f, def, sizeof(Entity));
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
f->id = battle.entId;
|
2015-10-20 13:51:49 +02:00
|
|
|
f->next = NULL;
|
|
|
|
|
|
|
|
f->x = x;
|
|
|
|
f->y = y;
|
|
|
|
f->side = side;
|
|
|
|
|
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case SIDE_ALLIES:
|
2015-11-14 12:32:37 +01:00
|
|
|
f->aggression = 2 + rand() % 3;
|
2015-10-20 13:51:49 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIDE_PIRATE:
|
|
|
|
f->aggression = rand() % 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIDE_PANDORAN:
|
|
|
|
f->aggression = 3 + rand() % 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(name, "ATAF") == 0)
|
|
|
|
{
|
|
|
|
f->aggression = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(name, "Dart") == 0)
|
|
|
|
{
|
|
|
|
randomizeDart(f);
|
|
|
|
}
|
|
|
|
|
2015-11-13 09:46:06 +01:00
|
|
|
if (strcmp(name, "Civilian") == 0 && rand() % 2 == 0)
|
|
|
|
{
|
|
|
|
f->texture = getTexture("gfx/craft/civilian02.png");
|
|
|
|
}
|
|
|
|
|
2015-11-15 14:26:34 +01:00
|
|
|
f->action = doAI;
|
2015-10-20 13:51:49 +02:00
|
|
|
f->die = die;
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
static void randomizeDart(Entity *dart)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
char textureName[MAX_DESCRIPTION_LENGTH];
|
|
|
|
|
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->health = dart->maxHealth = 5 + (rand() % 21);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->shield = dart->maxShield = 1 + (rand() % 16);
|
|
|
|
dart->shieldRechargeRate = 30 + (rand() % 90);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->speed = 2 + (rand() % 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rand() % 5 == 0)
|
|
|
|
{
|
|
|
|
dart->reloadTime = 24 + (rand() % 11);
|
|
|
|
}
|
|
|
|
|
|
|
|
randomizeDartGuns(dart);
|
|
|
|
|
2015-10-30 22:55:01 +01:00
|
|
|
dart->missiles.ammo = rand() % 3;
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
sprintf(textureName, "gfx/fighters/dart0%d.png", 1 + rand() % 7);
|
|
|
|
|
|
|
|
dart->texture = getTexture(textureName);
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
static void randomizeDartGuns(Entity *dart)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (rand() % 4)
|
|
|
|
{
|
|
|
|
/* Single plasma gun */
|
|
|
|
case 0:
|
|
|
|
dart->guns[0].type = BT_PLASMA;
|
|
|
|
dart->guns[0].x = dart->guns[0].y = 0;
|
|
|
|
|
|
|
|
for (i = 1 ; i < MAX_FIGHTER_GUNS ; i++)
|
|
|
|
{
|
|
|
|
if (dart->guns[i].type)
|
|
|
|
{
|
|
|
|
dart->guns[i].type = BT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Dual plasma guns */
|
|
|
|
case 1:
|
|
|
|
dart->guns[0].type = BT_PLASMA;
|
|
|
|
dart->guns[1].type = BT_PLASMA;
|
|
|
|
|
|
|
|
for (i = 2 ; i < MAX_FIGHTER_GUNS ; i++)
|
|
|
|
{
|
|
|
|
if (dart->guns[i].type)
|
|
|
|
{
|
|
|
|
dart->guns[i].type = BT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Triple particle guns */
|
|
|
|
case 2:
|
|
|
|
dart->guns[2].type = BT_PARTICLE;
|
|
|
|
dart->guns[2].y = -10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-11-15 00:19:17 +01:00
|
|
|
attachRope();
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
self->reload = MAX(self->reload - 1, 0);
|
|
|
|
self->shieldRecharge = MAX(self->shieldRecharge - 1, 0);
|
|
|
|
self->armourHit = MAX(self->armourHit - 25, 0);
|
|
|
|
self->shieldHit = MAX(self->shieldHit - 5, 0);
|
|
|
|
self->systemHit = MAX(self->systemHit - 25, 0);
|
2015-10-20 13:51:49 +02: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
|
|
|
}
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
if (!self->shieldRecharge)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-27 08:24:17 +01:00
|
|
|
self->shield = MIN(self->shield + 1, self->maxShield);
|
|
|
|
self->shieldRecharge = self->shieldRechargeRate;
|
2015-10-20 13:51:49 +02: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();
|
2015-10-20 13:51:49 +02: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;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-11-14 17:14:48 +01:00
|
|
|
if ((self->flags & EF_DISABLED) == 0)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-11-14 17:14:48 +01:00
|
|
|
self->flags |= EF_DISABLED;
|
2015-10-27 08:24:17 +01:00
|
|
|
updateObjective(self->name, TT_DISABLE);
|
2015-10-26 20:16:12 +01:00
|
|
|
battle.stats[STAT_DISABLED]++;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
}
|
|
|
|
|
2015-11-11 23:34:48 +01:00
|
|
|
if (self->alive == ALIVE_ESCAPED)
|
|
|
|
{
|
|
|
|
if (self->side != SIDE_ALLIES)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.red, "Mission target has escaped.");
|
|
|
|
battle.stats[STAT_ENEMIES_ESCAPED]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
battle.stats[STAT_ALLIES_ESCAPED]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateObjective(self->name, TT_ESCAPED);
|
|
|
|
|
|
|
|
updateCondition(self->name, TT_ESCAPED);
|
|
|
|
|
|
|
|
checkTrigger("ESCAPE", TRIGGER_ESCAPES);
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
if (self->alive == ALIVE_DEAD)
|
2015-10-26 20:16:12 +01:00
|
|
|
{
|
2015-10-27 08:24:17 +01:00
|
|
|
if (self == player)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-26 20:16:12 +01:00
|
|
|
battle.stats[STAT_PLAYER_KILLED]++;
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2015-10-26 20:16:12 +01:00
|
|
|
else if (player != NULL)
|
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
|
|
|
{
|
2015-10-26 20:16:12 +01:00
|
|
|
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-10-26 20:16:12 +01:00
|
|
|
battle.stats[STAT_ALLIES_KILLED]++;
|
|
|
|
|
2015-11-01 12:37:12 +01:00
|
|
|
if (!battle.epic)
|
|
|
|
{
|
2015-11-13 17:55:49 +01:00
|
|
|
if (self->flags & EF_CIVILIAN)
|
|
|
|
{
|
|
|
|
addHudMessage(colors.red, "Civilian has been killed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addHudMessage(colors.red, "Ally has been killed");
|
|
|
|
}
|
2015-11-01 12:37:12 +01:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
updateObjective(self->name, TT_DESTROY);
|
2015-11-13 17:55:49 +01:00
|
|
|
adjustObjectiveTargetValue(self->name, TT_ESCAPED, -1);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
updateCondition(self->name, TT_DESTROY);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-27 08:24:17 +01:00
|
|
|
checkTrigger(self->name, TRIGGER_KILLS);
|
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;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
dx = dy = 0;
|
|
|
|
count = 0;
|
|
|
|
force = 0;
|
|
|
|
|
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);
|
2015-11-02 13:14:29 +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-11-11 07:46:58 +01:00
|
|
|
if (e->type == ET_FIGHTER)
|
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);
|
2015-11-02 13:14:29 +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);
|
|
|
|
|
|
|
|
dx += sin(TO_RAIDANS(angle));
|
|
|
|
dy += -cos(TO_RAIDANS(angle));
|
|
|
|
force += (self->separationRadius - distance) * 0.005;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
dx /= count;
|
|
|
|
dy /= count;
|
|
|
|
|
|
|
|
dx *= force;
|
|
|
|
dy *= force;
|
|
|
|
|
|
|
|
self->dx -= dx;
|
|
|
|
self->dy -= dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
void drawFighter(Entity *e)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
SDL_Texture *shieldHitTexture = getTexture("gfx/battle/shieldHit.png");
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
SDL_SetTextureColorMod(e->texture, 255, 255, 255);
|
|
|
|
|
|
|
|
if (e->armourHit > 0)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-26 20:16:12 +01:00
|
|
|
SDL_SetTextureColorMod(e->texture, 255, 255 - e->armourHit, 255 - e->armourHit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->systemHit > 0)
|
|
|
|
{
|
|
|
|
SDL_SetTextureColorMod(e->texture, 255 - e->systemHit, 255, 255);
|
|
|
|
}
|
|
|
|
|
2015-11-01 00:09:43 +01:00
|
|
|
blitRotated(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->angle);
|
2015-10-26 20:16:12 +01:00
|
|
|
|
|
|
|
if (e->shieldHit > 0)
|
|
|
|
{
|
|
|
|
SDL_SetTextureBlendMode(shieldHitTexture, SDL_BLENDMODE_BLEND);
|
|
|
|
SDL_SetTextureAlphaMod(shieldHitTexture, e->shieldHit);
|
2015-11-01 00:09:43 +01:00
|
|
|
blit(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.y, 1);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyFighterThrust(void)
|
|
|
|
{
|
|
|
|
float v;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy));
|
|
|
|
}
|
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
void damageFighter(Entity *f, int amount, long flags)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-21 20:21:45 +02:00
|
|
|
if (flags & BF_SYSTEM_DAMAGE)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-21 20:21:45 +02:00
|
|
|
f->systemPower = MAX(0, f->systemPower - amount);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-21 20:21:45 +02:00
|
|
|
f->systemHit = 255;
|
|
|
|
|
|
|
|
if (f->systemPower == 0)
|
|
|
|
{
|
|
|
|
f->shield = f->maxShield = 0;
|
2015-11-15 14:26:34 +01:00
|
|
|
f->action = NULL;
|
2015-10-21 20:21:45 +02:00
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
2015-10-21 20:21:45 +02:00
|
|
|
else
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
2015-10-21 20:21:45 +02:00
|
|
|
f->shield -= amount;
|
|
|
|
|
|
|
|
if (f->shield < 0)
|
|
|
|
{
|
|
|
|
f->health -= abs(f->shield);
|
|
|
|
f->shield = 0;
|
|
|
|
f->armourHit = 255;
|
|
|
|
|
|
|
|
playBattleSound(SND_ARMOUR_HIT, f->x, f->y);
|
|
|
|
}
|
|
|
|
else if (f->shield > 0)
|
|
|
|
{
|
|
|
|
f->shieldHit = 255;
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void die(void)
|
|
|
|
{
|
|
|
|
int n = rand() % 3;
|
|
|
|
if (self == player)
|
|
|
|
{
|
|
|
|
n = rand() % 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
self->action = straightDie;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
self->action = spinDie;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
self->action = immediateDie;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void immediateDie(void)
|
|
|
|
{
|
|
|
|
self->alive = ALIVE_DEAD;
|
|
|
|
addFighterExplosion();
|
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
self->angle += 8;
|
|
|
|
|
|
|
|
if (rand() % 2 == 0)
|
|
|
|
{
|
|
|
|
addSmallFighterExplosion();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
addFighterExplosion();
|
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
if (rand() % 2 == 0)
|
|
|
|
{
|
|
|
|
addSmallFighterExplosion();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
addFighterExplosion();
|
|
|
|
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
|
|
|
|
}
|
|
|
|
}
|
2015-11-15 14:26:34 +01:00
|
|
|
|
|
|
|
void fleeAllEnemies(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
|
|
|
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->type == ET_FIGHTER && e->side != SIDE_ALLIES)
|
|
|
|
{
|
|
|
|
e->flags |= EF_ALWAYS_FLEES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 18:23:56 +01:00
|
|
|
|
|
|
|
Entity *getFighterDef(char *name)
|
|
|
|
{
|
|
|
|
Entity *f;
|
|
|
|
|
|
|
|
for (f = defHead.next ; f != NULL ; f = f->next)
|
|
|
|
{
|
|
|
|
if (strcmp(f->name, name) == 0)
|
|
|
|
{
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Error: no such fighter '%s'\n", name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadFighterDefs(void)
|
|
|
|
{
|
|
|
|
cJSON *root, *node;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = readFile("data/fighters/list.json");
|
|
|
|
root = cJSON_Parse(text);
|
|
|
|
|
|
|
|
memset(&defHead, 0, sizeof(Entity));
|
|
|
|
defTail = &defHead;
|
|
|
|
|
|
|
|
for (node = root->child ; node != NULL ; node = node->next)
|
|
|
|
{
|
|
|
|
loadFighterDef(node->valuestring);
|
|
|
|
}
|
|
|
|
|
|
|
|
cJSON_Delete(root);
|
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadFighterDef(char *filename)
|
|
|
|
{
|
|
|
|
cJSON *root, *node;
|
|
|
|
char *text;
|
|
|
|
Entity *f;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
|
|
|
|
|
|
|
text = readFile(filename);
|
|
|
|
|
|
|
|
f = malloc(sizeof(Entity));
|
|
|
|
memset(f, 0, sizeof(Entity));
|
|
|
|
defTail->next = f;
|
|
|
|
defTail = f;
|
|
|
|
|
|
|
|
f->type = ET_FIGHTER;
|
|
|
|
f->active = 1;
|
|
|
|
|
|
|
|
root = cJSON_Parse(text);
|
|
|
|
|
|
|
|
STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
STRNCPY(f->defName, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
f->health = f->maxHealth = cJSON_GetObjectItem(root, "health")->valueint;
|
|
|
|
f->shield = f->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
|
|
|
|
f->speed = cJSON_GetObjectItem(root, "speed")->valuedouble;
|
|
|
|
f->reloadTime = cJSON_GetObjectItem(root, "reloadTime")->valueint;
|
|
|
|
f->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
|
|
|
|
f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring);
|
|
|
|
|
|
|
|
SDL_QueryTexture(f->texture, NULL, NULL, &f->w, &f->h);
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(root, "guns"))
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
for (node = cJSON_GetObjectItem(root, "guns")->child ; node != NULL ; node = node->next)
|
|
|
|
{
|
|
|
|
f->guns[i].type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
|
|
|
f->guns[i].x = cJSON_GetObjectItem(node, "x")->valueint;
|
|
|
|
f->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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(root, "combinedGuns"))
|
|
|
|
{
|
|
|
|
f->combinedGuns = cJSON_GetObjectItem(root, "combinedGuns")->valueint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f->selectedGunType = f->guns[0].type;
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(root, "missiles"))
|
|
|
|
{
|
|
|
|
node = cJSON_GetObjectItem(root, "missiles");
|
|
|
|
|
|
|
|
f->missiles.type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
|
|
|
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(root, "flags"))
|
|
|
|
{
|
|
|
|
f->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring);
|
|
|
|
}
|
|
|
|
|
|
|
|
f->separationRadius = MAX(f->w, f->h);
|
|
|
|
f->separationRadius *= 2;
|
|
|
|
|
|
|
|
/* all craft default to 100 system power */
|
|
|
|
f->systemPower = 100;
|
|
|
|
|
|
|
|
cJSON_Delete(root);
|
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroyFighterDefs(void)
|
|
|
|
{
|
|
|
|
Entity *f;
|
|
|
|
|
|
|
|
while (defHead.next)
|
|
|
|
{
|
|
|
|
f = defHead.next;
|
|
|
|
defHead.next = f->next;
|
|
|
|
free(f);
|
|
|
|
}
|
|
|
|
}
|