Unit Movement Penalty Promo - Can it be done?

ww2commander

Emperor
Joined
Aug 23, 2003
Messages
1,243
Location
Australia
This one is a head scratcher as my testing seems to not get any results!

Can you make a promotion that gives a negative penalty to a unit's movement. I tried changing <MoveChange> tag in UnitPromotions to -1 but it seems to make no difference. The unit still moves with all its movement points.

Is there a way to do this or am I sending my self crazy trying to figure out something that can't be done? :crazyeye:
 
This one is a head scratcher as my testing seems to not get any results!

Can you make a promotion that gives a negative penalty to a unit's movement. I tried changing <MoveChange> tag in UnitPromotions to -1 but it seems to make no difference. The unit still moves with all its movement points.

Is there a way to do this or am I sending my self crazy trying to figure out something that can't be done? :crazyeye:

I don't know if there is a way to do this... if the <MovesChange> (if your xml field is lacking that "s", then it wouldn't work) is set up correctly, and the negative isn't changing anything, then I don't think it can be done (except perhaps through Lua). The closest you can get then is setting the <RoughTerrainEndsTurn> field to "true", which provides a movement penalty of sorts.
 
It wont be a typo as I make it a habit to cut/pasting tags directly from the XML files when creating SQL and XML scripts. This reduce wasted time on troubleshooting typos.

Another approach might be to inverse the solution and give all units a base movement that is the penalty rate and then apply promotions giving additional movement points.

Thus all I have to do is strip the promotion during poor weather seasons and reapply during summer.

Thanks for the assistance Androrc.
 
I think it could be done using Lua, but your inverted idea will do as well, and may be faster to implement.
 
Can you dynamically change movement rate for units via LUA?

I thought that once the XML files are loaded, they remain static in the DebugDatabase.db (cant remember exact name!) file.

Gedemon, I am using a heavily modified version of your dynamic promotion code to apply this promotion during certain turns and conditions.

Any 'outside of the box' thinking on how to do this in LUA would be appreciated.
 
Can you dynamically change movement rate for units via LUA?

I'm not sure you can change the stat itself, but movement points can be adjusted on-the-fly each turn if that's what's needed. In my Mythology mod I do something like this for a "Stun" attack, where at the start of its next turn the stunned unit is set to 0 movement points. So in theory you could just subtract 1 MP from certain units if they have your penalty promotion, by adjusting the number of points remaining at the start of each turn.
 
Can you dynamically change movement rate for units via LUA?

I thought that once the XML files are loaded, they remain static in the DebugDatabase.db (cant remember exact name!) file.

Gedemon, I am using a heavily modified version of your dynamic promotion code to apply this promotion during certain turns and conditions.

Any 'outside of the box' thinking on how to do this in LUA would be appreciated.
Yep, the DynamicUnitPromotion() is called once for each player at their turn starts (add it to add to GameEvents.PlayerDoTurn), so here you can modify the number of moves left on any unit with your custom promotion using unit:SetMoves() and unit:MovesLeft()

Basically unit:SetMoves(unit:MovesLeft()+60) will add one movement point (on plot with no road/railsroad) and unit:SetMoves(unit:MovesLeft() -60) will remove one.

Referring to the defines MOVE_DENOMINATOR would be safer ie unit:SetMoves(unit:MovesLeft() + GameDefines.MOVE_DENOMINATOR) to add one movement in case the value of one movement point is change in a patch.
 
Thanks Spatz and Gedemon.

I was looking too hard at one solution and completely forgot about using the SetMoves approach.

Just curious about the 60 value. How would I work with this value if units are using roads (without rail)? I assume -180 equates to -3 unit movement points?

I ask as I want to represent the Rasputitsa season on the Eastern Front during WWII where roads turned into bogs of mud and became useless to units.
 
It wont be a typo as I make it a habit to cut/pasting tags directly from the XML files when creating SQL and XML scripts. This reduce wasted time on troubleshooting typos.

Another approach might be to inverse the solution and give all units a base movement that is the penalty rate and then apply promotions giving additional movement points.

Thus all I have to do is strip the promotion during poor weather seasons and reapply during summer.

Thanks for the assistance Androrc.

So all you want to do is give all units less one movement point in winter? I don't think you need promotions for that. This lua code should work:

Code:
function WinterMovementPenalty( iPlayer )
	local player = Players[iPlayer]
	local season = (Game:GetGameTurn() % 4);

	if (season == 0) then
		for unit in player:Units() do
			unit:ChangeMoves(-1)
		end
	end
end

GameEvents.PlayerDoTurn.Add( WinterMovementPenalty )
 
Question is what is the most optimal way?

Is to slower doing this for 400+ units during winter turns or allocating a promo to each unit and letting the DLL code do it?
 
Heres my logic:

Method 1 - Promo given once on turn x, effects automatically apply as per any other promo for duration of season period (up to 5 turns).

Method 2 - LUA code would need to be executed for 5 turns (using above figure) and loop through each unit 400+ times per turn to ensure modifier is applied across scenario.

Is this logic over simplifying the problem or do I have reason to worry?
 
Just to revisit this thread and put some closure to it.

You can indeed allocate a promotion that subtracts movement. The only catch is that it works on the next turn (and not the turn it is allocated)!!

So I got around this by also using the unit:ChangeMoves() function on the initial turn.

It seems that the full amount of moves is allocated to a unit and then promotions are applied (in that order). On next turn the promotion seems to work correctly with movement reduces.

On a side note Androrc, the ChangeMoves() function requires the value to be entered as per the move denominator Gedemon mentioned above in the globaldefines file. The reason -1 is working is that you have used 1/60 of the first move so it is counting it as using part of the first move (if that makes sense!!!!).

i.e. unit:ChangeMoves(-180) will remove 3 moves and so on.
 
Back
Top Bottom