14 Oct, 2010, Xrakisis wrote in the 1st comment:
Votes: 0
Hi all.
Im trying to give each class a number for spell power… (ch->spellpower) and have this affect the damage spells do. Sorcerers and Liches would do more spell damage than Hoplites and Templars. I cant get it to work and was looking for some advice..

in bool damage in fight.c

// old try
// if (dam > 1 && skill_table[sn].slot != 0 && skill_table[sn].spell_fun != 0)
// if (skill_table[sn].spell_fun != spell_null)


// New try
sn = 0;
sn = find_spell(ch,skill_table[sn].name);

if (skill_table[sn].slot > 0)
dam += ch->spellpower * 20;


if i try to have the damage multiply by spell power it crashes

im trying this on my ROM, started from quickmud
thanks, -xrak
14 Oct, 2010, Bobo the bee wrote in the 2nd comment:
Votes: 0
I would imagine it's because spellpower isn't initializing. Did you add spellpower to char_data and to the proper places to save and load it in a pfile? And initialization as far as setting the initial power. To make things safe, you should probably also set spellpower to 1 when you create a new character, too – and a new MOB, since that check would throw on NPCs too, I think.
14 Oct, 2010, Xrakisis wrote in the 3rd comment:
Votes: 0
Yeah, spellpower is in char_data… it saves and reads from pfile.. theres an update for those who created before spellpower was in… the biggest problem is i dont know how to initialize it.. cant figure out how to check if the damage being done is a spell and if so to increase the spells damage…
14 Oct, 2010, Mudder wrote in the 4th comment:
Votes: 0
Why not put it in the spell itself? Might be a little repetitive, but this would allow flexibility in that each spell can be affected differently by spell power.

Alternatively you could add a boolean variable in there which defaults to false and if true it means the damage was caused by a spell.
14 Oct, 2010, Bobo the bee wrote in the 5th comment:
Votes: 0
Xrakisis said:
Yeah, spellpower is in char_data… it saves and reads from pfile.. theres an update for those who created before spellpower was in… the biggest problem is i dont know how to initialize it.. cant figure out how to check if the damage being done is a spell and if so to increase the spells damage…


Creating a command of something like 'setspellpower' or some such – there might be a command like set in there anyways, I'm not sure if that comes with Rom or not – where you can type setspellpower Xrakisis 15 or what-have-you. Or you could just go into your pfile and edit it manually – if it's set to save and load right, giving it that initial value should be enough so that it initializes on a startup. Alternatively you could make a new character – assuming you did put a check in to set spellpower to 1 for new characters.
14 Oct, 2010, ATT_Turan wrote in the 6th comment:
Votes: 0
Xrakisis said:
// New try
sn = 0;
sn = find_spell(ch,skill_table[sn].name);


This doesn't make any sense. This is what you're saying:
"Okay, the number of the spell I don't know is zero until I know what it is. Now, I'm going to figure out what the number of the spell is by looking for the name of skill zero." This will always be the same thing and always be zero. Incidentally, find_spell is used to check whether a character can cast a spell. For just finding a spell's index based on its name, you would use skill_lookup. This code would still be wrong using skill_lookup.


Xrakisis said:
Yeah, spellpower is in char_data… it saves and reads from pfile.. theres an update for those who created before spellpower was in… the biggest problem is i dont know how to initialize it.. cant figure out how to check if the damage being done is a spell and if so to increase the spells damage…


1) Do you need a spellpower variable? From your original post, it seems like you just want to change how much damage is done by different classes. Do you need it to be more flexible than that, such that two Hoplites have different spellpowers, or can you replace this whole mess with a check for the character's class and not need to track it on a per character basis?

2) Variables are initialized in the new_char function in recycle.c. The best way to find something like this is to take something that you know happens - for example, you know all characters start with 20 hit points. You would then, in your Linux shell, type "grep max_hit *.c". This means "show me every line from any of my .c files that has "max_hit" in it. You would then see in recycle.c on line 300 the command initializing hit points and could put any similar variables (such as spellpower) into the same function.

