The fourth chunk (hope im not overwhelming you)
RULE event Tick
Name "latertick"
:action
// basic energy management
Debug("realBattle tick");
AIFleetL3:=GetFreeSel();
SelectShips(AIFleetL3, s.race=#race_raptor);
ExecList(AIFleetL3,
if(s.this:reserveLevel>25, //full power to weapons, hovever we leave reserve for shield augmenting
s.this:tEnergyMode(1, 2);
,
s.this:tEnergyMode(1, 0);
);
if(s.this:shieldLevel<50, //boost shield when low
s.this:tEnergyMode(2, 2);
,
s.this:tEnergyMode(2, 0);
);
);
if(isValid(m.AITeam_leader)&isValid(m.mainTarget)¬(m.mainTarget:wreck)¬(m.AITeam_leader:wreck),
if(range(m.AITeam_leader,m.mainTarget)>3, //main target running away
LocalEvent(GetMainTarget);
);
);
if(isValid(m.secondaryTarget)&isValid(m.mainTarget)¬(m.mainTarget:wreck)¬(m.secondaryTarget:wreck),
if(range(m.secondaryTarget,m.mainTarget)>3, //secondary target running away
LocalEvent(GetSecondaryTarget);
);
);
if(isValid(m.missileTarget)¬(m.missileTarget:wreck),
InBlastRange:=0;
AIFleetL4:=GetFreeSel();
SelectShips(AIFleetL4, s.race=#race_raptor);
ExecList(AIFleetL4,
if(range(m.missileTarget,s.this)=2,
InBlastRange:=1;
);
);
DeleteSelect(AIFleetL4);
if(InBlastRange,LocalEvent(GetSecondaryTarget)); //some of our ships are in blast range - retargeting missiles
);
DeleteSelect(AIFleetL3);
:end
END
Tick 6
RULE event CO_ShipInRange
:action
Debug("In range");
AIFleetL5:=GetFreeSel();
SelectShips(AIFleetL5, s.race=#race_raptor);
ExecList(AIFleetL5,
EnableDodge(s.this, 1);
s.this:tEngineMode(2);
);
DeleteSelect(AIFleetL5);
:end
END
RULE event CO_DeviceDestroyed
condition e.device:owner:race=#race_player&DeviceFocused(e.device,#race_raptor)
:action
LocalEvent(FocusOnDevices);
LocalEvent(GetSecondaryTarget);
:end
END
RULE event ShieldDown
condition e.ship:race=#race_player
:action
LocalEvent(FireMainShield);
:end
END
RULE event ShieldUp
condition E.ship:race=#race_player
:action
LocalEvent(FireMainShield);
:end
END
RULE event FocusOnDevices
:action
PlayerFleetL6:=GetFreeSel();
SelectShips(PlayerFleetL6, s.race=#race_player);
ExecList(PlayerFleetL6,
WGDevL:=GetFreeSel();
SelectDevices(WGDevL, s.this, s.this:damage<100&InSet(S.this, 70)); //focusing on weapon generators
if(isValid(PickFirst(WGDevL)), FocusDevice(PickFirst(WGDevL), #race_raptor, 1));
DeleteSelect(WGDevL);
);
DeleteSelect(PlayerFleetL6);
:end
END
RULE event GetMainTarget
:action
Debug("GetMainTarget");
if(isValid(m.AITeam_leader)¬(m.AITeam_leader:wreck),
PlayerFleetL7:=GetFreeSel();
SelectShips(PlayerFleetL7, s.race=#race_player&range(s.this,m.AITeam_leader)=2&s.this:damage>35); //if there is heavy damaged ship nearby, first finish it off
if(AllNumOf(PlayerFleetL7)>0,
m.mainTarget:=PickMax(PlayerFleetL7,s.this:damage);
,
SelectShips(PlayerFleetL7, s.race=#race_player&range(s.this,m.AITeam_leader)=2); //else we pick most dangerous nearby ship
if(AllNumOf(PlayerFleetL7)>0,
m.mainTarget:=PickMax(PlayerFleetL7, (s.this:tDamage(m.AITeam_leader,2,1)+s.this:tDamage(m.AITeam_leader,2,2)+s.this:tDamage(m.AITeam_leader,2,3)+s.this:tDamage(m.AITeam_leader,3,1)+s.this:tDamage(m.AITeam_leader,3,2)+s.this:tDamage(m.AITeam_leader,3,3)));
,
SelectShips(PlayerFleetL7, s.race=#race_player); //else we pick closest target
if(AllNumOf(PlayerFleetL7)>0, m.mainTarget:=PickMax(PlayerFleetL7, 1 / distance(s.this, m.AITeam_leader)), ChangeState(noTeam0,0));
);
);
ExecList(AIShipSHBusterL,
s.this:tMoveTo(m.mainTarget, 2, 0);
);
LocalEvent(FireMainHull);
LocalEvent(FireMainShield);
DeleteSelect(PlayerFleetL7);
,
LocalEvent(FatalDamaged, E.ship=m.AITeam_leader);
);
:end
END
RULE event GetSecondaryTarget
:action
Debug("GetSecondaryTarget");
if(NumOf(AIShipDeviceBusterL)>0,
if(isValid(m.mainTarget)¬(m.mainTarget:wreck),
PlayerFleetL8:=GetFreeSel();
SelectShips(PlayerFleetL8, s.race=#race_player&(range(s.this,m.mainTarget)=2|range(s.this,m.mainTarget)=3)); // we want to have main target in device buster ships artilery range
if(AllNumOf(PlayerFleetL8)>0, m.secondaryTarget:=PickMax(PlayerFleetL8, (s.this:tDamage(m.AITeam_leader,2,1)+s.this:tDamage(m.AITeam_leader,2,2)+s.this:tDamage(m.AITeam_leader,2,3)+s.this:tDamage(m.AITeam_leader,3,1)+s.this:tDamage(m.AITeam_leader,3,2)+s.this:tDamage(m.AITeam_leader,3,3))), m.secondaryTarget:=m.mainTarget); //most dangerous opponent
DeleteSelect(PlayerFleetL8);
,
LocalEvent(GetMainTarget);
);
ExecList(AIShipDeviceBusterL,
s.this:tMoveTo(m.secondaryTarget, 2, 0);
);
,
m.secondaryTarget:=m.mainTarget;
);
LocalEvent(FireToSecondary);
:end
END
RULE event GetMissileTarget
:action
Debug("GetMissileTarget");
if(isValid(m.AITeam_leader)¬(m.AITeam_leader:wreck),
PlayerFleetL9:=GetFreeSel();
SelectShips(PlayerFleetL9, s.race=#race_player&range(s.this,m.AITeam_leader)>2);
if(AllNumOf(PlayerFleetL9)>0,
AIFleetL9:=GetFreeSel();
SelectShips(AIFleetL9, s.race=#race_raptor&s.this!=m.AITeam_leader); // we don't want to have any AI ships in blast range
if(AllNumOf(AIFleetL9)>0,
ExecList(PlayerFleetL9,
PotentialTarget:=s.this;
ExecList(AIFleetL9,
if(range(PotentialTarget,s.this)=2,
RemoveItem(PlayerFleetL9, PotentialTarget);
);
);
);
);
DeleteSelect(AIFleetL9);
if(NumOf(PlayerFleetL9)>0,
m.missileTarget:=PickMax(PlayerFleetL9, 1 / distance(s.this, m.AITeam_leader));
LocalEvent(FireMissile);
);
);
DeleteSelect(PlayerFleetL9);
,
LocalEvent(FatalDamaged, E.ship=m.AITeam_leader);
);
:end
END
RULE event FireMainHull
:action
Debug("FireMainHull");
if(isValid(m.AITeam_leader)&isValid(m.mainTarget)¬(m.mainTarget:wreck)¬(m.AITeam_leader:wreck),
AIFleetL10:=GetFreeSel();
SelectShips(AIFleetL10, s.race=#race_raptor);
ExecList(AIFleetL10,
s.this:tSetForbid(#FORBID_FIRE);
s.this:tSetForbid(#FORBID_FIRE_BOMBER);
AIFleetWeaponL10:=GetFreeSel();
SelectDevices(AIFleetWeaponL10, s.this, S.working&S.weapon&s.count!=0&s.hullValue=1);
ExecList(AIFleetWeaponL10,
s.this:contFire:=1;
ActivateDevice(S.this, 1);
TargetWeapon(s.this, m.mainTarget);
);
DeleteSelect(AIFleetWeaponL10);
AIFleetBomberL10:=GetFreeSel();
SelectDevices(AIFleetBomberL10, s.this, s.hullValue=1&s.working&(Inset(s.this,20)|Inset(s.this,21)|Inset(s.this,22)));
ExecList(AIFleetBomberL10,WeaponMode(S.this,5,m.mainTarget));
DeleteSelect(AIFleetBomberL10);
);
DeleteSelect(AIFleetL10);
);
:end
END
RULE event FireMainShield
:action
Debug("FireMainShield");
if(isValid(m.AITeam_leader)¬(m.AITeam_leader:wreck),
if(isValid(m.mainTarget)¬(m.mainTarget:wreck),
AIFleetL11:=GetFreeSel();
SelectShips(AIFleetL11, s.race=#race_raptor);
ExecList(AIFleetL11,
AIFleetWeaponL11:=GetFreeSel();
SelectDevices(AIFleetWeaponL11, s.this, S.working&S.weapon&s.count!=0&s.hullValue=0&s.shieldValue=1);
ExecList(AIFleetWeaponL11,
s.this:contFire:=1;
ActivateDevice(S.this, 1);
if(m.mainTarget:isShielded,
TargetWeapon(s.this, m.mainTarget);
,
if(isValid(m.secondaryTarget)¬(m.secondaryTarget:wreck)
if(m.secondaryTarget:isShielded,
TargetWeapon(s.this, m.secondaryTarget);
,
PlayerFleetL11:=GetFreeSel();
SelectShips(PlayerFleetL11, s.race=#race_player&s.this:isShielded);
if(AllNumOf(PlayerFleetL11)>0,
TargetWeapon(s.this,PickMax(PlayerFleetL11, 1 / distance(s.this, m.AITeam_leader)));
);
);
,
LocalEvent(GetSecondaryTarget);
);
);
);
);
DeleteSelect(AIFleetL11);
,
LocalEvent(GetMainTarget);
);
);
:end
END