Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Split: Deployable subentities

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

Moderators: winston, another_commander

Post Reply
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Split: Deployable subentities

Post by dertien »

Hello,

I hope I am posting in the right forum;

I am trying to figure out how to remove a specific subentity from a ship, when another subentity is destroyed, since you cannot attach a subentity to another and both get destroyed in one go.

I have this code that I recycled mostly from Eric Walsh'es Griff Sidewinder with frangible subentities

Code: Select all

case "player_escapepoddeluxe": 
        {
            this.ship.owner.commsMessage("Sys. Destroyed - Escape Pod");
			this.ship.owner.removeEquipment("EQ_ESCAPE_POD");
            break;
			//also insert code here to remove the escape pod light subentity that uses another .png
        }
This code displays a console message and also removes the equipment from the ship, that seems to work; however

What I would like to do is that once the escape pod subentity is shot off (for example), the lights (which are a different subentity since they use another texture) are also removed from the (mother)ship. The same goes for the Large Cargo bay, which I would like to make destroyable, but then the lights and other subentities that appear attached to it also get destroyed.

I found these possibilities, and I know they should fit above the "break" code above, but don't really know how to define them so they apply to a specific subentity like "escapepodlights" for example :

Code: Select all

ship.subEntities[0].remove()
this.ship.subEntities[x].remove(true);
Can someone help or direct me to an example ?


Also, I have a port and starboard shieldbooster subentity. How would I go about removing the installed shieldbooster equipment only when both subentities have been destroyed ?

Something in the lines of if Case shieldbooster Port and starboard are true, then remove equipment ? or if that is a backbreaker, have a 50% chance of destroying the shieldbooster by shooting destroyeing either one?

I am lost beyond belief in syntax and semantics here.

Edited:

How can I be such an idiot: Another thing I found out through testing is that sometimes player purchased equipment gets destroyed BEFORE the subentity. This means that the code up there does not work for Player ships. The proper mechanic should be that the subentity should be destroyed and that should trigger the EQUIPMENT to be removed. Not the other way around... anyway. help, ideas and code snippets are greatly appreciated.

Thank you.
Alpha Backer of Elite Dangerous
With 250 GBP :D
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

dertien wrote:
I am trying to figure out how to remove a specific subentity from a ship, when another subentity is destroyed, since you cannot attach a subentity to another and both get destroyed in one go.
If it's one-directional - i.e. A gets destroyed and B goes too, but if B gets destroyed A is unaffected - you should be able to make B a subentity of A rather than a subentity of the ship.

If that's not going to work in this case or there are other bits of the OXP which mean you have to take a different approach, what I'd do is this, which will be useful for other bits :

When you create the ship, ship.subEntities[0] will be the first one defined in shipdata.plist, [1] will be the second, and so on. Once bits have been shot off it, or removed on creation because it doesn't carry that equipment in the first place, that's not going to apply - if [1] gets destroyed, then everything above it will move along a place, so [2] will be the new [1].

So, what you can do is search through the subentities list until you find the one you want.

Code: Select all

// define this in the ship script
this._findSubEntity = function(key) 
{
  for (var i = ship.subEntities.length - 1 ; i >=0 ; --i)
  {
    if (ship.subEntities[i].dataKey == key)
    {
      return ship.SubEntities[i];
    }
  }
  return null; // couldn't find it.
}
This will search through all the subentities until it finds one with the shipdata.plist key you passed the function. So then you could do

Code: Select all

var epl = this._findSubEntity("escapepodlights");
if (epl)
{
  epl.remove();
}
and it would remove that subentity from the ship, if it was still there.

This gives you a way to handle the shield booster question as well.

Code: Select all

// destruction of port shield booster has been destroyed
if (this._findSubEntity("starboardshieldbooster") == null)
{
  // and the starboard shield booster isn't fitted to the ship any more either
  this.ship.setEquipmentStatus("EQ_SHIELD_BOOSTER","EQUIPMENT_DAMAGED");
}
// other actions for destruction of port shield booster go here
...and similarly for the other booster.
dertien wrote:
sometimes player purchased equipment gets destroyed BEFORE the subentity
Yes - Oolite doesn't know the equipment is actually on the subentity, and there's no easy way to tell it. What you can do is put this in the ship script

Code: Select all

