* Attempts to perform a reaction snap shot. * @param unit The unit to check sight from. * @param target The unit to check sight TO. * @return True if the action should (theoretically) succeed. */
| 935 | * @return True if the action should (theoretically) succeed. |
| 936 | */ |
| 937 | bool TileEngine::tryReactionSnap(BattleUnit *unit, BattleUnit *target) |
| 938 | { |
| 939 | BattleAction action; |
| 940 | action.cameraPosition = _save->getBattleState()->getMap()->getCamera()->getMapOffset(); |
| 941 | action.actor = unit; |
| 942 | action.weapon = unit->getMainHandWeapon(); |
| 943 | if (!action.weapon) |
| 944 | { |
| 945 | return false; |
| 946 | } |
| 947 | // reaction fire is ALWAYS snap shot. |
| 948 | action.type = BA_SNAPSHOT; |
| 949 | // unless we're a melee unit. |
| 950 | if (action.weapon->getRules()->getBattleType() == BT_MELEE) |
| 951 | { |
| 952 | action.type = BA_HIT; |
| 953 | } |
| 954 | action.target = target->getPosition(); |
| 955 | action.TU = unit->getActionTUs(action.type, action.weapon); |
| 956 | |
| 957 | if (action.weapon->getAmmoItem() && action.weapon->getAmmoItem()->getAmmoQuantity() && unit->getTimeUnits() >= action.TU) |
| 958 | { |
| 959 | action.targeting = true; |
| 960 | |
| 961 | // hostile units will go into an "aggro" state when they react. |
| 962 | if (unit->getFaction() == FACTION_HOSTILE) |
| 963 | { |
| 964 | AlienBAIState *aggro = dynamic_cast<AlienBAIState*>(unit->getCurrentAIState()); |
| 965 | if (aggro == 0) |
| 966 | { |
| 967 | // should not happen, but just in case... |
| 968 | aggro = new AlienBAIState(_save, unit, 0); |
| 969 | unit->setAIState(aggro); |
| 970 | } |
| 971 | |
| 972 | if (action.weapon->getAmmoItem()->getRules()->getExplosionRadius() && |
| 973 | aggro->explosiveEfficacy(action.target, unit, action.weapon->getAmmoItem()->getRules()->getExplosionRadius(), -1) == false) |
| 974 | { |
| 975 | action.targeting = false; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | if (action.targeting && unit->spendTimeUnits(action.TU)) |
| 980 | { |
| 981 | action.TU = 0; |
| 982 | _save->getBattleGame()->statePushBack(new UnitTurnBState(_save->getBattleGame(), action)); |
| 983 | _save->getBattleGame()->statePushBack(new ProjectileFlyBState(_save->getBattleGame(), action)); |
| 984 | return true; |
| 985 | } |
| 986 | } |
| 987 | return false; |
| 988 | } |
| 989 | |
| 990 | /** |
| 991 | * Handles bullet/weapon hits. |
nothing calls this directly
no test coverage detected