Exemplo n.º 1
0
        private void Start()
        {
            List <Resource> resources = new List <Resource>();

            foreach (var resourceSource in FindObjectsOfType <ResourceSource>())
            {
                resources.Add(Resource.CreateResourceActor <Resource>(resourceSource.gameObject));
            }
            // Initialize Resources to use the shared list
            Instance.Players[0].SharedResources = resources;

            foreach (var player in Players)
            {
                // Spawn starting Bases and Workers
                Player.CurrentPlayer = player;
                Actor.Create <BaseCenter>(
                    BuildingHelper.InstantiateProgressBuilding(
                        BuildingHelper.FindBuildingInFaction(BuildingType.BaseCenter, null),
                        BaseCenterProgressPrefab,
                        player.FactionIndex,
                        player.MyBase.Center,
                        Quaternion.identity)
                    .Place()
                    .gameObject
                    , player);
                for (var workerIndex = 0; workerIndex < StartingWorkers; workerIndex++)
                {
                    Actor.Create <Worker>(
                        UnitHelper.InstantiateUnit(
                            WorkerPrefab,
                            // Workers will be spawned near the first Base
                            PositionHelper.PositionToLocation(((BaseCenter)player.Buildings[0]).SpawnPosition),
                            player.FactionIndex),
                        player);
                }

                // Initialize (single) enemy player for each of them
                var enemyFactionIndex = player.Faction.EnemyFactionIndexes()[0];
                foreach (var enemyPlayer in Players)
                {
                    if (enemyPlayer.FactionIndex != enemyFactionIndex)
                    {
                        continue;
                    }
                    player.EnemyBase = enemyPlayer.MyBase;
                    break;
                }
            }

            // Start the Test (build workaround)
            // No longer required, the GameTestRunner is included in the project
            //StartTest();
        }
Exemplo n.º 2
0
        public static GameObject PlaceProgressBuilding(Building building, List <UnitController> builderUnits,
                                                       int factionIndex, Position position, Quaternion rotation, ResourceManager resourceManager)
        {
            Vector3 location = PositionHelper.PositionToLocation(position);

            try
            {
                BuildingHelper.CheckValidPlacement(building, position, location, false);
            }
            catch (Exception)
            {
                // Visualizing the error placement
                if (GameManager.Instance.Debug)
                {
                    building.ClosePoints(GameManager.Instance.Grid, position.PointLocation);
                }
                throw;
            }
            for (int x = 0; x < building.cost.Length; x++)
            {
                if (building.cost[x] > 0 && resourceManager.resourceTypes[x].amount < building.cost[x])
                {
                    throw new InvalidOperationException(
                              "Not enough resources for placing the " + building + " building");
                }
            }
            for (int x = 0; x < building.cost.Length; x++)
            {
                if (building.cost[x] > 0)
                {
                    resourceManager.resourceTypes[x].amount -= building.cost[x];
                }
            }
            GameObject buildingObject;

            if (building.autoBuild)
            {
                buildingObject = BuildingHelper.InstantiateProgressBuilding(
                    building, building.obj, factionIndex, position, rotation)
                                 .gameObject;
            }
            else
            {
                buildingObject = BuildingHelper.InstantiateProgressBuilding(
                    building, building.progressObj, factionIndex, position, rotation)
                                 .gameObject;
                UnitSelection.SetTarget(builderUnits, buildingObject, buildingObject.transform.position);
            }
            return(buildingObject);
        }