From cf3618a3b35f24189cf86bcc3aa6ea082a1177af Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Fri, 3 Jun 2011 06:18:08 +0000 Subject: [PATCH] rng.range, rng.float have now reversable parameters git-svn-id: http://svn.net-core.org/repos/t-engine4@3554 51575b47-30f0-44d4-a5cc-537603b46e54 --- .../engine/dialogs/ShowPickupFloor.lua | 1 + game/modules/tome/class/Player.lua | 1 - src/core_lua.c | 29 +++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/game/engines/default/engine/dialogs/ShowPickupFloor.lua b/game/engines/default/engine/dialogs/ShowPickupFloor.lua index 119e8f96c3..9b2273ee3a 100644 --- a/game/engines/default/engine/dialogs/ShowPickupFloor.lua +++ b/game/engines/default/engine/dialogs/ShowPickupFloor.lua @@ -80,6 +80,7 @@ function _M:used() game:unregisterDialog(self) return false end + self:select(self.c_list.list[self.c_list.sel]) return true end diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index 082e05c61c..65a632a0fd 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -681,7 +681,6 @@ function _M:playerPickup() local titleupdator = self:getEncumberTitleUpdator("Pickup") local d d = self:showPickupFloor(titleupdator(), nil, function(o, item) self:pickupFloor(item, true) - d:select(d.c_list.list[d.c_list.sel]) self.changed = true d:updateTitle(titleupdator()) d:used() diff --git a/src/core_lua.c b/src/core_lua.c index 6107c7f751..b60ac0b6eb 100644 --- a/src/core_lua.c +++ b/src/core_lua.c @@ -1936,7 +1936,10 @@ static int rng_float(lua_State *L) { float min = luaL_checknumber(L, 1); float max = luaL_checknumber(L, 2); - lua_pushnumber(L, genrand_real(min, max)); + if (min < max) + lua_pushnumber(L, genrand_real(min, max)); + else + lua_pushnumber(L, genrand_real(max, min)); return 1; } @@ -1955,8 +1958,16 @@ static int rng_range(lua_State *L) { int x = luaL_checknumber(L, 1); int y = luaL_checknumber(L, 2); - int res = x + rand_div(1 + y - x); - lua_pushnumber(L, res); + if (x < y) + { + int res = x + rand_div(1 + y - x); + lua_pushnumber(L, res); + } + else + { + int res = y + rand_div(1 + x - y); + lua_pushnumber(L, res); + } return 1; } @@ -1983,8 +1994,16 @@ static int rng_call(lua_State *L) if (lua_isnumber(L, 2)) { int y = luaL_checknumber(L, 2); - int res = x + rand_div(1 + y - x); - lua_pushnumber(L, res); + if (x < y) + { + int res = x + rand_div(1 + y - x); + lua_pushnumber(L, res); + } + else + { + int res = y + rand_div(1 + x - y); + lua_pushnumber(L, res); + } } else { -- GitLab