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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines