Skip to content

Commit

Permalink
Commander evolution bufix (#3032)
Browse files Browse the repository at this point in the history
* Create unit_respawning.lua

This gadget enables unit respawning at a designated target.
This is mainly intended for Evocom.

* hotfix unit_respawning.lua

Made the effigy spawn on the commander.
added 5 second immunity after respawn.
effigy is now destroyed upon commander suicide, unless respawn_pad is true.
Added instructions for iseffigy.

* Hotfix unit_respawning

Added a missing return statement

* hotfix unit_respawning

Fixed a bug preventing the effigy wreck from teleporting to the commanders position.

Added clearing of the commanders commands when respawning.

* Feature Update Unit_Evolution

Added export of target unitID when evolving.

Added options:
new conditions: power, and health
Health transfer: "flat", "percentage", and "full

* Update unit_respawning.lua

Added transfering/replacing of the effigy when evolving, or destruction if the evolution target do not have respawning enabled.

* Update unit_respawning.lua

Added respawn sound

* bugfix unit_evolution

Evolving units should now properly stay in their assigned unit group.

Transports: Time based evolutions will stay on the transport, as long as the evolution target is valid for transport.
Power based evolutions will delay the evolution until disembarked.

* Update unit_evolution.lua

fixes unit group when evolving.

fixes evolving with transports.
  • Loading branch information
Xehrath committed May 18, 2024
1 parent 58841a7 commit e32ef74
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions luarules/gadgets/unit_evolution.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ if gadgetHandler:IsSyncedCode() then
local dx, dy, dz = spGetUnitDirection(unitID)
local stockpile, stockpilequeued, stockpilebuildpercent = spGetUnitStockpile(unitID)
local commandQueue = spGetUnitCommands(unitID, -1)
local transporter = Spring.GetUnitTransporter(unitID)

local newUnitID = spCreateUnit(newUnit, x,y,z, 0, team)

Expand All @@ -131,7 +132,7 @@ if gadgetHandler:IsSyncedCode() then
end

spSetUnitRulesParam(unitID, "unit_evolved", newUnitID, PRIVATE)

SendToUnsynced("unit_evolve_finished", unitID, newUnitID, announcement,announcementSize)
if evolutionMetaList[unitID].evolution_health_transfer == "full" then
elseif evolutionMetaList[unitID].evolution_health_transfer == "percentage" then
Expand All @@ -153,6 +154,9 @@ if gadgetHandler:IsSyncedCode() then
end
end

if transporter then
spGiveOrderToUnit(transporter, CMD.LOAD_UNITS, { newUnitID }, 0)
end

spGiveOrderToUnit(newUnitID, CMD.FIRE_STATE, { states.firestate }, { })
spGiveOrderToUnit(newUnitID, CMD.MOVE_STATE, { states.movestate }, { })
Expand Down Expand Up @@ -271,6 +275,8 @@ if gadgetHandler:IsSyncedCode() then
local enemyCount = -1
local teamID = spGetUnitTeam(unitID)
local powerValue = 0
local transporterID = Spring.GetUnitTransporter(unitID)

for team, power in pairs(teamPowerList) do
if team and teamID and power then
local teamsAllied = Spring.AreTeamsAllied(team, teamID)
Expand All @@ -286,8 +292,8 @@ if gadgetHandler:IsSyncedCode() then
enemyPower = enemyPower/enemyCount
end
powerValue = powerValue + enemyPower

if evolutionMetaList[unitID].evolution_condition == "power" and powerValue > evolutionMetaList[unitID].evolution_power_threshold then
if transporterID then
elseif evolutionMetaList[unitID].evolution_condition == "power" and powerValue > evolutionMetaList[unitID].evolution_power_threshold then
local enemyNearby = spGetUnitNearestEnemy(unitID, evolutionMetaList[unitID].combatRadius)
local inCombat = false
if enemyNearby then
Expand Down Expand Up @@ -342,6 +348,10 @@ else

local function EvolveFinished(cmd, oldID, newID, newAnnouncement, newAnnouncementSize)
local selUnits = spGetSelectedUnits()
local unitGroup = Spring.GetUnitGroup(oldID)
if unitGroup then
Spring.SetUnitGroup(newID, unitGroup)
end
for i=1,#selUnits do
local unitID = selUnits[i]
if (unitID == oldID) then
Expand Down

0 comments on commit e32ef74

Please sign in to comment.