I have made 2 changes to your code:
- also if the attack on player comes from a neutral (not only from enemy), it will work... this is not possible yet, but will be once we merge changes from vanilla
- healing enemies should work as it worked before... I think your change allowed only healing enemies hurt by enemies, not by player
Please review, I'm quite confused from all the ands, ors and nots right now:
https://github.com/MeridianOXC/OpenXcom/commit/b2713dc6c5b789ae2dae0b99461863a6a0a4c3a2
The diff you posted looks totally wrong... but it isn't. It's just that you've put the changes in two separate commits, and so it all looks a bit different.
I'm pretty sure my code still worked fine for healing enemies. The conditions we are adding are to check whether or not we should abort the function; not continue to add experience. So the added conditions wouldn't have changed the fact that healing enemies worked in the first place.
I don't think we need to check the original faction of the target; because the wound still needs to be caused by our enemy. I kind of like the idea of gaining bravery for healing neutrals who were wounded by the enemy. So I'd probably skip the original faction check for that reason, and for simplicity.
I can't see any problems with your code. And I commend you moving the weapon condition to the top. Good call on that.
But since you've moved things around a bit, I'll suggest a few more minor tweaks changes for readability. The main thing is that the 'else' block after checking that there's a target doesn't need to be a block at all. Because if there's no target, we abort immediately.
Here's what I suggest for now:
if (!weapon) return false;
if (!target) return false;
https:// only give experience for actions performed on enemies...
https:// ... unless the action is to heal a fatal wound which was inflicted by an enemy (or neutral)
if (weapon->getRules()->getBattleType() == BT_MEDIKIT && target->killedBy() != FACTION_PLAYER)
{
https:// continue as normal
}
else
{
https:// only enemies count, not friends or neutrals
if (target->getOriginalFaction() != FACTION_HOSTILE) return false;
https:// mind-controlled enemies don't count though!
if (target->getFaction() != FACTION_HOSTILE) return false;
}
I usually wouldn't use an empty if block like that; but I've left if that way because it does kind of make the conditions easier to follow, somehow.
It would probably be nice to have some consistency in how the `if() return` things are done. In the current version of the code, there are three versions...
if (condition) return false;
if (condition)
{
return false;
}
if (condition)
return false;
If it were up to me, I'd use the final one all the time. But I'm pretty sure I've read that the style guidelines for this project say not to use that one ever! (All `if`s are meant to have braces.)
So I've changed it to use the shortest one, just to keep it... short. Its probably good to be able to see all the ways the code can return early without having to scroll.
In any case, your current code looks fine to me. I'm just tinkering at the edges now.