Jump to content

[IsHostileTo / IsFriendlyTo] Do they really need specific code?


Guest Toinan67

Recommended Posts

Hi,

From what I've seen in Unit.cpp, IsHostileTo and IsFriendlyTo have exactly the same code, except for returns (which is quite normal).

I've spent 10 min trying to understand why, maybe something more in one function, but nothing, exactly the same.

So my question is : is there any reason for writing 2 times the same "algorithm" ?

I suggest a very simple modification :

bool Unit::IsFriendlyTo(Unit const* unit) const
{
   return !IsHostileTo(unit);
}

Tell me if I missed something.

Link to comment
Share on other sites

Think of any faction, like Bloodsail Buccaneers:

If you are neutral with them (and haven't checked the 'at war' checkbox), both functions will return false.

I think IsFriendlyTo is supposed to determine if you are allowed to heal/buff a target. The client has its own checks for this, so you won't see perfect behavior (such as when you turn on cross-faction grouping, but can't heal each other).

Link to comment
Share on other sites

Ok, the key thing is :

If you are neutral with them (and haven't checked the 'at war' checkbox), both functions will return false.

I actually didn't think about that. In my mind the 2 functions were "complementary", like "if you're not hostile you're friendly", if one returns true the other returns false.

Thanks :)

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use