All scripts now use underscore prefix for custom properties. Also general cleanup and linting.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3732 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-07-30 21:54:50 +00:00
parent 5abbe23f56
commit d16dc20f0b
12 changed files with 424 additions and 377 deletions

View File

@ -12,7 +12,7 @@
"TARGET_DESTROYED" = ("setStateTo: LURK");
"TARGET_LOST" = ("setStateTo: LURK");
"ENTER WORMHOLE" = ("setStateTo: ENTER_WORMHOLE");
UPDATE = ("sendScriptMessage: checkDistance", "pauseAI: 5.0");
UPDATE = ("sendScriptMessage: _checkDistance", "pauseAI: 5.0");
};
FLEE =
{
@ -23,7 +23,7 @@
"INCOMING_MISSILE" = (fightOrFleeMissile, "setStateTo: FLEE");
"REACHED_SAFETY" = ("setSpeedTo: 0.0", performIdle, "pauseAI: 10.0");
ATTACKED = (setTargetToPrimaryAggressor, "setStateTo: FLEE");
UPDATE = ("sendScriptMessage: checkDistance", "pauseAI: 5.0");
UPDATE = ("sendScriptMessage: _checkDistance", "pauseAI: 5.0");
};
"TRAVEL_TO_LURK_AREA" =
{
@ -33,7 +33,7 @@
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setStateTo: ATTACK_SHIP");
"INCOMING_MISSILE" = (fightOrFleeMissile, "setStateTo: FLEE");
"EXITED WITCHSPACE" = ("setStateTo: LURK");
UPDATE = ("sendScriptMessage: checkDistance", "pauseAI: 1.0");
UPDATE = ("sendScriptMessage: _checkDistance", "pauseAI: 1.0");
};
LURK =
{
@ -44,7 +44,7 @@
"ODDS_GOOD" = (groupAttackTarget);
"ODDS_LEVEL" = (groupAttackTarget);
"GROUP_ATTACK_TARGET" = (setTargetToFoundTarget, "setStateTo: ATTACK_SHIP");
UPDATE = ("sendScriptMessage: checkDistance", "scanForNearestShipWithPrimaryRole: player", "pauseAI: 5.0");
UPDATE = ("sendScriptMessage: _checkDistance", "scanForNearestShipWithPrimaryRole: player", "pauseAI: 5.0");
};
"ENTER_WORMHOLE" =
{

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global galaxyNumber, missionVariables, system*/

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global player*/

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global missionVariables*/

View File

@ -26,7 +26,8 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
// jslint bug: the "laxbreak" setting doesn't reliably work, which causes complaints about case indentation.
/*jslint white: true, laxbreak: true, undef: true, eqeqeq: true, bitwise: true, newcap: true, immed: true */
/*global galaxyNumber, guiScreen, mission, missionVariables, player, system*/
@ -36,9 +37,9 @@ this.copyright = "© 2008-2010 the Oolite team.";
this.version = "1.75";
this.cleanUp = function ()
this._cleanUp = function ()
{
// Remove event handlers.
// Remove event handlers.
delete this.guiScreenChanged;
delete this.missionScreenOpportunity;
delete this.shipExitedWitchspace;
@ -46,70 +47,91 @@ this.cleanUp = function ()
};
this.addToScreen = function ()
/**** Event handlers ****/
this.startUp = function ()
{
if (guiScreen === "GUI_SCREEN_SYSTEM_DATA")
// Remove event handlers once the mission is over.
if (missionVariables.conhunt === "MISSION_COMPLETE")
{
if (galaxyNumber === 0)
this._cleanUp();
}
delete this.startUp;
};
this.guiScreenChanged = function ()
{
if (galaxyNumber < 2 && missionVariables.conhunt === "STAGE_1")
{
if (guiScreen === "GUI_SCREEN_SYSTEM_DATA")
{
switch (system.ID)
if (galaxyNumber === 0)
{
case 28:
case 36:
case 150:
mission.addMessageTextKey("constrictor_hunt_0_" + system.ID);
break;
default:
break;
switch (system.ID)
{
case 28:
case 36:
case 150:
mission.addMessageTextKey("constrictor_hunt_0_" + system.ID);
break;
default:
break;
}
}
}
if (galaxyNumber === 1)
{
switch (system.ID)
if (galaxyNumber === 1)
{
case 3:
case 5:
case 16:
case 26:
case 32:
case 68:
case 106:
case 107:
case 162:
case 164:
case 184:
case 192:
case 220:
mission.addMessageTextKey("constrictor_hunt_1_A");
break;
case 253:
case 79:
case 53:
case 118:
case 193:
mission.addMessageTextKey("constrictor_hunt_1_" + system.ID);
break;
default:
break;
switch (system.ID)
{
case 3:
case 5:
case 16:
case 26:
case 32:
case 68:
case 106:
case 107:
case 162:
case 164:
case 184:
case 192:
case 220:
mission.addMessageTextKey("constrictor_hunt_1_A");
break;
case 253:
case 79:
case 53:
case 118:
case 193:
mission.addMessageTextKey("constrictor_hunt_1_" + system.ID);
break;
default:
break;
}
}
}
}
};
this.missionOffers = function ()
{
if (!player.ship.docked) { return; }
// this function is potentially called multiple times.
this.missionScreenOpportunity = function ()
{
if (player.ship.dockedStation.isMainStation)
{
if (galaxyNumber < 2 && !missionVariables.conhunt && player.score > 255)
{
// there are no options to deal with, we don't need a callback function.
mission.runScreen({titleKey:"constrictor_hunt_title", messageKey:"constrictor_hunt_brief1", model: "constrictor"});
mission.runScreen({
titleKey: "constrictor_hunt_title",
messageKey: "constrictor_hunt_brief1",
model: "constrictor"
});
if (galaxyNumber === 0)
{
mission.addMessageTextKey("constrictor_hunt_brief1a"); // galaxy = 0
@ -124,19 +146,23 @@ this.missionOffers = function ()
}
if (missionVariables.conhunt === "CONSTRICTOR_DESTROYED") // Variable is set by the ship script
{
mission.runScreen({titleKey:"constrictor_hunt_title", messageKey:"constrictor_hunt_debrief", model: "constrictor"});
mission.runScreen({
titleKey: "constrictor_hunt_title",
messageKey: "constrictor_hunt_debrief",
model: "constrictor"
});
player.credits += 5000;
player.bounty = 0; // legal status
player.score += 256; // ship kills
mission.setInstructions(null); // reset the mission briefing
missionVariables.conhunt = "MISSION_COMPLETE";
this.cleanUp();
this._cleanUp();
}
}
};
this.setUpShips = function ()
this.shipExitedWitchspace = this.shipLaunchedFromStation = function ()
{
if (galaxyNumber === 1 &&
system.ID === 193 &&
@ -147,35 +173,3 @@ this.setUpShips = function ()
constrictor[0].bounty = 250; // Ensure a bounty, in case it was missing in a custom shipdata.plist.
}
};
/**** Event handlers ****/
this.startUp = function ()
{
// Remove event handlers once the mission is over.
if (missionVariables.conhunt === "MISSION_COMPLETE") { this.cleanUp(); }
};
this.guiScreenChanged = function ()
{
if (galaxyNumber < 2 && missionVariables.conhunt === "STAGE_1")
{
this.addToScreen();
}
};
// this function is potentially called multiple times
this.missionScreenOpportunity = function ()
{
this.missionOffers();
};
this.shipExitedWitchspace = this.shipLaunchedFromStation = function ()
{
this.setUpShips();
};

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global missionVariables, player*/
@ -36,42 +36,54 @@ this.copyright = "© 2008-2010 the Oolite team.";
this.version = "1.75";
this.legalPoints = 0;
/*
To avoid being attacked by other ships, the Constrictor goes legal when
the player is well out of range. When this happens, the "real" bounty
is stored in _legalPoints.
*/
this._legalPoints = 0;
this.shipSpawned = function ()
{
this.legalPoints = this.ship.bounty;
this._legalPoints = this.ship.bounty;
this.ship.bounty = 0;
if (player.score > 512) this.ship.awardEquipment("EQ_SHIELD_BOOSTER"); // Player is Dangerous
if (player.score > 2560) this.ship.awardEquipment("EQ_SHIELD_ENHANCER"); // Player is Deadly
if (player.score > 512)
{
this.ship.awardEquipment("EQ_SHIELD_BOOSTER"); // Player is Dangerous
}
if (player.score > 2560)
{
this.ship.awardEquipment("EQ_SHIELD_ENHANCER"); // Player is Deadly
}
this.ship.energy = this.ship.maxEnergy; // start with all energy banks full.
};
this.shipDied = function (killer)
{
if(killer.isPlayer)
if (killer.isPlayer)
{
missionVariables.conhunt = "CONSTRICTOR_DESTROYED";
}
};
this.checkDistance = function ()
this._checkDistance = function ()
{
if (player.ship.position.distanceTo(this.ship) < 50000)
{
if(this.legalPoints > 0)
if (this._legalPoints > 0)
{
this.ship.bounty = this.legalPoints;
this.legalPoints = 0;
this.ship.bounty = this._legalPoints;
this._legalPoints = 0;
}
}
else
{
if(this.legalPoints === 0)
if (this._legalPoints === 0)
{
this.legalPoints = this.ship.bounty;
this._legalPoints = this.ship.bounty;
this.ship.bounty = 0;
}
}

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, undef: true, eqeqeq: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
this.name = "oolite-default-ship-script";

View File

@ -36,8 +36,9 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, undef: true, eqeqeq: true, newcap: true*/
/*global Entity, global, mission, player, Quaternion, Ship, special, system, Vector3D, SystemInfo*/
// NOTE: for jslint to work, you must comment out the use of __proto__.
/*jslint white: true, undef: true, eqeqeq: true, bitwise: false, regexp: true, newcap: true, immed: true */
/*global Entity, global, mission, player, Quaternion, Ship, special, system, Vector3D, SystemInfo, expandMissionText*/
this.name = "oolite-global-prefix";
@ -48,16 +49,13 @@ this.version = "1.75";
/**** Utilities, not intended to be retired ****/
/* Object.getPrototypeOf(): ECMAScript 5th Edition eqivalent to __proto__
extension.
*/
// Object.getPrototypeOf(): ECMAScript 5th Edition eqivalent to __proto__ extension.
if (typeof Object.getPrototypeOf !== "function")
{
Object.getPrototypeOf = function (object)
{
return object.__proto__;
}
};
}
@ -73,7 +71,7 @@ Object.getPrototypeOf(Ship).spawnOne = function Ship_spawnOne(role)
mission.addMessageTextKey = function mission_addMessageTextKey(textKey)
{
mission.addMessageText((textKey ? expandMissionText(textKey) : null));
}
};
/* string.trim(): remove leading and trailing whitespace.
@ -88,7 +86,7 @@ if (typeof String.prototype.trim !== "function")
var str = this.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i))){}
while (ws.test(str.charAt(--i))) {}
return str.slice(0, i + 1);
};
}
@ -121,11 +119,11 @@ SystemInfo.systemsInRange = function SystemInfo_systemsInRange(range)
}
}
return SystemInfo.filteredSystems(this, function(other)
return SystemInfo.filteredSystems(this, function (other)
{
return (other.systemID !== thisSystem.systemID) && (thisSystem.distanceToSystem(other) <= range);
});
}
};
/* system.scrambledPseudoRandom(salt : Number (integer)) : Number
@ -157,13 +155,13 @@ system.scrambledPseudoRandomNumber = function system_scrambledPseudoRandomNumber
// Convert from (effectively) 32-bit signed integer to float in [0..1).
return n / 4294967296.0 + 0.5;
}
};
/**** Backwards-compatibility functions. These will be removed before next stable. ****/
// Define a function that is an alias for another function.
this.defineCompatibilityAlias = function (oldName, newName)
this._defineCompatibilityAlias = function (oldName, newName)
{
global[oldName] = function ()
{
@ -173,7 +171,7 @@ this.defineCompatibilityAlias = function (oldName, newName)
};
// Define a read-only property that is an alias for another property.
this.defineCompatibilityGetter = function (constructorName, oldName, newName)
this._defineCompatibilityGetter = function (constructorName, oldName, newName)
{
var getter = function ()
{
@ -184,7 +182,7 @@ this.defineCompatibilityGetter = function (constructorName, oldName, newName)
};
// Define a write-only property that is an alias for another property.
this.defineCompatibilitySetter = function (constructorName, oldName, newName)
this._defineCompatibilitySetter = function (constructorName, oldName, newName)
{
var setter = function (value)
{
@ -195,14 +193,14 @@ this.defineCompatibilitySetter = function (constructorName, oldName, newName)
};
// Define a read/write property that is an alias for another property.
this.defineCompatibilityGetterAndSetter = function (constructorName, oldName, newName)
this._defineCompatibilityGetterAndSetter = function (constructorName, oldName, newName)
{
this.defineCompatibilityGetter(constructorName, oldName, newName);
this.defineCompatibilitySetter(constructorName, oldName, newName);
this._defineCompatibilityGetter(constructorName, oldName, newName);
this._defineCompatibilitySetter(constructorName, oldName, newName);
};
// Define a write-only property that is an alias for a function.
this.defineCompatibilityWriteOnly = function (constructorName, oldName, funcName)
this._defineCompatibilityWriteOnly = function (constructorName, oldName, funcName)
{
var getter = function ()
{
@ -219,8 +217,8 @@ this.defineCompatibilityWriteOnly = function (constructorName, oldName, funcName
};
// Define a compatibility getter for a property that's moved to another property.
// Example: to map player.docked to player.ship.docked, this.defineCompatibilitySubGetter("player", "ship", "docked")
this.defineCompatibilitySubGetter = function (singletonName, subName, propName)
// Example: to map player.docked to player.ship.docked, this._defineCompatibilitySubGetter("player", "ship", "docked")
this._defineCompatibilitySubGetter = function (singletonName, subName, propName)
{
var getter = function ()
{
@ -231,7 +229,7 @@ this.defineCompatibilitySubGetter = function (singletonName, subName, propName)
};
// Define a compatibility setter for a property that's moved to another property.
this.defineCompatibilitySubSetter = function (singletonName, subName, propName)
this._defineCompatibilitySubSetter = function (singletonName, subName, propName)
{
var setter = function (value)
{
@ -242,14 +240,14 @@ this.defineCompatibilitySubSetter = function (singletonName, subName, propName)
};
// Define a compatibility getter and setter for a property that's moved to another property.
this.defineCompatibilitySubGetterAndSetter = function (singletonName, subName, propName)
this._defineCompatibilitySubGetterAndSetter = function (singletonName, subName, propName)
{
this.defineCompatibilitySubGetter(singletonName, subName, propName);
this.defineCompatibilitySubSetter(singletonName, subName, propName);
this._defineCompatibilitySubGetter(singletonName, subName, propName);
this._defineCompatibilitySubSetter(singletonName, subName, propName);
};
// Like defineCompatibilitySubGetter() et al, for methods.
this.defineCompatibilitySubMethod = function (singletonName, subName, methodName)
this._defineCompatibilitySubMethod = function (singletonName, subName, methodName)
{
global[singletonName][methodName] = function ()
{

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global Timer, expandDescription, galaxyNumber, guiScreen, mission, missionVariables, player, system*/
@ -36,104 +36,28 @@ this.copyright = "© 2008-2010 the Oolite team.";
this.version = "1.75";
this.missionScreenOpportunity = function ()
{
if (!player.ship.docked) { return; }
// Choices are handled inside this.choiceEvaluation.
if (player.ship.dockedStation.isMainStation)
{
if (galaxyNumber === 3)
{
if (!missionVariables.nova && !missionVariables.novacount) { missionVariables.novacount = 0; }
if (missionVariables.nova === "TWO_HRS_TO_ZERO")
{
mission.runScreen({titleKey:"oolite_nova_title", messageKey:"oolite_nova_brief", background:"solar.png", choicesKey:"oolite_nova_yesno"}, this.choiceEvaluation);
this.novaMissionTimer.stop();
}
}
if (galaxyNumber === 3 || galaxyNumber === 4)
{
if (missionVariables.nova === "NOVA_ESCAPED_SYSTEM")
{
player.ship.removeAllCargo();
mission.runScreen({titleKey:"oolite_nova_title", messageKey:"oolite_nova_hero", background:"solar.png"});
player.ship.manifest["gem-stones"] += 100;
this.endTheMission();
}
else if (missionVariables.nova === "NOVA_ESCAPE_POD")
{
player.ship.removeAllCargo(); // can only be done while docked.
mission.runScreen({titleKey:"oolite_nova_title", messageKey:"oolite_nova_disappointed", background:"solar.png"});
this.endTheMission();
}
else if (missionVariables.nova === "NOVA_ESCAPE_OTHER")
{
mission.runScreen({titleKey:"oolite_nova_title", messageKey:"oolite_nova_ignored", background:"solar.png"});
this.endTheMission();
}
else if (missionVariables.nova === "NOVA_ESCAPE_COWARD" && !system.sun.isGoingNova && !system.sun.hasGoneNova)
{
player.decreaseContractReputation();
player.decreasePassengerReputation();
mission.runScreen({titleKey:"oolite_nova_title", messageKey:"oolite_nova_disappointed", background:"solar.png"});
this.endTheMission();
}
}
}
else if (missionVariables.nova === "TWO_HRS_TO_ZERO")
{
// this is the the nova system, but not the main station.
player.ship.launch();
player.commsMessage(expandDescription("[oolite-nova-visit-main]"));
}
};
this.endTheMission = function()
this._endTheMission = function ()
{
missionVariables.nova = "NOVA_HERO"; // even if not a hero, other scripts expect this string at mission end.
mission.setInstructions(null);
this.cleanUp();
}
this._cleanUp();
};
this.cleanUp = function()
this._cleanUp = function ()
{
// mission is over, we don't need most of the event handlers
// mission is over, we don't need most of the event handlers.
// this.shipExitedWitchspace is still needed after the nova mission.
delete this.shipWillEnterWitchspace;
delete this.shipWillExitWitchspace;
delete this.missionScreenOpportunity;
delete this.shipLaunchedEscapePod;
delete this.shipLaunchedFromStation;
}
this.choiceEvaluation = function(choice)
{
if (choice === "YES")
{
player.ship.useSpecialCargo(expandDescription("[oolite-nova-refugees]"));
mission.setInstructionsKey("oolite_nova_info");
missionVariables.nova = "NOVA_ESCAPE_HERO";
player.ship.launch();
this.blowUpAllStations();
system.sun.goNova(30);
}
else
{
// mission.choice == "NO", or null when player launched without making a choice.
missionVariables.nova = "NOVA_ESCAPE_COWARD";
player.commsMessage(expandDescription("[oolite-nova-coward]"), 4.5);
system.sun.goNova(9); // barely enough time to jump out of the system.
}
missionVariables.novacount = null;
};
// used when player enters nova system during nova mission.
this.sendShipsAwayForMission = function()
this._sendShipsAwayForMission = function ()
{
if (missionVariables.nova !== "TWO_HRS_TO_ZERO")
{
@ -142,8 +66,12 @@ this.sendShipsAwayForMission = function()
else
{
system.sendAllShipsAway();
if(!this.buoyLoaded) {this.witchBuoy = system.shipsWithPrimaryRole("buoy-witchpoint")[0]; this.buoyLoaded = true;}
if(this.witchBuoy && this.witchBuoy.isValid)
if (!this.buoyLoaded)
{
this.witchBuoy = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
this.buoyLoaded = true;
}
if (this.witchBuoy && this.witchBuoy.isValid)
{
this.witchBuoy.commsMessage(expandDescription("[oolite-nova-distress-call]"));
}
@ -151,21 +79,8 @@ this.sendShipsAwayForMission = function()
};
// Destroy all stations (and carriers) in the system. If we just blow up the
// main one, the player can eject, be rescued and buy fuel without triggering
// the escape pod failure state.
this.blowUpAllStations = function ()
{
// Find all stations in the system.
var stations = system.filteredEntities(this, function (entity) { return entity.isStation; });
// Blow them all up.
stations.forEach(function (entity) { entity.explode(); });
};
// used when player enters nova system after nova mission.
this.sendShipsAway = function()
this._sendShipsAway = function ()
{
if (!system.sun.hasGoneNova)
{
@ -179,50 +94,174 @@ this.sendShipsAway = function()
};
this.flareUp = function()
// Destroy all stations (and carriers) in the system. If we just blow up the
// main one, the player can eject, be rescued and buy fuel without triggering
// the escape pod failure state.
this._blowUpAllStations = function ()
{
system.info.corona_hues=1;
// This flare up (.25 to .5 flare) will last between 10 and 30 seconds
this.flareChange(.25 + Math.random()*.25,this.flareDown,Math.random() * 20 + 10);
system.filteredEntities(this, function (entity)
{
if (entity.isStation)
{
entity.explode();
}
});
};
this.flareDown = function()
this._flareUp = function ()
{
system.info.corona_hues = .8;
// This quiet moment ( .1 to .2 flare ) will last between 30 seconds and 2 minutes
this.flareChange(.1 + Math.random() * .1,this.flareUp,Math.random() * 90 + 30);
system.info.corona_hues = 1;
// This flare up (0.25 to 0.5 flare) will last between 10 and 30 seconds
this._flareChange(0.25 + Math.random() * 0.25, this._flareDown, Math.random() * 20 + 10);
};
this.flareChange = function(toValue,callFunc,callDelay,pass)
this._flareDown = function ()
{
system.info.corona_hues = 0.8;
// This quiet moment (0.1 to 0.2 flare) will last between 30 seconds and 2 minutes
this._flareChange(0.1 + Math.random() * 0.1, this._flareUp, Math.random() * 90 + 30);
};
this._flareChange = function (toValue, callFunc, callDelay, pass)
{
this.flareTimer.stop();
delete this.flareTimer;
pass = pass || 0;
if (pass < 5 )
if (pass < 5)
{
var f = system.info.corona_flare;
system.info.corona_flare = (f < toValue ? toValue*1.5+f : toValue+f*1.5) / 2.5;
this.flareTimer = new Timer(this, function(){this.flareChange(toValue,callFunc,callDelay,++pass);}, .25);
system.info.corona_flare = ((f < toValue) ? (toValue * 1.5 + f) : (toValue + f * 1.5)) / 2.5;
this.flareTimer = new Timer(this, function ()
{
this._flareChange(toValue, callFunc, callDelay, ++pass);
}, 0.25);
}
else
{
system.info.corona_flare = toValue;
this.flareTimer = new Timer(this, callFunc, callDelay);
}
}
};
/**** Event handlers ****/
this.startUp = function ()
{
// Remove all event handlers once the mission is over.
if (missionVariables.nova === "NOVA_HERO") { this.cleanUp(); }
if (missionVariables.nova === "NOVA_HERO")
{
this._cleanUp();
}
delete this.startUp;
}
};
this.missionScreenOpportunity = function ()
{
if (!player.ship.docked)
{
return;
}
function choiceEvaluation(choice)
{
if (choice === "YES")
{
player.ship.useSpecialCargo(expandDescription("[oolite-nova-refugees]"));
mission.setInstructionsKey("oolite_nova_info");
missionVariables.nova = "NOVA_ESCAPE_HERO";
player.ship.launch();
this._blowUpAllStations();
system.sun.goNova(30);
}
else
{
// choice == "NO", or null when player launched without making a choice.
missionVariables.nova = "NOVA_ESCAPE_COWARD";
player.commsMessage(expandDescription("[oolite-nova-coward]"), 4.5);
system.sun.goNova(9); // barely enough time to jump out of the system.
}
missionVariables.novacount = null;
}
if (player.ship.dockedStation.isMainStation)
{
if (galaxyNumber === 3)
{
if (!missionVariables.nova && !missionVariables.novacount)
{
missionVariables.novacount = 0;
}
if (missionVariables.nova === "TWO_HRS_TO_ZERO")
{
mission.runScreen({
titleKey: "oolite_nova_title",
messageKey: "oolite_nova_brief",
background: "solar.png",
choicesKey: "oolite_nova_yesno"
},
choiceEvaluation);
this.novaMissionTimer.stop();
}
}
if (galaxyNumber === 3 || galaxyNumber === 4)
{
if (missionVariables.nova === "NOVA_ESCAPED_SYSTEM")
{
player.ship.removeAllCargo();
mission.runScreen({
titleKey: "oolite_nova_title",
messageKey: "oolite_nova_hero",
background: "solar.png"
});
player.ship.manifest["gem-stones"] += 100;
this._endTheMission();
}
else if (missionVariables.nova === "NOVA_ESCAPE_POD")
{
player.ship.removeAllCargo(); // can only be done while docked.
mission.runScreen(
{
titleKey: "oolite_nova_title",
messageKey: "oolite_nova_disappointed",
background: "solar.png"
});
this._endTheMission();
}
else if (missionVariables.nova === "NOVA_ESCAPE_OTHER")
{
mission.runScreen({
titleKey: "oolite_nova_title",
messageKey: "oolite_nova_ignored",
background: "solar.png"
});
this._endTheMission();
}
else if (missionVariables.nova === "NOVA_ESCAPE_COWARD" && !system.sun.isGoingNova && !system.sun.hasGoneNova)
{
player.decreaseContractReputation();
player.decreasePassengerReputation();
mission.runScreen({
titleKey: "oolite_nova_title",
messageKey: "oolite_nova_disappointed",
background: "solar.png"
});
this._endTheMission();
}
}
}
else if (missionVariables.nova === "TWO_HRS_TO_ZERO")
{
// this is the the nova system, but not the main station.
player.ship.launch();
player.commsMessage(expandDescription("[oolite-nova-visit-main]"));
}
};
this.shipLaunchedEscapePod = function ()
@ -241,16 +280,22 @@ this.shipWillEnterWitchspace = function ()
system.info.sun_gone_nova = true;
delete this.willGoNova;
// did the player leave the nova system without docking at the main station?
if (missionVariables.nova === "TWO_HRS_TO_ZERO") missionVariables.nova = "NOVA_ESCAPE_OTHER";
if (missionVariables.nova === "TWO_HRS_TO_ZERO")
{
missionVariables.nova = "NOVA_ESCAPE_OTHER";
}
}
}
};
this.shipWillExitWitchspace = function () // call this as soon as possible so other scripts can see it will go nova.
{
if (!missionVariables.nova && galaxyNumber === 3)
{
if (missionVariables.novacount !== undefined) { missionVariables.novacount++; }
if (missionVariables.novacount !== undefined)
{
missionVariables.novacount++;
}
if (player.ship.equipmentStatus("EQ_GAL_DRIVE") === "EQUIPMENT_OK" && missionVariables.novacount > 3 && !missionVariables.nova && !system.isInterstellarSpace)
{
missionVariables.nova = "TWO_HRS_TO_ZERO";
@ -267,7 +312,7 @@ this.shipWillExitWitchspace = function () // call this as soon as possible so o
}
else
{
this.novaMissionTimer = new Timer(this, this.sendShipsAwayForMission, 5, 30);
this.novaMissionTimer = new Timer(this, this._sendShipsAwayForMission, 5, 30);
}
}
}
@ -277,15 +322,17 @@ this.shipWillExitWitchspace = function () // call this as soon as possible so o
}
};
this.shipLaunchedFromStation = function()
this.shipLaunchedFromStation = function ()
{
if (system.sun && (system.sun.isGoingNova || system.sun.hasGoneNova) && missionVariables.nova === "NOVA_ESCAPE_COWARD")
{
this.blowUpAllStations();
this._blowUpAllStations();
}
}
};
this.shipExitedWitchspace = function()
this.shipExitedWitchspace = function ()
{
if (system.sun)
{
@ -295,7 +342,7 @@ this.shipExitedWitchspace = function()
delete this.flareTimer;
}
if(system.sun.isGoingNova || system.sun.hasGoneNova)
if (system.sun.isGoingNova || system.sun.hasGoneNova)
{
if (this.novaTimer)
{
@ -303,13 +350,13 @@ this.shipExitedWitchspace = function()
}
else
{
this.novaTimer = new Timer(this, this.sendShipsAway, 5, 60);
this.novaTimer = new Timer(this, this._sendShipsAway, 5, 60);
}
}
if(system.sun.isGoingNova)
if (system.sun.isGoingNova)
{
// The first flare up will begin in between 30 seconds and 1 minute
this.flareTimer = new Timer(this, this.flareUp, Math.random() * 30 + 30);
// The first flare up will begin in between 30 seconds and 1 minute.
this.flareTimer = new Timer(this, this._flareUp, Math.random() * 30 + 30);
}
}
};

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global EquipmentInfo, Timer, galaxyNumber, guiScreen, mission, missionVariables, player, system*/
@ -36,9 +36,77 @@ this.copyright = "© 2008-2010 the Oolite team.";
this.version = "1.75";
this.missionOffers = function ()
this._setUpShips = function ()
{
if (!player.ship.docked) { return; }
function addThargoids()
{
this._waveCount++; // 5 loops of adding in the legacy script with a script timer.
if (this._waveCount > 5)
{
this._thargoidTimer.stop();
return;
}
if (system.countShipsWithRole("thargoid") < 2)
{
system.legacy_addSystemShips("thargoid", 1, 0.33);
system.legacy_addSystemShips("thargoid", 1, 0.66);
}
if (system.countShipsWithRole("thargoid") < 5 && Math.random() < 0.5)
{
system.legacy_addShips("thargoid", 1);
}
}
if (missionVariables.thargplans === "RUNNING" && galaxyNumber === 2)
{
if (this._thargoidTimer)
{
this._thargoidTimer.start();
}
else
{
this._thargoidTimer = new Timer(this, addThargoids, 10, 10);
}
}
};
this._cleanUp = function ()
{
/* After the mission is complete, it's good
practice to remove the event handlers. The
less event handlers, the smoother the game
experience.
From 1.74, loading a saved game - or restarting
the game - reloads all world scripts,including
all handlers. Calling _cleanUp from startUp
after the mission is finished allows us to keep
the gaming experience as smooth as possible.
*/
delete this.missionScreenOpportunity;
delete this.shipLaunchedFromStation;
delete this.shipExitedWitchspace;
};
/**** Event handlers ****/
this.startUp = function ()
{
this._waveCount = 0; // should be zero on the first launch after a reset.
if (missionVariables.thargplans === "MISSION_COMPLETE")
{
this._cleanUp();
}
};
this.missionScreenOpportunity = function ()
{
if (!player.ship.docked)
{
return;
}
if (player.ship.dockedStation.isMainStation)
{
@ -49,7 +117,10 @@ this.missionOffers = function ()
player.score > 1280 &&
system.ID !== 83)
{
mission.runScreen({titleKey:"thargoid_plans_title", messageKey:"thargoid_plans_brief1"});
mission.runScreen({
titleKey: "thargoid_plans_title",
messageKey: "thargoid_plans_brief1"
});
missionVariables.thargplans = "PRELUDE";
mission.setInstructionsKey("thargoid_plans_info1");
mission.markSystem(83);
@ -58,7 +129,11 @@ this.missionOffers = function ()
system.ID === 83)
{
mission.unmarkSystem(83);
mission.runScreen({titleKey:"thargoid_plans_title", messageKey:"thargoid_plans_brief2", model: "thargoid"});
mission.runScreen({
titleKey: "thargoid_plans_title",
messageKey: "thargoid_plans_brief2",
model: "thargoid"
});
missionVariables.thargplans = "RUNNING";
mission.setInstructionsKey("thargoid_plans_info2");
mission.markSystem(36);
@ -66,7 +141,11 @@ this.missionOffers = function ()
else if (missionVariables.thargplans === "RUNNING" &&
system.ID === 36)
{
mission.runScreen({titleKey:"thargoid_plans_title", messageKey:"thargoid_plans_debrief", model: "thargoid"});
mission.runScreen({
titleKey: "thargoid_plans_title",
messageKey: "thargoid_plans_debrief",
model: "thargoid"
});
player.score += 256; // ship kills
mission.setInstructions(null); // reset the mission briefing
missionVariables.thargplans = "MISSION_COMPLETE";
@ -79,91 +158,21 @@ this.missionOffers = function ()
player.ship.awardEquipment("EQ_NAVAL_ENERGY_UNIT");
EquipmentInfo.infoForKey("EQ_NAVAL_ENERGY_UNIT").effectiveTechLevel = 13;
mission.unmarkSystem(36);
this.cleanUp();
this._cleanUp();
}
}
}
};
this.addTargoids = function ()
{
this.loopcount++; // 5 loops of adding in the legacy script with a script timer.
if (this.loopcount > 5)
{
this.targoidTimer.stop();
return;
}
if (system.countShipsWithRole("thargoid") < 2)
{
system.legacy_addSystemShips("thargoid", 1, 0.33);
system.legacy_addSystemShips("thargoid", 1, 0.66);
}
if (system.countShipsWithRole("thargoid") < 5 && Math.random() < 0.5)
{
system.legacy_addShips("thargoid", 1);
}
};
this.setUpShips = function ()
{
if (missionVariables.thargplans === "RUNNING" && galaxyNumber === 2)
{
if (this.targoidTimer)
{
this.targoidTimer.start();
}
else
{
this.targoidTimer = new Timer(this, this.addTargoids, 10, 10);
}
}
};
this.cleanUp = function()
{
/* After the mission is complete, it's good
practice to remove the event handlers. The
less event handlers, the smoother the game
experience.
From 1.74, loading a savegame - or restarting
the game - reloads all world scripts,including
all handlers. Calling cleanUp from startUp
after the mission is finished allows us to keep
the gaming experience as smooth as possible.
*/
delete this.missionScreenOpportunity;
delete this.shipLaunchedFromStation;
delete this.shipExitedWitchspace;
}
/**** Event handlers ****/
this.startUp = function ()
{
this.loopcount = 0; // should be zero on the first launch after a reset.
if (missionVariables.thargplans === "MISSION_COMPLETE") { this.cleanUp(); }
};
this.missionScreenOpportunity = function ()
{
this.missionOffers();
};
this.shipLaunchedFromStation = function ()
{
this.setUpShips();
this._setUpShips();
};
this.shipExitedWitchspace = function ()
{
this.loopcount = 0;
this.setUpShips();
this._waveCount = 0;
this._setUpShips();
};

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global expandDescription*/

View File

@ -26,7 +26,7 @@ MA 02110-1301, USA.
*/
/*jslint bitwise: true, undef: true, eqeqeq: true, immed: true, newcap: true*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global guiScreen, mission, missionVariables, player*/
@ -37,25 +37,8 @@ this.description = "Random offers of trumbles.";
this.version = "1.75";
this.startUp = function ()
{
/* For simplicity, ensure that missionVariables.trumbles is never
undefined when running the rest of the script. If it could be
undefined, it would be necessary to test for undefinedness before
doing any tests on the value, like so:
if (missionVariables.trumbles && missionVariables.trumbles == "FOO")
*/
if (!missionVariables.trumbles)
{
missionVariables.trumbles = "";
}
};
this.missionScreenOpportunity = function ()
{
if (!player.ship.docked) { return; } // Player might have been forcibly undocked by another script.
/* In the pre-JavaScript implementation, the mission variable was set to
OFFER_MADE while the mission screen was shown. If the player lanched
in that state, the offer would never be made again -- unless some
@ -69,37 +52,41 @@ this.missionScreenOpportunity = function ()
}
if (player.ship.dockedStation.isMainStation &&
missionVariables.trumbles === "" &&
!missionVariables.trumbles &&
!missionVariables.novacount && // So the offers eventually stop for long-time players who keep refusing.
player.credits > 6553.5)
{
missionVariables.trumbles = "BUY_ME";
}
if (missionVariables.trumbles === "BUY_ME" && player.trumbleCount === 0 &&
if (missionVariables.trumbles === "BUY_ME" &&
player.trumbleCount === 0 &&
Math.random() < 0.2) // 20% chance of trumble being offered.
{
// Show the mission screen
mission.runScreen({titleKey:"oolite_trumble_title", messageKey:"oolite_trumble_offer", background:"trumblebox.png", choicesKey:"oolite_trumble_offer_yesno"}, this.trumbleOffered);
// Show the mission screen.
mission.runScreen({
titleKey: "oolite_trumble_title",
messageKey: "oolite_trumble_offer",
background: "trumblebox.png",
choicesKey: "oolite_trumble_offer_yesno"
},
function (choice)
{
if (choice === "OOLITE_TRUMBLE_YES")
{
missionVariables.trumbles = "TRUMBLE_BOUGHT";
player.credits -= 30;
player.ship.awardEquipment("EQ_TRUMBLE");
}
else
{
missionVariables.trumbles = "NOT_NOW";
}
});
}
};
this.trumbleOffered = function(choice)
{
if (choice === "OOLITE_TRUMBLE_YES")
{
missionVariables.trumbles = "TRUMBLE_BOUGHT";
player.credits -= 30;
player.ship.awardEquipment("EQ_TRUMBLE");
}
else
{
missionVariables.trumbles = "NOT_NOW";
}
}
this.shipWillExitWitchspace = function ()
{
// If player has rejected a trumble offer, reset trumble mission with 2% probability per jump.