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,2011 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> |
… | |
… | |
108 | } |
109 | } |
109 | |
110 | |
110 | return shstr (buf); |
111 | return shstr (buf); |
111 | } |
112 | } |
112 | |
113 | |
113 | noinline SV * |
114 | ecb_noinline SV * |
114 | random_map_params::opt_sv (const char *option) const |
115 | random_map_params::opt_sv (const char *option) const |
115 | { |
116 | { |
116 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
117 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
117 | |
118 | |
118 | return he ? *he : 0; |
119 | return he ? *he : 0; |
119 | } |
120 | } |
120 | |
121 | |
121 | noinline const_utf8_string |
122 | ecb_noinline const_utf8_string |
122 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
123 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
123 | { |
124 | { |
124 | SV *sv = opt_sv (option); |
125 | SV *sv = opt_sv (option); |
125 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
126 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
126 | } |
127 | } |
127 | |
128 | |
128 | noinline IV |
129 | ecb_noinline IV |
129 | random_map_params::get_iv (const char *option, IV fallback) const |
130 | random_map_params::get_iv (const char *option, IV fallback) const |
130 | { |
131 | { |
131 | SV *sv = opt_sv (option); |
132 | SV *sv = opt_sv (option); |
132 | return sv ? SvIV (sv) : fallback; |
133 | return sv ? SvIV (sv) : fallback; |
133 | } |
134 | } |
134 | |
135 | |
135 | noinline UV |
136 | ecb_noinline UV |
136 | random_map_params::get_uv (const char *option, UV fallback) const |
137 | random_map_params::get_uv (const char *option, UV fallback) const |
137 | { |
138 | { |
138 | SV *sv = opt_sv (option); |
139 | SV *sv = opt_sv (option); |
139 | return sv ? SvUV (sv) : fallback; |
140 | return sv ? SvUV (sv) : fallback; |
140 | } |
141 | } |
141 | |
142 | |
142 | noinline NV |
143 | ecb_noinline NV |
143 | random_map_params::get_nv (const char *option, NV fallback) const |
144 | random_map_params::get_nv (const char *option, NV fallback) const |
144 | { |
145 | { |
145 | SV *sv = opt_sv (option); |
146 | SV *sv = opt_sv (option); |
146 | return sv ? SvNV (sv) : fallback; |
147 | return sv ? SvNV (sv) : fallback; |
147 | } |
148 | } |
148 | |
149 | |
149 | noinline void |
150 | ecb_noinline void |
150 | random_map_params::set (const char *option, SV *value) const |
151 | random_map_params::set (const char *option, SV *value) const |
151 | { |
152 | { |
152 | int len = strlen (option); |
153 | int len = strlen (option); |
153 | |
154 | |
154 | if (value) |
155 | if (value) |
155 | hv_store (hv, option, len, value, 0); |
156 | hv_store (hv, option, len, value, 0); |
156 | else |
157 | else |
157 | hv_delete (hv, option, len, G_DISCARD); |
158 | hv_delete (hv, option, len, G_DISCARD); |
158 | } |
159 | } |
159 | |
160 | |
160 | noinline void |
161 | ecb_noinline void |
161 | random_map_params::set (const char *option, const_utf8_string value) const |
162 | random_map_params::set (const char *option, const_utf8_string value) const |
162 | { |
163 | { |
163 | set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); |
164 | set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); |
164 | } |
165 | } |
165 | |
166 | |
… | |
… | |
193 | UV random_seed = RP->get_uv ("random_seed"); |
194 | UV random_seed = RP->get_uv ("random_seed"); |
194 | |
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 | random_seed = random_seed |
197 | random_seed = random_seed |
197 | ? 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 (random_seed); |
202 | rmg_rndm.seed (random_seed); |
202 | |
203 | |
203 | shstr buf = RP->as_shstr (); |
204 | shstr buf = RP->as_shstr (); |
… | |
… | |
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 | } |