Esempio n. 1
0
        public void AddBuilding(ConstructionSite constructionSite)
        {
            var building = constructionSite.Building;

            buildings.Add(building);
            constructionSite.DestroySite();
            Map.Instance.AddTeamControl(this, constructionSite.Tile, building.controlRadius);
        }
Esempio n. 2
0
        public override void Update()
        {
            if (constructionSite == null)
            {
                // Check if there is an existing construction site.
                if (targetTile.ConstructionSite != null)
                {
                    if (targetTile.ConstructionSite.Team != unit.UnitTeam)
                    {
                        StopState();
                        return;
                    }

                    constructionSite = targetTile.ConstructionSite;
                }
                else
                {
                    if (targetTile.CheckCanBuild(unit.UnitTeam.teamTag, buildingType) == false || GameController.Instance.CanBeBuild.Contains(buildingType) == false)
                    {
                        StopState();
                        return;
                    }

                    if (Vector3.Distance(unit.transform.position, targetTile.transform.position) > unit.CurrentJob.buildingDistance)
                    {
                        PushMoveState(unit, targetTile.transform.position, unit.CurrentJob.buildingDistance);
                        return;
                    }

                    // Try to create construction site.
                    constructionSite = BuildingController.Instance.CreateConstructionSite(unit.UnitTeam, buildingType, targetTile, direction);
                    targetTile.AddConstructionSite(constructionSite);
                    var resourcesLeft = constructionSite.TryAddResource(unit.carriedResource);
                    unit.SpendCarriedResource(unit.carriedResource.value - resourcesLeft);
                }
            }

            switch (constructionSite.State)
            {
            case ConstructionSite.ConstructionState.GatheringResources:
                PushState(new DeliveryState(unit, constructionSite));
                return;

            case ConstructionSite.ConstructionState.Building:
                PushState(new AddBuildingPointsState(unit, constructionSite));
                return;

            case ConstructionSite.ConstructionState.Finished:
                StopState();
                return;
            }
        }
Esempio n. 3
0
 // IMPROVE: Move TryGetDelivery to interface.
 public DeliveryState(Unit unit, ConstructionSite constructionSite)
 {
     this.unit             = unit;
     this.constructionSite = constructionSite;
 }
Esempio n. 4
0
 private void ConstructionSiteFinishedHandler(ConstructionSite cs) => ConstructionSite = null;
Esempio n. 5
0
 public void AddConstructionSite(ConstructionSite constructionSite)
 {
     ConstructionSite = constructionSite;
     constructionSite.OnConstructionSiteFinished += ConstructionSiteFinishedHandler;
 }
Esempio n. 6
0
 public AddBuildingPointsState(Unit unit, ConstructionSite constructionSite)
 {
     this.unit             = unit;
     this.constructionSite = constructionSite;
 }
Esempio n. 7
0
 public BringResourcesState(Unit unit, ConstructionSite constructionSite)
 {
     this.unit             = unit;
     this.constructionSite = constructionSite;
 }
Esempio n. 8
0
 public void AddBuildingSite(ConstructionSite constructionSite)
 {
     constructionSites.Add(constructionSite);
     constructionSite.OnConstructionSiteFinished += ConstructionSiteFinishedHandler;
 }
Esempio n. 9
0
 private void ConstructionSiteFinishedHandler(ConstructionSite constructionSite)
 {
     constructionSites.Remove(constructionSite);
     AddBuilding(constructionSite);
 }