Project

General

Profile

Bug #3935

Incorrect attack strength for AI actors

Added by Andrei Kortunov 6 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Game Mechanics
Target version:
Start date:
06/27/2017
% Done:

100%

Reproducibility:
Always
Operating system:
Other
Severity:
Normal

Description

According to Wiki, attack strength varies from 0.1 to 1.0, but in OpenMW NPC always have 1.0 attack strength.
See https://github.com/OpenMW/openmw/blob/master/apps/openmw/mwmechanics/character.cpp#L1358
When NPC hits, complete = 1. Creatures use random number instead and do not have this issue.

With ranged weapons "complete" varies from 0.0 to 1.0, what leads to #3639 (minimal strength should be 0.1).

Associated revisions

Revision f594eda5 (diff)
Added by scrawl . 3 months ago

Reset attackStrength when starting a new attack (Fixes #3935)

History

#1 Updated by Haoda Wang 5 months ago

From https://github.com/OpenMW/openmw/blob/master/apps/openmw/mwmechanics/character.cpp#L1359 it seems that removing the if statement and bringing the attackStrength assignment out will provide the expected behavior, but why is the if statement there in the first place?

#2 Updated by Andrei Kortunov 5 months ago

why is the if statement there in the first place?

Just read a comment below this line.

AI actually selects attack strength in aicombat.cpp (by random generator). This value should affect attack animation speed for melee weapons.
Also we need to read this value in character.cpp somehow to apply a damage.
OpenMW supposed to read attack strength from weapon attack animation status, but when we calculate a damage, this animation is already finished.
Maybe it supposed to use animation DURATION instead of % COMPLETED?

Some creatures do not have this animation, so we are forced to generate attack strength TWICE for creatures.

Anyway, current attack strength calculations for all actors is not entirely correct.

What we can do:
1) Set minimal attack strength to 10% in aicombat.cpp
2) Store attack strength somewhere
3) Read it in character.cpp instead of using animation data

#3 Updated by Haoda Wang 5 months ago

Is there any way to access an NPC's AiCombatStorage from character.cpp?

#4 Updated by Andrei Kortunov 5 months ago

Is there any way to access an NPC's AiCombatStorage from character.cpp?

Try to use something like:

AiState& state = actor->getAiState();
AiCombatStorage& storage = state.get<AiCombatStorage>();

#5 Updated by Haoda Wang 5 months ago

How about getting an actor from a MWWorld::Ptr?

#6 Updated by Alexei Dobrohotov 3 months ago

  • Status changed from New to Confirmed
  • Operating system changed from Linux to Other

#7 Updated by scrawl . 3 months ago

  • Status changed from Confirmed to Resolved
  • Target version set to openmw-0.43
  • % Done changed from 0 to 100

#8 Updated by scrawl . 3 months ago

Anyway, current attack strength calculations for all actors is not entirely correct.

What we can do:
1) Set minimal attack strength to 10% in aicombat.cpp
2) Store attack strength somewhere
3) Read it in character.cpp instead of using animation data

This is how AI attack strength works (or is supposed to work):
- The AI decides a random attack strength, stores it and sets the CharacterController's 'Attack' flag to true.
- Every frame, the AI checks if the current wind-up animation progress, as determined by the CharacterController, is >= the desired attack strength. If so, it sets the 'Attack' to false to release it.

I put in some logging, couldn't reproduce this issue in the sense that all attacks are full strength, but there is something odd. You can see how the first attack winds up correctly, but for the next attack an incorrect value is picked up:

 AI starting new attack with intended strength of 0.731278
 animation unreleased 0.105287
 animation unreleased 0.184482
 animation unreleased 0.302358
 animation unreleased 0.383841
 animation unreleased 0.536278
 animation unreleased 0.614099
 animation unreleased 0.772946
 AI stopping attack at 0.772946 intended 0.731278
 animation released 0.85214
 AI starting new attack with intended strength of 0.16478
 AI stopping attack at 0.85214 intended 0.16478 <--- WTF?
 animation released 0.0385672 <--- ???

Apparently, what went wrong is the CharacterController only updates 'mAttackStrength' once the animation is past the 'MinAttack' marker, but not if it's still at 'StartToMin'. So if getting past that point takes longer than one frame, mAttackStrength will remain at the value from the previous attack, and trigger an incorrect release with an incorrect strength value. This depends on the frame rate and possibly the animation in use.

Applying a fix for mAttackStrength to be reset to 0 when a new attack starts has fixed this issue, now the log looks as expected.

#9 Updated by scrawl . 3 months ago

  • Subject changed from NPC always deal max damage with melee weapons to Incorrect attack strength for AI actors

#10 Updated by Andrei Kortunov 3 months ago

  • Status changed from Resolved to Closed
  • Assignee set to scrawl .

Also available in: Atom PDF