1 /* $Id: multi.h,v 1.8 2002/09/14 00:23:06 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14 
15 /*
16  *
17  * FIXME: put description here
18  *
19  */
20 
21 #ifndef _MULTI_H
22 #define _MULTI_H
23 
24 #define MAX_MESSAGE_LEN 35
25 
26 // Defines
27 #include "gameseq.h"
28 #include "piggy.h"
29 
30 // What version of the multiplayer protocol is this?
31 
32 #ifdef SHAREWARE
33 #define MULTI_PROTO_VERSION 3
34 #else
35 #define MULTI_PROTO_VERSION 4
36 #endif
37 
38 // Protocol versions:
39 //   1 Descent Shareware
40 //   2 Descent Registered/Commercial
41 //   3 Descent II Shareware
42 //   4 Descent II Commercial
43 
44 // Save multiplayer games?
45 
46 #define MULTI_SAVE
47 
48 // How many simultaneous network players do we support?
49 
50 #define MAX_NUM_NET_PLAYERS     8
51 
52 #define MULTI_POSITION          0
53 #define MULTI_REAPPEAR          1
54 #define MULTI_FIRE              2
55 #define MULTI_KILL              3
56 #define MULTI_REMOVE_OBJECT     4
57 #define MULTI_PLAYER_EXPLODE    5
58 #define MULTI_MESSAGE           6
59 #define MULTI_QUIT              7
60 #define MULTI_PLAY_SOUND        8
61 #define MULTI_BEGIN_SYNC        9
62 #define MULTI_CONTROLCEN        10
63 #define MULTI_ROBOT_CLAIM       11
64 #define MULTI_END_SYNC          12
65 #define MULTI_CLOAK             13
66 #define MULTI_ENDLEVEL_START    14
67 #define MULTI_DOOR_OPEN         15
68 #define MULTI_CREATE_EXPLOSION  16
69 #define MULTI_CONTROLCEN_FIRE   17
70 #define MULTI_PLAYER_DROP       18
71 #define MULTI_CREATE_POWERUP    19
72 #define MULTI_CONSISTENCY       20
73 #define MULTI_DECLOAK           21
74 #define MULTI_MENU_CHOICE       22
75 #define MULTI_ROBOT_POSITION    23
76 #define MULTI_ROBOT_EXPLODE     24
77 #define MULTI_ROBOT_RELEASE     25
78 #define MULTI_ROBOT_FIRE        26
79 #define MULTI_SCORE             27
80 #define MULTI_CREATE_ROBOT      28
81 #define MULTI_TRIGGER           29
82 #define MULTI_BOSS_ACTIONS      30
83 #define MULTI_CREATE_ROBOT_POWERUPS 31
84 #define MULTI_HOSTAGE_DOOR      32
85 
86 #define MULTI_SAVE_GAME         33
87 #define MULTI_RESTORE_GAME      34
88 
89 #define MULTI_REQ_PLAYER        35  // Someone requests my player structure
90 #define MULTI_SEND_PLAYER       36  // Sending someone my player structure
91 #define MULTI_MARKER            37
92 #define MULTI_DROP_WEAPON       38
93 #define MULTI_GUIDED            39
94 #define MULTI_STOLEN_ITEMS      40
95 #define MULTI_WALL_STATUS       41  // send to new players
96 #define MULTI_HEARTBEAT         42
97 #define MULTI_KILLGOALS         43
98 #define MULTI_SEISMIC           44
99 #define MULTI_LIGHT             45
100 #define MULTI_START_TRIGGER     46
101 #define MULTI_FLAGS             47
102 #define MULTI_DROP_BLOB         48
103 #define MULTI_POWERUP_UPDATE    49
104 #define MULTI_ACTIVE_DOOR       50
105 #define MULTI_SOUND_FUNCTION    51
106 #define MULTI_CAPTURE_BONUS     52
107 #define MULTI_GOT_FLAG          53
108 #define MULTI_DROP_FLAG         54
109 #define MULTI_ROBOT_CONTROLS    55
110 #define MULTI_FINISH_GAME       56
111 #define MULTI_RANK              57
112 #define MULTI_MODEM_PING        58
113 #define MULTI_MODEM_PING_RETURN 59
114 #define MULTI_ORB_BONUS         60
115 #define MULTI_GOT_ORB           61
116 #define MULTI_DROP_ORB          62
117 #define MULTI_PLAY_BY_PLAY      63
118 
119 #define MULTI_MAX_TYPE          63
120 
121 #define MAX_NET_CREATE_OBJECTS  40
122 
123 #define MAX_MULTI_MESSAGE_LEN   120
124 
125 // Exported functions
126 
127 int objnum_remote_to_local(int remote_obj, int owner);
128 int objnum_local_to_remote(int local_obj, byte *owner);
129 void map_objnum_local_to_remote(int local, int remote, int owner);
130 void map_objnum_local_to_local(int objnum);
131 
132 void multi_init_objects(void);
133 void multi_show_player_list(void);
134 void multi_do_frame(void);
135 
136 
137 void multi_send_flags(char);
138 void multi_send_fire(void);
139 void multi_send_destroy_controlcen(int objnum, int player);
140 void multi_send_endlevel_start(int);
141 void multi_send_player_explode(char type);
142 void multi_send_message(void);
143 void multi_send_position(int objnum);
144 void multi_send_reappear();
145 void multi_send_kill(int objnum);
146 void multi_send_remobj(int objnum);
147 void multi_send_quit(int why);
148 void multi_send_door_open(int segnum, int side,ubyte flag);
149 void multi_send_create_explosion(int player_num);
150 void multi_send_controlcen_fire(vms_vector *to_target, int gun_num, int objnum);
151 void multi_send_cloak(void);
152 void multi_send_decloak(void);
153 void multi_send_create_powerup(int powerup_type, int segnum, int objnum, vms_vector *pos);
154 void multi_send_play_sound(int sound_num, fix volume);
155 void multi_send_audio_taunt(int taunt_num);
156 void multi_send_score(void);
157 void multi_send_trigger(int trigger);
158 void multi_send_hostage_door_status(int wallnum);
159 void multi_send_netplayer_stats_request(ubyte player_num);
160 void multi_send_drop_weapon (int objnum,int seed);
161 void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
162 void multi_send_guided_info (object *miss,char);
163 
164 
165 void multi_endlevel_score(void);
166 void multi_prep_level(void);
167 int multi_endlevel(int *secret);
168 int multi_menu_poll(void);
169 void multi_leave_game(void);
170 void multi_process_data(char *dat, int len);
171 void multi_process_bigdata(char *buf, int len);
172 void multi_do_death(int objnum);
173 void multi_send_message_dialog(void);
174 int multi_delete_extra_objects(void);
175 void multi_make_ghost_player(int objnum);
176 void multi_make_player_ghost(int objnum);
177 void multi_define_macro(int key);
178 void multi_send_macro(int key);
179 int multi_get_kill_list(int *plist);
180 void multi_new_game(void);
181 void multi_sort_kill_list(void);
182 int multi_choose_mission(int *anarchy_only);
183 void multi_reset_stuff(void);
184 
185 void multi_send_data(char *buf, int len, int repeat);
186 
187 int get_team(int pnum);
188 
189 // Exported variables
190 
191 
192 extern int Network_active;
193 extern int Network_laser_gun;
194 extern int Network_laser_fired;
195 extern int Network_laser_level;
196 extern int Network_laser_flags;
197 extern int Netlife_kills,Netlife_killed;
198 
199 extern int message_length[MULTI_MAX_TYPE+1];
200 extern char multibuf[MAX_MULTI_MESSAGE_LEN+4];
201 extern short Network_laser_track;
202 
203 extern int who_killed_controlcen;
204 
205 extern int Net_create_objnums[MAX_NET_CREATE_OBJECTS];
206 extern int Net_create_loc;
207 
208 extern short kill_matrix[MAX_NUM_NET_PLAYERS][MAX_NUM_NET_PLAYERS];
209 extern short team_kills[2];
210 
211 extern int multi_goto_secret;
212 
213 //do we draw the kill list on the HUD?
214 extern int Show_kill_list;
215 extern int Show_reticle_name;
216 extern fix Show_kill_list_timer;
217 
218 // Used to send network messages
219 
220 extern char Network_message[MAX_MESSAGE_LEN];
221 extern char Network_message_macro[4][MAX_MESSAGE_LEN];
222 extern int Network_message_reciever;
223 
224 // Used to map network to local object numbers
225 
226 extern short remote_to_local[MAX_NUM_NET_PLAYERS][MAX_OBJECTS];  // Network object num for each
227 extern short local_to_remote[MAX_OBJECTS];   // Local object num for each network objnum
228 extern byte object_owner[MAX_OBJECTS]; // Who 'owns' each local object for network purposes
229 
230 extern int multi_in_menu; // Flag to tell if we're executing GameLoop from within a newmenu.
231 extern int multi_leave_menu;
232 extern int multi_quit_game;
233 
234 extern int multi_sending_message;
235 extern int multi_defining_message;
236 extern void multi_message_input_sub( int key );
237 extern void multi_send_message_start();
238 
239 extern int multi_powerup_is_4pack(int );
240 extern void multi_send_orb_bonus( char pnum );
241 extern void multi_send_got_orb( char pnum );
242 extern void multi_add_lifetime_kills(void);
243 
244 extern int control_invul_time;
245 
246 #define N_PLAYER_SHIP_TEXTURES 6
247 
248 extern bitmap_index multi_player_textures[MAX_NUM_NET_PLAYERS][N_PLAYER_SHIP_TEXTURES];
249 
250 #define NETGAME_FLAG_CLOSED             1
251 #define NETGAME_FLAG_SHOW_ID            2
252 #define NETGAME_FLAG_SHOW_MAP           4
253 #define NETGAME_FLAG_HOARD              8
254 #define NETGAME_FLAG_TEAM_HOARD         16
255 #define NETGAME_FLAG_REALLY_ENDLEVEL    32
256 #define NETGAME_FLAG_REALLY_FORMING     64
257 
258 #define NETGAME_NAME_LEN                15
259 
260 enum __pack__ comp_type {DOS,WIN_32,WIN_95,MAC};
261 
262 // sigh...the socket structure member was moved away from it's friends.
263 // I'll have to create a union for appletalk network info with just
264 // the server and node members since I cannot change the order ot these
265 // members.
266 
267 typedef struct netplayer_info {
268 	char    callsign[CALLSIGN_LEN+1];
269 	union {
270 		struct {
271 			ubyte   server[4];
272 			ubyte   node[6];
273 		} ipx;
274 		struct {
275 			ushort  net;
276 			ubyte   node;
277 			ubyte   socket;
278 		} appletalk;
279 	} network;
280 
281 	ubyte   version_major;
282 	ubyte   version_minor;
283 	enum comp_type computer_type;
284 	byte    connected;
285 
286 	ushort  socket;
287 
288 	ubyte   rank;
289 
290 } __pack__ netplayer_info;
291 
292 typedef struct AllNetPlayers_info
293 {
294 	char    type;
295 	int     Security;
296 	struct netplayer_info players[MAX_PLAYERS+4];
297 } __pack__ AllNetPlayers_info;
298 
299 typedef struct netgame_info {
300 	ubyte   type;
301 	int     Security;
302 	char    game_name[NETGAME_NAME_LEN+1];
303 	char    mission_title[MISSION_NAME_LEN+1];
304 	char    mission_name[9];
305 	int     levelnum;
306 	ubyte   gamemode;
307 	ubyte   RefusePlayers;
308 	ubyte   difficulty;
309 	ubyte   game_status;
310 	ubyte   numplayers;
311 	ubyte   max_numplayers;
312 	ubyte   numconnected;
313 	ubyte   game_flags;
314 	ubyte   protocol_version;
315 	ubyte   version_major;
316 	ubyte   version_minor;
317 	ubyte   team_vector;
318 
319 // change the order of the bit fields for the mac compiler.
320 // doing so will mean I don't have to do screwy things to
321 // send this as network information
322 
323 #ifndef WORDS_BIGENDIAN
324 	short DoMegas:1;
325 	short DoSmarts:1;
326 	short DoFusions:1;
327 	short DoHelix:1;
328 	short DoPhoenix:1;
329 	short DoAfterburner:1;
330 	short DoInvulnerability:1;
331 	short DoCloak:1;
332 	short DoGauss:1;
333 	short DoVulcan:1;
334 	short DoPlasma:1;
335 	short DoOmega:1;
336 	short DoSuperLaser:1;
337 	short DoProximity:1;
338 	short DoSpread:1;
339 	short DoSmartMine:1;
340 	short DoFlash:1;
341 	short DoGuided:1;
342 	short DoEarthShaker:1;
343 	short DoMercury:1;
344 	short Allow_marker_view:1;
345 	short AlwaysLighting:1;
346 	short DoAmmoRack:1;
347 	short DoConverter:1;
348 	short DoHeadlight:1;
349 	short DoHoming:1;
350 	short DoLaserUpgrade:1;
351 	short DoQuadLasers:1;
352 	short ShowAllNames:1;
353 	short BrightPlayers:1;
354 	short invul:1;
355 #else
356 	short DoSmartMine:1;
357 	short DoSpread:1;
358 	short DoProximity:1;
359 	short DoSuperLaser:1;
360 	short DoOmega:1;
361 	short DoPlasma:1;
362 	short DoVulcan:1;
363 	short DoGauss:1;
364 	short DoCloak:1;
365 	short DoInvulnerability:1;
366 	short DoAfterburner:1;
367 	short DoPhoenix:1;
368 	short DoHelix:1;
369 	short DoFusions:1;
370 	short DoSmarts:1;
371 	short DoMegas:1;
372 
373 	short bitfield_not_used2:1;
374 	short invul:1;
375 	short BrightPlayers:1;
376 	short ShowAllNames:1;
377 	short DoQuadLasers:1;
378 	short DoLaserUpgrade:1;
379 	short DoHoming:1;
380 	short DoHeadlight:1;
381 	short DoConverter:1;
382 	short DoAmmoRack:1;
383 	short AlwaysLighting:1;
384 	short Allow_marker_view:1;
385 	short DoMercury:1;
386 	short DoEarthShaker:1;
387 	short DoGuided:1;
388 	short DoFlash:1;
389 #endif
390 
391 	char    team_name[2][CALLSIGN_LEN+1];
392 	int     locations[MAX_PLAYERS];
393 	short   kills[MAX_PLAYERS][MAX_PLAYERS];
394 	ushort  segments_checksum;
395 	short   team_kills[2];
396 	short   killed[MAX_PLAYERS];
397 	short   player_kills[MAX_PLAYERS];
398 	int     KillGoal;
399 	fix     PlayTimeAllowed;
400 	fix     level_time;
401 	int     control_invul_time;
402 	int     monitor_vector;
403 	int     player_score[MAX_PLAYERS];
404 	ubyte   player_flags[MAX_PLAYERS];
405 	short   PacketsPerSec;
406 	ubyte   ShortPackets;
407 
408 } __pack__ netgame_info;
409 
410 extern struct netgame_info Netgame;
411 extern struct AllNetPlayers_info NetPlayers;
412 
413 int network_i_am_master(void);
414 void change_playernum_to(int new_pnum);
415 
416 //how to encode missiles & flares in weapon packets
417 #define MISSILE_ADJUST  100
418 #define FLARE_ADJUST    127
419 
420 
421 #endif
422