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,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * 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 |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * 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 |
9 | * 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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * 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 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <spells.h> |
26 | #include <spells.h> |
… | |
… | |
158 | sp *= (int) PATH_SP_MULT (caster, spell); |
158 | sp *= (int) PATH_SP_MULT (caster, spell); |
159 | if (!sp && spell->stats.sp) |
159 | if (!sp && spell->stats.sp) |
160 | sp = 1; |
160 | sp = 1; |
161 | |
161 | |
162 | if (spell->stats.grace && spell->stats.maxgrace) |
162 | if (spell->stats.grace && spell->stats.maxgrace) |
163 | grace = spell->stats.grace * (1.0 + max (0, float (level - spell->level) / spell->stats.maxgrace)); |
163 | grace = spell->stats.grace * (1.f + max (0.f, float (level - spell->level) / spell->stats.maxgrace)); |
164 | else |
164 | else |
165 | grace = spell->stats.grace; |
165 | grace = spell->stats.grace; |
166 | |
166 | |
167 | grace *= PATH_SP_MULT (caster, spell); |
167 | grace *= PATH_SP_MULT (caster, spell); |
168 | if (spell->stats.grace && !grace) |
168 | if (spell->stats.grace && !grace) |
… | |
… | |
255 | return spop; |
255 | return spop; |
256 | |
256 | |
257 | return 0; |
257 | return 0; |
258 | } |
258 | } |
259 | |
259 | |
260 | /* |
260 | /* |
261 | * Look at object 'op' and see if they know the spell |
261 | * Look at object 'op' and see if they know the spell |
262 | * spname. This is pretty close to check_spell_known |
262 | * spname. This is pretty close to check_spell_known |
263 | * above, but it uses a looser matching mechanism. |
263 | * above, but it uses a looser matching mechanism. |
264 | * returns the matching spell object, or NULL. |
264 | * returns the matching spell object, or NULL. |
265 | * If we match multiple spells but don't get an |
265 | * If we match multiple spells but don't get an |
266 | * exact match, we also return NULL. |
266 | * exact match, we also return NULL. |
267 | */ |
267 | */ |
268 | object * |
268 | object * |
269 | lookup_spell_by_name (object *op, const char *spname) |
269 | object::find_spell (const_utf8_string prefix) const |
270 | { |
270 | { |
271 | object *spob1 = 0, *spob2 = 0; |
271 | if (shstr_cmp name = prefix) |
272 | int nummatch = 0; |
272 | { |
273 | |
273 | // 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) |
274 | for (object *spob = inv; spob; spob = spob->below) |
|
|
275 | if (spob->name == name && spob->type == SPELL) |
|
|
276 | return spob; |
282 | { |
277 | } |
|
|
278 | else |
|
|
279 | { |
|
|
280 | // case 2, match prefix |
|
|
281 | int len = strlen (prefix); |
|
|
282 | |
|
|
283 | for (object *spob = inv; spob; spob = spob->below) |
283 | if (spob->type == SPELL) |
284 | if (spob->type == SPELL |
284 | { |
285 | && spob->name.length () < len |
285 | // TODO: WTF? |
286 | && prefix [spob->name.length ()] <= ' ' |
286 | if (!strncmp (spob->name, spname, strlen (spname))) |
287 | && !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; |
288 | return spob; |
|
|
289 | } |
310 | |
290 | |
311 | if (spob1 && nummatch == 1) |
|
|
312 | return spob1; |
|
|
313 | |
|
|
314 | return NULL; |
291 | return 0; |
315 | } |
292 | } |
316 | |
293 | |
317 | /* reflwall - decides weither the (spell-)object sp_op will |
294 | /* reflwall - decides weither the (spell-)object sp_op will |
318 | * be reflected from the given mapsquare. Returns 1 if true. |
295 | * be reflected from the given mapsquare. Returns 1 if true. |
319 | * (Note that for living creatures there is a small chance that |
296 | * (Note that for living creatures there is a small chance that |
… | |
… | |
338 | |
315 | |
339 | /* cast_create_object: creates object new_op in direction dir |
316 | /* cast_create_object: creates object new_op in direction dir |
340 | * or if that is blocked, beneath the player (op). |
317 | * or if that is blocked, beneath the player (op). |
341 | * we pass 'caster', but don't use it for anything. |
318 | * we pass 'caster', but don't use it for anything. |
342 | * This is really just a simple wrapper function . |
319 | * This is really just a simple wrapper function . |
343 | * returns the direction that the object was actually placed |
320 | * returns true to indicate whether the operation was successful. |
344 | * in. |
321 | * destroys the object is unsuccessful. |
345 | */ |
322 | */ |
346 | int |
323 | bool |
347 | cast_create_obj (object *op, object *caster, object *new_op, int dir) |
324 | cast_create_obj (object *op, object *caster, object *new_op, int dir) |
348 | { |
325 | { |
349 | maptile *m; |
326 | mapxy pos (op); |
350 | sint16 sx, sy; |
327 | pos.move (dir); |
351 | |
328 | |
352 | if (dir && |
329 | 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) || |
330 | || 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)))) |
331 | || !new_op->can_drop_at (pos.m, pos.x, pos.y) |
|
|
332 | ) |
355 | { |
333 | { |
356 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
334 | 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."); |
335 | new_op->destroy (); |
358 | dir = 0; |
336 | return 0; |
359 | } |
337 | } |
360 | |
338 | |
361 | new_op->set_flag (FLAG_IDENTIFIED); |
339 | 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 | |
340 | |
|
|
341 | pos.insert (new_op, op, dir ? 0 : INS_BELOW_ORIGINATOR); |
|
|
342 | |
367 | return dir; |
343 | return 1; |
368 | } |
344 | } |
369 | |
345 | |
370 | static bool |
346 | static bool |
371 | mergable_owner (object *o1, object *o2) |
347 | mergable_owner (object *o1, object *o2) |
372 | { |
348 | { |
… | |
… | |
795 | godname = "Your spirit"; |
771 | godname = "Your spirit"; |
796 | |
772 | |
797 | if (failure <= -20 && failure > -40) /* wonder */ |
773 | if (failure <= -20 && failure > -40) /* wonder */ |
798 | { |
774 | { |
799 | op->failmsgf ("%s gives a sign to renew your faith." HINT_GRACE, godname); |
775 | op->failmsgf ("%s gives a sign to renew your faith." HINT_GRACE, godname); |
800 | tmp = get_archetype (SPELL_WONDER); |
776 | tmp = archetype::get (SPELL_WONDER); |
801 | cast_cone (op, op, 0, tmp); |
777 | cast_cone (op, op, 0, tmp); |
802 | tmp->destroy (); |
778 | tmp->destroy (); |
803 | } |
779 | } |
804 | |
780 | |
805 | else if (failure <= -40 && failure > -60) /* confusion */ |
781 | else if (failure <= -40 && failure > -60) /* confusion */ |
… | |
… | |
814 | godname); |
790 | godname); |
815 | paralyze_player (op, op, 99); |
791 | paralyze_player (op, op, 99); |
816 | } |
792 | } |
817 | else if (failure <= -150) /* blast the immediate area */ |
793 | else if (failure <= -150) /* blast the immediate area */ |
818 | { |
794 | { |
819 | tmp = get_archetype (GOD_POWER); |
795 | tmp = archetype::get (GOD_POWER); |
820 | op->failmsgf ("%s smites you!" HINT_GRACE, godname); |
796 | op->failmsgf ("%s smites you!" HINT_GRACE, godname); |
821 | cast_magic_storm (op, tmp, power); |
797 | cast_magic_storm (op, tmp, power); |
822 | } |
798 | } |
823 | } |
799 | } |
824 | |
800 | |
825 | /* |
801 | /* |
826 | * spell_failure() handles the various effects for differing degrees |
802 | * spell_failure() handles the various effects for differing degrees |
827 | * of failure badness. |
803 | * of failure badness. |
828 | * op is the player that failed. |
804 | * op is the player that failed. |
829 | * failure is a random value of how badly you failed. |
805 | * failure is a random value of how badly you failed. |
830 | * power is how many spellpoints you'd normally need for the spell. |
806 | * power is how many spellpoints you'd normally need for the spell. |
831 | * skill is the skill you'd need to cast the spell. |
807 | * skill is the skill you'd need to cast the spell. |
832 | */ |
808 | */ |
833 | |
|
|
834 | void |
809 | void |
835 | spell_failure (object *op, int failure, int power, object *skill) |
810 | spell_failure (object *op, int failure, int power, object *skill) |
836 | { |
811 | { |
837 | object *tmp; |
812 | object *tmp; |
838 | |
813 | |
… | |
… | |
840 | return; |
815 | return; |
841 | |
816 | |
842 | if (failure <= -20 && failure > -40) /* wonder */ |
817 | if (failure <= -20 && failure > -40) /* wonder */ |
843 | { |
818 | { |
844 | op->failmsg ("Your spell causes an unexpected effect."); |
819 | op->failmsg ("Your spell causes an unexpected effect."); |
845 | tmp = get_archetype (SPELL_WONDER); |
820 | tmp = archetype::get (SPELL_WONDER); |
846 | cast_cone (op, op, 0, tmp); |
821 | cast_cone (op, op, 0, tmp); |
847 | tmp->destroy (); |
822 | tmp->destroy (); |
848 | } |
823 | } |
849 | |
824 | |
850 | else if (failure <= -40 && failure > -60) /* confusion */ |
825 | else if (failure <= -40 && failure > -60) /* confusion */ |
… | |
… | |
869 | |
844 | |
870 | } |
845 | } |
871 | else |
846 | else |
872 | { |
847 | { |
873 | op->failmsg ("You lose control of the mana! The uncontrolled magic blasts you!"); |
848 | op->failmsg ("You lose control of the mana! The uncontrolled magic blasts you!"); |
874 | tmp = get_archetype (LOOSE_MANA); |
849 | tmp = archetype::get (LOOSE_MANA); |
875 | tmp->level = skill->level; |
850 | tmp->level = skill->level; |
876 | |
851 | |
877 | /* increase the area of destruction a little for more powerful spells */ |
852 | /* increase the area of destruction a little for more powerful spells */ |
878 | tmp->range += isqrt (power); |
853 | tmp->range += isqrt (power); |
879 | |
854 | |
… | |
… | |
1504 | * the victim with a specific maximum level. |
1479 | * the victim with a specific maximum level. |
1505 | */ |
1480 | */ |
1506 | void |
1481 | void |
1507 | create_exploding_ball_at (object *victim, int level) |
1482 | create_exploding_ball_at (object *victim, int level) |
1508 | { |
1483 | { |
1509 | object *ball = get_archetype (EXPLODING_FIREBALL); |
1484 | object *ball = archetype::get (EXPLODING_FIREBALL); |
1510 | ball->dam_modifier = random_roll (1, level, victim, PREFER_LOW) / 5 + 1; |
1485 | ball->dam_modifier = random_roll (1, level, victim, PREFER_LOW) / 5 + 1; |
1511 | ball->stats.maxhp = random_roll (1, level, victim, PREFER_LOW) / 10 + 2; |
1486 | ball->stats.maxhp = random_roll (1, level, victim, PREFER_LOW) / 10 + 2; |
1512 | ball->insert_at (victim); |
1487 | ball->insert_at (victim); |
1513 | } |
1488 | } |