예제 #1
0
        /**
         *<summary>
         * Updates the road visuals for this node based on the neighbors
         * Calls 2nd gen redrawRoads for direct neighbors
         *</summary>
         */
        public void redrawRoads()
        {
            view.redrawRoads(nodePos);

            NodeModel temp = NodeManager.getNode(nodePos.xIndex + 1, nodePos.zIndex);

            if (temp != null)
            {
                temp.redrawRoads2ndGen();
            }

            temp = NodeManager.getNode(nodePos.xIndex - 1, nodePos.zIndex);
            if (temp != null)
            {
                temp.redrawRoads2ndGen();
            }

            temp = NodeManager.getNode(nodePos.xIndex, nodePos.zIndex + 1);
            if (temp != null)
            {
                temp.redrawRoads2ndGen();
            }

            temp = NodeManager.getNode(nodePos.xIndex, nodePos.zIndex - 1);
            if (temp != null)
            {
                temp.redrawRoads2ndGen();
            }
        }
예제 #2
0
        /**
         *<summary>
         * Adds all direct neighbors of a node to a stack and as well as any node connected to the node by roads
         *</summary>
         */
        void populateFrontier(Stack <NodeModel> stack, NodeModel node)
        {
            NodeModel workingModel = NodeManager.getNode(node.nodePos.xIndex + 1, node.nodePos.zIndex);

            if (workingModel != null)
            {
                stack.Push(workingModel);
                workingModel.visitedThisTickUpdatePass = true;
                addNeighbors(stack, workingModel);
            }

            workingModel = NodeManager.getNode(node.nodePos.xIndex - 1, node.nodePos.zIndex);
            if (workingModel != null)
            {
                stack.Push(workingModel);
                workingModel.visitedThisTickUpdatePass = true;
                addNeighbors(stack, workingModel);
            }

            workingModel = NodeManager.getNode(node.nodePos.xIndex, node.nodePos.zIndex + 1);
            if (workingModel != null)
            {
                stack.Push(workingModel);
                workingModel.visitedThisTickUpdatePass = true;
                addNeighbors(stack, workingModel);
            }

            workingModel = NodeManager.getNode(node.nodePos.xIndex, node.nodePos.zIndex - 1);
            if (workingModel != null)
            {
                stack.Push(workingModel);
                workingModel.visitedThisTickUpdatePass = true;
                addNeighbors(stack, workingModel);
            }
        }
예제 #3
0
        /**
         *<summary>
         * Returns a 3D array of integers capturing the current amount of resources (read: creatures) available for tiles to feed off of this tick
         *</summary>
         */
        int[,,] getCurrentCreatureAmountsByTile(CreatureType creatureTypeOnCurrentTile)
        {
            int[,,] retValue = new int[NodeManager.MapWidth, NodeManager.MapLength, DataManager.amountOfCreatures];

            NodeModel workingModel;

            for (int i = 0; i < NodeManager.MapWidth; i++)
            {
                for (int j = 0; j < NodeManager.MapLength; j++)
                {
                    for (int k = 0; k < DataManager.amountOfCreatures; k++)
                    {
                        workingModel = NodeManager.getNode(i, j);
                        if (workingModel != null)
                        {
                            if (k == 0)
                            {
                                Debug.Log("Creature Amounts: " + workingModel.getCreatureAmount(k));
                                Debug.Log("Creature Percent Available: " + DataManager.creatureLookupTable.creatureData[(int)creatureTypeOnCurrentTile].percentOfResourceAvailable[k]);
                                Debug.Log("Multiple of Creature Amounts and Percent Available: " + (workingModel.getCreatureAmount(k) * DataManager.creatureLookupTable.creatureData[(int)creatureTypeOnCurrentTile].percentOfResourceAvailable[k]));
                                Debug.Log("^^ Divided by 10: " + (workingModel.getCreatureAmount(k) * DataManager.creatureLookupTable.creatureData[(int)creatureTypeOnCurrentTile].percentOfResourceAvailable[k]) / 10);
                            }
                            retValue[i, j, k] = (workingModel.getCreatureAmount(k) * DataManager.creatureLookupTable.creatureData[(int)creatureTypeOnCurrentTile].percentOfResourceAvailable[k]) / 10;
                            //Debug.Log("CreatureAmounts for " + i + "," + j + "," + k + " : " + retValue[i, j, k]);
                        }

                        //Debug.Log(i + "," + j + "\n" + retValue[i, j, k]);
                    }
                }
            }

            return(retValue);
        }
