Example #1
0
    /**
     * helper function that scans neighbors for a shorter path to a vertex
     * @param v the vertex whose neighbors we will scan
     */
    private void findMinimalDistance(Vertex v)
    {
        ICollection neighbors = v.getNeighbors();

        // check all neighbors of this vertex.
        foreach (Vertex neighbor in neighbors)
        {
            // if there is a shorter path to vertex v via this neighbor
            if (getWeightofPathtoVertex(neighbor) > getWeightofPathtoVertex(v) + getEdgeWeight(v, neighbor))
            {
                // update the distance
                weightToTarget[neighbor] = getWeightofPathtoVertex(v) + getEdgeWeight(v, neighbor);
                // mark the neighbor as the previous step in path to source vertex
                predecessor[neighbor] = v;
                // and add neighbor to unvisited list.
                openVertices.Add(neighbor);
            }
        }
    }
Example #2
0
 public void SpreadDeitonBiome(Vertex v)
 {
     if (v.getBiome() == LOW_BIOME || v.getBiome() == OIL_BIOME || v.getBiome() == WATER_BIOME || v.getBiome() == STONE_BIOME)
     {
         v.setBiome(DEITON_BIOME);
         ResourceController resourceCont = (GameObject.FindObjectOfType(typeof(ResourceController)) as ResourceController);
         if (resourceCont != null)
         {
             resourceCont.DeitonMade(v);
         }
         Vertex[] neighbors = v.getNeighbors();
         for (int i = 0; i < neighbors.Length; i++)
         {
             if (neighbors[i].getHeight() < 0 && neighbors[i].getBiome() != STONE_BIOME)
             {
                 SpreadDeitonBiome(neighbors[i]);
             }
         }
     }
 }
Example #3
0
 public void SpreadOilBiome(Vertex v)
 {
     if (v.getBiome() == LOW_BIOME || v.getBiome() == WATER_BIOME || v.getBiome() == STONE_BIOME)
     {
         v.setBiome(OIL_BIOME);
         ResourceController resourceCont = (GameObject.FindObjectOfType(typeof(ResourceController)) as ResourceController);
         if (resourceCont != null)
         {
             resourceCont.OilMade(v);
         }
         (GameObject.FindObjectOfType(typeof(MusicController)) as MusicController).StartPlacing();
         Vertex[] neighbors = v.getNeighbors();
         for (int i = 0; i < neighbors.Length; i++)
         {
             if (neighbors[i].getHeight() < 0 && neighbors[i].getBiome() != OIL_BIOME)
             {
                 SpreadOilBiome(neighbors[i]);
             }
         }
     }
 }
Example #4
0
 public void SpreadStoneBiome(Vertex v)
 {
     if (v.getBiome() == LOW_BIOME || v.getBiome() == OIL_BIOME || v.getBiome() == WATER_BIOME)
     {
         v.setBiome(STONE_BIOME);
         ResourceController resourceCont = (GameObject.FindObjectOfType(typeof(ResourceController)) as ResourceController);
         if (resourceCont != null)
         {
             resourceCont.StoneMade(v);
         }
         GameObject stone = Resources.Load("Prefabs/Stone" + Random.Range(0, 1), typeof(GameObject)) as GameObject;
         stone = Instantiate(stone, transform.TransformPoint(v.getSphereVector()), Quaternion.identity) as GameObject;
         //v.removeResource ();
         //v.setResource (stone);
         Vertex[] neighbors = v.getNeighbors();
         for (int i = 0; i < neighbors.Length; i++)
         {
             if (neighbors[i].getHeight() < 0 && neighbors[i].getBiome() != STONE_BIOME)
             {
                 SpreadStoneBiome(neighbors[i]);
             }
         }
     }
 }
Example #5
0
		//------------------TOPOLOGICAL-SORTING-----------------------------------

		public void depthFirstTS(Vertex v, List<Vertex> list) {

			Edge edge;
			v.setVisited(true);

			foreach (Vertex neighbor in v.getNeighbors()) {
				edge = findEdge(v, neighbor);
				if( !neighbor.isVisited() && (edge != null) )
					depthFirstTS(neighbor, list);
			}

			list.Add(v);
		}