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.74 by root, Sun Aug 22 20:27:35 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>
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 difficulty = get_iv ("difficulty"); 69 difficulty = get_iv ("difficulty");
70 difficulty_given = get_iv ("difficulty_given"); 70 difficulty_given = get_iv ("difficulty_given");
71 difficulty_increase = get_nv ("difficulty_increase"); 71 difficulty_increase = get_nv ("difficulty_increase");
72 dungeon_level = get_iv ("dungeon_level"); 72 dungeon_level = get_iv ("dungeon_level");
73 dungeon_depth = get_iv ("dungeon_depth"); 73 dungeon_depth = get_iv ("dungeon_depth");
74 random_seed = get_uv ("random_seed");
75 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
76 symmetry_used = get_iv ("symmetry_used"); 75 symmetry_used = get_iv ("symmetry_used");
77} 76}
78 77
79random_map_params::~random_map_params () 78random_map_params::~random_map_params ()
88 set ("ysize" , ysize); 87 set ("ysize" , ysize);
89 set ("layoutoptions1" , layoutoptions1); 88 set ("layoutoptions1" , layoutoptions1);
90 set ("layoutoptions2" , layoutoptions2); 89 set ("layoutoptions2" , layoutoptions2);
91 set ("layoutoptions3" , layoutoptions3); 90 set ("layoutoptions3" , layoutoptions3);
92 set ("dungeon_depth" , dungeon_depth); 91 set ("dungeon_depth" , dungeon_depth);
93 set ("random_seed" , (UV)random_seed);
94 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); 92 set ("difficulty" , difficulty && difficulty_given ? difficulty : 0);
95 set ("difficulty_increase", difficulty_increase); 93 set ("difficulty_increase", difficulty_increase);
96 set ("dungeon_level" , dungeon_level); 94 set ("dungeon_level" , dungeon_level);
97 95
98 dynbuf_text buf; 96 dynbuf_text buf;
111 } 109 }
112 110
113 return shstr (buf); 111 return shstr (buf);
114} 112}
115 113
116noinline SV * 114ecb_noinline SV *
117random_map_params::get_sv (const char *option) const 115random_map_params::opt_sv (const char *option) const
118{ 116{
119 SV **he = hv_fetch (hv, option, strlen (option), 0); 117 SV **he = hv_fetch (hv, option, strlen (option), 0);
120 118
121 return he ? *he : 0; 119 return he ? *he : 0;
122} 120}
123 121
124noinline const_utf8_string 122ecb_noinline const_utf8_string
125random_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
126{ 124{
127 SV *sv = get_sv (option); 125 SV *sv = opt_sv (option);
128 return sv ? cfSvPVutf8_nolen (sv) : fallback; 126 return sv ? cfSvPVutf8_nolen (sv) : fallback;
129} 127}
130 128
131noinline IV 129ecb_noinline IV
132random_map_params::get_iv (const char *option, IV fallback) const 130random_map_params::get_iv (const char *option, IV fallback) const
133{ 131{
134 SV *sv = get_sv (option); 132 SV *sv = opt_sv (option);
135 return sv ? SvIV (sv) : fallback; 133 return sv ? SvIV (sv) : fallback;
136} 134}
137 135
138noinline UV 136ecb_noinline UV
139random_map_params::get_uv (const char *option, UV fallback) const 137random_map_params::get_uv (const char *option, UV fallback) const
140{ 138{
141 SV *sv = get_sv (option); 139 SV *sv = opt_sv (option);
142 return sv ? SvUV (sv) : fallback; 140 return sv ? SvUV (sv) : fallback;
143} 141}
144 142
145noinline NV 143ecb_noinline NV
146random_map_params::get_nv (const char *option, NV fallback) const 144random_map_params::get_nv (const char *option, NV fallback) const
147{ 145{
148 SV *sv = get_sv (option); 146 SV *sv = opt_sv (option);
149 return sv ? SvNV (sv) : fallback; 147 return sv ? SvNV (sv) : fallback;
150} 148}
151 149
152noinline void 150ecb_noinline void
153random_map_params::set (const char *option, SV *value) const 151random_map_params::set (const char *option, SV *value) const
154{ 152{
155 int len = strlen (option); 153 int len = strlen (option);
156 154
157 if (value) 155 if (value)
158 hv_store (hv, option, len, value, 0); 156 hv_store (hv, option, len, value, 0);
159 else 157 else
160 hv_delete (hv, option, len, G_DISCARD); 158 hv_delete (hv, option, len, G_DISCARD);
161} 159}
162 160
163noinline void 161ecb_noinline void
164random_map_params::set (const char *option, const_utf8_string value) const 162random_map_params::set (const char *option, const_utf8_string value) const
165{ 163{
166 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); 164 set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0);
167} 165}
168 166
190 RP->Xsize = RP->xsize; 188 RP->Xsize = RP->xsize;
191 RP->Ysize = RP->ysize; 189 RP->Ysize = RP->ysize;
192 190
193 max_it (RP->dungeon_level, 1); 191 max_it (RP->dungeon_level, 1);
194 192
193 IV expand2x = RP->get_iv ("expand2x");
194 UV random_seed = RP->get_uv ("random_seed");
195
195 /* 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 */
196 RP->random_seed = RP->random_seed 197 random_seed = random_seed
197 ? RP->random_seed + RP->dungeon_level 198 ? random_seed + RP->dungeon_level
198 : pticks; 199 : server_tick;
199 200
200 // we run "single-threaded" 201 // we run "single-threaded"
201 rmg_rndm.seed (RP->random_seed); 202 rmg_rndm.seed (random_seed);
202 203
203 shstr buf = RP->as_shstr (); 204 shstr buf = RP->as_shstr ();
204 205
205 if (RP->difficulty == 0) 206 if (RP->difficulty == 0)
206 { 207 {
235 RP->Ysize = RP->Ysize / 2 + 1; 236 RP->Ysize = RP->Ysize / 2 + 1;
236 237
237 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) 238 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
238 RP->Xsize = RP->Xsize / 2 + 1; 239 RP->Xsize = RP->Xsize / 2 + 1;
239 240
240 if (RP->expand2x > 0) 241 if (expand2x)
241 { 242 {
242 RP->Xsize /= 2; 243 RP->Xsize /= 2;
243 RP->Ysize /= 2; 244 RP->Ysize /= 2;
244 } 245 }
245 246
272 if (RP->get_iv ("rotate", 1)) 273 if (RP->get_iv ("rotate", 1))
273 maze.rotate (rmg_rndm (4)); 274 maze.rotate (rmg_rndm (4));
274 275
275 maze.symmetrize (RP->symmetry_used); 276 maze.symmetrize (RP->symmetry_used);
276 277
277 if (RP->expand2x) 278 if (expand2x)
278 maze.expand2x (); 279 maze.expand2x ();
279 280
280#if 0 281#if 0
281 maze.print ();//D 282 maze.print ();//D
282#endif 283#endif
358 CEDE; 359 CEDE;
359 360
360 unblock_exits (this, maze); 361 unblock_exits (this, maze);
361 362
362 msg = buf; 363 msg = buf;
363 in_memory = MAP_ACTIVE; 364 state = MAP_INACTIVE; // this is probably a lie, but currently works with ext/map-random.ext
364 365
365 CEDE; 366 CEDE;
366 367
367 return 1; 368 return 1;
368} 369}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines