public void Modify(Area area, EcsManager ecs, Owner owner, Random random) { var landscape = ecs.GetContainer <Landscape>(); var building = ecs.GetContainer <Building>(); var squad = ecs.GetContainer <Squad>(); Vector position; do { position = random.NextPosition(area.Size); }while (area.ContainerSlice <Landscape>()[position] < landscape.Water || area.ContainerSlice <Building>()[position] < building.Mountain); area.ContainerSlice <Building>()[position] = building.WoodenHouse; area.ContainerSlice <Building>()[position].GetComponent <Owned>().Owner = owner; do { position = random.NextPosition(area.Size); }while (area.ContainerSlice <Landscape>()[position] < landscape.Water || area.ContainerSlice <Building>()[position] < building.Mountain); area.ContainerSlice <Squad>()[position] = squad.Test; area.ContainerSlice <Squad>()[position].GetComponent <Owned>().Owner = owner; }
protected virtual void GenerateRidge(Ridge ridge, Area area, EcsManager ecs, Random random) { var landscape = ecs.GetContainer <Landscape>(); var building = ecs.GetContainer <Building>(); var delta = ridge.To - ridge.From; for (var px = Math.Max(0, Math.Min(ridge.From.X, ridge.To.X) - ridge.Width); px < Math.Min(area.Size.X - 1, Math.Max(ridge.From.X, ridge.To.X) + ridge.Width); px++) { for (var py = Math.Max(0, Math.Min(ridge.From.Y, ridge.To.Y) - ridge.Width); py < Math.Min(area.Size.Y - 1, Math.Max(ridge.From.Y, ridge.To.Y) + ridge.Width); py++) { var position = new Vector(px, py); var internalPosition = delta.TransitionMatrix() * (2 * position - ridge.From - ridge.To).ToMatrix() / 2; var x = internalPosition[0, 0]; var y = internalPosition[1, 0] * delta.Magnitude / ridge.Width * 2; if (random.Chance( 2 * (1 - Math.Sqrt(x * x + y * y)))) { area.ContainerSlice <Landscape>()[position] = landscape.Plain; area.ContainerSlice <Building>()[position] = building.Mountain; } } } }
public void Generate(Area area, EcsManager ecs, Random random) { var landscape = ecs.GetContainer <Landscape>(); var building = ecs.GetContainer <Building>(); foreach (var position in area.Size.Range()) { area.ContainerSlice <Landscape>()[position] = landscape.Water; area.ContainerSlice <Building>()[position] = building.None; } }
public void Generate(Area area, EcsManager ecs, Random random) { var landscape = ecs.GetContainer <Landscape>(); var building = ecs.GetContainer <Building>(); foreach (var vector in area.Size.Range()) { if (area.ContainerSlice <Landscape>()[vector] < landscape.Plain && random.Chance( MaximalChance * (1 - 2 / (MaximalTemperature - MinimalTemperature) * Math.Abs(area.GetTemperature(vector) + MinimalTemperature)))) { area.ContainerSlice <Building>()[vector] = building.Forest; } } }
public void Generate(Area area, EcsManager ecs, Random random) { var landscape = ecs.GetContainer <Landscape>(); var landscapeSlice = area.ContainerSlice <Landscape>(); var maximalLandNumber = LandFraction * area.Size.X * area.Size.Y; var counter = 0; while (counter < maximalLandNumber - 1) { var radius = random.NextDouble() * Math.Sqrt((maximalLandNumber - counter) / Math.PI) / 2; var sourcePosition = random.NextPosition(area.Size); var sizeVector = (int)radius * Vector.One; foreach (var vector in (sizeVector * 2 + Vector.One).Range().Select(v => v - sizeVector)) { var part = (vector.Magnitude - SeasideBorder * radius) / (radius * (1 - SeasideBorder)); if (random.Chance(0.5 * (Math.Abs(part - 1) - Math.Abs(part) + 1))) { var newPosition = Vector.Clamp( vector + sourcePosition, Vector.Zero, area.Size - Vector.One); if (landscapeSlice[newPosition] < landscape.Water) { counter++; landscapeSlice[newPosition] = landscape.Plain; } } } } }
protected override void InitializePrototypes(EcsManager ecs) { WoodenHouse = new Entity("Wooden house") | new Placer() | new Incomer { IncomePerSecond = new Resources { Food = 3600 } } | new Owned() | new Observer() | new Destructible(20) | new Productor(TimeSpan.FromSeconds(1), ecs.GetContainer <Squad>().Test); Sawmill = new Entity("Sawmill") | new Placer() | new Incomer { IncomePerSecond = new Resources { Wood = 3600 } } | new Owned() | new Observer(); None = new Entity("None") | new Placer() | new Upgradable( new Upgrade(WoodenHouse)); Field = new Entity("Field") | new Placer() | new Incomer { IncomePerSecond = new Resources { Corn = 3600 } } | new Owned(); Forest = new Entity("Forest") | new Placer(); Mountain = new Entity("Mountain") | new Placer(); }
public static void Main(string[] consoleArgs) { Console.Title = "Imperium"; Console.SetWindowSize(120, 40); Ecs = new EcsFactory().Generate(); Server = new ResponseServerFactory <Owner, EcsManager>().Generate(Ecs, typeof(Program).Assembly); EventRegistrator.Register(Server, Ecs); var player = Ecs.EntityManager.Create(Ecs.GetContainer <Global>().Player).GetComponent <Owner>(); Server.Accounts.Add(new Account <Owner>("", "", new[] { Permission.User, Permission.Admin }, player)); Ecs.SystemManager.GetSystem <Ownership>().Register(player); new PlayerModifier().Modify(Ecs.SystemManager.GetSystem <Area>(), Ecs, player, new Random()); new Thread(Server.Start).Start(); Ecs.Start(); }
private static void GenerateSystems(EcsManager ecs) { var area = new Area(new Vector(40, 40)); var systems = new Ecs.System[] { area, new Ownership(Resources.Zero), new IncomeSystem(), new ClientVision(), new OrderManager(), new ResearchSystem(ecs.GetContainer <Science>().Test), new ProductionManager(), }; foreach (var system in systems) { ecs.SystemManager.Register(system); } new AreaBasicGenerator().Generate(area, ecs, new Random()); }