17 #define GETTEXT_DOMAIN "wesnoth-lib"
28 #include "widgets/slider.hpp"
32 #define DBG_NG LOG_STREAM(debug, log_engine)
35 const size_t max_island = 10;
36 const size_t max_coastal = 5;
57 int width = cfg[
"map_width"];
61 int height = cfg[
"map_height"];
68 int iterations = cfg[
"iterations"];
72 int hill_size = cfg[
"hill_size"];
76 int max_lakes = cfg[
"max_lakes"];
80 int nvillages = cfg[
"villages"];
84 int castle_size = cfg[
"castle_size"];
88 int nplayers = cfg[
"players"];
92 int island_size = cfg[
"island_size"];
105 const int width = 600;
107 const int xpos = screen.
getx()/2 - width/2;
108 int ypos = screen.
gety()/2 - height/2;
111 std::vector<gui::button*> buttons(1,&close_button);
114 f.
layout(xpos,ypos,width,height);
123 const std::string& iterations_label =
_(
"Number of hills:");
124 const std::string& hillsize_label =
_(
"Max hill size:");
126 const std::string& castlesize_label =
_(
"Castle size:");
138 const int horz_margin = 15;
139 const int text_right = xpos + horz_margin +
140 std::max<int>(std::max<int>(std::max<int>(std::max<int>(std::max<int>(std::max<int>(
141 players_rect.w,width_rect.w),height_rect.w),iterations_rect.w),hillsize_rect.w),villages_rect.w),castlesize_rect.w);
143 players_rect.x = text_right - players_rect.w;
144 width_rect.x = text_right - width_rect.w;
145 height_rect.x = text_right - height_rect.w;
146 iterations_rect.x = text_right - iterations_rect.w;
147 hillsize_rect.x = text_right - hillsize_rect.w;
148 villages_rect.x = text_right - villages_rect.w;
149 castlesize_rect.x = text_right - castlesize_rect.w;
150 landform_rect.x = text_right - landform_rect.w;
152 const int vertical_margin = 20;
153 players_rect.y = ypos + vertical_margin*2;
154 width_rect.y = players_rect.y + players_rect.h + vertical_margin;
155 height_rect.y = width_rect.y + width_rect.h + vertical_margin;
156 iterations_rect.y = height_rect.y + height_rect.h + vertical_margin;
157 hillsize_rect.y = iterations_rect.y + iterations_rect.h + vertical_margin;
158 villages_rect.y = hillsize_rect.y + hillsize_rect.h + vertical_margin;
159 castlesize_rect.y = villages_rect.y + iterations_rect.h + vertical_margin;
160 landform_rect.y = castlesize_rect.y + villages_rect.h + vertical_margin;
162 const int right_space = 150;
164 const int slider_left = text_right + 10;
165 const int slider_right = xpos + width - horz_margin - right_space;
168 , slider_right - slider_left
177 const int min_width = 20;
178 const int max_width = 100;
179 const int max_height = 100;
180 const int extra_size_per_player = 2;
182 slider_rect.y = width_rect.y;
185 width_slider.
set_min(min_width+(players_slider.
value()-2)*extra_size_per_player);
186 width_slider.
set_max(max_width);
189 slider_rect.y = height_rect.y;
192 height_slider.
set_min(min_width+(players_slider.
value()-2)*extra_size_per_player);
193 height_slider.
set_max(max_height);
196 const int min_iterations = 10;
197 const int max_iterations = 3000;
199 slider_rect.y = iterations_rect.y;
202 iterations_slider.
set_min(min_iterations);
203 iterations_slider.
set_max(max_iterations);
206 const int min_hillsize = 1;
207 const int max_hillsize = 50;
209 slider_rect.y = hillsize_rect.y;
212 hillsize_slider.
set_min(min_hillsize);
213 hillsize_slider.
set_max(max_hillsize);
216 const int min_villages = 0;
217 const int max_villages = 50;
219 slider_rect.y = villages_rect.y;
222 villages_slider.
set_min(min_villages);
223 villages_slider.
set_max(max_villages);
226 const int min_castlesize = 2;
227 const int max_castlesize = 14;
229 slider_rect.y = castlesize_rect.y;
232 castlesize_slider.
set_min(min_castlesize);
233 castlesize_slider.
set_max(max_castlesize);
237 const int min_landform = 0;
238 const int max_landform =
int(max_island);
239 slider_rect.y = landform_rect.y;
242 landform_slider.
set_min(min_landform);
243 landform_slider.
set_max(max_landform);
246 SDL_Rect link_rect = slider_rect;
247 link_rect.y = link_rect.y + link_rect.h + vertical_margin;
253 SDL_Rect labels_rect = link_rect;
254 labels_rect.y = labels_rect.y + labels_rect.h + vertical_margin;
286 width_slider.
set_min(min_width+(players_slider.
value()-2)*extra_size_per_player);
287 height_slider.
set_min(min_width+(players_slider.
value()-2)*extra_size_per_player);
304 slider_right + horz_margin, players_rect.y);
308 slider_right + horz_margin, width_rect.y);
312 slider_right+horz_margin,height_rect.y);
314 std::stringstream villages_str;
317 slider_right+horz_margin,villages_rect.y);
321 slider_right + horz_margin, castlesize_rect.y);
323 std::stringstream landform_str;
326 slider_right+horz_margin,landform_rect.y);
373 size_t island_size = 0;
374 size_t island_off_center = 0;
384 const size_t island_radius = 50 + ((max_island -
island_size_)*50)/(max_island - max_coastal);
385 island_size = (island_radius*(
width_/2))/100;
389 const size_t island_radius = 40 + ((max_coastal -
island_size_)*40)/max_coastal;
390 island_size = (island_radius*
width_*2)/100;
392 DBG_NG <<
"calculated coastal params...\n";
398 std::map<map_location,std::string> labels_copy;
399 std::map<map_location,std::string> * labels_ptr = labels ? &labels_copy :
nullptr;
407 labels_copy = *labels;
419 }
while (tries && map.empty());
421 labels->swap(labels_copy);
424 if (error_message !=
"")
432 DBG_NG <<
"creating scenario...\n";
436 DBG_NG <<
"got scenario data...\n";
438 std::map<map_location,std::string> labels;
439 DBG_NG <<
"generating map...\n";
445 res[
"map_data"] =
"";
446 res[
"error_message"] = exc.
message;
448 DBG_NG <<
"done generating map..\n";
450 for(std::map<map_location,std::string>::const_iterator
i =
451 labels.begin();
i != labels.end(); ++
i) {
453 if(
i->first.x >= 0 &&
i->first.y >= 0 &&
454 i->first.x < static_cast<long>(
width_) &&
455 i->first.y <
static_cast<long>(
height_)) {
458 label[
"text"] =
i->second;
459 label[
"category"] =
"villages";
460 i->first.write(label);
std::string generate_map(std::map< map_location, std::string > *labels, boost::optional< boost::uint32_t > randomseed)
std::string default_generate_map(size_t width, size_t height, size_t island_size, size_t island_off_center, size_t iterations, size_t hill_size, size_t max_lakes, size_t nvillages, size_t castle_size, size_t nplayers, bool roads_between_castles, std::map< map_location, std::string > *labels, const config &cfg)
Generate the map.
static const style default_style
void set_value(int value)
config create_scenario(boost::optional< boost::uint32_t > randomseed)
std::string config_name() const
Return a friendly name for the generator used to differentiate between different configs of the same ...
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
static lg::log_domain log_engine("engine")
const SDL_Color NORMAL_COLOR
void set_location(int x, int y)
dimension_measurements layout(int x, int y, int w, int h)
static UNUSEDNOWARN std::string _(const char *str)
std::string create_map(boost::optional< boost::uint32_t > randomseed)
Creates a new map and returns it.
config & add_child(const std::string &key)
static UNUSEDNOWARN std::string gettext(const char *str)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
bool allow_user_config() const
Returns true if the map generator has an interactive screen, which allows the user to modify how the ...
void raise_process_event()
default_map_generator(const config &game_config)
void user_config(CVideo &v)
Display the interactive screen, which allows the user to modify how the generator behaves...
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
Contains the SDL_Rect helper code.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Standard logging facilities (interface).
static void delay(unsigned int milliseconds)
std::string name() const
Returns a string identifying the generator by name.
GLint GLint GLint GLint GLint GLint GLsizei width
A config object defines a single node in a WML file, with access to child nodes.
void update_rect(const SDL_Rect &)
GLsizei const GLcharARB ** string