2018-01-27 12:22:29 +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 "pressurePlate.h"
|
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
static void init(void);
|
2018-01-27 12:22:29 +01:00
|
|
|
static void tick(void);
|
|
|
|
static void touch(Entity *other);
|
2018-01-30 23:47:40 +01:00
|
|
|
static void load(cJSON *root);
|
|
|
|
static void save(cJSON *root);
|
2018-01-27 12:22:29 +01:00
|
|
|
|
2018-01-30 09:29:09 +01:00
|
|
|
Entity *initPressurePlate(void)
|
2018-01-27 12:22:29 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
2018-01-30 09:29:09 +01:00
|
|
|
s = createStructure();
|
2018-01-28 09:30:53 +01:00
|
|
|
|
2018-01-28 10:34:14 +01:00
|
|
|
s->type = ET_PRESSURE_PLATE;
|
|
|
|
|
2018-01-30 00:00:14 +01:00
|
|
|
s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("PressurePlate");
|
2018-01-27 12:22:29 +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 12:22:29 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->plane = PLANE_FOREGROUND;
|
2018-01-27 12:22:29 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->isStatic = 1;
|
2018-01-27 12:22:29 +01:00
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
s->init = init;
|
2018-01-28 09:30:53 +01:00
|
|
|
s->tick = tick;
|
|
|
|
s->touch = touch;
|
2018-01-30 23:47:40 +01:00
|
|
|
s->load = load;
|
|
|
|
s->save = save;
|
2018-01-30 09:29:09 +01:00
|
|
|
|
|
|
|
return (Entity*)s;
|
2018-01-27 12:22:29 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 08:50:37 +01:00
|
|
|
static void init(void)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
if (s->active)
|
|
|
|
{
|
|
|
|
s->spriteTime = -1;
|
|
|
|
s->spriteFrame = 1;
|
|
|
|
|
|
|
|
if (s->isWeighted)
|
|
|
|
{
|
|
|
|
s->weightApplied = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 12:22:29 +01:00
|
|
|
static void tick(void)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
if (s->isWeighted)
|
2018-01-27 12:22:29 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
s->weightApplied = MAX(s->weightApplied - 1, 0);
|
2018-01-27 12:22:29 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
if (s->active && s->weightApplied == 0)
|
2018-01-27 12:22:29 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
s->active = 0;
|
|
|
|
s->spriteFrame = 0;
|
2018-01-27 12:22:29 +01:00
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
activateEntities(s->targetNames, 0);
|
2018-01-27 12:22:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void touch(Entity *other)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
2018-01-27 12:22:29 +01:00
|
|
|
if (other->type == ET_BOB || other->type == ET_PUSHBLOCK)
|
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
if (!s->active)
|
2018-01-27 12:22:29 +01:00
|
|
|
{
|
2018-01-28 09:30:53 +01:00
|
|
|
activateEntities(s->targetNames, 1);
|
2018-01-27 12:22:29 +01:00
|
|
|
|
2018-02-26 19:56:13 +01:00
|
|
|
playBattleSound(SND_PRESSURE_PLATE, s->uniqueId % MAX_SND_CHANNELS, s->x, s->y);
|
2018-01-27 12:22:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 09:30:53 +01:00
|
|
|
s->active = 1;
|
|
|
|
s->spriteFrame = 1;
|
|
|
|
s->weightApplied = 5;
|
2018-01-27 12:22:29 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-30 23:47:40 +01:00
|
|
|
|
|
|
|
static void load(cJSON *root)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
if (cJSON_GetObjectItem(root, "active"))
|
|
|
|
{
|
|
|
|
s->active = cJSON_GetObjectItem(root, "active")->valueint;
|
|
|
|
}
|
|
|
|
s->isWeighted = cJSON_GetObjectItem(root, "isWeighted")->valueint;
|
|
|
|
STRNCPY(s->targetNames, cJSON_GetObjectItem(root, "targetNames")->valuestring, MAX_DESCRIPTION_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save(cJSON *root)
|
|
|
|
{
|
|
|
|
Structure *s;
|
|
|
|
|
|
|
|
s = (Structure*)self;
|
|
|
|
|
|
|
|
cJSON_AddStringToObject(root, "type", "PressurePlate");
|
|
|
|
cJSON_AddNumberToObject(root, "active", s->active);
|
|
|
|
cJSON_AddNumberToObject(root, "isWeighted", s->isWeighted);
|
|
|
|
cJSON_AddStringToObject(root, "targetNames", s->targetNames);
|
|
|
|
}
|