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.91 by root, Sun Jan 11 00:31:52 2009 UTC

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;
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} 98}
99 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}
118
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 */
122int 103int
123casting_level (object *caster, object *spell) 104casting_level (object *caster, object *spell)
145 level = lerp (level, (int)spell->level, 100, 1, 100); 126 level = lerp (level, (int)spell->level, 100, 1, 100);
146 127
147 /* 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
148 * errors in various places. 129 * errors in various places.
149 */ 130 */
150 return max (level, 1); 131 return clamp (level, 1, settings.max_level);
151} 132}
152 133
153/* The following function scales the spellpoint cost of 134/* The following function scales the spellpoint cost of
154 * a spell by it's increased effectiveness. Some of the 135 * a spell by it's increased effectiveness. Some of the
155 * lower level spells become incredibly vicious at high 136 * lower level spells become incredibly vicious at high
266/* 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
267 * as an existing spell, we presume they know it. 248 * as an existing spell, we presume they know it.
268 * 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.
269 */ 250 */
270object * 251object *
271check_spell_known (object *op, const char *name) 252check_spell_known (object *op, shstr_cmp name)
272{ 253{
273 object *spop; 254 object *spop;
274 shstr_cmp name_ (name);
275 255
276 for (spop = op->inv; spop; spop = spop->below) 256 for (spop = op->inv; spop; spop = spop->below)
277 if (spop->type == SPELL && spop->name == name) 257 if (spop->type == SPELL && spop->name == name)
278 return spop; 258 return spop;
279 259
289 * exact match, we also return NULL. 269 * exact match, we also return NULL.
290 */ 270 */
291object * 271object *
292lookup_spell_by_name (object *op, const char *spname) 272lookup_spell_by_name (object *op, const char *spname)
293{ 273{
294 object *spob1 = NULL, *spob2 = NULL, *spob; 274 object *spob1 = 0, *spob2 = 0;
295 int nummatch = 0; 275 int nummatch = 0;
296 276
297 if (spname == NULL) 277 if (!spname)
298 return NULL; 278 return 0;
299 279
300 /* Try to find the spell. We store the results in spob1 280 /* Try to find the spell. We store the results in spob1
301 * and spob2 - spob1 is only taking the length of 281 * and spob2 - spob1 is only taking the length of
302 * the past spname, spob2 uses the length of the spell name. 282 * the past spname, spob2 uses the length of the spell name.
303 */ 283 */
304 for (spob = op->inv; spob; spob = spob->below) 284 for (object *spob = op->inv; spob; spob = spob->below)
305 { 285 {
306 if (spob->type == SPELL) 286 if (spob->type == SPELL)
307 { 287 {
288 // TODO: WTF?
308 if (!strncmp (spob->name, spname, strlen (spname))) 289 if (!strncmp (spob->name, spname, strlen (spname)))
309 { 290 {
310 nummatch++; 291 nummatch++;
311 spob1 = spob; 292 spob1 = spob;
312 } 293 }
317 * fall into this category). It shouldn't be hard to 298 * fall into this category). It shouldn't be hard to
318 * make sure spell names don't overlap in that fashion. 299 * make sure spell names don't overlap in that fashion.
319 */ 300 */
320 if (spob2) 301 if (spob2)
321 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
322 spob2 = spob; 304 spob2 = spob;
323 } 305 }
324 } 306 }
325 } 307 }
326 /* 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
327 * on the loser match, return that, otehrwise null 309 * on the loser match, return that, otehrwise null
328 */ 310 */
329 if (spob2) 311 if (spob2)
330 return spob2; 312 return spob2;
313
331 if (spob1 && nummatch == 1) 314 if (spob1 && nummatch == 1)
332 return spob1; 315 return spob1;
316
333 return NULL; 317 return NULL;
334} 318}
335 319
336/* reflwall - decides weither the (spell-)object sp_op will 320/* reflwall - decides weither the (spell-)object sp_op will
337 * be reflected from the given mapsquare. Returns 1 if true. 321 * be reflected from the given mapsquare. Returns 1 if true.
764 { 748 {
765 SET_ANIMATION (op, ATTACKS[i].face); 749 SET_ANIMATION (op, ATTACKS[i].face);
766 } 750 }
767} 751}
768 752
769
770/* prayer_failure: This is called when a player fails 753/* prayer_failure: This is called when a player fails
771 * at casting a prayer. 754 * at casting a prayer.
772 * op is the player. 755 * op is the player.
773 * failure is basically how much grace they had. 756 * failure is basically how much grace they had.
774 * power is how much grace the spell would normally take to cast. 757 * power is how much grace the spell would normally take to cast.
775 */ 758 */
776
777void 759void
778prayer_failure (object *op, int failure, int power) 760prayer_failure (object *op, int failure, int power)
779{ 761{
780 const char *godname; 762 const char *godname;
781 object *tmp; 763 object *tmp;
937 */ 919 */
938int 920int
939cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 921cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
940{ 922{
941 const char *godname; 923 const char *godname;
942 int success = 0, cast_level = 0; 924 int success = 0;
943 object *skill = NULL; 925 object *skill = NULL;
944 926
945 if (!spell_ob) 927 if (!spell_ob)
946 { 928 {
947 LOG (llevError, "cast_spell: null spell object passed\n"); 929 LOG (llevError, "cast_spell: null spell object passed\n");
995 977
996 int caster_level = skill->level; 978 int caster_level = skill->level;
997 979
998 if (op->path_attuned & spell_ob->path_attuned) 980 if (op->path_attuned & spell_ob->path_attuned)
999 { 981 {
1000 caster_level += min (cast_level * 2, ATTUNE_REPELL); 982 caster_level += min (caster_level, ATTUNE_REPELL);
1001 msg = " (attuned)"; 983 msg = " (attuned)";
1002 } 984 }
1003 985
1004 if (op->path_repelled & spell_ob->path_attuned) 986 if (op->path_repelled & spell_ob->path_attuned)
1005 { 987 {
1006 caster_level = ATTUNE_REPELL; // negative is ok 988 caster_level -= ATTUNE_REPELL; // negative is ok
1007 msg = " (repelled)"; 989 msg = " (repelled)";
1008 } 990 }
1009 991
1010 if (spell_ob->level > caster_level) 992 if (spell_ob->level > caster_level)
1011 { 993 {
1018 } 1000 }
1019 1001
1020 /* If the caster is the wiz, they don't ever fail, and don't have 1002 /* If the caster is the wiz, they don't ever fail, and don't have
1021 * to have sufficient grace/mana. 1003 * to have sufficient grace/mana.
1022 */ 1004 */
1023 if (!QUERY_FLAG (op, FLAG_WIZ)) 1005 if (!QUERY_FLAG (op, FLAG_WIZCAST))
1024 { 1006 {
1025 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && 1007 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) &&
1026 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1008 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1027 { 1009 {
1028 op->failmsg ("You don't have enough mana!"); 1010 op->failmsg ("You don't have enough mana!");
1472 1454
1473 case SP_MAGIC_MISSILE: 1455 case SP_MAGIC_MISSILE:
1474 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1456 if (QUERY_FLAG (victim, FLAG_ALIVE))
1475 { 1457 {
1476 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1458 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1477
1478 if (!spell->destroyed ())
1479 spell->destroy (); 1459 spell->destroy ();
1480 } 1460 }
1481 break; 1461 break;
1482 1462
1483 case SP_MOVING_BALL: 1463 case SP_MOVING_BALL:
1484 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1464 if (QUERY_FLAG (victim, FLAG_ALIVE))
1485 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1465 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1486 else if (victim->materialname) 1466 else if (victim->materialname)
1487 save_throw_object (victim, spell->attacktype, spell); 1467 save_throw_object (victim, spell->attacktype, spell);
1488 break;
1489 }
1490}
1491 1468
1469 break;
1470 }
1471}
1472

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines