Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. Replicator::Replicator(WorldObjects& worldObjects, WorldReplicators& replicators, std::string ID, unsigned int category, unsigned int energy) :
  2.     ChargedObject(energy), m_ID(ID), m_category(category), m_Leader(NULL)
  3. {
  4.     if( ( getCounter()++ ) == 0 )
  5.         srand(time(0));
  6.  
  7.     setPosition( rand() % WORLD_BOUNDARIES_X, rand() % WORLD_BOUNDARIES_Y );
  8.     setRadius( REPLICATOR_BASE_ABSORPTION_RADIUS );
  9.  
  10.     m_targetMarked = false;
  11.  
  12.  
  13.     /** Behaviour Management **/
  14.  
  15.     /// The blackboard represents the memory and the senses of this Replicator
  16.  
  17.     m_bt.setBlackboard( new ReplicatorBlackboard(*this, worldObjects, replicators) );
  18.  
  19.     /// This tree will only have two nodes
  20.  
  21.     /// I) The first one is going to represent the logic for seeking nearby objects charged with energy
  22.  
  23.     BT_Node *searchForEnergy = new BT_Node("Search for energy");
  24.  
  25.     m_bt.add( searchForEnergy );
  26.  
  27.     /// First we add a service that is going to search for the closest charged object
  28.  
  29.     searchForEnergy->add( new ReplicatorService_FindClosestObject );
  30.  
  31.     /** Then we add some conditions to see if we want to go for this object
  32.     *** 1) Do we need more energy ?
  33.     *** 2) Do we have enough energy to move to this object ?
  34.     **/
  35.  
  36.     searchForEnergy->add( new ReplicatorCheck_LowEnergy );
  37.     searchForEnergy->add( new ReplicatorCheck_TargetReachable );
  38.  
  39.     /// II) The second node is going to represent the logic for seeking another Replicator of a higher category in case we already
  40.     ///     have enough energy
  41.  
  42.     BT_Node *searchForHigherReplicators = new BT_Node("Search for higher Replicators");
  43.  
  44.     m_bt.add( searchForHigherReplicators );
  45.  
  46.     /// First we add a service that is going to search for a higher Replicator nearby
  47.  
  48.     searchForHigherReplicators->add( new ReplicatorService_FindHigherReplicator );
  49.  
  50.     /** Then we add some conditions to see if we want to go after this Replicator
  51.     *** 1) Do we have enough energy to move to this object...
  52.     *** 2) AND Do we have enough energy to download it's data ?
  53.     **/
  54.  
  55.     searchForEnergy->add( new ReplicatorCheck_CanReachTargetAndDownload );
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement