Skip to content

Commit

Permalink
npctalk: make mapgen_update into dialogue effect
Browse files Browse the repository at this point in the history
Allow specifying mapgen_update as a dialogue effect.  Each mapgen_update
effect has a location description that uses the same format as
missiondef's assign_mission_target, and 1 or more mapgen_update_ids that
will be performed on that overmap position.
  • Loading branch information
mlangsdorf committed Apr 23, 2019
1 parent 54db27d commit f741141
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
25 changes: 25 additions & 0 deletions data/json/npcs/TALK_TEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,31 @@
"dynamic_line": "This is a test conversation that shouldn't appear in the game.",
"responses": [ { "text": "This is a basic test response.", "topic": "TALK_DONE" } ]
},
{
"type": "talk_topic",
"id": "TALK_TEST_SPEAKER_EFFECT_COMPOUND_SENTINEL_CONDITIONAL",
"dynamic_line": [ "This is an example of mapgen_update effect variations" ],
"responses": [
{
"text": "Please test some simple remote mapgen",
"topic": "TALK_DONE",
"effect": { "mapgen_update": "faction_wall_level_N_0", "origin_npc": true }
},
{
"text": "Please test mapgen_update multiples",
"topic": "TALK_DONE",
"effect": [
{ "mapgen_update": "faction_wall_level_E_0", "origin_npc": true, "offset_y": 1 },
{ "mapgen_update": "faction_wall_level_W_0", "origin_npc": true, "offset_x": 1 }
]
},
{
"text": "Please test mapgen_update linked",
"topic": "TALK_DONE",
"effect": { "mapgen_update": [ "faction_wall_level_S_1", "faction_wall_level_N_1" ], "origin_npc": true, "offset_y": -1 }
}
]
},
{
"type": "npc",
"id": "test_talker",
Expand Down
27 changes: 25 additions & 2 deletions doc/NPCs.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ set_npc_engagement_rule: rule_string | Sets the NPC follower AI rule for engagem
set_npc_aim_rule: rule_string | Sets the NPC follower AI rule for aiming speed to the value of `rule_string`.
npc_die | The NPC will die at the end of the conversation.

#### Map Updates
mapgen_update: mapgen_update_id_string<br/>mapgen_update: list of mapgen_update_id_strings, (optional assign_mission_target parameters) | With no other parameters, update's the the overmap tile at the player's current location with the changes described in mapgen_update_id (or for each mapgen_update_id in the list). The assign_mission_target parameters can be used to change the location of the overmap tile that gets updated. See doc/MISSIONS_JSON.md for assign_mission_target parameters and doc/MAPGEN.md for mapgen_update.
#### Deprecated

Effect | Description
Expand Down Expand Up @@ -565,11 +567,11 @@ Condition | Type | Description
"topic": "TALK_NONE",
"condition": {
"not": {
"npc_has_var": "has_met_PC", "type": "general", "context": "examples", "value": "true"
"npc_has_var": "has_met_PC", "type": "general", "context": "examples", "value": "yes"
}
},
"effect": {
"npc_set_var": "has_met_PC", "type": "general", "context": "examples", "value": "true" }
"npc_add_var": "has_met_PC", "type": "general", "context": "examples", "value": "yes" }
}
},
{
Expand Down Expand Up @@ -656,5 +658,26 @@ Condition | Type | Description
"trial": { "type": "LIE", "difficulty": 10, "mod": [ [ "TRUST", 3 ] ] },
"success": { "topic": "TALK_NONE" },
"failure": { "topic": "TALK_MISSION_FAILURE" }
},
{
"text": "Didn't you say you knew where the Vault was?",
"topic: "TALK_VAULT_INFO",
"condition": { "not": { "u_has_var": "asked_about_vault", "value": "yes", "type": "sentinel", "context": "old_guard_rep" } },
"effect": [
{ "u_add_var": "asked_about_vault", "value": "yes", "type": "sentinel", "context": "old_guard" },
{ "mapgen_update": "hulk_hairstyling", "om_terrain": "necropolis_a_13", "om_special": "Necropolis", "om_terrain_replace": "field", "z": 0 }
]
},
{
"text": "Why do zombies keep attacking every time I talk to you?"
"topic": "TALK_RUN_AWAY_MORE_ZOMBIES",
"condition": { "u_has_var": "even_more_zombies", "value": "yes", "type": "trigger", "context": "learning_experience" },
"effect": [
{ "mapgen_update": [ "even_more_zombies", "more zombies" ], "origin_npc": true },
{ "mapgen_update": "more zombies", "origin_npc": true, "offset_x": 1 },
{ "mapgen_update": "more zombies", "origin_npc": true, "offset_x": -1 },
{ "mapgen_update": "more zombies", "origin_npc": true, "offset_y": 1 },
{ "mapgen_update": "more zombies", "origin_npc": true, "offset_y": -1 }
]
}
```
2 changes: 1 addition & 1 deletion src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct talk_effect_fun_t {
void set_clear_npc_rule( const std::string &rule );
void set_npc_engagement_rule( const std::string &setting );
void set_npc_aim_rule( const std::string &setting );

void set_mapgen_update( JsonObject jo, const std::string &member );

void operator()( const dialogue &d ) const {
if( !function ) {
Expand Down
6 changes: 3 additions & 3 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8693,13 +8693,13 @@ mapgen_update_func add_mapgen_update_func( JsonObject &jo, bool &defer )
return update_function;
}

bool run_mapgen_update_func( const std::string update_mapgen_id, const tripoint &omt_pos,
mission *miss )
bool run_mapgen_update_func( const std::string &update_mapgen_id, const tripoint &omt_pos,
mission *miss, bool cancel_on_collision )
{
const auto update_function = update_mapgen.find( update_mapgen_id );

if( update_function == update_mapgen.end() || update_function->second.empty() ) {
return false;
}
return update_function->second[0]->update_map( omt_pos, 0, 0, miss, true );
return update_function->second[0]->update_map( omt_pos, 0, 0, miss, cancel_on_collision );
}
4 changes: 2 additions & 2 deletions src/mapgen_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void madd_field( map *m, int x, int y, field_id type, int density );
void place_stairs( map *m, oter_id terrain_type, mapgendata dat );

mapgen_update_func add_mapgen_update_func( JsonObject &jo, bool &defer );
bool run_mapgen_update_func( const std::string update_mapgen_id, const tripoint &omt_pos,
mission *miss = nullptr );
bool run_mapgen_update_func( const std::string &update_mapgen_id, const tripoint &omt_pos,
mission *miss = nullptr, bool cancel_on_collision = true );

#endif
28 changes: 28 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "json.h"
#include "line.h"
#include "map.h"
#include "mapgen_functions.h"
#include "map_selector.h"
#include "martialarts.h"
#include "messages.h"
#include "mission.h"
Expand Down Expand Up @@ -1784,6 +1786,30 @@ void talk_effect_fun_t::set_npc_aim_rule( const std::string &setting )
};
}

void talk_effect_fun_t::set_mapgen_update( JsonObject jo, const std::string &member )
{
mission_target_params target_params = mission_util::parse_mission_om_target( jo );
std::vector<std::string> update_ids;

if( jo.has_string( member ) ) {
update_ids.emplace_back( jo.get_string( member ) );
} else if( jo.has_array( member ) ) {
JsonArray ja = jo.get_array( member );
while( ja.has_more() ) {
update_ids.emplace_back( ja.next_string() );
}
}

function = [target_params, update_ids]( const dialogue & d ) {
mission_target_params update_params = target_params;
update_params.guy = d.beta;
const tripoint omt_pos = mission_util::get_om_terrain_pos( update_params );
for( const std::string mapgen_update_id : update_ids ) {
run_mapgen_update_func( mapgen_update_id, omt_pos, d.beta->chatbin.mission_selected );
}
};
}

void talk_effect_t::set_effect_consequence( const talk_effect_fun_t &fun, dialogue_consequence con )
{
effects.push_back( fun );
Expand Down Expand Up @@ -1969,6 +1995,8 @@ void talk_effect_t::parse_sub_effect( JsonObject jo )
} else if( jo.has_string( "set_npc_aim_rule" ) ) {
const std::string setting = jo.get_string( "set_npc_aim_rule" );
subeffect_fun.set_npc_aim_rule( setting );
} else if( jo.has_member( "mapgen_update" ) ) {
subeffect_fun.set_mapgen_update( jo, "mapgen_update" );
} else {
jo.throw_error( "invalid sub effect syntax :" + jo.str() );
}
Expand Down

0 comments on commit f741141

Please sign in to comment.