lundi 17 juillet 2017

Reseting value of variable just for specific condition and fixed value for everything else

I'm making an update for a game.
In the game, there are units with different number of weapons. Like as: Baneblade Super Heavy Tank with (Baneblade Cannoon, Demolisher Cannon and Heavy Bolter).
And some weapons have special weapon traits and others don't. Weapons with zero traits are shown as "" (not null, only space).
In my example, Baneblade Cannon is "", Demolisher Cannon is "Siege", Heavy Bolter is "".
What I want to do is: If a weapon have "Siege" trait, enemy cover will be ignored and it will be "0".
I can do it as:

        int nDefCover = g_arrTerrainTypes[m_arrUnitEx[nDef].nTerrain].nCover; // to reset nCover
        if (m_arrUnitEx[nAtt].unit.pType->arrWeapons[w]->strTraits.Find("Siege") != std::string::npos) // I check if a number w weapon has "Siege" string
        {
            g_arrTerrainTypes[m_arrUnitEx[nDef].nTerrain].nCover = 0; // nCover gives the value of enemy's cover.
        }

        ... // some other weapon trait codes

        if (m_arrUnitEx[nAtt].unit.pType->arrWeapons[w]->strTraits.Find("") != std::string::npos)
        {
            g_arrTerrainTypes[m_arrUnitEx[nDef].nTerrain].nCover = nDefCover;
        }

After this, I have to reset the nCover value or from now on, all weapons will ignore cover bonus for enemy. I want just Siege weapon to ignore cover.
So, I use "g_arrTerrainTypes[m_arrUnitEx[nDef].nTerrain].nCover = nDefCover;" to reset nCover to actual value for other weapons.

But system works like this:
It looks at first weapon. It's "", so it changes nCover to its original value.
It looks at second weapon and it is "Siege", so it changes nCover to 0.
It looks at third weapon and it is "", so it changes nCover to its original value.
In the end, nCover returns as its original value and Siege weapon traits means nothing. It is like 0 OR 0 OR 1 situation.
If a unit has a Siege weapon in its last weapon slot this code can work but weapons order changes with every unit.
How can I change nCover to 0 for Siege weapon but for every other situation, change to its original value without changing Siege weapon nCover.

Aucun commentaire:

Enregistrer un commentaire