Skip to content

Commit

Permalink
Move default item spawning out of sourcefiles, allow placement of rei…
Browse files Browse the repository at this point in the history
…nforced vending machines
  • Loading branch information
John-Candlebury committed Sep 13, 2017
1 parent 0422836 commit 3efc637
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
4 changes: 2 additions & 2 deletions data/json/item_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@
]
},{
"type" : "item_group",
"id" : "vending_food",
"id" : "vending_food_items",
"items":[
["chips", 65],
["fried_seeds", 25],
Expand Down Expand Up @@ -1163,7 +1163,7 @@
]
},{
"type" : "item_group",
"id" : "vending_drink",
"id" : "vending_drink_items",
"items":[
["water_clean", 90],
["water_mineral", 10],
Expand Down
40 changes: 40 additions & 0 deletions data/json/itemgroups/vending_machines.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"type" : "item_group",
"id" : "default_vending_machine",
"entries":[
{ "group": "vending_drink", "chance": 50},
{ "group": "vending_drink", "chance": 50}
]
},{
"type" : "item_group",
"subtype" : "collection",
"id" : "vending_food",
"entries":[
{ "group": "vending_food_items", "count-min": 5, "count-max": 20 },
{ "group": "vending_food_items", "prob": 66, "count-min": 5, "count-max": 25 },
{ "group": "vending_food_items", "prob": 20, "count-min": 5, "count-max": 25 }
]
},{
"type" : "item_group",
"subtype" : "collection",
"id" : "vending_drink",
"entries":[
{ "group": "vending_drink_items", "count-min": 5, "count-max": 20 },
{ "group": "vending_drink_items", "prob": 66, "count-min": 5, "count-max": 25 },
{ "group": "vending_drink_items", "prob": 20, "count-min": 5, "count-max": 25 }
]
},{
"type" : "item_group",
"subtype" : "collection",
"id" : "vending_ammo",
"entries":[
{ "group": "ammo_pistol_common", "count-min": 3, "count-max": 8 },
{ "group": "ammo_rifle_common", "prob": 50, "count-min": 2, "count-max": 6 },
{ "group": "ammo_shotgun_common", "prob": 50, "count-min": 2, "count-max": 6 },
{ "group": "ammo_pistol_rare", "prob": 20, "count-min": 1, "count-max": 2 },
{ "group": "ammo_rifle_rare", "prob": 20, "count-min": 1, "count-max": 2 },
{ "group": "ammo_shotgun_rare", "prob": 20, "count-min": 1, "count-max": 2 }
]
}
]
2 changes: 1 addition & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ void add_corpse( const tripoint &p );
void place_gas_pump(const int x, const int y, const int charges);
void place_gas_pump(const int x, const int y, const int charges, std::string fuel_type);
void place_toilet(const int x, const int y, const int charges = 6 * 4); // 6 liters at 250 ml per charge
void place_vending(int x, int y, std::string type);
void place_vending(int x, int y, std::string type, bool reinforced = false );
int place_npc( int x, int y, const string_id<npc_template> &type );

void add_spawn(const mtype_id& type, const int count, const int x, const int y, bool friendly = false,
Expand Down
3 changes: 2 additions & 1 deletion src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ furn_id f_null,
f_floor_canvas,
f_tatami,
f_kiln_empty, f_kiln_full, f_kiln_metal_empty, f_kiln_metal_full,
f_robotic_arm;
f_robotic_arm, f_vending_reinforced;

void set_furn_ids() {
f_null = furn_id( "f_null" );
Expand Down Expand Up @@ -857,6 +857,7 @@ void set_furn_ids() {
f_dryer = furn_id( "f_dryer" );
f_vending_c = furn_id( "f_vending_c" );
f_vending_o = furn_id( "f_vending_o" );
f_vending_reinforced = furn_id( "f_vending_reinforced" );
f_dumpster = furn_id( "f_dumpster" );
f_dive_block = furn_id( "f_dive_block" );
f_crate_c = furn_id( "f_crate_c" );
Expand Down
2 changes: 1 addition & 1 deletion src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ extern furn_id f_null,
f_flower_marloss,
f_tatami,
f_kiln_empty, f_kiln_full, f_kiln_metal_empty, f_kiln_metal_full,
f_robotic_arm;
f_robotic_arm, f_vending_reinforced;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// These are on their way OUT and only used in certain switch statements until they are rewritten.
Expand Down
23 changes: 15 additions & 8 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,11 @@ class jmapgen_sign : public jmapgen_piece {
*/
class jmapgen_vending_machine : public jmapgen_piece {
public:
bool reinforced;
std::string item_group_id;
jmapgen_vending_machine( JsonObject &jsi ) : jmapgen_piece()
, item_group_id( jsi.get_string( "item_group", one_in( 2 ) ? "vending_food" : "vending_drink" ) )
, item_group_id( jsi.get_string( "item_group", "default_vending_machine" ) )
, reinforced( jsi.get_bool( "reinforced", false ) )
{
if( !item_group::group_is_defined( item_group_id ) ) {
jsi.throw_error( "no such item group", "item_group" );
Expand All @@ -719,7 +721,7 @@ class jmapgen_vending_machine : public jmapgen_piece {
const int rx = x.get();
const int ry = y.get();
m.furn_set( rx, ry, f_null );
m.place_vending( rx, ry, item_group_id );
m.place_vending( rx, ry, item_group_id, reinforced );
}
};
/**
Expand Down Expand Up @@ -8454,15 +8456,20 @@ void map::place_toilet(int x, int y, int charges)
furn_set(x, y, f_toilet);
}

void map::place_vending(int x, int y, std::string type)
void map::place_vending(int x, int y, std::string type, bool reinforced)
{
const bool broken = one_in(5);
if( broken ) {
furn_set(x, y, f_vending_o);
if ( reinforced ) {
furn_set( x, y, f_vending_reinforced );
place_items( type, 100, x, y, x, y, false, 0 );
} else {
furn_set(x, y, f_vending_c);
const bool broken = one_in( 5 );
if( broken ) {
furn_set(x, y, f_vending_o);
} else {
furn_set(x, y, f_vending_c);
place_items( type, 100, x, y, x, y, false, 0 );
}
}
place_items( type, broken ? 40 : 99, x, y, x, y, false, 0 );
}

int map::place_npc( int x, int y, const string_id<npc_template> &type )
Expand Down

0 comments on commit 3efc637

Please sign in to comment.