Divergent/mods/Tosox Mini Mods Repo/gamedata/scripts/treasure_manager_monkey_map...

76 lines
2.6 KiB
Plaintext

--[[
ADJACENT STASH REWARDS (Tosox Mini Mods Repo)
[https://www.moddb.com/mods/stalker-anomaly/addons/tosox-mini-mods-repo]
This mod spawns rewarded stashes in the levels connected to
your current level. So say bye to stash rewards in
Pripyat while you are still exploring Cordon.
Author: Singustromo <singustromo at disroot.org>
--]]
-- Superseded functions
GetRandomStash = treasure_manager.get_random_stash
BoxInSameMap = treasure_manager.box_in_same_map
--------------------------
-- Monkey Patches --
--------------------------
-- We always force local stashes
function treasure_manager.get_random_stash(no_spot, hint, spawn_local, inv_box)
-- Exception, so stash contents are created on first init
-- It's called like this on first init in on_game_load():
-- get_random_stash(true, "stash")
local first_init = no_spot and (hint == "stash") and not (spawn_local and inv_box)
spawn_local = not first_init -- Kinda scuffed but not compute intensive
return GetRandomStash(no_spot, hint, spawn_local, inv_box)
end
-- Here we change the logic to find out which stashes are considered local
function treasure_manager.box_in_same_map(id)
if (not id) then return end
local obj1, obj2 = alife():actor(), alife_object(id)
return is_on_nearby_level(obj1, obj2)
end
-----------------------------
-- Utility Functions --
-----------------------------
function is_on_nearby_level(se_obj_1, se_obj_2)
local obj1_level, obj2_level = get_obj_level(se_obj_1), get_obj_level(se_obj_2)
if not (obj1_level and obj2_level) then return end
return (obj1_level == obj2_level)
or level_directly_connected(obj1_level, obj2_level)
end
function get_obj_level(se_obj)
if (not se_obj) then return end
local sim, gg = alife(), game_graph()
return sim:level_name(gg:vertex(se_obj.m_game_vertex_id):level_id())
end
-- output of next() is nil when table is empty
function is_table_empty(tbl)
return not (tbl and next(tbl))
end
-- Uses txr_routes.routes to determine if those levels are adjacent
-- Does not account for additional transitions made by e.g. Extra level Transitions
-- as that addon circumvents this vanilla system completely.
function level_directly_connected(section_1, section_2)
local routes = txr_routes.routes
local map1, map2 = txr_routes.get_map(section_1), txr_routes.get_map(section_2)
if not (map1 and map2) then return end
local route = (routes[map1]) and routes[map1][map2]
or (routes[map2] and routes[map2][map1])
return not is_table_empty(route)
end