this.equipmentDamaged = function(eqKey)
{
  if (eqKey == "EQ_SHIELD_BOOSTER")
  {
     if (this._findSubEntity("starboardshieldbooster") != null 
      || this._findSubEntity("portshieldbooster") != null)
    {
       // then one of the shield booster subentities is still intact
       // and the equipment shouldn't have been destroyed. Repair it.
       this.ship.setEquipmentStatus("EQ_SHIELD_BOOSTER","EQUIPMENT_OK");
    }
  }
  else if (eqKey == "EQ_ECM") 
  {
     // and so on
  }
  // and so on
}
- if the equipment was destroyed before the subentity (or subentities) was lost, put it back.
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Thank you Cim,

Instead of being completely blind, at least now, I can see some light coming through those closed shutters. :)
If it's one-directional - i.e. A gets destroyed and B goes too, but if B gets destroyed A is unaffected - you should be able to make B a subentity of A rather than a subentity of the ship.
That is good news for the Large Cargo Bay; since I can attach a number of subentities on the LCB instead of on the ship. The LCB has lights, a gunhull, a nozzle (pulselaser), 4 latches and a box that holds the laser. They will all fit nicely on the right model.


As for the code you wrote a lot actually makes sense, and I feel confident enough to copy paste this in the right place and make the necessary changes, and test if it all works out. I might be back quick if the shit hits the proverbial fan though. There are also a number of other things I would like to add, gameplay wise, but will first sort out this lot.

Thanks and CU soon :wink:
Alpha Backer of Elite Dangerous
With 250 GBP :D
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Another little question,

is there a way to give a subent more "hitpoints" or make it tougher against laser fire (not missiles) ?
The large cargo bay should obviously be able to take more hits than a Toruspanel cover; also having your front laser destroyed (and effectively making you harmless) should not happen directly after your front shield is down and you are taking hits... or should it ? I don't want to create an übership but some subents would definitely feel more "real" if they were tougher.

Is this calculated by Oolite by mass or can somehow the density property in the shipdata.plist help here ? Is it possible at all ?
Alpha Backer of Elite Dangerous
With 250 GBP :D
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Set the subentity's max_energy property in shipdata.plist - the default value is 200, which is probably far tougher than it needs to be for most of them. (Missile damage always hits the main hull)
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Ah thanks,

I thought this value was solely related to shield energy and not toughness itself, giving more energy for the shield instead of hitpoints to every subentity by adding max_energy... That's good to know.

I guess giving a reasonable max_energy value to gameplay related subents is mandatory, and setting it to max_energy = 0 or some low value for the eyecandy ones that can be shot off almost with one shot once the shields are down.

A bit like this:

Gameplay and equipment related if destroyed: max_energy Between 5-30 from small to large.

-Torus panel (small) (exposes the torus after a few hits after that it's the Torus drive that takes the pounding and eventually gets destroyed making the trip to safety a lot longer and your wallet a lot thinner)
-Passenger cabin (medium) ( destroying the psngcabin transforms your passenger and reputation to fertilizer along with failing the mission)
-LCB (Large)(destroys the LCB and spawns cargo that can be scooped back up if a scoop and enough space is still available) The LCB will need to be bought again, if desired.

Eyecandy related: max_energy Between 2-8 from small to large

- Dorsal cover, docking hooks etc... repaired by maintenance overhaul.

- Engines, Engines' emissions (lights) etc... I believe repairing them with your script above should they be destroyed before the mothership is, should do the trick here to make them 'invincible' until the end right ?

Would distributing the sum of all installed subentities amounting towards 45% of the hull value (256 in total for a Cobra Mk 3) thus around 115 and adding 115 to the max_energy work ?
Alpha Backer of Elite Dangerous
With 250 GBP :D
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Something to note: a pulse laser does 15 points of damage per hit (there are weaker weapons, but the pulse laser is far more common), so the difference between something with 1 energy and something with 15 energy is almost non-existent. The default recharge rate for an undestroyed sub-entity is 1 point per second - set energy_recharge_rate to modify this: it is not inherited from the ship and nor does it drain the ship's energy banks to recharge it.

If you want even the small subentities able to take a hit or two, the subentity total energy will probably be 100 times bigger than the main hull.

To make a single subentity invincible on a ship with frangible subentities, put this in the subentity's ship script (not the main entity's ship script)

Code: Select all

this.shipTakingDamage = function(amount, whom, type)
{
  this.ship.energy += amount; // repair the damage taken to the subentity
  this.ship.owner.energy -= amount; // give the damage to the main ship instead
}
Heat damage, by the way, is applied to all entities and subentities simultaneously. If you overheat your ship so much that its shields start failing, you'll almost certainly lose all subentities at once. If you want to avoid that, you'll need those subentities to detect and at least partially cancel heat damage. Mostly in this case the ship is going to explode in seconds anyway, so maybe it should be a complete wreck if it somehow escapes...
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

