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.122 by root, Sat Dec 31 06:18:02 2011 UTC vs.
Revision 1.132 by root, Sun Nov 18 15:19:48 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * 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 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.h>
26#include <spells.h> 27#include <spells.h>
255 return spop; 256 return spop;
256 257
257 return 0; 258 return 0;
258} 259}
259 260
260/* 261/*
261 * Look at object 'op' and see if they know the spell 262 * Look at object 'op' and see if they know the spell
262 * spname. This is pretty close to check_spell_known 263 * spname. This is pretty close to check_spell_known
263 * above, but it uses a looser matching mechanism. 264 * above, but it uses a looser matching mechanism.
264 * returns the matching spell object, or NULL. 265 * returns the matching spell object, or NULL.
265 * If we match multiple spells but don't get an 266 * If we match multiple spells but don't get an
266 * exact match, we also return NULL. 267 * exact match, we also return NULL.
267 */ 268 */
268object * 269object *
269lookup_spell_by_name (object *op, const char *spname) 270object::find_spell (const_utf8_string prefix) const
270{ 271{
271 object *spob1 = 0, *spob2 = 0; 272 if (shstr_cmp name = prefix)
272 int nummatch = 0; 273 {
273 274 // case 1, match spell name exactly
274 if (!spname)
275 return 0;
276
277 /* Try to find the spell. We store the results in spob1
278 * and spob2 - spob1 is only taking the length of
279 * the past spname, spob2 uses the length of the spell name.
280 */
281 for (object *spob = op->inv; spob; spob = spob->below) 275 for (object *spob = inv; spob; spob = spob->below)
276 if (spob->name == name && spob->type == SPELL)
277 return spob;
282 { 278 }
279 else
280 {
281 // case 2, match prefix
282 int len = strlen (prefix);
283
284 for (object *spob = inv; spob; spob = spob->below)
283 if (spob->type == SPELL) 285 if (spob->type == SPELL
284 { 286 && spob->name.length () < len
285 // TODO: WTF? 287 && prefix [spob->name.length ()] <= ' '
286 if (!strncmp (spob->name, spname, strlen (spname))) 288 && !memcmp (prefix, spob->name, spob->name.length ()))
287 {
288 nummatch++;
289 spob1 = spob;
290 }
291 else if (!strncmp (spob->name, spname, strlen (spob->name)))
292 {
293 /* if spells have ambiguous names, it makes matching
294 * really difficult. (eg, fire and fireball would
295 * fall into this category). It shouldn't be hard to
296 * make sure spell names don't overlap in that fashion.
297 */
298 if (spob2)
299 LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name);
300
301 spob2 = spob;
302 }
303 }
304 }
305 /* if we have best match, return it. Otherwise, if we have one match
306 * on the loser match, return that, otehrwise null
307 */
308 if (spob2)
309 return spob2; 289 return spob;
290 }
310 291
311 if (spob1 && nummatch == 1)
312 return spob1;
313
314 return NULL; 292 return 0;
315} 293}
316 294
317/* reflwall - decides weither the (spell-)object sp_op will 295/* reflwall - decides weither the (spell-)object sp_op will
318 * be reflected from the given mapsquare. Returns 1 if true. 296 * be reflected from the given mapsquare. Returns 1 if true.
319 * (Note that for living creatures there is a small chance that 297 * (Note that for living creatures there is a small chance that
338 316
339/* cast_create_object: creates object new_op in direction dir 317/* cast_create_object: creates object new_op in direction dir
340 * or if that is blocked, beneath the player (op). 318 * or if that is blocked, beneath the player (op).
341 * we pass 'caster', but don't use it for anything. 319 * we pass 'caster', but don't use it for anything.
342 * This is really just a simple wrapper function . 320 * This is really just a simple wrapper function .
343 * returns the direction that the object was actually placed 321 * returns true to indicate whether the operation was successful.
344 * in. 322 * destroys the object is unsuccessful.
345 */ 323 */
346int 324bool
347cast_create_obj (object *op, object *caster, object *new_op, int dir) 325cast_create_obj (object *op, object *caster, object *new_op, int dir)
348{ 326{
349 maptile *m; 327 mapxy pos (op);
350 sint16 sx, sy; 328 pos.move (dir);
351 329
352 if (dir && 330 if (!pos.normalise ()
353 ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) || 331 || pos->blocks (op) // perversely enough, we check if the palyer can reach that space
354 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))) 332 || !new_op->can_drop_at (pos.m, pos.x, pos.y)
333 )
355 { 334 {
356 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 335 op->failmsg ("Your spell fizzles! H<Something is in the way.>");
357 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); 336 new_op->destroy ();
358 dir = 0; 337 return 0;
359 } 338 }
360 339
361 new_op->set_flag (FLAG_IDENTIFIED); 340 new_op->set_flag (FLAG_IDENTIFIED);
362 op->map->insert (new_op,
363 op->x + freearr_x[dir], op->y + freearr_y[dir],
364 op,
365 dir ? 0 : INS_BELOW_ORIGINATOR);
366 341
342 pos.insert (new_op, op, dir ? 0 : INS_BELOW_ORIGINATOR);
343
367 return dir; 344 return 1;
368} 345}
369 346
370static bool 347static bool
371mergable_owner (object *o1, object *o2) 348mergable_owner (object *o1, object *o2)
372{ 349{
386} 363}
387 364
388/* Returns true if it is ok to put spell *op on the space/may provided. 365/* Returns true if it is ok to put spell *op on the space/may provided.
389 * immune_stop is basically the attacktype of the spell (why 366 * immune_stop is basically the attacktype of the spell (why
390 * passed as a different value, not sure of). If immune_stop 367 * passed as a different value, not sure of). If immune_stop
391 * has the AT_MAGIC bit set, and there is a counterwall 368 * has the AT_MAGIC bit set, and there is a counterwall
392 * on the space, the object doesn't get placed. if immune stop 369 * on the space, the object doesn't get placed. if immune stop
393 * does not have AT_MAGIC, then counterwalls do not effect the spell. 370 * does not have AT_MAGIC, then counterwalls do not effect the spell.
394 */ 371 */
395int 372int
396ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) 373ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
515 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 492 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
516 if (!tailor_god_spell (tmp, op)) 493 if (!tailor_god_spell (tmp, op))
517 return 0; 494 return 0;
518 495
519 if (tmp->flag [FLAG_IS_TURNABLE]) 496 if (tmp->flag [FLAG_IS_TURNABLE])
520 SET_ANIMATION (tmp, dir); 497 tmp->set_anim_frame (dir);
521 498
522 if ((tmp = op->map->insert (tmp, x, y, op))) 499 if ((tmp = op->map->insert (tmp, x, y, op)))
523 move_spell_effect (tmp); 500 move_spell_effect (tmp);
524 501
525 return 1; 502 return 1;
568 tmp = op; 545 tmp = op;
569 } 546 }
570 else 547 else
571 { 548 {
572 maptile *m = op->map; 549 maptile *m = op->map;
573 sint16 x = op->x + freearr_x[dir]; 550 sint16 x = op->x + DIRX (dir);
574 sint16 y = op->y + freearr_y[dir]; 551 sint16 y = op->y + DIRY (dir);
575 552
576 tmp = xy_normalise (m, x, y) 553 tmp = xy_normalise (m, x, y)
577 ? m->at (x, y).player () 554 ? m->at (x, y).player ()
578 : 0; 555 : 0;
579 } 556 }
610 if (exclude && exclude->type) 587 if (exclude && exclude->type)
611 owner_type = exclude->type; 588 owner_type = exclude->type;
612 589
613 for (i = rndm (1, 8); i < max; i++) 590 for (i = rndm (1, 8); i < max; i++)
614 { 591 {
615 nx = x + freearr_x[i]; 592 nx = x + DIRX (i);
616 ny = y + freearr_y[i]; 593 ny = y + DIRY (i);
617 mp = m; 594 mp = m;
618 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 595 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
619 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) 596 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW))
620 continue; 597 continue;
621 598
647 624
648 if ((at = archetype::find (monstername)) == NULL) 625 if ((at = archetype::find (monstername)) == NULL)
649 return; 626 return;
650 627
651 /* find a free square nearby 628 /* find a free square nearby
652 * first we check the closest square for free squares 629 * first we check the closest square for free squares
653 */ 630 */
654 631
655 dir = find_first_free_spot (at, op->map, op->x, op->y); 632 dir = find_first_free_spot (at, op->map, op->x, op->y);
656 if (dir != -1) 633 if (dir != -1)
657 { 634 {
660 */ 637 */
661 //TODO: use expand_tail + ... 638 //TODO: use expand_tail + ...
662 while (at != NULL) 639 while (at != NULL)
663 { 640 {
664 tmp = at->instance (); 641 tmp = at->instance ();
665 tmp->x = op->x + freearr_x[dir] + at->x; 642 tmp->x = op->x + DIRX (dir) + at->x;
666 tmp->y = op->y + freearr_y[dir] + at->y; 643 tmp->y = op->y + DIRY (dir) + at->y;
667 tmp->map = op->map; 644 tmp->map = op->map;
668 if (head) 645 if (head)
669 { 646 {
670 tmp->head = head; 647 tmp->head = head;
671 prev->more = tmp; 648 prev->more = tmp;
683 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 660 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
684 661
685 insert_ob_in_map (head, op->map, op, 0); 662 insert_ob_in_map (head, op->map, op, 0);
686 663
687 /* thought it'd be cool to insert a burnout, too. */ 664 /* thought it'd be cool to insert a burnout, too. */
688 op->map->insert (archetype::get (shstr_burnout), op->x + freearr_x[dir], op->y + freearr_y[dir], op); 665 op->map->insert (archetype::get (shstr_burnout), op->x + DIRX (dir), op->y + DIRY (dir), op);
689 } 666 }
690} 667}
691 668
692/* peterm: function which summons hostile monsters and 669/* peterm: function which summons hostile monsters and
693 * places them in nearby squares. 670 * places them in nearby squares.
711 put_a_monster (op, monstername); 688 put_a_monster (op, monstername);
712 689
713 return n; 690 return n;
714} 691}
715 692
716
717/* Some local definitions for shuffle-attack */ 693/* Some local definitions for shuffle-attack */
718struct attacktype_shuffle 694struct attacktype_shuffle
719{ 695{
720 int attacktype; 696 int attacktype;
721 int face; 697 int face;
722} ATTACKS[22] = 698} ATTACKS[] =
723{ 699{
724 { AT_PHYSICAL, 0}, 700 { AT_PHYSICAL, 0},
725 { AT_PHYSICAL, 0}, /*face = explosion */ 701 { AT_PHYSICAL, 0}, /* face = explosion */
726 { AT_PHYSICAL, 0}, 702 { AT_PHYSICAL, 0},
727 { AT_MAGIC, 1}, 703 { AT_MAGIC, 1},
728 { AT_MAGIC, 1}, /* face = last-burnout */ 704 { AT_MAGIC, 1}, /* face = last-burnout */
729 { AT_MAGIC, 1}, 705 { AT_MAGIC, 1},
730 { AT_FIRE, 2}, 706 { AT_FIRE, 2},
744 { AT_PARALYZE, 9}, 720 { AT_PARALYZE, 9},
745 { AT_FEAR, 10}, 721 { AT_FEAR, 10},
746}; 722};
747 723
748/* shuffle_attack: peterm 724/* shuffle_attack: peterm
749 * This routine shuffles the attack of op to one of the 725 * This routine shuffles the attack of op to one of the
750 * ones in the list. It does this at random. It also 726 * ones in the list. It does this at random. It also
751 * chooses a face appropriate to the attack that is 727 * chooses a face appropriate to the attack that is
752 * being committed by that square at the moment. 728 * being committed by that square at the moment.
753 * right now it's being used by color spray and create pool of 729 * right now it's being used by color spray and create pool of
754 * chaos. 730 * chaos.
755 * This could really be a better implementation - the 731 * This could really be a better implementation - the
756 * faces and attacktypes above are hardcoded, which is never 732 * faces and attacktypes above are hardcoded, which is never
757 * good. The faces refer to faces in the animation sequence. 733 * good. The faces refer to faces in the animation sequence.
762 * attacktypes, which probably wasn't the intent. MSW 2003-06-03 738 * attacktypes, which probably wasn't the intent. MSW 2003-06-03
763 */ 739 */
764void 740void
765shuffle_attack (object *op, int change_face) 741shuffle_attack (object *op, int change_face)
766{ 742{
767 int i; 743 int i = rndm (ecb_array_length (ATTACKS));
768
769 i = rndm (0, 21);
770 744
771 op->attacktype = ATTACKS[i].attacktype | AT_MAGIC; 745 op->attacktype = ATTACKS[i].attacktype | AT_MAGIC;
772 746
773 if (change_face) 747 if (change_face)
774 { 748 op->set_anim_frame (ATTACKS[i].face);
775 SET_ANIMATION (op, ATTACKS[i].face);
776 }
777} 749}
778 750
779/* prayer_failure: This is called when a player fails 751/* prayer_failure: This is called when a player fails
780 * at casting a prayer. 752 * at casting a prayer.
781 * op is the player. 753 * op is the player.
820 op->failmsgf ("%s smites you!" HINT_GRACE, godname); 792 op->failmsgf ("%s smites you!" HINT_GRACE, godname);
821 cast_magic_storm (op, tmp, power); 793 cast_magic_storm (op, tmp, power);
822 } 794 }
823} 795}
824 796
825/* 797/*
826 * spell_failure() handles the various effects for differing degrees 798 * spell_failure() handles the various effects for differing degrees
827 * of failure badness. 799 * of failure badness.
828 * op is the player that failed. 800 * op is the player that failed.
829 * failure is a random value of how badly you failed. 801 * failure is a random value of how badly you failed.
830 * power is how many spellpoints you'd normally need for the spell. 802 * power is how many spellpoints you'd normally need for the spell.
831 * skill is the skill you'd need to cast the spell. 803 * skill is the skill you'd need to cast the spell.
832 */ 804 */
833
834void 805void
835spell_failure (object *op, int failure, int power, object *skill) 806spell_failure (object *op, int failure, int power, object *skill)
836{ 807{
837 object *tmp; 808 object *tmp;
838 809
970 { 941 {
971 LOG (llevError, "cast_spell: null caster object passed\n"); 942 LOG (llevError, "cast_spell: null caster object passed\n");
972 return 0; 943 return 0;
973 } 944 }
974 945
975 /* if caster is a spell casting object, this normally shouldn't be 946 /* if caster is a spell casting object, this normally shouldn't be
976 * an issue, because they don't have any spellpaths set up. 947 * an issue, because they don't have any spellpaths set up.
977 */ 948 */
978 if (caster->path_denied & spell_ob->path_attuned && !caster->flag [FLAG_WIZCAST]) 949 if (caster->path_denied & spell_ob->path_attuned && !caster->flag [FLAG_WIZCAST])
979 { 950 {
980 op->failmsg ("That spell path is denied to you."); 951 op->failmsg ("That spell path is denied to you.");
982 } 953 }
983 954
984 object *skill = 0; 955 object *skill = 0;
985 956
986 /* if it is a player casting the spell, and they are really casting it 957 /* if it is a player casting the spell, and they are really casting it
987 * (vs it coming from a wand, scroll, or whatever else), do some 958 * (vs it coming from a wand, scroll, or whatever else), do some
988 * checks. We let monsters do special things - eg, they 959 * checks. We let monsters do special things - eg, they
989 * don't need the SKILL, BYpass level checks, etc. The monster function 960 * don't need the SKILL, BYpass level checks, etc. The monster function
990 * should take care of that. 961 * should take care of that.
991 * Remove the wiz check here and move it further down - some spells 962 * Remove the wiz check here and move it further down - some spells
992 * need to have the right skill pointer passed, so we need to 963 * need to have the right skill pointer passed, so we need to
1024 } 995 }
1025 996
1026 if (spell_ob->level > caster_level) 997 if (spell_ob->level > caster_level)
1027 { 998 {
1028 op->failmsgf ("You lack enough skill to cast that spell! " 999 op->failmsgf ("You lack enough skill to cast that spell! "
1029 "H<Your effective cast level is %d%s, but level %d is required.>", 1000 "H<Your effective cast level is %d%s, but level %d is required.>",
1030 caster_level, msg, spell_ob->level); 1001 caster_level, msg, spell_ob->level);
1031 if (!op->is_wiz ()) 1002 if (!op->is_wiz ())
1032 return 0; 1003 return 0;
1033 } 1004 }
1034 } 1005 }
1130 1101
1131 // undo the flood protection from earlier 1102 // undo the flood protection from earlier
1132 op->speed_left += 4 * op->speed; // ~0.5s on failure 1103 op->speed_left += 4 * op->speed; // ~0.5s on failure
1133 1104
1134 /* Take into account how long it takes to cast the spell. 1105 /* Take into account how long it takes to cast the spell.
1135 * if the player is casting it, then we use the time in 1106 * if the player is casting it, then we use the time in
1136 * the spell object. If it is a spell object, have it 1107 * the spell object. If it is a spell object, have it
1137 * take two ticks. Things that cast spells on the players 1108 * take two ticks. Things that cast spells on the players
1138 * behalf (eg, altars, and whatever else) shouldn't cost 1109 * behalf (eg, altars, and whatever else) shouldn't cost
1139 * the player any time. 1110 * the player any time.
1140 * Ignore casting time for firewalls 1111 * Ignore casting time for firewalls

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines