protected override void PrepareVehiclesWithStructures(SeaPortZoneClusterConsumption[] structures) { int desiredAmountOfShips = structures.Count() * AmountOfShipsPerHarbour; var candidates = _candidatesCache.GetValue(); if (candidates == null) { return; } while (NewShipCanBeInserted && Vehicles.Count() < desiredAmountOfShips && Vehicles.All(x => x.IsReadyAndMoving)) { var candidate = GetZoneInfosFunc() .Where(IsSuitableForShip) .OrderBy(x => Random.Next()) .FirstOrDefault(); if (candidate != null) { AddVehicle(new Ship(GetZoneInfosFunc, candidate, _shipSpeedInMilliSeconds, _maxDistance)); _lastShipInsertion = DateTime.Now; } else { return; } } }
public bool IsValid() { if (Vehicles != null) { if (Vehicles.Count(v => !v.IsValid()) > 0) { return(false); } } if (Drivers != null) { if (Drivers.Count(d => !d.IsValid()) > 0) { return(false); } } return(true); }
protected override void PrepareVehiclesWithStructures(AirportZoneClusterConsumption[] structures) { int desiredAmountOfPlanes = structures.Count() * 2; while (Vehicles.Count() < desiredAmountOfPlanes) { var spawnPoint = structures.OrderBy(x => Random.Next()).First(); var centralCell = spawnPoint.ZoneClusterMembers.Single(y => y.IsCentralClusterMember); centralCell.GetZoneInfo().WithResultIfHasMatch(zoneInfo => { var steerDirection = Directions.OrderBy(d => Random.Next()).First(); var alternateDirection = zoneInfo.GetSteerDirections(steerDirection).OrderBy(x => Random.Next()).First(); AddVehicle(new Airplane(GetZoneInfosFunc, zoneInfo, steerDirection, alternateDirection, Random.Next(5, 10))); }); } }
private void Redraw() { if (ShowEstimate) { BackgroundColor = Theme.CompanyColor; HorizontalDividerTop.BackgroundColor = Theme.LabelTextColor; EstimateContainer.Hidden = false; VehicleSelectionContainer.Hidden = true; if (Eta.HasValue() && ShowEta) { EstimateContainer.RemoveConstraint(_constraintEstimatedFareLabelHeight); _constraintEstimatedFareLabelHeight = _estimatedFareLabelHeightValueWithEta; EstimateContainer.AddConstraint(_constraintEstimatedFareLabelHeight); _constraintEstimatedFareLabelTop.Constant = EstimatedFareLabelTopValueWithEta; } else { EstimateContainer.RemoveConstraint(_constraintEstimatedFareLabelHeight); _constraintEstimatedFareLabelHeight = _estimatedFareLabelHeightValueWithoutEta; EstimateContainer.AddConstraint(_constraintEstimatedFareLabelHeight); _constraintEstimatedFareLabelTop.Constant = EstimatedFareLabelTopValueWithoutEta; } } else { BackgroundColor = UIColor.Clear; HorizontalDividerTop.BackgroundColor = UIColor.FromRGB(177, 177, 177); EstimateContainer.Hidden = true; VehicleSelectionContainer.Hidden = false; VehicleSelectionContainer.Subviews.ForEach(x => x.RemoveFromSuperview()); if (Vehicles.None()) { return; } var i = 0; foreach (var vehicle in Vehicles) { var vehicleView = new VehicleTypeView(new CGRect(), vehicle, SelectedVehicle != null ? vehicle.Id == SelectedVehicle.Id : false); vehicleView.TouchUpInside += (sender, e) => { if (!IsReadOnly && VehicleSelected != null) { VehicleSelected(vehicle); } }; VehicleSelectionContainer.Add(vehicleView); VehicleSelectionContainer.AddConstraints(new [] { NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, vehicleView.Superview, NSLayoutAttribute.Top, 1f, 0f), NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, vehicleView.Superview, NSLayoutAttribute.Height, 1f, 0f) }); if (i == 0) { // first vehicle VehicleSelectionContainer.AddConstraint(NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, vehicleView.Superview, NSLayoutAttribute.Left, 1f, VehicleSelectionPadding)); } else { // add constraint relative to previous vehicle VehicleSelectionContainer.AddConstraints(new [] { NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, VehicleSelectionContainer.Subviews[i - 1], NSLayoutAttribute.Right, 1f, 0f), NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, VehicleSelectionContainer.Subviews[i - 1], NSLayoutAttribute.Width, 1f, 0f) }); } if (i == (Vehicles.Count() - 1)) { // last vehicle VehicleSelectionContainer.AddConstraint(NSLayoutConstraint.Create(vehicleView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, VehicleSelectionContainer, NSLayoutAttribute.Right, 1f, -VehicleSelectionPadding)); } i++; } } _constraintEstimateVehicleWidth.Constant = EstimateSelectedVehicleType.WidthToFitLabel(); }
public override string ToString() { return(string.Format("Vehicles: {0}, LastTime: {1}", Vehicles.Count(), LastTime)); }
public void ParseFileName(string path) { var filename = Path.GetFileNameWithoutExtension(path); if (ReplayList.IsLeftDate || ReplayList.IsRightDate) { var date = File.GetLastWriteTime(path).Date; if (ReplayList.IsLeftDate && date < ReplayList.LeftDate) { throw new NotImplementedException(); } if (ReplayList.IsRightDate && date > ReplayList.RightDate) { throw new NotImplementedException(); } } var tw = filename.Split(chararray, StringSplitOptions.RemoveEmptyEntries); var mapindx = Array.FindLastIndex(tw, x => x.All(y => char.IsDigit(y))); Tank = new ArraySegment <string>(tw, 2, mapindx - 2).JoinIntoString("_"); Map = TryReplaceMap(new ArraySegment <string>(tw, mapindx, tw.Length - mapindx).JoinIntoString("_").Replace('-', ' ').Replace('_', '-')); var json = string.Empty; using (var stream = File.OpenRead(path)) { using (var br = new BinaryReader(stream)) { br.BaseStream.Position = 4; var jsonscount = br.ReadInt32(); var jsonbuilder = new StringBuilder(); for (var i = 0; i < jsonscount; i++) { jsonbuilder.Append(ANSI.GetString(br.ReadBytes(br.ReadInt32()))); } json = jsonbuilder.ToString(); } } { var damageindex = 0; do { damageindex = json.IndexOf(damageDealt, damageindex + damageDealt.Length); if (damageindex == -1) { Damage = -1; break; } var damagestr = GetNextString(12, json, damageDealt, damageindex); if (damagestr.Contains("}")) { continue; } if (damagestr == null) { Damage = -1; } else { Damage = int.Parse(damagestr.Replace("\"", "")); } break; }while (damageindex != -1); } { var gameplayidstr = GetNextString(24, json, gameplayID); var battletypestr = GetNextString(20, json, battleType); if (gameplayidstr == null || battletypestr == null) { gameplayidstr = GetNextString(24, json, gameplayID2); battletypestr = GetNextString(20, json, battleType2); } OrigMode = $"{gameplayidstr.Replace("\"", "")}_{battletypestr}"; Mode = TryReplaceMode(OrigMode); } var owntankcount = 0; var indx = 0; var count = 0; var maxcount = GetMaximumVehicles(OrigMode); do { indx = json.IndexOf(vehicleType, indx + vehicleType.Length); if (indx == -1) { break; } var tankstr = GetNextString(48, json, vehicleType, indx); if (tankstr == null) { tankstr = GetNextString(48, json, vehicleType2, indx); } var tankname = ParseTankNameFronJSON(tankstr).Replace("\"", ""); if (Tank == tankname) { owntankcount++; if (owntankcount > 1) { Vehicles.Add(tankname); } } else { Vehicles.Add(tankname); } count++; }while (indx != -1 && count < maxcount); Artys = Vehicles.Count(x => ArtysNames.Contains(x)); }