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.38 by root, Sun Jul 1 05:00:20 2007 UTC vs.
Revision 1.74 by root, Sat Nov 17 23:40:04 2018 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 (©) 2017,2018 Marc Alexander Lehmann / 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 (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 10 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your 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 GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
20 * 22 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 23 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 24 */
23 25
24#include <global.h> 26#include <global.h>
25#include <sproto.h> 27#include <sproto.h>
26 28
31 * this is now tilemap aware. 33 * this is now tilemap aware.
32 */ 34 */
33object * 35object *
34get_pet_enemy (object *pet, rv_vector * rv) 36get_pet_enemy (object *pet, rv_vector * rv)
35{ 37{
36 object *owner, *tmp, *attacker, *tmp3; 38 object *tmp, *attacker, *tmp3;
37 int i; 39 int i;
38 sint16 x, y; 40 sint16 x, y;
39 maptile *nm; 41 maptile *nm;
40 int search_arr[SIZEOFFREE]; 42 int search_arr[SIZEOFFREE];
41 int mflags; 43 int mflags;
42 44
43 attacker = pet->attacked_by; /*pointer to attacking enemy */ 45 attacker = pet->attacked_by; /*pointer to attacking enemy */
44 pet->attacked_by = NULL; /*clear this, since we are dealing with it */ 46 pet->attacked_by = NULL; /*clear this, since we are dealing with it */
45 47
46 if (owner = pet->owner) 48 object *owner = pet->owner;
47 { 49
48 /* If the owner has turned on the pet, make the pet 50 if (!owner)
49 * unfriendly.
50 */
51 if (check_enemy (owner, rv) == pet)
52 {
53 remove_friendly_object (pet);
54 pet->attack_movement &= ~PETMOVE;
55 return owner;
56 }
57 } 51 {
58 else
59 {
60 /* else the owner is no longer around, so the 52 /* the owner is no longer around, so the
61 * pet no longer needs to be friendly. 53 * pet no longer needs to be friendly.
62 */ 54 */
63 remove_friendly_object (pet); 55 remove_friendly_object (pet);
64 pet->attack_movement &= ~PETMOVE; 56 pet->attack_movement &= ~PETMOVE;
65 return 0; 57 return 0;
66 } 58 }
67 59
60 /* If the owner has turned on the pet, make the pet
61 * unfriendly.
62 */
63 if (check_enemy (owner, rv) == pet)
64 {
65 remove_friendly_object (pet);
66 pet->attack_movement &= ~PETMOVE;
67 return owner;
68 }
69
68 /* If they are not on the same map, the pet won't be agressive */ 70 /* If they are not on the same map, the pet won't be agressive */
69 //if (!on_same_map (pet, owner)) 71 //if (!on_same_map (pet, owner))
70 // return 0; 72 // return 0;
71 73
72 /* See if the pet has an existing enemy. If so, don't start a new one */ 74 /* See if the pet has an existing enemy. If so, don't start a new one */
73 if (tmp = check_enemy (pet, rv)) 75 if (tmp = check_enemy (pet, rv))
74 { 76 {
75 if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) 77 if (tmp == owner && !pet->flag [FLAG_CONFUSED] && pet->flag [FLAG_FRIENDLY])
76 /* without this check, you can actually get pets with 78 /* without this check, you can actually get pets with
77 * enemy set to owner! 79 * enemy set to owner!
78 */ 80 */
79 pet->enemy = 0; 81 pet->enemy = 0;
80 else 82 else
81 return tmp; 83 return tmp;
82 } 84 }
101 pet->enemy = 0; 103 pet->enemy = 0;
102 return 0; 104 return 0;
103 } 105 }
104 } 106 }
105 107
106 /* Since the pet has no existing enemy, look for anything nasty 108 /* Since the pet has no existing enemy, look for anything nasty
107 * around the owner that it should go and attack. (if the owner is 109 * around the owner that it should go and attack. (if the owner is
108 * still on a map) 110 * still on a map)
109 */ 111 */
110 // owners sometimes are not on a map but in the inventory of somehting else 112 // owners sometimes are not on a map but in the inventory of somehting else
111 if (!owner->flag [FLAG_REMOVED] && owner->map) 113 if (!owner->flag [FLAG_REMOVED] && owner->map)
112 { 114 {
113 tmp3 = 0; 115 tmp3 = 0;
114 116
115 for (i = 0; i < SIZEOFFREE; i++) 117 for (i = 0; i < SIZEOFFREE; i++)
116 { 118 {
117 x = owner->x + freearr_x[search_arr[i]]; 119 x = owner->x + DIRX (search_arr[i]);
118 y = owner->y + freearr_y[search_arr[i]]; 120 y = owner->y + DIRY (search_arr[i]);
119 nm = owner->map; 121 nm = owner->map;
120 /* Only look on the space if there is something alive there. */ 122 /* Only look on the space if there is something alive there. */
121 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 123 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
122 124
123 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 125 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
124 { 126 {
125 for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) 127 for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above)
126 { 128 {
127 object *tmp2 = tmp->head == 0 ? tmp : tmp->head; 129 object *tmp2 = tmp->head == 0 ? tmp : tmp->head;
128 130
129 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && 131 if (tmp2->flag [FLAG_ALIVE] && ((!tmp2->flag [FLAG_FRIENDLY] &&
130 (tmp2->type != PLAYER)) || 132 (tmp2->type != PLAYER)) ||
131 should_arena_attack (pet, owner, tmp2)) 133 should_arena_attack (pet, owner, tmp2))
132 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) 134 && !tmp2->flag [FLAG_UNAGGRESSIVE] && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv))
133 { 135 {
134 136
135 if (!can_see_enemy (pet, tmp2)) 137 if (!can_see_enemy (pet, tmp2))
136 { 138 {
137 if (tmp3 != 0) 139 if (tmp3 != 0)
165 /* No threat to owner, check to see if the pet has an attacker */ 167 /* No threat to owner, check to see if the pet has an attacker */
166 if (attacker) 168 if (attacker)
167 { 169 {
168 /* also need to check to make sure it is not freindly */ 170 /* also need to check to make sure it is not freindly */
169 /* or otherwise non-hostile, and is an appropriate target */ 171 /* or otherwise non-hostile, and is an appropriate target */
170 if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) 172 if (!attacker->flag [FLAG_FRIENDLY] && on_same_map (pet, attacker))
171 { 173 {
172 pet->enemy = attacker; 174 pet->enemy = attacker;
173 175
174 if (check_enemy (pet, rv) != 0) 176 if (check_enemy (pet, rv) != 0)
175 return attacker; 177 return attacker;
186 if (owner->type == PLAYER && owner->contr->petmode != pet_defend) 188 if (owner->type == PLAYER && owner->contr->petmode != pet_defend)
187 { 189 {
188 tmp3 = 0; 190 tmp3 = 0;
189 for (i = 0; i < SIZEOFFREE; i++) 191 for (i = 0; i < SIZEOFFREE; i++)
190 { 192 {
191 x = pet->x + freearr_x[search_arr[i]]; 193 x = pet->x + DIRX (search_arr[i]);
192 y = pet->y + freearr_y[search_arr[i]]; 194 y = pet->y + DIRY (search_arr[i]);
193 nm = pet->map; 195 nm = pet->map;
194 /* Only look on the space if there is something alive there. */ 196 /* Only look on the space if there is something alive there. */
195 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 197 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
196 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 198 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
197 { 199 {
198 for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) 200 for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above)
199 { 201 {
200 object *tmp2 = tmp->head == 0 ? tmp : tmp->head; 202 object *tmp2 = tmp->head == 0 ? tmp : tmp->head;
201 203
202 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && 204 if (tmp2->flag [FLAG_ALIVE] && ((!tmp2->flag [FLAG_FRIENDLY] &&
203 (tmp2->type != PLAYER)) || 205 (tmp2->type != PLAYER)) ||
204 should_arena_attack (pet, owner, tmp2)) 206 should_arena_attack (pet, owner, tmp2))
205 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) 207 && !tmp2->flag [FLAG_UNAGGRESSIVE] && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv))
206 { 208 {
207 209
208 if (!can_see_enemy (pet, tmp2)) 210 if (!can_see_enemy (pet, tmp2))
209 { 211 {
210 if (tmp3 != 0) 212 if (tmp3 != 0)
254 { 256 {
255 object *ob = obl->ob; 257 object *ob = obl->ob;
256 next = obl->next; 258 next = obl->next;
257 259
258 if (ob->owner == owner) 260 if (ob->owner == owner)
259 ob->destroy (); 261 ob->drop_and_destroy ();
260 } 262 }
261} 263}
262 264
263/* 265/*
264 * Unfortunately, sometimes, the owner of a pet is in the 266 * Unfortunately, sometimes, the owner of a pet is in the
265 * process of entering a new map when this is called. 267 * process of entering a new map when this is called.
266 * Thus the map isn't loaded yet, and we have to remove
267 * the pet...
268 * Interesting enough, we don't use the passed map structure in 268 * Interesting enough, we don't use the passed map structure in
269 * this function. 269 * this function.
270 */ 270 */
271void 271void
272remove_all_pets (maptile *map) 272move_all_pets ()
273{ 273{
274 objectlink *obl, *next; 274 objectlink *obl, *next;
275 object *owner; 275 object *owner;
276 276
277 for (obl = first_friendly_object; obl; obl = next) 277 for (obl = first_friendly_object; obl; obl = next)
278 { 278 {
279 next = obl->next; 279 next = obl->next;
280 280
281 if (obl->ob->type != PLAYER 281 if (obl->ob->type != PLAYER
282 && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) 282 && obl->ob->flag [FLAG_FRIENDLY]
283 && (owner = obl->ob->owner) != 0 283 && (owner = obl->ob->owner)
284 && !on_same_map (owner, obl->ob)) 284 && !on_same_map (owner, obl->ob))
285 { 285 {
286 /* follow owner checks map status for us */ 286 /* follow owner checks map status for us */
287 follow_owner (obl->ob, owner); 287 follow_owner (obl->ob, owner);
288 } 288 }
292int 292int
293follow_owner (object *ob, object *owner) 293follow_owner (object *ob, object *owner)
294{ 294{
295 if (owner->flag [FLAG_REMOVED]) 295 if (owner->flag [FLAG_REMOVED])
296 return 0; // do nothing if the owner is removed 296 return 0; // do nothing if the owner is removed
297 else if (!owner->map || owner->map->in_memory != MAP_IN_MEMORY) 297 else if (!owner->map || owner->map->state != MAP_ACTIVE)
298 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); 298 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name);
299 else 299 else
300 { 300 {
301 int 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);
302 302
303 if (dir >= 0) 303 if (dir >= 0)
304 { 304 {
305 owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]); 305 owner->map->insert (ob, owner->x + DIRX (dir), owner->y + DIRY (dir));
306 306
307 if (owner->type == PLAYER) /* Uh, I hope this is always true... */ 307 if (owner->type == PLAYER) /* Uh, I hope this is always true... */
308 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");
309 309
310 return 0; 310 return 0;
311 } 311 }
312 } 312 }
313 313
314 ob->destroy (); 314 ob->drop_and_destroy ();
315
315 return 1; 316 return 1;
316} 317}
317 318
318void 319void
319pet_move (object *ob) 320pet_move (object *ob)
324 maptile *m; 325 maptile *m;
325 326
326 /* Check to see if player pulled out */ 327 /* Check to see if player pulled out */
327 if ((owner = ob->owner) == NULL) 328 if ((owner = ob->owner) == NULL)
328 { 329 {
329 ob->destroy (); 330 ob->drop_and_destroy ();
330 LOG (llevMonster, "Pet: no owner, leaving.\n"); 331 LOG (llevTrace, "Pet: no owner, leaving.\n");
331 return; 332 return;
332 } 333 }
333 334
334 /* move monster into the owners map if not in the same map 335 /* move monster into the owners map if not in the same map
335 * except when the owner is removed. 336 * except when the owner is removed.
337 if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) 338 if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED])
338 { 339 {
339 follow_owner (ob, owner); 340 follow_owner (ob, owner);
340 return; 341 return;
341 } 342 }
343
342 /* Calculate Direction */ 344 /* Calculate Direction */
343 if (owner->type == PLAYER && owner->contr->petmode == pet_sad) 345 if (owner->type == PLAYER && owner->contr->petmode == pet_sad)
344 { 346 {
345 /* in S&D mode, if we have no enemy, run randomly about. */ 347 /* in S&D mode, if we have no enemy, run randomly about. */
346 for (i = 0; i < 15; i++) 348 for (i = 0; i < 15; i++)
347 { 349 {
348 dir = rndm (1, 8); 350 dir = rndm (1, 8);
349 dx = ob->x + freearr_x[dir]; 351 dx = ob->x + DIRX (dir);
350 dy = ob->y + freearr_y[dir]; 352 dy = ob->y + DIRY (dir);
351 m = ob->map; 353 m = ob->map;
352 if (get_map_flags (ob->map, &m, dx, dy, &dx, &dy) & P_OUT_OF_MAP) 354 if (get_map_flags (ob->map, &m, dx, dy, &dx, &dy) & P_OUT_OF_MAP)
353 continue; 355 continue;
354 else if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m, dx, dy))) 356 else if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m, dx, dy)))
355 continue; 357 continue;
362 struct rv_vector rv; 364 struct rv_vector rv;
363 365
364 get_rangevector (ob, ob->owner, &rv, 0); 366 get_rangevector (ob, ob->owner, &rv, 0);
365 dir = rv.direction; 367 dir = rv.direction;
366 } 368 }
369
367 ob->direction = dir; 370 ob->direction = dir;
368 371
369 /* move_ob returns 0 if the object couldn't move. If that is the 372 /* move_ob returns 0 if the object couldn't move. If that is the
370 * case, lets do some other work. 373 * case, lets do some other work.
371 */ 374 */
372 if (!(move_ob (ob, dir, ob))) 375 if (!(ob->move (dir)))
373 { 376 {
374 object *part; 377 object *part;
375 378
376 /* the failed move_ob above may destroy the pet, so check here */ 379 /* the failed move_ob above may destroy the pet, so check here */
377 if (ob->destroyed ()) 380 if (ob->destroyed ())
378 return; 381 return;
379 382
380 for (part = ob; part != NULL; part = part->more) 383 for (part = ob; part != NULL; part = part->more)
381 { 384 {
382 dx = part->x + freearr_x[dir]; 385 dx = part->x + DIRX (dir);
383 dy = part->y + freearr_y[dir]; 386 dy = part->y + DIRY (dir);
384 m = get_map_from_coord (part->map, &dx, &dy); 387 m = get_map_from_coord (part->map, &dx, &dy);
385 if (!m) 388 if (!m)
386 continue; 389 continue;
387 390
388 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) 391 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above)
389 { 392 {
390 object *new_ob; 393 object *new_ob;
391 394
392 new_ob = ob2->head ? ob2->head : ob2; 395 new_ob = ob2->head ? ob2->head : ob2;
396
393 if (new_ob == ob) 397 if (new_ob == ob)
394 break; 398 break;
399
395 if (new_ob == ob->owner) 400 if (new_ob == ob->owner)
396 return; 401 return;
402
397 if (new_ob->owner == ob->owner) 403 if (new_ob->owner == ob->owner)
398 break; 404 break;
399 405
400 /* Hmm. Did we try to move into an enemy monster? If so, 406 /* Hmm. Did we try to move into an enemy monster? If so,
401 * make it our enemy. 407 * make it our enemy.
402 */ 408 */
403 if (QUERY_FLAG (new_ob, FLAG_ALIVE) && !QUERY_FLAG (ob, FLAG_UNAGGRESSIVE) 409 if (new_ob->flag [FLAG_ALIVE] && !ob->flag [FLAG_UNAGGRESSIVE]
404 && !QUERY_FLAG (new_ob, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (new_ob, FLAG_FRIENDLY)) 410 && !new_ob->flag [FLAG_UNAGGRESSIVE] && !new_ob->flag [FLAG_FRIENDLY])
405 { 411 {
406 412
407 ob->enemy = new_ob; 413 ob->enemy = new_ob;
408 if (new_ob->enemy == NULL) 414 if (new_ob->enemy == NULL)
409 new_ob->enemy = ob; 415 new_ob->enemy = ob;
416 } 422 }
417 } 423 }
418 } 424 }
419 /* Try a different course */ 425 /* Try a different course */
420 dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); 426 dir = absdir (dir + 4 - (rndm (5)) - (rndm (5)));
421 (void) move_ob (ob, dir, ob); 427 ob->move (dir);
422 } 428 }
423 return;
424} 429}
425 430
426/**************************************************************************** 431/****************************************************************************
427 * 432 *
428 * GOLEM SPELL CODE 433 * GOLEM SPELL CODE
429 * 434 *
430 ****************************************************************************/ 435 ****************************************************************************/
431 436
432/* fix_summon_pet() - this makes multisquare/single square monsters 437/* fix_summon_pet() - this makes multisquare/single square monsters
433 * proper for map insertion. 438 * proper for map insertion.
434 * at is the archetype, op is the caster of the spell, dir is the 439 * at is the archetype, op is the caster of the spell, dir is the
435 * direction the monster should be placed in. 440 * direction the monster should be placed in.
436 * is_golem is to note that this is a golem spell. 441 * is_golem is to note that this is a golem spell.
437 */ 442 */
438object * 443static object *
439fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 444fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
440{ 445{
441 object *tmp = NULL, *prev = NULL, *head = NULL; 446 object *tmp = NULL, *prev = NULL, *head = NULL;
442 447
443 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) 448 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
444 { 449 {
445 tmp = arch_to_object (atmp); 450 tmp = atmp->instance ();
446 451
447 if (atmp == at) 452 if (atmp == at)
448 { 453 {
449 if (!is_golem) 454 if (!is_golem)
450 SET_FLAG (tmp, FLAG_MONSTER); 455 tmp->set_flag (FLAG_MONSTER);
451 456
452 tmp->set_owner (op); 457 tmp->set_owner (op);
453 458
454 if (op->type == PLAYER) 459 if (op->type == PLAYER)
455 { 460 {
456 tmp->stats.exp = 0; 461 tmp->stats.exp = 0;
457 add_friendly_object (tmp); 462 add_friendly_object (tmp);
458 if (is_golem) 463 if (is_golem)
459 CLEAR_FLAG (tmp, FLAG_MONSTER); 464 tmp->clr_flag (FLAG_MONSTER);
460 } 465 }
461 else 466 else
462 { 467 {
463 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 468 if (op->flag [FLAG_FRIENDLY])
464 { 469 {
465 object *owner = op->owner; 470 object *owner = op->owner;
466 471
467 if (owner) 472 if (owner)
468 { /* For now, we transfer ownership */ 473 { /* For now, we transfer ownership */
486 } 491 }
487 492
488 if (!head) 493 if (!head)
489 head = tmp; 494 head = tmp;
490 495
491 tmp->x = op->x + freearr_x[dir] + tmp->arch->x; 496 tmp->x = op->x + DIRX (dir) + tmp->arch->x;
492 tmp->y = op->y + freearr_y[dir] + tmp->arch->y; 497 tmp->y = op->y + DIRY (dir) + tmp->arch->y;
493 tmp->map = op->map; 498 tmp->map = op->map;
494 499
495 if (tmp->invisible) 500 if (tmp->invisible)
496 tmp->invisible = 0; 501 tmp->invisible = 0;
497 502
508 head->last_eat = 0; 513 head->last_eat = 0;
509 head->last_grace = 0; 514 head->last_grace = 0;
510 head->last_sp = 0; 515 head->last_sp = 0;
511 head->other_arch = NULL; 516 head->other_arch = NULL;
512 head->stats.exp = 0; 517 head->stats.exp = 0;
513 CLEAR_FLAG (head, FLAG_CHANGING); 518 head->clr_flag (FLAG_CHANGING);
514 CLEAR_FLAG (head, FLAG_STAND_STILL); 519 head->clr_flag (FLAG_STAND_STILL);
515 CLEAR_FLAG (head, FLAG_GENERATOR); 520 head->clr_flag (FLAG_GENERATOR);
516 CLEAR_FLAG (head, FLAG_SPLITTING); 521 head->clr_flag (FLAG_SPLITTING);
517 if (head->attacktype & AT_GHOSTHIT) 522 if (head->attacktype & AT_GHOSTHIT)
518 head->attacktype = (AT_PHYSICAL | AT_DRAIN); 523 head->attacktype = (AT_PHYSICAL | AT_DRAIN);
519 524
520 return head; 525 return head;
521} 526}
526move_golem (object *op) 531move_golem (object *op)
527{ 532{
528 int made_attack = 0; 533 int made_attack = 0;
529 object *tmp; 534 object *tmp;
530 535
531 if (QUERY_FLAG (op, FLAG_MONSTER)) 536 if (op->flag [FLAG_MONSTER])
532 return; /* Has already been moved */ 537 return; /* Has already been moved */
533 538
534 if (!op->owner) 539 if (!op->owner)
535 { 540 {
536 LOG (llevDebug, "Golem without owner destructed.\n"); 541 LOG (llevDebug, "Golem without owner destructed.\n");
537 op->remove ();
538 op->destroy (); 542 op->drop_and_destroy ();
539 return; 543 return;
540 } 544 }
541 545
542 /* It would be nice to have a cleaner way of what message to print 546 /* It would be nice to have a cleaner way of what message to print
543 * when the golem expires than these hard coded entries. 547 * when the golem expires than these hard coded entries.
547 if (--op->stats.hp < 0) 551 if (--op->stats.hp < 0)
548 { 552 {
549 if (op->msg) 553 if (op->msg)
550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 554 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
551 555
552 op->destroy (); 556 op->drop_and_destroy ();
553 return; 557 return;
554 } 558 }
555 559
556 /* Do golem attacks/movement for single & multisq golems. 560 /* Do golem attacks/movement for single & multisq golems.
557 * Assuming here that op is the 'head' object. Pass only op to 561 * Assuming here that op is the 'head' object. Pass only op to
558 * move_ob (makes recursive calls to other parts) 562 * ->move (makes recursive calls to other parts)
559 * move_ob returns 0 if the creature was not able to move. 563 * move_ob returns 0 if the creature was not able to move.
560 */ 564 */
561 if (move_ob (op, op->direction, op)) 565 if (op->move (op->direction, op))
562 return; 566 return;
563 567
564 if (op->destroyed ()) 568 if (op->destroyed ())
565 return; 569 return;
566 570
567 for (tmp = op; tmp; tmp = tmp->more) 571 for (tmp = op; tmp; tmp = tmp->more)
568 { 572 {
569 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; 573 sint16 x = tmp->x + DIRX (op->direction), y = tmp->y + DIRY (op->direction);
570 object *victim; 574 object *victim;
571 maptile *m; 575 maptile *m;
572 int mflags; 576 int mflags;
573 577
574 m = op->map; 578 m = op->map;
575 mflags = get_map_flags (m, &m, x, y, &x, &y); 579 mflags = get_map_flags (m, &m, x, y, &x, &y);
576 580
577 if (mflags & P_OUT_OF_MAP) 581 if (mflags & P_OUT_OF_MAP)
578 continue; 582 continue;
579 583
580 for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) 584 for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above)
581 if (QUERY_FLAG (victim, FLAG_ALIVE)) 585 if (victim->flag [FLAG_ALIVE])
582 break; 586 break;
583 587
584 /* We used to call will_hit_self to make sure we don't 588 /* We used to call will_hit_self to make sure we don't
585 * hit ourselves, but that didn't work, and I don't really 589 * hit ourselves, but that didn't work, and I don't really
586 * know if that was more efficient anyways than this. 590 * know if that was more efficient anyways than this.
589 * that isn't a problem. 593 * that isn't a problem.
590 */ 594 */
591 if (victim && victim != op && victim->head != op) 595 if (victim && victim != op && victim->head != op)
592 { 596 {
593 /* for golems with race fields, we don't attack 597 /* for golems with race fields, we don't attack
594 * aligned races 598 * aligned races
595 */ 599 */
596 600
597 if (victim->race && op->race && strstr (op->race, victim->race)) 601 if (victim->race && op->race && op->race.contains (victim->race))
598 { 602 {
599 if (op->owner) 603 if (op->owner)
600 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); 604 new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name);
601 } 605 }
602 else if (victim == op->owner) 606 else if (victim == op->owner)
625control_golem (object *op, int dir) 629control_golem (object *op, int dir)
626{ 630{
627 op->direction = dir; 631 op->direction = dir;
628} 632}
629 633
630/* summon golem: summons a monster for 'op'. caster is the object 634/* summon golem: summons a monster for 'op'. caster is the object
631 * casting the spell, dir is the direction to place the monster, 635 * casting the spell, dir is the direction to place the monster,
632 * at is the archetype of the monster, and spob is the spell 636 * at is the archetype of the monster, and spob is the spell
633 * object. At this stage, all spob is really used for is to 637 * object. At this stage, all spob is really used for is to
634 * adjust some values in the monster. 638 * adjust some values in the monster.
635 */ 639 */
636int 640int
637summon_golem (object *op, object *caster, int dir, object *spob) 641summon_golem (object *op, object *caster, int dir, object *spob)
638{ 642{
639 object *tmp, *god = NULL; 643 object *tmp, *god = NULL;
640 archetype *at; 644 archetype *at;
641 char buf[MAX_BUF];
642 645
643 /* Because there can be different golem spells, player may want to 646 /* Because there can be different golem spells, player may want to
644 * 'lose' their old golem. 647 * 'lose' their old golem.
645 */ 648 */
646 if (op->type == PLAYER && op->contr->golem) 649 if (op->type == PLAYER && op->contr->golem)
647 { 650 {
648 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); 651 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem.");
649 op->contr->golem->remove ();
650 op->contr->golem->destroy (); 652 op->contr->golem->drop_and_destroy ();
651 op->contr->golem = 0; 653 op->contr->golem = 0;
652 } 654 }
653 655
654 if (spob->other_arch) 656 if (spob->other_arch)
655 at = spob->other_arch; 657 at = spob->other_arch;
678 } 680 }
679 681
680 if (!dir) 682 if (!dir)
681 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); 683 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
682 684
683 if (dir < 0 || ob_blocked (at, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 685 if (dir < 0 || at->blocked (op->map, op->x + DIRX (dir), op->y + DIRY (dir)))
684 { 686 {
685 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 687 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
686 return 0; 688 return 0;
687 } 689 }
688 690
695 } 697 }
696 698
697 if (op->type == PLAYER) 699 if (op->type == PLAYER)
698 { 700 {
699 tmp->type = GOLEM; 701 tmp->type = GOLEM;
700 tmp->set_owner (op);
701 op->contr->golem = tmp; 702 op->contr->golem = tmp;
702 /* give the player control of the golem */ 703 /* give the player control of the golem */
703 set_spell_skill (op, caster, spob, tmp); 704 set_spell_skill (op, caster, spob, tmp);
704 } 705 }
705 else
706 {
707 if (QUERY_FLAG (op, FLAG_FRIENDLY))
708 {
709 object *owner = op->owner;
710 706
711 if (owner)
712 { /* For now, we transfer ownership */
713 tmp->set_owner (owner);
714 tmp->attack_movement = PETMOVE;
715 add_friendly_object (tmp);
716 }
717 }
718
719 SET_FLAG (tmp, FLAG_MONSTER);
720 }
721
722 /* make the speed positive. */
723 tmp->speed = FABS (tmp->speed);
724
725 /* This sets the level dependencies on dam and hp for monsters */ 707 /* This sets the level dependencies on dam and hp for monsters */
726 /* players can't cope with too strong summonings. */ 708 /* players can't cope with too strong summonings. */
727 /* but monsters can. reserve these for players. */ 709 /* but monsters can. reserve these for players. */
728 if (op->type == PLAYER) 710 if (op->type == PLAYER)
729 { 711 {
730 tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); 712 tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob);
732 if (!spob->stats.dam) 714 if (!spob->stats.dam)
733 tmp->stats.dam += SP_level_dam_adjust (caster, spob); 715 tmp->stats.dam += SP_level_dam_adjust (caster, spob);
734 else 716 else
735 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); 717 tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob);
736 718
737 tmp->speed += .02 * SP_level_range_adjust (caster, spob); 719 tmp->set_speed (min (1.f, tmp->speed + .02f * SP_level_range_adjust (caster, spob)));
738 tmp->speed = MIN (tmp->speed, 1.0);
739 720
740 if (spob->attacktype) 721 if (spob->attacktype)
741 tmp->attacktype = spob->attacktype; 722 tmp->attacktype = spob->attacktype;
742 } 723 }
743 724
747 728
748 /* make experience increase in proportion to the strength. 729 /* make experience increase in proportion to the strength.
749 * this is a bit simplistic - we are basically just looking at how 730 * this is a bit simplistic - we are basically just looking at how
750 * often the sp doubles and use that as the ratio. 731 * often the sp doubles and use that as the ratio.
751 */ 732 */
752 tmp->stats.exp *= 1 + (MAX (spob->stats.maxgrace, spob->stats.sp) / caster_level (caster, spob)); 733 tmp->stats.exp *= 1 + max (spob->stats.maxgrace, spob->stats.sp) / casting_level (caster, spob);
753 tmp->speed_left = 0; 734 tmp->speed_left = 0;
754 tmp->direction = dir; 735 tmp->direction = dir;
755 736
756 /* Holy spell - some additional tailoring */ 737 /* Holy spell - some additional tailoring */
757 if (god) 738 if (god)
758 { 739 {
759 object *tmp2;
760
761 sprintf (buf, "%s of %s", &spob->name, &god->name); 740 char *buf = format ("%s of %s", &spob->name, &god->name);
762 buf[0] = toupper (buf[0]); 741 buf[0] = toupper (buf[0]);
763 742
764 for (tmp2 = tmp; tmp2; tmp2 = tmp2->more) 743 for (object *tmp2 = tmp; tmp2; tmp2 = tmp2->more)
765 tmp2->name = buf; 744 tmp2->name = buf;
766 745
767 tmp->attacktype |= god->attacktype; 746 tmp->attacktype |= god->attacktype;
768 memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); 747 memcpy (tmp->resist, god->resist, sizeof (tmp->resist));
769 tmp->race = god->race; 748 tmp->race = god->race;
773 if (!(tmp->attacktype & AT_PHYSICAL)) 752 if (!(tmp->attacktype & AT_PHYSICAL))
774 tmp->attacktype |= AT_PHYSICAL; 753 tmp->attacktype |= AT_PHYSICAL;
775 } 754 }
776 755
777 insert_ob_in_map (tmp, tmp->map, op, 0); 756 insert_ob_in_map (tmp, tmp->map, op, 0);
757
778 return 1; 758 return 1;
779} 759}
780 760
781 761
782/*************************************************************************** 762/***************************************************************************
788/* Returns a monster (chosen at random) that this particular player (and his 768/* Returns a monster (chosen at random) that this particular player (and his
789 * god) find acceptable. This checks level, races allowed by god, etc 769 * god) find acceptable. This checks level, races allowed by god, etc
790 * to determine what is acceptable. 770 * to determine what is acceptable.
791 * This returns NULL if no match was found. 771 * This returns NULL if no match was found.
792 */ 772 */
793 773static object *
794object *
795choose_cult_monster (object *pl, object *god, int summon_level) 774choose_cult_monster (object *pl, object *god, int summon_level)
796{ 775{
797 char buf[MAX_BUF]; 776 char buf[MAX_BUF];
798 const char *race; 777 const char *race;
799 int racenr, mon_nr, i; 778 int racenr, mon_nr, i;
839 /* search for an apprplritate monster on this race list */ 818 /* search for an apprplritate monster on this race list */
840 mon_nr = 0; 819 mon_nr = 0;
841 for (tobl = list->member; tobl; tobl = tobl->next) 820 for (tobl = list->member; tobl; tobl = tobl->next)
842 { 821 {
843 otmp = tobl->ob; 822 otmp = tobl->ob;
844 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 823 if (!otmp || !otmp->flag [FLAG_MONSTER])
845 continue; 824 continue;
846 if (otmp->level <= summon_level) 825 if (otmp->level <= summon_level)
847 mon_nr++; 826 mon_nr++;
848 } 827 }
849 828
853 * a valid entry, assuming nothing is available and quit. 832 * a valid entry, assuming nothing is available and quit.
854 */ 833 */
855 if (!mon_nr) 834 if (!mon_nr)
856 return NULL; 835 return NULL;
857 836
858 mon_nr = rndm (0, mon_nr - 1); 837 mon_nr = rndm (mon_nr - 1);
859 for (tobl = list->member; tobl; tobl = tobl->next) 838 for (tobl = list->member; tobl; tobl = tobl->next)
860 { 839 {
861 otmp = tobl->ob; 840 otmp = tobl->ob;
862 if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) 841 if (!otmp || !otmp->flag [FLAG_MONSTER])
863 continue; 842 continue;
843
864 if (otmp->level <= summon_level && !mon_nr--) 844 if (otmp->level <= summon_level && !mon_nr--)
865 return otmp; 845 return otmp;
866 } 846 }
847
867 /* This should not happen */ 848 /* This should not happen */
868 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); 849 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n");
869 return NULL; 850 return NULL;
870} 851}
871 852
872int 853int
873summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) 854summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
874{ 855{
875 sint16 x, y, nrof = 1, i; 856 int nrof = 1;
876 archetype *summon_arch; 857 archetype *summon_arch;
877 int ndir; 858 int ndir;
878 859
879 if (spell_ob->other_arch) 860 if (spell_ob->other_arch)
880 summon_arch = spell_ob->other_arch; 861 summon_arch = spell_ob->other_arch;
881 else if (spell_ob->randomitems) 862 else if (spell_ob->randomitems)
882 { 863 {
883 int level = caster_level (caster, spell_ob); 864 int level = casting_level (caster, spell_ob);
884 treasure *tr, *lasttr = NULL; 865 treasure *tr, *lasttr = NULL;
885 866
886 shstr_cmp sparam (stringarg); 867 shstr_cmp sparam (stringarg);
887 868
888 /* In old code, this was a very convoluted for statement, 869 /* In old code, this was a very convoluted for statement,
889 * with all the checks in the 'for' portion itself. Much 870 * with all the checks in the 'for' portion itself. Much
890 * more readable to break some of the conditions out. 871 * more readable to break some of the conditions out.
891 */ 872 */
892 for (tr = spell_ob->randomitems->items; tr; tr = tr->next) 873 for (tr = spell_ob->randomitems->items; tr; tr = tr->next)
893 { 874 {
911 } 892 }
912 893
913 summon_arch = lasttr->item; 894 summon_arch = lasttr->item;
914 nrof = lasttr->nrof; 895 nrof = lasttr->nrof;
915 } 896 }
916 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 897 else if (spell_ob->race == shstr_GODCULTMON)
917 { 898 {
918 object *god = find_god (determine_god (op)), *mon, *owner; 899 object *god = find_god (determine_god (op)), *mon, *owner;
919 int summon_level, tries; 900 int summon_level, tries;
920 901
921 if (!god && ((owner = op->owner) != NULL)) 902 if (!god && ((owner = op->owner) != NULL))
930 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); 911 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name);
931 return 0; 912 return 0;
932 } 913 }
933 914
934 /* the summon level */ 915 /* the summon level */
935 summon_level = caster_level (caster, spell_ob); 916 summon_level = casting_level (caster, spell_ob);
936 if (summon_level == 0) 917 if (summon_level == 0)
937 summon_level = 1; 918 summon_level = 1;
938 919
939 tries = 0; 920 tries = 0;
940 do 921 do
949 ndir = dir; 930 ndir = dir;
950 931
951 if (!ndir) 932 if (!ndir)
952 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 933 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
953 934
954 if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 935 if (ndir < 0 || mon->blocked (op->map, op->x + DIRX (ndir), op->y + DIRY (ndir)))
955 { 936 {
956 ndir = -1; 937 ndir = -1;
957 if (++tries == 5) 938 if (++tries == 5)
958 { 939 {
959 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 940 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
980 { 961 {
981 new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); 962 new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning.");
982 return 0; 963 return 0;
983 } 964 }
984 965
985 for (i = 1; i <= nrof; i++) 966 for (int i = 1; i <= nrof; i++)
986 { 967 {
987 object *prev = NULL, *head = NULL, *tmp; 968 object *prev = NULL, *head = NULL, *tmp;
988 969
989 if (dir) 970 if (dir)
990 { 971 {
992 dir = absdir (dir + 1); 973 dir = absdir (dir + 1);
993 } 974 }
994 else 975 else
995 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); 976 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE);
996 977
997 if (ndir > 0) 978 sint16 x = DIRX (ndir);
998 { 979 sint16 y = DIRY (ndir);
999 x = freearr_x[ndir];
1000 y = freearr_y[ndir];
1001 }
1002 980
1003 if (ndir < 0 || ob_blocked (summon_arch, op->map, op->x + x, op->y + y)) 981 if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y))
1004 { 982 {
1005 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 983 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1006 if (nrof > 1) 984 if (nrof > 1)
1007 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); 985 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting.");
1008 986
1009 return nrof > 1; 987 return nrof > 1;
1010 } 988 }
1011 989
1012 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more) 990 for (archetype *atmp = summon_arch; atmp; atmp = (archetype *)atmp->more)
1013 { 991 {
1014 tmp = arch_to_object (atmp); 992 tmp = atmp->instance ();
1015 if (atmp == summon_arch) 993 if (atmp == summon_arch)
1016 { 994 {
1017 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 995 if (tmp->flag [FLAG_MONSTER])
1018 { 996 {
1019 tmp->set_owner (op); 997 tmp->set_owner (op);
1020 set_spell_skill (op, caster, spell_ob, tmp); 998 set_spell_skill (op, caster, spell_ob, tmp);
1021 tmp->enemy = op->enemy; 999 tmp->enemy = op->enemy;
1022 tmp->type = 0; 1000 tmp->type = 0;
1023 CLEAR_FLAG (tmp, FLAG_SLEEP); 1001 tmp->clr_flag (FLAG_SLEEP);
1024 1002
1025 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) 1003 if (op->type == PLAYER || op->flag [FLAG_FRIENDLY])
1026 { 1004 {
1027 /* If this is not set, we make it friendly */ 1005 /* If this is not set, we make it friendly */
1028 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) 1006 if (!spell_ob->flag [FLAG_MONSTER])
1029 { 1007 {
1030 add_friendly_object (tmp); 1008 add_friendly_object (tmp);
1031 tmp->stats.exp = 0; 1009 tmp->stats.exp = 0;
1032 1010
1033 if (spell_ob->attack_movement) 1011 if (spell_ob->attack_movement)
1037 tmp->set_owner (op->owner); 1015 tmp->set_owner (op->owner);
1038 } 1016 }
1039 } 1017 }
1040 } 1018 }
1041 1019
1042 if (tmp->speed > MIN_ACTIVE_SPEED) 1020 if (tmp->has_active_speed ())
1043 tmp->speed_left = -1; 1021 tmp->speed_left = -1;
1044 } 1022 }
1045 1023
1046 if (head == NULL) 1024 if (head == NULL)
1047 head = tmp; 1025 head = tmp;
1064 if (head && head->randomitems) 1042 if (head && head->randomitems)
1065 { 1043 {
1066 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1044 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1067 1045
1068 for (object *tmp = head->inv; tmp; tmp = tmp->below) 1046 for (object *tmp = head->inv; tmp; tmp = tmp->below)
1069 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); 1047 tmp->set_flag (FLAG_DESTROY_ON_DEATH);
1070 } 1048 }
1071 } /* for i < nrof */ 1049 } /* for i < nrof */
1072 1050
1073 return 1; 1051 return 1;
1074}
1075
1076/* recursively look through the owner property of objects until the real owner
1077is found */
1078object *
1079get_real_owner (object *ob)
1080{
1081 object *realowner = ob;
1082
1083 if (realowner == NULL)
1084 return NULL;
1085
1086 while (realowner->owner != NULL)
1087 {
1088 realowner = realowner->owner;
1089 }
1090 return realowner;
1091} 1052}
1092 1053
1093/* determines if checks so pets don't attack players or other pets should be 1054/* determines if checks so pets don't attack players or other pets should be
1094overruled by the arena petmode */ 1055overruled by the arena petmode */
1095int 1056int
1101 if ((target == NULL) || (pet == NULL) || (owner == NULL)) 1062 if ((target == NULL) || (pet == NULL) || (owner == NULL))
1102 return 0; 1063 return 0;
1103 1064
1104 /* get the owners of itself and the target, this is to deal with pets of 1065 /* get the owners of itself and the target, this is to deal with pets of
1105 pets */ 1066 pets */
1106 rowner = get_real_owner (owner); 1067 rowner = owner->outer_owner ();
1107 towner = target->type == PLAYER ? 0 : get_real_owner (target); 1068 towner = target->is_player () ? 0 : target->outer_owner ();
1108 1069
1109 /* if the pet has now owner, exit with error */ 1070 /* if the pet has now owner, exit with error */
1110 if (!rowner) 1071 if (!rowner)
1111 { 1072 {
1112 LOG (llevError, "Pet has no owner.\n"); 1073 LOG (llevError, "Pet has no owner.\n");
1113 return 0; 1074 return 0;
1114 } 1075 }
1115 1076
1116 /* if the target is not a player, and has no owner, we shouldn't be here 1077 /* if the target is not a player, and has no owner, we shouldn't be here
1117 */ 1078 */
1118 if ((towner == NULL) && (target->type != PLAYER)) 1079 if (!towner && !target->is_player ())
1119 { 1080 {
1120 LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); 1081 LOG (llevError, "Target is not a player but has no owner. We should not be here.\n");
1121 return 0; 1082 return 0;
1122 } 1083 }
1123 1084
1124 /* make sure that the owner is a player */ 1085 /* make sure that the owner is a player */
1125 if (rowner->type != PLAYER) 1086 if (!rowner->is_player ())
1126 return 0; 1087 return 0;
1127 1088
1128 /* abort if the petmode is not arena */ 1089 /* abort if the petmode is not arena */
1129 if (rowner->contr->petmode != pet_arena) 1090 if (rowner->contr->petmode != pet_arena)
1130 return 0; 1091 return 0;
1132 /* abort if the pet, it's owner, or the target is not on battleground */ 1093 /* abort if the pet, it's owner, or the target is not on battleground */
1133 if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) 1094 if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL)))
1134 return 0; 1095 return 0;
1135 1096
1136 /* if the target is a monster, make sure it's owner is not the same */ 1097 /* if the target is a monster, make sure it's owner is not the same */
1137 if ((target->type != PLAYER) && (rowner == towner)) 1098 if (!target->is_player () && rowner == towner)
1138 return 0; 1099 return 0;
1139 1100
1140 /* check if the target is a player which affects how it will handle 1101 /* check if the target is a player which affects how it will handle
1141 parties */ 1102 parties */
1142 if (target->type != PLAYER) 1103 if (!target->is_player ())
1143 { 1104 {
1144 /* if the target is owned by a player make sure than make sure 1105 /* if the target is owned by a player make sure than make sure
1145 it's not in the same party */ 1106 it's not in the same party */
1146 if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) 1107 if (towner->is_player () && rowner->contr->party)
1147 {
1148 if (rowner->contr->party == towner->contr->party) 1108 if (rowner->contr->party == towner->contr->party)
1149 return 0; 1109 return 0;
1150 }
1151 } 1110 }
1152 else 1111 else
1153 { 1112 {
1154 /* if the target is a player make sure than make sure it's not 1113 /* if the target is a player make sure than make sure it's not
1155 in the same party */ 1114 in the same party */
1156 if (rowner->contr->party != NULL) 1115 if (rowner->contr->party)
1157 {
1158 if (rowner->contr->party == target->contr->party) 1116 if (rowner->contr->party == target->contr->party)
1159 return 0; 1117 return 0;
1160 }
1161 } 1118 }
1162 1119
1163 return 1; 1120 return 1;
1164} 1121}
1122

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines