Skip to content
Permalink
Browse files

Adding map extra weightings to regional json settings

  • Loading branch information...
trinsic
trinsic committed Jun 16, 2015
1 parent b11aae0 commit 327ec053f7eec98153617412138133a403f5b252
Showing with 128 additions and 0 deletions.
  1. +63 −0 data/json/regional_map_settings.json
  2. +5 −0 src/mapdata.h
  3. +58 −0 src/overmap.cpp
  4. +2 −0 src/overmap.h
@@ -34,6 +34,69 @@
},
"boosted_other_percent": 50.0, "//": "...accounts for this % of total coverage"
},
"map_extras": { "//": "mapping for weighted lists of extras",
"field": { "//": "% of plants that aren't default_ter",
"chance": 90, "//": "one in # chance of spawning an extra",
"extras": { "//": "weighted list",
"mx_helicopter": 40,
"mx_military": 8,
"mx_science": 20,
"mx_collegekids": 25,
"mx_drugdeal": 20,
"mx_supplydrop": 10,
"mx_portal": 3,
"mx_minefield": 50,
"mx_crater": 10,
"mx_fumarole": 8,
"mx_portal_in": 1,
"mx_anomaly": 3
}
},
"road": { "//": "% of plants that aren't default_ter",
"chance": 75, "//": "one in # chance of spawning an extra",
"extras": { "//": "weighted list",
"mx_helicopter": 40,
"mx_military": 25,
"mx_science": 40,
"mx_collegekids": 50,
"mx_roadblock": 100,
"mx_drugdeal": 30,
"mx_supplydrop": 10,
"mx_portal": 5,
"mx_minefield": 80,
"mx_crater": 10,
"mx_fumarole": 8,
"mx_portal_in": 2,
"mx_anomaly": 3
}
},
"building": { "//": "% of plants that aren't default_ter",
"chance": 90, "//": "one in # chance of spawning an extra",
"extras": { "//": "weighted list",
"mx_military": 5,
"mx_science": 12,
"mx_collegekids": 15,
"mx_portal": 5,
"mx_minefield": 5,
"mx_crater": 60,
"mx_fumarole": 8,
"mx_portal_in": 1,
"mx_anomaly": 3
}
},
"subway": { "//": "% of plants that aren't default_ter",
"chance": 75, "//": "one in # chance of spawning an extra",
"extras": { "//": "weighted list",
"mx_military": 5,
"mx_science": 12,
"mx_collegekids": 15,
"mx_portal": 7,
"mx_fumarole": 20,
"mx_portal_in": 1,
"mx_anomaly": 3
}
}
},
"num_forests": 250, "//": "# of forest chunks",
"forest_size_min": 15, "//": "size range of forest chunk",
"forest_size_max": 40, "//": "note: 32400 tiles in omap, 250*minmax = 3750-10000 default_oters become forests",
@@ -7,6 +7,7 @@
#include "iexamine.h"
#include "int_id.h"
#include "string_id.h"
#include "weighted_list.h"
#include "rng.h"

#include <bitset>
@@ -287,7 +288,11 @@ const int classic_extras = mfb(mx_helicopter) | mfb(mx_military) |

struct map_extras {
unsigned int chance;
weighted_int_list<std::string> extras;

int chances[num_map_extras + 1];
map_extras() :chance(0) {}

map_extras(unsigned int embellished, int helicopter = 0, int mili = 0,
int sci = 0, int roadblock = 0, int drug = 0, int supply = 0,
int portal = 0, int minefield = 0,
@@ -561,6 +561,43 @@ void load_region_settings( JsonObject &jo )
}
}

if ( ! jo.has_object("map_extras") ) {
if ( strict ) {
jo.throw_error("\"map_extras\": { ... } required for default");
}
} else {
JsonObject pjo = jo.get_object("map_extras");

std::set<std::string> zones = pjo.get_member_names();
for( const auto &zone : zones ) {
if( zone != "//" ) {
JsonObject zjo = pjo.get_object(zone);
map_extras extras(0);

if ( ! zjo.read("chance", extras.chance) && strict ) {
zjo.throw_error("chance required for default");
}

if ( ! zjo.has_object("extras") ) {
if ( strict ) {
zjo.throw_error("\"extras\": { ... } required for default");
}
} else {
JsonObject exjo = zjo.get_object("extras");

std::set<std::string> keys = exjo.get_member_names();
for( const auto &key : keys ) {
if(key != "//" ) {
extras.extras.add(key, exjo.get_int(key, 0));
}
}
}

new_region.region_extras[zone] = extras;
}
}
}

if ( ! jo.has_object("city") ) {
if ( strict ) {
jo.throw_error("\"city\": { ... } required for default");
@@ -720,6 +757,27 @@ void apply_region_overlay(JsonObject &jo, regional_settings &region)
fieldjo.throw_error("boost_chance > 0 requires boosted_other { ... }");
}

JsonObject mapextrajo = jo.get_object("map_extras");
std::set<std::string> extrazones = mapextrajo.get_member_names();
for( const auto &zone : extrazones ) {
if( zone != "//" ) {
JsonObject zonejo = mapextrajo.get_object(zone);

int tmpval = 0;
if (zonejo.read("chance", tmpval)) {
region.region_extras[zone].chance = tmpval;
}

JsonObject extrasjo = zonejo.get_object("extras");
std::set<std::string> extrakeys = extrasjo.get_member_names();
for( const auto &key : extrakeys ) {
if( key != "//" ) {
region.region_extras[zone].extras.add_or_replace(key, extrasjo.get_int(key));
}
}
}
}

JsonObject cityjo = jo.get_object("city");

cityjo.read("shop_radius", region.city_spec.shop_radius);
@@ -121,6 +121,8 @@ struct regional_settings {
groundcover_extra field_coverage;
groundcover_extra forest_coverage;

std::unordered_map<std::string, map_extras> region_extras;

regional_settings() : id("null"), default_oter("field"), default_groundcover(0, 0, 0) { }
void setup();
static void setup_oter(oter_weight &oter);

0 comments on commit 327ec05

Please sign in to comment.
You can’t perform that action at this time.