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
nebula_generic.cpp
Go to the documentation of this file.
1 #include "nebula_generic.h"
2 #include "vegastrike.h"
3 #include "vsfilesystem.h"
4 #include <assert.h>
5 #include "configxml.h"
6 #include "vs_globals.h"
7 #include <sys/stat.h>
8 #include "xml_support.h"
9 #undef BOOST_NO_CWCHAR
10 
14 using namespace NebulaXML;
15 
17 {
18  if (val == "exp")
19  return FOG_EXP;
20  else if (val == "exp2")
21  return FOG_EXP2;
22  else if (val == "linear")
23  return FOG_LINEAR;
24  else
25  return FOG_OFF;
26 }
27 
28 void Nebula::beginElement( void *Userdata, const XML_Char *name, const XML_Char **atts )
29 {
30  ( (Nebula*) Userdata )->beginElem( std::string( name ), AttributeList( atts ) );
31 }
32 
33 static void Nebula_endElement( void *Userdata, const XML_Char* ) {}
34 
35 void Nebula::beginElem( const std::string &name, const AttributeList &atts )
36 {
37  Names elem = (Names) element_map.lookup( name );
38  AttributeList::const_iterator iter;
39  switch (elem)
40  {
41  case UNKNOWN:
42  break;
43  case NEBULA:
44  fogme = true;
45  explosiontime = 0;
46  index = 0;
47  fogmode = FOG_LINEAR;
48  for (iter = atts.begin(); iter != atts.end(); iter++) {
49  switch ( attribute_map.lookup( (*iter).name ) )
50  {
51  case DENSITY:
52  Density = parse_float( (*iter).value );
53  break;
54  case INDEX:
55  index = parse_int( (*iter).value );
56  break;
57  case MODE:
58  fogmode = parse_fogmode( (*iter).value );
59  break;
60  case EXPLOSIONTIME:
61  explosiontime = parse_float( (*iter).value );
62  break;
63  case FOGTHIS:
64  fogme = parse_bool( (*iter).value );
65  break;
66  }
67  }
68  break;
69  case COLOR:
70  for (iter = atts.begin(); iter != atts.end(); iter++) {
71  switch ( attribute_map.lookup( (*iter).name ) )
72  {
73  case RED:
74  color.i = parse_float( (*iter).value );
75  break;
76  case GREEN:
77  color.j = parse_float( (*iter).value );
78  break;
79  case BLUE:
80  color.k = parse_float( (*iter).value );
81  break;
82  }
83  }
84  break;
85  case LIMITS:
86  for (iter = atts.begin(); iter != atts.end(); iter++) {
87  switch ( attribute_map.lookup( (*iter).name ) )
88  {
89  case NEBNEAR:
90  fognear = parse_float( (*iter).value );
91  break;
92  case NEBFAR:
93  fogfar = parse_float( (*iter).value );
94  break;
95  }
96  }
97  break;
98  default:
99  break;
100  }
101 }
102 
103 using namespace VSFileSystem;
104 void Nebula::LoadXML( const char *filename )
105 {
106  VSFile f;
107  VSError err = f.OpenReadOnly( filename, UnitFile );
108  static bool usefog = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "fog", "true" ) );
109  if (err > Ok || !usefog) {
110  if (err <= Ok)
111  f.Close();
112  else
113  VSFileSystem::vs_fprintf( stderr, "\nUnit file %s not found\n", filename );
114  fogmode = FOG_OFF;
115  return;
116  }
117  XML_Parser parser = XML_ParserCreate( NULL );
118  XML_SetUserData( parser, this );
119  XML_SetElementHandler( parser, &Nebula::beginElement, &Nebula_endElement );
120  XML_Parse( parser, ( f.ReadFull() ).c_str(), f.Size(), 1 );
121  XML_ParserFree( parser );
122  f.Close();
123 }
124 
125 void Nebula::InitNebula( const char *unitfile, bool SubU, int faction, Flightgroup *fg, int fg_snumber )
126 {
127  fogme = true;
128  string fullpath( unitfile );
129  fullpath += ".nebula";
130 
131  LoadXML( fullpath.c_str() );
132 }
133 
134 Nebula::Nebula( const char *unitfile, bool SubU, int faction, Flightgroup *fg, int fg_snumber ) :
135  Unit( unitfile, SubU, faction, string( "" ), fg, fg_snumber )
136 {
137  this->InitNebula( unitfile, SubU, faction, fg, fg_snumber );
138 }
139 
141  const QVector &biglocation,
142  const Vector &bignormal,
143  const QVector &smalllocation,
144  const Vector &smallnormal,
145  float dist )
146 {
147  if (fogme)
148  SetNebula( this );
149  smaller->SetNebula( this );
150 }
151 
153  const Transformation &old_physical_state,
154  const Vector &accel,
155  float difficulty,
156  const Matrix &transmat,
157  const Vector &CumulativeVelocity,
158  bool ResolveLast,
159  UnitCollection *uc )
160 {
161  Unit::UpdatePhysics2( trans, old_physical_state, accel, difficulty, transmat, CumulativeVelocity, ResolveLast, uc );
162 }
163