3) Then look at how damage is done (in the damage function in fight.c) and how spells hurt people (by looking at the spell functions in magic.c). You'd notice that one of the arguments for the damage function is a dam_type which, we presume, may tell us what type of damage is being done. If we then look at how spells call that function, we can see, for example with burning hands, that it uses DAM_FIRE. Cause wound spells use DAM_HARM and so on. What are all of the possible values here? Values that will never change are usually in header files, so opening merc.h and searching for DAM_FIRE we find a list of damage classes; we also see that everything after (with a higher value than) DAM_SLASH looks like it would be spell damage. Therefore, in your damage function in fight.c, you can simply say "if our damage class comes after slash on the list, it's magic and I'm gonna change it according to the character's spellpower":
if (dam_type>DAM_SLASH)
{
dam+=your calculation for how spellpower works;
}
14 Oct, 2010, Bobo the bee wrote in the 7th comment:
Votes: 0
ATT_Turan said:
3) Then look at how damage is done (in the damage function in fight.c) and how spells hurt people (by looking at the spell functions in magic.c). You'd notice that one of the arguments for the damage function is a dam_type which, we presume, may tell us what type of damage is being done. If we then look at how spells call that function, we can see, for example with burning hands, that it uses DAM_FIRE. Cause wound spells use DAM_HARM and so on. What are all of the possible values here? Values that will never change are usually in header files, so opening merc.h and searching for DAM_FIRE we find a list of damage classes; we also see that everything after (with a higher value than) DAM_SLASH looks like it would be spell damage. Therefore, in your damage function in fight.c, you can simply say "if our damage class comes after slash on the list, it's magic and I'm gonna change it according to the character's spellpower":
if (dam_type>DAM_SLASH)
{
dam+=your calculation for how spellpower works;
}


The problem with this is that there might be non-magical DAM_FIRE and might be magical DAM_SLASH (nothing says there can't be!). What I'd do is either modify damage passed into the damage function – before damage reduction due to AC is calculated, or add an isspell boolean to the dam funct, or even better do what I know Dawn of Time does in creating a seperate function for spell_damage(), where you could tweak how damage is ultimately calculated for spells only.
14 Oct, 2010, ATT_Turan wrote in the 8th comment:
Votes: 0
Bobo the bee said:
The problem with this is that there might be non-magical DAM_FIRE and might be magical DAM_SLASH (nothing says there can't be!). What I'd do is either modify damage passed into the damage function – before damage reduction due to AC is calculated, or add an isspell boolean to the dam funct, or even better do what I know Dawn of Time does in creating a seperate function for spell_damage(), where you could tweak how damage is ultimately calculated for spells only.


Depends on what you mean by "might" - yes, those values could be used that way, but in his code they are not. If I were doing something like this I would put it into the spell functions (whether they each have their own calculation or an external spell_damage) - however, for the purposes of this thread, I think it is most helpful to give the simplest solutions. If it were easy for Xrakisis to make a new function to calculate spell damage and insert it into all of his spells, he would not have had problems adding in his spellpower using the approach he currently is.
14 Oct, 2010, Bobo the bee wrote in the 9th comment:
Votes: 0
ATT_Turan said:
Depends on what you mean by "might" - yes, those values could be used that way, but in his code they are not. If I were doing something like this I would put it into the spell functions (whether they each have their own calculation or an external spell_damage) - however, for the purposes of this thread, I think it is most helpful to give the simplest solutions. If it were easy for Xrakisis to make a new function to calculate spell damage and insert it into all of his spells, he would not have had problems adding in his spellpower using the approach he currently is.


Fair enough.
28 Oct, 2010, Rarva.Riendf wrote in the 10th comment:
Votes: 0
You could add a boolean in the damage method telling if it is magical dam or not.
It also helps to see if you can dodge it or not (usually you cannot dodge magical damage)
28 Oct, 2010, jurdendurden wrote in the 11th comment:
Votes: 0
Rarva.Riendf said:
You could add a boolean in the damage method telling if it is magical dam or not.
It also helps to see if you can dodge it or not (usually you cannot dodge magical damage)


That's exactly how I do it, sending the boolean to the damage function. If TRUE, it calls an external function to check the player's spell_damage based on intelligence, level, class, equipment, and race. If FALSE, it's a non-magical hit and the normal rules apply.
28 Oct, 2010, ATT_Turan wrote in the 12th comment:
Votes: 0
Rarva.Riendf said:
You could add a boolean in the damage method telling if it is magical dam or not.
It also helps to see if you can dodge it or not (usually you cannot dodge magical damage)


Note that the original poster is working with a ROM codebase, which means this is already taken care of (possibility to dodge is handled inside of one_hit, and spells bypass that function going directly to damage).

For the purpose of knowing the damage is magical, adding a boolean was suggested in post #4 :wink:
28 Oct, 2010, Runter wrote in the 13th comment:
Votes: 0
Well yes. In rom, once damage is called mitigation (including dodge) should likely already have been calculated.
29 Oct, 2010, Rarva.Riendf wrote in the 14th comment:
Votes: 0
ATT_Turan said:
Note that the original poster is working with a ROM codebase, which means this is already taken care of (possibility to dodge is handled inside of one_hit, and spells bypass that function going directly to damage).

For the purpose of knowing the damage is magical, adding a boolean was suggested in post #4 :wink:


Heh I work in a ROM base code as well, forgot to check how far it differs though. Dodge/parry/shield block etc is check in the damage method in my code.
0.0/14