Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.name = "ZekeMiner Ship Script"
- this.author = "Micha"
- this.copyright = "(C) 2011 Micha." // With thanks to Wyvern_Mommy and Wildeblood
- this.licence = "CC-NC-by-SA 2.0"
- this.description = "Ensures at least 1 Rock Hermit is in a system if the player is flying the Zeke Transporter Miner.";
- this.version = "0.1"
- ///////////////////////////////////////////////////////////////////////////////
- // Ship logic functions
- ///////////////////////////////////////////////////////////////////////////////
- this.getSalt = function()
- {
- // We only generate the salt once per save-game and store it in a
- // mission variable. This ensures that pseudo-randomly generated
- // things (such as the location of the Rock Hermits) are always
- // the same for a given save-game, but differs for each new save-game
- // ensuring replay value.
- // Also, we use a script-global variable to cache the value to reduce
- // access to mission variables as that is expensive.
- if (typeof this.random_salt === 'undefined') {
- if (missionVariables.ZekeMiner_salt == null) {
- missionVariables.ZekeMiner_salt = Math.random() * 1000;
- }
- this.random_salt = missionVariables.ZekeMiner_salt;
- log("ZekeMiningTransporter", "New random salt: " + this.random_salt);
- }
- return this.random_salt;
- }
- this.checkSpawnHermit = function()
- {
- // This function ensures that a RockHermit exists in the system
- var rockHermits = system.shipsWithRole("rockhermit");
- if( rockHermits.length == 0 ) {
- log("ZekeMiningTransporter", "No Rock Hermits in system, adding one");
- // Randomly add to one of the routes
- // NB: Use system.scrambledPseudoRandomNumber() to ensure it is always
- // generated in the same position for a given save-game.
- var dice = system.scrambledPseudoRandomNumber(this.getSalt());
- var route = "wp";
- if( dice > 0.8 ) {
- route = "ws";
- } else if (dice > 0.5) {
- route = "ps";
- }
- do {
- dice = system.scrambledPseudoRandomNumber(dice*100);
- } while(dice < 0.1 || dice > 0.9);
- rockHermits = system.addShipsToRoute("rockhermit", 1, dice, route);
- var position = rockHermits[0].position;
- // Now add up to 5..20 asteroids near the hermitage.
- system.addShips("asteroid", (Math.random() * 15) + 5, position);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- // Ship event handlers
- ///////////////////////////////////////////////////////////////////////////////
- this.shipWillLaunchFromStation = function()
- {
- log("ZekeMiningTransporter", "Player launching");
- this.checkSpawnHermit();
- }
- this.shipWillExitWitchspace = function()
- {
- log("ZekeMiningTransporter", "Player exiting witchspace");
- this.checkSpawnHermit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement