private void displayBuildingResouceDelta(IBuilding newBuiding) { // Updates the resource display for only the resources this building cares about // IE: input, output and cost to build resources // Update the income per turn for the building List <ResourceType> allResources = newBuiding.outputResources(); allResources.AddRange(newBuiding.inputResources()); foreach (ResourceType rt in allResources) { int newStockpile = gameState.getStockpile(rt); int newRPT = gameState.getChangePerTick(rt); resourceDisplay.updateCountAndRPT(rt, newStockpile, newRPT); } // Update the cost to build the building foreach (ResourceChange rc in newBuiding.costToBuild()) { if (allResources.Contains(rc.resourceType)) { continue; } // If we've already updated this resource type above ignore it int newStockpile = gameState.getStockpile(rc.resourceType); resourceDisplay.updateResourceCount(rc.resourceType, newStockpile); } }
private void updateAiResourceDisplay() { Debug.Log("Updating ai resource display"); Debug.Log(bank + ", " + stone + ", " + wood + ", " + silver); foreach (ResourceType rt in aiCurrentGameState.getAllResourceTypes()) { //Debug.Log("update: " + rt + ", " + aiCurrentGameState.getStockpile(rt)); aiResourceDisplay.updateCountAndRPT(rt, aiCurrentGameState.getStockpile(rt), aiCurrentGameState.getChangePerTick(rt)); } aiResourceDisplay.updateWorkers(); }
private void updateTargetDisplay(BuildingGS gameState, int indexActor) { Debug.Log("actor to update target display: " + indexActor); ResourceDisplayController rdc = meTargetDisplay; if (indexActor == indexAi) { rdc = aiTargetDisplay; } foreach (ResourceType rt in gameState.getAllResourceTypes()) { rdc.updateCountAndRPT(rt, gameState.getStockpile(rt), gameState.getChangePerTick(rt)); } }
private bool isTargetReached(int indexActor) { BuildingGS gsToCheck = GameController.gameState; if (indexActor == indexAi) { gsToCheck = aiCurrentGameState; } BuildingGS targetGs = targetGameStates[currentTargetGsIndex[indexActor]]; foreach (ResourceType rt in gsToCheck.getAllResourceTypes()) { if ((gsToCheck.getStockpile(rt) < targetGs.getStockpile(rt)) || (gsToCheck.getChangePerTick(rt) < targetGs.getChangePerTick(rt))) { return(false); } } Debug.Log("Target reached for : " + indexActor); return(true); }
public static RemainingDistance estematedRemainingDistance(BuildingGS currentGS, BuildingGS targetGS) { // How far away are we from the target? RemainingDistance result = new RemainingDistance(); // Compare numerical distance foreach (ResourceType rt in targetGS.getAllResourceTypes()) { int currentStockpile = currentGS.getStockpile(rt); int targetStockpile = targetGS.getStockpile(rt); int stockpileDelta = Mathf.Max(0, targetStockpile - currentStockpile); result.updateStockpileDelta(stockpileDelta); int currentResourcePerTick = currentGS.getChangePerTick(rt); int targetResourcePerTick = targetGS.getChangePerTick(rt); int rptDelta = Mathf.Max(0, targetResourcePerTick - currentResourcePerTick); result.updateCPTDelta(rt, rptDelta); int currentBestResourcePerTick = currentGS.getBestPossibleChangePerTick(rt); int bestPossibleRPTDelta = Mathf.Max(0, targetResourcePerTick - currentBestResourcePerTick); result.updateBestPossibleCPTDelta(bestPossibleRPTDelta); if (currentResourcePerTick <= 0) { result.addInfinity(); } else { float exactWaitTime = stockpileDelta / (float)currentResourcePerTick; int estWaitTime = (int)(exactWaitTime + 0.5f); result.updateWaitTime(estWaitTime); float bestPossibleWaitTime = stockpileDelta / (float)currentBestResourcePerTick; int estBestWaitTime = (int)(bestPossibleWaitTime + 0.5f); result.updateBestPossibleWaitTime(estBestWaitTime); } } return(result); }
private BuildingGS modifyGameStateForPersonality(BuildingGS targetGsHuman, AIPersonalityType aiPersonality) { switch (aiPersonality) { case AIPersonalityType.GoldDigger: targetGsHuman.setStockpile(ResourceType.Gold, targetGsHuman.getStockpile(ResourceType.Gold) * 2); targetGsHuman.addResourcePerTick(ResourceType.Gold, targetGsHuman.getChangePerTick(ResourceType.Gold) * 2); break; case AIPersonalityType.Pragmatist: foreach (ResourceType rt in targetGsHuman.getStockpileResourceTypes()) { targetGsHuman.setStockpile(rt, (int)(targetGsHuman.getStockpile(rt) * 1.3)); } break; case AIPersonalityType.Warrior: case AIPersonalityType.ScienceGeek: case AIPersonalityType.Conservative: default: break; } return(targetGsHuman); }
private void calculatePreRecDelta() { // Look through the remaining rpt delta // For each type of resource, how many pre recs do we have // Over the required amount _reccomendedPreRecDelta = 0; // Figure out what rpt types are not up to snuff foreach (ResourceType actualTargetResource in distanceRuler.getRemainingResourceTypes()) { //Debug.Log("Considering " + actualTargetResource); int contribution = 0; // Find all the reccomended pre-recs for that resource foreach (var kvp in hiddenReq.getAllHiddenCosts(actualTargetResource)) { ResourceType reccomendedExtraResource = kvp.Key; int reccomendedExtraIncome = kvp.Value; //Debug.Log(" has hiddenRed: " + reccomendedExtraResource); // Calculate our actual extra income for the recomended resource int surplussIncome = Math.Max(0, currentNode.gameState.getChangePerTick(reccomendedExtraResource) - targetGS.getChangePerTick(reccomendedExtraResource)); //Debug.Log(" surpluss = " + surplussIncome); //Debug.Log(" reccomended surplus: " + reccomendedExtraIncome); contribution += Math.Max(0, reccomendedExtraIncome - surplussIncome); //Debug.Log(" new individual contra: " + contribution); } //Debug.Log("Contribution : " + contribution); //Debug.Log("num of resouce: " + distanceRuler.specificCPTDistance(actualTargetResource)); _reccomendedPreRecDelta += contribution * distanceRuler.specificCPTDistance(actualTargetResource); //Debug.Log("new preRecDelta: " + _reccomendedPreRecDelta); } //Debug.Log("End"); preCalculatedPreRecDelta = true; }