Skip to content

Commit

Permalink
MP2D,E Fix "free" Workers II upgrade was costing if player had Explos…
Browse files Browse the repository at this point in the history
…ives
  • Loading branch information
Lexxie9952 committed Jul 3, 2024
1 parent 3dbc1d7 commit 369abc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions freeciv/freeciv/data/mp2-dragoon/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 <font color=#9090ff>upgraded for free.</font>"))
-- 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 <font color=#9090ff>gold compensated.</font>"), lost_gold)
edit.change_gold(player, lost_gold)
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions freeciv/freeciv/data/mp2-elephant/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 <font color=#9090ff>upgraded for free.</font>"))
-- 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 <font color=#9090ff>gold compensated.</font>"), lost_gold)
edit.change_gold(player, lost_gold)
end
end
end
end
Expand Down

0 comments on commit 369abc4

Please sign in to comment.