Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     spawnables        = new HashSet <Spawnable>();
     spawnerConfig     = GetComponent <SpawnerConfig>();
     target            = GameObject.FindGameObjectWithTag("Player");
     isSpawningObjects = startActive;
 }
Beispiel #2
0
        public MapViewForm()
        {
            InitializeComponent();

            Size        = new Size(1000, 700);
            WindowState = FormWindowState.Maximized;

            DoubleBuffered = true;

            var r = new Random();

            var easyTier   = new SpawnerConfig(SigmaIndex.Zero, 3, 30, 0.5);
            var mediumTier = new SpawnerConfig(SigmaIndex.Zero, 30, 1000, 0.5);
            var hardTier   = new SpawnerConfig(SigmaIndex.Zero, 14, 16, 0.5);
            var nightmare  = new SpawnerConfig(SigmaIndex.Zero, 16.5, 20, 0.5);

            var gen = HommMapGenerator
                      .From(new DiagonalMazeGenerator(r))
                      .With(new BfsRoadGenerator(r, TileTerrain.Road)
                            .Over(new VoronoiTerrainGenerator(r, TileTerrain.Nature.ToArray())))
                      .With(new TopologicSpawner(r, mediumTier, p => new Mine(Resource.Crystals, p)))
                      .With(new MinDistanceSpawner(r, hardTier, p => new Mine(Resource.Ore, p)))
                      .With(new TopologicSpawner(r, easyTier, p => new Mine(Resource.Rubles, p)))
                      .And(new MinDistanceSpawner(r, nightmare, p => new Mine(Resource.Gems, p)));

            Map map = null;

            var generateButton = new Button {
                Text = "Generate!", Location = new Point(150, 0)
            };

            var mapSizeBox = new ComboBox();

            for (var size = 4; size < 20; ++size)
            {
                mapSizeBox.Items.Add(2 * size);
            }

            mapSizeBox.SelectedIndex = 5;

            generateButton.Click += (s, e) =>
            {
                mapSize = (int)mapSizeBox.SelectedItem;
                map     = gen.GenerateMap(mapSize);
                this.Invalidate();
            };

            Controls.Add(mapSizeBox);
            Controls.Add(generateButton);

            Paint += (s, e) => {
                if (map != null)
                {
                    foreach (var tile in map)
                    {
                        DrawTile(tile, e.Graphics);
                    }
                }
            };
        }
Beispiel #3
0
        private HommMapGenerator.BuilderOnSelectEntities AddGuards(
            HommMapGenerator.BuilderOnSelectEntities builder, Random random)
        {
            var guardsConfig = new SpawnerConfig(Location.Zero, 12.5, 100, 1);

            return(builder.With(new DistanceSpawner(random, guardsConfig,
                                                    (map, maze, p) => NeutralArmy.BuildRandom(p, 400, random),
                                                    symmetricFactory: (original, location) => ((NeutralArmy)original).Copy(location))));
        }
Beispiel #4
0
        private HommMapGenerator.BuilderOnSelectEntities AddMines(
            HommMapGenerator.BuilderOnSelectEntities builder, Random random)
        {
            var minesConfig = new SpawnerConfig(Location.Zero, 25, 100, 0.2);

            foreach (var resource in spawnableResources)
            {
                builder = builder.With(new GraphSpawner(random, minesConfig,
                                                        (map, maze, loc) => new Mine(resource, loc, FindPlaceForBuilding(map, maze, loc)),
                                                        (map, maze, loc) => IsGoodPlaceForBuilding(map, maze, loc)));
            }

            return(builder);
        }
Beispiel #5
0
        public static Map CreateMap(Random random)
        {
            var easyTier   = new SpawnerConfig(Location.Zero, 3, 30, 0.5);
            var mediumTier = new SpawnerConfig(Location.Zero, 30, 1000, 0.5);
            var hardTier   = new SpawnerConfig(Location.Zero, 14, 16, 0.5);
            var nightmare  = new SpawnerConfig(Location.Zero, 16.5, 20, 0.5);

            var mapGenerator = HommMapGenerator
                               .From(new DiagonalMazeGenerator(random))
                               .With(new BfsRoadGenerator(random, TileTerrain.Road)
                                     .Over(new VoronoiTerrainGenerator(random, TileTerrain.Nature.ToArray())))
                               .With(new GraphSpawner(random, mediumTier, p => new Mine(Resource.Crystals, p)))
                               .With(new DistanceSpawner(random, hardTier, p => new Mine(Resource.Ore, p)))
                               .With(new GraphSpawner(random, easyTier, p => new Mine(Resource.Rubles, p)))
                               .And(new DistanceSpawner(random, nightmare, p => new Mine(Resource.Gems, p)));

            return(mapGenerator.GenerateMap(18));
        }
