/** *<summary> * Returns an int representing the surplus/deficit for a given Tile based on its <see cref="NodeTickInputData"/> and the current resources available for feeding *</summary> */ int calculateTileSurplus(int[,,] creatureAmountsByTile, NodeTickInputData currentTileInputData) { //If there are no creatures on the tile, confirm that it has an available resource then return 1 if (currentTileInputData.amountOfCreaturesOnTile == 0) { int availableResources = 0; int retValue = 0; while (availableResources < 1 && currentTileInputData.neighborStack.Count > 0) { NodePosition nodePos = currentTileInputData.neighborStack.Pop(); for (int i = 0; i < DataManager.amountOfCreatures; i++) { if (creatureAmountsByTile[nodePos.xIndex, nodePos.zIndex, i] > 0) { retValue = 1; } } } if (currentTileInputData.type != CreatureType.VEGETATION) { Debug.Log("Retvalue: " + retValue); } return(retValue); } int deficit = DataManager.creatureLookupTable.creatureData[(int)currentTileInputData.type].energyCostPerTick * currentTileInputData.amountOfCreaturesOnTile; //Creature is fed when deficit <= 0 or has run out of neighbors to feed off of while (currentTileInputData.neighborStack.Count > 0 && deficit > 0) { NodePosition nodePos = currentTileInputData.neighborStack.Pop(); for (int i = 0; i < DataManager.amountOfCreatures; i++) { int amountOfResourceOnTile = creatureAmountsByTile[nodePos.xIndex, nodePos.zIndex, i]; if (deficit >= amountOfResourceOnTile) { deficit -= amountOfResourceOnTile; creatureAmountsByTile[nodePos.xIndex, nodePos.zIndex, i] = 0; } else { creatureAmountsByTile[nodePos.xIndex, nodePos.zIndex, i] -= deficit; deficit -= amountOfResourceOnTile; } } } return(-deficit); }
/** *<summary> * Returns an array of integers representing the amount of each type of creature the given tile will need to be fully satisfied *</summary> */ int[] getAmountOfResourcesNeeded(NodeTickInputData currentTileInputData) { int[] retValue = new int[DataManager.amountOfCreatures]; DataManager.creatureLookupTable.creatureData[(int)currentTileInputData.type].percentOfResourceAvailable.CopyTo(retValue, 0); for (int i = 0; i < DataManager.amountOfCreatures; i++) { if (DataManager.creatureLookupTable.creatureData[(int)currentTileInputData.type].feedingEnabled[i]) { retValue[i] *= currentTileInputData.amountOfCreaturesOnTile; } else { retValue[i] = 0; } } return(retValue); }
/** *<summary> * Surveys the game state and returns a <see cref="Tick"/> to be sent in <see cref"TickUpdateEvent"/> *</summary> */ Tick getNextTick() { NodeTickInputData[,] tickData = new NodeTickInputData[NodeManager.MapWidth, NodeManager.MapLength]; Queue <NodePosition>[] tilesByCreatureTypeQueue = new Queue <NodePosition> [DataManager.amountOfCreatures]; for (int i = 0; i < DataManager.amountOfCreatures; i++) { tilesByCreatureTypeQueue[i] = new Queue <NodePosition>(); } for (int i = 0; i < NodeManager.MapWidth; i++) { for (int j = 0; j < NodeManager.MapLength; j++) { NodeModel workingNode = NodeManager.getNode(i, j); if (workingNode != null) { tickData[i, j] = workingNode.getNodeTickData(); tilesByCreatureTypeQueue[(int)workingNode.type].Enqueue(workingNode.nodePos); } } } return(new Tick(tickData, tilesByCreatureTypeQueue, getWeatherEffect())); }