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
missionscript.cpp
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 /*
23  * AI for mission scripting written by Alexander Rawass <alexannika@users.sourceforge.net>
24  */
25 
26 #include "script.h"
27 #include "navigation.h"
28 #include "xml_support.h"
29 #include "flybywire.h"
30 #include <stdio.h>
31 #include <vector>
32 #include <stack>
33 #include "vsfilesystem.h"
34 #include "tactics.h"
35 #include "cmd/unit_generic.h"
36 
37 #include "missionscript.h"
38 #include "cmd/script/mission.h"
39 
41 {
42  actionstring = "";
43 
45 
47 
48  first_run = true;
49 }
50 
52 {
53  printf( "destructor\n%s", parent->getFullAIDescription().c_str() );
54 
55  mission->runScript( modulename, "quitai", classid );
56 
58 #ifdef ORDERDEBUG
59  VSFileSystem::vs_fprintf( stderr, "aims%x", this );
60  fflush( stderr );
61 #endif
62 }
63 
65 {
66  desired_ang_velocity = Vector( 0, 0, 0 );
67  desired_velocity = Vector( 0, 0, 0 );
68 
70  mission->setCurrentAIOrder( this );
71  if (first_run) {
72  for (unsigned int i = 0;
73  ( i < active_missions.size() )
74  && ( !( mission->runScript( modulename, "initai", classid ) ) );
75  i++) {}
76  first_run = false;
77  }
78  mission->runScript( modulename, "executeai", classid );
79 
81  if (vi == NULL || vi->type != VAR_INT) {
83  } else {
84  if (vi->int_val == 0)
86  else if (vi->int_val == 1)
88  }
89  mission->deleteVarInst( vi );
90  done = false;
91 
92  varInst *done_vi = mission->lookupClassVariable( modulename, "_done", classid );
93  if (done_vi != NULL && done_vi->type == VAR_BOOL && done_vi->bool_val == true)
94  done = true;
95  mission->deleteVarInst( done_vi );
96 }
97 
98 AIFlyToWaypoint::AIFlyToWaypoint( const QVector &wp, float velo, bool afburn,
99  float rng ) : AImissionScript( "ai_flyto_waypoint" )
100 {
101  waypoint = wp;
102  vel = velo;
103  range = rng;
104  aburn = afburn;
105 
106  varInst *vi_wp = mission->lookupClassVariable( modulename, "waypoint", classid );
108 
109  varInst *vi_range = mission->lookupClassVariable( modulename, "abort_range", classid );
110  vi_range->float_val = range;
111 
112  varInst *vi_vel = mission->lookupClassVariable( modulename, "vel", classid );
113  vi_vel->float_val = vel;
114 
115  varInst *vi_aburn = mission->lookupClassVariable( modulename, "afterburner", classid );
116  vi_aburn->bool_val = aburn;
117 }
118 
119 AIFlyToWaypointDefend::AIFlyToWaypointDefend( const QVector &wp, float velo, bool afburn, float rng,
120  float defend_range ) : AImissionScript( "ai_flyto_waypoint_defend" )
121 {
122  waypoint = wp;
123  vel = velo;
124  range = rng;
125  aburn = afburn;
126 
127  varInst *vi_wp = mission->lookupClassVariable( modulename, "waypoint", classid );
129 
130  varInst *vi_range = mission->lookupClassVariable( modulename, "abort_range", classid );
131  vi_range->float_val = range;
132 
133  varInst *vi_defrange = mission->lookupClassVariable( modulename, "defend_range", classid );
134  vi_defrange->float_val = defend_range;
135 
136  varInst *vi_vel = mission->lookupClassVariable( modulename, "vel", classid );
137  vi_vel->float_val = vel;
138 
139  varInst *vi_aburn = mission->lookupClassVariable( modulename, "afterburner", classid );
140  vi_aburn->bool_val = aburn;
141 }
142 
144 AIFlyToJumppoint::AIFlyToJumppoint( Unit *jumppoint_unit, float fly_speed, bool aft ) : AImissionScript( "ai_flyto_jumppoint" )
145 {
146  varInst *vi_speed = mission->lookupClassVariable( modulename, "fly_speed", classid );
147  vi_speed->float_val = fly_speed;
148 
149  varInst *vi_aft = mission->lookupClassVariable( modulename, "afterburner", classid );
150  vi_aft->bool_val = aft;
151 
152  varInst *vi_unit = mission->lookupClassVariable( modulename, "jumppoint_unit", classid );
153  vi_unit->objectname = "unit";
154  vi_unit->object = jumppoint_unit;
155 }
156 
157 AIPatrol::AIPatrol( int mode, const QVector &area, float range, Unit *around_unit,
158  float patrol_speed ) : AImissionScript( "ai_patrol" )
159 {
160  varInst *vi_wp = mission->lookupClassVariable( modulename, "area", classid );
161  mission->call_vector_into_olist( vi_wp, area );
162 
163  varInst *vi_range = mission->lookupClassVariable( modulename, "range", classid );
164  vi_range->float_val = range;
165 
166  varInst *vi_speed = mission->lookupClassVariable( modulename, "patrol_speed", classid );
167  vi_speed->float_val = patrol_speed;
168 
169  varInst *vi_mode = mission->lookupClassVariable( modulename, "patrol_mode", classid );
170  vi_mode->int_val = mode;
171 
172  varInst *vi_unit = mission->lookupClassVariable( modulename, "around_unit", classid );
173  vi_unit->objectname = "unit";
174  vi_unit->object = around_unit;
175 }
176 AIPatrolDefend::AIPatrolDefend( int mode, const QVector &area, float range, Unit *around_unit,
177  float patrol_speed ) : AImissionScript( "ai_patrol_defend" )
178 {
179  varInst *vi_wp = mission->lookupClassVariable( modulename, "area", classid );
180  mission->call_vector_into_olist( vi_wp, area );
181 
182  varInst *vi_range = mission->lookupClassVariable( modulename, "range", classid );
183  vi_range->float_val = range;
184 
185  varInst *vi_speed = mission->lookupClassVariable( modulename, "patrol_speed", classid );
186  vi_speed->float_val = patrol_speed;
187 
188  varInst *vi_mode = mission->lookupClassVariable( modulename, "patrol_mode", classid );
189  vi_mode->int_val = mode;
190 
191  varInst *vi_unit = mission->lookupClassVariable( modulename, "around_unit", classid );
192  vi_unit->objectname = "unit";
193  vi_unit->object = around_unit;
194 }
195 
196 AIOrderList::AIOrderList( olist_t *orderlist ) : AImissionScript( "ai_orderlist" )
197 {
198  varInst *vi_unit = mission->lookupClassVariable( modulename, "my_order_list", classid );
199  vi_unit->objectname = "olist";
200  vi_unit->object = orderlist;
201 
202  my_orderlist = orderlist;
203 }
204