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.37 by root, Tue Feb 13 21:28:11 2007 UTC vs.
Revision 1.42 by root, Mon Apr 30 04:25:30 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23 */ 23 */
24 24
25
26#include <global.h> 25#include <global.h>
27#include <spells.h> 26#include <spells.h>
28#include <object.h> 27#include <object.h>
29#include <errno.h> 28#include <errno.h>
30#include <sproto.h> 29#include <sproto.h>
188 * is being cast at. 187 * is being cast at.
189 * Note that I changed the repelled/attuned bonus to 2 from 5. 188 * Note that I changed the repelled/attuned bonus to 2 from 5.
190 * This is because the new code compares casting_level against 189 * This is because the new code compares casting_level against
191 * min_caster_level, so the difference is effectively 4 190 * min_caster_level, so the difference is effectively 4
192 */ 191 */
193
194int 192int
195caster_level (object *caster, object *spell) 193caster_level (object *caster, object *spell)
196{ 194{
197 int level = caster->level; 195 int level = caster->level;
198 196
213 211
214 level = MIN (level, sk_level + level / 10 + 1); 212 level = MIN (level, sk_level + level / 10 + 1);
215 } 213 }
216 214
217 /* Got valid caster level. Now adjust for attunement */ 215 /* Got valid caster level. Now adjust for attunement */
218 level += ((caster->path_repelled & spell->path_attuned) ? -2 : 0) + ((caster->path_attuned & spell->path_attuned) ? 2 : 0); 216 level += caster->path_repelled & spell->path_attuned ? -2 : 0;
217 level += caster->path_attuned & spell->path_attuned ? +2 : 0;
219 218
220 /* Always make this at least 1. If this is zero, we get divide by zero 219 /* Always make this at least 1. If this is zero, we get divide by zero
221 * errors in various places. 220 * errors in various places.
222 */ 221 */
223 if (level < 1)
224 level = 1;
225
226 return level; 222 return max (level, 1);
227} 223}
228 224
229/* The following function scales the spellpoint cost of 225/* The following function scales the spellpoint cost of
230 * a spell by it's increased effectiveness. Some of the 226 * a spell by it's increased effectiveness. Some of the
231 * lower level spells become incredibly vicious at high 227 * lower level spells become incredibly vicious at high
500 * resources, and may not work as well if a player is standing 496 * resources, and may not work as well if a player is standing
501 * on top of a counterwall spell (may hit the player before being 497 * on top of a counterwall spell (may hit the player before being
502 * removed.) On the other hand, it may be more dramatic for the 498 * removed.) On the other hand, it may be more dramatic for the
503 * spell to actually hit the counterwall and be sucked up. 499 * spell to actually hit the counterwall and be sucked up.
504 */ 500 */
505 if ((tmp->attacktype & AT_COUNTERSPELL) && 501 if ((tmp->attacktype & AT_COUNTERSPELL)
506 (tmp->type != PLAYER) && !QUERY_FLAG (tmp, FLAG_MONSTER) && 502 && !QUERY_FLAG (tmp, FLAG_MONSTER)
507 (tmp->type != WEAPON) && (tmp->type != BOW) && (tmp->type != ARROW) && (tmp->type != GOLEM) && (immune_stop & AT_MAGIC)) 503 && (tmp->type != PLAYER)
504 && (tmp->type != WEAPON)
505 && (tmp->type != BOW)
506 && (tmp->type != ARROW)
507 && (tmp->type != GOLEM)
508 && !QUERY_FLAG (tmp, FLAG_IS_FLOOR) // XXX:
509 // we special case floor here because there
510 // are sometimes spell effect floors
511 // which are used to inflict damage
512 // (and those shouldn't go away from
513 // sanctuary) see also: permanent lava
514 && (immune_stop & AT_MAGIC))
508 return 0; 515 return 0;
509 516
510 /* This is to prevent 'out of control' spells. Basically, this 517 /* This is to prevent 'out of control' spells. Basically, this
511 * limits one spell effect per space per spell. This is definately 518 * limits one spell effect per space per spell. This is definately
512 * needed for performance reasons, and just for playability I believe. 519 * needed for performance reasons, and just for playability I believe.
727 return freedir[i]; 734 return freedir[i];
728 } 735 }
729 return -1; /* flag for "keep going the way you were" */ 736 return -1; /* flag for "keep going the way you were" */
730} 737}
731 738
732
733
734/* put_a_monster: puts a monster named monstername near by 739/* put_a_monster: puts a monster named monstername near by
735 * op. This creates the treasures for the monsters, and 740 * op. This creates the treasures for the monsters, and
736 * also deals with multipart monsters properly. 741 * also deals with multipart monsters properly.
737 */ 742 */
738
739void 743void
740put_a_monster (object *op, const char *monstername) 744put_a_monster (object *op, const char *monstername)
741{ 745{
742 object *tmp, *head = NULL, *prev = NULL; 746 object *tmp, *head = NULL, *prev = NULL;
743 archetype *at; 747 archetype *at;
816{ 820{
817 int attacktype; 821 int attacktype;
818 int face; 822 int face;
819} ATTACKS[22] = 823} ATTACKS[22] =
820{ 824{
821 {
822 AT_PHYSICAL, 0}, 825 { AT_PHYSICAL, 0},
823 {
824 AT_PHYSICAL, 0}, /*face = explosion */ 826 { AT_PHYSICAL, 0}, /*face = explosion */
825 {
826 AT_PHYSICAL, 0}, 827 { AT_PHYSICAL, 0},
827 {
828 AT_MAGIC, 1}, 828 { AT_MAGIC, 1},
829 {
830 AT_MAGIC, 1}, /* face = last-burnout */ 829 { AT_MAGIC, 1}, /* face = last-burnout */
831 {
832 AT_MAGIC, 1}, 830 { AT_MAGIC, 1},
833 {
834 AT_FIRE, 2}, 831 { AT_FIRE, 2},
835 {
836 AT_FIRE, 2}, /* face = fire.... */ 832 { AT_FIRE, 2}, /* face = fire.... */
837 {
838 AT_FIRE, 2}, 833 { AT_FIRE, 2},
839 {
840 AT_ELECTRICITY, 3}, 834 { AT_ELECTRICITY, 3},
841 {
842 AT_ELECTRICITY, 3}, /* ball_lightning */ 835 { AT_ELECTRICITY, 3}, /* ball_lightning */
843 {
844 AT_ELECTRICITY, 3}, 836 { AT_ELECTRICITY, 3},
845 {
846 AT_COLD, 4}, 837 { AT_COLD, 4},
847 {
848 AT_COLD, 4}, /* face=icestorm */ 838 { AT_COLD, 4}, /* face=icestorm */
849 {
850 AT_COLD, 4}, 839 { AT_COLD, 4},
851 {
852 AT_CONFUSION, 5}, 840 { AT_CONFUSION, 5},
853 {
854 AT_POISON, 7}, 841 { AT_POISON, 7},
855 {
856 AT_POISON, 7}, /* face = acid sphere. generator */ 842 { AT_POISON, 7}, /* face = acid sphere. generator */
857 {
858 AT_POISON, 7}, /* poisoncloud face */ 843 { AT_POISON, 7}, /* poisoncloud face */
859 {
860 AT_SLOW, 8}, 844 { AT_SLOW, 8},
861 {
862 AT_PARALYZE, 9}, 845 { AT_PARALYZE, 9},
863 {
864AT_FEAR, 10}}; 846 { AT_FEAR, 10},
865 847};
866
867 848
868/* shuffle_attack: peterm 849/* shuffle_attack: peterm
869 * This routine shuffles the attack of op to one of the 850 * This routine shuffles the attack of op to one of the
870 * ones in the list. It does this at random. It also 851 * ones in the list. It does this at random. It also
871 * chooses a face appropriate to the attack that is 852 * chooses a face appropriate to the attack that is
1009 990
1010int 991int
1011cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 992cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1012{ 993{
1013 int success; 994 int success;
1014 player *pl;
1015 object *spell; 995 object *spell;
1016 996
1017 if (!spell_ob->other_arch) 997 if (!spell_ob->other_arch)
1018 { 998 {
1019 LOG (llevError, "cast_party_spell: empty other arch\n"); 999 LOG (llevError, "cast_party_spell: empty other arch\n");
1063 * 1043 *
1064 * if it is a player casting the spell (op->type == PLAYER, op == caster), 1044 * if it is a player casting the spell (op->type == PLAYER, op == caster),
1065 * this function will decrease the mana/grace appropriately. For other 1045 * this function will decrease the mana/grace appropriately. For other
1066 * objects, the caller should do what it considers appropriate. 1046 * objects, the caller should do what it considers appropriate.
1067 */ 1047 */
1068
1069int 1048int
1070cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 1049cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1071{ 1050{
1072 const char *godname; 1051 const char *godname;
1073 int success = 0, mflags, cast_level = 0, old_shoottype; 1052 int success = 0, mflags, cast_level = 0;
1074 object *skill = NULL; 1053 object *skill = NULL;
1075
1076 old_shoottype = op->contr ? op->contr->shoottype : 0;
1077 1054
1078 if (!spell_ob) 1055 if (!spell_ob)
1079 { 1056 {
1080 LOG (llevError, "cast_spell: null spell object passed\n"); 1057 LOG (llevError, "cast_spell: null spell object passed\n");
1081 return 0; 1058 return 0;
1174 if (failure < 0) 1151 if (failure < 0)
1175 { 1152 {
1176 new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use."); 1153 new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use.");
1177 if (settings.spell_failure_effects == TRUE) 1154 if (settings.spell_failure_effects == TRUE)
1178 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill); 1155 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill);
1179 op->contr->shoottype = (rangetype) old_shoottype; 1156
1180 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW); 1157 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1181 return 0; 1158 return 0;
1182 } 1159 }
1183 } 1160 }
1184 } 1161 }
1207 { 1184 {
1208 if (op->type != PLAYER) 1185 if (op->type != PLAYER)
1209 return 0; 1186 return 0;
1210 1187
1211 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) 1188 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)
1212 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname); 1189 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname);
1213 else 1190 else
1214 switch (op->contr->shoottype)
1215 {
1216 case range_magic:
1217 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting."); 1191 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the spell!");
1218 break; 1192
1219 case range_misc:
1220 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item.");
1221 break;
1222 case range_golem:
1223 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll.");
1224 break;
1225 default:
1226 break;
1227 }
1228 return 0; 1193 return 0;
1229 } 1194 }
1230 1195
1231 if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL) 1196 if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL)
1232 { 1197 {
1350 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1315 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1351 break; 1316 break;
1352 1317
1353 case SP_SUMMON_GOLEM: 1318 case SP_SUMMON_GOLEM:
1354 success = summon_golem (op, caster, dir, spell_ob); 1319 success = summon_golem (op, caster, dir, spell_ob);
1355 old_shoottype = range_golem;
1356 break; 1320 break;
1357 1321
1358 case SP_DIMENSION_DOOR: 1322 case SP_DIMENSION_DOOR:
1359 /* dimension door needs the actual caster, because that is what is 1323 /* dimension door needs the actual caster, because that is what is
1360 * moved. 1324 * moved.
1493 success = cast_consecrate (op, caster, spell_ob); 1457 success = cast_consecrate (op, caster, spell_ob);
1494 break; 1458 break;
1495 1459
1496 case SP_ANIMATE_WEAPON: 1460 case SP_ANIMATE_WEAPON:
1497 success = animate_weapon (op, caster, spell_ob, dir); 1461 success = animate_weapon (op, caster, spell_ob, dir);
1498 old_shoottype = range_golem;
1499 break; 1462 break;
1500 1463
1501 case SP_LIGHT: 1464 case SP_LIGHT:
1502 success = cast_light (op, caster, spell_ob, dir); 1465 success = cast_light (op, caster, spell_ob, dir);
1503 break; 1466 break;
1538 1501
1539 /* free the spell arg */ 1502 /* free the spell arg */
1540 if (settings.casting_time == TRUE && stringarg) 1503 if (settings.casting_time == TRUE && stringarg)
1541 { 1504 {
1542 free (stringarg); 1505 free (stringarg);
1543 stringarg = NULL; 1506 stringarg = 0;
1544 } 1507 }
1545 /* perhaps a bit of a hack, but if using a wand, it has to change the skill
1546 * to something like use_magic_item, but you really want to be able to fire
1547 * it again.
1548 */
1549 if (op->contr)
1550 op->contr->shoottype = (rangetype) old_shoottype;
1551 1508
1552 return success; 1509 return success;
1553} 1510}
1554 1511
1555 1512

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines