I'm currently trying to implement a bookless caster class, the Necromancer, in Vanilla. The Necromancer (and other bookless casters) would have a small collection of powerful but relatively specialized spells - in this class's case, mostly offensive spells.
My design for the spell system looks something like this...
- For actually casting the spell, I have a cast_necro_spell function, which takes the index of a spell, and a direction. Spell indices are set with #define statements, as per book spells. Damages, radii, etc. are hardcoded into this function.
- However, using tables or such for the info stuff struck me as annoying and maybe not so smart. Instead I figured I would use a struct, necro_infoholder, like this:
And have a function to return a necro_infoholder struct, whose values could be used by other functions:
So for browsing necromantic spells, I could do
... Does this sound in any way sane, or am I just making more trouble for myself? Please be a little forgiving, I am quite new to C.
My design for the spell system looks something like this...
- For actually casting the spell, I have a cast_necro_spell function, which takes the index of a spell, and a direction. Spell indices are set with #define statements, as per book spells. Damages, radii, etc. are hardcoded into this function.
- However, using tables or such for the info stuff struck me as annoying and maybe not so smart. Instead I figured I would use a struct, necro_infoholder, like this:
Code:
struct necro_infoholder {
int initial_level;
int mana_cost;
int initial_fail_rate;
char *desc;
};
Code:
struct *necro_infoholder necro_spell_info(int spell) {
struct necro_infoholder info;
switch(spell) {
case NECRO_DARK_BOLT:
{
info.initial_level = 1;
info.mana_cost = 2;
info.intial_fail_rate = 20;
info.desc = "Fires a bolt of elemental darkness.";
}
/* ... etc. */
}
return info;
}
Code:
struct necro_infoholder *some_spell_info = necro_spell_info(NECRO_DARK_BOLT); /* blah blah code to print the info */

Comment