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.34 by root, Wed Jul 11 16:55:18 2007 UTC vs.
Revision 1.38 by root, Sun May 4 15:23:04 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra 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 3 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,
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, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <unistd.h> 25#include <unistd.h>
26 26
114 } 114 }
115 115
116 return default_region (); 116 return default_region ();
117} 117}
118 118
119void
120region::do_destroy ()
121{
122 regions.erase (this);
123
124 attachable::do_destroy ();
125
126 refcnt_dec ();
127}
128
119/* 129/*
120 * returns 1 if the player is in the region reg, or a child region thereof 130 * returns 1 if the player is in the region reg, or a child region thereof
121 * otherwise returns 0 131 * otherwise returns 0
122 * if passed a NULL region returns -1 132 * if passed a NULL region returns -1
123 */ 133 */
124
125static int 134static int
126region_is_child_of_region (const region * child, const region * r) 135region_is_child_of_region (const region * child, const region * r)
127{ 136{
128 137
129 if (r == NULL) 138 if (r == NULL)
147 * created by this function. 156 * created by this function.
148 */ 157 */
149object * 158object *
150get_jail_exit (object *op) 159get_jail_exit (object *op)
151{ 160{
152 region *reg;
153 object *exit;
154
155 if (op->type != PLAYER) 161 if (op->type != PLAYER)
156 { 162 {
157 LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); 163 LOG (llevError, "region.c: get_jail_exit called against non-player object.\n");
158 return NULL; 164 return NULL;
159 } 165 }
160 166
161 reg = op->region (); 167 region *reg = op->region ();
162 while (reg) 168 while (reg)
163 { 169 {
164 if (reg->jailmap) 170 if (reg->jailmap)
165 { 171 {
166 exit = object::create (); 172 object *exit = object::create ();
167 EXIT_PATH (exit) = reg->jailmap; 173 EXIT_PATH (exit) = reg->jailmap;
168 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ 174 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */
169 SET_FLAG (exit, FLAG_DAMNED); 175 SET_FLAG (exit, FLAG_DAMNED);
170 EXIT_X (exit) = reg->jailx; 176 EXIT_X (exit) = reg->jailx;
171 EXIT_Y (exit) = reg->jaily; 177 EXIT_Y (exit) = reg->jaily;
184region::read (object_thawer &f) 190region::read (object_thawer &f)
185{ 191{
186 assert (f.kw == KW_region); 192 assert (f.kw == KW_region);
187 193
188 region *rgn = new region; 194 region *rgn = new region;
195 rgn->refcnt_inc ();
196
189 f.get (rgn->name); 197 f.get (rgn->name);
190 f.next (); 198 f.next ();
191 199
192 for (;;) 200 for (;;)
193 { 201 {
213 break; 221 break;
214 222
215 case KW_end: 223 case KW_end:
216 f.next (); 224 f.next ();
217 225
226 // cannot use find as that will request the default region
218 for_all_regions (old) 227 for_all_regions (old)
219 if (old->name == rgn->name) 228 if (old->name == rgn->name)
220 { 229 {
221 // replace, copy new values (ugly) 230 old->destroy ();
222 rgn->index = old->index;
223 *old = *rgn;
224 delete rgn;
225
226 return old; 231 break;
227 } 232 }
228 233
229 // just append 234 // just append
230 regions.push_back (rgn); 235 regions.push_back (rgn);
231 return rgn; 236 return rgn;
232 237
233 case KW_ERROR: 238 case KW_ERROR:
234 rgn->set_key (f.kw_str, f.value); 239 rgn->set_key_text (f.kw_str, f.value);
235 //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D 240 //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D
236 break; 241 break;
237 242
238 default: 243 default:
239 if (!f.parse_error ("region", rgn->name)) 244 if (!f.parse_error ("region", rgn->name))
240 { 245 {
241 delete rgn; 246 rgn->destroy ();
242 return 0; 247 return 0;
243 } 248 }
244 break; 249 break;
245 } 250 }
246 251

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines