Really pleased with the effect with this script! Been playtesting (with Thargoid's Second Wave installed
), spawning a bar and 15 thargoids by the w/p. The Gunners are opening up on the bugs, but stopping fire if they hit a hunter or a clean ship by mistake and the hunters break off if they hit the bar, another clean ship or each other by mistake. By using FRIENDLY_FIRE and ENEMY_FIRE as AI messages, they send curses (but don't attack) if hit by friendly fire or say sorry if they hit friendly ship. Still need to playtest a bit more, but seems to be working.
Script
Code: Select all
/*
this.name = "oolite-random-hits-spacebar";
this.author = "LittleBear, Eric Walch & Thargoid";
this.copyright = "November 2008 - But do what you like with it in your OXPs!";
this.description = "Checks the role of a ship attacking a spacebar to avoid friendly fire incidents between the bar's turret gunners and hunters launched by the bar."
this.version = "2.0";
*/
this.shipBeingAttacked = function(who)
{
if(who.primaryRole == "random_hits_patrol")
{
this.ship.reactToAIMessage("LAWFUL_ATTACK"); // The AIs of the bars and hunters do not react to the nomal "ATTACKED" message, only the special "ENEMY_ATTACK". They therefore ignore attacks by their own side and the police. The lawful attacker has it's AI set to randomhitsbackoffAI which forces it to off and stop attacking, before being returned to its normalAI.
this.ship.bounty = 0
}
if(who.primaryRole == "police")
{
this.ship.reactToAIMessage("LAWFUL_ATTACK"); // Since neither police or hunter ships will deliberatley target a Clean Target - bar is kept clean at all times - The Bar takes attackes by ships with these roles as a friendly fire stray shot and does not fire back.
this.ship.bounty = 0
}
else
{
this.ship.reactToAIMessage("ENEMY_ATTACK"); // Any other attack is met with deadly force!
this.ship.bounty = 0
}
}
SpaceBar's Attack State:-
Code: Select all
"ATTACK" = {
"ENEMY_ATTACK" = (setTargetToFoundTarget, "sendTargetCommsMessage: [spacebar-warning]", "markTargetForOffence: 51", increaseAlertLevel, groupAttackTarget);
"LAWFUL_ATTACK" = (setTargetToFoundTarget, "safeScriptActionOnTarget: setAITo: randomhitsbreakoffAI.plist", setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_PLAYER");
"OFFENCE_COMMITTED" = (setTargetToFoundTarget, "markTargetForOffence: 15", increaseAlertLevel, "sendTargetCommsMessage: [spacebar-warning]", groupAttackTarget);
"ACCEPT_DISTRESS_CALL" = (setTargetToFoundTarget, increaseAlertLevel, "launchShipWithRole: random_hits_patrol", groupAttackTarget);
"ENTER" = ("launchShipWithRole: random_hits_patrol", checkTargetLegalStatus, increaseAlertLevel);
"EXIT" =();
"INCOMING_MISSILE" = (fireECM, setTargetToFoundTarget, "sendTargetCommsMessage: [spacebar-warning]", "markTargetForOffence: 51", increaseAlertLevel);
"NO_TARGET" = (setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_PLAYER");
"RED_ALERT" = ("launchShipWithRole: random_hits_patrol");
"CONDITION_GREEN" = (setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_PLAYER");
"TARGET_DESTROYED" = (setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_PLAYER");
"TARGET_LOST" = (setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_PLAYER");
"TARGET_CLEAN" = ("sendTargetCommsMessage: [random_hits_sorry_for_friendly_fire]", setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_PLAYER");
"UPDATE" = ("pauseAI: 1.0", checkTargetLegalStatus, decreaseAlertLevel, performAttack); };
Hunter's Attack States :-
Code: Select all
"ATTACK_ATTACKING_SHIP" = {
ENTER = (performAttack);
"ENEMY_ATTACK" = (setTargetToFoundTarget, "markTargetForOffence: 15", performAttack);
"FRIENDLY_FIRE" = ( "setStateTo: FRIENDLY_FIRE_INCIDENT");
"ENERGY_LOW" = (setTargetToFoundTarget, performAttack);
"INCOMING_MISSILE" = (fightOrFleeMissile, setTargetToFoundTarget, "markTargetForOffence: 15", performAttack);
"TARGET_DESTROYED" = (setTargetToSystemStation, "setStateTo: RANGE_CHECK");
"TARGET_LOST" = (setTargetToSystemStation, "setStateTo: RANGE_CHECK");
"FRUSTRATED" = (performAttack);
EXIT = ();
UPDATE = ();
};
"ATTACK_SELECTED_TARGET" = {
ENTER = (checkTargetLegalStatus);
"ENEMY_ATTACK" = (setTargetToFoundTarget, "markTargetForOffence: 15", "setStateTo: ATTACK_ATTACKING_SHIP");
"ENERGY_LOW" = (setTargetToFoundTarget, performAttack);
"INCOMING_MISSILE" = (fightOrFleeMissile, "markTargetForOffence: 15", performAttack);
"TARGET_DESTROYED" = (setTargetToSystemStation, "setStateTo: RANGE_CHECK");
"TARGET_LOST" = (setTargetToSystemStation, "setStateTo: SCAN_FOR_CRIMINAL_TRADERS");
"TARGET_CLEAN" = ("setStateTo: SORRY_FOR_FRIENDLY_FIRE_INCIDENT");
"FRIENDLY_FIRE" = ("setStateTo: FRIENDLY_FIRE_INCIDENT");
"FRUSTRATED" = (performAttack);
EXIT = ();
UPDATE = (checkTargetLegalStatus, performAttack);
};
"FRIENDLY_FIRE_INCIDENT" = {
ENTER = ("commsMessage: [random_hits_friendly_fire]", setTargetToFoundTarget, "addFuel: 3", "setSpeedFactorTo: 2.0", "setDesiredRangeTo: 2500", performFlee);
"ENERGY_LOW" = ();
"INCOMING_MISSILE" = (setTargetToFoundTarget, fightOrFleeMissile, performFlee);
"ENEMY_ATTACK" = (setTargetToFoundTarget, "setStateTo: ATTACK_ATTACKING_SHIP");
"TARGET_LOST" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
"TARGET_DESTROYED" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
EXIT = ();
"REACHED_SAFETY" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
"DESIRED_RANGE_ACHIEVED" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
UPDATE = (); };
"SORRY_FOR_FRIENDLY_FIRE_INCIDENT" = {
ENTER = ("commsMessage: [random_hits_sorry_for_friendly_fire]", setTargetToFoundTarget, "addFuel: 3", "setSpeedFactorTo: 2.0", "setDesiredRangeTo: 2500", performFlee);
"ENERGY_LOW" = ();
"INCOMING_MISSILE" = (setTargetToFoundTarget, fightOrFleeMissile, performFlee);
"ENEMY_ATTACK" = (setTargetToFoundTarget, "setStateTo: ATTACK_ATTACKING_SHIP");
"TARGET_LOST" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
"TARGET_DESTROYED" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
EXIT = ();
"REACHED_SAFETY" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
"DESIRED_RANGE_ACHIEVED" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: FRIENDLY_FIRE_INCIDENT_PAUSE");
UPDATE = (); };
"FRIENDLY_FIRE_INCIDENT_PAUSE" = {
ENTER = (setTargetToSystemStation, "setSpeedFactorTo: 1.0", performIdle, "pauseAI: 1.0");
"ENERGY_LOW" = ();
"INCOMING_MISSILE" = (setTargetToFoundTarget, fightOrFleeMissile, "setStateTo: ATTACK_ATTACKING_SHIP");
"ENEMY_ATTACK" = (setTargetToFoundTarget, "setStateTo: ATTACK_ATTACKING_SHIP");
EXIT = ();
UPDATE = ("setStateTo: RANGE_CHECK"); };
BreakOffAI to force the Lawful Attacker to stop attacking and back off:-
Code: Select all
{
"GLOBAL" = {
ENTER = ("commsMessage: [random_hits_sorry_for_friendly_fire]", "setStateTo: BREAK_OFF_ATTACK");
EXIT = ();
UPDATE = (); };
"BREAK_OFF_ATTACK" = {
ENTER = ("addFuel: 3", "setSpeedFactorTo: 2.0", "setDesiredRangeTo: 5500", performFlee);
"ENERGY_LOW" = ();
"INCOMING_MISSILE" = (setTargetToFoundTarget, performFlee);
"TARGET_LOST" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: BREAK_OFF_ATTACK_PAUSE");
"TARGET_DESTROYED" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: BREAK_OFF_ATTACK_PAUSE");
EXIT = ();
"REACHED_SAFETY" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: BREAK_OFF_ATTACK_PAUSE");
"DESIRED_RANGE_ACHIEVED" = (performIdle, "addFuel: -3", setTargetToSystemStation, "setStateTo: BREAK_OFF_ATTACK_PAUSE");
UPDATE = (); };
"BREAK_OFF_ATTACK_PAUSE" = {
ENTER = ("setSpeedFactorTo: 1.0", performIdle);
"ENERGY_LOW" = ();
EXIT = ();
UPDATE = ("pauseAI: 1.0", setTargetToSystemStation, exitAI); };
}
And some entries in descriptions for some curses / applogies. If anybody wants to post some more I'll C&P them in! :-
Code: Select all
<!-- Strings used for hunters' complaints / appologies over friendly fire incidents! -->
<key>random_hits_friendly_fire</key>
<array>
<string>[random_hits_friendly_fire1] [assassination_board_insult]! [random_hits_friendly_fire2]</string>
</array>
<key>random_hits_friendly_fire1</key>
<array>
<string>Blue on Blue</string>
<string>I'm on your side</string>
<string>Watch your fire</string>
</array>
<key>random_hits_friendly_fire2</key>
<array>
<string>Stop it!</string>
<string>Cease your attack!</string>
<string>Be more careful!</string>
<string>Check your targets!</string>
<string>Are you blind?</string>
<string>Do I look like a [spacebar-warning2]?</string>
</array>
<key>random_hits_sorry_for_friendly_fire</key>
<array>
<string>[random_hits_sorry_for_friendly_fire1] [random_hits_sorry_for_friendly_fire2]. [random_hits_sorry_for_friendly_fire3]!</string>
</array>
<key>random_hits_sorry_for_friendly_fire1</key>
<array>
<string>Sorry</string>
<string>My appologies</string>
<string>I beg your pardon</string>
</array>
<key>random_hits_sorry_for_friendly_fire2</key>
<array>
<string>dude</string>
<string>buddy</string>
<string>mate</string>
</array>
<key>random_hits_sorry_for_friendly_fire3</key>
<array>
<string>There are trumbles in my targeting computer</string>
<string>My mistake</string>
<string>I thought you were a [spacebar-warning2]</string>
</array>