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_server.cpp
Go to the documentation of this file.
1 #include "unit_factory.h"
2 #include "unit_generic.h"
3 #include "gfx/cockpit_generic.h"
4 #include "nebula_generic.h"
5 #include "planet_generic.h"
6 #include "asteroid_generic.h"
7 #include "missile_generic.h"
8 #include "enhancement_generic.h"
9 #if defined (_WIN32) && !defined (__CYGWIN__)
10 #include <direct.h>
11 #else
12 #include <unistd.h>
13 #include <pwd.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16 #endif
18 #include "networking/zonemgr.h"
19 #include "networking/netserver.h"
20 
22 {
23  return new Unit( 0 );
24 }
25 
26 Unit* UnitFactory::createUnit( const char *filename,
27  bool SubUnit,
28  int faction,
29  std::string customizedUnit,
30  Flightgroup *flightgroup,
31  int fg_subnumber,
32  string *netxml,
33  ObjSerial netcreate )
34 {
35  _Universe->netLock( true );
36  Unit *un = new Unit( filename,
37  SubUnit,
38  faction,
39  customizedUnit,
40  flightgroup,
41  fg_subnumber, netxml );
42  _Universe->netLock( false );
43  if (netcreate)
44  //Send a packet to clients in order to make them create this unit
45  un->SetSerial( netcreate );
46 /* if (!_Universe->netLocked()) {
47  * NetBuffer netbuf;
48  *
49  * // NETFIXME: addBuffer for all subunits?
50  * addUnitBuffer(netbuf, un, netxml);
51  * endBuffer(netbuf);
52  * // Broadcast to the current universe star system
53  * VSServer->broadcast( netbuf, 0, _Universe->activeStarSystem()->GetZone(), CMD_ENTERCLIENT, true);
54  * }
55  * VSServer->invalidateSnapshot();
56  */
57  return un;
58 }
59 Unit* UnitFactory::createServerSideUnit( const char *filename,
60  bool SubUnit,
61  int faction,
62  std::string customizedUnit,
63  Flightgroup *flightgroup,
64  int fg_subnumber )
65 {
66  return new Unit( filename,
67  SubUnit,
68  faction,
69  customizedUnit,
70  flightgroup,
71  fg_subnumber );
72 }
73 
74 Unit* UnitFactory::createUnit( vector< Mesh* > &meshes, bool Subunit, int faction )
75 {
76  return new Unit( meshes,
77  Subunit,
78  faction );
79 }
80 
81 Nebula* UnitFactory::createNebula( const char *unitfile,
82  bool SubU,
83  int faction,
84  Flightgroup *fg,
85  int fg_snumber,
86  ObjSerial netcreate )
87 {
88  _Universe->netLock( true );
89  Nebula *neb = new Nebula( unitfile,
90  SubU,
91  faction,
92  fg,
93  fg_snumber );
94  _Universe->netLock( false );
95  if (netcreate)
96  neb->SetSerial( netcreate );
97 /*
98  * if (!_Universe->netLocked()) {
99  * NetBuffer netbuf;
100  * addNebulaBuffer(netbuf, neb);
101  * endBuffer(netbuf);
102  * VSServer->broadcast( netbuf, 0, _Universe->activeStarSystem()->GetZone(), CMD_ENTERCLIENT, true);
103  * }
104  * VSServer->invalidateSnapshot();
105  */
106  return neb;
107 }
108 
109 Missile* UnitFactory::createMissile( const char *filename,
110  int faction,
111  const string &modifications,
112  const float damage,
113  float phasedamage,
114  float time,
115  float radialeffect,
116  float radmult,
117  float detonation_radius,
118  ObjSerial netcreate )
119 {
120  _Universe->netLock( true );
121  Missile *un = new Missile( filename,
122  faction,
123  modifications,
124  damage,
125  phasedamage,
126  time,
127  radialeffect,
128  radmult,
129  detonation_radius );
130  _Universe->netLock( false );
131  if (netcreate)
132  un->SetSerial( netcreate );
133 /*
134  * if (!_Universe->netLocked()) {
135  * NetBuffer netbuf;
136  * addMissileBuffer( netbuf, un );
137  * endBuffer( netbuf );
138  * VSServer->broadcast( netbuf, 0, _Universe->activeStarSystem()->GetZone(), CMD_ENTERCLIENT, true);
139  * }
140  * VSServer->invalidateSnapshot();
141  */
142  return un;
143 }
144 
146 {
147  return new Planet;
148 }
149 
151  QVector y,
152  float vely,
153  const Vector &rotvel,
154  float pos,
155  float gravity,
156  float radius,
157  const std::string &filename,
158  const std::string &technique,
159  const std::string &unitname,
160  BLENDFUNC sr,
161  BLENDFUNC ds,
162  const vector< string > &dest,
163  const QVector &orbitcent,
164  Unit *parent,
165  const GFXMaterial &ourmat,
166  const std::vector< GFXLightLocal > &ligh,
167  int faction,
168  string fullname,
169  bool inside_out,
170  ObjSerial netcreate )
171 {
172  _Universe->netLock( true );
173  Planet *p = new Planet( x, y, vely, rotvel, pos, gravity, radius,
174  filename, technique, unitname, dest, orbitcent, parent, faction,
175  fullname, inside_out, ligh.size() );
176  _Universe->netLock( false );
177  if (netcreate)
178  p->SetSerial( netcreate );
179 /*
180  * // False: Only allow creation through system files? Doesn't make sense to be able to dynamically generate these.
181  * // Could cause inconsistencies with new clients that just read system files.
182  * if ( false && !_Universe->netLocked()) {
183  * NetBuffer netbuf;
184  * // Send a packet to clients in order to make them create this unit
185  *
186  * addPlanetBuffer( netbuf, x, y, vely, rotvel, pos, gravity, radius, filename, sr, ds, dest, orbitcent, parent, ourmat, ligh, faction, fullname, inside_out, netcreate);
187  * endBuffer( netbuf );
188  * VSServer->broadcast( netbuf, 0, _Universe->activeStarSystem()->GetZone(), CMD_ENTERCLIENT, true);
189  * }
190  * VSServer->invalidateSnapshot();
191  */
192  return p;
193 }
194 
195 Enhancement* UnitFactory::createEnhancement( const char *filename,
196  int faction,
197  const string &modifications,
198  Flightgroup *flightgrp,
199  int fg_subnumber )
200 {
201  return new Enhancement( filename, faction, modifications, flightgrp, fg_subnumber );
202 }
203 
205  bool vehicle,
206  const char *filename,
207  bool SubUnit,
208  int faction,
209  const std::string &unitModifications,
210  Flightgroup *fg )
211 {
212  return NULL;
213 }
214 
216  bool vehicle,
217  const char *filename,
218  bool SubUnit,
219  int faction,
220  const std::string &unitModifications,
221  Flightgroup *fg )
222 {
223  return NULL;
224 }
225 
226 Asteroid* UnitFactory::createAsteroid( const char *filename,
227  int faction,
228  Flightgroup *fg,
229  int fg_snumber,
230  float difficulty,
231  ObjSerial netcreate )
232 {
233  _Universe->netLock( true );
234  Asteroid *ast = new Asteroid( filename, faction, fg, fg_snumber, difficulty );
235  _Universe->netLock( false );
236  if (netcreate)
237  //Only allow creating through system files? Doesn't make sense to be able to dynamically generate these.
238  ast->SetSerial( netcreate );
239 /*
240  * if ( !_Universe->netLocked()) {
241  * NetBuffer netbuf;
242  * addAsteroidBuffer( netbuf, ast);
243  * endBuffer(netbuf);
244  * // NETFIXME: addBuffer for all subunits?
245  * VSServer->broadcast( netbuf, 0, _Universe->activeStarSystem()->GetZone(), CMD_ENTERCLIENT, true);
246  * }
247  * VSServer->invalidateSnapshot();
248  */
249  return ast;
250 }
251 
252 Terrain* UnitFactory::createTerrain( const char *file, Vector scale, float position, float radius, Matrix &t )
253 {
254  return NULL;
255 }
256 
257 ContinuousTerrain* UnitFactory::createContinuousTerrain( const char *file, Vector scale, float position, Matrix &t )
258 {
259  return NULL;
260 }
261 
262 void UnitFactory::broadcastUnit( Unit *unit, unsigned short zone )
263 {
264  if ( !_Universe->netLocked() && unit->GetSerial() )
265  if (SERVER) VSServer->broadcastUnit( unit, zone );
266 }
267