2018-01-25 09:11:45 +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 "teeka.h"
|
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
static void (*superTick)(void);
|
2018-01-25 09:11:45 +01:00
|
|
|
static void tick(void);
|
|
|
|
static void lookForEnemies(void);
|
|
|
|
static void preFire(void);
|
|
|
|
static void attack(void);
|
|
|
|
|
|
|
|
static Entity *target;
|
2018-01-30 00:00:14 +01:00
|
|
|
static Sprite *aimedSprite;
|
2018-01-25 09:11:45 +01:00
|
|
|
static int exitMission;
|
|
|
|
|
2018-02-10 08:56:28 +01:00
|
|
|
Entity *initTeeka(void)
|
2018-01-25 09:11:45 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Unit *u;
|
|
|
|
|
2018-01-29 23:12:18 +01:00
|
|
|
u = createUnit();
|
2018-01-28 09:30:53 +01:00
|
|
|
|
|
|
|
u->type = ET_TEEKA;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->flags |= EF_IMMUNE;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->action = lookForEnemies;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->weaponType = WPN_AIMED_PISTOL;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
u->sprite[FACING_LEFT] = getSprite("TeekaLeft");
|
|
|
|
u->sprite[FACING_RIGHT] = getSprite("TeekaRight");
|
|
|
|
u->sprite[FACING_DIE] = getSprite("TeekaLeft");
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-29 23:12:18 +01:00
|
|
|
u->health = u->healthMax = 9999;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
superTick = u->tick;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->tick = tick;
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
aimedSprite = getSprite("AimedShot");
|
2018-02-10 08:56:28 +01:00
|
|
|
|
|
|
|
return (Entity*)u;
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tick(void)
|
|
|
|
{
|
|
|
|
self->health = self->healthMax = 9999;
|
|
|
|
|
|
|
|
if (target != NULL)
|
|
|
|
{
|
|
|
|
self->facing = (target->x < self->x) ? FACING_LEFT : FACING_RIGHT;
|
|
|
|
|
|
|
|
if (target->alive == ALIVE_DEAD)
|
|
|
|
{
|
|
|
|
target = NULL;
|
|
|
|
|
2018-01-26 08:56:12 +01:00
|
|
|
self->action = lookForEnemies;
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
superTick();
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lookForEnemies(void)
|
|
|
|
{
|
|
|
|
Entity *e;
|
|
|
|
float distance, range;
|
2018-01-28 09:30:53 +01:00
|
|
|
Unit *u;
|
|
|
|
|
|
|
|
u = (Unit*)self;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->thinkTime = rrnd(FPS / 2, FPS);
|
2018-01-25 09:11:45 +01:00
|
|
|
|
|
|
|
target = NULL;
|
|
|
|
|
|
|
|
distance = 800;
|
|
|
|
|
|
|
|
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
|
|
|
{
|
|
|
|
if (e->type == ET_ENEMY)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
range = getDistance(u->x, u->y, e->x, e->y);
|
2018-01-25 09:11:45 +01:00
|
|
|
|
|
|
|
if (range < distance)
|
|
|
|
{
|
|
|
|
if (hasLineOfSight(self, e))
|
|
|
|
{
|
|
|
|
target = e;
|
|
|
|
distance = range;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target != NULL)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
u->shotsToFire = rrnd(3, 5);
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->action = preFire;
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
else if (exitMission)
|
|
|
|
{
|
|
|
|
addTeleportStars(self);
|
2018-01-28 09:30:53 +01:00
|
|
|
u->alive = ALIVE_DEAD;
|
2018-02-25 18:29:44 +01:00
|
|
|
playSound(SND_APPEAR, u->uniqueId % MAX_SND_CHANNELS);
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
u->facing = rand() % 2 == 0 ? FACING_LEFT : FACING_RIGHT;
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void preFire(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Unit *u;
|
|
|
|
|
|
|
|
u = (Unit*)self;
|
|
|
|
|
|
|
|
if (u->reload > 0)
|
2018-01-25 09:11:45 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (target->y < u->y && u->isOnGround && rand() % 10 == 0)
|
2018-01-25 09:11:45 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
u->dy = JUMP_POWER;
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
attack();
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
u->shotsToFire--;
|
2018-01-25 09:11:45 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (u->shotsToFire == 0)
|
2018-01-25 09:11:45 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
u->thinkTime = FPS;
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void attack(void)
|
|
|
|
{
|
2018-01-27 09:13:50 +01:00
|
|
|
Bullet *bullet;
|
2018-01-25 09:11:45 +01:00
|
|
|
float dx, dy;
|
|
|
|
|
|
|
|
getSlope(target->x, target->y, self->x, self->y, &dx, &dy);
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
bullet = createBaseBullet((Unit*)self);
|
2018-01-25 09:11:45 +01:00
|
|
|
bullet->x = self->x;
|
|
|
|
bullet->y = (self->y + self->h / 2) - 3;
|
|
|
|
bullet->facing = self->facing;
|
|
|
|
bullet->damage = 1;
|
|
|
|
bullet->owner = self;
|
|
|
|
bullet->health = FPS * 3;
|
|
|
|
bullet->weaponType = WPN_AIMED_PISTOL;
|
|
|
|
bullet->dx = dx * 9;
|
|
|
|
bullet->dy = dy * 9;
|
|
|
|
bullet->sprite[0] = bullet->sprite[1] = aimedSprite;
|
|
|
|
bullet->health *= 2;
|
|
|
|
|
2018-02-11 15:10:15 +01:00
|
|
|
((Unit*)self)->reload = 8;
|
|
|
|
|
2018-02-25 18:29:44 +01:00
|
|
|
playSound(SND_PISTOL, self->uniqueId % MAX_SND_CHANNELS);
|
2018-01-25 09:11:45 +01:00
|
|
|
}
|
2018-01-26 23:29:08 +01:00
|
|
|
|
|
|
|
void teekaExitMission(void)
|
|
|
|
{
|
|
|
|
exitMission = 1;
|
|
|
|
}
|