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
weapon_xml.cpp File Reference
#include "star_system.h"
#include "weapon_xml.h"
#include <assert.h>
#include "audiolib.h"
#include "unit_generic.h"
#include "beam.h"
#include "unit_const_cache.h"
#include "vsfilesystem.h"
#include "role_bitmask.h"
#include "endianness.h"
#include "xml_support.h"
#include "physics.h"
#include <vector>
#include <expat.h>

Go to the source code of this file.

Namespaces

 BeamXML
 

Constant Groups

 BeamXML
 

Macros

#define color_step   (49)
 
#define Gamma_Needed(gamma, count, depth)
 

Enumerations

enum  BeamXML::Names {
  BeamXML::UNKNOWN, BeamXML::WEAPONS, BeamXML::BEAM, BeamXML::BALL,
  BeamXML::BOLT, BeamXML::PROJECTILE, BeamXML::APPEARANCE, BeamXML::ENERGY,
  BeamXML::DAMAGE, BeamXML::DISTANCE, BeamXML::NAME, BeamXML::SOUNDMP3,
  BeamXML::SOUNDWAV, BeamXML::WEAPSIZE, BeamXML::XFILE, BeamXML::RED,
  BeamXML::GREEN, BeamXML::BLUE, BeamXML::ALPHA, BeamXML::SPEED,
  BeamXML::OFFSETX, BeamXML::OFFSETY, BeamXML::OFFSETZ, BeamXML::PULSESPEED,
  BeamXML::RADIALSPEED, BeamXML::RANGE, BeamXML::RADIUS, BeamXML::RATE,
  BeamXML::STABILITY, BeamXML::LONGRANGE, BeamXML::CONSUMPTION, BeamXML::REFIRE,
  BeamXML::LENGTH, BeamXML::PHASEDAMAGE, BeamXML::VOLUME, BeamXML::DETONATIONRADIUS,
  BeamXML::LOCKTIME, BeamXML::ROLE, BeamXML::ANTIROLE, BeamXML::TEXTURESTRETCH
}
 

Functions

enum weapon_info::MOUNT_SIZE lookupMountSize (const char *str)
 
weapon_info getWeaponInfoFromBuffer (char *netbuf, int &size)
 
void setWeaponInfoToBuffer (weapon_info wi, char *netbuf, int &bufsize)
 
void BeamXML::beginElementXML_Char (void *userData, const XML_Char *name, const XML_Char **atts)
 
void BeamXML::beginElement (void *userData, const char *name, const char **atts)
 
void BeamXML::endElement (void *userData, const XML_Char *name)
 
weapon_infogetTemplate (const string &kkey)
 
void LoadWeapons (const char *filename)
 

Variables

int counts = time( NULL )
 
const EnumMap::Pair BeamXML::element_names []
 
const EnumMap::Pair BeamXML::attribute_names []
 
const EnumMap BeamXML::element_map (element_names, 10)
 
const EnumMap BeamXML::attribute_map (attribute_names, 32)
 
Hashtable< string, weapon_info, 257 > BeamXML::lookuptable
 
string BeamXML::curname
 
weapon_info BeamXML::tmpweapon (weapon_info::BEAM)
 
int BeamXML::level = -1
 

Macro Definition Documentation

#define color_step   (49)

Definition at line 231 of file weapon_xml.cpp.

Referenced by BeamXML::beginElement().

#define Gamma_Needed (   gamma,
  count,
  depth 
)
Value:
( \
!( \
( count/(100*depth*gamma) ) \
%( (6*(color_step*100+depth)/gamma-1)/3 ) \
-100 \
) \
)

Definition at line 233 of file weapon_xml.cpp.

Referenced by BeamXML::beginElement().

Function Documentation

weapon_info* getTemplate ( const string &  kkey)

Definition at line 525 of file weapon_xml.cpp.

References VSFileSystem::CachedFileLookup(), ClassCache< Typ, Key >::getCachedMutable(), VegaConfig::getVariable(), weapon_info::gun, weapon_info::gun1, Mesh::LoadMesh(), BeamXML::lookuptable, VSFileSystem::MeshFile, VSFileSystem::Ok, ClassCache< Typ, Key >::setCachedMutable(), strtolower(), strtoupper(), Vector, vs_config, and weapon_info::weapon_name.

526 {
527  weapon_info *wi = lookuptable.Get( strtoupper( kkey ) );
528  if (wi) {
530  static string sharedmountdir = vs_config->getVariable( "data", "mountlocation", "weapons" );
531  static FileLookupCache lookup_cache;
532  string meshname = strtolower( kkey )+".bfxm";
533  if (CachedFileLookup( lookup_cache, meshname, MeshFile ) <= Ok) {
535  Mesh::LoadMesh( meshname.c_str(), Vector( 1, 1, 1 ), 0, NULL ) );
537  Mesh::LoadMesh( meshname.c_str(), Vector( 1, 1, 1 ), 0, NULL ) );
538  }
539  }
540  }
541  return wi;
542 }
weapon_info getWeaponInfoFromBuffer ( char *  netbuf,
int size 
)

Definition at line 23 of file weapon_xml.cpp.

References weapon_info::file, VsnetOSS::memcpy(), weapon_info::UNKNOWN, VSSwapHostShortToLittle(), and weapon_info::weapon_name.

