[LUA] Disable unit movement, but heal

Lort Krassbeter

Chieftain
Joined
Mar 8, 2015
Messages
17
Location
Beyond Earth
Hi,
working on a mod that has to disable the user to move units at specific times during the turn. Currently I am doing this by setting the units movement points to 0. However, I noticed that this prevents a unit that actually hasn't moved to heal at the end of the turn. So I implemented a functionality that sets the movement points back to maximum movement points OnActivePlayerTurnEnd for the units that would normally have healed, since I assumed that that is causing them not to heal. Since it still didn't work I took a look into the DLL to figure out what a unit that will heal has to be like:
Code:
if(!pLoopUnit->isEmbarked())
		{
			if(pLoopUnit->hasMoved())
			{
				if(pLoopUnit->isAlwaysHeal())
				{
					pLoopUnit->doHeal();
				}
			}
			else
			{
				if(pLoopUnit->IsHurt())
				{
					pLoopUnit->doHeal();
				}
			}
		}
Okay, so the unit will only heal if it has not moved as I assumed. But this whole function is called in the setTurnActive function of CvPlayer and is in fact called before DLLUI->PublishActivePlayerTurnEnd();
Do I assume correctly that PublishActivePlayerTurnEnd() will trigger the lua event?
If so this means I can not use ActivePlayerTurnEnd to fix my problem. Are there any other events in that case that can perhaps be used?
Alternatively, it would also be possible to deny the player to select the units that have to heal, so I do not have to set their movement points to 0. However I could not figure out any way to do so yet. Any help is appreciated :)
 
You don't know if pLoopUnit->hasMoved() determines whether the unit moved. I can practically guarantee it does not check that, since nothing in programming checks whether an event happened. ... except listeners.
 
so the unit will only heal if it has not moved

Not true. The unit will only heal if it has not moved OR it has a promotion where <AlwaysHeal> is true.

So, create a new promotion, say PROMOTION_NO_MOVE_BUT_HEAL, and at the same time as you take the movement points away from the unit give it the promotion.

At the start of every player's turn, loop all their units and remove the promotion from all of them - a simple pUnit:SetHasPromotion(GameInfoTypes. PROMOTION_NO_MOVE_BUT_HEAL, false) is sufficient as the game core ignores any attempt to remove a promotion a unit doesn't actually have.

HTH

W
 
You don't know if pLoopUnit->hasMoved() determines whether the unit moved. I can practically guarantee it does not check that, since nothing in programming checks whether an event happened. ... except listeners.
Yea, it doesn't check if an event happened, but it checks if the units movement points are smaller than their maximum movement points. So it's basically the result of the unit moving.
Not true. The unit will only heal if it has not moved OR it has a promotion where <AlwaysHeal> is true.

So, create a new promotion, say PROMOTION_NO_MOVE_BUT_HEAL, and at the same time as you take the movement points away from the unit give it the promotion.

At the start of every player's turn, loop all their units and remove the promotion from all of them - a simple pUnit:SetHasPromotion(GameInfoTypes. PROMOTION_NO_MOVE_BUT_HEAL, false) is sufficient as the game core ignores any attempt to remove a promotion a unit doesn't actually have.
Oh very nice! I also thought of the "march" promotion, but then realized that it would only work for land units so I was looking for different solutions. But since this way it works for every unit, it is by far the most elegant solution. Thanks!
 
Yea, it doesn't check if an event happened, but it checks if the units movement points are smaller than their maximum movement points. So it's basically the result of the unit moving.

There are exceptions to that equivalence which actually occur. Almost every award of extra movement is bugged out and will be such a situation. Having 0 movement will always be less than the maximum movement though.

Too bad you can't set max movement to 0 and back as easily as you can with actual movement. You'd still need a promotion. Or if the trade units had a feature which made them not even have a move button that you could factor out without getting all the trade unit behaviours with it.
 
Back
Top Bottom