Thargoid wrote:cim wrote:New ship methods: ship.dealEnergyDamage(amount,range,shaping)
As the wiki is lagging a little with all these new goodies, can you explain a little what shaping
means in ship.dealEnergyDamage
?
It works a bit differently to the old AI command. With the AI command, you set a range and the weapon_energy property sets an amount of damage. The explosion then deals
range * weapon_energy / 6.76
points of damage at 1m range (for a standard missile, 166420 points of damage). This falls off on an inverse square basis (and rises, within 1m range) until the set range, where it is truncated to zero.
The problem with this is that the damage dealt by a missile is highly dependent on the range it detonates at, which is dependent on the frame rate (the higher the frame rate, the closer to the programmed range the missile will explode). As a result, a single missile impact can destroy just about anything at low frame rates - and a frame rate of 30, which is perfectly adequate for normal play, still sees normal missiles able to destroy a fully military shielded Cobra III in a single hit with a head-on collision ... whereas at a frame rate of 100, this will never happen.
(A second problem: that damage formula is really not intuitive for working out how much damage the missile actually deals at its programmed range)
So, ship.dealEnergyDamage(amount,range) works a bit differently. Rather than setting the maximum range for the explosion, you set the ideal range. 'amount' damage is dealt at this range
and at closer ranges. The maximum range is then automatically calculated based on an inverse square falloff of damage outside the ideal range (with a truncation to zero for efficiency at max scanner range)
...but. The old behaviour meant that missiles did more damage if you hit them head-on, and less if you got them to explode while fleeing. This is an interesting dynamic that we wanted to keep (or introduce, at frame rates closer to 100...) - but with just those two parameters every missile does exactly the same damage regardless (around 270 points for a standard missile).
So, the third parameter "shaping" (it is internally called "velocityBias" and I may go back to that name for the docs) for ship.dealEnergyDamage looks at the relative positions and velocities of the two objects, and adds on "shaping" points of damage for every 0.001LM of relative closing speed (capped at 1.0LM). This means that a collision where the missile is just scraping the edge of its detonation distance, at quite an angle (if you almost but not quite evade it, for instance) will do significantly reduced damage, while a head-on collision will do significantly increased damage.
For the standard missile, I calibrated it assuming the "standard collision" which should do 266 damage was for a ship doing about 0.3-0.35LM fleeing from a missile doing 0.75LM, for a relative closing speed of around 0.4LM. The standard missile is therefore set to
this.ship.dealEnergyDamage(170, 32.5, 0.25);
and it detonates at about 25m, which is within the 32.5m ideal damage radius even with some framerate oddities.
- at 0.4LM against a fleeing target it does 170+(400*0.25) = 270 damage: near enough the intended damage, but it can be lower if the target managed to curve out of the blast. Still enough to destroy an unshielded Cobra III most of the time, as intended.
- at 0.75LM against a stationary target it does 170+(750*0.25) = 357.5 damage. Enough to seriously damage but not destroy a shielded Cobra III
- at 1.0LM+, when a pirate FDL drops a missile on you head-on at point-blank range, it does 170+(1000*0.25) = 420 damage. Enough to destroy a shielded Cobra III, or significantly damage one with full military shields.
(relative closing speed can be negative, though generally only if the missile was aimed at someone else)
Thanks for reminding me I'd missed the documentation for that one.