CPathfinder.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "global.h"
  2. #include "CPathfinder.h"
  3. #define CGI (CGameInfo::mainObj)
  4. CPath * CPathfinder::getPath(int3 &src, int3 &dest)
  5. {
  6. if(src.z!=dest.z) //first check
  7. return NULL;
  8. //graph initialization
  9. graph.resize(CGI->ac->map.width);
  10. for(int i=0; i<graph.size(); ++i)
  11. {
  12. graph[i].resize(CGI->ac->map.height);
  13. for(int j=0; j<graph[i].size(); ++j)
  14. {
  15. graph[i][j].accesible = true;
  16. graph[i][j].dist = -1;
  17. graph[i][j].theNodeBefore = NULL;
  18. graph[i][j].x = i;
  19. graph[i][j].y = j;
  20. }
  21. }
  22. for(int h=0; h<CGI->objh->objInstances.size(); ++h)
  23. {
  24. if(CGI->objh->objInstances[h].pos.z == src.z)
  25. {
  26. unsigned char blockMap[6];
  27. std::string ourName = CGI->ac->map.defy[CGI->objh->objInstances[h].defNumber].name;
  28. std::transform(ourName.begin(), ourName.end(), ourName.begin(), (int(*)(int))toupper);
  29. for(int y=0; y<CGI->dobjinfo->objs.size(); ++y)
  30. {
  31. std::string cName = CGI->dobjinfo->objs[y].defName;
  32. std::transform(cName.begin(), cName.end(), cName.begin(), (int(*)(int))toupper);
  33. if(cName==ourName)
  34. {
  35. for(int u=0; u<6; ++u)
  36. {
  37. blockMap[u] = CGI->dobjinfo->objs[y].blockMap[u];
  38. }
  39. break;
  40. }
  41. }
  42. for(int i=0; i<6; ++i)
  43. {
  44. for(int j=0; j<8; ++j)
  45. {
  46. int cPosX = CGI->objh->objInstances[h].pos.x - j;
  47. int cPosY = CGI->objh->objInstances[h].pos.y - i;
  48. if(cPosX>0 && cPosY>0)
  49. {
  50. graph[cPosX][cPosY].accesible = blockMap[i] & (128 >> j);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. //graph initialized
  57. return NULL;
  58. }