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.75 by root, Sat Nov 7 18:30:06 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))
873/* Returns a randomly selected spell. This logic is still 873/* Returns a randomly selected spell. This logic is still
874 * less than ideal. This code also only seems to deal with 874 * less than ideal. This code also only seems to deal with
875 * wizard spells, as the check is against sp, and not grace. 875 * wizard spells, as the check is against sp, and not grace.
876 * can mosnters know cleric spells? 876 * can mosnters know cleric spells?
877 */ 877 */
878object * 878static object *
879monster_choose_random_spell (object *monster) 879monster_choose_random_spell (object *monster)
880{ 880{
881 object *altern[MAX_KNOWN_SPELLS]; 881 object *altern[MAX_KNOWN_SPELLS];
882 int i = 0; 882 int i = 0;
883 883
906 * part is the part of the monster we are checking against. 906 * part is the part of the monster we are checking against.
907 * pl is the target. 907 * pl is the target.
908 * dir is the direction to case. 908 * dir is the direction to case.
909 * rv is the vector which describes where the enemy is. 909 * rv is the vector which describes where the enemy is.
910 */ 910 */
911int 911static int
912monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) 912monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv)
913{ 913{
914 object *spell_item; 914 object *spell_item;
915 object *owner; 915 object *owner;
916 rv_vector rv1; 916 rv_vector rv1;
982 head->spellitem = NULL; 982 head->spellitem = NULL;
983 983
984 return cast_spell (part, part, dir, spell_item, NULL); 984 return cast_spell (part, part, dir, spell_item, NULL);
985} 985}
986 986
987int 987static int
988monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) 988monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv)
989{ 989{
990 object *scroll; 990 object *scroll;
991 object *owner; 991 object *owner;
992 rv_vector rv1; 992 rv_vector rv1;
1040 * The skills we are treating here are all but those. -b.t. 1040 * The skills we are treating here are all but those. -b.t.
1041 * 1041 *
1042 * At the moment this is only useful for throwing, perhaps for 1042 * 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 1043 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01
1044 */ 1044 */
1045int 1045static int
1046monster_use_skill (object *head, object *part, object *pl, int dir) 1046monster_use_skill (object *head, object *part, object *pl, int dir)
1047{ 1047{
1048 object *skill, *owner; 1048 object *skill, *owner;
1049 1049
1050 if (!(dir = path_to_player (part, pl, 0))) 1050 if (!(dir = path_to_player (part, pl, 0)))
1083 /* use skill */ 1083 /* use skill */
1084 return do_skill (head, part, head->chosen_skill, dir, NULL); 1084 return do_skill (head, part, head->chosen_skill, dir, NULL);
1085} 1085}
1086 1086
1087/* Monster will use a ranged spell attack. */ 1087/* Monster will use a ranged spell attack. */
1088int 1088static int
1089monster_use_range (object *head, object *part, object *pl, int dir) 1089monster_use_range (object *head, object *part, object *pl, int dir)
1090{ 1090{
1091 object *wand, *owner; 1091 object *wand, *owner;
1092 int at_least_one = 0; 1092 int at_least_one = 0;
1093 1093
1130 } 1130 }
1131 else if (wand->type == ROD || wand->type == HORN) 1131 else if (wand->type == ROD || wand->type == HORN)
1132 { 1132 {
1133 /* Found rod/horn, let's use it if possible */ 1133 /* Found rod/horn, let's use it if possible */
1134 at_least_one = 1; 1134 at_least_one = 1;
1135 if (wand->stats.hp < MAX (wand->inv->stats.sp, wand->inv->stats.grace)) 1135 if (wand->stats.hp < max (wand->inv->stats.sp, wand->inv->stats.grace))
1136 continue; 1136 continue;
1137 1137
1138 /* drain charge before casting spell - can be a case where the 1138 /* drain charge before casting spell - can be a case where the
1139 * spell destroys the monster, and rod, so if done after, results 1139 * spell destroys the monster, and rod, so if done after, results
1140 * in crash. 1140 * in crash.
1153 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count); 1153 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); 1154 CLEAR_FLAG (head, FLAG_READY_RANGE);
1155 return 0; 1155 return 0;
1156} 1156}
1157 1157
1158int 1158static int
1159monster_use_bow (object *head, object *part, object *pl, int dir) 1159monster_use_bow (object *head, object *part, object *pl, int dir)
1160{ 1160{
1161 object *owner; 1161 object *owner;
1162 1162
1163 if (!(dir = path_to_player (part, pl, 0))) 1163 if (!(dir = path_to_player (part, pl, 0)))
1292 * 1292 *
1293 * Cast to sint32 before comparing to maxhp since otherwise an (sint16) 1293 * Cast to sint32 before comparing to maxhp since otherwise an (sint16)
1294 * overflow might produce monsters with negative hp. 1294 * overflow might produce monsters with negative hp.
1295 */ 1295 */
1296 1296
1297 op->last_heal += (int) ((float) (8 * op->stats.Con) / FABS (op->speed)); 1297 op->last_heal += (int) ((float) (8 * op->stats.Con) / fabs (op->speed));
1298 op->stats.hp = MIN ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */ 1298 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; 1299 op->last_heal %= 32;
1300 1300
1301 /* So if the monster has gained enough HP that they are no longer afraid */ 1301 /* 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)) 1302 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); 1303 CLEAR_FLAG (op, FLAG_RUN_AWAY);
1316 * 1316 *
1317 * Cast to sint32 before comparing to maxhp since otherwise an (sint16) 1317 * Cast to sint32 before comparing to maxhp since otherwise an (sint16)
1318 * overflow might produce monsters with negative sp. 1318 * overflow might produce monsters with negative sp.
1319 */ 1319 */
1320 1320
1321 op->last_sp += (int) ((float) (8 * op->stats.Pow) / fabsf (op->speed)); 1321 op->last_sp += (int) ((float) (8 * op->stats.Pow) / fabs (op->speed));
1322 op->stats.sp = min (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */ 1322 op->stats.sp = min (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */
1323 op->last_sp %= 128; 1323 op->last_sp %= 128;
1324 } 1324 }
1325 1325
1326 /* this should probably get modified by many more values. 1326 /* this should probably get modified by many more values.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines