public TerrainGenerationTask(Initializer init) : base("Terrain Generation") { myWorld = new World(init); myCache = myWorld.database; //use a null world for generation myGenerator = (myWorld.terrainSource as LocalGeneratedTerrainSource).generator; MaterialManager.init(); Kernel.eventManager.addListener(handleTerrainRequest, "terrain.chunk.request"); Kernel.eventManager.addListener(handleTerrainRebuild, "terrain.chunk.rebuild"); Kernel.eventManager.addListener(handleTerrainReset, "terrain.reset"); frequency = 10; }
void place() { if (currentSelected != Selected.WALL && !game.World.IsInWorld(MouseInput.GamePosition)) { return; } var pos = MouseInput.GamePosition; var mpos = pos.ToMPos(); var bounds = game.World.Map.Bounds; switch (currentSelected) { case Selected.ACTOR: if (actorWidget.CurrentType == null) { return; } if (actorWidget.RelativeHP == 0) { return; } pos = actorWidget.Rasterization ? rasterizedPosition(pos) : pos; var team = Math.Max(actorWidget.Team, (byte)0); var actor = ActorCache.Create(game.World, actorWidget.CurrentType, pos, team, actorWidget.Bot, false, actorWidget.RelativeHP); actor.Angle = actorWidget.RelativeFacing * Angle.MaxRange; game.World.Add(actor); break; case Selected.TILE: if (terrainWidget.CurrentType == null) { return; } if (mpos.X < 0 || mpos.Y < 0 || mpos.X >= bounds.X || mpos.Y >= bounds.Y) { return; } if (game.World.TerrainLayer.Terrain[mpos.X, mpos.Y].Type == terrainWidget.CurrentType) { return; } var terrain = TerrainCache.Create(game.World, mpos, terrainWidget.CurrentType.ID); game.World.TerrainLayer.Set(terrain); WorldRenderer.CheckTerrainAround(mpos, true); break; case Selected.WALL: if (wallWidget.CurrentType == null) { return; } if (mpos.X < 0 || mpos.Y < 0 || mpos.X > bounds.X || mpos.Y > bounds.Y) { return; } mpos = new MPos(mpos.X * 2 + (wallWidget.Horizontal ? 0 : 1), mpos.Y); var wallLayer = game.World.WallLayer; if (mpos.X >= wallLayer.Bounds.X - 2) { return; } if (mpos.Y >= wallLayer.Bounds.Y - 2 && wallWidget.Horizontal) { return; } var type = wallWidget.CurrentType; var plannedHealth = (int)(type.Health * wallWidget.RelativeHP); if (plannedHealth == 0 && type.Health != 0) { return; } var currentWall = wallLayer.Walls[mpos.X, mpos.Y]; if (currentWall != null && currentWall.Type.ID == type.ID && currentWall.Health == plannedHealth) { return; } var wall = WallCache.Create(mpos, wallLayer, type.ID); wall.Health = plannedHealth; wallLayer.Set(wall); break; } }