1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcsid_monster_c = |
3 | * static char *rcsid_monster_c = |
4 | * "$Id: monster.C,v 1.8 2006/09/10 15:59:57 root Exp $"; |
4 | * "$Id: monster.C,v 1.9 2006/09/14 17:10:25 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
175 | find_enemy (object *npc, rv_vector * rv) |
175 | find_enemy (object *npc, rv_vector * rv) |
176 | { |
176 | { |
177 | object *attacker, *tmp = NULL; |
177 | object *attacker, *tmp = NULL; |
178 | |
178 | |
179 | attacker = npc->attacked_by; /* save this for later use. This can be a attacker. */ |
179 | attacker = npc->attacked_by; /* save this for later use. This can be a attacker. */ |
180 | npc->attacked_by = NULL; /* always clear the attacker entry */ |
180 | npc->attacked_by = 0; /* always clear the attacker entry */ |
181 | |
181 | |
182 | /* if we berserk, we don't care about others - we attack all we can find */ |
182 | /* if we berserk, we don't care about others - we attack all we can find */ |
183 | if (QUERY_FLAG (npc, FLAG_BERSERK)) |
183 | if (QUERY_FLAG (npc, FLAG_BERSERK)) |
184 | { |
184 | { |
185 | tmp = find_nearest_living_creature (npc); |
185 | tmp = find_nearest_living_creature (npc); |
|
|
186 | |
186 | if (tmp) |
187 | if (tmp) |
187 | get_rangevector (npc, tmp, rv, 0); |
188 | get_rangevector (npc, tmp, rv, 0); |
188 | return tmp; |
189 | return tmp; |
189 | } |
190 | } |
190 | |
191 | |
… | |
… | |
200 | |
201 | |
201 | /* pet move */ |
202 | /* pet move */ |
202 | if ((npc->attack_movement & HI4) == PETMOVE) |
203 | if ((npc->attack_movement & HI4) == PETMOVE) |
203 | { |
204 | { |
204 | tmp = get_pet_enemy (npc, rv); |
205 | tmp = get_pet_enemy (npc, rv); |
|
|
206 | |
205 | if (tmp) |
207 | if (tmp) |
206 | get_rangevector (npc, tmp, rv, 0); |
208 | get_rangevector (npc, tmp, rv, 0); |
|
|
209 | |
207 | return tmp; |
210 | return tmp; |
208 | } |
211 | } |
209 | |
212 | |
210 | /* we check our old enemy. */ |
213 | /* we check our old enemy. */ |
211 | if ((tmp = check_enemy (npc, rv)) == NULL) |
214 | if (!(tmp = check_enemy (npc, rv))) |
212 | { |
215 | { |
213 | if (attacker) /* if we have an attacker, check him */ |
216 | if (attacker) /* if we have an attacker, check him */ |
214 | { |
217 | { |
215 | /* we want be sure this is the right one! */ |
218 | /* TODO: thats not finished */ |
216 | if (attacker->count == npc->attacked_by_count) |
219 | /* we don't want a fight evil vs evil or good against non evil */ |
|
|
220 | |
|
|
221 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
|
|
222 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
|
|
223 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
|
|
224 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
|
|
225 | else if (on_same_map (npc, attacker)) /* thats the only thing we must know... */ |
217 | { |
226 | { |
218 | /* TODO: thats not finished */ |
|
|
219 | /* we don't want a fight evil vs evil or good against non evil */ |
|
|
220 | |
|
|
221 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
|
|
222 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
|
|
223 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
|
|
224 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
|
|
225 | else if (on_same_map (npc, attacker)) /* thats the only thing we must know... */ |
|
|
226 | { |
|
|
227 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
227 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
228 | npc->enemy = attacker; |
228 | npc->enemy = attacker; |
229 | return attacker; /* yes, we face our attacker! */ |
229 | return attacker; /* yes, we face our attacker! */ |
230 | } |
|
|
231 | } |
230 | } |
232 | } |
231 | } |
233 | |
232 | |
234 | /* we have no legal enemy or attacker, so we try to target a new one */ |
233 | /* we have no legal enemy or attacker, so we try to target a new one */ |
235 | if (!QUERY_FLAG (npc, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (npc, FLAG_FRIENDLY) && !QUERY_FLAG (npc, FLAG_NEUTRAL)) |
234 | if (!QUERY_FLAG (npc, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (npc, FLAG_FRIENDLY) && !QUERY_FLAG (npc, FLAG_NEUTRAL)) |
… | |
… | |
326 | oph = oph->head; |
325 | oph = oph->head; |
327 | |
326 | |
328 | if (QUERY_FLAG (op, FLAG_NO_ATTACK)) /* we never ever attack */ |
327 | if (QUERY_FLAG (op, FLAG_NO_ATTACK)) /* we never ever attack */ |
329 | enemy = op->enemy = NULL; |
328 | enemy = op->enemy = NULL; |
330 | else if ((enemy = find_enemy (op, &rv))) |
329 | else if ((enemy = find_enemy (op, &rv))) |
331 | { |
|
|
332 | /* we have an enemy, just tell him we want him dead */ |
330 | /* we have an enemy, just tell him we want him dead */ |
333 | enemy->attacked_by = op; /* our ptr */ |
331 | enemy->attacked_by = op; /* our ptr */ |
334 | enemy->attacked_by_count = op->count; /* our tag */ |
|
|
335 | } |
|
|
336 | |
332 | |
337 | /* generate hp, if applicable */ |
333 | /* generate hp, if applicable */ |
338 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
334 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
339 | { |
335 | { |
340 | |
336 | |