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.9 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.22 by root, Mon Jan 8 01:19:04 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
20 21
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23*/
23 24
24#include <global.h> 25#include <global.h>
25#ifndef __CEXTRACT__
26# include <sproto.h> 26#include <sproto.h>
27#endif
28 27
29/* given that 'pet' is a friendly object, this function returns a 28/* given that 'pet' is a friendly object, this function returns a
30 * monster the pet should attack, NULL if nothing appropriate is 29 * monster the pet should attack, NULL if nothing appropriate is
31 * found. it basically looks for nasty things around the owner 30 * found. it basically looks for nasty things around the owner
32 * of the pet to attack. 31 * of the pet to attack.
33 * this is now tilemap aware. 32 * this is now tilemap aware.
34 */ 33 */
35
36object * 34object *
37get_pet_enemy (object *pet, rv_vector * rv) 35get_pet_enemy (object *pet, rv_vector * rv)
38{ 36{
39 object *owner, *tmp, *attacker, *tmp3; 37 object *owner, *tmp, *attacker, *tmp3;
40 int i; 38 int i;
41 sint16 x, y; 39 sint16 x, y;
42 mapstruct *nm; 40 maptile *nm;
43 int search_arr[SIZEOFFREE]; 41 int search_arr[SIZEOFFREE];
44 int mflags; 42 int mflags;
45 43
46 attacker = pet->attacked_by; /*pointer to attacking enemy */ 44 attacker = pet->attacked_by; /*pointer to attacking enemy */
47 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 */
48 46
49 if ((owner = get_owner (pet)) != NULL) 47 if ((owner = pet->owner) != NULL)
50 { 48 {
51 /* If the owner has turned on the pet, make the pet 49 /* If the owner has turned on the pet, make the pet
52 * unfriendly. 50 * unfriendly.
53 */ 51 */
54 if ((check_enemy (owner, rv)) == pet) 52 if ((check_enemy (owner, rv)) == pet)
82 */ 80 */
83 pet->enemy = NULL; 81 pet->enemy = NULL;
84 else 82 else
85 return tmp; 83 return tmp;
86 } 84 }
85
87 get_search_arr (search_arr); 86 get_search_arr (search_arr);
88 87
89 if (owner->type == PLAYER && owner->contr->petmode > pet_normal) 88 if (owner->type == PLAYER && owner->contr->petmode > pet_normal)
90 { 89 {
91 if (owner->contr->petmode == pet_sad) 90 if (owner->contr->petmode == pet_sad)
115 x = owner->x + freearr_x[search_arr[i]]; 114 x = owner->x + freearr_x[search_arr[i]];
116 y = owner->y + freearr_y[search_arr[i]]; 115 y = owner->y + freearr_y[search_arr[i]];
117 nm = owner->map; 116 nm = owner->map;
118 /* Only look on the space if there is something alive there. */ 117 /* Only look on the space if there is something alive there. */
119 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 118 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
119
120 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 120 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
121 { 121 {
122 for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) 122 for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above)
123 { 123 {
124 object *tmp2 = tmp->head == NULL ? tmp : tmp->head; 124 object *tmp2 = tmp->head == NULL ? tmp : tmp->head;
125 125
126 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && 126 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
127 (tmp2->type != PLAYER)) || 127 (tmp2->type != PLAYER)) ||
189 nm = pet->map; 189 nm = pet->map;
190 /* Only look on the space if there is something alive there. */ 190 /* Only look on the space if there is something alive there. */
191 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 191 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
192 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 192 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
193 { 193 {
194 for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) 194 for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above)
195 { 195 {
196 object *tmp2 = tmp->head == NULL ? tmp : tmp->head; 196 object *tmp2 = tmp->head == NULL ? tmp : tmp->head;
197 197
198 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && 198 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
199 (tmp2->type != PLAYER)) || 199 (tmp2->type != PLAYER)) ||
243 for (obl = first_friendly_object; obl != NULL; obl = next) 243 for (obl = first_friendly_object; obl != NULL; obl = next)
244 { 244 {
245 object *ob = obl->ob; 245 object *ob = obl->ob;
246 246
247 next = obl->next; 247 next = obl->next;
248 if (get_owner (ob) == owner) 248 if (ob->owner == owner)
249 { 249 {
250 if (!QUERY_FLAG (ob, FLAG_REMOVED)) 250 if (!QUERY_FLAG (ob, FLAG_REMOVED))
251 remove_ob (ob); 251 ob->remove ();
252 remove_friendly_object (ob); 252 remove_friendly_object (ob);
253 free_object (ob); 253 ob->destroy ();
254 } 254 }
255 } 255 }
256} 256}
257 257
258/* 258/*
261 * Thus the map isn't loaded yet, and we have to remove 261 * Thus the map isn't loaded yet, and we have to remove
262 * the pet... 262 * the pet...
263 * Interesting enough, we don't use the passed map structure in 263 * Interesting enough, we don't use the passed map structure in
264 * this function. 264 * this function.
265 */ 265 */
266
267void 266void
268remove_all_pets (mapstruct *map) 267remove_all_pets (maptile *map)
269{ 268{
270 objectlink *obl, *next; 269 objectlink *obl, *next;
271 object *owner; 270 object *owner;
272 271
273 for (obl = first_friendly_object; obl != NULL; obl = next) 272 for (obl = first_friendly_object; obl != NULL; obl = next)
274 { 273 {
275 next = obl->next; 274 next = obl->next;
276 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && 275 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) &&
277 (owner = get_owner (obl->ob)) != NULL && !on_same_map (owner, obl->ob)) 276 (owner = obl->ob->owner) != NULL && !on_same_map (owner, obl->ob))
278 { 277 {
279 /* follow owner checks map status for us */ 278 /* follow owner checks map status for us */
280 follow_owner (obl->ob, owner); 279 follow_owner (obl->ob, owner);
281 } 280 }
282 } 281 }
287{ 286{
288 object *tmp; 287 object *tmp;
289 int dir; 288 int dir;
290 289
291 if (!QUERY_FLAG (ob, FLAG_REMOVED)) 290 if (!QUERY_FLAG (ob, FLAG_REMOVED))
292 remove_ob (ob); 291 ob->remove ();
293 292
294 if (owner->map == NULL) 293 if (owner->map == NULL)
295 { 294 {
296 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); 295 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name);
297 goto fail; 296 goto fail;
325 324
326 return 0; 325 return 0;
327 326
328fail: 327fail:
329 remove_friendly_object (ob); 328 remove_friendly_object (ob);
330 free_object (ob); 329 ob->destroy ();
331 330
332 return 1; 331 return 1;
333} 332}
334 333
335void 334void
336pet_move (object *ob) 335pet_move (object *ob)
337{ 336{
338 int dir, tag, i; 337 int dir, i;
339 sint16 dx, dy; 338 sint16 dx, dy;
340 object *ob2, *owner; 339 object *ob2, *owner;
341 mapstruct *m; 340 maptile *m;
342 341
343 /* Check to see if player pulled out */ 342 /* Check to see if player pulled out */
344 if ((owner = get_owner (ob)) == NULL) 343 if ((owner = ob->owner) == NULL)
345 { 344 {
346 remove_ob (ob); /* Will be freed when returning */ 345 ob->remove (); /* Will be freed when returning */
347 remove_friendly_object (ob); 346 remove_friendly_object (ob);
348 free_object (ob); 347 ob->destroy ();
349 LOG (llevMonster, "Pet: no owner, leaving.\n"); 348 LOG (llevMonster, "Pet: no owner, leaving.\n");
350 return; 349 return;
351 } 350 }
352 351
353 /* move monster into the owners map if not in the same map */ 352 /* move monster into the owners map if not in the same map */
381 get_rangevector (ob, ob->owner, &rv, 0); 380 get_rangevector (ob, ob->owner, &rv, 0);
382 dir = rv.direction; 381 dir = rv.direction;
383 } 382 }
384 ob->direction = dir; 383 ob->direction = dir;
385 384
386 tag = ob->count;
387 /* move_ob returns 0 if the object couldn't move. If that is the 385 /* move_ob returns 0 if the object couldn't move. If that is the
388 * case, lets do some other work. 386 * case, lets do some other work.
389 */ 387 */
390 if (!(move_ob (ob, dir, ob))) 388 if (!(move_ob (ob, dir, ob)))
391 { 389 {
392 object *part; 390 object *part;
393 391
394 /* the failed move_ob above may destroy the pet, so check here */ 392 /* the failed move_ob above may destroy the pet, so check here */
395 if (was_destroyed (ob, tag)) 393 if (ob->destroyed ())
396 return; 394 return;
397 395
398 for (part = ob; part != NULL; part = part->more) 396 for (part = ob; part != NULL; part = part->more)
399 { 397 {
400 dx = part->x + freearr_x[dir]; 398 dx = part->x + freearr_x[dir];
401 dy = part->y + freearr_y[dir]; 399 dy = part->y + freearr_y[dir];
402 m = get_map_from_coord (part->map, &dx, &dy); 400 m = get_map_from_coord (part->map, &dx, &dy);
403 if (!m) 401 if (!m)
404 continue; 402 continue;
405 403
406 for (ob2 = get_map_ob (m, dx, dy); ob2 != NULL; ob2 = ob2->above) 404 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above)
407 { 405 {
408 object *new_ob; 406 object *new_ob;
409 407
410 new_ob = ob2->head ? ob2->head : ob2; 408 new_ob = ob2->head ? ob2->head : ob2;
411 if (new_ob == ob) 409 if (new_ob == ob)
412 break; 410 break;
413 if (new_ob == ob->owner) 411 if (new_ob == ob->owner)
414 return; 412 return;
415 if (get_owner (new_ob) == ob->owner) 413 if (new_ob->owner == ob->owner)
416 break; 414 break;
417 415
418 /* Hmm. Did we try to move into an enemy monster? If so, 416 /* Hmm. Did we try to move into an enemy monster? If so,
419 * make it our enemy. 417 * make it our enemy.
420 */ 418 */
457fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 455fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
458{ 456{
459 archetype *atmp; 457 archetype *atmp;
460 object *tmp = NULL, *prev = NULL, *head = NULL; 458 object *tmp = NULL, *prev = NULL, *head = NULL;
461 459
462 for (atmp = at; atmp != NULL; atmp = atmp->more) 460 for (atmp = at; atmp; atmp = atmp->more)
463 { 461 {
464 tmp = arch_to_object (atmp); 462 tmp = arch_to_object (atmp);
463
465 if (atmp == at) 464 if (atmp == at)
466 { 465 {
467 if (!is_golem) 466 if (!is_golem)
468 SET_FLAG (tmp, FLAG_MONSTER); 467 SET_FLAG (tmp, FLAG_MONSTER);
468
469 set_owner (tmp, op); 469 tmp->set_owner (op);
470 if (op->type == PLAYER) 470 if (op->type == PLAYER)
471 { 471 {
472 tmp->stats.exp = 0; 472 tmp->stats.exp = 0;
473 add_friendly_object (tmp); 473 add_friendly_object (tmp);
474 SET_FLAG (tmp, FLAG_FRIENDLY);
475 if (is_golem) 474 if (is_golem)
476 CLEAR_FLAG (tmp, FLAG_MONSTER); 475 CLEAR_FLAG (tmp, FLAG_MONSTER);
477 } 476 }
478 else 477 else
479 { 478 {
480 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 479 if (QUERY_FLAG (op, FLAG_FRIENDLY))
481 { 480 {
482 object *owner = get_owner (op); 481 object *owner = op->owner;
483 482
484 if (owner != NULL) 483 if (owner)
485 { /* For now, we transfer ownership */ 484 { /* For now, we transfer ownership */
486 set_owner (tmp, owner); 485 tmp->set_owner (owner);
487 tmp->attack_movement = PETMOVE; 486 tmp->attack_movement = PETMOVE;
488 add_friendly_object (tmp); 487 add_friendly_object (tmp);
489 SET_FLAG (tmp, FLAG_FRIENDLY);
490 } 488 }
491 } 489 }
492 } 490 }
491
493 if (op->type != PLAYER || !is_golem) 492 if (op->type != PLAYER || !is_golem)
494 { 493 {
495 tmp->attack_movement = PETMOVE; 494 tmp->attack_movement = PETMOVE;
496 tmp->speed_left = -1; 495 tmp->speed_left = -1;
497 tmp->type = 0; 496 tmp->type = 0;
499 } 498 }
500 else 499 else
501 tmp->type = GOLEM; 500 tmp->type = GOLEM;
502 501
503 } 502 }
503
504 if (head == NULL) 504 if (!head)
505 head = tmp; 505 head = tmp;
506
506 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; 507 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x;
507 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; 508 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y;
508 tmp->map = op->map; 509 tmp->map = op->map;
510
509 if (tmp->invisible) 511 if (tmp->invisible)
510 tmp->invisible = 0; 512 tmp->invisible = 0;
513
511 if (head != tmp) 514 if (head != tmp)
512 tmp->head = head, prev->more = tmp; 515 tmp->head = head, prev->more = tmp;
516
513 prev = tmp; 517 prev = tmp;
514 } 518 }
519
515 head->direction = dir; 520 head->direction = dir;
516 521
517 /* need to change some monster attr to prevent problems/crashing */ 522 /* need to change some monster attr to prevent problems/crashing */
518 head->last_heal = 0; 523 head->last_heal = 0;
519 head->last_eat = 0; 524 head->last_eat = 0;
530 535
531 return head; 536 return head;
532} 537}
533 538
534/* updated this to allow more than the golem 'head' to attack */ 539/* updated this to allow more than the golem 'head' to attack */
535
536/* op is the golem to be moved. */ 540/* op is the golem to be moved. */
537
538void 541void
539move_golem (object *op) 542move_golem (object *op)
540{ 543{
541 int made_attack = 0; 544 int made_attack = 0;
542 object *tmp; 545 object *tmp;
543 tag_t tag;
544 546
545 if (QUERY_FLAG (op, FLAG_MONSTER)) 547 if (QUERY_FLAG (op, FLAG_MONSTER))
546 return; /* Has already been moved */ 548 return; /* Has already been moved */
547 549
548 if (get_owner (op) == NULL) 550 if (op->owner == NULL)
549 { 551 {
550 LOG (llevDebug, "Golem without owner destructed.\n"); 552 LOG (llevDebug, "Golem without owner destructed.\n");
551 remove_ob (op); 553 op->remove ();
552 free_object (op); 554 op->destroy ();
553 return; 555 return;
554 } 556 }
557
555 /* It would be nice to have a cleaner way of what message to print 558 /* It would be nice to have a cleaner way of what message to print
556 * when the golem expires than these hard coded entries. 559 * when the golem expires than these hard coded entries.
557 * Note it is intentional that a golems duration is based on its 560 * Note it is intentional that a golems duration is based on its
558 * hp, and not duration 561 * hp, and not duration
559 */ 562 */
560 if (--op->stats.hp < 0) 563 if (--op->stats.hp < 0)
561 { 564 {
562 if (op->msg) 565 if (op->msg)
563 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 566 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
567
564 op->owner->contr->ranges[range_golem] = NULL; 568 op->owner->contr->ranges[range_golem] = 0;
565 op->owner->contr->golem_count = 0;
566 remove_friendly_object (op); 569 remove_friendly_object (op);
567 remove_ob (op); 570 op->remove ();
568 free_object (op); 571 op->destroy ();
569 return; 572 return;
570 } 573 }
571 574
572 /* Do golem attacks/movement for single & multisq golems. 575 /* Do golem attacks/movement for single & multisq golems.
573 * Assuming here that op is the 'head' object. Pass only op to 576 * Assuming here that op is the 'head' object. Pass only op to
574 * move_ob (makes recursive calls to other parts) 577 * move_ob (makes recursive calls to other parts)
575 * move_ob returns 0 if the creature was not able to move. 578 * move_ob returns 0 if the creature was not able to move.
576 */ 579 */
577 tag = op->count;
578 if (move_ob (op, op->direction, op)) 580 if (move_ob (op, op->direction, op))
579 return; 581 return;
580 if (was_destroyed (op, tag)) 582
583 if (op->destroyed ())
581 return; 584 return;
582 585
583 for (tmp = op; tmp; tmp = tmp->more) 586 for (tmp = op; tmp; tmp = tmp->more)
584 { 587 {
585 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; 588 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction];
586 object *victim; 589 object *victim;
587 mapstruct *m; 590 maptile *m;
588 int mflags; 591 int mflags;
589 592
590 m = op->map; 593 m = op->map;
591 mflags = get_map_flags (m, &m, x, y, &x, &y); 594 mflags = get_map_flags (m, &m, x, y, &x, &y);
592 595
593 if (mflags & P_OUT_OF_MAP) 596 if (mflags & P_OUT_OF_MAP)
594 continue; 597 continue;
595 598
596 for (victim = get_map_ob (op->map, x, y); victim; victim = victim->above) 599 for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above)
597 if (QUERY_FLAG (victim, FLAG_ALIVE)) 600 if (QUERY_FLAG (victim, FLAG_ALIVE))
598 break; 601 break;
599 602
600 /* We used to call will_hit_self to make sure we don't 603 /* We used to call will_hit_self to make sure we don't
601 * hit ourselves, but that didn't work, and I don't really 604 * hit ourselves, but that didn't work, and I don't really
657 char buf[MAX_BUF]; 660 char buf[MAX_BUF];
658 661
659 /* Because there can be different golem spells, player may want to 662 /* Because there can be different golem spells, player may want to
660 * 'lose' their old golem. 663 * 'lose' their old golem.
661 */ 664 */
662 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) 665 if (op->type == PLAYER && op->contr->ranges[range_golem])
663 { 666 {
664 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); 667 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem.");
665 remove_ob (op->contr->ranges[range_golem]); 668 op->contr->ranges[range_golem]->remove ();
666 free_object (op->contr->ranges[range_golem]); 669 op->contr->ranges[range_golem]->destroy ();
667 op->contr->ranges[range_golem] = NULL; 670 op->contr->ranges[range_golem] = 0;
668 op->contr->golem_count = (uint32) - 1;
669 } 671 }
670 672
671 if (spob->other_arch) 673 if (spob->other_arch)
672 at = spob->other_arch; 674 at = spob->other_arch;
673 else if (spob->race) 675 else if (spob->race)
700 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 702 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
701 { 703 {
702 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 704 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
703 return 0; 705 return 0;
704 } 706 }
707
705 /* basically want to get proper map/coordinates for this object */ 708 /* basically want to get proper map/coordinates for this object */
706 709
707 if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) 710 if (!(tmp = fix_summon_pet (at, op, dir, GOLEM)))
708 { 711 {
709 new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); 712 new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails.");
711 } 714 }
712 715
713 if (op->type == PLAYER) 716 if (op->type == PLAYER)
714 { 717 {
715 tmp->type = GOLEM; 718 tmp->type = GOLEM;
716 set_owner (tmp, op); 719 tmp->set_owner (op);
717 set_spell_skill (op, caster, spob, tmp); 720 set_spell_skill (op, caster, spob, tmp);
718 op->contr->ranges[range_golem] = tmp; 721 op->contr->ranges[range_golem] = tmp;
719 op->contr->golem_count = tmp->count;
720 /* give the player control of the golem */ 722 /* give the player control of the golem */
721 op->contr->shoottype = range_golem; 723 op->contr->shoottype = range_golem;
722 } 724 }
723 else 725 else
724 { 726 {
725 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 727 if (QUERY_FLAG (op, FLAG_FRIENDLY))
726 { 728 {
727 object *owner = get_owner (op); 729 object *owner = op->owner;
728 730
729 if (owner != NULL) 731 if (owner)
730 { /* For now, we transfer ownership */ 732 { /* For now, we transfer ownership */
731 set_owner (tmp, owner); 733 tmp->set_owner (owner);
732 tmp->attack_movement = PETMOVE; 734 tmp->attack_movement = PETMOVE;
733 add_friendly_object (tmp); 735 add_friendly_object (tmp);
734 SET_FLAG (tmp, FLAG_FRIENDLY);
735 } 736 }
736 } 737 }
737 738
738 SET_FLAG (tmp, FLAG_MONSTER); 739 SET_FLAG (tmp, FLAG_MONSTER);
739 } 740 }
908 * with all the checks in the 'for' portion itself. Much 909 * with all the checks in the 'for' portion itself. Much
909 * more readable to break some of the conditions out. 910 * more readable to break some of the conditions out.
910 */ 911 */
911 for (tr = spell_ob->randomitems->items; tr; tr = tr->next) 912 for (tr = spell_ob->randomitems->items; tr; tr = tr->next)
912 { 913 {
914 if (!tr->item)
915 continue;
916
913 if (level < tr->magic) 917 if (level < tr->magic)
914 break; 918 break;
915 919
916 lasttr = tr; 920 lasttr = tr;
917 921
918 if (tr->item->name == sparam) 922 if (tr->item->name == sparam)
919 break;
920
921 if (!tr->next || !tr->next->item)
922 break; 923 break;
923 } 924 }
924 925
925 if (!lasttr) 926 if (!lasttr)
926 { 927 {
928 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); 929 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters.");
929 return 0; 930 return 0;
930 } 931 }
931 932
932 summon_arch = lasttr->item; 933 summon_arch = lasttr->item;
933 nrof = lasttr->nrof; 934 nrof = lasttr->nrof;
934 } 935 }
935 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 936 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON"))
936 { 937 {
937 object *god = find_god (determine_god (op)), *mon, *owner; 938 object *god = find_god (determine_god (op)), *mon, *owner;
938 int summon_level, tries; 939 int summon_level, tries;
939 940
940 if (!god && ((owner = get_owner (op)) != NULL)) 941 if (!god && ((owner = op->owner) != NULL))
941 god = find_god (determine_god (owner)); 942 god = find_god (determine_god (owner));
942 943
943 /* If we can't find a god, can't get what monster to summon */ 944 /* If we can't find a god, can't get what monster to summon */
944 if (!god) 945 if (!god)
945 return 0; 946 return 0;
1034 tmp = arch_to_object (atmp); 1035 tmp = arch_to_object (atmp);
1035 if (atmp == summon_arch) 1036 if (atmp == summon_arch)
1036 { 1037 {
1037 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1038 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1038 { 1039 {
1039 set_owner (tmp, op); 1040 tmp->set_owner (op);
1040 set_spell_skill (op, caster, spell_ob, tmp); 1041 set_spell_skill (op, caster, spell_ob, tmp);
1041 tmp->enemy = op->enemy; 1042 tmp->enemy = op->enemy;
1042 tmp->type = 0; 1043 tmp->type = 0;
1043 CLEAR_FLAG (tmp, FLAG_SLEEP); 1044 CLEAR_FLAG (tmp, FLAG_SLEEP);
1044 1045
1045 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) 1046 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY))
1046 { 1047 {
1047 /* If this is not set, we make it friendly */ 1048 /* If this is not set, we make it friendly */
1048 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) 1049 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER))
1049 { 1050 {
1050 SET_FLAG (tmp, FLAG_FRIENDLY);
1051 add_friendly_object (tmp); 1051 add_friendly_object (tmp);
1052 tmp->stats.exp = 0; 1052 tmp->stats.exp = 0;
1053 1053
1054 if (spell_ob->attack_movement) 1054 if (spell_ob->attack_movement)
1055 tmp->attack_movement = spell_ob->attack_movement; 1055 tmp->attack_movement = spell_ob->attack_movement;
1056 1056
1057 if (get_owner (op)) 1057 if (op->owner)
1058 set_owner (tmp, get_owner (op)); 1058 tmp->set_owner (op->owner);
1059 } 1059 }
1060 } 1060 }
1061 } 1061 }
1062 1062
1063 if (tmp->speed > MIN_ACTIVE_SPEED) 1063 if (tmp->speed > MIN_ACTIVE_SPEED)
1082 head->stats.exp = 0; 1082 head->stats.exp = 0;
1083 head = insert_ob_in_map (head, head->map, op, 0); 1083 head = insert_ob_in_map (head, head->map, op, 0);
1084 1084
1085 if (head && head->randomitems) 1085 if (head && head->randomitems)
1086 { 1086 {
1087 object *tmp;
1088
1089 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1087 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1088
1090 for (tmp = head->inv; tmp; tmp = tmp->below) 1089 for (object *tmp = head->inv; tmp; tmp = tmp->below)
1091 if (!tmp->nrof)
1092 SET_FLAG (tmp, FLAG_NO_DROP); 1090 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH);
1093 } 1091 }
1094 } /* for i < nrof */ 1092 } /* for i < nrof */
1095 1093
1096 return 1; 1094 return 1;
1097} 1095}
1104 object *realowner = ob; 1102 object *realowner = ob;
1105 1103
1106 if (realowner == NULL) 1104 if (realowner == NULL)
1107 return NULL; 1105 return NULL;
1108 1106
1109 while (get_owner (realowner) != NULL) 1107 while (realowner->owner != NULL)
1110 { 1108 {
1111 realowner = get_owner (realowner); 1109 realowner = realowner->owner;
1112 } 1110 }
1113 return realowner; 1111 return realowner;
1114} 1112}
1115 1113
1116/* determines if checks so pets don't attack players or other pets should be 1114/* determines if checks so pets don't attack players or other pets should be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines