Dwarf Fortress Bug Tracker - Dwarf Fortress
View Issue Details
0006262Dwarf FortressThrowing/Shootingpublic2012-12-12 05:182014-08-03 13:29
Pirate Bob 
Toady One 
normaltrivialalways
resolvedfixed 
ComputerWindows/Linuxall
0.34.11 
0.40.05 
0006262: Rounding Error in Calculation of Projectile Velocities
Projectile (bolts, arrows, blowdarts) velocities appear to be calculated using the formula:
velocity=[SHOOT_FORCE]/(([SOLID_DENSITY]*[SIZE])/1,000,000),
and then capped to [SHOOT_MAXVEL]. All numbers are treated as integers throughout, and therefore floored to the nearest integer after each multiplication/division. [SHOOT_FORCE], [SIZE] and [SHOOT_MAXVEL] are defined by the launcher (bow, crossbow, etc) and [SOLID_DENSITY] by the ammo material. See this thread for details and derivation: http://www.bay12forums.com/smf/index.php?topic=116151.msg3716892;topicseen#msg3716892 [^]

As a result:
1) Any bolts/arrows with [SOLID_DENSITY] between 6666 and 13333 (all metals except adamantine) will have velocity equal to [SHOOT_FORCE].
2) Bolts lighter than [SOLID_DENSITY:6666] (wood, bone, adamantine) will have velocity equal to [SHOOT_MAXVEL].
3) Since both [SHOOT_FORCE] and [SHOOT_MAXVEL] are 1000, all bolts will have velocity 1000.
4) Armor penetration (in most cases) and damage depend on bolt momentum, so bolts made of denser materials will be more effective.
Download the script chkproj.lua from http://www.bay12forums.com/smf/index.php?topic=116151.msg3716892;topicseen#msg371689 [^] and use it to check projectile velocities, which are given by the variable unk22. By changing [SHOOT_FORCE], [SHOOT_MAXVAL] and bolt [SOLID_DENSITY] one can quickly verify the rounding behavior.

This has also been verified by measuring deflection of bolts off armored targets. All metal bolts were found to have exactly the same rate of deflection as a function of momentum when momentum was calculated using the velocity formula described, and mass=([SOLID_DENSITY]*[SIZE])/1,000,000. See http://www.bay12forums.com/smf/index.php?topic=116151.msg3733282#msg3733282. [^]
This could easily be fixed by changing the velocity calculation to:
velocity=1,000,000*SHOOT_FORCE/[SOLID_DENSITY]/[SIZE]
If this is not possible, then the original calculation could be used with all numbers converted to floating point within the calculation, and then the final velocity rounded to an integer.

The effects of this bug cannot be detected without modding/hacking in the current version because all bolts have such high momenta that small differences have no noticeable impact. I have therefore marked it as trivial. However, if bolt momenta were reduced to give armor a chance of stopping projectiles (see [url=http://www.bay12games.com/dwarves/mantisbt/view.php?id=5516 [^]]5516[/url]), then this bug would become significant.

It is also possible, but I think very unlikely, that this is "intended behavior". This bug renders the [SHOOT_FORCE] parameter almost useless, as all projectiles are fired with the same velocity. If Toady wanted all projectiles fired with the same velocity, he could have just set a fixed projectile velocity rather than calculating it from [SHOOT_FORCE].
No tags attached.
related to 0005516resolved Toady One Absurdly Powerful Bolts/Arrows 
related to 0006364resolved Toady One Weight fraction not considered when calculating weapon velocities 
related to 0006870resolved Toady One Bolts, crossbows and other ranged weapons have excessive SHOOT_FORCE values, leading to ranged combat issues 
Issue History
2012-12-12 05:18Pirate BobNew Issue
2012-12-12 05:51Pirate BobIssue Monitored: Pirate Bob
2012-12-12 05:58Pirate BobNote Added: 0023774
2012-12-12 07:18PetWolverineIssue Monitored: PetWolverine
2012-12-12 09:48Knight OtuRelationship addedrelated to 0005516
2013-04-13 13:07Pirate BobTag Attached: Probable Quick Fix
2013-04-13 15:34QuietustNote Added: 0023944
2013-04-19 05:00ScegfOdNote Added: 0023947
2013-08-02 04:28Knight OtuRelationship addedrelated to 0006364
2013-10-09 12:39UristDaVinciNote Added: 0024164
2013-10-28 11:22JimiDIssue Monitored: JimiD
2014-01-17 10:33Kirig StonebeardIssue Monitored: Kirig Stonebeard
2014-07-14 11:28FootkerchiefRelationship addedhas duplicate 0006870
2014-07-24 09:30FootkerchiefTag Detached: Probable Quick Fix
2014-07-24 14:35FootkerchiefRelationship replacedrelated to 0006870
2014-07-24 15:05Toady OneStatusnew => resolved
2014-07-24 15:05Toady OneFixed in Version => Next Version
2014-07-24 15:05Toady OneResolutionopen => fixed
2014-07-24 15:05Toady OneAssigned To => Toady One
2014-08-03 13:29PetWolverineIssue End Monitor: PetWolverine

Notes
(0023774)
Pirate Bob   
2012-12-12 05:58   
This bug should be marked as related to 0005516, and vice versa, but I can't figure out how to do that (maybe admin privileges are required?). Also, sorry about the nasty looking links - I thought maybe BBcode would work, but apparently not...
(0023944)
Quietust   
2013-04-13 15:34   
For reference, the "chkproj.lua" mentioned above is a script for use with DFHack and thus isn't likely to be useful to Toady in tracking down the problem (since he can debug the game directly).
(0023947)
ScegfOd   
2013-04-19 05:00   
this bug reminded me of a C++ tutorial i was looking at once upon a time...
does Toady program in C++?
type casting might fix this bug easily

http://www.cprogramming.com/tutorial/c/lesson11.html [^]
(0024164)
UristDaVinci   
2013-10-09 12:39   
I used windbg on the relevant code, and this "bug" is caused by only the integer weight of the bolt being used in the integer division SHOOT_FORCE/WEIGHT. It appears that this code was imported from earlier versions of Dwarf Fortress (such as "40d"), where weight numbers were all larger. This code wasn't updated when fractional weights were introduced.

It's almost not a bug, instead just a non-updated feature like siege weapons.