Question about an existing oxz (AuxEnergyGenerators)

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

Post Reply
User avatar
Slartibartfast
Deadly
Deadly
Posts: 148
Joined: Mon Jan 21, 2008 3:54 pm

Question about an existing oxz (AuxEnergyGenerators)

Post by Slartibartfast »

Hello

I`am trying to learn write scripts for oolite, therefore i looked to other oxp/z to see,
how its done there.

So i stumbled something, that ( after some hours searching wiki's and ... )
i was not able to understand.
==>> Oolite.oxp.QCS.QTHI_AuxEnergyGenerators_0.1.1
------
in "/config" there is a file "worldscripts.plist" with an entry:

Code: Select all

(
  "AuxEnergyGenerator.js"
)
.
But in the whole oxp there is no script with that name.
As i have read in "https://wiki.alioth.net/index.php/Misc_ ... ipts.plist" it should exist.
Structure

The file is organized as an array. Every entry consists of a string, with the name of a script. The name must correspond with a file inside the Scripts folder inside the OXP.
hmmmmm?

matthias
Oolite 1.91 / Imperial Trader ( slighly modified :wink: ) on Lubuntu 21.10 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
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1133
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Question about an existing oxz (AuxEnergyGenerators)

Post by montana05 »

Slartibartfast wrote: Thu Jun 02, 2022 1:55 pm hmmmmm?

matthias
Good evening Matthias,
my first guess, after a quick look, would be that AuxEnergyGenerator.js in the worldscripts should be EQ_QTHI_AuxEnergyGenerator.js in the scripts folder. Currently, it seems that this script is not executed at all.
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Slartibartfast
Deadly
Deadly
Posts: 148
Joined: Mon Jan 21, 2008 3:54 pm

Re: Question about an existing oxz (AuxEnergyGenerators)

Post by Slartibartfast »

Hi

==>> EQ_QTHI_AuxEnergyGenerator.js
...but that script is running ( this.description = "Equipment script for the Generator (Priming/Activation)."; )

i can't find these actions in the other script.
:?
Oolite 1.91 / Imperial Trader ( slighly modified :wink: ) on Lubuntu 21.10 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
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 1133
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Question about an existing oxz (AuxEnergyGenerators)

Post by montana05 »

Slartibartfast wrote: Thu Jun 02, 2022 2:34 pm Hi

==>> EQ_QTHI_AuxEnergyGenerator.js
...but that script is running ( this.description = "Equipment script for the Generator (Priming/Activation)."; )

i can't find these actions in the other script.
:?
My bad, it is triggered from the equipment.plist. :oops:
Scars remind us where we've been. They don't have to dictate where we're going.
User avatar
Slartibartfast
Deadly
Deadly
Posts: 148
Joined: Mon Jan 21, 2008 3:54 pm

Re: Question about an existing oxz (AuxEnergyGenerators)

Post by Slartibartfast »

ups.... i'm blind

thx montana

now i'll kill the worldscript.plist .. and see what happens
( why i have not done this before... :roll: )
Oolite 1.91 / Imperial Trader ( slighly modified :wink: ) on Lubuntu 21.10 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
User avatar
Slartibartfast
Deadly
Deadly
Posts: 148
Joined: Mon Jan 21, 2008 3:54 pm

Re: Question about an existing oxz (AuxEnergyGenerators)

Post by Slartibartfast »

Hello

after disabling the worldscript.plist (rename to *.dead )
- the .oxz seems to work without problems.

matthias
Oolite 1.91 / Imperial Trader ( slighly modified :wink: ) on Lubuntu 21.10 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
User avatar
Slartibartfast
Deadly
Deadly
Posts: 148
Joined: Mon Jan 21, 2008 3:54 pm

Re: Question about an existing oxz (AuxEnergyGenerators)

Post by Slartibartfast »

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 / Imperial Trader ( slighly modified :wink: ) on Lubuntu 21.10 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
Post Reply