Beispiel #6
0
        private HommMapGenerator.BuilderOnSelectEntities AddEnemies(
            HommMapGenerator.BuilderOnSelectEntities builder, Random random)
        {
            var easyTier = new SpawnerConfig(Location.Zero, 0, 40, 1);
            var hardTier = new SpawnerConfig(Location.Zero, 40, 100, 1);

            return(builder

                   .With(new GraphSpawner(random, easyTier,
                                          (map, maze, location) => NeutralArmy.BuildRandom(location, 75, random),
                                          (map, maze, location) => map[location].Any(x => x is Mine),
                                          (original, location) => ((NeutralArmy)original).Copy(location)))

                   .With(new GraphSpawner(random, hardTier,
                                          (map, maze, location) => NeutralArmy.BuildRandom(location, 225, random),
                                          (map, maze, location) => map[location].Any(x => x is Mine),
                                          (original, location) => ((NeutralArmy)original).Copy(location))));
        }
Beispiel #7
0
        private HommMapGenerator.BuilderOnSelectEntities AddPiles(
            HommMapGenerator.BuilderOnSelectEntities builder, Random random)
        {
            var nearPiles = new SpawnerConfig(Location.Zero, 3, 15, 0.3);
            var farPiles  = new SpawnerConfig(Location.Zero, 15, 100, 0.1);

            foreach (var resource in spawnableResources)
            {
                builder = builder

                          .With(new GraphSpawner(random, nearPiles,
                                                 (map, maze, location) => new ResourcePile(resource, 10, location)))

                          .With(new GraphSpawner(random, farPiles,
                                                 (map, maze, location) => new ResourcePile(resource, 25, location)));
            }

            return(builder);
        }
Beispiel #8
0
        private void UpdateFields()
        {
            if (typeof(SpawnerConfig) == target.GetType())
            {
                Config = (SpawnerConfig)target;
                if (Config != null)
                {
                    var          configType   = typeof(SpawnerConfig);
                    List <Array> fieldsArrays = new List <Array> {
                        configType.GetFields()
                    };
                    var derived = configType;
                    do
                    {
                        derived = derived.BaseType;
                        if (derived != null)
                        {
                            fieldsArrays.Add(derived.GetFields());
                        }
                    } while (derived != null);

                    if (fieldsArrays.Count > 0)
                    {
                        List <FieldInfo> allFields   = new List <FieldInfo>();
                        List <string>    fieldsNames = new List <string>();
                        for (int i = fieldsArrays.Count - 1; i >= 0; i--)
                        {
                            for (int j = 0; j < fieldsArrays[i].Length; j++)
                            {
                                var field = fieldsArrays[i].GetValue(j) as FieldInfo;
                                if (!fieldsNames.Contains(field.Name))
                                {
                                    allFields.Add(field);
                                    fieldsNames.Add(field.Name);
                                }
                            }
                        }

                        Fields = allFields;
                    }
                }
            }
        }
        /// <summary>
        /// Create new instance of spawner controller
        /// </summary>
        /// <param name="spawnerId"></param>
        /// <param name="connection"></param>
        /// <param name="options"></param>
        public SpawnerController(int spawnerId, IClientSocket connection, SpawnerOptions spawnerOptions)
        {
            Logger = Msf.Create.Logger(typeof(SpawnerController).Name, LogLevel.Info);

            Connection = connection;
            SpawnerId  = spawnerId;

            SpawnSettings = new SpawnerConfig()
            {
                MasterIp         = connection.ConnectionIp,
                MasterPort       = connection.ConnectionPort,
                SpawnInBatchmode = false,
                MachineIp        = spawnerOptions.MachineIp,
                Region           = string.IsNullOrEmpty(spawnerOptions.Region) ? "International" : spawnerOptions.Region
            };

            // Add static handlers to listen one message for all controllers
            connection.SetHandler((short)MsfMessageCodes.SpawnProcessRequest, SpawnProcessRequestHandler);
            connection.SetHandler((short)MsfMessageCodes.KillProcessRequest, KillProcessRequestHandler);
        }
