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