1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | |
7 | * |
8 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | 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 |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
21 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
|
|
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <sproto.h> |
25 | #include <sproto.h> |
27 | #include <spells.h> |
26 | #include <spells.h> |
28 | #include <skills.h> |
27 | #include <skills.h> |
… | |
… | |
85 | * target enemy - this code below makes sure the enemy is something |
84 | * target enemy - this code below makes sure the enemy is something |
86 | * that should be attacked. My guess is that the arrow hits |
85 | * that should be attacked. My guess is that the arrow hits |
87 | * the creature/owner, and so the creature then takes that |
86 | * the creature/owner, and so the creature then takes that |
88 | * as the enemy to attack. |
87 | * as the enemy to attack. |
89 | */ |
88 | */ |
90 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) && |
89 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
91 | !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) && npc->enemy->type != PLAYER && npc->enemy->type != GOLEM) |
90 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
|
|
91 | && npc->enemy->type != PLAYER |
|
|
92 | && npc->enemy->type != GOLEM) |
92 | npc->enemy = NULL; |
93 | npc->enemy = NULL; |
93 | |
94 | |
94 | } |
95 | } |
|
|
96 | |
95 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
96 | } |
98 | } |
97 | |
99 | |
98 | /* Returns the nearest living creature (monster or generator). |
100 | /* Returns the nearest living creature (monster or generator). |
99 | * Modified to deal with tiled maps properly. |
101 | * Modified to deal with tiled maps properly. |
… | |
… | |
143 | } |
145 | } |
144 | |
146 | |
145 | return 0; |
147 | return 0; |
146 | } |
148 | } |
147 | |
149 | |
148 | |
|
|
149 | /* Tries to find an enmy for npc. We pass the range vector since |
150 | /* Tries to find an enemy for npc. We pass the range vector since |
150 | * our caller will find the information useful. |
151 | * our caller will find the information useful. |
151 | * Currently, only move_monster calls this function. |
152 | * Currently, only move_monster calls this function. |
152 | * Fix function so that we always make calls to get_rangevector |
153 | * Fix function so that we always make calls to get_rangevector |
153 | * if we have a valid target - function as not doing so in |
154 | * if we have a valid target - function as not doing so in |
154 | * many cases. |
155 | * many cases. |
155 | */ |
156 | */ |
156 | |
|
|
157 | object * |
157 | object * |
158 | find_enemy (object *npc, rv_vector * rv) |
158 | find_enemy (object *npc, rv_vector * rv) |
159 | { |
159 | { |
160 | object *attacker, *tmp = NULL; |
160 | object *attacker, *tmp = NULL; |
161 | |
161 | |
… | |
… | |
167 | { |
167 | { |
168 | tmp = find_nearest_living_creature (npc); |
168 | tmp = find_nearest_living_creature (npc); |
169 | |
169 | |
170 | if (tmp) |
170 | if (tmp) |
171 | get_rangevector (npc, tmp, rv, 0); |
171 | get_rangevector (npc, tmp, rv, 0); |
|
|
172 | |
172 | return tmp; |
173 | return tmp; |
173 | } |
174 | } |
174 | |
175 | |
175 | /* Here is the main enemy selection. |
176 | /* Here is the main enemy selection. |
176 | * We want this: if there is an enemy, attack him until its not possible or |
177 | * We want this: if there is an enemy, attack him until its not possible or |
… | |
… | |
196 | /* we check our old enemy. */ |
197 | /* we check our old enemy. */ |
197 | if (!(tmp = check_enemy (npc, rv))) |
198 | if (!(tmp = check_enemy (npc, rv))) |
198 | { |
199 | { |
199 | if (attacker) /* if we have an attacker, check him */ |
200 | if (attacker) /* if we have an attacker, check him */ |
200 | { |
201 | { |
201 | /* TODO: thats not finished */ |
202 | /* TODO: that's not finished */ |
202 | /* we don't want a fight evil vs evil or good against non evil */ |
203 | /* we don't want a fight evil vs evil or good against non evil */ |
203 | |
204 | |
204 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
205 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
205 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
206 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
206 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
207 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
207 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
208 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
208 | else if (on_same_map (npc, attacker)) /* thats the only thing we must know... */ |
209 | else if (on_same_map (npc, attacker)) /* that's the only thing we must know... */ |
209 | { |
210 | { |
210 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
211 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
211 | npc->enemy = attacker; |
212 | npc->enemy = attacker; |
212 | return attacker; /* yes, we face our attacker! */ |
213 | return attacker; /* yes, we face our attacker! */ |
213 | } |
214 | } |
… | |
… | |
229 | /* Sees if this monster should wake up. |
230 | /* Sees if this monster should wake up. |
230 | * Currently, this is only called from move_monster, and |
231 | * Currently, this is only called from move_monster, and |
231 | * if enemy is set, then so should be rv. |
232 | * if enemy is set, then so should be rv. |
232 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | * returns 1 if the monster should wake up, 0 otherwise. |
233 | */ |
234 | */ |
234 | |
|
|
235 | int |
235 | int |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
236 | check_wakeup (object *op, object *enemy, rv_vector * rv) |
237 | { |
237 | { |
238 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
238 | int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS; |
239 | |
239 | |
… | |
… | |
273 | } |
273 | } |
274 | |
274 | |
275 | int |
275 | int |
276 | move_randomly (object *op) |
276 | move_randomly (object *op) |
277 | { |
277 | { |
278 | int i; |
|
|
279 | |
|
|
280 | /* Give up to 15 chances for a monster to move randomly */ |
278 | /* Give up to 15 chances for a monster to move randomly */ |
281 | for (i = 0; i < 15; i++) |
279 | for (int i = 0; i < 15; i++) |
282 | { |
|
|
283 | if (move_object (op, RANDOM () % 8 + 1)) |
280 | if (move_object (op, rndm (8) + 1)) |
284 | return 1; |
281 | return 1; |
285 | } |
282 | |
286 | return 0; |
283 | return 0; |
287 | } |
284 | } |
288 | |
285 | |
289 | /* |
286 | /* |
290 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
287 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
291 | */ |
288 | */ |
292 | |
|
|
293 | int |
289 | int |
294 | move_monster (object *op) |
290 | move_monster (object *op) |
295 | { |
291 | { |
296 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
292 | int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ |
297 | object *owner, *enemy, *part, *oph = op; |
293 | object *owner, *enemy, *part, *oph = op; |
… | |
… | |
314 | enemy->attacked_by = op; /* our ptr */ |
310 | enemy->attacked_by = op; /* our ptr */ |
315 | |
311 | |
316 | /* generate hp, if applicable */ |
312 | /* generate hp, if applicable */ |
317 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
313 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
318 | { |
314 | { |
319 | |
|
|
320 | /* last heal is in funny units. Dividing by speed puts |
315 | /* last heal is in funny units. Dividing by speed puts |
321 | * the regeneration rate on a basis of time instead of |
316 | * the regeneration rate on a basis of time instead of |
322 | * #moves the monster makes. The scaling by 8 is |
317 | * #moves the monster makes. The scaling by 8 is |
323 | * to capture 8th's of a hp fraction regens |
318 | * to capture 8th's of a hp fraction regens |
324 | * |
319 | * |
… | |
… | |
339 | } |
334 | } |
340 | |
335 | |
341 | /* generate sp, if applicable */ |
336 | /* generate sp, if applicable */ |
342 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
337 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
343 | { |
338 | { |
344 | |
|
|
345 | /* last_sp is in funny units. Dividing by speed puts |
339 | /* last_sp is in funny units. Dividing by speed puts |
346 | * the regeneration rate on a basis of time instead of |
340 | * the regeneration rate on a basis of time instead of |
347 | * #moves the monster makes. The scaling by 8 is |
341 | * #moves the monster makes. The scaling by 8 is |
348 | * to capture 8th's of a sp fraction regens |
342 | * to capture 8th's of a sp fraction regens |
349 | * |
343 | * |
… | |
… | |
357 | } |
351 | } |
358 | |
352 | |
359 | /* this should probably get modified by many more values. |
353 | /* this should probably get modified by many more values. |
360 | * (eg, creatures resistance to fear, level, etc. ) |
354 | * (eg, creatures resistance to fear, level, etc. ) |
361 | */ |
355 | */ |
362 | if (QUERY_FLAG (op, FLAG_SCARED) && !(RANDOM () % 20)) |
356 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
363 | { |
|
|
364 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
357 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
365 | } |
|
|
366 | |
358 | |
367 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
359 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
368 | return QUERY_FLAG (op, FLAG_FREED); |
360 | return QUERY_FLAG (op, FLAG_FREED); |
369 | |
361 | |
370 | if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || |
362 | if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || |
371 | ((op->map->darkness > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
363 | ((op->map->darkness > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
372 | { |
|
|
373 | if (!check_wakeup (op, enemy, &rv)) |
364 | if (!check_wakeup (op, enemy, &rv)) |
374 | return 0; |
365 | return 0; |
375 | } |
|
|
376 | |
366 | |
377 | /* check if monster pops out of hidden spot */ |
367 | /* check if monster pops out of hidden spot */ |
378 | if (op->hide) |
368 | if (op->flag [FLAG_HIDDEN]) |
379 | do_hidden_move (op); |
369 | do_hidden_move (op); |
380 | |
370 | |
381 | if (op->pick_up) |
371 | if (op->pick_up) |
382 | monster_check_pickup (op); |
372 | monster_check_pickup (op); |
383 | |
373 | |
… | |
… | |
387 | /* If we don't have an enemy, do special movement or the like */ |
377 | /* If we don't have an enemy, do special movement or the like */ |
388 | if (!enemy) |
378 | if (!enemy) |
389 | { |
379 | { |
390 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
380 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
391 | { |
381 | { |
392 | op->destroy (); |
382 | op->drop_and_destroy (); |
393 | return 1; |
383 | return 1; |
394 | } |
384 | } |
395 | |
385 | |
396 | /* Probably really a bug for a creature to have both |
386 | /* Probably really a bug for a creature to have both |
397 | * stand still and a movement type set. |
387 | * stand still and a movement type set. |
… | |
… | |
400 | { |
390 | { |
401 | if (op->attack_movement & HI4) |
391 | if (op->attack_movement & HI4) |
402 | { |
392 | { |
403 | switch (op->attack_movement & HI4) |
393 | switch (op->attack_movement & HI4) |
404 | { |
394 | { |
405 | case (PETMOVE): |
395 | case (PETMOVE): |
406 | pet_move (op); |
396 | pet_move (op); |
407 | break; |
397 | break; |
408 | |
398 | |
409 | case (CIRCLE1): |
399 | case (CIRCLE1): |
410 | circ1_move (op); |
400 | circ1_move (op); |
411 | break; |
401 | break; |
412 | |
402 | |
413 | case (CIRCLE2): |
403 | case (CIRCLE2): |
414 | circ2_move (op); |
404 | circ2_move (op); |
415 | break; |
405 | break; |
416 | |
406 | |
417 | case (PACEV): |
407 | case (PACEV): |
418 | pace_movev (op); |
408 | pace_movev (op); |
419 | break; |
409 | break; |
420 | |
410 | |
421 | case (PACEH): |
411 | case (PACEH): |
422 | pace_moveh (op); |
412 | pace_moveh (op); |
423 | break; |
413 | break; |
424 | |
414 | |
425 | case (PACEV2): |
415 | case (PACEV2): |
426 | pace2_movev (op); |
416 | pace2_movev (op); |
427 | break; |
417 | break; |
428 | |
418 | |
429 | case (PACEH2): |
419 | case (PACEH2): |
430 | pace2_moveh (op); |
420 | pace2_moveh (op); |
431 | break; |
421 | break; |
432 | |
422 | |
433 | case (RANDO): |
423 | case (RANDO): |
434 | rand_move (op); |
424 | rand_move (op); |
435 | break; |
425 | break; |
436 | |
426 | |
437 | case (RANDO2): |
427 | case (RANDO2): |
438 | move_randomly (op); |
428 | move_randomly (op); |
439 | break; |
429 | break; |
440 | } |
430 | } |
|
|
431 | |
441 | return 0; |
432 | return 0; |
442 | } |
433 | } |
443 | else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) |
434 | else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) |
444 | (void) move_randomly (op); |
435 | move_randomly (op); |
445 | |
|
|
446 | } /* stand still */ |
436 | } /* stand still */ |
|
|
437 | |
447 | return 0; |
438 | return 0; |
448 | } /* no enemy */ |
439 | } /* no enemy */ |
449 | |
440 | |
450 | /* We have an enemy. Block immediately below is for pets */ |
441 | /* We have an enemy. Block immediately below is for pets */ |
451 | if ((op->attack_movement & HI4) == PETMOVE && (owner = op->owner) != NULL && !on_same_map (op, owner)) |
442 | if ((op->attack_movement & HI4) == PETMOVE |
|
|
443 | && (owner = op->owner) != NULL |
|
|
444 | && !on_same_map (op, owner) |
|
|
445 | && !owner->flag [FLAG_REMOVED]) |
452 | return follow_owner (op, owner); |
446 | return follow_owner (op, owner); |
453 | |
447 | |
454 | /* doppleganger code to change monster facing to that of the nearest |
448 | /* doppleganger code to change monster facing to that of the nearest |
455 | * player. Hmm. The code is here, but no monster in the current |
449 | * player. Hmm. The code is here, but no monster in the current |
456 | * arch set uses it. |
450 | * arch set uses it. |
… | |
… | |
475 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
469 | if (!QUERY_FLAG (op, FLAG_SCARED)) |
476 | { |
470 | { |
477 | rv_vector rv1; |
471 | rv_vector rv1; |
478 | |
472 | |
479 | /* now we test every part of an object .... this is a real ugly piece of code */ |
473 | /* now we test every part of an object .... this is a real ugly piece of code */ |
480 | for (part = op; part != NULL; part = part->more) |
474 | for (part = op; part; part = part->more) |
481 | { |
475 | { |
482 | get_rangevector (part, enemy, &rv1, 0x1); |
476 | get_rangevector (part, enemy, &rv1, 0x1); |
483 | dir = rv1.direction; |
477 | dir = rv1.direction; |
484 | |
478 | |
485 | /* hm, not sure about this part - in original was a scared flag here too |
479 | /* hm, not sure about this part - in original was a scared flag here too |
486 | * but that we test above... so can be old code here |
480 | * but that we test above... so can be old code here |
487 | */ |
481 | */ |
488 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
482 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
489 | dir = absdir (dir + 4); |
483 | dir = absdir (dir + 4); |
|
|
484 | |
490 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
485 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
491 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
486 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
492 | |
487 | |
493 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(RANDOM () % 3)) |
488 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) |
494 | { |
|
|
495 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
489 | if (monster_cast_spell (op, part, enemy, dir, &rv1)) |
496 | return 0; |
490 | return 0; |
497 | } |
|
|
498 | |
491 | |
499 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(RANDOM () % 3)) |
492 | if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) |
500 | { |
|
|
501 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
493 | if (monster_use_scroll (op, part, enemy, dir, &rv1)) |
502 | return 0; |
494 | return 0; |
503 | } |
|
|
504 | |
495 | |
505 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(RANDOM () % 3)) |
496 | if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) |
506 | { |
|
|
507 | if (monster_use_range (op, part, enemy, dir)) |
497 | if (monster_use_range (op, part, enemy, dir)) |
508 | return 0; |
498 | return 0; |
509 | } |
499 | |
510 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(RANDOM () % 3)) |
500 | if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) |
511 | { |
|
|
512 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
501 | if (monster_use_skill (op, rv.part, enemy, rv.direction)) |
513 | return 0; |
502 | return 0; |
514 | } |
503 | |
515 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(RANDOM () % 2)) |
504 | if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) |
516 | { |
|
|
517 | if (monster_use_bow (op, part, enemy, dir)) |
505 | if (monster_use_bow (op, part, enemy, dir)) |
518 | return 0; |
506 | return 0; |
519 | } |
|
|
520 | } /* for processing of all parts */ |
507 | } /* for processing of all parts */ |
521 | } /* If not scared */ |
508 | } /* If not scared */ |
522 | |
509 | |
523 | |
510 | |
524 | part = rv.part; |
511 | part = rv.part; |
… | |
… | |
526 | |
513 | |
527 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
514 | if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
528 | dir = absdir (dir + 4); |
515 | dir = absdir (dir + 4); |
529 | |
516 | |
530 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
517 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
531 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
518 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
532 | |
519 | |
533 | pre_att_dir = dir; /* remember the original direction */ |
520 | pre_att_dir = dir; /* remember the original direction */ |
534 | |
521 | |
535 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
522 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
536 | { |
523 | { |
537 | switch (op->attack_movement & LO4) |
524 | switch (op->attack_movement & LO4) |
538 | { |
525 | { |
539 | case DISTATT: |
526 | case DISTATT: |
540 | dir = dist_att (dir, op, enemy, part, &rv); |
527 | dir = dist_att (dir, op, enemy, part, &rv); |
541 | break; |
528 | break; |
542 | |
529 | |
543 | case RUNATT: |
530 | case RUNATT: |
544 | dir = run_att (dir, op, enemy, part, &rv); |
531 | dir = run_att (dir, op, enemy, part, &rv); |
545 | break; |
532 | break; |
546 | |
533 | |
547 | case HITRUN: |
534 | case HITRUN: |
548 | dir = hitrun_att (dir, op, enemy); |
535 | dir = hitrun_att (dir, op, enemy); |
549 | break; |
536 | break; |
550 | |
537 | |
551 | case WAITATT: |
538 | case WAITATT: |
552 | dir = wait_att (dir, op, enemy, part, &rv); |
539 | dir = wait_att (dir, op, enemy, part, &rv); |
553 | break; |
540 | break; |
554 | |
541 | |
555 | case RUSH: /* default - monster normally moves towards player */ |
542 | case RUSH: /* default - monster normally moves towards player */ |
556 | case ALLRUN: |
543 | case ALLRUN: |
557 | break; |
544 | break; |
558 | |
545 | |
559 | case DISTHIT: |
546 | case DISTHIT: |
560 | dir = disthit_att (dir, op, enemy, part, &rv); |
547 | dir = disthit_att (dir, op, enemy, part, &rv); |
561 | break; |
548 | break; |
562 | |
549 | |
563 | case WAIT2: |
550 | case WAIT2: |
564 | dir = wait_att2 (dir, op, enemy, part, &rv); |
551 | dir = wait_att2 (dir, op, enemy, part, &rv); |
565 | break; |
552 | break; |
566 | |
553 | |
567 | default: |
554 | default: |
568 | LOG (llevDebug, "Illegal low mon-move: %d\n", op->attack_movement & LO4); |
555 | LOG (llevDebug, "Illegal low mon-move: %d\n", op->attack_movement & LO4); |
569 | } |
556 | } |
570 | } |
557 | } |
571 | |
558 | |
572 | if (!dir) |
559 | if (!dir) |
573 | return 0; |
560 | return 0; |
… | |
… | |
583 | return 0; |
570 | return 0; |
584 | } |
571 | } |
585 | |
572 | |
586 | if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
573 | if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
587 | { |
574 | { |
588 | |
|
|
589 | /* Try move around corners if !close */ |
575 | /* Try move around corners if !close */ |
590 | int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || RANDOM () & 1) ? 1 : 2; |
576 | int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || RANDOM () & 1) ? 1 : 2; |
591 | |
577 | |
592 | for (diff = 1; diff <= maxdiff; diff++) |
578 | for (diff = 1; diff <= maxdiff; diff++) |
593 | { |
579 | { |
… | |
… | |
643 | * still be pretty nasty. |
629 | * still be pretty nasty. |
644 | */ |
630 | */ |
645 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
631 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
646 | { |
632 | { |
647 | part->stats.wc += 10; |
633 | part->stats.wc += 10; |
648 | (void) skill_attack (enemy, part, 0, NULL, NULL); |
634 | skill_attack (enemy, part, 0, NULL, NULL); |
649 | part->stats.wc -= 10; |
635 | part->stats.wc -= 10; |
650 | } |
636 | } |
651 | else |
637 | else |
652 | (void) skill_attack (enemy, part, 0, NULL, NULL); |
638 | skill_attack (enemy, part, 0, NULL, NULL); |
653 | } /* if monster is in attack range */ |
639 | } /* if monster is in attack range */ |
654 | |
640 | |
655 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
641 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
656 | return 1; |
642 | return 1; |
657 | |
643 | |
658 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
644 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
659 | { |
645 | { |
660 | op->remove (); |
|
|
661 | op->destroy (); |
646 | op->drop_and_destroy (); |
662 | return 1; |
647 | return 1; |
663 | } |
648 | } |
|
|
649 | |
664 | return 0; |
650 | return 0; |
665 | } |
651 | } |
666 | |
652 | |
667 | int |
653 | int |
668 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
654 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
669 | { |
655 | { |
670 | object *more; |
656 | object *more; |
671 | rv_vector rv1; |
657 | rv_vector rv1; |
672 | |
658 | |
673 | if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(RANDOM () % 3)) |
659 | if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(rndm (3))) |
674 | return 0; |
660 | return 0; |
675 | |
661 | |
676 | if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) |
662 | if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) |
677 | return 1; |
663 | return 1; |
678 | |
664 | |
… | |
… | |
683 | { |
669 | { |
684 | get_rangevector (ob1, more, &rv1, 0); |
670 | get_rangevector (ob1, more, &rv1, 0); |
685 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
671 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
686 | return 1; |
672 | return 1; |
687 | } |
673 | } |
|
|
674 | |
688 | return 0; |
675 | return 0; |
689 | |
|
|
690 | } |
676 | } |
691 | |
677 | |
692 | /* Returns 1 is monster should cast spell sp at an enemy |
678 | /* Returns 1 is monster should cast spell sp at an enemy |
693 | * Returns 0 if the monster should not cast this spell. |
679 | * Returns 0 if the monster should not cast this spell. |
694 | * |
680 | * |
… | |
… | |
712 | spell_ob->subtype == SP_EXPLOSION || spell_ob->subtype == SP_CONE || |
698 | spell_ob->subtype == SP_EXPLOSION || spell_ob->subtype == SP_CONE || |
713 | spell_ob->subtype == SP_BOMB || spell_ob->subtype == SP_SMITE || |
699 | spell_ob->subtype == SP_BOMB || spell_ob->subtype == SP_SMITE || |
714 | spell_ob->subtype == SP_MAGIC_MISSILE || spell_ob->subtype == SP_SUMMON_GOLEM || |
700 | spell_ob->subtype == SP_MAGIC_MISSILE || spell_ob->subtype == SP_SUMMON_GOLEM || |
715 | spell_ob->subtype == SP_MAGIC_WALL || spell_ob->subtype == SP_SUMMON_MONSTER || |
701 | spell_ob->subtype == SP_MAGIC_WALL || spell_ob->subtype == SP_SUMMON_MONSTER || |
716 | spell_ob->subtype == SP_MOVING_BALL || spell_ob->subtype == SP_SWARM || spell_ob->subtype == SP_INVISIBLE) |
702 | spell_ob->subtype == SP_MOVING_BALL || spell_ob->subtype == SP_SWARM || spell_ob->subtype == SP_INVISIBLE) |
717 | |
|
|
718 | return 1; |
703 | return 1; |
719 | |
704 | |
720 | return 0; |
705 | return 0; |
721 | } |
706 | } |
722 | |
|
|
723 | |
707 | |
724 | #define MAX_KNOWN_SPELLS 20 |
708 | #define MAX_KNOWN_SPELLS 20 |
725 | |
709 | |
726 | /* Returns a randomly selected spell. This logic is still |
710 | /* Returns a randomly selected spell. This logic is still |
727 | * less than ideal. This code also only seems to deal with |
711 | * less than ideal. This code also only seems to deal with |
… | |
… | |
730 | */ |
714 | */ |
731 | object * |
715 | object * |
732 | monster_choose_random_spell (object *monster) |
716 | monster_choose_random_spell (object *monster) |
733 | { |
717 | { |
734 | object *altern[MAX_KNOWN_SPELLS]; |
718 | object *altern[MAX_KNOWN_SPELLS]; |
735 | object *tmp; |
|
|
736 | int i = 0; |
719 | int i = 0; |
737 | |
720 | |
738 | for (tmp = monster->inv; tmp != NULL; tmp = tmp->below) |
721 | for (object *tmp = monster->inv; tmp; tmp = tmp->below) |
739 | if (tmp->type == SPELLBOOK || tmp->type == SPELL) |
722 | if (tmp->type == SPELLBOOK || tmp->type == SPELL) |
740 | { |
723 | { |
741 | /* Check and see if it's actually a useful spell. |
724 | /* Check and see if it's actually a useful spell. |
742 | * If its a spellbook, the spell is actually the inventory item. |
725 | * If its a spellbook, the spell is actually the inventory item. |
743 | * if it is a spell, then it is just the object itself. |
726 | * if it is a spell, then it is just the object itself. |
744 | */ |
727 | */ |
745 | if (monster_should_cast_spell (monster, (tmp->type == SPELLBOOK) ? tmp->inv : tmp)) |
728 | if (monster_should_cast_spell (monster, (tmp->type == SPELLBOOK) ? tmp->inv : tmp)) |
746 | { |
729 | { |
747 | altern[i++] = tmp; |
730 | altern [i++] = tmp; |
|
|
731 | |
748 | if (i == MAX_KNOWN_SPELLS) |
732 | if (i == MAX_KNOWN_SPELLS) |
749 | break; |
733 | break; |
750 | } |
734 | } |
751 | } |
735 | } |
752 | if (!i) |
736 | |
753 | return NULL; |
737 | return i ? altern [rndm (i)] : 0; |
754 | return altern[RANDOM () % i]; |
|
|
755 | } |
738 | } |
756 | |
739 | |
757 | /* This checks to see if the monster should cast a spell/ability. |
740 | /* This checks to see if the monster should cast a spell/ability. |
758 | * it returns true if the monster casts a spell, 0 if he doesn't. |
741 | * it returns true if the monster casts a spell, 0 if he doesn't. |
759 | * head is the head of the monster. |
742 | * head is the head of the monster. |
760 | * part is the part of the monster we are checking against. |
743 | * part is the part of the monster we are checking against. |
761 | * pl is the target. |
744 | * pl is the target. |
762 | * dir is the direction to case. |
745 | * dir is the direction to case. |
763 | * rv is the vector which describes where the enemy is. |
746 | * rv is the vector which describes where the enemy is. |
764 | */ |
747 | */ |
765 | |
|
|
766 | int |
748 | int |
767 | monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) |
749 | monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) |
768 | { |
750 | { |
769 | object *spell_item; |
751 | object *spell_item; |
770 | object *owner; |
752 | object *owner; |
… | |
… | |
781 | |
763 | |
782 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
764 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
783 | { |
765 | { |
784 | get_rangevector (head, owner, &rv1, 0x1); |
766 | get_rangevector (head, owner, &rv1, 0x1); |
785 | if (dirdiff (dir, rv1.direction) < 2) |
767 | if (dirdiff (dir, rv1.direction) < 2) |
786 | { |
|
|
787 | return 0; /* Might hit owner with spell */ |
768 | return 0; /* Might hit owner with spell */ |
788 | } |
|
|
789 | } |
769 | } |
790 | |
770 | |
791 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
771 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
792 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
772 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
793 | |
773 | |
794 | /* If the monster hasn't already chosen a spell, choose one |
774 | /* If the monster hasn't already chosen a spell, choose one |
795 | * I'm not sure if it really make sense to pre-select spells (events |
775 | * I'm not sure if it really make sense to pre-select spells (events |
796 | * could be different by the time the monster goes again). |
776 | * could be different by the time the monster goes again). |
797 | */ |
777 | */ |
… | |
… | |
801 | { |
781 | { |
802 | LOG (llevMonster, "Turned off spells in %s\n", &head->name); |
782 | LOG (llevMonster, "Turned off spells in %s\n", &head->name); |
803 | CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ |
783 | CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ |
804 | return 0; |
784 | return 0; |
805 | } |
785 | } |
|
|
786 | |
806 | if (spell_item->type == SPELLBOOK) |
787 | if (spell_item->type == SPELLBOOK) |
807 | { |
788 | { |
808 | if (!spell_item->inv) |
789 | if (!spell_item->inv) |
809 | { |
790 | { |
810 | LOG (llevError, "spellbook %s does not contain a spell?\n", &spell_item->name); |
791 | LOG (llevError, "spellbook %s does not contain a spell?\n", &spell_item->name); |
811 | return 0; |
792 | return 0; |
812 | } |
793 | } |
|
|
794 | |
813 | spell_item = spell_item->inv; |
795 | spell_item = spell_item->inv; |
814 | } |
796 | } |
815 | } |
797 | } |
816 | else |
798 | else |
817 | spell_item = head->spellitem; |
799 | spell_item = head->spellitem; |
… | |
… | |
836 | /* set this to null, so next time monster will choose something different */ |
818 | /* set this to null, so next time monster will choose something different */ |
837 | head->spellitem = NULL; |
819 | head->spellitem = NULL; |
838 | |
820 | |
839 | return cast_spell (part, part, dir, spell_item, NULL); |
821 | return cast_spell (part, part, dir, spell_item, NULL); |
840 | } |
822 | } |
841 | |
|
|
842 | |
823 | |
843 | int |
824 | int |
844 | monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) |
825 | monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) |
845 | { |
826 | { |
846 | object *scroll; |
827 | object *scroll; |
… | |
… | |
864 | return 0; /* Might hit owner with spell */ |
845 | return 0; /* Might hit owner with spell */ |
865 | } |
846 | } |
866 | } |
847 | } |
867 | |
848 | |
868 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
849 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
869 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
850 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
870 | |
851 | |
871 | for (scroll = head->inv; scroll; scroll = scroll->below) |
852 | for (scroll = head->inv; scroll; scroll = scroll->below) |
872 | if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) |
853 | if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) |
873 | break; |
854 | break; |
874 | |
855 | |
… | |
… | |
896 | * The skills we are treating here are all but those. -b.t. |
877 | * The skills we are treating here are all but those. -b.t. |
897 | * |
878 | * |
898 | * At the moment this is only useful for throwing, perhaps for |
879 | * At the moment this is only useful for throwing, perhaps for |
899 | * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 |
880 | * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 |
900 | */ |
881 | */ |
901 | |
|
|
902 | int |
882 | int |
903 | monster_use_skill (object *head, object *part, object *pl, int dir) |
883 | monster_use_skill (object *head, object *part, object *pl, int dir) |
904 | { |
884 | { |
905 | object *skill, *owner; |
885 | object *skill, *owner; |
906 | |
886 | |
… | |
… | |
912 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
892 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
913 | |
893 | |
914 | if (dirdiff (dir, dir2) < 1) |
894 | if (dirdiff (dir, dir2) < 1) |
915 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
895 | return 0; /* Might hit owner with skill -thrown rocks for example ? */ |
916 | } |
896 | } |
|
|
897 | |
917 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
898 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
918 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
899 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
919 | |
900 | |
920 | /* skill selection - monster will use the next unused skill. |
901 | /* skill selection - monster will use the next unused skill. |
921 | * well...the following scenario will allow the monster to |
902 | * well...the following scenario will allow the monster to |
922 | * toggle between 2 skills. One day it would be nice to make |
903 | * toggle between 2 skills. One day it would be nice to make |
923 | * more skills available to monsters. |
904 | * more skills available to monsters. |
924 | */ |
905 | */ |
925 | |
|
|
926 | for (skill = head->inv; skill != NULL; skill = skill->below) |
906 | for (skill = head->inv; skill; skill = skill->below) |
927 | if (skill->type == SKILL && skill != head->chosen_skill) |
907 | if (skill->type == SKILL && skill != head->chosen_skill) |
928 | { |
908 | { |
929 | head->chosen_skill = skill; |
909 | head->chosen_skill = skill; |
930 | break; |
910 | break; |
931 | } |
911 | } |
… | |
… | |
934 | { |
914 | { |
935 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
915 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
936 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
916 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
937 | return 0; |
917 | return 0; |
938 | } |
918 | } |
|
|
919 | |
939 | /* use skill */ |
920 | /* use skill */ |
940 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
921 | return do_skill (head, part, head->chosen_skill, dir, NULL); |
941 | } |
922 | } |
942 | |
923 | |
943 | /* Monster will use a ranged spell attack. */ |
924 | /* Monster will use a ranged spell attack. */ |
944 | |
|
|
945 | int |
925 | int |
946 | monster_use_range (object *head, object *part, object *pl, int dir) |
926 | monster_use_range (object *head, object *part, object *pl, int dir) |
947 | { |
927 | { |
948 | object *wand, *owner; |
928 | object *wand, *owner; |
949 | int at_least_one = 0; |
929 | int at_least_one = 0; |
… | |
… | |
956 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
936 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
957 | |
937 | |
958 | if (dirdiff (dir, dir2) < 2) |
938 | if (dirdiff (dir, dir2) < 2) |
959 | return 0; /* Might hit owner with spell */ |
939 | return 0; /* Might hit owner with spell */ |
960 | } |
940 | } |
|
|
941 | |
961 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
942 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
962 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
943 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
963 | |
944 | |
964 | for (wand = head->inv; wand != NULL; wand = wand->below) |
945 | for (wand = head->inv; wand; wand = wand->below) |
965 | { |
946 | { |
966 | if (wand->type == WAND) |
947 | if (wand->type == WAND) |
967 | { |
948 | { |
968 | /* Found a wand, let's see if it has charges left */ |
949 | /* Found a wand, let's see if it has charges left */ |
969 | at_least_one = 1; |
950 | at_least_one = 1; |
… | |
… | |
975 | if (!(--wand->stats.food)) |
956 | if (!(--wand->stats.food)) |
976 | { |
957 | { |
977 | if (wand->arch) |
958 | if (wand->arch) |
978 | { |
959 | { |
979 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
960 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
980 | wand->face = wand->arch->clone.face; |
961 | wand->face = wand->arch->face; |
981 | wand->set_speed (0); |
962 | wand->set_speed (0); |
982 | } |
963 | } |
983 | } |
964 | } |
984 | /* Success */ |
965 | /* Success */ |
985 | return 1; |
966 | return 1; |
… | |
… | |
1004 | } |
985 | } |
1005 | |
986 | |
1006 | if (at_least_one) |
987 | if (at_least_one) |
1007 | return 0; |
988 | return 0; |
1008 | |
989 | |
1009 | LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANG() without wand/horn/rod.\n", &head->name, head->count); |
990 | LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count); |
1010 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
991 | CLEAR_FLAG (head, FLAG_READY_RANGE); |
1011 | return 0; |
992 | return 0; |
1012 | } |
993 | } |
1013 | |
994 | |
1014 | int |
995 | int |
… | |
… | |
1016 | { |
997 | { |
1017 | object *owner; |
998 | object *owner; |
1018 | |
999 | |
1019 | if (!(dir = path_to_player (part, pl, 0))) |
1000 | if (!(dir = path_to_player (part, pl, 0))) |
1020 | return 0; |
1001 | return 0; |
|
|
1002 | |
1021 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1003 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1022 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
1004 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1023 | |
1005 | |
1024 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1006 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
1025 | { |
1007 | { |
1026 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
1008 | int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); |
1027 | |
1009 | |
… | |
… | |
1033 | return fire_bow (head, part, NULL, dir, 0, part->x, part->y); |
1015 | return fire_bow (head, part, NULL, dir, 0, part->x, part->y); |
1034 | |
1016 | |
1035 | } |
1017 | } |
1036 | |
1018 | |
1037 | /* Checks if putting on 'item' will make 'who' do more |
1019 | /* Checks if putting on 'item' will make 'who' do more |
1038 | * damage. This is a very simplistic check - also checking things |
1020 | * damage. This is a very simplistic check - also checking things |
1039 | * like speed and ac are also relevant. |
1021 | * like speed and ac are also relevant. |
1040 | * |
1022 | * |
1041 | * return true if item is a better object. |
1023 | * return true if item is a better object. |
1042 | */ |
1024 | */ |
1043 | |
|
|
1044 | int |
1025 | int |
1045 | check_good_weapon (object *who, object *item) |
1026 | check_good_weapon (object *who, object *item) |
1046 | { |
1027 | { |
1047 | object *other_weap; |
1028 | object *other_weap; |
1048 | int val = 0, i; |
1029 | int val = 0, i; |
1049 | |
1030 | |
1050 | for (other_weap = who->inv; other_weap != NULL; other_weap = other_weap->below) |
1031 | for (other_weap = who->inv; other_weap; other_weap = other_weap->below) |
1051 | if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) |
1032 | if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) |
1052 | break; |
1033 | break; |
1053 | |
1034 | |
1054 | if (other_weap == NULL) /* No other weapons */ |
1035 | if (!other_weap) /* No other weapons */ |
1055 | return 1; |
1036 | return 1; |
1056 | |
1037 | |
1057 | /* Rather than go through and apply the new one, and see if it is |
1038 | /* Rather than go through and apply the new one, and see if it is |
1058 | * better, just do some simple checks |
1039 | * better, just do some simple checks |
1059 | * Put some multipliers for things that hvae several effects, |
1040 | * Put some multipliers for things that hvae several effects, |
… | |
… | |
1064 | val += (item->magic - other_weap->magic) * 3; |
1045 | val += (item->magic - other_weap->magic) * 3; |
1065 | /* Monsters don't really get benefits from things like regen rates |
1046 | /* Monsters don't really get benefits from things like regen rates |
1066 | * from items. But the bonus for their stats are very important. |
1047 | * from items. But the bonus for their stats are very important. |
1067 | */ |
1048 | */ |
1068 | for (i = 0; i < NUM_STATS; i++) |
1049 | for (i = 0; i < NUM_STATS; i++) |
1069 | val += (get_attr_value (&item->stats, i) - get_attr_value (&other_weap->stats, i)) * 2; |
1050 | val += item->stats.stat (i) - other_weap->stats.stat (i) * 2; |
1070 | |
1051 | |
1071 | if (val > 0) |
1052 | if (val > 0) |
1072 | return 1; |
1053 | return 1; |
1073 | else |
1054 | else |
1074 | return 0; |
1055 | return 0; |
1075 | |
|
|
1076 | } |
1056 | } |
1077 | |
1057 | |
1078 | int |
1058 | int |
1079 | check_good_armour (object *who, object *item) |
1059 | check_good_armour (object *who, object *item) |
1080 | { |
1060 | { |
1081 | object *other_armour; |
1061 | object *other_armour; |
1082 | int val = 0, i; |
1062 | int val = 0, i; |
1083 | |
1063 | |
1084 | for (other_armour = who->inv; other_armour != NULL; other_armour = other_armour->below) |
1064 | for (other_armour = who->inv; other_armour; other_armour = other_armour->below) |
1085 | if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) |
1065 | if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) |
1086 | break; |
1066 | break; |
1087 | |
1067 | |
1088 | if (other_armour == NULL) /* No other armour, use the new */ |
1068 | if (other_armour == NULL) /* No other armour, use the new */ |
1089 | return 1; |
1069 | return 1; |
… | |
… | |
1111 | |
1091 | |
1112 | if (val > 0) |
1092 | if (val > 0) |
1113 | return 1; |
1093 | return 1; |
1114 | else |
1094 | else |
1115 | return 0; |
1095 | return 0; |
1116 | |
|
|
1117 | } |
1096 | } |
1118 | |
1097 | |
1119 | /* |
1098 | /* |
1120 | * monster_check_pickup(): checks for items that monster can pick up. |
1099 | * monster_check_pickup(): checks for items that monster can pick up. |
1121 | * |
1100 | * |
… | |
… | |
1129 | * This function was seen be continueing looping at one point (tmp->below |
1108 | * This function was seen be continueing looping at one point (tmp->below |
1130 | * became a recursive loop. It may be better to call monster_check_apply |
1109 | * became a recursive loop. It may be better to call monster_check_apply |
1131 | * after we pick everything up, since that function may call others which |
1110 | * after we pick everything up, since that function may call others which |
1132 | * affect stacking on this space. |
1111 | * affect stacking on this space. |
1133 | */ |
1112 | */ |
1134 | |
|
|
1135 | void |
1113 | void |
1136 | monster_check_pickup (object *monster) |
1114 | monster_check_pickup (object *monster) |
1137 | { |
1115 | { |
1138 | object *tmp, *next; |
1116 | object *tmp, *next; |
1139 | |
1117 | |
… | |
… | |
1158 | * monster_can_pick(): If the monster is interested in picking up |
1136 | * monster_can_pick(): If the monster is interested in picking up |
1159 | * the item, then return 0. Otherwise 0. |
1137 | * the item, then return 0. Otherwise 0. |
1160 | * Instead of pick_up, flags for "greed", etc, should be used. |
1138 | * Instead of pick_up, flags for "greed", etc, should be used. |
1161 | * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. |
1139 | * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. |
1162 | */ |
1140 | */ |
1163 | |
|
|
1164 | int |
1141 | int |
1165 | monster_can_pick (object *monster, object *item) |
1142 | monster_can_pick (object *monster, object *item) |
1166 | { |
1143 | { |
1167 | int flag = 0; |
1144 | int flag = 0; |
1168 | int i; |
1145 | int i; |
… | |
… | |
1214 | case ROD: |
1191 | case ROD: |
1215 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1192 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1216 | break; |
1193 | break; |
1217 | |
1194 | |
1218 | case SPELLBOOK: |
1195 | case SPELLBOOK: |
1219 | flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); |
1196 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1220 | break; |
1197 | break; |
1221 | |
1198 | |
1222 | case SCROLL: |
1199 | case SCROLL: |
1223 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1200 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1224 | break; |
1201 | break; |
… | |
… | |
1226 | case BOW: |
1203 | case BOW: |
1227 | case ARROW: |
1204 | case ARROW: |
1228 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1205 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1229 | break; |
1206 | break; |
1230 | } |
1207 | } |
|
|
1208 | |
1231 | /* Simplistic check - if the monster has a location to equip it, he will |
1209 | /* Simplistic check - if the monster has a location to equip it, he will |
1232 | * pick it up. Note that this doesn't handle cases where an item may |
1210 | * pick it up. Note that this doesn't handle cases where an item may |
1233 | * use several locations. |
1211 | * use several locations. |
1234 | */ |
1212 | */ |
1235 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1213 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
1236 | { |
1214 | { |
1237 | if (monster->body_info[i] && item->body_info[i]) |
1215 | if (monster->slot[i].info && item->slot[i].info) |
1238 | { |
1216 | { |
1239 | flag = 1; |
1217 | flag = 1; |
1240 | break; |
1218 | break; |
1241 | } |
1219 | } |
1242 | } |
1220 | } |
1243 | |
1221 | |
1244 | if (((!(monster->pick_up & 32)) && flag) || ((monster->pick_up & 32) && (!flag))) |
1222 | if (((!(monster->pick_up & 32)) && flag) || ((monster->pick_up & 32) && (!flag))) |
1245 | return 1; |
1223 | return 1; |
|
|
1224 | |
1246 | return 0; |
1225 | return 0; |
1247 | } |
1226 | } |
1248 | |
1227 | |
1249 | /* |
1228 | /* |
1250 | * monster_apply_below(): |
1229 | * monster_apply_below(): |
1251 | * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's |
1230 | * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's |
1252 | * eager to apply things, encounters something apply-able, |
1231 | * eager to apply things, encounters something apply-able, |
1253 | * then make him apply it |
1232 | * then make him apply it |
1254 | */ |
1233 | */ |
1255 | |
|
|
1256 | void |
1234 | void |
1257 | monster_apply_below (object *monster) |
1235 | monster_apply_below (object *monster) |
1258 | { |
1236 | { |
1259 | object *tmp, *next; |
1237 | object *tmp, *next; |
1260 | |
1238 | |
… | |
… | |
1287 | * a pointer to that object is returned, so it can be dropped. |
1265 | * a pointer to that object is returned, so it can be dropped. |
1288 | * (so that other monsters can pick it up and use it) |
1266 | * (so that other monsters can pick it up and use it) |
1289 | * Note that as things are now, monsters never drop something - |
1267 | * Note that as things are now, monsters never drop something - |
1290 | * they can pick up all that they can use. |
1268 | * they can pick up all that they can use. |
1291 | */ |
1269 | */ |
1292 | |
|
|
1293 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1270 | /* Sept 96, fixed this so skills will be readied -b.t.*/ |
1294 | |
|
|
1295 | void |
1271 | void |
1296 | monster_check_apply (object *mon, object *item) |
1272 | monster_check_apply (object *mon, object *item) |
1297 | { |
1273 | { |
1298 | |
|
|
1299 | int flag = 0; |
1274 | int flag = 0; |
1300 | |
1275 | |
1301 | if (item->type == SPELLBOOK && mon->arch != NULL && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) |
1276 | if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG (mon->arch, FLAG_CAST_SPELL))) |
1302 | { |
1277 | { |
1303 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1278 | SET_FLAG (mon, FLAG_CAST_SPELL); |
1304 | return; |
1279 | return; |
1305 | } |
1280 | } |
1306 | |
1281 | |
… | |
… | |
1315 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1290 | if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) |
1316 | { |
1291 | { |
1317 | /* Check for the right kind of bow */ |
1292 | /* Check for the right kind of bow */ |
1318 | object *bow; |
1293 | object *bow; |
1319 | |
1294 | |
1320 | for (bow = mon->inv; bow != NULL; bow = bow->below) |
1295 | for (bow = mon->inv; bow; bow = bow->below) |
1321 | if (bow->type == BOW && bow->race == item->race) |
1296 | if (bow->type == BOW && bow->race == item->race) |
1322 | { |
1297 | { |
1323 | SET_FLAG (mon, FLAG_READY_BOW); |
1298 | SET_FLAG (mon, FLAG_READY_BOW); |
1324 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1299 | LOG (llevMonster, "Found correct bow for arrows.\n"); |
1325 | return; /* nothing more to do for arrows */ |
1300 | return; /* nothing more to do for arrows */ |
… | |
… | |
1377 | */ |
1352 | */ |
1378 | SET_FLAG (mon, FLAG_READY_SKILL); |
1353 | SET_FLAG (mon, FLAG_READY_SKILL); |
1379 | return; |
1354 | return; |
1380 | } |
1355 | } |
1381 | |
1356 | |
1382 | |
|
|
1383 | /* if we don't match one of the above types, return now. |
1357 | /* if we don't match one of the above types, return now. |
1384 | * can_apply_object will say that we can apply things like flesh, |
1358 | * can_apply_object will say that we can apply things like flesh, |
1385 | * bolts, and whatever else, because it only checks against the |
1359 | * bolts, and whatever else, because it only checks against the |
1386 | * body_info locations. |
1360 | * body_info locations. |
1387 | */ |
1361 | */ |
… | |
… | |
1398 | /* should only be applying this item, not unapplying it. |
1372 | /* should only be applying this item, not unapplying it. |
1399 | * also, ignore status of curse so they can take off old armour. |
1373 | * also, ignore status of curse so they can take off old armour. |
1400 | * monsters have some advantages after all. |
1374 | * monsters have some advantages after all. |
1401 | */ |
1375 | */ |
1402 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1376 | manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); |
1403 | |
|
|
1404 | return; |
|
|
1405 | } |
1377 | } |
1406 | |
1378 | |
1407 | void |
1379 | void |
1408 | npc_call_help (object *op) |
1380 | npc_call_help (object *op) |
1409 | { |
1381 | { |
… | |
… | |
1427 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1399 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1428 | npc->enemy = op->enemy; |
1400 | npc->enemy = op->enemy; |
1429 | } |
1401 | } |
1430 | } |
1402 | } |
1431 | |
1403 | |
1432 | |
|
|
1433 | int |
1404 | int |
1434 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1405 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1435 | { |
1406 | { |
1436 | |
|
|
1437 | if (can_hit (part, enemy, rv)) |
1407 | if (can_hit (part, enemy, rv)) |
1438 | return dir; |
1408 | return dir; |
|
|
1409 | |
1439 | if (rv->distance < 10) |
1410 | if (rv->distance < 10) |
1440 | return absdir (dir + 4); |
1411 | return absdir (dir + 4); |
1441 | else if (rv->distance > 18) |
1412 | else if (rv->distance > 18) |
1442 | return dir; |
1413 | return dir; |
|
|
1414 | |
1443 | return 0; |
1415 | return 0; |
1444 | } |
1416 | } |
1445 | |
1417 | |
1446 | int |
1418 | int |
1447 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1419 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1448 | { |
1420 | { |
1449 | |
|
|
1450 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1421 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1451 | { |
1422 | { |
1452 | ob->move_status++; |
1423 | ob->move_status++; |
1453 | return (dir); |
1424 | return (dir); |
1454 | } |
1425 | } |
1455 | else if (ob->move_status > 20) |
1426 | else if (ob->move_status > 20) |
1456 | ob->move_status = 0; |
1427 | ob->move_status = 0; |
|
|
1428 | |
1457 | return absdir (dir + 4); |
1429 | return absdir (dir + 4); |
1458 | } |
1430 | } |
1459 | |
1431 | |
1460 | int |
1432 | int |
1461 | hitrun_att (int dir, object *ob, object *enemy) |
1433 | hitrun_att (int dir, object *ob, object *enemy) |
… | |
… | |
1464 | return dir; |
1436 | return dir; |
1465 | else if (ob->move_status < 50) |
1437 | else if (ob->move_status < 50) |
1466 | return absdir (dir + 4); |
1438 | return absdir (dir + 4); |
1467 | else |
1439 | else |
1468 | ob->move_status = 0; |
1440 | ob->move_status = 0; |
|
|
1441 | |
1469 | return absdir (dir + 4); |
1442 | return absdir (dir + 4); |
1470 | } |
1443 | } |
1471 | |
1444 | |
1472 | int |
1445 | int |
1473 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1446 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
… | |
… | |
1482 | return 0; |
1455 | return 0; |
1483 | else if (ob->move_status < 10) |
1456 | else if (ob->move_status < 10) |
1484 | return dir; |
1457 | return dir; |
1485 | else if (ob->move_status < 15) |
1458 | else if (ob->move_status < 15) |
1486 | return absdir (dir + 4); |
1459 | return absdir (dir + 4); |
|
|
1460 | |
1487 | ob->move_status = 0; |
1461 | ob->move_status = 0; |
1488 | return 0; |
1462 | return 0; |
1489 | } |
1463 | } |
1490 | |
1464 | |
1491 | int |
1465 | int |
… | |
… | |
1499 | * at least one map has this set, and whatever the map contains, the |
1473 | * at least one map has this set, and whatever the map contains, the |
1500 | * server should try to be resilant enough to avoid the problem |
1474 | * server should try to be resilant enough to avoid the problem |
1501 | */ |
1475 | */ |
1502 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1476 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1503 | return absdir (dir + 4); |
1477 | return absdir (dir + 4); |
|
|
1478 | |
1504 | return dist_att (dir, ob, enemy, part, rv); |
1479 | return dist_att (dir, ob, enemy, part, rv); |
1505 | } |
1480 | } |
1506 | |
1481 | |
1507 | int |
1482 | int |
1508 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1483 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1509 | { |
1484 | { |
1510 | if (rv->distance < 9) |
1485 | if (rv->distance < 9) |
1511 | return absdir (dir + 4); |
1486 | return absdir (dir + 4); |
|
|
1487 | |
1512 | return 0; |
1488 | return 0; |
1513 | } |
1489 | } |
1514 | |
1490 | |
1515 | void |
1491 | void |
1516 | circ1_move (object *ob) |
1492 | circ1_move (object *ob) |
1517 | { |
1493 | { |
1518 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
1494 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
|
|
1495 | |
1519 | if (++ob->move_status > 11) |
1496 | if (++ob->move_status > 11) |
1520 | ob->move_status = 0; |
1497 | ob->move_status = 0; |
|
|
1498 | |
1521 | if (!(move_object (ob, circle[ob->move_status]))) |
1499 | if (!(move_object (ob, circle[ob->move_status]))) |
1522 | (void) move_object (ob, RANDOM () % 8 + 1); |
1500 | move_object (ob, rndm (8) + 1); |
1523 | } |
1501 | } |
1524 | |
1502 | |
1525 | void |
1503 | void |
1526 | circ2_move (object *ob) |
1504 | circ2_move (object *ob) |
1527 | { |
1505 | { |
1528 | static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; |
1506 | static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; |
|
|
1507 | |
1529 | if (++ob->move_status > 19) |
1508 | if (++ob->move_status > 19) |
1530 | ob->move_status = 0; |
1509 | ob->move_status = 0; |
|
|
1510 | |
1531 | if (!(move_object (ob, circle[ob->move_status]))) |
1511 | if (!(move_object (ob, circle[ob->move_status]))) |
1532 | (void) move_object (ob, RANDOM () % 8 + 1); |
1512 | move_object (ob, rndm (8) + 1); |
1533 | } |
1513 | } |
1534 | |
1514 | |
1535 | void |
1515 | void |
1536 | pace_movev (object *ob) |
1516 | pace_movev (object *ob) |
1537 | { |
1517 | { |
1538 | if (ob->move_status++ > 6) |
1518 | if (ob->move_status++ > 6) |
1539 | ob->move_status = 0; |
1519 | ob->move_status = 0; |
|
|
1520 | |
1540 | if (ob->move_status < 4) |
1521 | if (ob->move_status < 4) |
1541 | (void) move_object (ob, 5); |
1522 | move_object (ob, 5); |
1542 | else |
1523 | else |
1543 | (void) move_object (ob, 1); |
1524 | move_object (ob, 1); |
1544 | } |
1525 | } |
1545 | |
1526 | |
1546 | void |
1527 | void |
1547 | pace_moveh (object *ob) |
1528 | pace_moveh (object *ob) |
1548 | { |
1529 | { |
1549 | if (ob->move_status++ > 6) |
1530 | if (ob->move_status++ > 6) |
1550 | ob->move_status = 0; |
1531 | ob->move_status = 0; |
|
|
1532 | |
1551 | if (ob->move_status < 4) |
1533 | if (ob->move_status < 4) |
1552 | (void) move_object (ob, 3); |
1534 | move_object (ob, 3); |
1553 | else |
1535 | else |
1554 | (void) move_object (ob, 7); |
1536 | move_object (ob, 7); |
1555 | } |
1537 | } |
1556 | |
1538 | |
1557 | void |
1539 | void |
1558 | pace2_movev (object *ob) |
1540 | pace2_movev (object *ob) |
1559 | { |
1541 | { |
1560 | if (ob->move_status++ > 16) |
1542 | if (ob->move_status++ > 16) |
1561 | ob->move_status = 0; |
1543 | ob->move_status = 0; |
|
|
1544 | |
1562 | if (ob->move_status < 6) |
1545 | if (ob->move_status < 6) |
1563 | (void) move_object (ob, 5); |
1546 | move_object (ob, 5); |
1564 | else if (ob->move_status < 8) |
1547 | else if (ob->move_status < 8) |
1565 | return; |
1548 | return; |
1566 | else if (ob->move_status < 13) |
1549 | else if (ob->move_status < 13) |
1567 | (void) move_object (ob, 1); |
1550 | move_object (ob, 1); |
1568 | else |
1551 | else |
1569 | return; |
1552 | return; |
1570 | } |
1553 | } |
1571 | |
1554 | |
1572 | void |
1555 | void |
1573 | pace2_moveh (object *ob) |
1556 | pace2_moveh (object *ob) |
1574 | { |
1557 | { |
1575 | if (ob->move_status++ > 16) |
1558 | if (ob->move_status++ > 16) |
1576 | ob->move_status = 0; |
1559 | ob->move_status = 0; |
|
|
1560 | |
1577 | if (ob->move_status < 6) |
1561 | if (ob->move_status < 6) |
1578 | (void) move_object (ob, 3); |
1562 | move_object (ob, 3); |
1579 | else if (ob->move_status < 8) |
1563 | else if (ob->move_status < 8) |
1580 | return; |
1564 | return; |
1581 | else if (ob->move_status < 13) |
1565 | else if (ob->move_status < 13) |
1582 | (void) move_object (ob, 7); |
1566 | move_object (ob, 7); |
1583 | else |
1567 | else |
1584 | return; |
1568 | return; |
1585 | } |
1569 | } |
1586 | |
1570 | |
1587 | void |
1571 | void |
1588 | rand_move (object *ob) |
1572 | rand_move (object *ob) |
1589 | { |
1573 | { |
1590 | int i; |
|
|
1591 | |
|
|
1592 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(RANDOM () % 9)))) |
1574 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1593 | for (i = 0; i < 5; i++) |
1575 | for (int i = 0; i < 5; i++) |
1594 | if (move_object (ob, ob->move_status = RANDOM () % 8 + 1)) |
1576 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1595 | return; |
1577 | return; |
1596 | } |
1578 | } |
1597 | |
1579 | |
1598 | void |
1580 | void |
1599 | check_earthwalls (object *op, maptile *m, int x, int y) |
1581 | check_earthwalls (object *op, maptile *m, int x, int y) |
1600 | { |
1582 | { |
1601 | object *tmp; |
|
|
1602 | |
|
|
1603 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1583 | for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1604 | { |
|
|
1605 | if (tmp->type == EARTHWALL) |
1584 | if (tmp->type == EARTHWALL) |
1606 | { |
1585 | { |
1607 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1586 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1608 | return; |
1587 | return; |
1609 | } |
1588 | } |
1610 | } |
|
|
1611 | } |
1589 | } |
1612 | |
1590 | |
1613 | void |
1591 | void |
1614 | check_doors (object *op, maptile *m, int x, int y) |
1592 | check_doors (object *op, maptile *m, int x, int y) |
1615 | { |
1593 | { |
1616 | object *tmp; |
|
|
1617 | |
|
|
1618 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1594 | for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1619 | { |
|
|
1620 | if (tmp->type == DOOR) |
1595 | if (tmp->type == DOOR) |
1621 | { |
1596 | { |
1622 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1597 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1623 | return; |
1598 | return; |
1624 | } |
1599 | } |
1625 | } |
|
|
1626 | } |
1600 | } |
1627 | |
1601 | |
1628 | /* find_mon_throw_ob() - modeled on find_throw_ob |
1602 | /* find_mon_throw_ob() - modeled on find_throw_ob |
1629 | * This is probably overly simplistic as it is now - We want |
1603 | * This is probably overly simplistic as it is now - We want |
1630 | * monsters to throw things like chairs and other pieces of |
1604 | * monsters to throw things like chairs and other pieces of |
1631 | * furniture, even if they are not good throwable objects. |
1605 | * furniture, even if they are not good throwable objects. |
1632 | * Probably better to have the monster throw a throwable object |
1606 | * Probably better to have the monster throw a throwable object |
1633 | * first, then throw any non equipped weapon. |
1607 | * first, then throw any non equipped weapon. |
1634 | */ |
1608 | */ |
1635 | |
|
|
1636 | object * |
1609 | object * |
1637 | find_mon_throw_ob (object *op) |
1610 | find_mon_throw_ob (object *op) |
1638 | { |
1611 | { |
1639 | object *tmp = NULL; |
1612 | object *tmp = NULL; |
1640 | |
1613 | |
… | |
… | |
1644 | tmp = op; |
1617 | tmp = op; |
1645 | |
1618 | |
1646 | /* New throw code: look through the inventory. Grap the first legal is_thrown |
1619 | /* New throw code: look through the inventory. Grap the first legal is_thrown |
1647 | * marked item and throw it to the enemy. |
1620 | * marked item and throw it to the enemy. |
1648 | */ |
1621 | */ |
1649 | |
|
|
1650 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1622 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1651 | { |
1623 | { |
1652 | |
|
|
1653 | /* Can't throw invisible objects or items that are applied */ |
1624 | /* Can't throw invisible objects or items that are applied */ |
1654 | if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) |
1625 | if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) |
1655 | continue; |
1626 | continue; |
1656 | |
1627 | |
1657 | if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1628 | if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
… | |
… | |
1673 | * properly. I also so odd code in place that checked for x distance |
1644 | * properly. I also so odd code in place that checked for x distance |
1674 | * OR y distance being within some range - that seemed wrong - both should |
1645 | * OR y distance being within some range - that seemed wrong - both should |
1675 | * be within the valid range. MSW 2001-08-05 |
1646 | * be within the valid range. MSW 2001-08-05 |
1676 | * Returns 0 if enemy can not be detected, 1 if it is detected |
1647 | * Returns 0 if enemy can not be detected, 1 if it is detected |
1677 | */ |
1648 | */ |
1678 | |
|
|
1679 | int |
1649 | int |
1680 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1650 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1681 | { |
1651 | { |
1682 | int radius = MIN_MON_RADIUS, hide_discovery; |
1652 | int radius = MIN_MON_RADIUS, hide_discovery; |
1683 | |
1653 | |
… | |
… | |
1690 | return 0; |
1660 | return 0; |
1691 | |
1661 | |
1692 | get_rangevector (op, enemy, rv, 0); |
1662 | get_rangevector (op, enemy, rv, 0); |
1693 | |
1663 | |
1694 | /* Monsters always ignore the DM */ |
1664 | /* Monsters always ignore the DM */ |
1695 | if ((op->type != PLAYER) && QUERY_FLAG (enemy, FLAG_WIZ)) |
1665 | if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) |
1696 | return 0; |
1666 | return 0; |
1697 | |
1667 | |
1698 | /* simple check. Should probably put some range checks in here. */ |
1668 | /* simple check. Should probably put some range checks in here. */ |
1699 | if (can_see_enemy (op, enemy)) |
1669 | if (can_see_enemy (op, enemy)) |
1700 | return 1; |
1670 | return 1; |
… | |
… | |
1713 | |
1683 | |
1714 | /* use this for invis also */ |
1684 | /* use this for invis also */ |
1715 | hide_discovery = op->stats.Int / 5; |
1685 | hide_discovery = op->stats.Int / 5; |
1716 | |
1686 | |
1717 | /* Determine Detection radii */ |
1687 | /* Determine Detection radii */ |
1718 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1688 | if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ |
1719 | radius = (op->stats.Wis / 5) + 1 > MIN_MON_RADIUS ? (op->stats.Wis / 5) + 1 : MIN_MON_RADIUS; |
1689 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); |
1720 | else |
1690 | else |
1721 | { /* a level/INT/Dex adjustment for hiding */ |
1691 | { /* a level/INT/Dex adjustment for hiding */ |
1722 | object *sk_hide; |
|
|
1723 | int bonus = (op->level / 2) + (op->stats.Int / 5); |
1692 | int bonus = op->level / 2 + op->stats.Int / 5; |
1724 | |
1693 | |
1725 | if (enemy->type == PLAYER) |
1694 | if (enemy->type == PLAYER) |
1726 | { |
1695 | { |
1727 | if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) |
1696 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1728 | bonus -= sk_hide->level; |
1697 | bonus -= sk_hide->level; |
1729 | else |
1698 | else |
1730 | { |
1699 | { |
1731 | LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); |
1700 | LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); |
1732 | make_visible (enemy); |
1701 | make_visible (enemy); |
… | |
… | |
1741 | } /* else creature has modifiers for hiding */ |
1710 | } /* else creature has modifiers for hiding */ |
1742 | |
1711 | |
1743 | /* Radii stealth adjustment. Only if you are stealthy |
1712 | /* Radii stealth adjustment. Only if you are stealthy |
1744 | * will you be able to sneak up closer to creatures */ |
1713 | * will you be able to sneak up closer to creatures */ |
1745 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1714 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1746 | radius = radius / 2, hide_discovery = hide_discovery / 3; |
1715 | { |
|
|
1716 | radius /= 2; |
|
|
1717 | hide_discovery /= 3; |
|
|
1718 | } |
1747 | |
1719 | |
1748 | /* Radii adjustment for enemy standing in the dark */ |
1720 | /* Radii adjustment for enemy standing in the dark */ |
1749 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1721 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1750 | { |
1722 | { |
1751 | /* on dark maps body heat can help indicate location with infravision |
1723 | /* on dark maps body heat can help indicate location with infravision |
… | |
… | |
1769 | * may have for their map - in that way, creatures at the edge will |
1741 | * may have for their map - in that way, creatures at the edge will |
1770 | * do something. Note that the distance field in the |
1742 | * do something. Note that the distance field in the |
1771 | * vector is real distance, so in theory this should be 18 to |
1743 | * vector is real distance, so in theory this should be 18 to |
1772 | * find that. |
1744 | * find that. |
1773 | */ |
1745 | */ |
1774 | if (radius > 13) |
1746 | // note that the above reasoning was utter bullshit even at the time it was written |
1775 | radius = 13; |
1747 | // we use 25, lets see if we have the cpu time for it |
|
|
1748 | radius = min (25, radius); |
1776 | |
1749 | |
1777 | /* Enemy in range! Now test for detection */ |
1750 | /* Enemy in range! Now test for detection */ |
1778 | if ((int) rv->distance <= radius) |
1751 | if (rv->distance <= radius) |
1779 | { |
1752 | { |
1780 | /* ah, we are within range, detected? take cases */ |
1753 | /* ah, we are within range, detected? take cases */ |
1781 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1754 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1782 | return 1; |
1755 | return 1; |
1783 | |
1756 | |
1784 | /* hidden or low-quality invisible */ |
1757 | /* hidden or low-quality invisible */ |
1785 | if (enemy->hide && (rv->distance <= 1) && (RANDOM () % 100 <= hide_discovery)) |
1758 | if (enemy->flag [FLAG_HIDDEN] && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1786 | { |
1759 | { |
1787 | make_visible (enemy); |
1760 | make_visible (enemy); |
|
|
1761 | |
1788 | /* inform players of new status */ |
1762 | /* inform players of new status */ |
1789 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1763 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1790 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
1764 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
|
|
1765 | |
1791 | return 1; /* detected enemy */ |
1766 | return 1; /* detected enemy */ |
1792 | } |
1767 | } |
1793 | else if (enemy->invisible) |
1768 | else if (enemy->invisible) |
1794 | { |
1769 | { |
1795 | /* Change this around - instead of negating the invisible, just |
1770 | /* Change this around - instead of negating the invisible, just |
1796 | * return true so that the mosnter that managed to detect you can |
1771 | * return true so that the monster that managed to detect you can |
1797 | * do something to you. Decreasing the duration of invisible |
1772 | * do something to you. Decreasing the duration of invisible |
1798 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1773 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1799 | * can then basically negate the spell. The spell isn't negated - |
1774 | * can then basically negate the spell. The spell isn't negated - |
1800 | * they just know where you are! |
1775 | * they just know where you are! |
1801 | */ |
1776 | */ |
1802 | if ((RANDOM () % 50) <= hide_discovery) |
1777 | if (rndm (50) <= hide_discovery) |
1803 | { |
1778 | { |
1804 | if (enemy->type == PLAYER) |
1779 | if (enemy->type == PLAYER) |
1805 | { |
|
|
1806 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1780 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1807 | } |
1781 | |
1808 | return 1; |
1782 | return 1; |
1809 | } |
1783 | } |
1810 | } |
1784 | } |
1811 | } /* within range */ |
1785 | } /* within range */ |
1812 | |
1786 | |
… | |
… | |
1817 | /* determine if op stands in a lighted square. This is not a very |
1791 | /* determine if op stands in a lighted square. This is not a very |
1818 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1792 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1819 | * is possible for a bright light to illuminate a player on the |
1793 | * is possible for a bright light to illuminate a player on the |
1820 | * other side of a wall (!). |
1794 | * other side of a wall (!). |
1821 | */ |
1795 | */ |
1822 | |
|
|
1823 | int |
1796 | int |
1824 | stand_in_light (object *op) |
1797 | stand_in_light (object *op) |
1825 | { |
1798 | { |
1826 | sint16 nx, ny; |
|
|
1827 | maptile *m; |
|
|
1828 | |
|
|
1829 | |
|
|
1830 | if (!op) |
1799 | if (!op) |
1831 | return 0; |
1800 | return 0; |
|
|
1801 | |
1832 | if (op->glow_radius > 0) |
1802 | if (op->glow_radius > 0) |
1833 | return 1; |
1803 | return 1; |
1834 | |
1804 | |
1835 | if (op->map) |
1805 | if (op->map) |
1836 | { |
1806 | { |
1837 | int x, y, x1, y1; |
|
|
1838 | |
|
|
1839 | |
|
|
1840 | |
|
|
1841 | /* Check the spaces with the max light radius to see if any of them |
1807 | /* Check the spaces with the max light radius to see if any of them |
1842 | * have lights, and if any of them light the player enough, then return 1. |
1808 | * have lights, and if any of them light the player enough, then return 1. |
1843 | */ |
1809 | */ |
1844 | for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
1810 | for (int x = op->x - MAX_LIGHT_RADIUS; x <= op->x + MAX_LIGHT_RADIUS; x++) |
1845 | { |
1811 | { |
1846 | for (y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
1812 | for (int y = op->y - MAX_LIGHT_RADIUS; y <= op->y + MAX_LIGHT_RADIUS; y++) |
1847 | { |
1813 | { |
1848 | m = op->map; |
1814 | maptile *m = op->map; |
1849 | nx = x; |
1815 | sint16 nx = x; |
1850 | ny = y; |
1816 | sint16 ny = y; |
1851 | |
1817 | |
1852 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1818 | if (xy_normalise (m, nx, ny)) |
1853 | continue; |
1819 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
1854 | |
|
|
1855 | x1 = abs (x - op->x) * abs (x - op->x); |
|
|
1856 | y1 = abs (y - op->y) * abs (y - op->y); |
|
|
1857 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
|
|
1858 | return 1; |
1820 | return 1; |
1859 | } |
1821 | } |
1860 | } |
1822 | } |
1861 | } |
1823 | } |
|
|
1824 | |
1862 | return 0; |
1825 | return 0; |
1863 | } |
1826 | } |
1864 | |
|
|
1865 | |
1827 | |
1866 | /* assuming no walls/barriers, lets check to see if its *possible* |
1828 | /* assuming no walls/barriers, lets check to see if its *possible* |
1867 | * to see an enemy. Note, "detection" is different from "seeing". |
1829 | * to see an enemy. Note, "detection" is different from "seeing". |
1868 | * See can_detect_enemy() for more details. -b.t. |
1830 | * See can_detect_enemy() for more details. -b.t. |
1869 | * return 0 if can't be seen, 1 if can be |
1831 | * return 0 if can't be seen, 1 if can be |
1870 | */ |
1832 | */ |
1871 | |
|
|
1872 | int |
1833 | int |
1873 | can_see_enemy (object *op, object *enemy) |
1834 | can_see_enemy (object *op, object *enemy) |
1874 | { |
1835 | { |
1875 | object *looker = op->head ? op->head : op; |
1836 | object *looker = op->head ? op->head : op; |
1876 | |
1837 | |
… | |
… | |
1892 | * However,if you carry any source of light, then the hidden |
1853 | * However,if you carry any source of light, then the hidden |
1893 | * creature is seeable (and stupid) */ |
1854 | * creature is seeable (and stupid) */ |
1894 | |
1855 | |
1895 | if (has_carried_lights (enemy)) |
1856 | if (has_carried_lights (enemy)) |
1896 | { |
1857 | { |
1897 | if (enemy->hide) |
1858 | if (enemy->flag [FLAG_HIDDEN]) |
1898 | { |
1859 | { |
1899 | make_visible (enemy); |
1860 | make_visible (enemy); |
1900 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1861 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1901 | } |
1862 | } |
|
|
1863 | |
1902 | return 1; |
1864 | return 1; |
1903 | } |
1865 | } |
1904 | else if (enemy->hide) |
1866 | else if (enemy->flag [FLAG_HIDDEN]) |
1905 | return 0; |
1867 | return 0; |
1906 | |
1868 | |
1907 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1869 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1908 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1870 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1909 | * and making it a conditional makes the code pretty ugly. |
1871 | * and making it a conditional makes the code pretty ugly. |
1910 | */ |
1872 | */ |
1911 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1873 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1912 | { |
|
|
1913 | if (makes_invisible_to (enemy, looker)) |
1874 | if (makes_invisible_to (enemy, looker)) |
1914 | return 0; |
1875 | return 0; |
1915 | } |
|
|
1916 | } |
1876 | } |
1917 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1877 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1918 | if (player_can_view (looker, enemy)) |
1878 | if (player_can_view (looker, enemy)) |
1919 | return 1; |
1879 | return 1; |
1920 | |
1880 | |
… | |
… | |
1931 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1891 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1932 | return 0; |
1892 | return 0; |
1933 | |
1893 | |
1934 | return 1; |
1894 | return 1; |
1935 | } |
1895 | } |
|
|
1896 | |