Beispiel #10
0
        private HommMapGenerator.BuilderOnSelectEntities AddDwellings(
            HommMapGenerator.BuilderOnSelectEntities builder, Random random)
        {
            builder = builder
                      .With(new SimpleSpawner(
                                (map, maze, location) => new Dwelling(UnitType.Militia,
                                                                      location, location == Location.Zero ? location - Vector2i.One : location + Vector2i.One,
                                                                      HommRules.Current.Units.WeeklyGrowth[UnitType.Militia]),
                                maze => new[] { Location.Zero, Location.Max(maze.Size) }));

            var dwellingsConfig = new SpawnerConfig(Location.Zero, 15, 100, 0.2);

            foreach (var unitType in spawnableDwellings)
            {
                builder = builder.With(new GraphSpawner(random, dwellingsConfig,
                                                        (map, maze, loc) => new Dwelling(unitType, loc,
                                                                                         FindPlaceForBuilding(map, maze, loc), HommRules.Current.Units.WeeklyGrowth[unitType]),
                                                        (map, maze, loc) => IsGoodPlaceForBuilding(map, maze, loc)));
            }

            return(builder);
        }
Beispiel #11
0
    void RandomLinear(SpawnerConfig config)
    {
        Random.InitState(config.seed);
        positions = new List <Vector3>();

        for (int i = 0; i < config.maxIteration; ++i)
        {
            Vector3 unitSphere = Random.onUnitSphere;
            //Debug.Log("Test : " + unitSphere);
            float   elevation = planet.noiseGenerator.GetNoise3D(unitSphere);
            Vector3 pos       = unitSphere * (1 + elevation) * planet.radius;

            bool isOk = true;
            foreach (Vector3 opos in positions)
            {
                if (Vector3.Distance(pos, opos) < config.minDistance)
                {
                    isOk = false;
                    break;
                }
            }
            if (isOk)
            {
                positions.Add(pos);
            }
        }
        int count          = 0;
        int forestSize     = 25;
        int elementSpacing = 3;

        foreach (Vector3 pos in positions)
        {
            if (count % 100 == 0)
            {
                //Debug.Log("OOOOOOOOOOOOOOOOK");
                //float x_old = pos.x, y_old = pos.y;
                //for (int x = 0; x < forestSize; x += elementSpacing)
                //{
                //    for (int z = 0; z < forestSize; z += elementSpacing)
                //    {
                //        Vector3 position = Quaternion.Euler(x, 0, z) * pos;
                //        Vector3 offset = new Vector3(Random.Range(-0.75f, 0.75f), 0f, Random.Range(-0.75f, 0.75f));
                //        Vector3 rotation = new Vector3(Random.Range(0, 5f), Random.Range(0, 360f), Random.Range(0, 5f));
                //        Vector3 scale = Vector3.one * Random.Range(0.75f, 1.25f);



                //        string word = GenerateWord(g1, 2);
                //        WordTo2DTree(word, position, Quaternion.FromToRotation(Vector3.up, (pos + position).normalized), 3);

                //    }
                //}

                GameObject go = GameObject.Instantiate(config.obj);
                go.transform.position           = pos;
                go.transform.transform.rotation = Quaternion.FromToRotation(Vector3.up, pos.normalized);

                //Vector3 position = new Vector3(pos.x, pos.y, pos.z);
                //Vector3 offset = new Vector3(Random.Range(-0.75f, 0.75f), 0f, Random.Range(-0.75f, 0.75f));
                //Vector3 rotation = new Vector3(Random.Range(0, 5f), Random.Range(0, 360f), Random.Range(0, 5f));
                //Vector3 scale = Vector3.one * Random.Range(0.75f, 1.25f);

                //string word = GenerateWord(g1, 2);
                //WordTo2DTree(word, position, Quaternion.FromToRotation(Vector3.up, pos.normalized));
            }

            count++;
        }
    }