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.16 by root, Wed Dec 20 09:14:22 2006 UTC

37get_pet_enemy (object *pet, rv_vector * rv) 37get_pet_enemy (object *pet, rv_vector * rv)
38{ 38{
39 object *owner, *tmp, *attacker, *tmp3; 39 object *owner, *tmp, *attacker, *tmp3;
40 int i; 40 int i;
41 sint16 x, y; 41 sint16 x, y;
42 mapstruct *nm; 42 maptile *nm;
43 int search_arr[SIZEOFFREE]; 43 int search_arr[SIZEOFFREE];
44 int mflags; 44 int mflags;
45 45
46 attacker = pet->attacked_by; /*pointer to attacking enemy */ 46 attacker = pet->attacked_by; /*pointer to attacking enemy */
47 pet->attacked_by = NULL; /*clear this, since we are dealing with it */ 47 pet->attacked_by = NULL; /*clear this, since we are dealing with it */
48 48
49 if ((owner = get_owner (pet)) != NULL) 49 if ((owner = pet->owner) != NULL)
50 { 50 {
51 /* If the owner has turned on the pet, make the pet 51 /* If the owner has turned on the pet, make the pet
52 * unfriendly. 52 * unfriendly.
53 */ 53 */
54 if ((check_enemy (owner, rv)) == pet) 54 if ((check_enemy (owner, rv)) == pet)
117 nm = owner->map; 117 nm = owner->map;
118 /* Only look on the space if there is something alive there. */ 118 /* Only look on the space if there is something alive there. */
119 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 119 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
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/*
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 266
267void 267void
268remove_all_pets (mapstruct *map) 268remove_all_pets (maptile *map)
269{ 269{
270 objectlink *obl, *next; 270 objectlink *obl, *next;
271 object *owner; 271 object *owner;
272 272
273 for (obl = first_friendly_object; obl != NULL; obl = next) 273 for (obl = first_friendly_object; obl != NULL; obl = next)
274 { 274 {
275 next = obl->next; 275 next = obl->next;
276 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && 276 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) &&
277 (owner = get_owner (obl->ob)) != NULL && !on_same_map (owner, obl->ob)) 277 (owner = obl->ob->owner) != NULL && !on_same_map (owner, obl->ob))
278 { 278 {
279 /* follow owner checks map status for us */ 279 /* follow owner checks map status for us */
280 follow_owner (obl->ob, owner); 280 follow_owner (obl->ob, owner);
281 } 281 }
282 } 282 }
287{ 287{
288 object *tmp; 288 object *tmp;
289 int dir; 289 int dir;
290 290
291 if (!QUERY_FLAG (ob, FLAG_REMOVED)) 291 if (!QUERY_FLAG (ob, FLAG_REMOVED))
292 remove_ob (ob); 292 ob->remove ();
293 293
294 if (owner->map == NULL) 294 if (owner->map == NULL)
295 { 295 {
296 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); 296 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name);
297 goto fail; 297 goto fail;
325 325
326 return 0; 326 return 0;
327 327
328fail: 328fail:
329 remove_friendly_object (ob); 329 remove_friendly_object (ob);
330 free_object (ob); 330 ob->destroy ();
331 331
332 return 1; 332 return 1;
333} 333}
334 334
335void 335void
336pet_move (object *ob) 336pet_move (object *ob)
337{ 337{
338 int dir, tag, i; 338 int dir, i;
339 sint16 dx, dy; 339 sint16 dx, dy;
340 object *ob2, *owner; 340 object *ob2, *owner;
341 mapstruct *m; 341 maptile *m;
342 342
343 /* Check to see if player pulled out */ 343 /* Check to see if player pulled out */
344 if ((owner = get_owner (ob)) == NULL) 344 if ((owner = ob->owner) == NULL)
345 { 345 {
346 remove_ob (ob); /* Will be freed when returning */ 346 ob->remove (); /* Will be freed when returning */
347 remove_friendly_object (ob); 347 remove_friendly_object (ob);
348 free_object (ob); 348 ob->destroy ();
349 LOG (llevMonster, "Pet: no owner, leaving.\n"); 349 LOG (llevMonster, "Pet: no owner, leaving.\n");
350 return; 350 return;
351 } 351 }
352 352
353 /* move monster into the owners map if not in the same map */ 353 /* move monster into the owners map if not in the same map */
381 get_rangevector (ob, ob->owner, &rv, 0); 381 get_rangevector (ob, ob->owner, &rv, 0);
382 dir = rv.direction; 382 dir = rv.direction;
383 } 383 }
384 ob->direction = dir; 384 ob->direction = dir;
385 385
386 tag = ob->count;
387 /* move_ob returns 0 if the object couldn't move. If that is the 386 /* move_ob returns 0 if the object couldn't move. If that is the
388 * case, lets do some other work. 387 * case, lets do some other work.
389 */ 388 */
390 if (!(move_ob (ob, dir, ob))) 389 if (!(move_ob (ob, dir, ob)))
391 { 390 {
392 object *part; 391 object *part;
393 392
394 /* the failed move_ob above may destroy the pet, so check here */ 393 /* the failed move_ob above may destroy the pet, so check here */
395 if (was_destroyed (ob, tag)) 394 if (ob->destroyed ())
396 return; 395 return;
397 396
398 for (part = ob; part != NULL; part = part->more) 397 for (part = ob; part != NULL; part = part->more)
399 { 398 {
400 dx = part->x + freearr_x[dir]; 399 dx = part->x + freearr_x[dir];
401 dy = part->y + freearr_y[dir]; 400 dy = part->y + freearr_y[dir];
402 m = get_map_from_coord (part->map, &dx, &dy); 401 m = get_map_from_coord (part->map, &dx, &dy);
403 if (!m) 402 if (!m)
404 continue; 403 continue;
405 404
406 for (ob2 = get_map_ob (m, dx, dy); ob2 != NULL; ob2 = ob2->above) 405 for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above)
407 { 406 {
408 object *new_ob; 407 object *new_ob;
409 408
410 new_ob = ob2->head ? ob2->head : ob2; 409 new_ob = ob2->head ? ob2->head : ob2;
411 if (new_ob == ob) 410 if (new_ob == ob)
412 break; 411 break;
413 if (new_ob == ob->owner) 412 if (new_ob == ob->owner)
414 return; 413 return;
415 if (get_owner (new_ob) == ob->owner) 414 if (new_ob->owner == ob->owner)
416 break; 415 break;
417 416
418 /* Hmm. Did we try to move into an enemy monster? If so, 417 /* Hmm. Did we try to move into an enemy monster? If so,
419 * make it our enemy. 418 * make it our enemy.
420 */ 419 */
464 tmp = arch_to_object (atmp); 463 tmp = arch_to_object (atmp);
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);
469 set_owner (tmp, op); 468 tmp->set_owner (op);
470 if (op->type == PLAYER) 469 if (op->type == PLAYER)
471 { 470 {
472 tmp->stats.exp = 0; 471 tmp->stats.exp = 0;
473 add_friendly_object (tmp); 472 add_friendly_object (tmp);
474 SET_FLAG (tmp, FLAG_FRIENDLY); 473 SET_FLAG (tmp, FLAG_FRIENDLY);
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 != NULL)
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); 488 SET_FLAG (tmp, FLAG_FRIENDLY);
490 } 489 }
491 } 490 }
538void 537void
539move_golem (object *op) 538move_golem (object *op)
540{ 539{
541 int made_attack = 0; 540 int made_attack = 0;
542 object *tmp; 541 object *tmp;
543 tag_t tag;
544 542
545 if (QUERY_FLAG (op, FLAG_MONSTER)) 543 if (QUERY_FLAG (op, FLAG_MONSTER))
546 return; /* Has already been moved */ 544 return; /* Has already been moved */
547 545
548 if (get_owner (op) == NULL) 546 if (op->owner == NULL)
549 { 547 {
550 LOG (llevDebug, "Golem without owner destructed.\n"); 548 LOG (llevDebug, "Golem without owner destructed.\n");
551 remove_ob (op); 549 op->remove ();
552 free_object (op); 550 op->destroy ();
553 return; 551 return;
554 } 552 }
553
555 /* It would be nice to have a cleaner way of what message to print 554 /* It would be nice to have a cleaner way of what message to print
556 * when the golem expires than these hard coded entries. 555 * when the golem expires than these hard coded entries.
557 * Note it is intentional that a golems duration is based on its 556 * Note it is intentional that a golems duration is based on its
558 * hp, and not duration 557 * hp, and not duration
559 */ 558 */
560 if (--op->stats.hp < 0) 559 if (--op->stats.hp < 0)
561 { 560 {
562 if (op->msg) 561 if (op->msg)
563 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 562 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
563
564 op->owner->contr->ranges[range_golem] = NULL; 564 op->owner->contr->ranges[range_golem] = 0;
565 op->owner->contr->golem_count = 0;
566 remove_friendly_object (op); 565 remove_friendly_object (op);
567 remove_ob (op); 566 op->remove ();
568 free_object (op); 567 op->destroy ();
569 return; 568 return;
570 } 569 }
571 570
572 /* Do golem attacks/movement for single & multisq golems. 571 /* Do golem attacks/movement for single & multisq golems.
573 * Assuming here that op is the 'head' object. Pass only op to 572 * Assuming here that op is the 'head' object. Pass only op to
574 * move_ob (makes recursive calls to other parts) 573 * move_ob (makes recursive calls to other parts)
575 * move_ob returns 0 if the creature was not able to move. 574 * move_ob returns 0 if the creature was not able to move.
576 */ 575 */
577 tag = op->count;
578 if (move_ob (op, op->direction, op)) 576 if (move_ob (op, op->direction, op))
579 return; 577 return;
580 if (was_destroyed (op, tag)) 578
579 if (op->destroyed ())
581 return; 580 return;
582 581
583 for (tmp = op; tmp; tmp = tmp->more) 582 for (tmp = op; tmp; tmp = tmp->more)
584 { 583 {
585 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; 584 sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction];
586 object *victim; 585 object *victim;
587 mapstruct *m; 586 maptile *m;
588 int mflags; 587 int mflags;
589 588
590 m = op->map; 589 m = op->map;
591 mflags = get_map_flags (m, &m, x, y, &x, &y); 590 mflags = get_map_flags (m, &m, x, y, &x, &y);
592 591
593 if (mflags & P_OUT_OF_MAP) 592 if (mflags & P_OUT_OF_MAP)
594 continue; 593 continue;
595 594
596 for (victim = get_map_ob (op->map, x, y); victim; victim = victim->above) 595 for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above)
597 if (QUERY_FLAG (victim, FLAG_ALIVE)) 596 if (QUERY_FLAG (victim, FLAG_ALIVE))
598 break; 597 break;
599 598
600 /* We used to call will_hit_self to make sure we don't 599 /* 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 600 * hit ourselves, but that didn't work, and I don't really
657 char buf[MAX_BUF]; 656 char buf[MAX_BUF];
658 657
659 /* Because there can be different golem spells, player may want to 658 /* Because there can be different golem spells, player may want to
660 * 'lose' their old golem. 659 * 'lose' their old golem.
661 */ 660 */
662 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) 661 if (op->type == PLAYER && op->contr->ranges[range_golem])
663 { 662 {
664 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); 663 new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem.");
665 remove_ob (op->contr->ranges[range_golem]); 664 op->contr->ranges[range_golem]->remove ();
666 free_object (op->contr->ranges[range_golem]); 665 op->contr->ranges[range_golem]->destroy ();
667 op->contr->ranges[range_golem] = NULL; 666 op->contr->ranges[range_golem] = 0;
668 op->contr->golem_count = (uint32) - 1;
669 } 667 }
670 668
671 if (spob->other_arch) 669 if (spob->other_arch)
672 at = spob->other_arch; 670 at = spob->other_arch;
673 else if (spob->race) 671 else if (spob->race)
711 } 709 }
712 710
713 if (op->type == PLAYER) 711 if (op->type == PLAYER)
714 { 712 {
715 tmp->type = GOLEM; 713 tmp->type = GOLEM;
716 set_owner (tmp, op); 714 tmp->set_owner (op);
717 set_spell_skill (op, caster, spob, tmp); 715 set_spell_skill (op, caster, spob, tmp);
718 op->contr->ranges[range_golem] = tmp; 716 op->contr->ranges[range_golem] = tmp;
719 op->contr->golem_count = tmp->count;
720 /* give the player control of the golem */ 717 /* give the player control of the golem */
721 op->contr->shoottype = range_golem; 718 op->contr->shoottype = range_golem;
722 } 719 }
723 else 720 else
724 { 721 {
725 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 722 if (QUERY_FLAG (op, FLAG_FRIENDLY))
726 { 723 {
727 object *owner = get_owner (op); 724 object *owner = op->owner;
728 725
729 if (owner != NULL) 726 if (owner != NULL)
730 { /* For now, we transfer ownership */ 727 { /* For now, we transfer ownership */
731 set_owner (tmp, owner); 728 tmp->set_owner (owner);
732 tmp->attack_movement = PETMOVE; 729 tmp->attack_movement = PETMOVE;
733 add_friendly_object (tmp); 730 add_friendly_object (tmp);
734 SET_FLAG (tmp, FLAG_FRIENDLY); 731 SET_FLAG (tmp, FLAG_FRIENDLY);
735 } 732 }
736 } 733 }
935 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 932 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON"))
936 { 933 {
937 object *god = find_god (determine_god (op)), *mon, *owner; 934 object *god = find_god (determine_god (op)), *mon, *owner;
938 int summon_level, tries; 935 int summon_level, tries;
939 936
940 if (!god && ((owner = get_owner (op)) != NULL)) 937 if (!god && ((owner = op->owner) != NULL))
941 god = find_god (determine_god (owner)); 938 god = find_god (determine_god (owner));
942 939
943 /* If we can't find a god, can't get what monster to summon */ 940 /* If we can't find a god, can't get what monster to summon */
944 if (!god) 941 if (!god)
945 return 0; 942 return 0;
1034 tmp = arch_to_object (atmp); 1031 tmp = arch_to_object (atmp);
1035 if (atmp == summon_arch) 1032 if (atmp == summon_arch)
1036 { 1033 {
1037 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1034 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1038 { 1035 {
1039 set_owner (tmp, op); 1036 tmp->set_owner (op);
1040 set_spell_skill (op, caster, spell_ob, tmp); 1037 set_spell_skill (op, caster, spell_ob, tmp);
1041 tmp->enemy = op->enemy; 1038 tmp->enemy = op->enemy;
1042 tmp->type = 0; 1039 tmp->type = 0;
1043 CLEAR_FLAG (tmp, FLAG_SLEEP); 1040 CLEAR_FLAG (tmp, FLAG_SLEEP);
1044 1041
1052 tmp->stats.exp = 0; 1049 tmp->stats.exp = 0;
1053 1050
1054 if (spell_ob->attack_movement) 1051 if (spell_ob->attack_movement)
1055 tmp->attack_movement = spell_ob->attack_movement; 1052 tmp->attack_movement = spell_ob->attack_movement;
1056 1053
1057 if (get_owner (op)) 1054 if (op->owner)
1058 set_owner (tmp, get_owner (op)); 1055 tmp->set_owner (op->owner);
1059 } 1056 }
1060 } 1057 }
1061 } 1058 }
1062 1059
1063 if (tmp->speed > MIN_ACTIVE_SPEED) 1060 if (tmp->speed > MIN_ACTIVE_SPEED)
1104 object *realowner = ob; 1101 object *realowner = ob;
1105 1102
1106 if (realowner == NULL) 1103 if (realowner == NULL)
1107 return NULL; 1104 return NULL;
1108 1105
1109 while (get_owner (realowner) != NULL) 1106 while (realowner->owner != NULL)
1110 { 1107 {
1111 realowner = get_owner (realowner); 1108 realowner = realowner->owner;
1112 } 1109 }
1113 return realowner; 1110 return realowner;
1114} 1111}
1115 1112
1116/* determines if checks so pets don't attack players or other pets should be 1113/* determines if checks so pets don't attack players or other pets should be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines