When equipment gets damaged, what happens to it?

For test results, bug reports, announcements of new builds etc.

Moderators: another_commander, winston, Getafix

Post Reply
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

When equipment gets damaged, what happens to it?

Post by ocz »

I'm sorry if this question is already answered, but I can find anything on the wiki, the board and so far nothing in the few parts source code I looked into.

When equipment gets damaged, what happens to it?

I'm writing an OXP, that requires equipment to break. So far I have been very successful in breaking it, but I kinda expected, that a "repair it" option would pop up in the purchase list (F3), that offers a repair, very much like with every other standard equipment. (min. repair Techlevel = ( min. purchase Techlevel)-1, repair costs = (purchase costs)/2)

It didn't appear and now I'm sad. :(

Of course it's no problem for me to implement the repair entry for that new equipment, but I thought this was already hard coded and now I fear, it indeed is and it's gonna pop up in the next versions 1.84, 1.90 or whatever.

By looking into a savegame I saw, that, when equipment gets damaged, the identifier changes form "EQ_MEGAHYPERFUNITRON" to "EQ_MEGAHYPERFUNITRON_DAMAGED". I don't wanna tinker with that, so my approach to repair it would be, to throw the equipment out and put a new one inplace instead. Duhhh. I meant, I'm gonna use the setEquipmentStatus method, if I have to.

I'm also using condition scripts in my OXP. Could they have broken the hard coded repair option?

So:
When equipment gets damaged, what happens to it?

EDIT: My problem is fixed. In my case, the equipment in question took some cargo space. You need the same amount of free cargo space to repair it, but on the ship I used wasn't enough.
Last edited by ocz on Sat Nov 14, 2015 6:32 pm, edited 1 time in total.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: When equipment gets damaged, what happens to it?

Post by another_commander »

The core will recognize the equipment as damaged and present you with the option for its repair in the F3 screen (this is handled in PlayerEntity.m, method - (void) setGuiToEquipShipScreen:(int)skipParam selectingFacingFor:(NSString *)eqKeyForSelectFacing, lines 8792-8804 of present trunk). All equipment that is checked with this code comes from a list of allowed equipment and there are plenty of rules that determine what is available and what is not.

Can you post the equipment.plist entry of your equipment, so that we can check if there is a special condition that may interfere with the normal operation? System/station tech level maybe? I did a quick test. Loaded up a game on a TL14 system, damaged the Gal Drive, went to F3, option to repair was there. Then, switched TL of system to 1, went to F3, repair option was not there. Check if something like this is happening in your case.
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: When equipment gets damaged, what happens to it?

Post by ocz »

I'm in a TL 14 system. The thing is, I made a other stand-in equipment "EQ_NAMEBUY" with a higher TL requirement purchasable and on buying it, it switches with the real equipment "EQ_NAME" per script. "EQ_NAME" is forbidden by condition script, but allowed for "purchase"/repair, when it's damaged....oooohh, but it's name is now "EQ_NAME_DAMAGED". Maybe the bug lies here.

EDIT: I thought of something, but nope. I prepare the code for upload.
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: When equipment gets damaged, what happens to it?

Post by ocz »

equipment.plist:

Code: Select all

(
   (
      9,
      4000,
      "Generic new equipment (Stand-in)",
      "EQ_GENERICNAMEBUY",
      "Stuff about the Generic new equipment.",
       {
	   "available_to_all" = true;
	   "available_to_NPCs" = false;
	   "available_to_player" = true;
	   "condition_script" = "GenericOXPConditions.js";
	   "damage_probability" = 1.0;
	   "incompatible_with_equipment" = "EQ_GENERICNAME";
	   "requires_cargo_space" = 2;
	   "strict_mode_only" = false;
	   "strict_mode_compatible" = true;
       }
    ),
	
   (
      3,
      4000,
      "Generic new equipment (The real deal)",
      "EQ_GENERICNAME",
      "",
       {
	   "available_to_all" = true;
	   "available_to_NPCs" = true;
	   "available_to_player" = true;
	   "condition_script" = "GenericOXPConditions.js";
	   "damage_probability" = 1.0;
	   "requires_cargo_space" = 2;
	   "strict_mode_only" = false;
	   "strict_mode_compatible" = true;
       }
    ),
)
GenericOXPConditions.js:

Code: Select all

this.allowAwardEquipment = function(eqKey, ship, context) {
	if (context === "purchase" && eqKey === "EQ_GENERICNAME") {
		if (player.ship.equipmentStatus("EQ_GENERICNAME") === "EQUIPMENT_DAMAGED")
		 	{return true;} //True for repairs.
		return false; //False for purchase.
	}
//	if (context === "purchase" && eqKey === "EQ_GENERICNAME_DAMAGED") {
//		return true; //Tried that, but duuuhh, it didn't work
//	}
	if (context === "purchase" && eqKey === "EQ_GENERICNAMEBUY" && player.ship.hasHyperspaceMotor === true) {
		return false; //You can't buy it, if the ship has a witchdrive. It makes sense. Trust me on this
	}
	
	return true; // In any other case, it's fine. (All other stuff is available, too.)
}
GenericOXPScripts.js:

Code: Select all


this.playerBoughtEquipment = function(equipment) {
	if (equipment == "EQ_GENERICNAMEBUY") {
		player.ship.removeEquipment("EQ_GENERICNAMEBUY");
		player.ship.awardEquipment("EQ_GENERICNAME");
		player.ship.hyperspaceSpinTime = 15;		//This line gives both the ship the ability to make Witchjumps and sets the countdown length to 15s.
		return;
	}
}

this.shipWillEnterWitchspace = function(cause, destination) {
	if (player.ship.equipmentStatus("EQ_GENERICNAME") === "EQUIPMENT_OK" && cause === "standard jump") {
		player.ship.setEquipmentStatus("EQ_GENERICNAME", "EQUIPMENT_DAMAGED"); // Equipment breaks after witchjump;
	}
}

this.equipmentDamaged = function(equipment) {
    if (equipment === "EQ_GENERICNAME") {
		player.ship.hyperspaceSpinTime = -1;	//The ship loses its witchjump ability, when it breaks.
	}
}

this.equipmentRepaired = function(equipment) {
    if (equipment === "EQ_GENERICNAME") {
		player.ship.hyperspaceSpinTime = 15;	//If that equipment gets repaired, the ship regains its witchjump ability.
		//Untestet, because I can't repair it in-game right now.
	}
}

this.startUpComplete = function() {
	if (player.ship.equipmentStatus("EQ_GENERICNAME") === "EQUIPMENT_OK") {
		player.ship.hyperspaceSpinTime = 15;  //Necessary after loading a savegame. 
	}
}
And that's that. If someone sees it, post it.
Last edited by ocz on Sat Nov 14, 2015 5:29 pm, edited 1 time in total.
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: When equipment gets damaged, what happens to it?

Post by ocz »

I removed the following code from the conditions scripts:

Code: Select all

if (context === "purchase" && eqKey === "EQ_GENERICNAME") {
      if (player.ship.equipmentStatus("EQ_GENERICNAME") === "EQUIPMENT_DAMAGED")
          {return true;} //True for repairs.
      return false; //False for purchase.
   }
No difference, except "EQ_GENERICNAME" in now purchasable, but still not repairable. Did my stand-in purchase equipment break it somehow?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: When equipment gets damaged, what happens to it?

Post by another_commander »

Code: Select all

this.playerBoughtEquipment = function(equipment) {
   if (equipment == "EQ_GENERICNAMEBUY") {
      player.ship.removeEquipment("EQ_GENERICNAMEBUY");
      player.ship.awardEquipment("EQ_GENERICNAME");
      player.ship.hyperspaceSpinTime = 15;      //This line gives both the ship the ability to make Witchjumps and sets the countdown length to 15s.
      return;
   }
<----------- There should be a closing brace here...
With this fixed, the (real deal) equipment can be seen as requiring repair in the F3 screen.

Edit: Always look at the log when the game doesn't do what you expected it to. In this case, it had this to say when I tried buying the EQ_GENERICNAMEBUY:

Code: Select all

18:13:04.461 [script.javaScript.exception.curlyAfterBody]: ***** JavaScript exception (GenericOXPScripts.js.anon-script): SyntaxError: missing } after function body
18:13:04.461 [script.javaScript.exception.curlyAfterBody]:       ../AddOns/Test.oxp/Scripts/GenericOXPScripts.js, line 33.
18:13:04.463 [script.javaScript.load.failed]: ***** Error loading JavaScript script ../AddOns/Test.oxp/Scripts/GenericOXPScripts.js -- compilation failed
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: When equipment gets damaged, what happens to it?

Post by ocz »

I'm terrible sorry, but there is a closing bracket in my code. I didn't copied it by mistake. If it would be missing there, the whole "GenericOXPConditions.js" would be corrupted and ignored and the whole inner mechanics (witchdrive on/off) wouldn't work, but this part does.

I also broke other new equipment (I created) and the repair dialog doesn' show up either, though it's in the same OXP file, so it might doesn't mean much. I look into the sourcecode you provided.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: When equipment gets damaged, what happens to it?

Post by another_commander »

If the closing brace was there, then I am not sure what the problem is. The equipment breaks and the hyperspace capability is removed, then repaired and it is restored. It Works For Me (TM)
Image

I suggest you run a test without any other OXPs installed.

Also, are you trying this with the Sidewinder by any chance? It has no cargo capability, so the equipment cannot appear in the list of buyable equipment due to requiring 2t cargo space.
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: When equipment gets damaged, what happens to it?

Post by ocz »

I did try a nearly vanilla run (+IllicitUnlock OXP), as I wanted to try it on ships without a witchdrive...in my case a Gecko.

Than I read you posting.

It was the dam* cargo space. I would NEVER ever have guest it. I should have tried it on a Cobra MK.III.

But now really. This is illogical. To repair equipment that takes up cargo space you need the same amount of cargo space a second time?

It was like I have feared it. I would have implemented my own repair option, only to see (or not to see) that there would have been two repair options in some cases and the whole twice the cargo space shabang would have been fix in a future version anyway. :lol:
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: When equipment gets damaged, what happens to it?

Post by another_commander »

ocz wrote:
But now really. This is illogical. To repair equipment that takes up cargo space you need the same amount of cargo space a second time?
I have to admit this sounds a lot like a bug of some sort. I have a fix for your scenario, but I am kind of afraid of commiting it because the potential to mess up gameplay is huge. I'll have to test it for a while first.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4612
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: When equipment gets damaged, what happens to it?

Post by phkb »

I'd wondered about this before while working on the smuggling compartment in "Smugglers". In the end I just created my own "repair" equipment items because I thought that was the right way of doing it.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: When equipment gets damaged, what happens to it?

Post by another_commander »

A fix for repairs requiring cargo space has gone to github with commit 6fc0f1d. Please check and test. It seems to not cause side effects for me but we all know how these things go...
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16055
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: When equipment gets damaged, what happens to it?

Post by Cody »

another_commander wrote:
It seems to not cause side effects for me but we all know how these things go...
Ain't that the truth!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
Post Reply