本文整理汇总了C#中Vehicle.GetLastFrameData方法的典型用法代码示例。如果您正苦于以下问题:C# Vehicle.GetLastFrameData方法的具体用法?C# Vehicle.GetLastFrameData怎么用?C# Vehicle.GetLastFrameData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vehicle
的用法示例。
在下文中一共展示了Vehicle.GetLastFrameData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimulationStep
public override void SimulationStep(ushort vehicleID, ref Vehicle vehicleData, ushort leaderID, ref Vehicle leaderData, int lodPhysics)
{
if ((CSLTraffic.Options & OptionsManager.ModOptions.UseRealisticSpeeds) == OptionsManager.ModOptions.UseRealisticSpeeds)
{
if (CustomCarAI.sm_speedData[vehicleID].speedMultiplier == 0 || CustomCarAI.sm_speedData[vehicleID].currentPath != vehicleData.m_path)
{
CustomCarAI.sm_speedData[vehicleID].currentPath = vehicleData.m_path;
CustomCarAI.sm_speedData[vehicleID].SetRandomSpeedMultiplier(0.7f, 1.1f);
}
CustomCarAI.sm_speedData[vehicleID].ApplySpeedMultiplier(this.m_info);
}
if ((vehicleData.m_flags & Vehicle.Flags.Spawned) != Vehicle.Flags.None)
{
Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData();
if (this.m_info.m_isLargeVehicle)
{
int num = Mathf.Clamp((int)(lastFrameData.m_position.x / 320f + 27f), 0, 53);
int num2 = Mathf.Clamp((int)(lastFrameData.m_position.z / 320f + 27f), 0, 53);
CustomCarAI.SimulationStep(this, vehicleID, ref vehicleData, ref lastFrameData, leaderID, ref leaderData, lodPhysics);
int num3 = Mathf.Clamp((int)(lastFrameData.m_position.x / 320f + 27f), 0, 53);
int num4 = Mathf.Clamp((int)(lastFrameData.m_position.z / 320f + 27f), 0, 53);
if ((num3 != num || num4 != num2) && (vehicleData.m_flags & Vehicle.Flags.Spawned) != Vehicle.Flags.None)
{
Singleton<VehicleManager>.instance.RemoveFromGrid(vehicleID, ref vehicleData, true, num, num2);
Singleton<VehicleManager>.instance.AddToGrid(vehicleID, ref vehicleData, true, num3, num4);
}
}
else
{
int num5 = Mathf.Clamp((int)(lastFrameData.m_position.x / 32f + 270f), 0, 539);
int num6 = Mathf.Clamp((int)(lastFrameData.m_position.z / 32f + 270f), 0, 539);
CustomCarAI.SimulationStep(this, vehicleID, ref vehicleData, ref lastFrameData, leaderID, ref leaderData, lodPhysics);
int num7 = Mathf.Clamp((int)(lastFrameData.m_position.x / 32f + 270f), 0, 539);
int num8 = Mathf.Clamp((int)(lastFrameData.m_position.z / 32f + 270f), 0, 539);
if ((num7 != num5 || num8 != num6) && (vehicleData.m_flags & Vehicle.Flags.Spawned) != Vehicle.Flags.None)
{
Singleton<VehicleManager>.instance.RemoveFromGrid(vehicleID, ref vehicleData, false, num5, num6);
Singleton<VehicleManager>.instance.AddToGrid(vehicleID, ref vehicleData, false, num7, num8);
}
}
if ((vehicleData.m_flags & (Vehicle.Flags.Created | Vehicle.Flags.Deleted)) == Vehicle.Flags.Created)
{
this.FrameDataUpdated(vehicleID, ref vehicleData, ref lastFrameData);
vehicleData.SetFrameData(Singleton<SimulationManager>.instance.m_currentFrameIndex, lastFrameData);
}
}
if ((CSLTraffic.Options & OptionsManager.ModOptions.UseRealisticSpeeds) == OptionsManager.ModOptions.UseRealisticSpeeds)
{
CustomCarAI.sm_speedData[vehicleID].RestoreVehicleSpeed(this.m_info);
}
}
示例2: 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)
{
//.........这里部分代码省略.........
示例3: HandleVehicle
/// <summary>
/// Handles vehicle path information in order to manage special nodes (nodes with priority signs or traffic lights).
/// Data like "vehicle X is on segment S0 and is going to segment S1" is collected.
/// </summary>
/// <param name="vehicleId"></param>
/// <param name="vehicleData"></param>
internal static void HandleVehicle(ushort vehicleId, ref Vehicle vehicleData, bool addTraffic, bool realTraffic, byte maxUpcomingPathPositions, bool debug = false) {
if (maxUpcomingPathPositions <= 0)
maxUpcomingPathPositions = 1; // we need at least one upcoming path position
var netManager = Singleton<NetManager>.instance;
var lastFrameData = vehicleData.GetLastFrameData();
var lastFrameVehiclePos = lastFrameData.m_position;
#if DEBUGV
var camPos = Camera.main.transform.position;
//debug = (lastFrameVehiclePos - camPos).sqrMagnitude < CloseLod;
debug = false;
List<String> logBuffer = new List<String>();
bool logme = false;
#endif
if ((vehicleData.m_flags & Vehicle.Flags.Created) == 0) {
TrafficPriority.RemoveVehicleFromSegments(vehicleId);
return;
}
if (vehicleData.Info.m_vehicleType != VehicleInfo.VehicleType.Car &&
vehicleData.Info.m_vehicleType != VehicleInfo.VehicleType.Train &&
vehicleData.Info.m_vehicleType != VehicleInfo.VehicleType.Tram) {
//Log._Debug($"HandleVehicle does not handle vehicles of type {vehicleData.Info.m_vehicleType}");
return;
}
#if DEBUGV
logBuffer.Add("Calculating prio info for vehicleId " + vehicleId);
#endif
ExtVehicleType? vehicleType = CustomVehicleAI.DetermineVehicleTypeFromVehicle(vehicleId, ref vehicleData);
if (vehicleType == null) {
Log.Warning($"Could not determine vehicle type of vehicle {vehicleId}!");
}
if (vehicleType == null || vehicleType == ExtVehicleType.None) {
return;
}
// add vehicle to our vehicle list
VehiclePosition vehiclePos = TrafficPriority.GetVehiclePosition(vehicleId);
// we extract the segment information directly from the vehicle
var currentPathUnitId = vehicleData.m_path;
List<ushort> realTimeDestinationNodes = new List<ushort>(); // current and upcoming node ids
List<PathUnit.Position> realTimePositions = new List<PathUnit.Position>(); // current and upcoming vehicle positions
#if DEBUGV
logBuffer.Add("* vehicleId " + vehicleId + ". currentPathId: " + currentPathUnitId + " pathPositionIndex: " + vehicleData.m_pathPositionIndex);
#endif
if (currentPathUnitId > 0) {
// vehicle has a path...
if ((Singleton<PathManager>.instance.m_pathUnits.m_buffer[currentPathUnitId].m_pathFindFlags & PathUnit.FLAG_READY) != 0) {
// The path(unit) is established and is ready for use: get the vehicle's current position in terms of segment and lane
realTimePositions.Add(Singleton<PathManager>.instance.m_pathUnits.m_buffer[currentPathUnitId].GetPosition(vehicleData.m_pathPositionIndex >> 1));
if (realTimePositions[0].m_offset == 0) {
realTimeDestinationNodes.Add(netManager.m_segments.m_buffer[realTimePositions[0].m_segment].m_startNode);
} else {
realTimeDestinationNodes.Add(netManager.m_segments.m_buffer[realTimePositions[0].m_segment].m_endNode);
}
if (maxUpcomingPathPositions > 0) {
// evaluate upcoming path units
byte i = 0;
uint pathUnitId = currentPathUnitId;
int pathPos = (byte)((vehicleData.m_pathPositionIndex >> 1) + 1);
while (true) {
if (pathPos > 11) {
// go to next path unit
pathPos = 0;
pathUnitId = Singleton<PathManager>.instance.m_pathUnits.m_buffer[pathUnitId].m_nextPathUnit;
#if DEBUGV
logBuffer.Add("* vehicleId " + vehicleId + ". Going to next path unit (1). pathUnitId=" + pathUnitId);
#endif
if (pathUnitId <= 0)
break;
}
PathUnit.Position nextRealTimePosition = default(PathUnit.Position);
if (!Singleton<PathManager>.instance.m_pathUnits.m_buffer[pathUnitId].GetPosition(pathPos, out nextRealTimePosition)) { // if this returns false, there is no next path unit
#if DEBUGV
logBuffer.Add("* vehicleId " + vehicleId + ". No next path unit! pathPos=" + pathPos + ", pathUnitId=" + pathUnitId);
#endif
break;
}
ushort destNodeId = 0;
if (nextRealTimePosition.m_segment > 0) {
if (nextRealTimePosition.m_offset == 0) {
destNodeId = netManager.m_segments.m_buffer[nextRealTimePosition.m_segment].m_startNode;
} else {
destNodeId = netManager.m_segments.m_buffer[nextRealTimePosition.m_segment].m_endNode;
}
}
//.........这里部分代码省略.........
示例4: CheckOtherVehicle
private ushort CheckOtherVehicle(ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ref float maxSpeed, ref bool blocked, float maxBraking, ushort otherID, ref Vehicle otherData, Vector3 min, Vector3 max, int lodPhysics)
{
if (otherID != vehicleID && vehicleData.m_leadingVehicle != otherID && vehicleData.m_trailingVehicle != otherID)
{
Vector3 vector;
Vector3 vector2;
if (lodPhysics >= 1)
{
vector = otherData.m_segment.Min ();
vector2 = otherData.m_segment.Max ();
}
else
{
vector = Vector3.Min (otherData.m_segment.Min (), otherData.m_targetPos3);
vector2 = Vector3.Max (otherData.m_segment.Max (), otherData.m_targetPos3);
}
if (min.x < vector2.x + 2f && min.y < vector2.y + 2f && min.z < vector2.z + 2f && vector.x < max.x + 2f && vector.y < max.y + 2f && vector.z < max.z + 2f)
{
Vehicle.Frame lastFrameData = otherData.GetLastFrameData ();
VehicleInfo info = otherData.Info;
float num = frameData.m_velocity.magnitude + 0.01f;
float num2 = lastFrameData.m_velocity.magnitude;
float num3 = num2 * (0.5f + 0.5f * num2 / info.m_braking) + info.m_generatedInfo.m_size.z * Mathf.Min (0.5f, num2 * 0.1f);
num2 += 0.01f;
float num4 = 0f;
Vector3 vector3 = frameData.m_position;
Vector3 lhs = ((Vector3) vehicleData.m_targetPos3) - frameData.m_position;
for (int i = 1; i < 4; i++)
{
Vector3 vector4 = vehicleData.GetTargetPos (i);
Vector3 vector5 = vector4 - vector3;
if (Vector3.Dot (lhs, vector5) > 0f)
{
float magnitude = vector5.magnitude;
Segment3 segment = new Segment3 (vector3, vector4);
min = segment.Min ();
max = segment.Max ();
segment.a.y = segment.a.y * 0.5f;
segment.b.y = segment.b.y * 0.5f;
if (magnitude > 0.01f && min.x < vector2.x + 2f && min.y < vector2.y + 2f && min.z < vector2.z + 2f && vector.x < max.x + 2f && vector.y < max.y + 2f && vector.z < max.z + 2f)
{
Vector3 a = otherData.m_segment.a;
a.y *= 0.5f;
float num5;
if (segment.DistanceSqr (a, out num5) < 400f)
{
float num6 = Vector3.Dot (lastFrameData.m_velocity, vector5) / magnitude;
float num7 = num4 + magnitude * num5;
if (num7 >= 0.01f)
{
num7 -= num6 + 30f;
float num8 = Mathf.Max (0f, CalculateMaxSpeed (num7, num6, maxBraking));
if (num8 < 0.01f)
{
blocked = true;
}
Vector3 rhs = Vector3.Normalize (((Vector3)otherData.m_targetPos3) - otherData.GetLastFramePosition ());
float num9 = 1.2f - 1f / ((float)vehicleData.m_blockCounter * 0.02f + 0.5f);
if (Vector3.Dot (vector5, rhs) > num9 * magnitude)
{
maxSpeed = Mathf.Min (maxSpeed, num8);
}
}
break;
}
if (lodPhysics == 0)
{
float num10 = 0f;
float num11 = num3;
Vector3 vector6 = otherData.GetLastFramePosition ();
Vector3 lhs2 = ((Vector3)otherData.m_targetPos3) - vector6;
bool flag = false;
int num12 = 1;
while (num12 < 4 && num11 > 0.1f)
{
Vector3 vector7 = otherData.GetTargetPos (num12);
Vector3 vector8 = Vector3.ClampMagnitude (vector7 - vector6, num11);
if (Vector3.Dot (lhs2, vector8) > 0f)
{
vector7 = vector6 + vector8;
float magnitude2 = vector8.magnitude;
num11 -= magnitude2;
Segment3 segment2 = new Segment3 (vector6, vector7);
segment2.a.y = segment2.a.y * 0.5f;
segment2.b.y = segment2.b.y * 0.5f;
if (magnitude2 > 0.01f)
{
float num14;
float num15;
float num13;
if (otherID < vehicleID)
{
num13 = segment2.DistanceSqr (segment, out num14, out num15);
}
else
{
num13 = segment.DistanceSqr (segment2, out num15, out num14);
}
if (num13 < 400f)
{
//.........这里部分代码省略.........
示例5: 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)) {
//.........这里部分代码省略.........
示例6: CheckOtherVehicle
private static ushort CheckOtherVehicle(ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ref float maxSpeed, ref bool blocked, ref Vector3 collisionPush, float maxBraking, ushort otherID, ref Vehicle otherData, Vector3 min, Vector3 max, int lodPhysics)
{
if (otherID != vehicleID && vehicleData.m_leadingVehicle != otherID && vehicleData.m_trailingVehicle != otherID)
{
VehicleInfo info = otherData.Info;
if (info.m_vehicleType == VehicleInfo.VehicleType.Bicycle)
{
return otherData.m_nextGridVehicle;
}
Vector3 vector;
Vector3 vector2;
if (lodPhysics >= 2)
{
vector = otherData.m_segment.Min();
vector2 = otherData.m_segment.Max();
}
else
{
vector = Vector3.Min(otherData.m_segment.Min(), otherData.m_targetPos3);
vector2 = Vector3.Max(otherData.m_segment.Max(), otherData.m_targetPos3);
}
if (min.x < vector2.x + 2f && min.y < vector2.y + 2f && min.z < vector2.z + 2f && vector.x < max.x + 2f && vector.y < max.y + 2f && vector.z < max.z + 2f)
{
Vehicle.Frame lastFrameData = otherData.GetLastFrameData();
if (lodPhysics < 2)
{
float num2;
float num3;
float num = vehicleData.m_segment.DistanceSqr(otherData.m_segment, out num2, out num3);
if (num < 4f)
{
Vector3 a = vehicleData.m_segment.Position(0.5f);
Vector3 b = otherData.m_segment.Position(0.5f);
Vector3 lhs = vehicleData.m_segment.b - vehicleData.m_segment.a;
if (Vector3.Dot(lhs, a - b) < 0f)
{
collisionPush -= lhs.normalized * (0.1f - num * 0.025f);
}
else
{
collisionPush += lhs.normalized * (0.1f - num * 0.025f);
}
blocked = true;
}
}
float num4 = frameData.m_velocity.magnitude + 0.01f;
float num5 = lastFrameData.m_velocity.magnitude;
float num6 = num5 * (0.5f + 0.5f * num5 / info.m_braking) + Mathf.Min(1f, num5);
num5 += 0.01f;
float num7 = 0f;
Vector3 vector3 = vehicleData.m_segment.b;
Vector3 lhs2 = vehicleData.m_segment.b - vehicleData.m_segment.a;
for (int i = 0; i < 4; i++)
{
Vector3 vector4 = vehicleData.GetTargetPos(i);
Vector3 vector5 = vector4 - vector3;
if (Vector3.Dot(lhs2, vector5) > 0f)
{
float magnitude = vector5.magnitude;
Segment3 segment = new Segment3(vector3, vector4);
min = segment.Min();
max = segment.Max();
segment.a.y = segment.a.y * 0.5f;
segment.b.y = segment.b.y * 0.5f;
if (magnitude > 0.01f && min.x < vector2.x + 2f && min.y < vector2.y + 2f && min.z < vector2.z + 2f && vector.x < max.x + 2f && vector.y < max.y + 2f && vector.z < max.z + 2f)
{
Vector3 a2 = otherData.m_segment.a;
a2.y *= 0.5f;
float num8;
if (segment.DistanceSqr(a2, out num8) < 4f)
{
float num9 = Vector3.Dot(lastFrameData.m_velocity, vector5) / magnitude;
float num10 = num7 + magnitude * num8;
if (num10 >= 0.01f)
{
num10 -= num9 + 3f;
float num11 = Mathf.Max(0f, CalculateMaxSpeed(num10, num9, maxBraking));
if (num11 < 0.01f)
{
blocked = true;
}
Vector3 rhs = Vector3.Normalize(otherData.m_targetPos0 - (Vector4)otherData.m_segment.a);
float num12 = 1.2f - 1f / ((float)vehicleData.m_blockCounter * 0.02f + 0.5f);
if (Vector3.Dot(vector5, rhs) > num12 * magnitude)
{
maxSpeed = Mathf.Min(maxSpeed, num11);
}
}
break;
}
if (lodPhysics < 2)
{
float num13 = 0f;
float num14 = num6;
Vector3 vector6 = otherData.m_segment.b;
Vector3 lhs3 = otherData.m_segment.b - otherData.m_segment.a;
bool flag = false;
int num15 = 0;
while (num15 < 4 && num14 > 0.1f)
{
//.........这里部分代码省略.........
示例7: 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)
{
//.........这里部分代码省略.........
示例8: 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
示例9: CheckOverlap
private static ushort CheckOverlap(Segment3 segment, ushort ignoreVehicle, float maxVelocity, ushort otherID, ref Vehicle otherData, ref bool overlap)
{
float num;
float num2;
if ((ignoreVehicle == 0 || (otherID != ignoreVehicle && otherData.m_leadingVehicle != ignoreVehicle && otherData.m_trailingVehicle != ignoreVehicle)) && segment.DistanceSqr (otherData.m_segment, out num, out num2) < 4f)
{
VehicleInfo info = otherData.Info;
if (info.m_vehicleType == VehicleInfo.VehicleType.Bicycle)
{
return otherData.m_nextGridVehicle;
}
if (otherData.GetLastFrameData ().m_velocity.sqrMagnitude < maxVelocity * maxVelocity)
{
overlap = true;
}
}
return otherData.m_nextGridVehicle;
}
示例10: ResetTargets
private static void ResetTargets(ushort vehicleID, ref Vehicle vehicleData, ushort leaderID, ref Vehicle leaderData, bool pushPathPos)
{
Vehicle.Frame lastFrameData = vehicleData.GetLastFrameData ();
VehicleInfo info = vehicleData.Info;
TrainAI trainAI = info.m_vehicleAI as TrainAI;
Vector3 vector = lastFrameData.m_position;
Vector3 vector2 = lastFrameData.m_position;
Vector3 b = lastFrameData.m_rotation * new Vector3 (0f, 0f, info.m_generatedInfo.m_wheelBase * 0.5f);
if ((leaderData.m_flags & Vehicle.Flags.Reversed) != Vehicle.Flags.None)
{
vector -= b;
vector2 += b;
}
else
{
vector += b;
vector2 -= b;
}
vehicleData.m_targetPos0 = vector2;
vehicleData.m_targetPos0.w = 2f;
vehicleData.m_targetPos1 = vector;
vehicleData.m_targetPos1.w = 2f;
vehicleData.m_targetPos2 = vehicleData.m_targetPos1;
vehicleData.m_targetPos3 = vehicleData.m_targetPos1;
if (vehicleData.m_path != 0u)
{
PathManager instance = Singleton<PathManager>.instance;
int num = (vehicleData.m_pathPositionIndex >> 1) + 1;
uint num2 = vehicleData.m_path;
if (num >= (int)instance.m_pathUnits.m_buffer [(int)((UIntPtr)num2)].m_positionCount)
{
num = 0;
num2 = instance.m_pathUnits.m_buffer [(int)((UIntPtr)num2)].m_nextPathUnit;
}
PathUnit.Position pathPos;
if (instance.m_pathUnits.m_buffer [(int)((UIntPtr)vehicleData.m_path)].GetPosition (vehicleData.m_pathPositionIndex >> 1, out pathPos))
{
uint laneID = PathManager.GetLaneID (pathPos);
PathUnit.Position pathPos2;
if (num2 != 0u && instance.m_pathUnits.m_buffer [(int)((UIntPtr)num2)].GetPosition (num, out pathPos2))
{
uint laneID2 = PathManager.GetLaneID (pathPos2);
if (laneID2 == laneID)
{
if (num2 != vehicleData.m_path)
{
instance.ReleaseFirstUnit (ref vehicleData.m_path);
}
vehicleData.m_pathPositionIndex = (byte)(num << 1);
}
}
PathUnit.CalculatePathPositionOffset (laneID, vector2, out vehicleData.m_lastPathOffset);
}
}
if (vehicleData.m_path != 0u)
{
int num3 = 0;
((FakeTrainAI)trainAI).UpdatePathTargetPositions (vehicleID, ref vehicleData, vector2, vector, 0, ref leaderData, ref num3, 1, 4, 4f, 1f);
}
}
示例11: 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 {
//.........这里部分代码省略.........
示例12: 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;
//.........这里部分代码省略.........