Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix floating vehicles when Parking AI disabled #993

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions TLM/TLM/Manager/Impl/AdvancedParkingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,50 @@ public bool FindParkingSpaceBuilding(VehicleInfo vehicleInfo,
out parkOffset) != 0;
}

public bool VanillaFindParkingSpaceWithoutRestrictions(bool isElectric,
ushort homeId,
Vector3 refPos,
Vector3 searchDir,
ushort segment,
float width,
float length,
out Vector3 parkPos,
out Quaternion parkRot,
out float parkOffset) {
if (!CustomPassengerCarAI.FindParkingSpace(isElectric,
homeId,
refPos,
searchDir,
segment,
width,
length,
out parkPos,
out parkRot,
out parkOffset)) {
return false;
}

// in vanilla parkOffset is always >= 0 for RoadSideParkingSpace
krzychu124 marked this conversation as resolved.
Show resolved Hide resolved
if (Options.parkingRestrictionsEnabled && parkOffset >= 0) {
if (Singleton<NetManager>.instance.m_segments.m_buffer[segment].GetClosestLanePosition(
refPos,
NetInfo.LaneType.Parking,
VehicleInfo.VehicleType.Car,
out _,
out _,
out int laneIndex,
out _)) {
NetInfo.Direction direction
= Singleton<NetManager>.instance.m_segments.m_buffer[segment].Info.m_lanes[laneIndex].m_finalDirection;
if (!ParkingRestrictionsManager.Instance.IsParkingAllowed(segment, direction)) {
return false;
}
}
}

return true;
}

public bool GetBuildingInfoViewColor(ushort buildingId,
ref Building buildingData,
ref ExtBuilding extBuilding,
Expand Down
14 changes: 7 additions & 7 deletions TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ bool citizenDebug
}

if (!searchedParkingSpace) {
bool isElectric = vehicleInfo.m_class.m_subService != ItemClass.SubService.ResidentialLow;
foundParkingSpace =
Constants.ManagerFactory.AdvancedParkingManager.FindParkingSpaceInVicinity(
Constants.ManagerFactory.AdvancedParkingManager.VanillaFindParkingSpaceWithoutRestrictions(
isElectric,
homeID,
refPos,
searchDir,
vehicleInfo,
homeID,
vehicleID,
GlobalConfig.Instance.ParkingAI.MaxBuildingToPedestrianLaneDistance,
out ExtParkingSpaceLocation parkLoc,
out ushort parkId,
pathPos.m_segment,
vehicleInfo.m_generatedInfo.m_size.x,
vehicleInfo.m_generatedInfo.m_size.z,
out parkPos,
out parkRot,
out parkOffset);
Expand Down
25 changes: 25 additions & 0 deletions TLM/TMPE.API/Manager/IAdvancedParkingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,30 @@ bool FindParkingSpacePropAtBuilding(VehicleInfo vehicleInfo,
out Vector3 parkPos,
out Quaternion parkRot,
out float parkOffset);

/// <summary>
/// Tries to find parking space using vanilla code, preserving parking restrictions
/// </summary>
/// <param name="isElectric">Is electric vehicle</param>
/// <param name="homeId">Home building id of the citizen (citizens are not allowed to park their car on foreign residential premises)</param>
/// <param name="refPos">Target position that is used as a center point for the search procedure</param>
/// <param name="searchDir">Search direction</param>
/// <param name="segment">If != 0, the building is forced to be "accessible" from this segment (where accessible means "close enough")</param>
/// <param name="width">Vehicle width</param>
/// <param name="length">Vehicle length</param>
/// <param name="parkPos">Identified parking space position (only valid if method returns true)</param>
/// <param name="parkRot">Identified parking space rotation (only valid if method returns true)</param>
/// <param name="parkOffset">Identified parking space offset (only valid if method returns true and a segment id was given)</param>
/// <returns></returns>
bool VanillaFindParkingSpaceWithoutRestrictions(bool isElectric,
ushort homeId,
Vector3 refPos,
Vector3 searchDir,
ushort segment,
float width,
float length,
out Vector3 parkPos,
out Quaternion parkRot,
out float parkOffset);
}
}