blobwarsAttrition/src/world/items.c

181 lines
3.6 KiB
C
Raw Normal View History

2018-01-22 09:27:08 +01:00
/*
2019-06-02 17:13:34 +02:00
Copyright (C) 2018-2019 Parallel Realities
2018-01-22 09:27:08 +01:00
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 "items.h"
static void throwItem(Item *i);
2018-01-22 09:27:08 +01:00
static int getRandomPlayerWeaponAt(int x, int y);
2018-01-30 00:00:14 +01:00
static Sprite *wpnIconSprite;
static Sprite *cherrySprite[3];
static Sprite *batterySprite;
2018-01-22 09:27:08 +01:00
void initItems(void)
{
2018-01-30 00:00:14 +01:00
wpnIconSprite = getSprite("Weapon");
batterySprite = getSprite("Battery");
2018-01-22 09:27:08 +01:00
2018-01-30 00:00:14 +01:00
cherrySprite[0] = getSprite("Cherry");
cherrySprite[1] = getSprite("DualCherry");
cherrySprite[2] = getSprite("CherryBunch");
2018-01-22 09:27:08 +01:00
}
2018-02-24 17:01:36 +01:00
void addRandomWeapon(int x, int y)
2018-01-22 09:27:08 +01:00
{
2018-02-06 08:29:39 +01:00
Item *i;
2018-01-22 09:27:08 +01:00
int type;
2018-02-06 08:29:39 +01:00
i = initWeaponPickup();
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
i->x = x;
i->y = y;
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
type = getRandomPlayerWeaponAt(i->x, i->y);
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
i->weaponType = type;
i->sprite[0] = i->sprite[1] = i->sprite[2] = wpnIconSprite;
i->spriteFrame = type;
i->spriteTime = -1;
2018-01-22 09:27:08 +01:00
2018-02-06 08:29:39 +01:00
throwItem(i);
2018-01-22 09:27:08 +01:00
}
static int getRandomPlayerWeaponAt(int x, int y)
{
int type;
2019-06-02 17:13:34 +02:00
type = getRandomPlayerWeapon(world.missionType == MT_BOSS);
2019-06-02 17:13:34 +02:00
2018-01-22 09:27:08 +01:00
if (world.map.data[(x / MAP_TILE_SIZE)][(y / MAP_TILE_SIZE)] == MAP_TILE_WATER)
{
type = WPN_PISTOL;
}
else if (type == WPN_PISTOL && rand() % 100 < 65)
2018-01-22 09:27:08 +01:00
{
type = getRandomPlayerWeapon(world.missionType == MT_BOSS);
2018-01-22 09:27:08 +01:00
}
2019-06-02 17:13:34 +02:00
2018-01-22 09:27:08 +01:00
return type;
}
2018-02-24 17:01:36 +01:00
void dropRandomCherry(int x, int y)
2018-01-22 09:41:15 +01:00
{
Item *i;
2018-01-30 00:00:14 +01:00
int r;
2018-01-22 09:41:15 +01:00
2018-02-06 08:29:39 +01:00
i = initCherry();
2019-06-02 17:13:34 +02:00
2018-01-22 09:41:15 +01:00
r = rand() % 100;
if (r < 1)
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_CHERRY_BUNCH], MAX_NAME_LENGTH);
i->value = 10;
i->sprite[0] = i->sprite[1] = i->sprite[2] = cherrySprite[2];
2018-01-22 09:41:15 +01:00
}
else if (r < 10)
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_CHERRY_PAIR], MAX_NAME_LENGTH);
i->value = 3;
i->sprite[0] = i->sprite[1] = i->sprite[2] = cherrySprite[1];
2018-01-22 09:41:15 +01:00
}
else
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_CHERRY_SMALL], MAX_NAME_LENGTH);
i->value = 1;
i->sprite[0] = i->sprite[1] = i->sprite[2] = cherrySprite[0];
2018-01-22 09:41:15 +01:00
}
i->x = x;
i->y = y;
2018-02-06 08:29:39 +01:00
i->spriteFrame = 0;
2018-01-22 09:41:15 +01:00
throwItem(i);
2018-01-22 09:41:15 +01:00
}
2018-02-24 17:01:36 +01:00
static void dropBattery(int x, int y)
2018-01-22 09:41:15 +01:00
{
Item *i;
2018-01-30 00:00:14 +01:00
int r;
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
i = initBattery();
2018-01-22 09:41:15 +01:00
r = rand() % 100;
if (r < 1)
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_BATTERY_FULL], MAX_NAME_LENGTH);
i->power = 4;
2018-01-22 09:41:15 +01:00
}
else if (r < 10)
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_BATTERY], MAX_NAME_LENGTH);
i->power = 3;
2018-01-22 09:41:15 +01:00
}
else if (r < 25)
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_USED_BATTERY], MAX_NAME_LENGTH);
i->power = 2;
2018-01-22 09:41:15 +01:00
}
else
{
2018-04-01 18:41:45 +02:00
STRNCPY(i->name, app.strings[ST_WEAK_BATTERY], MAX_NAME_LENGTH);
i->power = 1;
2018-01-22 09:41:15 +01:00
}
i->sprite[0] = i->sprite[1] = i->sprite[2] = batterySprite;
i->spriteTime = -1;
i->spriteFrame = i->power;
2019-06-02 17:13:34 +02:00
i->x = x;
i->y = y;
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
i->animate();
2018-01-22 09:41:15 +01:00
throwItem(i);
2018-01-22 09:41:15 +01:00
}
2018-02-24 17:01:36 +01:00
void addRandomItems(int x, int y)
2018-01-22 09:41:15 +01:00
{
int cherryChance, batteryChance;
cherryChance = 100 - getPercent(world.bob->health, world.bob->healthMax);
batteryChance = 100 - getPercent(world.bob->power, world.bob->powerMax);
cherryChance = MIN(cherryChance, 50);
batteryChance = MIN(batteryChance, 50);
if (rand() % 100 < cherryChance)
2018-01-22 09:41:15 +01:00
{
dropRandomCherry(x, y);
}
if (rand() % 100 < batteryChance)
2018-01-22 09:41:15 +01:00
{
dropBattery(x, y);
}
}
static void throwItem(Item *i)
2018-01-22 09:27:08 +01:00
{
i->dx = rrnd(-3, 3);
i->dy = rrnd(-7, -5);
2018-01-22 09:27:08 +01:00
}