blobwarsAttrition/src/entities/items/weaponPickup.c

122 lines
2.3 KiB
C
Raw Normal View History

2018-01-26 23:29: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 "weaponPickup.h"
2018-02-06 08:29:39 +01:00
static void (*superTick)(void);
static void init(void);
2018-01-26 23:29:08 +01:00
static void tick(void);
static void touch(Entity *other);
static void load(cJSON *root);
static void save(cJSON *root);
2018-01-26 23:29:08 +01:00
2018-02-06 08:29:39 +01:00
Entity *initWeaponPickup(void)
2018-01-26 23:29:08 +01:00
{
Item *i;
2018-02-06 08:29:39 +01:00
i = (Item*)initConsumable();
2018-01-26 23:29:08 +01:00
i->weaponType = WPN_PISTOL;
2018-02-06 08:29:39 +01:00
superTick = i->tick;
i->init = init;
i->tick = tick;
i->touch = touch;
i->load = load;
i->save = save;
2018-02-06 08:29:39 +01:00
return (Entity*)i;
}
2018-01-26 23:29:08 +01:00
2018-02-06 08:29:39 +01:00
static void init(void)
{
Item *i;
i = (Item*)self;
2018-01-30 00:00:14 +01:00
i->sprite[0] = i->sprite[1] = i->sprite[2] = getSprite("Weapon");
i->spriteFrame = i->weaponType;
i->spriteTime = -1;
2018-01-26 23:29:08 +01:00
if (i->provided)
2018-01-26 23:29:08 +01:00
{
i->health = 9999;
2018-01-26 23:29:08 +01:00
}
}
static void tick(void)
{
Item *i;
i = (Item*)self;
2018-02-06 08:29:39 +01:00
superTick();
2018-01-26 23:29:08 +01:00
if (i->provided && i->alive == ALIVE_ALIVE)
2018-01-26 23:29:08 +01:00
{
i->health = 9999;
2018-01-26 23:29:08 +01:00
}
}
static void touch(Entity *other)
{
Item *i;
i = (Item*)self;
2018-01-26 23:29:08 +01:00
if (touchedPlayer(other))
{
world.bob->weaponType = i->weaponType;
2018-01-26 23:29:08 +01:00
switch (i->weaponType)
2018-01-26 23:29:08 +01:00
{
case WPN_GRENADES:
2018-01-28 17:33:37 +01:00
setGameplayMessage(MSG_STANDARD, _("Got some Grenades"));
2018-01-26 23:29:08 +01:00
break;
default:
2018-02-04 10:50:07 +01:00
setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), getWeaponName(i->weaponType));
2018-01-26 23:29:08 +01:00
break;
}
pickupItem();
2018-02-25 18:29:44 +01:00
playSound(SND_WEAPON, i->uniqueId % MAX_SND_CHANNELS);
2018-02-13 22:36:42 +01:00
game.stats[STAT_WEAPONS_PICKED_UP]++;
2018-01-26 23:29:08 +01:00
}
}
static void load(cJSON *root)
{
Item *i;
i = (Item*)self;
i->weaponType = lookup(cJSON_GetObjectItem(root, "weaponType")->valuestring);
i->provided = cJSON_GetObjectItem(root, "provided")->valueint;
}
static void save(cJSON *root)
{
/* boss missions, only - not going to worry about saving these */
}