CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.29k stars 4.12k forks source link

Melee weapon attack move cost algorithm based on simple physical modeling. #72648

Closed wwkk222208 closed 3 months ago

wwkk222208 commented 5 months ago

Is your feature request related to a problem? Please describe.

In the current game, using a dagger or simply fighting with bare hands is the inevitable last choice for players who specialize in melee weapon. Their attack speed is very fast and they only consume very little stamina. Commonly seen professional cold weapons in the real world, such as long swords and war hammers, have become a worse choice because of their long attack intervals and the consumption of a lot of stamina. I reviewed the relevant code and found that the reason for this phenomenon is that the melee weapon attack move cost algorithm is not based on a physical model. Therefore, I hope to improve it.

Solution you would like.

Physical modeling of stab weapon is based on the following assumptions. 1.The force F applied by the character arm and weapon is conserved. 2.The character's attack is regarded as move arm and weapon to a specific distance s.

image

Physical modeling of cut and stun weapon is based on the following assumptions. 1.The character's arm and weapon are treated as a rigid body as a whole. L0 is the distance between the hand and the rotation center. 2.The weapon is a homogeneous stick with a density of ρ and the cross-sectional area S is negligible. Its length is L. 3.The character holds the bottom of the weapon. 4.The moment of force τ applied by the character to the rigid body is conserved. 5.The character's attack is regarded as rotating the rigid body to a specific angle θ. 6.The weaponis perpendicular to the line connecting the hand and the rotation center. The calculation process is as follows. image

α is angular acceleration. I is rotary inertia. c1 and c2 are constants to be determined. c0 is the base attack move.

Now consider the extreme case, first when the "balance" is extreme. The weapon is not a homogeneous stick any more, it becomes a ponit at the position of hand. image Then consider the case when the "unbalance" is extreme The weapon becomes a point at the other end. image

Therefore, how unbalanced a weapon is can be quantified.

It is necessary to adjust the coefficient that the mass needs to be multiplied by according to the label of the weapon category.

Describe alternatives you have considered.

Actually, the above assumptions are difficult to meet in real scenarios, so this model cannot fully and truly reflect the attack process, but it can determine that the attack duration is related to the 0.5th power of the weight of the weapon rather than the first power in the current game. Perhaps these effects can be summarized by a general attack speed correction factor, but I am not sure whether it is necessary to introduce it.

Additional context

To develop test procedures to ascertain the effect of this modification on the game's balance.

Zireael07 commented 5 months ago

Why open only to close immediately as not planned?

wwkk222208 commented 5 months ago

LOL...I found some errors in the previous calculation formula, so I temporarily closed it. But it's back now.

Zireael07 commented 5 months ago

The only thing such "temporary" closing does is make noise in people's feeds. Not an advisable thing to do

wwkk222208 commented 5 months ago

I feel sorry about that.

I-am-Erk commented 5 months ago

Don't worry too much about it. I'd suggest just setting it to draft until you're ready for merge with something this big, but it's fine to open and close if you need to

GuardianDll commented 5 months ago

..it's an issue, Erk

I-am-Erk commented 5 months ago

Oh. Well, good point.

Opening and closing it is fine in a case like that where you're worried someone is going to start taking you up on your flawed math then. Personally, I'd usually just edit in something like

"Aaaaaaagh I just found a math error don't use this until it's fixed"

But that's just my style

LyranRenegade commented 5 months ago

curious to see some simplified math of this

Zireael07 commented 5 months ago

Woops I'm guilty of thinking it's a PR, too :P

I-am-Erk commented 5 months ago

So, if I'm understanding your math correctly, this looks excellent but has some drawbacks we should consider, primarily with swinging weapons. AFAICT the stab algo looks fine

  1. I believe you're using item length to presume the overall length of the lever arm. A lot of the time that will work, eg. a sword, but a lot of the time it doesn't at all, eg a quarterstaff.
  2. many cut/blunt weapons in game are not exclusively used to swing, they may also stab. A sword or quarterstaff is a good example here.

This doesn't invalidate your work. It just means we should have some ways to adapt it, and I would suggest we use the json data in to-hit for that. We have two stats I'd like to visit: balance and surface.[^1]

