- Timestamp:
- Nov 23, 2015, 11:17:22 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10827 r10832 73 73 public: 74 74 static const float hardcoded_projectile_speed = 750; 75 76 75 static const float ACTION_INTERVAL = 1.0f; 77 78 76 79 77 CommonController(Context* context); 80 78 virtual ~CommonController(); 81 79 80 //----[XML data]---- 81 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 82 //----[Action data]---- 83 Action::Value getAction (); 84 void setAction (Action::Value action); 85 void setAction (Action::Value action, ControllableEntity* target); 86 void setAction (Action::Value action, const Vector3& target); 87 void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); 88 void setActionXML( std::string val); 89 std::string getActionXML(); 90 //----[/Action data]---- 91 //----[Formation data]---- 92 virtual void setFormationModeXML(std::string val); 93 virtual std::string getFormationModeXML(); 94 virtual void setFormationMode(FormationMode::Value val) 95 { this->formationMode_ = val; } 96 inline FormationMode::Value getFormationMode() const 97 { return this->formationMode_; } 98 //----[/Formation data]---- 99 //----[Rank data]---- 100 virtual void setRank(Rank::Value val) 101 { this->rank_ = val; } 102 inline Rank::Value getRank() const 103 { return this->rank_; } 104 //----[/Rank data]---- 105 //----[/XML data]---- 82 106 107 //----[Interaction with other Controllers]---- 108 virtual bool setWingman(CommonController* wingman); 109 virtual bool hasWingman(); 83 110 111 void setPositionOfTarget(const Vector3& target); 112 void setOrientationOfTarget(const Quaternion& orient); 84 113 114 void setTarget(ControllableEntity* target); 115 ControllableEntity* getTarget(); 116 bool hasTarget(); 85 117 86 virtual void setFormationMode(FormationMode::Value val) 87 { this->formationMode_ = val; } 88 inline FormationMode::Value getFormationMode() const 89 { return this->formationMode_; } 90 virtual void setFormationModeXML(std::string val); 91 virtual std::string getFormationModeXML(); 118 void setTargetPosition(const Vector3& target); 119 void setTargetOrientation(const Quaternion& orient); 120 void setTargetOrientation(ControllableEntity* target); 121 //----[/Interaction with other Controllers]---- 92 122 93 virtual void setRank(Rank::Value val) 94 { this->rank_ = val; } 95 inline Rank::Value getRank() const 96 { return this->rank_; } 123 //----[Helper functions]---- 124 float randomInRange(float a, float b); 125 static float distance(ControllableEntity* entity1, ControllableEntity* entity2); 126 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2); 127 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; 97 128 98 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 99 100 101 102 virtual bool setWingman(CommonController* wingman); 103 virtual bool hasWingman(); 104 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2); 105 void setTarget(ControllableEntity* target); 106 bool hasTarget(); 107 ControllableEntity* getTarget(); 108 void setTargetOrientation(const Quaternion& orient); 109 void setTargetOrientation(ControllableEntity* target); 110 void setTargetPosition(const Vector3& target); 111 112 /*void spin(); 113 void turn180();*/ 114 Action::Value getAction (); 115 void setAction (Action::Value action, ControllableEntity* target); 116 void setAction (Action::Value action, const Vector3& target); 117 void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); 129 float squaredDistanceToTarget() const; 130 bool isLookingAtTarget(float angle) const; 131 //----[/Helper functions]---- 118 132 119 133 protected: 120 void dodge(Vector3& thisPosition, Vector3& diffUnit); 121 int counter; 122 void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); 123 bool moveAndRoll(float dt); 134 //----[Flying functionality]---- 135 void stopMoving(); 124 136 125 void moveToPosition(const Vector3& target, float dt); 126 void moveToTargetPosition(float dt); 127 //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes 137 void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); 138 bool moveAndRoll(float dt); 128 139 129 //Mode mode_; 130 void copyOrientation(const Quaternion& orient, float dt); 131 void copyTargetOrientation(float dt); 140 void moveToPosition(const Vector3& target, float dt); 141 void moveToTargetPosition(float dt); 132 142 133 static float distance(ControllableEntity* entity1, ControllableEntity* entity2); 134 float squaredDistanceToTarget() const; 135 void doFire(); 136 void aimAtTarget(); 137 bool isLookingAtTarget(float angle) const; 138 bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const; 143 void copyOrientation(const Quaternion& orient, float dt); 144 void copyTargetOrientation(float dt); 139 145 140 //checks if spaceship points at enemy and if there are allies inbetween 141 bool canFire(); 142 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() 143 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 144 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) 145 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 146 bool bSetupWorked; //<! If false, setupWeapons() is called. 147 int getFiremode(std::string name); 146 void lookAtTarget(float dt); 147 void stopLookingAtTarget(); 148 void startLookingAtTarget(); 148 149 149 float randomInRange(float a, float b); 150 bool bHasTargetPosition_; 151 Vector3 targetPosition_; 152 bool bHasTargetOrientation_; 153 Quaternion targetOrientation_; 150 bool bLookAtTarget_; 151 //----[/Flying functionality]---- 152 153 //----[Fighting functionality]---- 154 void maneuver(); 155 void dodge(Vector3& thisPosition, Vector3& diffUnit); 156 void aimAtTarget(); 157 bool canFire(); 158 void doFire(); 159 void setClosestTarget(); 154 160 155 Vector3 destination_; 156 bool bHasDestination; 161 bool bShooting_; 162 int maneuverCounter_; 163 //----[/Fighting functionality]---- 164 165 //----[where-to-fly information]---- 166 bool bHasTargetPosition_; 167 Vector3 targetPosition_; 168 bool bHasTargetOrientation_; 169 Quaternion targetOrientation_; 170 // Vector3 destination_; 171 // bool bHasDestination; 172 //----[/where-to-fly information]---- 173 174 //----[who-to-kill information]---- 175 WeakPtr<ControllableEntity> target_; 176 //WeakPtr<ControllableEntity> objectiveTarget_; 157 177 178 bool bHasPositionOfTarget_; 179 Vector3 positionOfTarget_; 180 bool bHasOrientationOfTarget_; 181 Quaternion orientationOfTarget_; 182 //----[/who-to-kill information]---- 158 183 159 void stopMoving(); 160 void setPositionOfTarget(const Vector3& target); 161 void setOrientationOfTarget(const Quaternion& orient); 162 bool bHasPositionOfTarget_; 163 Vector3 positionOfTarget_; 164 bool bHasOrientationOfTarget_; 165 Quaternion orientationOfTarget_; 166 167 168 WeakPtr<ControllableEntity> target_; 169 //WeakPtr<ControllableEntity> thisEntity_; 170 171 172 173 Action::Value action_; 174 bool bEngaging_; 175 bool bShooting_; 176 WeakPtr<ControllableEntity> objectiveTarget_; 177 178 void lookAtTarget(float dt); 179 void stopLookingAtTarget(); 180 void startLookingAtTarget(); 181 bool bLookAtTarget_; 182 void maneuver(); 183 void chooseManeuverType(); 184 void gunsD(); 185 void attack(); 186 void scissors(); 187 FormationMode::Value formationMode_; 188 Rank::Value rank_; 189 190 bool executingMoveToPoint_; 191 192 private: 193 194 184 //----["Private" variables]---- 185 FormationMode::Value formationMode_; 186 Rank::Value rank_; 187 Action::Value action_; 188 //----[/"Private" variables]---- 195 189 }; 196 190 }
Note: See TracChangeset
for help on using the changeset viewer.