00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00015 #pragma warning (disable:4996)
00016 #pragma warning (disable:4005)
00017 #pragma warning(disable:4275)
00018
00019 #ifndef _AIBEHAVIORS_H
00020 #define _AIBEHAVIORS_H
00021
00022 #include "globals.h"
00023 #include "aiCharacter.h"
00024
00025 #include "seek.h"
00026 #include "flee.h"
00027 #include "pursue.h"
00028 #include "evade.h"
00029 #include "arrival.h"
00030 #include "flock.h"
00031 #include "wander.h"
00032
00033
00043
00045
00046 class AICharacter;
00047 class Seek;
00048 class Flee;
00049 class Pursue;
00050 class Evade;
00051 class Arrival;
00052 class Flock;
00053 class Wander;
00054
00055 typedef list<Flee, allocator<Flee> > ListFlee;
00056 typedef list<Evade, allocator<Evade> > ListEvade;
00057
00058 class AIBehaviors {
00059
00060 public:
00061 enum _behavior_type {
00062 _none = 0x00000,
00063 _seek = 0x00002,
00064 _flee = 0x00004,
00065 _flee_activate = 0x00100,
00066 _arrival = 0x00008,
00067 _arrival_activate = 0x01000,
00068 _wander = 0x00010,
00069 _pursue = 0x00040,
00070 _evade = 0x00080,
00071 _evade_activate = 0x00800,
00072 _flock = 0x00200,
00073 _flock_activate = 0x00400
00074 };
00075
00076 AICharacter *_ai_char;
00077 Flock *_flock_group;
00078
00079 int _behaviors_flags;
00080 LVecBase3f _steering_force;
00081
00082 Seek *_seek_obj;
00083 LVecBase3f _seek_force;
00084
00085 Flee *_flee_obj;
00086 LVecBase3f _flee_force;
00087
00089 ListFlee _flee_list;
00090 ListFlee::iterator _flee_itr;
00091
00092 Pursue *_pursue_obj;
00093 LVecBase3f _pursue_force;
00094
00095 Evade *_evade_obj;
00096 LVecBase3f _evade_force;
00097
00099 ListEvade _evade_list;
00100 ListEvade::iterator _evade_itr;
00101
00102 Arrival *_arrival_obj;
00103 LVecBase3f _arrival_force;
00104
00106 float _flock_weight;
00107 LVecBase3f _flock_force;
00108 bool _flock_done;
00109
00110 Wander * _wander_obj;
00111 LVecBase3f _wander_force;
00112
00113 bool _conflict, _previous_conflict;
00114
00115 AIBehaviors();
00116 ~AIBehaviors() {
00117 }
00118
00119 bool On(_behavior_type bt) {
00120 return (_behaviors_flags & bt) == bt;
00121 }
00122 bool Off(_behavior_type bt) {
00123 return (_behaviors_flags | bt) == bt;
00124 }
00125
00126 void seek_on() {
00127 _behaviors_flags |= _seek;
00128 }
00129 void flee_on() {
00130 _behaviors_flags |= _flee;
00131 }
00132 void flee_activate_on() {
00133 _behaviors_flags |= _flee_activate;
00134 }
00135 void arrival_on() {
00136 _behaviors_flags |= _arrival;
00137 }
00138 void arrival_activate_on() {
00139 _behaviors_flags |= _arrival_activate;
00140 }
00141 void pursue_on() {
00142 _behaviors_flags |= _pursue;
00143 }
00144 void evade_on() {
00145 _behaviors_flags |= _evade;
00146 }
00147 void evade_activate_on() {
00148 _behaviors_flags |= _evade_activate;
00149 }
00150 void flock_on() {
00151 _behaviors_flags |= _flock;
00152 }
00153 void flock_activate_on() {
00154 _behaviors_flags |= _flock_activate;
00155 }
00156 void wander_on() {
00157 _behaviors_flags |= _wander;
00158 }
00159
00160 void seek_off();
00161 void flee_off();
00162 void flee_activate_off() {
00163 if (On(_flee_activate)) _behaviors_flags ^= _flee_activate;
00164 }
00165 void arrival_off();
00166 void arrival_activate_off() {
00167 if (On(_arrival_activate)) _behaviors_flags ^= _arrival_activate;
00168 }
00169 void pursue_off();
00170 void evade_off();
00171 void evade_activate_off() {
00172 if (On(_evade_activate)) _behaviors_flags ^= _evade_activate;
00173 }
00174 void flock_off();
00175 void flock_activate_off() {
00176 if (On(_flock_activate)) _behaviors_flags ^= _flock_activate;
00177 }
00178 void wander_off();
00179
00180 bool is_off() {
00181 return Off(_none);
00182 }
00183 bool is_seek_on() {
00184 return On(_seek);
00185 }
00186 bool is_flee_on() {
00187 return On(_flee);
00188 }
00189 bool is_flee_activate_on() {
00190 return On(_flee_activate);
00191 }
00192 bool is_arrival_on(){
00193 return On(_arrival);
00194 }
00195 bool is_arrival_activate_on() {
00196 return On(_arrival_activate);
00197 }
00198 bool is_pursue_on() {
00199 return On(_pursue);
00200 }
00201 bool is_evade_on() {
00202 return On(_evade);
00203 }
00204 bool is_evade_activate_on() {
00205 return On(_evade_activate);
00206 }
00207 bool is_flock_on() {
00208 return On(_flock);
00209 }
00210 bool is_flock_activate_on() {
00211 return On(_flock_activate);
00212 }
00213 bool is_wander_on() {
00214 return On(_wander);
00215 }
00216
00217 bool is_conflict();
00218
00219 void accumulate_force(string force_type, LVecBase3f force);
00220 LVecBase3f calculate_prioritized();
00221
00222 void flock_activate();
00223 LVecBase3f do_flock();
00224
00225 int char_to_int(string ai_type);
00226
00227 PUBLISHED:
00228 void seek(NodePath target_object, float seek_wt = 1.0);
00229 void seek(LVecBase3f pos, float seek_wt = 1.0);
00230 bool seek_status();
00231
00232 void flee(NodePath target_object, double panic_distance = 10.0, double relax_distance = 10.0, float flee_wt = 1.0);
00233 void flee(LVecBase3f pos, double panic_distance = 10.0, double relax_distance = 10.0, float flee_wt = 1.0);
00234 bool flee_status();
00235
00236 void pursue(NodePath target_object, float pursue_wt = 1.0);
00237 bool pursue_status();
00238
00239 void evade(NodePath target_object, double panic_distance = 10.0, double relax_distance = 10.0, float evade_wt = 1.0);
00240 bool evade_status();
00241
00242 void arrival(NodePath target_object, double distance = 10.0);
00243 bool arrival_status();
00244
00245 void flock(float flock_wt);
00246 bool flock_status();
00247
00248 void wander(double wander_radius = 5.0, bool flag_3D = false, double aoe = 0.0, float wander_weight = 1.0);
00249 bool wander_status();
00250
00251 void remove_ai(string ai_type);
00252 void pause_ai(string ai_type);
00253 void resume_ai(string ai_type);
00254 };
00255
00256 #endif
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267