Skip to content

Commit

Permalink
Merge pull request #38239 from Fris0uman/dark_build
Browse files Browse the repository at this point in the history
Make spots craftable in the dark
  • Loading branch information
kevingranade authored Feb 22, 2020
2 parents 5c80905 + 58ad188 commit 14a261e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions data/json/construction.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"pre_note": "Mark a spot for crafting. Crafting tasks next to this tile will automatically use this location instead of attempting to craft in your hands, with the usual crafting speed penalty for working on the ground. Does not prevent using a proper workbench, if available. Deconstruct or smash to remove.",
"pre_special": "check_empty",
"post_flags": [ "keep_items" ],
"dark_craftable": true,
"post_terrain": "f_ground_crafting_spot"
},
{
Expand Down Expand Up @@ -3040,6 +3041,7 @@
"pre_note": "Firewood or other flammable materials on a nearby tile marked in this way may be used to automatically refuel fires. This will be done to maintain light during long-running tasks that require it such as crafting or reading, but not (for example) if you are simply waiting nearby.",
"pre_special": "check_no_trap",
"post_special": "done_mark_firewood",
"dark_craftable": true,
"post_flags": [ "keep_items" ]
},
{
Expand All @@ -3052,6 +3054,7 @@
"pre_note": "Mark a spot for target practice. Firing will automatically target the first practice target location found in gun range, if no enemies are around.",
"pre_special": "check_no_trap",
"post_special": "done_mark_practice_target",
"dark_craftable": true,
"post_flags": [ "keep_items" ]
},
{
Expand Down
21 changes: 13 additions & 8 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,10 @@ construction_id construction_menu( const bool blueprint )
}
if( !blueprint ) {
if( player_can_build( g->u, total_inv, constructs[select] ) ) {
if( g->u.fine_detail_vision_mod() > 4 && !g->u.has_trait( trait_DEBUG_HS ) ) {
add_msg( m_info, _( "It is too dark to construct right now." ) );
} else {
place_construction( constructs[select] );
uistate.last_construction = constructs[select];
}
place_construction( constructs[select] );
uistate.last_construction = constructs[select];
exit = true;
} else {
popup( _( "You can't build that!" ) );
draw_grid( w_con, w_list_width + w_list_x0 );
update_info = true;
}
Expand Down Expand Up @@ -738,14 +733,23 @@ bool player_can_build( player &p, const inventory &inv, const std::string &desc

bool player_can_build( player &p, const inventory &inv, const construction &con )
{

if( p.has_trait( trait_DEBUG_HS ) ) {
return true;
}

if( !p.meets_skill_requirements( con ) ) {
return false;
}
return con.requirements->can_make_with_inventory( inv, is_crafting_component );

const bool can_build = con.requirements->can_make_with_inventory( inv, is_crafting_component );
if( !can_build ) {
popup( _( "You can't build that!" ) );
} else if( g->u.fine_detail_vision_mod() > 4 && !con.dark_craftable ) {
popup( _( "It is too dark to construct right now." ) );
return false;
}
return can_build;
}

bool can_construct( const std::string &desc )
Expand Down Expand Up @@ -1456,6 +1460,7 @@ void load_construction( const JsonObject &jo )
con.vehicle_start = jo.get_bool( "vehicle_start", false );

con.on_display = jo.get_bool( "on_display", true );
con.dark_craftable = jo.get_bool( "dark_craftable", false );

constructions.push_back( con );
construction_id_map.emplace( con.str_id, con.id );
Expand Down
3 changes: 3 additions & 0 deletions src/construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ struct construction {

// make the construction available for selection
bool on_display = true;

//can be build in the dark
bool dark_craftable = false;
private:
std::string get_time_string() const;
};
Expand Down

0 comments on commit 14a261e

Please sign in to comment.