1 | /* |
1 | /* |
2 | * static char *rcsid_monster_c = |
2 | * static char *rcsid_monster_c = |
3 | * "$Id: monster.c,v 1.3 2006/03/10 14:08:38 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 | */ |
… | |
… | |
1247 | |
1250 | |
1248 | if (item->type == TREASURE && mon->will_apply & WILL_APPLY_TREASURE) flag=1; |
1251 | if (item->type == TREASURE && mon->will_apply & WILL_APPLY_TREASURE) flag=1; |
1249 | /* Eating food gets hp back */ |
1252 | /* Eating food gets hp back */ |
1250 | else if (item->type == FOOD && mon->will_apply & WILL_APPLY_FOOD) flag=1; |
1253 | else if (item->type == FOOD && mon->will_apply & WILL_APPLY_FOOD) flag=1; |
1251 | else if (item->type == SCROLL && QUERY_FLAG(mon, FLAG_USE_SCROLL)) { |
1254 | else if (item->type == SCROLL && QUERY_FLAG(mon, FLAG_USE_SCROLL)) { |
|
|
1255 | if (!item->inv) |
|
|
1256 | LOG(llevDebug,"Monster %d having scroll %d with empty inventory!", mon->count, item->count); |
1252 | if (item->inv && monster_should_cast_spell(mon, item->inv)) |
1257 | else if (monster_should_cast_spell(mon, item->inv)) |
1253 | SET_FLAG(mon, FLAG_READY_SCROLL); |
1258 | SET_FLAG(mon, FLAG_READY_SCROLL); |
1254 | /* Don't use it right now */ |
1259 | /* Don't use it right now */ |
1255 | return; |
1260 | return; |
1256 | } |
1261 | } |
1257 | else if (item->type == WEAPON) flag = check_good_weapon(mon,item); |
1262 | else if (item->type == WEAPON) flag = check_good_weapon(mon,item); |
1258 | else if (IS_ARMOR(item)) flag = check_good_armour(mon,item); |
1263 | else if (IS_ARMOR(item)) flag = check_good_armour(mon,item); |
1259 | /* Should do something more, like make sure this is a better item */ |
1264 | /* Should do something more, like make sure this is a better item */ |
1260 | else if (item->type == RING) |
1265 | else if (item->type == RING) |
… | |
… | |
1652 | return 0; |
1657 | return 0; |
1653 | /* Lauwenmark - Here we let the objects inside inventories hear and answer, too. */ |
1658 | /* Lauwenmark - Here we let the objects inside inventories hear and answer, too. */ |
1654 | /* This allows the existence of "intelligent" weapons you can discuss with */ |
1659 | /* This allows the existence of "intelligent" weapons you can discuss with */ |
1655 | for(cobj=npc->inv;cobj!=NULL; cobj = cobj->below) |
1660 | for(cobj=npc->inv;cobj!=NULL; cobj = cobj->below) |
1656 | { |
1661 | { |
1657 | if (execute_event(cobj, EVENT_SAY,npc,NULL,txt,SCRIPT_FIX_ALL)!=0) |
1662 | if (execute_event(cobj, EVENT_SAY,op,NULL,txt,SCRIPT_FIX_ALL)!=0) |
1658 | return 0; |
1663 | return 0; |
1659 | } |
1664 | } |
1660 | for ( cobj = npc->inv; cobj; cobj = cobj->below ) |
1665 | for ( cobj = npc->inv; cobj; cobj = cobj->below ) |
1661 | if ( quest_is_override_compatible( cobj, op ) ) |
1666 | if ( quest_is_override_compatible( cobj, op ) ) |
1662 | if ( do_talk_npc( op, npc, cobj, txt ) ) |
1667 | if ( do_talk_npc( op, npc, cobj, txt ) ) |