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

Comparing deliantra/server/server/spell_effect.C (file contents):
Revision 1.130 by root, Wed Apr 21 05:48:35 2010 UTC vs.
Revision 1.143 by root, Mon Nov 12 03:48:34 2012 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,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 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.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <object.h> 26#include <object.h>
73 if (!(random_roll (0, 3, op, PREFER_HIGH))) 73 if (!(random_roll (0, 3, op, PREFER_HIGH)))
74 { 74 {
75 op->failmsgf ("The %s vibrates violently, then explodes!", query_name (wand)); 75 op->failmsgf ("The %s vibrates violently, then explodes!", query_name (wand));
76 op->play_sound (sound_find ("ob_explode")); 76 op->play_sound (sound_find ("ob_explode"));
77 wand->destroy (); 77 wand->destroy ();
78 object *tmp = get_archetype (shstr_fireball); 78 object *tmp = archetype::get (shstr_fireball);
79 tmp->stats.dam = (spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob)) / 10; 79 tmp->stats.dam = (spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob)) / 10;
80 80
81 if (!tmp->stats.dam) 81 if (!tmp->stats.dam)
82 tmp->stats.dam = 1; 82 tmp->stats.dam = 1;
83 83
196 /* Can't get any money for these objects */ 196 /* Can't get any money for these objects */
197 missile->value = 0; 197 missile->value = 0;
198 198
199 missile->set_flag (FLAG_IDENTIFIED); 199 missile->set_flag (FLAG_IDENTIFIED);
200 200
201 if (!cast_create_obj (op, caster, missile, dir) && op->type == PLAYER && !missile->destroyed ()) 201 cast_create_obj (op, caster, missile, dir);
202
203 if (!dir
204 && op->type == PLAYER
205 && !missile->destroyed ())
202 pick_up (op, missile); 206 pick_up (op, missile);
203 207
204 return 1; 208 return 1;
205} 209}
206
207 210
208/* allows the choice of what sort of food object to make. 211/* allows the choice of what sort of food object to make.
209 * If spellparam is NULL, it will create food dependent on level --PeterM*/ 212 * If spellparam is NULL, it will create food dependent on level --PeterM*/
210int 213int
211cast_create_food (object *op, object *caster, object *spell_ob, int dir, const char *spellparam) 214cast_create_food (object *op, object *caster, object *spell_ob, int dir, const char *spellparam)
389 392
390 /* Remove the switch with 90% duplicate code - just handle the differences with 393 /* Remove the switch with 90% duplicate code - just handle the differences with
391 * and if statement or two. 394 * and if statement or two.
392 */ 395 */
393 op->invisible += spell_ob->duration + SP_level_duration_adjust (caster, spell_ob); 396 op->invisible += spell_ob->duration + SP_level_duration_adjust (caster, spell_ob);
397
394 /* max duration */ 398 /* limit duration */
395 if (op->invisible > 1000) 399 min_it (op->invisible, 1000);
396 op->invisible = 1000;
397 400
398 if (op->type == PLAYER) 401 if (op->type == PLAYER)
399 { 402 {
400 op->contr->invis_race = spell_ob->race; 403 op->contr->invis_race = spell_ob->race;
401 404
461 464
462void 465void
463execute_word_of_recall (object *op) 466execute_word_of_recall (object *op)
464{ 467{
465 if (object *pl = op->in_player ()) 468 if (object *pl = op->in_player ())
466 {
467 if (pl->ms ().flags () & P_NO_CLERIC && !pl->flag [FLAG_WIZCAST]) 469 if (pl->ms ().flags () & P_NO_CLERIC && !pl->flag [FLAG_WIZCAST])
468 new_draw_info (NDI_UNIQUE, 0, pl, "You feel something fizzle inside you."); 470 new_draw_info (NDI_UNIQUE, 0, pl, "You feel something fizzle inside you.");
469 else 471 else
470 pl->player_goto (op->slaying, op->stats.hp, op->stats.sp); 472 pl->player_goto (op->slaying, op->stats.hp, op->stats.sp);
471 }
472 473
473 op->destroy (); 474 op->destroy ();
474} 475}
475 476
476/* Word of recall causes the player to return 'home'. 477/* Word of recall causes the player to return 'home'.
478 * time delay effect. 479 * time delay effect.
479 */ 480 */
480int 481int
481cast_word_of_recall (object *op, object *caster, object *spell_ob) 482cast_word_of_recall (object *op, object *caster, object *spell_ob)
482{ 483{
483 object *dummy; 484 if (!op->is_player ())
484 int time;
485
486 if (op->type != PLAYER)
487 return 0; 485 return 0;
488 486
489 if (find_obj_by_type_subtype (op, SPELL_EFFECT, SP_WORD_OF_RECALL)) 487 if (find_obj_by_type_subtype (op, SPELL_EFFECT, SP_WORD_OF_RECALL))
490 { 488 {
491 new_draw_info (NDI_UNIQUE, 0, op, "You feel a force starting to build up inside you."); 489 new_draw_info (NDI_UNIQUE, 0, op, "You feel a force starting to build up inside you.");
492 return 1; 490 return 1;
493 } 491 }
494 492
495 dummy = get_archetype (FORCE_NAME); 493 object *dummy = archetype::get (FORCE_NAME);
496 494
497 if (!dummy)
498 {
499 new_draw_info (NDI_UNIQUE, 0, op, "Oops, program error!");
500 LOG (llevError, "cast_word_of_recall: get_archetype(force) failed!\n");
501 return 0;
502 }
503
504 time = spell_ob->duration - SP_level_duration_adjust (caster, spell_ob); 495 int time = max (1, spell_ob->duration - SP_level_duration_adjust (caster, spell_ob));
505 if (time < 1)
506 time = 1;
507 496
508 /* value of speed really doesn't make much difference, as long as it is 497 /* value of speed really doesn't make much difference, as long as it is
509 * positive. Lower value may be useful so that the problem doesn't 498 * positive. Lower value may be useful so that the problem doesn't
510 * do anything really odd if it say a -1000 or something. 499 * do anything really odd if it say a -1000 or something.
511 */ 500 */
512 dummy->set_speed (0.002); 501 dummy->set_speed (0.002);
513 dummy->speed_left = -dummy->speed * time; 502 dummy->speed_left = -dummy->speed * time;
514 dummy->type = SPELL_EFFECT; 503 dummy->type = SPELL_EFFECT;
515 dummy->subtype = SP_WORD_OF_RECALL; 504 dummy->subtype = SP_WORD_OF_RECALL;
516 505 dummy->slaying = op->contr->savebed_map;
517 /* If we could take advantage of enter_player_savebed() here, it would be 506 dummy->stats.hp = op->contr->bed_x;
518 * nice, but until the map load fails, we can't. 507 dummy->stats.sp = op->contr->bed_y;
519 */
520 EXIT_PATH (dummy) = op->contr->savebed_map;
521 EXIT_X (dummy) = op->contr->bed_x;
522 EXIT_Y (dummy) = op->contr->bed_y;
523 508
524 op->insert (dummy); 509 op->insert (dummy);
525 510
526 new_draw_info (NDI_UNIQUE, 0, op, "You feel a force starting to build up inside you."); 511 new_draw_info (NDI_UNIQUE, 0, op, "You feel a force starting to build up inside you.");
527 512
1090 1075
1091 new_draw_info_format (NDI_UNIQUE, 0, op, 1076 new_draw_info_format (NDI_UNIQUE, 0, op,
1092 "You create an aura of magical force. H<The effect will last for about %.10g seconds.>", 1077 "You create an aura of magical force. H<The effect will last for about %.10g seconds.>",
1093 TICK2TIME (duration)); 1078 TICK2TIME (duration));
1094 1079
1095 force = get_archetype (FORCE_NAME); 1080 force = archetype::get (FORCE_NAME);
1096 force->subtype = FORCE_CHANGE_ABILITY; 1081 force->subtype = FORCE_CHANGE_ABILITY;
1097 force->duration = duration; 1082 force->duration = duration;
1098 1083
1099 if (spell_ob->race) 1084 if (spell_ob->race)
1100 force->name = spell_ob->race; 1085 force->name = spell_ob->race;
1107 force->speed_left = -1.0; 1092 force->speed_left = -1.0;
1108 force->set_flag (FLAG_APPLIED); 1093 force->set_flag (FLAG_APPLIED);
1109 1094
1110 /* Now start processing the effects. First, protections */ 1095 /* Now start processing the effects. First, protections */
1111 for (i = 0; i < NROFATTACKS; i++) 1096 for (i = 0; i < NROFATTACKS; i++)
1112 {
1113 if (spell_ob->resist[i]) 1097 if (spell_ob->resist[i])
1114 {
1115 force->resist[i] = spell_ob->resist[i] + SP_level_dam_adjust (caster, spell_ob); 1098 force->resist[i] = min (100, spell_ob->resist[i] + SP_level_dam_adjust (caster, spell_ob));
1116 if (force->resist[i] > 100)
1117 force->resist[i] = 100;
1118 }
1119 }
1120 1099
1121 if (spell_ob->stats.hp) 1100 if (spell_ob->stats.hp)
1122 force->stats.hp = spell_ob->stats.hp + SP_level_dam_adjust (caster, spell_ob); 1101 force->stats.hp = spell_ob->stats.hp + SP_level_dam_adjust (caster, spell_ob);
1123 1102
1124 if (tmp->type == PLAYER) 1103 if (tmp->type == PLAYER)
1210 } 1189 }
1211 } 1190 }
1212 1191
1213 if (force == NULL) 1192 if (force == NULL)
1214 { 1193 {
1215 force = get_archetype (FORCE_NAME); 1194 force = archetype::get (FORCE_NAME);
1216 force->subtype = FORCE_CHANGE_ABILITY; 1195 force->subtype = FORCE_CHANGE_ABILITY;
1217 if (spell_ob->race) 1196 if (spell_ob->race)
1218 force->name = spell_ob->race; 1197 force->name = spell_ob->race;
1219 else 1198 else
1220 force->name = spell_ob->name; 1199 force->name = spell_ob->name;
1235 { 1214 {
1236 new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect."); 1215 new_draw_info (NDI_UNIQUE, 0, op, "Recasting the spell had no effect.");
1237 } 1216 }
1238 return 0; 1217 return 0;
1239 } 1218 }
1219
1240 force->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50; 1220 force->duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob) * 50;
1241 force->speed = 1.0; 1221 force->speed = 1.0;
1242 force->speed_left = -1.0; 1222 force->speed_left = -1.0;
1243 force->set_flag (FLAG_APPLIED); 1223 force->set_flag (FLAG_APPLIED);
1244 1224
1280 1260
1281/* Alchemy code by Mark Wedel 1261/* Alchemy code by Mark Wedel
1282 * 1262 *
1283 * This code adds a new spell, called alchemy. Alchemy will turn 1263 * This code adds a new spell, called alchemy. Alchemy will turn
1284 * objects to pyrite ("false gold"), henceforth called gold nuggets. 1264 * objects to pyrite ("false gold"), henceforth called gold nuggets.
1285 * 1265 *
1286 * The value of the gold nuggets being about 90% of that of the item 1266 * The value of the gold nuggets being about 90% of that of the item
1287 * itself. It uses the value of the object before charisma adjustments, 1267 * itself. It uses the value of the object before charisma adjustments,
1288 * because the nuggets themselves will be will be adjusted by charisma 1268 * because the nuggets themselves will be will be adjusted by charisma
1289 * when sold. 1269 * when sold.
1290 * 1270 *
1392 } 1372 }
1393 1373
1394 value -= rndm (value >> 4); 1374 value -= rndm (value >> 4);
1395 value = min (value, value_max); 1375 value = min (value, value_max);
1396 1376
1397 for (int i = 0; i < sizeof (nugget) / sizeof (nugget [0]); ++i) 1377 for (int i = 0; i < array_length (nugget); ++i)
1398 if (int nrof = value / nugget [i]->value) 1378 if (int nrof = value / nugget [i]->value)
1399 { 1379 {
1400 value -= nrof * nugget[i]->value; 1380 value -= nrof * nugget[i]->value;
1401 1381
1402 object *tmp = nugget[i]->instance (); 1382 object *tmp = nugget[i]->instance ();
1420int 1400int
1421remove_curse (object *op, object *caster, object *spell) 1401remove_curse (object *op, object *caster, object *spell)
1422{ 1402{
1423 int success = 0, was_one = 0; 1403 int success = 0, was_one = 0;
1424 1404
1405 int num_uncurse = max (1, spell->stats.dam + SP_level_dam_adjust (caster, spell));
1406
1407 op->splay_marked ();
1408
1409 int typeflag = spell->last_sp ? FLAG_DAMNED : FLAG_CURSED;
1410
1425 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1411 for (object *tmp = op->inv; tmp && num_uncurse; tmp = tmp->below)
1426 if (tmp->flag [FLAG_APPLIED] && 1412 if (!tmp->invisible && tmp->flag [typeflag])
1427 ((tmp->flag [FLAG_CURSED] && spell->flag [FLAG_CURSED]) ||
1428 (tmp->flag [FLAG_DAMNED] && spell->flag [FLAG_DAMNED])))
1429 { 1413 {
1430 was_one++; 1414 ++was_one;
1431 1415
1432 if (tmp->level <= casting_level (caster, spell)) 1416 if (tmp->level <= casting_level (caster, spell))
1433 { 1417 {
1434 success++; 1418 ++success;
1435 if (spell->flag [FLAG_DAMNED]) 1419 --num_uncurse;
1436 tmp->clr_flag (FLAG_DAMNED);
1437 1420
1421 tmp->clr_flag (typeflag);
1438 tmp->clr_flag (FLAG_CURSED); 1422 tmp->clr_flag (FLAG_CURSED);
1439 tmp->clr_flag (FLAG_KNOWN_CURSED); 1423 tmp->clr_flag (FLAG_KNOWN_CURSED);
1440 tmp->value = 0; /* Still can't sell it */ 1424 tmp->value = 0; /* Still can't sell it */
1441 1425
1442 if (object *pl = tmp->visible_to ()) 1426 if (object *pl = tmp->visible_to ())
1445 } 1429 }
1446 1430
1447 if (op->type == PLAYER) 1431 if (op->type == PLAYER)
1448 { 1432 {
1449 if (success) 1433 if (success)
1450 new_draw_info (NDI_UNIQUE, 0, op, "You feel like some of your items are looser now."); 1434 new_draw_info (NDI_UNIQUE, 0, op, "You realise that some of your items look shinier now. H<You successfully removed some curses.>");
1451 else 1435 else
1452 { 1436 {
1453 if (was_one) 1437 if (was_one)
1454 new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove the curse."); 1438 new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove any curse. H<The spell was not strong enough.>");
1455 else 1439 else
1456 new_draw_info (NDI_UNIQUE, 0, op, "You are not using any cursed items."); 1440 new_draw_info (NDI_UNIQUE, 0, op, "You are not having any cursed items. H<Epic fail.>");
1457 } 1441 }
1458 } 1442 }
1459 1443
1460 return success; 1444 return success;
1461} 1445}
1462 1446
1463/* Identifies objects in the players inventory/on the ground */ 1447/* Identifies objects in the players inventory/on the ground */
1464int 1448int
1465cast_identify (object *op, object *caster, object *spell) 1449cast_identify (object *op, object *caster, object *spell)
1466{ 1450{
1467 object *tmp;
1468 dynbuf_text &buf = msg_dynbuf; buf.clear (); 1451 dynbuf_text &buf = msg_dynbuf; buf.clear ();
1469 1452
1470 int num_ident = max (1, spell->stats.dam + SP_level_dam_adjust (caster, spell)); 1453 int num_ident = max (1, spell->stats.dam + SP_level_dam_adjust (caster, spell));
1471 1454
1455 op->splay_marked ();
1456
1472 for (tmp = op->inv; tmp; tmp = tmp->below) 1457 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1473 { 1458 {
1474 if (!tmp->flag [FLAG_IDENTIFIED] && !tmp->invisible && tmp->need_identify ()) 1459 if (!tmp->flag [FLAG_IDENTIFIED] && !tmp->invisible && tmp->need_identify ())
1475 { 1460 {
1476 identify (tmp); 1461 identify (tmp);
1477 1462
1492 * stuff on the floor. Only identify stuff on the floor if the spell 1477 * stuff on the floor. Only identify stuff on the floor if the spell
1493 * was not fully used. 1478 * was not fully used.
1494 */ 1479 */
1495 if (num_ident) 1480 if (num_ident)
1496 { 1481 {
1497 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above) 1482 for (object *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
1498 if (!tmp->flag [FLAG_IDENTIFIED] && !tmp->invisible && tmp->need_identify ()) 1483 if (!tmp->flag [FLAG_IDENTIFIED] && !tmp->invisible && tmp->need_identify ())
1499 { 1484 {
1500 identify (tmp); 1485 identify (tmp);
1501 1486
1502 if (object *pl = tmp->visible_to ()) 1487 if (object *pl = tmp->visible_to ())
1529 1514
1530int 1515int
1531cast_detection (object *op, object *caster, object *spell, object *skill) 1516cast_detection (object *op, object *caster, object *spell, object *skill)
1532{ 1517{
1533 object *tmp, *last, *god, *detect; 1518 object *tmp, *last, *god, *detect;
1534 int done_one, range, mflags, floor, level; 1519 int done_one, range, floor, level;
1535 sint16 x, y, nx, ny; 1520 sint16 x, y, nx, ny;
1536 maptile *m; 1521 maptile *m;
1537 1522
1538 /* We precompute some values here so that we don't have to keep 1523 /* We precompute some values here so that we don't have to keep
1539 * doing it over and over again. 1524 * doing it over and over again.
2127 /* Improve weapon's armour value according to best save vs. physical of its material */ 2112 /* Improve weapon's armour value according to best save vs. physical of its material */
2128 2113
2129 if (a > 14) 2114 if (a > 14)
2130 a = 14; 2115 a = 14;
2131 2116
2132 tmp->resist[ATNR_PHYSICAL] = 100 - (int) ((100.0 - (float) tmp->resist[ATNR_PHYSICAL]) / (30.0 - 2.0 * a)); 2117 tmp->resist[ATNR_PHYSICAL] = 100 - (int) ((100.f - (float) tmp->resist[ATNR_PHYSICAL]) / (30.f - 2.f * a));
2133 2118
2134 /* Determine golem's speed */ 2119 /* Determine golem's speed */
2135 tmp->set_speed (min (3.33, 0.4 + 0.1 * SP_level_range_adjust (caster, spell))); 2120 tmp->set_speed (min (3.33f, 0.4f + 0.1f * SP_level_range_adjust (caster, spell)));
2136 2121
2137 if (!spell->race) 2122 if (!spell->race)
2138 { 2123 {
2139 sprintf (buf, "animated %s", &weapon->name); 2124 sprintf (buf, "animated %s", &weapon->name);
2140 tmp->name = buf; 2125 tmp->name = buf;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines