Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mission descriptions to refer to the effects of the mission. #33411

Merged
merged 11 commits into from
Aug 31, 2019
Merged
2 changes: 2 additions & 0 deletions src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct talk_topic {
struct talk_effect_fun_t {
private:
std::function<void( const dialogue &d )> function;
std::vector<std::pair<int, std::string>> likely_rewards;

public:
talk_effect_fun_t() = default;
Expand Down Expand Up @@ -121,6 +122,7 @@ struct talk_effect_fun_t {
void set_bulk_trade_accept( bool is_trade, bool is_npc = false );
void set_npc_gets_item( bool to_use );
void set_add_mission( std::string mission_id );
std::vector<std::pair<int, std::string>> get_likely_rewards();

void operator()( const dialogue &d ) const {
if( !function ) {
Expand Down
5 changes: 5 additions & 0 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ character_id mission::get_npc_id() const
return npc_id;
}

std::vector<std::pair<int, std::string>> mission::get_likely_rewards()
{
return type->likely_rewards;
}

void mission::set_target( const tripoint &p )
{
target = p;
Expand Down
4 changes: 4 additions & 0 deletions src/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ struct mission_type {
// If true, the NPC will press this mission!
bool urgent = false;

// A limited subset of the talk_effects on the mission
std::vector<std::pair<int, std::string>> likely_rewards;

// Points of origin
std::vector<mission_origin> origins;
itype_id item_id = "null";
Expand Down Expand Up @@ -371,6 +374,7 @@ class mission
int get_id() const;
const std::string &get_item_id() const;
character_id get_npc_id() const;
std::vector<std::pair<int, std::string>> get_likely_rewards();
Petethegoat marked this conversation as resolved.
Show resolved Hide resolved
/**
* Whether the mission is assigned to a player character. If not, the mission is free and
* can be assigned.
Expand Down
14 changes: 13 additions & 1 deletion src/mission_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include <regex>

#include "avatar.h"
#include "mission.h"
Expand Down Expand Up @@ -123,10 +124,21 @@ void game::list_missions()
y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, col,
miss->name() + for_npc );

auto format_tokenized_description = []( const std::string description,
std::vector<std::pair<int, std::string>> rewards ) {
std::string formatted_description = description;
for( size_t i = 0; i < rewards.size(); i++ ) {
Petethegoat marked this conversation as resolved.
Show resolved Hide resolved
std::regex token("<reward_count:" + rewards[i].second + ">");
Petethegoat marked this conversation as resolved.
Show resolved Hide resolved
formatted_description = std::regex_replace( formatted_description, token, string_format( "%d",
rewards[i].first ) );
}
return formatted_description;
};

y++;
if( !miss->get_description().empty() ) {
y += fold_and_print( w_missions, point( 31, y ), getmaxx( w_missions ) - 33, c_white,
miss->get_description() );
format_tokenized_description( miss->get_description(), miss->get_likely_rewards() ) );
}
if( miss->has_deadline() ) {
const time_point deadline = miss->get_deadline();
Expand Down
9 changes: 9 additions & 0 deletions src/mission_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "mapgen_functions.h"
#include "messages.h"
#include "npc.h"
#include "npctalk.h"
#include "overmap.h"
#include "overmapbuffer.h"
#include "rng.h"
Expand Down Expand Up @@ -527,5 +528,13 @@ bool mission_type::parse_funcs( JsonObject &jo, std::function<void( mission * )>
mission_function( miss );
}
};

for( talk_effect_fun_t &effect : talk_effects.effects ) {
auto rewards = effect.get_likely_rewards();
if( !rewards.empty() ) {
likely_rewards.insert( likely_rewards.end(), rewards.begin(), rewards.end() );
}
}

return true;
}
11 changes: 11 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,12 @@ void talk_effect_fun_t::set_u_buy_item( const std::string &item_name, int cost,
popup( _( "%1$s gives you a %2$s." ), p.name, container.tname() );
}
};

// Update structure used by mission descriptions.
if (cost <= 0)
{
likely_rewards.push_back(std::pair<int, std::string>(count, item_name));
}
}

void talk_effect_fun_t::set_u_sell_item( const std::string &item_name, int cost, int count )
Expand Down Expand Up @@ -2097,6 +2103,11 @@ void talk_effect_fun_t::set_add_mission( const std::string mission_id )
};
}

std::vector<std::pair<int, std::string>> talk_effect_fun_t::get_likely_rewards()
{
return likely_rewards;
}

void talk_effect_t::set_effect_consequence( const talk_effect_fun_t &fun, dialogue_consequence con )
{
effects.push_back( fun );
Expand Down