I don't know if somebody already solved the problem of the number of AI fleets in this way but I haven't seen anything similiar yet, so maybe it would be useful.
Our goal is to give AI constant opportunity to naval invasions but in the meantime we won't another stack spam caused by AI itself (by setting recruit priority offset high) or by our script (by setting regular fleet spawn every few turns) and the key to achieve this is the character label. When I tried to make work my first script regarding to army spawn I came across Withwnar's post (so all credits for him) concerning a possibility to reusing character labels and there was a conclusion that it is possible in the case of admirals. And at that moment I had the idea to use this possibility to solve the mentioned problem.
So, let's go:
Code:
monitor_event PreFactionTurnStart TrueCondition ; in the first turn all factions got their fleets and it's how we start our loop
if I_IsFactionAIControlled england ; it's only for the AI
spawn_army
faction england
character random_name, admiral, age 16, x 76, y 211, label engfleet ; we have to define separate label for every fleet of every faction
unit holk exp 3 armour 0 weapon_lvl 0
unit holk exp 3 armour 0 weapon_lvl 0
unit holk exp 3 armour 0 weapon_lvl 0 ; of curse it's your decision how big the fleet would be
end
; here we can add more fleets for this faction
end_if
; and here is the space for other factions fleets
terminate_monitor ; we need this monitor to fire only once
end_monitor
And now it's another monitor, which stay with us until the end of time:
Code:
monitor_event PreFactionTurnStart FactionType slave
if I_IsFactionAIControlled england
and I_NumberOfSettlements england > 0 ; we need fleets only for living factions (I don't know if it would be a problem to spawn a fleet for non-existing faction)
and not I_CharacterExists engfleet ; and here we repeat earlier defined label to make sure that when our admiral dies there will be another one
spawn_army
faction england
character random_name, admiral, age 16, x 76, y 211, label engfleet ; and here it stays like before, to make repeat spawn our fleet until the end of time
unit holk exp 3 armour 0 weapon_lvl 0
unit holk exp 3 armour 0 weapon_lvl 0
unit holk exp 3 armour 0 weapon_lvl 0
end
end_if
end_monitor
As you see, it's quite simple script and should ensure that AI factions always will have at least one fleet. I'm not sure if admiral can die without lost all of the ships (apart form his natural death but it could be partially solved by setting his age below 20), because if he can, then there is a risk to spawn another fleet before the latter is destroyed. Still, I thnik it's a far better solution than constant spawning another fleets regardless whether the previous one was destroyed.