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.80 by root, Mon Sep 29 08:25:02 2008 UTC vs.
Revision 1.89 by root, Wed Dec 31 17:35:38 2008 UTC

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;
93 // compute the attuned/repelled bonus 93 // compute the attuned/repelled bonus
94 // attuned only increases up to 2 times the original level (i.e. bonus <= level) */ 94 // attuned only increases up to 2 times the original level (i.e. bonus <= level) */
95 // repell has no such quarrels 95 // repell has no such quarrels
96 return (caster->path_attuned & spell->path_attuned ? min (level, +ATTUNE_REPELL) : 0) 96 return (caster->path_attuned & spell->path_attuned ? min (level, +ATTUNE_REPELL) : 0)
97 + (caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0); 97 + (caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0);
98}
99
100/*
101 * This function takes a caster and spell and presents the
102 * effective level the caster needs to be to cast the spell.
103 * basically, it just adjusts the spell->level with attuned/repelled
104 * spellpaths. Was called path_level_mod.
105 *
106 * caster is person casting the spell.
107 * spell is the spell object.
108 * Returns modified level.
109 */
110int
111min_casting_level (object *caster, object *spell)
112{
113 if (caster->path_denied & spell->path_attuned)
114 return 500;
115
116 return max (1, spell->level + attuned_bonus (caster, spell, spell->level));
117} 98}
118 99
119/* This function returns the effective level the spell 100/* This function returns the effective level the spell
120 * is being cast at. 101 * is being cast at.
121 */ 102 */
289 * exact match, we also return NULL. 270 * exact match, we also return NULL.
290 */ 271 */
291object * 272object *
292lookup_spell_by_name (object *op, const char *spname) 273lookup_spell_by_name (object *op, const char *spname)
293{ 274{
294 object *spob1 = NULL, *spob2 = NULL, *spob; 275 object *spob1 = 0, *spob2 = 0;
295 int nummatch = 0; 276 int nummatch = 0;
296 277
297 if (spname == NULL) 278 if (!spname)
298 return NULL; 279 return 0;
299 280
300 /* Try to find the spell. We store the results in spob1 281 /* Try to find the spell. We store the results in spob1
301 * and spob2 - spob1 is only taking the length of 282 * and spob2 - spob1 is only taking the length of
302 * the past spname, spob2 uses the length of the spell name. 283 * the past spname, spob2 uses the length of the spell name.
303 */ 284 */
304 for (spob = op->inv; spob; spob = spob->below) 285 for (object *spob = op->inv; spob; spob = spob->below)
305 { 286 {
306 if (spob->type == SPELL) 287 if (spob->type == SPELL)
307 { 288 {
289 // TODO: WTF?
308 if (!strncmp (spob->name, spname, strlen (spname))) 290 if (!strncmp (spob->name, spname, strlen (spname)))
309 { 291 {
310 nummatch++; 292 nummatch++;
311 spob1 = spob; 293 spob1 = spob;
312 } 294 }
317 * fall into this category). It shouldn't be hard to 299 * fall into this category). It shouldn't be hard to
318 * make sure spell names don't overlap in that fashion. 300 * make sure spell names don't overlap in that fashion.
319 */ 301 */
320 if (spob2) 302 if (spob2)
321 LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name); 303 LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name);
304
322 spob2 = spob; 305 spob2 = spob;
323 } 306 }
324 } 307 }
325 } 308 }
326 /* if we have best match, return it. Otherwise, if we have one match 309 /* if we have best match, return it. Otherwise, if we have one match
327 * on the loser match, return that, otehrwise null 310 * on the loser match, return that, otehrwise null
328 */ 311 */
329 if (spob2) 312 if (spob2)
330 return spob2; 313 return spob2;
314
331 if (spob1 && nummatch == 1) 315 if (spob1 && nummatch == 1)
332 return spob1; 316 return spob1;
317
333 return NULL; 318 return NULL;
334} 319}
335 320
336/* reflwall - decides weither the (spell-)object sp_op will 321/* reflwall - decides weither the (spell-)object sp_op will
337 * be reflected from the given mapsquare. Returns 1 if true. 322 * be reflected from the given mapsquare. Returns 1 if true.
764 { 749 {
765 SET_ANIMATION (op, ATTACKS[i].face); 750 SET_ANIMATION (op, ATTACKS[i].face);
766 } 751 }
767} 752}
768 753
769
770/* prayer_failure: This is called when a player fails 754/* prayer_failure: This is called when a player fails
771 * at casting a prayer. 755 * at casting a prayer.
772 * op is the player. 756 * op is the player.
773 * failure is basically how much grace they had. 757 * failure is basically how much grace they had.
774 * power is how much grace the spell would normally take to cast. 758 * power is how much grace the spell would normally take to cast.
775 */ 759 */
776
777void 760void
778prayer_failure (object *op, int failure, int power) 761prayer_failure (object *op, int failure, int power)
779{ 762{
780 const char *godname; 763 const char *godname;
781 object *tmp; 764 object *tmp;
937 */ 920 */
938int 921int
939cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 922cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
940{ 923{
941 const char *godname; 924 const char *godname;
942 int success = 0, cast_level = 0; 925 int success = 0;
943 object *skill = NULL; 926 object *skill = NULL;
944 927
945 if (!spell_ob) 928 if (!spell_ob)
946 { 929 {
947 LOG (llevError, "cast_spell: null spell object passed\n"); 930 LOG (llevError, "cast_spell: null spell object passed\n");
995 978
996 int caster_level = skill->level; 979 int caster_level = skill->level;
997 980
998 if (op->path_attuned & spell_ob->path_attuned) 981 if (op->path_attuned & spell_ob->path_attuned)
999 { 982 {
1000 caster_level += min (cast_level * 2, ATTUNE_REPELL); 983 caster_level += min (caster_level, ATTUNE_REPELL);
1001 msg = " (attuned)"; 984 msg = " (attuned)";
1002 } 985 }
1003 986
1004 if (op->path_repelled & spell_ob->path_attuned) 987 if (op->path_repelled & spell_ob->path_attuned)
1005 { 988 {
1006 caster_level = ATTUNE_REPELL; // negative is ok 989 caster_level -= ATTUNE_REPELL; // negative is ok
1007 msg = " (repelled)"; 990 msg = " (repelled)";
1008 } 991 }
1009 992
1010 if (spell_ob->level > caster_level) 993 if (spell_ob->level > caster_level)
1011 { 994 {
1018 } 1001 }
1019 1002
1020 /* If the caster is the wiz, they don't ever fail, and don't have 1003 /* If the caster is the wiz, they don't ever fail, and don't have
1021 * to have sufficient grace/mana. 1004 * to have sufficient grace/mana.
1022 */ 1005 */
1023 if (!QUERY_FLAG (op, FLAG_WIZ)) 1006 if (!QUERY_FLAG (op, FLAG_WIZCAST))
1024 { 1007 {
1025 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && 1008 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) &&
1026 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1009 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1027 { 1010 {
1028 op->failmsg ("You don't have enough mana!"); 1011 op->failmsg ("You don't have enough mana!");
1472 1455
1473 case SP_MAGIC_MISSILE: 1456 case SP_MAGIC_MISSILE:
1474 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1457 if (QUERY_FLAG (victim, FLAG_ALIVE))
1475 { 1458 {
1476 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1459 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1477
1478 if (!spell->destroyed ())
1479 spell->destroy (); 1460 spell->destroy ();
1480 } 1461 }
1481 break; 1462 break;
1482 1463
1483 case SP_MOVING_BALL: 1464 case SP_MOVING_BALL:
1484 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1465 if (QUERY_FLAG (victim, FLAG_ALIVE))
1485 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1466 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1486 else if (victim->materialname) 1467 else if (victim->materialname)
1487 save_throw_object (victim, spell->attacktype, spell); 1468 save_throw_object (victim, spell->attacktype, spell);
1488 break;
1489 }
1490}
1491 1469
1470 break;
1471 }
1472}
1473

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines