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.73 by root, Sat May 17 14:11:13 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
261 */ 261 */
262object * 262object *
263check_spell_known (object *op, const char *name) 263check_spell_known (object *op, const char *name)
264{ 264{
265 object *spop; 265 object *spop;
266 shstr_cmp name_ (name);
266 267
267 for (spop = op->inv; spop; spop = spop->below) 268 for (spop = op->inv; spop; spop = spop->below)
268 if (spop->type == SPELL && !strcmp (spop->name, name)) 269 if (spop->type == SPELL && spop->name == name)
269 return spop; 270 return spop;
270 271
271 return NULL; 272 return 0;
272} 273}
273 274
274 275
275/* 276/*
276 * Look at object 'op' and see if they know the spell 277 * Look at object 'op' and see if they know the spell
438 /* 439 /*
439 * Combine similar spell effects into one spell effect. Needed for 440 * Combine similar spell effects into one spell effect. Needed for
440 * performance reasons with meteor swarm and the like, but also for 441 * performance reasons with meteor swarm and the like, but also for
441 * playability reasons. 442 * playability reasons.
442 */ 443 */
443 if (tmp->arch == op->arch 444 if (tmp->arch == op->arch /* no harm if not comparing by name here */
444 && tmp->type == op->type 445 && tmp->type == op->type
445 && tmp->subtype == op->subtype 446 && tmp->subtype == op->subtype
446 && tmp->owner == op->owner 447 && tmp->owner == op->owner
447 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) 448 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
448 { 449 {
472 * returns 0 on failure, 1 on success. 473 * returns 0 on failure, 1 on success.
473 */ 474 */
474int 475int
475fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 476fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
476{ 477{
477 object *tmp;
478 int mflags;
479 maptile *m;
480
481 if (spell->other_arch == NULL) 478 if (!spell->other_arch)
482 return 0; 479 return 0;
483 480
484 m = op->map; 481 mapxy pos (op->map, x, y);//TODO, should not pass x, y
485 mflags = get_map_flags (m, &m, x, y, &x, &y);
486 if (mflags & P_OUT_OF_MAP)
487 {
488 return 0;
489 }
490 482
491 tmp = arch_to_object (spell->other_arch); 483 pos.move (dir ? dir : rndm (1, 8));
492 484
493 if (tmp == NULL) 485 if (!pos.normalise ())
494 return 0; 486 return 0;
495 487
496 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) 488 object *tmp = spell->other_arch->instance ();
489
490 if (!tmp)
491 return 0;
492
493 if (pos.ms ().blocks (tmp))
497 { 494 {
498 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); 495 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast this spell on top of a wall!\n");
499 tmp->destroy (); 496 tmp->destroy ();
500 return 0; 497 return 0;
501 } 498 }
502 499
503 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 500 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
507 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 504 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
508 tmp->attacktype = spell->attacktype; 505 tmp->attacktype = spell->attacktype;
509 tmp->x = x; 506 tmp->x = x;
510 tmp->y = y; 507 tmp->y = y;
511 tmp->direction = dir; 508 tmp->direction = dir;
512 if (op->owner != NULL)
513 tmp->set_owner (op); 509 tmp->set_owner (op);
514 else
515 tmp->set_owner (op);
516 tmp->level = caster_level (caster, spell); 510 tmp->level = caster_level (caster, spell);
517 set_spell_skill (op, caster, spell, tmp); 511 set_spell_skill (op, caster, spell, tmp);
518 512
519 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 513 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
520 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 514 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
521 {
522 if (!tailor_god_spell (tmp, op)) 515 if (!tailor_god_spell (tmp, op))
523 return 0; 516 return 0;
524 } 517
525 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 518 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
526 SET_ANIMATION (tmp, dir); 519 SET_ANIMATION (tmp, dir);
527 520
528 if ((tmp = insert_ob_in_map (tmp, m, op, 0))) 521 if ((tmp = op->map->insert (tmp, x, y, op)))
529 move_spell_effect (tmp); 522 move_spell_effect (tmp);
530 523
531 return 1; 524 return 1;
532} 525}
533 526
588 if (!tmp) 581 if (!tmp)
589 tmp = op->ms ().player (); 582 tmp = op->ms ().player ();
590 583
591 return tmp; 584 return tmp;
592} 585}
593
594
595 586
596/* raytrace: 587/* raytrace:
597 * spell_find_dir(map, x, y, exclude) will search first the center square 588 * 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 589 * then some close squares in the given map at the given coordinates for
599 * live objects. 590 * live objects.
602 * monsters/generators only. If not, the spell will hunt players only. 593 * 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 594 * It returns the direction toward the first/closest live object if it finds
604 * any, otherwise -1. 595 * any, otherwise -1.
605 * note that exclude can be NULL, in which case all bets are off. 596 * note that exclude can be NULL, in which case all bets are off.
606 */ 597 */
607
608int 598int
609spell_find_dir (maptile *m, int x, int y, object *exclude) 599spell_find_dir (maptile *m, int x, int y, object *exclude)
610{ 600{
611 int i, max = SIZEOFFREE; 601 int i, max = SIZEOFFREE;
612 sint16 nx, ny; 602 sint16 nx, ny;
692 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 682 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
693 683
694 insert_ob_in_map (head, op->map, op, 0); 684 insert_ob_in_map (head, op->map, op, 0);
695 685
696 /* thought it'd be cool to insert a burnout, too. */ 686 /* 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); 687 op->map->insert (archetype::get (shstr_burnout), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
698 } 688 }
699} 689}
700 690
701/* peterm: function which summons hostile monsters and 691/* peterm: function which summons hostile monsters and
702 * places them in nearby squares. 692 * places them in nearby squares.
1004 { 994 {
1005 skill = find_skill_by_name (op, spell_ob->skill); 995 skill = find_skill_by_name (op, spell_ob->skill);
1006 996
1007 if (!skill) 997 if (!skill)
1008 { 998 {
1009 op->failmsg (format ("You need the skill %s to cast %s!", &spell_ob->skill, &spell_ob->name)); 999 op->failmsg (format ("You need the skill %s to cast %s! "
1000 "H<You either need to learn the skill via a skill scroll "
1001 "or you need to wear a talisman or holy symbol.>",
1002 &spell_ob->skill, &spell_ob->name));
1010 return 0; 1003 return 0;
1011 } 1004 }
1012 1005
1006 int casting_level = min_casting_level (op, spell_ob);
1007
1013 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 1008 if (casting_level > cast_level && !QUERY_FLAG (op, FLAG_WIZ))
1014 { 1009 {
1015 op->failmsg ("You lack enough skill to cast that spell!"); 1010 op->failmsg (format ("You lack enough skill to cast that spell! "
1011 "H<Your cast level is %d, but level %d is required. Maybe you are repelled?>",
1012 cast_level, casting_level));
1016 return 0; 1013 return 0;
1017 } 1014 }
1018 } 1015 }
1019 1016
1020 /* If the caster is the wiz, they don't ever fail, and don't have 1017 /* If the caster is the wiz, they don't ever fail, and don't have
1196 case SP_SMITE: 1193 case SP_SMITE:
1197 success = cast_smite_spell (op, caster, dir, spell_ob); 1194 success = cast_smite_spell (op, caster, dir, spell_ob);
1198 break; 1195 break;
1199 1196
1200 case SP_MAGIC_MISSILE: 1197 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); 1198 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1202 break; 1199 break;
1203 1200
1204 case SP_SUMMON_GOLEM: 1201 case SP_SUMMON_GOLEM:
1205 success = summon_golem (op, caster, dir, spell_ob); 1202 success = summon_golem (op, caster, dir, spell_ob);
1206 break; 1203 break;
1317 { 1314 {
1318 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name)); 1315 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name));
1319 success = 0; 1316 success = 0;
1320 } 1317 }
1321 else 1318 else
1322 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1319 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1323 break; 1320 break;
1324 1321
1325 case SP_SWARM: 1322 case SP_SWARM:
1326 success = fire_swarm (op, caster, spell_ob, dir); 1323 success = fire_swarm (op, caster, spell_ob, dir);
1327 break; 1324 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines