Skip to content

Commit

Permalink
Rewrite how NPCs evaluate threats. (CleverRaven#69537)
Browse files Browse the repository at this point in the history
* refactor and fix evaluate_enemy

* Cleanup, simplify until maths working

* add estimate_armour function

refactor/rewrite... nearly... complete

* add perception and pain effect

* asstile

* Update npcmove.cpp

* Add some more debug messages for testing

* simplify calc by tallying allies vs enemies

Uncover still more issues in the process

* this might work now

* logic and formatting

1. add colour to messages for easier reading
2. adjust error in perception calculation
3. running away NPCs are valued lower.

* Colourize debug log

because why not

* fix another math error

monster HP was backwards.

Also updates more colours.

* math errors math errors aaaah

melee and ranged weapons were not in even vague parity on evaluation.

Did not fix that, but did make it tolerable for now.

* scale ally threat same as enemy threat

missed a scalar

* Add a bleeding assessment to threat.
  • Loading branch information
I-am-Erk authored Nov 21, 2023
1 parent f7a39d3 commit 8e02002
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ std::string filter_name( debug_filter value )
case DF_MONSTER: return "DF_MONSTER";
case DF_MUTATION: return "DF_MUTATION";
case DF_NPC: return "DF_NPC";
case DF_NPC_COMBATAI: return "DF_NPC_COMBATAI";
case DF_NPC_ITEMAI: return "DF_NPC_ITEMAI";
case DF_OVERMAP: return "DF_OVERMAP";
case DF_RADIO: return "DF_RADIO";
Expand Down
3 changes: 2 additions & 1 deletion src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ enum debug_filter : int {
DF_MONMOVE, // movement/pathfinding-related
DF_MONSTER, // monster generic
DF_MUTATION, // mutation/purification logic
DF_NPC, // npc generic
DF_NPC, // npc generic, less verbose comments
DF_NPC_COMBATAI, // npc combat and danger assessment logic
DF_NPC_ITEMAI, // npc weapon/item logic - weapon choices, decision to reload, etc.
DF_OVERMAP, // overmap generic
DF_RADIO, // radio stuff
Expand Down
14 changes: 12 additions & 2 deletions src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2761,8 +2761,18 @@ double Character::weapon_value( const item &weap, int ammo ) const
return cached_value->second;
}
}
const double val_gun = gun_value( weap, ammo );
const double val_melee = melee_value( weap );
double val_gun = gun_value( weap, ammo );
val_gun = val_gun /
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.
add_msg_debug( debugmode::DF_NPC_ITEMAI,
"<color_magenta>weapon_value</color>%s %s valued at <color_light_cyan>%1.2f as a ranged weapon</color>.",
disp_name( true ), weap.type->get_id().str(), val_gun );
double val_melee = melee_value( weap );
val_melee *=
val_melee; // Same emergency patch. Same purple prose descriptors, you already saw them above.
add_msg_debug( debugmode::DF_NPC_ITEMAI,
"%s %s valued at <color_light_cyan>%1.2f as a melee weapon</color>.", disp_name( true ),
weap.type->get_id().str(), val_melee );
const double more = std::max( val_gun, val_melee );
const double less = std::min( val_gun, val_melee );

Expand Down
7 changes: 5 additions & 2 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,10 @@ class npc : public Character
bool invoke_item( item *used, const std::string &method ) override;
bool invoke_item( item * ) override;

/** rates how dangerous a target is from 0 (harmless) to 1 (max danger) */
float evaluate_enemy( const Creature &target ) const;
/** rates how dangerous a target is */
float evaluate_monster( const monster &target, int dist ) const;
float evaluate_character( const Character &candidate, bool my_gun, bool enemy ) const;
float evaluate_self( bool my_gun ) const;

void assess_danger();
bool is_safe() const;
Expand All @@ -1098,6 +1100,7 @@ class npc : public Character
// picks among melee, guns, spells, etc.
// updates the ai_cache
void evaluate_best_weapon( const Creature *target );
float estimate_armour( const Character &candidate ) const;

static std::array<std::pair<std::string, overmap_location_str_id>, npc_need::num_needs> need_data;

Expand Down
Loading

0 comments on commit 8e02002

Please sign in to comment.