Panda3D
aiBehaviors.h
1 ////////////////////////////////////////////////////////////////////////
2 // Filename : aiBehaviors.cxx
3 // Created by : Deepak, John, Navin
4 // Date : 8 Sep 09
5 ////////////////////////////////////////////////////////////////////
6 //
7 // PANDA 3D SOFTWARE
8 // Copyright (c) Carnegie Mellon University. All rights reserved.
9 //
10 // All use of this software is subject to the terms of the revised BSD
11 // license. You should have received a copy of this license along
12 // with this source code in a file named "LICENSE."
13 //
14 ////////////////////////////////////////////////////////////////////
15 
16 #pragma warning (disable:4996)
17 #pragma warning (disable:4005)
18 #pragma warning(disable:4275)
19 
20 #ifndef _AIBEHAVIORS_H
21 #define _AIBEHAVIORS_H
22 
23 #include "aiGlobals.h"
24 
25 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26 //
27 // Class : AIBehaviors
28 // Description : This class implements all the steering behaviors of the AI framework, such as
29 // seek, flee, pursue, evade, wander and flock. Each steering behavior has a weight which is used when more than
30 // one type of steering behavior is acting on the same ai character. The weight decides the contribution of each
31 // type of steering behavior. The AICharacter class has a handle to an object of this class and this allows to
32 // invoke the steering behaviors via the AICharacter. This class also provides functionality such as pausing, resuming
33 // and removing the AI behaviors of an AI character at anytime.
34 
35 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36 
37 class AICharacter;
38 class Seek;
39 class Flee;
40 class Pursue;
41 class Evade;
42 class Arrival;
43 class Flock;
44 class Wander;
45 class PathFollow;
46 class PathFind;
47 class ObstacleAvoidance;
48 
49 typedef list<Flee, allocator<Flee> > ListFlee;
50 typedef list<Evade, allocator<Evade> > ListEvade;
51 
52 class EXPCL_PANDAAI AIBehaviors {
53 
54 public:
55  enum _behavior_type {
56  _none = 0x00000,
57  _seek = 0x00002,
58  _flee = 0x00004,
59  _flee_activate = 0x00100,
60  _arrival = 0x00008,
61  _arrival_activate = 0x01000,
62  _wander = 0x00010,
63  _pursue = 0x00040,
64  _evade = 0x00080,
65  _evade_activate = 0x00800,
66  _flock = 0x00200,
67  _flock_activate = 0x00400,
68  _obstacle_avoidance = 0x02000,
69  _obstacle_avoidance_activate = 0x04000
70  };
71 
72  AICharacter *_ai_char;
73  Flock *_flock_group;
74 
75  int _behaviors_flags;
76  LVecBase3 _steering_force;
77 
78  Seek *_seek_obj;
79  LVecBase3 _seek_force;
80 
81  Flee *_flee_obj;
82  LVecBase3 _flee_force;
83 
84  //! This list is used if the ai character needs to flee from multiple onjects.
85  ListFlee _flee_list;
86  ListFlee::iterator _flee_itr;
87 
88  Pursue *_pursue_obj;
89  LVecBase3 _pursue_force;
90 
91  Evade *_evade_obj;
92  LVecBase3 _evade_force;
93 
94  //! This list is used if the ai character needs to evade from multiple onjects.
95  ListEvade _evade_list;
96  ListEvade::iterator _evade_itr;
97 
98  Arrival *_arrival_obj;
99  LVecBase3 _arrival_force;
100 
101  //! Since Flock is a collective behavior the variables are declared within the AIBehaviors class.
103  LVecBase3 _flock_force;
104  bool _flock_done;
105 
106  Wander * _wander_obj;
107  LVecBase3 _wander_force;
108 
109  ObstacleAvoidance *_obstacle_avoidance_obj;
110  LVecBase3 _obstacle_avoidance_force;
111 
112  PathFollow *_path_follow_obj;
113 
114  PathFind *_path_find_obj;
115 
116  bool _conflict, _previous_conflict;
117 
118  AIBehaviors();
119  ~AIBehaviors();
120 
121  bool is_on(_behavior_type bt);
122  bool is_on(string ai_type); // special cases for pathfollow and pathfinding
123  bool is_off(_behavior_type bt);
124  bool is_off(string ai_type); // special cases for pathfollow and pathfinding
125  void turn_on(string ai_type);
126  void turn_off(string ai_type);
127 
128  bool is_conflict();
129 
130  void accumulate_force(string force_type, LVecBase3 force);
131  LVecBase3 calculate_prioritized();
132 
133  void flock_activate();
134  LVecBase3 do_flock();
135 
136  int char_to_int(string ai_type);
137 
138 PUBLISHED:
139  void seek(NodePath target_object, float seek_wt = 1.0);
140  void seek(LVecBase3 pos, float seek_wt = 1.0);
141 
142  void flee(NodePath target_object, double panic_distance = 10.0, double relax_distance = 10.0, float flee_wt = 1.0);
143  void flee(LVecBase3 pos, double panic_distance = 10.0, double relax_distance = 10.0, float flee_wt = 1.0);
144 
145  void pursue(NodePath target_object, float pursue_wt = 1.0);
146 
147  void evade(NodePath target_object, double panic_distance = 10.0, double relax_distance = 10.0, float evade_wt = 1.0);
148 
149  void arrival(double distance = 10.0);
150 
151  void flock(float flock_wt);
152 
153  void wander(double wander_radius = 5.0, int flag =0, double aoe = 0.0, float wander_weight = 1.0);
154 
155  void obstacle_avoidance(float feeler_length = 1.0);
156 
157  void path_follow(float follow_wt);
158  void add_to_path(LVecBase3 pos);
159  void start_follow(string type = "normal");
160 
161  // should have different function names.
162  void init_path_find(const char* navmesh_filename);
163  void path_find_to(LVecBase3 pos, string type = "normal");
164  void path_find_to(NodePath target, string type = "normal");
165  void add_static_obstacle(NodePath obstacle);
166  void add_dynamic_obstacle(NodePath obstacle);
167  //
168 
169  void remove_ai(string ai_type);
170  void pause_ai(string ai_type);
171  void resume_ai(string ai_type);
172 
173  string behavior_status(string ai_type);
174 };
175 
176 #endif
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
float _flock_weight
Since Flock is a collective behavior the variables are declared within the AIBehaviors class...
Definition: aiBehaviors.h:102
Definition: wander.h:23
Definition: evade.h:24
ListEvade _evade_list
This list is used if the ai character needs to evade from multiple onjects.
Definition: aiBehaviors.h:95
This class is used to define the flock attributes and the AI characters which are part of the flock...
Definition: flock.h:32
This class contains all the members and functions that are required to form an interface between the ...
Definition: pathFind.h:36
Definition: seek.h:24
Definition: pursue.h:24
Definition: flee.h:24
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
ListFlee _flee_list
This list is used if the ai character needs to flee from multiple onjects.
Definition: aiBehaviors.h:85