Skip to content

Commit

Permalink
Add simple workbench crafting bonus
Browse files Browse the repository at this point in the history
- plus various small fixes and tweaks
  • Loading branch information
ifreund committed Apr 11, 2019
1 parent dbcb8ee commit f160ee2
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/json/items/vehicle_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"type": "GENERIC",
"id": "workbench",
"name": "workbench",
"description": "A crude wooden table.",
"description": "A sturdy workbench built out of metal. It is perfect for crafting large and heavy things.",
"weight": 23000,
"to_hit": -8,
"color": "red",
Expand Down
18 changes: 18 additions & 0 deletions data/json/vehicleparts/vp_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,23 @@
"type": "json_flag",
"context": [ "vehicle_part" ],
"info": "If the center of balance of your vehicle is between all the wheels, the vehicle will be able to move, provided it has an active engine or motor with enough power to move the vehicle."
},
{
"id": "FLAT_SURF",
"type": "json_flag",
"context": [ "vehicle_part" ],
"info": "This has a flat surface. It would be a nice place to eat."
},
{
"id": "WORKBENCH1",
"type": "json_flag",
"context": [ "vehicle_part" ],
"info": "You can craft here, though a proper workbench would be better."
},
{
"id": "WORKBENCH2",
"type": "json_flag",
"context": [ "vehicle_part" ],
"info": "A sturdy metal workbench bolted in place. This is a good place to craft, though crafting in a vehicle is still a little cramped."
}
]
9 changes: 4 additions & 5 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2653,7 +2653,9 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
}

const recipe &rec = craft->get_making();
const float crafting_speed = p->crafting_speed_multiplier( rec, true );
const tripoint loc = act->targets.front().where() == item_location::type::character ?
tripoint_zero : act->targets.front().position();
const float crafting_speed = p->crafting_speed_multiplier( rec, true, loc );
const bool is_long = act->values[0];

if( crafting_speed <= 0.0f ) {
Expand All @@ -2676,7 +2678,7 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
// Base moves for batch size with no speed modifier or assistants
const double base_total_moves = rec.batch_time( craft->charges, 1.0f, 0 );
// Current expected total moves, includes crafting speed modifiers and assistants
const double cur_total_moves = p->expected_time_to_craft( rec, craft->charges );
const double cur_total_moves = p->expected_time_to_craft( rec, craft->charges, true, loc );
// Delta progress in moves adjusted for current crafting speed
const double delta_progress = p->get_moves() * base_total_moves / cur_total_moves;
// Current progress in moves
Expand All @@ -2688,9 +2690,6 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
// if item_counter has reached 100% or more
if( craft->item_counter >= 10000 ) {
item craft_copy = *craft;
const tripoint loc = act->targets.front().where() == item_location::type::character ?
tripoint_zero :
act->targets.front().position();
act->targets.front().remove_item();
p->cancel_activity();
p->complete_craft( craft_copy, loc );
Expand Down
55 changes: 51 additions & 4 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,55 @@ float player::morale_crafting_speed_multiplier( const recipe &rec ) const
return 1.0f / morale_effect;
}

float player::crafting_speed_multiplier( const recipe &rec, bool in_progress ) const
static float workbench_crafting_speed_multiplier( const tripoint &loc )
{
float result = morale_crafting_speed_multiplier( rec ) * lighting_craft_speed_multiplier( rec );
// tripoint_zero indicates crafting from inventory, so no effect
if( loc == tripoint_zero ) {
return 1.0f;
}

int workbench_level = 0;

if( const optional_vpart_position vp = g->m.veh_at( loc ) ) {
const point loc_point( loc.x, loc.y );
if( vp->vehicle().avail_part_with_feature( loc_point, "WORKBENCH1", true ) ) {
workbench_level = 1;
} else if( vp->vehicle().avail_part_with_feature( loc_point, "WORKBENCH2", true ) ) {
workbench_level = 2;
}
} else {
if( g->m.has_flag_furn( "WORKBENCH1", loc ) ) {
workbench_level = 1;
} else if( g->m.has_flag_furn( "WORKBENCH2", loc ) ) {
workbench_level = 2;
} else if( g->m.has_flag_furn( "WORKBENCH3", loc ) ) {
workbench_level = 3;
}
}

switch( workbench_level ) {
case 3: {
return 1.2f;
}
case 2: {
return 1.1f;
}
case 1: {
return 1.0f;
}
default: {
// If there is no workbench impose a 10% penalty
return 0.9f;
}
}
}

float player::crafting_speed_multiplier( const recipe &rec, bool in_progress,
const tripoint &loc ) const
{
float result = morale_crafting_speed_multiplier( rec ) *
lighting_craft_speed_multiplier( rec ) *
workbench_crafting_speed_multiplier( loc );
// Can't start if we'd need 300% time, but we can still finish the job
if( !in_progress && result < 0.33f ) {
return 0.0f;
Expand Down Expand Up @@ -196,10 +242,11 @@ int player::base_time_to_craft( const recipe &rec, int batch_size ) const
return rec.batch_time( batch_size, 1.0f, assistants );
}

int player::expected_time_to_craft( const recipe &rec, int batch_size ) const
int player::expected_time_to_craft( const recipe &rec, int batch_size, bool in_progress,
const tripoint &loc ) const
{
const size_t assistants = available_assistant_count( *this, rec );
float modifier = crafting_speed_multiplier( rec );
float modifier = crafting_speed_multiplier( rec, in_progress, loc );
return rec.batch_time( batch_size, modifier, assistants );
}

Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3188,7 +3188,7 @@ void game::debug()
#if defined(TILES)
const point offset {
POSX - u.posx() + u.view_offset.x,
POSY - u.posy() + u.view_offset.y
POSY - u.posy() + u.view_offset.y
};
draw_ter();
auto sounds_to_draw = sounds::get_monster_sounds();
Expand Down
2 changes: 2 additions & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ struct map_deconstruct_info {
*
* Furniture only:
* BLOCKSDOOR - This will boost map terrain's resistance to bashing if str_*_blocked is set (see map_bash_info)
* FLAT_SURF - This is required for full butchery and gives a morale bonus while eating.
* WORKBENCH1/WORKBENCH2/WORKBENCH3 - This is an adequate/good/great workbench for crafting. Should be paired with a workbench iexamine.
*/

/*
Expand Down
6 changes: 4 additions & 2 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,17 @@ class player : public Character
// crafting.cpp
float morale_crafting_speed_multiplier( const recipe &rec ) const;
float lighting_craft_speed_multiplier( const recipe &rec ) const;
float crafting_speed_multiplier( const recipe &rec, bool in_progress = false ) const;
float crafting_speed_multiplier( const recipe &rec, bool in_progress = false,
const tripoint &loc = tripoint_zero ) const;
/**
* Time to craft not including speed multiplier
*/
int base_time_to_craft( const recipe &rec, int batch_size = 1 ) const;
/**
* Expected time to craft a recipe, with assumption that multipliers stay constant.
*/
int expected_time_to_craft( const recipe &rec, int batch_size = 1 ) const;
int expected_time_to_craft( const recipe &rec, int batch_size = 1, bool in_progress = false,
const tripoint &loc = tripoint_zero ) const;
std::vector<const item *> get_eligible_containers_for_crafting() const;
bool check_eligible_containers_for_crafting( const recipe &rec, int batch_size = 1 ) const;
bool has_morale_to_craft() const;
Expand Down

0 comments on commit f160ee2

Please sign in to comment.