Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/controllers/FormationController.h @ 9811

Last change on this file since 9811 was 9797, checked in by jo, 11 years ago

Added Team functionality down to the controller class.

  • Property svn:eol-style set to native
File size: 5.1 KB
RevLine 
[8978]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:
[9255]23 *      ...
[8978]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _FormationController_h__
30#define _FormationController_h__
31
32#include "OrxonoxPrereqs.h"
33
34#include <vector>
[9667]35#include "core/class/Super.h"
[8978]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:
[9667]48      FormationController(Context* context);
[8978]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);
[9625]60      void setNewMasterWithinFormation(FormationController* newMaster);
[8978]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      inline void setPassive(bool passive)
74           { this->passive_ = passive; }
75      inline bool getPassive() const
76           { return this->passive_; }
77
78
[9797]79
[8978]80      /**
81        @brief Mode of the formation, behaviour of slaves
82               Normal-normal behaviour
83               Defend-just defend the master
84               Attack-leave formation, attack every target
[8999]85      */
[8991]86      enum FormationMode {NORMAL,DEFEND,ATTACK};
[8999]87
[8978]88      /**
89        @brief Sets the new mode. If master, set it for all slaves.
90      */
[8991]91      void setFormationMode(FormationMode val);
92      inline FormationMode getFormationMode() const
93           { return this->formationMode_; }
[8978]94
[9348]95      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
[9256]96
[9625]97      FormationController* getMaster( void ) { return myMaster_; }
98      FormationController* getController( void ) { return this; }
99      FormationController* getSlave( void ) { return this->slaves_.back(); }
100
[9256]101  protected:
[8978]102      bool formationFlight_;
103      bool passive_;
104      unsigned int maxFormationSize_;
105      int freedomCount_;
106      enum State {SLAVE, MASTER, FREE};
[8999]107
[8978]108      State state_;
109      std::vector<FormationController*> slaves_;
110      FormationController* myMaster_;
111
[8991]112      FormationMode formationMode_;
[8978]113
114      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
115      SpecificMasterAction specificMasterAction_;
116      int specificMasterActionHoldCount_;
117      float speedCounter_; //for speed adjustment when following
118
119      void moveToPosition(const Vector3& target);
120      void moveToTargetPosition();
[8992]121      void absoluteMoveToPosition(const Vector3& target);
[8978]122      void copyOrientation(const Quaternion& orient);
123      void copyTargetOrientation();
124
125      void removeFromFormation();
126      void unregisterSlave();
127      void searchNewMaster();
128      void commandSlaves();
[9625]129      void takeLeadOfFormation();
130      void loseMasterState();
[8978]131      void setNewMasterWithinFormation();
132
133      void freeSlaves();
134      void forceFreeSlaves();
135      void forceFreedom();
136      bool forcedFree();
137
[8999]138      void masterAttacked(Pawn* originator);
[8978]139
140      void specificMasterActionHold();
141      void turn180Init();
142      void spinInit();
143      void spin();
144      void turn180();
145      void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
146      void followRandomHumanInit();
147      void follow();
148
149      void setTargetPosition(const Vector3& target);
150      void searchRandomTargetPosition();
151
152      void setTargetOrientation(const Quaternion& orient);
153      void setTargetOrientation(Pawn* target);
154
155      virtual void positionReached() {}
156
157      static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
158
[8999]159
[8978]160      void setTarget(Pawn* target);
[9625]161
[8978]162      void searchNewTarget();
163      void forgetTarget();
164
165      void targetDied();
[8999]166
[8978]167      bool bHasTargetPosition_;
168      Vector3 targetPosition_;
169      bool bHasTargetOrientation_;
170      Quaternion targetOrientation_;
171
172      WeakPtr<Pawn> target_;
173      bool bShooting_;
174  };
175
176
177}
178#endif /* _FormationController_h__ */
179
180
Note: See TracBrowser for help on using the repository browser.