Weight monster loot according to player health.

More health in flesh and more flesh sprites.
This commit is contained in:
Linus Probert 2018-02-24 21:15:13 +01:00
parent 462a22f7a0
commit 71c7345c78
7 changed files with 25 additions and 12 deletions

View File

@ -158,13 +158,13 @@ item_builder_build_item(ItemKey key, int level)
Item *item = NULL;
switch (key) {
case TREASURE:
item = create_treasure(level);
item = create_treasure(level*2);
break;
case FLESH:
item = create_item(path_flesh,
(SDL_Rect) { 0, 0, 16, 16 },
(SDL_Rect) { get_random(7) * 16, get_random(1) * 16, 16, 16 },
&eat_flesh);
item->value = get_random(level);
item->value = 1 + get_random(level*2);
break;
case HEALTH:
item = create_item(path_potion,

View File

@ -34,8 +34,8 @@ typedef enum {
} Treasure;
typedef enum {
FLESH,
HEALTH,
FLESH,
TREASURE,
ITEM_COUNT
} ItemKey;

View File

@ -446,7 +446,7 @@ check_next_level(void)
static void
run_game(void)
{
map_clear_dead_monsters(gMap);
map_clear_dead_monsters(gMap, gPlayer);
map_clear_collected_items(gMap);
roommatrix_populate_from_map(gRoomMatrix, gMap);
roommatrix_add_lightsource(gRoomMatrix,

View File

@ -95,7 +95,7 @@ void map_add_decoration(Map *map, Position *tile_pos, MapTile *tile)
}
void
map_clear_dead_monsters(Map *map)
map_clear_dead_monsters(Map *map, Player *player)
{
LinkedList *last, *current, *next;
@ -112,7 +112,7 @@ map_clear_dead_monsters(Map *map)
Monster *monster = current->data;
// Loot drops
monster_drop_loot(monster, map);
monster_drop_loot(monster, map, player);
monster_destroy(monster);
current->data = NULL;

View File

@ -29,6 +29,7 @@
#include "timer.h"
#include "defines.h"
#include "monster.h"
#include "player.h"
typedef struct MapTile_t {
int textureIndex0;
@ -74,7 +75,7 @@ bool
map_move_monsters(Map*, RoomMatrix*);
void
map_clear_dead_monsters(Map*);
map_clear_dead_monsters(Map*, Player*);
void
map_clear_collected_items(Map*);

View File

@ -294,13 +294,19 @@ monster_update_stats_for_level(Monster *m, unsigned int level)
}
void
monster_drop_loot(Monster *monster, Map *map)
monster_drop_loot(Monster *monster, Map *map, Player *player)
{
static unsigned int item_drop_chance = 1;
static unsigned int treasure_drop_chance = 1;
unsigned int item_drop_chance = 1;
Item *item;
Item *items[2];
unsigned int item_count = 0;
bool player_full_health = false;
player_full_health = player->stats.hp >= player->stats.maxhp;
if (player->stats.hp < player->stats.maxhp / 2)
item_drop_chance = 0;
if (get_random(treasure_drop_chance) == 0) {
item = item_builder_build_item(TREASURE, map->level);
@ -308,7 +314,12 @@ monster_drop_loot(Monster *monster, Map *map)
items[item_count++] = item;
}
if (get_random(item_drop_chance) == 0) {
item = item_builder_build_item(get_random(TREASURE - 1), map->level);
ItemKey key;
if (!player_full_health)
key = get_random(TREASURE - 1);
else
key = HEALTH;
item = item_builder_build_item(key, map->level);
item->sprite->pos = monster->sprite->pos;
items[item_count++] = item;
}

View File

@ -23,6 +23,7 @@
#include "sprite.h"
#include "stats.h"
#include "actiontext.h"
#include "player.h"
typedef enum { PASSIVE, AGRESSIVE, SCARED } StateType;
@ -61,7 +62,7 @@ void
monster_update_stats_for_level(Monster*, unsigned int level);
void
monster_drop_loot(Monster*, Map*);
monster_drop_loot(Monster*, Map*, Player*);
void
monster_destroy(Monster*);