diff --git a/data/json/field_type.json b/data/json/field_type.json index 68221c74d4bad..c4eaec74e8863 100644 --- a/data/json/field_type.json +++ b/data/json/field_type.json @@ -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, @@ -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, @@ -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, @@ -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, @@ -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", @@ -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, @@ -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, @@ -168,6 +175,7 @@ ] } ], + "description_affix": "covered_in", "is_splattering": true, "priority": 2, "half_life": "2 minutes", @@ -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", @@ -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, @@ -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, @@ -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, @@ -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, @@ -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", @@ -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", @@ -533,6 +548,7 @@ "monster_spawn_group": "GROUP_NETHER_FATIGUE_FIELD" } ], + "description_affix": "under", "priority": 8, "display_items": false, "display_field": true @@ -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", @@ -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", @@ -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, @@ -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 @@ -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", @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/src/field.cpp b/src/field.cpp index bf0f5a5bbbe66..de3362f1ed383 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -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; diff --git a/src/field.h b/src/field.h index 3ccd136ac1797..72f1566b0161d 100644 --- a/src/field.h +++ b/src/field.h @@ -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::iterator begin(); std::map::const_iterator begin() const; diff --git a/src/field_type.cpp b/src/field_type.cpp index a9b88ad52b205..c05219a4f7ae6 100644 --- a/src/field_type.cpp +++ b/src/field_type.cpp @@ -33,6 +33,24 @@ std::string enum_to_string( game_message_type data ) abort(); } +template<> +std::string enum_to_string( 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 @@ -220,6 +238,9 @@ void field_type::load( 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 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", PNULL ); } diff --git a/src/field_type.h b/src/field_type.h index 54f1a8322b737..563e9a98d20f7 100644 --- a/src/field_type.h +++ b/src/field_type.h @@ -24,6 +24,28 @@ 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 +}; + +static const std::unordered_map 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 { + static constexpr description_affix last = description_affix::DESCRIPTION_AFFIX_NUM; +}; + struct field_effect { efftype_id id; time_duration min_duration = 0_seconds; @@ -110,6 +132,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 npc_complain_data; diff --git a/src/iuse.cpp b/src/iuse.cpp index 3451746c3fc9a..509add6d9629b 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -6804,44 +6804,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> 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> on_affix_ids = { - fd_fire, fd_flame_burst - }; - static const std::unordered_set> under_affix_ids = { - fd_gas_vent, fd_fire_vent, fd_fatigue - }; - static const std::unordered_set> illuminated_by_affix_ids = { - fd_spotlight, fd_laser, fd_dazzling, fd_electricity - }; - static const std::vector>, 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; }