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

Comparing deliantra/server/server/pets.C (file contents):
Revision 1.6 by root, Tue Sep 12 20:55:18 2006 UTC vs.
Revision 1.38 by root, Sun Jul 1 05:00:20 2007 UTC

1
2/* 1/*
3 * static char *rcsid_pets_c = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
4 * "$Id: pets.C,v 1.6 2006/09/12 20:55:18 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
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
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
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/>.
20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
5 */ 22 */
6 23
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28*/
29
30#include <global.h> 24#include <global.h>
31#ifndef __CEXTRACT__
32# include <sproto.h> 25#include <sproto.h>
33#endif
34 26
35/* given that 'pet' is a friendly object, this function returns a 27/* given that 'pet' is a friendly object, this function returns a
36 * monster the pet should attack, NULL if nothing appropriate is 28 * monster the pet should attack, NULL if nothing appropriate is
37 * found. it basically looks for nasty things around the owner 29 * found. it basically looks for nasty things around the owner
38 * of the pet to attack. 30 * of the pet to attack.
39 * this is now tilemap aware. 31 * this is now tilemap aware.
40 */ 32 */
41
42object * 33object *
43get_pet_enemy (object *pet, rv_vector * rv) 34get_pet_enemy (object *pet, rv_vector * rv)
44{ 35{
45 object *owner, *tmp, *attacker, *tmp3; 36 object *owner, *tmp, *attacker, *tmp3;
46 int i; 37 int i;
47 sint16 x, y; 38 sint16 x, y;
48 mapstruct *nm; 39 maptile *nm;
49 int search_arr[SIZEOFFREE]; 40 int search_arr[SIZEOFFREE];
50 int mflags; 41 int mflags;
51 42
52 attacker = pet->attacked_by; /*pointer to attacking enemy */ 43 attacker = pet->attacked_by; /*pointer to attacking enemy */
53 pet->attacked_by = NULL; /*clear this, since we are dealing with it */ 44 pet->attacked_by = NULL; /*clear this, since we are dealing with it */
54 45
55 if ((owner = get_owner (pet)) != NULL) 46 if (owner = pet->owner)
56 { 47 {
57 /* If the owner has turned on the pet, make the pet 48 /* If the owner has turned on the pet, make the pet
58 * unfriendly. 49 * unfriendly.
59 */ 50 */
60 if ((check_enemy (owner, rv)) == pet) 51 if (check_enemy (owner, rv) == pet)
61 { 52 {
62 CLEAR_FLAG (pet, FLAG_FRIENDLY);
63 remove_friendly_object (pet); 53 remove_friendly_object (pet);
64 pet->attack_movement &= ~PETMOVE; 54 pet->attack_movement &= ~PETMOVE;
65 return owner; 55 return owner;
66 } 56 }
67 } 57 }
68 else 58 else
69 { 59 {
70 /* else the owner is no longer around, so the 60 /* else the owner is no longer around, so the
71 * pet no longer needs to be friendly. 61 * pet no longer needs to be friendly.
72 */ 62 */
73 CLEAR_FLAG (pet, FLAG_FRIENDLY);
74 remove_friendly_object (pet); 63 remove_friendly_object (pet);
75 pet->attack_movement &= ~PETMOVE; 64 pet->attack_movement &= ~PETMOVE;
76 return NULL; 65 return 0;
77 } 66 }
67
78 /* If they are not on the same map, the pet won't be agressive */ 68 /* If they are not on the same map, the pet won't be agressive */
79 if (!on_same_map (pet, owner)) 69 //if (!on_same_map (pet, owner))
80 return NULL; 70 // return 0;
81 71
82 /* See if the pet has an existing enemy. If so, don't start a new one */ 72 /* See if the pet has an existing enemy. If so, don't start a new one */
83 if ((tmp = check_enemy (pet, rv)) != NULL) 73 if (tmp = check_enemy (pet, rv))
84 { 74 {
85 if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) 75 if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY))
86 /* without this check, you can actually get pets with 76 /* without this check, you can actually get pets with
87 * enemy set to owner! 77 * enemy set to owner!
88 */ 78 */
89 pet->enemy = NULL; 79 pet->enemy = 0;
90 else 80 else
91 return tmp; 81 return tmp;
92 } 82 }
83
93 get_search_arr (search_arr); 84 get_search_arr (search_arr);
94 85
95 if (owner->type == PLAYER && owner->contr->petmode > pet_normal) 86 if (owner->type == PLAYER && owner->contr->petmode > pet_normal)
96 { 87 {
97 if (owner->contr->petmode == pet_sad) 88 if (owner->contr->petmode == pet_sad)
98 { 89 {
99 tmp = find_nearest_living_creature (pet); 90 tmp = find_nearest_living_creature (pet);
100 if (tmp != NULL) 91 if (tmp != 0)
101 { 92 {
102 get_rangevector (pet, tmp, rv, 0); 93 get_rangevector (pet, tmp, rv, 0);
103 if (check_enemy (pet, rv) != NULL) 94 if (check_enemy (pet, rv) != 0)
104 return tmp; 95 return tmp;
105 else 96 else
106 pet->enemy = NULL; 97 pet->enemy = 0;
107 } 98 }
108 /* if we got here we have no enemy */ 99 /* if we got here we have no enemy */
109 /* we return NULL to avoid heading back to the owner */ 100 /* we return 0 to avoid heading back to the owner */
110 pet->enemy = NULL; 101 pet->enemy = 0;
111 return NULL; 102 return 0;
112 } 103 }
113 } 104 }
114 105
115 /* Since the pet has no existing enemy, look for anything nasty 106 /* Since the pet has no existing enemy, look for anything nasty
116 * around the owner that it should go and attack. 107 * around the owner that it should go and attack. (if the owner is
108 * still on a map)
117 */ 109 */
118 tmp3 = NULL; 110 // owners sometimes are not on a map but in the inventory of somehting else
111 if (!owner->flag [FLAG_REMOVED] && owner->map)
112 {
113 tmp3 = 0;
114
119 for (i = 0; i < SIZEOFFREE; i++) 115 for (i = 0; i < SIZEOFFREE; i++)
120 { 116 {
121 x = owner->x + freearr_x[search_arr[i]]; 117 x = owner->x + freearr_x[search_arr[i]];
122 y = owner->y + freearr_y[search_arr[i]]; 118 y = owner->y + freearr_y[search_arr[i]];
123 nm = owner->map; 119 nm = owner->map;
124 /* Only look on the space if there is something alive there. */ 120 /* Only look on the space if there is something alive there. */
125 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 121 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
122
126 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 123 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
127 { 124 {
128 for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) 125 for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above)
129 {
130 object *tmp2 = tmp->head == NULL ? tmp : tmp->head;
131
132 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
133 (tmp2->type != PLAYER)) ||
134 should_arena_attack (pet, owner, tmp2))
135 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv))
136 { 126 {
127 object *tmp2 = tmp->head == 0 ? tmp : tmp->head;
137 128
138 if (!can_see_enemy (pet, tmp2)) 129 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
130 (tmp2->type != PLAYER)) ||
131 should_arena_attack (pet, owner, tmp2))
132 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv))
139 { 133 {
134
135 if (!can_see_enemy (pet, tmp2))
136 {
140 if (tmp3 != NULL) 137 if (tmp3 != 0)
141 tmp3 = tmp2; 138 tmp3 = tmp2;
142 } 139 }
143 else
144 {
145 pet->enemy = tmp2;
146 if (check_enemy (pet, rv) != NULL)
147 return tmp2;
148 else 140 else
141 {
142 pet->enemy = tmp2;
143 if (check_enemy (pet, rv) != 0)
144 return tmp2;
145 else
149 pet->enemy = NULL; 146 pet->enemy = 0;
150 } 147 }
151 } /* if this is a valid enemy */ 148 } /* if this is a valid enemy */
152 } /* for objects on this space */ 149 } /* for objects on this space */
153 } /* if there is something living on this space */ 150 } /* if there is something living on this space */
154 } /* for loop of spaces around the owner */ 151 } /* for loop of spaces around the owner */
155 152
156 /* fine, we went through the whole loop and didn't find one we could 153 /* fine, we went through the whole loop and didn't find one we could
157 see, take what we have */ 154 see, take what we have */
158 if (tmp3 != NULL) 155 if (tmp3 != 0)
159 { 156 {
160 pet->enemy = tmp3; 157 pet->enemy = tmp3;
161 if (check_enemy (pet, rv) != NULL) 158 if (check_enemy (pet, rv) != 0)
162 return tmp3; 159 return tmp3;
163 else 160 else
164 pet->enemy = NULL; 161 pet->enemy = 0;
162 }
165 } 163 }
166 164
167 /* No threat to owner, check to see if the pet has an attacker */ 165 /* No threat to owner, check to see if the pet has an attacker */
168 if (attacker) 166 if (attacker)
169 { 167 {
170 /* need to be sure this is the right one! */
171 if (attacker->count == pet->attacked_by_count)
172 {
173 /* also need to check to make sure it is not freindly */ 168 /* also need to check to make sure it is not freindly */
174 /* or otherwise non-hostile, and is an appropriate target */ 169 /* or otherwise non-hostile, and is an appropriate target */
175 if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) 170 if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker))
176 { 171 {
177 pet->enemy = attacker; 172 pet->enemy = attacker;
173
178 if (check_enemy (pet, rv) != NULL) 174 if (check_enemy (pet, rv) != 0)
179 return attacker; 175 return attacker;
180 else 176 else
181 pet->enemy = NULL; 177 pet->enemy = 0;
182 }
183 } 178 }
184 } 179 }
185 180
186 /* Don't have an attacker or legal enemy, so look for a new one!. 181 /* Don't have an attacker or legal enemy, so look for a new one!.
187 * This looks for one around where the pet is. Thus, you could lead 182 * This looks for one around where the pet is. Thus, you could lead
188 * a pet to danger, then take a few steps back. This code is basically 183 * a pet to danger, then take a few steps back. This code is basically
189 * the same as the code that looks around the owner. 184 * the same as the code that looks around the owner.
190 */ 185 */
191 if (owner->type == PLAYER && owner->contr->petmode != pet_defend) 186 if (owner->type == PLAYER && owner->contr->petmode != pet_defend)
192 { 187 {
193 tmp3 = NULL; 188 tmp3 = 0;
194 for (i = 0; i < SIZEOFFREE; i++) 189 for (i = 0; i < SIZEOFFREE; i++)
195 { 190 {
196 x = pet->x + freearr_x[search_arr[i]]; 191 x = pet->x + freearr_x[search_arr[i]];
197 y = pet->y + freearr_y[search_arr[i]]; 192 y = pet->y + freearr_y[search_arr[i]];
198 nm = pet->map; 193 nm = pet->map;
199 /* Only look on the space if there is something alive there. */ 194 /* Only look on the space if there is something alive there. */
200 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 195 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
201 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 196 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
202 { 197 {
203 for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) 198 for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above)
204 { 199 {
205 object *tmp2 = tmp->head == NULL ? tmp : tmp->head; 200 object *tmp2 = tmp->head == 0 ? tmp : tmp->head;
206 201
207 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && 202 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
208 (tmp2->type != PLAYER)) || 203 (tmp2->type != PLAYER)) ||
209 should_arena_attack (pet, owner, tmp2)) 204 should_arena_attack (pet, owner, tmp2))
210 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) 205 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv))
211 { 206 {
212 207
213 if (!can_see_enemy (pet, tmp2)) 208 if (!can_see_enemy (pet, tmp2))
214 { 209 {
215 if (tmp3 != NULL) 210 if (tmp3 != 0)
216 tmp3 = tmp2; 211 tmp3 = tmp2;
217 } 212 }
218 else 213 else
219 { 214 {
220 pet->enemy = tmp2; 215 pet->enemy = tmp2;
221 if (check_enemy (pet, rv) != NULL) 216 if (check_enemy (pet, rv) != 0)
222 return tmp2; 217 return tmp2;
223 else 218 else
224 pet->enemy = NULL; 219 pet->enemy = 0;
225 } 220 }
226 } /* make sure we can get to the bugger */ 221 } /* make sure we can get to the bugger */
227 } /* for objects on this space */ 222 } /* for objects on this space */
228 } /* if there is something living on this space */ 223 } /* if there is something living on this space */
229 } /* for loop of spaces around the pet */ 224 } /* for loop of spaces around the pet */
225
226 /* fine, we went through the whole loop and didn't find one we could
227 see, take what we have */
228 if (tmp3 != 0)
229 {
230 pet->enemy = tmp3;
231 if (check_enemy (pet, rv) != 0)
232 return tmp3;
233 else
234 pet->enemy = 0;
235 }
230 } /* pet in defence mode */ 236 } /* pet in defence mode */
231 237
232 /* fine, we went through the whole loop and didn't find one we could 238 object *enemy = check_enemy (pet, rv);
233 see, take what we have */ 239 // we have a summoned pet here and the owners enemy isn't set or can't
234 if (tmp3 != NULL) 240 // be reached => search for a player around us and set it as our new enemy!!
235 { 241 if (!enemy && pet->owner && pet->owner->type != PLAYER)
236 pet->enemy = tmp3; 242 enemy = get_nearest_player (pet);
237 if (check_enemy (pet, rv) != NULL)
238 return tmp3;
239 else
240 pet->enemy = NULL;
241 }
242 243
243 /* Didn't find anything - return the owner's enemy or NULL */ 244 /* Didn't find anything - return the owner's enemy or 0 */
244 return check_enemy (pet, rv); 245 return enemy;
245} 246}
246 247
247void 248void
248terminate_all_pets (object *owner) 249terminate_all_pets (object *owner)
249{ 250{
250 objectlink *obl, *next; 251 objectlink *obl, *next;
251 252
252 for (obl = first_friendly_object; obl != NULL; obl = next) 253 for (obl = first_friendly_object; obl; obl = next)
253 { 254 {
254 object *ob = obl->ob; 255 object *ob = obl->ob;
255
256 next = obl->next; 256 next = obl->next;
257
257 if (get_owner (ob) == owner) 258 if (ob->owner == owner)
258 { 259 ob->destroy ();
259 if (!QUERY_FLAG (ob, FLAG_REMOVED))
260 remove_ob (ob);
261 remove_friendly_object (ob);
262 free_object (ob);
263 }
264 } 260 }
265} 261}
266 262
267/* 263/*
268 * Unfortunately, sometimes, the owner of a pet is in the 264 * Unfortunately, sometimes, the owner of a pet is in the
270 * Thus the map isn't loaded yet, and we have to remove 266 * Thus the map isn't loaded yet, and we have to remove
271 * the pet... 267 * the pet...
272 * Interesting enough, we don't use the passed map structure in 268 * Interesting enough, we don't use the passed map structure in
273 * this function. 269 * this function.
274 */ 270 */
275
276void 271void
277remove_all_pets (mapstruct *map) 272remove_all_pets (maptile *map)
278{ 273{
279 objectlink *obl, *next; 274 objectlink *obl, *next;
280 object *owner; 275 object *owner;
281 276
282 for (obl = first_friendly_object; obl != NULL; obl = next) 277 for (obl = first_friendly_object; obl; obl = next)
283 { 278 {
284 next = obl->next; 279 next = obl->next;
285 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && 280
286 (owner = get_owner (obl->ob)) != NULL && !on_same_map (owner, obl->ob)) 281 if (obl->ob->type != PLAYER
282 && QUERY_FLAG (obl->ob, FLAG_FRIENDLY)
283 && (owner = obl->ob->owner) != 0
284 && !on_same_map (owner, obl->ob))
287 { 285 {
288 /* follow owner checks map status for us */ 286 /* follow owner checks map status for us */
289 follow_owner (obl->ob, owner); 287 follow_owner (obl->ob, owner);
290 } 288 }
291 } 289 }
292} 290}
293 291
294int 292int
295follow_owner (object *ob, object *owner) 293follow_owner (object *ob, object *owner)
296{ 294{
297 object *tmp; 295 if (owner->flag [FLAG_REMOVED])
298 int dir; 296 return 0; // do nothing if the owner is removed
299
300 if (!QUERY_FLAG (ob, FLAG_REMOVED))
301 remove_ob (ob);
302
303 if (owner->map == NULL)
304 {
305 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name);
306 goto fail;
307 }
308 if (owner->map->in_memory != MAP_IN_MEMORY) 297 else if (!owner->map || owner->map->in_memory != MAP_IN_MEMORY)
309 {
310 LOG (llevError, "Owner of the pet not on a map in memory!?\n"); 298 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name);
311 goto fail; 299 else
312 } 300 {
313
314 dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); 301 int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE);
315 302
316 if (dir == -1) 303 if (dir >= 0)
317 {
318 LOG (llevMonster, "No space for pet to follow, freeing %s.\n", &ob->name);
319 goto fail;
320 }
321 for (tmp = ob; tmp != NULL; tmp = tmp->more)
322 {
323 tmp->x = owner->x + freearr_x[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
324 tmp->y = owner->y + freearr_y[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
325 tmp->map = owner->map;
326 if (OUT_OF_REAL_MAP (tmp->map, tmp->x, tmp->y))
327 {
328 tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y);
329 } 304 {
330 } 305 owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]);
331 insert_ob_in_map (ob, ob->map, NULL, 0); 306
332 if (owner->type == PLAYER) /* Uh, I hope this is always true... */ 307 if (owner->type == PLAYER) /* Uh, I hope this is always true... */
333 new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); 308 new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you");
334 309
335 return 0; 310 return 0;
311 }
312 }
336 313
337fail: 314 ob->destroy ();
338 remove_friendly_object (ob);
339 free_object (ob);
340
341 return 1; 315 return 1;
342} 316}
343 317
344void 318void
345pet_move (object *ob) 319pet_move (object *ob)
346{ 320{
347 int dir, tag, i; 321 int dir = 0, i;
348 sint16 dx, dy; 322 sint16 dx, dy;
349 object *ob2, *owner; 323 object *ob2, *owner;
350 mapstruct *m; 324 maptile *m;
351 325
352 /* Check to see if player pulled out */ 326 /* Check to see if player pulled out */
353 if ((owner = get_owner (ob)) == NULL) 327 if ((owner = ob->owner) == NULL)
354 { 328 {
355 remove_ob (ob); /* Will be freed when returning */ 329 ob->destroy ();
356 remove_friendly_object (ob);
357 free_object (ob);
358 LOG (llevMonster, "Pet: no owner, leaving.\n"); 330 LOG (llevMonster, "Pet: no owner, leaving.\n");
359 return; 331 return;
360 } 332 }
361 333
362 /* move monster into the owners map if not in the same map */ 334 /* move monster into the owners map if not in the same map
363 if (!on_same_map (ob, owner)) 335 * except when the owner is removed.
336 */
337 if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED])
364 { 338 {
365 follow_owner (ob, owner); 339 follow_owner (ob, owner);
366 return; 340 return;
367 } 341 }
368 /* Calculate Direction */ 342 /* Calculate Direction */
381 continue; 355 continue;
382 else 356 else
383 break; 357 break;
384 } 358 }
385 } 359 }
386 else 360 else if (!owner->flag [FLAG_REMOVED]) // only get vector to owner when owner not removed
387 { 361 {
388 struct rv_vector rv; 362 struct rv_vector rv;
389 363
390 get_rangevector (ob, ob->owner, &rv, 0); 364 get_rangevector (ob, ob->owner, &rv, 0);
391 dir = rv.direction; 365 dir = rv.direction;
392 } 366 }
393 ob->direction = dir; 367 ob->direction = dir;
394 368
395 tag = ob->count;
396 /* move_ob returns 0 if the object couldn't move. If that is the 369 /* move_ob returns 0 if the object couldn't move. If that is the
397 * case, lets do some other work. 370 * case, lets do some other work.
398 */ 371 */
399 if (!(move_ob (ob, dir, ob))) 372 if (!(move_ob (ob, dir, ob)))
400 { 373 {
401 object *part; 374 object *part;
402 375
403 /* the failed move_ob above may destroy the pet, so check here */ 376 /* the failed move_ob above may destroy the pet, so check here */
404 if (was_destroyed (ob, tag)) 377 if (ob->destroyed ())
405 return; 378 return;
406 379
407 for (part = ob; part != NULL; part = part->more) 380 for (part = ob; part != NULL; part = part->more)
408 { 381 {
409 dx = part->x + freearr_x[dir]; 382 dx = part->x + freearr_x[dir];
410 dy = part->y + freearr_y[dir]; 383 dy = part->y + freearr_y[dir];
411 m = get_map_from_coord (part->map, &dx, &dy); 384 m = get_map_from_coord (part->map, &dx, &dy);
412 if (!m) 385 if (!m)
413 continue; 386 continue;
414 387
415 for (ob2 = get_map_ob (m, dx, dy); ob2 != NULL; ob2 = ob2->above) 388 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above)
416 { 389 {
417 object *new_ob; 390 object *new_ob;
418 391
419 new_ob = ob2->head ? ob2->head : ob2; 392 new_ob = ob2->head ? ob2->head : ob2;
420 if (new_ob == ob) 393 if (new_ob == ob)
421 break; 394 break;
422 if (new_ob == ob->owner) 395 if (new_ob == ob->owner)
423 return; 396 return;
424 if (get_owner (new_ob) == ob->owner) 397 if (new_ob->owner == ob->owner)
425 break; 398 break;
426 399
427 /* Hmm. Did we try to move into an enemy monster? If so, 400 /* Hmm. Did we try to move into an enemy monster? If so,
428 * make it our enemy. 401 * make it our enemy.
429 */ 402 */
442 return; 415 return;
443 } 416 }
444 } 417 }
445 } 418 }
446 /* Try a different course */ 419 /* Try a different course */
447 dir = absdir (dir + 4 - (RANDOM () % 5) - (RANDOM () % 5)); 420 dir = absdir (dir + 4 - (rndm (5)) - (rndm (5)));
448 (void) move_ob (ob, dir, ob); 421 (void) move_ob (ob, dir, ob);
449 } 422 }
450 return; 423 return;
451} 424}
452 425
463 * is_golem is to note that this is a golem spell. 436 * is_golem is to note that this is a golem spell.
464 */ 437 */
465object * 438object *
466fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 439fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
467{ 440{
468 archetype *atmp;
469 object *tmp = NULL, *prev = NULL, *head = NULL; 441 object *tmp = NULL, *prev = NULL, *head = NULL;
470 442
471 for (atmp = at; atmp != NULL; atmp = atmp->more) 443 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
472 { 444 {
473 tmp = arch_to_object (atmp); 445 tmp = arch_to_object (atmp);
446
474 if (atmp == at) 447 if (atmp == at)
475 { 448 {
476 if (!is_golem) 449 if (!is_golem)
477 SET_FLAG (tmp, FLAG_MONSTER); 450 SET_FLAG (tmp, FLAG_MONSTER);
451
478 set_owner (tmp, op); 452 tmp->set_owner (op);
453
479 if (op->type == PLAYER) 454 if (op->type == PLAYER)
480 { 455 {
481 tmp->stats.exp = 0; 456 tmp->stats.exp = 0;
482 add_friendly_object (tmp); 457 add_friendly_object (tmp);
483 SET_FLAG (tmp, FLAG_FRIENDLY);
484 if (is_golem) 458 if (is_golem)
485 CLEAR_FLAG (tmp, FLAG_MONSTER); 459 CLEAR_FLAG (tmp, FLAG_MONSTER);
486 } 460 }
487 else 461 else
488 { 462 {
489 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 463 if (QUERY_FLAG (op, FLAG_FRIENDLY))
490 { 464 {
491 object *owner = get_owner (op); 465 object *owner = op->owner;
492 466
493 if (owner != NULL) 467 if (owner)
494 { /* For now, we transfer ownership */ 468 { /* For now, we transfer ownership */
495 set_owner (tmp, owner); 469 tmp->set_owner (owner);
496 tmp->attack_movement = PETMOVE; 470 tmp->attack_movement = PETMOVE;
497 add_friendly_object (tmp); 471 add_friendly_object (tmp);
498 SET_FLAG (tmp, FLAG_FRIENDLY);
499 } 472 }
500 } 473 }
501 } 474 }
475
502 if (op->type != PLAYER || !is_golem) 476 if (op->type != PLAYER || !is_golem)
503 { 477 {
504 tmp->attack_movement = PETMOVE; 478 tmp->attack_movement = PETMOVE;
505 tmp->speed_left = -1; 479 tmp->speed_left = -1;
506 tmp->type = 0; 480 tmp->type = 0;
508 } 482 }
509 else 483 else
510 tmp->type = GOLEM; 484 tmp->type = GOLEM;
511 485
512 } 486 }
487
513 if (head == NULL) 488 if (!head)
514 head = tmp; 489 head = tmp;
490
515 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; 491 tmp->x = op->x + freearr_x[dir] + tmp->arch->x;
516 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; 492 tmp->y = op->y + freearr_y[dir] + tmp->arch->y;
517 tmp->map = op->map; 493 tmp->map = op->map;
494
518 if (tmp->invisible) 495 if (tmp->invisible)
519 tmp->invisible = 0; 496 tmp->invisible = 0;
497
520 if (head != tmp) 498 if (head != tmp)
521 tmp->head = head, prev->more = tmp; 499 tmp->head = head, prev->more = tmp;
500
522 prev = tmp; 501 prev = tmp;
523 } 502 }
503
524 head->direction = dir; 504 head->direction = dir;
525 505
526 /* need to change some monster attr to prevent problems/crashing */ 506 /* need to change some monster attr to prevent problems/crashing */
527 head->last_heal = 0; 507 head->last_heal = 0;
528 head->last_eat = 0; 508 head->last_eat = 0;
539 519
540 return head; 520 return head;
541} 521}
542 522
543/* updated this to allow more than the golem 'head' to attack */ 523/* updated this to allow more than the golem 'head' to attack */
544
545/* op is the golem to be moved. */ 524/* op is the golem to be moved. */
546
547void 525void
548move_golem (object *op) 526move_golem (object *op)
549{ 527{
550 int made_attack = 0; 528 int made_attack = 0;
551 object *tmp; 529 object *tmp;
552 tag_t tag;
553 530
554 if (QUERY_FLAG (op, FLAG_MONSTER)) 531 if (QUERY_FLAG (op, FLAG_MONSTER))
555 return; /* Has already been moved */ 532 return; /* Has already been moved */
556 533
557 if (get_owner (op) == NULL) 534 if (!op->owner)
558 { 535 {
559 LOG (llevDebug, "Golem without owner destructed.\n"); 536 LOG (llevDebug, "Golem without owner destructed.\n");
560 remove_ob (op); 537 op->remove ();
561 free_object (op); 538 op->destroy ();
562 return; 539 return;
563 } 540 }
541
564 /* It would be nice to have a cleaner way of what message to print 542 /* It would be nice to have a cleaner way of what message to print
565 * when the golem expires than these hard coded entries. 543 * when the golem expires than these hard coded entries.
566 * Note it is intentional that a golems duration is based on its 544 * Note it is intentional that a golems duration is based on its
567 * hp, and not duration 545 * hp, and not duration
568 */ 546 */
569 if (--op->stats.hp < 0) 547 if (--op->stats.hp < 0)
570 { 548 {
571 if (op->msg) 549 if (op->msg)
572 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
573 op->owner->contr->ranges[range_golem] = NULL; 551
574 op->owner->contr->golem_count = 0; 552 op->destroy ();
575 remove_friendly_object (op);
576 remove_ob (op);
577 free_object (op);
578 return; 553 return;
579 } 554 }
580 555
581 /* Do golem attacks/movement for single & multisq golems. 556 /* Do golem attacks/movement for single & multisq golems.
582 * Assuming here that op is the 'head' object. Pass only op to 557 * Assuming here that op is the 'head' object. Pass only op to
583 * move_ob (makes recursive calls to other parts) 558 * move_ob (makes recursive calls to other parts)
584 * move_ob returns 0 if the creature was not able to move. 559 * move_ob returns 0 if the creature was not able to move.
585 */ 560 */
586 tag = op->count;
587 if (move_ob (op, op->direction, op)) 561 if (move_ob (op, op->direction, op))
588 return; 562 return;
589 if (was_destroyed (op, tag)) 563
564 if (op->destroyed ())
590 return; 565 return;
591 566
592 for (tmp = op; tmp; tmp = tmp->more) 567 for (tmp = op; tmp; tmp = tmp->more)
593 { 568 {
594 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; 569 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction];
595 object *victim; 570 object *victim;
596 mapstruct *m; 571 maptile *m;
597 int mflags; 572 int mflags;
598 573
599 m = op->map; 574 m = op->map;
600 mflags = get_map_flags (m, &m, x, y, &x, &y); 575 mflags = get_map_flags (m, &m, x, y, &x, &y);
601 576
602 if (mflags & P_OUT_OF_MAP) 577 if (mflags & P_OUT_OF_MAP)
603 continue; 578 continue;
604 579
605 for (victim = get_map_ob (op->map, x, y); victim; victim = victim->above) 580 for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above)
606 if (QUERY_FLAG (victim, FLAG_ALIVE)) 581 if (QUERY_FLAG (victim, FLAG_ALIVE))
607 break; 582 break;
608 583
609 /* We used to call will_hit_self to make sure we don't 584 /* We used to call will_hit_self to make sure we don't
610 * hit ourselves, but that didn't work, and I don't really 585 * hit ourselves, but that didn't work, and I don't really
613 * but since we are not trying to dereferance that pointer, 588 * but since we are not trying to dereferance that pointer,
614 * that isn't a problem. 589 * that isn't a problem.
615 */ 590 */
616 if (victim && victim != op && victim->head != op) 591 if (victim && victim != op && victim->head != op)
617 { 592 {
618
619 /* for golems with race fields, we don't attack 593 /* for golems with race fields, we don't attack
620 * aligned races 594 * aligned races
621 */ 595 */
622 596
623 if (victim->race && op->race && strstr (op->race, victim->race)) 597 if (victim->race && op->race && strstr (op->race, victim->race))
635 attack_ob (victim, op); 609 attack_ob (victim, op);
636 made_attack = 1; 610 made_attack = 1;
637 } 611 }
638 } /* If victim */ 612 } /* If victim */
639 } 613 }
614
640 if (made_attack) 615 if (made_attack)
641 update_object (op, UP_OBJ_FACE); 616 update_object (op, UP_OBJ_FACE);
642} 617}
643 618
644/* this is a really stupid function when you get down and 619/* this is a really stupid function when you get down and
666 char buf[MAX_BUF]; 641 char buf[MAX_BUF];
667 642
668 /* Because there can be different golem spells, player may want to 643 /* Because there can be different golem spells, player may want to
669 * 'lose' their old golem. 644 * 'lose' their old golem.
670 */ 645 */
671 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) 646 if (op->type == PLAYER && op->contr->golem)
672 { 647 {
673 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); 648 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem.");
674 remove_ob (op->contr->ranges[range_golem]); 649 op->contr->golem->remove ();
675 free_object (op->contr->ranges[range_golem]); 650 op->contr->golem->destroy ();
676 op->contr->ranges[range_golem] = NULL; 651 op->contr->golem = 0;
677 op->contr->golem_count = (uint32) - 1;
678 } 652 }
679 653
680 if (spob->other_arch) 654 if (spob->other_arch)
681 at = spob->other_arch; 655 at = spob->other_arch;
682 else if (spob->race) 656 else if (spob->race)
702 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); 676 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name);
703 return 0; 677 return 0;
704 } 678 }
705 679
706 if (!dir) 680 if (!dir)
707 dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); 681 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
708 682
709 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 683 if (dir < 0 || ob_blocked (at, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
710 { 684 {
711 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 685 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
712 return 0; 686 return 0;
713 } 687 }
688
714 /* basically want to get proper map/coordinates for this object */ 689 /* basically want to get proper map/coordinates for this object */
715 690
716 if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) 691 if (!(tmp = fix_summon_pet (at, op, dir, GOLEM)))
717 { 692 {
718 new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); 693 new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails.");
720 } 695 }
721 696
722 if (op->type == PLAYER) 697 if (op->type == PLAYER)
723 { 698 {
724 tmp->type = GOLEM; 699 tmp->type = GOLEM;
725 set_owner (tmp, op); 700 tmp->set_owner (op);
701 op->contr->golem = tmp;
702 /* give the player control of the golem */
726 set_spell_skill (op, caster, spob, tmp); 703 set_spell_skill (op, caster, spob, tmp);
727 op->contr->ranges[range_golem] = tmp;
728 op->contr->golem_count = tmp->count;
729 /* give the player control of the golem */
730 op->contr->shoottype = range_golem;
731 } 704 }
732 else 705 else
733 { 706 {
734 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 707 if (QUERY_FLAG (op, FLAG_FRIENDLY))
735 { 708 {
736 object *owner = get_owner (op); 709 object *owner = op->owner;
737 710
738 if (owner != NULL) 711 if (owner)
739 { /* For now, we transfer ownership */ 712 { /* For now, we transfer ownership */
740 set_owner (tmp, owner); 713 tmp->set_owner (owner);
741 tmp->attack_movement = PETMOVE; 714 tmp->attack_movement = PETMOVE;
742 add_friendly_object (tmp); 715 add_friendly_object (tmp);
743 SET_FLAG (tmp, FLAG_FRIENDLY);
744 } 716 }
745 } 717 }
746 718
747 SET_FLAG (tmp, FLAG_MONSTER); 719 SET_FLAG (tmp, FLAG_MONSTER);
748 } 720 }
917 * with all the checks in the 'for' portion itself. Much 889 * with all the checks in the 'for' portion itself. Much
918 * more readable to break some of the conditions out. 890 * more readable to break some of the conditions out.
919 */ 891 */
920 for (tr = spell_ob->randomitems->items; tr; tr = tr->next) 892 for (tr = spell_ob->randomitems->items; tr; tr = tr->next)
921 { 893 {
894 if (!tr->item)
895 continue;
896
922 if (level < tr->magic) 897 if (level < tr->magic)
923 break; 898 break;
924 899
925 lasttr = tr; 900 lasttr = tr;
926 901
927 if (stringarg && tr->item->name == sparam) 902 if (tr->item->archname == sparam)
928 break;
929
930 if (!tr->next || !tr->next->item)
931 break; 903 break;
932 } 904 }
933 905
934 if (!lasttr) 906 if (!lasttr)
935 { 907 {
937 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); 909 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters.");
938 return 0; 910 return 0;
939 } 911 }
940 912
941 summon_arch = lasttr->item; 913 summon_arch = lasttr->item;
942 nrof = lasttr->nrof; 914 nrof = lasttr->nrof;
943 } 915 }
944 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 916 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON"))
945 { 917 {
946 object *god = find_god (determine_god (op)), *mon, *owner; 918 object *god = find_god (determine_god (op)), *mon, *owner;
947 int summon_level, tries; 919 int summon_level, tries;
948 920
949 if (!god && ((owner = get_owner (op)) != NULL)) 921 if (!god && ((owner = op->owner) != NULL))
950 god = find_god (determine_god (owner)); 922 god = find_god (determine_god (owner));
951 923
952 /* If we can't find a god, can't get what monster to summon */ 924 /* If we can't find a god, can't get what monster to summon */
953 if (!god) 925 if (!god)
954 return 0; 926 return 0;
977 ndir = dir; 949 ndir = dir;
978 950
979 if (!ndir) 951 if (!ndir)
980 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 952 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
981 953
982 if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 954 if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
983 { 955 {
984 ndir = -1; 956 ndir = -1;
985 if (++tries == 5) 957 if (++tries == 5)
986 { 958 {
987 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 959 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1010 return 0; 982 return 0;
1011 } 983 }
1012 984
1013 for (i = 1; i <= nrof; i++) 985 for (i = 1; i <= nrof; i++)
1014 { 986 {
1015 archetype *atmp;
1016 object *prev = NULL, *head = NULL, *tmp; 987 object *prev = NULL, *head = NULL, *tmp;
1017 988
1018 if (dir) 989 if (dir)
1019 { 990 {
1020 ndir = dir; 991 ndir = dir;
1021 dir = absdir (dir + 1); 992 dir = absdir (dir + 1);
1022 } 993 }
1023 else 994 else
1024 ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); 995 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE);
1025 996
1026 if (ndir > 0) 997 if (ndir > 0)
1027 { 998 {
1028 x = freearr_x[ndir]; 999 x = freearr_x[ndir];
1029 y = freearr_y[ndir]; 1000 y = freearr_y[ndir];
1030 } 1001 }
1031 1002
1032 if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) 1003 if (ndir < 0 || ob_blocked (summon_arch, op->map, op->x + x, op->y + y))
1033 { 1004 {
1034 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 1005 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1035 if (nrof > 1) 1006 if (nrof > 1)
1036 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); 1007 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting.");
1037 1008
1038 return nrof > 1; 1009 return nrof > 1;
1039 } 1010 }
1040 1011
1041 for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) 1012 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more)
1042 { 1013 {
1043 tmp = arch_to_object (atmp); 1014 tmp = arch_to_object (atmp);
1044 if (atmp == summon_arch) 1015 if (atmp == summon_arch)
1045 { 1016 {
1046 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1017 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1047 { 1018 {
1048 set_owner (tmp, op); 1019 tmp->set_owner (op);
1049 set_spell_skill (op, caster, spell_ob, tmp); 1020 set_spell_skill (op, caster, spell_ob, tmp);
1050 tmp->enemy = op->enemy; 1021 tmp->enemy = op->enemy;
1051 tmp->type = 0; 1022 tmp->type = 0;
1052 CLEAR_FLAG (tmp, FLAG_SLEEP); 1023 CLEAR_FLAG (tmp, FLAG_SLEEP);
1053 1024
1054 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) 1025 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY))
1055 { 1026 {
1056 /* If this is not set, we make it friendly */ 1027 /* If this is not set, we make it friendly */
1057 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) 1028 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER))
1058 { 1029 {
1059 SET_FLAG (tmp, FLAG_FRIENDLY);
1060 add_friendly_object (tmp); 1030 add_friendly_object (tmp);
1061 tmp->stats.exp = 0; 1031 tmp->stats.exp = 0;
1062 1032
1063 if (spell_ob->attack_movement) 1033 if (spell_ob->attack_movement)
1064 tmp->attack_movement = spell_ob->attack_movement; 1034 tmp->attack_movement = spell_ob->attack_movement;
1065 1035
1066 if (get_owner (op)) 1036 if (op->owner)
1067 set_owner (tmp, get_owner (op)); 1037 tmp->set_owner (op->owner);
1068 } 1038 }
1069 } 1039 }
1070 } 1040 }
1071 1041
1072 if (tmp->speed > MIN_ACTIVE_SPEED) 1042 if (tmp->speed > MIN_ACTIVE_SPEED)
1080 tmp->head = head; 1050 tmp->head = head;
1081 prev->more = tmp; 1051 prev->more = tmp;
1082 } 1052 }
1083 1053
1084 prev = tmp; 1054 prev = tmp;
1085 tmp->x = op->x + x + tmp->arch->clone.x; 1055 tmp->x = op->x + x + tmp->arch->x;
1086 tmp->y = op->y + y + tmp->arch->clone.y; 1056 tmp->y = op->y + y + tmp->arch->y;
1087 tmp->map = op->map; 1057 tmp->map = op->map;
1088 } 1058 }
1089 1059
1090 head->direction = freedir[ndir]; 1060 head->direction = freedir[ndir];
1091 head->stats.exp = 0; 1061 head->stats.exp = 0;
1092 head = insert_ob_in_map (head, head->map, op, 0); 1062 head = insert_ob_in_map (head, head->map, op, 0);
1093 1063
1094 if (head && head->randomitems) 1064 if (head && head->randomitems)
1095 { 1065 {
1096 object *tmp;
1097
1098 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1066 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1067
1099 for (tmp = head->inv; tmp; tmp = tmp->below) 1068 for (object *tmp = head->inv; tmp; tmp = tmp->below)
1100 if (!tmp->nrof)
1101 SET_FLAG (tmp, FLAG_NO_DROP); 1069 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH);
1102 } 1070 }
1103 } /* for i < nrof */ 1071 } /* for i < nrof */
1104 1072
1105 return 1; 1073 return 1;
1106} 1074}
1113 object *realowner = ob; 1081 object *realowner = ob;
1114 1082
1115 if (realowner == NULL) 1083 if (realowner == NULL)
1116 return NULL; 1084 return NULL;
1117 1085
1118 while (get_owner (realowner) != NULL) 1086 while (realowner->owner != NULL)
1119 { 1087 {
1120 realowner = get_owner (realowner); 1088 realowner = realowner->owner;
1121 } 1089 }
1122 return realowner; 1090 return realowner;
1123} 1091}
1124 1092
1125/* determines if checks so pets don't attack players or other pets should be 1093/* determines if checks so pets don't attack players or other pets should be
1134 return 0; 1102 return 0;
1135 1103
1136 /* get the owners of itself and the target, this is to deal with pets of 1104 /* get the owners of itself and the target, this is to deal with pets of
1137 pets */ 1105 pets */
1138 rowner = get_real_owner (owner); 1106 rowner = get_real_owner (owner);
1139 if (target->type != PLAYER) 1107 towner = target->type == PLAYER ? 0 : get_real_owner (target);
1140 {
1141 towner = get_real_owner (target);
1142 }
1143 else
1144 {
1145 towner = 0;
1146 }
1147 1108
1148 /* if the pet has now owner, exit with error */ 1109 /* if the pet has now owner, exit with error */
1149 if (rowner == NULL) 1110 if (!rowner)
1150 { 1111 {
1151 LOG (llevError, "Pet has no owner.\n"); 1112 LOG (llevError, "Pet has no owner.\n");
1152 return 0; 1113 return 0;
1153 } 1114 }
1154 1115

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines