Orrexon

Distance units

Apr 18th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. template<class Subject>
  2. bt1::Status bt1::ActionFindPathAndGo<Subject>::update()
  3. {
  4.     if (BB->GetGameWorldTankSearching())
  5.     {
  6.         return bt1::BH_RUNNING;
  7.     }
  8.  
  9.     sf::Vector2f goal = BB->GetGameWorldTilePosition(BB->GetGoalPosition());
  10.     sf::Vector2f start = BB->GetGameWorldTilePosition(BB->GetGameWorldTankPosition());
  11.     bool succeed = BB->GameWorldPathObjectFindPath(start, goal);
  12.     if (succeed == true)
  13.     {
  14.         std::cout << "Agent: " << BB->GetGameWorldTankID() << " Reporting to have found a path" << std::endl;
  15.         BB->SetGameWorldTankSearching(true);
  16.  
  17.  
  18. //MIND THE GetCurrentTankDistanceUnits! This is a new function in BlackBoard, it returns the distance int through gameworld::tankIter.
  19. //The definition is pasted below.
  20.  
  21. //this loop traverses the path list generated by the AStarPath object from back to front, stopping prematurely.
  22. //in this particular case GetCurrentTankDistanceUnits() returns the number two.
  23.         for (int i = (BB->GameWorldPathObjectPathListSize() - 1 ); i > BB->GetCurrentTankDistanceUnits(); i--)
  24.         {
  25.             sf::Vector2f position = BB->GetGameWorldPathObjectPathListIndexPosition(i);
  26.             BB->GameWorldTankPathAttach(position);
  27.         }
  28.         return bt1::BH_SUCCESS;
  29.     }
  30.     return bt1::BH_FAILURE;
  31. }
  32.  
  33. template<class Subject>
  34. int BlackBoard<Subject>::GetCurrentTankDistanceUnits()
  35. {
  36.     return (*gameWorld->tankIter)->distanceUnits;
  37. }
  38.  
  39. //distanceUnits is an int declared in the base class Agent, from which class Tank inherits.
Advertisement
Add Comment
Please, Sign In to add comment