From 2a83ea5ad1f7dfe317b3a13cf1ae232cac8a891f Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Mon, 14 Oct 2019 23:11:04 +0200 Subject: [PATCH] Fixed saved prices being synced between forces --- map_gen/maps/space_race/market_handler.lua | 14 +++++++------- map_gen/maps/space_race/scenario.lua | 14 +------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/map_gen/maps/space_race/market_handler.lua b/map_gen/maps/space_race/market_handler.lua index ee5ff07a..e1b81060 100644 --- a/map_gen/maps/space_race/market_handler.lua +++ b/map_gen/maps/space_race/market_handler.lua @@ -17,12 +17,16 @@ local unlock_progress = { } } +local saved_prices = {} + Global.register( { - unlock_progress = unlock_progress + unlock_progress = unlock_progress, + saved_prices = saved_prices }, function(tbl) unlock_progress = tbl.unlock_progress + saved_prices = tbl.saved_prices end ) @@ -82,12 +86,7 @@ local function random_tech(tier, force, group_name) if not techs_left then local items = Retailer.get_items(group_name) local price = items[tier_name].price - for _, prototype in pairs(MarketItems) do - if prototype.name == tier_name then - prototype.price = price - break - end - end + saved_prices[force.name][tier_name] = price Retailer.remove_item(group_name, tier_name) end end @@ -124,6 +123,7 @@ local function on_market_purchase(event) if not Retailer.get_items(group_name)[tier_name] then for _, prototype in pairs(MarketItems) do if prototype.name == tier_name then + prototype.price = saved_prices[force.name][tier_name] Retailer.set_item(group_name, prototype) break end diff --git a/map_gen/maps/space_race/scenario.lua b/map_gen/maps/space_race/scenario.lua index 27df5daf..02c453d3 100644 --- a/map_gen/maps/space_race/scenario.lua +++ b/map_gen/maps/space_race/scenario.lua @@ -148,7 +148,7 @@ Event.on_init( local items = Table.deep_copy(Market_Items) for _, prototype in pairs(items) do local name = prototype.name - prototype.price = (disabled_research[name] and disabled_research[name].player) and disabled_research[name].player * player_kill_reward or prototype.price + --prototype.price = (disabled_research[name] and disabled_research[name].player) and disabled_research[name].player * player_kill_reward or prototype.price local unlock_requires = disabled_research[name] if prototype.disabled and unlock_requires then if unlock_requires.invert then @@ -161,18 +161,6 @@ Event.on_init( end end - --[[ - Items support the following structure: - { - name: the (raw) item inserted in inventory, does nothing when type is not item - name_label: the name shown in the GUI. If omitted and a prototype exists for 'name', it will use that LocalisedString, can be a LocalisedString - sprite: a custom sprite, will use 'item/' if omitted - price: the price of an item, supports floats (0.95 for example) - description: an additional description displayed in the tooltip, can be a LocalisedString - disabled: whether or not the item should be disabled by default - disabled_reason: the reason the item is disabled, can be a LocalisedString - } - ]] --ensures that the spawn points are not water surface.set_tiles( {