… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * 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 Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
… | |
… | |
46 | npc->enemy = NULL; |
47 | npc->enemy = NULL; |
47 | else if (npc->enemy == NULL) |
48 | else if (npc->enemy == NULL) |
48 | npc->enemy = npc->owner->enemy; |
49 | npc->enemy = npc->owner->enemy; |
49 | } |
50 | } |
50 | |
51 | |
51 | /* periodically, a monster mayu change its target. Also, if the object |
52 | /* periodically, a monster may change its target. Also, if the object |
52 | * has been destroyed, etc, clear the enemy. |
53 | * has been destroyed, etc, clear the enemy. |
53 | * TODO: this should be changed, because it invokes to attack forced or |
54 | * TODO: this should be changed, because it invokes to attack forced or |
54 | * attacked monsters to leave the attacker alone, before it is destroyed |
55 | * attacked monsters to leave the attacker alone, before it is destroyed |
55 | */ |
56 | */ |
56 | /* i had removed the random target leave, this invokes problems with friendly |
57 | /* I had removed the random target leave, this invokes problems with friendly |
57 | * objects, getting attacked and defending herself - they don't try to attack |
58 | * objects, getting attacked and defending herself - they don't try to attack |
58 | * again then but perhaps get attack on and on |
59 | * again then but perhaps get attack on and on |
59 | * If we include a aggravated flag in , we can handle evil vs evil and good vs good |
60 | * If we include a aggravated flag in , we can handle evil vs evil and good vs good |
60 | * too. */ |
61 | * too. */ |
61 | |
62 | |
… | |
… | |
65 | * the grouping checks are. Code is the same. |
66 | * the grouping checks are. Code is the same. |
66 | */ |
67 | */ |
67 | if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || |
68 | if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || |
68 | QUERY_FLAG (npc->enemy, FLAG_FREED) || |
69 | QUERY_FLAG (npc->enemy, FLAG_FREED) || |
69 | !on_same_map (npc, npc->enemy) || npc == npc->enemy || QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (npc->enemy, FLAG_NEUTRAL)) |
70 | !on_same_map (npc, npc->enemy) || npc == npc->enemy || QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (npc->enemy, FLAG_NEUTRAL)) |
70 | npc->enemy = NULL; |
71 | npc->enemy = 0; |
71 | |
72 | |
72 | else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) |
73 | else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) |
73 | && !(should_arena_attack (npc, npc->owner, npc->enemy))) |
74 | && !(should_arena_attack (npc, npc->owner, npc->enemy))) |
74 | || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy))) |
75 | || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy))) |
75 | || npc->enemy == npc->owner)) |
76 | || npc->enemy == npc->owner)) |
76 | npc->enemy = NULL; |
77 | npc->enemy = 0; |
77 | |
78 | |
78 | |
79 | |
79 | else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER)) |
80 | else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER)) |
80 | npc->enemy = NULL; |
81 | npc->enemy = 0; |
81 | |
82 | |
82 | /* I've noticed that pets could sometimes get an arrow as the |
83 | /* I've noticed that pets could sometimes get an arrow as the |
83 | * target enemy - this code below makes sure the enemy is something |
84 | * target enemy - this code below makes sure the enemy is something |
84 | * that should be attacked. My guess is that the arrow hits |
85 | * that should be attacked. My guess is that the arrow hits |
85 | * the creature/owner, and so the creature then takes that |
86 | * the creature/owner, and so the creature then takes that |
… | |
… | |
87 | */ |
88 | */ |
88 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
89 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
89 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
90 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
90 | && npc->enemy->type != PLAYER |
91 | && npc->enemy->type != PLAYER |
91 | && npc->enemy->type != GOLEM) |
92 | && npc->enemy->type != GOLEM) |
92 | npc->enemy = NULL; |
93 | npc->enemy = 0; |
93 | |
|
|
94 | } |
94 | } |
95 | |
95 | |
96 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
96 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : 0; |
97 | } |
97 | } |
98 | |
98 | |
99 | /* Returns the nearest living creature (monster or generator). |
99 | /* Returns the nearest living creature (monster or generator). |
100 | * Modified to deal with tiled maps properly. |
100 | * Modified to deal with tiled maps properly. |
101 | * Also fixed logic so that monsters in the lower directions were more |
101 | * Also fixed logic so that monsters in the lower directions were more |
… | |
… | |
1282 | for (tmp = monster->below; tmp != NULL; tmp = next) |
1282 | for (tmp = monster->below; tmp != NULL; tmp = next) |
1283 | { |
1283 | { |
1284 | next = tmp->below; |
1284 | next = tmp->below; |
1285 | switch (tmp->type) |
1285 | switch (tmp->type) |
1286 | { |
1286 | { |
1287 | case CF_HANDLE: |
1287 | case T_HANDLE: |
1288 | case TRIGGER: |
1288 | case TRIGGER: |
1289 | if (monster->will_apply & 1) |
1289 | if (monster->will_apply & 1) |
1290 | manual_apply (monster, tmp, 0); |
1290 | manual_apply (monster, tmp, 0); |
1291 | break; |
1291 | break; |
1292 | |
1292 | |