public void Init(List <RailSegment> lastSegments) { LastSegments = lastSegments; RailPosition = new RailPathPosition(LastSegments[0], 0f); UpcomingSegments = new List <RailSegment>(); UpcomingSegments.Add(RailPosition.Segment); // Init upcoming segments while (UpcomingSegments.Count < UpcomingSegmentsLength) { RailSegment furthest = null; RailSegment secondFurthest = null; if (UpcomingSegments.Count == 1) { furthest = RailPosition.Segment; secondFurthest = LastSegments[1]; } else { furthest = UpcomingSegments[UpcomingSegments.Count - 1]; secondFurthest = UpcomingSegments[UpcomingSegments.Count - 2]; } UpcomingSegments.Add(furthest.GetNextSegment(secondFurthest)); } UpdatePosition(); }
public void SpawnRail(float density, float size, float spawnAngleDiff, int segIndex, float killTime = 15f) { var isCorrupted = UnityEngine.Random.value <= corruptedRailOverrideChance; if (isCorrupted || Perlin.Noise01(Time.time * 5 + seed) <= density) { RailSegment r = CreateRailSegment(size, spawnAngleDiff, segIndex, killTime: killTime); if (isCorrupted) { r.SetCorrupted(true); corruptedRailOverrideChance *= 0.5f; } else { r.SetCorrupted(false); corruptedRailOverrideChance = 0; } } else { previousRailSegment = null; Vector2 rd = (transform.position - lastRailSpawnPosition).normalized; Vector2 normal = rd.Rotate(90); Debug.DrawRay(transform.position, normal, Color.blue, 3f); nodes.Add(new RailNode(segIndex, 0, transform.position, rd, normal, isCorrupted, false)); lastRailSpawnPosition = transform.position; } }
public void DrawPath() { GameObject railPath = new GameObject("RailPath"); // Draw segments for (int i = 1; i < PathPoints.Count; i++) { RailSegment newSegment = RailSegmentMeshGenerator.GenerateRailSegment(railPath, PathPoints[i - 1], PathPoints[i], RailSettings); newSegment.Init(PathPoints[i - 1], PathPoints[i], RailSettings); RailSegments.Add(newSegment); } // Init segment connections foreach (RailPathPoint rpp in PathPoints) { foreach (RailSegment rs1 in rpp.Segments) { foreach (RailSegment rs2 in rpp.Segments) { if (rs1 != rs2 && !rs1.ConnectedSegments.Contains(rs2) && !rs2.ConnectedSegments.Contains(rs1)) { rs1.ConnectedSegments.Add(rs2); rs2.ConnectedSegments.Add(rs1); } } } } }
public void SpawnCorruptedRail(float size, float spawnAngleDiff, int segIndex) { RailSegment r = CreateRailSegment(size, spawnAngleDiff, segIndex, true); r.SetCorrupted(true); corruptedRailOverrideChance = 0.8f; previousRailSegment = r; }
/// <summary> /// Returns the segment in the direction when coming from "previousSegment" /// </summary> public RailSegment GetNextSegment(RailSegment previousSegment) { // can only handle straights foreach (RailSegment segment in ConnectedSegments) { if (segment != previousSegment) { return(segment); } } return(null); }
private RailSegment CreateRailSegment(float size, float spawnAngleDiff, int segIndex, bool corrupted = false, float killTime = 15f) { RailSegment r = RailSegment.Create(); r.parentRail = this; r.Init(killTime); var newNodes = r.CalculateNodes(size, spawnAngleDiff, lastRailSpawnPosition, this.transform.position, corrupted, segIndex); nodes.AddRange(newNodes); RailSegmentPositions.Add(transform.position); previousRailSegment = r; lastRailSpawnPosition = transform.position; return(r); }
public static RailSegment Create() { var name = "Rail-Segment"; PoolManager pm = PoolManager.Instance; if (!pm.ContainsKey(name)) { RailSegment prefab = Resources.Load <RailSegment>($"Prefabs/{name}"); prefab.Key = name; pm.CreatePool(prefab); } RailSegment seg = pm.Next <RailSegment>(name); return(seg); }
public void SpawnRailWithRechargeMarker(float size, float spawnAngleDiff, int segIndex) { RailSegment r = CreateRailSegment(size, spawnAngleDiff, segIndex); r.SetCorrupted(false); OnRailRechargeMarker marker = OnRailRechargeMarker.Create(); marker.Init(); RailNode n = r.Nodes[r.Nodes.Length / 2]; marker.transform.position = new Vector3(n.Position.x, n.Position.y, -1f); marker.transform.localRotation = Quaternion.Euler(0, 0, Utils.VectorToAngle(n.Direction)); marker.AttachedRailSegment = r; r.RechargeMarker = marker; previousRailSegment = r; }
public void SetRailSegment(Transform position = null) { if (position) { for (int i = 0; i < segments.Count; i++) { if (segments[i].distance > Vector3.Distance(segments[i].firstEndPoint.position, position.position)) { currentSegmentIndex = i; currentSegment = segments[i]; break; } } } else { currentSegment = segments[currentSegmentIndex]; } }
public static RailSegment GenerateRailSegment(GameObject railPathObject, RailPathPoint p1, RailPathPoint p2, RailSettings settings) { GameObject railSegmentObject = new GameObject("RailSegment"); railSegmentObject.transform.SetParent(railPathObject.transform); RailSegment railSegment = railSegmentObject.AddComponent <RailSegment>(); Vector3 toVector = p2.Position - p1.Position; Vector3 toVectorPpc = (Quaternion.Euler(0, 90, 0) * new Vector3(toVector.x, 0f, toVector.z)).normalized; // PPC = perpendicular (90°) Vector3 fromVector = p1.PreviousPoint != null ? p1.Position - p1.PreviousPoint.Position : toVector; Vector3 fromVectorPpc = (Quaternion.Euler(0, 90, 0) * new Vector3(fromVector.x, 0f, fromVector.z)).normalized; float offsetLeft = -(settings.TrackGap / 2 + settings.TrackWidth); float offsetRight = settings.TrackGap / 2; GenerateTrack(railSegmentObject, p1, p2, settings, fromVectorPpc, toVectorPpc, offsetLeft); GenerateTrack(railSegmentObject, p1, p2, settings, fromVectorPpc, toVectorPpc, offsetRight); GeneratePlank(railSegmentObject, p1, p2, settings, toVector, toVectorPpc); return(railSegment); }
public int GetTargetIndex(RailSegment rs, Vector3 collisionPosition) { return(GetTargetFromNodes(rs.Nodes, collisionPosition)); }
static void Main(string[] args) { // // PING REQUEST // String payload = "this my payload; there are many like it but this one is mine"; String someTraceId = "doesntmatter-8176"; String originApp = "UAPI"; //set up the request parameters into a PingReq object PingReq req = new PingReq(); req.Payload = payload; req.TraceId = someTraceId; UAPIConsumptionSamples.SystemService.BillingPointOfSaleInfo billSetInfo = new UAPIConsumptionSamples.SystemService.BillingPointOfSaleInfo(); billSetInfo.OriginApplication = originApp; req.BillingPointOfSaleInfo = billSetInfo; req.TargetBranch = CommonUtility.GetConfigValue(ProjectConstants.G_TARGET_BRANCH); Console.WriteLine(req); try { //run the ping request //WSDLService.sysPing.showXML(true); SystemPingPortTypeClient client = new SystemPingPortTypeClient("SystemPingPort", WsdlService.SYSTEM_ENDPOINT); //Console.WriteLine(client.Endpoint); client.ClientCredentials.UserName.UserName = Helper.RetrunUsername(); client.ClientCredentials.UserName.Password = Helper.ReturnPassword(); /*var httpHeaders = new Dictionary<string, string>(); * httpHeaders.Add("Username", "travelportsuperadmin"); * httpHeaders.Add("Password", "abc123"); * client.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders));*/ /*HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty(); * httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " + * Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + * ":" + client.ClientCredentials.UserName.Password)); * * using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) * { * OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = * httpRequestProperty; * return client.processRequest(castRequest) as TSRsp; * } * * * OperationContext.Current.OutgoingMessageProperties*/ var httpHeaders = Helper.ReturnHttpHeader(); client.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); //String soapMsg = Helper.ObjectToSOAP(req); PingRsp rsp = client.service(req); //print results.. payload and trace ID are echoed back in response Console.WriteLine(rsp.Payload); //Console.WriteLine(rsp.TraceId); //Console.WriteLine(rsp.TransactionId); } catch (Exception e) { //usually only the error message is useful, not the full stack //trace, since the stack trace in is your address space... Console.WriteLine("Error : " + e.Message); } VehicleSvcTest vehicleTest = new VehicleSvcTest(); vehicleTest.ProcessVehicleFlow(); RailSvcTest railtest = new RailSvcTest(); RailAvailabilitySearchRsp railSearchRsp = railtest.ProcessRailFlow(); if (railSearchRsp != null) { RailPricingSolution lowestPrice = new RailPricingSolution() { TotalPrice = "0" }; List <RailJourney> journey = new List <RailJourney>(); List <RailSegment> selectedSegmentList = new List <RailSegment>(); List <RailFare> railFareList = new List <RailFare>(); List <RailBookingInfo> bookingInfoList = new List <RailBookingInfo>(); if (railSearchRsp.RailPricingSolution != null && railSearchRsp.RailPricingSolution.Count <RailPricingSolution>() > 0) { IEnumerator <RailPricingSolution> railPricingSoltionList = railSearchRsp.RailPricingSolution.ToList().GetEnumerator(); while (railPricingSoltionList.MoveNext()) { RailPricingSolution railPriceSol = railPricingSoltionList.Current; if (Helper.ReturnValue(lowestPrice.TotalPrice) == 0) { lowestPrice = railPriceSol; } else if (Helper.ReturnValue(railPriceSol.TotalPrice) < Helper.ReturnValue(lowestPrice.TotalPrice)) { lowestPrice = railPriceSol; } } if (Helper.ReturnValue(lowestPrice.TotalPrice) > 0) { IEnumerator <RailJourney> journeyList = railSearchRsp.RailJourneyList.ToList().GetEnumerator(); IEnumerator journeyRefList = lowestPrice.Items.GetEnumerator(); while (journeyRefList.MoveNext()) { RailJourneyRef j = (RailJourneyRef)journeyRefList.Current; while (journeyList.MoveNext()) { RailJourney currJourney = journeyList.Current; if (j.Key.CompareTo(currJourney.Key) == 0) { journey.Add(currJourney); } } } } IEnumerator <RailJourney> railJourneyList = journey.GetEnumerator(); IEnumerator <RailSegment> railSegmentList = railSearchRsp.RailSegmentList.ToList().GetEnumerator(); while (railJourneyList.MoveNext()) { RailJourney railJourney = railJourneyList.Current; IEnumerator segmentRefList = railJourney.Items.GetEnumerator(); while (segmentRefList.MoveNext()) { RailSegmentRef segRef = (RailSegmentRef)segmentRefList.Current; while (railSegmentList.MoveNext()) { RailSegment segment = railSegmentList.Current; if (segRef.Key.CompareTo(segment.Key) == 0) { selectedSegmentList.Add(segment); } } } } IEnumerator <RailPricingInfo> railPriceInfoList = lowestPrice.RailPricingInfo.ToList().GetEnumerator(); IEnumerator <RailFare> railFares = railSearchRsp.RailFareList.ToList().GetEnumerator(); while (railPriceInfoList.MoveNext()) { RailPricingInfo priceInfo = railPriceInfoList.Current; IEnumerator fareList = priceInfo.Items.ToList().GetEnumerator(); while (fareList.MoveNext()) { RailFareRef fareRef = (RailFareRef)fareList.Current; while (railFares.MoveNext()) { RailFare fare = railFares.Current; if (fareRef.Key.CompareTo(fare.Key) == 0) { railFareList.Add(fare); } } } IEnumerator <RailBookingInfo> infoList = priceInfo.RailBookingInfo.ToList().GetEnumerator(); while (infoList.MoveNext()) { RailBookingInfo bookingInfo = infoList.Current; bookingInfoList.Add(bookingInfo); } } } railtest.ProcessRailBookFlow(lowestPrice, journey, selectedSegmentList, railFareList, bookingInfoList); } }
public void SetPosition(RailPathPosition position) { Segment = position.Segment; Distance = position.Distance; }
public float Distance; // The distance on the segment (is always between 0 and RailPathGenerator.RailSegmentLength) public RailPathPosition(RailSegment segment, float distance) { Segment = segment; Distance = distance; }
private void UpdateAdjacentSegments(RailSegment newSegment) { if (newSegment == RailPosition.Segment) { throw new System.Exception("UpdateAdjacentSegments was called even though the current segment didn't change!"); } if (UpcomingSegments.Contains(newSegment) && LastSegments.Contains(newSegment)) { throw new System.Exception("New segment found in both last and upcoming segments, that doesn't make any sense."); } if (!UpcomingSegments.Contains(newSegment) && !LastSegments.Contains(newSegment)) { throw new System.Exception("New segment was not found in either last or upcoming segments."); } // Segment is an upcoming one => train going forwards if (UpcomingSegments.Contains(newSegment)) { // Handle passed segments int segmentIndex = UpcomingSegments.IndexOf(newSegment); for (int i = 0; i < segmentIndex; i++) { UpcomingSegments.RemoveAt(0); LastSegments.Insert(0, UpcomingSegments[0]); } // Adjust length of last segments while (LastSegments.Count > LastSegmentsLength) { LastSegments.RemoveAt(LastSegments.Count - 1); } // Adjust length of upcoming segments while (UpcomingSegments.Count < UpcomingSegmentsLength) { RailSegment furthest = UpcomingSegments[UpcomingSegments.Count - 1]; RailSegment secondFurthest = UpcomingSegments[UpcomingSegments.Count - 2]; UpcomingSegments.Add(furthest.GetNextSegment(secondFurthest)); } } // Segment is a past one => train going backwards else if (LastSegments.Contains(newSegment)) { int segmentIndex = LastSegments.IndexOf(newSegment); for (int i = 0; i < segmentIndex; i++) { LastSegments.RemoveAt(0); UpcomingSegments.Insert(0, LastSegments[0]); } // Adjust length of last segments while (LastSegments.Count < LastSegmentsLength) { RailSegment last = LastSegments[LastSegments.Count - 1]; RailSegment secondLast = LastSegments[LastSegments.Count - 2]; LastSegments.Add(last.GetNextSegment(secondLast)); } // Adjust length of upcoming segments while (UpcomingSegments.Count > UpcomingSegmentsLength) { UpcomingSegments.RemoveAt(UpcomingSegments.Count - 1); } } }