-
References to classes
Hi everyone. I have a huge problem(for one such as I this is really a problem). In my game I have a lot of subclasses that are magics. Example:
Code:
class Enchantament{
//...
};
class Regeneration : Enchantament{
//...
};
class Storm : Enchantament{
//...
};
The creatures that has these magics only know a number, for example the magic regenaration has the number 2. But they need to cast this magic on another creature. The magic itself is the class that has a method that apply to the target creature.
So... the owner of the magic needs do instantiate a new object from the desired magic on the target creature.
My first thought was, somehow, out it all in an array, but that is impossible... Is that anyway that I can get a reference to a class and later create an object from it? Maybe rtti...
-
Does each creature have pointers to all kinds of magic?
Suppose each creature has a method that receives the magic number from the "magic owner", and maybe uses a switch block to call the appropriate magic constructor.
Then the magic owner can call that method of the target creature, sending it the magic number.
Would that work?
-
it kinda soudns like you should use structures instead... create a class with structures in it... give each character a copy of that class... and based on some user input (character type) just use some of the structures' members and the class' functions to pick them/pass them along...
-
Actually, the fact that creature "has" that class, means that ih is under the effect of that class... I made an interface that send all the correct event to all the registered classes from that creature, so the effect could be activated... my fault! Because this is very complicated to explain here, so Iīll try to change my question as best as I can... how can I construct a class whitout calling the constructor? for example, using pointers to functions...
Code:
class T{
T(){}
};
class W{
W(){}
};
//declares an array of functions
static void (*array[])()={ T::T , W:: W } // "assing" the pointers
This is s little impossible I think, but that is the idea...
Anyway, I think that this kind of thing itīs too "complex", maybe I should use a big case... Itīs not the most ellegant solution, but it works :)