Skip to content

Commit c5fefe6

Browse files
committed
Replace character creation's offense summary with evaluate_weapon() values
1 parent be71696 commit c5fefe6

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

src/character.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,8 +1197,7 @@ class Character : public Creature, public visitable
11971197
bool can_attack_high() const override;
11981198

11991199
/** NPC-related item rating functions */
1200-
double evaluate_weapon( const item &maybe_weapon ) const;
1201-
double weapon_value( const item &weap, int ammo = 10 ) const; // Evaluates item as a weapon
1200+
double evaluate_weapon( const item &maybe_weapon, bool pretend_have_ammo = false ) const;
12021201
double gun_value( const item &weap, int ammo = 10 ) const; // Evaluates item as a gun
12031202
double melee_value( const item &weap ) const; // As above, but only as melee
12041203
double unarmed_value() const; // Evaluate yourself!
@@ -1222,7 +1221,7 @@ class Character : public Creature, public visitable
12221221

12231222
private:
12241223
double evaluate_weapon_internal( const item &maybe_weapon, bool can_use_gun,
1225-
bool use_silent ) const;
1224+
bool use_silent, const int pretend_ammo = 0 ) const;
12261225
mutable std::optional<bool> cached_dead_state;
12271226
public:
12281227
void set_part_hp_cur( const bodypart_id &id, int set ) override;

src/melee.cpp

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ int Character::attack_speed( const item &weap ) const
27232723
return std::round( move_cost );
27242724
}
27252725

2726-
double Character::evaluate_weapon( const item &maybe_weapon ) const
2726+
double Character::evaluate_weapon( const item &maybe_weapon, const bool pretend_have_ammo ) const
27272727
{
27282728
bool can_use_gun = true;
27292729
bool use_silent = false;
@@ -2736,11 +2736,27 @@ double Character::evaluate_weapon( const item &maybe_weapon ) const
27362736
use_silent = true;
27372737
}
27382738
}
2739-
return evaluate_weapon_internal( maybe_weapon, can_use_gun, use_silent );
2739+
// ABSOLUTELY disgusting fake gun assembly for character creation
2740+
int pretend_ammo = 0;
2741+
if( pretend_have_ammo && maybe_weapon.is_gun() ) {
2742+
itype_id ammo_id = itype_id::NULL_ID();
2743+
if( maybe_weapon.ammo_default().is_null() ) {
2744+
ammo_id = item( maybe_weapon.magazine_default() ).ammo_default();
2745+
} else {
2746+
ammo_id = maybe_weapon.ammo_default();
2747+
}
2748+
const ammotype &type_of_ammo = item::find_type( ammo_id )->ammo->type;
2749+
if( maybe_weapon.magazine_integral() ) {
2750+
pretend_ammo = maybe_weapon.ammo_capacity( type_of_ammo );
2751+
} else {
2752+
pretend_ammo = item( maybe_weapon.magazine_default() ).ammo_capacity( type_of_ammo );
2753+
}
2754+
}
2755+
return evaluate_weapon_internal( maybe_weapon, can_use_gun, use_silent, pretend_ammo );
27402756
}
27412757

