Skip to content

Commit

Permalink
Update maxWantedSpeed after all unit_attributes speed changes. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Mar 13, 2019
1 parent bbf2c6c commit d66bf49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions LuaRules/Gadgets/unit_attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ local function UpdateMovementSpeed(unitID, ud, speedFactor, turnAccelFactor, max
decRate = state.origMaxDec *maxAccelerationFactor
}
spSetGunshipMoveTypeData (unitID, attribute)
GG.ForceUpdateWantedMaxSpeed(unitID, unitDefID)
elseif state.movetype == 2 then
if workingGroundMoveType then
local accRate = state.origMaxAcc*maxAccelerationFactor
Expand All @@ -325,6 +326,7 @@ local function UpdateMovementSpeed(unitID, ud, speedFactor, turnAccelFactor, max
turnAccel = state.origTurnRate *turnAccelFactor*1.2,
}
spSetGroundMoveTypeData (unitID, attribute)
GG.ForceUpdateWantedMaxSpeed(unitID, unitDefID)
else
--Spring.Echo(state.origSpeed*speedFactor*WACKY_CONVERSION_FACTOR_1)
--Spring.Echo(Spring.GetUnitCOBValue(unitID, COB_MAX_SPEED))
Expand Down
13 changes: 8 additions & 5 deletions LuaRules/Gadgets/unit_wanted_speed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ local units = {}
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------

local function SetUnitWantedSpeed(unitID, unitDefID, wantedSpeed)
local function SetUnitWantedSpeed(unitID, unitDefID, wantedSpeed, forceUpdate)
if not unitDefID then
return
end
if not units[unitID] then
if not wantedSpeed then
if not (forceUpdate or wantedSpeed) then
return
end
local ud = UnitDefs[unitDefID]
Expand All @@ -58,19 +58,23 @@ local function SetUnitWantedSpeed(unitID, unitDefID, wantedSpeed)
return
end

if units[unitID].lastWantedSpeed == wantedSpeed then
if (not forceUpdate) and (units[unitID].lastWantedSpeed == wantedSpeed) then
return
end
units[unitID].lastWantedSpeed = wantedSpeed

--Spring.Utilities.UnitEcho(unitID, wantedSpeed)
Spring.Utilities.UnitEcho(unitID, wantedSpeed or "f")
if units[unitID].moveType == 1 then
Spring.MoveCtrl.SetGunshipMoveTypeData(unitID, "maxWantedSpeed", (wantedSpeed or 2000))
elseif units[unitID].moveType == 2 then
Spring.MoveCtrl.SetGroundMoveTypeData(unitID, "maxWantedSpeed", (wantedSpeed or 2000))
end
end

function GG.ForceUpdateWantedMaxSpeed(unitID, unitDefID)
SetUnitWantedSpeed(unitID, unitDefID, units and units[unitID] and units[unitID].lastWantedSpeed, true)
end

local function MaintainWantedSpeed(unitID)
if not (units[unitID] and units[unitID].lastWantedSpeed) then
return
Expand Down Expand Up @@ -102,7 +106,6 @@ function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOpt
if not (wantedSpeed and teamID) then
return false
end

wantedSpeed = (wantedSpeed > 0) and wantedSpeed
SetUnitWantedSpeed(unitID, unitDefID, wantedSpeed)

Expand Down

0 comments on commit d66bf49

Please sign in to comment.