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
navparse.h
Go to the documentation of this file.
1 #include "vsfilesystem.h"
2 
3 //using namespace VSFileSystem;
6 bool NavigationSystem::ParseFile( string filename )
7 {
8  string expression = "";
9  string tag = "";
10  string data = "";
11  char next = ' ';
12  int totalitems = 0;
13 
14  //ifstream dataset_file;
15  //dataset_file.open("navdata.xml");
16  VSFile f;
17  VSError err = f.OpenReadOnly( "nav/navdata.xml", CockpitFile );
18  //if (dataset_file.fail())
19  if (err > Ok)
20  return 0;
21  while ( !f.Eof() ) {
22  if (next == '<') {
23  //trap <*>
24  //- know what type it is
25  f.Read( &next, 1 ); //
26  while (next != '>') {
27  //
28  //
29  expression = expression+next; //
30  f.Read( &next, 1 ); //
31  } //
32  if (expression[0] == '!') {
33  //doesnt catch comment in comment
34  while ( (expression[expression.size()-1] != '>') || (expression[expression.size()-2] != '-') ) {
35  expression = expression+next;
36  f.Read( &next, 1 );
37  }
38  expression = "";
39  continue;
40  }
41  if ( (expression[0] != '/') && (expression[expression.size()-1] != '/') ) {
42  //starter
43  tag = expression;
44  expression = "";
45  } else if (expression[0] == '/') {
46  //terminator = no more to be done
47  data = "";
48  tag = "";
49  expression = "";
50  } else if (expression[expression.size()-1] == '/') {
51  //data
52  data = expression;
53  if (tag == "console") {
54  string mesh_ = retrievedata( data, "file" );
55  float x_small = atof( ( retrievedata( data, "x_small" ) ).c_str() );
56  float x_large = atof( ( retrievedata( data, "x_large" ) ).c_str() );
57  float y_small = atof( ( retrievedata( data, "y_small" ) ).c_str() );
58  float y_large = atof( ( retrievedata( data, "y_large" ) ).c_str() );
59  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
60  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
61  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
62  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
63  meshcoordinate_x[0] = x_mesh_coord;
64  meshcoordinate_y[0] = y_mesh_coord;
65  meshcoordinate_z[0] = z_mesh_coord;
66  screenskipby4[0] = x_small;
67  screenskipby4[1] = x_large;
68  screenskipby4[2] = y_small;
69  screenskipby4[3] = y_large;
70  mesh[0] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
71  } else if (tag == "button1") {
72  string mesh_ = retrievedata( data, "file" );
73  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
74  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
75  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
76  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
77  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
78  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
79  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
80  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
81  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
82 
83  meshcoordinate_x[1] = x_mesh_coord;
84  meshcoordinate_y[1] = y_mesh_coord;
85  meshcoordinate_z[1] = z_mesh_coord;
86  meshcoordinate_z_delta[1] = z_mesh_coord_delta;
87  buttonskipby4_1[0] = x_;
88  buttonskipby4_1[1] = x_+dx_;
89  buttonskipby4_1[2] = y_;
90  buttonskipby4_1[3] = y_+dy_;
91 
92  mesh[1] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
93  } else if (tag == "button2") {
94  string mesh_ = retrievedata( data, "file" );
95  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
96  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
97  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
98  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
99  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
100 
101  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
102  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
103  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
104  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
105 
106  meshcoordinate_x[2] = x_mesh_coord;
107  meshcoordinate_y[2] = y_mesh_coord;
108  meshcoordinate_z[2] = z_mesh_coord;
109  meshcoordinate_z_delta[2] = z_mesh_coord_delta;
110 
111  buttonskipby4_2[0] = x_;
112  buttonskipby4_2[1] = x_+dx_;
113  buttonskipby4_2[2] = y_;
114  buttonskipby4_2[3] = y_+dy_;
115 
116  mesh[2] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
117  } else if (tag == "button3") {
118  string mesh_ = retrievedata( data, "file" );
119  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
120  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
121  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
122  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
123  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
124 
125  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
126  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
127  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
128  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
129 
130  meshcoordinate_x[3] = x_mesh_coord;
131  meshcoordinate_y[3] = y_mesh_coord;
132  meshcoordinate_z[3] = z_mesh_coord;
133  meshcoordinate_z_delta[3] = z_mesh_coord_delta;
134 
135  buttonskipby4_3[0] = x_;
136  buttonskipby4_3[1] = x_+dx_;
137  buttonskipby4_3[2] = y_;
138  buttonskipby4_3[3] = y_+dy_;
139 
140  mesh[3] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
141  } else if (tag == "button4") {
142  string mesh_ = retrievedata( data, "file" );
143  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
144  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
145  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
146  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
147  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
148 
149  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
150  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
151  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
152  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
153 
154  meshcoordinate_x[4] = x_mesh_coord;
155  meshcoordinate_y[4] = y_mesh_coord;
156  meshcoordinate_z[4] = z_mesh_coord;
157  meshcoordinate_z_delta[4] = z_mesh_coord_delta;
158 
159  buttonskipby4_4[0] = x_;
160  buttonskipby4_4[1] = x_+dx_;
161  buttonskipby4_4[2] = y_;
162  buttonskipby4_4[3] = y_+dy_;
163 
164  mesh[4] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
165  } else if (tag == "button5") {
166  string mesh_ = retrievedata( data, "file" );
167  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
168  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
169  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
170  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
171  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
172 
173  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
174  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
175  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
176  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
177 
178  meshcoordinate_x[5] = x_mesh_coord;
179  meshcoordinate_y[5] = y_mesh_coord;
180  meshcoordinate_z[5] = z_mesh_coord;
181  meshcoordinate_z_delta[5] = z_mesh_coord_delta;
182 
183  buttonskipby4_5[0] = x_;
184  buttonskipby4_5[1] = x_+dx_;
185  buttonskipby4_5[2] = y_;
186  buttonskipby4_5[3] = y_+dy_;
187 
188  mesh[5] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
189  } else if (tag == "button6") {
190  string mesh_ = retrievedata( data, "file" );
191  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
192  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
193  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
194  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
195  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
196 
197  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
198  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
199  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
200  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
201 
202  meshcoordinate_x[6] = x_mesh_coord;
203  meshcoordinate_y[6] = y_mesh_coord;
204  meshcoordinate_z[6] = z_mesh_coord;
205  meshcoordinate_z_delta[6] = z_mesh_coord_delta;
206 
207  buttonskipby4_6[0] = x_;
208  buttonskipby4_6[1] = x_+dx_;
209  buttonskipby4_6[2] = y_;
210  buttonskipby4_6[3] = y_+dy_;
211 
212  mesh[6] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
213  } else if (tag == "button7") {
214  string mesh_ = retrievedata( data, "file" );
215  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
216  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
217  float dx_ = atof( ( retrievedata( data, "dx" ) ).c_str() );
218  float dy_ = atof( ( retrievedata( data, "dy" ) ).c_str() );
219  float scale_ = atof( ( retrievedata( data, "scale" ) ).c_str() );
220 
221  float x_mesh_coord = atof( ( retrievedata( data, "x_mesh_coord" ) ).c_str() );
222  float y_mesh_coord = atof( ( retrievedata( data, "y_mesh_coord" ) ).c_str() );
223  float z_mesh_coord = atof( ( retrievedata( data, "z_mesh_coord" ) ).c_str() );
224  float z_mesh_coord_delta = atof( ( retrievedata( data, "z_mesh_coord_delta" ) ).c_str() );
225 
226  meshcoordinate_x[7] = x_mesh_coord;
227  meshcoordinate_y[7] = y_mesh_coord;
228  meshcoordinate_z[7] = z_mesh_coord;
229  meshcoordinate_z_delta[7] = z_mesh_coord_delta;
230 
231  buttonskipby4_7[0] = x_;
232  buttonskipby4_7[1] = x_+dx_;
233  buttonskipby4_7[2] = y_;
234  buttonskipby4_7[3] = y_+dy_;
235 
236  mesh[7] = Mesh::LoadMesh( mesh_.c_str(), Vector( scale_, scale_, scale_ ), 0, NULL );
237  } else if (tag == "objectives") {
238  float x_ = atof( ( retrievedata( data, "x" ) ).c_str() );
239  float y_ = atof( ( retrievedata( data, "y" ) ).c_str() );
240  float dx_ = x_+atof( ( retrievedata( data, "dx" ) ).c_str() );
241  float dy_ = y_+atof( ( retrievedata( data, "dy" ) ).c_str() );
242  ScreenToCoord( x_ );
243  ScreenToCoord( y_ );
244  ScreenToCoord( dx_ );
245  ScreenToCoord( dy_ );
246 
247  screen_objectives.SetPos( x_, dy_ );
248  screen_objectives.SetSize( dx_-x_, y_-dy_ );
249  dosetbit( whattodraw, 4 );
250  } else if (tag == "systemiteminfo") {
251  float scale_ = atof( ( retrievedata( data, "itemscale" ) ).c_str() );
252  float zmult_ = atof( ( retrievedata( data, "zshiftmultiplier" ) ).c_str() );
253  float zfactor_ = atof( ( retrievedata( data, "itemzscalefactor" ) ).c_str() );
254  float _unselectedalpha = atof( ( retrievedata( data, "unselectedalpha" ) ).c_str() );
255  float _minimumitemscaledown = atof( ( retrievedata( data, "minimumitemscaledown" ) ).c_str() );
256  float _maximumitemscaleup = atof( ( retrievedata( data, "maximumitemscaleup" ) ).c_str() );
257 
258  unselectedalpha = _unselectedalpha;
259  minimumitemscaledown = _minimumitemscaledown;
260  maximumitemscaleup = _maximumitemscaleup;
261  if (scale_ < 0.5)
262  system_item_scale = 0.5;
263  else if (scale_ > 4)
264  system_item_scale = 4;
265  else
266  system_item_scale = scale_;
267  if (zmult_ < 0.5)
268  zshiftmultiplier = 0.5;
269  else if (zmult_ > 6)
270  zshiftmultiplier = 6;
271  else
272  zshiftmultiplier = zmult_;
273  if (zfactor_ < 1.0)
274  item_zscalefactor = 1.0;
275  else if (zfactor_ > 8)
276  item_zscalefactor = 8;
277  else
278  item_zscalefactor = zfactor_;
279  } else if (tag == "dimensions") {
280  int how_many_sys = atoi( ( retrievedata( data, "system" ) ).c_str() );
281  int how_many_gal = atoi( ( retrievedata( data, "galaxy" ) ).c_str() );
282  string multi_sys = retrievedata( data, "systemmultidimensional" );
283  string multi_gal = retrievedata( data, "galaxymultidimensional" );
284  if (how_many_sys == 3)
285  system_view = VIEW_3D;
286  else
287  system_view = VIEW_2D;
288  if (how_many_gal == 3)
289  galaxy_view = VIEW_3D;
290  else
291  galaxy_view = VIEW_2D;
292  if (multi_sys == "yes")
293  system_multi_dimensional = 1;
294  else
295  system_multi_dimensional = 0;
296  if (multi_gal == "yes")
297  galaxy_multi_dimensional = 1;
298  else
299  galaxy_multi_dimensional = 0;
300  } else if (tag == "factioncolours") {
301  string factionname = retrievedata( data, "faction" );
302  float r_ = atof( ( retrievedata( data, "r" ) ).c_str() );
303  float g_ = atof( ( retrievedata( data, "g" ) ).c_str() );
304  float b_ = atof( ( retrievedata( data, "b" ) ).c_str() );
305  float a_ = atof( ( retrievedata( data, "a" ) ).c_str() );
306  for (unsigned int k = 0; k < FactionUtil::GetNumFactions(); k++)
307  if ( ( FactionUtil::GetFactionName( k ) ) == factionname ) {
308  factioncolours[k].r = r_;
309  factioncolours[k].g = g_;
310  factioncolours[k].b = b_;
311  factioncolours[k].a = a_;
312  }
313  } else if (tag == "configmode") {
314  int configmode_ = atoi( ( retrievedata( data, "configmode" ) ).c_str() );
315  configmode = configmode_;
316  }
317  data = "";
318  //tag = "";
319  expression = "";
320  continue;
321  } else {
322  continue;
323  }
324  }
325  f.Read( &next, 1 );
326  //do something
327  }
328  f.Close();
329  if (totalitems == 0)
330  return 1;
331  else
332  return 0;
333 }
334