Skip to content

Commit

Permalink
Merge pull request #79307 from ShnitzelX2/efiles-map-cache-fix
Browse files Browse the repository at this point in the history
fix `map cache` item/EOC
  • Loading branch information
Maleclypse authored Jan 26, 2025
2 parents f0f8b43 + 94b7109 commit aea8979
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 73 deletions.
20 changes: 8 additions & 12 deletions data/json/effects_on_condition/computer_eocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,21 @@
"type": "effect_on_condition",
"id": "EOC_CHECK_MAP_CACHE",
"//": "todo: make it not reveal fungal towers and such? would require edits in reveal_map code, to accept blacklist of locations?",
"condition": { "or": [ { "compare_string": [ { "npc_val": "map_cache" }, "has", "lack", "read" ] } ] },
"false_effect": [ { "npc_add_var": "map_cache", "possible_values": [ "has", "lack" ] }, { "run_eocs": "EOC_CHECK_MAP_CACHE" } ],
"effect": [
{
"if": { "compare_string": [ "read", { "npc_val": "map_cache" } ] },
"then": [ { "u_message": "You already noted everything this map cache can offer." } ]
},
{
"if": { "compare_string": [ "has", { "npc_val": "map_cache" } ] },
"then": [
{ "location_variable_adjust": { "npc_val": "spawn_location_omt" }, "z_adjust": 0, "z_override": true },
"then": [ { "u_message": "You already noted everything this map cache can offer." } ],
"else": [
{
"location_variable_adjust": { "npc_val": "spawn_location_omt" },
"z_adjust": 0,
"z_override": true,
"overmap_tile": true
},
{ "reveal_map": { "npc_val": "spawn_location_omt" }, "radius": { "math": [ "rng(11, 36)" ] } },
{ "npc_add_var": "map_cache", "value": "read" },
{ "u_message": "You found some useful data in the map cache and noted it.", "type": "good" }
]
},
{
"if": { "compare_string": [ "lack", { "npc_val": "map_cache" } ] },
"then": [ { "u_message": "Whoever used this device didn't ever open their map application. Worthless." } ]
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion data/json/items/software.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"name": "map cache",
"description": "Information about nearby locations stored from previous use.",
"ememory_size": "32 MB",
"use_action": { "type": "effect_on_conditions", "effect_on_conditions": [ "EOC_CHECK_MAP_CACHE" ] }
"use_action": { "type": "effect_on_conditions", "effect_on_conditions": [ "EOC_CHECK_MAP_CACHE" ] },
"extend": { "flags": [ "PRESERVE_SPAWN_OMT" ] }
},
{
"abstract": "abstract_efile_recipes",
Expand Down
12 changes: 1 addition & 11 deletions data/json/items/tool/electronics.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,17 +760,7 @@
},
{ "type": "link_up", "cable_length": 3, "charge_rate": "20 W" }
],
"flags": [
"WATCH",
"ALARMCLOCK",
"USE_UPS",
"NO_UNLOAD",
"NO_RELOAD",
"WATER_BREAK",
"CALORIES_INTAKE",
"ELECTRONIC",
"PRESERVE_SPAWN_OMT"
],
"flags": [ "WATCH", "ALARMCLOCK", "USE_UPS", "NO_UNLOAD", "NO_RELOAD", "WATER_BREAK", "CALORIES_INTAKE", "ELECTRONIC" ],
"pocket_data": [
{ "pocket_type": "MAGAZINE", "rigid": true, "ammo_restriction": { "battery": 56 } },
{
Expand Down
39 changes: 30 additions & 9 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,42 @@ str_translation_or_var get_str_translation_or_var(
return ret_val;
}

tripoint_abs_ms get_tripoint_from_var( std::optional<var_info> var, const_dialogue const &d,
bool is_npc )
template<typename T>
T convert_tripoint_from_var( std::optional<var_info> &var, const_dialogue const &d,
bool is_npc )
{
if( var.has_value() ) {
std::string value = read_var_value( var.value(), d );
if( !value.empty() ) {
return tripoint_abs_ms( tripoint::from_string( value ) );
return T( tripoint::from_string( value ) );
}
}
if( !d.has_actor( is_npc ) ) {
debugmsg( "Tried to access location of invalid %s talker. %s", is_npc ? "beta" : "alpha",
d.get_callstack() );
return tripoint_abs_ms::invalid;
return T::invalid;
}
return T::invalid;
}

tripoint_abs_ms get_tripoint_ms_from_var( std::optional<var_info> var, const_dialogue const &d,
bool is_npc )
{
tripoint_abs_ms pt = convert_tripoint_from_var<tripoint_abs_ms>( var, d, is_npc );
if( pt.is_invalid() ) {
return get_map().get_abs( d.const_actor( is_npc )->pos_bub() );
}
return pt;
}

tripoint_abs_omt get_tripoint_omt_from_var( std::optional<var_info> var, const_dialogue const &d,
bool is_npc )
{
tripoint_abs_omt pt = convert_tripoint_from_var<tripoint_abs_omt>( var, d, is_npc );
if( pt.is_invalid() ) {
return coords::project_to<coords::omt>( get_map().get_abs( d.const_actor( is_npc )->pos_bub() ) );
}
return get_map().get_abs( d.const_actor( is_npc )->pos_bub() );
return pt;
}

template<class T>
Expand Down Expand Up @@ -1691,8 +1712,8 @@ conditional_t::func f_line_of_sight( const JsonObject &jo, std::string_view memb
with_fields = jo.get_bool( "with_fields" );
}
return [range, loc_var_1, loc_var_2, with_fields]( const_dialogue const & d ) {
tripoint_bub_ms loc_1 = get_map().get_bub( get_tripoint_from_var( loc_var_1, d, false ) );
tripoint_bub_ms loc_2 = get_map().get_bub( get_tripoint_from_var( loc_var_2, d, false ) );
tripoint_bub_ms loc_1 = get_map().get_bub( get_tripoint_ms_from_var( loc_var_1, d, false ) );
tripoint_bub_ms loc_2 = get_map().get_bub( get_tripoint_ms_from_var( loc_var_2, d, false ) );

return get_map().sees( loc_1, loc_2, range.evaluate( d ), with_fields );
};
Expand Down Expand Up @@ -1804,7 +1825,7 @@ conditional_t::func f_map_ter_furn_with_flag( const JsonObject &jo, std::string_
terrain = false;
}
return [terrain, furn_type, loc_var]( const_dialogue const & d ) {
tripoint_bub_ms loc = get_map().get_bub( get_tripoint_from_var( loc_var, d, false ) );
tripoint_bub_ms loc = get_map().get_bub( get_tripoint_ms_from_var( loc_var, d, false ) );
if( terrain ) {
return get_map().ter( loc )->has_flag( furn_type.evaluate( d ) );
} else {
Expand All @@ -1819,7 +1840,7 @@ conditional_t::func f_map_ter_furn_id( const JsonObject &jo, std::string_view me
var_info loc_var = read_var_info( jo.get_object( "loc" ) );

return [member, furn_type, loc_var]( const_dialogue const & d ) {
tripoint_bub_ms loc = get_map().get_bub( get_tripoint_from_var( loc_var, d, false ) );
tripoint_bub_ms loc = get_map().get_bub( get_tripoint_ms_from_var( loc_var, d, false ) );
if( member == "map_terrain_id" ) {
return get_map().ter( loc ) == ter_id( furn_type.evaluate( d ) );
} else if( member == "map_furniture_id" ) {
Expand Down
9 changes: 7 additions & 2 deletions src/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ duration_or_var get_duration_or_var( const JsonObject &jo, const std::string_vie
duration_or_var_part get_duration_or_var_part( const JsonValue &jv, const std::string_view &member,
bool required = true,
time_duration default_val = 0_seconds );
tripoint_abs_ms get_tripoint_from_var( std::optional<var_info> var, const_dialogue const &d,
bool is_npc );
template<typename T>
T convert_tripoint_from_var( std::optional<var_info> &var, const_dialogue const &d,
bool is_npc );
tripoint_abs_ms get_tripoint_ms_from_var( std::optional<var_info> var, const_dialogue const &d,
bool is_npc );
tripoint_abs_omt get_tripoint_omt_from_var( std::optional<var_info> var, const_dialogue const &d,
bool is_npc );
var_info read_var_info( const JsonObject &jo );
translation_var_info read_translation_var_info( const JsonObject &jo );
void write_var_value( var_type type, const std::string &name, dialogue *d,
Expand Down
11 changes: 11 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15798,6 +15798,17 @@ std::list<const item *> item::all_items_ptr() const
return all_items_internal;
}

std::list<item *> item::all_items_ptr()
{
std::list<item *> all_items_internal;
for( int i = static_cast<int>( pocket_type::CONTAINER );
i < static_cast<int>( pocket_type::LAST ); i++ ) {
std::list<item *> inserted{ all_items_top_recursive( static_cast<pocket_type>( i ) ) };
all_items_internal.insert( all_items_internal.end(), inserted.begin(), inserted.end() );
}
return all_items_internal;
}

std::list<const item *> item::all_items_ptr( pocket_type pk_type ) const
{
return all_items_top_recursive( pk_type );
Expand Down
6 changes: 4 additions & 2 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -3059,16 +3059,18 @@ class item : public visitable
aggregate_t aggregated_contents( int depth = 0, int maxdepth = 2 ) const;

/**
* returns a list of pointers to all items inside recursively
* returns a list of pointers to *all items in all pockets* inside recursively
* includes mods. used for item_location::unpack()
*/
std::list<const item *> all_items_ptr() const;
std::list<item *> all_items_ptr();
/** returns a list of pointers to all items inside recursively */
std::list<const item *> all_items_ptr( pocket_type pk_type ) const;
/** returns a list of pointers to all items inside recursively */
std::list<item *> all_items_ptr( pocket_type pk_type );

/** returns a list of pointers to all visible or remembered top-level items */
/** returns a list of pointers to all visible or remembered
* top-level items in standard pockets */
std::list<item *> all_known_contents();
std::list<const item *> all_known_contents() const;

Expand Down
10 changes: 4 additions & 6 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5264,16 +5264,14 @@ item &map::add_item( const tripoint_bub_ms &p, item new_item, int copies )
coords::project_to<coords::omt>( get_abs( p ) ) );
}

if( new_item.has_flag( json_flag_PRESERVE_SPAWN_OMT ) &&
!new_item.has_var( "spawn_location_omt" ) ) {
new_item.set_var( "spawn_location_omt", coords::project_to<coords::omt>( get_abs( p ) ) );
}
for( item *const it : new_item.all_items_top( pocket_type::CONTAINER ) ) {
std::list<item *> all_items = new_item.all_items_ptr();
all_items.emplace_back( &new_item );
for( item *it : all_items ) {
if( it->has_flag( json_flag_PRESERVE_SPAWN_OMT ) &&
!it->has_var( "spawn_location_omt" ) ) {
it->set_var( "spawn_location_omt", coords::project_to<coords::omt>( get_abs( p ) ) );
}
}
};

if( new_item.has_flag( flag_ACTIVATE_ON_PLACE ) ) {
new_item.activate();
Expand Down
6 changes: 3 additions & 3 deletions src/math_parser_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ diag_eval_dbl_f field_strength_eval( char scope, std::vector<diag_value> const &
map &here = get_map();
tripoint_abs_ms loc;
if( loc_var.has_value() ) {
loc = get_tripoint_from_var( loc_var, d, beta );
loc = get_tripoint_ms_from_var( loc_var, d, beta );
} else {
loc = d.const_actor( beta )->pos_abs();
}
Expand Down Expand Up @@ -788,7 +788,7 @@ diag_eval_dbl_f _characters_nearby_eval( char scope, std::vector<diag_value> con
allow_hallucinations_val ]( const_dialogue const & d ) {
tripoint_abs_ms loc;
if( loc_var.has_value() ) {
loc = get_tripoint_from_var( loc_var, d, beta );
loc = get_tripoint_ms_from_var( loc_var, d, beta );
} else {
loc = d.const_actor( beta )->pos_abs();
}
Expand Down Expand Up @@ -906,7 +906,7 @@ diag_eval_dbl_f _monsters_nearby_eval( char scope, std::vector<diag_value> const
f]( const_dialogue const & d ) {
tripoint_abs_ms loc;
if( loc_var.has_value() ) {
loc = get_tripoint_from_var( loc_var, d, beta );
loc = get_tripoint_ms_from_var( loc_var, d, beta );
} else {
loc = d.const_actor( beta )->pos_abs();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mission_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static std::optional<tripoint_abs_omt> find_or_create_om_terrain(
tripoint_abs_omt target_pos = tripoint_abs_omt::invalid;

if( params.target_var.has_value() ) {
return project_to<coords::omt>( get_tripoint_from_var( params.target_var.value(), d, false ) );
return project_to<coords::omt>( get_tripoint_ms_from_var( params.target_var.value(), d, false ) );
}

omt_find_params find_params;
Expand Down
Loading

0 comments on commit aea8979

Please sign in to comment.