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.66 by root, Sat Mar 15 13:52:38 2008 UTC vs.
Revision 1.76 by root, Wed Jul 16 14:29:40 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
77 dest->skill = spob->skill; 77 dest->skill = spob->skill;
78 else 78 else
79 dest->skill = caster->skill; 79 dest->skill = caster->skill;
80} 80}
81 81
82/* init_spells: This should really be called check_spells, as that
83 * is what it does. It goes through the spells looking for any
84 * obvious errors. This was most useful in debugging when re-doing
85 * all the spells to catch simple errors. To use it all the time
86 * will result in it spitting out messages that aren't really errors.
87 */
88void
89init_spells (void)
90{
91#ifdef SPELL_DEBUG
92 static int init_spells_done = 0;
93 int i;
94 archetype *at;
95
96 if (init_spells_done)
97 return;
98 LOG (llevDebug, "Checking spells...\n");
99
100 for_all_archetypes (at)
101 {
102 if (at->type == SPELL)
103 {
104 if (at->skill)
105 {
106 for (i = 1; i < NUM_SKILLS; i++)
107 if (!strcmp (skill_names[i], at->skill))
108 break;
109 if (i == NUM_SKILLS)
110 {
111 LOG (llevError, "Spell %s has improper associated skill %s\n", at->name, at->skill);
112 }
113 }
114 /* other_arch is already checked for in the loader */
115 }
116 }
117
118 i = 0;
119 while (spell_mapping[i])
120 {
121 if (!archetype::find (spell_mapping[i]))
122 {
123 LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i);
124 }
125 i++;
126 }
127 LOG (llevDebug, "Checking spells completed.\n");
128#endif
129}
130
131/* Dumps all the spells - now also dumps skill associated with the spell.
132 * not sure what this would be used for, as the data seems pretty
133 * minimal, but easy enough to keep around.
134 */
135void
136dump_spells ()
137{
138 for_all_archetypes (at)
139 if (at->type == SPELL)
140 fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->object::name,
141 &at->archname, at->other_arch ? &at->other_arch->archname : "<nil>", &at->skill, at->level);
142}
143
144/* pretty basic function - basically just takes 82/* pretty basic function - basically just takes
145 * an object, sets the x,y, and calls insert_ob_in_map 83 * an object, sets the x,y, and calls insert_ob_in_map
146 */ 84 */
147void 85void
148spell_effect (object *spob, int x, int y, maptile *map, object *originator) 86spell_effect (object *spob, int x, int y, maptile *map, object *originator)
323 */ 261 */
324object * 262object *
325check_spell_known (object *op, const char *name) 263check_spell_known (object *op, const char *name)
326{ 264{
327 object *spop; 265 object *spop;
266 shstr_cmp name_ (name);
328 267
329 for (spop = op->inv; spop; spop = spop->below) 268 for (spop = op->inv; spop; spop = spop->below)
330 if (spop->type == SPELL && !strcmp (spop->name, name)) 269 if (spop->type == SPELL && spop->name == name)
331 return spop; 270 return spop;
332 271
333 return NULL; 272 return 0;
334} 273}
335 274
336 275
337/* 276/*
338 * Look at object 'op' and see if they know the spell 277 * Look at object 'op' and see if they know the spell
455{ 394{
456 if (!xy_normalise (m, x, y)) 395 if (!xy_normalise (m, x, y))
457 return 0; 396 return 0;
458 397
459 mapspace &ms = m->at (x, y); 398 mapspace &ms = m->at (x, y);
399 ms.update ();
460 400
461 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) 401 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
462 return 0; 402 return 0;
463 403
464 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 404 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
500 /* 440 /*
501 * Combine similar spell effects into one spell effect. Needed for 441 * Combine similar spell effects into one spell effect. Needed for
502 * performance reasons with meteor swarm and the like, but also for 442 * performance reasons with meteor swarm and the like, but also for
503 * playability reasons. 443 * playability reasons.
504 */ 444 */
505 if (tmp->arch == op->arch 445 if (tmp->arch == op->arch /* no harm if not comparing by name here */
506 && tmp->type == op->type 446 && tmp->type == op->type
507 && tmp->subtype == op->subtype 447 && tmp->subtype == op->subtype
508 && tmp->owner == op->owner 448 && tmp->owner == op->owner
509 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) 449 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
510 { 450 {
534 * returns 0 on failure, 1 on success. 474 * returns 0 on failure, 1 on success.
535 */ 475 */
536int 476int
537fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 477fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
538{ 478{
539 object *tmp;
540 int mflags;
541 maptile *m;
542
543 if (spell->other_arch == NULL) 479 if (!spell->other_arch)
544 return 0; 480 return 0;
545 481
546 m = op->map; 482 object *tmp = spell->other_arch->instance ();
547 mflags = get_map_flags (m, &m, x, y, &x, &y);
548 if (mflags & P_OUT_OF_MAP)
549 {
550 return 0;
551 }
552 483
553 tmp = arch_to_object (spell->other_arch); 484 if (!tmp)
554
555 if (tmp == NULL)
556 return 0; 485 return 0;
557
558 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y)))
559 {
560 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n");
561 tmp->destroy ();
562 return 0;
563 }
564 486
565 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 487 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
566 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); 488 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
567 /* code in time.c uses food for some things, duration for others */ 489 /* code in time.c uses food for some things, duration for others */
568 tmp->stats.food = tmp->duration; 490 tmp->stats.food = tmp->duration;
569 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 491 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
570 tmp->attacktype = spell->attacktype; 492 tmp->attacktype = spell->attacktype;
571 tmp->x = x;
572 tmp->y = y;
573 tmp->direction = dir; 493 tmp->direction = dir;
574 if (op->owner != NULL)
575 tmp->set_owner (op); 494 tmp->set_owner (op);
576 else
577 tmp->set_owner (op);
578 tmp->level = caster_level (caster, spell); 495 tmp->level = caster_level (caster, spell);
579 set_spell_skill (op, caster, spell, tmp); 496 set_spell_skill (op, caster, spell, tmp);
580 497
581 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 498 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
582 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 499 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
583 {
584 if (!tailor_god_spell (tmp, op)) 500 if (!tailor_god_spell (tmp, op))
585 return 0; 501 return 0;
586 } 502
587 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 503 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
588 SET_ANIMATION (tmp, dir); 504 SET_ANIMATION (tmp, dir);
589 505
590 if ((tmp = insert_ob_in_map (tmp, m, op, 0))) 506 if ((tmp = op->map->insert (tmp, x, y, op)))
591 move_spell_effect (tmp); 507 move_spell_effect (tmp);
592 508
593 return 1; 509 return 1;
594} 510}
595 511
650 if (!tmp) 566 if (!tmp)
651 tmp = op->ms ().player (); 567 tmp = op->ms ().player ();
652 568
653 return tmp; 569 return tmp;
654} 570}
655
656
657 571
658/* raytrace: 572/* raytrace:
659 * spell_find_dir(map, x, y, exclude) will search first the center square 573 * spell_find_dir(map, x, y, exclude) will search first the center square
660 * then some close squares in the given map at the given coordinates for 574 * then some close squares in the given map at the given coordinates for
661 * live objects. 575 * live objects.
664 * monsters/generators only. If not, the spell will hunt players only. 578 * monsters/generators only. If not, the spell will hunt players only.
665 * It returns the direction toward the first/closest live object if it finds 579 * It returns the direction toward the first/closest live object if it finds
666 * any, otherwise -1. 580 * any, otherwise -1.
667 * note that exclude can be NULL, in which case all bets are off. 581 * note that exclude can be NULL, in which case all bets are off.
668 */ 582 */
669
670int 583int
671spell_find_dir (maptile *m, int x, int y, object *exclude) 584spell_find_dir (maptile *m, int x, int y, object *exclude)
672{ 585{
673 int i, max = SIZEOFFREE; 586 int i, max = SIZEOFFREE;
674 sint16 nx, ny; 587 sint16 nx, ny;
754 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 667 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
755 668
756 insert_ob_in_map (head, op->map, op, 0); 669 insert_ob_in_map (head, op->map, op, 0);
757 670
758 /* thought it'd be cool to insert a burnout, too. */ 671 /* thought it'd be cool to insert a burnout, too. */
759 op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op); 672 op->map->insert (archetype::get (shstr_burnout), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
760 } 673 }
761} 674}
762 675
763/* peterm: function which summons hostile monsters and 676/* peterm: function which summons hostile monsters and
764 * places them in nearby squares. 677 * places them in nearby squares.
1066 { 979 {
1067 skill = find_skill_by_name (op, spell_ob->skill); 980 skill = find_skill_by_name (op, spell_ob->skill);
1068 981
1069 if (!skill) 982 if (!skill)
1070 { 983 {
1071 op->failmsg (format ("You need the skill %s to cast %s!", &spell_ob->skill, &spell_ob->name)); 984 op->failmsg (format ("You need the skill %s to cast %s! "
985 "H<You either need to learn the skill via a skill scroll "
986 "or you need to wear a talisman or holy symbol.>",
987 &spell_ob->skill, &spell_ob->name));
1072 return 0; 988 return 0;
1073 } 989 }
1074 990
991 int casting_level = min_casting_level (op, spell_ob);
992
1075 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 993 if (casting_level > cast_level && !QUERY_FLAG (op, FLAG_WIZ))
1076 { 994 {
1077 op->failmsg ("You lack enough skill to cast that spell!"); 995 op->failmsg (format ("You lack enough skill to cast that spell! "
996 "H<Your cast level is %d, but level %d is required. Maybe you are repelled?>",
997 cast_level, casting_level));
1078 return 0; 998 return 0;
1079 } 999 }
1080 } 1000 }
1081 1001
1082 /* If the caster is the wiz, they don't ever fail, and don't have 1002 /* If the caster is the wiz, they don't ever fail, and don't have
1258 case SP_SMITE: 1178 case SP_SMITE:
1259 success = cast_smite_spell (op, caster, dir, spell_ob); 1179 success = cast_smite_spell (op, caster, dir, spell_ob);
1260 break; 1180 break;
1261 1181
1262 case SP_MAGIC_MISSILE: 1182 case SP_MAGIC_MISSILE:
1263 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1183 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1264 break; 1184 break;
1265 1185
1266 case SP_SUMMON_GOLEM: 1186 case SP_SUMMON_GOLEM:
1267 success = summon_golem (op, caster, dir, spell_ob); 1187 success = summon_golem (op, caster, dir, spell_ob);
1268 break; 1188 break;
1379 { 1299 {
1380 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name)); 1300 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name));
1381 success = 0; 1301 success = 0;
1382 } 1302 }
1383 else 1303 else
1384 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1304 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1385 break; 1305 break;
1386 1306
1387 case SP_SWARM: 1307 case SP_SWARM:
1388 success = fire_swarm (op, caster, spell_ob, dir); 1308 success = fire_swarm (op, caster, spell_ob, dir);
1389 break; 1309 break;
1515 check_bullet (op); 1435 check_bullet (op);
1516 return; 1436 return;
1517 } 1437 }
1518} 1438}
1519 1439
1520/* This is called by move_apply. Basically, if someone 1440/* This is called by move_apply. Basically, if someone
1521 * moves onto a spell effect and the walk_on or fly_on flags 1441 * moves onto a spell effect and the walk_on or fly_on flags
1522 * are set, this is called. This should only be called for 1442 * are set, this is called. This should only be called for
1523 * objects of the appropraite type. 1443 * objects of the appropriate type.
1524 */ 1444 */
1525void 1445void
1526apply_spell_effect (object *spell, object *victim) 1446apply_spell_effect (object *spell, object *victim)
1527{ 1447{
1528 switch (spell->subtype) 1448 switch (spell->subtype)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines