From 4ba301769a235c36e0f74d55c116f67fac9aa145 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Fri, 10 Aug 2018 22:31:06 +0200 Subject: [PATCH] Fixes: #30 - Also fixes a bug with artifact generation - Extends menu room with new features - Adds more descriptive text to container openings - Fixes bug with container loot generation --- data/menumapgen.lua | 6 ++++++ src/artifact.c | 21 +++++++-------------- src/item.c | 22 ++++++++++++---------- src/item_builder.c | 4 ++-- src/map_lua.c | 6 +++--- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/data/menumapgen.lua b/data/menumapgen.lua index f446c6b..1f041ad 100644 --- a/data/menumapgen.lua +++ b/data/menumapgen.lua @@ -1,5 +1,7 @@ local room_builder = require "maproombuilder" local monster_gen = require "monstergen" +local trap_gen = require "trapgen" +local chest_gen = require "chestgen" map = create_map(CURRENT_LEVEL) -- 'map' needs to be global @@ -10,5 +12,9 @@ local room = room_builder.create_empty_room() room_builder.build_room(room) room_builder.add_full_lighting(room) monster_gen.add_monsters_to_room(room, 0, 0) +trap_gen.add_traps_to_room(room, 0, 0) +chest_gen.add_chests_to_room(room, 0, 0) room_builder.load_room(map, room) monster_gen.load_monsters(map, room.monsters) +trap_gen.load_traps(map, room.traps) +chest_gen.load_chests(map, room.chests) diff --git a/src/artifact.c b/src/artifact.c index 0a614c4..b04f24d 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -95,20 +95,13 @@ Artifact * artifact_create_random(Player *p, Uint8 level) { int option = -1; - switch (p->stats.lvl) { - case 4: - option = get_random(CHARGE_THROUGH); - break; - case 3: - option = get_random(INCREASED_STUN); - break; - case 1: - option = get_random(FEAR_INDUCING); - break; - default: - option = get_random(LAST_ARTIFACT_EFFECT) - 1; - break; - } + if (p->stats.lvl >= 4) + option = get_random(LAST_ARTIFACT_EFFECT); + else if (p->stats.lvl >= 3) + option = get_random(INCREASED_STUN); + else + option = get_random(FEAR_INDUCING); + Artifact *a = artifact_create(option); a->level = level; return a; diff --git a/src/item.c b/src/item.c index 84ca455..7d6d84e 100644 --- a/src/item.c +++ b/src/item.c @@ -20,6 +20,7 @@ #include "item.h" #include "util.h" #include "mixer.h" +#include "gui.h" Item * item_create(void) @@ -48,21 +49,22 @@ item_collected(Item *item, Player *player) if (item->collected || item->opened) return; - while (item->items) { - Item *subitem = linkedlist_pop(&item->items); - item_collected(subitem, player); - item_destroy(subitem); + if (!item->openable) { + item->collected = true; + } else { + mixer_play_effect(CHEST_OPEN); + gui_log("You open a container"); + item->opened = true; + item->sprite->texture_index = 1; } if (item->effect != NULL) item->effect(item, player); - if (!item->openable) { - item->collected = true; - } else { - mixer_play_effect(CHEST_OPEN); - item->opened = true; - item->sprite->texture_index = 1; + while (item->items) { + Item *subitem = linkedlist_pop(&item->items); + item_collected(subitem, player); + item_destroy(subitem); } } diff --git a/src/item_builder.c b/src/item_builder.c index 47b6080..bc88722 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -115,7 +115,7 @@ create_treasure(int current_level) unsigned int highest_treasure; unsigned int value; - amt = (unsigned int) get_random(5*current_level) % 40; + amt = (unsigned int) 1 + get_random(5*current_level) % 40; if (current_level > 9) { highest_treasure = TREASURE_COUNT; @@ -125,7 +125,7 @@ create_treasure(int current_level) highest_treasure = GOLD; } - value = get_random(highest_treasure) - 1; + value = get_random(highest_treasure); SDL_Rect clip = CLIP16(0, 0); switch (value) { diff --git a/src/map_lua.c b/src/map_lua.c index c643ed2..fbcc784 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -333,11 +333,11 @@ l_add_chest(lua_State *L) lua_pop(L, 4); if (get_random(1) == 0) - linkedlist_append(&chest->items, item_builder_build_item(level, TREASURE)); + linkedlist_append(&chest->items, item_builder_build_item(TREASURE, level)); if (get_random(4) == 0) - linkedlist_append(&chest->items, item_builder_build_item(level, HEALTH)); + linkedlist_append(&chest->items, item_builder_build_item(HEALTH, level)); if (get_random(4) == 0) - linkedlist_append(&chest->items, item_builder_build_item(level, DAGGER)); + linkedlist_append(&chest->items, item_builder_build_item(DAGGER, level)); linkedlist_append(&map->items, chest);