Skip to content

Commit

Permalink
Scale crafting speed based on workbench
Browse files Browse the repository at this point in the history
- Numbers are mostly just placeholders right now
- Jsonize workbench stats
- Remove outdated flags
- Update documentation
  • Loading branch information
ifreund committed Apr 11, 2019
1 parent 1217c0b commit 40fd36c
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 81 deletions.
25 changes: 15 additions & 10 deletions data/json/furniture.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
"color": "light_red",
"move_cost_mod": 1,
"required_str": 8,
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "CONTAINER", "PLACE_ITEM", "ORGANIC", "MOUNTABLE", "FLAT_SURF", "WORKBENCH" ],
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "CONTAINER", "PLACE_ITEM", "ORGANIC", "MOUNTABLE", "FLAT_SURF" ],
"deconstruct": { "items": [ { "item": "2x4", "count": 4 }, { "item": "nail", "charges": [ 6, 10 ] } ] },
"max_volume": 4000,
"bash": {
Expand All @@ -755,7 +755,8 @@
"sound_fail": "whump.",
"items": [ { "item": "2x4", "count": [ 1, 3 ] }, { "item": "nail", "charges": [ 2, 6 ] }, { "item": "splinter", "count": 1 } ]
},
"examine_action": "workbench"
"examine_action": "workbench",
"workbench": { "multiplier": 1.0, "mass": 100000, "volume": "100L" }
},
{
"type": "furniture",
Expand Down Expand Up @@ -857,7 +858,7 @@
"move_cost_mod": 2,
"required_str": 8,
"max_volume": 4000,
"flags": [ "TRANSPARENT", "FLAMMABLE", "ORGANIC", "MOUNTABLE", "SHORT", "FLAT_SURF", "WORKBENCH" ],
"flags": [ "TRANSPARENT", "FLAMMABLE", "ORGANIC", "MOUNTABLE", "SHORT", "FLAT_SURF" ],
"deconstruct": { "items": [ { "item": "2x4", "count": 6 }, { "item": "nail", "charges": [ 6, 8 ] } ] },
"bash": {
"str_min": 12,
Expand All @@ -866,7 +867,8 @@
"sound_fail": "whump.",
"items": [ { "item": "2x4", "count": [ 2, 6 ] }, { "item": "nail", "charges": [ 4, 8 ] }, { "item": "splinter", "count": 1 } ]
},
"examine_action": "workbench"
"examine_action": "workbench",
"workbench": { "multiplier": 1.0, "mass": 100000, "volume": "100L" }
},
{
"type": "furniture",
Expand Down Expand Up @@ -970,7 +972,7 @@
"color": "blue",
"move_cost_mod": 2,
"required_str": 10,
"flags": [ "TRANSPARENT", "FLAMMABLE", "ORGANIC", "MOUNTABLE", "SHORT", "FLAT_SURF", "WORKBENCH" ],
"flags": [ "TRANSPARENT", "FLAMMABLE", "ORGANIC", "MOUNTABLE", "SHORT", "FLAT_SURF" ],
"deconstruct": { "items": [ { "item": "2x4", "count": 6 }, { "item": "nail", "charges": [ 6, 8 ] } ] },
"max_volume": 4000,
"bash": {
Expand All @@ -980,7 +982,8 @@
"sound_fail": "whump.",
"items": [ { "item": "2x4", "count": [ 2, 6 ] }, { "item": "nail", "charges": [ 4, 8 ] }, { "item": "splinter", "count": 1 } ]
},
"examine_action": "workbench"
"examine_action": "workbench",
"workbench": { "multiplier": 1.0, "mass": 100000, "volume": "100L" }
},
{
"type": "furniture",
Expand Down Expand Up @@ -4456,7 +4459,7 @@
"move_cost_mod": 2,
"required_str": -1,
"looks_like": "f_counter",
"flags": [ "TRANSPARENT", "PLACE_ITEM", "MOUNTABLE", "FLAT_SURF", "WORKBENCH2" ],
"flags": [ "TRANSPARENT", "PLACE_ITEM", "MOUNTABLE", "FLAT_SURF" ],
"deconstruct": {
"items": [
{ "item": "pipe", "count": [ 6, 12 ] },
Expand All @@ -4483,7 +4486,8 @@
{ "item": "cu_pipe", "count": 1 }
]
},
"examine_action": "workbench"
"examine_action": "workbench",
"workbench": { "multiplier": 1.1, "mass": 100000, "volume": "100L" }
},
{
"type": "furniture",
Expand Down Expand Up @@ -5524,7 +5528,7 @@
"move_cost_mod": 2,
"required_str": -1,
"looks_like": "f_lab_bench",
"flags": [ "TRANSPARENT", "PLACE_ITEM", "MOUNTABLE", "FLAT_SURF", "WORKBENCH3" ],
"flags": [ "TRANSPARENT", "PLACE_ITEM", "MOUNTABLE", "FLAT_SURF" ],
"deconstruct": {
"items": [
{ "item": "pipe", "count": [ 6, 8 ] },
Expand All @@ -5546,6 +5550,7 @@
{ "item": "scrap", "count": [ 12, 24 ] }
]
},
"examine_action": "workbench"
"examine_action": "workbench",
"workbench": { "multiplier": 1.2, "mass": 100000, "volume": "100L" }
}
]
25 changes: 14 additions & 11 deletions data/json/vehicle_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -969,12 +969,13 @@
"item": "v_table",
"difficulty": 1,
"location": "center",
"flags": [ "CARGO", "OBSTACLE", "TOOL_WRENCH", "FLAT_SURF", "WORKBENCH1" ],
"flags": [ "CARGO", "OBSTACLE", "TOOL_WRENCH", "FLAT_SURF", "WORKBENCH" ],
"breaks_into": [
{ "item": "2x4", "count": [ 1, 6 ] },
{ "item": "splinter", "count": [ 4, 6 ] },
{ "item": "nail", "charges": [ 4, 7 ] }
]
],
"workbench": { "multiplier": 1.0, "mass": 100000, "volume": "100L" }
},
{
"type": "vehicle_part",
Expand All @@ -990,12 +991,13 @@
"item": "w_table",
"difficulty": 1,
"location": "center",
"flags": [ "CARGO", "OBSTACLE", "TOOL_WRENCH", "FLAT_SURF", "WORKBENCH1" ],
"flags": [ "CARGO", "OBSTACLE", "TOOL_WRENCH", "FLAT_SURF", "WORKBENCH" ],
"breaks_into": [
{ "item": "2x4", "count": [ 1, 6 ] },
{ "item": "splinter", "count": [ 4, 6 ] },
{ "item": "nail", "charges": [ 4, 7 ] }
]
],
"workbench": { "multiplier": 1.0, "mass": 100000, "volume": "100L" }
},
{
"type": "vehicle_part",
Expand All @@ -1012,14 +1014,15 @@
"item": "workbench",
"difficulty": 1,
"location": "center",
"flags": [ "CARGO", "OBSTACLE", "TOOL_WRENCH", "FLAT_SURF", "WORKBENCH2" ],
"flags": [ "CARGO", "OBSTACLE", "TOOL_WRENCH", "FLAT_SURF", "WORKBENCH" ],
"breaks_into": [
{ "item": "pipe", "count": [ 4, 6 ] },
{ "item": "sheet_metal", "count": [ 0, 1 ] },
{ "item": "sheet_metal_small", "count": [ 12, 24 ] },
{ "item": "steel_chunk", "count": [ 4, 8 ] },
{ "item": "scrap", "count": [ 12, 24 ] }
]
{ "item": "pipe", "count": [ 4, 6 ] },
{ "item": "sheet_metal", "count": [ 0, 1 ] },
{ "item": "sheet_metal_small", "count": [ 12, 24 ] },
{ "item": "steel_chunk", "count": [ 4, 8 ] },
{ "item": "scrap", "count": [ 12, 24 ] }
],
"workbench": { "multiplier": 1.2, "mass": 100000, "volume": "100L" }
},
{
"type": "vehicle_part",
Expand Down
10 changes: 2 additions & 8 deletions data/json/vehicleparts/vp_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,9 @@
"info": "This has a flat surface. It would be a nice place to eat."
},
{
"id": "WORKBENCH1",
"id": "WORKBENCH",
"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."
"info": "You can craft here."
}
]
9 changes: 3 additions & 6 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ List of known flags, used in both terrain.json and furniture.json
- ```FLAMMABLE_ASH``` Burns to ash rather than rubble.
- ```FLAMMABLE_HARD``` Harder to light on fire, but still possible.
- ```FLAT``` Player can build and move furniture on.
- ```FLAT_SURF``` Furniture or terrain with flat hard surface (e.g. table, but not chair; tree stump, etc.).
- ```FLAT_SURF``` Furniture or terrain with a flat hard surface (e.g. table, but not chair; tree stump, etc.).
- ```GOES_DOWN``` Can use <kbd>></kbd> to go down a level.
- ```GOES_UP``` Can use <kbd><</kbd> to go up a level.
- ```HARVESTED``` Marks the harvested version of a terrain type (e.g. harvesting an apple tree turns it into a harvested tree, which later becomes an apple tree again).
Expand Down Expand Up @@ -152,7 +152,6 @@ List of known flags, used in both terrain.json and furniture.json
- ```toilet``` Either drink or get water out of the toilet.
- ```trap``` Interact with a trap.
- ```water_source``` Drink or get water from a water source.
- ```workbench``` Craft items on the furniture, or continue an in progress craft. Should be paired with a ```WORKBENCH1```/```WORKBENCH2```/```WORKBENCH3``` flag.
### Currently only used for Fungal conversions
Expand All @@ -166,8 +165,6 @@ List of known flags, used in both terrain.json and furniture.json
### Furniture only
- ```BLOCKSDOOR``` This will boost map terrain's resistance to bashing if `str_*_blocked` is set (see `map_bash_info`)
- ```WORKBENCH1```/```WORKBENCH2```/```WORKBENCH3``` This is an adequate/good/great workbench for crafting. Should be paired with a workbench iexamine.
## Monsters
Expand Down Expand Up @@ -513,7 +510,7 @@ These branches are also the valid entries for the categories of `dreams` in `dre
- ```EVENTURN``` Only on during even turns.
- ```EXTRA_DRAG``` tells the vehicle that the part exerts engine power reduction.
- ```FAUCET```
- ```FLAT_SURF``` Part with flat hard surface (e.g. table).
- ```FLAT_SURF``` Part with a flat hard surface (e.g. table).
- ```FOLDABLE```
- ```FORGE``` Acts as a forge for crafting.
- ```FRIDGE``` Can refrigerate items.
Expand Down Expand Up @@ -580,7 +577,7 @@ These branches are also the valid entries for the categories of `dreams` in `dre
- ```WASHING_MACHINE``` Can be used to wash filthy clothes en masse.
- ```WATER_WHEEL``` Recharges vehicle batteries when in flowing water.
- ```WINDOW``` Can see through this part and can install curtains over it.
- ```WORKBENCH1```/```WORKBENCH2``` Craft items on the vehicle part, or continue an in progress craft.
- ```WORKBENCH``` Can craft at this part, must be paired with a workbench json entry.
## Ammo

