Esempio n. 1
0
 /// <summary>
 /// Internal method, do not use.
 /// </summary>
 internal void GatherByWorker(List <UnitController> gatheringUnits)
 {
     if (GameObject == null)
     {
         throw new ResourceExhaustedException(this);
     }
     UnitSelection.SetTarget(gatheringUnits, GameObject, GameObject.transform.position);
 }
Esempio n. 2
0
 internal static void MoveToPosition(Position where, UnitController unitController)
 {
     UnitSelection.SetTarget(
         new List <UnitController> {
         unitController
     },
         GameManager.Instance.Terrain.gameObject,
         PositionHelper.PositionToLocation(where));
 }
Esempio n. 3
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);
        }
Esempio n. 4
0
 /// <summary>
 /// Internal method, do not use.
 /// </summary>
 internal bool AttackedByUnit(UnitController attackerUnit)
 {
     if (Dead)
     {
         return(true);
     }
     if (GameManager.Instance.Factions[UnitController.FactionIndex]
         .Relations[attackerUnit.FactionIndex]
         .state != 2)
     {
         throw new Exception("The target Unit is not enemy, so it cannot be attacked");
     }
     UnitSelection.SetTarget(new List <UnitController> {
         attackerUnit
     }, GameObject, GameObject.transform.position);
     return(false);
 }
Esempio n. 5
0
 /// <summary>
 /// Internal method, do not use.
 /// </summary>
 internal bool FinishBuildingByWorker(UnitController builderUnit)
 {
     if (Destroyed)
     {
         return(false);
     }
     if (GameManager.Instance.Factions[BuildingController.FactionIndex]
         .Relations[builderUnit.FactionIndex]
         .state == 2)
     {
         throw new Exception("The target Building belongs to an enemy, so a worker cannot be construct it");
     }
     UnitSelection.SetTarget(new List <UnitController> {
         builderUnit
     }, GameObject, GameObject.transform.position);
     return(true);
 }