Skip to content

Commit

Permalink
eoc: try to fix f_query_tile
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei8l committed Nov 8, 2024
1 parent c0ed85d commit 63ef4d6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 36 deletions.
34 changes: 17 additions & 17 deletions data/json/effects_on_condition/example_eocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@
"id": "EOC_query_tile_test_anywhere",
"effect": [
{
"if": { "u_query_tile": "anywhere", "target_var": { "context_val": "pos" }, "message": "Select point" },
"then": { "u_message": "<context_val:pos>" },
"if": { "u_query_tile": "anywhere", "target_var": { "global_val": "pos" }, "message": "Select point" },
"then": { "u_message": "<global_val:pos>" },
"else": { "u_message": "Canceled" }
}
]
Expand All @@ -342,8 +342,8 @@
"id": "EOC_query_tile_test_line_of_sight",
"effect": [
{
"if": { "u_query_tile": "line_of_sight", "target_var": { "context_val": "pos" }, "message": "Select point", "range": 10 },
"then": { "u_message": "<context_val:pos>" },
"if": { "u_query_tile": "line_of_sight", "target_var": { "global_val": "pos" }, "message": "Select point", "range": 10 },
"then": { "u_message": "<global_val:pos>" },
"else": { "u_message": "Canceled" }
}
]
Expand All @@ -353,8 +353,8 @@
"id": "EOC_query_tile_test_around",
"effect": [
{
"if": { "u_query_tile": "around", "target_var": { "context_val": "pos" }, "message": "Choose direction" },
"then": { "u_message": "<context_val:pos>" },
"if": { "u_query_tile": "around", "target_var": { "global_val": "pos" }, "message": "Choose direction" },
"then": { "u_message": "<global_val:pos>" },
"else": { "u_message": "Canceled" }
}
]
Expand All @@ -381,20 +381,20 @@
"id": "EOC_can_see_location_test",
"effect": [
{
"if": { "u_query_tile": "anywhere", "target_var": { "context_val": "pos" }, "message": "Select point" },
"if": { "u_query_tile": "anywhere", "target_var": { "global_val": "pos" }, "message": "Select point" },
"then": [
{
"if": { "u_can_see_location": { "context_val": "pos" } },
"then": { "u_message": "You can see <context_val:pos>." },
"else": { "u_message": "You can't see <context_val:pos>." }
"if": { "u_can_see_location": { "global_val": "pos" } },
"then": { "u_message": "You can see <global_val:pos>." },
"else": { "u_message": "You can't see <global_val:pos>." }
},
{
"u_run_npc_eocs": [
{
"id": "EOC_can_see_location_test_nest",
"condition": { "u_can_see_location": { "context_val": "pos" } },
"effect": { "message": "<u_name> can see <context_val:pos>." },
"false_effect": { "message": "<u_name> can't see <context_val:pos>." }
"condition": { "u_can_see_location": { "global_val": "pos" } },
"effect": { "message": "<u_name> can see <global_val:pos>." },
"false_effect": { "message": "<u_name> can't see <global_val:pos>." }
}
],
"local": true
Expand Down Expand Up @@ -438,10 +438,10 @@
"id": "EOC_teleport_test_other",
"effect": [
{
"if": { "u_query_tile": "anywhere", "target_var": { "context_val": "loc" }, "message": "Select point" },
"if": { "u_query_tile": "anywhere", "target_var": { "global_val": "loc" }, "message": "Select point" },
"then": {
"run_eoc_with": { "id": "EOC_teleport_test_other_do", "effect": { "npc_teleport": { "global_val": "teleport_test_pos" } } },
"beta_loc": { "context_val": "loc" },
"beta_loc": { "global_val": "loc" },
"false_eocs": { "id": "EOC_teleport_test_other_do_fail_msg", "effect": { "message": "Please select a creature." } }
},
"else": { "u_message": "Canceled" }
Expand All @@ -467,13 +467,13 @@
"effect": [
{ "u_set_talker": { "global_val": "player_id" } },
{
"if": { "u_query_tile": "anywhere", "target_var": { "context_val": "loc" }, "message": "Select point" },
"if": { "u_query_tile": "anywhere", "target_var": { "global_val": "loc" }, "message": "Select point" },
"then": {
"run_eoc_with": {
"id": "_EOC_control_npc_do",
"effect": [ { "if": "npc_is_npc", "then": [ "follow", "take_control" ], "else": { "message": "Please select a NPC." } } ]
},
"beta_loc": { "context_val": "loc" },
"beta_loc": { "global_val": "loc" },
"false_eocs": { "id": "_EOC_control_npc_fail_msg", "effect": { "message": "Please select a NPC." } }
},
"else": { "u_message": "Canceled" }
Expand Down
4 changes: 2 additions & 2 deletions data/mods/Magiclysm/Spells/druid.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,11 +1115,11 @@
{
"if": {
"u_query_tile": "around",
"target_var": { "context_val": "druid_treeshape_location" },
"target_var": { "global_val": "druid_treeshape_location" },
"message": "Select nearby tree"
},
"then": {
"if": { "map_terrain_with_flag": "TREE", "loc": { "context_val": "druid_treeshape_location" } },
"if": { "map_terrain_with_flag": "TREE", "loc": { "global_val": "druid_treeshape_location" } },
"then": [
{
"u_message": "The wood of the tree grows and forms as you cast the spell and when it ends, there is a log lying on the ground, entirely covered in bark but otherwise straight and ready to be used in other projects.",
Expand Down
8 changes: 4 additions & 4 deletions data/mods/Sky_Island/EOCs.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,15 +932,15 @@
{
"if": {
"u_query_tile": "around",
"target_var": { "context_val": "warped_pond_location" },
"target_var": { "global_val": "warped_pond_location" },
"message": "Select nearby water source"
},
"then": {
"if": {
"or": [
{ "map_terrain_with_flag": "LIQUID", "loc": { "context_val": "warped_pond_location" } },
{ "map_terrain_id": "t_wooden_well", "loc": { "context_val": "warped_pond_location" } },
{ "map_terrain_id": "t_water_pump", "loc": { "context_val": "warped_pond_location" } }
{ "map_terrain_with_flag": "LIQUID", "loc": { "global_val": "warped_pond_location" } },
{ "map_terrain_id": "t_wooden_well", "loc": { "global_val": "warped_pond_location" } },
{ "map_terrain_id": "t_water_pump", "loc": { "global_val": "warped_pond_location" } }
]
},
"then": {
Expand Down
12 changes: 6 additions & 6 deletions data/mods/Xedra_Evolved/mutations/paraclesians/arvore_eocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
{
"if": {
"u_query_tile": "line_of_sight",
"target_var": { "context_val": "arvore_walk_wilds_location" },
"target_var": { "global_val": "arvore_walk_wilds_location" },
"range": {
"math": [ "( ( (u_spell_level('arvore_traverse_the_wilds') * 1.5) + 5) * (scaling_factor(u_val('perception') ) ) )" ]
},
Expand All @@ -264,12 +264,12 @@
"then": {
"if": {
"or": [
{ "map_terrain_with_flag": "TREE", "loc": { "context_val": "arvore_walk_wilds_location" } },
{ "map_terrain_with_flag": "YOUNG", "loc": { "context_val": "arvore_walk_wilds_location" } }
{ "map_terrain_with_flag": "TREE", "loc": { "global_val": "arvore_walk_wilds_location" } },
{ "map_terrain_with_flag": "YOUNG", "loc": { "global_val": "arvore_walk_wilds_location" } }
]
},
"then": [
{ "u_teleport": { "context_val": "arvore_walk_wilds_location" }, "force": true },
{ "u_teleport": { "global_val": "arvore_walk_wilds_location" }, "force": true },
{ "u_message": "You step into the tree and step out of another one nearby.", "type": "neutral" }
],
"else": { "u_message": "You must select a tree to step to." }
Expand Down Expand Up @@ -605,11 +605,11 @@
{
"if": {
"u_query_tile": "around",
"target_var": { "context_val": "arvore_treesung_location" },
"target_var": { "global_val": "arvore_treesung_location" },
"message": "Select nearby tree"
},
"then": {
"if": { "map_terrain_with_flag": "TREE", "loc": { "context_val": "arvore_treesung_location" } },
"if": { "map_terrain_with_flag": "TREE", "loc": { "global_val": "arvore_treesung_location" } },
"then": { "u_assign_activity": "ACT_ARVORE_TREESINGING", "duration": "45 minutes" },
"else": { "u_message": "You must be near a tree to treesing to it." }
},
Expand Down
6 changes: 3 additions & 3 deletions data/mods/Xedra_Evolved/mutations/vampire_trait_eocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1232,14 +1232,14 @@
{
"if": {
"u_query_tile": "around",
"target_var": { "context_val": "vampire_mist_door_or_window_seep" },
"target_var": { "global_val": "vampire_mist_door_or_window_seep" },
"message": "Select door or window, then target the space beyond it."
},
"then": {
"if": { "map_terrain_with_flag": "DOOR", "loc": { "context_val": "vampire_mist_door_or_window_seep" } },
"if": { "map_terrain_with_flag": "DOOR", "loc": { "global_val": "vampire_mist_door_or_window_seep" } },
"then": { "u_cast_spell": { "id": "vampire_mist_form_pass_through_doors_and_windows_teleport" }, "targeted": true },
"else": {
"if": { "map_terrain_with_flag": "WINDOW", "loc": { "context_val": "vampire_mist_door_or_window_seep" } },
"if": { "map_terrain_with_flag": "WINDOW", "loc": { "global_val": "vampire_mist_door_or_window_seep" } },
"then": { "u_cast_spell": { "id": "vampire_mist_form_pass_through_doors_and_windows_teleport" }, "targeted": true },
"else": { "u_message": "You must be near a door or window to seep through." }
}
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,7 @@ class Character : public Creature, public visitable
// Items currently being hauled
std::vector<item_location> haul_list;

tripoint_rel_ms view_offset;
mutable tripoint_rel_ms view_offset;

player_activity stashed_outbounds_activity;
player_activity stashed_outbounds_backlog;
Expand Down
31 changes: 28 additions & 3 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,27 @@ void write_var_value( var_type type, const std::string &name, dialogue *d,
}
}

void write_var_value( var_type type, const std::string &name, const_dialogue const &d,
const std::string &value )
{
switch( type ) {
case var_type::global:
get_globals().set_global_value( name, value );
break;
case var_type::context:
case var_type::var:
case var_type::u:
case var_type::npc:
case var_type::faction:
case var_type::party:
debugmsg( "Only global variables can be assigned from an eval function.\n%s", d.get_callstack() );
break;
default:
debugmsg( "Invalid type." );
break;
}
}

void write_var_value( var_type type, const std::string &name, dialogue *d,
double value )
{
Expand Down Expand Up @@ -1658,6 +1679,9 @@ conditional_t::func f_query_tile( const JsonObject &jo, std::string_view member,
{
std::string type = jo.get_string( member.data() );
var_info target_var = read_var_info( jo.get_object( "target_var" ) );
if( target_var.type != var_type::global ) {
jo.throw_error_at( "target_var", "Only global variables can be used as targets for u_query" ) ;
}
std::string message;
if( jo.has_member( "message" ) ) {
message = jo.get_string( "message" );
Expand All @@ -1671,7 +1695,6 @@ conditional_t::func f_query_tile( const JsonObject &jo, std::string_view member,
std::optional<tripoint> loc;
Character const *ch = d.const_actor( is_npc )->get_const_character();
if( ch && ch->as_avatar() ) {
avatar const *you = ch->as_avatar();
if( type == "anywhere" ) {
if( !message.empty() ) {
static_popup popup;
Expand All @@ -1687,7 +1710,9 @@ conditional_t::func f_query_tile( const JsonObject &jo, std::string_view member,
popup.on_top( true );
popup.message( "%s", message );
}
target_handler::trajectory traj = target_handler::mode_select_only( *you, range.evaluate( d ) );
avatar dummy;
dummy.set_location( get_avatar().get_location() );
target_handler::trajectory traj = target_handler::mode_select_only( dummy, range.evaluate( d ) );
if( !traj.empty() ) {
loc = traj.back().raw();
}
Expand All @@ -1704,7 +1729,7 @@ conditional_t::func f_query_tile( const JsonObject &jo, std::string_view member,
}
if( loc.has_value() ) {
tripoint_abs_ms pos_global = get_map().getglobal( *loc );
write_var_value( target_var.type, target_var.name, &d,
write_var_value( target_var.type, target_var.name, d,
pos_global.to_string() );
}
return loc.has_value();
Expand Down
2 changes: 2 additions & 0 deletions src/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ void write_var_value( var_type type, const std::string &name, dialogue *d,
const std::string &value, int call_depth = 0 );
void write_var_value( var_type type, const std::string &name, dialogue *d,
double value );
void write_var_value( var_type type, const std::string &name, const_dialogue const &d,
const std::string &value );
std::string get_talk_varname( const JsonObject &jo, std::string_view member,
bool check_value, dbl_or_var &default_val );
std::string get_talk_var_basename( const JsonObject &jo, std::string_view member,
Expand Down

0 comments on commit 63ef4d6

Please sign in to comment.