From 369abc431c2457e86f09778e6035d8c53e1df8f2 Mon Sep 17 00:00:00 2001 From: Lexxie9952 <32187224+Lexxie9952@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:32:48 -0700 Subject: [PATCH] MP2D,E Fix "free" Workers II upgrade was costing if player had Explosives --- freeciv/freeciv/data/mp2-dragoon/script.lua | 7 +++++++ freeciv/freeciv/data/mp2-elephant/script.lua | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/freeciv/freeciv/data/mp2-dragoon/script.lua b/freeciv/freeciv/data/mp2-dragoon/script.lua index f64734fa8..e92de257b 100644 --- a/freeciv/freeciv/data/mp2-dragoon/script.lua +++ b/freeciv/freeciv/data/mp2-dragoon/script.lua @@ -133,9 +133,16 @@ function tech_researched_handler(tech, player, how) -- This works fine for direct upgrade: local success = u:upgrade(0) -- local success = u:transform(u:can_upgrade(), 0); << this is supposed to work but maybe doesn't, but we don't need it. -- The below is used because we don't want a free upgrade to Engineers, only to first obsoleted_by type which is Workers II: + local pre_gold = player:gold() local success = u:transform(u.utype.obsoleted_by, 0) if success then + local lost_gold = pre_gold - player:gold() notify.event(player, u.tile, E.UNIT_UPGRADED, ("[`gift`] Workers upgraded for free.")) + -- This is a hack to ensure the upgrade is free. In some cases like having Explosives already, it wasn't free. + if lost_gold > 0 then + --DEBUG: notify.event(player, u.tile, E.UNIT_UPGRADED, ("[`gift`] %i gold compensated."), lost_gold) + edit.change_gold(player, lost_gold) + end end end end diff --git a/freeciv/freeciv/data/mp2-elephant/script.lua b/freeciv/freeciv/data/mp2-elephant/script.lua index 8b433cb08..6c1e336e3 100644 --- a/freeciv/freeciv/data/mp2-elephant/script.lua +++ b/freeciv/freeciv/data/mp2-elephant/script.lua @@ -193,9 +193,16 @@ function tech_researched_handler(tech, player, how) -- This works fine for direct upgrade: local success = u:upgrade(0) -- local success = u:transform(u:can_upgrade(), 0); << this is supposed to work but maybe doesn't, but we don't need it. -- The below is used because we don't want a free upgrade to Engineers, only to first obsoleted_by type which is Workers II: + local pre_gold = player:gold() local success = u:transform(u.utype.obsoleted_by, 0) if success then + local lost_gold = pre_gold - player:gold() notify.event(player, u.tile, E.UNIT_UPGRADED, ("[`gift`] Workers upgraded for free.")) + -- This is a hack to ensure the upgrade is free. In some cases like having Explosives already, it wasn't free. + if lost_gold > 0 then + --DEBUG: notify.event(player, u.tile, E.UNIT_UPGRADED, ("[`gift`] %i gold compensated."), lost_gold) + edit.change_gold(player, lost_gold) + end end end end