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

Refactor base camp code to make it more sane, and fix translation issues #34058

Merged
merged 7 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/TRANSLATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ new syntax "name" would be a `dict`, which may break unmigrated script.
| Spell messages and monster spell messages
| Martial art names and descriptions
| Mission names and descriptions
| Recipe blueprint names
| Recipe group recipe descriptions
| Item descriptions
| Recipe descriptions

### Recommendations

Expand Down
2 changes: 2 additions & 0 deletions lang/extract_json_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ def extract_recipes(item):
writestr(outfile, arr[2])
if "description" in item:
writestr(outfile, item["description"])
if "blueprint_name" in item:
writestr(outfile, item["blueprint_name"])


def extract_recipe_group(item):
Expand Down
30 changes: 19 additions & 11 deletions src/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,10 @@ std::string new_artifact()
def.create_name( newname.str() );
}
}
def.description = string_format(
_( "This is the %s.\nIt is the only one of its kind.\nIt may have unknown powers; try activating them." ),
def.nname( 1 ) );
def.description = no_translation(
string_format(
_( "This is the %s.\nIt is the only one of its kind.\nIt may have unknown powers; try activating them." ),
def.nname( 1 ) ) );

// Finally, pick some powers
art_effect_passive passive_tmp = AEP_NULL;
Expand Down Expand Up @@ -887,7 +888,7 @@ std::string new_artifact()
}
}

def.description = description.str();
def.description = no_translation( description.str() );

// Finally, pick some effects
int num_good = 0;
Expand Down Expand Up @@ -939,8 +940,9 @@ std::string new_natural_artifact( artifact_natural_property prop )
def.m_to_hit = 0;

def.create_name( _( property_data.name ), _( shape_data.name ) );
def.description = string_format( pgettext( "artifact description", "This %1$s %2$s." ),
_( shape_data.desc ), _( property_data.desc ) );
def.description = no_translation(
string_format( pgettext( "artifact description", "This %1$s %2$s." ),
_( shape_data.desc ), _( property_data.desc ) ) );