예제 #4
0
        /**
         *<summary>
         * Responds to <see cref="NodeManager.activeNodeUpdateEvent"/>
         * Updates the ActiveNodeLabel
         * Updates the
         *</summary>
         */
        void OnActiveNodeUpdateEvent(NodePosition newActiveNode)
        {
            updateActiveNodeLabel(newActiveNode);

            NodeModel activeNodeModel = NodeManager.getNode(newActiveNode);

            updateStatsLabel(activeNodeModel.creatureAmounts);
        }
예제 #5
0
        /**
         *<summary>
         * Changes the tile Gameobject to the appropriate one and sets the rotation based on its neighbors
         *</summary>
         */
        public void redrawRoads(NodePosition nodePos)
        {
            Debug.Log("Redraw Roads is called for " + nodePos);
            bool nNeighborEnabled = false, sNeighborEnabled = false, eNeighborEnabled = false, wNeighborEnabled = false;
            int  newNeighborWithRoadCount = 0;

            NodeModel temp = NodeManager.getNode(nodePos.xIndex + 1, nodePos.zIndex);

            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    eNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            temp = NodeManager.getNode(nodePos.xIndex - 1, nodePos.zIndex);
            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    wNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            temp = NodeManager.getNode(nodePos.xIndex, nodePos.zIndex + 1);
            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    nNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            temp = NodeManager.getNode(nodePos.xIndex, nodePos.zIndex - 1);
            if (temp != null)
            {
                if (temp.roadEnabled)
                {
                    sNeighborEnabled          = true;
                    newNeighborWithRoadCount += 1;
                    Debug.Log("Got here");
                }
            }

            //Debug.Log(newNeighborWithRoadCount);

            type = assignTileRoadType(newNeighborWithRoadCount, nNeighborEnabled, sNeighborEnabled, eNeighborEnabled, wNeighborEnabled);
            updateTile(type);
            correctRoadRotation(type, nNeighborEnabled, sNeighborEnabled, eNeighborEnabled, wNeighborEnabled);
        }
예제 #6
0
        /**
         *<summary>
         * Pushes all tiles connected by roads to a given Stack
         *</summary>
         */
        void addNeighbors(Stack <NodeModel> stack, NodeModel node)
        {
            if (node.roadEnabled)
            {
                NodeModel workingModel;

                workingModel = NodeManager.getNode(node.nodePos.xIndex + 1, node.nodePos.zIndex);
                if (workingModel != null)
                {
                    if (!workingModel.visitedThisTickUpdatePass && workingModel.roadEnabled)
                    {
                        stack.Push(workingModel);
                        workingModel.visitedThisTickUpdatePass = true;

                        addNeighbors(stack, workingModel);
                    }
                }

                workingModel = NodeManager.getNode(node.nodePos.xIndex - 1, node.nodePos.zIndex);
                if (workingModel != null)
                {
                    if (!workingModel.visitedThisTickUpdatePass && workingModel.roadEnabled)
                    {
                        stack.Push(workingModel);
                        workingModel.visitedThisTickUpdatePass = true;

                        addNeighbors(stack, workingModel);
                    }
                }

                workingModel = NodeManager.getNode(node.nodePos.xIndex, node.nodePos.zIndex - 1);
                if (workingModel != null)
                {
                    if (!workingModel.visitedThisTickUpdatePass && workingModel.roadEnabled)
                    {
                        stack.Push(workingModel);
                        workingModel.visitedThisTickUpdatePass = true;

                        addNeighbors(stack, workingModel);
                    }
                }

                workingModel = NodeManager.getNode(node.nodePos.xIndex, node.nodePos.zIndex + 1);
                if (workingModel != null)
                {
                    if (!workingModel.visitedThisTickUpdatePass && workingModel.roadEnabled)
                    {
                        stack.Push(workingModel);
                        workingModel.visitedThisTickUpdatePass = true;

                        addNeighbors(stack, workingModel);
                    }
                }
            }
        }
