From b4a6c4b46feded7a466394e2eb751c4bcb8f4f72 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sat, 11 Aug 2018 15:15:53 +0200 Subject: [PATCH] Fixes some render layer issues - Chance for more daggers in containers - Less health from meat - Prevent exit from spawning under containers --- data/maproombuilder.lua | 25 ++++++++++++------------- src/item.c | 2 ++ src/item_builder.c | 2 +- src/main.c | 4 +++- src/map.c | 27 +++++++++++++++++++-------- src/map.h | 3 +++ src/map_lua.c | 7 +++++-- src/monster.c | 5 +++++ src/monster.h | 3 +++ src/projectile.c | 1 + 10 files changed, 54 insertions(+), 25 deletions(-) diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index 4849cde..6a57259 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -398,17 +398,22 @@ local function build_coridoor_room(room) build_center_corner_walls(room, exits) end +local function room_tile_available(room, rx, ry) + return not room.chests[rx][ry] + and not room.traps[rx][ry] + and not room.monsters[rx][ry] + and not room.decor[rx][ry] + and (room.tiles[rx][ry] + and not room.tiles[rx][ry][5] + and not room.tiles[rx][ry][8]) +end + local function add_level_exit(room) success = false while not success do x = random(14) y = random(10) - if not room.decor[x][y] - and not room.traps[x][y] - and (room.tiles[x][y] - and not room.tiles[x][y][5] - and not room.tiles[x][y][8]) - then + if room_tile_available(room, x, y) then success = true room.tiles[x][y] = special.level_exit end @@ -453,13 +458,7 @@ function module.add_full_lighting(room) end function module.is_tile_avilable(room, rx, ry) - return not room.chests[rx][ry] - and not room.traps[rx][ry] - and not room.monsters[rx][ry] - and not room.decor[rx][ry] - and (room.tiles[rx][ry] - and not room.tiles[rx][ry][5] - and not room.tiles[rx][ry][8]) + return room_tile_available(room, rx, ry); end function module.create_empty_room() diff --git a/src/item.c b/src/item.c index 7d6d84e..8edbf10 100644 --- a/src/item.c +++ b/src/item.c @@ -56,6 +56,8 @@ item_collected(Item *item, Player *player) gui_log("You open a container"); item->opened = true; item->sprite->texture_index = 1; + if (!item->items) + gui_log("You find nothing inside"); } if (item->effect != NULL) diff --git a/src/item_builder.c b/src/item_builder.c index bc88722..57658e7 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -48,7 +48,7 @@ static void eat_flesh(Item *item, Player *player) { int original_hp = player->stats.hp; - player->stats.hp += (int) item->value * player->stats.lvl; + player->stats.hp += (int) item->value; if (player->stats.hp > player->stats.maxhp) player->stats.hp = player->stats.maxhp; diff --git a/src/main.c b/src/main.c index c7549cc..56b7b48 100644 --- a/src/main.c +++ b/src/main.c @@ -538,13 +538,15 @@ run_game_render(void) SDL_RenderSetViewport(gRenderer, &gameViewport); map_render(gMap, gCamera); particle_engine_render_game(gCamera); - map_render_top_layer(gMap, gCamera); + map_render_mid_layer(gMap, gCamera); if (!is_player_dead()) { player_render(gPlayer, gCamera); player_render_toplayer(gPlayer, gCamera); } + map_render_top_layer(gMap, gCamera); + if (gPlayer->class == MAGE || gPlayer->class == PALADIN) roommatrix_render_mouse_square(gRoomMatrix, gCamera); diff --git a/src/map.c b/src/map.c index 21b3e1f..b146e61 100644 --- a/src/map.c +++ b/src/map.c @@ -309,15 +309,8 @@ void map_render(Map *map, Camera *cam) } void -map_render_top_layer(Map *map, Camera *cam) +map_render_mid_layer(Map *map, Camera *cam) { - LinkedList *monsterItem = map->monsters; - while (monsterItem != NULL) { - Monster *monster = monsterItem->data; - monsterItem = monsterItem->next; - monster_render(monster, cam); - } - LinkedList *items = map->items; while (items != NULL) { item_render(items->data, cam); @@ -329,6 +322,24 @@ map_render_top_layer(Map *map, Camera *cam) artifact_render(artifacts->data, cam); artifacts = artifacts->next; } + + LinkedList *monsterItem = map->monsters; + while (monsterItem != NULL) { + Monster *monster = monsterItem->data; + monsterItem = monsterItem->next; + monster_render(monster, cam); + } +} + +void +map_render_top_layer(Map *map, Camera *cam) +{ + LinkedList *monsterItem = map->monsters; + while (monsterItem != NULL) { + Monster *monster = monsterItem->data; + monsterItem = monsterItem->next; + monster_render_top_layer(monster, cam); + } } void map_set_current_room(Map *map, Position *pos) diff --git a/src/map.h b/src/map.h index 6be60e8..294bc4a 100644 --- a/src/map.h +++ b/src/map.h @@ -103,6 +103,9 @@ map_update(UpdateData*); void map_render(Map*, Camera*); +void +map_render_mid_layer(Map*, Camera*); + void map_render_top_layer(Map*, Camera*); diff --git a/src/map_lua.c b/src/map_lua.c index fbcc784..37df660 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -336,8 +336,11 @@ l_add_chest(lua_State *L) linkedlist_append(&chest->items, item_builder_build_item(TREASURE, level)); if (get_random(4) == 0) linkedlist_append(&chest->items, item_builder_build_item(HEALTH, level)); - if (get_random(4) == 0) - linkedlist_append(&chest->items, item_builder_build_item(DAGGER, level)); + if (get_random(4) == 0) { + Item *dagger = item_builder_build_item(DAGGER, level); + dagger->value = get_random(4) + 1; + linkedlist_append(&chest->items, dagger); + } linkedlist_append(&map->items, chest); diff --git a/src/monster.c b/src/monster.c index db4d1b2..8761ab2 100644 --- a/src/monster.c +++ b/src/monster.c @@ -571,6 +571,11 @@ monster_render(Monster *m, Camera *cam) return; sprite_render(m->sprite, cam); +} + +void +monster_render_top_layer(Monster *m, Camera *cam) +{ if (m->stateIndicator.displayCount != 0) sprite_render(m->stateIndicator.sprite, cam); } diff --git a/src/monster.h b/src/monster.h index 6749ee5..b47adb9 100644 --- a/src/monster.h +++ b/src/monster.h @@ -82,6 +82,9 @@ monster_move(Monster*, RoomMatrix*); void monster_render(Monster*, Camera*); +void +monster_render_top_layer(Monster*, Camera*); + void monster_hit(Monster*, unsigned int dmg); diff --git a/src/projectile.c b/src/projectile.c index 5977061..2cb7768 100644 --- a/src/projectile.c +++ b/src/projectile.c @@ -17,6 +17,7 @@ */ #include +#include #include "projectile.h" #include "util.h" #include "texturecache.h"