From 8c9622d6bda0b76761f65af81dffbfd271fa3895 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Fri, 8 Mar 2019 14:39:23 +0100 Subject: [PATCH] Shopkeeper now has bodyguards next time you meet after kiling him Fixed cl warnings in cmake and added some more walldecorations as well. Wall decorations needs better logic so we get the right decoration on the right tile. --- CMakeLists.txt | 28 +++++++++++++--------------- bh_random/CMakeLists.txt | 18 ++++++++++-------- data/layoutparser.lua | 21 +++++++++++++++++++++ data/mapgen.lua | 6 +++++- data/maproombuilder.lua | 10 +++++----- data/monstergen.lua | 35 ++++++++++++++++++++++++++++++++++- src/map_lua.c | 18 +++++++++++++----- src/monster.c | 1 + 8 files changed, 102 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ccbbe9..de68e3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,15 +68,17 @@ endif() IF ( MSVC ) MESSAGE ( STATUS "Setting MSVC MT switches") - SET ( - CMAKE_C_FLAGS_DEBUG - "${CMAKE_C_FLAGS_DEBUG} /MTd" - CACHE STRING "MSVC MT flags " FORCE + string (REPLACE + "/MDd" + "/MTd" + CMAKE_C_FLAGS_DEBUG + ${CMAKE_C_FLAGS_DEBUG} ) - SET ( - CMAKE_C_FLAGS_RELEASE - "${CMAKE_C_FLAGS_RELEASE} /MT" - CACHE STRING "MSVC MT flags " FORCE + string (REPLACE + "/MDd" + "/MTd" + CMAKE_C_FLAGS_RELEASE + ${CMAKE_C_FLAGS_RELEASE} ) ELSEIF ( WIN32 ) SET ( @@ -320,16 +322,12 @@ if (NOT DEBUG_BUILD) "monstergen.lua" "trapgen.lua" "chestgen.lua" + "layoutparser.lua" "pitlayouts.dat" + "walllayouts.dat" + "shoplayouts.dat" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data ) - if (WIN32 AND NOT MSVC) - add_definitions(-mwindows) - endif() -else() - if (WIN32) - add_definitions(-mconsole) - endif() endif () SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT "Release") diff --git a/bh_random/CMakeLists.txt b/bh_random/CMakeLists.txt index 965de8d..ac34664 100644 --- a/bh_random/CMakeLists.txt +++ b/bh_random/CMakeLists.txt @@ -13,15 +13,17 @@ add_library(bh_random STATIC IF ( MSVC ) MESSAGE ( STATUS "Setting MSVC MT switches") - SET ( - CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} /MTd" - CACHE STRING "MSVC MT flags " FORCE + string (REPLACE + "/MDd" + "/MTd" + CMAKE_C_FLAGS_DEBUG + ${CMAKE_C_FLAGS_DEBUG} ) - SET ( - CMAKE_CXX_FLAGS_RELEASE - "${CMAKE_CXX_FLAGS_RELEASE} /MT" - CACHE STRING "MSVC MT flags " FORCE + string (REPLACE + "/MDd" + "/MTd" + CMAKE_C_FLAGS_RELEASE + ${CMAKE_C_FLAGS_RELEASE} ) endif () diff --git a/data/layoutparser.lua b/data/layoutparser.lua index cbf0a96..3da9bc5 100644 --- a/data/layoutparser.lua +++ b/data/layoutparser.lua @@ -3,6 +3,7 @@ local pits = {} local walls = {} local fences = {} local lights = {} +local decor = {} local function readLayoutFile(file) local layoutfile = read_file(file) @@ -187,6 +188,23 @@ function module.load_textures(map, wall_xoffset, wall_yoffset) candle1 = { t_decor0, t_decor1, 1 * 16, 8 * 16, true, true }, candle2 = { t_decor0, t_decor1, 5 * 16, 8 * 16, true, false }, } + + decor = { + -- Webs + { t_decor0, nil, 0 * 16, 19 * 16, false }, + { t_decor0, nil, 1 * 16, 19 * 16, false }, + { t_decor0, nil, 2 * 16, 19 * 16, false }, + { t_decor0, nil, 3 * 16, 19 * 16, false }, + { t_decor0, nil, 4 * 16, 19 * 16, false }, + + -- Cracks + { t_decor0, nil, 0 * 16, 2 * 16, false }, + { t_decor0, nil, 1 * 16, 2 * 16, false }, + + -- Vines + { t_decor0, nil, 4 * 16, 2 * 16, false }, + { t_decor0, nil, 5 * 16, 2 * 16, false }, + } end function createJumbleLayout(matrix) @@ -226,6 +244,9 @@ function draw_layout_to_room(room, matrix, roomx, roomy) setPitTile(room, matrix, i, j); elseif matrix[i][j] == "#" then setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) + if (random(4) == 1) then + room.decor[i][j] = decor[random(#decor)] + end elseif matrix[i][j] == "\"" then setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) room.decor[i][j] = lights.candle1 diff --git a/data/mapgen.lua b/data/mapgen.lua index 5afcacf..4586110 100644 --- a/data/mapgen.lua +++ b/data/mapgen.lua @@ -128,7 +128,7 @@ local function generate_path () for j=1,10 do room = map_matrix[i][j] if room then - if roomCount > 5 and shopLevel and not shopAdded then + if roomCount > 4 and shopLevel and not shopAdded then room.type = "shop" shopAdded = true end @@ -140,6 +140,10 @@ local function generate_path () chest_gen.add_chests_to_room(room, i-1, j-1) else monster_gen.add_shopkeeper_to_room(room, i-1, j-1) + if PlayerData.shopOwnerKiller then + monster_gen.add_bodyguard_to_room(room, i-1, j-1) + monster_gen.add_bodyguard_to_room(room, i-1, j-1) + end end if roomCount > 3 and bossLevel and not bossAdded then bossAdded = true diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index ed6b314..3c618c5 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -54,11 +54,11 @@ local function load_decor_textures() table.insert(floorDecor, { td0, td1, 48, 13 * 16, false, false }) -- Webs - table.insert(floorDecor, { td0, td1, 0 * 16, 19 * 16, false }) - table.insert(floorDecor, { td0, td1, 1 * 16, 19 * 16, false }) - table.insert(floorDecor, { td0, td1, 2 * 16, 19 * 16, false }) - table.insert(floorDecor, { td0, td1, 3 * 16, 19 * 16, false }) - table.insert(floorDecor, { td0, td1, 4 * 16, 19 * 16, false }) + --table.insert(floorDecor, { td0, td1, 0 * 16, 19 * 16, false }) + --table.insert(floorDecor, { td0, td1, 1 * 16, 19 * 16, false }) + --table.insert(floorDecor, { td0, td1, 2 * 16, 19 * 16, false }) + --table.insert(floorDecor, { td0, td1, 3 * 16, 19 * 16, false }) + --table.insert(floorDecor, { td0, td1, 4 * 16, 19 * 16, false }) -- Urns table.insert(floorDecor, { td0, td1, 6 * 16, 48, false, false }) diff --git a/data/monstergen.lua b/data/monstergen.lua index 56aaee2..05342d5 100644 --- a/data/monstergen.lua +++ b/data/monstergen.lua @@ -278,6 +278,11 @@ for i=1,#eastereggs do eastereggs[i] = concat({ texturePaths.player0, texturePaths.player1 }, eastereggs[i]) end +local shopkeeperBehaviour = behaviour.passive +if PlayerData.shopOwnerKiller then + shopkeeperBehaviour = behaviour.hostile +end + local shopkeeper = { texturePaths.humanoid0, texturePaths.humanoid1, @@ -285,7 +290,17 @@ local shopkeeper = { 16, 12*16, "The Trader", - behaviour.passive + shopkeeperBehaviour +} + +local bodyguard = { + texturePaths.humanoid0, + texturePaths.humanoid1, + stats.orc, + 32, + 12*16, + "A Bodyguard", + behaviour.hostile } -- Add Platino @@ -420,6 +435,24 @@ function module.add_shopkeeper_to_room(room, roomx, roomy) end end +function module.add_bodyguard_to_room(room, roomx, roomy) + local success = false + while not success do + local rx = random(13) + 1 + local ry = random(9) + 1 + if room_builder.is_tile_avilable(room, rx, ry) then + local x = (roomx * 512) + rx * 32 + local y = (roomy * 384) + ry * 32 + room.monsters[rx][ry] = { + x, + y, + bodyguard + } + success = true + end + end +end + function module.load_monsters(map, monsters) for i=0,15 do for j=0,11 do diff --git a/src/map_lua.c b/src/map_lua.c index 47f67b2..4bcacf9 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -375,7 +375,6 @@ l_add_chest(lua_State *L) static int l_add_monster(lua_State *L) { - Player *player = luaL_checkplayer(L); Monster *monster; Map *map; int x, y, clip_x, clip_y, behaviour; @@ -419,10 +418,6 @@ l_add_monster(lua_State *L) lua_pop(L, 8); // Make sure traders stay hostile if you've killed one - if (strcmp(label, "The Trader") == 0 && player->stateData.shopOwnerKiller) { - behaviour = HOSTILE; - } - monster = monster_create(); monster->sprite->clip = (SDL_Rect) { clip_x, clip_y, 16, 16 }; monster_update_pos(monster, (Position) { x, y }); @@ -532,6 +527,17 @@ l_create_shop_artifact(lua_State *L) return 0; } +static void +build_player_state_table(lua_State *L, Player *player) +{ + lua_createtable(L, 0, 1); + lua_pushboolean(L, player ? player->stateData.shopOwnerKiller : false); + lua_setfield(L, -2, "shopOwnerKiller"); + lua_pushnumber(L, player ? player->stats.lvl : 1); + lua_setfield(L, -2, "level"); + lua_setglobal(L, "PlayerData"); +} + static Map* generate_map(unsigned int level, const char *file, GameMode gameMode, Player *player, SDL_Renderer *renderer) { @@ -552,6 +558,8 @@ generate_map(unsigned int level, const char *file, GameMode gameMode, Player *pl } // Present stuff to lua + build_player_state_table(L, player); + lua_pushlightuserdata(L, renderer); lua_setglobal(L, "_sdl_renderer"); diff --git a/src/monster.c b/src/monster.c index ffc1f93..7f62d3b 100644 --- a/src/monster.c +++ b/src/monster.c @@ -18,6 +18,7 @@ #include #include +#include #include "monster.h" #include "util.h"