Page 1 of 3
[WIP] NPC Equipment Damage
Posted: Tue May 10, 2016 11:13 am
by Ngalo
Allows NPC equipment to be damaged in combat.
Download from Elite Wiki. (version 0.2.1, with more bug fixes (see below))
Compatible with N-Shields and Ship Configuration. Probably won't work with CustomShields or NPC Shields. OXP equipment can add its own handlers to a list if it needs to de-activate scripts etc when damaged.
Re: [WIP] NPC Equipment Damage
Posted: Tue May 10, 2016 11:28 pm
by phkb
I like this very much!
After having a bit of a look at the code, I think for better compatibility in future releases I need to make the $awaitEquipmentDamaged routine in ShipConfig accept a ship as a parameter, and thereby making it available to be used for NPC's. That should streamline your job of applying equipment breakage for ShipConfig equipment items to NPC's. I think I'll be able to squeeze that into the next release.
Edit: Actually, I'm going to attach $awaitEquipmentDamaged to the "script" property of the player ship, meaning that all the ship references in the routine will become "this.ship" and it can therefore be applied to any other ship.
Re: [WIP] NPC Equipment Damage
Posted: Wed May 11, 2016 3:31 am
by phkb
A couple of bugs:
Code: Select all
12:41:10.286 [script.javaScript.exception.notDefined]: ***** JavaScript exception (upsScavenger 1.0): ReferenceError: quantity is not defined
12:41:10.286 [script.javaScript.exception.notDefined]: ../AddOns/Testing.oxp/NPC_Equipment_Damage.oxz/Scripts/NPC_Equipment_Damage.js, line 62.
The way you have "quantity" specified JS is turning it into a variable, rather than using it as a property. Just remove the "[" and "]" from around the name and it should be good to go. Same goes for "commodity" 2 lines later.
Next one:
Code: Select all
12:42:30.629 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (griff_spawn_wreckage 1.1): TypeError: handlers[h] is undefined
12:42:30.630 [script.javaScript.exception.unexpectedType]: ../AddOns/Testing.oxp/NPC_Equipment_Damage.oxz/Scripts/NPC_Equipment_Damage.js, line 108.
With this one, I think you need to change this:
Code: Select all
for (h in handlers)
{
handlers[h].apply(ship.script, [eq.equipmentKey]);
}
To this:
Code: Select all
for (h in handlers)
{
if (typeof h == "function") h.apply(ship.script, [eq.equipmentKey]);
}
Because "h" is already the item in the array.
One more:
Code: Select all
13:10:33.559 [script.javaScript.exception.notFunction]: ***** JavaScript exception (oolite-default-ship-script 1.82): TypeError: cargopods.append is not a function
13:10:33.559 [script.javaScript.exception.notFunction]: ../AddOns/Testing.oxp/NPC_Equipment_Damage.oxp/Scripts/NPC_Equipment_Damage.js, line 64.
In this case I think your should just change "append" for "push".
Re: [WIP] NPC Equipment Damage
Posted: Wed May 11, 2016 11:37 am
by Norby
Hi Ngalo!
First of all I like your new addons, the codes inside looks like skillfull works. I hope you will be persistent enough to make a few more versions to reach enough stable stages.
I got many lines into my log, too much to quote, please check it
here. Most of the 7000 lines in a 10 min session is "calling internal dmg", the game was frozen without any new frame displayed for more seconds while several hundreds of these are generated. I never seen similar long stops so far, so you produced something unique.
Ship script is terminated due to timeLimit during these times. Don't worry, I think you can solve it, or feel free to ask.
Re: [WIP] NPC Equipment Damage
Posted: Thu May 26, 2016 12:28 pm
by Ngalo
Thanks for all your bug-finding help with this and N-Shields. I think I have now (0.1.1) fixed everything except the 'handlers[h] undefined' bug. I've left that one because debug-console experimentation shows that, although what you suggested would be right in Python, it apparently isn't in JS:
Code: Select all
> for (i in ["spam", "eggs", "ni", "foo", "bar"]){log("item: ", i)}
0
1
2
3
4
Therefore I don't know what's actually wrong and am not going to break it further by attempting a fix while thus ignorant.
Re: [WIP] NPC Equipment Damage
Posted: Tue May 31, 2016 4:07 am
by phkb
I'm not sure if this is correct or not, but anyway...
I'm noticing that the script is damaging the same items over and over again on the same ship, as evidenced by this log extract:
13:43:03.684 [NPC_Equipment_Damage]: damaging EQ_HEAT_SINK on Gnat: Fletcher's Skull
13:43:03.789 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:03.953 [NPC_Equipment_Damage]: damaging EQ_FUEL_SCOOPS on Gnat: Fletcher's Skull
13:43:04.246 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:04.368 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:04.476 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:04.834 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:05.060 [NPC_Equipment_Damage]: damaging EQ_HEAT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:08.032 [NPC_Equipment_Damage]: damaging EQ_FORWARD_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:08.175 [NPC_Equipment_Damage]: damaging EQ_HYPERDRIVE_TYPE2 on Gnat: Fletcher's Skull
13:43:08.364 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:08.476 [NPC_Equipment_Damage]: damaging EQ_HEAT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:08.571 [NPC_Equipment_Damage]: damaging EQ_HEAT_SHIELD_TYPE2 on Fer-de-Lance: Rachael
13:43:08.699 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Fer-de-Lance: Rachael
13:43:08.743 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:08.799 [NPC_Equipment_Damage]: damaging EQ_FUEL_SCOOPS on Gnat: Fletcher's Skull
13:43:08.930 [NPC_Equipment_Damage]: damaging EQ_AFT_SHIELD_TYPE2 on Gnat: Fletcher's Skull
13:43:09.022 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:09.126 [NPC_Equipment_Damage]: damaging EQ_THRUSTERS_TYPE2A on Gnat: Fletcher's Skull
13:43:09.984 [NPC_Equipment_Damage]: damaging EQ_ENERGYBANK_TYPE5 on Gnat: Fletcher's Skull
13:43:10.103 [NPC_Equipment_Damage]: damaging EQ_HYPERDRIVE_TYPE2 on Gnat: Fletcher's Skull
13:43:10.230 [NPC_Equipment_Damage]: damaging EQ_FORWARD_SHIELD_TYPE2 on Gnat: Fletcher's Skull
The poor energy bank got damaged 4 times within the space of a second! Is the damaging routine checking if the equipment is already damaged, or is it competing with ShipConfig's process of restoring equipment if the ship has armour?
Re: [WIP] NPC Equipment Damage
Posted: Tue May 31, 2016 4:38 am
by phkb
I'm also seeing this in my log file:
Code: Select all
<<snip 30 other lines of "damaging [equipment_item] on GalCop Viper Interceptor >>
14:21:36.146 [NPC_Equipment_Damage]: damaging EQ_FUEL_INJECTION_TYPE2 on GalCop Viper Interceptor: KPL581-DI6
14:21:36.169 [script.javaScript.timeLimit]: ***** ERROR: Script "griff_spawn_wreckage" ran for 1.12141 seconds and has been terminated.
14:21:36.169 [script.javaScript.stackTrace]: 0 (NPC_Equipment_Damage.js:77) <anonymous function>
14:21:36.169 [script.javaScript.stackTrace]: this: [Script "NPC_Equipment_Damage" version 0.1.1]
14:21:36.169 [script.javaScript.stackTrace]: ship: [Ship "GalCop Viper Interceptor" position: (56387.9, 60499.5, 744699) scanClass: CLASS_POLICE status: STATUS_IN_FLIGHT]
14:21:36.169 [script.javaScript.stackTrace]: handlers: undefined
14:21:36.169 [script.javaScript.stackTrace]: accumulator: undefined
14:21:36.169 [script.javaScript.stackTrace]: target: undefined
14:21:36.169 [script.javaScript.stackTrace]: eq: [EquipmentInfo EQ_THRUSTERS_TYPE2C "Manoeuvring Thrusters Class 2C"]
14:21:36.169 [script.javaScript.stackTrace]: damageableOdds: 1
14:21:36.169 [script.javaScript.stackTrace]: damageableCounter: 1
14:21:36.169 [script.javaScript.stackTrace]: i: "5"
14:21:36.169 [script.javaScript.stackTrace]: cargopods: []
14:21:36.169 [script.javaScript.stackTrace]: damage_to: 2.52182734375
14:21:36.169 [script.javaScript.stackTrace]: n_considered: 3.52182734375
14:21:36.169 [script.javaScript.stackTrace]: n_mass: 3.52182734375
14:21:36.169 [script.javaScript.stackTrace]: n_cargo: 0
14:21:36.169 [script.javaScript.stackTrace]: 1 (NPC_Equipment_Damage.js:44) <anonymous function>
14:21:36.169 [script.javaScript.stackTrace]: this: [Script "griff_spawn_wreckage" version 1.1]
14:21:36.169 [script.javaScript.stackTrace]: type: "scrape damage"
14:21:36.169 [script.javaScript.stackTrace]: whom: [Ship "Navigation Buoy" position: (56363.1, 60473.3, 744739) scanClass: CLASS_BUOY status: STATUS_IN_FLIGHT]
14:21:36.169 [script.javaScript.stackTrace]: amount: 18694.5703125
14:21:36.169 [script.javaScript.stackTrace]: internal_damage: true
14:21:36.169 [script.javaScript.stackTrace]: 2 (N-Shields.js:777) <anonymous function>
14:21:36.169 [script.javaScript.stackTrace]: this: [Script "NShields" version 0.6.2]
14:21:36.170 [script.javaScript.stackTrace]: type: "scrape damage"
14:21:36.170 [script.javaScript.stackTrace]: whom: [Ship "Navigation Buoy" position: (56363.1, 60473.3, 744739) scanClass: CLASS_BUOY status: STATUS_IN_FLIGHT]
14:21:36.170 [script.javaScript.stackTrace]: amount: 19686.5703125
14:21:36.170 [script.javaScript.stackTrace]: ship: [Ship "GalCop Viper Interceptor" position: (56387.9, 60499.5, 744699) scanClass: CLASS_POLICE status: STATUS_IN_FLIGHT]
14:21:36.170 [script.javaScript.stackTrace]: 3 (N-Shields.js:472) <anonymous function>
14:21:36.170 [script.javaScript.stackTrace]: this: [Script "griff_spawn_wreckage" version 1.1]
14:21:36.170 [script.javaScript.stackTrace]: caller: undefined
14:21:36.170 [script.javaScript.stackTrace]: type: "scrape damage"
14:21:36.170 [script.javaScript.stackTrace]: whom: [Ship "Navigation Buoy" position: (56363.1, 60473.3, 744739) scanClass: CLASS_BUOY status: STATUS_IN_FLIGHT]
14:21:36.170 [script.javaScript.stackTrace]: amount: 19814.5703125
14:21:36.170 [script.javaScript.stackTrace]: hitLocationRelative: (-26.0033, -16.9483, 24.8363)
14:21:36.170 [script.javaScript.stackTrace]: hitLocation: (56361.9, 60482.6, 744724)
Re: [WIP] NPC Equipment Damage
Posted: Tue Jun 07, 2016 2:34 pm
by Ngalo
Version 0.2 is now out with improved Ship Configuration compatibility and an attempt to fix the issue with the same equipment getting damaged multiple times (due to not checking whether it was already damaged, although I'm not sure I've corrected it in an entirely fair manner).
Re: [WIP] NPC Equipment Damage
Posted: Tue Jun 14, 2016 2:52 am
by phkb
Still seeing this in my log file occasionally:
Code: Select all
12:48:33.015 [script.javaScript.timeLimit]: ***** ERROR: Script "griff_cobra_III_(alt)_externalMissiles.js" ran for 1.14818 seconds and has been terminated.
12:48:33.015 [script.javaScript.stackTrace]: 0 (NPC_Equipment_Damage.js:84) <anonymous function>
12:48:33.015 [script.javaScript.stackTrace]: this: [Script "NPC_Equipment_Damage" version 0.2]
12:48:33.015 [script.javaScript.stackTrace]: ship: [Ship "Cobra Mark III" position: (-41597.4, 15340.7, 349765) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
12:48:33.015 [script.javaScript.stackTrace]: handlers: undefined
12:48:33.015 [script.javaScript.stackTrace]: accumulator: undefined
12:48:33.015 [script.javaScript.stackTrace]: target: undefined
12:48:33.016 [script.javaScript.stackTrace]: eq: [EquipmentInfo EQ_ENGINE_COUPLING_TYPE2 "Engine Power Coupling Class 2"]
12:48:33.016 [script.javaScript.stackTrace]: damageableEquip: [[EquipmentInfo EQ_THRUSTERS_TYPE2A "Manoeuvring Thrusters Class 2A"]]
12:48:33.016 [script.javaScript.stackTrace]: damageableOdds: 1
12:48:33.016 [script.javaScript.stackTrace]: damageableCounter: 1
12:48:33.016 [script.javaScript.stackTrace]: i: "6"
12:48:33.016 [script.javaScript.stackTrace]: cargopods: ["minerals", "minerals"]
12:48:33.016 [script.javaScript.stackTrace]: damage_to: 645.0336249999996
12:48:33.016 [script.javaScript.stackTrace]: n_considered: 2501.0336249999996
12:48:33.016 [script.javaScript.stackTrace]: n_mass: 21.68389375
12:48:33.016 [script.javaScript.stackTrace]: n_cargo: 20
12:48:33.016 [script.javaScript.stackTrace]: 1 (NPC_Equipment_Damage.js:50) <anonymous function>
12:48:33.016 [script.javaScript.stackTrace]: this: [Script "griff_cobra_III_(alt)_externalMissiles.js" version 1.01]
12:48:33.016 [script.javaScript.stackTrace]: type: "scrape damage"
12:48:33.016 [script.javaScript.stackTrace]: whom: [Ship "Asteroid" position: (-41624.9, 15266.9, 349762) scanClass: CLASS_ROCK status: STATUS_IN_FLIGHT]
12:48:33.016 [script.javaScript.stackTrace]: amount: 5425.53564453125
12:48:33.016 [script.javaScript.stackTrace]: internal_damage: true
12:48:33.016 [script.javaScript.stackTrace]: 2 (N-Shields.js:794) <anonymous function>
12:48:33.016 [script.javaScript.stackTrace]: this: [Script "NShields" version 0.6.3]
12:48:33.016 [script.javaScript.stackTrace]: type: "scrape damage"
12:48:33.016 [script.javaScript.stackTrace]: whom: [Ship "Asteroid" position: (-41624.9, 15266.9, 349762) scanClass: CLASS_ROCK status: STATUS_IN_FLIGHT]
12:48:33.016 [script.javaScript.stackTrace]: amount: 7985.53564453125
12:48:33.016 [script.javaScript.stackTrace]: ship: [Ship "Cobra Mark III" position: (-41597.4, 15340.7, 349765) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
12:48:33.016 [script.javaScript.stackTrace]: 3 (N-Shields.js:489) <anonymous function>
12:48:33.016 [script.javaScript.stackTrace]: this: [Script "griff_cobra_III_(alt)_externalMissiles.js" version 1.01]
12:48:33.016 [script.javaScript.stackTrace]: caller: undefined
12:48:33.017 [script.javaScript.stackTrace]: type: "scrape damage"
12:48:33.017 [script.javaScript.stackTrace]: whom: [Ship "Asteroid" position: (-41624.9, 15266.9, 349762) scanClass: CLASS_ROCK status: STATUS_IN_FLIGHT]
12:48:33.017 [script.javaScript.stackTrace]: amount: 8113.53564453125
12:48:33.017 [script.javaScript.stackTrace]: hitLocationRelative: (-31.0124, -70.7728, -1.39412)
12:48:33.017 [script.javaScript.stackTrace]: hitLocation: (-41628.4, 15269.9, 349763)
Other issues appear to be fixed, though.
Re: [WIP] NPC Equipment Damage
Posted: Tue Jun 14, 2016 1:08 pm
by Ngalo
I think what's happening with the scripts running out of time is that my code doesn't check whether the damage amount is sufficient to destroy the ship, so occasionally something like a collision or a Q-bomb does a truly ridiculous amount of damage and the equipment damage code still gets called once for every 32 points of it.
The download link will shortly be updated to version 0.2.1 with a fix.
Re: [WIP] NPC Equipment Damage
Posted: Wed Jun 15, 2016 1:04 am
by phkb
Small bug in the manifest.plist file on version 0.2.1. You're missing a comma "," between the two "optional_oxp" entries.
Re: [WIP] NPC Equipment Damage
Posted: Wed Dec 09, 2020 7:32 pm
by Cholmondely
phkb wrote: ↑Wed Jun 15, 2016 1:04 am
Small bug in the manifest.plist file on version 0.2.1. You're missing a comma "," between the two "optional_oxp" entries.
The most recent version seems to be 10th May 2016 - so this bug was presumably not fixed.
There is a bug preventing loading on the
AppleMac.
See here:
https://bb.oolite.space/viewtopic.ph ... 34#p273134 for the relevant sections in opening.log and putative fixes!
Re: [WIP] NPC Equipment Damage
Posted: Wed Dec 09, 2020 8:21 pm
by dybal
This OXP is in my TODO list for updating and making sure it smoothly integrates with N-Shields. I plan to do as I did with NPC Energy Units for the same reason (the original's license): re-write as a new OXP (different ID, incompatible with the original so there is no collision) and put the new version in the Expansion Manager.
Re: [WIP] NPC Equipment Damage
Posted: Wed Dec 09, 2020 8:26 pm
by Cholmondely
I'll see if I can bung up a wiki page for it then.
Re: [WIP] NPC Equipment Damage
Posted: Wed Dec 09, 2020 8:28 pm
by Cholmondely