private static Coordinates GroundCoordinates(double x, double z, GetSnapshotHeight ground)
        {
            double y = ground == null ?  0: (double)ground((float)x, (float)z);

            y += heightBuffer;
            return(new Coordinates(x, y, z));
        }
        public static void Generate(Arguments arguments, float fieldSize, GetSnapshotHeight ground = null, List <UnitSnapshot> units = null, List <FieldSnapshot> fields = null)
        {
            Debug.Log("Generating snapshot.");
            var snapshot = CreateSnapshot(ground, fieldSize, units, fields);

            Debug.Log($"Writing snapshot to: {arguments.OutputPath}");
            snapshot.WriteToFile(arguments.OutputPath);
        }
        public static void Generate(Arguments arguments, GetSnapshotHeight ground = null)
        {
            Debug.Log("Generating snapshot.");
            var snapshot = CreateSnapshot(ground);

            Debug.Log($"Writing snapshot to: {arguments.OutputPath}");
            snapshot.WriteToFile(arguments.OutputPath);
        }
 private static void AddUnits(Snapshot snapshot, GetSnapshotHeight ground, List <UnitSnapshot> units)
 {
     foreach (var u in units)
     {
         var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, GroundCoordinates(u.pos.x, u.pos.y, u.pos.z), u.type);
         snapshot.AddEntity(template);
     }
 }
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount, GetSnapshotHeight ground = null)
        {
            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var cubesToSpawn = cubeCount;

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    UnitSide side = x < 0 ? UnitSide.A : UnitSide.B;
                    int      nx;
                    if (x < 0)
                    {
                        nx = x - 3;
                    }
                    else
                    {
                        nx = x + 3;
                    }

                    double pos_x          = nx * scale;
                    double pos_z          = z * scale;
                    var    entityTemplate = BaseUnitTemplate.CreateBaseUnitEntityTemplate(side, GroundCoordinates(pos_x, pos_z, ground), UnitType.Soldier);
                    snapshot.AddEntity(entityTemplate);
                }
            }

            AddDefaultUnits(snapshot, ground);
        }
Ejemplo n.º 6
0
        public static Snapshot GenerateGroundSnapshot(float fieldSize, GetSnapshotHeight ground = null)
        {
            var snapshot = new Snapshot();

            int count = (int)Mathf.Round(fieldSize / standardSize) * 2;

            for (int i = 0; i <= count; i++)
            {
                for (int j = 0; j <= count; j++)
                {
                    var length_x = standardSize * (i - (count - 1) / 2.0f);
                    var length_z = standardSize * (j - (count - 1) / 2.0f);
                    AddPlayerSpawner(snapshot, GroundCoordinates(length_x, length_z, ground));
                }
            }

            return(snapshot);
        }
Ejemplo n.º 7
0
        private static void AddUnits(Snapshot snapshot, GetSnapshotHeight ground, List <UnitSnapshot> units)
        {
            foreach (var u in units)
            {
                var template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, u.type, GroundCoordinates(u.pos.x, u.pos.y, u.pos.z), u.rotate.ToCompressedQuaternion());
                if (u.attachments != null)
                {
                    foreach (var attach in u.attachments)
                    {
                        attach.AddComponent(template);
                    }
                }

                snapshot.AddEntity(template);

                //if (u.type == UnitType.HeadQuarter)
                //{
                //    template = BaseUnitTemplate.CreateBaseUnitEntityTemplate(u.side, new Coordinates(u.pos.x, FixedParams.StrategyHeight, u.pos.z), UnitType.ArmyCloud);
                //}
            }
        }
        private static void AddDefaultUnits(Snapshot snapshot, GetSnapshotHeight ground = null)
        {
            var gridLength = (int)Math.Ceiling(Math.Sqrt(16));
            var len        = gridLength * scale;
            var templateA  = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3, 0, ground), UnitType.Stronghold);
            var templateB  = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3, 0, ground), UnitType.Stronghold);

            snapshot.AddEntity(templateA);
            snapshot.AddEntity(templateB);

            var templateCa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 2, 0, ground), UnitType.Commander);
            var templateCb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 2, 0, ground), UnitType.Commander);

            snapshot.AddEntity(templateCa);
            snapshot.AddEntity(templateCb);

            var templateHa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3.5, 0, ground), UnitType.HeadQuarter);
            var templateHb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3.5, 0, ground), UnitType.HeadQuarter);

            snapshot.AddEntity(templateHa);
            snapshot.AddEntity(templateHb);
        }
        private static Snapshot CreateSnapshot(GetSnapshotHeight ground = null, float fieldSize = standardSize, List <UnitSnapshot> units = null, List <FieldSnapshot> fields = null)
        {
            var snapshot = new Snapshot();

            int count = (int)Mathf.Round(fieldSize / standardSize) * 2;

            for (int i = 0; i <= count; i++)
            {
                for (int j = 0; j <= count; j++)
                {
                    var length_x = standardSize * (i - (count - 1) / 2.0f);
                    var length_z = standardSize * (j - (count - 1) / 2.0f);
                    AddPlayerSpawner(snapshot, GroundCoordinates(length_x, length_z, ground));
                }
            }

            AddWorldTimer(snapshot, Coordinates.Zero);
            if (units == null)
            {
                AddDefaultUnits(snapshot, ground);
            }
            else
            {
                AddUnits(snapshot, ground, units);
            }

            if (fields == null)
            {
                AddField(snapshot, Coordinates.Zero);
            }
            else
            {
                AddFields(snapshot, fields);
            }

            return(snapshot);
        }