Skip to content

Commit

Permalink
rename mapgen: { type: (builtin|lua|json), ..} from type to method, d…
Browse files Browse the repository at this point in the history
…ue to clash with convention
  • Loading branch information
atomicdryad committed Nov 27, 2013
1 parent f7b0721 commit 04e45ea
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 47 deletions.
89 changes: 47 additions & 42 deletions data/json/overmap_terrain.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"extras" : "field",
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "field_test", "weight": -1, "comment": "weight < 1 disabbles" },
{ "type": "lua", "weight": 500, "comment": "Inlined, easier to edit", "script": [
{ "method": "builtin", "name": "field", "weight": -1, "comment": "weight < 1 disables" },
{ "method": "builtin", "name": "field_test", "weight": -1, "comment": "weight < 1 disables" },
{ "method": "lua", "weight": 500, "comment": "Inlined, easier to edit", "script": [
"-- tertype, turn = ...",
"function g_or_d_or_p()",
" if game.one_in(6) then",
Expand All @@ -60,7 +61,7 @@
"game.add_msg(\"generated oter=\"..tertype..\" turn=\"..turn)"
]
},
{ "type": "json", "object": {
{ "method": "json", "object": {
"rows":[
"000000000000000000000000",
"000000000000000000000000",
Expand Down Expand Up @@ -104,8 +105,12 @@
[ "7", "f_makeshift_bed" ]
],
"spawn_items": [
{ "type": "prozac", "x": [ 0, 23 ], "y": [ 0, 23 ], "amount": [ 1, 23 ] },
{ "type": "badge_deputy", "x": 6, "y": 6, "amount": 1 }
{ "method": "prozac", "x": [ 0, 23 ], "y": [ 0, 23 ], "amount": [ 1, 23 ] },
{ "method": "badge_deputy", "x": 6, "y": 6, "amount": 1 }
],
"set": [
{ "set": "trap", "x": [ 0, 23 ], "y": [ 0, 23 ], "id": "tr_beartrap", "chance": 2, "repeat": 35 },
{ "set": "terrain", "x": [ 0, 23 ], "y": [ 0, 23 ], "id": "t_water_sh", "repeat": [ 15, 60 ] }
]
}, "weight": 2000 }
]
Expand All @@ -128,7 +133,7 @@
"extras" : "field",
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "forest" }
{ "method": "builtin", "name": "forest" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -140,7 +145,7 @@
"extras" : "field",
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "forest" }
{ "method": "builtin", "name": "forest" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -152,7 +157,7 @@
"extras" : "road",
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "highway" }
{ "method": "builtin", "name": "highway" }
]

},{
Expand All @@ -165,7 +170,7 @@
"extras" : "road",
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "highway" }
{ "method": "builtin", "name": "highway" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -186,16 +191,16 @@
"allow_road" : true,
"comment" : "the entries below are optional and serve as an example of mapgen for line_drawing tiles",
"mapgen_straight": [
{ "type": "builtin", "name": "road_straight" }
{ "method": "builtin", "name": "road_straight" }
],
"mapgen_curved": [
{ "type": "builtin", "name": "road_curved" }
{ "method": "builtin", "name": "road_curved" }
],
"mapgen_tee": [
{ "type": "builtin", "name": "road_tee" }
{ "method": "builtin", "name": "road_tee" }
],
"mapgen_four_way": [
{ "type": "builtin", "name": "road_four_way" }
{ "method": "builtin", "name": "road_four_way" }
]

},{
Expand All @@ -209,7 +214,7 @@
"known_down" : true,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "road_four_way" }
{ "method": "builtin", "name": "road_four_way" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -220,7 +225,7 @@
"see_cost" : 2,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "bridge" }
{ "method": "builtin", "name": "bridge" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -231,7 +236,7 @@
"see_cost" : 2,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "bridge" }
{ "method": "builtin", "name": "bridge" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -242,7 +247,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_center" }
{ "method": "builtin", "name": "river_center" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -254,7 +259,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_straight" }
{ "method": "builtin", "name": "river_straight" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -265,7 +270,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved_not" }
{ "method": "builtin", "name": "river_curved_not" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -276,7 +281,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved_not" }
{ "method": "builtin", "name": "river_curved_not" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -287,7 +292,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved_not" }
{ "method": "builtin", "name": "river_curved_not" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -298,7 +303,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved_not" }
{ "method": "builtin", "name": "river_curved_not" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -309,7 +314,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved" }
{ "method": "builtin", "name": "river_curved" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -320,7 +325,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved" }
{ "method": "builtin", "name": "river_curved" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -331,7 +336,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved" }
{ "method": "builtin", "name": "river_curved" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -342,7 +347,7 @@
"see_cost" : 1,
"allow_road" : true,
"mapgen": [
{ "type": "builtin", "name": "river_curved" }
{ "method": "builtin", "name": "river_curved" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -356,9 +361,9 @@
"mondensity" : 2,
"sidewalk" : true,
"mapgen": [
{ "type": "builtin", "name": "house_generic_boxy" },
{ "type": "builtin", "name": "house_generic_big_livingroom" },
{ "type": "builtin", "name": "house_generic_center_hallway" }
{ "method": "builtin", "name": "house_generic_boxy" },
{ "method": "builtin", "name": "house_generic_big_livingroom" },
{ "method": "builtin", "name": "house_generic_center_hallway" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -372,9 +377,9 @@
"mondensity" : 2,
"sidewalk" : true,
"mapgen": [
{ "type": "builtin", "name": "house_generic_boxy" },
{ "type": "builtin", "name": "house_generic_big_livingroom" },
{ "type": "builtin", "name": "house_generic_center_hallway" }
{ "method": "builtin", "name": "house_generic_boxy" },
{ "method": "builtin", "name": "house_generic_big_livingroom" },
{ "method": "builtin", "name": "house_generic_center_hallway" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -387,7 +392,7 @@
"mondensity" : 2,
"sidewalk" : true,
"mapgen": [
{ "type": "builtin", "name": "parking_lot" }
{ "method": "builtin", "name": "parking_lot" }
]
},{
"type" : "overmap_terrain",
Expand All @@ -400,8 +405,8 @@
"mondensity" : 2,
"sidewalk" : true,
"mapgen": [
{ "type": "builtin", "name": "park_playground", "weight": 500 },
{ "type": "builtin", "name": "park_basketball", "weight": 1000, "comment": "1000 is default" }
{ "method": "builtin", "name": "park_playground", "weight": 500 },
{ "method": "builtin", "name": "park_basketball", "weight": 1000, "comment": "1000 is default" }
]
},{
"type" : "overmap_terrain",
Expand Down Expand Up @@ -540,8 +545,8 @@
"mondensity" : 2,
"sidewalk" : true,
"mapgen": [
{ "type": "builtin", "name": "church_new_england" },
{ "type": "builtin", "name": "church_gothic" }
{ "method": "builtin", "name": "church_new_england" },
{ "method": "builtin", "name": "church_gothic" }
]
},{
"type" : "overmap_terrain",
Expand Down Expand Up @@ -1611,11 +1616,11 @@
"known_up" : true,
"mondensity" : 2,
"mapgen": [
{ "type": "builtin", "name": "basement_junk" },
{ "type": "builtin", "name": "basement_guns" },
{ "type": "builtin", "name": "basement_survivalist" },
{ "type": "builtin", "name": "basement_chemlab" },
{ "type": "builtin", "name": "basement_weed" }
{ "method": "builtin", "name": "basement_junk" },
{ "method": "builtin", "name": "basement_guns" },
{ "method": "builtin", "name": "basement_survivalist" },
{ "method": "builtin", "name": "basement_chemlab" },
{ "method": "builtin", "name": "basement_weed" }
]
},{
"type" : "overmap_terrain",
Expand Down
22 changes: 17 additions & 5 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,22 @@ void load_oter(oter_t & oter) {
oterlist.push_back(oter);
}

void load_mapgen_function(JsonObject &jio, const std::string id_base) {
void load_mapgen_function(JsonObject &jio, const std::string id_base, int default_idx) {
int mgweight = jio.get_int("weight", 1000);
bool isdisabled = false;
if ( mgweight <= 0 || jio.get_bool("disabled", false) == true ) {
const std::string mgtype = jio.get_string("method");
if ( default_idx != -1 && mgtype == "builtin" ) {
if ( jio.has_string("name") ) {
const std::string mgname = jio.get_string("name");
if ( mgname == id_base ) {
oter_mapgen[id_base][ default_idx ]->weight = 0;
}
}
}
return; // nothing
} else if ( jio.has_string("type") ) {
const std::string mgtype = jio.get_string("type");
} else if ( jio.has_string("method") ) {
const std::string mgtype = jio.get_string("method");
if ( mgtype == "builtin" ) { // c-function
if ( jio.has_string("name") ) {
const std::string mgname = jio.get_string("name");
Expand Down Expand Up @@ -410,7 +420,7 @@ void load_mapgen_function(JsonObject &jio, const std::string id_base) {
debugmsg("oter_t[%s]: Invalid mapgen function type: %s", id_base.c_str(), mgtype.c_str() );
}
} else {
debugmsg("oter_t[%s]: Invalid mapgen function (missing \"type\" value).", id_base.c_str() );
debugmsg("oter_t[%s]: Invalid mapgen function (missing \"method\" value, must be \"builtin\", \"lua\", or \"json\").", id_base.c_str() );
}
}

Expand All @@ -423,9 +433,11 @@ void load_overmap_terrain_mapgens(JsonObject &jo, const std::string id_base, con
const std::string fmapkey(id_base + suffix);
const std::string jsonkey("mapgen" + suffix);
bool default_mapgen = jo.get_bool("default_mapgen", true);
int default_idx = -1;
if ( default_mapgen ) {
if ( mapgen_cfunction_map.find( fmapkey ) != mapgen_cfunction_map.end() ) {
oter_mapgen[fmapkey].push_back( new mapgen_function_builtin( fmapkey ) );
default_idx = oter_mapgen[fmapkey].size() - 1;
}
}

Expand All @@ -435,7 +447,7 @@ void load_overmap_terrain_mapgens(JsonObject &jo, const std::string id_base, con
while ( ja.has_more() ) {
if ( ja.has_object(c) ) {
JsonObject jio = ja.next_object();
load_mapgen_function( jio, fmapkey );
load_mapgen_function( jio, fmapkey, default_idx );
}
c++;
}
Expand Down

0 comments on commit 04e45ea

Please sign in to comment.