Ejemplo n.º 1
0
        /// <summary>
        /// Sends the Worker to Create a Building of a specific type.
        /// </summary>
        /// <param name="buildingType">Type of the Building to be created.</param>
        /// <param name="position">Position where the Building will be placed.
        /// Use Position.IsValidPlacement to check if the position can be used.</param>
        /// <returns>Instance of the building in a progress state.</returns>
        public IBuilding CreateBuilding(BuildingType buildingType, Position position)
        {
            // TODO:
            // 1. send worker to the position near building, queued event when arrival
            // 2. start construction object, queued event when finished
            // 2.5. if interrupted, worker can repeat step 1 and continue on 2 without creating a new object
            // 3. finished event, return to gather
            StopGathering();
            var player = Player.CurrentPlayer;
            var actor  = Create <Building>(
                BuildingHelper.DetermineBuildingType(buildingType),
                BuildingPlacement.PlaceProgressBuilding(
                    BuildingHelper.FindBuildingInFaction(buildingType, UnitController),
                    new List <UnitController> {
                UnitController
            },
                    UnitController.FactionIndex,
                    position,
                    Quaternion.identity,
                    GameManager.Instance.ResourceManagerFaction[UnitController.FactionIndex]
                    ),
                player
                );

            // TODO: make sure the CurrentPlayer stays the same after the movement
            Tutorial.Instance.CreateBuilding();
            // TODO: asynchronous after the movement
            GameManager.Instance.FiredEvent(player, GameEventType.BuildingStartedConstruction, new Arguments
            {
                MyUnit     = this,
                MyBuilding = actor
            });
            return(actor);
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks whether a Building of the chosen type can be placed on the Position.
 /// The condition is also that the Fog is currently uncovered there.
 /// </summary>
 /// <param name="buildingType">Type of the building meant to be built.</param>
 /// <returns>True if the building can be placed on the Position.</returns>
 public bool IsValidPlacement(BuildingType buildingType)
 {
     return(IsFogUncovered() &&
            BuildingHelper.IsValidPlacement(
                BuildingHelper.FindBuildingInFaction(buildingType, null), this, Location, false));
 }