Scripts/cougar-ship-script.js |
/*
cougar-ship-script.js
Ship script for the Cougar Bounty Hunter.
Oolite
Copyright © 2004-2010 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
cbh.oxp
Copyright � 2010 "Smivs"
This work is licensed under the Creative Commons
Attribution-Noncommercial-Share Alike 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
to Creative Commons, 171 Second Street, Suite 300, San Francisco,
California, 94105, USA.
*/
"use strict";
this.name = "cougar-ship-script.js";
this.author = "Commander McLane";
this.copyright = "� 2009 Commander McLane";
this.license = "CC-by-nc-sa 3.0";
this.description = "Scan script for the Cougar Bounty Hunter";
this.version = "5.0";
this.shipDied = function(who, cause)
{
log("cougar-ship-script", "The Cougar ST was killed by "+who+" because of "+cause);
}
this.$scanForPrey = function()
{
// log("cougar-ship-script", "Cougar ST scanning for prey.");
// one scan for anything with a bounty should actually be enough, but just to be safe we also include the primary role of "pirate" as a criterion; note that ships like the renegade pirates (primary role "hardpirate") will not be found through their role
// we use the JS function "system.filteredEntities", because there is no direct function for finding ships by bounty, like "system.shipsWithPrimaryRole" for primary role
// "system.filteredEntities" calls a self-defined function, in this case "isOffender(entity)", which returns all entities that match the criteria specified behind the "return" command
// the filtered (= found) entities are returned in an array, sorted by proximity; the closest is the first in the array
function isOffender(entity)
{
// the entity must be a ship, have either a bounty or primary role "pirate", must not be cloaked, must not be a derelict and must not be an asteroid (because
// (normal AI scans don't asteroids have small bounties)
// find anything cloaked)
return entity.isShip && (entity.bounty > 0 || entity.primaryRole == "pirate") && !entity.isCloaked && entity.scanClass !== "CLASS_CARGO" && entity.scanClass !== "CLASS_ROCK"
}
// the self-defined function is called and the result put in the variable "nextTarget"
// the function has to filter and find all entities matching its criteria in a radius of 25600 meters around the calling ship, which equals the scanner range
var nextTarget = system.filteredEntities(this, isOffender, this.ship, 25600);
// if something was found, and the first element of the array is therefore not undefined..
if(nextTarget[0])
{
// the found entity is made the current target...
this.ship.target = nextTarget[0];
// again the logging can be activated by deleting the leading "//" in the next line
// log("cougar-ship-script", "Cougar found some scum. Attacking a " + this.ship.target.displayName + " with a bounty of " + this.ship.target.bounty + ".");
// and the message "TARGET_FOUND" is sent to the Cougar's AI, which causes the methods connected with that message in the current AI state to be executed
this.ship.reactToAIMessage("TARGET_FOUND");
}
// and this is the end of the scan
// note that, if there is more than one pirate in the vicinity, the Cougar will always go after the closest ship
// a more sophisticated algorithm for choosing among many targets could be devised, for instance attacking the one with the biggest bounty first
// if nothing is found, the next scan will be performed in the next "UPDATE" of the AI
}
|
Scripts/spawncougar-script.js |
// Standard attributes
this.name = "Spawn Cougar ST";
this.author = "another_commander";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.15";
this.description = "Script to occasionally add a Cougar ST.";
this.shipWillExitWitchspace = function()
{
if (system.government < 2 && Math.random() >= 0.80)
{
var hitship = system.addShipsToRoute("cougar_st", 1, 0.25, "wp");
}
};
|