Hi
As an exercise for me, i rewrote the /config/script.js ( without changing the original idea/structure ).
--- my first intention was to learn how that works
----- after a long time looking at this script -
i decided to try convert function by function ( because i loose the overview )
So i tried to use the script structure, which i have used with "bash" before.
( btw.: i hate "if-else-if-else-if-else-if-else-if-else-if-else" ).
after converting ( with more overview )
- i removed 2 not necessary lines (double definition,double "if")
- changed parameters
---- more fuel consumption for the heavy one / less for the light one
---- more heat for the heavy one
- added a lot of comments ( // ### ... )
so here the new one -- !!!! i have kept the header as it was !!!!
--- i was not able to remove "did not use strict" messsage in the log
Code: Select all
"use strict";
this.name = "QTHI Auxiliary Generators";
this.author = "QCS";
this.copyright = "(C) 2015 QCS.";
this.licence = "CC-NC-by-SA 4.0";
this.description = "Core script based on EnergyEquipment from Thargoid, content by QCS.";
this.version = "0.1.1";
// #### begin exit-wormhole function
this.shipExitedWormhole = function()
{
// ### check existing generator
this.auxGen_ar = ["EQ_QTHI_AuxEnergyGenerator", "EQ_QTHI_AuxEnergyGeneratorHT", "EQ_QTHI_AuxEnergyGeneratorHv", "EQ_QTHI_AuxEnergyGeneratorLt"];
this.auxGeneratorKey = null;
var i = this.auxGen_ar.length;
while (i--)
{
this.auxGen = this.auxGen_ar[i];
if(player.ship.equipmentStatus(this.auxGen) === "EQUIPMENT_OK")
{ this.auxGeneratorKey = this.auxGen; break }
}
// ### leave this function if no generator is installed
if(this.auxGeneratorKey == null)
{ return }
// ### check/restart existing EnergyCheckTimer or start new one
if(this.auxEnergyCheckTimer)
{ this.auxEnergyCheckTimer.start() }
else
{ this.auxEnergyCheckTimer = new Timer(this, this.auxEnergyCheck,0,1) }
// ### check/restart existing EnergyCostTimer or start new one (only for HT,Hv,Hl)
if (this.auxGeneratorKey !== "EQ_QTHI_AuxEnergyGenerator")
{ if(this.auxHtEnergyCostTimer)
{ this.auxHtEnergyCostTimer.start() }
else
{ this.auxHtEnergyCostTimer = new Timer(this, this.auxHtEnergyCost,0,1) }
}
}
// #### end exit-wormhole function ####
// #### begin exit-station function - does the same as exit-wormhole #####
this.shipLaunchedFromStation = function(station)
{ this.shipExitedWormhole() }
// ### end exit-station function
// ### this function reduces the ship-energie, because that is needed for generator-start (HT,Hv,Hl)
this.auxHtEnergyCost = function()
{ if (this.isGeneratorEnabled === true)
{ player.energy -= 2 }
}
// ### starts generator (if not running AND energy is below chosen ratio)
this.auxEnergyCheck = function()
{
if (this.auxEnergyGeneratorRunning === true)
{ return }
if (this.auxEnergyReloadTimer)
{ this.auxEnergyReloadTimer.stop()}
if(player.ship.docked || player.ship.equipmentStatus(this.auxGeneratorKey) != "EQUIPMENT_OK")
{this.auxEnergyCheckTimer.stop()}
else
{
// isGeneratorEnabled and kickinRatio comes from other script
if(this.isGeneratorEnabled === true && player.ship.energy < player.ship.maxEnergy * this.kickInRatio && player.ship.fuel > 0)
{
this.auxEnergyGeneratorRunning = true;
player.ship.fuel -= 0.1;
player.consoleMessage("Firing up Auxiliary Energy Generator!",6);
log(this.name, "Firing up Auxiliary Energy Generator!");
this.auxEnergyReloadCount = 0;
this.auxEnergyReloadTimer = new Timer(this, this.auxEnergyReload, 0, 0.25);
}
}
}
// ### reloads energy (every 0,25sec) and checks energy-status (every 50*0,25sec = 12,5sec)
this.auxEnergyReload = function()
{
if (this.auxEnergyReloadCount < 50)
{
switch (this.auxGeneratorKey)
{
case "EQ_QTHI_AuxEnergyGenerator": player.ship.energy += 2; player.ship.temperature *= 1.01; break;
case "EQ_QTHI_AuxEnergyGeneratorHT": player.ship.energy += 2; player.ship.temperature *= 1.01; break;
case "EQ_QTHI_AuxEnergyGeneratorHv": player.ship.energy += 4; player.ship.temperature *= 1.02; break;
case "EQ_QTHI_AuxEnergyGeneratorLt": player.ship.energy += 1; player.ship.temperature *= 1.00; break;
}
this.auxEnergyReloadCount++;
}
else
{
if (this.auxEnergyGeneratorRunning === true)
{
if (player.ship.energy < player.ship.maxEnergy * this.kickInRatio && player.ship.fuel > 0)
{
player.consoleMessage("Energy still critical: Keeping Auxiliary Energy Generator online");
// log(this.name, "Energy still critical: Keeping Auxiliary Energy Generator online");
this.auxEnergyReloadCount = 0;
switch (this.auxGeneratorKey)
{
case "EQ_QTHI_AuxEnergyGenerator": player.ship.fuel -= 0.1; break;
case "EQ_QTHI_AuxEnergyGeneratorHT": player.ship.fuel -= 0.1; break;
case "EQ_QTHI_AuxEnergyGeneratorHv": player.ship.fuel -= 0.2; break;
case "EQ_QTHI_AuxEnergyGeneratorLt": player.ship.fuel -= 0.05; break;
}
}
else
{
player.consoleMessage("Auxiliary Energy Generator offline.");
// log(this.name, "Auxiliary Energy Generator offline.");
this.auxEnergyGeneratorRunning = false;
}
}
}
}
this.shipDied = function()
{
if(this.auxEnergyCheckTimer)
{ this.auxEnergyCheckTimer.stop() }
}
// ### sell ###
this.playerBoughtEquipment = function(equipmentKey)
{
if(equipmentKey == ("EQ_QTHI_AuxEnergyGenerator_Sell"))
{
player.ship.removeEquipment("EQ_QTHI_AuxEnergyGenerator");
player.ship.removeEquipment("EQ_QTHI_AuxEnergyGenerator_Sell");
player.credits += 500;
}
if(equipmentKey == ("EQ_QTHI_AuxEnergyGeneratorHT_Sell"))
{
player.ship.removeEquipment("EQ_QTHI_AuxEnergyGeneratorHT");
player.ship.removeEquipment("EQ_QTHI_AuxEnergyGeneratorHT_Sell");
player.credits += 800;
}
if(equipmentKey == ("EQ_QTHI_AuxEnergyGeneratorHv_Sell"))
{
player.ship.removeEquipment("EQ_QTHI_AuxEnergyGeneratorHv");
player.ship.removeEquipment("EQ_QTHI_AuxEnergyGeneratorHv_Sell");
player.credits += 1950;
}
//nothing special for EQ_QTHI_AuxEnergyGeneratorLt_Sell
}
// ### no hyperspace with Lt
this.playerStartedJumpCountdown = function(type)
{
if (this.auxGeneratorKey === "EQ_QTHI_AuxEnergyGeneratorLt" && this.isGeneratorEnabled === true)
{
player.consoleMessage("Witchspace drive disabled");
player.ship.cancelHyperspaceCountdown();
}
}
Oolite 1.91 / Imp. Trader ( slighly modified
) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard