public void FindSingleEnemy(MySquad squad) { var myRandomUnit = _str.MyVehicles.FirstOrDefault(v => v.Groups.Contains(squad.Id)); if (myRandomUnit == null || !_str.EnemyVehicles.Any()) { return; } var nearestEnemyPoint = new MyPoint(); double distance = 10000; IEnumerable <Vehicle> targets; var fac = _str.World.Facilities.Where(f => f.OwnerPlayerId != _str.Me.Id && f.Type == FacilityType.VehicleFactory); if (!fac.Any()) { fac = _str.World.Facilities.Where(f => f.OwnerPlayerId != _str.Me.Id && f.Type == FacilityType.ControlCenter); } if (!fac.Any()) { targets = _str.EnemyVehicles.Where(v => v.Type != VehicleType.Fighter && v.Type != VehicleType.Helicopter); if (!targets.Any()) { new MyPoint(512, 512); } foreach (var vehicle in targets) { double currentDistance; try { currentDistance = vehicle.GetDistanceTo(myRandomUnit); } catch (Exception e) { continue; } if (currentDistance < distance) { distance = currentDistance; nearestEnemyPoint.X = vehicle.X; nearestEnemyPoint.Y = vehicle.Y; } } } else { foreach (var f in fac) { double currentDistance = f.Distance(myRandomUnit.X, myRandomUnit.Y); if (currentDistance < distance) { distance = currentDistance; nearestEnemyPoint.X = f.Top + 42; nearestEnemyPoint.Y = f.Left + 32; } } } _str.MainGameTasks.Enqueue(_str.Act.SelectByGroup(squad.Id)); _str.MainGameTasks.Enqueue(_str.Act.MoveToPoint(nearestEnemyPoint)); }
public MyPoint GetNearestFasility(Group group) { var squad = _str.GroupManager.Squads.Single(s => s.Id == (int)group); if (squad == null) { return(new MyPoint(500, 300)); } double distToFacility = 10000d; IEnumerable <Facility> facilities; switch (group) { case Group.LandTopR: facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.Left - v.Top >= 350); break; case Group.LandTop: facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.Left - v.Top < 350 && v.Left - v.Top >= 200); break; case Group.Tank: facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.Left - v.Top <200 && v.Left - v.Top> -200); break; case Group.LandLeft: facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.Left - v.Top <= -200 && v.Left - v.Top > -350); break; case Group.LandLeftR: facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.Left - v.Top <= -350); break; default: facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id); break; } if (facilities == null || !facilities.Any()) { if (group == Group.LandLeftR || group == Group.LandTopR) { if (group == Group.LandLeftR) { facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.VehicleType != VehicleType.Tank && v.Left < v.Top); } else { facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id && v.VehicleType != VehicleType.Tank && v.Left >= v.Top); } } else { facilities = _str.World.Facilities.Where(v => v.OwnerPlayerId != _str.Me.Id); } } if (facilities == null || !facilities.Any()) { if (group != Group.LandLeftR && group != Group.LandTopR) { return(_str.StrategyController.FindSingleEnemy((int)group)); } } MyPoint point = new MyPoint(0, 0); foreach (var facility in facilities) { var distToCurrentFacility = squad.Distance(facility); if (distToCurrentFacility < distToFacility) { distToFacility = distToCurrentFacility; point.X = facility.Left + 32; point.Y = facility.Top + 32; } } return(point); }