This comment has been minimized.

Copy link
@josemerca1969

josemerca1969 Apr 11, 2019

Workbench1

Expand Down
16 changes: 11 additions & 5 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1630,8 +1630,8 @@ Optional message to be printed when a creature using the harvest definition is b

#### `entries`

Array of dictionaries defining possible items produced on butchering and their likelihood of being produced.
`drop` value should be the `id` string of the item to be produced.
Array of dictionaries defining possible items produced on butchering and their likelihood of being produced.
`drop` value should be the `id` string of the item to be produced.
Acceptable values are as follows:
`flesh`: the "meat" of the creature.
`offal`: the "organs" of the creature. these are removed when field dressing.
Expand All @@ -1642,7 +1642,7 @@ Acceptable values are as follows:

`type` value should be a string with the associated body part the item comes from.

`base_num` value should be an array with two elements in which the first defines the minimum number of the corresponding item produced and the second defines the maximum number.
`base_num` value should be an array with two elements in which the first defines the minimum number of the corresponding item produced and the second defines the maximum number.

`scale_num` value should be an array with two elements, increasing the minimum and maximum drop numbers respectively by element value * survival skill.

Expand All @@ -1660,14 +1660,16 @@ Acceptable values are as follows:
"color": "white",
"move_cost_mod": 2,
"required_str": 18,
"flags": ["TRANSPARENT", "BASHABLE", "FLAMMABLE_HARD"],
"flags": [ "TRANSPARENT", "BASHABLE", "FLAMMABLE_HARD" ],
"crafting_pseudo_item": "anvil",
"examine_action": "toilet",
"close": "f_foo_closed",
"open": "f_foo_open",
"bash": "TODO",
"deconstruct": "TODO",
"max_volume": 4000
"max_volume": 4000,
"examine_action": "workbench",
"workbench": { "multiplier": 1.1, "mass": 10000, "volume": "50L" }
}
```

Expand All @@ -1691,6 +1693,10 @@ Strength required to move the furniture around. Negative values indicate an unmo

(Optional) Id of an item (tool) that will be available for crafting when this furniture is range (the furniture acts as an item of that type).

#### `workbench`

(Optional) Can craft here. Must specify a speed multiplier, allowed mass, and allowed volume. Mass/volume over these limits incur a speed penalty. Must be paired with a `"workbench"` `examine_action` to function.

### Terrain

```C++
Expand Down
70 changes: 35 additions & 35 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "vehicle_selector.h"
#include "vpart_position.h"
#include "vpart_reference.h"
#include "veh_type.h"

