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

Method think

src/Battlescape/ProjectileFlyBState.cpp:405–583  ·  view source on GitHub ↗

* Animates the projectile (moves to the next point in its trajectory). * If the animation is finished the projectile sprite is removed from the map, * and this state is finished. */

Source from the content-addressed store, hash-verified

403 * and this state is finished.
404 */
405void ProjectileFlyBState::think()
406{
407 _parent->getSave()->getBattleState()->clearMouseScrollingState();
408 /* TODO refactoring : store the projectile in this state, instead of getting it from the map each time? */
409 if (_parent->getMap()->getProjectile() == 0)
410 {
411 Tile *t = _parent->getSave()->getTile(_action.actor->getPosition());
412 Tile *bt = _parent->getSave()->getTile(_action.actor->getPosition() + Position(0,0,-1));
413 bool hasFloor = t && !t->hasNoFloor(bt);
414 bool unitCanFly = _action.actor->getArmor()->getMovementType() == MT_FLY;
415
416 if (_action.type == BA_AUTOSHOT
417 && _action.autoShotCounter < _action.weapon->getRules()->getAutoShots()
418 && !_action.actor->isOut()
419 && _ammo->getAmmoQuantity() != 0
420 && (hasFloor || unitCanFly))
421 {
422 createNewProjectile();
423 if (_action.cameraPosition.z != -1)
424 {
425 _parent->getMap()->getCamera()->setMapOffset(_action.cameraPosition);
426 _parent->getMap()->invalidate();
427 }
428 }
429 else
430 {
431 if (_action.cameraPosition.z != -1)
432 {
433 _parent->getMap()->getCamera()->setMapOffset(_action.cameraPosition);
434 _parent->getMap()->invalidate();
435 }
436 if (_action.type != BA_PANIC && _action.type != BA_MINDCONTROL && !_parent->getSave()->getUnitsFalling())
437 {
438 _parent->getTileEngine()->checkReactionFire(_unit);
439 }
440 if (!_unit->isOut())
441 {
442 _unit->abortTurn();
443 }
444 if (_parent->getSave()->getSide() == FACTION_PLAYER || _parent->getSave()->getDebugMode())
445 {
446 _parent->setupCursor();
447 }
448 _parent->popState();
449 }
450 }
451 else
452 {
453 if (_action.type != BA_THROW && _ammo && _ammo->getRules()->getShotgunPellets() != 0)
454 {
455 // shotgun pellets move to their terminal location instantly as fast as possible
456 _parent->getMap()->getProjectile()->skipTrajectory();
457 }
458 if(!_parent->getMap()->getProjectile()->move())
459 {
460 // impact !
461 if (_action.type == BA_THROW)
462 {

Callers

nothing calls this directly

Calls 15

getBattleStateMethod · 0.80
getSaveMethod · 0.80
getProjectileMethod · 0.80
hasNoFloorMethod · 0.80
getMovementTypeMethod · 0.80
getAutoShotsMethod · 0.80
isOutMethod · 0.80
getAmmoQuantityMethod · 0.80
setMapOffsetMethod · 0.80
getCameraMethod · 0.80
invalidateMethod · 0.80

Tested by

no test coverage detected