本文整理汇总了C#中Vehicle.CalculateTotalLength方法的典型用法代码示例。如果您正苦于以下问题:C# Vehicle.CalculateTotalLength方法的具体用法?C# Vehicle.CalculateTotalLength怎么用?C# Vehicle.CalculateTotalLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vehicle
的用法示例。
在下文中一共展示了Vehicle.CalculateTotalLength方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateSegmentPosition
protected override void CalculateSegmentPosition(ushort vehicleId, ref Vehicle vehicleData, PathUnit.Position nextPosition,
PathUnit.Position position, uint laneId, byte offset, PathUnit.Position prevPos, uint prevLaneId,
byte prevOffset, out Vector3 pos, out Vector3 dir, out float maxSpeed)
{
NetManager instance = Singleton<NetManager>.instance;
instance.m_lanes.m_buffer[(int)((UIntPtr)laneId)].CalculatePositionAndDirection(offset * 0.003921569f, out pos, out dir);
Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData();
Vector3 position2 = lastFrameData.m_position;
Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneId)].CalculatePosition(prevOffset * 0.003921569f);
float num = 0.5f * lastFrameData.m_velocity.sqrMagnitude / m_info.m_braking + m_info.m_generatedInfo.m_size.z * 0.5f;
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car)
{
if (!TrafficPriority.VehicleList.ContainsKey(vehicleId))
{
TrafficPriority.VehicleList.Add(vehicleId, new PriorityCar());
}
}
if (Vector3.Distance(position2, b) >= num - 1f)
{
Segment3 segment;
segment.a = pos;
ushort num2;
ushort num3;
if (offset < position.m_offset)
{
segment.b = pos + dir.normalized*m_info.m_generatedInfo.m_size.z;
num2 = instance.m_segments.m_buffer[position.m_segment].m_startNode;
num3 = instance.m_segments.m_buffer[position.m_segment].m_endNode;
}
else
{
segment.b = pos - dir.normalized*m_info.m_generatedInfo.m_size.z;
num2 = instance.m_segments.m_buffer[position.m_segment].m_endNode;
num3 = instance.m_segments.m_buffer[position.m_segment].m_startNode;
}
ushort num4;
if (prevOffset == 0)
{
num4 = instance.m_segments.m_buffer[prevPos.m_segment].m_startNode;
}
else
{
num4 = instance.m_segments.m_buffer[prevPos.m_segment].m_endNode;
}
if (num2 == num4)
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
uint num5 = (uint)((num4 << 8) / 32768);
uint num6 = currentFrameIndex - num5 & 255u;
NetNode.Flags flags = instance.m_nodes.m_buffer[num2].m_flags;
NetLane.Flags flags2 =
(NetLane.Flags) instance.m_lanes.m_buffer[(int) ((UIntPtr) prevLaneId)].m_flags;
bool flag = (flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None;
bool flag2 = (flags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None;
bool flag3 = (flags2 & NetLane.Flags.JoinedJunction) != NetLane.Flags.None;
if ((flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) ==
NetNode.Flags.Junction && instance.m_nodes.m_buffer[num2].CountSegments() != 2)
{
float len = vehicleData.CalculateTotalLength(vehicleId) + 2f;
if (!instance.m_lanes.m_buffer[(int) ((UIntPtr) laneId)].CheckSpace(len))
{
bool flag4 = false;
if (nextPosition.m_segment != 0 &&
instance.m_lanes.m_buffer[(int) ((UIntPtr) laneId)].m_length < 30f)
{
NetNode.Flags flags3 = instance.m_nodes.m_buffer[num3].m_flags;
if ((flags3 &
(NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) !=
NetNode.Flags.Junction || instance.m_nodes.m_buffer[num3].CountSegments() == 2)
{
uint laneId2 = PathManager.GetLaneID(nextPosition);
if (laneId2 != 0u)
{
flag4 = instance.m_lanes.m_buffer[(int) ((UIntPtr) laneId2)].CheckSpace(len);
}
}
}
if (!flag4)
{
maxSpeed = 0f;
return;
}
}
}
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car &&
TrafficPriority.VehicleList.ContainsKey(vehicleId) &&
TrafficPriority.IsPrioritySegment(num2, prevPos.m_segment))
{
uint currentFrameIndex2 = Singleton<SimulationManager>.instance.m_currentFrameIndex;
uint frame = currentFrameIndex2 >> 4;
var prioritySegment = TrafficPriority.GetPrioritySegment(num2, prevPos.m_segment);
if (TrafficPriority.VehicleList[vehicleId].toNode != num2 ||
TrafficPriority.VehicleList[vehicleId].fromSegment != prevPos.m_segment)
{
//.........这里部分代码省略.........
示例2: CustomCalculateSegmentPosition
public void CustomCalculateSegmentPosition(ushort vehicleId, ref Vehicle vehicleData, PathUnit.Position nextPosition,
PathUnit.Position position, uint laneID, byte offset, PathUnit.Position prevPos, uint prevLaneID,
byte prevOffset, int index, out Vector3 pos, out Vector3 dir, out float maxSpeed) {
var netManager = Singleton<NetManager>.instance;
//var vehicleManager = Singleton<VehicleManager>.instance;
netManager.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePositionAndDirection(offset * 0.003921569f, out pos, out dir);
bool isRecklessDriver = IsRecklessDriver(vehicleId, ref vehicleData);
var lastFrameData = vehicleData.GetLastFrameData();
var lastFrameVehiclePos = lastFrameData.m_position;
var camPos = Camera.main.transform.position;
bool simulatePrioritySigns = (lastFrameVehiclePos - camPos).sqrMagnitude < FarLod && !isRecklessDriver;
if (Options.simAccuracy <= 0) {
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car) {
VehiclePosition vehiclePos = TrafficPriority.GetVehiclePosition(vehicleId);
if (vehiclePos.Valid && simulatePrioritySigns) { // TODO check if this should be !vehiclePos.Valid
try {
CustomVehicleAI.HandleVehicle(vehicleId, ref Singleton<VehicleManager>.instance.m_vehicles.m_buffer[vehicleId], false, false);
} catch (Exception e) {
Log.Error("CarAI TmCalculateSegmentPosition Error: " + e.ToString());
}
}
} else {
//Log._Debug($"TmCalculateSegmentPosition does not handle vehicles of type {vehicleData.Info.m_vehicleType}");
}
}
// I think this is supposed to be the lane position?
// [VN, 12/23/2015] It's the 3D car position on the Bezier curve of the lane.
// This crazy 0.003921569f equals to 1f/255 and prevOffset is the byte value (0..255) of the car position.
var vehiclePosOnBezier = netManager.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].CalculatePosition(prevOffset * 0.003921569f);
//ushort currentSegmentId = netManager.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_segment;
ushort destinationNodeId;
ushort sourceNodeId;
if (offset < position.m_offset) {
destinationNodeId = netManager.m_segments.m_buffer[position.m_segment].m_startNode;
sourceNodeId = netManager.m_segments.m_buffer[position.m_segment].m_endNode;
} else {
destinationNodeId = netManager.m_segments.m_buffer[position.m_segment].m_endNode;
sourceNodeId = netManager.m_segments.m_buffer[position.m_segment].m_startNode;
}
var previousDestinationNode = prevOffset == 0 ? netManager.m_segments.m_buffer[prevPos.m_segment].m_startNode : netManager.m_segments.m_buffer[prevPos.m_segment].m_endNode;
// this seems to be like the required braking force in order to stop the vehicle within its half length.
var crazyValue = 0.5f * lastFrameData.m_velocity.sqrMagnitude / m_info.m_braking + m_info.m_generatedInfo.m_size.z * 0.5f;
// Essentially, this is true if the car has enough time and space to brake (e.g. for a red traffic light)
if (destinationNodeId == previousDestinationNode) {
if (Vector3.Distance(lastFrameVehiclePos, vehiclePosOnBezier) >= crazyValue - 1f) {
var currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
var num5 = (uint)((previousDestinationNode << 8) / 32768);
var num6 = currentFrameIndex - num5 & 255u;
var nodeFlags = netManager.m_nodes.m_buffer[destinationNodeId].m_flags;
var prevLaneFlags = (NetLane.Flags)netManager.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_flags;
var hasTrafficLight = (nodeFlags & NetNode.Flags.TrafficLights) != NetNode.Flags.None;
var hasCrossing = (nodeFlags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None;
var isJoinedJunction = (prevLaneFlags & NetLane.Flags.JoinedJunction) != NetLane.Flags.None;
bool checkSpace = !Flags.getEnterWhenBlockedAllowed(prevPos.m_segment, netManager.m_segments.m_buffer[prevPos.m_segment].m_startNode == destinationNodeId) && !isRecklessDriver;
//TrafficLightSimulation nodeSim = TrafficLightSimulation.GetNodeSimulation(destinationNodeId);
/*if (timedNode != null && timedNode.vehiclesMayEnterBlockedJunctions) {
checkSpace = false;
}*/
if (checkSpace) {
// check if there is enough space
if ((nodeFlags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) == NetNode.Flags.Junction &&
netManager.m_nodes.m_buffer[destinationNodeId].CountSegments() != 2) {
var len = vehicleData.CalculateTotalLength(vehicleId) + 2f;
if (!netManager.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CheckSpace(len)) {
var sufficientSpace = false;
if (nextPosition.m_segment != 0 &&
netManager.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_length < 30f) {
var flags3 = netManager.m_nodes.m_buffer[sourceNodeId].m_flags;
if ((flags3 &
(NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) !=
NetNode.Flags.Junction || netManager.m_nodes.m_buffer[sourceNodeId].CountSegments() == 2) {
var laneId2 = PathManager.GetLaneID(nextPosition);
if (laneId2 != 0u) {
sufficientSpace = netManager.m_lanes.m_buffer[(int)((UIntPtr)laneId2)].CheckSpace(len);
}
}
}
if (!sufficientSpace) {
maxSpeed = 0f;
return;
}
}
}
}
try {
VehiclePosition globalTargetPos = TrafficPriority.GetVehiclePosition(vehicleId);
if ((vehicleData.m_flags & Vehicle.Flags.Emergency2) == 0) {
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car) {
if (hasTrafficLight && (!isJoinedJunction || hasCrossing)) {
//.........这里部分代码省略.........
示例3: HandleVehicle
//.........这里部分代码省略.........
logBuffer.Add("* vehicleId " + vehicleId + ". Next path unit! node " + destNodeId + ", seg. " + nextRealTimePosition.m_segment + ", pathUnitId=" + pathUnitId + ", pathPos: " + pathPos);
#endif
realTimePositions.Add(nextRealTimePosition);
realTimeDestinationNodes.Add(destNodeId);
if (i >= maxUpcomingPathPositions - 1)
break; // we calculate up to 2 upcoming path units at the moment
++pathPos;
++i;
}
}
// please don't ask why we use "m_pathPositionIndex >> 1" (which equals to "m_pathPositionIndex / 2") here (Though it would
// be interesting to know why they used such an ugly indexing scheme!!). I assume the oddness of m_pathPositionIndex relates
// to the car's position on the segment. If it is even the car might be in the segment's first half and if it is odd, it might
// be in the segment's second half.
#if DEBUGV
logBuffer.Add("* vehicleId " + vehicleId + ". *INFO* rtPos.seg=" + realTimePositions[0].m_segment + " nrtPos.seg=" + (realTimePositions.Count > 1 ? ""+realTimePositions[1].m_segment : "n/a"));
#endif
}
}
// we have seen the car!
vehiclePos.LastFrame = Singleton<SimulationManager>.instance.m_currentFrameIndex;
#if DEBUGV
logBuffer.Add("* vehicleId " + vehicleId + ". ToNode: " + vehiclePos.ToNode + ". FromSegment: " + vehiclePos.FromSegment/* + ". FromLaneId: " + TrafficPriority.Vehicles[vehicleId].FromLaneId*/);
#endif
if (addTraffic && vehicleData.m_leadingVehicle == 0 && realTimePositions.Count > 0) {
// add traffic to lane
uint laneId = PathManager.GetLaneID(realTimePositions[0]);
CustomRoadAI.AddTraffic(laneId, (ushort)Mathf.RoundToInt(vehicleData.CalculateTotalLength(vehicleId)), (ushort)Mathf.RoundToInt(lastFrameData.m_velocity.magnitude), realTraffic);
}
#if DEBUGV
logBuffer.Add("* vehicleId " + vehicleId + ". Real time positions: " + realTimePositions.Count + ", Destination nodes: " + realTimeDestinationNodes.Count);
#endif
if (realTimePositions.Count >= 1) {
// we found a valid path unit
var sourceLaneIndex = realTimePositions[0].m_lane;
if (
!vehiclePos.Valid ||
vehiclePos.ToNode != realTimeDestinationNodes[0] ||
vehiclePos.FromSegment != realTimePositions[0].m_segment ||
vehiclePos.FromLaneIndex != sourceLaneIndex) {
// vehicle information is not up-to-date. remove the car from old priority segments (if existing)...
TrafficPriority.RemoveVehicleFromSegments(vehicleId);
if (realTimePositions.Count >= 2) {
// save vehicle information for priority rule handling
vehiclePos.Valid = true;
vehiclePos.CarState = VehicleJunctionTransitState.None;
vehiclePos.WaitTime = 0;
vehiclePos.Stopped = false;
vehiclePos.ToNode = realTimeDestinationNodes[0];
vehiclePos.FromSegment = realTimePositions[0].m_segment;
vehiclePos.FromLaneIndex = realTimePositions[0].m_lane;
vehiclePos.ToSegment = realTimePositions[1].m_segment;
vehiclePos.ToLaneIndex = realTimePositions[1].m_lane;
vehiclePos.ReduceSpeedByValueToYield = UnityEngine.Random.Range(16f, 28f);
vehiclePos.OnEmergency = (vehicleData.m_flags & Vehicle.Flags.Emergency2) != 0;
vehiclePos.VehicleType = (ExtVehicleType)vehicleType;
示例4: CalculateSegmentPosition
protected override void CalculateSegmentPosition(ushort vehicleID, ref Vehicle vehicleData, PathUnit.Position nextPosition, PathUnit.Position position, uint laneID, byte offset, PathUnit.Position prevPos, uint prevLaneID, byte prevOffset, int index, out Vector3 pos, out Vector3 dir, out float maxSpeed)
{
NetManager instance = Singleton<NetManager>.instance;
instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePositionAndDirection((float)offset * 0.003921569f, out pos, out dir);
Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData();
Vector3 position2 = lastFrameData.m_position;
Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].CalculatePosition((float)prevOffset * 0.003921569f);
float num = 0.5f * lastFrameData.m_velocity.sqrMagnitude / this.m_info.m_braking + this.m_info.m_generatedInfo.m_size.z * 0.5f;
if (Vector3.Distance(position2, b) >= num - 1f)
{
Segment3 segment;
segment.a = pos;
ushort num2;
ushort num3;
if (offset < position.m_offset)
{
segment.b = pos + dir.normalized * this.m_info.m_generatedInfo.m_size.z;
num2 = instance.m_segments.m_buffer[(int)position.m_segment].m_startNode;
num3 = instance.m_segments.m_buffer[(int)position.m_segment].m_endNode;
}
else
{
segment.b = pos - dir.normalized * this.m_info.m_generatedInfo.m_size.z;
num2 = instance.m_segments.m_buffer[(int)position.m_segment].m_endNode;
num3 = instance.m_segments.m_buffer[(int)position.m_segment].m_startNode;
}
ushort num4;
if (prevOffset == 0)
{
num4 = instance.m_segments.m_buffer[(int)prevPos.m_segment].m_startNode;
}
else
{
num4 = instance.m_segments.m_buffer[(int)prevPos.m_segment].m_endNode;
}
if (num2 == num4)
{
NetNode.Flags flags = instance.m_nodes.m_buffer[(int)num2].m_flags;
NetLane.Flags flags2 = (NetLane.Flags)instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_flags;
bool flag = (flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None;
bool flag2 = (flags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None;
bool flag3 = (flags2 & NetLane.Flags.JoinedJunction) != NetLane.Flags.None;
if ((flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) == NetNode.Flags.Junction && instance.m_nodes.m_buffer[(int)num2].CountSegments() != 2)
{
float len = vehicleData.CalculateTotalLength(vehicleID) + 2f;
if (!instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CheckSpace(len))
{
bool flag4 = false;
if (nextPosition.m_segment != 0 && instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_length < 30f)
{
NetNode.Flags flags3 = instance.m_nodes.m_buffer[(int)num3].m_flags;
if ((flags3 & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) != NetNode.Flags.Junction || instance.m_nodes.m_buffer[(int)num3].CountSegments() == 2)
{
uint laneID2 = PathManager.GetLaneID(nextPosition);
if (laneID2 != 0u)
{
flag4 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID2)].CheckSpace(len);
}
}
}
if (!flag4)
{
maxSpeed = 0f;
return;
}
}
}
if (flag && (!flag3 || flag2))
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
uint num5 = (uint)(((int)num4 << 8) / 32768);
uint num6 = currentFrameIndex - num5 & 255u;
NetInfo info = instance.m_nodes.m_buffer[(int)num2].Info;
RoadBaseAI.TrafficLightState vehicleLightState;
RoadBaseAI.TrafficLightState pedestrianLightState;
bool flag5;
bool pedestrians;
RoadBaseAI.GetTrafficLightState(num4, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, out vehicleLightState, out pedestrianLightState, out flag5, out pedestrians);
if (!flag5 && num6 >= 196u)
{
flag5 = true;
RoadBaseAI.SetTrafficLightState(num4, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, vehicleLightState, pedestrianLightState, flag5, pedestrians);
}
if ((vehicleData.m_flags & Vehicle.Flags.Emergency2) == 0 || info.m_class.m_service != ItemClass.Service.Road)
{
switch (vehicleLightState)
{
case RoadBaseAI.TrafficLightState.RedToGreen:
if (num6 < 60u)
{
maxSpeed = 0f;
return;
}
break;
case RoadBaseAI.TrafficLightState.Red:
maxSpeed = 0f;
return;
case RoadBaseAI.TrafficLightState.GreenToRed:
if (num6 >= 30u)
{
//.........这里部分代码省略.........
示例5: SimulationStep
public static void SimulationStep(CarAI carAI, ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ushort leaderID, ref Vehicle leaderData, int lodPhysics)
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
frameData.m_position += frameData.m_velocity * 0.5f;
frameData.m_swayPosition += frameData.m_swayVelocity * 0.5f;
float acceleration = carAI.m_info.m_acceleration;
float braking = carAI.m_info.m_braking;
float magnitude = frameData.m_velocity.magnitude;
Vector3 vector = vehicleData.m_targetPos0 - (Vector4)frameData.m_position;
float sqrMagnitude = vector.sqrMagnitude;
float num = (magnitude + acceleration) * (0.5f + 0.5f * (magnitude + acceleration) / braking) + carAI.m_info.m_generatedInfo.m_size.z * 0.5f;
float num2 = Mathf.Max(magnitude + acceleration, 5f);
if (lodPhysics >= 2 && (ulong)(currentFrameIndex >> 4 & 3u) == (ulong)((long)(vehicleID & 3)))
{
num2 *= 2f;
}
float num3 = Mathf.Max((num - num2) / 3f, 1f);
float num4 = num2 * num2;
float num5 = num3 * num3;
int i = 0;
bool flag = false;
if ((sqrMagnitude < num4 || vehicleData.m_targetPos3.w < 0.01f) && (leaderData.m_flags & (Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped)) == Vehicle.Flags.None)
{
if (leaderData.m_path != 0u)
{
CustomVehicleAI.UpdatePathTargetPositions(carAI, vehicleID, ref vehicleData, frameData.m_position, ref i, 4, num4, num5);
if ((leaderData.m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.None)
{
frameData = vehicleData.m_frame0;
return;
}
}
if ((leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
{
while (i < 4)
{
float minSqrDistance;
Vector3 refPos;
if (i == 0)
{
minSqrDistance = num4;
refPos = frameData.m_position;
flag = true;
}
else
{
minSqrDistance = num5;
refPos = vehicleData.GetTargetPos(i - 1);
}
int num6 = i;
carAI.UpdateBuildingTargetPositions(vehicleID, ref vehicleData, refPos, leaderID, ref leaderData, ref i, minSqrDistance);
if (i == num6)
{
break;
}
}
if (i != 0)
{
Vector4 targetPos = vehicleData.GetTargetPos(i - 1);
while (i < 4)
{
vehicleData.SetTargetPos(i++, targetPos);
}
}
}
vector = vehicleData.m_targetPos0 - (Vector4)frameData.m_position;
sqrMagnitude = vector.sqrMagnitude;
}
if (leaderData.m_path != 0u && (leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
{
NetManager instance = Singleton<NetManager>.instance;
byte b = leaderData.m_pathPositionIndex;
byte lastPathOffset = leaderData.m_lastPathOffset;
if (b == 255)
{
b = 0;
}
float num7 = 1f + leaderData.CalculateTotalLength(leaderID);
PathManager instance2 = Singleton<PathManager>.instance;
PathUnit.Position pathPos;
if (instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetPosition(b >> 1, out pathPos))
{
instance.m_segments.m_buffer[(int)pathPos.m_segment].AddTraffic(Mathf.RoundToInt(num7 * 2.5f));
bool flag2 = false;
if ((b & 1) == 0 || lastPathOffset == 0)
{
uint laneID = PathManager.GetLaneID(pathPos);
if (laneID != 0u)
{
Vector3 b2 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePosition((float)pathPos.m_offset * 0.003921569f);
float num8 = 0.5f * magnitude * magnitude / carAI.m_info.m_braking + carAI.m_info.m_generatedInfo.m_size.z * 0.5f;
if (Vector3.Distance(frameData.m_position, b2) >= num8 - 1f)
{
instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].ReserveSpace(num7);
flag2 = true;
}
}
}
if (!flag2 && instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetNextPosition(b >> 1, out pathPos))
{
//.........这里部分代码省略.........
示例6: SimulationStep
public override void SimulationStep(ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ushort leaderID, ref Vehicle leaderData, int lodPhysics)
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
frameData.m_position += frameData.m_velocity * 0.5f;
frameData.m_swayPosition += frameData.m_swayVelocity * 0.5f;
float acceleration = this.m_info.m_acceleration;
float braking = this.m_info.m_braking;
float magnitude = frameData.m_velocity.magnitude;
Vector3 vector = (Vector3)vehicleData.m_targetPos0 - frameData.m_position;
float sqrMagnitude = vector.sqrMagnitude;
float num = (magnitude + acceleration) * (0.5f + 0.5f * (magnitude + acceleration) / braking) + this.m_info.m_generatedInfo.m_size.z * 0.5f;
float num2 = Mathf.Max(magnitude + acceleration, 5f);
if (lodPhysics >= 2 && (ulong)(currentFrameIndex >> 4 & 3u) == (ulong)((long)(vehicleID & 3)))
{
num2 *= 2f;
}
float num3 = Mathf.Max((num - num2) / 3f, 1f);
float num4 = num2 * num2;
float num5 = num3 * num3;
int i = 0;
bool flag = false;
if ((sqrMagnitude < num4 || vehicleData.m_targetPos3.w < 0.01f) && (leaderData.m_flags & (Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped)) == Vehicle.Flags.None)
{
if (leaderData.m_path != 0u)
{
base.UpdatePathTargetPositions(vehicleID, ref vehicleData, frameData.m_position, ref i, 4, num4, num5);
if ((leaderData.m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.None)
{
frameData = vehicleData.m_frame0;
return;
}
}
if ((leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
{
while (i < 4)
{
float minSqrDistance;
Vector3 refPos;
if (i == 0)
{
minSqrDistance = num4;
refPos = frameData.m_position;
flag = true;
}
else
{
minSqrDistance = num5;
refPos = vehicleData.GetTargetPos(i - 1);
}
int num6 = i;
this.UpdateBuildingTargetPositions(vehicleID, ref vehicleData, refPos, leaderID, ref leaderData, ref i, minSqrDistance);
if (i == num6)
{
break;
}
}
if (i != 0)
{
Vector4 targetPos = vehicleData.GetTargetPos(i - 1);
while (i < 4)
{
vehicleData.SetTargetPos(i++, targetPos);
}
}
}
vector = (Vector3)vehicleData.m_targetPos0 - frameData.m_position;
sqrMagnitude = vector.sqrMagnitude;
}
if (leaderData.m_path != 0u && (leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
{
NetManager instance = Singleton<NetManager>.instance;
byte b = leaderData.m_pathPositionIndex;
byte lastPathOffset = leaderData.m_lastPathOffset;
if (b == 255)
{
b = 0;
}
float num7 = 1f + leaderData.CalculateTotalLength(leaderID);
PathManager instance2 = Singleton<PathManager>.instance;
PathUnit.Position pathPos;
if (instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetPosition(b >> 1, out pathPos))
{
instance.m_segments.m_buffer[(int)pathPos.m_segment].AddTraffic(Mathf.RoundToInt(num7 * 2.5f));
bool flag2 = false;
if ((b & 1) == 0 || lastPathOffset == 0)
{
uint laneID = PathManager.GetLaneID(pathPos);
if (laneID != 0u)
{
Vector3 b2 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePosition((float)pathPos.m_offset * 0.003921569f);
float num8 = 0.5f * magnitude * magnitude / this.m_info.m_braking + this.m_info.m_generatedInfo.m_size.z * 0.5f;
if (Vector3.Distance(frameData.m_position, b2) >= num8 - 1f)
{
instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].ReserveSpace(num7);
flag2 = true;
}
}
}
if (!flag2 && instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetNextPosition(b >> 1, out pathPos))
{
//.........这里部分代码省略.........
示例7: TmCalculateSegmentPosition
public void TmCalculateSegmentPosition(ushort vehicleId, ref Vehicle vehicleData, PathUnit.Position nextPosition,
PathUnit.Position position, uint laneID, byte offset, PathUnit.Position prevPos, uint prevLaneID,
byte prevOffset, out Vector3 pos, out Vector3 dir, out float maxSpeed) {
var netManager = Singleton<NetManager>.instance;
//var vehicleManager = Singleton<VehicleManager>.instance;
netManager.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePositionAndDirection(offset * 0.003921569f, out pos, out dir);
bool isRecklessDriver = (uint)vehicleId % (Options.getRecklessDriverModulo()) == 0;
var lastFrameData = vehicleData.GetLastFrameData();
var lastFrameVehiclePos = lastFrameData.m_position;
var camPos = Camera.main.transform.position;
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car) {
// add vehicle to our vehicle list
VehiclePosition vehiclePos = TrafficPriority.Vehicles[vehicleId];
if (vehiclePos == null) {
vehiclePos = new VehiclePosition();
TrafficPriority.Vehicles[vehicleId] = vehiclePos;
}
if (
(
(lastFrameVehiclePos - camPos).sqrMagnitude < CloseLod &&
(TrafficPriority.Vehicles[vehicleId].LastFrame >> closeLodUpdateMod[Options.simAccuracy]) < (Singleton<SimulationManager>.instance.m_currentFrameIndex >> closeLodUpdateMod[Options.simAccuracy]) // very often
) ||
(
(lastFrameVehiclePos - camPos).sqrMagnitude < FarLod &&
(TrafficPriority.Vehicles[vehicleId].LastFrame >> farLodUpdateMod[Options.simAccuracy]) < (Singleton<SimulationManager>.instance.m_currentFrameIndex >> farLodUpdateMod[Options.simAccuracy]) // often
) ||
(TrafficPriority.Vehicles[vehicleId].LastFrame >> veryFarLodUpdateMod[Options.simAccuracy]) < (Singleton<SimulationManager>.instance.m_currentFrameIndex >> veryFarLodUpdateMod[Options.simAccuracy]) // less often
) {
//Log.Message("handle vehicle after threshold");
try {
HandleVehicle(vehicleId, ref vehicleData, false);
} catch (Exception e) {
Log.Error("CarAI TmCalculateSegmentPosition Error: " + e.ToString());
}
}
} else {
Log.Message($"TmCalculateSegmentPosition does not handle vehicles of type {vehicleData.Info.m_vehicleType}");
}
// I think this is supposed to be the lane position?
// [VN, 12/23/2015] It's the 3D car position on the Bezier curve of the lane.
// This crazy 0.003921569f equals to 1f/255 and prevOffset is the byte value (0..255) of the car position.
var vehiclePosOnBezier = netManager.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].CalculatePosition(prevOffset * 0.003921569f);
//ushort currentSegmentId = netManager.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_segment;
ushort destinationNodeId;
ushort sourceNodeId;
if (offset < position.m_offset) {
destinationNodeId = netManager.m_segments.m_buffer[position.m_segment].m_startNode;
sourceNodeId = netManager.m_segments.m_buffer[position.m_segment].m_endNode;
} else {
destinationNodeId = netManager.m_segments.m_buffer[position.m_segment].m_endNode;
sourceNodeId = netManager.m_segments.m_buffer[position.m_segment].m_startNode;
}
var previousDestinationNode = prevOffset == 0 ? netManager.m_segments.m_buffer[prevPos.m_segment].m_startNode : netManager.m_segments.m_buffer[prevPos.m_segment].m_endNode;
// this seems to be like the required braking force in order to stop the vehicle within its half length.
var crazyValue = 0.5f * lastFrameData.m_velocity.sqrMagnitude / m_info.m_braking + m_info.m_generatedInfo.m_size.z * 0.5f;
// Essentially, this is true if the car has enough time and space to brake (e.g. for a red traffic light)
if (destinationNodeId == previousDestinationNode) {
if (Vector3.Distance(lastFrameVehiclePos, vehiclePosOnBezier) >= crazyValue - 1f) {
var currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
var num5 = (uint)((previousDestinationNode << 8) / 32768);
var num6 = currentFrameIndex - num5 & 255u;
var nodeFlags = netManager.m_nodes.m_buffer[destinationNodeId].m_flags;
var prevLaneFlags = (NetLane.Flags)netManager.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_flags;
var hasTrafficLight = (nodeFlags & NetNode.Flags.TrafficLights) != NetNode.Flags.None;
var hasCrossing = (nodeFlags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None;
var isJoinedJunction = (prevLaneFlags & NetLane.Flags.JoinedJunction) != NetLane.Flags.None;
bool checkSpace = !Options.mayEnterBlockedJunctions;
if (checkSpace && (uint)vehicleId % (Options.getRecklessDriverModulo() / 2) == 0) {
checkSpace = false;
}
if (checkSpace) {
// check if there is enough space
if ((nodeFlags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) ==
NetNode.Flags.Junction && netManager.m_nodes.m_buffer[destinationNodeId].CountSegments() != 2) {
var len = vehicleData.CalculateTotalLength(vehicleId) + 2f;
if (!netManager.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CheckSpace(len)) {
var sufficientSpace = false;
if (nextPosition.m_segment != 0 &&
netManager.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_length < 30f) {
var flags3 = netManager.m_nodes.m_buffer[sourceNodeId].m_flags;
if ((flags3 &
(NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) !=
NetNode.Flags.Junction || netManager.m_nodes.m_buffer[sourceNodeId].CountSegments() == 2) {
var laneId2 = PathManager.GetLaneID(nextPosition);
if (laneId2 != 0u) {
sufficientSpace = netManager.m_lanes.m_buffer[(int)((UIntPtr)laneId2)].CheckSpace(len);
}
}
}
if (!sufficientSpace) {
maxSpeed = 0f;
return;
}
//.........这里部分代码省略.........
开发者ID:akira-ishizaki,项目名称:Cities-Skylines-Traffic-Manager-President-Edition,代码行数:101,代码来源:CustomCarAI.cs
示例8: PathFindReady
protected virtual bool PathFindReady(ushort vehicleID, ref Vehicle vehicleData)
{
PathManager instance = Singleton<PathManager>.instance;
NetManager instance2 = Singleton<NetManager>.instance;
float num = vehicleData.CalculateTotalLength (vehicleID);
float distance = (num + this.m_info.m_generatedInfo.m_wheelBase - this.m_info.m_generatedInfo.m_size.z) * 0.5f;
Vector3 vector = vehicleData.GetLastFramePosition ();
PathUnit.Position pathPos;
if ((vehicleData.m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.None && instance.m_pathUnits.m_buffer [(int)((UIntPtr)vehicleData.m_path)].GetPosition (0, out pathPos))
{
uint laneID = PathManager.GetLaneID (pathPos);
vector = instance2.m_lanes.m_buffer [(int)((UIntPtr)laneID)].CalculatePosition ((float)pathPos.m_offset * 0.003921569f);
}
vehicleData.m_flags &= ~Vehicle.Flags.WaitingPath;
instance.m_pathUnits.m_buffer [(int)((UIntPtr)vehicleData.m_path)].MoveLastPosition (vehicleData.m_path, distance);
if ((vehicleData.m_flags & Vehicle.Flags.Spawned) != Vehicle.Flags.None)
{
InitializePath (vehicleID, ref vehicleData);
}
else
{
int index = Mathf.Min (1, (int)(instance.m_pathUnits.m_buffer [(int)((UIntPtr)vehicleData.m_path)].m_positionCount - 1));
PathUnit.Position pathPos2;
if (instance.m_pathUnits.m_buffer [(int)((UIntPtr)vehicleData.m_path)].GetPosition (index, out pathPos2))
{
uint laneID2 = PathManager.GetLaneID (pathPos2);
Vector3 a = instance2.m_lanes.m_buffer [(int)((UIntPtr)laneID2)].CalculatePosition ((float)pathPos2.m_offset * 0.003921569f);
Vector3 forward = a - vector;
vehicleData.m_frame0.m_position = vector;
if (forward.sqrMagnitude > 1f)
{
float length = instance2.m_lanes.m_buffer [(int)((UIntPtr)laneID2)].m_length;
vehicleData.m_frame0.m_position = vehicleData.m_frame0.m_position + forward.normalized * Mathf.Min (length * 0.5f, (num - this.m_info.m_generatedInfo.m_size.z) * 0.5f);
vehicleData.m_frame0.m_rotation = Quaternion.LookRotation (forward);
}
vehicleData.m_frame1 = vehicleData.m_frame0;
vehicleData.m_frame2 = vehicleData.m_frame0;
vehicleData.m_frame3 = vehicleData.m_frame0;
this.FrameDataUpdated (vehicleID, ref vehicleData, ref vehicleData.m_frame0);
}
this.TrySpawn (vehicleID, ref vehicleData);
}
return true;
}
示例9: CustomCalculateSegmentPosition
public void CustomCalculateSegmentPosition(ushort vehicleID, ref Vehicle vehicleData, PathUnit.Position nextPosition, PathUnit.Position position, uint laneID, byte offset, PathUnit.Position prevPos, uint prevLaneID, byte prevOffset, int index, out Vector3 pos, out Vector3 dir, out float maxSpeed) {
NetManager instance = Singleton<NetManager>.instance;
instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePositionAndDirection((float)offset * 0.003921569f, out pos, out dir);
Vector3 b = instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].CalculatePosition((float)prevOffset * 0.003921569f);
Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData();
Vector3 a = lastFrameData.m_position;
Vector3 a2 = lastFrameData.m_position;
Vector3 b2 = lastFrameData.m_rotation * new Vector3(0f, 0f, this.m_info.m_generatedInfo.m_wheelBase * 0.5f);
a += b2;
a2 -= b2;
float num = 0.5f * lastFrameData.m_velocity.sqrMagnitude / this.m_info.m_braking;
float a3 = Vector3.Distance(a, b);
float b3 = Vector3.Distance(a2, b);
if (Mathf.Min(a3, b3) >= num - 1f) {
Segment3 segment;
segment.a = pos;
ushort num2;
ushort num3;
if (offset < position.m_offset) {
segment.b = pos + dir.normalized * this.m_info.m_generatedInfo.m_size.z;
num2 = instance.m_segments.m_buffer[(int)position.m_segment].m_startNode;
num3 = instance.m_segments.m_buffer[(int)position.m_segment].m_endNode;
} else {
segment.b = pos - dir.normalized * this.m_info.m_generatedInfo.m_size.z;
num2 = instance.m_segments.m_buffer[(int)position.m_segment].m_endNode;
num3 = instance.m_segments.m_buffer[(int)position.m_segment].m_startNode;
}
ushort num4;
if (prevOffset == 0) {
num4 = instance.m_segments.m_buffer[(int)prevPos.m_segment].m_startNode;
} else {
num4 = instance.m_segments.m_buffer[(int)prevPos.m_segment].m_endNode;
}
if (num2 == num4) {
NetNode.Flags flags = instance.m_nodes.m_buffer[(int)num2].m_flags;
NetLane.Flags flags2 = (NetLane.Flags)instance.m_lanes.m_buffer[(int)((UIntPtr)prevLaneID)].m_flags;
bool flag = (flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None;
bool flag2 = (flags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None;
bool flag3 = (flags2 & NetLane.Flags.JoinedJunction) != NetLane.Flags.None;
bool checkSpace = !Options.allowEnterBlockedJunctions; // NON-STOCK CODE
if (checkSpace && (flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) == NetNode.Flags.Junction && instance.m_nodes.m_buffer[(int)num2].CountSegments() != 2) {
float len = vehicleData.CalculateTotalLength(vehicleID) + 2f;
if (!instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CheckSpace(len)) {
bool flag4 = false;
if (nextPosition.m_segment != 0 && instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_length < 30f) {
NetNode.Flags flags3 = instance.m_nodes.m_buffer[(int)num3].m_flags;
if ((flags3 & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) != NetNode.Flags.Junction || instance.m_nodes.m_buffer[(int)num3].CountSegments() == 2) {
uint laneID2 = PathManager.GetLaneID(nextPosition);
if (laneID2 != 0u) {
flag4 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID2)].CheckSpace(len);
}
}
}
if (!flag4) {
maxSpeed = 0f;
return;
}
}
}
if (flag && (!flag3 || flag2)) {
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
uint num5 = (uint)(((int)num4 << 8) / 32768);
uint num6 = currentFrameIndex - num5 & 255u;
RoadBaseAI.TrafficLightState vehicleLightState;
RoadBaseAI.TrafficLightState pedestrianLightState;
bool flag5;
bool pedestrians;
/// NON-STOCK CODE START ///
CustomRoadAI.GetTrafficLightState(vehicleID, ref vehicleData, num4, prevPos.m_segment, position.m_segment, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, out vehicleLightState, out pedestrianLightState, out flag5, out pedestrians);
/// NON-STOCK CODE END ///
//RoadBaseAI.GetTrafficLightState(num4, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, out vehicleLightState, out pedestrianLightState, out flag5, out pedestrians);
if (!flag5 && num6 >= 196u) {
flag5 = true;
RoadBaseAI.SetTrafficLightState(num4, ref instance.m_segments.m_buffer[(int)prevPos.m_segment], currentFrameIndex - num5, vehicleLightState, pedestrianLightState, flag5, pedestrians);
}
switch (vehicleLightState) {
case RoadBaseAI.TrafficLightState.RedToGreen:
if (num6 < 60u) {
maxSpeed = 0f;
return;
}
break;
case RoadBaseAI.TrafficLightState.Red:
maxSpeed = 0f;
return;
case RoadBaseAI.TrafficLightState.GreenToRed:
if (num6 >= 30u) {
maxSpeed = 0f;
return;
}
break;
}
}
}
}
NetInfo info = instance.m_segments.m_buffer[(int)position.m_segment].Info;
if (info.m_lanes != null && info.m_lanes.Length > (int)position.m_lane) {
//maxSpeed = this.CalculateTargetSpeed(vehicleID, ref vehicleData, info.m_lanes[(int)position.m_lane].m_speedLimit, instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].m_curve);
maxSpeed = CalculateTargetSpeed(vehicleID, ref vehicleData, SpeedLimitManager.GetLockFreeGameSpeedLimit(position.m_segment, position.m_lane, laneID, info.m_lanes[position.m_lane]), instance.m_lanes.m_buffer[laneID].m_curve);
} else {
//.........这里部分代码省略.........
示例10: TmCalculateSegmentPosition
public void TmCalculateSegmentPosition(ushort vehicleId, ref Vehicle vehicleData, PathUnit.Position nextPosition,
PathUnit.Position position, uint laneId, byte offset, PathUnit.Position prevPos, uint prevLaneId,
byte prevOffset, out Vector3 pos, out Vector3 dir, out float maxSpeed)
{
var netManager = Singleton<NetManager>.instance;
netManager.m_lanes.m_buffer[(int)((UIntPtr) laneId)]
.CalculatePositionAndDirection(offset*0.003921569f, out pos, out dir);
var lastFrameData = vehicleData.GetLastFrameData();
var vehiclePositionLastFrame = lastFrameData.m_position;
// I think this is supposed to be the lane position?
var lanePosition = netManager.m_lanes.m_buffer[(int) ((UIntPtr) prevLaneId)]
.CalculatePosition(prevOffset*0.003921569f);
var num = 0.5f*lastFrameData.m_velocity.sqrMagnitude/m_info.m_braking + m_info.m_generatedInfo.m_size.z*0.5f;
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car)
{
if (!TrafficPriority.VehicleList.ContainsKey(vehicleId))
{
TrafficPriority.VehicleList.Add(vehicleId, new PriorityCar());
}
}
if (Vector3.Distance(vehiclePositionLastFrame, lanePosition) >= num - 1f)
{
ushort destinationNode;
ushort nodeId3;
if (offset < position.m_offset)
{
destinationNode = netManager.m_segments.m_buffer[position.m_segment].m_startNode;
nodeId3 = netManager.m_segments.m_buffer[position.m_segment].m_endNode;
}
else
{
destinationNode = netManager.m_segments.m_buffer[position.m_segment].m_endNode;
nodeId3 = netManager.m_segments.m_buffer[position.m_segment].m_startNode;
}
var nodeId4 = prevOffset == 0 ? netManager.m_segments.m_buffer[prevPos.m_segment].m_startNode :
netManager.m_segments.m_buffer[prevPos.m_segment].m_endNode;
if (destinationNode == nodeId4)
{
var currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
var num5 = (uint) ((nodeId4 << 8)/32768);
var num6 = currentFrameIndex - num5 & 255u;
var flags = netManager.m_nodes.m_buffer[destinationNode].m_flags;
var flags2 =
(NetLane.Flags) netManager.m_lanes.m_buffer[(int) ((UIntPtr) prevLaneId)].m_flags;
var flag = (flags & NetNode.Flags.TrafficLights) != NetNode.Flags.None;
var flag2 = (flags & NetNode.Flags.LevelCrossing) != NetNode.Flags.None;
var flag3 = (flags2 & NetLane.Flags.JoinedJunction) != NetLane.Flags.None;
if ((flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) ==
NetNode.Flags.Junction && netManager.m_nodes.m_buffer[destinationNode].CountSegments() != 2)
{
var len = vehicleData.CalculateTotalLength(vehicleId) + 2f;
if (!netManager.m_lanes.m_buffer[(int) ((UIntPtr) laneId)].CheckSpace(len))
{
var flag4 = false;
if (nextPosition.m_segment != 0 &&
netManager.m_lanes.m_buffer[(int) ((UIntPtr) laneId)].m_length < 30f)
{
var flags3 = netManager.m_nodes.m_buffer[nodeId3].m_flags;
if ((flags3 &
(NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) !=
NetNode.Flags.Junction || netManager.m_nodes.m_buffer[nodeId3].CountSegments() == 2)
{
var laneId2 = PathManager.GetLaneID(nextPosition);
if (laneId2 != 0u)
{
flag4 = netManager.m_lanes.m_buffer[(int) ((UIntPtr) laneId2)].CheckSpace(len);
}
}
}
if (!flag4)
{
maxSpeed = 0f;
return;
}
}
}
if (vehicleData.Info.m_vehicleType == VehicleInfo.VehicleType.Car &&
TrafficPriority.VehicleList.ContainsKey(vehicleId) &&
TrafficPriority.IsPrioritySegment(destinationNode, prevPos.m_segment))
{
var currentFrameIndex2 = Singleton<SimulationManager>.instance.m_currentFrameIndex;
var frame = currentFrameIndex2 >> 4;
var prioritySegment = TrafficPriority.GetPrioritySegment(destinationNode, prevPos.m_segment);
if (TrafficPriority.VehicleList[vehicleId].ToNode != destinationNode ||
TrafficPriority.VehicleList[vehicleId].FromSegment != prevPos.m_segment)
{
if (TrafficPriority.VehicleList[vehicleId].ToNode != 0 &&
TrafficPriority.VehicleList[vehicleId].FromSegment != 0)
{
var oldNode = TrafficPriority.VehicleList[vehicleId].ToNode;
var oldSegment = TrafficPriority.VehicleList[vehicleId].FromSegment;
//.........这里部分代码省略.........