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

Method think

src/Battlescape/UnitWalkBState.cpp:84–457  ·  view source on GitHub ↗

* Runs state functionality every cycle. */

Source from the content-addressed store, hash-verified

82 * Runs state functionality every cycle.
83 */
84void UnitWalkBState::think()
85{
86 bool unitSpotted = false;
87 bool onScreen = (_unit->getVisible() && _parent->getMap()->getCamera()->isOnScreen(_unit->getPosition(), true));
88 if (_unit->isKneeled())
89 {
90 if (_parent->kneel(_unit))
91 {
92 _unit->setCache(0);
93 _terrain->calculateFOV(_unit);
94 _parent->getMap()->cacheUnit(_unit);
95 return;
96 }
97 else
98 {
99 _action.result = "STR_NOT_ENOUGH_TIME_UNITS";
100 _pf->abortPath();
101 _parent->popState();
102 return;
103 }
104 }
105 Tile *tileBelow = _parent->getSave()->getTile(_unit->getPosition() + Position(0,0,-1));
106
107 if (_unit->isOut())
108 {
109 _pf->abortPath();
110 _parent->popState();
111 return;
112 }
113
114 if (_unit->getStatus() == STATUS_WALKING || _unit->getStatus() == STATUS_FLYING)
115 {
116 if ((_parent->getSave()->getTile(_unit->getDestination())->getUnit() == 0) || // next tile must be not occupied
117 (_parent->getSave()->getTile(_unit->getDestination())->getUnit() == _unit))
118 {
119 playMovementSound();
120 _unit->keepWalking(tileBelow, onScreen); // advances the phase
121 }
122 else if (!_falling)
123 {
124 _unit->lookAt(_unit->getDestination(), (_unit->getTurretType() != -1)); // turn to undiscovered unit
125 _pf->abortPath();
126 }
127
128 // unit moved from one tile to the other, update the tiles
129 if (_unit->getPosition() != _unit->getLastPosition())
130 {
131 int size = _unit->getArmor()->getSize() - 1;
132 bool largeCheck = true;
133 for (int x = size; x >= 0; x--)
134 {
135 for (int y = size; y >= 0; y--)
136 {
137 Tile *otherTileBelow = _parent->getSave()->getTile(_unit->getPosition() + Position(x,y,-1));
138 if (!_parent->getSave()->getTile(_unit->getPosition() + Position(x,y,0))->hasNoFloor(otherTileBelow) || _unit->getArmor()->getMovementType() == MT_FLY)
139 largeCheck = false;
140 _parent->getSave()->getTile(_unit->getLastPosition() + Position(x,y,0))->setUnit(0);
141 }

Callers

nothing calls this directly

Calls 15

isOnScreenMethod · 0.80
getCameraMethod · 0.80
isKneeledMethod · 0.80
setCacheMethod · 0.80
calculateFOVMethod · 0.80
cacheUnitMethod · 0.80
abortPathMethod · 0.80
getSaveMethod · 0.80
isOutMethod · 0.80
getDestinationMethod · 0.80
keepWalkingMethod · 0.80
lookAtMethod · 0.80

Tested by

no test coverage detected