2018-01-26 19:27:15 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2018 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 "tankCommander.h"
|
|
|
|
|
|
|
|
static void activate(int activate);
|
|
|
|
static void tick(void);
|
|
|
|
static void walk(void);
|
|
|
|
static void attackPistol(void);
|
|
|
|
static void attackMissile(void);
|
|
|
|
static void die1(void);
|
|
|
|
static void die2(void);
|
|
|
|
static void attack(void);
|
|
|
|
static void applyDamage(int amount);
|
|
|
|
static void preFire(void);
|
|
|
|
static void selectWeapon(void);
|
|
|
|
static void moveTowardsPlayer(void);
|
|
|
|
|
|
|
|
static Entity *tankTrack;
|
|
|
|
static int brakingTimer;
|
2018-01-30 00:00:14 +01:00
|
|
|
static Sprite *missileSprite[2];
|
|
|
|
static Sprite *aimedSprite;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
void initTankCommander(Entity *e)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
2018-01-26 19:27:15 +01:00
|
|
|
initBoss(e);
|
2018-01-28 09:30:53 +01:00
|
|
|
|
|
|
|
b = (Boss*)e;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
STRNCPY(e->name, "Tank Commander", MAX_NAME_LENGTH);
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
b->sprite[FACING_LEFT] = getSprite("TankCommanderLeft");
|
|
|
|
b->sprite[FACING_RIGHT] = getSprite("TankCommanderRight");
|
|
|
|
b->sprite[FACING_DIE] = getSprite("TankCommanderDie");
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->flags |= EF_EXPLODES;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->health = e->healthMax = 400;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->activate = activate;
|
|
|
|
b->walk = walk;
|
|
|
|
b->tick = tick;
|
|
|
|
b->die = die1;
|
|
|
|
b->applyDamage = applyDamage;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
brakingTimer = 0;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
world.boss = b;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
aimedSprite = getSprite("AimedShot");
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
missileSprite[0] = getSprite("MissileRight");
|
|
|
|
missileSprite[1] = getSprite("MissileLeft");
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
initTankTrack(tankTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void activate(int activate)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->flags &= ~EF_GONE;
|
2018-01-26 19:27:15 +01:00
|
|
|
tankTrack->flags &= ~EF_GONE;
|
|
|
|
|
|
|
|
world.isBossActive = 1;
|
|
|
|
|
|
|
|
addTeleportStars(self);
|
|
|
|
addTeleportStars(tankTrack);
|
|
|
|
|
|
|
|
playMusic("", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tick(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->health > 0)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->facing = (world.bob->x < b->x) ? FACING_LEFT : FACING_RIGHT;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->reload = limit(b->reload - 1, 0, FPS);
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
brakingTimer = limit(brakingTimer - 1, 0, FPS);
|
|
|
|
|
|
|
|
if (brakingTimer > 0)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->dx *= 0.9;
|
|
|
|
b->dy *= 0.9;
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lookForPlayer(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->thinkTime = rrnd(0, FPS / 2);
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
if (rand() % 10 == 0)
|
|
|
|
{
|
|
|
|
brakingTimer = rrnd(60, 120);
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (getDistance(world.bob->x, world.bob->y, b->x, b->y) > 650)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
|
|
|
moveTowardsPlayer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enemyCanSeePlayer(self))
|
|
|
|
{
|
|
|
|
moveTowardsPlayer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rand() % 100 <15)
|
|
|
|
{
|
|
|
|
selectWeapon();
|
|
|
|
}
|
|
|
|
|
|
|
|
moveTowardsPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void walk(void)
|
|
|
|
{
|
|
|
|
self->action = (self->health > 0) ? lookForPlayer : die1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void moveTowardsPlayer(void)
|
|
|
|
{
|
|
|
|
if (brakingTimer == 0)
|
|
|
|
{
|
|
|
|
if (world.bob->x < self->x)
|
|
|
|
{
|
|
|
|
self->dx -= 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.bob->x > self->x)
|
|
|
|
{
|
|
|
|
self->dx += 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self->dx = limit(self->dx, -7.5, 7.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void selectWeapon(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (abs(b->y - world.bob->y) > 64)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->weaponType = WPN_AIMED_PISTOL;
|
|
|
|
b->shotsToFire = rrnd(4, 12);
|
|
|
|
b->action = preFire;
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->weaponType = WPN_MISSILE;
|
|
|
|
b->shotsToFire = rrnd(1, 3);
|
|
|
|
b->action = preFire;
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void preFire(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
if (b->reload > 0)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
|
|
|
moveTowardsPlayer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
attack();
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->shotsToFire--;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->shotsToFire == 0)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
b->walk();
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void attack(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
switch (b->weaponType)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
|
|
|
case WPN_AIMED_PISTOL:
|
|
|
|
attackPistol();
|
|
|
|
break;
|
|
|
|
case WPN_MISSILE:
|
|
|
|
attackMissile();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void attackPistol(void)
|
|
|
|
{
|
|
|
|
int bx, by;
|
|
|
|
float dx, dy;
|
2018-01-27 09:13:50 +01:00
|
|
|
Bullet *bullet;
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
bx = world.bob->x + rrnd(-8, 24);
|
|
|
|
by = world.bob->y + rrnd(-8, 24);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
getSlope(bx, by, b->x, b->y, &dx, &dy);
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
bullet = createBaseBullet((Unit*)self);
|
|
|
|
bullet->x = (b->x + b->w / 2);
|
|
|
|
bullet->y = b->y + 30;
|
|
|
|
bullet->facing = b->facing;
|
2018-01-26 19:27:15 +01:00
|
|
|
bullet->damage = 1;
|
|
|
|
bullet->owner = self;
|
|
|
|
bullet->health = FPS * 3;
|
|
|
|
bullet->weaponType = WPN_AIMED_PISTOL;
|
|
|
|
bullet->dx = dx * 12;
|
|
|
|
bullet->dy = dy * 12;
|
|
|
|
bullet->sprite[0] = bullet->sprite[1] = aimedSprite;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->reload = 4;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
playSound(SND_MACHINE_GUN, CH_WEAPON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void attackMissile(void)
|
|
|
|
{
|
2018-01-27 09:13:50 +01:00
|
|
|
Bullet *missile;
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
missile = createBaseBullet((Unit*)self);
|
|
|
|
missile->x = b->x + b->w / 2;
|
|
|
|
missile->y = b->y + 30;
|
|
|
|
missile->facing = b->facing;
|
|
|
|
missile->dx = b->facing == FACING_RIGHT ? 15 : -15;
|
2018-01-26 19:27:15 +01:00
|
|
|
missile->dy = world.bob->y - missile->y;
|
|
|
|
missile->dy *= 0.01;
|
|
|
|
missile->owner = self;
|
|
|
|
missile->health = FPS * 3;
|
|
|
|
missile->sprite[0] = missileSprite[0];
|
|
|
|
missile->sprite[1] = missileSprite[1];
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->reload = 15;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
playSound(SND_MISSILE, CH_WEAPON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void die1(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
|
|
|
|
|
|
|
b->flags |= EF_BOUNCES;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->action = die2;
|
|
|
|
b->thinkTime = 0;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->spriteTime = 0;
|
|
|
|
b->spriteFrame = 0;
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void die2(void)
|
|
|
|
{
|
|
|
|
int mx, my;
|
2018-01-28 09:30:53 +01:00
|
|
|
Boss *b;
|
|
|
|
|
|
|
|
b = (Boss*)self;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->health--;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->health % 3 == 0)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
mx = (int) ((b->x + (b->w / 2)) / MAP_TILE_SIZE);
|
|
|
|
my = (int) ((b->y + b->h) / MAP_TILE_SIZE);
|
2018-01-26 19:27:15 +01:00
|
|
|
|
|
|
|
addScorchDecal(mx, my);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
addExplosion(b->x + rand() % b->w, b->y + rand() % b->h, 50, self);
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (b->health <= -100)
|
2018-01-26 19:27:15 +01:00
|
|
|
{
|
|
|
|
addTeleportStars(self);
|
|
|
|
addTeleportStars(tankTrack);
|
|
|
|
|
|
|
|
playSound(SND_APPEAR, CH_ANY);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
b->alive = tankTrack->alive = ALIVE_DEAD;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
updateObjective(b->name);
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-02-13 22:36:42 +01:00
|
|
|
game.stats[STAT_TARGETS_DEFEATED]++;
|
2018-01-26 19:27:15 +01:00
|
|
|
|
2018-02-13 22:36:42 +01:00
|
|
|
awardTrophy("");
|
|
|
|
|
|
|
|
game.stats[STAT_ENEMIES_KILLED]++;
|
2018-01-26 19:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void applyDamage(int amount)
|
|
|
|
{
|
|
|
|
self->health -= amount;
|
|
|
|
|
|
|
|
if (self->health <= 0)
|
|
|
|
{
|
|
|
|
self->health = 0;
|
|
|
|
addExplosion(self->x + self->w / 2, self->y + self->h / 2, 50, self);
|
|
|
|
}
|
|
|
|
}
|