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.40 by root, Wed Dec 31 17:35:37 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,2008 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 if (!r)
129 if (r == NULL)
130 return -1; 138 return -1;
131 139
132 if (child == NULL) 140 if (!child)
133 return 0; 141 return 0;
134 142
135 if (!strcmp (child->name, r->name)) 143 if (child->name == r->name)
136 return 1; 144 return 1;
137 145
138 else if (child->parent != NULL) 146 if (child->parent)
139 return region_is_child_of_region (child->parent, r); 147 return region_is_child_of_region (child->parent, r);
140 else 148
141 return 0; 149 return 0;
142} 150}
143 151
144/** Returns an object which is an exit through which the player represented by op should be 152/** Returns an object which is an exit through which the player represented by op should be
145 * sent in order to be imprisoned. If there is no suitable place to which an exit can be 153 * sent in order to be imprisoned. If there is no suitable place to which an exit can be
146 * constructed, then NULL will be returned. The caller is responsible for freeing the object 154 * constructed, then NULL will be returned. The caller is responsible for freeing the object
147 * created by this function. 155 * created by this function.
148 */ 156 */
149object * 157object *
150get_jail_exit (object *op) 158get_jail_exit (object *op)
151{ 159{
152 region *reg;
153 object *exit;
154
155 if (op->type != PLAYER) 160 if (op->type != PLAYER)
156 { 161 {
157 LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); 162 LOG (llevError, "region.c: get_jail_exit called against non-player object.\n");
158 return NULL; 163 return NULL;
159 } 164 }
160 165
161 reg = op->region (); 166 region *reg = op->region ();
162 while (reg) 167 while (reg)
163 { 168 {
164 if (reg->jailmap) 169 if (reg->jailmap)
165 { 170 {
166 exit = object::create (); 171 object *exit = object::create ();
167 EXIT_PATH (exit) = reg->jailmap; 172 EXIT_PATH (exit) = reg->jailmap;
168 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ 173 /* damned exits reset savebed and remove teleports, so the prisoner can't escape */
169 SET_FLAG (exit, FLAG_DAMNED); 174 SET_FLAG (exit, FLAG_DAMNED);
170 EXIT_X (exit) = reg->jailx; 175 EXIT_X (exit) = reg->jailx;
171 EXIT_Y (exit) = reg->jaily; 176 EXIT_Y (exit) = reg->jaily;
184region::read (object_thawer &f) 189region::read (object_thawer &f)
185{ 190{
186 assert (f.kw == KW_region); 191 assert (f.kw == KW_region);
187 192
188 region *rgn = new region; 193 region *rgn = new region;
194 rgn->refcnt_inc ();
195
189 f.get (rgn->name); 196 f.get (rgn->name);
190 f.next (); 197 f.next ();
191 198
192 for (;;) 199 for (;;)
193 { 200 {
213 break; 220 break;
214 221
215 case KW_end: 222 case KW_end:
216 f.next (); 223 f.next ();
217 224
225 // cannot use find as that will request the default region
218 for_all_regions (old) 226 for_all_regions (old)
219 if (old->name == rgn->name) 227 if (old->name == rgn->name)
220 { 228 {
221 // replace, copy new values (ugly) 229 old->destroy ();
222 rgn->index = old->index;
223 *old = *rgn;
224 delete rgn;
225
226 return old; 230 break;
227 } 231 }
228 232
229 // just append 233 // just append
230 regions.push_back (rgn); 234 regions.push_back (rgn);
231 return rgn; 235 return rgn;
232 236
233 case KW_ERROR: 237 case KW_ERROR:
234 rgn->set_key (f.kw_str, f.value); 238 rgn->set_key_text (f.kw_str, f.value);
235 //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D 239 //fprintf (stderr, "region addkv(%s,%s)\n", f.kw_str, f.value);//D
236 break; 240 break;
237 241
238 default: 242 default:
239 if (!f.parse_error ("region", rgn->name)) 243 if (!f.parse_error ("region", rgn->name))
240 { 244 {
241 delete rgn; 245 rgn->destroy ();
242 return 0; 246 return 0;
243 } 247 }
244 break; 248 break;
245 } 249 }
246 250

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines