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 | |
|
|
36 | object * |
34 | object * |
37 | get_pet_enemy (object *pet, rv_vector * rv) |
35 | get_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 | |
|
|
267 | void |
266 | void |
268 | remove_all_pets (mapstruct *map) |
267 | remove_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 | |
328 | fail: |
327 | fail: |
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 | |
335 | void |
334 | void |
336 | pet_move (object *ob) |
335 | pet_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 | */ |
… | |
… | |
457 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
455 | fix_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); |
474 | SET_FLAG (tmp, FLAG_FRIENDLY); |
… | |
… | |
477 | } |
477 | } |
478 | else |
478 | else |
479 | { |
479 | { |
480 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
480 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
481 | { |
481 | { |
482 | object *owner = get_owner (op); |
482 | object *owner = op->owner; |
483 | |
483 | |
484 | if (owner != NULL) |
484 | if (owner) |
485 | { /* For now, we transfer ownership */ |
485 | { /* For now, we transfer ownership */ |
486 | set_owner (tmp, owner); |
486 | tmp->set_owner (owner); |
487 | tmp->attack_movement = PETMOVE; |
487 | tmp->attack_movement = PETMOVE; |
488 | add_friendly_object (tmp); |
488 | add_friendly_object (tmp); |
489 | SET_FLAG (tmp, FLAG_FRIENDLY); |
489 | SET_FLAG (tmp, FLAG_FRIENDLY); |
490 | } |
490 | } |
491 | } |
491 | } |
492 | } |
492 | } |
|
|
493 | |
493 | if (op->type != PLAYER || !is_golem) |
494 | if (op->type != PLAYER || !is_golem) |
494 | { |
495 | { |
495 | tmp->attack_movement = PETMOVE; |
496 | tmp->attack_movement = PETMOVE; |
496 | tmp->speed_left = -1; |
497 | tmp->speed_left = -1; |
497 | tmp->type = 0; |
498 | tmp->type = 0; |
… | |
… | |
499 | } |
500 | } |
500 | else |
501 | else |
501 | tmp->type = GOLEM; |
502 | tmp->type = GOLEM; |
502 | |
503 | |
503 | } |
504 | } |
|
|
505 | |
504 | if (head == NULL) |
506 | if (!head) |
505 | head = tmp; |
507 | head = tmp; |
|
|
508 | |
506 | tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; |
509 | tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; |
507 | tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; |
510 | tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; |
508 | tmp->map = op->map; |
511 | tmp->map = op->map; |
|
|
512 | |
509 | if (tmp->invisible) |
513 | if (tmp->invisible) |
510 | tmp->invisible = 0; |
514 | tmp->invisible = 0; |
|
|
515 | |
511 | if (head != tmp) |
516 | if (head != tmp) |
512 | tmp->head = head, prev->more = tmp; |
517 | tmp->head = head, prev->more = tmp; |
|
|
518 | |
513 | prev = tmp; |
519 | prev = tmp; |
514 | } |
520 | } |
|
|
521 | |
515 | head->direction = dir; |
522 | head->direction = dir; |
516 | |
523 | |
517 | /* need to change some monster attr to prevent problems/crashing */ |
524 | /* need to change some monster attr to prevent problems/crashing */ |
518 | head->last_heal = 0; |
525 | head->last_heal = 0; |
519 | head->last_eat = 0; |
526 | head->last_eat = 0; |
… | |
… | |
530 | |
537 | |
531 | return head; |
538 | return head; |
532 | } |
539 | } |
533 | |
540 | |
534 | /* updated this to allow more than the golem 'head' to attack */ |
541 | /* updated this to allow more than the golem 'head' to attack */ |
535 | |
|
|
536 | /* op is the golem to be moved. */ |
542 | /* op is the golem to be moved. */ |
537 | |
|
|
538 | void |
543 | void |
539 | move_golem (object *op) |
544 | move_golem (object *op) |
540 | { |
545 | { |
541 | int made_attack = 0; |
546 | int made_attack = 0; |
542 | object *tmp; |
547 | object *tmp; |
543 | tag_t tag; |
|
|
544 | |
548 | |
545 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
549 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
546 | return; /* Has already been moved */ |
550 | return; /* Has already been moved */ |
547 | |
551 | |
548 | if (get_owner (op) == NULL) |
552 | if (op->owner == NULL) |
549 | { |
553 | { |
550 | LOG (llevDebug, "Golem without owner destructed.\n"); |
554 | LOG (llevDebug, "Golem without owner destructed.\n"); |
551 | remove_ob (op); |
555 | op->remove (); |
552 | free_object (op); |
556 | op->destroy (); |
553 | return; |
557 | return; |
554 | } |
558 | } |
|
|
559 | |
555 | /* It would be nice to have a cleaner way of what message to print |
560 | /* It would be nice to have a cleaner way of what message to print |
556 | * when the golem expires than these hard coded entries. |
561 | * when the golem expires than these hard coded entries. |
557 | * Note it is intentional that a golems duration is based on its |
562 | * Note it is intentional that a golems duration is based on its |
558 | * hp, and not duration |
563 | * hp, and not duration |
559 | */ |
564 | */ |
560 | if (--op->stats.hp < 0) |
565 | if (--op->stats.hp < 0) |
561 | { |
566 | { |
562 | if (op->msg) |
567 | if (op->msg) |
563 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
568 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
|
|
569 | |
564 | op->owner->contr->ranges[range_golem] = NULL; |
570 | op->owner->contr->ranges[range_golem] = 0; |
565 | op->owner->contr->golem_count = 0; |
|
|
566 | remove_friendly_object (op); |
571 | remove_friendly_object (op); |
567 | remove_ob (op); |
572 | op->remove (); |
568 | free_object (op); |
573 | op->destroy (); |
569 | return; |
574 | return; |
570 | } |
575 | } |
571 | |
576 | |
572 | /* Do golem attacks/movement for single & multisq golems. |
577 | /* Do golem attacks/movement for single & multisq golems. |
573 | * Assuming here that op is the 'head' object. Pass only op to |
578 | * Assuming here that op is the 'head' object. Pass only op to |
574 | * move_ob (makes recursive calls to other parts) |
579 | * move_ob (makes recursive calls to other parts) |
575 | * move_ob returns 0 if the creature was not able to move. |
580 | * move_ob returns 0 if the creature was not able to move. |
576 | */ |
581 | */ |
577 | tag = op->count; |
|
|
578 | if (move_ob (op, op->direction, op)) |
582 | if (move_ob (op, op->direction, op)) |
579 | return; |
583 | return; |
580 | if (was_destroyed (op, tag)) |
584 | |
|
|
585 | if (op->destroyed ()) |
581 | return; |
586 | return; |
582 | |
587 | |
583 | for (tmp = op; tmp; tmp = tmp->more) |
588 | for (tmp = op; tmp; tmp = tmp->more) |
584 | { |
589 | { |
585 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
590 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
586 | object *victim; |
591 | object *victim; |
587 | mapstruct *m; |
592 | maptile *m; |
588 | int mflags; |
593 | int mflags; |
589 | |
594 | |
590 | m = op->map; |
595 | m = op->map; |
591 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
596 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
592 | |
597 | |
593 | if (mflags & P_OUT_OF_MAP) |
598 | if (mflags & P_OUT_OF_MAP) |
594 | continue; |
599 | continue; |
595 | |
600 | |
596 | for (victim = get_map_ob (op->map, x, y); victim; victim = victim->above) |
601 | for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) |
597 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
602 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
598 | break; |
603 | break; |
599 | |
604 | |
600 | /* We used to call will_hit_self to make sure we don't |
605 | /* 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 |
606 | * hit ourselves, but that didn't work, and I don't really |
… | |
… | |
657 | char buf[MAX_BUF]; |
662 | char buf[MAX_BUF]; |
658 | |
663 | |
659 | /* Because there can be different golem spells, player may want to |
664 | /* Because there can be different golem spells, player may want to |
660 | * 'lose' their old golem. |
665 | * 'lose' their old golem. |
661 | */ |
666 | */ |
662 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) |
667 | if (op->type == PLAYER && op->contr->ranges[range_golem]) |
663 | { |
668 | { |
664 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
669 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
665 | remove_ob (op->contr->ranges[range_golem]); |
670 | op->contr->ranges[range_golem]->remove (); |
666 | free_object (op->contr->ranges[range_golem]); |
671 | op->contr->ranges[range_golem]->destroy (); |
667 | op->contr->ranges[range_golem] = NULL; |
672 | op->contr->ranges[range_golem] = 0; |
668 | op->contr->golem_count = (uint32) - 1; |
|
|
669 | } |
673 | } |
670 | |
674 | |
671 | if (spob->other_arch) |
675 | if (spob->other_arch) |
672 | at = spob->other_arch; |
676 | at = spob->other_arch; |
673 | else if (spob->race) |
677 | else if (spob->race) |
… | |
… | |
700 | if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
704 | if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
701 | { |
705 | { |
702 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
706 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
703 | return 0; |
707 | return 0; |
704 | } |
708 | } |
|
|
709 | |
705 | /* basically want to get proper map/coordinates for this object */ |
710 | /* basically want to get proper map/coordinates for this object */ |
706 | |
711 | |
707 | if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) |
712 | if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) |
708 | { |
713 | { |
709 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); |
714 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); |
… | |
… | |
711 | } |
716 | } |
712 | |
717 | |
713 | if (op->type == PLAYER) |
718 | if (op->type == PLAYER) |
714 | { |
719 | { |
715 | tmp->type = GOLEM; |
720 | tmp->type = GOLEM; |
716 | set_owner (tmp, op); |
721 | tmp->set_owner (op); |
717 | set_spell_skill (op, caster, spob, tmp); |
722 | set_spell_skill (op, caster, spob, tmp); |
718 | op->contr->ranges[range_golem] = tmp; |
723 | op->contr->ranges[range_golem] = tmp; |
719 | op->contr->golem_count = tmp->count; |
|
|
720 | /* give the player control of the golem */ |
724 | /* give the player control of the golem */ |
721 | op->contr->shoottype = range_golem; |
725 | op->contr->shoottype = range_golem; |
722 | } |
726 | } |
723 | else |
727 | else |
724 | { |
728 | { |
725 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
729 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
726 | { |
730 | { |
727 | object *owner = get_owner (op); |
731 | object *owner = op->owner; |
728 | |
732 | |
729 | if (owner != NULL) |
733 | if (owner) |
730 | { /* For now, we transfer ownership */ |
734 | { /* For now, we transfer ownership */ |
731 | set_owner (tmp, owner); |
735 | tmp->set_owner (owner); |
732 | tmp->attack_movement = PETMOVE; |
736 | tmp->attack_movement = PETMOVE; |
733 | add_friendly_object (tmp); |
737 | add_friendly_object (tmp); |
734 | SET_FLAG (tmp, FLAG_FRIENDLY); |
738 | SET_FLAG (tmp, FLAG_FRIENDLY); |
735 | } |
739 | } |
736 | } |
740 | } |
… | |
… | |
908 | * with all the checks in the 'for' portion itself. Much |
912 | * with all the checks in the 'for' portion itself. Much |
909 | * more readable to break some of the conditions out. |
913 | * more readable to break some of the conditions out. |
910 | */ |
914 | */ |
911 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
915 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
912 | { |
916 | { |
|
|
917 | if (!tr->item) |
|
|
918 | continue; |
|
|
919 | |
913 | if (level < tr->magic) |
920 | if (level < tr->magic) |
914 | break; |
921 | break; |
915 | |
922 | |
916 | lasttr = tr; |
923 | lasttr = tr; |
917 | |
924 | |
918 | if (tr->item->name == sparam) |
925 | if (tr->item->name == sparam) |
919 | break; |
|
|
920 | |
|
|
921 | if (!tr->next || !tr->next->item) |
|
|
922 | break; |
926 | break; |
923 | } |
927 | } |
924 | |
928 | |
925 | if (!lasttr) |
929 | if (!lasttr) |
926 | { |
930 | { |
… | |
… | |
928 | new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); |
932 | new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); |
929 | return 0; |
933 | return 0; |
930 | } |
934 | } |
931 | |
935 | |
932 | summon_arch = lasttr->item; |
936 | summon_arch = lasttr->item; |
933 | nrof = lasttr->nrof; |
937 | nrof = lasttr->nrof; |
934 | } |
938 | } |
935 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
939 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
936 | { |
940 | { |
937 | object *god = find_god (determine_god (op)), *mon, *owner; |
941 | object *god = find_god (determine_god (op)), *mon, *owner; |
938 | int summon_level, tries; |
942 | int summon_level, tries; |
939 | |
943 | |
940 | if (!god && ((owner = get_owner (op)) != NULL)) |
944 | if (!god && ((owner = op->owner) != NULL)) |
941 | god = find_god (determine_god (owner)); |
945 | god = find_god (determine_god (owner)); |
942 | |
946 | |
943 | /* If we can't find a god, can't get what monster to summon */ |
947 | /* If we can't find a god, can't get what monster to summon */ |
944 | if (!god) |
948 | if (!god) |
945 | return 0; |
949 | return 0; |
… | |
… | |
1034 | tmp = arch_to_object (atmp); |
1038 | tmp = arch_to_object (atmp); |
1035 | if (atmp == summon_arch) |
1039 | if (atmp == summon_arch) |
1036 | { |
1040 | { |
1037 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1041 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1038 | { |
1042 | { |
1039 | set_owner (tmp, op); |
1043 | tmp->set_owner (op); |
1040 | set_spell_skill (op, caster, spell_ob, tmp); |
1044 | set_spell_skill (op, caster, spell_ob, tmp); |
1041 | tmp->enemy = op->enemy; |
1045 | tmp->enemy = op->enemy; |
1042 | tmp->type = 0; |
1046 | tmp->type = 0; |
1043 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1047 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1044 | |
1048 | |
… | |
… | |
1052 | tmp->stats.exp = 0; |
1056 | tmp->stats.exp = 0; |
1053 | |
1057 | |
1054 | if (spell_ob->attack_movement) |
1058 | if (spell_ob->attack_movement) |
1055 | tmp->attack_movement = spell_ob->attack_movement; |
1059 | tmp->attack_movement = spell_ob->attack_movement; |
1056 | |
1060 | |
1057 | if (get_owner (op)) |
1061 | if (op->owner) |
1058 | set_owner (tmp, get_owner (op)); |
1062 | tmp->set_owner (op->owner); |
1059 | } |
1063 | } |
1060 | } |
1064 | } |
1061 | } |
1065 | } |
1062 | |
1066 | |
1063 | if (tmp->speed > MIN_ACTIVE_SPEED) |
1067 | if (tmp->speed > MIN_ACTIVE_SPEED) |
… | |
… | |
1082 | head->stats.exp = 0; |
1086 | head->stats.exp = 0; |
1083 | head = insert_ob_in_map (head, head->map, op, 0); |
1087 | head = insert_ob_in_map (head, head->map, op, 0); |
1084 | |
1088 | |
1085 | if (head && head->randomitems) |
1089 | if (head && head->randomitems) |
1086 | { |
1090 | { |
1087 | object *tmp; |
|
|
1088 | |
|
|
1089 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1091 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
|
|
1092 | |
1090 | for (tmp = head->inv; tmp; tmp = tmp->below) |
1093 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1091 | if (!tmp->nrof) |
|
|
1092 | SET_FLAG (tmp, FLAG_NO_DROP); |
1094 | SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); |
1093 | } |
1095 | } |
1094 | } /* for i < nrof */ |
1096 | } /* for i < nrof */ |
1095 | |
1097 | |
1096 | return 1; |
1098 | return 1; |
1097 | } |
1099 | } |
… | |
… | |
1104 | object *realowner = ob; |
1106 | object *realowner = ob; |
1105 | |
1107 | |
1106 | if (realowner == NULL) |
1108 | if (realowner == NULL) |
1107 | return NULL; |
1109 | return NULL; |
1108 | |
1110 | |
1109 | while (get_owner (realowner) != NULL) |
1111 | while (realowner->owner != NULL) |
1110 | { |
1112 | { |
1111 | realowner = get_owner (realowner); |
1113 | realowner = realowner->owner; |
1112 | } |
1114 | } |
1113 | return realowner; |
1115 | return realowner; |
1114 | } |
1116 | } |
1115 | |
1117 | |
1116 | /* determines if checks so pets don't attack players or other pets should be |
1118 | /* determines if checks so pets don't attack players or other pets should be |