CCallback.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "stdafx.h"
  2. #include "CCallback.h"
  3. #include "CPathfinder.h"
  4. #include "hch\CHeroHandler.h"
  5. #include "hch\CTownHandler.h"
  6. #include "CGameInfo.h"
  7. #include "hch\CAmbarCendamo.h"
  8. #include "mapHandler.h"
  9. #include "CGameState.h"
  10. #include "CGameInterface.h"
  11. bool CCallback::moveHero(int ID, int3 destPoint)
  12. {
  13. if(ID<0 || ID>CGI->heroh->heroInstances.size())
  14. return false;
  15. if(destPoint.x<0 || destPoint.x>CGI->ac->map.width)
  16. return false;
  17. if(destPoint.y<0 || destPoint.y>CGI->ac->map.height)
  18. return false;
  19. if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
  20. return false;
  21. CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
  22. if(!ourPath)
  23. return false;
  24. for(int i=ourPath->nodes.size()-1; i>0; i--)
  25. {
  26. int3 stpos, endpos;
  27. stpos = int3(ourPath->nodes[i].coord.x, ourPath->nodes[i].coord.y, CGI->heroh->heroInstances[ID]->pos.z);
  28. endpos = int3(ourPath->nodes[i-1].coord.x, ourPath->nodes[i-1].coord.y, CGI->heroh->heroInstances[ID]->pos.z);
  29. HeroMoveDetails curd;
  30. curd.src = stpos;
  31. curd.dst = endpos;
  32. curd.heroID = ID;
  33. curd.owner = CGI->heroh->heroInstances[ID]->owner;
  34. //if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
  35. { //performing move
  36. int nn=0; //number of interfece of currently browsed player
  37. for(std::map<int, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing
  38. {
  39. if(j->second.fogOfWarMap[stpos.x][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x][endpos.y][endpos.z])
  40. { //player should be notified
  41. CGI->playerint[nn]->heroMoved(curd);
  42. }
  43. ++nn;
  44. break; //for testing only
  45. }
  46. }
  47. //else
  48. //return true; //move ended - no more movement points
  49. }
  50. return true;
  51. }
  52. int CCallback::howManyTowns()
  53. {
  54. return gs->players[gs->currentPlayer].towns.size();
  55. }
  56. const CTownInstance * CCallback::getTownInfo(int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
  57. {
  58. if (!mode)
  59. return gs->players[gs->currentPlayer].towns[val];
  60. else
  61. {
  62. //TODO: add some smart ID to the CTownInstance
  63. //for (int i=0; i<gs->players[gs->currentPlayer].towns.size();i++)
  64. //{
  65. // if (gs->players[gs->currentPlayer].towns[i]->someID==val)
  66. // return gs->players[gs->currentPlayer].towns[i];
  67. //}
  68. return NULL;
  69. }
  70. return NULL;
  71. }
  72. int CCallback::howManyHeroes(int player)
  73. {
  74. if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
  75. return -1;
  76. return gs->players[player].heroes.size();
  77. }
  78. const CHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
  79. {
  80. if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
  81. return NULL;
  82. if (!mode)
  83. return gs->players[player].heroes[val];
  84. else
  85. {
  86. for (int i=0; i<gs->players[player].heroes.size();i++)
  87. {
  88. if (gs->players[player].heroes[i]->type->ID==val)
  89. return gs->players[player].heroes[i];
  90. }
  91. }
  92. return NULL;
  93. }
  94. int CCallback::getResourceAmount(int type)
  95. {
  96. return gs->players[gs->currentPlayer].resources[type];
  97. }
  98. int CCallback::getDate(int mode)
  99. {
  100. int temp;
  101. switch (mode)
  102. {
  103. case 0:
  104. return gs->day;
  105. case 1:
  106. temp = (gs->day)%7;
  107. if (temp)
  108. return temp;
  109. else return 7;
  110. case 2:
  111. temp = ((gs->day-1)/7)+1;
  112. if (temp%4)
  113. return temp;
  114. else return 4;
  115. case 3:
  116. return ((gs->day-1)/28)+1;
  117. }
  118. }