CCallback.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "stdafx.h"
  2. #include "CCallback.h"
  3. #include "CPathfinder.h"
  4. #include "hch\CHeroHandler.h"
  5. #include "CGameInfo.h"
  6. #include "hch\CAmbarCendamo.h"
  7. #include "mapHandler.h"
  8. #include "CGameState.h"
  9. #include "CGameInterface.h"
  10. bool CCallback::moveHero(int ID, int3 destPoint)
  11. {
  12. if(ID<0 || ID>CGI->heroh->heroInstances.size())
  13. return false;
  14. if(destPoint.x<0 || destPoint.x>CGI->ac->map.width)
  15. return false;
  16. if(destPoint.y<0 || destPoint.y>CGI->ac->map.height)
  17. return false;
  18. if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
  19. return false;
  20. CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
  21. if(!ourPath)
  22. return false;
  23. for(int i=ourPath->nodes.size()-1; i>0; i--)
  24. {
  25. int3 stpos, endpos;
  26. stpos = int3(ourPath->nodes[i].x, ourPath->nodes[i].y, CGI->heroh->heroInstances[ID]->pos.z);
  27. endpos = int3(ourPath->nodes[i-1].x, ourPath->nodes[i-1].y, CGI->heroh->heroInstances[ID]->pos.z);
  28. HeroMoveDetails curd;
  29. curd.src = stpos;
  30. curd.dst = endpos;
  31. curd.heroID = ID;
  32. curd.owner = CGI->heroh->heroInstances[ID]->owner;
  33. //if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
  34. { //performing move
  35. int nn=0; //number of interfece of currently browsed player
  36. for(std::map<int, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing
  37. {
  38. if(j->second.fogOfWarMap[stpos.x][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x][endpos.y][endpos.z])
  39. { //player should be notified
  40. CGI->playerint[nn]->heroMoved(curd);
  41. }
  42. ++nn;
  43. break; //for testing only
  44. }
  45. }
  46. //else
  47. //return true; //move ended - no more movement points
  48. }
  49. return true;
  50. }
  51. int CCallback::howManyHeroes(int player)
  52. {
  53. if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
  54. return -1;
  55. return gs->players[player].heroes.size();
  56. }
  57. const CHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
  58. {
  59. if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
  60. return NULL;
  61. if (!mode)
  62. return gs->players[player].heroes[val];
  63. else
  64. {
  65. for (int i=0; i<gs->players[player].heroes.size();i++)
  66. {
  67. if (gs->players[player].heroes[i]->type->ID==val)
  68. return gs->players[player].heroes[i];
  69. }
  70. }
  71. return NULL;
  72. }
  73. int CCallback::getResourceAmount(int type)
  74. {
  75. return gs->players[gs->currentPlayer].resources[type];
  76. }