Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI_HS15/src/orxonox/controllers/FormationController.h @ 10673

Last change on this file since 10673 was 10673, checked in by gania, 9 years ago

added setDesiredPositionOfSlaves() to FormationController, Vector3* desiredRelativePosition_ as a member var to FormationController, added a "stay in formation" functionality to tick of AIController. TODO change from moveToPosition to a Waypoint. Remark: create a WorldEntity object at certain position

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      ...
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _FormationController_h__
30#define _FormationController_h__
31
32#include "OrxonoxPrereqs.h"
33
34#include <vector>
35#include "core/class/Super.h"
36
37#include "util/Math.h"
38#include "controllers/Controller.h"
39#include "worldentities/ControllableEntity.h"
40
41
42namespace orxonox {
43
44  class _OrxonoxExport FormationController : public Controller
45  {
46
47      public:
48      FormationController(Context* context);
49
50      virtual ~FormationController();
51
52      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
53
54
55      static void formationflight(const bool form);
56      static void masteraction(const int action);
57      static void followme();
58      static void passivebehaviour(const bool passive);
59      static void formationsize(const int size);
60      void setNewMasterWithinFormation(FormationController* newMaster);
61
62      inline void setFormationFlight(bool formation)
63           { this->formationFlight_ = formation; }
64      inline bool getFormationFlight() const
65           { return this->formationFlight_; }
66
67      inline void setFormationSize(int size)
68           { this->maxFormationSize_ = size; }
69      inline int getFormationSize() const
70           { return this->maxFormationSize_; }
71
72      /**
73      @brief If master, set the desired position of slaves (Vector2) for all the slaves.
74      */
75      void setDesiredPositionOfSlaves();
76
77      inline void setPassive(bool passive)
78           { this->passive_ = passive; }
79      inline bool getPassive() const
80           { return this->passive_; }
81
82
83
84      /**
85        @brief Mode of the formation, behaviour of slaves
86               Normal-normal behaviour
87               Defend-just defend the master
88               Attack-leave formation, attack every target
89      */
90      enum FormationMode {NORMAL,DEFEND,ATTACK};
91
92      /**
93        @brief Sets the new mode. If master, set it for all slaves.
94      */
95      void setFormationMode(FormationMode val);
96      inline FormationMode getFormationMode() const
97           { return this->formationMode_; }
98     
99      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
100
101      FormationController* getMaster( void ) { return myMaster_; }
102      FormationController* getController( void ) { return this; }
103      FormationController* getSlave( void ) { return this->slaves_.back(); }
104
105      virtual void changedControllableEntity();
106
107  protected:
108      Vector3* desiredRelativePosition_;
109      bool formationFlight_;
110      bool passive_;
111      unsigned int maxFormationSize_;
112      int freedomCount_;
113      enum State {SLAVE, MASTER, FREE};
114
115      State state_;
116      std::vector<FormationController*> slaves_;
117      FormationController* myMaster_;
118
119      FormationMode formationMode_;
120
121      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
122      SpecificMasterAction specificMasterAction_;
123      int specificMasterActionHoldCount_;
124      float speedCounter_; //for speed adjustment when following
125
126      void moveToPosition(const Vector3& target);
127      void moveToTargetPosition();
128      void absoluteMoveToPosition(const Vector3& target);
129      void copyOrientation(const Quaternion& orient);
130      void copyTargetOrientation();
131
132      void removeFromFormation();
133      void unregisterSlave();
134      void searchNewMaster();
135      void commandSlaves();
136      void takeLeadOfFormation();
137      void loseMasterState();
138      void setNewMasterWithinFormation();
139
140      void freeSlaves();
141      void forceFreeSlaves();
142      void forceFreedom();
143      bool forcedFree();
144
145      void masterAttacked(Pawn* originator);
146
147      void specificMasterActionHold();
148      void turn180Init();
149      void spinInit();
150      void spin();
151      void turn180();
152      void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
153      void followRandomHumanInit();
154      void follow();
155
156      void setTargetPosition(const Vector3& target);
157      void searchRandomTargetPosition();
158
159      void setTargetOrientation(const Quaternion& orient);
160      void setTargetOrientation(Pawn* target);
161
162      virtual void positionReached() {}
163
164      static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
165
166
167      void setTarget(Pawn* target);
168
169      void searchNewTarget();
170      void forgetTarget();
171
172      void targetDied();
173
174      bool bHasTargetPosition_;
175      Vector3 targetPosition_;
176      bool bHasTargetOrientation_;
177      Quaternion targetOrientation_;
178
179      WeakPtr<Pawn> target_;
180      bool bShooting_;
181  };
182
183
184}
185#endif /* _FormationController_h__ */
186
187
Note: See TracBrowser for help on using the repository browser.