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
unit_factory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 Carsten Griwodz
3  *
4  * http://vegastrike.sourceforge.net/
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 #include <config.h>
21 
22 #include "unit_factory.h"
23 #include "unit.h"
24 #include "nebula.h"
25 #include "missile.h"
26 #include "enhancement.h"
27 #include "planet.h"
28 #include "asteroid.h"
29 #include "building.h"
30 #include "terrain.h"
31 #include "cont_terrain.h"
32 
34 {
35  static std::string mpl = vs_config->getVariable( "data", "master_part_list", "master_part_list" );
36  return mpl;
37 }
38 
39 void KillDuplicateUnits( ObjSerial likeSerial )
40 {
41  if ( likeSerial != 0 && (Network || SERVER) ) {
42  Unit *un; //FIXME What's the purpos of un here?; doesn't seem to be used --unless macro magic exists...
43  for (un_iter it = _Universe->activeStarSystem()->getUnitList().createIterator(); (un=*it)!=NULL; ++it)
44  if ( (*it)->GetSerial() == likeSerial )
45  (*it)->Kill();
46  }
47 }
48 
50 {
51  return new GameUnit< Unit > ( 0 );
52 }
53 
54 Unit* UnitFactory::createUnit( const char *filename,
55  bool SubUnit,
56  int faction,
57  std::string customizedUnit,
58  Flightgroup *flightgroup,
59  int fg_subnumber,
60  string *netxml,
61  ObjSerial netcreate )
62 {
63  Unit *un = new GameUnit< Unit > ( filename,
64  SubUnit,
65  faction,
66  customizedUnit,
67  flightgroup,
68  fg_subnumber, netxml );
69  if (netcreate) {
70  KillDuplicateUnits( netcreate );
71  un->SetSerial( netcreate );
72  }
73  return un;
74 }
75 Unit* UnitFactory::createServerSideUnit( const char *filename,
76  bool SubUnit,
77  int faction,
78  std::string customizedUnit,
79  Flightgroup *flightgroup,
80  int fg_subnumber )
81 {
82  return new Unit( filename,
83  SubUnit,
84  faction,
85  customizedUnit,
86  flightgroup,
87  fg_subnumber );
88 }
89 
90 Unit* UnitFactory::createUnit( vector< Mesh* > &meshes, bool Subunit, int faction )
91 {
92  return new GameUnit< Unit > ( meshes,
93  Subunit,
94  faction );
95 }
96 
97 Nebula* UnitFactory::createNebula( const char *unitfile,
98  bool SubU,
99  int faction,
100  Flightgroup *fg,
101  int fg_snumber,
102  ObjSerial netcreate )
103 {
104  Nebula *neb = new GameNebula( unitfile,
105  SubU,
106  faction,
107  fg,
108  fg_snumber );
109  if (netcreate) {
110  KillDuplicateUnits( netcreate );
111  neb->SetSerial( netcreate );
112  }
113  return neb;
114 }
115 
116 Missile* UnitFactory::createMissile( const char *filename,
117  int faction,
118  const string &modifications,
119  const float damage,
120  float phasedamage,
121  float time,
122  float radialeffect,
123  float radmult,
124  float detonation_radius,
125  ObjSerial netcreate )
126 {
127  Missile *un = new GameMissile( filename,
128  faction,
129  modifications,
130  damage,
131  phasedamage,
132  time,
133  radialeffect,
134  radmult,
135  detonation_radius );
136  if (netcreate) {
137  KillDuplicateUnits( netcreate );
138  un->SetSerial( netcreate );
139  }
140  return un;
141 }
142 
144 {
145  return new GamePlanet;
146 }
147 
149  QVector y,
150  float vely,
151  const Vector &rotvel,
152  float pos,
153  float gravity,
154  float radius,
155  const string &filename,
156  const string &technique,
157  const string &unitname,
158  BLENDFUNC sr,
159  BLENDFUNC ds,
160  const vector< string > &dest,
161  const QVector &orbitcent,
162  Unit *parent,
163  const GFXMaterial &ourmat,
164  const std::vector< GFXLightLocal > &ligh,
165  int faction,
166  string fullname,
167  bool inside_out,
168  ObjSerial netcreate )
169 {
170  Planet *p = new GamePlanet( x, y, vely, rotvel,
171  pos,
172  gravity, radius,
173  filename, technique, unitname,
174  sr, ds,
175  dest,
176  orbitcent, parent,
177  ourmat, ligh,
178  faction, fullname, inside_out );
179  if (netcreate) {
180  KillDuplicateUnits( netcreate );
181  p->SetSerial( netcreate );
182  }
183  return p;
184 }
185 
187  int faction,
188  const string &modifications,
189  Flightgroup *flightgrp,
190  int fg_subnumber )
191 {
192  return new GameEnhancement( filename,
193  faction,
194  modifications,
195  flightgrp,
196  fg_subnumber );
197 }
198 
200  bool vehicle,
201  const char *filename,
202  bool SubUnit,
203  int faction,
204  const std::string &unitModifications,
205  Flightgroup *fg )
206 {
207  return new GameBuilding( parent,
208  vehicle,
209  filename,
210  SubUnit,
211  faction,
212  unitModifications,
213  fg );
214 }
215 
217  bool vehicle,
218  const char *filename,
219  bool SubUnit,
220  int faction,
221  const std::string &unitModifications,
222  Flightgroup *fg )
223 {
224  return new GameBuilding( parent,
225  vehicle,
226  filename,
227  SubUnit,
228  faction,
229  unitModifications,
230  fg );
231 }
232 
233 Asteroid* UnitFactory::createAsteroid( const char *filename,
234  int faction,
235  Flightgroup *fg,
236  int fg_snumber,
237  float difficulty,
238  ObjSerial netcreate )
239 {
240  Asteroid *ast = new GameAsteroid( filename,
241  faction,
242  fg,
243  fg_snumber,
244  difficulty );
245  if (netcreate) {
246  KillDuplicateUnits( netcreate );
247  ast->SetSerial( netcreate );
248  }
249  return ast;
250 }
251 
252 void UnitFactory::broadcastUnit( Unit *un, unsigned short zone ) {}
253 
254 Terrain* UnitFactory::createTerrain( const char *file, Vector scale, float position, float radius, Matrix &t )
255 {
256  Terrain *tt;
257  tt = new Terrain( file, scale, position, radius );
258  tt->SetTransformation( t );
259  return tt;
260 }
261 
262 ContinuousTerrain* UnitFactory::createContinuousTerrain( const char *file, Vector scale, float position, Matrix &t )
263 {
264  ContinuousTerrain *ct;
265  ct = new ContinuousTerrain( file, scale, position );
266  ct->SetTransformation( t );
267  return ct;
268 }
269