24 {
26  unsigned short file_len = 0, weap_len = 0;
27  int offset = 0;
28 
29  //Get the weapon_info structure
30  memcpy( &wi, netbuf+offset, sizeof (wi) );
31  offset += sizeof (wi);
32  memcpy( &file_len, netbuf+offset, sizeof (file_len) );
33  offset += sizeof (file_len);
34  file_len = VSSwapHostShortToLittle( file_len );
35  char *filename = new char[file_len];
36  memcpy( filename, netbuf, file_len );
37  offset += file_len;
38  memcpy( &weap_len, netbuf+offset, sizeof (weap_len) );
39  offset += sizeof (weap_len);
40  weap_len = VSSwapHostShortToLittle( weap_len );
41  char *weapname = new char[weap_len];
42  memcpy( weapname, netbuf, weap_len );
43  wi.file = string( filename );
44  wi.weapon_name = string( weapname );
45  delete[] filename;
46  delete[] weapname;
47 
48  return wi;
49 }
void LoadWeapons ( const char *  filename)

Definition at line 544 of file weapon_xml.cpp.

References BeamXML::beginElementXML_Char(), BeamXML::endElement(), f, VSFileSystem::Ok, and VSFileSystem::UnknownFile.

Referenced by GameUniverse::Init(), and Universe::Init().

545 {
546  using namespace VSFileSystem;
547  VSFile f;
548  VSError err = f.OpenReadOnly( filename, UnknownFile );
549  if (err > Ok)
550  return;
551  XML_Parser parser = XML_ParserCreate( NULL );
552  XML_SetElementHandler( parser, &beginElementXML_Char, &endElement );
553  XML_Parse( parser, ( f.ReadFull() ).c_str(), f.Size(), 1 );
554  f.Close();
555  XML_ParserFree( parser );
556 }
enum weapon_info::MOUNT_SIZE lookupMountSize ( const char *  str)

Definition at line 237 of file unit_functions_generic.cpp.

238 {
239  int i;
240  char tmp[384];
241  for (i = 0; i < 383 && str[i] != '\0'; i++)
242  tmp[i] = (char) toupper( str[i] );
243  tmp[i] = '\0';
244  if (strcmp( "LIGHT", tmp ) == 0)
245  return weapon_info::LIGHT;
246  if (strcmp( "MEDIUM", tmp ) == 0)
247  return weapon_info::MEDIUM;
248  if (strcmp( "HEAVY", tmp ) == 0)
249  return weapon_info::HEAVY;
250  if (strcmp( "CAPSHIP-LIGHT", tmp ) == 0)
252  if (strcmp( "CAPSHIP-HEAVY", tmp ) == 0)
254  if (strcmp( "SPECIAL", tmp ) == 0)
255  return weapon_info::SPECIAL;
256  if (strcmp( "LIGHT-MISSILE", tmp ) == 0)
258  if (strcmp( "MEDIUM-MISSILE", tmp ) == 0)
260  if (strcmp( "HEAVY-MISSILE", tmp ) == 0)
262  if (strcmp( "LIGHT-CAPSHIP-MISSILE", tmp ) == 0)
264  if (strcmp( "HEAVY-CAPSHIP-MISSILE", tmp ) == 0)
266  if (strcmp( "SPECIAL-MISSILE", tmp ) == 0)
268  if (strcmp( "AUTOTRACKING", tmp ) == 0)
270  return weapon_info::NOWEAP;
271 }
void setWeaponInfoToBuffer ( weapon_info  wi,
char *  netbuf,
int bufsize 
)

Definition at line 51 of file weapon_xml.cpp.

References bufsize, weapon_info::file, accountXML::file, VsnetOSS::memcpy(), and weapon_info::weapon_name.

52 {
53  bufsize = sizeof (wi)+sizeof (wi.file)+sizeof (wi.weapon_name);
54  netbuf = new char[bufsize+1];
55  netbuf[bufsize] = 0;
56  int offset = 0;
57 
58  unsigned short file_len = wi.file.length();
59  unsigned short weap_len = wi.weapon_name.length();
60  char *file = new char[file_len+1];
61  char *weapon_name = new char[weap_len+1];
62  memcpy( file, wi.file.c_str(), file_len );
63  file[file_len] = 0;
64  memcpy( weapon_name, wi.weapon_name.c_str(), weap_len );
65  weapon_name[weap_len] = 0;
66 
67  //Copy the struct weapon_info in the buffer
68  memcpy( netbuf+offset, &wi, sizeof (wi) );
69  offset += sizeof (wi);
70  //Copy the size of filename in the buffer
71  memcpy( netbuf+offset, &file_len, sizeof (file_len) );
72  offset += sizeof (file_len);
73  //Copy the filename in the buffer because in weapon_info, it is a string
74  memcpy( netbuf+offset, file, file_len );
75  offset += file_len;
76  //Copy the size of filename in the buffer
77  memcpy( netbuf+offset, &weap_len, sizeof (weap_len) );
78  offset += sizeof (weap_len);
79  //Copy the weapon_name in the buffer because in weapon_info, it is a string
80  memcpy( netbuf+offset, weapon_name, weap_len );
81 
82  delete[] file;
83  delete[] weapon_name;
84 }

Variable Documentation

int counts = time( NULL )

Definition at line 18 of file weapon_xml.cpp.

Referenced by BeamXML::beginElement().