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 | * |
… | |
… | |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
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 | |
|
|
25 | |
24 | |
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> |
… | |
… | |
1044 | * |
1043 | * |
1045 | * 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), |
1046 | * this function will decrease the mana/grace appropriately. For other |
1045 | * this function will decrease the mana/grace appropriately. For other |
1047 | * objects, the caller should do what it considers appropriate. |
1046 | * objects, the caller should do what it considers appropriate. |
1048 | */ |
1047 | */ |
1049 | |
|
|
1050 | int |
1048 | int |
1051 | cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
1049 | cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
1052 | { |
1050 | { |
1053 | const char *godname; |
1051 | const char *godname; |
1054 | int success = 0, mflags, cast_level = 0, old_shoottype; |
1052 | int success = 0, mflags, cast_level = 0; |
1055 | object *skill = NULL; |
1053 | object *skill = NULL; |
1056 | |
|
|
1057 | old_shoottype = op->contr ? op->contr->shoottype : 0; |
|
|
1058 | |
1054 | |
1059 | if (!spell_ob) |
1055 | if (!spell_ob) |
1060 | { |
1056 | { |
1061 | LOG (llevError, "cast_spell: null spell object passed\n"); |
1057 | LOG (llevError, "cast_spell: null spell object passed\n"); |
1062 | return 0; |
1058 | return 0; |
… | |
… | |
1155 | if (failure < 0) |
1151 | if (failure < 0) |
1156 | { |
1152 | { |
1157 | 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."); |
1158 | if (settings.spell_failure_effects == TRUE) |
1154 | if (settings.spell_failure_effects == TRUE) |
1159 | 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); |
1160 | op->contr->shoottype = (rangetype) old_shoottype; |
1156 | |
1161 | 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); |
1162 | return 0; |
1158 | return 0; |
1163 | } |
1159 | } |
1164 | } |
1160 | } |
1165 | } |
1161 | } |
… | |
… | |
1188 | { |
1184 | { |
1189 | if (op->type != PLAYER) |
1185 | if (op->type != PLAYER) |
1190 | return 0; |
1186 | return 0; |
1191 | |
1187 | |
1192 | if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) |
1188 | if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) |
1193 | 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); |
1194 | else |
1190 | else |
1195 | switch (op->contr->shoottype) |
|
|
1196 | { |
|
|
1197 | case range_magic: |
|
|
1198 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting."); |
1191 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the spell!"); |
1199 | break; |
1192 | |
1200 | case range_misc: |
|
|
1201 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item."); |
|
|
1202 | break; |
|
|
1203 | case range_golem: |
|
|
1204 | new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll."); |
|
|
1205 | break; |
|
|
1206 | default: |
|
|
1207 | break; |
|
|
1208 | } |
|
|
1209 | return 0; |
1193 | return 0; |
1210 | } |
1194 | } |
1211 | |
1195 | |
1212 | if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL) |
1196 | if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL) |
1213 | { |
1197 | { |
… | |
… | |
1331 | 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); |
1332 | break; |
1316 | break; |
1333 | |
1317 | |
1334 | case SP_SUMMON_GOLEM: |
1318 | case SP_SUMMON_GOLEM: |
1335 | success = summon_golem (op, caster, dir, spell_ob); |
1319 | success = summon_golem (op, caster, dir, spell_ob); |
1336 | old_shoottype = range_golem; |
|
|
1337 | break; |
1320 | break; |
1338 | |
1321 | |
1339 | case SP_DIMENSION_DOOR: |
1322 | case SP_DIMENSION_DOOR: |
1340 | /* dimension door needs the actual caster, because that is what is |
1323 | /* dimension door needs the actual caster, because that is what is |
1341 | * moved. |
1324 | * moved. |
… | |
… | |
1474 | success = cast_consecrate (op, caster, spell_ob); |
1457 | success = cast_consecrate (op, caster, spell_ob); |
1475 | break; |
1458 | break; |
1476 | |
1459 | |
1477 | case SP_ANIMATE_WEAPON: |
1460 | case SP_ANIMATE_WEAPON: |
1478 | success = animate_weapon (op, caster, spell_ob, dir); |
1461 | success = animate_weapon (op, caster, spell_ob, dir); |
1479 | old_shoottype = range_golem; |
|
|
1480 | break; |
1462 | break; |
1481 | |
1463 | |
1482 | case SP_LIGHT: |
1464 | case SP_LIGHT: |
1483 | success = cast_light (op, caster, spell_ob, dir); |
1465 | success = cast_light (op, caster, spell_ob, dir); |
1484 | break; |
1466 | break; |
… | |
… | |
1519 | |
1501 | |
1520 | /* free the spell arg */ |
1502 | /* free the spell arg */ |
1521 | if (settings.casting_time == TRUE && stringarg) |
1503 | if (settings.casting_time == TRUE && stringarg) |
1522 | { |
1504 | { |
1523 | free (stringarg); |
1505 | free (stringarg); |
1524 | stringarg = NULL; |
1506 | stringarg = 0; |
1525 | } |
1507 | } |
1526 | /* perhaps a bit of a hack, but if using a wand, it has to change the skill |
|
|
1527 | * to something like use_magic_item, but you really want to be able to fire |
|
|
1528 | * it again. |
|
|
1529 | */ |
|
|
1530 | if (op->contr) |
|
|
1531 | op->contr->shoottype = (rangetype) old_shoottype; |
|
|
1532 | |
1508 | |
1533 | return success; |
1509 | return success; |
1534 | } |
1510 | } |
1535 | |
1511 | |
1536 | |
1512 | |