Steeriously  0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
SuperComponent.hpp
1 #ifndef SuperComponent_HPP
2 #define SuperComponent_HPP
3 
4 #include <steeriously/libinc.hpp>
5 
6 namespace steer
7 {
13  {
14  public:
16  virtual ~SuperComponent();
17 
18  void setParams(steer::BehaviorParameters* params) { m_params = params; };
19  steer::BehaviorParameters* getParams() { return m_params; };
20 
21  void Update(float dt);
22 
27  float getRotation() { return m_rotation; };
28 
29  void setNeighbors(std::vector<SuperComponent*>* n) { m_neighbors = n; };
30  std::vector<SuperComponent*>* getNeighbors() { return m_neighbors; };
31 
32  void setObstacles(std::vector<SphereObstacle*>* o) { m_obstacles = o; };
33  std::vector<SphereObstacle*>* getObstacles() { return m_obstacles; };
34 
35  void setWalls(std::vector<Wall*>* w) { m_walls = w; };
36  std::vector<Wall*>* getWalls() { return m_walls; };
37 
38  void setPath(steer::Path* p){m_path = p;};
39  steer::Path* getPath() const {return m_path;};
40 
41  //pure virtual - must implement see Agent.hpp
42  virtual bool on(steer::behaviorType behavior) override { return (m_iFlags & behavior) == behavior; };
43 
44  void alignmentOn() { m_iFlags |= steer::behaviorType::alignment; };
45  void separationOn() { m_iFlags |= steer::behaviorType::separation; };
46  void cohesionOn() { m_iFlags |= steer::behaviorType::cohesion; };
47  void seekOn() { m_iFlags |= steer::behaviorType::seek; };
48  void wanderOn() { m_iFlags |= steer::behaviorType::wander; };
49  void wallAvoidanceOn() { m_iFlags |= steer::behaviorType::wallAvoidance; };
50  void obstacleAvoidanceOn() { m_iFlags |= steer::behaviorType::obstacleAvoidance; };
51  void pursuitOn(){m_iFlags |= steer::behaviorType::pursuit;};
52  void offsetPursuitOn(){m_iFlags |= steer::behaviorType::offsetPursuit;};
53  void interposeOn(){m_iFlags |= steer::behaviorType::interpose;};
54  void hideOn(){m_iFlags |= steer::behaviorType::hide;};
55  void pathFollowingOn(){m_iFlags |= steer::behaviorType::followPath;};
56  void fleeOn(){m_iFlags |= steer::behaviorType::flee;};
57  void evadeOn(){m_iFlags |= steer::behaviorType::evade;};
58  void arriveOn(){m_iFlags |= steer::behaviorType::arrive;};
59 
60  void cohesionOff() { if (on(steer::behaviorType::cohesion)) m_iFlags ^= steer::behaviorType::cohesion; };
61  void separationOff() { if (on(steer::behaviorType::separation)) m_iFlags ^= steer::behaviorType::separation; };
62  void alignmentOff() { if (on(steer::behaviorType::alignment)) m_iFlags ^= steer::behaviorType::alignment; };
63  void seekOff() { if (on(steer::behaviorType::seek)) m_iFlags ^= steer::behaviorType::seek; };
64  void wanderOff() { if (on(steer::behaviorType::wander)) m_iFlags ^= steer::behaviorType::wander; };
65  void wallAvoidanceOff() { if (on(steer::behaviorType::wallAvoidance)) m_iFlags ^= steer::behaviorType::wallAvoidance; };
66  void obstacleAvoidanceOff() { if (on(steer::behaviorType::obstacleAvoidance)) m_iFlags ^= steer::behaviorType::obstacleAvoidance; };
67  void pursuitOff(){if(on(steer::behaviorType::pursuit)) m_iFlags ^=steer::behaviorType::pursuit;};
68  void offsetPursuitOff(){if(on(steer::behaviorType::offsetPursuit)) m_iFlags ^=steer::behaviorType::offsetPursuit;}
69  void interposeOff(){if(on(steer::behaviorType::interpose)) m_iFlags ^=steer::behaviorType::interpose;}
70  void hideOff(){if(on(steer::behaviorType::hide)) m_iFlags ^=steer::behaviorType::hide;}
71  void pathFollowingOff(){if(on(steer::behaviorType::followPath)) m_iFlags ^=steer::behaviorType::followPath;}
72  void fleeOff(){if(on(steer::behaviorType::flee)) m_iFlags ^=steer::behaviorType::flee;}
73  void evadeOff(){if(on(steer::behaviorType::evade)) m_iFlags ^=steer::behaviorType::evade;}
74  void arriveOff(){if(on(steer::behaviorType::arrive)) m_iFlags ^=steer::behaviorType::arrive;}
75 
76  bool isCohesionOn() { return on(steer::behaviorType::cohesion); };
77  bool isSeparationOn() { return on(steer::behaviorType::separation); };
78  bool isAlignmentOn() { return on(steer::behaviorType::alignment); };
79  bool isSeekOn() { return on(steer::behaviorType::seek); };
80  bool isWanderOn() { return on(steer::behaviorType::wander); };
81  bool isWallAvoidanceOn() { return on(steer::behaviorType::wallAvoidance); };
82  bool isObstacleAvoidanceOn() { return on(steer::behaviorType::obstacleAvoidance); };
83  bool isFlockingOn() { return isCohesionOn() && isAlignmentOn() && isSeparationOn() && isSeekOn() && isWanderOn() && isWallAvoidanceOn() && isObstacleAvoidanceOn(); };
84  bool isPursuitOn(){return on(steer::behaviorType::pursuit);};
85  bool isOffsetPursuitOn(){return on(steer::behaviorType::offsetPursuit);};
86  bool isInterposeOn(){return on(steer::behaviorType::interpose);};
87  bool isHideOn(){return on(steer::behaviorType::hide);};
88  bool isPathFollowingOn(){return on(steer::behaviorType::followPath);};
89  bool isFleeOn(){return on(steer::behaviorType::flee);};
90  bool isEvadeOn(){return on(steer::behaviorType::evade);};
91  bool isArriveOn(){return on(steer::behaviorType::arrive);};
92 
93  void flockingOn()
94  {
95  cohesionOn();
96  alignmentOn();
97  separationOn();
98  seekOn();
99  wanderOn();
100  wallAvoidanceOn();
101  obstacleAvoidanceOn();
102  };
103 
104  void flockingOff()
105  {
106  cohesionOff();
107  alignmentOff();
108  separationOff();
109  seekOff();
110  wanderOff();
111  wallAvoidanceOff();
112  obstacleAvoidanceOff();
113  }
114 
115  bool targetAcquired();
116 
117  void setEvadeAgent(steer::Agent* a){m_evadeAgent = a;};
118  steer::Agent* getEvadeAgent() const {return m_evadeAgent;};
119 
120  void setPursuitAgent(steer::Agent* a){m_pursuitAgent = a;};
121  steer::Agent* getPursuitAgent() const {return m_pursuitAgent;};
122 
123  void setLeader(steer::Agent* l){m_leader = l;};
124  steer::Agent* getLeader() const {return m_leader;};
125 
126  void setInterposeAgents(steer::Agent* a, steer::Agent* b){m_interposeAgentA = a; m_interposeAgentB = b;};
127  void setInterposeAgentA(steer::Agent* a){m_interposeAgentA = a;};
128  void setInterposeAgentB(steer::Agent* b){m_interposeAgentB = b;};
129 
130  steer::Agent* getInterposeAgentA() const {return m_interposeAgentA;};
131  steer::Agent* getInterposeAgentB() const {return m_interposeAgentB;};
132 
133  void setHideAgent(steer::Agent* a){m_hideAgent = a;};
134  steer::Agent* getHideAgent() const {return m_hideAgent;};
135 
136  //pure virtual - must implement see Agent.hpp
137  virtual Vector2 Calculate() override;
138 
139  //optional virtual
140  virtual Vector2 calculateWeightedSum() override;
141 
142  public:
158  private:
159  Uint32 m_iFlags;
160  float m_rotation;
161  steer::Agent* m_evadeAgent;
162  steer::Agent* m_pursuitAgent;
163  steer::Agent* m_leader;
164  steer::Agent* m_interposeAgentA;
165  steer::Agent* m_interposeAgentB;
166  steer::Agent* m_hideAgent;
167  std::vector<SuperComponent*>* m_neighbors;
168  std::vector<SphereObstacle*>* m_obstacles;
169  std::vector<Wall*>* m_walls;
170  steer::Path* m_path;
171  steer::BehaviorParameters* m_params;
172  };
173 }
174 
175 #endif // SuperComponent_HPP