Config/script.js |
/*
wormhole-restoration.js
Script for spawning Thargoid Witchspace Jammers in interstellar space.
Oolite
Copyright © 2003-2011 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.
wormhole_restoration.oxp
Copyright © 2011 "Commander McLane"
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 = "wormhole-restoration";
this.description = "Script for spawning Thargoid Witchspace Jammers";
this.author = "Commander McLane";
this.copyright = "© 2011 Commander McLane";
this.license = "CC-by-nc-sa 3.0";
this.version = "1.1";
/* event handlers */
this.shipWillEnterWitchspace = function(cause)
{
// the player's origin system is stored
if(!system.isInterstellarSpace)
{
this.originSystem = system.ID;
this.misjumpCounter = 0;
}
// consecutive misjumps are counted
this.misjumpCounter ++;
// if the player followed an NPC's wormhole, this fact is stored
if(cause === "wormhole") this.followedNPC = true;
}
this.shipWillExitWitchspace = function()
{
// only works in interstellar space and only for the first misjump
// (the Thargoids have their technology only installed in the middle between systems)
if(!system.isInterstellarSpace || this.misjumpCounter !== 1) return;
// the target system of the jump is established
this.originCoordinates = System.infoForSystem(galaxyNumber, this.originSystem).coordinates;
this.currentCoordinates = system.info.coordinates;
this.misjumpVector = this.currentCoordinates.subtract(this.originCoordinates);
this.jumpVector = this.misjumpVector.multiply(2);
this.targetCoordinates = this.originCoordinates.add(this.jumpVector);
this.targetSystem = SystemInfo.filteredSystems(this, function(other){return (other.coordinates.squaredDistanceTo(this.targetCoordinates) < 0.0000001)})[0].systemID;
// four Witchspace Jammers are spawned around the origin
system.addShips("wormhole_restoration_witchspace_jammer", 1, [14618.6, 8686.1, 10541.7], 0);
system.addShips("wormhole_restoration_witchspace_jammer", 1, [-7449.9, -15359.9, 10399.8], 0);
system.addShips("wormhole_restoration_witchspace_jammer", 1, [-14478.2, 13337.6, -3572.2], 0);
system.addShips("wormhole_restoration_witchspace_jammer", 1, [7359.4, -6668.0, -17369.2], 0);
}
|
Scripts/wormhole-restoration-witchspace-jammer.js |
/*
wormhole-restoration-witchspace-jammer.js
Script for the Thargoid Witchspace Jammer.
Oolite
Copyright © 2003-2011 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.
wormhole_restoration.oxp
Copyright © 2011 "Commander McLane"
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 = "wormhole-restoration-witchspace-jammer";
this.description = "Script for the Thargoid Witchspace Jammer";
this.author = "Commander McLane";
this.copyright = "© 2011 Commander McLane";
this.license = "CC-by-nc-sa 3.0";
this.version = "1.1";
/* functions */
function $isStrandedShip(entity)
{
return entity.scanClass === "CLASS_NEUTRAL" && !entity.owner && entity.primaryRole !== "generationship"
}
/* event handlers */
this.shipDied = function(whom, why)
{
if(system.countShipsWithRole("wormhole_restoration_witchspace_jammer") > 1)
{
player.commsMessage("1 Thargoid Witchspace Jammer destroyed. " + (system.countShipsWithRole("wormhole_restoration_witchspace_jammer") - 1) + " still active.");
}
else
{
// a wormhole-creating object is spawned around the origin
var wormholeCreator = system.addShips("wormhole_restoration_wormhole_creator", 1, [0, 0, 0], 5000)[0];
wormholeCreator.script.targetSystem = worldScripts["wormhole-restoration"].targetSystem;
// more wormhole-creating objects are spawned of there are more stranded ships
var strandedShips = system.filteredEntities(this, $isStrandedShip).length;
// if the player was using one of their wormholes in the first place, one wormhole less is created
if(worldScripts["wormhole-restoration"].followedNPC)
{
if(strandedShips !== 0)
{
strandedShips --;
}
delete worldScripts["wormhole-restoration"].followedNPC;
}
for(var i=0; i<strandedShips; i++)
{
wormholeCreator = system.addShips("wormhole_restoration_wormhole_creator", 1, [0, 0, 0], 5000)[0];
if(Math.random() < 0.5)
{
wormholeCreator.script.targetSystem = worldScripts["wormhole-restoration"].targetSystem;
}
else
{
wormholeCreator.script.targetSystem = worldScripts["wormhole-restoration"].originSystem;
}
}
// the player is notified
player.commsMessage("The last Thargoid Witchspace Jammer was destroyed. All wormholes are restored.");
}
}
this.shipTakingDamage = function(amount, whom, type)
{
if(type === "cascade weapon" || amount === 1000)
{
this.ship.energy += amount;
}
}
|
Scripts/wormhole-restoration-wormhole-creator.js |
/*
wormhole-restoration-wormhole-creator.js
Script for creating a wormhole and removing the wormhole creator object.
Oolite
Copyright © 2003-2011 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.
wormhole_restoration.oxp
Copyright © 2011 "Commander McLane"
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 = "wormhole-restoration-wormhole-creator";
this.description = "Script for creating a wormhole and removing the wormhole creator object";
this.author = "Commander McLane";
this.copyright = "© 2011 Commander McLane";
this.license = "CC-by-nc-sa 3.0";
this.version = "1.1";
/* functions */
this.$attemptJump = function()
{
// attempts to jump out to the player's original target system
if(this.ship.exitSystem(this.targetSystem) === true)
{
this.jumpAttemptTimer.stop();
delete this.jumpAttemptTimer;
}
}
/* event handlers */
this.shipSpawned = function()
{
this.jumpAttemptTimer = new Timer(this, this.$attemptJump, 0.1, 0.5)
}
this.shipExitedWormhole = function()
{
// the object is removed after the jump
this.ship.remove();
}
|