… | |
… | |
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 | |
|
|
36 | object * |
33 | object * |
37 | get_pet_enemy (object *pet, rv_vector * rv) |
34 | get_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; |
41 | sint16 x, y; |
38 | sint16 x, y; |
42 | mapstruct *nm; |
39 | maptile *nm; |
43 | int search_arr[SIZEOFFREE]; |
40 | int search_arr[SIZEOFFREE]; |
44 | int mflags; |
41 | int mflags; |
45 | |
42 | |
46 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
43 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
47 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
44 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
48 | |
45 | |
49 | if ((owner = get_owner (pet)) != NULL) |
46 | if ((owner = pet->owner) != NULL) |
50 | { |
47 | { |
51 | /* If the owner has turned on the pet, make the pet |
48 | /* If the owner has turned on the pet, make the pet |
52 | * unfriendly. |
49 | * unfriendly. |
53 | */ |
50 | */ |
54 | if ((check_enemy (owner, rv)) == pet) |
51 | if ((check_enemy (owner, rv)) == pet) |
… | |
… | |
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; |
125 | |
124 | |
126 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
125 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
127 | (tmp2->type != PLAYER)) || |
126 | (tmp2->type != PLAYER)) || |
… | |
… | |
189 | nm = pet->map; |
188 | nm = pet->map; |
190 | /* Only look on the space if there is something alive there. */ |
189 | /* Only look on the space if there is something alive there. */ |
191 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
190 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
192 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
191 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
193 | { |
192 | { |
194 | for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) |
193 | for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above) |
195 | { |
194 | { |
196 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
195 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
197 | |
196 | |
198 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
197 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
199 | (tmp2->type != PLAYER)) || |
198 | (tmp2->type != PLAYER)) || |
… | |
… | |
243 | for (obl = first_friendly_object; obl != NULL; obl = next) |
242 | for (obl = first_friendly_object; obl != NULL; obl = next) |
244 | { |
243 | { |
245 | object *ob = obl->ob; |
244 | object *ob = obl->ob; |
246 | |
245 | |
247 | next = obl->next; |
246 | next = obl->next; |
248 | if (get_owner (ob) == owner) |
247 | if (ob->owner == owner) |
249 | { |
248 | { |
250 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
249 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
251 | remove_ob (ob); |
250 | ob->remove (); |
252 | remove_friendly_object (ob); |
251 | remove_friendly_object (ob); |
253 | free_object (ob); |
252 | ob->destroy (); |
254 | } |
253 | } |
255 | } |
254 | } |
256 | } |
255 | } |
257 | |
256 | |
258 | /* |
257 | /* |
… | |
… | |
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 | |
|
|
267 | void |
265 | void |
268 | remove_all_pets (mapstruct *map) |
266 | remove_all_pets (maptile *map) |
269 | { |
267 | { |
270 | objectlink *obl, *next; |
268 | objectlink *obl, *next; |
271 | object *owner; |
269 | object *owner; |
272 | |
270 | |
273 | for (obl = first_friendly_object; obl != NULL; obl = next) |
271 | for (obl = first_friendly_object; obl != NULL; obl = next) |
274 | { |
272 | { |
275 | next = obl->next; |
273 | next = obl->next; |
276 | if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && |
274 | if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && |
277 | (owner = get_owner (obl->ob)) != NULL && !on_same_map (owner, obl->ob)) |
275 | (owner = obl->ob->owner) != NULL && !on_same_map (owner, obl->ob)) |
278 | { |
276 | { |
279 | /* follow owner checks map status for us */ |
277 | /* follow owner checks map status for us */ |
280 | follow_owner (obl->ob, owner); |
278 | follow_owner (obl->ob, owner); |
281 | } |
279 | } |
282 | } |
280 | } |
… | |
… | |
287 | { |
285 | { |
288 | object *tmp; |
286 | object *tmp; |
289 | int dir; |
287 | int dir; |
290 | |
288 | |
291 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
289 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
292 | remove_ob (ob); |
290 | ob->remove (); |
293 | |
291 | |
294 | if (owner->map == NULL) |
292 | if (owner->map == NULL) |
295 | { |
293 | { |
296 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
294 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
297 | goto fail; |
295 | goto fail; |
… | |
… | |
325 | |
323 | |
326 | return 0; |
324 | return 0; |
327 | |
325 | |
328 | fail: |
326 | fail: |
329 | remove_friendly_object (ob); |
327 | remove_friendly_object (ob); |
330 | free_object (ob); |
328 | ob->destroy (); |
331 | |
329 | |
332 | return 1; |
330 | return 1; |
333 | } |
331 | } |
334 | |
332 | |
335 | void |
333 | void |
336 | pet_move (object *ob) |
334 | pet_move (object *ob) |
337 | { |
335 | { |
338 | int dir, i; |
336 | int dir, i; |
339 | sint16 dx, dy; |
337 | sint16 dx, dy; |
340 | object *ob2, *owner; |
338 | object *ob2, *owner; |
341 | mapstruct *m; |
339 | maptile *m; |
342 | |
340 | |
343 | /* Check to see if player pulled out */ |
341 | /* Check to see if player pulled out */ |
344 | if ((owner = get_owner (ob)) == NULL) |
342 | if ((owner = ob->owner) == NULL) |
345 | { |
343 | { |
346 | remove_ob (ob); /* Will be freed when returning */ |
344 | ob->remove (); /* Will be freed when returning */ |
347 | remove_friendly_object (ob); |
345 | remove_friendly_object (ob); |
348 | free_object (ob); |
346 | ob->destroy (); |
349 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
347 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
350 | return; |
348 | return; |
351 | } |
349 | } |
352 | |
350 | |
353 | /* move monster into the owners map if not in the same map */ |
351 | /* move monster into the owners map if not in the same map */ |
… | |
… | |
400 | dy = part->y + freearr_y[dir]; |
398 | dy = part->y + freearr_y[dir]; |
401 | m = get_map_from_coord (part->map, &dx, &dy); |
399 | m = get_map_from_coord (part->map, &dx, &dy); |
402 | if (!m) |
400 | if (!m) |
403 | continue; |
401 | continue; |
404 | |
402 | |
405 | for (ob2 = get_map_ob (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
403 | for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
406 | { |
404 | { |
407 | object *new_ob; |
405 | object *new_ob; |
408 | |
406 | |
409 | new_ob = ob2->head ? ob2->head : ob2; |
407 | new_ob = ob2->head ? ob2->head : ob2; |
410 | if (new_ob == ob) |
408 | if (new_ob == ob) |
411 | break; |
409 | break; |
412 | if (new_ob == ob->owner) |
410 | if (new_ob == ob->owner) |
413 | return; |
411 | return; |
414 | if (get_owner (new_ob) == ob->owner) |
412 | if (new_ob->owner == ob->owner) |
415 | break; |
413 | break; |
416 | |
414 | |
417 | /* Hmm. Did we try to move into an enemy monster? If so, |
415 | /* Hmm. Did we try to move into an enemy monster? If so, |
418 | * make it our enemy. |
416 | * make it our enemy. |
419 | */ |
417 | */ |
… | |
… | |
456 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
454 | fix_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 | set_owner (tmp, 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); |
473 | SET_FLAG (tmp, FLAG_FRIENDLY); |
473 | SET_FLAG (tmp, FLAG_FRIENDLY); |
… | |
… | |
476 | } |
476 | } |
477 | else |
477 | else |
478 | { |
478 | { |
479 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
479 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
480 | { |
480 | { |
481 | object *owner = get_owner (op); |
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 | set_owner (tmp, 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 | |
|
|
537 | void |
542 | void |
538 | move_golem (object *op) |
543 | move_golem (object *op) |
539 | { |
544 | { |
540 | int made_attack = 0; |
545 | int made_attack = 0; |
541 | object *tmp; |
546 | object *tmp; |
542 | |
547 | |
543 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
548 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
544 | return; /* Has already been moved */ |
549 | return; /* Has already been moved */ |
545 | |
550 | |
546 | if (get_owner (op) == NULL) |
551 | if (op->owner == NULL) |
547 | { |
552 | { |
548 | LOG (llevDebug, "Golem without owner destructed.\n"); |
553 | LOG (llevDebug, "Golem without owner destructed.\n"); |
549 | remove_ob (op); |
554 | op->remove (); |
550 | free_object (op); |
555 | op->destroy (); |
551 | return; |
556 | return; |
552 | } |
557 | } |
553 | |
558 | |
554 | /* It would be nice to have a cleaner way of what message to print |
559 | /* It would be nice to have a cleaner way of what message to print |
555 | * when the golem expires than these hard coded entries. |
560 | * when the golem expires than these hard coded entries. |
… | |
… | |
558 | */ |
563 | */ |
559 | if (--op->stats.hp < 0) |
564 | if (--op->stats.hp < 0) |
560 | { |
565 | { |
561 | if (op->msg) |
566 | if (op->msg) |
562 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
567 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
|
|
568 | |
563 | op->owner->contr->ranges[range_golem] = NULL; |
569 | op->owner->contr->ranges[range_golem] = 0; |
564 | op->owner->contr->golem_count = 0; |
|
|
565 | remove_friendly_object (op); |
570 | remove_friendly_object (op); |
566 | remove_ob (op); |
571 | op->remove (); |
567 | free_object (op); |
572 | op->destroy (); |
568 | return; |
573 | return; |
569 | } |
574 | } |
570 | |
575 | |
571 | /* Do golem attacks/movement for single & multisq golems. |
576 | /* Do golem attacks/movement for single & multisq golems. |
572 | * Assuming here that op is the 'head' object. Pass only op to |
577 | * Assuming here that op is the 'head' object. Pass only op to |
… | |
… | |
581 | |
586 | |
582 | for (tmp = op; tmp; tmp = tmp->more) |
587 | for (tmp = op; tmp; tmp = tmp->more) |
583 | { |
588 | { |
584 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
589 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
585 | object *victim; |
590 | object *victim; |
586 | mapstruct *m; |
591 | maptile *m; |
587 | int mflags; |
592 | int mflags; |
588 | |
593 | |
589 | m = op->map; |
594 | m = op->map; |
590 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
595 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
591 | |
596 | |
592 | if (mflags & P_OUT_OF_MAP) |
597 | if (mflags & P_OUT_OF_MAP) |
593 | continue; |
598 | continue; |
594 | |
599 | |
595 | for (victim = get_map_ob (op->map, x, y); victim; victim = victim->above) |
600 | for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) |
596 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
601 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
597 | break; |
602 | break; |
598 | |
603 | |
599 | /* We used to call will_hit_self to make sure we don't |
604 | /* We used to call will_hit_self to make sure we don't |
600 | * hit ourselves, but that didn't work, and I don't really |
605 | * hit ourselves, but that didn't work, and I don't really |
… | |
… | |
656 | char buf[MAX_BUF]; |
661 | char buf[MAX_BUF]; |
657 | |
662 | |
658 | /* Because there can be different golem spells, player may want to |
663 | /* Because there can be different golem spells, player may want to |
659 | * 'lose' their old golem. |
664 | * 'lose' their old golem. |
660 | */ |
665 | */ |
661 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) |
666 | if (op->type == PLAYER && op->contr->ranges[range_golem]) |
662 | { |
667 | { |
663 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
668 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
664 | remove_ob (op->contr->ranges[range_golem]); |
669 | op->contr->ranges[range_golem]->remove (); |
665 | free_object (op->contr->ranges[range_golem]); |
670 | op->contr->ranges[range_golem]->destroy (); |
666 | op->contr->ranges[range_golem] = NULL; |
671 | op->contr->ranges[range_golem] = 0; |
667 | op->contr->golem_count = (uint32) - 1; |
|
|
668 | } |
672 | } |
669 | |
673 | |
670 | if (spob->other_arch) |
674 | if (spob->other_arch) |
671 | at = spob->other_arch; |
675 | at = spob->other_arch; |
672 | else if (spob->race) |
676 | else if (spob->race) |
… | |
… | |
699 | 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])) |
700 | { |
704 | { |
701 | 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."); |
702 | return 0; |
706 | return 0; |
703 | } |
707 | } |
|
|
708 | |
704 | /* basically want to get proper map/coordinates for this object */ |
709 | /* basically want to get proper map/coordinates for this object */ |
705 | |
710 | |
706 | if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) |
711 | if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) |
707 | { |
712 | { |
708 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); |
713 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); |
… | |
… | |
710 | } |
715 | } |
711 | |
716 | |
712 | if (op->type == PLAYER) |
717 | if (op->type == PLAYER) |
713 | { |
718 | { |
714 | tmp->type = GOLEM; |
719 | tmp->type = GOLEM; |
715 | set_owner (tmp, op); |
720 | tmp->set_owner (op); |
716 | set_spell_skill (op, caster, spob, tmp); |
721 | set_spell_skill (op, caster, spob, tmp); |
717 | op->contr->ranges[range_golem] = tmp; |
722 | op->contr->ranges[range_golem] = tmp; |
718 | op->contr->golem_count = tmp->count; |
|
|
719 | /* give the player control of the golem */ |
723 | /* give the player control of the golem */ |
720 | op->contr->shoottype = range_golem; |
724 | op->contr->shoottype = range_golem; |
721 | } |
725 | } |
722 | else |
726 | else |
723 | { |
727 | { |
724 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
728 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
725 | { |
729 | { |
726 | object *owner = get_owner (op); |
730 | object *owner = op->owner; |
727 | |
731 | |
728 | if (owner != NULL) |
732 | if (owner) |
729 | { /* For now, we transfer ownership */ |
733 | { /* For now, we transfer ownership */ |
730 | set_owner (tmp, owner); |
734 | tmp->set_owner (owner); |
731 | tmp->attack_movement = PETMOVE; |
735 | tmp->attack_movement = PETMOVE; |
732 | add_friendly_object (tmp); |
736 | add_friendly_object (tmp); |
733 | SET_FLAG (tmp, FLAG_FRIENDLY); |
737 | SET_FLAG (tmp, FLAG_FRIENDLY); |
734 | } |
738 | } |
735 | } |
739 | } |
… | |
… | |
907 | * with all the checks in the 'for' portion itself. Much |
911 | * with all the checks in the 'for' portion itself. Much |
908 | * more readable to break some of the conditions out. |
912 | * more readable to break some of the conditions out. |
909 | */ |
913 | */ |
910 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
914 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
911 | { |
915 | { |
|
|
916 | if (!tr->item) |
|
|
917 | continue; |
|
|
918 | |
912 | if (level < tr->magic) |
919 | if (level < tr->magic) |
913 | break; |
920 | break; |
914 | |
921 | |
915 | lasttr = tr; |
922 | lasttr = tr; |
916 | |
923 | |
917 | if (tr->item->name == sparam) |
924 | if (tr->item->name == sparam) |
918 | break; |
|
|
919 | |
|
|
920 | if (!tr->next || !tr->next->item) |
|
|
921 | break; |
925 | break; |
922 | } |
926 | } |
923 | |
927 | |
924 | if (!lasttr) |
928 | if (!lasttr) |
925 | { |
929 | { |
… | |
… | |
927 | 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."); |
928 | return 0; |
932 | return 0; |
929 | } |
933 | } |
930 | |
934 | |
931 | summon_arch = lasttr->item; |
935 | summon_arch = lasttr->item; |
932 | nrof = lasttr->nrof; |
936 | nrof = lasttr->nrof; |
933 | } |
937 | } |
934 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
938 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
935 | { |
939 | { |
936 | object *god = find_god (determine_god (op)), *mon, *owner; |
940 | object *god = find_god (determine_god (op)), *mon, *owner; |
937 | int summon_level, tries; |
941 | int summon_level, tries; |
938 | |
942 | |
939 | if (!god && ((owner = get_owner (op)) != NULL)) |
943 | if (!god && ((owner = op->owner) != NULL)) |
940 | god = find_god (determine_god (owner)); |
944 | god = find_god (determine_god (owner)); |
941 | |
945 | |
942 | /* If we can't find a god, can't get what monster to summon */ |
946 | /* If we can't find a god, can't get what monster to summon */ |
943 | if (!god) |
947 | if (!god) |
944 | return 0; |
948 | return 0; |
… | |
… | |
1033 | tmp = arch_to_object (atmp); |
1037 | tmp = arch_to_object (atmp); |
1034 | if (atmp == summon_arch) |
1038 | if (atmp == summon_arch) |
1035 | { |
1039 | { |
1036 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1040 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1037 | { |
1041 | { |
1038 | set_owner (tmp, op); |
1042 | tmp->set_owner (op); |
1039 | set_spell_skill (op, caster, spell_ob, tmp); |
1043 | set_spell_skill (op, caster, spell_ob, tmp); |
1040 | tmp->enemy = op->enemy; |
1044 | tmp->enemy = op->enemy; |
1041 | tmp->type = 0; |
1045 | tmp->type = 0; |
1042 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1046 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1043 | |
1047 | |
… | |
… | |
1051 | tmp->stats.exp = 0; |
1055 | tmp->stats.exp = 0; |
1052 | |
1056 | |
1053 | if (spell_ob->attack_movement) |
1057 | if (spell_ob->attack_movement) |
1054 | tmp->attack_movement = spell_ob->attack_movement; |
1058 | tmp->attack_movement = spell_ob->attack_movement; |
1055 | |
1059 | |
1056 | if (get_owner (op)) |
1060 | if (op->owner) |
1057 | set_owner (tmp, get_owner (op)); |
1061 | tmp->set_owner (op->owner); |
1058 | } |
1062 | } |
1059 | } |
1063 | } |
1060 | } |
1064 | } |
1061 | |
1065 | |
1062 | if (tmp->speed > MIN_ACTIVE_SPEED) |
1066 | if (tmp->speed > MIN_ACTIVE_SPEED) |
… | |
… | |
1081 | head->stats.exp = 0; |
1085 | head->stats.exp = 0; |
1082 | head = insert_ob_in_map (head, head->map, op, 0); |
1086 | head = insert_ob_in_map (head, head->map, op, 0); |
1083 | |
1087 | |
1084 | if (head && head->randomitems) |
1088 | if (head && head->randomitems) |
1085 | { |
1089 | { |
1086 | object *tmp; |
|
|
1087 | |
|
|
1088 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1090 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
|
|
1091 | |
1089 | for (tmp = head->inv; tmp; tmp = tmp->below) |
1092 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1090 | if (!tmp->nrof) |
|
|
1091 | SET_FLAG (tmp, FLAG_NO_DROP); |
1093 | SET_FLAG (tmp, FLAG_NO_DROP); |
1092 | } |
1094 | } |
1093 | } /* for i < nrof */ |
1095 | } /* for i < nrof */ |
1094 | |
1096 | |
1095 | return 1; |
1097 | return 1; |
1096 | } |
1098 | } |
… | |
… | |
1103 | object *realowner = ob; |
1105 | object *realowner = ob; |
1104 | |
1106 | |
1105 | if (realowner == NULL) |
1107 | if (realowner == NULL) |
1106 | return NULL; |
1108 | return NULL; |
1107 | |
1109 | |
1108 | while (get_owner (realowner) != NULL) |
1110 | while (realowner->owner != NULL) |
1109 | { |
1111 | { |
1110 | realowner = get_owner (realowner); |
1112 | realowner = realowner->owner; |
1111 | } |
1113 | } |
1112 | return realowner; |
1114 | return realowner; |
1113 | } |
1115 | } |
1114 | |
1116 | |
1115 | /* determines if checks so pets don't attack players or other pets should be |
1117 | /* determines if checks so pets don't attack players or other pets should be |