proc
heal(mob/M,amount)
M.hp+=amount
//VS
mob/proc
heal(amount)
src.hp+=amount
Problem description: Which way is better. Which do you prefer and why?
I assume mob/proc is faster, but is duplicated as many times as many mobs there are in the world. Then if I had hundreds of mobs wouldn't it be waste of space (especially if the proc is a much much longer)?
The global proc method is way that I saw people recommended for a long time, but is it good to use for this particular and similar cases?
Okay, basically, any arguments about speed, memory use do not matter here, it makes no difference, they're basically equivalent. In fact, stop asking which is faster, or uses less memory, because it doesn't matter for your game, I guarantee it. Any slowness or memory issue will be elsewhere.
They are not equivalent though, in terms of what you can do with them. Pretty much, I'd argue the complete opposite of what you've seen recommended (and frown at whoever recommended it). Here's why:
Specialisation
Okay, in our game, we have four races, humans, elves, dwarfs and undead. At first, healing for them is all the same:
So using the global method:
Simple, but then we go "Ah, actually, I can do some cool things with healing, for my game." So we decide, humans just heal like before, elves get a bonus, dwarfs get reduced healing, and for the undead, healing actually hurts them!
Alright ... not sooo bad, but if we keep adding special effects, and races, that's going to be a very long, and painful to read/debug kind of procedure.
However, by defining it on the mob, we can take advantage of inheritance, and specialising the procedure. So initially, we just have:
Pretty straight-forward, all sub-types get the procedure too, due to inheritance. Now to specialise:
Suddenly you see, each individual procedure only talks about the mob it's interested in. This method is of course extendable up to as many types as you like without getting any longer in terms of an individual procedure. Similarly, you only have to worry about that specific type's special code, not whether or not you accidentally trigger something you're not meant to.
If healing of say .. the undead, is bugged, you just go to the undead definition, and debug that, where it's very plain and straight-forward to read.