public void Setup() { var compMan = IoCManager.Resolve <IComponentManager>(); compMan.Initialize(); EntityManager = IoCManager.Resolve <IServerEntityManagerInternal>(); MapManager = IoCManager.Resolve <IMapManager>(); MapManager.Initialize(); MapManager.Startup(); MapManager.CreateMap(); var manager = IoCManager.Resolve <IPrototypeManager>(); manager.LoadFromStream(new StringReader(PROTOTYPES)); manager.Resync(); // build the net dream MapA = MapManager.CreateMap(); GridA = MapManager.CreateGrid(MapA); MapB = MapManager.CreateMap(); GridB = MapManager.CreateGrid(MapB); //NOTE: The grids have not moved, so we can assert worldpos == localpos for the test }
//TODO: This whole method should be removed once file loading/saving works, and replaced with a 'Demo' map. /// <summary> /// Generates 'Demo' grid and inserts it into the map manager. /// </summary> /// <param name="mapManager">The map manager to work with.</param> /// <param name="defManager">The definition manager to work with.</param> /// <param name="gridId">The ID of the grid to generate and insert into the map manager.</param> private static void NewDefaultMap(IMapManager mapManager, ITileDefinitionManager defManager, int gridId) { mapManager.SuppressOnTileChanged = true; try { Logger.Log("Cannot find map. Generating blank map.", LogLevel.Warning); var floor = defManager["Floor"].TileId; var wall = defManager["Wall"].TileId; Debug.Assert(floor > 0); Debug.Assert(wall > 0); var grid = mapManager.GetGrid(gridId) ?? mapManager.CreateGrid(gridId); for (var y = -32; y <= 32; ++y) { for (var x = -32; x <= 32; ++x) { if (Math.Abs(x) == 32 || Math.Abs(y) == 32 || Math.Abs(x) == 5 && Math.Abs(y) < 5 || Math.Abs(y) == 7 && Math.Abs(x) < 3) { grid.SetTile(x, y, new Tile(wall)); } else { grid.SetTile(x, y, new Tile(floor)); } } } } finally { mapManager.SuppressOnTileChanged = false; } }
public void AfterInteract(AfterInteractEventArgs eventArgs) { if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) { return; } if (!Owner.TryGetComponent(out StackComponent stack)) { return; } var location = eventArgs.ClickLocation.AlignWithClosestGridTile(); var locationMap = location.ToMap(Owner.EntityManager); var desiredTile = (ContentTileDefinition)_tileDefinitionManager[_outputTile]; if (_mapManager.TryGetGrid(location.GetGridId(Owner.EntityManager), out var mapGrid)) { var tile = mapGrid.GetTileRef(location); var baseTurf = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; if (HasBaseTurf(desiredTile, baseTurf.Name) && eventArgs.Target == null && stack.Use(1)) { PlaceAt(mapGrid, location, desiredTile.TileId); } } else if (HasBaseTurf(desiredTile, "space")) { mapGrid = _mapManager.CreateGrid(locationMap.MapId); mapGrid.WorldPosition = locationMap.Position; location = new EntityCoordinates(mapGrid.GridEntityId, Vector2.Zero); PlaceAt(mapGrid, location, desiredTile.TileId, mapGrid.TileSize / 2f); } }
/// <summary> /// Deserializes an IMapManager and ITileDefinitionManager from a properly formatted NetMessage. /// </summary> /// <param name="message">The message containing a serialized map and tileDefines.</param> private void HandleTileMap(MsgMap message) { Debug.Assert(_netManager.IsClient, "Why is the server calling this?"); var mapIndex = message.MapIndex; _defManager.RegisterServerTileMapping(message); var chunkSize = message.ChunkSize; var chunkCount = message.ChunkDefs.Length; if (!_mapManager.TryGetGrid(mapIndex, out IMapGrid grid)) { grid = _mapManager.CreateGrid(mapIndex, chunkSize); } for (var i = 0; i < chunkCount; ++i) { var chunkPos = new MapGrid.Indices(message.ChunkDefs[i].X, message.ChunkDefs[i].Y); var chunk = grid.GetChunk(chunkPos); var counter = 0; for (ushort x = 0; x < chunk.ChunkSize; x++) { for (ushort y = 0; y < chunk.ChunkSize; y++) { chunk.SetTile(x, y, (Tile)message.ChunkDefs[i].Tiles[counter]); counter++; } } } }
public void Setup() { EntityManager = IoCManager.Resolve <IClientEntityManager>(); MapManager = IoCManager.Resolve <IMapManager>(); var manager = IoCManager.Resolve <IPrototypeManager>(); manager.LoadFromStream(new StringReader(PROTOTYPES)); manager.Resync(); // build the net dream MapA = MapManager.CreateMap(); GridA = MapManager.CreateGrid(MapA); MapB = MapManager.CreateMap(); GridB = MapManager.CreateGrid(MapB); //NOTE: The grids have not moved, so we can assert worldpos == localpos for the tests }
private void OnAfterInteract(EntityUid uid, FloorTileComponent component, AfterInteractEvent args) { if (!args.CanReach) { return; } if (!TryComp <StackComponent>(uid, out var stack)) { return; } if (component.OutputTiles == null) { return; } // this looks a bit sussy but it might be because it needs to be able to place off of grids and expand them var location = args.ClickLocation.AlignWithClosestGridTile(); var locationMap = location.ToMap(EntityManager); if (locationMap.MapId == MapId.Nullspace) { return; } _mapManager.TryGetGrid(location.GetGridId(EntityManager), out var mapGrid); foreach (var currentTile in component.OutputTiles) { var currentTileDefinition = (ContentTileDefinition)_tileDefinitionManager[currentTile]; if (mapGrid != null) { var tile = mapGrid.GetTileRef(location); var baseTurf = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; if (HasBaseTurf(currentTileDefinition, baseTurf.ID)) { if (!_stackSystem.Use(uid, 1, stack)) { continue; } PlaceAt(mapGrid, location, currentTileDefinition.TileId, component.PlaceTileSound); } } else if (HasBaseTurf(currentTileDefinition, "space")) { mapGrid = _mapManager.CreateGrid(locationMap.MapId); mapGrid.WorldPosition = locationMap.Position; location = new EntityCoordinates(mapGrid.GridEntityId, Vector2.Zero); PlaceAt(mapGrid, location, _tileDefinitionManager[component.OutputTiles[0]].TileId, component.PlaceTileSound, mapGrid.TileSize / 2f); } } }
public void Initialize() { // Create ingress point map. Map = _mapManager.CreateMap(); var grid = _mapManager.CreateGrid(Map); grid.SetTile(new Vector2i(-1, -1), new Tile(0)); grid.SetTile(new Vector2i(0, -1), new Tile(1)); grid.SetTile(new Vector2i(1, -1), new Tile(0)); grid.SetTile(new Vector2i(-1, 0), new Tile(1)); grid.SetTile(new Vector2i(0, 0), new Tile(0)); grid.SetTile(new Vector2i(1, 0), new Tile(1)); grid.SetTile(new Vector2i(-1, 1), new Tile(0)); grid.SetTile(new Vector2i(0, 1), new Tile(1)); grid.SetTile(new Vector2i(1, 1), new Tile(0)); // _mapManager.CreateNewMapEntity(IngressMap); // Setup join experience. _playerManager.PlayerStatusChanged += PlayerStatusChanged; }
private void PlaceNewTile(ushort tileType, MapId mapId, Vector2 position) { // tile can snap up to 0.75m away from grid var gridSearchBox = new Box2(-0.5f, -0.5f, 0.5f, 0.5f) .Scale(1.5f) .Translated(position); var gridsInArea = _mapManager.FindGridsIntersecting(mapId, gridSearchBox); IMapGrid closest = null; float distance = float.PositiveInfinity; Box2 intersect = new Box2(); foreach (var grid in gridsInArea) { // figure out closest intersect var gridIntersect = gridSearchBox.Intersect(grid.WorldBounds); var gridDist = (gridIntersect.Center - position).LengthSquared; if (gridDist >= distance) { continue; } distance = gridDist; closest = grid; intersect = gridIntersect; } if (closest != null) // stick to existing grid { // round to nearest cardinal dir var normal = new Angle(position - intersect.Center).GetCardinalDir().ToVec(); // round coords to center of tile var tileIndices = closest.WorldToTile(intersect.Center); var tileCenterWorld = closest.GridTileToWorldPos(tileIndices); // move mouse one tile out along normal var newTilePos = tileCenterWorld + normal * closest.TileSize; // you can always remove a tile if (Tile.Empty.TypeId != tileType) { var tileBounds = Box2.UnitCentered.Scale(closest.TileSize).Translated(newTilePos); var collideCount = _mapManager.FindGridsIntersecting(mapId, tileBounds).Count(); // prevent placing a tile if it overlaps more than one grid if (collideCount > 1) { return; } } var pos = closest.WorldToTile(position); closest.SetTile(pos, new Tile(tileType)); } else // create a new grid { var newGrid = _mapManager.CreateGrid(mapId); newGrid.WorldPosition = position + (newGrid.TileSize / 2f); // assume bottom left tile origin var tilePos = newGrid.WorldToTile(position); newGrid.SetTile(tilePos, new Tile(tileType)); } }