Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help reduce amount of code required to manage


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 BaneTrapper   Members   -  Reputation: 1245

Like
0Likes
Like

Posted 22 February 2013 - 05:57 AM

Hello.

Currently i get codes like this:

"Scroll down if your not interested in code and its unneeded to know it"

void Buffs::Burn(HeroUnit& unit, Buff& objBuf, Battle& objBat)
{
    int amount = objBuf.amount - unit.battMA;
    if(amount < 1)
        amount = 1;

    //Check if damage kills unit
    if(unit.battHP - amount < 1)
    {
        //Kill unit
        unit.battHP = 0;
        unit.isAlive = false;
        unit.battRT = 0;
        objBat.ChatPushBackText(unit.name + " burned for " + std::to_string(amount) + " and died in process", sf::Color(255,150,150));
    }
    else
    {
        //Damage
        unit.battHP -= amount;
        objBat.ChatPushBackText(unit.name + " burned for " + std::to_string(amount), sf::Color(255,150,150));
    }
}
void Buffs::Burn(EnemyUnit& unit, Buff& objBuf, Battle& objBat)
{
    int amount = objBuf.amount - unit.battMA;
    if(amount < 1)
        amount = 1;

    //Check if damage kills unit
    if(unit.battHP - amount < 1)
    {
        //Kill unit
        unit.battHP = 0;
        unit.isAlive = false;
        unit.battRT = 0;
        objBat.ChatPushBackText(unit.name + " burned for " + std::to_string(amount) + " and died in process", sf::Color(255,150,150));
    }
    else
    {
        //Damage
        unit.battHP -= amount;
        objBat.ChatPushBackText(unit.name + " burned for " + std::to_string(amount), sf::Color(255,150,150));
    }
}

Exact code, but takes different unit parameter.

The different between units is sever, but they share same attributes used for/in battle.
I would use "inheritance" (structure units to inherit a "UnitBattleData" class).

But how to call a function when its parameters is "void Battle(UnitBattleData& good_unit, UnitBattleData& evil_unit);" and i have object of "HeroUnit good_unit" "EvilUnit evil_unit".


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9668

Like
1Likes
Like

Posted 22 February 2013 - 06:07 AM

If both HeroUnit and EvilUnit inherit from UnitBattleData then you can just use Battle(good_unit, evil_unit).

#3 BaneTrapper   Members   -  Reputation: 1245

Like
0Likes
Like

Posted 22 February 2013 - 07:11 AM

If both HeroUnit and EvilUnit inherit from UnitBattleData then you can just use Battle(good_unit, evil_unit).

I have encountered problems with the way you provided even before i made the post. But after a bit of checking i found that i have/had an error, thanks.


Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS