} //Constructor public override MapGenerator.MapData Generate(MapGenerator.RoomsDataCollection rooms, int mapWidth, int mapHeight) { // Make sure there is rooms and map data, if not then ... exit. if (rooms == null || rooms.Count == 0 || mapWidth <= 0 || mapHeight <= 0) { return(null); } // Clear and resize the map. MapGenerator.MapData results = new MapGenerator.MapData(mapWidth, mapHeight); // Create the instance to the randomizer. MapHelpers.SetRandomSeed(this.Options.Seed); // (Step 1) Fill the map with random matching tiles. FillWithRandomTiles(results, rooms, this.Options.IgnoreBoundries, this.Options.SubsetID, this.Options.IncludeRooms, this.Options.IncludePassages, this.Options.Pattern); // (Step 2) Decide what to do with the unconnected tiles ... if (this.Options.UnconnectedTilesAction == UnconnectedTilesActions.ConnectAll) { // ... Connect all unconnected tiles. MapHelpers.ConnectPathsets(results, rooms, this.Options.IgnoreBoundries, this.Options.SubsetID); } else if (this.Options.UnconnectedTilesAction == UnconnectedTilesActions.RemoveSmallerSets) { // ... Remove all unconnected tiles. MapHelpers.RemoveAllSmallPathSets(results); } // Remove the map data. return(results); } //Generate
public void AnimateMarker(double duration, LatLng startPosition, List <LatLng> wayPoints, int position) { if (wayPoints == null || !wayPoints.Any() || duration == 0) { return; } if (!isInit) { totalDuration = duration; totalDistance = CalculatorDistance(startPosition, wayPoints); isInit = true; } Handler handler = new Handler(); long start = SystemClock.UptimeMillis(); var interpolator = new LinearInterpolator(); var nextLocation = wayPoints[position]; var nextDuration = MapHelpers.GetDistance(startPosition.Latitude, startPosition.Longitude, nextLocation.Latitude, nextLocation.Longitude) * 1.0 / totalDistance * totalDuration; handler.Post(new MoveRunnable(_mMap, handler, interpolator, _mMarker, start, startPosition, nextLocation, nextDuration, () => { position++; if (wayPoints.Count > position) { AnimateMarker(duration, _mMarker.Position, wayPoints, position); } else { _mMarker.Remove(); } })); }
/// <summary> /// Create zone geometry. /// </summary> /// <param name="zone">Zone for creating geometry.</param> /// <returns>Created geometry.</returns> private ESRI.ArcGIS.Client.Geometry.Geometry _CreateGeometry(Zone zone) { ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; if (zone.Geometry != null) { if (zone.Geometry is ESRI.ArcLogistics.Geometry.Point?) { ESRI.ArcLogistics.Geometry.Point?point = zone.Geometry as ESRI.ArcLogistics.Geometry.Point?; geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(point.Value.X, point.Value.Y); } else { int?spatialReference = null; if (ParentLayer != null) { spatialReference = ParentLayer.SpatialReferenceID; } geometry = MapHelpers.ConvertToArcGISPolygon( zone.Geometry as ESRI.ArcLogistics.Geometry.Polygon, spatialReference); } } else { geometry = null; } return(geometry); }
/// <summary> /// React on scalebar widget loaded. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> private void ScaleBarWidget_Loaded(object sender, RoutedEventArgs e) { if (Map != null && this.Map.IsInitialized() && Map.ScaleBarUnits.HasValue) { ScaleBarWidget.MapUnit = MapHelpers.ConvertScalebarUnits(Map.ScaleBarUnits.Value); } if (RegionInfo.CurrentRegion.IsMetric) { ScaleBarWidget.DisplayUnit = ESRI.ArcGIS.Client.ScaleBarUnit.Kilometers; } else { ScaleBarWidget.DisplayUnit = ESRI.ArcGIS.Client.ScaleBarUnit.Miles; } if (!_isInited) { // Check that application is ArcLogistics. So it is possible to load map control in visual studio designer. if (Application.Current is ESRI.ArcLogistics.App.App) { ScaleBarWidget.Style = (Style)Application.Current.FindResource("ScaleBarStyleKey"); } } }
/// <summary> /// End Edit. /// </summary> public void EditEnded() { Debug.Assert(IsInEditedMode); if (EditedObject is Route || EditedObject is Stop) { EditedObject = null; return; } SetOpacityToLayers(FULL_OPACITY); if (_clustering != null) { _clustering.ClusteringLayer.Selectable = true; } // Find graphic, which represents edited item. Graphic graphic = MapHelpers.GetGraphicByDataItem(EditedObject, _objectLayers); EditedObject = null; _tools.EndEdit(graphic); // Show graphic which represents edited item. ((DataGraphicObject)graphic).IsVisible = true; }
} //Constructor public override MapGenerator.MapData Generate(MapGenerator.RoomsDataCollection rooms, int mapWidth, int mapHeight) { // Make sure there are rooms and there is map data, if not then ... return failure. if (rooms == null || rooms.Count == 0 || mapWidth <= 0 || mapHeight <= 0) { return(null); } // Resize the map to what we need. MapGenerator.MapData results = new MapGenerator.MapData(mapWidth, mapHeight); // Create the instance to the randomizer. MapHelpers.SetRandomSeed(this.Options.Seed); // (Step 1) Place the initial rooms to start out with. MapHelpers.PlotRandomRooms(results, rooms, MapHelpers.ComputeRandomRoomsCount(mapWidth, mapHeight, this.Options.RandomRoomsPercentage), this.Options.IgnoreBoundries, this.Options.SubsetID, this.Options.IncludeRooms, !this.Options.IncludeRooms, this.Options.Pattern, true); // (Step 2) Create the passages to connect each room together. MapHelpers.ConnectPathsets(results, rooms, this.Options.IgnoreBoundries, this.Options.SubsetID); // (Step 3) if(there is any left over path sets, remove them. //MapHelpers.RemoveAllSmallPathSets(results) // Remove the map data. return(results); } //Generate
public CastleByDistanceModel GetNearestCastle(List <string> castles, double lat, double lng) { return(Castles.Where(c => castles.Contains(c.Id)).Select(c => new CastleByDistanceModel { Castle = c, Distance = MapHelpers.GetDistance(c.Position.Lat, c.Position.Lng, lat, lng) }).OrderBy(d => d.Distance).First()); }
} //Generate private static void FillWithRandomTiles(MapGenerator.MapData map, MapGenerator.RoomsDataCollection rooms, bool ignoreBoundries = false, string subSetID = "", bool allowRooms = true, bool allowPassages = true, Bitmap pattern = null) { for (int row = 1; row <= map.Height; row++) { for (int column = 1; column <= map.Width; column++) { MapHelpers.PlotRandomRoom(map, rooms, column, row, ignoreBoundries, subSetID, allowRooms, allowPassages, pattern, false); } //column } //row } //FillWithRandomTiles
// server recieving entitymove means its a player moving public void OnEntityMovePacket(EntityMovePacket packet) { var player = Server.GetPlayerByConnectionId(packet.ClientId); var distanceMoved = MapHelpers.GetDistance(player.Position, packet.To); var timeToMove = Formulas.GetTimeToMoveBetweenTwoTiles(player.MoveSpeed); Log.Info("TIME TO MOVE " + timeToMove); var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; // Player tryng to hack ? if (distanceMoved > 1 || now < player.CanMoveAgainTime) { Log.Debug($"Player time to move {player.CanMoveAgainTime - now}"); // send player back to the position client-side player.Tcp.Send(new SyncPacket() { Position = player.Position }); return; } // subtract the player latency for possibility of lag for a smoother movement player.CanMoveAgainTime = now + timeToMove - player.Tcp.Latency; var entityMoveEvent = new EntityMoveEvent() { From = packet.From, To = packet.To, Entity = player }; Server.Events.Call(entityMoveEvent); if (entityMoveEvent.IsCancelled) { // send player back to the position client-side player.Tcp.Send(new SyncPacket() { Position = player.Position }); return; } // Updating player position locally player.Position.X = packet.To.X; player.Position.Y = packet.To.Y; // updating in database PlayerService.UpdatePlayerPosition(player.UID, player.Position.X, player.Position.Y); }
public override void ExecuteResult(ControllerContext context) { var encoding = context.HttpContext.Response.ContentEncoding.WebName; var declaration = new XDeclaration("1.0", encoding, "yes"); var mappedElements = from sitemap in _model select MapHelpers.Map(sitemap); var content = new XElement("urlset", _namespace, mappedElements); var sitemapDocument = new XDocument(declaration, content); context.HttpContext.Response.ContentType = "application/rss+xml"; context.HttpContext.Response.Flush(); context.HttpContext.Response.Write(sitemapDocument.Declaration + sitemapDocument.ToString()); }
/// <summary> /// Create barrier geometry. /// </summary> /// <param name="barrier">Barrier.</param> /// <returns>Barrier geometry.</returns> private ESRI.ArcGIS.Client.Geometry.Geometry _CreateGeometry(Barrier barrier) { ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; if (barrier.Geometry != null) { int?spatialReference = null; if (ParentLayer != null) { spatialReference = ParentLayer.SpatialReferenceID; } if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Point) { ESRI.ArcLogistics.Geometry.Point point = (ESRI.ArcLogistics.Geometry.Point)barrier.Geometry; // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator if (ParentLayer != null && ParentLayer.SpatialReferenceID != null) { point = WebMercatorUtil.ProjectPointToWebMercator(point, spatialReference.Value); } geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(point.X, point.Y); } else if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polygon) { geometry = MapHelpers.ConvertToArcGISPolygon( barrier.Geometry as ESRI.ArcLogistics.Geometry.Polygon, spatialReference); } else if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polyline) { geometry = MapHelpers.ConvertToArcGISPolyline( barrier.Geometry as ESRI.ArcLogistics.Geometry.Polyline, spatialReference); } else { System.Diagnostics.Debug.Assert(false); } _SetSymbol(); } else { geometry = null; } return(geometry); }
private async void Map_CameraIdle(object sender, EventArgs e) { var position = map.CameraPosition.Target; string key = Resources.GetString(Resource.String.mapkey); string address = await MapHelpers.FindCordinateAddress(position, key); if (!string.IsNullOrEmpty(address)) { placeTextView.Text = address; } else { placeTextView.Text = "Incotro?"; } placeTextView.Text = address; }
private bool NeedUpdateRotation() { if (_marker == null) { return(false); } if (_lastUpdatedLocation == null) { return(true); } if (MapHelpers.GetDistance(_marker.Position.Latitude, _marker.Position.Longitude, _lastUpdatedLocation.Latitude, _lastUpdatedLocation.Longitude) * 1000 > 3) { return(true); } return(false); }
public void GenerateMap(Tilemap tilemap, TileBase tile) { tilemap.ClearAllTiles(); if (randomSeed) { seed = Random.Range(0f, 10f); } int[,] map = new int[width, height]; map = MapHelpers.GenerateArray(width, height, true); Debug.Log("GenerateArray:\n" + LogMap(map)); map = MapHelpers.PerlinNoise(map, seed); Debug.Log("PerlinNoise:\n" + LogMap(map)); MapHelpers.RenderMap(map, tilemap, tile); }
public static void CheckChunks(this OnlinePlayer player) { var client = player.Tcp; if (client.OnlinePlayer != null && client.OnlinePlayer.AssetsReady) { var chunkX = client.OnlinePlayer.Position.X >> 4; var chunkY = client.OnlinePlayer.Position.Y >> 4; var shouldBeLoaded = MapHelpers.GetSquared3x3(new Position(chunkX, chunkY)); foreach (var position in shouldBeLoaded) { var chunkKey = $"{position.X}_{position.Y}"; if (!client.ChunksLoaded.Contains(chunkKey)) { if (Server.Map.Chunks.ContainsKey(chunkKey)) { client.ChunksLoaded.Add(chunkKey); var chunk = Server.Map.Chunks[chunkKey]; client.Send(new ChunkPacket() { X = position.X, Y = position.Y, ChunkData = chunk.GetData() }); foreach (var entity in chunk.EntitiesInChunk[EntityType.MONSTER]) { var monsterInstance = (Monster)entity; client.Send(new MonsterSpawnPacket() { MonsterUid = monsterInstance.UID, MonsterName = monsterInstance.Name, Position = monsterInstance.Position, SpriteIndex = monsterInstance.GetSpriteAsset().SpriteRowIndex, MoveSpeed = monsterInstance.MoveSpeed, SpawnAnimation = false }); } } } } } }
public List <OnlinePlayer> GetNearbyPlayers() { List <OnlinePlayer> near = new List <OnlinePlayer>(); var radius = MapHelpers.GetSquared3x3(new Position(Position.X >> 4, Position.Y >> 4)); foreach (var position in radius) { var chunkThere = Server.Map.GetChunk(position.X, position.Y); if (chunkThere != null) { foreach (var playerInChunk in chunkThere.PlayersInChunk) { near.Add(playerInChunk); } } } return(near); }
private double CalculatorDistance(LatLng start, List <LatLng> wayPoints) { if (!(wayPoints?.Any() ?? false)) { return(0); } double distance = 0; var startLocation = start; for (int i = 0; i < wayPoints.Count; i++) { var nextLocation = wayPoints[i]; distance += MapHelpers.GetDistance(startLocation.Latitude, startLocation.Longitude, nextLocation.Latitude, nextLocation.Longitude); startLocation = nextLocation; } return(distance); }
public static List <OnlinePlayer> GetPlayersNear(this Entity player) { List <OnlinePlayer> near = new List <OnlinePlayer>(); var chunk = player.GetChunk(); var radius = MapHelpers.GetSquared3x3(new Position(chunk.x, chunk.y)); foreach (var position in radius) { var chunkThere = Server.Map.GetChunk(position.X, position.Y); if (chunkThere != null) { foreach (var playerInChunk in chunkThere.PlayersInChunk) { if (playerInChunk.UID != player.UID) { near.Add(playerInChunk); } } } } return(near); }
private void SetRoute() { if (_goingToPosition != null && _movingToDirection == Direction.NONE) { _movingToDirection = MapHelpers.GetDirection(MapPosition, _goingToPosition); var timeToMove = (float)Formulas.GetTimeToMoveBetweenTwoTiles(MoveSpeed); SetDestination(new Vector3(_goingToPosition.X * 16, _goingToPosition.Y * 16, 0), timeToMove / 1000); SpriteSheets.ForEach(e => e.Direction = _movingToDirection); SpriteSheets.ForEach(e => e.Moving = true); UnityClient.Map.EntityPositions.RemoveEntity(EntityWrapper, MapPosition); MapPosition.X = _goingToPosition.X; MapPosition.Y = _goingToPosition.Y; UnityClient.Map.EntityPositions.RemoveEntity(EntityWrapper, MapPosition); _goingToPosition = null; } }
public virtual ActionResult Sitemap() { var model = new SitemapModel(new[] { MapHelpers.Map(Url, MVC.Product.List(null, null, null, null, null)) }); var categories = _categoryRepository.GetAll(); var products = _productRepository.GetAll(); foreach (var sitemap in categories.ToList().Select(c => MapHelpers.Map(Url, c))) { model.Add(sitemap); } foreach (var sitemap in products.ToList().Select(p => MapHelpers.Map(Url, p))) { model.Add(sitemap); } model.Add(MapHelpers.Map(Url, MVC.Home.Sitemap())); return(Sitemap(model)); }
private void PerformNextStep() { var player = UnityClient.Player; if (_nextStep != null && _movingToDirection == Direction.NONE) { _movingToDirection = MapHelpers.GetDirection(player.Position, _nextStep); var moveTimeInMs = Formulas.GetTimeToMoveBetweenTwoTiles(player.Speed); var moveTimeInSeconds = (float)moveTimeInMs / 1000; var now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; _shouldArriveAt = now + moveTimeInMs; UnityClient.TcpClient.Send(new EntityMovePacket() { UID = UnityClient.Player.UID, From = UnityClient.Player.Position, To = _nextStep }); StartMovement(new Vector3(_nextStep.X * 16, _nextStep.Y * 16, 0), moveTimeInSeconds); Debug.Log("Moving Player To " + _nextStep.X + " - " + _nextStep.Y); SpriteSheets.ForEach(e => e.Direction = _movingToDirection); SpriteSheets.ForEach(e => e.Moving = true); UnityClient.Map.EntityPositions.RemoveEntity(UnityClient.Player, UnityClient.Player.Position); UnityClient.Player.Position.X = _nextStep.X; UnityClient.Player.Position.Y = _nextStep.Y; UnityClient.Map.EntityPositions.AddEntity(UnityClient.Player, UnityClient.Player.Position); _nextStep = null; } }