Changeset 10709 for code/branches/AI_HS15/src/orxonox/controllers
- Timestamp:
- Oct 26, 2015, 5:44:31 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
r10678 r10709 13 13 FleetController.cc 14 14 DivisionController.cc 15 SectionController.cc16 15 LeaderController.cc 17 16 WingmanController.cc -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10678 r10709 35 35 RegisterClass(DivisionController); 36 36 37 DivisionController::DivisionController(Context* context) : FleetController(context)37 DivisionController::DivisionController(Context* context) : LeaderController(context) 38 38 { 39 39 RegisterObject(DivisionController); … … 47 47 } 48 48 } 49 49 void DivisionController::setLeader(LeaderController* leader) 50 { 51 this->leader_ = leader; 52 } 50 53 /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 51 54 { -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10681 r10709 30 30 #define _DivisionController_H__ 31 31 32 #include "controllers/FleetController.h" 32 #include "controllers/LeaderController.h" 33 33 34 34 35 35 36 namespace orxonox 36 37 { 37 class _OrxonoxExport DivisionController : public FleetController38 class _OrxonoxExport DivisionController : public LeaderController 38 39 { 39 40 public: … … 48 49 inline FormationMode getFormationMode() const 49 50 { return this->formationMode_; } 51 virtual void setLeader(LeaderController* leader); 52 50 53 51 virtual void doFire();52 53 //WAYPOINT FUNCTIONS`54 void addWaypoint(WorldEntity* waypoint);55 WorldEntity* getWaypoint(unsigned int index) const;56 57 inline void setAccuracy(float accuracy)58 { this->squaredaccuracy_ = accuracy*accuracy; }59 inline float getAccuracy() const60 { return sqrt(this->squaredaccuracy_); }61 void updatePointsOfInterest(std::string name, float distance);62 void manageWaypoints();63 54 64 55 protected: … … 70 61 bool bHasTargetOrientation_; 71 62 Quaternion targetOrientation_; 72 void setTargetPosition(const Vector3& target); 63 FormationMode formationMode_; 64 65 /*void setTargetPosition(const Vector3& target); 73 66 void searchRandomTargetPosition(); 74 67 … … 78 71 virtual void positionReached() {} 79 72 80 static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack81 73 82 74 … … 109 101 void spinInit(); 110 102 void spin(); 111 void turn180(); 103 void turn180();*/ 112 104 113 //WAYPOINT DATA 114 std::vector<WeakPtr<WorldEntity> > waypoints_; 115 size_t currentWaypoint_; 116 float squaredaccuracy_; 117 WorldEntity* defaultWaypoint_; 105 LeaderController* leader_; 106 107 118 108 119 109 private: -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10678 r10709 35 35 RegisterClass(FleetController); 36 36 37 FleetController::FleetController(Context* context) : Controller(context)37 FleetController::FleetController(Context* context) : FormationController(context) 38 38 { 39 39 RegisterObject(FleetController); … … 43 43 this->goalTarget_ = NULL; 44 44 this->goalProtect_ = NULL; 45 this->nTicks_ = 0; 46 this->bTicked_ = false; 47 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this))); 45 48 } 46 49 … … 52 55 } 53 56 } 54 57 void FleetController::action() 58 { 59 60 61 } 62 void FleetController::tick(float dt) 63 { 64 65 if (nTicks_ == 30) 66 { 67 std::vector<WeakPtr<WingmanController> > wingmen; 68 std::vector<WeakPtr<LeaderController> > leaders; 69 70 //--------------------------Put all WingmanController's in a vector-------------------------- 71 for (ObjectList<WingmanController>::iterator it = ObjectList<WingmanController>::begin(); it; ++it) 72 { 73 74 75 if ((*it)->getTeam() == this->getTeam()) 76 { 77 orxout(internal_error) << "ANOTHER SUCKER" << endl; 78 wingmen.push_back(*it); 79 } 80 81 } 82 //--------------------------Substitute half of WingmanController's with LeaderController-------------------------- 83 84 bool nowLeader = true; 85 LeaderController* leader; 86 87 for (std::vector<WeakPtr<WingmanController> >::iterator it = wingmen.begin() ; it != wingmen.end(); ++it) 88 { 89 if (nowLeader) 90 { 91 leader = new LeaderController(this->getContext()); 92 leader->setTeam(this->team_); 93 94 (*it)->getControllableEntity()->setController(leader); 95 leaders.push_back(leader); 96 nowLeader = !nowLeader; 97 orxout(internal_error) << "NEW SUCKER" << endl; 98 99 } 100 else 101 { 102 if (leader) 103 { 104 leader->setWingman(*it); 105 nowLeader = !nowLeader; 106 orxout(internal_error) << "I OWN THE SUCKER" << endl; 107 108 } 109 } 110 } 111 112 //--------------------------Substitute half of LeaderController's with DivisionController-------------------------- 113 bool nowDivision = true; 114 DivisionController* division; 115 116 for (std::vector<WeakPtr<LeaderController> >::iterator it = leaders.begin() ; it != leaders.end(); ++it) 117 { 118 if (nowDivision) 119 { 120 division = new DivisionController(this->getContext()); 121 division->setTeam(this->team_); 122 123 (*it)->getControllableEntity()->setController(division); 124 125 divisions_.push_back(division); 126 127 nowDivision = !nowDivision; 128 } 129 else 130 { 131 if (division) 132 { 133 division->setLeader(*it); 134 nowDivision = !nowDivision; 135 } 136 } 137 } 138 bTicked_ = true; 139 nTicks_ += 1; 140 } 141 else if (!bTicked_) 142 { 143 nTicks_ += 1; 144 145 } 146 SUPER(FleetController, tick, dt); 147 148 } 55 149 void FleetController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 56 150 { -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
r10681 r10709 29 29 #ifndef _FleetController_H__ 30 30 #define _FleetController_H__ 31 #include "controllers/FormationController.h" 31 32 32 33 #include "controllers/Controller.h" 34 #include "controllers/DivisionController.h" 35 #include "controllers/LeaderController.h" 36 #include "controllers/WingmanController.h" 33 37 34 38 #include "OrxonoxPrereqs.h" 35 39 #include "core/class/Super.h" 36 40 #include "core/CoreIncludes.h" 37 #include "core/XMLPort.h" 38 #include "core/command/ConsoleCommandIncludes.h" 39 #include "core/command/Executor.h" 41 40 42 41 43 #include <vector> … … 51 53 #include "worldentities/pawns/TeamBaseMatchBase.h" 52 54 53 #include "gametypes/TeamDeathmatch.h"54 #include "gametypes/Dynamicmatch.h"55 #include "gametypes/Mission.h"56 #include "gametypes/Gametype.h"57 58 #include "controllers/WaypointPatrolController.h"59 #include "controllers/NewHumanController.h"60 #include "controllers/DroneController.h"61 55 62 56 … … 64 58 { 65 59 66 class _OrxonoxExport FleetController : public Controller60 class _OrxonoxExport FleetController : public FormationController, public Tickable 67 61 { 68 62 public: … … 70 64 virtual ~FleetController(); 71 65 66 virtual void tick(float dt); //<! Carrying out the targets set in action(). 72 67 73 68 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); … … 80 75 enum GameGoal {DOMINATE, MOVE, DESTROY, PROTECT}; 81 76 82 /*void setGameGoal(GameGoal gameGoal)83 { this->gameGoal_ = gameGoal; }84 GameGoal getGameGoal() const85 { return this->gameGoal_; }86 77 87 void setGoalPosition(Vector3* goalPosition)88 { this->goalPosition_ = goalPosition; }89 Vector3* getGoalPosition() const90 { return this->goalPosition_; }91 92 void setGoalTarget(Pawn* goalTarget)93 { this->goalTarget_ = goalTarget; }94 Pawn* getGoalTarget() const95 { return this->goalTarget_; }96 97 void setGoalProtect(Pawn* goalProtect)98 { this->goalProtect_ = goalProtect; }99 Pawn* getGoalProtect() const100 { return this->goalProtect_; }*/101 102 78 103 79 … … 110 86 WeakPtr<Pawn> goalProtect_; 111 87 88 virtual void action(); 89 private: 90 int nTicks_; 91 bool bTicked_; 92 93 std::vector<WeakPtr<DivisionController> > divisions_; 94 //Timer actionTimer_; //<! Regularly calls action(). 112 95 113 96 }; -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10682 r10709 33 33 namespace orxonox 34 34 { 35 const float LeaderController::ACTION_INTERVAL = 1.0f;36 35 37 36 RegisterClass(LeaderController); 38 37 39 LeaderController::LeaderController(Context* context) : SectionController(context)38 LeaderController::LeaderController(Context* context) : WingmanController(context) 40 39 { 40 41 41 RegisterObject(LeaderController); 42 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));42 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); 43 43 } 44 44 45 45 46 LeaderController::~LeaderController() … … 49 50 void LeaderController::action() 50 51 { 51 52 //this->target_ = this->sectionTarget_; 52 53 } 53 54 /* … … 66 67 */ 67 68 void LeaderController::tick(float dt) 68 { 69 {/* 69 70 if (!this->isActive()) 70 71 return; 71 72 72 73 //--------------------------Stay in division-------------------------- 73 this->keepDivisionTick(); 74 this->keepDivisionTick();*/ 74 75 /*keepDivisionTick(){ 75 76 if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){ … … 80 81 } 81 82 */ 82 / /If ordered to attack -> follow target and shoot83 /*//If ordered to attack -> follow target and shoot 83 84 if (this->bAttackOrder_) 84 85 { 85 86 86 87 } 87 88 //If ordered to move -> move to a target Point 88 else if (this->bMoveOrder_) 89 { 90 91 } 92 else 89 93 90 //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 94 91 //(Section shoots same target, Boss's section shoots another target) 95 92 { 96 93 97 } 94 }*/ 98 95 99 96 orxout(internal_error) << "my Wingman is " << this->wingman_ << endl; 97 100 98 SUPER(LeaderController, tick, dt); 99 } 100 void LeaderController::setWingman(WingmanController* wingman) 101 { 102 this->wingman_ = wingman; 101 103 } 102 104 //**********************************************NEW -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10682 r10709 30 30 #define _LeaderController_H__ 31 31 32 #include "SectionController.h" 32 #include "controllers/WingmanController.h" 33 34 33 35 34 36 35 37 namespace orxonox 36 38 { 37 class _OrxonoxExport LeaderController : public SectionController, public Tickable39 class _OrxonoxExport LeaderController : public WingmanController 38 40 { 39 41 public: … … 41 43 LeaderController(Context* context); 42 44 virtual ~LeaderController(); 43 45 virtual void setWingman(WingmanController* wingman); 44 46 virtual void tick(float dt); //<! Carrying out the targets set in action(). 45 47 46 48 protected: 47 49 48 enum Mode {KEEPFORMATION, ROCKET, KILLENEMY}; 49 Mode mode_; 50 50 51 51 52 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 52 53 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot. 54 55 private: 53 56 57 WeakPtr<Pawn> target_; 58 59 WingmanController* wingman_; 54 60 55 //WEAPONSYSTEM DATA 56 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() 57 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 58 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) 59 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 60 bool bSetupWorked; //<! If false, setupWeapons() is called. 61 int getFiremode(std::string name); 62 63 void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost. 64 65 private: 66 static const float ACTION_INTERVAL; 67 68 Timer actionTimer_; //<! Regularly calls action(). 61 //Timer actionTimer_; //<! Regularly calls action(). 69 62 70 63 }; -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10682 r10709 32 32 namespace orxonox 33 33 { 34 const float WingmanController::ACTION_INTERVAL = 1.0f;35 34 36 35 RegisterClass(WingmanController); 37 36 38 WingmanController::WingmanController(Context* context) : SectionController(context)37 WingmanController::WingmanController(Context* context) : Controller(context) 39 38 { 40 39 RegisterObject(WingmanController); 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));40 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this))); 42 41 } 43 42 … … 55 54 void WingmanController::action() 56 55 { 57 //--------------------------Cover Leader's rear-------------------------- 58 //check for enemies in Leader's rear that can attack him and if they are visible, meaning there are no other Leader's between Leader and enemies. 59 //if there are enemies, set target_ to the nearest one and set bFollowLeader_ to false, 60 //otherwise set bFollowLeader_ to true and target_ to sectionTarget_ 61 this->coverAllyRear(this->sectionLeader_); 56 //this->target_ = this->sectionTarget_; 62 57 } 63 58 64 59 void WingmanController::tick(float dt) 65 { 60 {/* 66 61 if (!this->isActive()) 67 62 return; … … 69 64 if (bFollowLeader_) 70 65 { 71 this->keepSectionTick(); 66 this->keepSectionTick();*/ 72 67 /*keepSectionTick(){ 73 68 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){ … … 78 73 } 79 74 */ 80 75 /* 81 76 //--------------------------Attack same target as the Leader-------------------------- 82 77 83 78 if (this->target_) 84 79 { … … 86 81 this->doFire(); 87 82 } 88 } 89 //--------------------------Protect Leader by killing target_-------------------------- 90 91 else 92 { 93 if (this->target_) 94 { 95 //--------------------------Don't attack if not visible-------------------------- 96 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 97 { 98 this->forgetTarget(); 99 //this->bFollowLeader_ = true; 100 } 101 //--------------------------Otherwise destroy it-------------------------- 102 else 103 { 104 this->aimAtTarget(); 105 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 106 } 107 if (this->bHasTargetPosition_) 108 { 109 this->moveToTargetPosition(); 110 } 111 this->doFire(); 112 } 113 //--------------------------no target? do nothing until next action() -> either new target appears or bFollowLeader_ set to true-------------------------- 114 else 115 { 116 117 } 118 119 } 83 }*/ 84 //orxout(internal_error) << "I am " << this << endl; 85 120 86 SUPER(WingmanController, tick, dt); 121 87 } -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10681 r10709 31 31 32 32 33 #include "LeaderController.h" 33 #include "controllers/Controller.h" 34 35 36 #include "OrxonoxPrereqs.h" 37 #include "core/class/Super.h" 38 #include "core/CoreIncludes.h" 39 #include "core/XMLPort.h" 40 #include "core/command/ConsoleCommandIncludes.h" 41 #include "core/command/Executor.h" 42 43 #include <vector> 44 #include "util/Math.h" 45 #include <climits> 46 47 #include "tools/Timer.h" 48 #include "tools/interfaces/Tickable.h" 49 50 #include "worldentities/ControllableEntity.h" 51 #include "worldentities/pawns/SpaceShip.h" 52 #include "worldentities/pawns/Pawn.h" 53 #include "worldentities/pawns/TeamBaseMatchBase.h" 54 55 #include "gametypes/TeamDeathmatch.h" 56 #include "gametypes/Dynamicmatch.h" 57 #include "gametypes/Mission.h" 58 #include "gametypes/Gametype.h" 59 34 60 35 61 36 62 namespace orxonox 37 63 { 38 class _OrxonoxExport WingmanController : public LeaderController64 class _OrxonoxExport WingmanController : public Controller, public Tickable 39 65 { 40 66 public: … … 51 77 52 78 private: 53 static const float ACTION_INTERVAL; 79 //const float ACTION_INTERVAL; 80 81 WeakPtr<Pawn> target_; 82 83 //LeaderController* leader_; 54 84 55 Timer actionTimer_; //<! Regularly calls action().85 //Timer actionTimer_; //<! Regularly calls action(). 56 86 57 87 };
Note: See TracChangeset
for help on using the changeset viewer.