public void addBuildingsTest()
    {
        IBuilding bank1 = BuildingFactory.buildNew(BuildingType.Bank, 0, 0);
        IBuilding bank2 = BuildingFactory.buildNew(BuildingType.Bank, 1, 1);
        IBuilding bank3 = BuildingFactory.buildNew(BuildingType.Bank, 2, 2);

        this.gc.forceBuildBuilding(bank1);
        this.gc.forceBuildBuilding(bank2);
        this.gc.forceBuildBuilding(bank3);

        IBuilding sm1 = BuildingFactory.buildNew(BuildingType.StoneMason, 5, 5);
        IBuilding sm2 = BuildingFactory.buildNew(BuildingType.StoneMason, 5, 6);
        IBuilding sm3 = BuildingFactory.buildNew(BuildingType.StoneMason, 5, 7);

        this.gc.forceBuildBuilding(sm1);
        this.gc.forceBuildBuilding(sm2);
        this.gc.forceBuildBuilding(sm3);

        IBuilding wc1 = BuildingFactory.buildNew(BuildingType.WoodCutter, 10, 5);
        IBuilding wc2 = BuildingFactory.buildNew(BuildingType.WoodCutter, 10, 6);
        IBuilding wc3 = BuildingFactory.buildNew(BuildingType.WoodCutter, 10, 7);

        this.gc.forceBuildBuilding(wc1);
        this.gc.forceBuildBuilding(wc2);
        this.gc.forceBuildBuilding(wc3);
    }
Beispiel #2
0
    private void doWork(Work nextAiWork)
    {
        //Debug.Log("Updating ai resource display");
        //foreach (ResourceType rt in aiCurrentGameState.getAllResourceTypes())
        //{
        //    Debug.Log("RT: " + rt + ", " + aiCurrentGameState.getStockpile(rt));
        //    aiResourceDisplay.updateCountAndRPT(rt, aiCurrentGameState.getStockpile(rt), aiCurrentGameState.getChangePerTick(rt));
        //}
        Debug.Log("Doing work: " + nextAiWork.workType);
        switch (nextAiWork.workType)
        {
        case EWork.BuildBuilding:
            startBuildBuilding(BuildingFactory.buildNew(nextAiWork.buildingType, -1, -1), nextAiWork.frameWait);
            break;

        case EWork.BuyAndAssignWorker:
            Debug.Log("Worker for: " + nextAiWork.buildingType);
            if (aiCurrentGameState.canBuyWorker())
            {
                Debug.Log("can buy worker");
                aiCurrentGameState.buyAndAssignWorker(nextAiWork.buildingType);
                aiResourceDisplay.workerAssigned();
                aiResourceDisplay.addTotalWorker();

                switch (nextAiWork.buildingType)
                {
                case BuildingType.Bank:
                    bank++;
                    break;

                case BuildingType.SilverMine:
                    silver++;
                    break;

                case BuildingType.StoneMason:
                    stone++;
                    break;

                case BuildingType.WoodCutter:
                    wood++;
                    break;
                }
            }
            else
            {
                Debug.Log("cannot buy worker");
            }
            doNextWorkAi();
            break;

        case EWork.Wait:
            StartCoroutine(aiWait(nextAiWork.frameWait));
            break;

        default:
            doNextWorkAi();
            break;
        }
    }
Beispiel #3
0
    public void buildBuilding(BuildingType bt)
    {
        if (ConstructionController.tile == null)
        {
            throw new System.Exception("Trying to build without a tile. Please call turnOn(Tile t) before trying to build something");
        }
        IBuilding newBuilding = BuildingFactory.buildNew(bt, tile.x, tile.y);

        this.gc.startBuildBuilding(newBuilding);
    }
    public static HashSet <QGameState> getNeighbors(QGameState qEntry)
    {
        // For a given game state return all valid edges out of it

        HashSet <QGameState> result = new HashSet <QGameState>();
        BuildingGS           gs     = qEntry.gameState;

        // Branches related to workers
        if (gs.canBuyWorker())
        {
            // If we have the resources to build a new worker
            foreach (BuildingType bt in gs.getOpenSlots())
            {
                // One branch for every possible type of worker slot we can fill
                QGameState neighbor = QGameStateFactory.buyWorker(qEntry, bt);
                result.Add(neighbor);
            }
        }

        // The length of all the no-op edges we want to consider
        HashSet <int> waitTimes = new HashSet <int>()
        {
            10
        };

        // Branches related to Buildings
        // TODO: Why build a building if we can't populate it with a worker?
        foreach (BuildingType bt in BuildingFactory.allBuildings)
        {
            // One branch for every new possible building
            IBuilding possibleBuilding = BuildingFactory.buildNew(bt, -1, -1); // TODO: do we care about pos when doing A*?
            if (gs.canBuyBuilding(possibleBuilding))
            {
                // If we can build this building, then add a branch
                QGameState neighbor = QGameStateFactory.buyBuilding(qEntry, possibleBuilding);
                result.Add(neighbor);
            }
        }

        // Add in some no-op edges
        foreach (int waitTime in waitTimes)
        {
            result.Add(QGameStateFactory.waitTransition(qEntry, waitTime));
        }

        return(result);
    }
Beispiel #5
0
    private IEnumerator executeOrders(Stack <Work> workOrder)
    {
        this.currentStatus.text = "Working on the plan";
        foreach (Work w in workOrder)
        {
            switch (w.workType)
            {
            case EWork.Wait:
            case EWork.EMPTY:
                // A wait object is yield returned after the switch
                break;

            case EWork.BuildBuilding:
                Vector2Int nextPos = this.nextPos();
                IBuilding  b       = BuildingFactory.buildNew(w.buildingType, nextPos.x, nextPos.y);
                if (!gc.canBuildBuilding(w.buildingType, nextPos.x, nextPos.y))
                {
                    throw new System.Exception("Can't build the building for some reason : " + w.buildingType);
                }
                gc.startBuildBuilding(b);
                break;

            case EWork.BuyAndAssignWorker:
                if (!gc.canBuyWorker())
                {
                    throw new System.Exception("Can't buy worker for some reason");
                }
                gc.forceBuyWorker();
                IBuilding targetBuilding = gc.getAnyOpenBuilding(w.buildingType);
                if (targetBuilding == null)
                {
                    throw new System.Exception("No open building to assign worker to");
                }
                gc.cleanAssignWorker(targetBuilding);
                break;

            default:
                throw new System.Exception("Unknown work type: " + Enum.GetName(typeof(EWork), w.workType));
            }
            yield return(new WaitForSeconds(w.frameWait * GameSetup.TICK_LENGHT_SEC));
        }
        // Work done
        this.currentStatus.text = "Finished work";
        yield break;
    }