1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
8 | 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 |
… | |
… | |
20 | |
21 | |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #ifndef __CEXTRACT__ |
|
|
26 | # include <sproto.h> |
26 | #include <sproto.h> |
27 | # include <spells.h> |
27 | #include <spells.h> |
28 | # include <skills.h> |
28 | #include <skills.h> |
29 | #endif |
|
|
30 | |
|
|
31 | |
29 | |
32 | #define MIN_MON_RADIUS 3 /* minimum monster detection radius */ |
30 | #define MIN_MON_RADIUS 3 /* minimum monster detection radius */ |
33 | |
|
|
34 | |
31 | |
35 | /* checks npc->enemy and returns that enemy if still valid, |
32 | /* checks npc->enemy and returns that enemy if still valid, |
36 | * NULL otherwise. |
33 | * NULL otherwise. |
37 | * this is map tile aware. |
34 | * this is map tile aware. |
38 | * If this returns an enemy, the range vector rv should also be |
35 | * If this returns an enemy, the range vector rv should also be |
… | |
… | |
116 | find_nearest_living_creature (object *npc) |
113 | find_nearest_living_creature (object *npc) |
117 | { |
114 | { |
118 | int i, mflags; |
115 | int i, mflags; |
119 | sint16 nx, ny; |
116 | sint16 nx, ny; |
120 | maptile *m; |
117 | maptile *m; |
121 | object *tmp; |
|
|
122 | int search_arr[SIZEOFFREE]; |
118 | int search_arr[SIZEOFFREE]; |
123 | |
119 | |
124 | get_search_arr (search_arr); |
120 | get_search_arr (search_arr); |
|
|
121 | |
125 | for (i = 0; i < SIZEOFFREE; i++) |
122 | for (i = 0; i < SIZEOFFREE; i++) |
126 | { |
123 | { |
127 | /* modified to implement smart searching using search_arr |
124 | /* modified to implement smart searching using search_arr |
128 | * guidance array to determine direction of search order |
125 | * guidance array to determine direction of search order |
129 | */ |
126 | */ |
130 | nx = npc->x + freearr_x[search_arr[i]]; |
127 | nx = npc->x + freearr_x[search_arr[i]]; |
131 | ny = npc->y + freearr_y[search_arr[i]]; |
128 | ny = npc->y + freearr_y[search_arr[i]]; |
132 | m = npc->map; |
129 | m = npc->map; |
133 | |
130 | |
134 | mflags = get_map_flags (m, &m, nx, ny, &nx, &ny); |
131 | mflags = get_map_flags (m, &m, nx, ny, &nx, &ny); |
|
|
132 | |
135 | if (mflags & P_OUT_OF_MAP) |
133 | if (mflags & P_OUT_OF_MAP) |
136 | continue; |
134 | continue; |
137 | |
135 | |
138 | if (mflags & P_IS_ALIVE) |
136 | if (mflags & P_IS_ALIVE) |
139 | { |
137 | { |
140 | tmp = GET_MAP_OB (m, nx, ny); |
138 | for (object *tmp = m->at (nx, ny).top; tmp; tmp = tmp->below) |
141 | while (tmp != NULL && !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR) && tmp->type != PLAYER) |
139 | if (tmp->flag [FLAG_MONSTER] || tmp->flag [FLAG_GENERATOR] || tmp->type == PLAYER) |
142 | tmp = tmp->above; |
|
|
143 | |
|
|
144 | if (!tmp) |
|
|
145 | { |
|
|
146 | LOG (llevDebug, "find_nearest_living_creature: map %s (%d,%d) has is_alive set but did not find a monster?\n", |
|
|
147 | m->path, nx, ny); |
|
|
148 | } |
|
|
149 | else |
|
|
150 | { |
|
|
151 | if (can_see_monsterP (m, nx, ny, i)) |
140 | if (can_see_monsterP (m, nx, ny, i)) |
152 | return tmp; |
141 | return tmp; |
153 | } |
142 | } |
154 | } /* is something living on this space */ |
|
|
155 | } |
143 | } |
156 | return NULL; /* nothing found */ |
144 | |
|
|
145 | return 0; |
157 | } |
146 | } |
158 | |
147 | |
159 | |
148 | |
160 | /* Tries to find an enmy for npc. We pass the range vector since |
149 | /* Tries to find an enmy for npc. We pass the range vector since |
161 | * our caller will find the information useful. |
150 | * our caller will find the information useful. |
… | |
… | |
987 | { |
976 | { |
988 | if (wand->arch) |
977 | if (wand->arch) |
989 | { |
978 | { |
990 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
979 | CLEAR_FLAG (wand, FLAG_ANIMATE); |
991 | wand->face = wand->arch->clone.face; |
980 | wand->face = wand->arch->clone.face; |
992 | wand->speed = 0; |
981 | wand->set_speed (0); |
993 | update_ob_speed (wand); |
|
|
994 | } |
982 | } |
995 | } |
983 | } |
996 | /* Success */ |
984 | /* Success */ |
997 | return 1; |
985 | return 1; |
998 | } |
986 | } |