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
unit_wrapper_class.h
Go to the documentation of this file.
1 using std::string;
2 //WARNING: Macro City ahead. Please skip this section if you don't like macros.
3 static const char *error = "\nERROR: NULL Unit used in Python script; returning default value...";
4 #define CHECKME \
5  } \
6  Unit *me = GetUnit(); if (!me) {fprintf( stderr, "%s", error ); return
7 #define WRAPPED0( type, name, def ) \
8  type name() { \
9  {CHECKME def; } \
10  return me->name(); }
11 #define WRAPPED1( type, name, atype, a, def ) \
12  type name( atype a ) { \
13  {CHECKME def; } \
14  return me->name( a ); }
15 #define WRAPPED2( type, name, atype, a, btype, b, def ) \
16  type name( atype a, btype b ) { \
17  {CHECKME def; } \
18  return me->name( a, b ); }
19 #define WRAPPED3( type, name, atype, a, btype, b, ctype, c, def ) \
20  type name( atype a, btype b, ctype c ) { \
21  {CHECKME def; } \
22  return me->name( a, b, c ); }
23 #define WRAPPED4( type, name, atype, a, btype, b, ctype, c, dtype, d, def ) \
24  type name( atype a, btype b, ctype c, dtype d ) { \
25  {CHECKME def; } \
26  return me->name( a, b, c, d ); }
27 #define voidWRAPPED0( name ) \
28  void name() { \
29  {CHECKME; } \
30  me->name(); }
31 #define voidWRAPPED1( name, atype, a ) \
32  void name( atype a ) { \
33  {CHECKME; } \
34  me->name( a ); }
35 #define voidWRAPPED2( name, atype, a, btype, b ) \
36  void name( atype a, btype b ) { \
37  {CHECKME; } \
38  me->name( a, b ); }
39 #define voidWRAPPED3( name, atype, a, btype, b, ctype, c ) \
40  void name( atype a, btype b, ctype c ) { \
41  {CHECKME; } \
42  me->name( a, b, c ); }
43 #define voidWRAPPED5( name, atype, a, btype, b, ctype, c, dtype, d, etype, e ) \
44  void name( atype a, \
45  btype b, \
46  ctype c, \
47  dtype d, \
48  etype e ) { \
49  {CHECKME; } \
50  me->name( a, b, c, d, e ); }
51 
52 #define EXPORT_UTIL0( type, name ) type name() {return UnitUtil::name( GetUnit() ); }
53 #define EXPORT_UTIL1( type, name, atype, a ) type name( atype a ) {return UnitUtil::name( GetUnit(), a ); }
54 #define EXPORT_UTIL2( type, name, atype, a, btype, b ) type name( atype a, btype b ) {return UnitUtil::name( GetUnit(), a, b ); }
55 #define EXPORT_UTIL3( type, name, atype, a, btype, b, ctype, c ) \
56  type name( atype a, btype b, ctype c ) {return UnitUtil::name( \
57  GetUnit(), \
58  a, \
59  b, \
60  c ); }
61 #define EXPORT_UTIL5( type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e ) \
62  type name( atype a, \
63  btype b, \
64  ctype c, \
65  dtype d, \
66  etype e ) {return UnitUtil:: \
67  name( GetUnit( \
68  ), a, b, c, d, e ); }
69 #define voidEXPORT_UTIL0( name ) void name() {UnitUtil::name( GetUnit() ); }
70 #define voidEXPORT_UTIL1( name, atype, a ) void name( atype a ) {UnitUtil::name( GetUnit(), a ); }
71 #define voidEXPORT_UTIL2( name, atype, a, btype, b ) void name( atype a, btype b ) {UnitUtil::name( GetUnit(), a, b ); }
72 #define voidEXPORT_UTIL3( name, atype, a, btype, b, ctype, c ) \
73  void name( atype a, btype b, ctype c ) {UnitUtil::name( \
74  GetUnit(), a, b, c ); }
75 #define voidEXPORT_UTIL5( name, atype, a, btype, b, ctype, c, dtype, d, etype, e ) \
76  void name( atype a, \
77  btype b, \
78  ctype c, \
79  dtype d, \
80  etype e ) {UnitUtil::name( \
81  GetUnit(), \
82  a, \
83  b, \
84  c, \
85  d, \
86  e ); }
87 //#define EXPORT_UTIL(name,aff)
88 //#define voidEXPORT_UTIL(name) EXPORT_UTIL(name,0)
89 //End of Macro City
90 class UnitWrapper : public UnitContainer
91 {
92 public:
93 #include "python_unit_wrap.h"
95 //WRAPPED0(UnitCollection::UnitIterator, getSubUnits,0)
97  {
98  {
100  }
101  return unit->getSubUnits();
102  }
103  void Kill()
104  {
105  {
106  CHECKME;
107  }
108  unit->Kill( true );
109  }
111  {
112  {
113  CHECKME 0;
114  }
115  return unit->Target();
116  }
118  {
119  {
120  CHECKME 0;
121  }
122  return unit->VelocityReference();
123  }
125  {
126  {
128  }
129  unit->VelocityReference( targ );
130  }
131  void SetTarget( UnitWrapper targ )
132  {
133  {
134  CHECKME;
135  }
136  unit->Target( targ );
137  }
138  boost::python::tuple GetOrientation()
139  {
140  {
142  0,
143  0 ) );
144  }
145  Vector p, q, r;
146  unit->GetOrientation( p, q, r );
147  return VS_BOOST_MAKE_TUPLE( VS_BOOST_MAKE_TUPLE( p.i, p.j, p.k ), VS_BOOST_MAKE_TUPLE( q.i,
148  q.j,
149  q.k ),
150  VS_BOOST_MAKE_TUPLE( r.i, r.j, r.k ) );
151  }
152  boost::python::tuple rayCollide( QVector st, QVector en)
153  {
154  {
155  CHECKME VS_BOOST_MAKE_TUPLE( 0, VS_BOOST_MAKE_TUPLE( 0, 0, 1 ), 0 );
156  }
157  float dist;
158  UnitWrapper un;
159  Vector nml;
160  un = unit->rayCollide( st, en, nml, dist);
161  boost::python::tuple ret = VS_BOOST_MAKE_TUPLE( un, nml, dist );
162  return ret;
163  }
164  boost::python::tuple cosAngleToITTS( UnitWrapper target, float speed, float range )
165  {
166  {
168  }
169  float dist;
170  float ret = unit->cosAngleTo( target, dist, speed, range );
171  return VS_BOOST_MAKE_TUPLE_2( ret, dist );
172  }
173  boost::python::tuple cosAngleTo( UnitWrapper target )
174  {
175  {
177  }
178  float dist;
179  float ret = unit->cosAngleTo( target, dist );
180  return VS_BOOST_MAKE_TUPLE_2( ret, dist );
181  }
182  boost::python::tuple cosAngleFromMountTo( UnitWrapper target )
183  {
184  {
186  }
187  float dist;
188  float ret = unit->cosAngleFromMountTo( target, dist );
189  return VS_BOOST_MAKE_TUPLE_2( ret, dist );
190  }
191  boost::python::tuple getAverageGunSpeed()
192  {
193  {
194  CHECKME VS_BOOST_MAKE_TUPLE( 1, 0, 0 );
195  }
196  float speed, range, missilespeed;
197  unit->getAverageGunSpeed( speed, range, missilespeed );
198  return VS_BOOST_MAKE_TUPLE( speed, range, missilespeed );
199  }
200  boost::python::tuple InsideCollideTree( UnitWrapper smaller )
201  {
202  {
204  0,
205  0,
206  0 ), VS_BOOST_MAKE_TUPLE( 0, 0, 0 ) );
207  }
208  QVector bigpos, smallpos;
209  Vector bigNormal, smallNormal;
210  if ( !unit->InsideCollideTree( smaller, bigpos, bigNormal, smallpos, smallNormal ) ) {
211  bigpos = smallpos = QVector( 0,
212  0,
213  0 );
214  }
215  boost::python::tuple tup = VS_BOOST_MAKE_TUPLE_4( VS_BOOST_MAKE_TUPLE( bigpos.i,
216  bigpos.j,
217  bigpos.k ),
218  VS_BOOST_MAKE_TUPLE( bigNormal.i,
219  bigNormal.j,
220  bigNormal.k ), VS_BOOST_MAKE_TUPLE( smallpos.i,
221  smallpos
222  .j,
223  smallpos
224  .k ),
225  VS_BOOST_MAKE_TUPLE( smallNormal.i, smallNormal.j, smallNormal.k ) );
226  return tup;
227  }
229 //UnitWrapper getSubUnit(int which) {{CHECKME 0;}un_iter it=unit->getSubUnits(); for (int i=0;i<which;i++) {it.advance();}return it.current();}
230 //UnitWrapper getFlightgroupLeader () {{CHECKME 0;}Flightgroup *group=unit->getFlightgroup();if (group) return group->leader; else return 0;}
231 //void setFlightgroupLeader (Unit * un) {{CHECKME;}Flightgroup *group=unit->getFlightgroup();if (group) group->leader.SetUnit(un);}
233  {
234  {
235  CHECKME 0;
236  }
237  float diff = 1;
239  return diff;
240  }
242  {
243  {
244  CHECKME-1;
245  }
246  return unit->GetJumpStatus().drive;
247  }
248  void ApplyDamage( Vector pnt,
249  Vector normal,
250  float amt,
251  UnitWrapper dealer,
252  float phasedamage,
253  float r,
254  float g,
255  float b,
256  float a )
257  {
258  {
259  CHECKME;
260  }
261  unit->ApplyDamage( pnt, normal, amt, unit, GFXColor( r, g, b, a ), dealer.GetUnit(), phasedamage );
262  }
264 /*
265  * WRAPPED1(bool,TransferUnitToSystem,class StarSystem *,NewSystem,false)
266  * bool InCorrectStarSystem (StarSystem *active)
267  * // PYTHON_DEFINE_METHOD(Class,&TransferUnitToSystem(unsigned int whichJumpQueue, class StarSystem * previouslyActiveStarSystem, bool DoSightAndSound) {{CHECKME 0;}class StarSystem * othActiveStarSystem=previouslyActiveStarSystem; unit->TransferUnitToSystem(whichJumpQueue,othActiveStarSystem,DoSightAndSound); return othActiveStarSystem;}
268  * // class StarSystem * TransferUnitToSystem(unsigned int whichJumpQueue, class StarSystem * previouslyActiveStarSystem, bool DoSightAndSound) {{CHECKME 0;}class StarSystem * othActiveStarSystem=previouslyActiveStarSystem; unit->TransferUnitToSystem(whichJumpQueue,othActiveStarSystem,DoSightAndSound); return othActiveStarSystem;}
269  */
272  UnitWrapper( Unit *un = 0 ) : UnitContainer( un ) {}
273  operator Unit *()
274  {
275  return GetUnit();
276  }
277  bool isNull()
278  {
279  Unit *un = GetUnit();
280  if (un) if (un->GetHull() <= 0) return true;
281  return un == 0;
282  }
283  bool notNull()
284  {
285  return !isNull();
286  }
287  void setNull()
288  {
289  SetUnit( 0 );
290  }
291  bool equal( UnitWrapper oth )
292  {
293  return this->operator==( oth );
294  }
295  bool notequal( UnitWrapper oth )
296  {
297  return this->operator!=( oth );
298  }
299 };
300 #undef CHECKME
301 #undef WRAPPED0
302 #undef WRAPPED1
303 #undef WRAPPED2
304 #undef WRAPPED3
305 #undef WRAPPED4
306 #undef voidWRAPPED0
307 #undef voidWRAPPED1
308 #undef voidWRAPPED2
309 #undef voidWRAPPED3
310 #undef voidWRAPPED5
311 #undef EXPORT_UTIL0
312 #undef EXPORT_UTIL1
313 #undef EXPORT_UTIL2
314 #undef EXPORT_UTIL3
315 #undef EXPORT_UTIL5
316 #undef voidEXPORT_UTIL0
317 #undef voidEXPORT_UTIL1
318 #undef voidEXPORT_UTIL2
319 #undef voidEXPORT_UTIL3
320 #undef voidEXPORT_UTIL5
321