Page 1 of 1

Morale unit freezers

Posted: Fri Aug 21, 2020 12:32 pm
by Kossatx
Any idea about why the first script works for immobilize a british garrison from the beginning of the game, and the russian garrison of the second one begins unfreezed? (These modifications are over the great POTZBLITZ MOD, done by Robotron).

Code: Select all

local quebec = game:GetHex(8, 35)
if quebec.alliance.id == 1 
	and quebec.unit ~= nil
	and unit.hex ~= nil
	and unit.hex.x == 8
	and unit.hex.y == 35
	and britain.morale > 50
	and unit.type == Unit.LAND then
		unit.mp = 0
end	

Code: Select all

local reval = game:GetHex(118, 10)
if reval.alliance.id == 1 
	and reval.unit ~= nil
	and unit.hex ~= nil
	and unit.hex.x == 118
	and unit.hex.y == 10
	and russia.morale > 30
	and unit.type == Unit.LAND then
		unit.mp = 0
end

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 1:15 pm
by Robotron
Until Russia has joined Entente, Russia is neutral, therefore Reval is neutral too, therefore the check for Reval must be

Code: Select all

reval.alliance.id == 0

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 1:58 pm
by Kossatx
Robotron wrote: Fri Aug 21, 2020 1:15 pm Until Russia has joined Entente, Russia is neutral, therefore Reval is neutral too, therefore the check for Reval must be

Code: Select all

reval.alliance.id == 0
But Britain also starts neutral, not? And if I do what you say, once Russia joins Entente the units will be unfreeze, not?

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 2:14 pm
by Robotron
So, are both nations already in the war when you tested your script? You forgot to tell me.

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 3:50 pm
by Kossatx
I suppose "reval.alliance.id == 0" means "reval alliance is neutral at this turn", so althought Russia starts the war neutral (and its units don't move while neutral), once joins Entente its alliance is 1 and the script is triggered (so the garrison should be freezed... but not). I don't understand why I'm wrong :?:

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 4:12 pm
by Robotron
I have a theory that sometimes when a nation enters the war the alliance.id is not properly registered until the next turn. Don't ask me why.

So in your example Russia is still alliance.id == 0 on turn 5 even when having joined Entente. It will be alliance.id == 1 on all further turns, including all Russian cities.

You could try to check reval.alliance.id for being ~= 2, this should work if reval is still neutral or has joined Entente.

Code: Select all

local reval = game:GetHex(118, 10)
if reval.alliance.id ~= 2  
	and reval.unit ~= nil
	and unit.hex ~= nil
	and unit.hex.x == 118
	and unit.hex.y == 10
	and russia.morale > 30
	and unit.type == Unit.LAND then
		unit.mp = 0
end

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 5:16 pm
by Kossatx
Robotron wrote: Fri Aug 21, 2020 4:12 pm I have a theory that sometimes when a nation enters the war the alliance.id is not properly registered until the next turn. Don't ask me why.
Stranger things, but "~= 2" option neither works :|

I have many "freeze scripts" for russian units and all of them work correctly, except these with reference to russian morale. I think something happens with russian morale when enters at war... but I can't prove it :|

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 5:31 pm
by Robotron
How do you know your freeze scripts work correctly? The AI might haven chosen to keep the fleet in port.

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 6:42 pm
by Kossatx
Above 8 russian units are detached at neutral borders (Romania, Turkey and Persia) and the AI sends none to the front. Without including the scripts the AI always send all these troops to the front. Not only Russia do it, but all the nations in the game. That's because I decided to include these scripts to mantain some troops defending borders while neutral.

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 6:54 pm
by Robotron
Last attempt:

Code: Select all

local reval = game:GetHex(118, 10)
 if     unit.hex ~= nil
 	and unit.hex == reval
 	and unit.faction.id == 4
	and GetEvent("DOWrussia") >0
	and russia.morale > 30  then
		unit.mp = 0
end

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 7:12 pm
by Kossatx
Robotron wrote: Fri Aug 21, 2020 6:54 pm Last attempt:

Code: Select all

local reval = game:GetHex(118, 10)
 if     unit.hex ~= nil
 	and unit.hex == reval
 	and unit.faction.id == 4
	and GetEvent("DOWrussia") >0
	and russia.morale > 30  then
		unit.mp = 0
end
No way, it does'nt work :?

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 7:21 pm
by Robotron
If it does work without morale check, like you said above, then there's just not much else you can do than to remove the morale check, I guess.

Re: Morale unit freezers

Posted: Fri Aug 21, 2020 7:26 pm
by Kossatx
Very strange, is not morale the problem, with Reval, Riga and Abo neither works yor "in range" script:

Code: Select all

local reval = game:GetHex(118, 10)
local check = 0
local hexes = game.map:GetHexesInRange(reval, 3)
		for _, hex in pairs(hexes) do
			if hex.unit ~= nil
			and hex.unit.type == Unit.LAND
			and hex.unit.alliance.id == 2 then
				check = 1
				break	
			end
		end
		
		if reval.unit ~= nil 
		and reval.unit.prototype.name == "garrison"
		and reval.unit.faction.id == 1 
		and check == 0	then
			reval.unit.mp = 0
		end