Scripts/nexus_conditions.js |
/* nexus_conditions.js */
/*
------------------------
JSHINT: Options
------------------------
*/
/*jshint esversion: 6*/
/*jshint sub:true*/
this.name = "nexus_conditionsScript";
this.author = "UK_Eliter";
this.description = "Conditions script for Nexus missile";
this.copyright = "2014 Creative Commons: attribution, non-commercial, sharealike.";
this.licence = "CC-NC-SA 3";
/*
--------------
DEBUG SWITCHES
--------------
*/
//this.logging = true; // THIS SHOULD BE COMMENTED OUT WHEN NOT TESTING
//this.debug = false;
/*
------------------------
JSHINT: start of wrapper
------------------------
*/
(function() {
"use strict";
/*
---------
MAIN CODE
---------
*/
this.allowAwardEquipment = function(eqKey, ship, context) {
var chance = 0;
//
switch (eqKey) {
case "EQ_NEXUS_BASIC_MISSILE":
chance = 0.9;
break;
case "EQ_NEXUS_PREMIUM_MISSILE":
chance = 0.8;
break;
case "EQ_NEXUS_ULTIMATE_MISSILE":
chance = 0.6;
break;
case "EQ_NEXUS_BUG_MISSILE":
if (player.ship.dockedStation === "Navy SecCom Station") {
chance = 0.9;
} else {
chance = 0.4;
}
break;
case "EQ_NEXUS_BUG_R_MISSILE":
if (player.ship.dockedStation === "Navy SecCom Station") {
chance = 0.5;
} else {
chance = 0.8;
}
}
if (chance === 0) {
return false;
}
if (Math.random() < 0.9) {
if (system.scrambledPseudoRandomNumber(5922) < chance) {
return true;
}
} else if (Math.random() < chance) {
return true;
}
return false;
};
/*
----------------------
JSHINT: end of wrapper
----------------------
*/
}).call(this);
// EOF |
Scripts/nexus_missile_basicOrPremiumOrUltimate.js |
/* nexus_missile_basicOrPremiumOrUltimate.js */
/*
------------------------
JSHINT: Options
------------------------
*/
/*jshint esversion: 6*/
/*jshint sub:true*/
this.name = "nexus_missile_basicOrPremiumOrUltimate";
this.author = "UK_Eliter";
this.description = "";
this.copyright = "2014 Creative Commons: attribution, non-commercial, sharealike.";
this.licence = "CC-NC-SA 3";
/*
------------------
DEBUGGING SWTICHES
------------------
*/
//this.logging = true; // THIS SHOULD BE COMMENTED OUT WHEN NOT TESTING
/*
-------
GLOBALS
-------
*/
this.debug = false;
this.typeOfNexusMissile = "undetermined";
/*
------------------------
JSHINT: start of wrapper
------------------------
*/
(function() {
"use strict";
/*
====================
MAIN CODE
====================
*/
this.shipSpawned = function() {
this.MissileEnergyThreshhold = this.ship.maxEnergy * 0.8;
if (this.ship.hasRole("EQ_NEXUS_BASIC_MISSILE")) {
this.typeOfNexusMissile = "basic";
} else if (this.ship.hasRole("EQ_NEXUS_PREMIUM_MISSILE")) {
this.typeOfNexusMissile = "premium";
} else {
this.typeOfNexusMissile = "ultimate";
}
delete this.shipSpawned;
};
this.shipTakingDamage = function(amount, whom, type) {
if (this.ship.target) {
if (whom == this.ship.target) {
if (type === "scrape damage") {
this.$detonate();
return;
}
}
}
if (amount > 60 && Math.random() < 0.9) {
return;
}
if (this.ship.energy > this.MissileEnergyThreshhold || Math.random() > 0.8) {
return;
}
this.$spawnWarheads();
};
this.$isHostile = function(e) {
// if (this.debug) {player.consoleMessage("Hostile scan from MISSILE script", 6);}
return e.isShip && e.hasHostileTarget && (e.target == this.ship.owner);
};
this.$spawnWarheads = function() {
// SPAWN THE WARHEADS & do related stuff *
// Note: original missile will be removed by its AI
if (!this.ship || !this.ship.owner || !this.ship.owner.isValid) {
return;
}
var numWarheads;
var submunition;
switch (this.typeOfNexusMissile) {
case "basic":
numWarheads = 3;
submunition = "nexus_warhead";
break;
case "premium":
numWarheads = 3;
submunition = "nexus-premium-warhead";
break;
case "ultimate":
numWarheads = 4;
submunition = "nexus-ultimate-warhead";
}
// Actual spawn
var warheads = this.ship.spawn(submunition, numWarheads); // this will set warheads targets to the missile's target
var counter;
// set the owner of the warhead to the original missile's owner. Can't set '.owner' because read-only.
for (counter = 0; counter < numWarheads; counter++) {
warheads[counter].ultimateOwner = this.ship.owner;
}
// ALLOCATE TARGETS etc TO THE WARHEADS *
var targets = system.filteredEntities(this, this.$isHostile, this.ship.owner, this.ship.owner.scannerRange);
var numTargets = targets.length;
// NN: NOT 'if (numTargets < 2)' - i.e. abort if no target or one target - because could be one hostile AND missile's original target. We will investigate that below.
if (numTargets < 1) {
// if (this.debug) {player.consoleMessage("Missile script - No hostiles", 8);}
this.ship.explode(); // Do need this here!
return; // need do nothing else, because all the warheads will be set to what is, presently, their only possible target, = the original one. (If that target's been lost, the warhead AI will deal with that.)
}
// Create an array of possible targets, and a corresponding array that will record whether a potential target has yet been targeted
var isTargetTargetted = new Array(numTargets);
for (counter = 0; counter < numTargets; counter++) {
isTargetTargetted[counter] = false;
}
var startWarheadCounterAt;
if (this.ship.target && this.ship.target.isValid) {
// if (this.debug) {player.consoleMessage("Warhead 0 target is"+warheads[0].target, 8);player.consoleMessage("Num targets is "+numTargets, 8);}
// Now see if the target warheads inherited from the missile is *amongst the array of possible targets.* If it is (may not be, 'cos initial target may not be hostile) mark the ship as targetted.
for (counter = 0; counter < numTargets; counter++) {
if (targets[counter] == warheads[0].target) {
isTargetTargetted[counter] = true;
break;
}
}
startWarheadCounterAt = 1; // determine which warhead the targetting procedure should start with
} else {
startWarheadCounterAt = 0;
}
// Use the array of potential targets (hostiles) to assign targets to rest of the warheads (that 'rest' being either (1) all of them or (2) all but the first one)
// if (this.debug) {player.consoleMessage("Script targetting starts with (could be 0): "+startWarheadCounterAt, 6);}
var warheadCounter;
for (warheadCounter = startWarheadCounterAt; warheadCounter < numWarheads; warheadCounter++) {
for (counter = 0; counter < numTargets; counter++) {
if (!isTargetTargetted[counter]) {
warheads[warheadCounter].target = targets[counter];
isTargetTargetted[counter] = true;
// if (this.debug) {player.consoleMessage("Warhead "+ warheadCounter +" target: "+ targets[counter], 6);}
break; // have given the warhead a target, so should stop trying to do that!
}
}
}
this.ship.explode();
};
this.$detonate = function() {
// function dealEnergyDamage(damage : Number, idealRange : Number [, velocityBias : Number])
// The standard Oolite missile uses dealEnergyDamage(170, 32.5, 0.25), has a maximum speed of 0.75LM, and its AI tries to detonate it 25m from its target. [NB: If target within ideal range, takes full damage.]
switch (this.typeOfNexusMissile) {
case "basic":
this.ship.dealEnergyDamage(330, 50, 0.25);
break;
case "premium":
this.ship.dealEnergyDamage(470, 70, 0.25);
break;
case "ultimate":
this.ship.dealEnergyDamage(600, 90, 0.25);
}
this.ship.explode();
};
/*
=======================
JSHINT: end of wrapper
=======================
*/
}).call(this);
// EOF |
Scripts/nexus_missile_bugOff.js |
/* nexus_missile_bugOff.js */
/*
------------------------
JSHINT: Options
------------------------
*/
/*jshint esversion: 6*/
/*jshint sub:true*/
this.name = "nexus_missile_bugOff";
this.author = "UK_Eliter";
this.description = "Script for Nexus BugOff missile";
this.copyright = "2014 Creative Commons: attribution, non-commercial, sharealike.";
this.licence = "CC-NC-SA 3";
/*
--------------
DEBUG SWTICHES
--------------
*/
// this.logging = true; // THIS SHOULD BE COMMENTED OUT WHEN NOT TESTING
// this.debug = false;
/*
------------------------
JSHINT: start of wrapper
------------------------
*/
(function() {
"use strict";
/*
---------
MAIN CODE
---------
*/
this.shipSpawned = function() {
this.MissileEnergyThreshhold = this.ship.maxEnergy * 0.7;
delete this.shipSpawned;
};
this.shipTakingDamage = function(amount) {
if (amount > 65 || this.ship.energy > this.MissileEnergyThreshhold) {
return;
}
if (Math.random() < 0.9) {
this.$spawnWarheads();
}
};
this.$spawnWarheads = function() {
var chanceMalfunction;
if (this.ship.hasRole("EQ_NEXUS_BUG_R_MISSILE")) {
chanceMalfunction = 0.1;
} else {
chanceMalfunction = 0.025;
}
var totalNumberOfWarheadsToBeSpawned;
if (Math.random() < chanceMalfunction) {
// Malfunctioning missile
totalNumberOfWarheadsToBeSpawned = ~~(Math.random() * 5); // = Between - and 4.
if (totalNumberOfWarheadsToBeSpawned < 3) {
if (Math.random() < 0.7) {
totalNumberOfWarheadsToBeSpawned++;
} else if (totalNumberOfWarheadsToBeSpawned === 0) {
if (Math.random() < 0.3) {
this.ship.explode();
} else {
this.ship.switchAI("nullAI.plist");
}
return;
}
}
} else {
totalNumberOfWarheadsToBeSpawned = 5;
}
var primaryWarhead = this.ship.spawnOne("nexus-bug-warhead-primary");
// PRIMARY warhead. Its target will be the missile's target
if (totalNumberOfWarheadsToBeSpawned > 1) {
var secondaryWarheads;
if (!primaryWarhead || !primaryWarhead.isValid) {
secondaryWarheads = this.ship.spawn("nexus-bug-warhead-secondary", totalNumberOfWarheadsToBeSpawned);
// this will set warheads targets to the missile's target
} else {
secondaryWarheads = this.ship.spawn("nexus-bug-warhead-secondary", (totalNumberOfWarheadsToBeSpawned - 1));
// this will set warheads targets to the missile's target
}
}
// this.ship.switchAI("nullAI.plist");
this.ship.explode();
};
this.$detonate = function() {
// Called only by AI.
this.ship.dealEnergyDamage(650, 50, 0.25);
this.ship.explode();
};
/*
----------------------
JSHINT: end of wrapper
----------------------
*/
}).call(this);
// EOF |
Scripts/nexus_warhead_basicOrPremiumOrUltimate.js |
/* nexus_warhead_basicOrPremiumOrUltimate.js */
/*
------------------------
JSHINT: Options
------------------------
*/
/*jshint esversion: 6*/
/*jshint sub:true*/
this.name = "nexus_warhead_basicPremiumOrUltimate";
this.author = "UK_Eliter";
this.description = "Script for Nexus missile warheads";
this.copyright = "2014 Creative Commons: attribution, non-commercial, sharealike.";
this.licence = "CC-NC-SA 3";
// Associated AI: nexus_warheadAI.PLIST
/*
--------------
DEBUG SWTICHES
--------------
*/
//this.logging = true; // THIS SHOULD BE COMMENTED OUT WHEN NOT TESTING
//this.debug = false;
/*
-------
GLOBALS
-------
*/
this.typeOfWarhead = 0; // This gets set to something meaningful below.
/*
------------------------
JSLINT: start of wrapper
------------------------
*/
(function() {
"use strict";
/*
--------------
EVENT HANDLERS
--------------
*/
this.shipSpawned = function() {
if (this.ship.primaryRole === "nexus_warhead") {
this.typeOfWarhead = 1; // 1 = basic
} else if (this.ship.primaryRole === "nexus-premium-warhead") {
this.typeOfWarhead = 2; // 2 = premium;
} else {
this.typeOfWarhead = 3; // 3 = ultimate;
}
this.oldTarget = 0;
delete this.shipSpawned;
};
this.shipTakingDamage = function(amount, whom, type) {
//if (this.debug) {player.consoleMessage("Warhead AI - taking damage:" + amount, 5);}
if (amount > 14) {
return;
}
if (Math.random() < 0.2) {
this.ship.energy = this.ship.energy + amount; // Prevent it from being destroyed - but also so that we can *detonate* it.
this.$detonate();
}
};
/*
---------------
OTHER FUNCTIONS
---------------
*/
this.$detonateOrSeek = function() {
if (this.ship.target && !this.ship.target.isValid) {
this.$detonate();
return;
}
this.ship.reactToAIMessage("SCRIPT_SEEK");
};
this.$scanForTargets = function() {
//if (this.debug) {player.consoleMessage("Scanning for targets", 6);}
function $isHostileToOwnerOrWarhead(e) {
if (this.ship.ultimateOwner && this.ship.ultimateOwner.isValid) {
return e.isShip && e.hasHostileTarget && (e.target == this.ship.ultimateOwner || e.target == this.ship);
} else {
return e.isShip && e.hasHostileTarget && (e.target == this.ship);
}
}
var targetsArray = system.filteredEntities(this, $isHostileToOwnerOrWarhead, this.ship, this.ship.scannerRange);
if (targetsArray.length > 0) {
this.ship.target = targetsArray[0]; // go for nearest
this.ship.reactToAIMessage("TARGET");
this.ship.oldTarget = this.ship.target;
} else if ((this.oldTarget !== 0) && this.oldTarget.isValid) {
//if (this.debug) {player.consoleMessage("Nexus warhead - located first found target", 4);}
this.ship.target = this.oldTarget;
this.ship.reactToAIMessage("TARGET");
this.oldTarget = 0; // reset it
} else {
this.ship.reactToAIMessage("NO_TARGET");
}
};
this.$detonate = function() {
// function dealEnergyDamage(damage : Number, idealRange : Number [, velocityBias : Number])
// The standard Oolite missile uses dealEnergyDamage(170, 32.5, 0.25), has a maximum speed of 0.75LM, and its AI tries to detonate it 25m from its target. [NB: If target within ideal range, takes full damage.]
//
// 1 = basic; 2 = premium; 3 = ultimate.
switch (this.typeOfWarhead) {
case 1:
this.ship.dealEnergyDamage(110, 27, 0.25);
break;
case 2:
this.ship.dealEnergyDamage(150, 31, 0.22);
break;
case 3:
this.ship.dealEnergyDamage(195, 36, 0.15);
}
this.ship.explode();
};
/*
----------------------
JSHINT: end of wrapper
----------------------
*/
}).call(this);
// EOF |
Scripts/nexus_warhead_bugOff.js |
/* nexus_warhead_bugOff.js */
/*
------------------------
JSHINT: Options
------------------------
*/
/*jshint esversion: 6*/
/*jshint sub:true*/
this.name = "nexus_warhead_bugOff";
this.author = "UK_Eliter";
this.description = "Script for Nexus BugOff warhead";
this.copyright = "2014 Creative Commons: attribution, non-commercial, sharealike.";
this.licence = "CC-NC-SA 3";
// Associated AI nexus_warheadAI.PLIST
/*
--------------
DEBUG SWTICHES
---------------
*/
//this.logging = true; // THIS SHOULD BE COMMENTED OUT WHEN NOT TESTING
//this.debug = false;
/*
------------------------
JSHINT: start of wrapper
------------------------
*/
(function() {
"use strict";
/*
---------
MAIN CODE
---------
*/
this.$isBug = function(e) {
return e.isShip && e.isThargoid;
};
// Called only by AI.
this.$detonate = function() {
this.ship.dealEnergyDamage(140, 30, 0.14);
// function dealEnergyDamage(damage : Number, idealRange : Number [, velocityBias : Number])
// The standard Oolite missile uses dealEnergyDamage(170, 32.5, 0.25), has a maximum speed of 0.75LM, and its AI tries to detonate it 25m from its target. [NB: If target within ideal range, takes full damage.]
// Deal additional damage to anything thargoid.
var s = system.filteredEntities(this, this.$isBug, this.ship, 150);
var i = s.length;
while (i--) {
s[i].energy -= 65;
}
// Remove the warhead.
this.ship.explode();
};
/*
----------------------
JSHINT: end of wrapper
----------------------
*/
}).call(this);
// EOF |