1 | /* |
1 | /* |
2 | * static char *rcsid_monster_c = |
2 | * static char *rcsid_monster_c = |
3 | * "$Id: monster.c,v 1.5 2006/03/31 22:04:03 root Exp $"; |
3 | * "$Id: monster.c,v 1.7 2006/07/03 12:31:24 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
291 | /* |
291 | /* |
292 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
292 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
293 | */ |
293 | */ |
294 | |
294 | |
295 | int move_monster(object *op) { |
295 | int move_monster(object *op) { |
296 | int dir, diff; |
296 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
297 | object *owner, *enemy, *part, *oph=op; |
297 | object *owner, *enemy, *part, *oph=op; |
298 | rv_vector rv; |
298 | rv_vector rv; |
299 | |
299 | |
300 | /* Monsters not on maps don't do anything. These monsters are things |
300 | /* Monsters not on maps don't do anything. These monsters are things |
301 | * Like royal guards in city dwellers inventories. |
301 | * Like royal guards in city dwellers inventories. |
… | |
… | |
444 | return 0; |
444 | return 0; |
445 | } /* no enemy */ |
445 | } /* no enemy */ |
446 | |
446 | |
447 | /* We have an enemy. Block immediately below is for pets */ |
447 | /* We have an enemy. Block immediately below is for pets */ |
448 | if((op->attack_movement&HI4) == PETMOVE && (owner = get_owner(op)) != NULL && !on_same_map(op,owner)) |
448 | if((op->attack_movement&HI4) == PETMOVE && (owner = get_owner(op)) != NULL && !on_same_map(op,owner)) |
449 | { |
|
|
450 | follow_owner(op, owner); |
449 | return follow_owner(op, owner); |
451 | /* If the pet was unable to follow the owner, free it */ |
|
|
452 | if(QUERY_FLAG(op, FLAG_REMOVED) && FABS(op->speed) > MIN_ACTIVE_SPEED) { |
|
|
453 | remove_friendly_object(op); |
|
|
454 | free_object(op); |
|
|
455 | return 1; |
|
|
456 | } |
|
|
457 | return 0; |
|
|
458 | } |
|
|
459 | |
450 | |
460 | /* doppleganger code to change monster facing to that of the nearest |
451 | /* doppleganger code to change monster facing to that of the nearest |
461 | * player. Hmm. The code is here, but no monster in the current |
452 | * player. Hmm. The code is here, but no monster in the current |
462 | * arch set uses it. |
453 | * arch set uses it. |
463 | */ |
454 | */ |
… | |
… | |
530 | dir=absdir(dir+4); |
521 | dir=absdir(dir+4); |
531 | |
522 | |
532 | if(QUERY_FLAG(op,FLAG_CONFUSED)) |
523 | if(QUERY_FLAG(op,FLAG_CONFUSED)) |
533 | dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2); |
524 | dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2); |
534 | |
525 | |
|
|
526 | pre_att_dir = dir; /* remember the original direction */ |
|
|
527 | |
535 | if ((op->attack_movement & LO4) && !QUERY_FLAG(op, FLAG_SCARED)) |
528 | if ((op->attack_movement & LO4) && !QUERY_FLAG(op, FLAG_SCARED)) |
536 | { |
529 | { |
537 | switch (op->attack_movement & LO4) { |
530 | switch (op->attack_movement & LO4) { |
538 | case DISTATT: |
531 | case DISTATT: |
539 | dir = dist_att (dir,op,enemy,part,&rv); |
532 | dir = dist_att (dir,op,enemy,part,&rv); |
… | |
… | |
571 | if (!dir) |
564 | if (!dir) |
572 | return 0; |
565 | return 0; |
573 | |
566 | |
574 | if (!QUERY_FLAG(op,FLAG_STAND_STILL)) { |
567 | if (!QUERY_FLAG(op,FLAG_STAND_STILL)) { |
575 | if(move_object(op,dir)) /* Can the monster move directly toward player? */ |
568 | if(move_object(op,dir)) /* Can the monster move directly toward player? */ |
|
|
569 | { |
|
|
570 | /* elmex: Turn our monster after it moved if it has DISTATT attack */ |
|
|
571 | if ((op->attack_movement & LO4) == DISTATT) |
|
|
572 | op->direction = pre_att_dir; |
|
|
573 | |
576 | return 0; |
574 | return 0; |
|
|
575 | } |
577 | |
576 | |
578 | if(QUERY_FLAG(op, FLAG_SCARED) || !can_hit(part,enemy,&rv) |
577 | if(QUERY_FLAG(op, FLAG_SCARED) || !can_hit(part,enemy,&rv) |
579 | || QUERY_FLAG(op,FLAG_RUN_AWAY)) { |
578 | || QUERY_FLAG(op,FLAG_RUN_AWAY)) { |
580 | |
579 | |
581 | /* Try move around corners if !close */ |
580 | /* Try move around corners if !close */ |
… | |
… | |
587 | move_object(op,absdir(dir - diff*m))) |
586 | move_object(op,absdir(dir - diff*m))) |
588 | return 0; |
587 | return 0; |
589 | } |
588 | } |
590 | } |
589 | } |
591 | } /* if monster is not standing still */ |
590 | } /* if monster is not standing still */ |
|
|
591 | |
|
|
592 | /* elmex: Turn our monster after it moved if it has DISTATT attack */ |
|
|
593 | if ((op->attack_movement & LO4) == DISTATT) |
|
|
594 | op->direction = pre_att_dir; |
592 | |
595 | |
593 | /* |
596 | /* |
594 | * Eneq(@csd.uu.se): Patch to make RUN_AWAY or SCARED monsters move a random |
597 | * Eneq(@csd.uu.se): Patch to make RUN_AWAY or SCARED monsters move a random |
595 | * direction if they can't move away. |
598 | * direction if they can't move away. |
596 | */ |
599 | */ |