• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ [TFS 1.3] Doubt in a verification inside the function combatChangeHealth from game.cpp

Yan18

Member
Joined
Jun 14, 2014
Messages
104
Solutions
3
Reaction score
17
Hello there

I have a doubt in the following verification inside the function Game::combatChangeHealth from game.cpp:

C++:
if (damage.origin != ORIGIN_NONE)
        {
            const auto& events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE);
            if (!events.empty())
            {
                for (CreatureEvent* creatureEvent : events)
                {
                    creatureEvent->executeHealthChange(target, attacker, damage);
                }

                damage.origin = ORIGIN_NONE;

                return combatChangeHealth(attacker, target, damage, damage.primary.type);
            }
        }

Why is it returning the own function in the begin of the function in the case has events CREATURE_EVENT_HEALTHCHANGE in for loop?? I would like to understand what this happen.
 
The reason why the function is returning combatChangeHealth(attacker, target, damage, damage.primary.type) within the if statement is because it is assuming that the executeHealthChange function modified the target creature's health value, and therefore, it needs to call combatChangeHealth to update the combat system with the new health value.

In other words, if the events list is not empty, it means that there are some CreatureEvent objects that need to be executed when the target's health value changes. Therefore, the executeHealthChange function is called on each CreatureEvent object in the for loop, and it is assumed that this function will modify the target creature's health value (otherwise, there would be no point in executing the events).

Once the events have been executed, the code sets the origin of the damage to ORIGIN_NONE, indicating that the damage has been fully processed. Then, it calls combatChangeHealth with the updated parameters to update the combat system with the new health value of the target creature. The result of this function call is then returned as the result of the original function.

It is worth noting that the code is only returning combatChangeHealth if the events list is not empty. If the events list is empty, the code will not call combatChangeHealth and will simply continue executing the rest of the function.
 
The reason why the function is returning combatChangeHealth(attacker, target, damage, damage.primary.type) within the if statement is because it is assuming that the executeHealthChange function modified the target creature's health value, and therefore, it needs to call combatChangeHealth to update the combat system with the new health value.

In other words, if the events list is not empty, it means that there are some CreatureEvent objects that need to be executed when the target's health value changes. Therefore, the executeHealthChange function is called on each CreatureEvent object in the for loop, and it is assumed that this function will modify the target creature's health value (otherwise, there would be no point in executing the events).

Once the events have been executed, the code sets the origin of the damage to ORIGIN_NONE, indicating that the damage has been fully processed. Then, it calls combatChangeHealth with the updated parameters to update the combat system with the new health value of the target creature. The result of this function call is then returned as the result of the original function.

It is worth noting that the code is only returning combatChangeHealth if the events list is not empty. If the events list is empty, the code will not call combatChangeHealth and will simply continue executing the rest of the function.
Thanks!

I understand, but I have one more doubt. When the function is returned, it is returned as false or true?
 
Back
Top