(yeah that's right MFers I wrote a dang comment with footnotes. What you gonna do about it.

[^1]: If there's no detailed 'to hit' data then we should use the algorithm you've got above, unmodified. This encourages people to fill out better to hit data for things that should be used as weapons.

[^2]: Edit to add, it occurs to me that if I'm following the math right, we might be able to use the "stab" calculated time as the fastest possible attack? I am not completely sure I'm correct on this but I think I am.

[^3]: Outside this issue/PR but in the future, UNWIELDY weapons and perhaps CLUMSY as well might also want to have an additional "recovery time" after the attack that is some portion of their attack speed. Or this could be a thing for all weapons, but far more relevant for unwieldy and clumsy ones.

[^4]: We may want to add a new SURFACE json option. I note things like "arming sword" are (currently correctly) listed as "line" attacks, but we might want to add something like "line_versatile" meaning to-hit is calculated as a line, but attack speed is calculated as "any". This is definitely not part of your original concept, and may not be necessary at all. Don't do it on a first pass, just consider it based on outcomes.

I-am-Erk commented 5 months ago

Separate thought, but your point about length becoming a purely negative attribute is a good one. We may want to consider ways of boosting length by representing its ability to make attacks while keeping away from the enemy. If you're on discord, ping me.

EDIT: I have been discussing this on discord, there are two solutions. One is big and needs its own issue, but one should be pretty easy. Basically, we should give wielded items a "fend off" buff based on their length. Longer wielded items should give you a passive resistance to grabbing, which drops rapidly the more enemies there are. Basically:

grab_defense ∝ weapon_length * (modifier_related_to_skill) / number_adjacent_enemies
if number_adjacent_enemies >= (dex+per)/4, grab_defense = 0

I may add a separate issue for this concept. The bsaic idea is if you're holding a largish object, you can probably shove it between yourself and a zombie and keep that zombie from grabbing you, but the more zombies around you the less likely you are to hold them at bay. This serves mainly as a flat buff to longer melee weapons, but also lets you pick up a long stick and fend off a single zombie while trying to find a better strategy.

Ideally we should have a message for if the zombie would have grabbed you but is fended off, to communicate this advantage to players.

wwkk222208 commented 5 months ago

I really appreciate your suggestion. I feel very honored to be able to study this issue with you.

I believe you're using item length to presume the overall length of the lever arm. A lot of the time that will work, eg. a sword, but a lot of the time it doesn't at all, eg a quarterstaff. many cut/blunt weapons in game are not exclusively used to swing, they may also stab. A sword or quarterstaff is a good example here.

You're correct, my modeling here is closest to weapons similar to swords, and doesn't give much consideration to other types of weapons. Its greatest significance is to reflect to what extent the length and weight affect the attack time. If we model the attack method of long stick weapons, we will get formulas with similar forms but different coefficients.

I suggest that you use these formulae to calculate the slowest attack time for a weapon, and then have the balance and surface modify that down. That's because we're going to use balance and surface to make assumptions about things like choking up on the handle to shorten the lever arm.

There should probably be a minimum attack time as well, maybe 50% of the calculated?2 You'd need to look into what numbers you're getting to make a sanity check here, I'm just throwing out random guesses.

I have to admit that I think this formula determines the upper limit of the attack speed rather than the lower limit for weapons with specific attack methods, . Because when the weapon mass is 0, the formula calculates the base attack interval. Is it possible to attack faster with a held weapon than with bare hands? Of course it is possible, such as by swinging a long sword by rotating the wrist. But this actually changes the attack method, and from a practical point of view, the power of the wrist cannot compare with the power of the entire upper limb. The power of the weapon when using this special technique should be lower than normal. Yes, we now have Rapid Strike to simulate this technique.

Your ability to shorten attack time should be based on appropriate skill. Less skilled people are more likely to be making big wide strokes, more skilled people can adjust their position and swing to make quicker attacks without sacrificing anything.

Very good suggestion, but for the reasons mentioned earlier in the text, I prefer that the skill level can be increased to reduce the penalty rather than to increase the speed. As for whether the basic attack time can be reduced through skills or attributes, it should be a topic unrelated to the weapon itself.

BALANCE should straight up just increase attack speed when it is better: we are making the assumption that a better balanced weapon has a grip somewhere inside its length. I'd suggest that CLUMSY balance should use the base calculated speed, and that speed cannot be adjusted by weapon skill. UNEVEN3 balance uses the base calculated speed, but each level of weapon skill and melee skill reduces the time to swing by 0.5%. NEUTRAL balance reduces the base calculated time by 10%, and an additional 1% for each level of weapon and melee skill. GOOD balance reduces the base calculated time by 15%, and an additional 1% for each level of weapon and melee skill.

In fact, the balance of a weapon can be roughly quantified. For example, an extremely balanced weapon can be considered to have its center of gravity near the handgrip position. Whether the handgrip position is at the end point or the middle point of the weapon represents two extremes respectively. When the hand is at the end point and the center of gravity is also at this point, the weapon is abstracted as a particle, at which time the influence of length disappears, and the formula degenerates into the form of the stab formula, and the moment of inertia is the smallest. When the hand is at the middle point, the influence of length on the moment of inertia reaches the maximum, but it is still smaller than the moment of inertia when the hand holds the end point of a homogeneous and slender weapon. When considering the extreme unbalance of the weapon, the hand holds one end of the weapon, but the mass of the weapon is concentrated at the other end (such as a hammer with a very heavy head), then its moment of inertia is directly determined by the distance from the center of gravity to the center of rotation. Therefore, when measuring balance, only one controllable and meaningful factor needs to be introduced. Of course, this factor can also be linked to the extent to which skills can affect the use of weapons. It's cool. But I am considering that it may need more testing due to the potential problem of numerical inflation. In general, I believe that melee weapons can be classified into several categories in some way, each corresponding to a parameter that can be modified by the weapon's "Balance". Perhaps it is enough to divide them into three categories: one-handed weapons, two-handed weapons, and long stick weapons.

SURFACE may be really useful to us here, because it carries some info on how a weapon is swung. Regardless of damage type, if surface is listed as "POINT" we should use the first calculation as per stabbing weapons. If surface is listed as "LINE", use the second calculation for swinging weapons. if it is listed as "ANY"4 though, we get a cool new development. Good example is the quarterstaff which can be swung or thrust. This use case should cover a lot of our weapons with a widely variable grip, and should help a lot to mitigate the edge cases where your number is going to be high because it assumes the player is swinging their quarterstaff from one end. I am not quite sure how to resolve this and am open to suggestions. my first thought is that for weapons using ANY surface, we set their base attack time to be the average between the thrust and swing time equations. However another option would be to have the attack speed start closer to the SWING calculation and trend closer to the THRUST equation as the character skill increases (with balance bonuses added after).

Allowing a weapon to have both slashing and piercing functions at the same time is really cool. I really hope to add this feature to the next round of consideration.

Edit to add, it occurs to me that if I'm following the math right, we might be able to use the "stab" calculated time as the fastest possible attack? I am not completely sure I'm correct on this but I think I am.

Not really. For these two models, they have different assumptions. The former assumes that the character provides a constant force, while the latter assumes that the character provides a constant torque. Although in some ideal cases, the latter formula will degenerate into the same form as the former, their coefficients are still different. Of course, since the stroke of the stabbing weapon is usually shorter, stabbing should be the fastest, which can be achieved by adjusting the parameters.

I may add a separate issue for this concept. The bsaic idea is if you're holding a largish object, you can probably shove it between yourself and a zombie and keep that zombie from grabbing you, but the more zombies around you the less likely you are to hold them at bay. This serves mainly as a flat buff to longer melee weapons, but also lets you pick up a long stick and fend off a single zombie while trying to find a better strategy. Ideally we should have a message for if the zombie would have grabbed you but is fended off, to communicate this advantage to players.

Awesome!But I am not yet clear how grab_defense is implemented. Would multiplying by the length directly make it impossible to resist grab with a short weapon?

wwkk222208 commented 5 months ago

I didn't use Discord before, but I would like to start an account.

wwkk222208 commented 5 months ago

A term was missing in the previous formula, and now it has been corrected. And the expression has been changed to make it clearer.

wwkk222208 commented 5 months ago

Let's consider the long stick-like weapons, such as the quarterstaff. If I didn't misunderstand, the quickest attack method of the quarterstaff is to hold one hand at the quarter to one-third of the weapon, and the other hand holds the end point. The former remains motionless, and the latter moves to drive the weapon to rotate for attack. Therefore, the modeling assumption is as follows. 1.The character's arm and weapon are treated as rigid bodies 2.The weapon is a homogeneous stick with a density of ρ and the cross-sectional area S is negligible. Its length is L. 3.The center of rotation is located at one-third of the weapon. 4.The moment of force τ applied by the character to the rigid body is conserved. 5.The character's attack is regarded as rotating the rigid body to a specific angle θ.

image

It is necessary to note that the constants in this model are different from those in the sword model. But it can still indicates that this method of holding the weapon truly greatly reduces the time for the weapon to wield.

wwkk222208 commented 5 months ago

If we consider a two-handed sword or axe, then we only need to double the moment of inertia and the rotational inertia of the arm on the basis of the one-handed sword model, and the result is as follows. image Therefore, two-handed weapons can "tolerate" a greater length. Considering that the flexibility of two-handed weapons is not as good as that of one-handed weapons, its basic attack speed should be lower. When a weapon can be held with one hand or two hands, compare the calculated results of the two, and take the larger value.

wwkk222208 commented 5 months ago

Combined with the "Balance" factor, the above model should be applicable to classic weapons such as one-handed sword, one-handed axe / hammer, two-handed sword, two-handed axe / hammer, long stick, lance, dagger, etc.

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not bump or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.