Config/script.js |
//This oxp was created mainly as a learning experience. But also to give me better tracking on splinters when mining. Works Great with OreProcessor
//It was heavily influenced by Capt. Murphy's IFF Police Scanner Upgrade
"use strict";
this.name ="NS_Mining_Scanner_Upgrade";
this.author ="NewtSoup";
this.copyright ="2017 NewtSoup";
this.licence ="CC BY-NC-SA 3.0"; // see http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info
this.description="Upgrade to the IFF Scanner to show Asteroids as white/gray, Boulders as white/orange and Splinters and Alloys ( collectible ) as white/green - with an optional add-on to include Cargo containers as white/cyan and Escape pods as white/purple.";
this.version ="1.1.3";
this.startUp = function()
{
// initialize variables
this.$equip_scanner_ok = false;
this.$scavenger_upgrade = false;
this.$MiningScannerTimer = null;
}
this._startTimer = function()
{
if (this.$MiningScannerTimer) //if there is an existing timer already, simply restart it
{
this.$MiningScannerTimer.start();
//player.consoleMessage("Mining IFF Scanner Upgrade Active");
}
else //otherwise, create a new timer called $MiningScannerTimer to call this._identifyRocks every 300 milliseconds and attach it to this equipment
{
this.$MiningScannerTimer = new Timer ( this, this._identifyRocks, 0, 0.3);
}
}
this._stopTimer = function()
{
//if scanner timer exists and is running then stop it
if (this.$MiningScannerTimer && this.$MiningScannerTimer.isRunning)
{
this.$MiningScannerTimer.stop();
//player.consoleMessage("Mining IFF Scanner Upgrade Stopped");
}
}
//catch the playerBoughtEquipment event for removing the scanner or the hack
this.playerBoughtEquipment = function (equipment, paid) // 1.89 adds second parameter (paid), but we don't need it
{
switch (equipment)
{
case "EQ_NS_MINING_SCANNER_UPGRADE_REMOVAL":
//remove the scanner
player.ship.removeEquipment("EQ_NS_MINING_SCANNER_UPGRADE");
//remove the removal service placeholder as we don't want it to appear in the ship's installed equipment list
player.ship.removeEquipment("EQ_NS_MINING_SCANNER_UPGRADE_REMOVAL");
//refund the player the cost of the scanner
player.credits += EquipmentInfo.infoForKey("EQ_NS_MINING_SCANNER_UPGRADE").price;
//check for the scavenger hack and if it exists then remove that too
if ( player.ship.equipmentStatus("EQ_NS_SCANNER_SCAVENGER_HACK") !== "EQUIPMENT_UNAVAILABLE" )
{
player.ship.removeEquipment("EQ_NS_SCANNER_SCAVENGER_HACK");
}
break;
case "EQ_NS_UNDO_SCANNER_SCAVENGER_HACK":
//remove the scanner hack
player.ship.removeEquipment("EQ_NS_SCANNER_SCAVENGER_HACK");
//remove the removal service placeholder
player.ship.removeEquipment("EQ_NS_UNDO_SCANNER_SCAVENGER_HACK");
break;
}
}
//catch event when the player has launched
this.shipLaunchedFromStation = function (station)
{
if ( player.ship.status === "STATUS_IN_FLIGHT" ) // double check
{
this.$equip_scanner_ok = player.ship.equipmentStatus("EQ_NS_MINING_SCANNER_UPGRADE") === "EQUIPMENT_OK"; // true or false
this.$scavenger_upgrade = player.ship.equipmentStatus("EQ_NS_SCANNER_SCAVENGER_HACK") === "EQUIPMENT_OK"; // true or false
this._startTimer();
}
}
//catch the player docking
this.shipWillDockWithStation = function(station)
{
this._stopTimer();
}
//and entering witchspace
this.shipWillEnterWitchspace = function(cause, destination) // 1.81 adds second parameter (destination), but we don't need it
{
this._stopTimer();
}
//and leaving witchspace
this.shipExitedWitchspace = function()
{
this._startTimer();
}
this._filterRocksAndCargo = function _filterRocksAndCargo(entity)
{
return (entity.scanClass === "CLASS_ROCK" || entity.scanClass ==="CLASS_CARGO");
}
//called by the timer to change colours on the scanner to white and grey ( asteroid ), white and orange ( boulder ), white and green (splinter or alloy), white and cyan (cargo), white and purple (escape pod)
this._identifyRocks = function()
{
//firstly check if the scanner is damaged or simply not there for some reason
if (this.$equip_scanner_ok === false) return;
var scanrange = player.ship.scannerRange; // get the current scanner range of the player's current ship - if we're zoomed in then this reduces the processing needed (I think)
// filter entities with either scanClass "CLASS_ROCK" or "CLASS_CARGO" - asteroids and boulders are rock but splinters are cargo as they can be picked up by the player ship
var rocks = system.filteredEntities(this, this._filterRocksAndCargo, player.ship, scanrange); //a variable to hold an array masquerading as a rock grader
var idx = rocks.length; //create an index variable for iterating
//and awaaaaaay we go! (in your mind that's in the best Rick Sanchez voice you can imagine )
while( idx-- ) // starting from the end and working backwards to simplify iteration
{
if ( (rocks[idx].scannerDisplayColor2 !== "whiteColor" && rocks[idx].scannerDisplayColor2 !== null) || (rocks[idx].scannerDisplayColor1 !== "whiteColor" && rocks[idx].scannerDisplayColor1 !== null) )
{
// the color was changed already (either by this timer on a previous check, or by another OXP) ... either way, don't override non-default colours, skip this "rock" (or alloy/cargo canister/escape pod)
continue; // e.g., Asteroid Storm uses a cyan-like color, Rescue Stations has a scenario that colors certain rocks white/red, Curse of the Black Sunspot colors certain rocks red/yellow, etc.
}
else if ( rocks[idx].shipClassName === "Asteroid" )
{
//Asteroids will be White and Grey alternating
rocks[idx].scannerDisplayColor1 = "whiteColor";
rocks[idx].scannerDisplayColor2 = "grayColor";
}
else if ( rocks[idx].shipClassName === "Boulder" )
{
//Boulders will be White and Orange alternating
rocks[idx].scannerDisplayColor1 = "whiteColor";
rocks[idx].scannerDisplayColor2 = "orangeColor";
}
else if ( rocks[idx].shipClassName === "Splinter" || rocks[idx].shipClassName === "Metal fragment" ) // Staer9's Icesteroids OXP spawns alloys (metal fragments) instead of splinters
{
//Splinters or alloys - which can be collected - will be white and green alternating
rocks[idx].scannerDisplayColor1 = "whiteColor";
rocks[idx].scannerDisplayColor2 = "greenColor";
}
else if ( this.$scavenger_upgrade === false ) // skip next two cases if no scavenger upgrade
{
continue;
}
else if ( rocks[idx].shipClassName === "Cargo container" )
{
rocks[idx].scannerDisplayColor1 = "whiteColor";
rocks[idx].scannerDisplayColor2 = "cyanColor";
}
else if ( rocks[idx].shipClassName === "Escape capsule" )
{
rocks[idx].scannerDisplayColor1 = "whiteColor";
rocks[idx].scannerDisplayColor2 = "purpleColor";
}
else if ( rocks[idx].hasRole("cargopod") ) // catch some OXP cargo pods that change the name from Cargo container to something else
{
rocks[idx].scannerDisplayColor1 = "whiteColor";
rocks[idx].scannerDisplayColor2 = "cyanColor";
}
}
}
//catch the equipment damaged event
this.equipmentDamaged = function (equipment)
{
switch (equipment)
{
case "EQ_NS_MINING_SCANNER_UPGRADE":
//send a message to the console
player.consoleMessage ("Mining IFF Scanner Upgrade Damaged");
this.$equip_scanner_ok = false;
this._stopTimer();
// below code disabled by Milo to avoid overwriting changes by other OXPs: IFF colours already set remain, damaged equipment prevents colouring of newly detected entities
//now remove the custom colours
// var scanrange = player.ship.scannerRange;
// I can't be bothered writing the same comments again, this is basically the same loop used to colour them in the first place.. read above. If you don't get this you need more practice :P
// var rocks = system.filteredEntities(this, this._filterRocksAndCargo, player.ship, scanrange);
// var idx = rocks.length;
// while ( idx-- )
//{
// if (rocks[idx].shipClassName === "Asteroid" || rocks[idx].shipClassName === "Boulder" || rocks[idx].shipClassName === "Splinter" || rocks[idx].shipClassName === "Metal fragment" || rocks[idx].shipClassName==="Escape capsule" || rocks[idx].shipClassName === "Cargo container")
//{
// rocks[idx].scannerDisplayColor1 = null; // restore default scanner colour
// rocks[idx].scannerDisplayColor2 = null; // restore default scanner colour
// }
// }
break;
//case "EQ_NS_SCANNER_SCAVENGER_HACK": // not possible because equipment.plist sets damage_probability = 0 for this equipment
//player.ship.setEquipmentStatus("EQ_NS_SCANNER_SCAVENGER_HACK", "EQUIPMENT_OK");
//break;
}
}
//catch the equipment removed event added in Oolite 1.82 (called by removeEquipment and also when core replaces equipment with _DAMAGED variant due to damage or setEquipmentStatus)
this.equipmentRemoved = function(equipment)
{
switch (equipment)
{
case "EQ_NS_MINING_SCANNER_UPGRADE":
this.$equip_scanner_ok = false;
this._stopTimer();
break;
case "EQ_NS_SCANNER_SCAVENGER_HACK": // although equipment.plist sets damage_probability = 0 for this equipment, it can be removed by scripts or when player sells the scanner
this.$scavenger_upgrade = false;
break;
}
}
//catch the equipment added event added in Oolite 1.82 (called by awardEquipment and also when core replaces _DAMAGED equipment with the original due to setEquipmentStatus)
this.equipmentAdded = function(equipment)
{
switch (equipment)
{
case "EQ_NS_MINING_SCANNER_UPGRADE":
this.$equip_scanner_ok = true;
this._startTimer();
break;
case "EQ_NS_SCANNER_SCAVENGER_HACK":
this.$scavenger_upgrade = true;
break;
}
}
//catch the equipment repaired event
this.equipmentRepaired = function (equipment)
{
switch (equipment)
{
case "EQ_NS_MINING_SCANNER_UPGRADE":
this.$equip_scanner_ok = true;
this._startTimer();
break;
case "EQ_NS_SCANNER_SCAVENGER_HACK": // equipment.plist sets damage_probability = 0 for this equipment, so it shouldn't need to be repaired, but just in case a script overrides that ...
this.$scavenger_upgrade = true;
break;
}
}
//player was killed
this.shipDied = function(whom, why)
{
this.$equip_scanner_ok = false;
this.$scavenger_upgrade = false;
//stop all the clocks they are not needed any more, W.H Auden would be turning in his grave for that.
this._stopTimer();
}
|
Scripts/eq.ns.scavenger.hack.js |
"use strict";
this.name ="NS_Scavenger_Scanner_Hack";
this.author ="NewtSoup, Milo";
this.copyright ="2017 NewtSoup";
this.licence ="CC BY-NC-SA 3.0"; // see http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info."
this.description="Rock Hermit condition for purchasing the Mining Scanner Upgrade";
this.version ="1.1.2";
//this works without parameters because rock hermits are tech level 1 and sell nothing very much so no need to specify the equipment
//as it relies on the Mining Scanner Upgrade being present anyway. So all we really need to do is when a player is browsing equipment just
//check that they're docked at a rock hermit.
//revised by Milo so that Ship Storage Helper, Ship Configuration and other OXPs can manage this OXP's equipment
this.allowAwardEquipment = function(eqKey, ship, context) {
if ( context === "purchase" && player.ship.dockedStation.primaryRole !== "rockhermit")
{
return false;
}
else // context === 'purchase' (and rockhermit), 'scripted' (Ship Storage Helper, etc.), 'newShips' (other OXPs could list the scanner as standard equipment) or 'npc' (if OXPs switch player ship temporarily, they may spawn a copy of the player ship under NPC/AI control, then switch back later -- allowing player equipment to be awarded to NPC ships in this case makes it easier for such OXPs to do the swap; we still have "available_to_npcs" = no; in equipment.plist to block random spawns)
{
return true;
}
}
|