From 8a944ce377fdb4736432bcc44ea9175d4b289208 Mon Sep 17 00:00:00 2001 From: BevapDin Date: Sat, 21 Dec 2019 18:39:52 +0100 Subject: [PATCH] Actually read JSON object member instead of only checking their existence. This ensures the member type is checked and reported if it does not fit the expected type. It also means `"foo": false` is properly recognized as such (instead of being interpreted the same as `"foo": true`). --- src/condition.cpp | 2 +- src/flag.cpp | 2 +- src/mission_util.cpp | 2 +- src/npctalk.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/condition.cpp b/src/condition.cpp index 8a196f95fb223..6a1de477b1789 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -1030,7 +1030,7 @@ conditional_t::conditional_t( const JsonObject &jo ) set_npc_role_nearby( jo ); } else if( jo.has_int( "npc_allies" ) ) { set_npc_allies( jo ); - } else if( jo.has_int( "npc_service" ) ) { + } else if( jo.get_bool( "npc_service", false ) ) { set_npc_available(); } else if( jo.has_int( "u_has_cash" ) ) { set_u_has_cash( jo ); diff --git a/src/flag.cpp b/src/flag.cpp index a39b617ad5e21..611ccb45aac55 100644 --- a/src/flag.cpp +++ b/src/flag.cpp @@ -28,7 +28,7 @@ void json_flag::load( const JsonObject &jo ) // FIXME: most flags have a "context" field that isn't used for anything // Test for it here to avoid errors about unvisited members - jo.has_member( "context" ); + jo.get_member( "context" ); } void json_flag::check_consistency() diff --git a/src/mission_util.cpp b/src/mission_util.cpp index 105ec3306d78d..e06166ec02b3a 100644 --- a/src/mission_util.cpp +++ b/src/mission_util.cpp @@ -365,7 +365,7 @@ mission_target_params mission_util::parse_mission_om_target( const JsonObject &j if( jo.has_string( "om_terrain_match_type" ) ) { p.overmap_terrain_match_type = jo.get_enum_value( "om_terrain_match_type" ); } - if( jo.has_bool( "origin_npc" ) ) { + if( jo.get_bool( "origin_npc", false ) ) { p.origin_u = false; } if( jo.has_string( "om_terrain_replace" ) ) { diff --git a/src/npctalk.cpp b/src/npctalk.cpp index 454c47dd500a3..ddfdd371d5264 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -2886,11 +2886,11 @@ dynamic_line_t::dynamic_line_t( const JsonObject &jo ) } return all_lines; }; - } else if( jo.has_member( "give_hint" ) ) { + } else if( jo.get_bool( "give_hint", false ) ) { function = [&]( const dialogue & ) { return get_hint(); }; - } else if( jo.has_member( "use_reason" ) ) { + } else if( jo.get_bool( "use_reason", false ) ) { function = [&]( const dialogue & d ) { std::string tmp = d.reason; d.reason.clear();