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.67 by root, Sun Apr 20 00:44:13 2008 UTC vs.
Revision 1.78 by root, Sun Sep 28 15:51:04 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
104{ 104{
105 if (caster->path_denied & spell->path_attuned) 105 if (caster->path_denied & spell->path_attuned)
106 return 1; 106 return 1;
107 107
108 int new_level = spell->level 108 int new_level = spell->level
109 + (caster->path_repelled & spell->path_attuned ? +8 : 0) 109 + (caster->path_repelled & spell->path_attuned ? +ATTUNE_REPELL : 0)
110 + (caster->path_attuned & spell->path_attuned ? -8 : 0); 110 + (caster->path_attuned & spell->path_attuned ? -ATTUNE_REPELL : 0);
111 111
112 return max (1, new_level); 112 return max (1, new_level);
113} 113}
114 114
115/* This function returns the effective level the spell 115/* This function returns the effective level the spell
138 level = caster->contr->last_skill_ob[i]->level; 138 level = caster->contr->last_skill_ob[i]->level;
139 break; 139 break;
140 } 140 }
141 141
142 /* Got valid caster level. Now adjust for attunement */ 142 /* Got valid caster level. Now adjust for attunement */
143 level += caster->path_repelled & spell->path_attuned ? -8 : 0; 143 level += caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0;
144 level += caster->path_attuned & spell->path_attuned ? +8 : 0; 144 level += caster->path_attuned & spell->path_attuned ? +ATTUNE_REPELL : 0;
145 145
146 /* Always make this at least 1. If this is zero, we get divide by zero 146 /* Always make this at least 1. If this is zero, we get divide by zero
147 * errors in various places. 147 * errors in various places.
148 */ 148 */
149 return max (level, 1); 149 return max (level, 1);
212 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags); 212 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
213 return 0; 213 return 0;
214 } 214 }
215} 215}
216 216
217/*
218 * Return the effective casting level of the spell.
219 */
220static int
221SP_casting_level (object *caster, object *spell)
222{
223 int level = caster_level (caster, spell);
224 return max (0, level - min_casting_level (caster, spell));
225}
226
217/* SP_level_dam_adjust: Returns adjusted damage based on the caster. 227/* SP_level_dam_adjust: Returns adjusted damage based on the caster.
218 * spob is the spell we are adjusting. 228 * spob is the spell we are adjusting.
219 */ 229 */
220int 230int
221SP_level_dam_adjust (object *caster, object *spob) 231SP_level_dam_adjust (object *caster, object *spob)
222{ 232{
223 if (!spob->dam_modifier) 233 if (!spob->dam_modifier)
224 return 0; 234 return 0;
225 235
226 int level = caster_level (caster, spob);
227 return max (0, level - min_casting_level (caster, spob)) / spob->dam_modifier; 236 return SP_casting_level (caster, spob) / spob->dam_modifier;
228} 237}
229 238
230/* Adjust the strength of the spell based on level. 239/* Adjust the strength of the spell based on level.
231 * This is basically the same as SP_level_dam_adjust above, 240 * This is basically the same as SP_level_dam_adjust above,
232 * but instead looks at the level_modifier value. 241 * but instead looks at the level_modifier value.
235SP_level_duration_adjust (object *caster, object *spob) 244SP_level_duration_adjust (object *caster, object *spob)
236{ 245{
237 if (!spob->duration_modifier) 246 if (!spob->duration_modifier)
238 return 0; 247 return 0;
239 248
240 int level = caster_level (caster, spob);
241 return max (0, level - min_casting_level (caster, spob)) / spob->duration_modifier; 249 return SP_casting_level (caster, spob) / spob->duration_modifier;
242} 250}
243 251
244/* Adjust the strength of the spell based on level. 252/* Adjust the strength of the spell based on level.
245 * This is basically the same as SP_level_dam_adjust above, 253 * This is basically the same as SP_level_dam_adjust above,
246 * but instead looks at the level_modifier value. 254 * but instead looks at the level_modifier value.
250{ 258{
251 if (!spob->range_modifier) 259 if (!spob->range_modifier)
252 return 0; 260 return 0;
253 261
254 int level = caster_level (caster, spob); 262 int level = caster_level (caster, spob);
255 return (level - min_casting_level (caster, spob)) / spob->range_modifier; 263 return SP_casting_level (caster, spob) / spob->range_modifier;
256} 264}
257 265
258/* Checks to see if player knows the spell. If the name is the same 266/* Checks to see if player knows the spell. If the name is the same
259 * as an existing spell, we presume they know it. 267 * as an existing spell, we presume they know it.
260 * returns 1 if they know the spell, 0 if they don't. 268 * returns 1 if they know the spell, 0 if they don't.
261 */ 269 */
262object * 270object *
263check_spell_known (object *op, const char *name) 271check_spell_known (object *op, const char *name)
264{ 272{
265 object *spop; 273 object *spop;
274 shstr_cmp name_ (name);
266 275
267 for (spop = op->inv; spop; spop = spop->below) 276 for (spop = op->inv; spop; spop = spop->below)
268 if (spop->type == SPELL && !strcmp (spop->name, name)) 277 if (spop->type == SPELL && spop->name == name)
269 return spop; 278 return spop;
270 279
271 return NULL; 280 return 0;
272} 281}
273 282
274 283
275/* 284/*
276 * Look at object 'op' and see if they know the spell 285 * Look at object 'op' and see if they know the spell
393{ 402{
394 if (!xy_normalise (m, x, y)) 403 if (!xy_normalise (m, x, y))
395 return 0; 404 return 0;
396 405
397 mapspace &ms = m->at (x, y); 406 mapspace &ms = m->at (x, y);
407 ms.update ();
398 408
399 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) 409 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
400 return 0; 410 return 0;
401 411
402 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 412 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
438 /* 448 /*
439 * Combine similar spell effects into one spell effect. Needed for 449 * Combine similar spell effects into one spell effect. Needed for
440 * performance reasons with meteor swarm and the like, but also for 450 * performance reasons with meteor swarm and the like, but also for
441 * playability reasons. 451 * playability reasons.
442 */ 452 */
443 if (tmp->arch == op->arch 453 if (tmp->arch == op->arch /* no harm if not comparing by name here */
444 && tmp->type == op->type 454 && tmp->type == op->type
445 && tmp->subtype == op->subtype 455 && tmp->subtype == op->subtype
446 && tmp->owner == op->owner 456 && tmp->owner == op->owner
447 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) 457 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
448 { 458 {
472 * returns 0 on failure, 1 on success. 482 * returns 0 on failure, 1 on success.
473 */ 483 */
474int 484int
475fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 485fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
476{ 486{
477 object *tmp;
478 int mflags;
479 maptile *m;
480
481 if (spell->other_arch == NULL) 487 if (!spell->other_arch)
482 return 0; 488 return 0;
483 489
484 m = op->map; 490 object *tmp = spell->other_arch->instance ();
485 mflags = get_map_flags (m, &m, x, y, &x, &y);
486 if (mflags & P_OUT_OF_MAP)
487 {
488 return 0;
489 }
490 491
491 tmp = arch_to_object (spell->other_arch); 492 if (!tmp)
492
493 if (tmp == NULL)
494 return 0; 493 return 0;
495
496 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y)))
497 {
498 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n");
499 tmp->destroy ();
500 return 0;
501 }
502 494
503 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 495 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
504 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); 496 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
505 /* code in time.c uses food for some things, duration for others */ 497 /* code in time.c uses food for some things, duration for others */
506 tmp->stats.food = tmp->duration; 498 tmp->stats.food = tmp->duration;
507 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 499 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
508 tmp->attacktype = spell->attacktype; 500 tmp->attacktype = spell->attacktype;
509 tmp->x = x;
510 tmp->y = y;
511 tmp->direction = dir; 501 tmp->direction = dir;
512 if (op->owner != NULL)
513 tmp->set_owner (op); 502 tmp->set_owner (op);
514 else
515 tmp->set_owner (op);
516 tmp->level = caster_level (caster, spell); 503 tmp->level = caster_level (caster, spell);
517 set_spell_skill (op, caster, spell, tmp); 504 set_spell_skill (op, caster, spell, tmp);
518 505
519 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 506 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
520 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 507 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
521 {
522 if (!tailor_god_spell (tmp, op)) 508 if (!tailor_god_spell (tmp, op))
523 return 0; 509 return 0;
524 } 510
525 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 511 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
526 SET_ANIMATION (tmp, dir); 512 SET_ANIMATION (tmp, dir);
527 513
528 if ((tmp = insert_ob_in_map (tmp, m, op, 0))) 514 if ((tmp = op->map->insert (tmp, x, y, op)))
529 move_spell_effect (tmp); 515 move_spell_effect (tmp);
530 516
531 return 1; 517 return 1;
532} 518}
533 519
588 if (!tmp) 574 if (!tmp)
589 tmp = op->ms ().player (); 575 tmp = op->ms ().player ();
590 576
591 return tmp; 577 return tmp;
592} 578}
593
594
595 579
596/* raytrace: 580/* raytrace:
597 * spell_find_dir(map, x, y, exclude) will search first the center square 581 * spell_find_dir(map, x, y, exclude) will search first the center square
598 * then some close squares in the given map at the given coordinates for 582 * then some close squares in the given map at the given coordinates for
599 * live objects. 583 * live objects.
602 * monsters/generators only. If not, the spell will hunt players only. 586 * monsters/generators only. If not, the spell will hunt players only.
603 * It returns the direction toward the first/closest live object if it finds 587 * It returns the direction toward the first/closest live object if it finds
604 * any, otherwise -1. 588 * any, otherwise -1.
605 * note that exclude can be NULL, in which case all bets are off. 589 * note that exclude can be NULL, in which case all bets are off.
606 */ 590 */
607
608int 591int
609spell_find_dir (maptile *m, int x, int y, object *exclude) 592spell_find_dir (maptile *m, int x, int y, object *exclude)
610{ 593{
611 int i, max = SIZEOFFREE; 594 int i, max = SIZEOFFREE;
612 sint16 nx, ny; 595 sint16 nx, ny;
692 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 675 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
693 676
694 insert_ob_in_map (head, op->map, op, 0); 677 insert_ob_in_map (head, op->map, op, 0);
695 678
696 /* thought it'd be cool to insert a burnout, too. */ 679 /* thought it'd be cool to insert a burnout, too. */
697 op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op); 680 op->map->insert (archetype::get (shstr_burnout), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
698 } 681 }
699} 682}
700 683
701/* peterm: function which summons hostile monsters and 684/* peterm: function which summons hostile monsters and
702 * places them in nearby squares. 685 * places them in nearby squares.
1004 { 987 {
1005 skill = find_skill_by_name (op, spell_ob->skill); 988 skill = find_skill_by_name (op, spell_ob->skill);
1006 989
1007 if (!skill) 990 if (!skill)
1008 { 991 {
1009 op->failmsg (format ("You need the skill %s to cast %s!", &spell_ob->skill, &spell_ob->name)); 992 op->failmsg (format ("You need the skill %s to cast %s! "
993 "H<You either need to learn the skill via a skill scroll "
994 "or you need to wear a talisman or holy symbol.>",
995 &spell_ob->skill, &spell_ob->name));
1010 return 0; 996 return 0;
1011 } 997 }
1012 998
999 int casting_level = min_casting_level (op, spell_ob);
1000
1013 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 1001 if (casting_level > cast_level && !QUERY_FLAG (op, FLAG_WIZ))
1014 { 1002 {
1015 op->failmsg ("You lack enough skill to cast that spell!"); 1003 op->failmsg (format ("You lack enough skill to cast that spell! "
1004 "H<Your cast level is %d, but level %d is required. Maybe you are repelled?>",
1005 cast_level, casting_level));
1016 return 0; 1006 return 0;
1017 } 1007 }
1018 } 1008 }
1019 1009
1020 /* If the caster is the wiz, they don't ever fail, and don't have 1010 /* If the caster is the wiz, they don't ever fail, and don't have
1196 case SP_SMITE: 1186 case SP_SMITE:
1197 success = cast_smite_spell (op, caster, dir, spell_ob); 1187 success = cast_smite_spell (op, caster, dir, spell_ob);
1198 break; 1188 break;
1199 1189
1200 case SP_MAGIC_MISSILE: 1190 case SP_MAGIC_MISSILE:
1201 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1191 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1202 break; 1192 break;
1203 1193
1204 case SP_SUMMON_GOLEM: 1194 case SP_SUMMON_GOLEM:
1205 success = summon_golem (op, caster, dir, spell_ob); 1195 success = summon_golem (op, caster, dir, spell_ob);
1206 break; 1196 break;
1317 { 1307 {
1318 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name)); 1308 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name));
1319 success = 0; 1309 success = 0;
1320 } 1310 }
1321 else 1311 else
1322 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1312 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1323 break; 1313 break;
1324 1314
1325 case SP_SWARM: 1315 case SP_SWARM:
1326 success = fire_swarm (op, caster, spell_ob, dir); 1316 success = fire_swarm (op, caster, spell_ob, dir);
1327 break; 1317 break;
1453 check_bullet (op); 1443 check_bullet (op);
1454 return; 1444 return;
1455 } 1445 }
1456} 1446}
1457 1447
1458/* This is called by move_apply. Basically, if someone 1448/* This is called by move_apply. Basically, if someone
1459 * moves onto a spell effect and the walk_on or fly_on flags 1449 * moves onto a spell effect and the walk_on or fly_on flags
1460 * are set, this is called. This should only be called for 1450 * are set, this is called. This should only be called for
1461 * objects of the appropraite type. 1451 * objects of the appropriate type.
1462 */ 1452 */
1463void 1453void
1464apply_spell_effect (object *spell, object *victim) 1454apply_spell_effect (object *spell, object *victim)
1465{ 1455{
1466 switch (spell->subtype) 1456 switch (spell->subtype)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines