Skip to content

Commit 4a811b8

Browse files
authored
Merge pull request #84437 from GuardianDll/matches
2 parents 331962b + 34f263c commit 4a811b8

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

data/json/items/ammo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"color": "red",
116116
"flags": [ "TRADER_AVOID" ],
117117
"material": [ "wood" ],
118+
"use_action": { "type": "firestarter", "moves": 500, "moves_slow": 6000, "qualities_needed": { "STRIKING_SURFACE": 1 } },
118119
"ammo_type": "match"
119120
},
120121
{

data/json/items/tool/fire.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
"symbol": ",",
180180
"color": "blue",
181181
"charges_per_use": 1,
182+
"qualities": [ [ "STRIKING_SURFACE", 1 ] ],
182183
"pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "holster": true, "ammo_restriction": { "match": 20 } } ],
183184
"//COMMENT": "Open flame or effectively so. ~5 seconds to transfer flame assuming optimal conditions, a minute at worst.",
184185
"use_action": { "type": "firestarter", "moves": 500, "moves_slow": 6000 },
@@ -221,6 +222,7 @@
221222
"symbol": ",",
222223
"color": "blue",
223224
"charges_per_use": 1,
225+
"qualities": [ [ "STRIKING_SURFACE", 1 ] ],
224226
"pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "holster": true, "ammo_restriction": { "match": 32 } } ],
225227
"//COMMENT": "Open flame or effectively so. ~5 seconds to transfer flame assuming optimal conditions, a minute at worst.",
226228
"use_action": { "type": "firestarter", "moves": 500, "moves_slow": 6000 },

data/json/tool_qualities.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,5 +471,11 @@
471471
"type": "tool_quality",
472472
"id": "THREAD_TAP",
473473
"name": { "str": "thread tapping" }
474+
},
475+
{
476+
"type": "tool_quality",
477+
"id": "STRIKING_SURFACE",
478+
"//": "If item can be used to ignite matches.",
479+
"name": { "str": "striking surface" }
474480
}
475481
]

doc/JSON/ITEM.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,8 @@ The contents of `use_action` fields can either be a string indicating a built-in
13331333
"type": "firestarter", // Start a fire, like with a lighter.
13341334
"moves": 15, // Number of moves it takes to start the fire. This is reduced by survival skill
13351335
"moves_slow": 1500, // Number of moves it takes to start a fire on something that is difficult to ignite. This is reduced by survival skill
1336-
"need_sunlight": true // Whether the character needs to be in direct sunlight, e.g. to use magnifying glasses
1336+
"need_sunlight": true, // Whether the character needs to be in direct sunlight, e.g. to use magnifying glasses,
1337+
"qualities_needed": { "WRENCH_FINE": 1 } // Tool qualities needed, e.g. "fine bolt turning 1"
13371338
},
13381339
"use_action": {
13391340
"type": "unpack", // Unpack this item

src/iuse_actor.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ void firestarter_actor::load( const JsonObject &obj, const std::string & )
13831383
optional( obj, false, "moves", moves_cost_fast, 100 );
13841384
optional( obj, false, "moves_slow", moves_cost_slow, 1000 );
13851385
optional( obj, false, "need_sunlight", need_sunlight, false );
1386+
optional( obj, false, "qualities_needed", qualities_needed );
13861387
}
13871388

13881389
std::unique_ptr<iuse_actor> firestarter_actor::clone() const
@@ -1532,6 +1533,30 @@ ret_val<void> firestarter_actor::can_use( const Character &p, const item &it,
15321533
return ret_val<void>::make_failure( _( "You need direct sunlight to light a fire with this." ) );
15331534
}
15341535

1536+
if( qualities_needed.empty() ) {
1537+
return ret_val<void>::make_success();
1538+
}
1539+
1540+
std::map<quality_id, int> unmet_reqs;
1541+
inventory inv;
1542+
inv.form_from_map( p.pos_bub( *here ), 1, &p, true, true );
1543+
for( const auto &quality : qualities_needed ) {
1544+
if( !p.has_quality( quality.first, quality.second ) &&
1545+
!inv.has_quality( quality.first, quality.second ) ) {
1546+
unmet_reqs.insert( quality );
1547+
}
1548+
}
1549+
if( unmet_reqs.empty() ) {
1550+
return ret_val<void>::make_success();
1551+
}
1552+
std::string unmet_reqs_string = enumerate_as_string( unmet_reqs.begin(), unmet_reqs.end(),
1553+
[&]( const std::pair<quality_id, int> &unmet_req ) {
1554+
return string_format( "%s %d", unmet_req.first.obj().name, unmet_req.second );
1555+
} );
1556+
return ret_val<void>::make_failure( n_gettext( "You need a tool with %s.",
1557+
"You need tools with %s.",
1558+
unmet_reqs.size() ), unmet_reqs_string );
1559+
15351560
return ret_val<void>::make_success();
15361561
}
15371562

src/iuse_actor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ class firestarter_actor : public iuse_actor
502502
*/
503503
bool need_sunlight = false;
504504

505+
/** Tool qualities needed, e.g. "fine bolt turning 1". **/
506+
std::map<quality_id, int> qualities_needed;
507+
505508
enum class start_type : int {
506509
NONE,
507510
FIRE,

0 commit comments

Comments
 (0)