should i consolidate my classes??

Started by
14 comments, last by graveyard filla 20 years, 2 months ago
quote:Original post by null_void
I know you weren''t asking me, but that''s what I would do. I''d make the function virtual so that ''special'' Entity types could override the attack method.


what do you mean by... well all of that?

FTA, my 2D futuristic action MMORPG
Advertisement
if i were to do that i would have to implement some sort of damage mod variable... maybe pass it by refernce or maybe ill just make it a member variable of the entity class

also... if i wanted to do a damage mod thing.... i would have to use a double to calculate the damage mod like damage*1.06 for 6% damage increase........... but a player health has to be a whole number (integer) so how do i have the final damage be an int but its calculated with a double? would i get warnings or errors or what? not only that, but wouldnt it round the .06 to 0 and give me no damage mod. just wonderin how i could do this. thanks
FTA, my 2D futuristic action MMORPG
quote:Original post by graveyard filla
if i were to do that i would have to implement some sort of damage mod variable... maybe pass it by refernce or maybe ill just make it a member variable of the entity class

also... if i wanted to do a damage mod thing.... i would have to use a double to calculate the damage mod like damage*1.06 for 6% damage increase........... but a player health has to be a whole number (integer) so how do i have the final damage be an int but its calculated with a double? would i get warnings or errors or what? not only that, but wouldnt it round the .06 to 0 and give me no damage mod. just wonderin how i could do this. thanks


You shouldn''t have to cast an int to float, it might be cast automatically. But I wouldn''t count on that behavior. You would have to cast the damage variable to float explicitly to avoid warnings/errors. When the result is assigned back to damage, it''ll be re-cast to int (or whatever type damage is) and the decimal portion will drop (0.06 will be 0, 1.06 will be 1, etc.).

So damage = (float)damage*1.06f would do what you ask.

--------------------------
{ Arena: Resurrection, my text-based RPG/Mortal Kombat-like game }
{ A Look Into The World Of Arena II, a collection of short stories about characters in Arena II }
--------------------------{ Arena: Resurrection, my text-based RPG/Mortal Kombat-like game }{ A Look Into The World Of Arena II, a collection of short stories about characters in Arena II }
quote:Original post by graveyard filla
quote:Original post by null_void
I know you weren't asking me, but that's what I would do. I'd make the function virtual so that 'special' Entity types could override the attack method.


what do you mean by... well all of that?



quote:Original post by null_void
I know you weren't asking me, but that's what I would do.


It seemed that you were specifically speaking to Creative, though I could be mistaken.

quote:Original post by null_void
I'd make the function virtual so that 'special' Entity types could override the attack method.


Virtual functions allow you to define a default behavior for a base class and all of its derived classes. In this case, the Entity class. Derived classes, though (say, a specific type of enemy, maybe a boss?), can override that function.

At runtime, the specific type of object that is being operated on will be determined. If that object has overridden the function, the class specific function will be executed. Otherwise, the default one in the base class will be run.

Note that there is some debate over whether virtual functions incur too much cost to be efficient. According to Scott Meyers, who has written various books on C++, (and this logic makes sense to me), resolving a virtual function takes about 3 more instructions than it takes to follow a regular function pointer. I know I couldn't do these things without virtual functions and have it cost less than 3 instructions.

[edited by - null_void on February 6, 2004 7:58:08 PM]

[edited by - null_void on February 6, 2004 8:02:05 PM]
quote:Original post by graveyard filla
also... if i wanted to do a damage mod thing.... i would have to use a double to calculate the damage mod like damage*1.06 for 6% damage increase........... but a player health has to be a whole number (integer) so how do i have the final damage be an int but its calculated with a double? would i get warnings or errors or what? not only that, but wouldnt it round the .06 to 0 and give me no damage mod. just wonderin how i could do this. thanks

int moddeddamage = damage * 106 / 100; 


No casting, or use of FP at all this way. Be sure to do the multiplication first or you''ll get horrible precision.
thanks zahl....... dont know WTF casting is anyway =p
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement