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.20 by pippijn, Sat Jan 6 14:42:31 2007 UTC vs.
Revision 1.21 by root, Sun Jan 14 23:35:04 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines