Scripts/Q-Charger.js |
/*
Q-Charger.js
Script for a Q-Charger for your ship.
Oolite
Copyright � 2003-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.
Q-Chargerv1.24.oxp
Copyright � 2011 "CommonSenseOTB"
updated by Norby
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.
*/
this.name = "Q-Charger";
this.author = "CommonSenseOTB";
this.copyright = "Copyright 2011 by CommonSenseOTB CC-NC-by-SA 3.0";
this.description = "Provides a Q-Charger for your ship.";
this.version = "1.25";
this.startUp = function()
{
// You may toggle the sound here
// Developers may have their hud script toggle these remotely
//
//
//
// YOU MAY TOUCH THESE
//
this.togglesoundfx1 = "ON";// default "ON", change to "OFF" to turn off soundfx1(Q-Charger,power up and power down)(1,2,3,4,5)
//
//
//
// DO NOT TOUCH THESE PLEASE
//
this.qchargerenabled = true;// player can disable/enable by priming and activating Q-Charger
this.qchargercondition = "OFF";// player OFF and ON
this.qchargerfuelcounter = 0.0;// default for save anywhere do not prime Q-Charger with fuel first
this.qchargerfuelcounters = [];// array hold fuelcounters to all NPC ships equipped with Q-Charger
this.qchargerpercent = 0; //current speed bonus provided by q-charger to player, 1 mean +100%, read by NumericHUD
this.qchargerships = [];// array hold all NPC ships equipped with Q-Charger
this.qchargercounterpowerup = 0.0;// default is off
this.qchargercounterpowerdown = 0.0;// default is off
this.mySound1 = new SoundSource;
this.mySound1.sound = "Q-Charger.ogg";
this.mySound1.loop = true;
this.mySound2 = new SoundSource;
this.mySound2.sound = "Q-Charger Power Up.ogg";
this.mySound2.loop = false;
this.mySound3 = new SoundSource;
this.mySound3.sound = "Q-Charger Power Down.ogg";
this.mySound3.loop = false;
this.mySound4 = new SoundSource;
this.mySound4.sound = "Q-Charger Half Power Up.ogg";
this.mySound4.loop = false;
this.mySound5 = new SoundSource;
this.mySound5.sound = "Q-Charger Half Power Down.ogg";
this.mySound5.loop = false;
}
this.awardQCharger = function(ship) //call worldScripts["Q-Charger"].awardQCharger(ship); to give Q-Charger to an NPC ship
{
if(!ship || !ship.isValid || ship.isStation || ship === player.ship) return; //for sure
if(this.qchargerships.indexOf(ship) >= 0) {
//player.consoleMessage(ship.displayName+" Q-Charger already awarded");//debug
return;
}
if(ship.equipmentStatus("EQ_Q-CHARGER")!="EQUIPMENT_OK")
ship.awardEquipment("EQ_Q-CHARGER");//not enough, must be in the qchargerships array also
this.qchargerships[this.qchargerships.length] = ship;//store the ship, will not work without this
this.qchargerfuelcounters[this.qchargerfuelcounters.length] = 60.0;//and this
if(ship.equipmentStatus("EQ_ENERGY_UNIT")!="EQUIPMENT_OK")
ship.awardEquipment("EQ_ENERGY_UNIT");//some other awards to make usable the Q-Charger
if(ship.equipmentStatus("EQ_FUEL_INJECTION")!="EQUIPMENT_OK")
ship.awardEquipment("EQ_FUEL_INJECTION");
ship.fuel = 7.0;
}
this.shipSpawned = function(ship)
{
if(!ship || !ship.isValid || ship.isStation || ship === player.ship) return; //for sure
if(ship.equipmentStatus("EQ_Q-CHARGER")=="EQUIPMENT_OK")
{
//player.consoleMessage(ship.displayName+" spawned with Q-Charger");//debug
this.awardQCharger(ship);
} else { //Award Q-Charger to NPCs without ShipVersion OXP
if( ship.mass >= 30000 && Math.floor( ship.entityPersonality / 328 ) + 1 >= 60 ) ///exactly as in ShipVersion OXP
{
this.awardQCharger(ship);
}
}
}
this.playerBoughtEquipment = function(equipmentKey)
{
if(equipmentKey === ("EQ_Q-CHARGER_REMOVAL"))
{
player.ship.removeEquipment("EQ_Q-CHARGER");
player.ship.removeEquipment("EQ_Q-CHARGER_REMOVAL");
player.credits += 6500;
}
if(equipmentKey === ("EQ_Q-CHARGER_MESS_REMOVAL"))
{
player.ship.removeEquipment("EQ_Q-CHARGER_MESS");
player.ship.removeEquipment("EQ_Q-CHARGER_MESS_REMOVAL");
}
}
this.equipmentDamaged = this.equipmentDestroyed = function(equipment)
{ // if fuel injection or energy units damaged while in use, damage the Q-Charger
if((equipment === "EQ_FUEL_INJECTION") || (equipment === "EQ_ENERGY_UNIT") || (equipment === "EQ_NAVAL_ENERGY_UNIT"))
{
if((player.ship.equipmentStatus("EQ_Q-CHARGER") === "EQUIPMENT_OK") && (this.qchargercondition === "ON"))
{
player.ship.setEquipmentStatus("EQ_Q-CHARGER","EQUIPMENT_DAMAGED");
if(this.mySound1.isPlaying)//shutdown sequence
{
this.mySound1.stop();
}
if(this.mySound2.isPlaying)
{
this.mySound2.stop();
}
if(this.mySound3.isPlaying)
{
this.mySound3.stop();
}
if(this.mySound4.isPlaying)
{
this.mySound4.stop();
}
if(this.mySound5.isPlaying)
{
this.mySound5.stop();
}
this.qchargercondition = "OFF";
}
}
if(equipment === "EQ_Q-CHARGER")
{
if(this.qchargercondition === "ON")// direct hit while in use is disastrous
{
player.ship.removeEquipment("EQ_Q-CHARGER");
player.ship.awardEquipment("EQ_Q-CHARGER_MESS");
if(this.mySound1.isPlaying)//shutdown sequence
{
this.mySound1.stop();
}
if(this.mySound2.isPlaying)
{
this.mySound2.stop();
}
if(this.mySound3.isPlaying)
{
this.mySound3.stop();
}
if(this.mySound4.isPlaying)
{
this.mySound4.stop();
}
if(this.mySound5.isPlaying)
{
this.mySound5.stop();
}// play bad sounds here if required
this.qchargercondition = "OFF";
}
}
}
this.shipLaunchedFromStation = function()
{
if((missionVariables.framesave !== "MoveToOxpStation") && (missionVariables.framesave !== "MoveToMainStation"))//prevent priming Q-Charger when loading/saving Save Anywhere Savegame
{
this.qchargerfuelcounter = 120.0;// default at launch prime Q-Charger with fuel first
}
if(this.qchargerCheckTimer)
{
this.qchargerCheckTimer.start();
}
else
{
this.qchargerCheckTimer = new Timer(this, this.qchargerCheck,0,0.25);// check Q-Charger every 0.25 seconds
}
}
this.qchargerCheck = function()
{
var wdet = worldScripts["detectors"];
for(var i = 0; i < this.qchargerships.length; i++) //check all NPCs with Q-Charger
{
var ship = this.qchargerships[i];
if(ship.script) ship.script.$Detectors_QC = false;//this turn off the flag after use
if(ship.isValid && !ship.docked && ship.equipmentStatus("EQ_Q-CHARGER") === "EQUIPMENT_OK" && ship.equipmentStatus("EQ_FUEL_INJECTION") === "EQUIPMENT_OK" && (ship.equipmentStatus("EQ_ENERGY_UNIT") === "EQUIPMENT_OK" || ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") === "EQUIPMENT_OK") && ship.fuel >= 0.1 && ship.energy >= 32 && (!ship.script || ship.script.name !== "rocketships" || ship.script.$RocketShips_RDPause || ship.script.$RocketShips_RDPause <= 0) )
{
if(ship.speed > ship.maxSpeed * 0.95 && ship.speed <= ship.maxSpeed)
{
ship.velocity = ship.thrustVector;
this.qchargerfuelcounters[i] += 1.0;
if(this.qchargerfuelcounters[i] > 120.0)// use 0.1 ly of fuel every 30 seconds and at launch to prime the Q-Charger
{
//player.consoleMessage(ship.script.$Detectors_Origname+" Q-Charger ON");
this.qchargerfuelcounters[i] = 1.0;
ship.fuel -= 0.1;
}
ship.energy -= 1.0;// use 4 energy per second
ship.velocity = ship.velocity.add(ship.vectorForward.multiply(ship.maxSpeed));
if(ship.isVisible && wdet && player.ship && player.ship.isValid
&& player.ship.position.distanceTo(ship.position) < 25600)
ship.script.$Detectors_QC = true; //inform the player from the usage
// log("QC",ship.displayName+" "+ship.speed+" "+ship.maxSpeed);
}
}
}
if(player.ship.docked)
{
if(this.qchargerCheckTimer)
{
this.qchargerCheckTimer.stop()
}
if(this.qchargercondition === "ON")//shutdown sequence
{
if(this.mySound1.isPlaying)
{
this.mySound1.stop();
}
if(this.mySound2.isPlaying)
{
this.mySound2.stop();
}
if(this.mySound3.isPlaying)
{
this.mySound3.stop();
}
if(this.mySound4.isPlaying)
{
this.mySound4.stop();
}
if(this.mySound5.isPlaying)
{
this.mySound5.stop();
}
if(player.ship.equipmentStatus("EQ_Q-CHARGER") === "EQUIPMENT_OK")
{
if(this.togglesoundfx1 === "ON")
{
this.mySound3.play();//v1.2 added toggle check here
}
}
this.qchargercondition = "OFF";
}
}
else
{ // main script functions
if((player.ship.equipmentStatus("EQ_Q-CHARGER") === "EQUIPMENT_OK") && (player.ship.equipmentStatus("EQ_FUEL_INJECTION") === "EQUIPMENT_OK") && ((player.ship.equipmentStatus("EQ_ENERGY_UNIT") === "EQUIPMENT_OK") || (player.ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") === "EQUIPMENT_OK")) && (player.ship.fuel >= 0.1) && (player.ship.energy >= 32) && (!player.ship.script || player.ship.script.name !== "rocketships" || player.ship.script.$RocketShips_RDPause || player.ship.script.$RocketShips_RDPause <= 0))
{
this.qchargerdecision();
this.qchargeroperation();
return;
}
if(this.qchargercondition === "ON")// shutdown sequence
{
if(this.mySound1.isPlaying)
{
this.mySound1.stop();
}
if(this.mySound2.isPlaying)
{
this.mySound2.stop();
}
if(this.mySound3.isPlaying)
{
this.mySound3.stop();
}
if(this.mySound4.isPlaying)
{
this.mySound4.stop();
}
if(this.mySound5.isPlaying)
{
this.mySound5.stop();
}
if(player.ship.equipmentStatus("EQ_Q-CHARGER") === "EQUIPMENT_OK")
{
if(this.togglesoundfx1 === "ON")
{
this.mySound3.play();//v1.2 added toggle check here
}
}
this.qchargercondition = "OFF";
}
}
}
this.shipWillEnterWitchspace = function()
{
if(this.qchargerCheckTimer)
{
this.qchargerCheckTimer.stop()
}
if(this.qchargercondition === "ON")
{
if(this.mySound1.isPlaying)
{
this.mySound1.stop();
}
}
delete this.qchargerfuelcounters;// start new arrays in the new system
delete this.qchargerships;
this.qchargerfuelcounters = [];// array hold fuelcounters to all NPC ships equipped with Q-Charger
this.qchargerships = [];// array hold all NPC ships equipped with Q-Charger
}
this.shipExitedWitchspace = function()
{
if(this.qchargercondition === "ON")
{
if(this.togglesoundfx1 === "ON")
{
this.mySound1.play();//v1.2 added toggle check here
}
}
if(this.qchargerCheckTimer)
{
this.qchargerCheckTimer.start();
}
else
{
this.qchargerCheckTimer = new Timer(this, this.qchargerCheck,0,0.25);// check Q-Charger every 0.25 seconds
}
}
this.qchargerdecision = function()
{
if(this.qchargerenabled && (player.ship.speed > (player.ship.maxSpeed * 0.95)) && (player.ship.speed <= (player.ship.maxSpeed)))
{
if(this.qchargercondition === "OFF")
{
if(this.togglesoundfx1 === "ON")
{
if(!this.mySound1.isPlaying)
{
this.mySound2.play();
this.qchargercounterpowerup = 1.0;
}
if(this.mySound1.isPlaying)
{
this.mySound4.play();
this.qchargercounterpowerup = 0.0;
}
if(this.mySound3.isPlaying)
{
this.mySound3.stop();
this.qchargercounterpowerdown = 0.0;
}
if(this.mySound5.isPlaying)
{
this.mySound5.stop();
this.qchargercounterpowerdown = 0.0;
}
}
}
this.qchargercondition = "ON";
}
else
{
if(this.qchargercondition === "ON")
{
if(this.togglesoundfx1 === "ON")
{
if(this.mySound1.isPlaying)
{
this.mySound3.play();
this.qchargercounterpowerdown = 1.0;
}
if(!this.mySound1.isPlaying)
{
this.mySound5.play();
this.qchargercounterpowerdown = 0.0;
}
if(this.mySound2.isPlaying)
{
this.mySound2.stop();
this.qchargercounterpowerup = 0.0;
}
if(this.mySound4.isPlaying)
{
this.mySound4.stop();
this.qchargercounterpowerup = 0.0;
}
}
}
this.qchargercondition = "OFF";
}
}
this.qchargeroperation = function()
{
if(this.qchargercounterpowerup >= 1.0)
{
this.qchargercounterpowerup += 1.0;
}
if(this.qchargercounterpowerdown >= 1.0)
{
this.qchargercounterpowerdown += 1.0;
}
player.ship.velocity = player.ship.thrustVector;
if(this.qchargercondition === "OFF")
{
if(this.mySound1.isPlaying)
{
if(this.qchargercounterpowerdown >= 12.0)// timing of sound overlap
{
this.mySound1.stop();
this.qchargercounterpowerdown = 0.0;
}
}
return;
}
if(this.qchargercondition === "ON")
{
var p = 20 * ( player.ship.speed - 0.95 * player.ship.maxSpeed ) / player.ship.maxSpeed;
if( p > 0.9999 ) p = 1; //+100 percent speed at max. throttle
else if( p < 0 ) p = 0; //+0 percent speed below 95% throttle
this.qchargerpercent = p; //save to NumericHUD
this.qchargerfuelcounter += p;
if(this.qchargerfuelcounter > 120.0)// use 0.1 ly of fuel every 30 seconds and at launch to prime the Q-Charger
{
this.qchargerfuelcounter = 1.0;
player.ship.fuel -= 0.1;
}
player.ship.energy -= p;// use 4 energy per second at max. throttle
player.ship.velocity = player.ship.velocity.add(player.ship.vectorForward.multiply(player.ship.maxSpeed * p));
if(this.togglesoundfx1 === "ON")
{
if(!this.mySound1.isPlaying)
{
if(this.qchargercounterpowerup >= 24.0)// timing of sound overlap
{
this.mySound1.play();
this.qchargercounterpowerup = 0.0;
}
}
}
}
}
this.shipDied = function()
{
if(this.qchargerCheckTimer)
{
this.qchargerCheckTimer.stop()
}
if(this.mySound1.isPlaying)
{
this.mySound1.stop();
}
if(this.mySound2.isPlaying)
{
this.mySound2.stop();
}
if(this.mySound3.isPlaying)
{
this.mySound3.stop();
}
if(this.mySound4.isPlaying)
{
this.mySound4.stop();
}
if(this.mySound5.isPlaying)
{
this.mySound5.stop();
}
this.qchargercondition = "OFF";
delete this.qchargerfuelcounters;// start new arrays
delete this.qchargerships;
this.qchargerfuelcounters = [];// array hold fuelcounters to all NPC ships equipped with Q-Charger
this.qchargerships = [];// array hold all NPC ships equipped with Q-Charger
} |
Scripts/notforsmall.js |
"use strict";
this.name = "notforsmall";
this.author = "Norby";
this.copyright = "2013 Norbert Nagy";
this.licence = "CC BY-NC-SA 3.0";
this.description = "This equipment can not fit into small ships like the Rocket Fighter.";
this.version = "1.0";
this.allowAwardEquipment = function(eqKey, ship, context)
{
//bugfix for eqs with conditions scripts: need double replaceShip() to work!
//player.replaceShip(shipname, pers); player.replaceShip(shipname, pers);
//call twice! the first always got false for allow without run this script.
//Proof: if you uncomment the following line, only the 2nd call will write into the log.
//log("notforsmall", eqKey+" "+ship.name+" "+ship.mass+" "+context );
if( ship.mass >= 30000 ) return true;
else return false;
}
|