Skip to content
Permalink
Browse files

Add spawning maps specials to scenario.

  • Loading branch information...
BevapDin committed Jul 12, 2015
1 parent ef19fa1 commit a7dff2dbd76417eb6a8554d77e2793c7b890d1cd
Showing with 46 additions and 0 deletions.
  1. +10 −0 data/json/scenarios/scenarios.json
  2. +1 −0 doc/JSON_INFO.md
  3. +5 −0 src/game.cpp
  4. +11 −0 src/scenario.cpp
  5. +3 −0 src/scenario.h
  6. +12 −0 src/start_location.cpp
  7. +4 −0 src/start_location.h
@@ -145,5 +145,15 @@
"start_name": "Forest",
"professions" : ["unemployed", "survivalist", "naturalist", "bow_hunter", "lumberjack", "jr_survivalist", "fisher"],
"allowed_locs" : ["forest"]
},{
"type": "scenario",
"ident": "heli_crash",
"name": "Helicopter crash",
"points" : -8,
"description": "You've crashed your precious helicopter, it'll never fly again. Monster don't bother you, life without your Loach is worthless anyway.",
"start_name": "Crash site",
"professions" : ["unemployed", "bio_soldier"],
"allowed_locs" : ["field"],
"map_special": "mx_helicopter"
}
]
@@ -804,5 +804,6 @@ The format also support snippet ids like above.
"traits": [ "PROF_MED" ], // Allowed starting traits (see mutations.json). The player still has to choose them if they like, only useful if the listed trait can actually be chosen at game start.
"forced_traits": [ "PROF_MED" ], // Traits that are automatically added to the new character.
"forbidden_traits": [ "PROF_MED" ], // Traits that can explicitly not be chosen at start.
"map_special": "mx_helicopter", // (optional) Add a map special to the starting location, see JSON_FLAGS for the possible specials.
}
```
@@ -652,6 +652,11 @@ void game::start_game(std::string worldname)

const start_location &start_loc = *start_location::find( u.start_location );
const tripoint omtstart = start_loc.setup();
if( scen->has_map_special() ) {
// Specials can add monster spawn points and similar and should be done before the main
// map is loaded.
start_loc.add_map_special( omtstart, scen->get_map_special() );
}
tripoint lev = overmapbuffer::omt_to_sm_copy( omtstart );
// The player is centered in the map, but lev[xyz] refers to the top left point of the map
lev.x -= MAPSIZE / 2;
@@ -17,6 +17,7 @@
#include "skill.h"
#include "profession.h"
#include "mutation.h"
#include "mapgen.h"

scenario::scenario()
: _ident(""), _name_male("null"), _name_female("null"),
@@ -112,6 +113,7 @@ void scenario::load_scenario(JsonObject &jsobj)
while (jsarr.has_more()) {
scen.flags.insert(jsarr.next_string());
}
scen._map_special = jsobj.get_string( "map_special", "mx_null" );

_all_scens[scen._ident] = scen;
DebugLog( D_INFO, DC_ALL ) << "Loaded scenario: " << scen._ident;
@@ -219,6 +221,7 @@ void scenario::check_definition() const
check_traits( _allowed_traits, _ident );
check_traits( _forced_traits, _ident );
check_traits( _forbidden_traits, _ident );
MapExtras::get_function( _map_special ); // triggers a debug message upon invalid input
}

bool scenario::has_initialized()
@@ -355,4 +358,12 @@ bool scenario::can_pick(int points) const

return true;
}
bool scenario::has_map_special() const
{
return _map_special != "mx_null";
}
const std::string& scenario::get_map_special() const
{
return _map_special;
}
// vim:ts=4:sw=4:et:tw=0:fdm=marker:fdl=0:
@@ -42,6 +42,7 @@ class scenario
std::vector<std::string> _starting_items_male;
std::vector<std::string> _starting_items_female;
std::set<std::string> flags; // flags for some special properties of the scenario
std::string _map_special;

void add_items_from_jsonarray(JsonArray jsarr, std::string gender);
void add_item(std::string item, std::string gender);
@@ -93,6 +94,8 @@ class scenario
std::vector<std::string> items() const;
std::vector<std::string> items_male() const;
std::vector<std::string> items_female() const;
bool has_map_special() const;
const std::string& get_map_special() const;


/**
@@ -9,6 +9,7 @@
#include "json.h"
#include "overmap.h"
#include "field.h"
#include "mapgen.h"

static location_map _locations;

@@ -370,3 +371,14 @@ void start_location::burn( const tripoint &omtstart,
}
m.save();
}

void start_location::add_map_special( const tripoint &omtstart, const std::string& map_special ) const {
const tripoint player_location = overmapbuffer::omt_to_sm_copy( omtstart );
tinymap m;
m.load( player_location.x, player_location.y, player_location.z, false );

const auto ptr = MapExtras::get_function( map_special );
ptr( m, player_location );

m.save();
}
@@ -47,6 +47,10 @@ class start_location
*/
void burn( const tripoint &omtstart,
const size_t count, const int rad ) const;
/**
* Adds a map special, see mapgen.h and mapgen.cpp. Look at the namespace MapExtras.
*/
void add_map_special( const tripoint &omtstart, const std::string& map_special ) const;

private:
std::string _ident;

0 comments on commit a7dff2d

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