I haven`t run this code a single time it`s still at the pseudo-code level
while(!exit)
{
PathTile BestNode;
if(firstrun)
{
BestNode.x = Startx;
BestNode.z = Startz;
firstrun =false;
}
BestNode.weight = 1000;
for(int i =0; i < TrunkListCount; i ++)
{
if(!BestNode.cold)
{
if(TrunkList[i].weight < BestNode.weight)
{
BestNode.weight = TrunkList[i].weight;
BestNode.x = TrunkList[i].x;
BestNode.z = TrunkList[i].z;
}
}
}
if((BestNode.x != Endx)||(BestNode.z != Endz))
{
int x = BestNode.x;
int z = BestNode.z;
if(NodeCoord(x,z+1).access)//n
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x,z+1).x)&&(TrunkList[i].z == NodeCoord(x,z+1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x,z+1).x;
TrunkList[TrunkListCount].z = NodeCoord(x,z+1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x,z+1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
}
}
if(NodeCoord(x+1,z+1).access)//ne
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x+1,z+1).x)&&(TrunkList[i].z == NodeCoord(x+1,z+1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x+1,z+1).x;
TrunkList[TrunkListCount].z = NodeCoord(x+1,z+1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x+1,z+1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
}
}
if(NodeCoord(x+1,z).access)//e
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x+1,z).x)&&(TrunkList[i].z == NodeCoord(x+1,z).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x+1,z).x;
TrunkList[TrunkListCount].z = NodeCoord(x+1,z).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x+1,z,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
}
}
if(NodeCoord(x+1,z-1).access)//se
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x+1,z-1).x)&&(TrunkList[i].z == NodeCoord(x+1,z-1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x+1,z-1).x;
TrunkList[TrunkListCount].z = NodeCoord(x+1,z-1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x+1,z-1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
} }
if(NodeCoord(x,z-1).access)//s
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x,z-1).x)&&(TrunkList[i].z == NodeCoord(x,z-1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x,z-1).x;
TrunkList[TrunkListCount].z = NodeCoord(x,z-1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x,z-1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
}
}
if(NodeCoord(x-1,z-1).access)//sw
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x-1,z-1).x)&&(TrunkList[i].z == NodeCoord(x-1,z-1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x-1,z-1).x;
TrunkList[TrunkListCount].z = NodeCoord(x-1,z-1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x-1,z-1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
} }
if(NodeCoord(x-1,z).access)//w
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x+1,z-1).x)&&(TrunkList[i].z == NodeCoord(x+1,z-1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x+1,z-1).x;
TrunkList[TrunkListCount].z = NodeCoord(x+1,z-1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x+1,z-1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
}}
if(NodeCoord(x-1,z+1).access)//nw
{
exists = false;
for(int i =0; i < TrunkListCount; i++)
{
if((TrunkList[i].x == NodeCoord(x-1,z+1).x)&&(TrunkList[i].z == NodeCoord(x-1,z+1).z))
{
exists = true;
}
}
if(!exists)
{
TrunkListCount++;
TrunkList[TrunkListCount].x = NodeCoord(x-1,z+1).x;
TrunkList[TrunkListCount].z = NodeCoord(x-1,z+1).z;
TrunkList[TrunkListCount].index = TrunkListCount;
NodeCoord(x-1,z+1,TrunkListCount);
TrunkList[TrunkListCount].Parent = NodeCoord(x,z).tileindex;
} }
}
else
{
exit = true;
}
}