Naval AI not repairing its ships!

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, The Lordz

Robotron
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2180
Joined: Tue Nov 23, 2010 3:35 pm

Re: Naval AI not repairing its ships!

Post by Robotron »

I stopped messing with the AI scripts after I got all kinds of strange errors including crazy stuff like "Access violation - no RTTI data" which seems pretty severe to me.
I'll try to "remote-control" the AI via events now.

So for the time being I suggest the following function as a workaround to be inserted into the events list which will repair AI ships which are in ports until they are at full hp.

Code: Select all

function navalrepair()
for alliance in game.alliances do
		if alliance.id ~= 0 and alliance.id ~=  player.alliance.id then  
			
			for faction in alliance.factions do

				for unit in faction.units do
					if unit.alive and unit.type == Unit.NAVAL and unit.hex.construction ~= nil and unit.hex.construction.type == Construction.TYPE_PORT then
						
						if unit.prototype.name == "submarine" or  unit.prototype.name ~= "lightcruiser" then
						
							if unit.hp <= 70 then
							unit.hp = unit.hp + 30		
							faction:ConsumeManpower(2)
							faction:ConsumeProductionPoints(3)
							
							elseif unit.hp <= 80 then
								unit.hp = unit.hp + 20
								faction:ConsumeManpower(1)
								faction:ConsumeProductionPoints(2)
							elseif unit.hp <= 90 then
								unit.hp = unit.hp + 10
								faction:ConsumeManpower(1)
								faction:ConsumeProductionPoints(2)
								end
							
						elseif   unit.prototype.name == "dreadnought" or  unit.prototype.name == "battlecruiser" then
							if unit.hp <= 90 then
							unit.hp = unit.hp + 10		
							faction:ConsumeManpower(1)
							faction:ConsumeProductionPoints(1)
							end
							
						elseif unit.prototype.name == "pre-dreadnought" or  unit.prototype.name == "armouredcruiser" then
							if unit.hp <= 70 then
								unit.hp = unit.hp + 30		
							elseif unit.hp <= 80 then
								unit.hp = unit.hp + 20
							elseif unit.hp <= 90 then
								unit.hp = unit.hp + 10
							
							end
						end
					end
				end
			end
		end
	end
end	


While this won't force the AI to return damaged ships to port it should at least provide repairs at the usual pp/mp costs for ships that are in ports.

Let's see if that helps. 8)
kirk23
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 155
Joined: Wed Jul 18, 2012 1:23 pm

Re: Naval AI not repairing its ships!

Post by kirk23 »

Hi Robotron,
Thanks for the workaround naval repair event, I tried it out and the AI still does not repair its ships sitting in ports?
But one strange thing I have noticed, is if I attack a ship in port with one ship, and its causes damage to the enemy ship in port, and I make a second attack with another ship against the ship in port, instead of it taking damage, it repairs itself by 1 or 2 points? (VERY STRANGE) Anyway thanks for your help its very much appreciated.

I will continue experimenting with your workaround naval event script cheers!


NB: Update I think what is happening is the ships in port are repairing, but their on screen displayed strength is not showing that they have been repaired, and when you attack them again, on the next turn, they do take damage, but it then displays their updated strength, meaning that a ship before an attack was showing a strength of six, after the attack shows a strength of 8 for example!
Robotron
Brigadier-General - Elite Grenadier
Brigadier-General - Elite Grenadier
Posts: 2180
Joined: Tue Nov 23, 2010 3:35 pm

Re: Naval AI not repairing its ships!

Post by Robotron »

Obviously someone forgot to include updating the screen. ;)

*edit*

Maybe it would help if the call to the function be placed in the "TriggerTurnAfterEvents()" function (the one that calls Paris Taxis)?
Post Reply

Return to “Commander the Great War : Mods & Scenario Design”