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
zonemgr.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 /*
18  * Zone (StarSystems) Manager - written by Stephane Vaxelaire <svax@free.fr>
19  */
20 
21 #ifndef __ZONEMGR_H
22 #define __ZONEMGR_H
23 
24 #include <list>
25 #include <iostream>
26 #include "gfx/quaternion.h"
27 #include "cmd/unit_generic.h"
28 #include "networking/client.h"
30 #include "boost/smart_ptr.hpp"
31 #include "networking/clientptr.h"
32 
33 using std::list;
34 
35 typedef list< Unit* >::iterator LUI;
36 
37 typedef std::map< std::string, std::string > SystemMap;
38 typedef std::pair< std::string, std::string > SystemPair;
39 typedef std::map< std::string, std::string >::iterator SystemIt;
40 
41 class NetUI;
42 class NetBuffer;
43 
44 class ZoneInfo
45 {
46  friend class ZoneMgr;
47  ClientList zone_list;
48  int zone_clients;
49 
50  int zonenum;
51  static unsigned short next_zonenum;
52  StarSystem *star_system;
53 
54  ZoneInfo( StarSystem *parent )
55  {
56  this->zonenum = next_zonenum;
57  this->zone_clients = 0;
58  this->star_system = parent;
59  next_zonenum++;
60  }
61 public:
62  void display();
63  unsigned short getZoneNum()
64  {
65  return zonenum;
66  }
68  {
69  return star_system;
70  }
71 };
72 
73 typedef std::map< unsigned short, ZoneInfo >ZoneMap;
74 
75 class ZoneMgr
76 {
77 public:
78 /* SnapshotSubCommand removes a double interpretation from
79  * CMD_POSUPDATE and replaces CMD_FULLUPDATE.
80  */
82  {
83  End=0, //On client side (recv) : tells the buffer ends
84  PosUpdate=1, //On client side (send): containing a ship's
85  //data sent to server for position update
86  //On client side (recv) : receive minimal update
87  //data for a ship
88  FullUpdate =2, //On client side (recv) : receive full update
89  //info for a ship
90  DamageUpdate=8, //On client side (recv) : update changed damages.
91  SPECUpdate =16, //On client side (recv) : send SPEC mult and ramp.
92  };
94  {
95 //End=0, // Already defined... // Tells client that the buffer ends.
97  AddUnit =2,
99  AddPlanet =4, //Not implented
102  };
103 
104 private:
105 //vector<StarSystem *> starsystems;
106 //List of clients in zones
107 //vector<ClientList*> zone_list;
108 //vector<int> zone_clients;
109 //List of units in zones (but not Clients)
110 //vector<list<Unit *> > zone_unitlist;
111 //vector<int> zone_units;
112 
113  class Systems
114  {
115  SystemMap _map;
116 
117 public:
118  std::string insert( std::string sysname, std::string systemxml );
119  std::string get( std::string sysname );
120  bool remove( std::string sysname );
121  };
122  Systems Systems;
123 
124 public:
126 
127  ZoneMgr();
128 //ZoneMgr( int nbzones);
129 //~ZoneMgr();
130 //Serial is the zone id
131  void addSystem( string &sysname, string &system );
132  string getSystem( string &name );
133  StarSystem * addZone( string starsys );
134  ZoneInfo * GetZoneInfo( int serial );
135 
136  ClientList * GetZone( int serial );
137 //void addUnit( Unit * un, int zone);
138 //void removeUnit( Unit *un, int zone);
139  Unit * getUnit( ObjSerial unserial, unsigned short zone );
140 
141  void getZoneBuffer( unsigned short zoneid, NetBuffer &netbuf );
142 
143  StarSystem * addClient( ClientPtr clt, string starsys, unsigned short &num_zone );
144  void removeClient( ClientPtr clt );
145  void broadcast( ClientPtr clt, Packet *pckt, bool isTcp, unsigned short minVer = 0, unsigned short maxVer = 65535 );
146  void broadcast( int zone,
147  ObjSerial serial,
148  Packet *pckt,
149  bool isTcp,
150  unsigned short minVer = 0,
151  unsigned short maxVer = 65535 );
152  void broadcastNoSelf( int zone, ObjSerial serial, Packet *pckt, bool isTcp );
153  void broadcastSample( int zone, ObjSerial serial, Packet *pckt, float frequency );
154  void broadcastText( int zone, ObjSerial serial, Packet *pckt, float frequency );
155  void broadcastSnapshots( bool update_planets = false );
156  void addDamage( NetBuffer &netbuf, Unit *un );
157  bool addPosition( ClientPtr k, NetBuffer &netbuf, Unit *un, ClientState &un_cs );
158  void broadcastDamage();
159  double isVisible( Quaternion orient, QVector src_pos, QVector tar_pos );
160 
161  void displayNPCs();
162  void displayStats();
163  int displayMemory();
164 };
165 
166 #endif
167