home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Issue 2 / Freelog_HS_3_Setp_Oct_Nov_2000_CD2.mdx / Arcade / Orbit / src / orbit.h < prev    next >
C/C++ Source or Header  |  1999-10-02  |  20KB  |  755 lines

  1. /*
  2.  
  3. ORBIT, a freeware space combat simulator
  4. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. #define VERSION "1.01"
  23.  
  24. /* At one point I needed these to keep VC++ from including it own
  25.    GL headers */
  26. /* #define __glu_h__    */
  27. /* #define __gl_h_    */
  28.  
  29. #include <stdio.h>
  30. #include <time.h>
  31. #include <math.h>
  32. #include <string.h>
  33. #include <sys/types.h>
  34.  
  35. #ifndef WIN32
  36. #include <stdlib.h>
  37. #endif
  38.  
  39. #ifdef WIN32
  40. #include <windows.h>
  41. #include <GL/gl.h>
  42. #include <GL/glu.h>
  43. #include </mesa/mesa-3.0/include/GL/glut.h>
  44. #include <winsock.h>
  45. #else
  46. #include <GL/gl.h>
  47. #include <GL/glu.h>
  48. #include <GL/glut.h>
  49. #endif
  50.  
  51. #ifdef ALLOCATE
  52. #define EXTERN
  53. #else
  54. #define EXTERN extern
  55. #endif
  56.  
  57. #ifdef WIN32
  58. #pragma warning(disable:4013)    /* blah() undefined; assuming extern returning int */
  59. #pragma warning(disable:4033)    /* blah() must return a value */
  60. #pragma warning(disable:4716)    /* blah() must return a value */
  61. #endif
  62.  
  63. /* THETA is rate of rotation in radians per second */
  64. #define THETA (1.6)
  65.  
  66. /* Maximum change in velocity, per second, at full throttle */
  67. #define DELTAV (0.2)
  68.  
  69. /* Coefficient of current velocity added to acceleration under warp speed */
  70. #define WARP_COEFF (0.2)
  71.  
  72. /* Throttle limits for arcade mode, in kps */
  73. #define MAX_THROTTLE (10000.0 / KM_TO_UNITS1)
  74. #define MAX_WARP_THROTTLE (1000000.0 / KM_TO_UNITS1)
  75.  
  76. #define SCREENWIDTH (640)
  77. #define SCREENHEIGHT (480)
  78.  
  79. void DrawScene(void);
  80. void Reshape(int, int);
  81. void MovePlayer();
  82. double Dist2();
  83. double rnd();
  84. double Time();
  85. double Theta();
  86. double Dotp();
  87. double Mag();
  88. double Mag2();
  89. void Log (char *fmt, ...);
  90. void Mprint (char *msg, ...);
  91. void Cprint (char *c, ...);
  92. void DoConnect (void);
  93. void DoChat (void);
  94. void DoDrop (void);
  95. void DoLoad (void);
  96. void DoName (void);
  97.  
  98. EXTERN    int ScreenWidth, ScreenHeight;
  99. EXTERN    double fov;
  100.  
  101. /* Stuff to remember about the player */
  102. #define FLIGHT_NEWTONIAN (0)
  103. #define FLIGHT_ARCADE (1)
  104. EXTERN    struct
  105. {
  106.     char name[64];        /* Player name */
  107.     char model[128];    /* Ship model (for multiplayer) */
  108.     double pos[3];        /* Player position */
  109.     double up[3];        /* Camera "up" vector */
  110.     double view[3];        /* Viewing direction */
  111.     double right[3];    /* Right-hand vector */
  112.  
  113.     double move_forward, move_backward,
  114.           move_up, move_down,
  115.           move_pitchleft, move_pitchright,
  116.           move_left, move_right; /* Motion */
  117.  
  118.     int flightmodel;    /* Newtonian or arcade */
  119.  
  120.     double vel[3];        /* Player's velocity */
  121.     double throttle;    /* Throttle for arcade mode */
  122.     int score;            /* Player's score */
  123.  
  124.     double shields;        /* Strenth of shields */
  125.     double maxshields;    /* Maximum shields */
  126.     int weapon;            /* Current weapon */
  127.     double msl_idle;    /* Weapon idle time */
  128.     int waypoint;        /* Selected waypoint */
  129.     double dead_timer;    /* Time to die */
  130.     int still;            /* Not changing orientation */
  131.     int viewlock;        /* True if view locked on something */
  132. } player;
  133.  
  134. /* Clipping planes */
  135. EXTERN    double clipnear;
  136. EXTERN    double clipfar;
  137.  
  138. #define DEAD_TIME    (5.0)
  139.  
  140. EXTERN    int vulnerable;    /* If player can be killed */
  141.  
  142. EXTERN    int joy_available;    /* True if we have a joystick */
  143. /*
  144.  *  Joystick values:
  145.  *
  146.  *  x,y - stick position
  147.  *  r   - stick twist
  148.  *  z   - throttle position
  149.  */
  150. EXTERN    double joy_x, joy_xmin, joy_xmax,
  151.     joy_y, joy_ymin, joy_ymax,
  152.     joy_r, joy_rmin, joy_rmax,
  153.     joy_z, joy_zmin, joy_zmax;
  154. EXTERN    int joy_buttons;        /* State of joystick buttons */
  155. EXTERN    int joy_throttle;        /* True to use joystick throttle */
  156. EXTERN    double deadzone;            /* Joystick dead zone */
  157.  
  158. #define DEADZONE (0.1)    /* Joystick dead zone */
  159.  
  160. EXTERN    int mouse_x, mouse_y;    /* Stuff for mouse */
  161. EXTERN    int last_mouse_x, last_mouse_y;
  162.  
  163. /* Timer stuff */
  164. #define MAXDELTAT (0.1)
  165. EXTERN    long ticks_per_sec;
  166. EXTERN    double deltaT;
  167. EXTERN    double absT;
  168. EXTERN    double fps;
  169.  
  170. #ifdef WIN32
  171. EXTERN    _int64 last_ticks;
  172. #else
  173. EXTERN    int last_ticks;
  174. #endif
  175.  
  176. /* Stuff for the stars */
  177. #define NSTARS (2000)
  178. EXTERN    struct
  179. {
  180.     double x,y,z;    /* Star coords */
  181.     double mag;        /* Star magnitude */
  182.     double bright;    /* Point brightness */
  183.     double bright2;    /* Brightness for sparse starfield */
  184. } star[NSTARS];
  185.  
  186. EXTERN    int star_list;        /* Starfield display lists */
  187. EXTERN    int star_list_sparse;
  188. EXTERN    int star_list_dense;
  189. EXTERN    int starfield;    /* Display starfield? */
  190.  
  191. EXTERN    int paused;        /* True if game paused */
  192.  
  193. /* Whether or not to display the HUD */
  194. EXTERN    int drawhud;
  195.  
  196. /* Whether or not to show the frame rate */
  197. EXTERN    int showfps;
  198.  
  199. /* Stuff for the message console */
  200. #define CONSLINES (10)
  201. #define CONSBUF (128)
  202. #define CONSAGE (3.0)
  203. #define CONSHEIGHT (10)
  204. EXTERN    struct
  205. {
  206.     double age[CONSLINES];    /* How long each line has been on screen */
  207.     int next;        /* index of next line to use */
  208.     char buf[CONSLINES][CONSBUF];    /* messages */
  209. } console;
  210.  
  211. /* Gravity stuff */
  212. EXTERN    int gravity;    /* Is gravity on or off? */
  213. #define G (0.025)
  214. #define RMIN (2.0)
  215.  
  216. /* Allow full stop? */
  217. EXTERN    int fullstop;    /* True if full stop allowed */
  218.  
  219. /* Regular warp or super warp engines? */
  220. EXTERN    int superwarp;
  221.  
  222. /* Stuff for missiles */
  223. #define NMSLS (32)
  224. #define MSL_EXPIRE (5.0)
  225. #define MSL_IDLE (0.2)    /* Min seconds between missiles */
  226. #define TARGET_MSL_IDLE (2.0)    /* Same for targets */
  227. #define MSL_MIN_AGE (0.1)    /* Time before msl can hit something */
  228. #define MSL_VEL (0.5)
  229. EXTERN    struct
  230. {
  231.     double pos[3];    /* Missile position */
  232.     double vel[3];    /* Missile velocity */
  233.     double age;        /* Missile age (0 == not in use) */
  234.     int friendly;    /* True if player launced missile */
  235.     int weapon;        /* What type of weapon this is */
  236.     int owner;        /* Who owns this missile (-1 if player) */
  237. } msl[NMSLS];
  238.  
  239. /* Space junk */
  240. EXTERN    int junk;            /* True to draw space junk */
  241.  
  242. /* Stuff for explosions */
  243. #define NBOOMS (32)
  244. #define BOOM_TIME (1.0)    /* Length of explosion in seconds */
  245. EXTERN    int palette_flash;    /* True to flash whole screen */
  246. EXTERN    struct
  247. {
  248.     double pos[3];    /* Explosion position */
  249.     double age;        /* Explosion age (0 == not in use) */
  250.     int light;        /* Index of corresponding light[] entry */
  251.     double angle;    /* Angle to rotate boom */
  252.     double size;    /* Size of this boom */
  253. } boom[NBOOMS];
  254.  
  255. #define X .525731112119133606
  256. #define Z .850650808352039932
  257.  
  258. #ifdef ALLOCATE
  259. double icos_data[12][3] =
  260. {
  261.   {-X, 0, Z}, {X, 0, Z}, {-X, 0, -Z}, {X, 0, -Z}, {0, Z, X}, {0, Z, -X},
  262.   {0, -Z, X}, {0, -Z, -X}, {Z, X, 0}, {-Z, X, 0}, {Z, -X, 0}, {-Z, -X, 0}
  263. };
  264. #else
  265. extern double icos_data[12][3];
  266. #endif
  267.  
  268. #ifdef ALLOCATE
  269. int icos_index[20][3] =
  270. {
  271.   {0, 4, 1}, {0, 9, 4}, {9, 5, 4}, {4, 5, 8}, {4, 8, 1},
  272.   {8, 10, 1}, {8, 3, 10}, {5, 3, 8}, {5, 2, 3}, {2, 7, 3},
  273.   {7, 10, 3}, {7, 6, 10}, {7, 11, 6}, {11, 0, 6}, {0, 1, 6},
  274.   {6, 1, 10}, {9, 0, 11}, {9, 11, 2}, {9, 2, 5}, {7, 2, 11}
  275. };
  276. #else
  277. extern int icos_index[20][3];
  278. #endif
  279.  
  280. EXTERN    double boom_data[12][3];
  281.  
  282. #ifdef ALLOCATE
  283. double boom_color[12][4] =
  284. {
  285.   {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0},
  286.   {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0},
  287.   {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0},
  288.   {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0}, {0.75, 0.75, 0.0, 1.0}
  289. };
  290. #else
  291. extern double boom_color[12][4];
  292. #endif
  293.  
  294. /* Sound stuff */
  295. EXTERN    int sound;        /* True for sound effects */
  296.  
  297. /* Constants */
  298. enum sounds {
  299.     SOUND_FIRE,
  300.     SOUND_BOOM,
  301.     SOUND_COMM,
  302.     NSOUNDS
  303. };
  304.  
  305. /* Functions */
  306. int InitSound (void);
  307. int PlayAudio (enum sounds);
  308. void FinishSound (void);
  309.  
  310. EXTERN    int show_names;    /* True to show names of things */
  311.  
  312. /* Lights stuff */
  313. #define NLIGHTS GL_MAX_LIGHTS
  314.  
  315. EXTERN    struct
  316. {
  317.     float pos[4];    /* Light position */
  318.     float color[3];    /* Light color */
  319.     double age;        /* Age of light (0 == not in use) */
  320.     int gl_num;        /* GL number of light */
  321. } light[NLIGHTS];
  322.  
  323. /* Target stuff */
  324. #define NTARGETS (32)
  325. EXTERN    struct
  326. {
  327.     double pos[3];        /* Target position */
  328.     double vel[3];        /* Target velocity */
  329.     double view[3];        /* Viewing direction */
  330.     double up[3];        /* Up vector */
  331.     double right[3];    /* Right vector */
  332.     double age;            /* Target age (0 == unused) */
  333.     double range2;        /* Distance from player */
  334.     double move_forward, move_backward,
  335.           move_up, move_down,
  336.           move_pitchleft, move_pitchright,
  337.           move_left, move_right; /* Motion */
  338.     double msl_idle;    /* How long laucher has been idle */
  339.     char name[32];        /* Target name */
  340.     int list;            /* Target display list */
  341.     int score;            /* Points for destroying this target */
  342.     int model;            /* Index of target's model */
  343.     int strategy;        /* This target's strategy for ThinkTarget() */
  344.     int hidden;            /* True if hidden */
  345.     int invisible;            /* True if invisible */
  346.     int friendly;        /* True if on our side */
  347.     double shields;        /* Shield strength */
  348.     double maxshields;    /* Maximum shields */
  349.     double shieldregen;    /* How fast shields regenerate */
  350.     double turnrate;    /* How fast it can turn */
  351.     double maxvel;        /* How fast it can accelerate */
  352.     int weapon;            /* Current weapon */
  353. } target[NTARGETS];
  354.  
  355. #define TARGDIST (0.02)
  356. #define TARGDIST2 (TARGDIST * TARGDIST)
  357. #define MINFIREDIST (1.0 / KM_TO_UNITS1)
  358. #define MINFIREDIST2 (MINFIREDIST * MINFIREDIST)
  359. #define MAXFIREDIST (3000.0 / KM_TO_UNITS1)
  360. #define MAXFIREDIST2 (MAXFIREDIST * MAXFIREDIST)
  361. #define TARG_MAXRANGE (50000.0 / KM_TO_UNITS1)
  362. #define TARG_MAXRANGE2 (TARG_MAXRANGE * TARG_MAXRANGE)
  363.  
  364. /* Radar stuff */
  365. EXTERN    double radarR, radarCOS, radarSIN;
  366. EXTERN    struct
  367. {
  368.     int center[2];        /* Center of radar on screen, in pixels */
  369.     double fcenter[2];    /* Floating version */
  370.     int radius;            /* Radius of screen, in pixels */
  371.     double fradius;        /* Floating version */
  372.     int list;            /* Display list */
  373. } radar;
  374.  
  375. /* Other HUD stuff */
  376. EXTERN    struct
  377. {
  378.     double throt_min[2];    /* Coords of throttle display */
  379.     double throt_mid[2];
  380.     double throt_max[2];
  381.     double targ_name[2];    /* Coords of target name */
  382.     double targ_range[2];    /* Target range */
  383.     double vel[2];            /* Player velocity */
  384.     double shields_min[2];    /* Player shields */
  385.     double shields_max[2];
  386.     double weapon[2];        /* Weapon name */
  387.     double targshields_min[2]; /* Target shields */
  388.     double targshields_max[2];
  389.     double waypoint[2];        /* Current waypoint */
  390. } hud;
  391.  
  392. /* Shield stuff */
  393. #define SHIELD_REGEN (5.0)
  394.  
  395. /* Texture stuff */
  396. EXTERN    GLubyte planet_tex[256][256][3];    /* Planet texture */
  397. EXTERN    int planet_list;
  398.  
  399. /* Screen shot stuff */
  400. EXTERN    int screen_shot_num;
  401.  
  402. /* Planet stuff */
  403. #define NPLANETS (32)
  404. EXTERN    struct
  405. {
  406.     int hidden;            /* Don't draw */
  407.     double dist;        /* Distance from primary */
  408.     double pos[3];        /* Planet position */
  409.     double theta;        /* Solar angle */
  410.     double radius;        /* Planet size */
  411.     double oblicity;    /* Oblicity (inclination from orbital plane) */
  412.     double radius2;        /* Radius squared */
  413.     double range2;        /* Distance^2 from player */
  414.     double absrange2;    /* Absolute range (ignoring radius) */
  415.     double mass;        /* Mass, for gravity calculation */
  416.     float color[3];        /* Average color */
  417.     int texid;            /* Texture id */
  418.     GLubyte tex[256][256][3];    /* Texture */
  419.     char texfname[32];    /* Name of texture file */
  420.     char name[32];        /* Planet name */
  421.     int is_moon;        /* True if this is a moon */
  422.     int primary;        /* Index of primary if moon */
  423.     int list20;            /* Display lists */
  424.     int list80;
  425.     int list320;
  426.     int orbitlist;        /* Display list for orbit */
  427.     double angvel;        /* Angular velocity in degrees per second */
  428.     int custom;            /* True if customized */
  429. } planet[NPLANETS];
  430.  
  431. #define ORBIT_SECTORS (360)
  432.  
  433. /* Planet detail levels */
  434. EXTERN    int slices0, stacks0,
  435.             slices1, stacks1,
  436.             slices2, stacks2;
  437.  
  438. EXTERN    int textures;    /* True to draw textures */
  439.  
  440. EXTERN    int realdistances;    /* True for correct planet distances */
  441.  
  442. EXTERN    int draw_orbits;    /* True to draw orbits */
  443. EXTERN    int orbit;            /* True to make planets orbit */
  444. EXTERN    double compression;    /* Time compression */
  445.  
  446. EXTERN    int first_vertex;        /* For texture fixing */
  447. EXTERN    double maxtdiff;
  448.  
  449. /* Unit conversions */
  450. #define KM_TO_UNITS1    (6000.0)    /* Radii */
  451. #define KM_TO_UNITS2    (6000.0 / 1000000.0)    /* Distances */
  452.  
  453. /* Model stuff */
  454. #define NMODELS (32)
  455. EXTERN    struct
  456. {
  457.     int in_use;            /* True if in use */
  458.     char name[32];        /* Model name */
  459.     int list;            /* Display list */
  460.     double lobound[3];
  461.     double hibound[3];    /* Coords of bounding box */
  462.     double radius;
  463.     double radius2;        /* Radius of bounding sphere */
  464. } model[NMODELS];
  465.  
  466. /* Mission stuff */
  467. EXTERN    struct
  468. {
  469.     double cursor[3];
  470.     double player[3];
  471.     char briefing[4096];
  472.     char fn[128];
  473.     int verbose;
  474. } mission;
  475.  
  476. /* Strategies */
  477. #define STRAT_DONOTHING    (0)
  478. #define STRAT_SIT1 (1)
  479. #define STRAT_SIT2 (2)
  480. #define STRAT_SIT3 (3)
  481. #define STRAT_SIT4 (4)
  482. #define STRAT_HUNT1 (5)
  483. #define STRAT_HUNT2 (6)
  484. #define STRAT_HUNT3 (7)
  485. #define STRAT_HUNT4 (8)
  486.  
  487. /* Message stuff (messages in center of screen) */
  488. EXTERN    struct
  489. {
  490.     char text[4096];    /* Message text */
  491.     int len;            /* Length in pixels */
  492.     double age;            /* Age in seconds */
  493. } message;
  494.  
  495. /* Max time to keep message on screen */
  496. #define MSG_MAXAGE (30)
  497.  
  498. /* Rings stuff */
  499. #define NRINGS (4)
  500. #define MAX_RING_RANGE (200.0 * 200.0)
  501. #define RING_SECTORS (32)
  502. EXTERN    struct
  503. {
  504.     int primary;    /* Which planet */
  505.     int list;        /* Display list */
  506.     int texid;        /* Texture id */
  507.     GLubyte tex[256][8][4]; /* Texture */
  508.     double r1, r2;    /* Inner, outer radii */
  509.     char fn[64];    /* Texture file name */
  510. } ring[NRINGS];
  511.  
  512. EXTERN    int rings;        /* True to draw rings */
  513. EXTERN    int ring_sectors; /* Sectors per ring */
  514.  
  515. /* Event stuff */
  516. #define NEVENTS (32)
  517. #define ACTIONS_PER_EVENT (64)
  518. EXTERN    struct
  519. {
  520.     char name[32];    /* Event name */
  521.     int pending;    /* True if hasn't happened yet */
  522.     int enabled;    /* True if enabled */
  523.     int trigger;    /* Event type */
  524.     int ivalue;        /* Event values */
  525.     double fvalue;
  526.     char *cvalue;
  527.     double pos[3];    /* Event position */
  528.  
  529.     /* Actions */
  530.     struct
  531.     {
  532.         int active;
  533.         int action;        /* Event actions */
  534.         int ivalue;
  535.         double fvalue;
  536.         char *cvalue;
  537.     } action[ACTIONS_PER_EVENT];
  538. } event[NEVENTS];
  539.  
  540. /* Event triggers */
  541. #define EVENT_NULL (0)
  542. #define EVENT_APPROACH (1)
  543. #define EVENT_DESTROY (2)
  544. #define EVENT_SCORE (3)
  545. #define EVENT_ALARM (4)
  546. #define EVENT_DEPART (5)
  547. #define EVENT_TRUE (6)
  548. #define EVENT_STOPNEAR (7)
  549. #define EVENT_SHIELDS (8)
  550.  
  551. /* Event actions */
  552. #define EVENT_MESSAGE (10)
  553. #define EVENT_HIDE (11)
  554. #define EVENT_UNHIDE (12)
  555. #define EVENT_ENABLE (13)
  556. #define EVENT_DISABLE (14)
  557. #define EVENT_LOADMISSION (15)
  558. #define EVENT_STOP (16)
  559. #define EVENT_BOOM (17)
  560. #define EVENT_FLASH (18)
  561. #define EVENT_MOVEOBJECT (19)
  562. #define EVENT_MOVEPLAYER (20)
  563. #define EVENT_MOVEPLANET (21)
  564. #define EVENT_HIDEPLANET (22)
  565. #define EVENT_UNHIDEPLANET (23)
  566. #define EVENT_BETRAY (24)
  567.  
  568. /* Target lock stuff */
  569. #define LOCK_ENEMY (0)
  570. #define LOCK_FRIENDLY (1)
  571. #define LOCK_PLANET (2)
  572. EXTERN    struct
  573. {
  574.     int target;        /* Locked target, -1 if none */
  575.     int type;        /* Target type */
  576. } lock;
  577.  
  578. /* Weapons stuff */
  579. #define NWEAPONS (10)
  580. EXTERN    struct
  581. {
  582.     char name[32];    /* Name of weapon */
  583.     double yield;    /* How much damage it does */
  584.     double speed;    /* How fast it goes */
  585.     double idle;    /* Time between shots, in seconds */
  586.     double expire;    /* How long till it dissipates */
  587.     int renderer;    /* How to draw */
  588.     float color[3];    /* Color */
  589.     double range2;    /* Range of weapon squared */
  590. } weapon[NWEAPONS];
  591. #define NPLAYER_WEAPONS (4)
  592.  
  593. EXTERN    int warpspeed;    /* True if using warp engines */
  594.  
  595. /* Mouse stuff */
  596. EXTERN    struct
  597. {
  598.     int left, right, up, down;
  599.     int x, y;
  600.     int flipx;
  601.     int flipy;
  602. } mouse;
  603. EXTERN    int mouse_control;
  604.  
  605. /* Video mode stuff */
  606. EXTERN    int fullscreen;        /* To use glutFullScreen() */
  607. EXTERN    char gamemode[64];    /* To use glutGameMode() */
  608.  
  609. /* Game state stuff */
  610. #define STATE_INIT (1)
  611. #define STATE_NORMAL (2)
  612. #define STATE_DEAD1 (3)
  613. #define STATE_DEAD2 (4)
  614. #define STATE_LOADGAME (5)
  615. #define STATE_GETTEXT (6)
  616. EXTERN    int state;        /* Game state */
  617.  
  618. /* Stuff for loads and saves */
  619. #define NSAVES (10)
  620. EXTERN    struct
  621. {
  622.     char    fn[128];    /* Mission file name */
  623.     int    time;    /* Time stamp */
  624. } save[NSAVES];
  625. EXTERN    int nsaves;
  626.  
  627. /* Waypoints */
  628. #define NWAYPOINTS (32)
  629. EXTERN    struct
  630. {
  631.     double pos[3];        /* Waypoint location */
  632. } waypoint[NWAYPOINTS];
  633. EXTERN    int    nwaypoints;    /* Number of active waypoints */
  634.  
  635. /* 
  636.  *  Network stuff
  637.  */
  638.  
  639. #ifndef WIN32
  640. #define SOCKET int
  641. #endif
  642.  
  643. /* Undef this to use ASCII packets only.  Good if the two machines
  644.    don't use IEEE floats */
  645. #define BINARYPACKETS
  646.  
  647. #define    ORBIT_PORT    (2061)
  648.  
  649. /* Timing stuff */
  650. #define MAXCLIENTIDLE    (60.0)
  651. #define MAXSERVERIDLE    (120.0)
  652. #define PINGINTERVAL    (20.0)
  653. #define CLIENTPOSINTERVAL    (0.33)
  654. #define ROLLCALLINTERVAL    (30.0)
  655.  
  656. #define POSNINTERVALSMALL    (0.33)
  657. #define POSNINTERVALMEDIUM    (0.66)
  658. #define POSNINTERVALLARGE    (1.0)
  659. #define PINGFAST    (100.0)
  660. #define PINGSLOW    (400.0)
  661.  
  662. EXTERN    int    am_server;    /* True if I'm a server */
  663. EXTERN    int    am_client;    /* True if I'm a client */
  664.  
  665. void SendASCIIPacket (SOCKET socket, char *fmt, ...);
  666. void SendBinaryPacket (SOCKET socket, char *fmt, ...);
  667.  
  668. /* Stuff to remember about each client */
  669. #define NCLIENTS (16)
  670. EXTERN struct
  671. {
  672.     int active;    /* True if the client is active */
  673.     int is_me;    /* True if this client is me */
  674.     int target;    /* Index of target structure for this client */
  675.     SOCKET socket;    /* This client's socket */
  676.     double ping;    /* Ping time for this client */
  677.     double posninterval;    /* How often to send position reports to this client */
  678.     struct
  679.     {
  680.         double idle;    /* How long since we heard from this client */
  681.         double ping;    /* How long since we pinged this client */
  682.         double posn[NCLIENTS];    /* How long since we reported this client's
  683.                                 position to each other client */
  684.         double rollcall;    /* Time since we sent a roll call to this client */
  685.     } timer;
  686.     char pkt[1024];    /* Packet currently being received */
  687.     int ptr;    /* Index of next byte in pkt */
  688.     int state;    /* Binary packet state */
  689.     int remain;    /* Bytes remaining in this binary packet */
  690.     int frags;    /* Number of kills */
  691.     char ip[32];    /* IP address of client */
  692. } client[NCLIENTS];
  693.  
  694. /* Some server stuff */
  695. EXTERN struct
  696. {
  697.     SOCKET listening_socket;    /* Socket server listens on */
  698.     int client;            /* Number of server's client */
  699.     int port;            /* Port to listen on */
  700.     char ip[32];        /* My IP address */
  701. } server;
  702.  
  703. /* Network game flags */
  704. #define FLAG_GRAVITY (0x01)
  705. #define FLAG_FLIGHTMODEL (0x02)
  706. #define FLAG_FULLSTOP (0x04)
  707. #define FLAG_REALDISTANCES (0x08)
  708. #define FLAG_ORBIT (0x10)
  709.  
  710. EXTERN struct
  711. {
  712.     SOCKET socket;        /* Socket client uses to talk to server */
  713.     char pkt[1024];        /* Packet being received */
  714.     int ptr;        /* Next byte in pkt */
  715.     int state;        /* Binary packet state */
  716.     int remain;        /* Bytes remaining in this binary packet */
  717.     int client;        /* Our client number */
  718.     int urgent;        /* We have an urgent position report */
  719.     struct
  720.     {
  721.         double server;    /* Time since we heard from server */
  722.         double pos;    /* Time since we last reported position */
  723.     } timer;
  724. } clientme;
  725.  
  726. /* States for binary packets */
  727. #define NETSTATE_MAGIC (1)    /* Waiting for Magic byte */
  728. #define NETSTATE_SIZE (2)    /* Waiting for size byte */
  729. #define NETSTATE_PACKET (3)    /* Reading packet */
  730.  
  731. #define NET_MAGIC (0x56)    /* Magic start-of-packet byte */
  732.  
  733. /* Binary packet types.  HIGH BIT MUST BE SET! */
  734. #define PKT_POSS (0x80)        /* Short position */
  735. #define PKT_POSL (0x81)        /* Long position */
  736. #define PKT_POSU (0x82)        /* Urgent position */
  737. #define PKT_POSN (0x83)        /* Regular position */
  738. #define PKT_PLAN (0x84)        /* Planet position */
  739. #define PKT_VCNT (0x85)        /* Vacancy report */
  740. #define PKT_PING (0x86)        /* Ping to get latency */
  741.  
  742. EXTERN    double recv_bps, xmit_bps;    /* Receive, transmit rates */
  743. EXTERN    int recv_bytes, xmit_bytes;    /* Bytes received/sent */
  744.  
  745. /* Stuff for reading in text */
  746. #define TEXTSIZE (128)
  747. EXTERN struct
  748. {
  749.     int yes;            /* True if typing */
  750.     char buf[TEXTSIZE];    /* Buffer */
  751.     int index;            /* Index into buffer */
  752.     char prompt[32];    /* Prompt */
  753.     void (*func)(void);        /* Function to call when done */
  754. } text;
  755.