2018-01-25 08:41:10 +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 "mia.h"
|
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
static void init(void);
|
2018-01-25 08:41:10 +01:00
|
|
|
static void reset(void);
|
|
|
|
static void tick(void);
|
|
|
|
static void touch(Entity *other);
|
|
|
|
static void preTeleport(void);
|
|
|
|
static void teleport(void);
|
2018-01-30 23:47:40 +01:00
|
|
|
static void load(cJSON *root);
|
|
|
|
static void save(cJSON *root);
|
2018-01-25 08:41:10 +01:00
|
|
|
|
2018-01-30 09:29:09 +01:00
|
|
|
Entity *initMIA(void)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
MIA *m;
|
|
|
|
|
2018-01-29 23:12:18 +01:00
|
|
|
m = malloc(sizeof(MIA));
|
|
|
|
memset(m, 0, sizeof(MIA));
|
2018-01-28 09:30:53 +01:00
|
|
|
|
2018-01-30 09:29:09 +01:00
|
|
|
initEntity((Entity*)m);
|
|
|
|
|
2018-01-28 10:34:14 +01:00
|
|
|
m->type = ET_MIA;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
m->tx = m->ty = -1;
|
2018-01-25 08:41:10 +01:00
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
m->sprite[FACING_LEFT] = getSprite("MIA");
|
|
|
|
m->sprite[FACING_RIGHT] = getSprite("MIA");
|
|
|
|
m->sprite[FACING_DIE] = getSprite("MIA");
|
2018-01-25 08:41:10 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
m->flags |= EF_IGNORE_BULLETS;
|
2018-01-25 08:41:10 +01:00
|
|
|
|
|
|
|
/* blink at random intervals */
|
2018-01-28 09:30:53 +01:00
|
|
|
m->spriteFrame = 0;
|
|
|
|
m->spriteTime = rand() % 180;
|
2018-01-25 08:41:10 +01:00
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
m->init = init;
|
2018-01-28 09:30:53 +01:00
|
|
|
m->reset = reset;
|
|
|
|
m->tick = tick;
|
|
|
|
m->touch = touch;
|
2018-01-30 23:47:40 +01:00
|
|
|
m->load = load;
|
|
|
|
m->save = save;
|
2018-01-25 08:41:10 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
m->isMissionTarget = 1;
|
2018-01-30 09:29:09 +01:00
|
|
|
|
|
|
|
return (Entity*)m;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
static void init(void)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-02-01 08:50:37 +01:00
|
|
|
if (self->tx == -1 && self->ty == -1)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-02-01 08:50:37 +01:00
|
|
|
self->tx = self->x;
|
|
|
|
self->ty = self->y;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset(void)
|
|
|
|
{
|
|
|
|
self->tx = self->ty = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tick(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
MIA *m;
|
|
|
|
|
|
|
|
m = (MIA*)self;
|
|
|
|
|
2018-03-08 08:52:42 +01:00
|
|
|
if (--m->shudderTimer <= 0)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
m->x = (m->tx + rand() % 4);
|
|
|
|
m->shudderTimer = 2;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
|
|
|
|
2018-02-04 09:11:42 +01:00
|
|
|
if (!m->isMissionTarget)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-03-08 08:52:42 +01:00
|
|
|
if (--m->starTimer <= 0)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
addMIATeleportStars(m->x + rand() % m->w, m->y + rand() % m->h);
|
|
|
|
m->starTimer = 1;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
2018-03-08 08:52:42 +01:00
|
|
|
|
|
|
|
world.saveDelay = FPS;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void touch(Entity *other)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
MIA *m;
|
|
|
|
|
|
|
|
m = (MIA*)self;
|
|
|
|
|
2018-02-04 09:11:42 +01:00
|
|
|
if (m->isMissionTarget && other == (Entity*)world.bob)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
m->action = preTeleport;
|
|
|
|
m->teleportTimer = FPS * 3;
|
2018-04-01 18:41:45 +02:00
|
|
|
setGameplayMessage(MSG_OBJECTIVE, app.strings[ST_RESCUED], m->name);
|
2018-01-28 09:30:53 +01:00
|
|
|
m->isMissionTarget = 0;
|
|
|
|
m->flags |= EF_ALWAYS_PROCESS;
|
2018-03-05 09:38:59 +01:00
|
|
|
m->plane = PLANE_FOREGROUND;
|
2018-02-25 18:29:44 +01:00
|
|
|
playSound(SND_MIA, m->uniqueId % MAX_SND_CHANNELS);
|
2018-03-18 13:48:52 +01:00
|
|
|
game.stats[STAT_MIAS_RESCUED]++;
|
|
|
|
updateObjective("MIA");
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void preTeleport(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
MIA *m;
|
|
|
|
|
|
|
|
m = (MIA*)self;
|
|
|
|
|
2018-02-13 22:36:42 +01:00
|
|
|
if (--m->teleportTimer <= FPS)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
m->action = teleport;
|
|
|
|
m->flags |= (EF_NO_CLIP | EF_WEIGHTLESS);
|
|
|
|
m->dy = -5;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
2018-03-08 08:52:42 +01:00
|
|
|
|
|
|
|
world.saveDelay = FPS;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void teleport(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
MIA *m;
|
|
|
|
|
|
|
|
m = (MIA*)self;
|
|
|
|
|
2018-02-13 22:36:42 +01:00
|
|
|
if (--m->teleportTimer <= 0)
|
2018-01-25 08:41:10 +01:00
|
|
|
{
|
|
|
|
addTeleportStars(self);
|
2018-01-28 09:30:53 +01:00
|
|
|
m->alive = ALIVE_DEAD;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
2018-03-08 08:52:42 +01:00
|
|
|
|
|
|
|
world.saveDelay = FPS;
|
2018-01-25 08:41:10 +01:00
|
|
|
}
|
2018-01-30 23:47:40 +01:00
|
|
|
|
|
|
|
static void load(cJSON *root)
|
|
|
|
{
|
|
|
|
MIA *m;
|
|
|
|
|
|
|
|
m = (MIA*)self;
|
|
|
|
|
|
|
|
m->active = cJSON_GetObjectItem(root, "isMissionTarget")->valueint;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save(cJSON *root)
|
|
|
|
{
|
|
|
|
MIA *m;
|
|
|
|
|
|
|
|
m = (MIA*)self;
|
|
|
|
|
|
|
|
cJSON_AddStringToObject(root, "type", "MIA");
|
|
|
|
cJSON_AddNumberToObject(root, "isMissionTarget", m->isMissionTarget);
|
|
|
|
}
|