// Three possibilities: good passive + bad passive, good active + bad active,
// and bad passive + good active
Expand Down Expand Up @@ -1054,7 +1056,9 @@ std::string architects_cube()
def.item_tags.insert( weapon.tag );
}
// Add an extra weapon perhaps?
def.description = _( "The architect's cube." );
// Most artifact descriptions are generated and stored using `no_translation`,
// also do it here for consistency
def.description = no_translation( _( "The architect's cube." ) );
def.artifact->effects_carried.push_back( AEP_SUPER_CLAIRVOYANCE );
item_controller->add_item_type( static_cast<itype &>( def ) );
return def.get_id();
Expand Down Expand Up @@ -1129,7 +1133,7 @@ void it_artifact_tool::deserialize( JsonObject &jo )
{
id = jo.get_string( "id" );
name = jo.get_string( "name" );
description = jo.get_string( "description" );
description = no_translation( jo.get_string( "description" ) );
if( jo.has_int( "sym" ) ) {
sym = std::string( 1, jo.get_int( "sym" ) );
} else {
Expand Down Expand Up @@ -1244,7 +1248,7 @@ void it_artifact_armor::deserialize( JsonObject &jo )
{
id = jo.get_string( "id" );
name = jo.get_string( "name" );
description = jo.get_string( "description" );
description = no_translation( jo.get_string( "description" ) );
if( jo.has_int( "sym" ) ) {
sym = std::string( 1, jo.get_int( "sym" ) );
} else {
Expand Down Expand Up @@ -1336,7 +1340,9 @@ void it_artifact_tool::serialize( JsonOut &json ) const
// generic data
json.member( "id", id );
json.member( "name", name );
json.member( "description", description );
// Artifact descriptions are always constructed using `no_translation`,
// so `translated()` here only retrieves the underlying string
json.member( "description", description.translated() );
json.member( "sym", sym );
json.member( "color", color );
json.member( "price", price );
Expand Down Expand Up @@ -1390,7 +1396,9 @@ void it_artifact_armor::serialize( JsonOut &json ) const
// generic data
json.member( "id", id );
json.member( "name", name );
json.member( "description", description );
// Artifact descriptions are always constructed using `no_translation`,
// so `translated()` here only retrieves the underlying string
json.member( "description", description.translated() );
json.member( "sym", sym );
json.member( "color", color );
json.member( "price", price );
Expand Down
73 changes: 51 additions & 22 deletions src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@
#include "flat_set.h"
#include "line.h"


const std::map<point, base_camps::direction_data> base_camps::all_directions = {
// direction, direction id, tab order, direction abbreviation with bracket, direction tab title
{ base_camps::base_dir, { "[B]", base_camps::TAB_MAIN, to_translation( "base camp: base", "[B]" ), to_translation( "base camp: base", " MAIN " ) } },
{ point_north, { "[N]", base_camps::TAB_N, to_translation( "base camp: north", "[N]" ), to_translation( "base camp: north", " [N] " ) } },
{ point_north_east, { "[NE]", base_camps::TAB_NE, to_translation( "base camp: northeast", "[NE]" ), to_translation( "base camp: northeast", " [NE] " ) } },
{ point_east, { "[E]", base_camps::TAB_E, to_translation( "base camp: east", "[E]" ), to_translation( "base camp: east", " [E] " ) } },
{ point_south_east, { "[SE]", base_camps::TAB_SE, to_translation( "base camp: southeast", "[SE]" ), to_translation( "base camp: southeast", " [SE] " ) } },
{ point_south, { "[S]", base_camps::TAB_S, to_translation( "base camp: south", "[S]" ), to_translation( "base camp: south", " [S] " ) } },
{ point_south_west, { "[SW]", base_camps::TAB_SW, to_translation( "base camp: southwest", "[SW]" ), to_translation( "base camp: southwest", " [SW] " ) } },
{ point_west, { "[W]", base_camps::TAB_W, to_translation( "base camp: west", "[W]" ), to_translation( "base camp: west", " [W] " ) } },
{ point_north_west, { "[NW]", base_camps::TAB_NW, to_translation( "base camp: northwest", "[NW]" ), to_translation( "base camp: northwest", " [NW] " ) } },
};

point base_camps::direction_from_id( const std::string &id )
{
for( const auto &dir : all_directions ) {
if( dir.second.id == id ) {
return dir.first;
}
}
return base_dir;
}

std::string base_camps::faction_encode_short( const std::string &type )
{
return prefix + type + "_";
Expand Down Expand Up @@ -87,9 +111,9 @@ basecamp::basecamp( const std::string &name_, const tripoint &omt_pos_ ): name(
}

basecamp::basecamp( const std::string &name_, const tripoint &bb_pos_,
const std::vector<std::string> &directions_,
const std::map<std::string, expansion_data> &expansions_ ):
directions( directions_ ), name( name_ ), bb_pos( bb_pos_ ), expansions( expansions_ )
const std::vector<point> &directions_,
const std::map<point, expansion_data> &expansions_ )
: directions( directions_ ), name( name_ ), bb_pos( bb_pos_ ), expansions( expansions_ )
{
}

Expand Down Expand Up @@ -119,7 +143,7 @@ void basecamp::add_expansion( const std::string &terrain, const tripoint &new_po
return;
}

const std::string dir = talk_function::om_simple_dir( omt_pos, new_pos );
const point dir = talk_function::om_simple_dir( omt_pos, new_pos );
expansions[ dir ] = parse_expansion( terrain, new_pos );
bool by_radio = rl_dist( g->u.global_omt_location(), omt_pos ) > 2;
resources_updated = false;
Expand All @@ -129,7 +153,7 @@ void basecamp::add_expansion( const std::string &terrain, const tripoint &new_po
}

void basecamp::add_expansion( const std::string &bldg, const tripoint &new_pos,
const std::string &dir )
const point &dir )
{
expansion_data e;
e.type = base_camps::faction_decode( bldg );
Expand Down Expand Up @@ -157,12 +181,12 @@ void basecamp::define_camp( npc &p, const std::string &camp_type )
e.type = base_camps::faction_decode( camp_type );
e.cur_level = -1;
e.pos = omt_pos;
expansions[ base_camps::base_dir ] = e;
expansions[base_camps::base_dir] = e;
omt_ref = oter_id( "faction_base_camp_0" );
update_provides( base_camps::faction_encode_abs( e, 0 ),
expansions[ base_camps::base_dir ] );
expansions[base_camps::base_dir] );
} else {
expansions[ base_camps::base_dir ] = parse_expansion( om_cur, omt_pos );
expansions[base_camps::base_dir] = parse_expansion( om_cur, omt_pos );
}
}

Expand Down Expand Up @@ -195,7 +219,7 @@ std::string basecamp::om_upgrade_description( const std::string &bldg, bool trun

// upgrade levels
// legacy next upgrade
std::string basecamp::next_upgrade( const std::string &dir, const int offset ) const
std::string basecamp::next_upgrade( const point &dir, const int offset ) const
{
const auto &e = expansions.find( dir );
if( e == expansions.end() ) {
Expand Down Expand Up @@ -228,16 +252,17 @@ bool basecamp::has_provides( const std::string &req, const expansion_data &e_dat
return false;
}

bool basecamp::has_provides( const std::string &req, const std::string &dir, int level ) const
bool basecamp::has_provides( const std::string &req, const cata::optional<point> dir,
int level ) const
{
if( dir == "all" ) {
if( !dir ) {
for( const auto &e : expansions ) {
if( has_provides( req, e.second, level ) ) {
return true;
}
}
} else {
const auto &e = expansions.find( dir );
const auto &e = expansions.find( *dir );
if( e != expansions.end() ) {
return has_provides( req, e->second, level );
}
Expand All @@ -250,7 +275,7 @@ bool basecamp::can_expand()
return has_provides( "bed", base_camps::base_dir, directions.size() * 2 );
}

std::vector<basecamp_upgrade> basecamp::available_upgrades( const std::string &dir )
std::vector<basecamp_upgrade> basecamp::available_upgrades( const point &dir )
{
std::vector<basecamp_upgrade> ret_data;
auto e = expansions.find( dir );
Expand Down Expand Up @@ -312,23 +337,26 @@ std::vector<basecamp_upgrade> basecamp::available_upgrades( const std::string &d
}

// recipes and craft support functions
std::map<std::string, std::string> basecamp::recipe_deck( const std::string &dir ) const
std::map<recipe_id, translation> basecamp::recipe_deck( const point &dir ) const
{
std::map<std::string, std::string> recipes = recipe_group::get_recipes_by_bldg( dir );
if( !recipes.empty() ) {
return recipes;
}
std::map<recipe_id, translation> recipes;
const auto &e = expansions.find( dir );
if( e == expansions.end() ) {
return recipes;
}
for( const auto &provides : e->second.provides ) {
const auto &test_s = recipe_group::get_recipes_by_id( provides.first );
recipes.insert( test_s.begin(), test_s.end() );
recipes.insert( test_s.cbegin(), test_s.cend() );
}
return recipes;
}

std::map<recipe_id, translation> basecamp::recipe_deck( const std::string &bldg ) const
{
const std::map<recipe_id, translation> recipes = recipe_group::get_recipes_by_bldg( bldg );
return recipes;
}

std::string basecamp::get_gatherlist() const
{
const auto &e = expansions.find( base_camps::base_dir );
Expand Down Expand Up @@ -379,7 +407,7 @@ void basecamp::update_provides( const std::string &bldg, expansion_data &e_data
}
}

void basecamp::update_in_progress( const std::string &bldg, const std::string &dir )
void basecamp::update_in_progress( const std::string &bldg, const point &dir )
{
if( !recipe_id( bldg ).is_valid() ) {
return;
Expand Down Expand Up @@ -626,7 +654,7 @@ void basecamp::form_crafting_inventory( const bool by_radio )
}

// display names
std::string basecamp::expansion_tab( const std::string &dir ) const
std::string basecamp::expansion_tab( const point &dir ) const
{
if( dir == base_camps::base_dir ) {
return _( "Base Missions" );
Expand All @@ -635,7 +663,8 @@ std::string basecamp::expansion_tab( const std::string &dir ) const

const auto &e = expansions.find( dir );
if( e != expansions.end() ) {
const auto e_type = expansion_types.find( base_camps::faction_encode_abs( e->second, 0 ) );
recipe_id id( base_camps::faction_encode_abs( e->second, 0 ) );
const auto e_type = expansion_types.find( id );
if( e_type != expansion_types.end() ) {
return e_type->second + _( "Expansion" );
}
Expand Down
Loading