MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / updateWaterMotion

Method updateWaterMotion

src/OpenLoco/src/Vehicles/VehicleHead.cpp:2834–3014  ·  view source on GitHub ↗

0x00427C05 Input flags: bit 0 : commandedToStop bit 1 : isLeavingDock Output flags: bit 16 : reachedDock bit 17 : reachedADestination

Source from the content-addressed store, hash-verified

2832 // bit 16 : reachedDock
2833 // bit 17 : reachedADestination
2834 WaterMotionFlags VehicleHead::updateWaterMotion(WaterMotionFlags flags)
2835 {
2836 Vehicle train(*this);
2837 Vehicle2* veh2 = train.veh2;
2838
2839 // updates the current boats position and sets flags about position
2840 auto tile = TileManager::get(veh2->position);
2841
2842 SurfaceElement* surface = tile.surface();
2843
2844 if (surface != nullptr)
2845 {
2846 auto waterHeight = surface->water();
2847 if (waterHeight != 0)
2848 {
2849 if (surface->isIndustrial())
2850 {
2851 surface->setIsIndustrialFlag(false);
2852 surface->setGrowthStage(0);
2853 }
2854 surface->setIndustry(IndustryId(0));
2855 surface->setType6Flag(true);
2856 }
2857 }
2858
2859 auto targetSpeed = 5_mph;
2860 if (stationId == StationId::null)
2861 {
2862 if ((flags & WaterMotionFlags::isStopping) == WaterMotionFlags::none)
2863 {
2864 if (!veh2->has73Flags(Flags73::isBrokenDown))
2865 {
2866 targetSpeed = veh2->maxSpeed;
2867 }
2868 }
2869 }
2870
2871 if (targetSpeed == veh2->currentSpeed)
2872 {
2873 veh2->motorState = MotorState::coasting;
2874 }
2875 else if (targetSpeed < veh2->currentSpeed)
2876 {
2877 veh2->motorState = MotorState::coasting;
2878 auto decelerationRate = 1.0_mph;
2879 if (veh2->currentSpeed >= 50.0_mph)
2880 {
2881 decelerationRate = 3.0_mph;
2882 }
2883 veh2->motorState = MotorState::braking;
2884 auto newSpeed = std::max(veh2->currentSpeed - decelerationRate, 0.0_mph);
2885 veh2->currentSpeed = std::max<Speed32>(targetSpeed, newSpeed);
2886 }
2887 else
2888 {
2889 veh2->motorState = MotorState::accelerating;
2890 veh2->currentSpeed = std::min<Speed32>(targetSpeed, veh2->currentSpeed + 0.333333_mph);
2891 }

Callers

nothing calls this directly

Calls 15

IndustryIdEnum · 0.85
manhattanDistance2DFunction · 0.85
enumValueFunction · 0.85
waterPathfindFunction · 0.85
calculateYaw4FromVectorFunction · 0.85
calculateNextPositionFunction · 0.85
surfaceMethod · 0.80
waterMethod · 0.80
isIndustrialMethod · 0.80
setIsIndustrialFlagMethod · 0.80
setGrowthStageMethod · 0.80

Tested by

no test coverage detected