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