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.16 by root, Wed Dec 20 09:14:22 2006 UTC vs.
Revision 1.19 by root, Wed Jan 3 20:32:13 2007 UTC

20 20
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22*/
23 23
24#include <global.h> 24#include <global.h>
25#ifndef __CEXTRACT__
26# include <sproto.h> 25#include <sproto.h>
27#endif
28 26
29/* given that 'pet' is a friendly object, this function returns a 27/* given that 'pet' is a friendly object, this function returns a
30 * monster the pet should attack, NULL if nothing appropriate is 28 * monster the pet should attack, NULL if nothing appropriate is
31 * found. it basically looks for nasty things around the owner 29 * found. it basically looks for nasty things around the owner
32 * of the pet to attack. 30 * of the pet to attack.
33 * this is now tilemap aware. 31 * this is now tilemap aware.
34 */ 32 */
35
36object * 33object *
37get_pet_enemy (object *pet, rv_vector * rv) 34get_pet_enemy (object *pet, rv_vector * rv)
38{ 35{
39 object *owner, *tmp, *attacker, *tmp3; 36 object *owner, *tmp, *attacker, *tmp3;
40 int i; 37 int i;
82 */ 79 */
83 pet->enemy = NULL; 80 pet->enemy = NULL;
84 else 81 else
85 return tmp; 82 return tmp;
86 } 83 }
84
87 get_search_arr (search_arr); 85 get_search_arr (search_arr);
88 86
89 if (owner->type == PLAYER && owner->contr->petmode > pet_normal) 87 if (owner->type == PLAYER && owner->contr->petmode > pet_normal)
90 { 88 {
91 if (owner->contr->petmode == pet_sad) 89 if (owner->contr->petmode == pet_sad)
115 x = owner->x + freearr_x[search_arr[i]]; 113 x = owner->x + freearr_x[search_arr[i]];
116 y = owner->y + freearr_y[search_arr[i]]; 114 y = owner->y + freearr_y[search_arr[i]];
117 nm = owner->map; 115 nm = owner->map;
118 /* Only look on the space if there is something alive there. */ 116 /* Only look on the space if there is something alive there. */
119 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 117 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
118
120 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 119 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
121 { 120 {
122 for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above) 121 for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above)
123 { 122 {
124 object *tmp2 = tmp->head == NULL ? tmp : tmp->head; 123 object *tmp2 = tmp->head == NULL ? tmp : tmp->head;
261 * Thus the map isn't loaded yet, and we have to remove 260 * Thus the map isn't loaded yet, and we have to remove
262 * the pet... 261 * the pet...
263 * Interesting enough, we don't use the passed map structure in 262 * Interesting enough, we don't use the passed map structure in
264 * this function. 263 * this function.
265 */ 264 */
266
267void 265void
268remove_all_pets (maptile *map) 266remove_all_pets (maptile *map)
269{ 267{
270 objectlink *obl, *next; 268 objectlink *obl, *next;
271 object *owner; 269 object *owner;
456fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 454fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
457{ 455{
458 archetype *atmp; 456 archetype *atmp;
459 object *tmp = NULL, *prev = NULL, *head = NULL; 457 object *tmp = NULL, *prev = NULL, *head = NULL;
460 458
461 for (atmp = at; atmp != NULL; atmp = atmp->more) 459 for (atmp = at; atmp; atmp = atmp->more)
462 { 460 {
463 tmp = arch_to_object (atmp); 461 tmp = arch_to_object (atmp);
462
464 if (atmp == at) 463 if (atmp == at)
465 { 464 {
466 if (!is_golem) 465 if (!is_golem)
467 SET_FLAG (tmp, FLAG_MONSTER); 466 SET_FLAG (tmp, FLAG_MONSTER);
467
468 tmp->set_owner (op); 468 tmp->set_owner (op);
469 if (op->type == PLAYER) 469 if (op->type == PLAYER)
470 { 470 {
471 tmp->stats.exp = 0; 471 tmp->stats.exp = 0;
472 add_friendly_object (tmp); 472 add_friendly_object (tmp);
478 { 478 {
479 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 479 if (QUERY_FLAG (op, FLAG_FRIENDLY))
480 { 480 {
481 object *owner = op->owner; 481 object *owner = op->owner;
482 482
483 if (owner != NULL) 483 if (owner)
484 { /* For now, we transfer ownership */ 484 { /* For now, we transfer ownership */
485 tmp->set_owner (owner); 485 tmp->set_owner (owner);
486 tmp->attack_movement = PETMOVE; 486 tmp->attack_movement = PETMOVE;
487 add_friendly_object (tmp); 487 add_friendly_object (tmp);
488 SET_FLAG (tmp, FLAG_FRIENDLY); 488 SET_FLAG (tmp, FLAG_FRIENDLY);
489 } 489 }
490 } 490 }
491 } 491 }
492
492 if (op->type != PLAYER || !is_golem) 493 if (op->type != PLAYER || !is_golem)
493 { 494 {
494 tmp->attack_movement = PETMOVE; 495 tmp->attack_movement = PETMOVE;
495 tmp->speed_left = -1; 496 tmp->speed_left = -1;
496 tmp->type = 0; 497 tmp->type = 0;
498 } 499 }
499 else 500 else
500 tmp->type = GOLEM; 501 tmp->type = GOLEM;
501 502
502 } 503 }
504
503 if (head == NULL) 505 if (!head)
504 head = tmp; 506 head = tmp;
507
505 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; 508 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x;
506 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; 509 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y;
507 tmp->map = op->map; 510 tmp->map = op->map;
511
508 if (tmp->invisible) 512 if (tmp->invisible)
509 tmp->invisible = 0; 513 tmp->invisible = 0;
514
510 if (head != tmp) 515 if (head != tmp)
511 tmp->head = head, prev->more = tmp; 516 tmp->head = head, prev->more = tmp;
517
512 prev = tmp; 518 prev = tmp;
513 } 519 }
520
514 head->direction = dir; 521 head->direction = dir;
515 522
516 /* need to change some monster attr to prevent problems/crashing */ 523 /* need to change some monster attr to prevent problems/crashing */
517 head->last_heal = 0; 524 head->last_heal = 0;
518 head->last_eat = 0; 525 head->last_eat = 0;
529 536
530 return head; 537 return head;
531} 538}
532 539
533/* updated this to allow more than the golem 'head' to attack */ 540/* updated this to allow more than the golem 'head' to attack */
534
535/* op is the golem to be moved. */ 541/* op is the golem to be moved. */
536
537void 542void
538move_golem (object *op) 543move_golem (object *op)
539{ 544{
540 int made_attack = 0; 545 int made_attack = 0;
541 object *tmp; 546 object *tmp;
698 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 703 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
699 { 704 {
700 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 705 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
701 return 0; 706 return 0;
702 } 707 }
708
703 /* basically want to get proper map/coordinates for this object */ 709 /* basically want to get proper map/coordinates for this object */
704 710
705 if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) 711 if (!(tmp = fix_summon_pet (at, op, dir, GOLEM)))
706 { 712 {
707 new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); 713 new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails.");
721 { 727 {
722 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 728 if (QUERY_FLAG (op, FLAG_FRIENDLY))
723 { 729 {
724 object *owner = op->owner; 730 object *owner = op->owner;
725 731
726 if (owner != NULL) 732 if (owner)
727 { /* For now, we transfer ownership */ 733 { /* For now, we transfer ownership */
728 tmp->set_owner (owner); 734 tmp->set_owner (owner);
729 tmp->attack_movement = PETMOVE; 735 tmp->attack_movement = PETMOVE;
730 add_friendly_object (tmp); 736 add_friendly_object (tmp);
731 SET_FLAG (tmp, FLAG_FRIENDLY); 737 SET_FLAG (tmp, FLAG_FRIENDLY);
905 * with all the checks in the 'for' portion itself. Much 911 * with all the checks in the 'for' portion itself. Much
906 * more readable to break some of the conditions out. 912 * more readable to break some of the conditions out.
907 */ 913 */
908 for (tr = spell_ob->randomitems->items; tr; tr = tr->next) 914 for (tr = spell_ob->randomitems->items; tr; tr = tr->next)
909 { 915 {
916 if (!tr->item)
917 continue;
918
910 if (level < tr->magic) 919 if (level < tr->magic)
911 break; 920 break;
912 921
913 lasttr = tr; 922 lasttr = tr;
914 923
915 if (tr->item->name == sparam) 924 if (tr->item->name == sparam)
916 break;
917
918 if (!tr->next || !tr->next->item)
919 break; 925 break;
920 } 926 }
921 927
922 if (!lasttr) 928 if (!lasttr)
923 { 929 {
925 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); 931 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters.");
926 return 0; 932 return 0;
927 } 933 }
928 934
929 summon_arch = lasttr->item; 935 summon_arch = lasttr->item;
930 nrof = lasttr->nrof; 936 nrof = lasttr->nrof;
931 } 937 }
932 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 938 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON"))
933 { 939 {
934 object *god = find_god (determine_god (op)), *mon, *owner; 940 object *god = find_god (determine_god (op)), *mon, *owner;
935 int summon_level, tries; 941 int summon_level, tries;
1079 head->stats.exp = 0; 1085 head->stats.exp = 0;
1080 head = insert_ob_in_map (head, head->map, op, 0); 1086 head = insert_ob_in_map (head, head->map, op, 0);
1081 1087
1082 if (head && head->randomitems) 1088 if (head && head->randomitems)
1083 { 1089 {
1084 object *tmp;
1085
1086 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1090 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1091
1087 for (tmp = head->inv; tmp; tmp = tmp->below) 1092 for (object *tmp = head->inv; tmp; tmp = tmp->below)
1088 if (!tmp->nrof)
1089 SET_FLAG (tmp, FLAG_NO_DROP); 1093 SET_FLAG (tmp, FLAG_NO_DROP);
1090 } 1094 }
1091 } /* for i < nrof */ 1095 } /* for i < nrof */
1092 1096
1093 return 1; 1097 return 1;
1094} 1098}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines