* Gets the unit with the highest reaction score from the spotter vector. * @param spotters The vector of spotting units. * @param unit The unit to check scores against. * @return The unit with the highest reactions. */
| 873 | * @return The unit with the highest reactions. |
| 874 | */ |
| 875 | BattleUnit* TileEngine::getReactor(std::vector<BattleUnit *> spotters, BattleUnit *unit) |
| 876 | { |
| 877 | int bestScore = -1; |
| 878 | BattleUnit *bu = 0; |
| 879 | for (std::vector<BattleUnit *>::iterator i = spotters.begin(); i != spotters.end(); ++i) |
| 880 | { |
| 881 | if (!(*i)->isOut() && |
| 882 | canMakeSnap(*i, unit) && |
| 883 | (*i)->getReactionScore() > bestScore) |
| 884 | { |
| 885 | bestScore = (*i)->getReactionScore(); |
| 886 | bu = *i; |
| 887 | } |
| 888 | } |
| 889 | if (unit->getReactionScore() <= bestScore) |
| 890 | { |
| 891 | if (bu->getOriginalFaction() == FACTION_PLAYER) |
| 892 | { |
| 893 | bu->addReactionExp(); |
| 894 | } |
| 895 | } |
| 896 | else |
| 897 | { |
| 898 | bu = unit; |
| 899 | } |
| 900 | return bu; |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * Checks the validity of a snap shot performed here. |
nothing calls this directly
no test coverage detected