Skip to content

Commit

Permalink
Move faulty prefixes to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
irwiss committed Apr 20, 2023
1 parent 1518435 commit ed3147b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 58 deletions.
3 changes: 2 additions & 1 deletion data/json/faults/faults_bionic.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"id": "fault_bionic_salvaged",
"type": "fault",
"name": { "str": "Already deployed" },
"description": "This bionic needs to be reset to its factory state."
"description": "This bionic needs to be reset to its factory state.",
"item_prefix": "salvaged"
}
]
8 changes: 5 additions & 3 deletions data/json/faults/faults_gun.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
"type": "fault",
"name": { "str": "Blackpowder fouling" },
"description": "Firing blackpowder loads from a gun fouls it, which reduces reliability and, if left uncleaned, leads to rust. It fouls the gun much faster than the use of modern smokeless powder cartridges. Fouling is only a significant impact on reliability at high levels, but black powder fouling accumulates quickly.",
"flags": [ "SILENT", "BLACKPOWDER_FOULING_DAMAGE", "NO_DIRTYING" ]
"item_prefix": "rusting",
"flags": [ "BLACKPOWDER_FOULING_DAMAGE", "NO_DIRTYING" ]
},
{
"id": "fault_gun_chamber_spent",
"type": "fault",
"name": { "str": "Spent casing in chamber" },
"description": "This gun currently has an empty casing chambered. It will have to be removed before firing.",
"item_prefix": "jammed",
"flags": [ "JAMMED_GUN" ]
},
{
"id": "fault_gun_unlubricated",
"type": "fault",
"name": { "str": "Unlubricated" },
"description": "Either this gun is brand new and came without lubrication or it was recently cleaned with a solvent without oiling afterwards. Either way, it's not lubricated and will not cycle properly, and can even be damaged.",
"item_prefix": "unlubricated",
"flags": [ "UNLUBRICATED", "BAD_CYCLING" ]
},
{
"id": "fault_gun_dirt",
"type": "fault",
"name": { "str": "Fouling" },
"description": "Fouling is caused by firing gunpowder loads repeatedly, which reduces reliability and can eventually cause damage to the gun. Fouling accumulates slowly (unless blackpowder is used) due to the design of modern smokeless powder found in the vast majority of retail cartridges and it is not a significant problem until high levels of fouling are reached due to firing thousands of rounds without cleaning your firearm.",
"flags": [ "SILENT" ]
"description": "Fouling is caused by firing gunpowder loads repeatedly, which reduces reliability and can eventually cause damage to the gun. Fouling accumulates slowly (unless blackpowder is used) due to the design of modern smokeless powder found in the vast majority of retail cartridges and it is not a significant problem until high levels of fouling are reached due to firing thousands of rounds without cleaning your firearm."
}
]
8 changes: 8 additions & 0 deletions data/json/faults/faults_vehicles.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,63 @@
"type": "fault",
"name": { "str": "Worn drive belt" },
"description": "Required for operation of an attached alternator.",
"item_prefix": "faulty",
"flags": [ "NO_ALTERNATOR_CHARGE" ]
},
{
"id": "fault_engine_glow_plug",
"type": "fault",
"name": { "str": "Faulty glow plugs" },
"description": "Help when starting an engine in low ambient temperatures.",
"item_prefix": "faulty",
"flags": [ "BAD_COLD_START" ]
},
{
"id": "fault_engine_immobiliser",
"type": "fault",
"name": { "str": "Active immobiliser" },
"description": "An immobiliser device prevents starting of the vehicle without the appropriate key.",
"item_prefix": "faulty",
"flags": [ "IMMOBILIZER" ]
},
{
"id": "fault_engine_pump_diesel",
"type": "fault",
"name": { "str": "Faulty diesel pump" },
"description": "Required to pump and pressurize diesel from a vehicles tank.",
"item_prefix": "faulty",
"flags": [ "BAD_FUEL_PUMP" ]
},
{
"id": "fault_engine_filter_air",
"type": "fault",
"name": { "str": "Expired air filter" },
"description": "An expired filter reduces fuel efficiency and increases smoke production.",
"item_prefix": "faulty",
"flags": [ "DOUBLE_FUEL_CONSUMPTION", "EXTRA_EXHAUST" ]
},
{
"id": "fault_engine_filter_fuel",
"type": "fault",
"name": { "str": "Expired fuel filter" },
"description": "An expired filter reduces performance and increases the chance of backfires.",
"item_prefix": "faulty",
"flags": [ "REDUCE_ENG_POWER", "ENG_BACKFIRE" ]
},
{
"id": "fault_engine_pump_fuel",
"type": "fault",
"name": { "str": "Faulty fuel pump" },
"description": "Required to pump gasoline from a vehicles tank.",
"item_prefix": "faulty",
"flags": [ "BAD_FUEL_PUMP" ]
},
{
"id": "fault_engine_starter",
"type": "fault",
"name": { "str": "Faulty starter motor" },
"description": "Required to initially start the engine.",
"item_prefix": "faulty",
"flags": [ "BAD_STARTER" ]
}
]
3 changes: 3 additions & 0 deletions lang/string_extractor/parsers/fault.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ def parse_fault(json, origin):
write_text(json["name"], origin, comment="Name of a fault")
write_text(json["description"], origin,
comment="Description of fault \"{}\"".format(name))
if "item_prefix" in json:
write_text(json["item_prefix"], origin,
comment="Prefix for affected item's name \"{}\"".format(name))
6 changes: 6 additions & 0 deletions src/fault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ std::string fault::description() const
return description_.translated();
}

std::string fault::item_prefix() const
{
return item_prefix_.translated();
}

