ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/random_map.C
(Generate patch)

Comparing deliantra/server/random_maps/random_map.C (file contents):
Revision 1.68 by root, Sat Jul 3 12:25:45 2010 UTC vs.
Revision 1.85 by root, Sat Nov 17 23:40:02 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <time.h> 26#include <time.h>
26#include <stdio.h> 27#include <stdio.h>
27#include <global.h> 28#include <global.h>
28#include <random_map.h> 29#include <rmg.h>
29#include <rproto.h> 30#include <rproto.h>
30#include <sproto.h> 31#include <sproto.h>
31 32
32#define CEDE coroapi::cede_to_tick () 33#define CEDE coroapi::cede_to_tick ()
33 34
60 61
61 assign (wall_name, get_str ("wall_name")); 62 assign (wall_name, get_str ("wall_name"));
62 63
63 xsize = get_iv ("xsize"); 64 xsize = get_iv ("xsize");
64 ysize = get_iv ("ysize"); 65 ysize = get_iv ("ysize");
65 expand2x = get_iv ("expand2x");
66 layoutoptions1 = get_iv ("layoutoptions1"); 66 layoutoptions1 = get_iv ("layoutoptions1");
67 layoutoptions2 = get_iv ("layoutoptions2"); 67 layoutoptions2 = get_iv ("layoutoptions2");
68 layoutoptions3 = get_iv ("layoutoptions3"); 68 layoutoptions3 = get_iv ("layoutoptions3");
69 symmetry = get_iv ("symmetry");
70 difficulty = get_iv ("difficulty"); 69 difficulty = get_iv ("difficulty");
71 difficulty_given = get_iv ("difficulty_given"); 70 difficulty_given = get_iv ("difficulty_given");
72 difficulty_increase = get_nv ("difficulty_increase"); 71 difficulty_increase = get_nv ("difficulty_increase");
73 dungeon_level = get_iv ("dungeon_level"); 72 dungeon_level = get_iv ("dungeon_level");
74 dungeon_depth = get_iv ("dungeon_depth"); 73 dungeon_depth = get_iv ("dungeon_depth");
75 orientation = get_iv ("orientation");
76 random_seed = get_uv ("random_seed");
77 total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy 74 total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy
78 symmetry_used = get_iv ("symmetry_used"); 75 symmetry_used = get_iv ("symmetry_used");
79} 76}
80 77
81random_map_params::~random_map_params () 78random_map_params::~random_map_params ()
89 set ("xsize" , xsize); 86 set ("xsize" , xsize);
90 set ("ysize" , ysize); 87 set ("ysize" , ysize);
91 set ("layoutoptions1" , layoutoptions1); 88 set ("layoutoptions1" , layoutoptions1);
92 set ("layoutoptions2" , layoutoptions2); 89 set ("layoutoptions2" , layoutoptions2);
93 set ("layoutoptions3" , layoutoptions3); 90 set ("layoutoptions3" , layoutoptions3);
94 set ("symmetry" , symmetry);
95 set ("dungeon_depth" , dungeon_depth); 91 set ("dungeon_depth" , dungeon_depth);
96 set ("orientation" , orientation);
97 set ("random_seed" , (UV)random_seed);
98 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); 92 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0);
99 set ("difficulty_increase", difficulty_increase); 93 set ("difficulty_increase", difficulty_increase);
100 set ("dungeon_level" , dungeon_level); 94 set ("dungeon_level" , dungeon_level);
101 95
102 dynbuf_text buf; 96 dynbuf_text buf;
115 } 109 }
116 110
117 return shstr (buf); 111 return shstr (buf);
118} 112}
119 113
120noinline SV * 114ecb_noinline SV *
121random_map_params::get_sv (const char *option) const 115random_map_params::opt_sv (const char *option) const
122{ 116{
123 SV **he = hv_fetch (hv, option, strlen (option), 0); 117 SV **he = hv_fetch (hv, option, strlen (option), 0);
124 118
125 return he ? *he : 0; 119 return he ? *he : 0;
126} 120}
127 121
128noinline const_utf8_string 122ecb_noinline const_utf8_string
129random_map_params::get_str (const char *option, const_utf8_string fallback) const 123random_map_params::get_str (const char *option, const_utf8_string fallback) const
130{ 124{
131 SV *sv = get_sv (option); 125 SV *sv = opt_sv (option);
132 return sv ? cfSvPVutf8_nolen (sv) : fallback; 126 return sv ? cfSvPVutf8_nolen (sv) : fallback;
133} 127}
134 128
135noinline IV 129ecb_noinline IV
136random_map_params::get_iv (const char *option, IV fallback) const 130random_map_params::get_iv (const char *option, IV fallback) const
137{ 131{
138 SV *sv = get_sv (option); 132 SV *sv = opt_sv (option);
139 return sv ? SvIV (sv) : fallback; 133 return sv ? SvIV (sv) : fallback;
140} 134}
141 135
142noinline UV 136ecb_noinline UV
143random_map_params::get_uv (const char *option, UV fallback) const 137random_map_params::get_uv (const char *option, UV fallback) const
144{ 138{
145 SV *sv = get_sv (option); 139 SV *sv = opt_sv (option);
146 return sv ? SvUV (sv) : fallback; 140 return sv ? SvUV (sv) : fallback;
147} 141}
148 142
149noinline NV 143ecb_noinline NV
150random_map_params::get_nv (const char *option, NV fallback) const 144random_map_params::get_nv (const char *option, NV fallback) const
151{ 145{
152 SV *sv = get_sv (option); 146 SV *sv = opt_sv (option);
153 return sv ? SvNV (sv) : fallback; 147 return sv ? SvNV (sv) : fallback;
154} 148}
155 149
156noinline void 150ecb_noinline void
157random_map_params::set (const char *option, SV *value) const 151random_map_params::set (const char *option, SV *value) const
158{ 152{
159 int len = strlen (option); 153 int len = strlen (option);
160 154
161 if (value) 155 if (value)
162 hv_store (hv, option, len, value, 0); 156 hv_store (hv, option, len, value, 0);
163 else 157 else
164 hv_delete (hv, option, len, G_DISCARD); 158 hv_delete (hv, option, len, G_DISCARD);
165} 159}
166 160
167noinline void 161ecb_noinline void
168random_map_params::set (const char *option, const_utf8_string value) const 162random_map_params::set (const char *option, const_utf8_string value) const
169{ 163{
170 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); 164 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0);
171} 165}
172 166
194 RP->Xsize = RP->xsize; 188 RP->Xsize = RP->xsize;
195 RP->Ysize = RP->ysize; 189 RP->Ysize = RP->ysize;
196 190
197 max_it (RP->dungeon_level, 1); 191 max_it (RP->dungeon_level, 1);
198 192
193 IV expand2x = RP->get_iv ("expand2x");
194 UV random_seed = RP->get_uv ("random_seed");
195
199 /* pick a random seed, or use the one from the input file */ 196 /* pick a random seed, or use the one from the input file */
200 RP->random_seed = RP->random_seed 197 random_seed = random_seed
201 ? RP->random_seed + RP->dungeon_level 198 ? random_seed + RP->dungeon_level
202 : pticks; 199 : server_tick;
203 200
204 // we run "single-threaded" 201 // we run "single-threaded"
205 rmg_rndm.seed (RP->random_seed); 202 rmg_rndm.seed (random_seed);
206 203
207 shstr buf = RP->as_shstr (); 204 shstr buf = RP->as_shstr ();
208 205
209 if (RP->difficulty == 0) 206 if (RP->difficulty == 0)
210 { 207 {
226 RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; 223 RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5;
227 224
228 min_it (RP->Xsize, MAX_RANDOM_MAP_SIZE); 225 min_it (RP->Xsize, MAX_RANDOM_MAP_SIZE);
229 min_it (RP->Ysize, MAX_RANDOM_MAP_SIZE); 226 min_it (RP->Ysize, MAX_RANDOM_MAP_SIZE);
230 227
228 int symmetry = RP->get_iv ("symmetry", SYMMETRY_NONE);
229
231 if (RP->symmetry == SYMMETRY_RANDOM) 230 if (symmetry == SYMMETRY_RANDOM)
232 RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; 231 RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1;
233 else 232 else
234 RP->symmetry_used = RP->symmetry; 233 RP->symmetry_used = symmetry;
235 234
236 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) 235 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
237 RP->Ysize = RP->Ysize / 2 + 1; 236 RP->Ysize = RP->Ysize / 2 + 1;
238 237
239 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) 238 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
240 RP->Xsize = RP->Xsize / 2 + 1; 239 RP->Xsize = RP->Xsize / 2 + 1;
241 240
242 if (RP->expand2x > 0) 241 if (expand2x)
243 { 242 {
244 RP->Xsize /= 2; 243 RP->Xsize /= 2;
245 RP->Ysize /= 2; 244 RP->Ysize /= 2;
246 } 245 }
247 246
259 RP->map_layout_style = LAYOUT_SNAKE; 258 RP->map_layout_style = LAYOUT_SNAKE;
260 else if (strstr (layoutstyle, "squarespiral")) 259 else if (strstr (layoutstyle, "squarespiral"))
261 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; 260 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
262 else if (strstr (layoutstyle, "cave")) 261 else if (strstr (layoutstyle, "cave"))
263 RP->map_layout_style = LAYOUT_CAVE; 262 RP->map_layout_style = LAYOUT_CAVE;
263 else if (strstr (layoutstyle, "castle"))
264 RP->map_layout_style = LAYOUT_CASTLE;
264 else if (strstr (layoutstyle, "multiple")) 265 else if (strstr (layoutstyle, "multiple"))
265 RP->map_layout_style = LAYOUT_MULTIPLE; 266 RP->map_layout_style = LAYOUT_MULTIPLE;
266 else 267 else
267 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ 268 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */
268 269
269 layout maze (RP->Xsize, RP->Ysize); 270 layout maze (RP->Xsize, RP->Ysize);
270 maze.generate (RP); 271 maze.generate (RP);
272
273 if (RP->get_iv ("rotate", 1))
271 maze.rotate (rmg_rndm (4)); 274 maze.rotate (rmg_rndm (4));
275
272 maze.symmetrize (RP->symmetry_used); 276 maze.symmetrize (RP->symmetry_used);
273 277
274 if (RP->expand2x) 278 if (expand2x)
275 maze.expand2x (); 279 maze.expand2x ();
276 280
277#if 0 281#if 0
278 maze.print ();//D 282 maze.print ();//D
279#endif 283#endif
315 319
316 const char *exitstyle = RP->get_str ("exitstyle", ""); 320 const char *exitstyle = RP->get_str ("exitstyle", "");
317 321
318 /* create exits unless the exitstyle is "none" */ 322 /* create exits unless the exitstyle is "none" */
319 if (strcmp (exitstyle, "none")) 323 if (strcmp (exitstyle, "none"))
320 place_exits (this, maze, exitstyle, RP->orientation, RP); 324 place_exits (this, maze, exitstyle, RP->get_iv ("orientation", 0), RP);
321 325
322 CEDE; 326 CEDE;
323 327
324 const char *monsterstyle = RP->get_str ("monsterstyle", ""); 328 const char *monsterstyle = RP->get_str ("monsterstyle", "");
325 329
339 /* create treasure unless the treasurestyle is "none" */ 343 /* create treasure unless the treasurestyle is "none" */
340 place_treasure (this, maze, treasurestyle, RP->get_iv ("treasureoptions"), RP); 344 place_treasure (this, maze, treasurestyle, RP->get_iv ("treasureoptions"), RP);
341 345
342 CEDE; 346 CEDE;
343 347
344 const char *decorstyle = RP->get_str ("treasurestyle", ""); 348 const char *decorstyle = RP->get_str ("decorstyle", "");
345 349
346 /* create decor unless the decorstyle is "none" */ 350 /* create decor unless the decorstyle is "none" */
347 if (strcmp (decorstyle, "none")) 351 if (strcmp (decorstyle, "none"))
348 put_decor (this, maze, decorstyle, RP->get_iv ("decoroptions"), RP); 352 put_decor (this, maze, decorstyle, RP->get_iv ("decoroptions"), RP);
349 353
352 /* generate treasures, etc. */ 356 /* generate treasures, etc. */
353 fix_auto_apply (); 357 fix_auto_apply ();
354 358
355 CEDE; 359 CEDE;
356 360
357 unblock_exits (this, maze, RP); 361 unblock_exits (this, maze);
358 362
359 msg = buf; 363 msg = buf;
360 in_memory = MAP_ACTIVE; 364 state = MAP_INACTIVE; // this is probably a lie, but currently works with ext/map-random.ext
361 365
362 CEDE; 366 CEDE;
363 367
364 return 1; 368 return 1;
365} 369}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines