-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
map_create.cpp
74 lines (63 loc) · 2.45 KB
/
map_create.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Copyright (C) 2003 - 2014 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "global.hpp"
#include "map_create.hpp"
#include "generators/cavegen.hpp"
#include "generators/yamg/ya_mapgen.hpp"
#include "log.hpp"
#include "mapgen_dialog.hpp"
#include "scoped_resource.hpp"
#include "serialization/string_utils.hpp"
#include <cassert>
static lg::log_domain log_config("config");
#define ERR_CF LOG_STREAM(err, log_config)
map_generator* create_map_generator(const std::string& name, const config &cfg)
{
if(name == "default" || name == "") {
return new default_map_generator(cfg);
} else if(name == "cave") {
return new cave_map_generator(cfg);
} else if(name == "yamg") {
return new ya_mapgen(cfg);
} else {
return NULL;
}
}
//function to generate a random map, from a string which describes
//the generator to use and its arguments
std::string random_generate_map(const std::string& parms, const config &cfg)
{
//the first token is the name of the generator, tokens after
//that are arguments to the generator
std::vector<std::string> parameters = utils::split(parms, ' ');
assert(!parameters.empty()); //we use parameters.front() in the next line.
util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg));
if(generator == NULL) {
ERR_CF << "could not find map generator '" << parameters.front() << "'" << std::endl;
return std::string();
}
parameters.erase(parameters.begin());
return generator.get()->create_map(parameters);
}
config random_generate_scenario(const std::string& parms, const config &cfg)
{
//the first token is the name of the generator, tokens after
//that are arguments to the generator
std::vector<std::string> parameters = utils::split(parms, ' ');
util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg));
if(generator == NULL) {
ERR_CF << "could not find map generator '" << parameters.front() << "'" << std::endl;
return config();
}
parameters.erase(parameters.begin());
return generator->create_scenario(parameters);
}