added in facility to play maps in multiplayer that don't have scenario data...
...specified for them
This commit is contained in:
parent
1c23e287a9
commit
87c95d303f
9 changed files with 67 additions and 54 deletions
|
@ -1,8 +1,7 @@
|
|||
[multiplayer]
|
||||
name=ai-test
|
||||
map=ai-test
|
||||
[generic_multiplayer]
|
||||
name=User Map
|
||||
turns=90
|
||||
id=multiplayer-ai-test
|
||||
id=user_map
|
||||
|
||||
{DAWN}
|
||||
{MORNING}
|
||||
|
@ -10,20 +9,7 @@
|
|||
{DUSK}
|
||||
{FIRST_WATCH}
|
||||
{SECOND_WATCH}
|
||||
|
||||
[side]
|
||||
side=1
|
||||
enemy=2
|
||||
canrecruit=1
|
||||
controller=human
|
||||
[/side]
|
||||
[side]
|
||||
side=2
|
||||
enemy=1
|
||||
canrecruit=1
|
||||
controller=human
|
||||
[/side]
|
||||
[/multiplayer]
|
||||
[/generic_multiplayer]
|
||||
[multiplayer]
|
||||
name="Across The River"
|
||||
map_data="ffffffffffffffgggggggggggggggggggggggg
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "util.hpp"
|
||||
|
@ -224,6 +225,20 @@ std::string get_user_data_dir()
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string read_map(const std::string& name)
|
||||
{
|
||||
std::string res = read_file("data/maps/" + name);
|
||||
if(res == "") {
|
||||
res = read_file(get_user_data_dir() + "/data/maps/" + name);
|
||||
}
|
||||
|
||||
if(res == "") {
|
||||
res = read_file(get_user_data_dir() + "/editor/maps/" + name);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool is_directory_internal(const std::string& fname)
|
||||
|
|
|
@ -38,6 +38,8 @@ std::string get_saves_dir();
|
|||
std::string get_cache_dir();
|
||||
std::string get_user_data_dir();
|
||||
|
||||
std::string read_map(const std::string& name);
|
||||
|
||||
//function which returns true iff the given file is a directory
|
||||
bool is_directory(const std::string& fname);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "cursor.hpp"
|
||||
#include "events.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "font.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -68,12 +69,13 @@ multiplayer_game_setup_dialog::multiplayer_game_setup_dialog(
|
|||
state_.can_recruit.clear();
|
||||
|
||||
//build the list of scenarios to play
|
||||
std::vector<std::string> options;
|
||||
get_files_in_dir(get_user_data_dir() + "/editor/maps",&user_maps_,NULL,FILE_NAME_ONLY);
|
||||
|
||||
std::vector<std::string> options = user_maps_;
|
||||
|
||||
const config::child_list& levels = cfg.get_children("multiplayer");
|
||||
std::map<int,std::string> res_to_id;
|
||||
for(config::child_list::const_iterator i = levels.begin(); i != levels.end(); ++i){
|
||||
const std::string& id = (**i)["id"];
|
||||
res_to_id[i - levels.begin()] = id;
|
||||
|
||||
const std::string& lang_name = string_table[id];
|
||||
if(lang_name.empty() == false)
|
||||
|
@ -378,24 +380,38 @@ lobby::RESULT multiplayer_game_setup_dialog::process()
|
|||
generator_.assign(NULL);
|
||||
|
||||
const size_t select = size_t(maps_menu_->selection());
|
||||
if(select != maps_menu_->nitems()-1) {
|
||||
|
||||
if(select < user_maps_.size()) {
|
||||
const config* const generic_multiplayer = cfg_.child("generic_multiplayer");
|
||||
if(generic_multiplayer != NULL) {
|
||||
scenario_data_ = *generic_multiplayer;
|
||||
scenario_data_["map_data"] = read_map(user_maps_[select]);
|
||||
level_ = &scenario_data_;
|
||||
}
|
||||
|
||||
} else if(select != maps_menu_->nitems()-1) {
|
||||
const size_t index = select - user_maps_.size();
|
||||
const config::child_list& levels = cfg_.get_children("multiplayer");
|
||||
|
||||
assert(select < levels.size());
|
||||
config& scenario = *levels[select];
|
||||
level_ = &scenario;
|
||||
if(index < levels.size()) {
|
||||
|
||||
std::string& map_data = scenario["map_data"];
|
||||
if(map_data == "" && scenario["map"] != "") {
|
||||
map_data = read_file("data/maps/" + scenario["map"]);
|
||||
}
|
||||
scenario_data_ = *levels[index];
|
||||
level_ = &scenario_data_;
|
||||
|
||||
//if the map should be randomly generated
|
||||
if(scenario["map_generation"] != "") {
|
||||
generator_.assign(create_map_generator(scenario["map_generation"],scenario.child("generator")));
|
||||
std::string& map_data = scenario_data_["map_data"];
|
||||
if(map_data == "" && scenario_data_["map"] != "") {
|
||||
map_data = read_map(scenario_data_["map"]);
|
||||
}
|
||||
|
||||
//if the map should be randomly generated
|
||||
if(scenario_data_["map_generation"] != "") {
|
||||
generator_.assign(create_map_generator(scenario_data_["map_generation"],scenario_data_.child("generator")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
scenario_data_.clear();
|
||||
|
||||
playernum_restorer_.restore();
|
||||
minimap_restorer_.restore();
|
||||
const SDL_Rect& player_num_rect = playernum_restorer_.area();
|
||||
|
@ -490,7 +506,7 @@ void multiplayer_game_setup_dialog::start_game()
|
|||
|
||||
const int share = vision_combo_->selected();
|
||||
const int res = connector.load_map((*era_list[era_combo_->selected()])["id"],
|
||||
maps_menu_->selection(), turns, village_gold_slider_->value(),
|
||||
scenario_data_, turns, village_gold_slider_->value(),
|
||||
xp_modifier_slider_->value(), fog_game_->checked(),
|
||||
shroud_game_->checked(), observers_game_->checked(),
|
||||
share == 0, share == 1);
|
||||
|
|
|
@ -58,6 +58,9 @@ private:
|
|||
|
||||
int map_selection_;
|
||||
|
||||
std::vector<std::string> user_maps_;
|
||||
config scenario_data_;
|
||||
|
||||
util::scoped_ptr<gui::menu> maps_menu_;
|
||||
util::scoped_ptr<gui::slider> turns_slider_, village_gold_slider_, xp_modifier_slider_;
|
||||
util::scoped_ptr<gui::button> fog_game_, shroud_game_, observers_game_,
|
||||
|
|
|
@ -67,7 +67,7 @@ mp_connect::~mp_connect()
|
|||
}
|
||||
}
|
||||
|
||||
int mp_connect::load_map(const std::string& era, int map, int num_turns, int village_gold, int xpmodifier,
|
||||
int mp_connect::load_map(const std::string& era, config& scenario_data, int num_turns, int village_gold, int xpmodifier,
|
||||
bool fog_game, bool shroud_game, bool allow_observers, bool share_view, bool share_maps)
|
||||
{
|
||||
log_scope("load_map");
|
||||
|
@ -76,9 +76,7 @@ int mp_connect::load_map(const std::string& era, int map, int num_turns, int vil
|
|||
|
||||
era_ = era;
|
||||
|
||||
const config::child_list& levels = cfg_->get_children("multiplayer");
|
||||
|
||||
if(map == levels.size()) {
|
||||
if(scenario_data.empty()) {
|
||||
//Load a saved game
|
||||
save_ = true;
|
||||
bool show_replay = false;
|
||||
|
@ -110,8 +108,8 @@ int mp_connect::load_map(const std::string& era, int map, int num_turns, int vil
|
|||
}
|
||||
}
|
||||
|
||||
loaded_level_ = state_->snapshot;
|
||||
level_ptr = &loaded_level_;
|
||||
scenario_data = state_->snapshot;
|
||||
level_ptr = &scenario_data;
|
||||
|
||||
//make all sides untaken
|
||||
for(config::child_itors i = level_ptr->child_range("side");
|
||||
|
@ -127,7 +125,7 @@ int mp_connect::load_map(const std::string& era, int map, int num_turns, int vil
|
|||
config* const start = level_ptr->child("start");
|
||||
|
||||
//if this is a snapshot save, we don't want to use the replay data
|
||||
if(loaded_level_["snapshot"] == "yes") {
|
||||
if(scenario_data["snapshot"] == "yes") {
|
||||
if(start != NULL)
|
||||
start->clear_children("replay");
|
||||
level_ptr->clear_children("replay");
|
||||
|
@ -142,8 +140,7 @@ int mp_connect::load_map(const std::string& era, int map, int num_turns, int vil
|
|||
} else {
|
||||
//Load a new map
|
||||
save_ = false;
|
||||
loaded_level_ = *levels[map];
|
||||
level_ptr = &loaded_level_;
|
||||
level_ptr = &scenario_data;
|
||||
|
||||
//set the number of turns here
|
||||
std::stringstream turns;
|
||||
|
@ -160,13 +157,7 @@ int mp_connect::load_map(const std::string& era, int map, int num_turns, int vil
|
|||
state_->label = level_->values["name"];
|
||||
state_->gold = -10000;
|
||||
|
||||
std::map<int,std::string> res_to_id;
|
||||
for(config::child_list::const_iterator i = levels.begin(); i != levels.end(); ++i){
|
||||
const std::string& id = (**i)["id"];
|
||||
res_to_id[i - levels.begin()] = id;
|
||||
}
|
||||
|
||||
state_->scenario = res_to_id[map];
|
||||
state_->scenario = scenario_data["id"];
|
||||
|
||||
level_->values["observer"] = allow_observers ? "yes" : "no";
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
game_state& state, bool join = false);
|
||||
~mp_connect();
|
||||
|
||||
int load_map(const std::string& era, int map, int num_turns, int village_gold, int xpmodifier,
|
||||
int load_map(const std::string& era, config& scenario, int num_turns, int village_gold, int xpmodifier,
|
||||
bool fog_game, bool shroud_game, bool allow_observers, bool share_view, bool share_maps);
|
||||
|
||||
void start_game();
|
||||
|
@ -69,8 +69,6 @@ private:
|
|||
config old_level_;
|
||||
std::map<config*,network::connection> positions_;
|
||||
|
||||
config loaded_level_;
|
||||
|
||||
bool show_replay_;
|
||||
bool save_;
|
||||
int status_;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "events.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "font.hpp"
|
||||
#include "image.hpp"
|
||||
#include "key.hpp"
|
||||
|
@ -108,7 +109,7 @@ RESULT enter(display& disp, config& game_data, const config& terrain_data, dialo
|
|||
|
||||
std::string map_data = (**i.first)["map_data"];
|
||||
if(map_data == "") {
|
||||
map_data = read_file("data/maps/" + (**i.first)["map"]);
|
||||
map_data = read_map((**i.first)["map"]);
|
||||
}
|
||||
|
||||
if(map_data != "") {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "cursor.hpp"
|
||||
#include "events.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "game_events.hpp"
|
||||
#include "hotkeys.hpp"
|
||||
#include "intro.hpp"
|
||||
|
@ -129,7 +130,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
|
|||
|
||||
std::string map_data = (*level)["map_data"];
|
||||
if(map_data == "" && (*level)["map"] != "") {
|
||||
map_data = read_file("data/maps/" + (*level)["map"]);
|
||||
map_data = read_map((*level)["map"]);
|
||||
}
|
||||
|
||||
//if the map should be randomly generated
|
||||
|
|
Loading…
Add table
Reference in a new issue