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 |
… | |
… | |
112 | find_nearest_living_creature (object *npc) |
113 | find_nearest_living_creature (object *npc) |
113 | { |
114 | { |
114 | int i, mflags; |
115 | int i, mflags; |
115 | sint16 nx, ny; |
116 | sint16 nx, ny; |
116 | maptile *m; |
117 | maptile *m; |
117 | object *tmp; |
|
|
118 | int search_arr[SIZEOFFREE]; |
118 | int search_arr[SIZEOFFREE]; |
119 | |
119 | |
120 | get_search_arr (search_arr); |
120 | get_search_arr (search_arr); |
|
|
121 | |
121 | for (i = 0; i < SIZEOFFREE; i++) |
122 | for (i = 0; i < SIZEOFFREE; i++) |
122 | { |
123 | { |
123 | /* modified to implement smart searching using search_arr |
124 | /* modified to implement smart searching using search_arr |
124 | * guidance array to determine direction of search order |
125 | * guidance array to determine direction of search order |
125 | */ |
126 | */ |
126 | nx = npc->x + freearr_x[search_arr[i]]; |
127 | nx = npc->x + freearr_x[search_arr[i]]; |
127 | ny = npc->y + freearr_y[search_arr[i]]; |
128 | ny = npc->y + freearr_y[search_arr[i]]; |
128 | m = npc->map; |
129 | m = npc->map; |
129 | |
130 | |
130 | mflags = get_map_flags (m, &m, nx, ny, &nx, &ny); |
131 | mflags = get_map_flags (m, &m, nx, ny, &nx, &ny); |
|
|
132 | |
131 | if (mflags & P_OUT_OF_MAP) |
133 | if (mflags & P_OUT_OF_MAP) |
132 | continue; |
134 | continue; |
133 | |
135 | |
134 | if (mflags & P_IS_ALIVE) |
136 | if (mflags & P_IS_ALIVE) |
135 | { |
137 | { |
136 | tmp = GET_MAP_OB (m, nx, ny); |
138 | for (object *tmp = m->at (nx, ny).top; tmp; tmp = tmp->below) |
137 | 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) |
138 | tmp = tmp->above; |
|
|
139 | |
|
|
140 | if (!tmp) |
|
|
141 | { |
|
|
142 | LOG (llevDebug, "find_nearest_living_creature: map %s (%d,%d) has is_alive set but did not find a monster?\n", |
|
|
143 | &m->path, nx, ny); |
|
|
144 | } |
|
|
145 | else |
|
|
146 | { |
|
|
147 | if (can_see_monsterP (m, nx, ny, i)) |
140 | if (can_see_monsterP (m, nx, ny, i)) |
148 | return tmp; |
141 | return tmp; |
149 | } |
142 | } |
150 | } /* is something living on this space */ |
|
|
151 | } |
143 | } |
152 | return NULL; /* nothing found */ |
144 | |
|
|
145 | return 0; |
153 | } |
146 | } |
154 | |
147 | |
155 | |
148 | |
156 | /* 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 |
157 | * our caller will find the information useful. |
150 | * our caller will find the information useful. |