Skip to content

Commit

Permalink
Jsonized field description affixes (#35839)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg authored and kevingranade committed Dec 9, 2019
1 parent 9b24c74 commit 45a3b20
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 34 deletions.
27 changes: 27 additions & 0 deletions data/json/field_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "field_type",
"legacy_enum_id": 1,
"intensity_levels": [ { "name": "blood splatter", "color": "red" }, { "name": "blood stain" }, { "name": "puddle of blood" } ],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -23,6 +24,7 @@
"type": "field_type",
"legacy_enum_id": 2,
"intensity_levels": [ { "name": "bile splatter", "color": "pink" }, { "name": "bile stain" }, { "name": "puddle of bile" } ],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -40,6 +42,7 @@
{ "name": "bloody meat chunks", "color": "light_red" },
{ "name": "heap of gore", "color": "red" }
],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -57,6 +60,7 @@
{ "name": "shattered branches and leaves" },
{ "name": "broken vegetation tangle", "color": "green" }
],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -70,6 +74,7 @@
"type": "field_type",
"legacy_enum_id": 5,
"intensity_levels": [ { "name": "cowebs", "sym": "}" }, { "name": "webs" }, { "name": "thick webs", "transparent": false } ],
"description_affix": "covered_in",
"immunity_data": { "traits": [ "WEB_WALKER" ] },
"priority": 2,
"phase": "solid",
Expand All @@ -85,6 +90,7 @@
{ "name": "slime stain" },
{ "name": "puddle of slime", "color": "green" }
],
"description_affix": "covered_in",
"decay_amount_factor": 2,
"apply_slime_factor": 10,
"is_splattering": true,
Expand All @@ -102,6 +108,7 @@
{ "name": "acid streak" },
{ "name": "pool of acid", "color": "green" }
],
"description_affix": "covered_in",
"immunity_data": { "traits": [ "ACIDPROOF" ] },
"underwater_age_speedup": "2 minutes",
"has_acid": true,
Expand Down Expand Up @@ -168,6 +175,7 @@
]
}
],
"description_affix": "covered_in",
"is_splattering": true,
"priority": 2,
"half_life": "2 minutes",
Expand All @@ -183,6 +191,7 @@
{ "name": "sludge trail", "color": "dark_gray" },
{ "name": "thick sludge trail" }
],
"description_affix": "covered_in",
"is_splattering": true,
"priority": 2,
"half_life": "6 hours",
Expand All @@ -206,6 +215,7 @@
{ "name": "fire", "color": "light_red", "light_emitted": 60, "translucency": 0.4 },
{ "name": "raging fire", "color": "red", "light_emitted": 160, "translucency": 0.1 }
],
"description_affix": "on",
"decay_amount_factor": 3,
"has_fire": true,
"priority": 4,
Expand All @@ -219,6 +229,7 @@
"type": "field_type",
"legacy_enum_id": 11,
"intensity_levels": [ { "name": "legacy rubble", "sym": "#", "color": "dark_gray" } ],
"description_affix": "covered_in",
"half_life": "1 turns",
"phase": "solid",
"display_items": false,
Expand Down Expand Up @@ -437,6 +448,7 @@
"type": "field_type",
"legacy_enum_id": 16,
"intensity_levels": [ { "name": "gas vent" }, { "//": "repeat last entry" }, { "//": "repeat last entry" } ],
"description_affix": "under",
"wandering_field": "fd_toxic_gas",
"gas_absorption_factor": 15,
"dirty_transparency_cache": true,
Expand Down Expand Up @@ -477,6 +489,7 @@
"type": "field_type",
"legacy_enum_id": 17,
"intensity_levels": [ { "name": "fire vent", "light_emitted": 20 }, { "//": "repeat last entry" }, { "//": "repeat last entry" } ],
"description_affix": "under",
"has_fire": true,
"phase": "gas",
"display_items": false,
Expand All @@ -487,6 +500,7 @@
"type": "field_type",
"legacy_enum_id": 18,
"intensity_levels": [ { "name": "fire", "sym": "5", "color": "red", "dangerous": true, "light_emitted": 20 } ],
"description_affix": "on",
"has_fire": true,
"priority": 4,
"phase": "gas",
Expand All @@ -502,6 +516,7 @@
{ "name": "electric crackle", "color": "cyan", "light_emitted": 4 },
{ "name": "electric cloud", "color": "blue", "light_emitted": 20 }
],
"description_affix": "illuminated_by",
"has_elec": true,
"priority": 4,
"half_life": "2 turns",
Expand Down Expand Up @@ -533,6 +548,7 @@
"monster_spawn_group": "GROUP_NETHER_FATIGUE_FIELD"
}
],
"description_affix": "under",
"priority": 8,
"display_items": false,
"display_field": true
Expand All @@ -551,6 +567,7 @@
"type": "field_type",
"legacy_enum_id": 22,
"intensity_levels": [ { "name": "shock vent", "sym": "&" }, { "//": "repeat last entry" }, { "//": "repeat last entry" } ],
"description_affix": "under",
"has_elec": true,
"priority": -1,
"phase": "plasma",
Expand All @@ -562,6 +579,7 @@
"type": "field_type",
"legacy_enum_id": 23,
"intensity_levels": [ { "name": "acid vent", "sym": "&" }, { "//": "repeat last entry" }, { "//": "repeat last entry" } ],
"description_affix": "under",
"has_acid": true,
"priority": -1,
"phase": "liquid",
Expand Down Expand Up @@ -593,6 +611,7 @@
{ "name": "beam of light", "color": "light_blue" },
{ "name": "intense beam of light", "color": "white" }
],
"description_affix": "illuminated_by",
"priority": 4,
"half_life": "1 turns",
"dirty_transparency_cache": true,
Expand All @@ -605,6 +624,7 @@
"type": "field_type",
"legacy_enum_id": 26,
"intensity_levels": [ { "name": "spotlight", "sym": "&", "light_emitted": 80 } ],
"description_affix": "illuminated_by",
"priority": 1,
"half_life": "1 turns",
"display_field": true
Expand All @@ -614,6 +634,7 @@
"type": "field_type",
"legacy_enum_id": 27,
"intensity_levels": [ { "name": "dazzling", "color": "light_red_yellow", "sym": "#", "light_emitted": 5 } ],
"description_affix": "illuminated_by",
"priority": 4,
"half_life": "1 turns",
"phase": "plasma",
Expand All @@ -629,6 +650,7 @@
{ "name": "plant sap stain" },
{ "name": "puddle of resin" }
],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -642,6 +664,7 @@
"type": "field_type",
"legacy_enum_id": 29,
"intensity_levels": [ { "name": "bug blood splatter", "color": "green" }, { "name": "bug blood stain" }, { "name": "puddle of bug blood" } ],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -659,6 +682,7 @@
{ "name": "hemolymph stain" },
{ "name": "puddle of hemolymph" }
],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -676,6 +700,7 @@
{ "name": "shattered bug leg", "color": "green" },
{ "name": "torn insect organs", "color": "yellow" }
],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand All @@ -693,6 +718,7 @@
{ "name": "icky mess" },
{ "name": "heap of squishy gore", "color": "dark_gray" }
],
"description_affix": "covered_in",
"underwater_age_speedup": "25 minutes",
"decay_amount_factor": 2,
"is_splattering": true,
Expand Down Expand Up @@ -1222,6 +1248,7 @@
"type": "field_type",
"legacy_enum_id": 50,
"intensity_levels": [ { "name": "smoke vent", "dangerous": true }, { "//": "repeat last entry" }, { "//": "repeat last entry" } ],
"description_affix": "under",
"wandering_field": "fd_smoke",
"gas_absorption_factor": 15,
"dirty_transparency_cache": true,
Expand Down
5 changes: 5 additions & 0 deletions src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ field_type_id field::displayed_field_type() const
return _displayed_field_type;
}

