Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
order.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef _CMD_ORDER_H
23 
24 #define _CMD_ORDER_H
25 
26 #include "gfx/vec.h"
27 #include "cmd/container.h"
28 #include <list>
29 #include <vector>
30 #include <string>
31 
42 class Animation;
43 typedef std::vector< class varInst* >olist_t;
44 class Order
45 {
46 private:
47 
48 protected:
49  virtual ~Order();
53  unsigned int type;
54 
55  unsigned int subtype;
57  bool done;
63  std::vector< Order* >suborders;
65  std::list< class CommunicationMessage* >messagequeue;
67  virtual void Destructor();
68 protected:
70 
71 public:
72 
73  virtual void ChooseTarget()
74  {
75  /*not implemented see fire.cpp*/
76  }
77  virtual bool PursueTarget( Unit*, bool isleader )
78  {
79  return false;
80  }
82  void ClearMessages();
84  enum ORDERTYPES {MOVEMENT=1, FACING=2, WEAPON=4, CLOAKING=8, ALLTYPES=(1|2|4|8)};
88  : parent(NULL),
89  type(0),
90  subtype(0),
91  done(false),
92  targetlocation( 0, 0, 0 )
93  {
94  VSCONSTRUCT1( 'O' )
95  }
97  Order( int type, int subtype )
98  : parent(NULL),
99  type(type),
100  subtype(subtype),
101  done(false),
102  targetlocation( 0, 0, 0 )
103  {
104  VSCONSTRUCT1( 'O' )
105  }
107  virtual void Destroy();
108 
110  virtual void Execute();
112  Order * queryType( unsigned int type );
114  Order * queryAny( unsigned int type );
116  void eraseType( unsigned int type );
118  bool AttachOrder( Unit *targets );
120  bool AttachOrder( QVector target );
122  bool AttachSelfOrder( Unit *targets );
124  Order * EnqueueOrder( Order *ord );
126  Order * ReplaceOrder( Order *ord );
127  bool Done()
128  {
129  return done;
130  }
131  int getType()
132  {
133  return type;
134  }
136  {
137  return subtype;
138  }
140  virtual void SetParent( Unit *parent1 )
141  {
142  parent = parent1;
143  }
144  Unit * GetParent() const
145  {
146  return parent;
147  }
149  virtual void Communicate( const class CommunicationMessage &c );
151  virtual void ProcessCommMessage( class CommunicationMessage&c );
153  virtual void ProcessCommunicationMessages( float CommRepsonseTime, bool RemoveMessageProcessed );
155  Order * findOrder( Order *ord );
157  void eraseOrder( Order *ord );
159  Order * EnqueueOrderFirst( Order *ord );
161  virtual olist_t * getOrderList()
162  {
163  return NULL;
164  }
165  virtual void AdjustRelationTo( Unit *un, float factor );
166 
167  virtual std::string getOrderDescription()
168  {
169  return "empty";
170  }
171 
173  Order * findOrderList();
174  std::string createFullOrderDescription( int level = 0 );
175  void setActionString( std::string astring )
176  {
177  actionstring = astring;
178  }
179  std::string getActionString()
180  {
181  return actionstring;
182  }
183  virtual float getMood()
184  {
185  return 0;
186  }
187 protected:
188  std::string actionstring;
189 };
192 {
193 public:
194  virtual int type()
195  {
196  return 0;
197  }
199  virtual Order * newOrder()
200  {
201  return new Order;
202  }
203 };
204 
205 namespace Orders
206 {
207 
209 class ExecuteFor : public Order
210 {
211 private:
212 
214  Order *child;
216  float time;
218  float maxtime;
219 protected:
220  virtual ~ExecuteFor() {}
221 public: ExecuteFor( Order *chld, float seconds ) : Order( chld->getType(), chld->getSubType() )
222  , child( chld )
223  , time( 0 )
224  , maxtime( seconds ) {}
226  void Execute();
228  virtual void Destroy()
229  {
230  child->Destroy();
231  Order::Destroy();
232  }
233 };
234 
235 // Execute two orders simultaneously and wait until both has finished.
236 class Join : public Order
237 {
238 public:
239  Join(Unit *parent,
240  Order *firstOrder,
241  Order *secondOrder);
242  void Execute();
243 
244 private:
245  Order *first;
246  Order *second;
247 };
248 
249 // Execute one order and prevent other orders with excludeTypes from executing at the same time.
250 class Sequence : public Order
251 {
252 public:
254  Order *order,
255  unsigned int excludeTypes);
256  void Execute();
257 
258 private:
259  Order *order;
260 };
261 
262 } // namespace Orders
263 
264 #endif
265