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.65 by root, Fri Sep 25 18:44:58 2009 UTC vs.
Revision 1.68 by root, Fri Sep 25 19:09:20 2009 UTC

46 npc->enemy = NULL; 46 npc->enemy = NULL;
47 else if (npc->enemy == NULL) 47 else if (npc->enemy == NULL)
48 npc->enemy = npc->owner->enemy; 48 npc->enemy = npc->owner->enemy;
49 } 49 }
50 50
51 /* periodically, a monster mayu change its target. Also, if the object 51 /* periodically, a monster may change its target. Also, if the object
52 * has been destroyed, etc, clear the enemy. 52 * has been destroyed, etc, clear the enemy.
53 * TODO: this should be changed, because it invokes to attack forced or 53 * TODO: this should be changed, because it invokes to attack forced or
54 * attacked monsters to leave the attacker alone, before it is destroyed 54 * attacked monsters to leave the attacker alone, before it is destroyed
55 */ 55 */
56 /* i had removed the random target leave, this invokes problems with friendly 56 /* 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 57 * objects, getting attacked and defending herself - they don't try to attack
58 * again then but perhaps get attack on and on 58 * 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 59 * If we include a aggravated flag in , we can handle evil vs evil and good vs good
60 * too. */ 60 * too. */
61 61
65 * the grouping checks are. Code is the same. 65 * the grouping checks are. Code is the same.
66 */ 66 */
67 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || 67 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) ||
68 QUERY_FLAG (npc->enemy, FLAG_FREED) || 68 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)) 69 !on_same_map (npc, npc->enemy) || npc == npc->enemy || QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (npc->enemy, FLAG_NEUTRAL))
70 npc->enemy = NULL; 70 npc->enemy = 0;
71 71
72 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) 72 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY)
73 && !(should_arena_attack (npc, npc->owner, npc->enemy))) 73 && !(should_arena_attack (npc, npc->owner, npc->enemy)))
74 || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy))) 74 || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy)))
75 || npc->enemy == npc->owner)) 75 || npc->enemy == npc->owner))
76 npc->enemy = NULL; 76 npc->enemy = 0;
77 77
78 78
79 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER)) 79 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER))
80 npc->enemy = NULL; 80 npc->enemy = 0;
81 81
82 /* I've noticed that pets could sometimes get an arrow as the 82 /* I've noticed that pets could sometimes get an arrow as the
83 * target enemy - this code below makes sure the enemy is something 83 * target enemy - this code below makes sure the enemy is something
84 * that should be attacked. My guess is that the arrow hits 84 * that should be attacked. My guess is that the arrow hits
85 * the creature/owner, and so the creature then takes that 85 * the creature/owner, and so the creature then takes that
87 */ 87 */
88 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) 88 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER)
89 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) 89 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR)
90 && npc->enemy->type != PLAYER 90 && npc->enemy->type != PLAYER
91 && npc->enemy->type != GOLEM) 91 && npc->enemy->type != GOLEM)
92 npc->enemy = NULL; 92 npc->enemy = 0;
93
94 } 93 }
95 94
96 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; 95 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : 0;
97} 96}
98 97
99/* Returns the nearest living creature (monster or generator). 98/* Returns the nearest living creature (monster or generator).
100 * Modified to deal with tiled maps properly. 99 * Modified to deal with tiled maps properly.
101 * Also fixed logic so that monsters in the lower directions were more 100 * Also fixed logic so that monsters in the lower directions were more
706 return 1; 705 return 1;
707 706
708 /* check all the parts of ob2 - just because we can't get to 707 /* 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 708 * its head doesn't mean we don't want to pound its feet
710 */ 709 */
711 for (more = ob2->more; more != NULL; more = more->more) 710 for (more = ob2->more; more; more = more->more)
712 { 711 {
713 get_rangevector (ob1, more, &rv1, 0); 712 get_rangevector (ob1, more, &rv1, 0);
714 if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) 713 if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2)
715 return 1; 714 return 1;
716 } 715 }
1197 flag = 1; 1196 flag = 1;
1198 1197
1199 else 1198 else
1200 switch (item->type) 1199 switch (item->type)
1201 { 1200 {
1202 case MONEY: 1201 case MONEY:
1203 case GEM: 1202 case GEM:
1204 flag = monster->pick_up & 2; 1203 flag = monster->pick_up & 2;
1205 break; 1204 break;
1206 1205
1207 case FOOD: 1206 case FOOD:
1208 flag = monster->pick_up & 4; 1207 flag = monster->pick_up & 4;
1209 break; 1208 break;
1210 1209
1211 case WEAPON: 1210 case WEAPON:
1212 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); 1211 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON);
1213 break; 1212 break;
1214 1213
1215 case ARMOUR: 1214 case ARMOUR:
1216 case SHIELD: 1215 case SHIELD:
1217 case HELMET: 1216 case HELMET:
1218 case BOOTS: 1217 case BOOTS:
1219 case GLOVES: 1218 case GLOVES:
1220 case GIRDLE: 1219 case GIRDLE:
1221 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); 1220 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR);
1222 break; 1221 break;
1223 1222
1224 case SKILL: 1223 case SKILL:
1225 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); 1224 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL);
1226 break; 1225 break;
1227 1226
1228 case RING: 1227 case RING:
1229 flag = QUERY_FLAG (monster, FLAG_USE_RING); 1228 flag = QUERY_FLAG (monster, FLAG_USE_RING);
1230 break; 1229 break;
1231 1230
1232 case WAND: 1231 case WAND:
1233 case HORN: 1232 case HORN:
1234 case ROD: 1233 case ROD:
1235 flag = QUERY_FLAG (monster, FLAG_USE_RANGE); 1234 flag = QUERY_FLAG (monster, FLAG_USE_RANGE);
1236 break; 1235 break;
1237 1236
1238 case SPELLBOOK: 1237 case SPELLBOOK:
1239 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); 1238 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL);
1240 break; 1239 break;
1241 1240
1242 case SCROLL: 1241 case SCROLL:
1243 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); 1242 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL);
1244 break; 1243 break;
1245 1244
1246 case BOW: 1245 case BOW:
1247 case ARROW: 1246 case ARROW:
1248 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1247 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1249 break; 1248 break;
1250 } 1249 }
1251 1250
1252 /* Simplistic check - if the monster has a location to equip it, he will 1251 /* 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 1252 * pick it up. Note that this doesn't handle cases where an item may
1254 * use several locations. 1253 * use several locations.
1499 * the creature should run away (dir+4) 1498 * the creature should run away (dir+4)
1500 * I think its wrong for a creature to have a zero maxhp value, but 1499 * 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 1500 * 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 1501 * server should try to be resilant enough to avoid the problem
1503 */ 1502 */
1504 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) 1503 if (ob->stats.hp * 100 < ob->stats.maxhp * ob->run_away)
1505 return absdir (dir + 4); 1504 return absdir (dir + 4);
1506 1505
1507 return dist_att (dir, ob, enemy, part, rv); 1506 return dist_att (dir, ob, enemy, part, rv);
1508} 1507}
1509 1508

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines