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
24 changes: 21 additions & 3 deletions doc/MISSIONS_JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NPCs can assign missions to the player. There is a fairly regular structure for
"id": "MISSION_GET_BLACK_BOX_TRANSCRIPT",
"type": "mission_definition",
"name": "Retrieve Black Box Transcript",
"description": "Decrypt the contents of the black box using a terminal from a nearby lab.",
"goal": "MGOAL_FIND_ITEM",
"difficulty": 2,
"value": 150000,
Expand Down Expand Up @@ -36,11 +37,28 @@ Must always be there and must always be "mission_definition".

### id
The mission id is required, but for new missions, it can be arbitrary. Convention is to start
it with "MISSION" and to use a fairly desriptive name.
it with "MISSION" and to use a fairly descriptive name.

### name
The name is also required, and the name is what is displayed in the 'm'issions menu, so please
make it descriptive.
The name is also required, and is displayed to the user in the 'm'issions menu.

### description
Not required, but it's strongly recommended that you summarize all relevant info for the mission.
You may refer to mission end effects of the "u_buy_item" type, as long as they do not come at a
cost to the player. See the example below:
```JSON
"id": "MISSION_EXAMPLE_TOKENS",
"type": "mission_definition",
"name": "Murder Money",
"description": "Whack the target in exchange for <reward_item:FMCNote> c-notes and <reward_item:cig> cigarettes.",
"goal": "MGOAL_ASSASSINATE",
"end": {
"effect": [
{ "u_buy_item": "FMCNote", "count": 999 },
{ "u_buy_item": "cig", "count": 666 } ]
}
```
This system may be expanded in the future to allow referring to other mission parameters and effects.

### goal
Must be included, and must be one of these strings:
Expand Down
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 );
const std::vector<std::pair<int, std::string>> &get_likely_rewards() const;
void set_u_buy_monster( const std::string &monster_type_id, int cost, int count, bool pacified,
const translation &name );
void set_u_learn_recipe( const std::string &learned_recipe_id );
Expand Down
5 changes: 5 additions & 0 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ character_id mission::get_npc_id() const
return npc_id;
}

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

bool mission::has_generic_rewards() const
{
return type->has_generic_rewards;
Expand Down
4 changes: 4 additions & 0 deletions src/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ struct mission_type {
// If the mission has generic rewards, so that the completion dialogue knows whether to offer them.
bool has_generic_rewards = true;

// 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 @@ -365,6 +368,7 @@ class mission
int get_id() const;
const std::string &get_item_id() const;
character_id get_npc_id() const;
const std::vector<std::pair<int, std::string>> &get_likely_rewards() const;
bool has_generic_rewards() const;
/**
* Whether the mission is assigned to a player character. If not, the mission is free and
Expand Down
13 changes: 12 additions & 1 deletion src/mission_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,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,
const std::vector<std::pair<int, std::string>> rewards ) {
std::string formatted_description = description;
for( const auto &reward : rewards ) {
std::string token = "<reward_count:" + reward.second + ">";
formatted_description = string_replace( formatted_description, token, string_format( "%d",
reward.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;
}
10 changes: 10 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,11 @@ 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 @@ -2099,6 +2104,11 @@ void talk_effect_fun_t::set_add_mission( const std::string mission_id )
};
}

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

void talk_effect_fun_t::set_u_buy_monster( const std::string &monster_type_id, int cost, int count,
bool pacified, const translation &name )
{
Expand Down