bool fault::has_flag( const std::string &flag ) const
{
return flags.count( flag );
Expand All @@ -81,6 +86,7 @@ void fault::load( const JsonObject &jo )
mandatory( jo, false, "id", f.id_ );
mandatory( jo, false, "name", f.name_ );
mandatory( jo, false, "description", f.description_ );
optional( jo, false, "item_prefix", f.item_prefix_ );
optional( jo, false, "flags", f.flags );

if( !faults_all.emplace( f.id_, f ).second ) {
Expand Down
2 changes: 2 additions & 0 deletions src/fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class fault
const fault_id &id() const;
std::string name() const;
std::string description() const;
std::string item_prefix() const;
bool has_flag( const std::string &flag ) const;

const std::set<fault_fix_id> &get_fixes() const;
Expand All @@ -60,6 +61,7 @@ class fault
fault_id id_ = fault_id::NULL_ID();
translation name_;
translation description_;
translation item_prefix_; // prefix added to affected item's name
std::set<fault_fix_id> fixes;
std::set<std::string> flags;
};
Expand Down
69 changes: 21 additions & 48 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6320,36 +6320,19 @@ void item::on_contents_changed()

std::string item::dirt_symbol() const
{
const int dirt_level = get_var( "dirt", 0 ) / 2000;
std::string dirt_symbol;
// TODO: MATERIALS put this in json

// these symbols are unicode square characters of different heights, representing a rough
// estimation of fouling in a gun. This appears instead of "faulty"
// since most guns will have some level of fouling in them, and usually it is not a big deal.
switch( dirt_level ) {
case 0:
dirt_symbol.clear();
break;
case 1:
dirt_symbol = "<color_white>\u2581</color>";
break;
case 2:
dirt_symbol = "<color_light_gray>\u2583</color>";
break;
case 3:
dirt_symbol = "<color_light_gray>\u2585</color>";
break;
case 4:
dirt_symbol = "<color_dark_gray>\u2587</color>";
break;
case 5:
dirt_symbol = "<color_brown>\u2588</color>";
break;
default:
dirt_symbol.clear();
// estimation of fouling in a gun. This appears instead of "faulty" since most guns will
// have some level of fouling in them, and usually it is not a big deal.
switch( static_cast<int>( get_var( "dirt", 0 ) / 2000 ) ) {
// *INDENT-OFF*
case 1: return "<color_white>\u2581</color>";
case 2: return "<color_light_gray>\u2583</color>";
case 3: return "<color_light_gray>\u2585</color>";
case 4: return "<color_dark_gray>\u2587</color>";
case 5: return "<color_brown>\u2588</color>";
default: return "";
// *INDENT-ON*
}
return dirt_symbol;
}

std::string item::degradation_symbol() const
Expand Down Expand Up @@ -6384,9 +6367,18 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t
// item damage and/or fouling level
std::string damtext;

// add first prefix if item has a fault that defines a prefix (prioritize?)
for( const fault_id &f : faults ) {
if( !f->item_prefix().empty() ) {
damtext = f->item_prefix() + " ";
break;
}
}
damtext += dirt_symbol();

if( get_option<std::string>( "ASTERISK_POSITION" ) == "prefix" && with_prefix ) {
if( is_favorite ) {
damtext = _( "* " ); // Display asterisk for favorite items, before item's name
damtext += _( "* " ); // Display asterisk for favorite items, before item's name
}
}

Expand All @@ -6401,20 +6393,6 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t
truncate_override = utf8_width( damtext, false ) - utf8_width( damtext, true );
}
}
if( !faults.empty() ) {
bool silent = true;
for( const auto &fault : faults ) {
if( !fault->has_flag( flag_SILENT ) ) {
silent = false;
break;
}
}
if( silent ) {
damtext.insert( 0, dirt_symbol() );
} else {
damtext.insert( 0, _( "faulty " ) + dirt_symbol() );
}
}

std::string vehtext;
if( is_engine() && engine_displacement() > 0 ) {
Expand Down Expand Up @@ -9416,11 +9394,6 @@ bool item::is_toolmod() const
return !is_gunmod() && type->mod;
}

bool item::is_faulty() const
{
return is_engine() ? !faults.empty() : false;
}

bool item::is_irremovable() const
{
return has_flag( flag_IRREMOVABLE );
Expand Down
1 change: 0 additions & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,6 @@ class item : public visitable
bool is_fuel() const;
bool is_toolmod() const;

bool is_faulty() const;
bool is_irremovable() const;

/** Returns true if the item is broken and can't be activated or used in crafting */
Expand Down
4 changes: 1 addition & 3 deletions src/profession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ static void clear_faults( item &it )
if( it.get_var( "dirt", 0 ) > 0 ) {
it.set_var( "dirt", 0 );
}
if( it.is_faulty() ) {
it.faults.clear();
}
it.faults.clear();
}

std::list<item> profession::items( bool male, const std::vector<trait_id> &traits ) const
Expand Down
8 changes: 6 additions & 2 deletions src/vehicle_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "color.h"
#include "debug.h"
#include "enums.h"
#include "fault.h"
#include "flag.h"
#include "game.h"
#include "item.h"
Expand Down Expand Up @@ -117,8 +118,11 @@ std::string vehicle_part::name( bool with_prefix ) const
if( base.has_var( "contained_name" ) ) {
res += string_format( _( " holding %s" ), base.get_var( "contained_name" ) );
}
if( base.is_faulty() ) {
res += _( " (faulty)" );
for( const fault_id &f : base.faults ) {
if( !f->item_prefix().empty() ) {
res += f->item_prefix();
break;
}
}
if( is_leaking() ) {
res += _( " (draining)" );
Expand Down

0 comments on commit ed3147b

Please sign in to comment.