ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/spell_util.C
(Generate patch)

Comparing deliantra/server/server/spell_util.C (file contents):
Revision 1.101 by root, Fri Nov 6 13:03:34 2009 UTC vs.
Revision 1.115 by root, Sat Apr 10 05:12:57 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
83 */ 83 */
84void 84void
85spell_effect (object *spob, int x, int y, maptile *map, object *originator) 85spell_effect (object *spob, int x, int y, maptile *map, object *originator)
86{ 86{
87 if (spob->other_arch) 87 if (spob->other_arch)
88 map->insert (arch_to_object (spob->other_arch), x, y, originator); 88 map->insert (spob->other_arch->instance (), x, y, originator);
89} 89}
90 90
91static int 91static int
92attuned_bonus (object *caster, object *spell, int level) 92attuned_bonus (object *caster, object *spell, int level)
93{ 93{
149 int sp, grace, level = casting_level (caster, spell); 149 int sp, grace, level = casting_level (caster, spell);
150 150
151 if (settings.spellpoint_level_depend == TRUE) 151 if (settings.spellpoint_level_depend == TRUE)
152 { 152 {
153 if (spell->stats.sp && spell->stats.maxsp) 153 if (spell->stats.sp && spell->stats.maxsp)
154 {
155 sp = (int) (spell->stats.sp * (1.0 + MAX (0, (float) (level - spell->level) / (float) spell->stats.maxsp))); 154 sp = spell->stats.sp * (1.f + max (0.f, float (level - spell->level) / spell->stats.maxsp));
156 }
157 else 155 else
158 sp = spell->stats.sp; 156 sp = spell->stats.sp;
159 157
160 sp *= (int) PATH_SP_MULT (caster, spell); 158 sp *= (int) PATH_SP_MULT (caster, spell);
161 if (!sp && spell->stats.sp) 159 if (!sp && spell->stats.sp)
162 sp = 1; 160 sp = 1;
163 161
164 if (spell->stats.grace && spell->stats.maxgrace) 162 if (spell->stats.grace && spell->stats.maxgrace)
165 {
166 grace = (int) (spell->stats.grace * (1.0 + MAX (0, (float) (level - spell->level) / (float) spell->stats.maxgrace))); 163 grace = spell->stats.grace * (1.0 + max (0, float (level - spell->level) / spell->stats.maxgrace));
167 }
168 else 164 else
169 grace = spell->stats.grace; 165 grace = spell->stats.grace;
170 166
171 grace *= (int) PATH_SP_MULT (caster, spell); 167 grace *= PATH_SP_MULT (caster, spell);
172 if (spell->stats.grace && !grace) 168 if (spell->stats.grace && !grace)
173 grace = 1; 169 grace = 1;
174 } 170 }
175 else 171 else
176 { 172 {
182 if (spell->stats.grace && !grace) 178 if (spell->stats.grace && !grace)
183 grace = 1; 179 grace = 1;
184 } 180 }
185 181
186 if (flags == SPELL_HIGHEST) 182 if (flags == SPELL_HIGHEST)
187 return MAX (sp, grace); 183 return max (sp, grace);
188 else if (flags == SPELL_GRACE) 184 else if (flags == SPELL_GRACE)
189 return grace; 185 return grace;
190 else if (flags == SPELL_MANA) 186 else if (flags == SPELL_MANA)
191 return sp; 187 return sp;
192 else 188 else
536 ****************************************************************************/ 532 ****************************************************************************/
537void 533void
538regenerate_rod (object *rod) 534regenerate_rod (object *rod)
539{ 535{
540 if (rod->stats.hp < rod->stats.maxhp) 536 if (rod->stats.hp < rod->stats.maxhp)
541 rod->stats.hp = min (rod->stats.maxhp, rod->stats.hp + 1 + rod->stats.maxhp / 10); 537 rod->stats.hp = min (rod->stats.maxhp, rod->stats.hp + 1 + rod->stats.maxhp / 20);
542} 538}
543 539
544void 540void
545drain_rod_charge (object *rod) 541drain_rod_charge (object *rod)
546{ 542{
663 * insert multipart monsters properly 659 * insert multipart monsters properly
664 */ 660 */
665 //TODO: use expand_tail + ... 661 //TODO: use expand_tail + ...
666 while (at != NULL) 662 while (at != NULL)
667 { 663 {
668 tmp = arch_to_object (at); 664 tmp = at->instance ();
669 tmp->x = op->x + freearr_x[dir] + at->x; 665 tmp->x = op->x + freearr_x[dir] + at->x;
670 tmp->y = op->y + freearr_y[dir] + at->y; 666 tmp->y = op->y + freearr_y[dir] + at->y;
671 tmp->map = op->map; 667 tmp->map = op->map;
672 if (head) 668 if (head)
673 { 669 {
896 { 892 {
897 LOG (llevError, "cast_party_spell: empty other arch\n"); 893 LOG (llevError, "cast_party_spell: empty other arch\n");
898 return 0; 894 return 0;
899 } 895 }
900 896
901 object *spell = arch_to_object (spell_ob->other_arch); 897 object *spell = spell_ob->other_arch->instance ();
902 898
903 /* Always cast spell on caster */ 899 /* Always cast spell on caster */
904 int success = cast_spell (op, caster, dir, spell, spellparam); 900 int success = cast_spell (op, caster, dir, spell, spellparam);
905 901
906 if (!op->contr || !op->contr->party) 902 if (!op->contr || !op->contr->party)
949int 945int
950cast_spell (object *op, object *caster, int dir, object *spell_ob, char *spellparam) 946cast_spell (object *op, object *caster, int dir, object *spell_ob, char *spellparam)
951{ 947{
952 const char *godname; 948 const char *godname;
953 int success = 0; 949 int success = 0;
954 object *skill = NULL;
955 950
956 if (!spell_ob) 951 if (!spell_ob)
957 { 952 {
958 LOG (llevError, "cast_spell: null spell object passed\n"); 953 LOG (llevError, "cast_spell: null spell object passed\n");
959 return 0; 954 return 0;
976 { 971 {
977 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); 972 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you.");
978 return 0; 973 return 0;
979 } 974 }
980 975
976 object *skill = 0;
977
981 /* if it is a player casting the spell, and they are really casting it 978 /* if it is a player casting the spell, and they are really casting it
982 * (vs it coming from a wand, scroll, or whatever else), do some 979 * (vs it coming from a wand, scroll, or whatever else), do some
983 * checks. We let monsters do special things - eg, they 980 * checks. We let monsters do special things - eg, they
984 * don't need the skill, bypass level checks, etc. The monster function 981 * don't need the SKILL, BYpass level checks, etc. The monster function
985 * should take care of that. 982 * should take care of that.
986 * Remove the wiz check here and move it further down - some spells 983 * Remove the wiz check here and move it further down - some spells
987 * need to have the right skill pointer passed, so we need to 984 * need to have the right skill pointer passed, so we need to
988 * at least process that code. 985 * at least process that code.
989 */ 986 */
993 { 990 {
994 skill = find_skill_by_name (op, spell_ob->skill); 991 skill = find_skill_by_name (op, spell_ob->skill);
995 992
996 if (!skill) 993 if (!skill)
997 { 994 {
998 op->failmsg (format ("You need the skill %s to cast %s! " 995 op->failmsgf ("You need the %s skill to cast %s! "
999 "H<You either need to learn the skill via a skill scroll " 996 "H<You either need to learn the skill via a skill scroll "
1000 "or you need to wear a talisman or holy symbol.>", 997 "or you need to wear a talisman, holy symbol or another skill tool.>",
1001 &spell_ob->skill, &spell_ob->name)); 998 &spell_ob->skill, &spell_ob->name);
1002 return 0; 999 return 0;
1003 } 1000 }
1004 1001
1005 const char *msg = ""; 1002 const char *msg = "";
1006 1003
1007 int caster_level = skill->level; 1004 int caster_level = skill->level;
1018 msg = " (repelled)"; 1015 msg = " (repelled)";
1019 } 1016 }
1020 1017
1021 if (spell_ob->level > caster_level) 1018 if (spell_ob->level > caster_level)
1022 { 1019 {
1023 op->failmsg (format ("You lack enough skill to cast that spell! " 1020 op->failmsgf ("You lack enough skill to cast that spell! "
1024 "H<Your effective cast level is %d%s, but level %d is required.>", 1021 "H<Your effective cast level is %d%s, but level %d is required.>",
1025 caster_level, msg, spell_ob->level)); 1022 caster_level, msg, spell_ob->level);
1026 if (!op->is_wiz ()) 1023 if (!op->is_wiz ())
1027 return 0; 1024 return 0;
1028 } 1025 }
1029 } 1026 }
1030 1027
1047 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) 1044 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0)
1048 op->statusmsg (format ("%s grants your prayer, though you are unworthy.", godname)); 1045 op->statusmsg (format ("%s grants your prayer, though you are unworthy.", godname));
1049 else 1046 else
1050 { 1047 {
1051 prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace); 1048 prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace);
1052 op->failmsg (format ("%s ignores your prayer.", godname)); 1049 op->failmsgf ("%s ignores your prayer.", godname);
1053 return 0; 1050 return 0;
1054 } 1051 }
1055 } 1052 }
1056 1053
1057 /* player/monster is trying to cast the spell. might fumble it */ 1054 /* player/monster is trying to cast the spell. might fumble it */
1058 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < 1055 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) <
1059 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) 1056 (spell_ob->level / (float) max (1, op->level) * cleric_chance[op->stats.Wis]))
1060 { 1057 {
1061 op->contr->play_sound (sound_find ("fumble_spell")); 1058 op->contr->play_sound (sound_find ("fumble_spell"));
1062 op->failmsg ("You fumble the prayer."); 1059 op->failmsg ("You fumble the prayer.");
1063 1060
1064 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); 1061 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1089 * doing. 1086 * doing.
1090 */ 1087 */
1091 1088
1092 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)! 1089 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)!
1093 { 1090 {
1091 op->speed_left -= 2 * op->speed; // freeze for two ticks, so we don't flood
1094 op->failmsg ("This ground is sacred! The gods prevent any magical effects done by you here!"); 1092 op->failmsg ("This ground is sacred! The gods prevent any magical effects done by you here!");
1095 return 0; 1093 return 0;
1096 } 1094 }
1097 1095
1098 if ((spell_ob->type == SPELL) 1096 if ((spell_ob->type == SPELL)
1104 { 1102 {
1105 if (op->type != PLAYER) 1103 if (op->type != PLAYER)
1106 return 0; 1104 return 0;
1107 1105
1108 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) 1106 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)
1109 op->failmsg (format ("This ground is unholy! %s ignores you.", godname)); 1107 op->failmsgf ("This ground is unholy! %s ignores you.", godname);
1110 else if (object *item = op->contr->ranged_ob) 1108 else if (object *item = op->contr->ranged_ob)
1111 { 1109 {
1112 if (item->type == SPELL) 1110 if (item->type == SPELL)
1113 op->failmsg ("Something blocks your spellcasting."); 1111 op->failmsg ("Something blocks your spellcasting.");
1114 else if (item->type == SCROLL) 1112 else if (item->type == SCROLL)
1130 * the player any time. 1128 * the player any time.
1131 * Ignore casting time for firewalls 1129 * Ignore casting time for firewalls
1132 */ 1130 */
1133 if (caster == op && caster->type != FIREWALL) 1131 if (caster == op && caster->type != FIREWALL)
1134 { 1132 {
1135 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed); 1133 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * op->speed;
1136 /* Other portions of the code may also decrement the speed of the player, so 1134 /* Other portions of the code may also decrement the speed of the player, so
1137 * put a lower limit so that the player isn't stuck here too long 1135 * put a lower limit so that the player isn't stuck here too long
1138 */ 1136 */
1139 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed)) 1137 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * op->speed)
1140 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed); 1138 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * op->speed;
1141 } 1139 }
1142 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL) 1140 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL)
1143 op->speed_left -= 2 * FABS (op->speed); 1141 op->speed_left -= 2 * op->speed;
1144 1142
1145 if (op->type == PLAYER && op == caster) 1143 if (op->type == PLAYER && op == caster)
1146 { 1144 {
1147 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE); 1145 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE);
1148 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA); 1146 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA);
1153 * object requires. 1151 * object requires.
1154 */ 1152 */
1155 if (op != caster && !skill && caster->skill) 1153 if (op != caster && !skill && caster->skill)
1156 { 1154 {
1157 skill = find_skill_by_name (op, caster->skill); 1155 skill = find_skill_by_name (op, caster->skill);
1156
1158 if (!skill) 1157 if (!skill)
1159 { 1158 {
1160 op->failmsg (format ("You lack the skill %s to use the %s!", &caster->skill, query_name (caster))); 1159 op->failmsgf ("You lack the %s skill, which is required to use the %s!", &caster->skill, query_name (caster));
1161 return 0; 1160 return 0;
1162 } 1161 }
1163
1164 op->change_skill (skill); /* needed for proper exp credit */
1165 } 1162 }
1166 1163
1167 if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (spellparam))) 1164 if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (spellparam)))
1168 return RESULT_INT (0); 1165 return RESULT_INT (0);
1166
1167 // temporaroly replace chosen_skill by skill, we assume skill *could* be applied,
1168 // at least temporarily, which might not be true due to slot restrictions, but hey
1169 // invoke requires it basically.
1170
1171 object *chosen_skill = op->chosen_skill;
1172 op->chosen_skill = skill;
1169 1173
1170 switch (spell_ob->subtype) 1174 switch (spell_ob->subtype)
1171 { 1175 {
1172 /* The order of case statements is same as the order they show up 1176 /* The order of case statements is same as the order they show up
1173 * in spells.h. 1177 * in spells.h.
1324 break; 1328 break;
1325 1329
1326 case SP_MOVING_BALL: 1330 case SP_MOVING_BALL:
1327 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled) 1331 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled)
1328 { 1332 {
1329 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name)); 1333 op->failmsgf ("You lack the proper attunement to cast %s!", &spell_ob->name);
1330 success = 0; 1334 success = 0;
1331 } 1335 }
1332 else 1336 else
1333 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob); 1337 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1334 break; 1338 break;
1383 break; 1387 break;
1384 1388
1385 default: 1389 default:
1386 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); 1390 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1387 } 1391 }
1392
1393 // restore chosen_skill
1394 op->chosen_skill = chosen_skill;
1388 1395
1389 op->play_sound ( 1396 op->play_sound (
1390 success 1397 success
1391 ? spell_ob->sound 1398 ? spell_ob->sound
1392 ? spell_ob->sound 1399 ? spell_ob->sound
1446 move_aura (op); 1453 move_aura (op);
1447 break; 1454 break;
1448 } 1455 }
1449} 1456}
1450 1457
1451/* this checks to see if something special should happen if
1452 * something runs into the object.
1453 */
1454static void
1455check_spell_effect (object *op)
1456{
1457 switch (op->subtype)
1458 {
1459 case SP_BOLT:
1460 move_bolt (op);
1461 return;
1462
1463 case SP_BULLET:
1464 check_bullet (op);
1465 return;
1466 }
1467}
1468
1469/* This is called by move_apply. Basically, if someone 1458/* This is called by move_apply. Basically, if someone
1470 * moves onto a spell effect and the walk_on or fly_on flags 1459 * moves onto a spell effect and the walk_on or fly_on flags
1471 * are set, this is called. This should only be called for 1460 * are set, this is called. This should only be called for
1472 * objects of the appropriate type. 1461 * objects of the appropriate type.
1473 */ 1462 */
1475apply_spell_effect (object *spell, object *victim) 1464apply_spell_effect (object *spell, object *victim)
1476{ 1465{
1477 switch (spell->subtype) 1466 switch (spell->subtype)
1478 { 1467 {
1479 case SP_CONE: 1468 case SP_CONE:
1480 if (QUERY_FLAG (victim, FLAG_ALIVE) && spell->speed && spell->attacktype) 1469 if (QUERY_FLAG (victim, FLAG_ALIVE) && spell->has_active_speed () && spell->attacktype)
1481 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 0); 1470 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 0);
1482 break; 1471 break;
1483 1472
1484 case SP_MAGIC_MISSILE: 1473 case SP_MAGIC_MISSILE:
1485 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1474 if (QUERY_FLAG (victim, FLAG_ALIVE))
1490 break; 1479 break;
1491 1480
1492 case SP_MOVING_BALL: 1481 case SP_MOVING_BALL:
1493 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1482 if (QUERY_FLAG (victim, FLAG_ALIVE))
1494 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1483 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1495 else if (victim->materialname) 1484 else if (victim->material != MATERIAL_NULL)
1496 save_throw_object (victim, spell->attacktype, spell); 1485 save_throw_object (victim, spell->attacktype, spell);
1497 1486
1498 break; 1487 break;
1499 } 1488 }
1500} 1489}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines