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
base_write_xml.cpp
Go to the documentation of this file.
1 #include "base.h"
2 #ifdef BASE_MAKER
3 #ifdef BASE_XML
4 #include <stdio.h>
5 
6 void begintag( FILE *Fp, const char *tag, int indent )
7 {
8  int i;
9  for (i = 0; i < indent; i++)
10  VSFileSystem::Write( "\t", sizeof (char), 1, Fp );
11  VSFileSystem::Write( "<", sizeof (char), 1, Fp );
12  VSFileSystem::Write( tag, sizeof (char)*strlen( tag ), 1, Fp );
13 }
14 void midxmltag( FILE *Fp, const char *tag, const float value )
15 {
16  char value2[100] = {0}; //new char [100];
17  sprintf( value2, "%g", value );
18  VSFileSystem::Write( " ", sizeof (char), 1, Fp );
19  VSFileSystem::Write( tag, sizeof (char)*strlen( tag ), 1, Fp );
20  VSFileSystem::Write( "=\"", sizeof (char)*2, 1, Fp );
21  VSFileSystem::Write( value2, sizeof (char)*strlen( value2 ), 1, Fp );
22  VSFileSystem::Write( "\"", sizeof (char)*1, 1, Fp );
23 //delete value2;
24 }
25 void midxmlchar( FILE *Fp, const char *tag, const char *value )
26 {
27  VSFileSystem::Write( " ", sizeof (char), 1, Fp );
28  VSFileSystem::Write( tag, sizeof (char)*strlen( tag ), 1, Fp );
29  VSFileSystem::Write( "=\"", sizeof (char)*2, 1, Fp );
30  VSFileSystem::Write( value, sizeof (char)*strlen( value ), 1, Fp );
31  VSFileSystem::Write( "\"", sizeof (char)*1, 1, Fp );
32 }
33 void midxmlint( FILE *Fp, const char *tag, const int value )
34 {
35  char value2[100] = {0};
36  sprintf( value2, "%d", value );
37  VSFileSystem::Write( " ", sizeof (char), 1, Fp );
38  VSFileSystem::Write( tag, sizeof (char)*strlen( tag ), 1, Fp );
39  VSFileSystem::Write( "=\"", sizeof (char)*2, 1, Fp );
40  VSFileSystem::Write( value2, sizeof (char)*strlen( value2 ), 1, Fp );
41  VSFileSystem::Write( "\"", sizeof (char)*1, 1, Fp );
42 }
43 void midxmlbool( FILE *Fp, const char *tag, const bool value )
44 {
45  char value2[6];
46  strcpy( value2, value == true ? "true" : "false" );
47  VSFileSystem::Write( " ", sizeof (char), 1, Fp );
48  VSFileSystem::Write( tag, sizeof (char)*strlen( tag ), 1, Fp );
49  VSFileSystem::Write( "=\"", sizeof (char)*2, 1, Fp );
50  VSFileSystem::Write( value2, sizeof (char)*strlen( value2 ), 1, Fp );
51  VSFileSystem::Write( "\"", sizeof (char)*1, 1, Fp );
52 }
53 void endtag( FILE *Fp, bool end = false )
54 {
55  if (end == true)
56  VSFileSystem::Write( "/", sizeof (char), 1, Fp );
57  VSFileSystem::Write( ">\n", sizeof (char)*2, 1, Fp );
58 }
59 
60 void BaseInterface::Room::Link::EndXML( FILE *fp )
61 {
62  midxmlchar( fp, "Text", text.c_str() );
63  midxmltag( fp, "x", x );
64  midxmltag( fp, "y", y );
65  midxmltag( fp, "wid", wid );
66  midxmltag( fp, "hei", hei );
67 }
68 
69 void BaseInterface::Room::Python::EndXML( FILE *fp )
70 {
71  begintag( fp, "Python", 2 );
72  Link::EndXML( fp );
73  midxmlchar( fp, "pythonfile", file.c_str() );
74  endtag( fp, true );
75 }
76 
77 void BaseInterface::Room::Goto::EndXML( FILE *fp )
78 {
79  begintag( fp, "Link", 2 );
80  Link::EndXML( fp );
81  midxmlint( fp, "index", index );
82  endtag( fp, true );
83 }
84 
85 void BaseInterface::Room::Talk::EndXML( FILE *fp )
86 {
87  begintag( fp, "Talk", 2 );
88  Link::EndXML( fp );
89  endtag( fp, false );
90  for (int i = 0; i < say.size(); i++) {
91  begintag( fp, "say", 3 );
92  for (int j = 0; j < say[i].size(); j++)
93  if (say[i][j] == '\n')
94  say[i][j] = '\\';
95  midxmlchar( fp, "text", say[i].c_str() );
96  midxmlchar( fp, "soundfile", soundfiles[i].c_str() );
97  endtag( fp, true );
98  }
99  begintag( fp, "/Talk", 2 );
100  endtag( fp, false );
101 }
102 
103 void BaseInterface::Room::Launch::EndXML( FILE *fp )
104 {
105  begintag( fp, "Launch", 2 );
106  Link::EndXML( fp );
107  endtag( fp, true );
108 }
109 
110 void BaseInterface::Room::Comp::EndXML( FILE *fp )
111 {
112  begintag( fp, "Comp", 2 );
113  Link::EndXML( fp );
114  for (int i = 0; i < modes.size(); i++) {
115  char *mode = NULL;
116  switch (modes[i])
117  {
118  case BaseComputer::CARGO:
119  mode = "Cargo";
120  break;
122  mode = "Upgrade";
123  break;
125  mode = "ShipDealer";
126  break;
128  mode = "Missions";
129  break;
130  case BaseComputer::NEWS:
131  mode = "News";
132  break;
133  case BaseComputer::INFO:
134  mode = "Info";
135  break;
136  }
137  if (mode)
138  midxmlchar( fp, mode, "" );
139  }
140  endtag( fp, true );
141 }
142 
143 void BaseInterface::Room::BaseObj::EndXML( FILE *fp )
144 {
145 //Do nothing
146 }
147 
148 void BaseInterface::Room::BaseShip::EndXML( FILE *fp )
149 {
150  begintag( fp, "Ship", 2 );
151  midxmltag( fp, "x", mat.p.i );
152  midxmltag( fp, "y", mat.p.j );
153  midxmltag( fp, "z", mat.p.k );
154  midxmltag( fp, "ri", mat.getR().i );
155  midxmltag( fp, "rj", mat.getR().j );
156  midxmltag( fp, "rk", mat.getR().k );
157  midxmltag( fp, "qi", mat.getQ().i );
158  midxmltag( fp, "qj", mat.getQ().j );
159  midxmltag( fp, "qk", mat.getQ().k );
160  endtag( fp, true );
161 }
162 
163 void BaseInterface::Room::BaseVSSprite::EndXML( FILE *fp )
164 {
165  float x, y;
166  begintag( fp, "Texture", 2 );
167  spr.GetPosition( x, y );
168  midxmlchar( fp, "File", texfile.c_str() );
169  midxmltag( fp, "x", x );
170  midxmltag( fp, "y", y );
171  endtag( fp, true );
172 }
173 
174 void BaseInterface::Room::EndXML( FILE *fp )
175 {
176  begintag( fp, "Room", 1 );
177  midxmlchar( fp, "Text", deftext.c_str() );
178  endtag( fp, false );
179  int i;
180  for (i = 0; i < links.size(); i++)
181  if (links[i])
182  links[i]->EndXML( fp );
183  for (i = 0; i < objs.size(); i++)
184  if (objs[i])
185  objs[i]->EndXML( fp );
186  begintag( fp, "/Room", 1 );
187  endtag( fp, false );
188 }
189 
190 void BaseInterface::EndXML( FILE *fp )
191 {
192  begintag( fp, "Base", 0 );
193  endtag( fp, false );
194  for (int i = 0; i < rooms.size(); i++)
195  rooms[i]->EndXML( fp );
196  begintag( fp, "/Base", 0 );
197  endtag( fp, false );
198 }
199 
200 #endif
201 #endif
202