-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weapon Value Caches properly update #2742
Weapon Value Caches properly update #2742
Conversation
31cfb9a
to
2e440fa
Compare
Use magazine size instead.
2e440fa
to
1f71dc3
Compare
Best cannot be cbm_fake_toggled if the fake item is being wielded.
3d201c7
to
854552e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPC's inventory
output.mp4
I'm not sure why but the weapon switch of death (WSOD) still happens. could you check again?
this is my save with NPC setup for test.
EmptyWorld.zip
999933a
to
e797e11
Compare
Properly considers the item itself, reworks some old code. Ideal weapon value creates fake item with max ammo
e797e11
to
e199f04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spawn menacing debug monster within range. Check that the NPC wields their M4A1.
2023-05-04.09-28-26.mp4
using the same save. this time, npc only wields katana, despite having m4a1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache.mp4
confirmed that the npc
- wields and fires m4a1 rifle first, and reloaded only once.
- wields and fires their bionic shotgun until emptying magazine, then loads and fires ammo one at a time.
- uses their katana.
npc logic is still very wacky and sometimes they whack debug monster with m4a1 instead of their katana, but let's fix them later.
@@ -2015,7 +2015,7 @@ double npc_ai::gun_value( const Character &who, const item &weap, int ammo ) | |||
} | |||
|
|||
// Gives an approximation of DPS disregarding modes. | |||
float move_cost_factor = move_cost / 100; | |||
float move_cost_factor = move_cost / 100.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting. (godbolt)
#include <array>
#include <iostream>
auto main() -> int {
const auto a = int{123};
const auto b = int{100};
const auto c = float{100};
std::cout << "123 / 100 :: int = " << float{a / b} << "\n";
std::cout << "123 / 100 :: float = " << float{a / c} << "\n";
}
/*
123 / 100 :: int = 1
123 / 100 :: float = 1.23
*/
Summary
SUMMARY: Bugfixes "Weapon Value Caches properly update"
Purpose of change
#1705 revealed issues with weapon value cache for NPCs, where they try to store and read ideal and current values, leading to mismatch and incorrect evaluations.
Describe the solution
Adds new
wielded_value()
function dedicated to updating value of currently wielded weapon. Accepts Character and bool as arguments, where the bool decides whether the value to be retrieved is the ideal value if the NPC had access to "infinite" ammo (set to magazine size otherwise values can get absurd).Refactors
wield_better_weapon()
to solve secondary issue @scarf005 noticed in #1705 where NPC would swap to bionic weapon only to swap back due to how weapon swapping occurs in bothcheck_or_use_weapon_cbms()
andwield_better_weapon()
. Now weapon swapping can only occur inwield_better_weapon()
,check_or_use_weapon_cbms()
instead queues the cbm weapon for checking.Describe alternatives you've considered
Can't think of any.
Testing
Spawn NPC, give them a katana, an M4A1, a filled STANAG 20 round magazine, 50 5.56 NATO rounds, 6 00 shotshells, and then install the bionic shotgun into them.
Additional context
Note, NPC will not empty the M4A1 on their last mag but leave it on 1 bullet remaining, fixing this is somewhat out of scope, as it requires adding consideration for reload cost, weapon swap cost, and firing cost.