interesting :wink:

Okay, I will work out what I have and then post a test version of my messy code here when done soon.

Thanks Cim. Enjoy ur Sunday
Alpha Backer of Elite Dangerous
With 250 GBP :D
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Where can I find the damage per second for a beam laser please ? Did see it in the Javascript reference yesterday, but cannot seem to find it again.
Alpha Backer of Elite Dangerous
With 250 GBP :D
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Pulse laser: 15 damage per shot; 2 shots per second (thermal cutout in ~25 seconds)
Beam laser: 15 damage per shot; 10 shots per second (thermal cutout in ~3 seconds)
Military laser: 23 damage per shot; 10 shots per second (thermal cutout in ~3 seconds)
Mining laser: 50 damage per shot; 0.4 shots per second (never overheats)
Thargoid laser: 12.5 damage per shot; ~1 shot per second depending on warship (never overheats)
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Much obliged :wink:
Alpha Backer of Elite Dangerous
With 250 GBP :D
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Ok Cim,

Following up on what you all said concerning hit points, would you mind taking a look at this spreadsheet file and tell me what you think about the values:

https://app.box.com/s/3skqwkjh9oea69p1rtwo

I honestly don't understand how the damage transfer calculation is done, so I left that open. I took a value of 2500 for the hull of the Cobra Mk 3 compared to 1000 for the LCB, and hopefully kinda used good judgement for the rest of the values.

This will mean that:

- You will need to use shields, and manage them well if you don't want spend a whole lot of money on maintenance, I also saw that ERS script that GGShinobi was working on and it might become a necessary oxp requirement for this cobra if you don't wish to cheat.
- Pulse lasers don't cut it for piracy as a player: 910 seconds (15 minutes) vs 3 and 2 minutes using beam and military lasers respectively; NPC' however if not alone should have no significant problems.
- You will need to do the proverbial run for the hills now if you want to keep your ship in pristine condition.

What do you think, good values or too much of it ?
Alpha Backer of Elite Dangerous
With 250 GBP :D
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

It depends how much energy_recharge_rate you give the subentities. The difference between a 30 point subentity with 0 recharge (hit twice, an hour apart, and it goes) and one with 0.1 recharge (always takes 3 hits and they definitely need to be in the same fight) is quite significant - especially since the NPCs don't know to concentrate fire on the subentities (and their aim isn't precise enough anyway)

The main hull will last a bit longer than that, as well: in 3 minutes it will have regenerated 720 damage assuming no other demands on the energy banks (a little unlikely) and no extra energy units.

The numbers seem reasonable for what you're going for, but how well it actually works you'll just have to test: it's so far from conventional Oolite numbers that I really don't know what will happen.
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Okay,

I'll have a go with some different values, thanks for the useful info.
Alpha Backer of Elite Dangerous
With 250 GBP :D
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

Re: Scripters cove

Post by dertien »

Dear Cim,

I have been trying out different methods for hours now of getting the code you suggested to do anything ingame and copying it everywhere and nowhere, trying out different combos, but I am really pulling my hairs out now... since nothing seems to be working. As far as it goes the code in the first case thingie of the shipdied function is working and indeed spawning cargo, while telling me the Cargo bay was destroyed (like showing me the finger :lol: ). But that's about it.

In short, sorry, but I am stuck.

Here's as far as I got: https://app.box.com/s/4ulqy1rgj6m2s5pja29c

A little info on the file:

I have inserted the values for the different subentites as far as max_energy and energy_recharge_rate values go. I have seperated the ship from its subents and have them in different oxp folders, because I want to reuse them for future ships and stations, without having to copy them x number of times for x number of ships. I don't know if that affects the scripting or not. The script file is in the script folder of the subents oxp.
When you open the shipdata.plist in the subents oxp you will see that it has a convenient index file, which should greatly help find some values like entry names and role names of subentities (should that be necessary), although they are also found in the script file.
The other shipdata.plist file doesn't have an index, but the ship entries are pretty straightforward and there aren't so many.

I put the max_energy value of the LCB on 10 for easy testing.

I am not asking for a complete solution, just a few blocks that will enable me to continue on my own, then I can copy paste the rest of the subentities in, since that is alas the only javascript coding I can produce...

Please help.
Alpha Backer of Elite Dangerous
With 250 GBP :D
Post Reply