description_affix field::displayed_description_affix() const
{
return _displayed_field_type.obj().desc_affix;
}

int field::total_move_cost() const
{
int current_cost = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class field
*/
field_type_id displayed_field_type() const;

description_affix displayed_description_affix() const;

//Returns the vector iterator to begin searching through the list.
std::map<field_type_id, field_entry>::iterator begin();
std::map<field_type_id, field_entry>::const_iterator begin() const;
Expand Down
21 changes: 21 additions & 0 deletions src/field_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ std::string enum_to_string<game_message_type>( game_message_type data )
abort();
}

template<>
std::string enum_to_string<description_affix>( description_affix data )
{
switch( data ) {
// *INDENT-OFF*
case description_affix::DESCRIPTION_AFFIX_IN: return "in";
case description_affix::DESCRIPTION_AFFIX_COVERED_IN: return "covered_in";
case description_affix::DESCRIPTION_AFFIX_ON: return "on";
case description_affix::DESCRIPTION_AFFIX_UNDER: return "under";
case description_affix::DESCRIPTION_AFFIX_ILLUMINTED_BY: return "illuminated_by";
// *INDENT-ON*
case description_affix::DESCRIPTION_AFFIX_NUM:
break;
};
debugmsg( "Invalid description affix value '%d'.", data );
return "invalid";
}

} // namespace io