const efftype_id effect_contacts( "contacts" );

Expand Down Expand Up @@ -110,55 +111,54 @@ float player::morale_crafting_speed_multiplier( const recipe &rec ) const
return 1.0f / morale_effect;
}

static float workbench_crafting_speed_multiplier( const tripoint &loc )
static float workbench_crafting_speed_multiplier( const recipe &rec, const tripoint &loc )
{
// tripoint_zero indicates crafting from inventory, so no effect
if( loc == tripoint_zero ) {
return 1.0f;
}

int workbench_level = 0;
float multiplier = 1.0;
units::mass allowed_mass = 60_kilogram;
units::volume allowed_volume = 100000_ml;

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;
// tripoint_zero indicates crafting from inventory
if( loc == tripoint_zero ) {
// Do nothing
} else if( const cata::optional<vpart_reference> vp = g->m.veh_at(
loc ).part_with_feature( "WORKBENCH", true ) ) {
const vpart_info &vp_info = vp->part().info();
if( const cata::optional<vpslot_workbench> &wb_info = vp_info.get_workbench_info() ) {
multiplier = wb_info->multiplier;
allowed_mass = wb_info->allowed_mass;
allowed_volume = wb_info->allowed_volume;
}
} 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;
} else if( g->m.has_furn( loc ) ) {
const furn_t &f = g->m.furn( loc ).obj();
if( f.workbench ) {
multiplier = f.workbench->multiplier;
allowed_mass = f.workbench->allowed_mass;
allowed_volume = f.workbench->allowed_volume;
}
}
std::cout << "mult: " << multiplier << " mass: " << allowed_mass << " volume: " << allowed_volume <<
std::endl;

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;
}
const item result = rec.create_result();
const units::mass &result_mass = result.weight();
const units::volume &result_volume = result.volume();