27422758
double Character::evaluate_weapon_internal( const item &maybe_weapon, bool can_use_gun,
2743-
bool use_silent ) const
2759+
bool use_silent, const int pretend_ammo ) const
27442760
{
27452761
if( is_wielding( maybe_weapon ) || ( !get_wielded_item() && maybe_weapon.is_null() ) ) {
27462762
auto cached_value = cached_info.find( "weapon_value" );
@@ -2756,8 +2772,9 @@ double Character::evaluate_weapon_internal( const item &maybe_weapon, bool can_u
27562772
// This is relatively reasonable, as players can issue commands to NPCs when we do not want them to use ranged weapons.
27572773
// Conversely, we cannot directly issue commands when we want NPCs to prioritize ranged weapons.
27582774
// Note that the scoring method here is different from the 'weapon_value' used elsewhere.
2759-
double val_gun = allowed ? gun_value( maybe_weapon, maybe_weapon.shots_remaining( here,
2760-
this ) ) : 0;
2775+
double val_gun = allowed ? gun_value( maybe_weapon,
2776+
std::max( maybe_weapon.shots_remaining( here, this ), pretend_ammo )
2777+
) : 0;
27612778
add_msg_debug( debugmode::DF_NPC_ITEMAI,
27622779
"%s %s valued at <color_light_cyan>%1.2f as a ranged weapon to wield</color>.",
27632780
disp_name( true ), maybe_weapon.type->get_id().str(), val_gun );
@@ -2774,39 +2791,6 @@ double Character::evaluate_weapon_internal( const item &maybe_weapon, bool can_u
27742791
return val;
27752792
}
27762793

2777-
double Character::weapon_value( const item &weap, int ammo ) const
2778-
{
2779-
if( is_wielding( weap ) || ( !get_wielded_item() && weap.is_null() ) ) {
2780-
auto cached_value = cached_info.find( "weapon_value" );
2781-
if( cached_value != cached_info.end() ) {
2782-
return cached_value->second;
2783-
}
2784-
}
2785-
double val_gun = gun_value( weap, ammo );
2786-
val_gun = val_gun /
2787-
5.0f; // This is an emergency patch to get melee and ranged in approximate parity, if you're looking at it in 2025 or later and it's still here... I'm sorry. Kill it with fire. Tear it all down, and rebuild a glorious castle from the ashes.
2788-
add_msg_debug( debugmode::DF_NPC_ITEMAI,
2789-
"<color_magenta>weapon_value</color>%s %s valued at <color_light_cyan>%1.2f as a ranged weapon</color>.",
2790-
disp_name( true ), weap.type->get_id().str(), val_gun );
2791-
double val_melee = melee_value( weap );
2792-
val_melee *=
2793-
val_melee; // Same emergency patch. Same purple prose descriptors, you already saw them above.
2794-
add_msg_debug( debugmode::DF_NPC_ITEMAI,
2795-
"%s %s valued at <color_light_cyan>%1.2f as a melee weapon</color>.", disp_name( true ),
2796-
weap.type->get_id().str(), val_melee );
2797-
const double more = std::max( val_gun, val_melee );
2798-
const double less = std::min( val_gun, val_melee );
2799-
2800-
// A small bonus for guns you can also use to hit stuff with (bayonets etc.)
2801-
const double my_val = more + ( less / 2.0 );
2802-
add_msg_debug( debugmode::DF_MELEE, "%s (%ld ammo) sum value: %.1f", weap.type->get_id().str(),
2803-
ammo, my_val );
2804-
if( is_wielding( weap ) || ( !get_wielded_item() && weap.is_null() ) ) {
2805-
cached_info.emplace( "weapon_value", my_val );
2806-
}
2807-
return my_val;
2808-
}
2809-
28102794
double Character::melee_value( const item &weap ) const
28112795
{
28122796
// start with average effective dps against a range of enemies

src/player_difficulty.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "character_martial_arts.h"
1212
#include "inventory.h"
1313
#include "item.h"
14+
#include "itype.h"
1415
#include "mutation.h"
1516
#include "npc_opinion.h"
1617
#include "options.h"
@@ -30,6 +31,9 @@ static const damage_type_id damage_bash( "bash" );
3031
static const itype_id itype_bat( "bat" );
3132
static const itype_id itype_knife_combat( "knife_combat" );
3233
static const itype_id itype_machete( "machete" );
34+
static const itype_id itype_mossberg_500( "mossberg_500" );
35+
static const itype_id itype_ruger_1022( "ruger_1022" );
36+
static const itype_id itype_swbodyguard( "swbodyguard" );
3337

3438
static const profession_id profession_unemployed( "unemployed" );
3539

@@ -205,14 +209,23 @@ double player_difficulty::calc_dps_value( const Character &u )
205209
item early_cutting = item( itype_machete );
206210
item early_bashing = item( itype_bat );
207211

208-
double baseline = std::max( u.weapon_value( early_piercing ),
209-
u.weapon_value( early_cutting ) );
210-
baseline = std::max( baseline, u.weapon_value( early_bashing ) );
212+
// and some firearms, based on availability.
213+
item most_common_pistol = item( itype_swbodyguard );
214+
item most_common_rifle = item( itype_ruger_1022 );
215+
item most_common_shotgun = item( itype_mossberg_500 );
216+
217+
std::vector<item> weapons_to_test = {early_piercing, early_cutting, early_bashing, most_common_pistol, most_common_rifle, most_common_shotgun};
218+
double baseline = 0.0;
219+
220+
for( item &weapon : weapons_to_test ) {
221+
const double new_weapon_value = u.evaluate_weapon( weapon, true );
222+
baseline = std::max( baseline, new_weapon_value );
223+
}
211224

212225
// check any other items the character has on them
213226
if( u.prof ) {
214227
for( const item &i : u.prof->items( true, std::vector<trait_id>() ) ) {
215-
baseline = std::max( baseline, u.weapon_value( i ) );
228+
baseline = std::max( baseline, u.evaluate_weapon( i, true ) );
216229
}
217230
}
218231

0 commit comments

Comments
 (0)