Code: Select all
/* ahruman-test.js
JavaScript test.oxp
A script which responds to every event supported by Oolite 1.72 (except
tickle, which is commented out - see bottom of file).
This was originally written by dajt, but almost all the original script
has been replaced.
*/
this.name = "JavaScript-test";
this.author = "Jens Ayton";
this.copyright = "This work is hereby placed in the public domain.";
this.description = "A test OXP written using JavaScript. Based on a test script by dajt. Some further additions by another_commander";
this.version = "2.1";
this.hyperspaceCountdownTimer = null;
this.hyperspaceCountdownSecondsRemaining = 0;
// Called after all OXPs are launched, before the game has begun.
this.startUp = function()
{
log("jstest.startUp", "Script startUp called.");
log("jstest.oolite.versionString", "Oolite version: " + oolite.versionString);
}
// Called when saved game is loaded, or player respawns after dying.
this.reset = function()
{
log("jstest.reset", "Script reset called.");
}
function append(string, suffix)
{
log("Appending \"" + suffix + "\" to string \"" + string + "\".");
if (string != "") string += ", ";
string += suffix;
return string;
}
// Called when alert status changes.
this.alertConditionChanged = function()
{
var alertName;
switch (player.alertCondition)
{
case 0:
alertName = "docked";
break;
case 1:
alertName = "green";
break;
case 2:
alertName = "yellow";
break;
case 3:
alertName = "red";
break;
default:
alertName = "unknown value " + player.alertCondition;
};
var alertState = "";
if (player.alertTemperature) alertState = append(alertState, "cabin temperature high");
if (player.alertMassLocked) alertState = append(alertState, "mass locked");
if (player.alertAltitude) alertState = append(alertState, "altitude low");
if (player.alertHostiles) alertState = append(alertState, "hostiles present");
if (alertState == "") alertState = "clear";
log("jstest.alert", "Player alert condition changed to " + alertName + " (" + alertState + ")");
}
// Called before launch tunnel effect.
this.shipWillDockWithStation = function()
{
log("jstest.dock.begin", "Player is docking.");
}
// Called at end of docking tunnel effect.
this.shipDockedWithStation = function()
{
log("jstest.dock.complete", "Player docked at " + player.ship.dockedStation.name + ", which " + (player.ship.dockedStation.isMainStation ? "is" : "is not") + " the system's main station.");
}
// Called before launch tunnel effect.
this.shipWillLaunchFromStation = function()
{
log("jstest.launch.begin", "Player is launching.");
}
// Called after launch tunnel effect.
this.shipLaunchedFromStation = function()
{
log("jstest.launch.complete", "Player \"" + player.name + "\" has launched in a " + player.ship.name + " into galaxy " + galaxyNumber + ", planet " + system.ID + " (\"" + system.name + "\"), govt = " + system.government + " (" + system.governmentDescription + "), economy = " + system.economy + " (" + system.economyDescription + "), tech level = " + system.techLevel);
this.clockReport();
}
// Called when player initiates witchspace countdown.
this.didBeginJumpCountDown = function(type) // Type is one of: "standard", "galactic". Others may be added in future.
{
log("jstest.witchSpace.started", "Silly walk to " + type + " witchspace started.");
}
// Called if player cancels witchspace countdown.
this.didCancelJumpCountDown = function()
{
log("jstest.witchSpace.cancelled", "Rain dance cancelled on account of rain.");
}
// Called at end of witchspace countdown, if unsuccessful.
this.didFailToJump = function(reason) // Reason is one of: "blocked", "too far", "insufficient fuel". Others may be added in future.
{
switch (reason)
{
case "blocked":
reason = "A station ate the chicken."
break;
case "too far":
reason = "Our chicken isn't big enough."
break;
case "insufficient fuel":
reason = "Bad news ain't bad enough.";
}
log("jstest.witchSpace.failed", "Chicken-waving failed. Who ate the chicken? Reason: " + reason);
}
// Called at end of witchspace countdown, if successful, or on entring wormhole.
this.shipWillEnterWitchspace = function(cause) // cause is one of: "standard jump", "galactic jump", "wormhole". Others may be added in future.
{
this.scriptedMisjumpBeingExecuted = false;
log("jstest.witchSpace.begin", "Player is entering witchspace. Cause: " + cause);
if (player.ship.scriptedMisjump == true)
{
if (cause == "standard jump")
{
log("jstest.witchspace.begin", "Scripted misjump is active. Player will end up in witchspace.");
this.scriptedMisjumpBeingExecuted = true;
}
}
this.stopHyperspaceCountdownTimer();
if (system.name == "Rainza") // GH from Rainza will lead to Oresrati, as the legend dictates.
{
if (cause == "galactic jump")
{
log("jstest.witchSpace.begin", "Player is executing intergalactic jump from Rainza, G7. Setting jump destination to Oresrati, G8.");
player.ship.galacticHyperspaceBehaviour="BEHAVIOUR_FIXED_COORDINATES";
player.ship.galacticHyperspaceFixedCoords=[16, 255, 0]; // Oresrati, G8.
}
}
}
// Called at beginning of witchspace tunnel effect; the destination system is already set up at this time.
this.shipWillExitWitchspace = function()
{
log("jstest.witchSpace.arrive", "Player is exiting witchspace.");
}
this.playerEnteredNewGalaxy = function(galaxyNumber)
{
log("jstest.witchSpace.arriveToNewGalaxy", "Player has arrived on galaxy " + galaxyNumber + ".");
if (system.name == "Oresrati") // We are at Oresrati, reset GH properties.
{
Player.ship.setGalacticHyperspaceFixedCoords(96, 96);
Player.ship.galacticHyperspaceBehaviour("BEHAVIOUR_STANDARD");
}
}
// Called after witchspace tunnel effect.
this.shipExitedWitchspace = function()
{
log("jstest.witchSpace.complete", "Player exited witchspace into galaxy " + galaxyNumber + ", planet " + system.ID + " (\"" + system.name + "\"), govt = " + system.government + " (" + system.governmentDescription + "), economy = " + system.economy + " (" + system.economyDescription + "), tech level = " + system.techLevel);
}
// Called when auto-docking sequence begins (but not for insta-dock).
this.didStartAutoPilot = function()
{
log("jstest.autoPilot.on", "Player enabled autopilot.");
}
// Called when player cancels auto-docking sequence.
this.didAbortAutoPilot = function()
{
log("jstest.autoPilot.cancelled", "Player cancelled autopilot.");
}
// Station says player can't dock on account of being naughty.
this.didRecieveDockingRefusal = function()
{
log("jstest.autoPilot.refused", "Station refused autopilot docking.");
}
// Escape pod launched.
this.didLaunchEscapePod = function()
{
log("jstest.escapePod", "Player ejected... the sissy.");
}
// Player died.
this.shipDied = function(whom, why)
{
log("jstest.died", "Player has suffered an existence failure.");
log("jstest.died", "Killed by " + whom + " by means of " + why);
this.stopHyperspaceCountdownTimer();
}
// Clock report.
this.clockReport = function()
{
log("clockReport.clockString", clock.clockString);
}
this.playerBoughtEquipment = function(equipmentKey)
{
log("playerBoughtEquipment","Player has bought equipment: " + equipmentKey);
}
this.equipmentDamaged = function(equipmentKey)
{
log("equipmentDamaged", "Equipment " + equipmentKey + " damaged.");
}
this.playerRequestedDockingClearance = function(result)
{
if (result == "DOCKING_CLEARANCE_GRANTED")
log("playerRquestedDockingClearance", "Player has received docking clearance.");
else
log("playerRequestedDockingClearance", "Docking clearance result: " + result);
}
this.hyperspaceCountdownTimerFunc = function ()
{
//log("hyperspaceCountdownTimer", "Hyperspace in " + this.hyperspaceCountdownSecondsRemaining + " seconds.");
this.hyperspaceCountdownSecondsRemaining--;
}
this.stopHyperspaceCountdownTimer = function ()
{
if (this.hyperspaceCountdownTimer)
{
this.hyperspaceCountdownTimer.stop();
this.hyperspaceCountdownTimer = null;
}
}
// Called when player initiates witchspace countdown.
this.playerStartedJumpCountdown = function (type, delay)
{
// Get number of whole seconds until jump.
this.hyperspaceCountdownSecondsRemaining = Math.floor(delay);
// Get fractional part of delay, if any.
var initialDelay = delay - this.hyperspaceCountdownSecondsRemaining;
if (initialDelay == 0)
{
// If no fractional time, call countdown function immediately
// and use timer for subsequent seconds.
this.hyperspaceCountdownTimerFunc();
initialDelay = 1.0;
this.hyperspaceCountdownSecondsRemaining--;
}
// Call timer function every 1.0 seconds after initialDelay.
this.hyperspaceCountdownTimer =
new Timer(this, this.hyperspaceCountdownTimerFunc, initialDelay, 1.0);
}
this.playerCancelledJumpCountdown = function ()
{
this.stopHyperspaceCountdownTimer();
}
this.playerJumpFailed = function (reason)
{
this.stopHyperspaceCountdownTimer();
}
this.playerTargettedMissile = function (missile)
{
if (missile)
{
log("playerTargettedMissile", "Player has targetted incoming missile " + missile);
}
else
{
log("playerTargettedMissile", "Player attempted to target incoming missile, but area scan indicates no incoming.");
}
}
this.playerBoughtNewShip = function (newShip)
{
log("playerBoughtNewShip", "Player has bought a new " + newShip.displayName);
}
// Called periodically, more or less.
/*this.tickle = function(status)
{
log("jstest.idle", "Ping! Status is: " + status);
}*/
log("jstest.loaded", "Script loaded.");