namespace
Expand Down Expand Up @@ -220,6 +238,9 @@ void field_type::load( const JsonObject &jo, const std::string & )
optional( jo, was_loaded, "has_fume", has_fume, false );
optional( jo, was_loaded, "priority", priority, 0 );
optional( jo, was_loaded, "half_life", half_life, 0_turns );
const auto description_affix_reader = enum_flags_reader<description_affix> { "description affixes" };
optional( jo, was_loaded, "description_affix", desc_affix, description_affix_reader,
description_affix::DESCRIPTION_AFFIX_IN );
if( jo.has_member( "phase" ) ) {
phase = jo.get_enum_value<phase_id>( "phase", PNULL );
}
Expand Down
33 changes: 33 additions & 0 deletions src/field_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@ class JsonObject;
enum phase_id : int;
enum body_part : int;

enum class description_affix : int {
DESCRIPTION_AFFIX_IN,
DESCRIPTION_AFFIX_COVERED_IN,
DESCRIPTION_AFFIX_ON,
DESCRIPTION_AFFIX_UNDER,
DESCRIPTION_AFFIX_ILLUMINTED_BY,
DESCRIPTION_AFFIX_NUM
};

namespace std
{
template <>
struct hash<description_affix> {
std::size_t operator()( const description_affix &k ) const {
return static_cast<size_t>( k );
}
};
} // namespace std

static const std::unordered_map<description_affix, std::string> description_affixes = {
{ description_affix::DESCRIPTION_AFFIX_IN, translate_marker( " in %s" ) },
{ description_affix::DESCRIPTION_AFFIX_COVERED_IN, translate_marker( " covered in %s" ) },
{ description_affix::DESCRIPTION_AFFIX_ON, translate_marker( " on %s" ) },
{ description_affix::DESCRIPTION_AFFIX_UNDER, translate_marker( " under %s" ) },
{ description_affix::DESCRIPTION_AFFIX_ILLUMINTED_BY, translate_marker( " in %s" ) },
};

template<>
struct enum_traits<description_affix> {
static constexpr description_affix last = description_affix::DESCRIPTION_AFFIX_NUM;
};

struct field_effect {
efftype_id id;
time_duration min_duration = 0_seconds;
Expand Down Expand Up @@ -110,6 +142,7 @@ struct field_type {
bool has_acid = false;
bool has_elec = false;
bool has_fume = false;
description_affix desc_affix;

// chance, issue, duration, speech
std::tuple<int, std::string, time_duration, std::string> npc_complain_data;
Expand Down
36 changes: 2 additions & 34 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6810,44 +6810,12 @@ static std::string colorized_trap_name_at( const tripoint &point )

static std::string colorized_field_description_at( const tripoint &point )
{
static const std::unordered_set<field_type_id, std::hash<int>> covered_in_affix_ids = {
fd_blood, fd_bile, fd_gibs_flesh, fd_gibs_veggy, fd_web,
fd_slime, fd_acid, fd_sap, fd_sludge, fd_blood_veggy,
fd_blood_insect, fd_blood_invertebrate, fd_gibs_insect,
fd_gibs_invertebrate, fd_rubble
};
static const std::unordered_set<field_type_id, std::hash<int>> on_affix_ids = {
fd_fire, fd_flame_burst
};
static const std::unordered_set<field_type_id, std::hash<int>> under_affix_ids = {
fd_gas_vent, fd_fire_vent, fd_fatigue
};
static const std::unordered_set<field_type_id, std::hash<int>> illuminated_by_affix_ids = {
fd_spotlight, fd_laser, fd_dazzling, fd_electricity
};
static const std::vector<std::pair<std::unordered_set<field_type_id, std::hash<int>>, std::string>>
affixes_vec = {
{ covered_in_affix_ids, translate_marker( " covered in %s" ) },
{ on_affix_ids, translate_marker( " on %s" ) },
{ under_affix_ids, translate_marker( " under %s" ) },
{ illuminated_by_affix_ids, translate_marker( " illuminated by %s" ) }
}; // anything else is "in %s"

std::string field_text;
const field &field = g->m.field_at( point );
const field_entry *entry = field.find_field( field.displayed_field_type() );
if( entry ) {
std::string affix;
for( const auto &pair : affixes_vec ) {
if( pair.first.find( entry->get_field_type() ) != pair.first.end() ) {
affix = pair.second;
}
}
if( affix.empty() ) {
field_text = string_format( _( " in %s" ), colorize( entry->name(), entry->color() ) );
} else {
field_text = string_format( _( affix ), colorize( entry->name(), entry->color() ) );
}
field_text = string_format( _( description_affixes.at( field.displayed_description_affix() ) ),
colorize( entry->name(), entry->color() ) );
}
return field_text;
}
Expand Down

0 comments on commit 45a3b20

Please sign in to comment.