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

Comparing deliantra/server/common/region.C (file contents):
Revision 1.24 by root, Fri Feb 2 00:42:03 2007 UTC vs.
Revision 1.34 by root, Wed Jul 11 16:55:18 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <unistd.h> 25#include <unistd.h>
27
28#include "loader.h"
29 26
30regionvec regions; 27regionvec regions;
31 28
32region * 29region *
33region::default_region () 30region::default_region ()
181 LOG (llevError, "No suitable jailmap for region %s was found.\n", &reg->name); 178 LOG (llevError, "No suitable jailmap for region %s was found.\n", &reg->name);
182 179
183 return 0; 180 return 0;
184} 181}
185 182
186region *loader_region::get_region (const char *name) 183region *
184region::read (object_thawer &f)
187{ 185{
186 assert (f.kw == KW_region);
187
188 region *rgn = new region; 188 region *rgn = new region;
189 rgn->name = name; 189 f.get (rgn->name);
190 return rgn; 190 f.next ();
191}
192 191
193void loader_region::put_region (region *rgn)
194{
195 for_all_regions (old)
196 if (old->name == rgn->name)
197 {
198 // replace, copy new values (ugly)
199 rgn->index = old->index;
200 *old = *rgn;
201 delete rgn;
202
203 return;
204 }
205
206 // just append
207 regions.push_back (rgn);
208}
209
210bool
211loader_base::parse_region (object_thawer &thawer, region *rgn)
212{
213 for (;;) 192 for (;;)
214 { 193 {
215 keyword kw = thawer.get_kv ();
216
217 switch (kw) 194 switch (f.kw)
218 { 195 {
219 case KW_parent: 196 case KW_parent:
220 rgn->parent = region::find (thawer.get_str ()); 197 rgn->parent = region::find (f.get_str ());
221 break;
222
223 case KW_longname:
224 thawer.get (rgn->longname);
225 break; 198 break;
226 199
227 case KW_jail_map: 200 case KW_msg: f.get_ml (KW_endmsg, rgn->msg); break;
228 thawer.get (rgn->jailmap); 201 case KW_longname: f.get (rgn->longname); break;
229 break; 202 case KW_jail_map: f.get (rgn->jailmap); break;
203 case KW_jail_x: f.get (rgn->jailx); break;
204 case KW_jail_y: f.get (rgn->jaily); break;
205 case KW_portal_map: f.get (rgn->portalmap);break;
206 case KW_portal_x: f.get (rgn->portalx); break;
207 case KW_portal_y: f.get (rgn->portaly); break;
208 case KW_fallback: f.get (rgn->fallback); break;
209 case KW_chance: f.get (rgn->treasure_density); break;
230 210
231 case KW_jail_x:
232 thawer.get (rgn->jailx);
233 break;
234
235 case KW_jail_y:
236 thawer.get (rgn->jaily);
237 break;
238
239 case KW_msg: 211 case KW_randomitems:
240 thawer.get_ml (KW_endmsg, rgn->msg); 212 rgn->treasure = treasurelist::get (f.get_str ());
241 break;
242
243 case KW_fallback:
244 thawer.get (rgn->fallback);
245 break; 213 break;
246 214
247 case KW_end: 215 case KW_end:
216 f.next ();
217
218 for_all_regions (old)
219 if (old->name == rgn->name)
220 {
221 // replace, copy new values (ugly)
222 rgn->index = old->index;
223 *old = *rgn;
224 delete rgn;
225
226 return old;
227 }
228
229 // just append
230 regions.push_back (rgn);
248 return true; 231 return rgn;
232
233 case KW_ERROR:
234 rgn->set_key (f.kw_str, f.value);
235 //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D
236 break;
249 237
250 default: 238 default:
251 if (!thawer.parse_error (kw, "region", rgn->name)) 239 if (!f.parse_error ("region", rgn->name))
240 {
241 delete rgn;
252 return false; 242 return 0;
243 }
253 break; 244 break;
254 } 245 }
246
247 f.next ();
255 } 248 }
256} 249}
257 250
258/* 251/*
259 * First initialises the archtype hash-table (init_archetable()). 252 * First initialises the archtype hash-table (init_archetable()).
260 * Reads and parses the archetype file (with the first and second-pass 253 * Reads and parses the archetype file (with the first and second-pass
261 * functions). 254 * functions).
262 * Then initialises treasures by calling load_treasures().
263 */ 255 */
264void 256void
265init_regions (void) 257init_regions (void)
266{ 258{
267 if (!regions.size ()) 259 if (!regions.size ())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines