Preliminary research into attacks and the values in dfhack.
The attack action is currently filled with unknown variables. And currently looks like
target_unit_id = 28
unk_4 = <unit_action.T_data.T_attack.T_unk_4: 0x17234f0c>
attack_item_id = 15
target_body_part_id = 0
attack_body_part_id = -1
attack_id = 1
unk_28 = 0
unk_2c = 1
unk_30 = 57
flags = 66
unk_38 = 0
unk_3c = 58
timer1 = 3
timer2 = 4
It has been "established" that unk_30 and unk_3c are attack_velocity and attack_hitchance (or somehow related to hit chance) and I believe the names have even been changed in the new DFHack. The following research tries to investigate the other components.
Tests done. By having several groups of dwarves with the same stats attack eachother with differing skills I have been analyzing their attack actions. Currently found results.
attack.flagsFlags is a specific number, meaning you won't find just a random number between say 0 and 100. Instead it appears to be tied to the type of attack done (i.e. fast attack, wild attack, etc...). My reasoning behind this is that the attack.flag and attack.timer1/attack.timer2 is fixed, independent of attack preformed (with the exception of weapon vs non-weapon attacks). This means that if you were to tell me that the flags for a short sword attack was 66 I could tell you that the timer1 = 3 and timer4 = 4. In the couple dozen or so tests I ran with short swords, the flags values could be 2, 34, 66, 130, or 258. For the unnarmed attacks the flag values were 70, 134, or 262.
attack.unk_38This number appears constant depending on if it is a weapon attack or creature attack. With all tested weapon attacks having unk_38 = 0 and all tested creature attacks having unk_38=102 or unk_38=103 (no idea why the difference all dwarves tested used 103, but some other animals used both, some only used 102, possibly other animals use other numbers?)
attack.unk_3c or hitchanceA highly variable number, as expected increase skill, on average, increases hit chance. The attack.flags also impacts hit chance greatly. With larger timer1 values and smaller timer2 values increasing hit chance (4,3 appearing to give the best increase for the tests done). Still need to do more work concerning varying agility, speed, and enemy dodge skills.
attack.unk_30 or velocityVelocity values have been analyzed by Urist DaVinci in his disassemble work and appear to follow those values well.
attack.unk_28 and attack.unk_2cNo idea. Doesn't seem to be tied to anything I could think of, with unk_28 varying between 0 and 4 (usually 0, 1, or 2) and unk_2c varying between -2 and 5 (usually -2, -1, 0, or 1). Possibly related to the attack.unk_4 vector, as I have not studied the numbers in there yet.
That is my small update for now.
EDIT: After looking through about 50,000 attacks it appears that velocity and hit chance are related to eachother. For basic attacks (not fast, wild, hard, etc...) you have a higher velocity = higher hit chance (the particular equation I looked at was hit chance = velocity*0.8 - 40, but I haven't looked at the impact skills and attributes have yet). Now when you throw in different types of attacks the relationship changes, but it's a nice start.
EDIT2: Here are two simple graphs showing the velocity and hit chance of different types of attacks for dwarves with 1000 strength and 1000 agility at different skill levels.
You will notice that the hit chance increases linearly with skill level, but the velocity seems to plateau.
Other interesting notes
Quick and Heavy have the same hit chance as Normal attacks, with Precise having more and Wild having less
Normal and Precise have the same velocities, Wild and Heavy have the same velocities, and Quick has the lowest velocities
Next step will be to check the effect attributes have on this distribution. Presumably the general shape will remain the same, with just the absolute values changing.
EDIT3: Last update for now. The reason the velocity is plateauing is because the max velocity of all attacks doesn't increase as skill goes up, just the minimum and the average. I believe you can think of there being an optimum velocity that you can reach based on your attributes and weapon (this is the velocity Urist DaVinci calculates), then the game uses a fraction of that velocity depending on how skilled you are. The more skilled, the closer that fraction goes to reaching 1. This is different from hitchance, which doesn't seem to have an upper cap, and whose max just keeps increasing along with the average at each skill level.