1 /**
2  ** Objserial.h - Object serialization.
3  **
4  ** Written: 5/25/2001 - JSF
5  **/
6 
7 /*
8 Copyright (C) 2001  The Exult Team
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24 
25 #ifndef OBJSERIAL_H
26 #define OBJSERIAL_H 1
27 
28 #include <string>
29 #include "utils.h"
30 #include "servemsg.h"
31 
32 class Serial_out {
33 	unsigned char *&buf;
34 public:
Serial_out(unsigned char * & b)35 	Serial_out(unsigned char *&b) : buf(b)
36 	{  }
37 	template <typename T>
38 	Serial_out &operator<<(T v) {
39 		WriteN(buf, v);
40 		return *this;
41 	}
42 	Serial_out &operator<<(bool v) {
43 		*buf++ = (v ? 1 : 0);
44 		return *this;
45 	}
46 	Serial_out &operator<<(std::string &s);
47 	template <typename T>
48 	Serial_out &operator<<(const T *v) {
49 		(*this) << reinterpret_cast<uintptr>(v);
50 		return *this;
51 	}
52 };
53 
54 /*
55  *  Decode.
56  */
57 class Serial_in {
58 	const unsigned char *&buf;
59 public:
Serial_in(const unsigned char * & b)60 	Serial_in(const unsigned char *&b) : buf(b)
61 	{  }
62 	template <typename T>
63 	Serial_in &operator<<(T &v) {
64 		v = ReadN<T>(buf);
65 		return *this;
66 	}
67 	Serial_in &operator<<(bool &v) {
68 		v = *buf++ != 0;
69 		return *this;
70 	}
71 	Serial_in &operator<<(std::string &s);
72 	template <typename T>
73 	Serial_in &operator<<(T *&v) {
74 		uintptr val;
75 		(*this) << val;
76 		v = reinterpret_cast<T*>(val);
77 		return *this;
78 	}
79 };
80 
81 class Game_object;
82 
83 extern int Object_out(
84     int fd,             // Socket.
85     Exult_server::Msg_type id,  // Message id.
86     const Game_object *addr,     // Address.
87     int tx, int ty, int tz,     // Absolute tile coords.
88     int shape, int frame,
89     int quality,
90     std::string name
91 );
92 extern bool Object_in(
93     const unsigned char *data,        // Data that was read.
94     int datalen,            // Length of data.
95     Game_object *&addr,        // Address.
96     int &tx, int &ty, int &tz,  // Absolute tile coords.
97     int &shape, int &frame,
98     int &quality,
99     std::string &name
100 );
101 
102 class Container_game_object;
103 
104 extern int Container_out(
105     int fd,             // Socket.
106     const Container_game_object *addr,     // Address.
107     int tx, int ty, int tz,     // Absolute tile coords.
108     int shape, int frame,
109     int quality,
110     std::string name,
111     unsigned char resistance,
112     bool invisible, bool okay_to_take
113 );
114 extern bool Container_in(
115     const unsigned char *data,        // Data that was read.
116     int datalen,            // Length of data.
117     Container_game_object *&addr,        // Address.
118     int &tx, int &ty, int &tz,  // Absolute tile coords.
119     int &shape, int &frame,
120     int &quality,
121     std::string &name,
122     unsigned char &resistance,
123     bool &invisible, bool &okay_to_take
124 );
125 
126 class Barge_object;
127 
128 extern int Barge_object_out(
129     int fd,             // Socket.
130     const Barge_object *addr,     // Address.
131     int tx, int ty, int tz, // Absolute tile coords.
132     int shape, int frame,
133     int xtiles,
134     int ytiles,
135     int dir
136 );
137 extern bool Barge_object_in(
138     const unsigned char *data,        // Data that was read.
139     int datalen,            // Length of data.
140     Barge_object *&addr,        // Address.
141     int &tx, int &ty, int &tz,  // Absolute tile coords.
142     int &shape, int &frame,
143     int &xtiles,
144     int &ytiles,
145     int &dir
146 );
147 
148 class Egg_object;
149 
150 extern int Egg_object_out(
151     int fd,             // Socket.
152     const Egg_object *addr,     // Address.
153     int tx, int ty, int tz, // Absolute tile coords.
154     int shape, int frame,
155     int type,
156     int criteria,
157     int probability,
158     int distance,
159     bool nocturnal,
160     bool once,
161     bool hatched,
162     bool auto_reset,
163     int data1, int data2, int data3,
164     std::string str1
165 );
166 extern bool Egg_object_in(
167     const unsigned char *data,        // Data that was read.
168     int datalen,            // Length of data.
169     Egg_object *&addr,        // Address.
170     int &tx, int &ty, int &tz,  // Absolute tile coords.
171     int &shape, int &frame,
172     int &type,
173     int &criteria,
174     int &probability,
175     int &distance,
176     bool &nocturnal,
177     bool &once,
178     bool &hatched,
179     bool &auto_reset,
180     int &data1, int &data2, int &data3,
181     std::string &str1
182 );
183 
184 struct Serial_schedule {        // For passing a schedule change.
185 	short time;         // 0-7 (3-hour period).
186 	short type;         // Schedule type (mostly 0-31).
187 	int tx, ty, tz;         // Tile to go to.
188 };
189 
190 class Actor;
191 
192 int Npc_actor_out(
193     int fd,             // Socket.
194     const Actor *addr,     // Address.
195     int tx, int ty, int tz,     // Absolute tile coords.
196     int shape, int frame, int face,
197     std::string name,
198     short npc_num,
199     short ident,
200     int usecode,
201     std::string usecodefun,
202     int (&properties)[12],        // 12 entries.
203     short attack_mode,
204     short alignment,
205     unsigned long oflags,       // Object flags.
206     unsigned long xflags,       // Extra object flags.
207     unsigned long type_flags,   // Movement flags.
208     short num_schedules,        // # of schedule changes.
209     Serial_schedule *schedules  // Schedule changes.
210 );
211 bool Npc_actor_in(
212     const unsigned char *data,        // Data that was read.
213     int datalen,            // Length of data.
214     Actor *&addr,        // Address.
215     int &tx, int &ty, int &tz,  // Absolute tile coords.
216     int &shape, int &frame, int &face,
217     std::string &name,
218     short &npc_num,
219     short &ident,
220     int &usecode,
221     std::string &usecodefun,
222     int (&properties)[12],        // Must have room for 12.
223     short &attack_mode,
224     short &alignment,
225     unsigned long &oflags,      // Object flags.
226     unsigned long &xflags,      // Extra object flags.
227     unsigned long &type_flags,  // Movement flags.
228     short &num_schedules,       // # of schedule changes.
229     Serial_schedule *schedules  // Schedule changes.  Room for 8.
230 );
231 
232 extern int Game_info_out(
233     int fd,             // Socket.
234     int version,            // Server/client version.
235     int edit_lift,          // Lift being edited.
236     int hide_lift,          // Lift being hidden.
237     bool map_editing,       // In 'map-editing' mode.
238     bool tile_grid,         // Showing tile grid.
239     bool map_modified,      // Map was changed.
240     int edit_mode           // Mode we're in.
241 );
242 extern bool Game_info_in(
243     const unsigned char *data,        // Data that was read.
244     int datalen,            // Length of data.
245     int &version,           // Server/client version.
246     int &edit_lift,         // Lift being edited.
247     int &hide_lift,         // Lift being hidden.
248     bool &map_editing,      // In 'map-editing' mode.
249     bool &tile_grid,        // Showing tile grid.
250     bool &map_modified,     // Map was changed.
251     int &edit_mode          // Mode we're in.
252 );
253 
254 #endif
255 
256 
257 
258 
259