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.83 by root, Mon Sep 29 11:52:34 2008 UTC vs.
Revision 1.95 by root, Mon Mar 2 22:25:19 2009 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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 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
33/* This returns a random spell from 'ob'. If skill is set, then 33/* This returns a random spell from 'ob'. If skill is set, then
34 * the spell must be of this skill, it can be NULL in which case all 34 * the spell must be of this skill, it can be NULL in which case all
35 * matching spells are used. 35 * matching spells are used.
36 */ 36 */
37object * 37object *
38find_random_spell_in_ob (object *ob, const char *skill) 38find_random_spell_in_ob (object *ob, shstr_cmp skill)
39{ 39{
40 int k = 0, s; 40 int k = 0, s;
41 41
42 for (object *tmp = ob->inv; tmp; tmp = tmp->below) 42 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
43 if (tmp->type == SPELL && (!skill || tmp->skill == skill)) 43 if (tmp->type == SPELL && (!skill || tmp->skill == skill))
45 45
46 /* No spells, no need to progess further */ 46 /* No spells, no need to progess further */
47 if (!k) 47 if (!k)
48 return NULL; 48 return NULL;
49 49
50 s = RANDOM () % k; 50 s = rndm (k);
51 51
52 for (object *tmp = ob->inv; tmp; tmp = tmp->below) 52 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
53 if (tmp->type == SPELL && (!skill || tmp->skill == skill)) 53 if (tmp->type == SPELL && (!skill || tmp->skill == skill))
54 if (!s) 54 if (!s)
55 return tmp; 55 return tmp;
126 level = lerp (level, (int)spell->level, 100, 1, 100); 126 level = lerp (level, (int)spell->level, 100, 1, 100);
127 127
128 /* Always make this at least 1. If this is zero, we get divide by zero 128 /* Always make this at least 1. If this is zero, we get divide by zero
129 * errors in various places. 129 * errors in various places.
130 */ 130 */
131 return max (level, 1); 131 return clamp (level, 1, settings.max_level);
132} 132}
133 133
134/* The following function scales the spellpoint cost of 134/* The following function scales the spellpoint cost of
135 * a spell by it's increased effectiveness. Some of the 135 * a spell by it's increased effectiveness. Some of the
136 * lower level spells become incredibly vicious at high 136 * lower level spells become incredibly vicious at high
247/* Checks to see if player knows the spell. If the name is the same 247/* Checks to see if player knows the spell. If the name is the same
248 * as an existing spell, we presume they know it. 248 * as an existing spell, we presume they know it.
249 * returns 1 if they know the spell, 0 if they don't. 249 * returns 1 if they know the spell, 0 if they don't.
250 */ 250 */
251object * 251object *
252check_spell_known (object *op, const char *name) 252check_spell_known (object *op, shstr_cmp name)
253{ 253{
254 object *spop; 254 object *spop;
255 shstr_cmp name_ (name);
256 255
257 for (spop = op->inv; spop; spop = spop->below) 256 for (spop = op->inv; spop; spop = spop->below)
258 if (spop->type == SPELL && spop->name == name) 257 if (spop->type == SPELL && spop->name == name)
259 return spop; 258 return spop;
260 259
270 * exact match, we also return NULL. 269 * exact match, we also return NULL.
271 */ 270 */
272object * 271object *
273lookup_spell_by_name (object *op, const char *spname) 272lookup_spell_by_name (object *op, const char *spname)
274{ 273{
275 object *spob1 = NULL, *spob2 = NULL, *spob; 274 object *spob1 = 0, *spob2 = 0;
276 int nummatch = 0; 275 int nummatch = 0;
277 276
278 if (spname == NULL) 277 if (!spname)
279 return NULL; 278 return 0;
280 279
281 /* Try to find the spell. We store the results in spob1 280 /* Try to find the spell. We store the results in spob1
282 * and spob2 - spob1 is only taking the length of 281 * and spob2 - spob1 is only taking the length of
283 * the past spname, spob2 uses the length of the spell name. 282 * the past spname, spob2 uses the length of the spell name.
284 */ 283 */
285 for (spob = op->inv; spob; spob = spob->below) 284 for (object *spob = op->inv; spob; spob = spob->below)
286 { 285 {
287 if (spob->type == SPELL) 286 if (spob->type == SPELL)
288 { 287 {
288 // TODO: WTF?
289 if (!strncmp (spob->name, spname, strlen (spname))) 289 if (!strncmp (spob->name, spname, strlen (spname)))
290 { 290 {
291 nummatch++; 291 nummatch++;
292 spob1 = spob; 292 spob1 = spob;
293 } 293 }
298 * fall into this category). It shouldn't be hard to 298 * fall into this category). It shouldn't be hard to
299 * make sure spell names don't overlap in that fashion. 299 * make sure spell names don't overlap in that fashion.
300 */ 300 */
301 if (spob2) 301 if (spob2)
302 LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name); 302 LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name);
303
303 spob2 = spob; 304 spob2 = spob;
304 } 305 }
305 } 306 }
306 } 307 }
307 /* if we have best match, return it. Otherwise, if we have one match 308 /* if we have best match, return it. Otherwise, if we have one match
308 * on the loser match, return that, otehrwise null 309 * on the loser match, return that, otehrwise null
309 */ 310 */
310 if (spob2) 311 if (spob2)
311 return spob2; 312 return spob2;
313
312 if (spob1 && nummatch == 1) 314 if (spob1 && nummatch == 1)
313 return spob1; 315 return spob1;
316
314 return NULL; 317 return NULL;
315} 318}
316 319
317/* reflwall - decides weither the (spell-)object sp_op will 320/* reflwall - decides weither the (spell-)object sp_op will
318 * be reflected from the given mapsquare. Returns 1 if true. 321 * be reflected from the given mapsquare. Returns 1 if true.
365 dir ? 0 : INS_BELOW_ORIGINATOR); 368 dir ? 0 : INS_BELOW_ORIGINATOR);
366 369
367 return dir; 370 return dir;
368} 371}
369 372
373static bool
374mergable_owner (object *o1, object *o2)
375{
376 if (o1 == o2)
377 return 1;
378
379 if (!o1 || !o2)
380 return 0;
381
382 if (o1->flag [FLAG_FRIENDLY] != o1->flag [FLAG_FRIENDLY])
383 return 0;
384
385 if (o1->is_player () || o2->is_player ())
386 return 0;
387
388 return 1;
389}
390
370/* Returns true if it is ok to put spell *op on the space/may provided. 391/* Returns true if it is ok to put spell *op on the space/may provided.
371 * immune_stop is basically the attacktype of the spell (why 392 * immune_stop is basically the attacktype of the spell (why
372 * passed as a different value, not sure of). If immune_stop 393 * passed as a different value, not sure of). If immune_stop
373 * has the AT_MAGIC bit set, and there is a counterwall 394 * has the AT_MAGIC bit set, and there is a counterwall
374 * on the space, the object doesn't get placed. if immune stop 395 * on the space, the object doesn't get placed. if immune stop
375 * does not have AT_MAGIC, then counterwalls do not effect the spell. 396 * does not have AT_MAGIC, then counterwalls do not effect the spell.
376 *
377 */ 397 */
378int 398int
379ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) 399ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
380{ 400{
381 if (!xy_normalise (m, x, y)) 401 if (!xy_normalise (m, x, y))
384 mapspace &ms = m->at (x, y); 404 mapspace &ms = m->at (x, y);
385 ms.update (); 405 ms.update ();
386 406
387 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) 407 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
388 return 0; 408 return 0;
409
410 int max_effects = 5; // max. number of similar spells per mapspace
389 411
390 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 412 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
391 { 413 {
392 /* If there is a counterspell on the space, and this 414 /* If there is a counterspell on the space, and this
393 * object is using magic, don't progress. I believe we could 415 * object is using magic, don't progress. I believe we could
412 // (and those shouldn't go away from 434 // (and those shouldn't go away from
413 // sanctuary) see also: permanent lava 435 // sanctuary) see also: permanent lava
414 && (immune_stop & AT_MAGIC)) 436 && (immune_stop & AT_MAGIC))
415 return 0; 437 return 0;
416 438
417 /* This is to prevent 'out of control' spells. Basically, this
418 * limits one spell effect per space per spell. This is definately
419 * needed for performance reasons, and just for playability I believe.
420 * there are no such things as multispaced spells right now, so
421 * we don't need to worry about the head.
422 */
423 if ((tmp->stats.maxhp == op->stats.maxhp) && (tmp->type == op->type) && (tmp->subtype == op->subtype))
424 return 0;
425
426 /*
427 * Combine similar spell effects into one spell effect. Needed for
428 * performance reasons with meteor swarm and the like, but also for
429 * playability reasons.
430 */
431 if (tmp->arch == op->arch /* no harm if not comparing by name here */
432 && tmp->type == op->type 439 if (tmp->type == op->type)
433 && tmp->subtype == op->subtype
434 && tmp->owner == op->owner
435 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
436 { 440 {
437 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); 441 if (tmp->subtype == op->subtype
438 tmp->range = MAX (tmp->range, op->range); 442 && tmp->arch == op->arch /* no harm if not comparing by name here */)
439 tmp->duration = MAX (tmp->duration, op->duration); 443 {
444 /* This is to prevent 'out of control' spells. Basically, this
445 * limits one spell effect per space per spell. This is definately
446 * needed for performance reasons, and just for playability I believe.
447 * there are no such things as multispaced spells right now, so
448 * we don't need to worry about the head.
449 */
450 if (tmp->stats.maxhp == op->stats.maxhp)
451 return 0;
452
453 /*
454 * Combine similar spell effects into one spell effect. Needed for
455 * performance reasons with meteor swarm and the like, but also for
456 * playability reasons.
457 */
458 if (((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
459 if (mergable_owner (tmp, op))
460 {
461 // if same owner, then combine, but reduce advantage of multiple spells
462 max_it (tmp->stats.dam, op->stats.dam);
463 max_it (tmp->range , op->range);
464 max_it (tmp->duration , op->duration);
465 return 0;
466 }
467 }
468
469 // if there are too many spell effects on this space,
470 // then don't allow more of them, for performance reasons.
471 if (tmp->type == SPELL_EFFECT
472 && !--max_effects)
440 return 0; 473 return 0;
441 } 474 }
442 475
443 /* Perhaps we should also put checks in for no magic and unholy 476 /* Perhaps we should also put checks in for no magic and unholy
444 * ground to prevent it from moving along? 477 * ground to prevent it from moving along?
445 */ 478 */
670 * Note that this is not used by any spells (summon evil monsters 703 * Note that this is not used by any spells (summon evil monsters
671 * use to call this, but best I can tell, that spell/ability was 704 * use to call this, but best I can tell, that spell/ability was
672 * never used. This is however used by various failures on the 705 * never used. This is however used by various failures on the
673 * players part (alchemy, reincarnation, etc) 706 * players part (alchemy, reincarnation, etc)
674 */ 707 */
675
676int 708int
677summon_hostile_monsters (object *op, int n, const char *monstername) 709summon_hostile_monsters (object *op, int n, const char *monstername)
678{ 710{
679 int i; 711 int i;
680 712
745 { 777 {
746 SET_ANIMATION (op, ATTACKS[i].face); 778 SET_ANIMATION (op, ATTACKS[i].face);
747 } 779 }
748} 780}
749 781
750
751/* prayer_failure: This is called when a player fails 782/* prayer_failure: This is called when a player fails
752 * at casting a prayer. 783 * at casting a prayer.
753 * op is the player. 784 * op is the player.
754 * failure is basically how much grace they had. 785 * failure is basically how much grace they had.
755 * power is how much grace the spell would normally take to cast. 786 * power is how much grace the spell would normally take to cast.
756 */ 787 */
757
758void 788void
759prayer_failure (object *op, int failure, int power) 789prayer_failure (object *op, int failure, int power)
760{ 790{
761 const char *godname; 791 const char *godname;
762 object *tmp; 792 object *tmp;
918 */ 948 */
919int 949int
920cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 950cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
921{ 951{
922 const char *godname; 952 const char *godname;
923 int success = 0, cast_level = 0; 953 int success = 0;
924 object *skill = NULL; 954 object *skill = NULL;
925 955
926 if (!spell_ob) 956 if (!spell_ob)
927 { 957 {
928 LOG (llevError, "cast_spell: null spell object passed\n"); 958 LOG (llevError, "cast_spell: null spell object passed\n");
976 1006
977 int caster_level = skill->level; 1007 int caster_level = skill->level;
978 1008
979 if (op->path_attuned & spell_ob->path_attuned) 1009 if (op->path_attuned & spell_ob->path_attuned)
980 { 1010 {
981 caster_level += min (cast_level * 2, ATTUNE_REPELL); 1011 caster_level += min (caster_level, ATTUNE_REPELL);
982 msg = " (attuned)"; 1012 msg = " (attuned)";
983 } 1013 }
984 1014
985 if (op->path_repelled & spell_ob->path_attuned) 1015 if (op->path_repelled & spell_ob->path_attuned)
986 { 1016 {
987 caster_level = ATTUNE_REPELL; // negative is ok 1017 caster_level -= ATTUNE_REPELL; // negative is ok
988 msg = " (repelled)"; 1018 msg = " (repelled)";
989 } 1019 }
990 1020
991 if (spell_ob->level > caster_level) 1021 if (spell_ob->level > caster_level)
992 { 1022 {
999 } 1029 }
1000 1030
1001 /* If the caster is the wiz, they don't ever fail, and don't have 1031 /* If the caster is the wiz, they don't ever fail, and don't have
1002 * to have sufficient grace/mana. 1032 * to have sufficient grace/mana.
1003 */ 1033 */
1004 if (!QUERY_FLAG (op, FLAG_WIZ)) 1034 if (!QUERY_FLAG (op, FLAG_WIZCAST))
1005 { 1035 {
1006 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && 1036 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) &&
1007 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1037 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1008 { 1038 {
1009 op->failmsg ("You don't have enough mana!"); 1039 op->failmsg ("You don't have enough mana!");
1138 return RESULT_INT (0); 1168 return RESULT_INT (0);
1139 1169
1140 switch (spell_ob->subtype) 1170 switch (spell_ob->subtype)
1141 { 1171 {
1142 /* The order of case statements is same as the order they show up 1172 /* The order of case statements is same as the order they show up
1143 * in in spells.h. 1173 * in spells.h.
1144 */ 1174 */
1145 case SP_RAISE_DEAD: 1175 case SP_RAISE_DEAD:
1146 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg); 1176 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg);
1147 break; 1177 break;
1148 1178
1467 1497
1468 break; 1498 break;
1469 } 1499 }
1470} 1500}
1471 1501
1502/**
1503 * This function will let a fireball explode at the position of
1504 * the victim with a specific maximum level.
1505 */
1506void
1507create_exploding_ball_at (object *victim, int level)
1508{
1509 object *ball = get_archetype (EXPLODING_FIREBALL);
1510 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;
1512 ball->insert_at (victim);
1513}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines