Various tweaks and refactoring to accomodate capital ships.

This commit is contained in:
Steve 2015-12-07 19:19:41 +00:00
parent 6084251e9f
commit 6441f926e2
34 changed files with 139 additions and 85 deletions

View File

@ -6,7 +6,6 @@
"reloadTime" : 8,
"shieldRechargeRate" : 5,
"textureName" : "gfx/fighters/ataf.png",
"flags" : "EF_NO_EPIC",
"guns" : [
{
"type" : "BT_PLASMA",
@ -59,5 +58,6 @@
"y" : 0
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_NO_EPIC+EF_TAKES_DAMAGE"
}

View File

@ -17,5 +17,6 @@
"x" : 8,
"y" : 0
}
]
],
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -6,6 +6,6 @@
"reloadTime" : 0,
"shieldRechargeRate" : 0,
"textureName" : "gfx/craft/civilian01.png",
"flags" : "EF_MISSION_TARGET+EF_RETREATING",
"flags" : "EF_MISSION_TARGET+EF_RETREATING+EF_TAKES_DAMAGE",
"aiFlags" : "AIF_GOAL_EXTRACTION+AIF_AVOIDS_COMBAT+AIF_FOLLOWS_PLAYER"
}

View File

@ -18,5 +18,6 @@
"y" : 0
}
],
"missiles" : 2
"missiles" : 2,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -24,5 +24,6 @@
}
],
"combinedGuns" : 1,
"missiles" : 3
"missiles" : 3,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -24,5 +24,6 @@
}
],
"missiles" : 6,
"flags" : "EF_TAKES_DAMAGE",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE"
}

View File

@ -28,5 +28,6 @@
"y" : -12
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -28,5 +28,6 @@
"y" : -12
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -18,5 +18,6 @@
"y" : 0
}
],
"missiles" : 3
"missiles" : 3,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -29,5 +29,6 @@
}
],
"missiles" : 8,
"flags" : "EF_TAKES_DAMAGE",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE"
}

View File

@ -28,5 +28,6 @@
"y" : -12
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -23,5 +23,6 @@
"y" : -16
}
],
"missiles" : 3
"missiles" : 3,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -29,5 +29,6 @@
}
],
"combinedGuns" : 1,
"missiles" : 6
"missiles" : 6,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -6,5 +6,6 @@
"reloadTime" : 24,
"shieldRechargeRate" : 0,
"textureName" : "gfx/fighters/dart01.png",
"missiles" : 999
"missiles" : 999,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -18,5 +18,6 @@
"y" : -2
}
],
"missiles" : 3
"missiles" : 3,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -28,5 +28,6 @@
"y" : -12
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -13,6 +13,6 @@
"y" : 0
}
],
"flags" : "EF_STATIC",
"flags" : "EF_STATIC+EF_TAKES_DAMAGE",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_AGGRESSIVE+AIF_INSTANT_DIE"
}

View File

@ -28,5 +28,6 @@
"y" : 0
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -24,5 +24,6 @@
}
],
"missiles" : 8,
"flags" : "EF_TAKES_DAMAGE",
"aiFlags" : "AIF_MISSILE_BOAT+AIF_DEFENSIVE"
}

View File

@ -6,6 +6,6 @@
"reloadTime" : 0,
"shieldRechargeRate" : 60,
"textureName" : "gfx/craft/shuttle.png",
"flags" : "EF_COLLECTS_ITEMS",
"flags" : "EF_COLLECTS_ITEMS+EF_TAKES_DAMAGE",
"aiFlags" : "AIF_AVOIDS_COMBAT+AIF_COLLECTS_ITEMS"
}

View File

@ -18,5 +18,6 @@
"y" : 0
}
],
"missiles" : 2
"missiles" : 2,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -28,5 +28,6 @@
"y" : 0
}
],
"missiles" : 2
"missiles" : 2,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -5,5 +5,6 @@
"speed" : 0,
"reloadTime" : 24,
"shieldRechargeRate" : 0,
"textureName" : "gfx/fighters/dart01.png"
"textureName" : "gfx/fighters/dart01.png",
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -18,5 +18,6 @@
"y" : -12
}
],
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -34,5 +34,6 @@
}
],
"combinedGuns" : 1,
"missiles" : 4
"missiles" : 4,
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -13,6 +13,6 @@
"y" : 0
}
],
"flags" : "EF_HAS_ROPE",
"flags" : "EF_HAS_ROPE+EF_TAKES_DAMAGE",
"aiFlags" : "AIF_AVOIDS_COMBAT+AIF_TOWS"
}

