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 (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * 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 |
9 | * 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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * 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 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <time.h> |
25 | #include <time.h> |
26 | #include <stdio.h> |
26 | #include <stdio.h> |
27 | #include <global.h> |
27 | #include <global.h> |
28 | #include <random_map.h> |
28 | #include <rmg.h> |
29 | #include <rproto.h> |
29 | #include <rproto.h> |
30 | #include <sproto.h> |
30 | #include <sproto.h> |
31 | |
31 | |
32 | #define CEDE coroapi::cede_to_tick () |
32 | #define CEDE coroapi::cede_to_tick () |
33 | |
33 | |
… | |
… | |
60 | |
60 | |
61 | assign (wall_name, get_str ("wall_name")); |
61 | assign (wall_name, get_str ("wall_name")); |
62 | |
62 | |
63 | xsize = get_iv ("xsize"); |
63 | xsize = get_iv ("xsize"); |
64 | ysize = get_iv ("ysize"); |
64 | ysize = get_iv ("ysize"); |
65 | expand2x = get_iv ("expand2x"); |
|
|
66 | layoutoptions1 = get_iv ("layoutoptions1"); |
65 | layoutoptions1 = get_iv ("layoutoptions1"); |
67 | layoutoptions2 = get_iv ("layoutoptions2"); |
66 | layoutoptions2 = get_iv ("layoutoptions2"); |
68 | layoutoptions3 = get_iv ("layoutoptions3"); |
67 | layoutoptions3 = get_iv ("layoutoptions3"); |
69 | difficulty = get_iv ("difficulty"); |
68 | difficulty = get_iv ("difficulty"); |
70 | difficulty_given = get_iv ("difficulty_given"); |
69 | difficulty_given = get_iv ("difficulty_given"); |
71 | difficulty_increase = get_nv ("difficulty_increase"); |
70 | difficulty_increase = get_nv ("difficulty_increase"); |
72 | dungeon_level = get_iv ("dungeon_level"); |
71 | dungeon_level = get_iv ("dungeon_level"); |
73 | dungeon_depth = get_iv ("dungeon_depth"); |
72 | 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 |
73 | total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy |
76 | symmetry_used = get_iv ("symmetry_used"); |
74 | symmetry_used = get_iv ("symmetry_used"); |
77 | } |
75 | } |
78 | |
76 | |
79 | random_map_params::~random_map_params () |
77 | random_map_params::~random_map_params () |
… | |
… | |
88 | set ("ysize" , ysize); |
86 | set ("ysize" , ysize); |
89 | set ("layoutoptions1" , layoutoptions1); |
87 | set ("layoutoptions1" , layoutoptions1); |
90 | set ("layoutoptions2" , layoutoptions2); |
88 | set ("layoutoptions2" , layoutoptions2); |
91 | set ("layoutoptions3" , layoutoptions3); |
89 | set ("layoutoptions3" , layoutoptions3); |
92 | set ("dungeon_depth" , dungeon_depth); |
90 | set ("dungeon_depth" , dungeon_depth); |
93 | set ("random_seed" , (UV)random_seed); |
|
|
94 | set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); |
91 | set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); |
95 | set ("difficulty_increase", difficulty_increase); |
92 | set ("difficulty_increase", difficulty_increase); |
96 | set ("dungeon_level" , dungeon_level); |
93 | set ("dungeon_level" , dungeon_level); |
97 | |
94 | |
98 | dynbuf_text buf; |
95 | dynbuf_text buf; |
… | |
… | |
112 | |
109 | |
113 | return shstr (buf); |
110 | return shstr (buf); |
114 | } |
111 | } |
115 | |
112 | |
116 | noinline SV * |
113 | noinline SV * |
117 | random_map_params::get_sv (const char *option) const |
114 | random_map_params::opt_sv (const char *option) const |
118 | { |
115 | { |
119 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
116 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
120 | |
117 | |
121 | return he ? *he : 0; |
118 | return he ? *he : 0; |
122 | } |
119 | } |
123 | |
120 | |
124 | noinline const_utf8_string |
121 | noinline const_utf8_string |
125 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
122 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
126 | { |
123 | { |
127 | SV *sv = get_sv (option); |
124 | SV *sv = opt_sv (option); |
128 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
125 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
129 | } |
126 | } |
130 | |
127 | |
131 | noinline IV |
128 | noinline IV |
132 | random_map_params::get_iv (const char *option, IV fallback) const |
129 | random_map_params::get_iv (const char *option, IV fallback) const |
133 | { |
130 | { |
134 | SV *sv = get_sv (option); |
131 | SV *sv = opt_sv (option); |
135 | return sv ? SvIV (sv) : fallback; |
132 | return sv ? SvIV (sv) : fallback; |
136 | } |
133 | } |
137 | |
134 | |
138 | noinline UV |
135 | noinline UV |
139 | random_map_params::get_uv (const char *option, UV fallback) const |
136 | random_map_params::get_uv (const char *option, UV fallback) const |
140 | { |
137 | { |
141 | SV *sv = get_sv (option); |
138 | SV *sv = opt_sv (option); |
142 | return sv ? SvUV (sv) : fallback; |
139 | return sv ? SvUV (sv) : fallback; |
143 | } |
140 | } |
144 | |
141 | |
145 | noinline NV |
142 | noinline NV |
146 | random_map_params::get_nv (const char *option, NV fallback) const |
143 | random_map_params::get_nv (const char *option, NV fallback) const |
147 | { |
144 | { |
148 | SV *sv = get_sv (option); |
145 | SV *sv = opt_sv (option); |
149 | return sv ? SvNV (sv) : fallback; |
146 | return sv ? SvNV (sv) : fallback; |
150 | } |
147 | } |
151 | |
148 | |
152 | noinline void |
149 | noinline void |
153 | random_map_params::set (const char *option, SV *value) const |
150 | random_map_params::set (const char *option, SV *value) const |
… | |
… | |
190 | RP->Xsize = RP->xsize; |
187 | RP->Xsize = RP->xsize; |
191 | RP->Ysize = RP->ysize; |
188 | RP->Ysize = RP->ysize; |
192 | |
189 | |
193 | max_it (RP->dungeon_level, 1); |
190 | max_it (RP->dungeon_level, 1); |
194 | |
191 | |
|
|
192 | IV expand2x = RP->get_iv ("expand2x"); |
|
|
193 | UV random_seed = RP->get_uv ("random_seed"); |
|
|
194 | |
195 | /* pick a random seed, or use the one from the input file */ |
195 | /* pick a random seed, or use the one from the input file */ |
196 | RP->random_seed = RP->random_seed |
196 | random_seed = random_seed |
197 | ? RP->random_seed + RP->dungeon_level |
197 | ? random_seed + RP->dungeon_level |
198 | : pticks; |
198 | : server_tick; |
199 | |
199 | |
200 | // we run "single-threaded" |
200 | // we run "single-threaded" |
201 | rmg_rndm.seed (RP->random_seed); |
201 | rmg_rndm.seed (random_seed); |
202 | rmg_rndm.seed (RP->random_seed + pticks);//D |
|
|
203 | |
202 | |
204 | shstr buf = RP->as_shstr (); |
203 | shstr buf = RP->as_shstr (); |
205 | |
204 | |
206 | if (RP->difficulty == 0) |
205 | if (RP->difficulty == 0) |
207 | { |
206 | { |
… | |
… | |
236 | RP->Ysize = RP->Ysize / 2 + 1; |
235 | RP->Ysize = RP->Ysize / 2 + 1; |
237 | |
236 | |
238 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
237 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
239 | RP->Xsize = RP->Xsize / 2 + 1; |
238 | RP->Xsize = RP->Xsize / 2 + 1; |
240 | |
239 | |
241 | if (RP->expand2x > 0) |
240 | if (expand2x) |
242 | { |
241 | { |
243 | RP->Xsize /= 2; |
242 | RP->Xsize /= 2; |
244 | RP->Ysize /= 2; |
243 | RP->Ysize /= 2; |
245 | } |
244 | } |
246 | |
245 | |
… | |
… | |
273 | if (RP->get_iv ("rotate", 1)) |
272 | if (RP->get_iv ("rotate", 1)) |
274 | maze.rotate (rmg_rndm (4)); |
273 | maze.rotate (rmg_rndm (4)); |
275 | |
274 | |
276 | maze.symmetrize (RP->symmetry_used); |
275 | maze.symmetrize (RP->symmetry_used); |
277 | |
276 | |
278 | if (RP->expand2x) |
277 | if (expand2x) |
279 | maze.expand2x (); |
278 | maze.expand2x (); |
280 | |
279 | |
281 | #if 0 |
280 | #if 0 |
282 | maze.print ();//D |
281 | maze.print ();//D |
283 | #endif |
282 | #endif |
… | |
… | |
343 | /* create treasure unless the treasurestyle is "none" */ |
342 | /* create treasure unless the treasurestyle is "none" */ |
344 | place_treasure (this, maze, treasurestyle, RP->get_iv ("treasureoptions"), RP); |
343 | place_treasure (this, maze, treasurestyle, RP->get_iv ("treasureoptions"), RP); |
345 | |
344 | |
346 | CEDE; |
345 | CEDE; |
347 | |
346 | |
348 | const char *decorstyle = RP->get_str ("treasurestyle", ""); |
347 | const char *decorstyle = RP->get_str ("decorstyle", ""); |
349 | |
348 | |
350 | /* create decor unless the decorstyle is "none" */ |
349 | /* create decor unless the decorstyle is "none" */ |
351 | if (strcmp (decorstyle, "none")) |
350 | if (strcmp (decorstyle, "none")) |
352 | put_decor (this, maze, decorstyle, RP->get_iv ("decoroptions"), RP); |
351 | put_decor (this, maze, decorstyle, RP->get_iv ("decoroptions"), RP); |
353 | |
352 | |
… | |
… | |
359 | CEDE; |
358 | CEDE; |
360 | |
359 | |
361 | unblock_exits (this, maze); |
360 | unblock_exits (this, maze); |
362 | |
361 | |
363 | msg = buf; |
362 | msg = buf; |
364 | in_memory = MAP_ACTIVE; |
363 | state = MAP_INACTIVE; // this is probably a lie, but currently works with ext/map-random.ext |
365 | |
364 | |
366 | CEDE; |
365 | CEDE; |
367 | |
366 | |
368 | return 1; |
367 | return 1; |
369 | } |
368 | } |