[Scrymud] Notes about the new Spell class

gingon at WANfear.com gingon at WANfear.com
Thu Jan 31 11:29:09 PST 2002


alright, the new spell class and subclass are relatively easy to setup, and far 
more efficient than the old way of making spells. the resulting code is much 
smaller, by about 2-6k per spell. plus i've got a few more improvements to make 
shortly, which may cut the size down even further. execution speed may have 
suffered slightly, but is nothing compared to a stall due to reading from main 
memory. (generally 5-11 cycles on most pentium class cpus and probably on 
athlons too) in addition, with the common code being in one place, the chance 
of the needed code being in the L1 or L2 cache is much higher.

anyway, enough of my pointless cpu stuff and on to the stuff most of you are 
interested in, how to make a spell with the new code.

1. pick the target subclass, they are MobSpell, ObjSpell, DoorSpell, RoomSpell 
and SelfSpell. Only MobSpell works currently. also, if you need a spell that 
can target more than one type, or one that can target beyond the current room, 
you'll need to derive your spell directly from the Spell class and define the 
methods:
int getSpellTarget(int i_th, const String* vict, critter& pc);
void onCast(critter& vict, critter& pc, int is_canned = FALSE,int lvl = 0);
void onCast(int i_th, const String* vict, critter& pc, int is_canned = FALSE, 
int lvl = 0);

see the code in dam_spll.cc and dam_spll.h for examples of this

2. define void spellNameGoesHere::doSpellEffects();
this is where the magic happens(hehe, please forgive the pun, couldn't resist).

3. add a call to spellNameGoesHere.setupSpell(NAME_SKILL_NUM, 
1, "KMSNV", "GSM", "Name goes here", "No target message here.\n,", 
"messed up casting message here") in spells.cc in the function config_spells()

first arg is skill number, the second arg is the amount of pause the spell 
causes in the caster, the third arg is the string passed to ok_to_do_actions
(set the code for that for details) the fourth is the string passed to 
check_for_diversions(again, see code for details), the fifth is the spell name, 
sixth is the no target message, and seventh is the failed casting message.
the third and fourth args can be passed NULL, and the last two have defaults, 
though you may want to change the sixth arg's message(see code for details)

4. the final part, make sure you define a var for your spell class like:
SpellName spellName;
(note: you may want to put extern SpellName spellName some where in the header 
of the file you are working on, makes things easier in some cases.

and that's about it, only thing else is that the classes are defined in spells.h

hopefully this makes it easier for the rest of you to make new spells using the 
Spell class(it would be bad if you didn't, cause then i'd have to rewrite them, 
so use it!). 

--Gingon





More information about the ScryMUD mailing list