View File

@ -5,5 +5,6 @@
"speed" : 2.1,
"reloadTime" : 24,
"shieldRechargeRate" : 0,
"textureName" : "gfx/fighters/dart01.png"
"textureName" : "gfx/fighters/dart01.png",
"flags" : "EF_TAKES_DAMAGE"
}

View File

@ -169,10 +169,10 @@ static void draw(void)
blit(battle.planetTexture, battle.planet.x - battle.camera.x, battle.planet.y - battle.camera.y, 1);
drawBullets();
drawEntities();
drawBullets();
drawEffects();
drawHud();

View File

@ -134,7 +134,7 @@ static void checkCollisions(Bullet *b)
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
{
if (e->type == ET_FIGHTER)
if (e->flags & EF_TAKES_DAMAGE)
{
if (b->owner != e && e->health > 0 && collision(b->x - b->w / 2, b->y - b->h / 2, b->w, b->h, e->x - e->w / 2, e->y - e->h / 2, e->w, e->h))
{

View File

@ -140,7 +140,7 @@ void addSmallFighterExplosion(void)
e->y -= e->size / 2;
}
void addFighterExplosion(void)
void addSmallExplosion(void)
{
int i;
Effect *e;

View File

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void drawEntity(Entity *e);
static void doEntity(void);
static void alignComponents(void);
static void drawEntity(Entity *e);
static void activateEpicFighters(int n, int side);
static void restrictToGrid(Entity *e);
@ -59,6 +60,12 @@ void doEntities(void)
removeFromGrid(e);
e->reload = MAX(e->reload - 1, 0);
e->shieldRecharge = MAX(e->shieldRecharge - 1, 0);
e->armourHit = MAX(e->armourHit - 25, 0);
e->shieldHit = MAX(e->shieldHit - 5, 0);
e->systemHit = MAX(e->systemHit - 25, 0);
switch (e->type)
{
case ET_FIGHTER:
@ -75,7 +82,6 @@ void doEntities(void)
numActiveEnemies++;
}
}
break;
default:
@ -170,6 +176,8 @@ void doEntities(void)
activateEpicFighters(battle.epicFighterLimit - numActiveEnemies, SIDE_NONE);
}
}
alignComponents();
}
static void restrictToGrid(Entity *e)
@ -207,13 +215,60 @@ static void restrictToGrid(Entity *e)
static void doEntity(void)
{
if (self->alive == ALIVE_DYING)
if (self->die)
{
self->alive = ALIVE_DEAD;
if (self->health <= 0 && self->die && self->alive == ALIVE_ALIVE)
{
self->health = 0;
self->alive = ALIVE_DYING;
self->die();
if (self == battle.missionTarget)
{
battle.missionTarget = NULL;
}
}
}
else if (self->health <= 0)
else
{
self->alive = ALIVE_DYING;
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;
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{
if (e->type == ET_CAPITAL_SHIP_COMPONENT || e->type == ET_CAPITAL_SHIP_GUN)
{
s = sin(TO_RAIDANS(e->owner->angle));
c = cos(TO_RAIDANS(e->owner->angle));
x = (e->offsetX * c) - (e->offsetY * s);
y = (e->offsetX * s) + (e->offsetY * c);
x += e->owner->x;
y += e->owner->y;
e->x = x;
e->y = y;
if (e->owner->alive == ALIVE_DYING)
{
e->alive = ALIVE_DEAD;
}
}
}
}
@ -233,16 +288,7 @@ void drawEntities(void)
{
if (e->active)
{
switch (e->type)
{
case ET_FIGHTER:
drawFighter(e);
break;
default:
drawEntity(e);
break;
}
drawEntity(e);
}
drawTargetRects(e);
@ -253,7 +299,26 @@ void drawEntities(void)
static void drawEntity(Entity *e)
{
SDL_SetTextureColorMod(e->texture, 255, 255, 255);
if (e->armourHit > 0)
{
SDL_SetTextureColorMod(e->texture, 255, 255 - e->armourHit, 255 - e->armourHit);
}
if (e->systemHit > 0)
{
SDL_SetTextureColorMod(e->texture, 255 - e->systemHit, 255, 255);
}
blitRotated(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->angle);
if (e->shieldHit > 0)
{
drawShieldHitEffect(e);
}
SDL_SetTextureColorMod(e->texture, 255, 255, 255);
}
static void drawTargetRects(Entity *e)

View File

@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h"
extern void blitRotated(SDL_Texture *t, int x, int y, int angle);
extern void drawFighter(Entity *e);
extern void doFighter(void);
extern void addToGrid(Entity *e);
extern void removeFromGrid(Entity *e);
@ -29,6 +28,7 @@ extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern void doRope(Entity *e);
extern void drawRope(Entity *e);
extern void cutRope(Entity *e);
extern void drawShieldHitEffect(Entity *e);
extern App app;
extern Battle battle;

View File

@ -28,6 +28,7 @@ static void straightDie(void);
static void randomizeDart(Entity *dart);
static void randomizeDartGuns(Entity *dart);
static void loadFighterDef(char *filename);
static Entity *getFighterDef(char *name);
static Entity defHead, *defTail;
@ -188,12 +189,6 @@ void doFighter(void)
attachRope();
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);
if (self->thrust > 0.25)
{
addEngineEffect();
@ -361,30 +356,6 @@ static void separate(void)
}
}
void drawFighter(Entity *e)
{
SDL_SetTextureColorMod(e->texture, 255, 255, 255);
if (e->armourHit > 0)
{
SDL_SetTextureColorMod(e->texture, 255, 255 - e->armourHit, 255 - e->armourHit);
}
if (e->systemHit > 0)
{
SDL_SetTextureColorMod(e->texture, 255 - e->systemHit, 255, 255);
}
blitRotated(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->angle);
if (e->shieldHit > 0)
{
drawShieldHitEffect(e);
}
SDL_SetTextureColorMod(e->texture, 255, 255, 255);
}
void applyFighterThrust(void)
{
float v;
@ -496,7 +467,7 @@ static void die(void)
static void immediateDie(void)
{
self->alive = ALIVE_DEAD;
addFighterExplosion();
addSmallExplosion();
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
}
@ -518,7 +489,7 @@ static void spinDie(void)
if (self->health <= -(FPS * 1.5))
{
self->alive = ALIVE_DEAD;
addFighterExplosion();
addSmallExplosion();
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
}
}
@ -539,7 +510,7 @@ static void straightDie(void)
if (self->health <= -(FPS * 1.5))
{
self->alive = ALIVE_DEAD;
addFighterExplosion();
addSmallExplosion();
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
}
}
@ -576,7 +547,7 @@ void retreatAllies(void)
}
}
Entity *getFighterDef(char *name)
static Entity *getFighterDef(char *name)
{
Entity *f;
@ -634,7 +605,7 @@ static void loadFighterDef(char *filename)
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);
STRNCPY(f->defName, f->name, 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;

View File

@ -24,17 +24,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern SDL_Texture *getTexture(char *filename);
extern void doAI(void);
extern void blitRotated(SDL_Texture *t, int x, int y, int angle);
extern void blit(SDL_Texture *t, int x, int y, int center);
extern float getAngle(int x1, int y1, int x2, int y2);
extern int getDistance(int x1, int y1, int x2, int y2);
extern void addEngineEffect(void);
extern void addFighterExplosion(void);
extern void addSmallExplosion(void);
extern void addSmallFighterExplosion(void);
extern void playBattleSound(int id, int x, int y);
extern void updateObjective(char *name, int type);
extern void updateCondition(char *name, int type);
extern Entity *getFighterDef(char *name);
extern void addHudMessage(SDL_Color c, char *format, ...);
extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
extern Entity *spawnEntity(void);
@ -45,7 +42,6 @@ extern long lookup(char *name);
extern long flagsToLong(char *flags);
extern void addShieldSplinterEffect(Entity *ent);
extern void completeMission(void);
extern void drawShieldHitEffect(Entity *e);
extern void runScriptFunction(char *format, ...);
extern char *getFileLocation(char *filename);