… | |
… | |
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 |
… | |
… | |
706 | return 1; |
706 | return 1; |
707 | |
707 | |
708 | /* check all the parts of ob2 - just because we can't get to |
708 | /* check all the parts of ob2 - just because we can't get to |
709 | * its head doesn't mean we don't want to pound its feet |
709 | * its head doesn't mean we don't want to pound its feet |
710 | */ |
710 | */ |
711 | for (more = ob2->more; more != NULL; more = more->more) |
711 | for (more = ob2->more; more; more = more->more) |
712 | { |
712 | { |
713 | get_rangevector (ob1, more, &rv1, 0); |
713 | get_rangevector (ob1, more, &rv1, 0); |
714 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
714 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
715 | return 1; |
715 | return 1; |
716 | } |
716 | } |
… | |
… | |
1197 | flag = 1; |
1197 | flag = 1; |
1198 | |
1198 | |
1199 | else |
1199 | else |
1200 | switch (item->type) |
1200 | switch (item->type) |
1201 | { |
1201 | { |
1202 | case MONEY: |
1202 | case MONEY: |
1203 | case GEM: |
1203 | case GEM: |
1204 | flag = monster->pick_up & 2; |
1204 | flag = monster->pick_up & 2; |
1205 | break; |
1205 | break; |
1206 | |
1206 | |
1207 | case FOOD: |
1207 | case FOOD: |
1208 | flag = monster->pick_up & 4; |
1208 | flag = monster->pick_up & 4; |
1209 | break; |
1209 | break; |
1210 | |
1210 | |
1211 | case WEAPON: |
1211 | case WEAPON: |
1212 | flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); |
1212 | flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); |
1213 | break; |
1213 | break; |
1214 | |
1214 | |
1215 | case ARMOUR: |
1215 | case ARMOUR: |
1216 | case SHIELD: |
1216 | case SHIELD: |
1217 | case HELMET: |
1217 | case HELMET: |
1218 | case BOOTS: |
1218 | case BOOTS: |
1219 | case GLOVES: |
1219 | case GLOVES: |
1220 | case GIRDLE: |
1220 | case GIRDLE: |
1221 | flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); |
1221 | flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); |
1222 | break; |
1222 | break; |
1223 | |
1223 | |
1224 | case SKILL: |
1224 | case SKILL: |
1225 | flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); |
1225 | flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); |
1226 | break; |
1226 | break; |
1227 | |
1227 | |
1228 | case RING: |
1228 | case RING: |
1229 | flag = QUERY_FLAG (monster, FLAG_USE_RING); |
1229 | flag = QUERY_FLAG (monster, FLAG_USE_RING); |
1230 | break; |
1230 | break; |
1231 | |
1231 | |
1232 | case WAND: |
1232 | case WAND: |
1233 | case HORN: |
1233 | case HORN: |
1234 | case ROD: |
1234 | case ROD: |
1235 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1235 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1236 | break; |
1236 | break; |
1237 | |
1237 | |
1238 | case SPELLBOOK: |
1238 | case SPELLBOOK: |
1239 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1239 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1240 | break; |
1240 | break; |
1241 | |
1241 | |
1242 | case SCROLL: |
1242 | case SCROLL: |
1243 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1243 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1244 | break; |
1244 | break; |
1245 | |
1245 | |
1246 | case BOW: |
1246 | case BOW: |
1247 | case ARROW: |
1247 | case ARROW: |
1248 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1248 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1249 | break; |
1249 | break; |
1250 | } |
1250 | } |
1251 | |
1251 | |
1252 | /* Simplistic check - if the monster has a location to equip it, he will |
1252 | /* Simplistic check - if the monster has a location to equip it, he will |
1253 | * pick it up. Note that this doesn't handle cases where an item may |
1253 | * pick it up. Note that this doesn't handle cases where an item may |
1254 | * use several locations. |
1254 | * use several locations. |
… | |
… | |
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 | |
… | |
… | |
1499 | * the creature should run away (dir+4) |
1499 | * the creature should run away (dir+4) |
1500 | * I think its wrong for a creature to have a zero maxhp value, but |
1500 | * I think its wrong for a creature to have a zero maxhp value, but |
1501 | * at least one map has this set, and whatever the map contains, the |
1501 | * at least one map has this set, and whatever the map contains, the |
1502 | * server should try to be resilant enough to avoid the problem |
1502 | * server should try to be resilant enough to avoid the problem |
1503 | */ |
1503 | */ |
1504 | if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) |
1504 | if (ob->stats.hp * 100 < ob->stats.maxhp * ob->run_away) |
1505 | return absdir (dir + 4); |
1505 | return absdir (dir + 4); |
1506 | |
1506 | |
1507 | return dist_att (dir, ob, enemy, part, rv); |
1507 | return dist_att (dir, ob, enemy, part, rv); |
1508 | } |
1508 | } |
1509 | |
1509 | |