diff --git a/doc/EFFECT_ON_CONDITION.md b/doc/EFFECT_ON_CONDITION.md index 9784df93843d3..8d19d3d181e65 100644 --- a/doc/EFFECT_ON_CONDITION.md +++ b/doc/EFFECT_ON_CONDITION.md @@ -1031,6 +1031,37 @@ Check the north terrain or furniture has `TRANSPARENT` flag. }, ``` +### `map_terrain_id`, `map_furniture_id` +- type: string or [variable object](##variable-object) +- return true if the terrain or furniture has specific id +- `loc` will specify location of terrain or furniture (**mandatory**) + +#### Valid talkers: + +No talker is needed. + +#### Examples +Runs a query, allowing you to pick specific tile around. When picked, stores coordinates of this tile in `check_terrain` variable, and then check is it a `t_grass`. If yes, `effect` is run, otherwise `false_effect` is run +```json +{ + "type": "effect_on_condition", + "id": "EOC_TEST_QUERY", + "condition": { + "and": [ + { + "u_query_tile": "line_of_sight", + "target_var": { "context_val": "check_terrain" }, + "message": "Check what terrain it is", + "range": 10 + }, + { "map_terrain_id": "t_grass", "loc": { "context_val": "check_terrain" } } + ] + }, + "effect": [ { "u_message": "it is a grass" } ], + "false_effect": [ { "u_message": "it is NOT a grass" } ] +} +``` + ### `map_in_city` - type: location string or [variable object](##variable-object) - return true if the location is in a city diff --git a/src/condition.cpp b/src/condition.cpp index 17bd44358e8ae..3264f978aba5c 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -1589,6 +1589,26 @@ conditional_t::func f_map_ter_furn_with_flag( const JsonObject &jo, std::string_ }; } +conditional_t::func f_map_ter_furn_id( const JsonObject &jo, std::string_view member ) +{ + str_or_var furn_type = get_str_or_var( jo.get_member( member ), member, true ); + var_info loc_var = read_var_info( jo.get_object( "loc" ) ); + bool terrain = true; + if( member == "map_terrain_id" ) { + terrain = true; + } else if( member == "map_furniture_id" ) { + terrain = false; + } + return [terrain, furn_type, loc_var]( dialogue const & d ) { + tripoint loc = get_map().getlocal( get_tripoint_from_var( loc_var, d ) ); + if( terrain ) { + return get_map().ter( loc ) == ter_id( furn_type.evaluate( d ) ); + } else { + return get_map().ter( loc ) == ter_id( furn_type.evaluate( d ) ); + } + }; +} + conditional_t::func f_map_in_city( const JsonObject &jo, std::string_view member ) { str_or_var target = get_str_or_var( jo.get_member( member ), member, true ); @@ -2400,6 +2420,8 @@ parsers = { {"is_weather", jarg::member, &conditional_fun::f_is_weather }, {"map_terrain_with_flag", jarg::member, &conditional_fun::f_map_ter_furn_with_flag }, {"map_furniture_with_flag", jarg::member, &conditional_fun::f_map_ter_furn_with_flag }, + {"map_terrain_id", jarg::member, &conditional_fun::f_map_ter_furn_id }, + {"map_furniture_id", jarg::member, &conditional_fun::f_map_ter_furn_id }, {"map_in_city", jarg::member, &conditional_fun::f_map_in_city }, {"mod_is_loaded", jarg::member, &conditional_fun::f_mod_is_loaded }, {"u_has_faction_trust", jarg::member | jarg::array, &conditional_fun::f_has_faction_trust },