예제 #7
0
 /**
  *<summary>
  * Responds to <see cref="NodeManager.activeNodeUpdateEvent"/>.
  * If the passed node is not null enables the SelectedTileIndicator
  * otherwise disables the indicator
  *</summary>
  */
 void OnActiveNodeUpdateEvent(NodePosition nodePos)
 {
     if (NodeManager.getNode(nodePos) == null)
     {
         active = false;
     }
     //If there's a node in the array, active == true
     else
     {
         active = true;
     }
 }
예제 #8
0
        /**
         *<summary>
         * Returns Difference between the actual population on the tile and the amount of creatures the pop can support minus the number of decomposers on the tile
         *</summary>
         */
        int calculateTilePollutionValue(int xIndex, int zIndex)
        {
            NodeModel workingNode = NodeManager.getNode(xIndex, zIndex);

            if (workingNode == null)
            {
                return(0);
            }

            if (workingNode.type == CreatureType.VEGETATION)
            {
                return(-workingNode.getCreatureAmount(DataManager.amountOfCreatures - 1));
            }
            int energyCostPerCreature = DataManager.creatureLookupTable.creatureData[(int)workingNode.type].energyCostPerTick;

            return(tickData[xIndex, zIndex] / energyCostPerCreature - workingNode.getCreatureAmount(DataManager.amountOfCreatures - 1));
        }
예제 #9
0
        int[,,] getCurrentCreatureAmountsByTile()
        {
            int[,,] retValue = new int[NodeManager.MapWidth, NodeManager.MapLength, DataManager.amountOfCreatures];

            for (int i = 0; i < NodeManager.MapWidth; i++)
            {
                for (int j = 0; j < NodeManager.MapLength; j++)
                {
                    for (int k = 0; k < DataManager.amountOfCreatures; k++)
                    {
                        retValue[i, j, k] = NodeManager.getNode(i, j).getCreatureAmount(k);
                    }
                }
            }

            return(retValue);
        }
예제 #10
0
        /**
         *<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()));
        }
예제 #11
0
        /**
         *<summary>
         * Retuns a 2D array of integers representing whether a tile had a surplus or deficit of food for this tick
         *</summary>
         */
        int[,] calculateSurplusValues(NodeTickInputData[,] tickInputData, Queue <NodePosition>[] nodePosQueue)
        {
            int[,] retValue = new int[NodeManager.MapWidth, NodeManager.MapLength];

            for (int i = 1; i < DataManager.amountOfCreatures - 1; i++)
            {
                NodePosition workingNode;
                while (nodePosQueue[i].Count > 0)
                {
                    workingNode = nodePosQueue[i].Dequeue();
                    retValue[workingNode.xIndex, workingNode.zIndex] = calculateTileSurplus(getCurrentCreatureAmountsByTile(NodeManager.getNode(workingNode).type), tickInputData[workingNode.xIndex, workingNode.zIndex]);
                }
            }
            return(retValue);
        }
예제 #12
0
 /**
  *<summary>
  * Responds to <see cref="NodeManager.activeNodeUpdateEvent"/>
  * Updates the active node <see cref="NodePosition"/>
  *</summary>
  */
 void OnActiveNodeUpdate(NodePosition nodePos)
 {
     activeNode             = nodePos;
     control.controlEnabled = true;
     setSliderValue(NodeManager.getNode(nodePos).creatureAmounts[statIndex]);
 }