Skip to content
Permalink
Browse files

Update maxWantedSpeed after all unit_attributes speed changes. Fixes #…

  • Loading branch information...
GoogleFrog committed Mar 13, 2019
1 parent bbf2c6c commit d66bf499ce35f9c020f0107dce2d99ef02ff00fe
Showing with 10 additions and 5 deletions.
  1. +2 −0 LuaRules/Gadgets/unit_attributes.lua
  2. +8 −5 LuaRules/Gadgets/unit_wanted_speed.lua
@@ -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
@@ -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))
@@ -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]
@@ -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
@@ -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)

0 comments on commit d66bf49

Please sign in to comment.
You can’t perform that action at this time.