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

Method isVehicleTypeCompatible

src/OpenLoco/src/Vehicles/VehicleHead.cpp:800–862  ·  view source on GitHub ↗

0x004B8FA2 esi : self ax : vehicleTypeId

Source from the content-addressed store, hash-verified

798 // esi : self
799 // ax : vehicleTypeId
800 bool VehicleHead::isVehicleTypeCompatible(const uint16_t vehicleTypeId) // TODO: const
801 {
802 auto newObject = ObjectManager::get<VehicleObject>(vehicleTypeId);
803 if (newObject->mode == TransportMode::air || newObject->mode == TransportMode::water)
804 {
805 Vehicle train(head);
806 if (!train.cars.empty())
807 {
808 GameCommands::setErrorText(StringIds::incompatible_vehicle);
809 return false;
810 }
811 }
812 else
813 {
814 if (newObject->trackType != trackType)
815 {
816 GameCommands::setErrorText(StringIds::incompatible_vehicle);
817 return false;
818 }
819 }
820
821 if (newObject->mode != mode)
822 {
823 GameCommands::setErrorText(StringIds::incompatible_vehicle);
824 return false;
825 }
826
827 if (newObject->type != vehicleType)
828 {
829 GameCommands::setErrorText(StringIds::incompatible_vehicle);
830 return false;
831 }
832
833 {
834 Vehicle train(head);
835 for (const auto& car : train.cars)
836 {
837 // The objectId is the same for all vehicle components and car components of a car
838 if (!canVehiclesCouple(vehicleTypeId, car.front->objectId))
839 {
840 return false;
841 }
842 }
843 }
844 if (mode != TransportMode::road)
845 {
846 return true;
847 }
848
849 if (trackType != 0xFF)
850 {
851 return true;
852 }
853
854 auto curTotalLength = getVehicleTotalLength();
855 auto additionalNewLength = ObjectManager::get<VehicleObject>(vehicleTypeId)->getLength();
856 if (curTotalLength + additionalNewLength > kMaxRoadVehicleLength)
857 {

Callers 3

addCarToVehicleFunction · 0.80
vehicleRearrangeFunction · 0.80

Calls 4

setErrorTextFunction · 0.85
canVehiclesCoupleFunction · 0.85
emptyMethod · 0.45
getLengthMethod · 0.45

Tested by

no test coverage detected