MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdatePosition

Method UpdatePosition

src/disaster_vehicle.cpp:183–214  ·  view source on GitHub ↗

* Update the position of the vehicle. * @param x The new X-coordinate. * @param y The new Y-coordinate. * @param z The new Z-coordinate. */

Source from the content-addressed store, hash-verified

181 * @param z The new Z-coordinate.
182 */
183void DisasterVehicle::UpdatePosition(int x, int y, int z)
184{
185 this->x_pos = x;
186 this->y_pos = y;
187 this->z_pos = z;
188 this->tile = TileVirtXY(x, y);
189
190 this->UpdateImage();
191 this->UpdatePositionAndViewport();
192
193 DisasterVehicle *u = this->Next();
194 if (u != nullptr) {
195 int safe_x = Clamp(x, 0, Map::MaxX() * TILE_SIZE);
196 int safe_y = Clamp(y - 1, 0, Map::MaxY() * TILE_SIZE);
197
198 u->x_pos = x;
199 u->y_pos = y - 1 - (std::max(z - GetSlopePixelZ(safe_x, safe_y), 0) >> 3);
200 safe_y = Clamp(u->y_pos, 0, Map::MaxY() * TILE_SIZE);
201 u->z_pos = GetSlopePixelZ(safe_x, safe_y);
202 u->direction = this->direction;
203
204 u->UpdateImage();
205 u->UpdatePositionAndViewport();
206
207 if ((u = u->Next()) != nullptr) {
208 u->x_pos = x;
209 u->y_pos = y;
210 u->z_pos = z + ROTOR_Z_OFFSET;
211 u->UpdatePositionAndViewport();
212 }
213 }
214}
215
216/**
217 * Zeppeliner handling, v->state states:

Callers 6

DisasterTick_ZeppelinerFunction · 0.45
DisasterTick_UfoFunction · 0.45
DisasterTick_AircraftFunction · 0.45
DisasterTick_Big_UfoFunction · 0.45
DisasterTick_SubmarineFunction · 0.45

Calls 6

UpdateImageMethod · 0.95
TileVirtXYFunction · 0.85
ClampFunction · 0.85
GetSlopePixelZFunction · 0.85
NextMethod · 0.45

Tested by

no test coverage detected