* Checks if a sniper from the opposing faction sees this unit. The unit with the highest reaction score will be compared with the current unit's reaction score. * If it's higher, a shot is fired when enough time units, a weapon and ammo are available. * @param unit The unit to check reaction fire upon. * @return True if reaction fire took place. */
| 773 | * @return True if reaction fire took place. |
| 774 | */ |
| 775 | bool TileEngine::checkReactionFire(BattleUnit *unit) |
| 776 | { |
| 777 | // reaction fire only triggered when the actioning unit is of the currently playing side, and is still on the map (alive) |
| 778 | if (unit->getFaction() != _save->getSide() || unit->getTile() == 0) |
| 779 | { |
| 780 | return false; |
| 781 | } |
| 782 | |
| 783 | std::vector<BattleUnit *> spotters = getSpottingUnits(unit); |
| 784 | bool result = false; |
| 785 | |
| 786 | // not mind controlled, or controlled by the player |
| 787 | if (unit->getFaction() == unit->getOriginalFaction() |
| 788 | || unit->getFaction() != FACTION_HOSTILE) |
| 789 | { |
| 790 | // get the first man up to bat. |
| 791 | BattleUnit *reactor = getReactor(spotters, unit); |
| 792 | // start iterating through the possible reactors until the current unit is the one with the highest score. |
| 793 | while (reactor != unit) |
| 794 | { |
| 795 | if (!tryReactionSnap(reactor, unit)) |
| 796 | { |
| 797 | // can't make a reaction snapshot for whatever reason, boot this guy from the vector. |
| 798 | for (std::vector<BattleUnit *>::iterator i = spotters.begin(); i != spotters.end(); ++i) |
| 799 | { |
| 800 | if (*i == reactor) |
| 801 | { |
| 802 | spotters.erase(i); |
| 803 | break; |
| 804 | } |
| 805 | } |
| 806 | // avoid setting result to true, but carry on, just cause one unit can't react doesn't mean the rest of the units in the vector (if any) can't |
| 807 | reactor = getReactor(spotters, unit); |
| 808 | continue; |
| 809 | } |
| 810 | // nice shot, kid. don't get cocky. |
| 811 | reactor = getReactor(spotters, unit); |
| 812 | result = true; |
| 813 | } |
| 814 | } |
| 815 | return result; |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Creates a vector of units that can spot this unit. |
no test coverage detected