… | |
… | |
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 |
… | |
… | |
390 | { |
390 | { |
391 | if (op->attack_movement & HI4) |
391 | if (op->attack_movement & HI4) |
392 | { |
392 | { |
393 | switch (op->attack_movement & HI4) |
393 | switch (op->attack_movement & HI4) |
394 | { |
394 | { |
395 | case (PETMOVE): |
395 | case PETMOVE: |
396 | pet_move (op); |
396 | pet_move (op); |
397 | break; |
397 | break; |
398 | |
398 | |
399 | case (CIRCLE1): |
399 | case CIRCLE1: |
400 | circ1_move (op); |
400 | circ1_move (op); |
401 | break; |
401 | break; |
402 | |
402 | |
403 | case (CIRCLE2): |
403 | case CIRCLE2: |
404 | circ2_move (op); |
404 | circ2_move (op); |
405 | break; |
405 | break; |
406 | |
406 | |
407 | case (PACEV): |
407 | case PACEV: |
408 | pace_movev (op); |
408 | pace_movev (op); |
409 | break; |
409 | break; |
410 | |
410 | |
411 | case (PACEH): |
411 | case PACEH: |
412 | pace_moveh (op); |
412 | pace_moveh (op); |
413 | break; |
413 | break; |
414 | |
414 | |
415 | case (PACEV2): |
415 | case PACEV2: |
416 | pace2_movev (op); |
416 | pace2_movev (op); |
417 | break; |
417 | break; |
418 | |
418 | |
419 | case (PACEH2): |
419 | case PACEH2: |
420 | pace2_moveh (op); |
420 | pace2_moveh (op); |
421 | break; |
421 | break; |
422 | |
422 | |
423 | case (RANDO): |
423 | case RANDO: |
424 | rand_move (op); |
424 | rand_move (op); |
425 | break; |
425 | break; |
426 | |
426 | |
427 | case (RANDO2): |
427 | case RANDO2: |
428 | move_randomly (op); |
428 | move_randomly (op); |
429 | break; |
429 | break; |
430 | } |
430 | } |
431 | |
431 | |
432 | return 0; |
432 | return 0; |
… | |
… | |
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 | |
… | |
… | |
1420 | } |
1420 | } |
1421 | |
1421 | |
1422 | void |
1422 | void |
1423 | npc_call_help (object *op) |
1423 | npc_call_help (object *op) |
1424 | { |
1424 | { |
1425 | int x, y, mflags; |
1425 | unordered_mapwalk (op, -7, -7, 7, 7) |
1426 | object *npc; |
|
|
1427 | sint16 sx, sy; |
|
|
1428 | maptile *m; |
|
|
1429 | |
|
|
1430 | for (x = -3; x < 4; x++) |
|
|
1431 | for (y = -3; y < 4; y++) |
|
|
1432 | { |
1426 | { |
1433 | m = op->map; |
1427 | mapspace &ms = m->at (nx, ny); |
1434 | sx = op->x + x; |
1428 | |
1435 | sy = op->y + y; |
|
|
1436 | mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); |
|
|
1437 | /* If nothing alive on this space, no need to search the space. */ |
1429 | /* If nothing alive on this space, no need to search the space. */ |
1438 | if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) |
1430 | if (!(ms.flags () & P_IS_ALIVE)) |
1439 | continue; |
1431 | continue; |
1440 | |
1432 | |
1441 | for (npc = GET_MAP_OB (m, sx, sy); npc != NULL; npc = npc->above) |
1433 | for (object *npc = ms.bot; npc; npc = npc->above) |
1442 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1434 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1443 | npc->enemy = op->enemy; |
1435 | npc->enemy = op->enemy; |
1444 | } |
1436 | } |
1445 | } |
1437 | } |
1446 | |
1438 | |
1447 | int |
1439 | int |
1448 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1440 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv) |
1449 | { |
1441 | { |
1450 | if (can_hit (part, enemy, rv)) |
1442 | if (can_hit (part, enemy, rv)) |
1451 | return dir; |
1443 | return dir; |
1452 | |
1444 | |
1453 | if (rv->distance < 10) |
1445 | if (rv->distance < 10) |
… | |
… | |
1457 | |
1449 | |
1458 | return 0; |
1450 | return 0; |
1459 | } |
1451 | } |
1460 | |
1452 | |
1461 | int |
1453 | int |
1462 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1454 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv) |
1463 | { |
1455 | { |
1464 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1456 | if (can_hit (part, enemy, rv)) |
1465 | { |
|
|
1466 | ob->move_status++; |
|
|
1467 | return (dir); |
1457 | return dir; |
1468 | } |
1458 | else |
1469 | else if (ob->move_status > 20) |
|
|
1470 | ob->move_status = 0; |
|
|
1471 | |
|
|
1472 | return absdir (dir + 4); |
1459 | return absdir (dir + 4); |
1473 | } |
1460 | } |
1474 | |
1461 | |
1475 | int |
1462 | int |
1476 | hitrun_att (int dir, object *ob, object *enemy) |
1463 | hitrun_att (int dir, object *ob, object *enemy) |
1477 | { |
1464 | { |
… | |
… | |
1486 | } |
1473 | } |
1487 | |
1474 | |
1488 | int |
1475 | int |
1489 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1476 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1490 | { |
1477 | { |
1491 | |
|
|
1492 | int inrange = can_hit (part, enemy, rv); |
1478 | int inrange = can_hit (part, enemy, rv); |
1493 | |
1479 | |
1494 | if (ob->move_status || inrange) |
1480 | if (ob->move_status || inrange) |
1495 | ob->move_status++; |
1481 | ob->move_status++; |
1496 | |
1482 | |
… | |
… | |
1506 | } |
1492 | } |
1507 | |
1493 | |
1508 | int |
1494 | int |
1509 | disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1495 | disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1510 | { |
1496 | { |
1511 | |
|
|
1512 | /* The logic below here looked plain wrong before. Basically, what should |
1497 | /* The logic below here looked plain wrong before. Basically, what should |
1513 | * happen is that if the creatures hp percentage falls below run_away, |
1498 | * happen is that if the creatures hp percentage falls below run_away, |
1514 | * the creature should run away (dir+4) |
1499 | * the creature should run away (dir+4) |
1515 | * 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 |
1516 | * 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 |
1517 | * server should try to be resilant enough to avoid the problem |
1502 | * server should try to be resilant enough to avoid the problem |
1518 | */ |
1503 | */ |
1519 | 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) |
1520 | return absdir (dir + 4); |
1505 | return absdir (dir + 4); |
1521 | |
1506 | |
1522 | return dist_att (dir, ob, enemy, part, rv); |
1507 | return dist_att (dir, ob, enemy, part, rv); |
1523 | } |
1508 | } |
1524 | |
1509 | |
… | |
… | |
1892 | { |
1877 | { |
1893 | /* HIDDEN ENEMY. by definition, you can't see hidden stuff! |
1878 | /* HIDDEN ENEMY. by definition, you can't see hidden stuff! |
1894 | * However,if you carry any source of light, then the hidden |
1879 | * However,if you carry any source of light, then the hidden |
1895 | * creature is seeable (and stupid) */ |
1880 | * creature is seeable (and stupid) */ |
1896 | |
1881 | |
1897 | if (has_carried_lights (enemy)) |
1882 | if (enemy->has_carried_lights ()) |
1898 | { |
1883 | { |
1899 | if (enemy->flag [FLAG_HIDDEN]) |
1884 | if (enemy->flag [FLAG_HIDDEN]) |
1900 | { |
1885 | { |
1901 | make_visible (enemy); |
1886 | make_visible (enemy); |
1902 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1887 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |