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 | */ |
|
|
88 | void |
|
|
89 | init_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 | */ |
|
|
135 | void |
|
|
136 | dump_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 | */ |
147 | void |
85 | void |
148 | spell_effect (object *spob, int x, int y, maptile *map, object *originator) |
86 | spell_effect (object *spob, int x, int y, maptile *map, object *originator) |
… | |
… | |
183 | int |
121 | int |
184 | caster_level (object *caster, object *spell) |
122 | caster_level (object *caster, object *spell) |
185 | { |
123 | { |
186 | int level = caster->level; |
124 | int level = caster->level; |
187 | |
125 | |
188 | /* If this is a player, try to find the matching skill */ |
126 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
189 | if (caster->type == PLAYER && spell->skill) |
127 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
|
|
128 | { |
|
|
129 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
|
|
130 | int sk_level = skill ? skill->level : 1; |
|
|
131 | |
|
|
132 | level = min (level, sk_level + level / 10 + 1); |
|
|
133 | } |
|
|
134 | else if (caster->type == PLAYER && spell->skill) /* If this is a player, try to find the matching skill */ |
190 | for (int i = 0; i < NUM_SKILLS; i++) |
135 | for (int i = 0; i < NUM_SKILLS; i++) |
191 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
136 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
192 | { |
137 | { |
193 | level = caster->contr->last_skill_ob[i]->level; |
138 | level = caster->contr->last_skill_ob[i]->level; |
194 | break; |
139 | break; |
195 | } |
140 | } |
196 | |
|
|
197 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
|
|
198 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
|
|
199 | { |
|
|
200 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
|
|
201 | int sk_level = skill ? skill->level : 1; |
|
|
202 | |
|
|
203 | level = MIN (level, sk_level + level / 10 + 1); |
|
|
204 | } |
|
|
205 | |
141 | |
206 | /* Got valid caster level. Now adjust for attunement */ |
142 | /* Got valid caster level. Now adjust for attunement */ |
207 | level += caster->path_repelled & spell->path_attuned ? -8 : 0; |
143 | level += caster->path_repelled & spell->path_attuned ? -8 : 0; |
208 | level += caster->path_attuned & spell->path_attuned ? +8 : 0; |
144 | level += caster->path_attuned & spell->path_attuned ? +8 : 0; |
209 | |
145 | |
… | |
… | |
257 | else |
193 | else |
258 | { |
194 | { |
259 | sp = (int) (spell->stats.sp * PATH_SP_MULT (caster, spell)); |
195 | sp = (int) (spell->stats.sp * PATH_SP_MULT (caster, spell)); |
260 | if (spell->stats.sp && !sp) |
196 | if (spell->stats.sp && !sp) |
261 | sp = 1; |
197 | sp = 1; |
|
|
198 | |
262 | grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell)); |
199 | grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell)); |
263 | if (spell->stats.grace && !grace) |
200 | if (spell->stats.grace && !grace) |
264 | grace = 1; |
201 | grace = 1; |
265 | } |
202 | } |
266 | |
203 | |
… | |
… | |
324 | */ |
261 | */ |
325 | object * |
262 | object * |
326 | check_spell_known (object *op, const char *name) |
263 | check_spell_known (object *op, const char *name) |
327 | { |
264 | { |
328 | object *spop; |
265 | object *spop; |
|
|
266 | shstr_cmp name_ (name); |
329 | |
267 | |
330 | for (spop = op->inv; spop; spop = spop->below) |
268 | for (spop = op->inv; spop; spop = spop->below) |
331 | if (spop->type == SPELL && !strcmp (spop->name, name)) |
269 | if (spop->type == SPELL && spop->name == name) |
332 | return spop; |
270 | return spop; |
333 | |
271 | |
334 | return NULL; |
272 | return 0; |
335 | } |
273 | } |
336 | |
274 | |
337 | |
275 | |
338 | /* |
276 | /* |
339 | * Look at object 'op' and see if they know the spell |
277 | * Look at object 'op' and see if they know the spell |
… | |
… | |
501 | /* |
439 | /* |
502 | * Combine similar spell effects into one spell effect. Needed for |
440 | * Combine similar spell effects into one spell effect. Needed for |
503 | * performance reasons with meteor swarm and the like, but also for |
441 | * performance reasons with meteor swarm and the like, but also for |
504 | * playability reasons. |
442 | * playability reasons. |
505 | */ |
443 | */ |
506 | if (tmp->arch == op->arch |
444 | if (tmp->arch == op->arch /* no harm if not comparing by name here */ |
507 | && tmp->type == op->type |
445 | && tmp->type == op->type |
508 | && tmp->subtype == op->subtype |
446 | && tmp->subtype == op->subtype |
509 | && tmp->owner == op->owner |
447 | && tmp->owner == op->owner |
510 | && ((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))) |
511 | { |
449 | { |
… | |
… | |
535 | * returns 0 on failure, 1 on success. |
473 | * returns 0 on failure, 1 on success. |
536 | */ |
474 | */ |
537 | int |
475 | int |
538 | fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) |
476 | fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) |
539 | { |
477 | { |
540 | object *tmp; |
|
|
541 | int mflags; |
|
|
542 | maptile *m; |
|
|
543 | |
|
|
544 | if (spell->other_arch == NULL) |
478 | if (!spell->other_arch) |
545 | return 0; |
479 | return 0; |
546 | |
480 | |
547 | m = op->map; |
481 | mapxy pos (op->map, x, y);//TODO, should not pass x, y |
548 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
|
|
549 | if (mflags & P_OUT_OF_MAP) |
|
|
550 | { |
|
|
551 | return 0; |
|
|
552 | } |
|
|
553 | |
482 | |
554 | tmp = arch_to_object (spell->other_arch); |
483 | pos.move (dir ? dir : rndm (1, 8)); |
555 | |
484 | |
556 | if (tmp == NULL) |
485 | if (!pos.normalise ()) |
557 | return 0; |
486 | return 0; |
558 | |
487 | |
559 | 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)) |
560 | { |
494 | { |
561 | 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"); |
562 | tmp->destroy (); |
496 | tmp->destroy (); |
563 | return 0; |
497 | return 0; |
564 | } |
498 | } |
565 | |
499 | |
566 | 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); |
… | |
… | |
570 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
504 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
571 | tmp->attacktype = spell->attacktype; |
505 | tmp->attacktype = spell->attacktype; |
572 | tmp->x = x; |
506 | tmp->x = x; |
573 | tmp->y = y; |
507 | tmp->y = y; |
574 | tmp->direction = dir; |
508 | tmp->direction = dir; |
575 | if (op->owner != NULL) |
|
|
576 | tmp->set_owner (op); |
509 | tmp->set_owner (op); |
577 | else |
|
|
578 | tmp->set_owner (op); |
|
|
579 | tmp->level = caster_level (caster, spell); |
510 | tmp->level = caster_level (caster, spell); |
580 | set_spell_skill (op, caster, spell, tmp); |
511 | set_spell_skill (op, caster, spell, tmp); |
581 | |
512 | |
582 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
513 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
583 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
514 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
584 | { |
|
|
585 | if (!tailor_god_spell (tmp, op)) |
515 | if (!tailor_god_spell (tmp, op)) |
586 | return 0; |
516 | return 0; |
587 | } |
517 | |
588 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
518 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
589 | SET_ANIMATION (tmp, dir); |
519 | SET_ANIMATION (tmp, dir); |
590 | |
520 | |
591 | if ((tmp = insert_ob_in_map (tmp, m, op, 0))) |
521 | if ((tmp = op->map->insert (tmp, x, y, op))) |
592 | move_spell_effect (tmp); |
522 | move_spell_effect (tmp); |
593 | |
523 | |
594 | return 1; |
524 | return 1; |
595 | } |
525 | } |
596 | |
526 | |
… | |
… | |
651 | if (!tmp) |
581 | if (!tmp) |
652 | tmp = op->ms ().player (); |
582 | tmp = op->ms ().player (); |
653 | |
583 | |
654 | return tmp; |
584 | return tmp; |
655 | } |
585 | } |
656 | |
|
|
657 | |
|
|
658 | |
586 | |
659 | /* raytrace: |
587 | /* raytrace: |
660 | * 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 |
661 | * 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 |
662 | * live objects. |
590 | * live objects. |
… | |
… | |
665 | * monsters/generators only. If not, the spell will hunt players only. |
593 | * monsters/generators only. If not, the spell will hunt players only. |
666 | * 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 |
667 | * any, otherwise -1. |
595 | * any, otherwise -1. |
668 | * 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. |
669 | */ |
597 | */ |
670 | |
|
|
671 | int |
598 | int |
672 | spell_find_dir (maptile *m, int x, int y, object *exclude) |
599 | spell_find_dir (maptile *m, int x, int y, object *exclude) |
673 | { |
600 | { |
674 | int i, max = SIZEOFFREE; |
601 | int i, max = SIZEOFFREE; |
675 | sint16 nx, ny; |
602 | sint16 nx, ny; |
… | |
… | |
755 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
682 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
756 | |
683 | |
757 | insert_ob_in_map (head, op->map, op, 0); |
684 | insert_ob_in_map (head, op->map, op, 0); |
758 | |
685 | |
759 | /* thought it'd be cool to insert a burnout, too. */ |
686 | /* thought it'd be cool to insert a burnout, too. */ |
760 | 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); |
761 | } |
688 | } |
762 | } |
689 | } |
763 | |
690 | |
764 | /* peterm: function which summons hostile monsters and |
691 | /* peterm: function which summons hostile monsters and |
765 | * places them in nearby squares. |
692 | * places them in nearby squares. |
… | |
… | |
1067 | { |
994 | { |
1068 | skill = find_skill_by_name (op, spell_ob->skill); |
995 | skill = find_skill_by_name (op, spell_ob->skill); |
1069 | |
996 | |
1070 | if (!skill) |
997 | if (!skill) |
1071 | { |
998 | { |
1072 | 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)); |
1073 | return 0; |
1003 | return 0; |
1074 | } |
1004 | } |
1075 | |
1005 | |
|
|
1006 | int casting_level = min_casting_level (op, spell_ob); |
|
|
1007 | |
1076 | 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)) |
1077 | { |
1009 | { |
1078 | 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)); |
1079 | return 0; |
1013 | return 0; |
1080 | } |
1014 | } |
1081 | } |
1015 | } |
1082 | |
1016 | |
1083 | /* 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 |
… | |
… | |
1259 | case SP_SMITE: |
1193 | case SP_SMITE: |
1260 | success = cast_smite_spell (op, caster, dir, spell_ob); |
1194 | success = cast_smite_spell (op, caster, dir, spell_ob); |
1261 | break; |
1195 | break; |
1262 | |
1196 | |
1263 | case SP_MAGIC_MISSILE: |
1197 | case SP_MAGIC_MISSILE: |
1264 | 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); |
1265 | break; |
1199 | break; |
1266 | |
1200 | |
1267 | case SP_SUMMON_GOLEM: |
1201 | case SP_SUMMON_GOLEM: |
1268 | success = summon_golem (op, caster, dir, spell_ob); |
1202 | success = summon_golem (op, caster, dir, spell_ob); |
1269 | break; |
1203 | break; |
… | |
… | |
1380 | { |
1314 | { |
1381 | 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)); |
1382 | success = 0; |
1316 | success = 0; |
1383 | } |
1317 | } |
1384 | else |
1318 | else |
1385 | 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); |
1386 | break; |
1320 | break; |
1387 | |
1321 | |
1388 | case SP_SWARM: |
1322 | case SP_SWARM: |
1389 | success = fire_swarm (op, caster, spell_ob, dir); |
1323 | success = fire_swarm (op, caster, spell_ob, dir); |
1390 | break; |
1324 | break; |