1 struct rpgent : dynent 2 { 3 rpgobj *ro; 4 5 int lastaction, lastpain; 6 bool attacking; 7 8 bool magicprojectile; 9 vec mppos, mpdir; 10 rpgobj *mpweapon; 11 float mpdist; 12 13 rpgent *enemy; 14 float targetyaw, rotspeed; 15 16 enum { R_STARE, R_ROAM, R_SEEK, R_ATTACK, R_BLOCKED, R_BACKHOME }; 17 int npcstate; 18 19 int trigger; 20 21 float sink; 22 23 vec home; 24 25 enum { ROTSPEED = 200 }; 26 rorpgent27 rpgent(rpgobj *_ro, const vec &_pos, float _yaw, int _maxspeed = 40, int _type = ENT_AI) : ro(_ro), lastaction(0), lastpain(0), attacking(false), magicprojectile(false), enemy(NULL), rotspeed(0), npcstate(R_STARE), trigger(0), sink(0) 28 { 29 o = _pos; 30 home = _pos; 31 targetyaw = yaw = _yaw; 32 maxspeed = _maxspeed; 33 type = _type; 34 enemy = player1; 35 } 36 relyawrpgent37 float relyaw(vec &t) { return -(float)atan2(t.x-o.x, t.y-o.y)/RAD; }; 38 normalize_yawrpgent39 void normalize_yaw(float angle) 40 { 41 while(yaw<angle-180.0f) yaw += 360.0f; 42 while(yaw>angle+180.0f) yaw -= 360.0f; 43 } 44 45 void tryattackobj(rpgobj &eo, rpgobj &weapon); 46 void tryattack(vec &lookatpos, rpgobj &weapon); 47 void updateprojectile(); 48 bool allowmove(); 49 50 void transition(int _state, int _moving, int n); 51 void gotoyaw(float yaw, int s, int m, int t); 52 void gotopos(vec &pos, int s, int m, int t); 53 void goroam(); 54 void stareorroam(); 55 56 void update(float playerdist); 57 void updateplayer(); 58 }; 59