MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / btnActionMenuItemClick

Method btnActionMenuItemClick

src/Battlescape/ActionMenuState.cpp:195–314  ·  view source on GitHub ↗

* Executes the action corresponding to this action menu item. * @param action Pointer to an action. */

Source from the content-addressed store, hash-verified

193 * @param action Pointer to an action.
194 */
195void ActionMenuState::btnActionMenuItemClick(Action *action)
196{
197 _game->getSavedGame()->getSavedBattle()->getPathfinding()->removePreview();
198
199 int btnID = -1;
200 RuleItem *weapon = _action->weapon->getRules();
201
202 // got to find out which button was pressed
203 for (size_t i = 0; i < sizeof(_actionMenu)/sizeof(_actionMenu[0]) && btnID == -1; ++i)
204 {
205 if (action->getSender() == _actionMenu[i])
206 {
207 btnID = i;
208 }
209 }
210
211 if (btnID != -1)
212 {
213 _action->type = _actionMenu[btnID]->getAction();
214 _action->TU = _actionMenu[btnID]->getTUs();
215 if (_action->type == BA_PRIME)
216 {
217 if (weapon->getBattleType() == BT_PROXIMITYGRENADE)
218 {
219 _action->value = 0;
220 _game->popState();
221 }
222 else
223 {
224 _game->pushState(new PrimeGrenadeState(_game, _action, false, 0));
225 }
226 }
227 else if (_action->type == BA_USE && weapon->getBattleType() == BT_MEDIKIT)
228 {
229 BattleUnit *targetUnit = NULL;
230 std::vector<BattleUnit*> *const units (_game->getSavedGame()->getSavedBattle()->getUnits());
231 for(std::vector<BattleUnit*>::const_iterator i = units->begin (); i != units->end () && !targetUnit; ++i)
232 {
233 // we can heal a unit that is at the same position, unconscious and healable(=woundable)
234 if ((*i)->getPosition() == _action->actor->getPosition() && *i != _action->actor && (*i)->getStatus () == STATUS_UNCONSCIOUS && (*i)->isWoundable())
235 {
236 targetUnit = *i;
237 }
238 }
239 if (!targetUnit)
240 {
241 if (_game->getSavedGame()->getSavedBattle()->getTileEngine()->validMeleeRange(
242 _action->actor->getPosition(),
243 _action->actor->getDirection(),
244 _action->actor,
245 0, &_action->target))
246 {
247 Tile * tile (_game->getSavedGame()->getSavedBattle()->getTile(_action->target));
248 if (tile != 0 && tile->getUnit() && tile->getUnit()->isWoundable())
249 {
250 targetUnit = tile->getUnit();
251 }
252 }

Callers

nothing calls this directly

Calls 15

removePreviewMethod · 0.80
getSavedBattleMethod · 0.80
getSavedGameMethod · 0.80
getSenderMethod · 0.80
getTUsMethod · 0.80
getBattleTypeMethod · 0.80
pushStateMethod · 0.80
isWoundableMethod · 0.80
validMeleeRangeMethod · 0.80
spendTimeUnitsMethod · 0.80
getTimeUnitsMethod · 0.80
getAmmoQuantityMethod · 0.80

Tested by

no test coverage detected