2018-01-30 00:00:14 +01:00
|
|
|
/*
|
2018-01-27 11:32:17 +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 "exit.h"
|
|
|
|
|
2018-02-15 08:49:20 +01:00
|
|
|
static void init(void);
|
2018-01-27 11:32:17 +01:00
|
|
|
static void tick(void);
|
|
|
|
static void action(void);
|
|
|
|
static void touch(Entity *other);
|
2018-02-26 08:38:20 +01:00
|
|
|
static void getCollisionBounds(SDL_Rect *r);
|
2018-02-14 23:31:21 +01:00
|
|
|
static void load(cJSON *root);
|
|
|
|
static void save(cJSON *root);
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-01-30 09:29:09 +01:00
|
|
|
Entity *initExit(void)
|
2018-01-27 11:32:17 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
s = createStructure();
|
2018-01-28 09:30:53 +01:00
|
|
|
|
2018-01-28 10:34:14 +01:00
|
|
|
s->type = ET_EXIT;
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("Exit");
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS;
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->isStatic = 1;
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->active = 0;
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->spriteTime = -1;
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-02-15 08:49:20 +01:00
|
|
|
s->init = init;
|
2018-01-28 09:30:53 +01:00
|
|
|
s->tick = tick;
|
|
|
|
s->action = action;
|
|
|
|
s->touch = touch;
|
2018-02-26 08:38:20 +01:00
|
|
|
s->getCollisionBounds = getCollisionBounds;
|
2018-02-14 23:31:21 +01:00
|
|
|
s->load = load;
|
|
|
|
s->save = save;
|
2018-01-30 09:29:09 +01:00
|
|
|
|
|
|
|
return (Entity*)s;
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 08:49:20 +01:00
|
|
|
static void init(void)
|
|
|
|
{
|
|
|
|
if (!self->active)
|
|
|
|
{
|
|
|
|
self->spriteFrame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->spriteFrame = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->spriteTime = -1;
|
|
|
|
}
|
|
|
|
|
2018-01-27 11:32:17 +01:00
|
|
|
static void tick(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
if (!s->active)
|
2018-01-27 11:32:17 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
s->bobTouching = MAX(s->bobTouching - 1, 0);
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void action(void)
|
|
|
|
{
|
|
|
|
Objective *o;
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
2018-01-27 11:32:17 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (!s->active)
|
2018-01-27 11:32:17 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
s->active = 1;
|
2018-01-27 11:32:17 +01:00
|
|
|
|
|
|
|
for (o = world.objectiveHead.next ; o != NULL ; o = o->next)
|
|
|
|
{
|
|
|
|
if (o->required && strcmp(o->targetName, "EXIT") != 0 && o->currentValue < o->targetValue)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
s->active = 0;
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (s->active)
|
2018-01-27 11:32:17 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
s->spriteFrame = 1;
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->thinkTime = FPS;
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void touch(Entity *other)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
2018-01-27 11:32:17 +01:00
|
|
|
if (other->type == ET_BOB && !world.isReturnVisit)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
if (s->bobTouching == 0)
|
2018-01-27 11:32:17 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
if (s->active)
|
2018-01-27 11:32:17 +01:00
|
|
|
{
|
|
|
|
updateObjective("EXIT");
|
|
|
|
world.missionCompleteTimer = (int) (FPS * 1.5);
|
|
|
|
world.bob->flags |= (EF_IMMUNE | EF_GONE);
|
|
|
|
world.state = WS_COMPLETE;
|
|
|
|
stopMusic();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-28 17:33:37 +01:00
|
|
|
setGameplayMessage(MSG_GAMEPLAY, _("Can't exit yet - required objectives not met"));
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->bobTouching = 2;
|
2018-01-27 11:32:17 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-14 23:31:21 +01:00
|
|
|
|
2018-02-26 08:38:20 +01:00
|
|
|
static void getCollisionBounds(SDL_Rect *r)
|
|
|
|
{
|
|
|
|
r->x = self->x + 64;
|
|
|
|
r->y = self->y;
|
|
|
|
r->w = 2;
|
|
|
|
r->h = self->h;
|
|
|
|
}
|
|
|
|
|
2018-02-14 23:31:21 +01:00
|
|
|
static void load(cJSON *root)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
s->active = cJSON_GetObjectItem(root, "active")->valueint;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save(cJSON *root)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
cJSON_AddNumberToObject(root, "active", s->active);
|
|
|
|
}
|