blobwarsAttrition/src/entities/structures/cardReader.c

126 lines
2.9 KiB
C
Raw Normal View History

2018-01-27 09:53:08 +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 "cardReader.h"
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 09:53:08 +01:00
void initCardReader(Entity *e)
{
Structure *s;
2018-01-27 09:53:08 +01:00
initEntity(e);
s = (Structure*)e;
2018-01-28 10:34:14 +01:00
s->type = ET_CARD_READER;
s->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS | EF_NO_TELEPORT;
2018-01-27 09:53:08 +01:00
STRNCPY(s->requiredItem, "Black Keycard", MAX_NAME_LENGTH);
2018-01-27 09:53:08 +01:00
s->isStatic = 1;
2018-01-27 09:53:08 +01:00
if (!s->active)
2018-01-27 09:53:08 +01:00
{
2018-01-30 00:00:14 +01:00
s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("CardReaderIdle");
2018-01-27 09:53:08 +01:00
}
else
{
2018-01-30 00:00:14 +01:00
s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("CardReader");
2018-01-27 09:53:08 +01:00
}
s->tick = tick;
s->touch = touch;
2018-01-30 23:47:40 +01:00
s->load = load;
s->save = save;
2018-01-27 09:53:08 +01:00
}
static void tick(void)
{
Structure *s;
s = (Structure*)self;
if (!s->active)
2018-01-27 09:53:08 +01:00
{
s->bobTouching = MAX(s->bobTouching - 1, 0);
2018-01-27 09:53:08 +01:00
}
}
static void touch(Entity *other)
{
Structure *s;
s = (Structure*)self;
if (!s->active && other->type == ET_BOB)
2018-01-27 09:53:08 +01:00
{
if (hasItem(s->requiredItem) || dev.cheatKeys)
2018-01-27 09:53:08 +01:00
{
activateEntities(s->targetNames, 1);
2018-01-27 09:53:08 +01:00
2018-01-28 17:33:37 +01:00
setGameplayMessage(MSG_GAMEPLAY, _("%s removed"), s->requiredItem);
2018-01-27 09:53:08 +01:00
removeItem(s->requiredItem);
2018-01-27 09:53:08 +01:00
s->active = 1;
2018-01-30 00:00:14 +01:00
s->sprite[FACING_LEFT] = s->sprite[FACING_RIGHT] = s->sprite[FACING_DIE] = getSprite("CardReader");
s->spriteTime = 0;
s->spriteFrame = 0;
2018-01-27 09:53:08 +01:00
playSound(SND_CONFIRMED, CH_TOUCH);
}
else if (s->bobTouching == 0)
2018-01-27 09:53:08 +01:00
{
2018-01-28 17:33:37 +01:00
setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem);
2018-01-27 09:53:08 +01:00
playSound(SND_DENIED, CH_TOUCH);
}
s->bobTouching = 2;
2018-01-27 09:53:08 +01:00
}
}
2018-01-30 23:47:40 +01:00
static void load(cJSON *root)
{
Structure *s;
s = (Structure*)self;
s->active = cJSON_GetObjectItem(root, "active")->valueint;
STRNCPY(s->requiredItem, cJSON_GetObjectItem(root, "requiredCard")->valuestring, MAX_NAME_LENGTH);
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", "CardReader");
cJSON_AddNumberToObject(root, "active", s->active);
cJSON_AddStringToObject(root, "requiredCard", s->requiredItem);
cJSON_AddStringToObject(root, "targetNames", s->targetNames);
}