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.72 by root, Fri Nov 6 12:27:06 2009 UTC vs.
Revision 1.77 by root, Sun Nov 29 10:55:18 2009 UTC

153 * Currently, only move_monster calls this function. 153 * Currently, only move_monster calls this function.
154 * Fix function so that we always make calls to get_rangevector 154 * Fix function so that we always make calls to get_rangevector
155 * if we have a valid target - function as not doing so in 155 * if we have a valid target - function as not doing so in
156 * many cases. 156 * many cases.
157 */ 157 */
158object * 158static object *
159find_enemy (object *npc, rv_vector * rv) 159find_enemy (object *npc, rv_vector * rv)
160{ 160{
161 object *attacker, *tmp = NULL; 161 object *attacker, *tmp = NULL;
162 162
163 attacker = npc->attacked_by; /* save this for later use. This can be a attacker. */ 163 attacker = npc->attacked_by; /* save this for later use. This can be a attacker. */
231/* Sees if this monster should wake up. 231/* Sees if this monster should wake up.
232 * Currently, this is only called from move_monster, and 232 * Currently, this is only called from move_monster, and
233 * if enemy is set, then so should be rv. 233 * if enemy is set, then so should be rv.
234 * returns 1 if the monster should wake up, 0 otherwise. 234 * returns 1 if the monster should wake up, 0 otherwise.
235 */ 235 */
236int 236static int
237check_wakeup (object *op, object *enemy, rv_vector *rv) 237check_wakeup (object *op, object *enemy, rv_vector *rv)
238{ 238{
239 /* Trim work - if no enemy, no need to do anything below */ 239 /* Trim work - if no enemy, no need to do anything below */
240 if (!enemy) 240 if (!enemy)
241 return 0; 241 return 0;
272 } 272 }
273 273
274 return 0; 274 return 0;
275} 275}
276 276
277int 277static int
278move_randomly (object *op) 278move_randomly (object *op)
279{ 279{
280 /* Give up to 15 chances for a monster to move randomly */ 280 /* Give up to 15 chances for a monster to move randomly */
281 for (int i = 0; i < 15; i++) 281 for (int i = 0; i < 15; i++)
282 if (move_object (op, rndm (8) + 1)) 282 if (move_object (op, rndm (8) + 1))
403 next = tmp->below; 403 next = tmp->below;
404 if (monster_can_pick (monster, tmp)) 404 if (monster_can_pick (monster, tmp))
405 { 405 {
406 tmp->remove (); 406 tmp->remove ();
407 tmp = insert_ob_in_ob (tmp, monster); 407 tmp = insert_ob_in_ob (tmp, monster);
408 (void) monster_check_apply (monster, tmp); 408 monster_check_apply (monster, tmp);
409 } 409 }
410
410 /* We could try to re-establish the cycling, of the space, but probably 411 /* We could try to re-establish the cycling, of the space, but probably
411 * not a big deal to just bail out. 412 * not a big deal to just bail out.
412 */ 413 */
413 if (next && next->destroyed ()) 414 if (next && next->destroyed ())
414 return; 415 return;
873/* Returns a randomly selected spell. This logic is still 874/* Returns a randomly selected spell. This logic is still
874 * less than ideal. This code also only seems to deal with 875 * less than ideal. This code also only seems to deal with
875 * wizard spells, as the check is against sp, and not grace. 876 * wizard spells, as the check is against sp, and not grace.
876 * can mosnters know cleric spells? 877 * can mosnters know cleric spells?
877 */ 878 */
878object * 879static object *
879monster_choose_random_spell (object *monster) 880monster_choose_random_spell (object *monster)
880{ 881{
881 object *altern[MAX_KNOWN_SPELLS]; 882 object *altern[MAX_KNOWN_SPELLS];
882 int i = 0; 883 int i = 0;
883 884
906 * part is the part of the monster we are checking against. 907 * part is the part of the monster we are checking against.
907 * pl is the target. 908 * pl is the target.
908 * dir is the direction to case. 909 * dir is the direction to case.
909 * rv is the vector which describes where the enemy is. 910 * rv is the vector which describes where the enemy is.
910 */ 911 */
911int 912static int
912monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) 913monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv)
913{ 914{
914 object *spell_item; 915 object *spell_item;
915 object *owner; 916 object *owner;
916 rv_vector rv1; 917 rv_vector rv1;
982 head->spellitem = NULL; 983 head->spellitem = NULL;
983 984
984 return cast_spell (part, part, dir, spell_item, NULL); 985 return cast_spell (part, part, dir, spell_item, NULL);
985} 986}
986 987
987int 988static int
988monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) 989monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv)
989{ 990{
990 object *scroll; 991 object *scroll;
991 object *owner; 992 object *owner;
992 rv_vector rv1; 993 rv_vector rv1;
1040 * The skills we are treating here are all but those. -b.t. 1041 * The skills we are treating here are all but those. -b.t.
1041 * 1042 *
1042 * At the moment this is only useful for throwing, perhaps for 1043 * At the moment this is only useful for throwing, perhaps for
1043 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 1044 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01
1044 */ 1045 */
1045int 1046static int
1046monster_use_skill (object *head, object *part, object *pl, int dir) 1047monster_use_skill (object *head, object *part, object *pl, int dir)
1047{ 1048{
1048 object *skill, *owner; 1049 object *skill, *owner;
1049 1050
1050 if (!(dir = path_to_player (part, pl, 0))) 1051 if (!(dir = path_to_player (part, pl, 0)))
1083 /* use skill */ 1084 /* use skill */
1084 return do_skill (head, part, head->chosen_skill, dir, NULL); 1085 return do_skill (head, part, head->chosen_skill, dir, NULL);
1085} 1086}
1086 1087
1087/* Monster will use a ranged spell attack. */ 1088/* Monster will use a ranged spell attack. */
1088int 1089static int
1089monster_use_range (object *head, object *part, object *pl, int dir) 1090monster_use_range (object *head, object *part, object *pl, int dir)
1090{ 1091{
1091 object *wand, *owner; 1092 object *wand, *owner;
1092 int at_least_one = 0; 1093 int at_least_one = 0;
1093 1094
1130 } 1131 }
1131 else if (wand->type == ROD || wand->type == HORN) 1132 else if (wand->type == ROD || wand->type == HORN)
1132 { 1133 {
1133 /* Found rod/horn, let's use it if possible */ 1134 /* Found rod/horn, let's use it if possible */
1134 at_least_one = 1; 1135 at_least_one = 1;
1135 if (wand->stats.hp < MAX (wand->inv->stats.sp, wand->inv->stats.grace)) 1136 if (wand->stats.hp < max (wand->inv->stats.sp, wand->inv->stats.grace))
1136 continue; 1137 continue;
1137 1138
1138 /* drain charge before casting spell - can be a case where the 1139 /* drain charge before casting spell - can be a case where the
1139 * spell destroys the monster, and rod, so if done after, results 1140 * spell destroys the monster, and rod, so if done after, results
1140 * in crash. 1141 * in crash.
1153 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count); 1154 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count);
1154 CLEAR_FLAG (head, FLAG_READY_RANGE); 1155 CLEAR_FLAG (head, FLAG_READY_RANGE);
1155 return 0; 1156 return 0;
1156} 1157}
1157 1158
1158int 1159static int
1159monster_use_bow (object *head, object *part, object *pl, int dir) 1160monster_use_bow (object *head, object *part, object *pl, int dir)
1160{ 1161{
1161 object *owner; 1162 object *owner;
1162 1163
1163 if (!(dir = path_to_player (part, pl, 0))) 1164 if (!(dir = path_to_player (part, pl, 0)))
1292 * 1293 *
1293 * Cast to sint32 before comparing to maxhp since otherwise an (sint16) 1294 * Cast to sint32 before comparing to maxhp since otherwise an (sint16)
1294 * overflow might produce monsters with negative hp. 1295 * overflow might produce monsters with negative hp.
1295 */ 1296 */
1296 1297
1297 op->last_heal += (int) ((float) (8 * op->stats.Con) / FABS (op->speed)); 1298 op->last_heal += (int) ((float) (8 * op->stats.Con) / op->speed);
1298 op->stats.hp = MIN ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */ 1299 op->stats.hp = min ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */
1299 op->last_heal %= 32; 1300 op->last_heal %= 32;
1300 1301
1301 /* So if the monster has gained enough HP that they are no longer afraid */ 1302 /* So if the monster has gained enough HP that they are no longer afraid */
1302 if (QUERY_FLAG (op, FLAG_RUN_AWAY) && op->stats.hp >= (signed short)(((float)op->run_away / 100.f) * (float)op->stats.maxhp)) 1303 if (QUERY_FLAG (op, FLAG_RUN_AWAY) && op->stats.hp >= (signed short)(((float)op->run_away / 100.f) * (float)op->stats.maxhp))
1303 CLEAR_FLAG (op, FLAG_RUN_AWAY); 1304 CLEAR_FLAG (op, FLAG_RUN_AWAY);
1316 * 1317 *
1317 * Cast to sint32 before comparing to maxhp since otherwise an (sint16) 1318 * Cast to sint32 before comparing to maxhp since otherwise an (sint16)
1318 * overflow might produce monsters with negative sp. 1319 * overflow might produce monsters with negative sp.
1319 */ 1320 */
1320 1321
1321 op->last_sp += (int) ((float) (8 * op->stats.Pow) / fabsf (op->speed)); 1322 op->last_sp += (int) ((float) (8 * op->stats.Pow) / op->speed);
1322 op->stats.sp = min (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */ 1323 op->stats.sp = min (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */
1323 op->last_sp %= 128; 1324 op->last_sp %= 128;
1324 } 1325 }
1325 1326
1326 /* this should probably get modified by many more values. 1327 /* this should probably get modified by many more values.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines