Game Development Community

Player Energy and Damage changes

by John "Mythic" Henry · in Torque Game Engine · 08/23/2005 (12:24 pm) · 4 replies

Just a short mod for Player Energy...
As I like to keeps things that go together working the same way,
I noticed a Glitch in my opinion:

Energy and Damage are not Calculated the Same way..
Energy is Added to to Recharge,
Damaged is Subtracted from to Repair...

This is just not the best way in my opinion.
As both are used in similar ways, both should be dealt with the same.

ShapeBase.cc (Original)
void ShapeBase::processTick(const Move* move)
{
   // Energy management
   if (mDamageState == Enabled && mDataBlock->inheritEnergyFromMount == false) {
      F32 store = mEnergy;
      mEnergy += mRechargeRate;
      if (mEnergy > mDataBlock->maxEnergy)
         mEnergy = mDataBlock->maxEnergy;
      else
         if (mEnergy < 0)
            mEnergy = 0;
      // Virtual setEnergyLevel is used here by some derived classes to
      // decide whether they really want to set the energy mask bit.
      if (mEnergy != store)
         setEnergyLevel(mEnergy);
   }
   // Repair management
   if (mDataBlock->isInvincible == false)
   {

<---- SNIP  --->
F32 ShapeBase::getEnergyLevel()
{
   if (mDataBlock->inheritEnergyFromMount == false)
      return mEnergy;
   else if (isMounted()) {
      return getObjectMount()->getEnergyLevel();
   } else {
      return 0.0f;
   }
}
F32 ShapeBase::getEnergyValue()
{
   if (mDataBlock->inheritEnergyFromMount == false) {
      F32 maxEnergy = mDataBlock->maxEnergy;
      if ( maxEnergy > 0.f )
         return (mEnergy / mDataBlock->maxEnergy);
   } else if (isMounted()) {
      F32 maxEnergy = getObjectMount()->mDataBlock->maxEnergy;
      if ( maxEnergy > 0.f )
         return (getObjectMount()->getEnergyLevel() / maxEnergy);
   }
   return 0.0f;
}

You'll notice from this that they send the SAME type of Value to the Client:
Energy/MaxEnergy

YET to recharge they ADD to that Value...

I think this could cause problems for new developers as they
might think Damage and Energy are dealt with in the exact same way.

Only if you spot the difference in the HealthBarHud would you notice
they deal with it:

(Energy Percent) mValue = getEnergyValue() (Value > 0.5 is good)
(Damage Percent) mValue = 1 - control->getDamageValue();(Value > 0.5 is bad)

The Modifcations I did are posted below...

#1
08/23/2005 (12:26 pm)
This is just cleaner...
Warning, to change these areas,
require slight changes to how you ACCESS Energy and Damage values...
Energy will now be dealt with like Damage:
Damage = 0.0 FULL Health
Damage = 1.0 DEAD
Energy = 0.0 FULL Energy
Energy = 1.0 NO Energy
One other Note here:
You'll notice I have Moved the MaxEnergy from the DataBlock to the Object..
You can use this with the DataBlock system by changing my access to mMaxEnergy
back to : mDataBlock->maxEnergy

Also this uses Mana values which have to be added in completely seperately.
Also I modified the Bar to allow me to Choose which of the 3 I want to display.

Modified: ShapeBase.cc

void ShapeBase::processTick(const Move* move)
{
	// Energy management
	if (mDamageState == Enabled ) 
	{
		F32 store = mEnergy;
		mEnergy -= mRechargeRate;
		mEnergy  = mClampF(mEnergy, 0.f, mMaxEnergy);
		// Virtual setEnergyLevel is used here by some derived classes to
		// decide whether they really want to set the Mana mask bit.
		if (mEnergy != store)       setEnergyLevel(mEnergy);

		// Mana management
		store = mMana;
		mMana -= mManaRate;
		mMana  = mClampF(mMana, 0.f, mMaxMana);
		// Virtual setManaLevel is used here by some derived classes to
		// decide whether they really want to set the Mana mask bit.
		if (mMana != store)       setManaLevel(mMana);
   }
   // Repair management
   if (mDataBlock->isInvincible == false)
   {
<-------------------------  SNIP  ------------------------->
F32 ShapeBase::getEnergyLevel()
{
               	F32 maxEnergy = mMaxEnergy;
	if( mDataBlock->inheritEnergyFromMount == true )  {
		if (isMounted()) {
			maxEnergy = (maxEnergy + getObjectMount()->mMaxEnergy) / 2;
			F32 tempEnergy = getObjectMount()->getEnergyLevel();
			tempEnergy = (mEnergy + tempEnergy)/2;
			tempEnergy = mClampF(tempEnergy, 0.f, maxEnergy);
			return tempEnergy;
		}
	}
	return mEnergy;
}
F32 ShapeBase::getEnergyValue()
{
   F32 maxEnergy = mMaxEnergy;
   if( maxEnergy <= 0.f )	   return 0.0f;
   if( mDataBlock->inheritEnergyFromMount == true )    {
		if( isMounted() )	{
			F32 tempEnergy = getObjectMount()->getEnergyLevel();
			tempEnergy = (mEnergy + tempEnergy)/2;
			tempEnergy = mClampF(tempEnergy, 0.f, maxEnergy);
			return ( tempEnergy / maxEnergy);
		}
   }
   return (mEnergy / mMaxEnergy);
}
#2
12/04/2007 (8:52 am)
You should probably remove your Mana code ;)
#3
12/04/2007 (9:13 am)
I would like to think that, almost 26 months later, he has ;)
#4
12/04/2007 (10:05 am)
Hehe... Didn't see the date :-P