if( result_mass > allowed_mass ) {
multiplier *= .9f;
}
if( result_volume > allowed_volume ) {
multiplier *= .9f;
}

return multiplier;
}

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 );
workbench_crafting_speed_multiplier( rec, 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
19 changes: 19 additions & 0 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ bool map_deconstruct_info::load( JsonObject &jsobj, const std::string &member, b
return true;
}

furn_workbench_info::furn_workbench_info() : multiplier( 1.0f ), allowed_mass( units::mass_max ),
allowed_volume( units::volume_max ) {}

bool furn_workbench_info::load( JsonObject &jsobj, const std::string &member )
{
JsonObject j = jsobj.get_object( member );

assign( j, "multiplier", multiplier );
assign( j, "mass", allowed_mass );
assign( j, "volume", allowed_volume );

return true;
}

furn_t null_furniture_t()
{
furn_t new_furniture;
Expand Down Expand Up @@ -1195,6 +1209,11 @@ void furn_t::load( JsonObject &jo, const std::string &src )

bash.load( jo, "bash", true );
deconstruct.load( jo, "deconstruct", true );

if( jo.has_object( "workbench" ) ) {
workbench = furn_workbench_info();
workbench->load( jo, "workbench" );
}
}

void map_data_common_t::check() const
Expand Down
Loading

0 comments on commit 40fd36c

Please sign in to comment.