2018-01-27 11:47:53 +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 "itemPad.h"
|
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
static void init(void);
|
2018-01-27 11:47:53 +01:00
|
|
|
static void tick(void);
|
|
|
|
static void touch(Entity *other);
|
2018-02-26 08:38:20 +01:00
|
|
|
static void getCollisionBounds(SDL_Rect *r);
|
2018-02-15 08:48:51 +01:00
|
|
|
static void load(cJSON *root);
|
|
|
|
static void save(cJSON *root);
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
Entity *initItemPad(void)
|
2018-01-27 11:47:53 +01:00
|
|
|
{
|
2018-02-15 08:48:51 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = createStructure();
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
s->type = ET_ITEM_PAD;
|
2018-01-28 10:34:14 +01:00
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
s->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
s->plane = PLANE_FOREGROUND;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
s->isStatic = 1;
|
|
|
|
|
|
|
|
s->init = init;
|
|
|
|
s->tick = tick;
|
|
|
|
s->touch = touch;
|
2018-02-26 08:38:20 +01:00
|
|
|
s->getCollisionBounds = getCollisionBounds;
|
2018-02-15 08:48:51 +01:00
|
|
|
s->load = load;
|
|
|
|
s->save = save;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
return (Entity*)s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init(void)
|
|
|
|
{
|
|
|
|
if (self->active)
|
2018-01-27 11:47:53 +01:00
|
|
|
{
|
2018-02-15 08:48:51 +01:00
|
|
|
self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSprite("ItemPadActive");
|
2018-01-27 11:47:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-15 08:48:51 +01:00
|
|
|
self->sprite[FACING_LEFT] = self->sprite[FACING_RIGHT] = self->sprite[FACING_DIE] = getSprite("ItemPadInactive");
|
2018-01-27 11:47:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tick(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
s->bobTouching = MAX(s->bobTouching - 1, 0);
|
2018-01-27 11:47:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void touch(Entity *other)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
Item *i;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (other->type == ET_BOB && !s->active)
|
2018-01-27 11:47:53 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
i = getItem(s->requiredItem);
|
2018-01-27 11:47:53 +01:00
|
|
|
|
|
|
|
if (i != NULL)
|
|
|
|
{
|
|
|
|
removeItem(i->name);
|
|
|
|
|
|
|
|
i->flags &= ~EF_GONE;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
i->x = s->x + (s->w / 2) - (i->w / 2);
|
|
|
|
i->y = s->y - i->h;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
|
|
|
i->canBeCarried = i->canBePickedUp = i->isMissionTarget = 0;
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->active = 1;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-01-28 17:33:37 +01:00
|
|
|
setGameplayMessage(MSG_GAMEPLAY, _("%s removed"), s->requiredItem);
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("ItemPadActive");
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->spriteFrame = 0;
|
2018-01-27 11:47:53 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
updateObjective(s->name);
|
2018-01-27 11:47:53 +01:00
|
|
|
}
|
2018-01-28 09:30:53 +01:00
|
|
|
else if (!s->bobTouching)
|
2018-01-27 11:47:53 +01:00
|
|
|
{
|
2018-01-28 17:33:37 +01:00
|
|
|
setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem);
|
2018-01-27 11:47:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->bobTouching = 2;
|
2018-01-27 11:47:53 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-15 08:48:51 +01:00
|
|
|
|
2018-02-26 08:38:20 +01:00
|
|
|
static void getCollisionBounds(SDL_Rect *r)
|
|
|
|
{
|
|
|
|
r->x = self->x;
|
|
|
|
r->y = self->y - 4;
|
|
|
|
r->w = self->w;
|
|
|
|
r->h = self->h;
|
|
|
|
}
|
|
|
|
|
2018-02-15 08:48:51 +01:00
|
|
|
static void load(cJSON *root)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(root, "active"))
|
|
|
|
{
|
|
|
|
s->active = cJSON_GetObjectItem(root, "active")->valueint;
|
|
|
|
}
|
|
|
|
STRNCPY(s->requiredItem, cJSON_GetObjectItem(root, "requiredItem")->valuestring, MAX_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save(cJSON *root)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
cJSON_AddStringToObject(root, "type", "ItemPad");
|
|
|
|
cJSON_AddNumberToObject(root, "active", s->active);
|
|
|
|
cJSON_AddStringToObject(root, "requiredItem", s->requiredItem);
|
|
|
|
}
|