Commits

Mihael Peklar  committed 48d8759

Pathfinding redesigned, v indicates speed, 0.0 is unpassable.
Draws prettier things!

  • Participants
  • Parent commits 7fb10df

Comments (0)

Files changed (1)

 #include<cstdio>
 #include<algorithm>
+#include<limits>
 
 #include "map.h"
 #include "tileset.h"
 
 #define pnode _pnode
 
+const double INFINITY=numeric_limits<double>::infinity();
+
 double Map::distance(int a, int b) //samo za ortogonalno susjedne tileove
 {
 	if(a>=tiles.size() && b>=tiles.size())
 		throw 5;
 	double d1=this->tileset->getSpeed(this->tiles[a]->getType());
 	double d2=this->tileset->getSpeed(this->tiles[b]->getType());
-	return (d1+d2)/2;
+	if(d1==-1.0 || d2==-1.0)
+		return INFINITY;
+	return (1/d1+1/d2)/2;
+		
 }
 
 std::vector<int> Map::find_path(int s, int e)
 		if(blocked[c] || visited[c])
 			continue;
 		visited[c]=true;
+		if(d==INFINITY)
+			continue;
 		int y=c/tilesPerRow;
 		int x=c-y*tilesPerRow;
 		mem.push_back(make_pair(c, p));
 }
 
 #include<GL/gl.h>
+extern Font* test;
+char temp[30];
 
 void Map::drawPath(vector<int> path)
 {
     for(vector<int>::iterator i=path.begin(); i!=path.end(); ++i)
     {
         glVertex2f((*i%this->tilesPerRow)*TILE_WIDTH, -(*i/this->tilesPerRow)*TILE_HEIGHT);
-        printf("%g %g, ", (*i%this->tilesPerRow)*TILE_WIDTH, -(*i/this->tilesPerRow)*TILE_HEIGHT);
     }
-    printf("voila!\n");
     glEnd();
     glBegin(GL_POINTS);
     for(vector<int>::iterator i=path.begin(); i!=path.end(); ++i)
         glVertex2f(*i%this->tilesPerRow*TILE_WIDTH, -*i/this->tilesPerRow*TILE_HEIGHT);
     glEnd();
-    glColor4f(1.0,1.0,1.0,1.0);
+    glColor4f(0.0, 1.0, 1.0, 0.5);
+    glBegin(GL_POINTS);
+    for(int i=0; i<blocked.size(); ++i)
+    	if(blocked[i])
+	        glVertex2f(i%this->tilesPerRow*TILE_WIDTH, -i/this->tilesPerRow*TILE_HEIGHT);
+    glEnd();
+    glColor4f(1.0,1.0,1.0, 0.5);
+    glEnable(GL_TEXTURE_2D);
+    for(int i=0; i<this->tiles.size(); ++i)
+    {
+    	sprintf(temp, "%.3f", this->tileset->getSpeed(tiles[i]->getType()));
+        test->drawCenteredLine(temp, i%this->tilesPerRow*TILE_WIDTH, -i/this->tilesPerRow*TILE_HEIGHT);
+    }
+    glColor4f(1.0,1.0,1.0, 1.0);
 }