private SegmentAIPath Create(AISegment segment, LaneDescription laneDescription, ref float offset, byte id) { var path = new SegmentAIPath(segment, laneDescription, offset + laneDescription.Width / 2, id); offset += path.Lane.Width; return(path); }
public void ReadFromFile(BinaryReader reader) { unk02 = reader.ReadInt32(); unk03 = reader.ReadInt32(); unk04 = reader.ReadInt16(); int nameSize = reader.ReadInt16(); preFileName = new string(reader.ReadChars(nameSize)); unk05 = reader.ReadInt32(); nameSize = reader.ReadInt16(); unkString1 = new string(reader.ReadChars(nameSize)); nameSize = reader.ReadInt16(); unkString2 = new string(reader.ReadChars(nameSize)); nameSize = reader.ReadInt16(); typeName = new string(reader.ReadChars(nameSize)); unk06 = reader.ReadByte(); if (unk06 != 1) { throw new Exception("unk06 was not 1"); } int unkCount = reader.ReadInt32(); segments = new AISegment[unkCount]; for (int i = 0; i != unkCount; i++) { segments[i] = new AISegment(reader); } originFile = Functions.ReadString(reader); trailingBytes = reader.ReadBytes(8); }
public SegmentAIPath(AISegment segment, LaneDescription laneDescription, float offset, byte id) { this.segment = segment; this.laneDescription = laneDescription; this.offset = offset; this.agents = new LinkedAgentChain(); }
public SegmentAIRoute[] CreateRoutes(AISegment segment) { var lanes = segment.Description.Lanes; var paths = new SegmentAIPath[lanes.Length]; float offset = -lanes.Sum(l => l.Width) / 2; for (byte i = 0; i < paths.Length; i++) { var path = Create(segment, lanes[i], ref offset, i); if (i > 0) { if (paths[i - 1].Reverse == path.Reverse) { SegmentAIPath.ConnectParralel(paths[i - 1], path); } } paths[i] = path; } return(paths.GroupBy(t => t.Reverse).Select(t => new SegmentAIRoute(segment, t.ToArray(), t.Key)).ToArray()); }
public TestRoads() { this.aiRoadManager = new AIRoadManager(); this.n_0_0 = aiRoadManager.CreateNodeAt(0, 0); this.n_10_0 = aiRoadManager.CreateNodeAt(10, 0); this.n_20_0 = aiRoadManager.CreateNodeAt(20, 0); this.n_20_10 = aiRoadManager.CreateNodeAt(20, 10); this.n_30_0 = aiRoadManager.CreateNodeAt(30, 0); this.n_30_10 = aiRoadManager.CreateNodeAt(30, 10); this.n_40_0 = aiRoadManager.CreateNodeAt(40, 0); this.n_50_0 = aiRoadManager.CreateNodeAt(50, 0); this.seg_0_0_10_0 = aiRoadManager.CreateSegment(n_0_0, n_10_0, highway3Lanes); this.seg_10_0_20_10 = aiRoadManager.CreateSegment(n_10_0, n_20_10, highway3Lanes); this.seg_10_0_20_0 = aiRoadManager.CreateSegment(n_10_0, n_20_0, singleDirtTrack); this.seg_20_10_30_10 = aiRoadManager.CreateSegment(n_20_10, n_30_10, highway3Lanes); this.seg_20_0_30_0 = aiRoadManager.CreateSegment(n_10_0, n_20_0, singleDirtTrack); this.seg_30_10_40_0 = aiRoadManager.CreateSegment(n_30_10, n_40_0, highway3Lanes); this.seg_30_0_40_0 = aiRoadManager.CreateSegment(n_10_0, n_20_0, singleDirtTrack); this.seg_40_0_50_0 = aiRoadManager.CreateSegment(n_30_10, n_40_0, highway3Lanes); }
public SegmentAIRoute(AISegment segment, SegmentAIPath[] segmentAIPath, bool reverse) { this.Segment = segment; this.Paths = segmentAIPath; this.Reverse = reverse; }
public void Save() { if (string.IsNullOrEmpty(path)) { return; } const int offset = 0x04; int byteLength = offset + 0x4C * segments.Count; byte[] data = new byte[byteLength]; BitConverter.GetBytes((short)segments.Count).CopyTo(data, 0); for (int i = 0; i < segments.Count; i++) // Fill reverse node connections with null index { int dp = i * 0x4C + offset; BitConverter.GetBytes(-1).CopyTo(data, dp + 0x1C); BitConverter.GetBytes(-1).CopyTo(data, dp + 0x20); } for (int i = 0; i < segments.Count; i++) { AISegment segment = segments[i]; int dp = i * 0x4C + offset; data[dp] = (byte)segment.priority; if (segment.start) { data[dp + 0x01]++; } data[dp + 0x02] = data[dp + 0x03] = (byte)segment.walls; // Value is doubled in file for some reason, but just to be safe BitConverter.GetBytes(segment.raceLine).CopyTo(data, dp + 0x04); BitConverter.GetBytes(segment.altRaceLine).CopyTo(data, dp + 0x0C); BitConverter.GetBytes(segment.raceSpeed).CopyTo(data, dp + 0x14); BitConverter.GetBytes(segment.centerSpeed).CopyTo(data, dp + 0x18); if (segment.connectedIndexes[0] != -1) { int c0dp = segment.connectedIndexes[0] * 0x4C + offset; if (BitConverter.ToInt32(data, c0dp + 0x1C) == -1) { BitConverter.GetBytes(i).CopyTo(data, c0dp + 0x1C); } else { BitConverter.GetBytes(i).CopyTo(data, c0dp + 0x20); } } if (segment.connectedIndexes[1] != -1) { int c1dp = segment.connectedIndexes[1] * 0x4C + offset; if (BitConverter.ToInt32(data, c1dp + 0x1C) == -1) { BitConverter.GetBytes(i).CopyTo(data, c1dp + 0x1C); } else { BitConverter.GetBytes(i).CopyTo(data, c1dp + 0x20); } } BitConverter.GetBytes(segment.connectedIndexes[0]).CopyTo(data, dp + 0x24); BitConverter.GetBytes(segment.connectedIndexes[1]).CopyTo(data, dp + 0x28); BitConverter.GetBytes(segment.rightSpeed).CopyTo(data, dp + 0x2C); BitConverter.GetBytes(segment.right.x * 100).CopyTo(data, dp + 0x30); BitConverter.GetBytes(segment.right.y * -100).CopyTo(data, dp + 0x34); BitConverter.GetBytes(segment.right.z * 100).CopyTo(data, dp + 0x38); BitConverter.GetBytes(segment.leftSpeed).CopyTo(data, dp + 0x3C); BitConverter.GetBytes(segment.left.x * 100).CopyTo(data, dp + 0x40); BitConverter.GetBytes(segment.left.y * -100).CopyTo(data, dp + 0x44); BitConverter.GetBytes(segment.left.z * 100).CopyTo(data, dp + 0x48); } File.WriteAllBytes(path, data); }
private static IEnumerable <SegmentAIRoute> GetRoutes(bool isEnd, AISegment segment) { return(segment?.AIRoutes.Where(t => t.Reverse != isEnd)); }