From a01f15e08da3b2e0e326b2a94100e17962136741 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Apr 2012 14:50:36 +0200 Subject: Lua: Refactor all the corruption code into C --- lib/core/crpt_aux.lua | 144 -------------------------------------------------- lib/core/init.lua | 1 - 2 files changed, 145 deletions(-) delete mode 100644 lib/core/crpt_aux.lua (limited to 'lib/core') diff --git a/lib/core/crpt_aux.lua b/lib/core/crpt_aux.lua deleted file mode 100644 index 24b71860..00000000 --- a/lib/core/crpt_aux.lua +++ /dev/null @@ -1,144 +0,0 @@ --- Core functions for corruptions - -__corruptions = {} -__corruptions_max = 0 -__corruptions_callbacks_max = 0 - --- Get the corruption -function player.corruption(c) - return player.corruptions_aux[c + 1] -end - --- Test if we have that corruption --- We must: --- 1) have it or be willing to get it --- 2) have all its dependancies --- 3) have none of its opposing corruptions --- 4) pass the possible tests -function test_depend_corrupt(corrupt, can_gain) - local i, c - - if not can_gain then can_gain = FALSE end - - if can_gain == TRUE then - if (player.corruption(corrupt) ~= FALSE) then - return FALSE - end - else - if (player.corruption(corrupt) ~= TRUE) then - return FALSE - end - end - - for c, i in __corruptions[corrupt].depends do - if test_depend_corrupt(c) ~= TRUE then - return FALSE - end - end - - for c, i in __corruptions[corrupt].oppose do - if test_depend_corrupt(c) ~= FALSE then - return FALSE - end - end - - -- are we even allowed to get it? - return player_can_gain_corruption(corrupt) -end - --- Gain a new corruption -function gain_corruption(group) - local i, max - local pos = {} - - -- Get the list of all possible ones - max = 0 - for i = 0, __corruptions_max - 1 do - if __corruptions[i].group == group and test_depend_corrupt(i, TRUE) == TRUE and __corruptions[i].random == TRUE and __corruptions[i].allow() then - pos[max] = i - max = max + 1 - end - end - - -- Ok now get one of them - if (max > 0) then - local ret = rand_int(max) - - player_gain_corruption(pos[ret]) - cmsg_print(TERM_L_RED, __corruptions[pos[ret]].get_text) - - return pos[ret] - else - return -1 - end -end - --- Lose an existing corruption -function lose_corruption() - local i, max - local pos = {} - - -- Get the list of all possible ones - max = 0 - for i = 0, __corruptions_max - 1 do - if test_depend_corrupt(i) == TRUE and __corruptions[i].removable == TRUE then - pos[max] = i - max = max + 1 - end - end - - -- Ok now get one of them - if (max > 0) then - local ret = rand_int(max) - - player_lose_corruption(pos[ret]) - cmsg_print(TERM_L_RED, __corruptions[pos[ret]].lose_text) - - -- Ok now lets see if it broke some dependancies - for i = 0, max - 1 do - if player.corruption(pos[i]) ~= test_depend_corrupt(pos[i]) then - player_lose_corruption(pos[i]) - cmsg_print(TERM_L_RED, __corruptions[pos[i]].lose_text) - end - end - - return pos[ret] - else - return -1 - end -end - --- Creates a new corruption -function add_corruption(c) - assert(c.color, "No corruption color") - assert(c.name, "No corruption name") - assert(c.get_text, "No corruption get_text") - assert(c.lose_text, "No corruption lose_text") - assert(c.desc, "No corruption desc") - if not c.random then c.random = TRUE end - if not c.removable then c.removable = TRUE end - if not c.allow then c.allow = function() return not nil end end - - if c.depends == nil then c.depends = {} end - if c.oppose == nil then c.oppose = {} end - - -- We must make sure the other ones opposes too - local o, i - for o, i in c.oppose do - __corruptions[o].oppose[__corruptions_max] = TRUE - end - - if type(c.desc) == "table" then - local new_desc = "" - local index, h - for index, h in c.desc do - new_desc = new_desc..h.."\n" - end - c.desc = new_desc - end - - __corruptions[__corruptions_max] = c - __corruptions_max = __corruptions_max + 1 - return (__corruptions_max - 1) -end - diff --git a/lib/core/init.lua b/lib/core/init.lua index 11b812d5..3db34076 100644 --- a/lib/core/init.lua +++ b/lib/core/init.lua @@ -17,7 +17,6 @@ tome_dofile_anywhere(ANGBAND_DIR_CORE, "monsters.lua") tome_dofile_anywhere(ANGBAND_DIR_CORE, "building.lua") tome_dofile_anywhere(ANGBAND_DIR_CORE, "dungeon.lua") tome_dofile_anywhere(ANGBAND_DIR_CORE, "s_aux.lua") -tome_dofile_anywhere(ANGBAND_DIR_CORE, "crpt_aux.lua") tome_dofile_anywhere(ANGBAND_DIR_CORE, "mimc_aux.lua") tome_dofile_anywhere(ANGBAND_DIR_CORE, "quests.lua") tome_dofile_anywhere(ANGBAND_DIR_CORE, "gods.lua") -- cgit v1.2.3