ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/monster.C
(Generate patch)

Comparing deliantra/server/server/monster.C (file contents):
Revision 1.30 by root, Mon May 7 03:05:58 2007 UTC vs.
Revision 1.45 by root, Sun Nov 16 03:52:13 2008 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 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.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
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>
92 && npc->enemy->type != PLAYER 91 && npc->enemy->type != PLAYER
93 && npc->enemy->type != GOLEM) 92 && npc->enemy->type != GOLEM)
94 npc->enemy = NULL; 93 npc->enemy = NULL;
95 94
96 } 95 }
96
97 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; 97 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL;
98} 98}
99 99
100/* Returns the nearest living creature (monster or generator). 100/* Returns the nearest living creature (monster or generator).
101 * Modified to deal with tiled maps properly. 101 * Modified to deal with tiled maps properly.
145 } 145 }
146 146
147 return 0; 147 return 0;
148} 148}
149 149
150
151/* 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
152 * our caller will find the information useful. 151 * our caller will find the information useful.
153 * Currently, only move_monster calls this function. 152 * Currently, only move_monster calls this function.
154 * Fix function so that we always make calls to get_rangevector 153 * Fix function so that we always make calls to get_rangevector
155 * 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
156 * many cases. 155 * many cases.
157 */ 156 */
158
159object * 157object *
160find_enemy (object *npc, rv_vector * rv) 158find_enemy (object *npc, rv_vector * rv)
161{ 159{
162 object *attacker, *tmp = NULL; 160 object *attacker, *tmp = NULL;
163 161
169 { 167 {
170 tmp = find_nearest_living_creature (npc); 168 tmp = find_nearest_living_creature (npc);
171 169
172 if (tmp) 170 if (tmp)
173 get_rangevector (npc, tmp, rv, 0); 171 get_rangevector (npc, tmp, rv, 0);
172
174 return tmp; 173 return tmp;
175 } 174 }
176 175
177 /* Here is the main enemy selection. 176 /* Here is the main enemy selection.
178 * 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
231/* Sees if this monster should wake up. 230/* Sees if this monster should wake up.
232 * Currently, this is only called from move_monster, and 231 * Currently, this is only called from move_monster, and
233 * if enemy is set, then so should be rv. 232 * if enemy is set, then so should be rv.
234 * returns 1 if the monster should wake up, 0 otherwise. 233 * returns 1 if the monster should wake up, 0 otherwise.
235 */ 234 */
236
237int 235int
238check_wakeup (object *op, object *enemy, rv_vector * rv) 236check_wakeup (object *op, object *enemy, rv_vector * rv)
239{ 237{
240 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;
241 239
289} 287}
290 288
291/* 289/*
292 * Move-monster returns 1 if the object has been freed, otherwise 0. 290 * Move-monster returns 1 if the object has been freed, otherwise 0.
293 */ 291 */
294
295int 292int
296move_monster (object *op) 293move_monster (object *op)
297{ 294{
298 int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */ 295 int dir, diff, pre_att_dir; /* elmex: pre_att_dir remembers the direction before attack movement */
299 object *owner, *enemy, *part, *oph = op; 296 object *owner, *enemy, *part, *oph = op;
375 if (!check_wakeup (op, enemy, &rv)) 372 if (!check_wakeup (op, enemy, &rv))
376 return 0; 373 return 0;
377 } 374 }
378 375
379 /* check if monster pops out of hidden spot */ 376 /* check if monster pops out of hidden spot */
380 if (op->hide) 377 if (op->flag [FLAG_HIDDEN])
381 do_hidden_move (op); 378 do_hidden_move (op);
382 379
383 if (op->pick_up) 380 if (op->pick_up)
384 monster_check_pickup (op); 381 monster_check_pickup (op);
385 382
389 /* If we don't have an enemy, do special movement or the like */ 386 /* If we don't have an enemy, do special movement or the like */
390 if (!enemy) 387 if (!enemy)
391 { 388 {
392 if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) 389 if (QUERY_FLAG (op, FLAG_ONLY_ATTACK))
393 { 390 {
394 op->destroy (); 391 op->drop_and_destroy ();
395 return 1; 392 return 1;
396 } 393 }
397 394
398 /* Probably really a bug for a creature to have both 395 /* Probably really a bug for a creature to have both
399 * stand still and a movement type set. 396 * stand still and a movement type set.
490 /* hm, not sure about this part - in original was a scared flag here too 487 /* hm, not sure about this part - in original was a scared flag here too
491 * but that we test above... so can be old code here 488 * but that we test above... so can be old code here
492 */ 489 */
493 if (QUERY_FLAG (op, FLAG_RUN_AWAY)) 490 if (QUERY_FLAG (op, FLAG_RUN_AWAY))
494 dir = absdir (dir + 4); 491 dir = absdir (dir + 4);
492
495 if (QUERY_FLAG (op, FLAG_CONFUSED)) 493 if (QUERY_FLAG (op, FLAG_CONFUSED))
496 dir = absdir (dir + rndm (3) + rndm (3) - 2); 494 dir = absdir (dir + rndm (3) + rndm (3) - 2);
497 495
498 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) 496 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3)))
499 {
500 if (monster_cast_spell (op, part, enemy, dir, &rv1)) 497 if (monster_cast_spell (op, part, enemy, dir, &rv1))
501 return 0; 498 return 0;
502 }
503 499
504 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) 500 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3)))
505 {
506 if (monster_use_scroll (op, part, enemy, dir, &rv1)) 501 if (monster_use_scroll (op, part, enemy, dir, &rv1))
507 return 0; 502 return 0;
508 }
509 503
510 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) 504 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3)))
511 {
512 if (monster_use_range (op, part, enemy, dir)) 505 if (monster_use_range (op, part, enemy, dir))
513 return 0; 506 return 0;
514 } 507
515 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) 508 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3)))
516 {
517 if (monster_use_skill (op, rv.part, enemy, rv.direction)) 509 if (monster_use_skill (op, rv.part, enemy, rv.direction))
518 return 0; 510 return 0;
519 } 511
520 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) 512 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2)))
521 {
522 if (monster_use_bow (op, part, enemy, dir)) 513 if (monster_use_bow (op, part, enemy, dir))
523 return 0; 514 return 0;
524 }
525 } /* for processing of all parts */ 515 } /* for processing of all parts */
526 } /* If not scared */ 516 } /* If not scared */
527 517
528 518
529 part = rv.part; 519 part = rv.part;
660 if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ 650 if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */
661 return 1; 651 return 1;
662 652
663 if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) 653 if (QUERY_FLAG (op, FLAG_ONLY_ATTACK))
664 { 654 {
665 op->remove ();
666 op->destroy (); 655 op->drop_and_destroy ();
667 return 1; 656 return 1;
668 } 657 }
658
669 return 0; 659 return 0;
670} 660}
671 661
672int 662int
673can_hit (object *ob1, object *ob2, rv_vector * rv) 663can_hit (object *ob1, object *ob2, rv_vector * rv)
960 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 950 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
961 951
962 if (dirdiff (dir, dir2) < 2) 952 if (dirdiff (dir, dir2) < 2)
963 return 0; /* Might hit owner with spell */ 953 return 0; /* Might hit owner with spell */
964 } 954 }
955
965 if (QUERY_FLAG (head, FLAG_CONFUSED)) 956 if (QUERY_FLAG (head, FLAG_CONFUSED))
966 dir = absdir (dir + rndm (3) + rndm (3) - 2); 957 dir = absdir (dir + rndm (3) + rndm (3) - 2);
967 958
968 for (wand = head->inv; wand; wand = wand->below) 959 for (wand = head->inv; wand; wand = wand->below)
969 { 960 {
979 if (!(--wand->stats.food)) 970 if (!(--wand->stats.food))
980 { 971 {
981 if (wand->arch) 972 if (wand->arch)
982 { 973 {
983 CLEAR_FLAG (wand, FLAG_ANIMATE); 974 CLEAR_FLAG (wand, FLAG_ANIMATE);
984 wand->face = wand->arch->clone.face; 975 wand->face = wand->arch->face;
985 wand->set_speed (0); 976 wand->set_speed (0);
986 } 977 }
987 } 978 }
988 /* Success */ 979 /* Success */
989 return 1; 980 return 1;
1008 } 999 }
1009 1000
1010 if (at_least_one) 1001 if (at_least_one)
1011 return 0; 1002 return 0;
1012 1003
1013 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANG() without wand/horn/rod.\n", &head->name, head->count); 1004 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count);
1014 CLEAR_FLAG (head, FLAG_READY_RANGE); 1005 CLEAR_FLAG (head, FLAG_READY_RANGE);
1015 return 0; 1006 return 0;
1016} 1007}
1017 1008
1018int 1009int
1020{ 1011{
1021 object *owner; 1012 object *owner;
1022 1013
1023 if (!(dir = path_to_player (part, pl, 0))) 1014 if (!(dir = path_to_player (part, pl, 0)))
1024 return 0; 1015 return 0;
1016
1025 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1017 if (QUERY_FLAG (head, FLAG_CONFUSED))
1026 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1018 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1027 1019
1028 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1020 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL)
1029 { 1021 {
1037 return fire_bow (head, part, NULL, dir, 0, part->x, part->y); 1029 return fire_bow (head, part, NULL, dir, 0, part->x, part->y);
1038 1030
1039} 1031}
1040 1032
1041/* Checks if putting on 'item' will make 'who' do more 1033/* Checks if putting on 'item' will make 'who' do more
1042 * damage. This is a very simplistic check - also checking things 1034 * damage. This is a very simplistic check - also checking things
1043 * like speed and ac are also relevant. 1035 * like speed and ac are also relevant.
1044 * 1036 *
1045 * return true if item is a better object. 1037 * return true if item is a better object.
1046 */ 1038 */
1047
1048int 1039int
1049check_good_weapon (object *who, object *item) 1040check_good_weapon (object *who, object *item)
1050{ 1041{
1051 object *other_weap; 1042 object *other_weap;
1052 int val = 0, i; 1043 int val = 0, i;
1053 1044
1054 for (other_weap = who->inv; other_weap != NULL; other_weap = other_weap->below) 1045 for (other_weap = who->inv; other_weap; other_weap = other_weap->below)
1055 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) 1046 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED))
1056 break; 1047 break;
1057 1048
1058 if (other_weap == NULL) /* No other weapons */ 1049 if (!other_weap) /* No other weapons */
1059 return 1; 1050 return 1;
1060 1051
1061 /* Rather than go through and apply the new one, and see if it is 1052 /* Rather than go through and apply the new one, and see if it is
1062 * better, just do some simple checks 1053 * better, just do some simple checks
1063 * Put some multipliers for things that hvae several effects, 1054 * Put some multipliers for things that hvae several effects,
1068 val += (item->magic - other_weap->magic) * 3; 1059 val += (item->magic - other_weap->magic) * 3;
1069 /* Monsters don't really get benefits from things like regen rates 1060 /* Monsters don't really get benefits from things like regen rates
1070 * from items. But the bonus for their stats are very important. 1061 * from items. But the bonus for their stats are very important.
1071 */ 1062 */
1072 for (i = 0; i < NUM_STATS; i++) 1063 for (i = 0; i < NUM_STATS; i++)
1073 val += (get_attr_value (&item->stats, i) - get_attr_value (&other_weap->stats, i)) * 2; 1064 val += item->stats.stat (i) - other_weap->stats.stat (i) * 2;
1074 1065
1075 if (val > 0) 1066 if (val > 0)
1076 return 1; 1067 return 1;
1077 else 1068 else
1078 return 0; 1069 return 0;
1082check_good_armour (object *who, object *item) 1073check_good_armour (object *who, object *item)
1083{ 1074{
1084 object *other_armour; 1075 object *other_armour;
1085 int val = 0, i; 1076 int val = 0, i;
1086 1077
1087 for (other_armour = who->inv; other_armour != NULL; other_armour = other_armour->below) 1078 for (other_armour = who->inv; other_armour; other_armour = other_armour->below)
1088 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) 1079 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED))
1089 break; 1080 break;
1090 1081
1091 if (other_armour == NULL) /* No other armour, use the new */ 1082 if (other_armour == NULL) /* No other armour, use the new */
1092 return 1; 1083 return 1;
1214 case ROD: 1205 case ROD:
1215 flag = QUERY_FLAG (monster, FLAG_USE_RANGE); 1206 flag = QUERY_FLAG (monster, FLAG_USE_RANGE);
1216 break; 1207 break;
1217 1208
1218 case SPELLBOOK: 1209 case SPELLBOOK:
1219 flag = (monster->arch != NULL && QUERY_FLAG ((&monster->arch->clone), FLAG_CAST_SPELL)); 1210 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL);
1220 break; 1211 break;
1221 1212
1222 case SCROLL: 1213 case SCROLL:
1223 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); 1214 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL);
1224 break; 1215 break;
1293void 1284void
1294monster_check_apply (object *mon, object *item) 1285monster_check_apply (object *mon, object *item)
1295{ 1286{
1296 int flag = 0; 1287 int flag = 0;
1297 1288
1298 if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) 1289 if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG (mon->arch, FLAG_CAST_SPELL)))
1299 { 1290 {
1300 SET_FLAG (mon, FLAG_CAST_SPELL); 1291 SET_FLAG (mon, FLAG_CAST_SPELL);
1301 return; 1292 return;
1302 } 1293 }
1303 1294
1675 * properly. I also so odd code in place that checked for x distance 1666 * properly. I also so odd code in place that checked for x distance
1676 * OR y distance being within some range - that seemed wrong - both should 1667 * OR y distance being within some range - that seemed wrong - both should
1677 * be within the valid range. MSW 2001-08-05 1668 * be within the valid range. MSW 2001-08-05
1678 * Returns 0 if enemy can not be detected, 1 if it is detected 1669 * Returns 0 if enemy can not be detected, 1 if it is detected
1679 */ 1670 */
1680
1681int 1671int
1682can_detect_enemy (object *op, object *enemy, rv_vector * rv) 1672can_detect_enemy (object *op, object *enemy, rv_vector * rv)
1683{ 1673{
1684 int radius = MIN_MON_RADIUS, hide_discovery; 1674 int radius = MIN_MON_RADIUS, hide_discovery;
1685 1675
1715 1705
1716 /* use this for invis also */ 1706 /* use this for invis also */
1717 hide_discovery = op->stats.Int / 5; 1707 hide_discovery = op->stats.Int / 5;
1718 1708
1719 /* Determine Detection radii */ 1709 /* Determine Detection radii */
1720 if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ 1710 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */
1721 radius = (op->stats.Wis / 5) + 1 > MIN_MON_RADIUS ? (op->stats.Wis / 5) + 1 : MIN_MON_RADIUS; 1711 radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1);
1722 else 1712 else
1723 { /* a level/INT/Dex adjustment for hiding */ 1713 { /* a level/INT/Dex adjustment for hiding */
1724 object *sk_hide;
1725 int bonus = (op->level / 2) + (op->stats.Int / 5); 1714 int bonus = op->level / 2 + op->stats.Int / 5;
1726 1715
1727 if (enemy->type == PLAYER) 1716 if (enemy->type == PLAYER)
1728 { 1717 {
1729 if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) 1718 if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING))
1730 bonus -= sk_hide->level; 1719 bonus -= sk_hide->level;
1731 else 1720 else
1732 { 1721 {
1733 LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); 1722 LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n");
1734 make_visible (enemy); 1723 make_visible (enemy);
1743 } /* else creature has modifiers for hiding */ 1732 } /* else creature has modifiers for hiding */
1744 1733
1745 /* Radii stealth adjustment. Only if you are stealthy 1734 /* Radii stealth adjustment. Only if you are stealthy
1746 * will you be able to sneak up closer to creatures */ 1735 * will you be able to sneak up closer to creatures */
1747 if (QUERY_FLAG (enemy, FLAG_STEALTH)) 1736 if (QUERY_FLAG (enemy, FLAG_STEALTH))
1748 radius = radius / 2, hide_discovery = hide_discovery / 3; 1737 {
1738 radius /= 2;
1739 hide_discovery /= 3;
1740 }
1749 1741
1750 /* Radii adjustment for enemy standing in the dark */ 1742 /* Radii adjustment for enemy standing in the dark */
1751 if (op->map->darkness > 0 && !stand_in_light (enemy)) 1743 if (op->map->darkness > 0 && !stand_in_light (enemy))
1752 { 1744 {
1753 /* on dark maps body heat can help indicate location with infravision 1745 /* on dark maps body heat can help indicate location with infravision
1771 * may have for their map - in that way, creatures at the edge will 1763 * may have for their map - in that way, creatures at the edge will
1772 * do something. Note that the distance field in the 1764 * do something. Note that the distance field in the
1773 * vector is real distance, so in theory this should be 18 to 1765 * vector is real distance, so in theory this should be 18 to
1774 * find that. 1766 * find that.
1775 */ 1767 */
1776 if (radius > 13) 1768 // note that the above reasoning was utter bullshit even at the time it was written
1777 radius = 13; 1769 // we use 25, lets see if we have the cpu time for it
1770 radius = min (25, radius);
1778 1771
1779 /* Enemy in range! Now test for detection */ 1772 /* Enemy in range! Now test for detection */
1780 if ((int) rv->distance <= radius) 1773 if (rv->distance <= radius)
1781 { 1774 {
1782 /* ah, we are within range, detected? take cases */ 1775 /* ah, we are within range, detected? take cases */
1783 if (!enemy->invisible) /* enemy in dark squares... are seen! */ 1776 if (!enemy->invisible) /* enemy in dark squares... are seen! */
1784 return 1; 1777 return 1;
1785 1778
1786 /* hidden or low-quality invisible */ 1779 /* hidden or low-quality invisible */
1787 if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery)) 1780 if (enemy->flag [FLAG_HIDDEN] && rv->distance <= 1 && rndm (100) <= hide_discovery)
1788 { 1781 {
1789 make_visible (enemy); 1782 make_visible (enemy);
1783
1790 /* inform players of new status */ 1784 /* inform players of new status */
1791 if (enemy->type == PLAYER && player_can_view (enemy, op)) 1785 if (enemy->type == PLAYER && player_can_view (enemy, op))
1792 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); 1786 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name);
1787
1793 return 1; /* detected enemy */ 1788 return 1; /* detected enemy */
1794 } 1789 }
1795 else if (enemy->invisible) 1790 else if (enemy->invisible)
1796 { 1791 {
1797 /* Change this around - instead of negating the invisible, just 1792 /* Change this around - instead of negating the invisible, just
1798 * return true so that the mosnter that managed to detect you can 1793 * return true so that the monster that managed to detect you can
1799 * do something to you. Decreasing the duration of invisible 1794 * do something to you. Decreasing the duration of invisible
1800 * doesn't make a lot of sense IMO, as a bunch of stupid creatures 1795 * doesn't make a lot of sense IMO, as a bunch of stupid creatures
1801 * can then basically negate the spell. The spell isn't negated - 1796 * can then basically negate the spell. The spell isn't negated -
1802 * they just know where you are! 1797 * they just know where you are!
1803 */ 1798 */
1804 if ((rndm (50)) <= hide_discovery) 1799 if (rndm (50) <= hide_discovery)
1805 { 1800 {
1806 if (enemy->type == PLAYER) 1801 if (enemy->type == PLAYER)
1807 {
1808 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); 1802 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op));
1809 } 1803
1810 return 1; 1804 return 1;
1811 } 1805 }
1812 } 1806 }
1813 } /* within range */ 1807 } /* within range */
1814 1808
1822 * other side of a wall (!). 1816 * other side of a wall (!).
1823 */ 1817 */
1824int 1818int
1825stand_in_light (object *op) 1819stand_in_light (object *op)
1826{ 1820{
1827 sint16 nx, ny;
1828 maptile *m;
1829
1830 if (!op) 1821 if (!op)
1831 return 0; 1822 return 0;
1832 1823
1833 if (op->glow_radius > 0) 1824 if (op->glow_radius > 0)
1834 return 1; 1825 return 1;
1835 1826
1836 if (op->map) 1827 if (op->map)
1837 { 1828 {
1838 int x, y, x1, y1;
1839
1840 /* Check the spaces with the max light radius to see if any of them 1829 /* Check the spaces with the max light radius to see if any of them
1841 * have lights, and if any of them light the player enough, then return 1. 1830 * have lights, and if any of them light the player enough, then return 1.
1842 */ 1831 */
1843 for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) 1832 for (int x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++)
1844 { 1833 {
1845 for (y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) 1834 for (int y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++)
1846 { 1835 {
1847 m = op->map; 1836 maptile *m = op->map;
1848 nx = x; 1837 sint16 nx = x;
1849 ny = y; 1838 sint16 ny = y;
1850 1839
1851 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) 1840 if (xy_normalise (m, nx, ny))
1852 continue; 1841 if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light)
1853
1854 x1 = abs (x - op->x) * abs (x - op->x);
1855 y1 = abs (y - op->y) * abs (y - op->y);
1856 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny))
1857 return 1; 1842 return 1;
1858 } 1843 }
1859 } 1844 }
1860 } 1845 }
1861 1846
1862 return 0; 1847 return 0;
1890 * However,if you carry any source of light, then the hidden 1875 * However,if you carry any source of light, then the hidden
1891 * creature is seeable (and stupid) */ 1876 * creature is seeable (and stupid) */
1892 1877
1893 if (has_carried_lights (enemy)) 1878 if (has_carried_lights (enemy))
1894 { 1879 {
1895 if (enemy->hide) 1880 if (enemy->flag [FLAG_HIDDEN])
1896 { 1881 {
1897 make_visible (enemy); 1882 make_visible (enemy);
1898 new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); 1883 new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!");
1899 } 1884 }
1885
1900 return 1; 1886 return 1;
1901 } 1887 }
1902 else if (enemy->hide) 1888 else if (enemy->flag [FLAG_HIDDEN])
1903 return 0; 1889 return 0;
1904 1890
1905 /* Invisible enemy. Break apart the check for invis undead/invis looker 1891 /* Invisible enemy. Break apart the check for invis undead/invis looker
1906 * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, 1892 * into more simple checks - the QUERY_FLAG doesn't return 1/0 values,
1907 * and making it a conditional makes the code pretty ugly. 1893 * and making it a conditional makes the code pretty ugly.
1908 */ 1894 */
1909 if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) 1895 if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE))
1910 {
1911 if (makes_invisible_to (enemy, looker)) 1896 if (makes_invisible_to (enemy, looker))
1912 return 0; 1897 return 0;
1913 }
1914 } 1898 }
1915 else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ 1899 else if (looker->type == PLAYER) /* for players, a (possible) shortcut */
1916 if (player_can_view (looker, enemy)) 1900 if (player_can_view (looker, enemy))
1917 return 1; 1901 return 1;
1918 1902
1929 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) 1913 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS)))
1930 return 0; 1914 return 0;
1931 1915
1932 return 1; 1916 return 1;
1933} 1917}
1918

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines