Skip to content

Commit

Permalink
Feedback for burnout of candles and torches (#41481)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexusmrsep authored Jun 22, 2020
1 parent 6b26feb commit ae2aa53
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@
"context": [ "ARMOR", "TOOL_ARMOR" ],
"info": "This gear is equipped with an accurate hygrometer (which is used to measure humidity)."
},
{
"id": "BURNOUT",
"type": "json_flag",
"context": [ "TOOL" ],
"//": "You can visually inspect how much it is burned out (candle, torch)."
},
{
"id": "IRREMOVABLE",
"type": "json_flag",
Expand Down
20 changes: 11 additions & 9 deletions data/json/items/tool/lighting.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
"need_fire": 1,
"menu_text": "Light",
"type": "transform"
}
},
"flags": [ "BURNOUT" ]
},
{
"id": "candle_lit",
Expand All @@ -134,7 +135,7 @@
{ "type": "firestarter", "moves": 100 },
{ "target": "candle", "msg": "The candle winks out.", "menu_text": "Extinguish", "type": "transform" }
],
"flags": [ "LIGHT_8", "WATER_EXTINGUISH", "TRADER_AVOID", "WIND_EXTINGUISH", "FIRESTARTER" ]
"flags": [ "LIGHT_8", "WATER_EXTINGUISH", "TRADER_AVOID", "WIND_EXTINGUISH", "FIRESTARTER", "BURNOUT" ]
},
{
"id": "electric_lantern",
Expand Down Expand Up @@ -684,8 +685,8 @@
"symbol": "/",
"color": "brown",
"techniques": [ "WBLOCK_1" ],
"initial_charges": 25,
"max_charges": 25,
"initial_charges": 20,
"max_charges": 20,
"charges_per_use": 1,
"use_action": {
"target": "torch_lit",
Expand All @@ -694,7 +695,8 @@
"need_fire": 1,
"menu_text": "Light torch",
"type": "transform"
}
},
"flags": [ "BURNOUT" ]
},
{
"id": "torch_lit",
Expand All @@ -710,9 +712,9 @@
"material": [ "wood" ],
"symbol": "/",
"color": "brown",
"initial_charges": 75,
"max_charges": 75,
"turns_per_charge": 40,
"initial_charges": 20,
"max_charges": 20,
"turns_per_charge": 60,
"revert_to": "torch_done",
"use_action": [
{ "type": "firestarter", "moves": 30 },
Expand All @@ -725,6 +727,6 @@
}
],
"techniques": [ "WBLOCK_1" ],
"flags": [ "FIRE", "LIGHT_310", "CHARGEDIM", "FLAMING", "TRADER_AVOID", "WATER_EXTINGUISH" ]
"flags": [ "FIRE", "LIGHT_310", "CHARGEDIM", "FLAMING", "TRADER_AVOID", "WATER_EXTINGUISH", "BURNOUT" ]
}
]
19 changes: 19 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static const std::string flag_HIDDEN_HALLU( "HIDDEN_HALLU" );
static const std::string flag_HIDDEN_POISON( "HIDDEN_POISON" );
static const std::string flag_HOT( "HOT" );
static const std::string flag_IRREMOVABLE( "IRREMOVABLE" );
static const std::string flag_BURNOUT( "BURNOUT" );
static const std::string flag_IS_ARMOR( "IS_ARMOR" );
static const std::string flag_IS_PET_ARMOR( "IS_PET_ARMOR" );
static const std::string flag_IS_UPS( "IS_UPS" );
Expand Down Expand Up @@ -3060,6 +3061,24 @@ void item::tool_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
} else if( has_flag( flag_USES_BIONIC_POWER ) ) {
info.emplace_back( "DESCRIPTION",
_( "* This tool <info>runs on bionic power</info>." ) );
} else if( has_flag( flag_BURNOUT ) && parts->test( iteminfo_parts::TOOL_BURNOUT ) ) {
int percent_left = 100 * ammo_remaining() / type->maximum_charges();
std::string feedback;
if( percent_left == 100 ) {
feedback = _( "It's new, and ready to burn." );
} else if( percent_left >= 75 ) {
feedback = _( "Almost new, with much material to burn." );
} else if( percent_left >= 50 ) {
feedback = _( "More than a quarter has burned away." );
} else if( percent_left >= 25 ) {
feedback = _( "More than half has burned away." );
} else if( percent_left >= 10 ) {
feedback = _( "Less than a quarter left to burn." );
} else {
feedback = _( "Almost completely burned out." );
}
feedback = _( "<bold>Fuel</bold>: " ) + feedback;
info.push_back( iteminfo( "DESCRIPTION", feedback ) );
}
}

Expand Down
1 change: 1 addition & 0 deletions src/iteminfo_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ enum class iteminfo_parts : size_t {
TOOL_MAGAZINE_CURRENT,
TOOL_MAGAZINE_COMPATIBLE,
TOOL_CAPACITY,
TOOL_BURNOUT,

DESCRIPTION_COMPONENTS_MADEFROM,
DESCRIPTION_COMPONENTS_DISASSEMBLE,
Expand Down
17 changes: 17 additions & 0 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,23 @@ TEST_CASE( "tool info", "[iteminfo][tool]" )
"<color_c_white>Charges</color>: 20\n" );
}

SECTION( "candle with feedback on burnout" ) {
std::vector<iteminfo_parts> burnout = { iteminfo_parts::TOOL_BURNOUT };

item candle( "candle" );
REQUIRE( candle.ammo_remaining() > 0 );

candle.charges = candle.type->maximum_charges();
CHECK( item_info_str( candle, burnout ) ==
"--\n"
"<color_c_white>Fuel</color>: It's new, and ready to burn.\n" );

candle.charges = ( candle.type->maximum_charges() / 2 ) - 1;
CHECK( item_info_str( candle, burnout ) ==
"--\n"
"<color_c_white>Fuel</color>: More than half has burned away.\n" );
}

SECTION( "UPS charged tool" ) {
std::vector<iteminfo_parts> recharge_ups = { iteminfo_parts::DESCRIPTION_RECHARGE_UPSMODDED };

Expand Down

0 comments on commit ae2aa53

Please sign in to comment.