1 #ifndef E323_ATASK_H 2 #define E323_ATASK_H 3 4 #include <list> 5 #include <iostream> 6 7 #include "CAI.h" 8 #include "ARegistrar.h" 9 10 enum TaskType { 11 TASK_UNDEFINED, 12 TASK_BUILD, 13 TASK_ASSIST, 14 TASK_ATTACK, 15 TASK_MERGE, 16 TASK_FACTORY, 17 TASK_REPAIR, 18 TASK_GUARD 19 }; 20 21 class CGroup; 22 23 class ATask: public ARegistrar { 24 25 public: 26 enum NPriority { LOW = 0, NORMAL, HIGH }; 27 28 ATask(AIClasses *_ai); ~ATask()29 ~ATask() {} 30 31 bool active; 32 // task is active 33 bool suspended; 34 // task is suspended 35 NPriority priority; 36 // task priority 37 int queueID; 38 // queue ID this task belongs to 39 int initFrame; 40 // frame when task was initialized 41 int validateInterval; 42 // validate interval in frames; 0 means validation is OFF 43 int nextValidateFrame; 44 // next frame to execute task validation 45 TaskType t; 46 // type of the task: BUILD, ASSIST, ATTACK, etc. 47 std::list<ATask*> assisters; 48 // the assisters assisting this task 49 std::list<CGroup*> groups; 50 // groups involved 51 //CGroup *group; 52 // the group involved; for Merge task it is master-group 53 bool isMoving; 54 // determine if all groups in this task are moving or not 55 float3 pos; 56 // the position to navigate too 57 // TODO: make it as method because for assisting task this position 58 // may vary depending on master task 59 60 CGroup* firstGroup() const; 61 /* Remove this task, unreg groups involved, and make them available again */ 62 virtual void remove(); 63 /* Overload */ 64 void remove(ARegistrar &group); 65 /* Add a group to this task */ 66 void addGroup(CGroup &group); 67 68 void removeGroup(CGroup &group); 69 /* Scan and micro for resources */ 70 bool resourceScan(); 71 /* Scan and micro for damaged units */ 72 bool repairScan(); 73 /* Scan and micro for enemy targets */ 74 bool enemyScan(int& target); 75 /* Task lifetime in frames */ 76 int lifeFrames() const; 77 /* Task lifetime in sec */ 78 float lifeTime() const; 79 /* Update this task */ 80 void update(); 81 urgent()82 bool urgent() { return priority == HIGH; } 83 84 virtual void onUpdate() = 0; 85 onValidate()86 virtual bool onValidate() { return true; } 87 88 virtual void toStream(std::ostream& out) const = 0; 89 onEnemyDestroyed(int enemy,int attacker)90 virtual void onEnemyDestroyed(int enemy, int attacker) {}; 91 onUnitDestroyed(int uid,int attacker)92 virtual void onUnitDestroyed(int uid, int attacker) {}; 93 regtype()94 ARegistrar::NType regtype() const { return ARegistrar::TASK; } 95 96 friend std::ostream& operator<<(std::ostream& out, const ATask& task); 97 98 protected: 99 AIClasses *ai; 100 101 private: 102 static int counter; 103 // task counter, used as task key; shared among all AI instances 104 }; 105 106 #endif 107