… | |
… | |
35 | * set to sane values. |
35 | * set to sane values. |
36 | */ |
36 | */ |
37 | object * |
37 | object * |
38 | check_enemy (object *npc, rv_vector * rv) |
38 | check_enemy (object *npc, rv_vector * rv) |
39 | { |
39 | { |
40 | |
|
|
41 | /* if this is pet, let him attack the same enemy as his owner |
40 | /* if this is pet, let him attack the same enemy as his owner |
42 | * TODO: when there is no ower enemy, try to find a target, |
41 | * TODO: when there is no ower enemy, try to find a target, |
43 | * which CAN attack the owner. */ |
42 | * which CAN attack the owner. */ |
44 | if ((npc->attack_movement & HI4) == PETMOVE) |
43 | if ((npc->attack_movement & HI4) == PETMOVE) |
45 | { |
44 | { |
… | |
… | |
324 | op->last_heal += (int) ((float) (8 * op->stats.Con) / FABS (op->speed)); |
323 | op->last_heal += (int) ((float) (8 * op->stats.Con) / FABS (op->speed)); |
325 | op->stats.hp = MIN ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */ |
324 | op->stats.hp = MIN ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */ |
326 | op->last_heal %= 32; |
325 | op->last_heal %= 32; |
327 | |
326 | |
328 | /* So if the monster has gained enough HP that they are no longer afraid */ |
327 | /* So if the monster has gained enough HP that they are no longer afraid */ |
329 | if (QUERY_FLAG (op, FLAG_RUN_AWAY) && op->stats.hp >= (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp)) |
328 | if (QUERY_FLAG (op, FLAG_RUN_AWAY) && op->stats.hp >= (signed short)(((float)op->run_away / 100.f) * (float)op->stats.maxhp)) |
330 | CLEAR_FLAG (op, FLAG_RUN_AWAY); |
329 | CLEAR_FLAG (op, FLAG_RUN_AWAY); |
331 | |
330 | |
332 | if (op->stats.hp > op->stats.maxhp) |
331 | if (op->stats.hp > op->stats.maxhp) |
333 | op->stats.hp = op->stats.maxhp; |
332 | op->stats.hp = op->stats.maxhp; |
334 | } |
333 | } |
335 | |
334 | |
336 | /* generate sp, if applicable */ |
335 | /* generate sp, if applicable */ |
337 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
336 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
338 | { |
337 | { |
339 | /* last_sp is in funny units. Dividing by speed puts |
338 | /* last_sp is in funny units. Dividing by speed puts |
340 | * the regeneration rate on a basis of time instead of |
339 | * the regeneration rate on a basis of time instead of |
341 | * #moves the monster makes. The scaling by 8 is |
340 | * #moves the monster makes. The scaling by 8 is |
342 | * to capture 8th's of a sp fraction regens |
341 | * to capture 8th's of a sp fraction regens |
343 | * |
342 | * |
344 | * Cast to sint32 before comparing to maxhp since otherwise an (sint16) |
343 | * Cast to sint32 before comparing to maxhp since otherwise an (sint16) |
345 | * overflow might produce monsters with negative sp. |
344 | * overflow might produce monsters with negative sp. |
346 | */ |
345 | */ |
347 | |
346 | |
348 | op->last_sp += (int) ((float) (8 * op->stats.Pow) / FABS (op->speed)); |
347 | op->last_sp += (int) ((float) (8 * op->stats.Pow) / fabsf (op->speed)); |
349 | op->stats.sp = MIN (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */ |
348 | op->stats.sp = min (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */ |
350 | op->last_sp %= 128; |
349 | op->last_sp %= 128; |
351 | } |
350 | } |
352 | |
351 | |
353 | /* this should probably get modified by many more values. |
352 | /* this should probably get modified by many more values. |
354 | * (eg, creatures resistance to fear, level, etc. ) |
353 | * (eg, creatures resistance to fear, level, etc. ) |
… | |
… | |
505 | if (monster_use_bow (op, part, enemy, dir)) |
504 | if (monster_use_bow (op, part, enemy, dir)) |
506 | return 0; |
505 | return 0; |
507 | } /* for processing of all parts */ |
506 | } /* for processing of all parts */ |
508 | } /* If not scared */ |
507 | } /* If not scared */ |
509 | |
508 | |
510 | |
|
|
511 | part = rv.part; |
509 | part = rv.part; |
512 | dir = rv.direction; |
510 | dir = rv.direction; |
|
|
511 | |
|
|
512 | #if DEVEL |
|
|
513 | int sdir = 0; |
|
|
514 | |
|
|
515 | for (int dir = 1; dir <= 8; ++dir) |
|
|
516 | { |
|
|
517 | mapxy pos (op); pos.move (dir); |
|
|
518 | if (pos.normalise ()) |
|
|
519 | { |
|
|
520 | mapspace &ms = pos.ms (); |
|
|
521 | |
|
|
522 | if (ms.smell > op->ms ().smell) |
|
|
523 | { |
|
|
524 | printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D |
|
|
525 | op->ms ().smell = ms.smell - 1; |
|
|
526 | sdir = dir; |
|
|
527 | |
|
|
528 | // perturbing the path might let the monster lose track, |
|
|
529 | // but it will also wide the actual path, spreading information |
|
|
530 | if (!rndm (20)) |
|
|
531 | sdir += absdir (1 - rndm (2) * 2); |
|
|
532 | } |
|
|
533 | } |
|
|
534 | } |
|
|
535 | |
|
|
536 | if (sdir) |
|
|
537 | dir = sdir; |
|
|
538 | else |
|
|
539 | // no better smell found, so assume the player jumped, and erase this smell |
|
|
540 | {if (op->ms ().smell) printf ("erasing smell %d\n", op->ms ().smell);//D |
|
|
541 | ordered_mapwalk_begin (op, -1, -1, 1, 1) |
|
|
542 | if (m) |
|
|
543 | m->at (nx, ny).smell = 0; |
|
|
544 | ordered_mapwalk_end |
|
|
545 | }//D |
|
|
546 | |
|
|
547 | #endif |
513 | |
548 | |
514 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
549 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
515 | dir = absdir (dir + 4); |
550 | dir = absdir (dir + 4); |
516 | |
551 | |
517 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
552 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |