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,2012 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 |
… | |
… | |
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 | */ |
268 | object * |
269 | object * |
269 | lookup_spell_by_name (object *op, const char *spname) |
270 | object::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 |
… | |
… | |
385 | } |
363 | } |
386 | |
364 | |
387 | /* 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. |
388 | * immune_stop is basically the attacktype of the spell (why |
366 | * immune_stop is basically the attacktype of the spell (why |
389 | * passed as a different value, not sure of). If immune_stop |
367 | * passed as a different value, not sure of). If immune_stop |
390 | * has the AT_MAGIC bit set, and there is a counterwall |
368 | * has the AT_MAGIC bit set, and there is a counterwall |
391 | * 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 |
392 | * 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. |
393 | */ |
371 | */ |
394 | int |
372 | int |
395 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
373 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
… | |
… | |
567 | tmp = op; |
545 | tmp = op; |
568 | } |
546 | } |
569 | else |
547 | else |
570 | { |
548 | { |
571 | maptile *m = op->map; |
549 | maptile *m = op->map; |
572 | sint16 x = op->x + freearr_x[dir]; |
550 | sint16 x = op->x + DIRX (dir); |
573 | sint16 y = op->y + freearr_y[dir]; |
551 | sint16 y = op->y + DIRY (dir); |
574 | |
552 | |
575 | tmp = xy_normalise (m, x, y) |
553 | tmp = xy_normalise (m, x, y) |
576 | ? m->at (x, y).player () |
554 | ? m->at (x, y).player () |
577 | : 0; |
555 | : 0; |
578 | } |
556 | } |
… | |
… | |
609 | if (exclude && exclude->type) |
587 | if (exclude && exclude->type) |
610 | owner_type = exclude->type; |
588 | owner_type = exclude->type; |
611 | |
589 | |
612 | for (i = rndm (1, 8); i < max; i++) |
590 | for (i = rndm (1, 8); i < max; i++) |
613 | { |
591 | { |
614 | nx = x + freearr_x[i]; |
592 | nx = x + DIRX (i); |
615 | ny = y + freearr_y[i]; |
593 | ny = y + DIRY (i); |
616 | mp = m; |
594 | mp = m; |
617 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
595 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
618 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
596 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
619 | continue; |
597 | continue; |
620 | |
598 | |
… | |
… | |
646 | |
624 | |
647 | if ((at = archetype::find (monstername)) == NULL) |
625 | if ((at = archetype::find (monstername)) == NULL) |
648 | return; |
626 | return; |
649 | |
627 | |
650 | /* find a free square nearby |
628 | /* find a free square nearby |
651 | * first we check the closest square for free squares |
629 | * first we check the closest square for free squares |
652 | */ |
630 | */ |
653 | |
631 | |
654 | 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); |
655 | if (dir != -1) |
633 | if (dir != -1) |
656 | { |
634 | { |
… | |
… | |
659 | */ |
637 | */ |
660 | //TODO: use expand_tail + ... |
638 | //TODO: use expand_tail + ... |
661 | while (at != NULL) |
639 | while (at != NULL) |
662 | { |
640 | { |
663 | tmp = at->instance (); |
641 | tmp = at->instance (); |
664 | tmp->x = op->x + freearr_x[dir] + at->x; |
642 | tmp->x = op->x + DIRX (dir) + at->x; |
665 | tmp->y = op->y + freearr_y[dir] + at->y; |
643 | tmp->y = op->y + DIRY (dir) + at->y; |
666 | tmp->map = op->map; |
644 | tmp->map = op->map; |
667 | if (head) |
645 | if (head) |
668 | { |
646 | { |
669 | tmp->head = head; |
647 | tmp->head = head; |
670 | prev->more = tmp; |
648 | prev->more = tmp; |
… | |
… | |
682 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
660 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
683 | |
661 | |
684 | insert_ob_in_map (head, op->map, op, 0); |
662 | insert_ob_in_map (head, op->map, op, 0); |
685 | |
663 | |
686 | /* thought it'd be cool to insert a burnout, too. */ |
664 | /* thought it'd be cool to insert a burnout, too. */ |
687 | 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); |
688 | } |
666 | } |
689 | } |
667 | } |
690 | |
668 | |
691 | /* peterm: function which summons hostile monsters and |
669 | /* peterm: function which summons hostile monsters and |
692 | * places them in nearby squares. |
670 | * places them in nearby squares. |
… | |
… | |
743 | { AT_PARALYZE, 9}, |
721 | { AT_PARALYZE, 9}, |
744 | { AT_FEAR, 10}, |
722 | { AT_FEAR, 10}, |
745 | }; |
723 | }; |
746 | |
724 | |
747 | /* shuffle_attack: peterm |
725 | /* shuffle_attack: peterm |
748 | * This routine shuffles the attack of op to one of the |
726 | * This routine shuffles the attack of op to one of the |
749 | * ones in the list. It does this at random. It also |
727 | * ones in the list. It does this at random. It also |
750 | * chooses a face appropriate to the attack that is |
728 | * chooses a face appropriate to the attack that is |
751 | * being committed by that square at the moment. |
729 | * being committed by that square at the moment. |
752 | * right now it's being used by color spray and create pool of |
730 | * right now it's being used by color spray and create pool of |
753 | * chaos. |
731 | * chaos. |
754 | * This could really be a better implementation - the |
732 | * This could really be a better implementation - the |
755 | * faces and attacktypes above are hardcoded, which is never |
733 | * faces and attacktypes above are hardcoded, which is never |
756 | * good. The faces refer to faces in the animation sequence. |
734 | * good. The faces refer to faces in the animation sequence. |
… | |
… | |
968 | { |
946 | { |
969 | LOG (llevError, "cast_spell: null caster object passed\n"); |
947 | LOG (llevError, "cast_spell: null caster object passed\n"); |
970 | return 0; |
948 | return 0; |
971 | } |
949 | } |
972 | |
950 | |
973 | /* if caster is a spell casting object, this normally shouldn't be |
951 | /* if caster is a spell casting object, this normally shouldn't be |
974 | * an issue, because they don't have any spellpaths set up. |
952 | * an issue, because they don't have any spellpaths set up. |
975 | */ |
953 | */ |
976 | if (caster->path_denied & spell_ob->path_attuned && !caster->flag [FLAG_WIZCAST]) |
954 | if (caster->path_denied & spell_ob->path_attuned && !caster->flag [FLAG_WIZCAST]) |
977 | { |
955 | { |
978 | op->failmsg ("That spell path is denied to you."); |
956 | op->failmsg ("That spell path is denied to you."); |
… | |
… | |
980 | } |
958 | } |
981 | |
959 | |
982 | object *skill = 0; |
960 | object *skill = 0; |
983 | |
961 | |
984 | /* if it is a player casting the spell, and they are really casting it |
962 | /* if it is a player casting the spell, and they are really casting it |
985 | * (vs it coming from a wand, scroll, or whatever else), do some |
963 | * (vs it coming from a wand, scroll, or whatever else), do some |
986 | * checks. We let monsters do special things - eg, they |
964 | * checks. We let monsters do special things - eg, they |
987 | * don't need the SKILL, BYpass level checks, etc. The monster function |
965 | * don't need the SKILL, BYpass level checks, etc. The monster function |
988 | * should take care of that. |
966 | * should take care of that. |
989 | * Remove the wiz check here and move it further down - some spells |
967 | * Remove the wiz check here and move it further down - some spells |
990 | * need to have the right skill pointer passed, so we need to |
968 | * need to have the right skill pointer passed, so we need to |
… | |
… | |
1022 | } |
1000 | } |
1023 | |
1001 | |
1024 | if (spell_ob->level > caster_level) |
1002 | if (spell_ob->level > caster_level) |
1025 | { |
1003 | { |
1026 | op->failmsgf ("You lack enough skill to cast that spell! " |
1004 | op->failmsgf ("You lack enough skill to cast that spell! " |
1027 | "H<Your effective cast level is %d%s, but level %d is required.>", |
1005 | "H<Your effective cast level is %d%s, but level %d is required.>", |
1028 | caster_level, msg, spell_ob->level); |
1006 | caster_level, msg, spell_ob->level); |
1029 | if (!op->is_wiz ()) |
1007 | if (!op->is_wiz ()) |
1030 | return 0; |
1008 | return 0; |
1031 | } |
1009 | } |
1032 | } |
1010 | } |
… | |
… | |
1128 | |
1106 | |
1129 | // undo the flood protection from earlier |
1107 | // undo the flood protection from earlier |
1130 | op->speed_left += 4 * op->speed; // ~0.5s on failure |
1108 | op->speed_left += 4 * op->speed; // ~0.5s on failure |
1131 | |
1109 | |
1132 | /* Take into account how long it takes to cast the spell. |
1110 | /* Take into account how long it takes to cast the spell. |
1133 | * if the player is casting it, then we use the time in |
1111 | * if the player is casting it, then we use the time in |
1134 | * the spell object. If it is a spell object, have it |
1112 | * the spell object. If it is a spell object, have it |
1135 | * take two ticks. Things that cast spells on the players |
1113 | * take two ticks. Things that cast spells on the players |
1136 | * behalf (eg, altars, and whatever else) shouldn't cost |
1114 | * behalf (eg, altars, and whatever else) shouldn't cost |
1137 | * the player any time. |
1115 | * the player any time. |
1138 | * Ignore casting time for firewalls |
1116 | * Ignore casting time for firewalls |