Skip to content

Commit

Permalink
Monster vision enchantment and evaluation (CleverRaven#75753)
Browse files Browse the repository at this point in the history
* Add enchantment to affect monster vision

* improve vision_range_eval() to evaluate monster sight range also
  • Loading branch information
GuardianDll authored Aug 18, 2024
1 parent 7db405a commit 56dd3fc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/MAGIC.md
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ Character status value | Description
`ARMOR_HEAT` |
`ARMOR_STAB` |
`REGEN_HP` | Affects the rate the monster recovers hp.
`VISION_RANGE` | Affects monster vision range, both day and night one.
`SPEED` | Affects the base speed of the monster.
`LUMINATION` | Affects monster luminance

Expand Down
2 changes: 1 addition & 1 deletion doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ _some functions support array arguments or kwargs, denoted with square brackets
| npc_value() ||| u, n | Return NPC value toward opposite talker. <br/><br/>Example:<br/> `{ "math": [ "n_npc_value()", "+=", "2" ] }`|
| vitamin(`s`/`v`) ||| u, n | Return or set the characters vitamin level.<br/>Argument is vitamin ID.<br/><br/>Example:<br/>`{ "math": [ "u_vitamin('mutagen')", "=", "0" ] }`|
| warmth(`s`/`v`) ||| u, n | Return the characters warmth on a body part.<br/>Argument is bodypart ID.<br/><br/>Example:<br/> The value displayed in-game is calculated as follows.<br/> `"{ "math": [ "u_warmth_in_game", "=", "(u_warmth('torso') / 100) * 2 - 100"] }`|
| vision_range() ||| u, n | Return the character's visual range, adjusted by their mutations, effects, and other issues.<br/><br/>Example:<br/> `"{ "math": [ "u_vision_range", "<", "30"] }`|
| vision_range() ||| u, n | Return the character's or monsters visual range, adjusted by their mutations, effects, and other issues.<br/><br/>Example:<br/> `"{ "math": [ "n_vision_range()", "<", "30"] }`|
| weather(`s`) ||| N/A<br/>(global) | Return or set a weather aspect<br/><br/>Aspect must be one of:<br/>`temperature` (in Kelvin),<br/>`humidity` (as percentage),<br/>`pressure` (in millibar),<br/>`windpower` (in mph).<br/>`precipitation` (in mm / h) either 0.5 (very_light ), 1.5 (light), or 3 (heavy). Read only.<br/><br/>Temperature conversion functions are available: `celsius()`, `fahrenheit()`, `from_celsius()`, and `from_fahrenheit()`.<br/><br/>Examples:<br/>`{ "math": [ "weather('temperature')", "<", "from_fahrenheit( 33 )" ] }`<br/>`{ "math": [ "fahrenheit( weather('temperature') )", "==", "21" ] }`|
| damage_level() ||| u, n | Return the damage level of the talker, which must be an item.<br/><br/>Example:<br/>`"condition": { "math": [ "n_damage_level()", "<", "1" ] }`|
| climate_control_str_heat() ||| u, n | return amount of heat climate control that character currently has (character feels better in warm places with it), in warmth points; default 0, affected by CLIMATE_CONTROL_HEAT enchantment.<br/><br/>Example:<br/>`"condition": { "math": [ "u_climate_control_str_heat()", "<", "0" ] }`|
Expand Down
3 changes: 3 additions & 0 deletions src/magic_enchantment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace io
case enchant_vals::mod::ATTACK_NOISE: return "ATTACK_NOISE";
case enchant_vals::mod::SHOUT_NOISE: return "SHOUT_NOISE";
case enchant_vals::mod::FOOTSTEP_NOISE: return "FOOTSTEP_NOISE";
case enchant_vals::mod::VISION_RANGE: return "VISION_RANGE";
case enchant_vals::mod::SIGHT_RANGE_ELECTRIC: return "SIGHT_RANGE_ELECTRIC";
case enchant_vals::mod::MOTION_VISION_RANGE: return "MOTION_VISION_RANGE";
case enchant_vals::mod::SIGHT_RANGE_FAE: return "SIGHT_RANGE_FAE";
Expand Down Expand Up @@ -324,6 +325,7 @@ bool enchantment::is_monster_relevant() const
pair_values.first == enchant_vals::mod::ARMOR_HEAT ||
pair_values.first == enchant_vals::mod::ARMOR_STAB ||
pair_values.first == enchant_vals::mod::REGEN_HP ||
pair_values.first == enchant_vals::mod::VISION_RANGE ||
pair_values.first == enchant_vals::mod::SPEED ||
pair_values.first == enchant_vals::mod::LUMINATION ) {
return true;
Expand All @@ -344,6 +346,7 @@ bool enchantment::is_monster_relevant() const
pair_values.first == enchant_vals::mod::ARMOR_HEAT ||
pair_values.first == enchant_vals::mod::ARMOR_STAB ||
pair_values.first == enchant_vals::mod::REGEN_HP ||
pair_values.first == enchant_vals::mod::VISION_RANGE ||
pair_values.first == enchant_vals::mod::SPEED ||
pair_values.first == enchant_vals::mod::LUMINATION ) {
return true;
Expand Down
1 change: 1 addition & 0 deletions src/magic_enchantment.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ enum class mod : int {
ATTACK_NOISE,
SHOUT_NOISE,
FOOTSTEP_NOISE,
VISION_RANGE,
SIGHT_RANGE_ELECTRIC,
MOTION_VISION_RANGE,
SIGHT_RANGE_FAE,
Expand Down
4 changes: 4 additions & 0 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,10 @@ std::function<double( dialogue & )> vision_range_eval( char scope,
talker const *const actor = d.actor( beta );
if( Character const *const chr = actor->get_character(); chr != nullptr ) {
return chr->unimpaired_range();
} else if( monster const *const mon = actor->get_monster(); mon != nullptr ) {
map &here = get_map();
tripoint_bub_ms tripoint = get_map().bub_from_abs( mon->get_location() );
return mon->sight_range( here.ambient_light_at( tripoint ) );
}
debugmsg( "Tried to access vision range of a non-Character talker" );
return 0;
Expand Down
6 changes: 4 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,13 +1385,15 @@ int monster::sight_range( const float light_level ) const
}
static const float default_daylight = default_daylight_level();
if( light_level == 0 ) {
return type->vision_night;
return calculate_by_enchantment( type->vision_night, enchant_vals::mod::VISION_RANGE, true );
} else if( light_level >= default_daylight ) {
return type->vision_day;
return calculate_by_enchantment( type->vision_day, enchant_vals::mod::VISION_RANGE, true );
}
int range = ( light_level * type->vision_day + ( default_daylight - light_level ) *
type->vision_night ) / default_daylight;

range = calculate_by_enchantment( range, enchant_vals::mod::VISION_RANGE, true );

return range;
}

Expand Down

0 comments on commit 56dd3fc

Please sign in to comment.