integrate with dm
[unix-history] / usr / src / games / sail / extern.h
index eabeff1..33fb604 100644 (file)
@@ -1,27 +1,55 @@
 /*
 /*
- * @(#)extern.h        1.5 83/07/20
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)extern.h    5.1 (Berkeley) %G%
  */
  */
+
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
+#include <setjmp.h>
 #include "machdep.h"
 
 #include "machdep.h"
 
+       /* program mode */
+int mode;
+jmp_buf restart;
+#define MODE_PLAYER    1
+#define MODE_DRIVER    2
+#define MODE_LOGGER    3
+
+       /* command line flags */
+char debug;                            /* -D */
+char randomize;                                /* -x, give first available ship */
+char longfmt;                          /* -l, print score in long format */
+char nobells;                          /* -b, don't ring bell before Signal */
+
+       /* other initial modes */
+char issetuid;                         /* running setuid */
+
 #define die()          ((rand() >> 3) % 6 + 1)
 #define sqr(a)         ((a) * (a))
 #define abs(a)         ((a) > 0 ? (a) : -(a))
 #define min(a,b)       ((a) < (b) ? (a) : (b))
 
 #define die()          ((rand() >> 3) % 6 + 1)
 #define sqr(a)         ((a) * (a))
 #define abs(a)         ((a) > 0 ? (a) : -(a))
 #define min(a,b)       ((a) < (b) ? (a) : (b))
 
-#define grappled(a)    Snagged(a, 1)
-#define fouled(a)      Snagged(a, 0)
-#define snagged(a)     (Snagged(a, 0) || Snagged(a, 1))
-#define grappled2(a,b) Snagged2(a, b, 1, 0)
-#define fouled2(a,b)   Snagged2(a, b, 0, 0)
-#define snagged2(a,b)  (Snagged2(a, b, 0, 0) || Snagged2(a, b, 1, 0))
-#define Xgrappled2(a,b)        Snagged2(a, b, 1, 1)
-#define Xfouled2(a,b)  Snagged2(a, b, 0, 1)
-#define Xsnagged2(a,b) (Snagged2(a, b, 0, 1) || Snagged2(a, b, 1, 1))
-
-#define sterncolour(sp)        ((sp)->file->stern+'0'-((sp)->file->captured?16:0))
+#define grappled(a)    ((a)->file->ngrap)
+#define fouled(a)      ((a)->file->nfoul)
+#define snagged(a)     (grappled(a) + fouled(a))
+
+#define grappled2(a, b)        ((a)->file->grap[(b)->file->index].sn_count)
+#define fouled2(a, b)  ((a)->file->foul[(b)->file->index].sn_count)
+#define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
+
+#define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
+#define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
+#define Xsnagged2(a, b)        (Xgrappled2(a, b) + Xfouled2(a, b))
+
+#define cleangrapple(a, b, c)  Cleansnag(a, b, c, 1)
+#define cleanfoul(a, b, c)     Cleansnag(a, b, c, 2)
+#define cleansnag(a, b, c)     Cleansnag(a, b, c, 3)
+
+#define sterncolour(sp)        ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
 #define sternrow(sp)   ((sp)->file->row + dr[(sp)->file->dir])
 #define sterncol(sp)   ((sp)->file->col + dc[(sp)->file->dir])
 
 #define sternrow(sp)   ((sp)->file->row + dr[(sp)->file->dir])
 #define sterncol(sp)   ((sp)->file->col + dc[(sp)->file->dir])
 
 #define W_GUNL         10
 #define W_GUNR         11
 #define W_HULL         12
 #define W_GUNL         10
 #define W_GUNR         11
 #define W_HULL         12
-#define W_LAST         13
+#define W_MOVE         13
 #define W_OBP          14
 #define W_PCREW                15
 #define W_OBP          14
 #define W_PCREW                15
-#define W_PEOPLE       16
+#define W_UNFOUL       16
 #define W_POINTS       17
 #define W_QUAL         18
 #define W_POINTS       17
 #define W_QUAL         18
-/* 19 */
+#define W_UNGRAP       19
 #define W_RIGG         20
 #define W_RIGG         20
-#define W_SHIPCOL      21
-#define W_SHIPDIR      22
-#define W_SHIPROW      23
+#define W_COL          21
+#define W_DIR          22
+#define W_ROW          23
 #define W_SIGNAL       24
 #define W_SINK         25
 #define W_STRUCK       26
 #define W_TA           27
 #define W_SIGNAL       24
 #define W_SINK         25
 #define W_STRUCK       26
 #define W_TA           27
-#define W_TIME         28
+#define W_ALIVE                28
 #define W_TURN         29
 #define W_WIND         30
 #define W_FS           31
 #define W_TURN         29
 #define W_WIND         30
 #define W_FS           31
 #define W_RIG2         34
 #define W_RIG3         35
 #define W_RIG4         36
 #define W_RIG2         34
 #define W_RIG3         35
 #define W_RIG4         36
+#define W_BEGIN                37
+#define W_END          38
+#define W_DDEAD                39
 
 
+#define NLOG 10
 struct logs {
        char l_name[20];
        int l_uid;
 struct logs {
        char l_name[20];
        int l_uid;
@@ -95,100 +127,103 @@ struct logs {
 };
 
 struct BP {
 };
 
 struct BP {
-       int turnsent;
+       short turnsent;
        struct ship *toship;
        struct ship *toship;
-       int mensent;
+       short mensent;
 };
 
 struct snag {
 };
 
 struct snag {
-       int turnfoul;
-       struct ship *toship;
+       short sn_count;
+       short sn_turn;
 };
 
 };
 
-#define NSCENE 31
+#define NSCENE nscene
 #define NSHIP  10
 #define NBP    3
 
 #define NSHIP  10
 #define NBP    3
 
-#define NNATION        5
+#define NNATION        8
 #define N_A    0
 #define N_B    1
 #define N_S    2
 #define N_F    3
 #define N_J    4
 #define N_A    0
 #define N_B    1
 #define N_S    2
 #define N_F    3
 #define N_J    4
+#define N_D    5
+#define N_K    6
+#define N_O    7
 
 struct File {
 
 struct File {
+       int index;
        char captain[20];               /* 0 */
        char captain[20];               /* 0 */
-       int points;                     /* 20 */
-       int loadL;                      /* 22 */
-       int loadR;                      /* 24 */
-       int readyL;                     /* 26 */
-       int readyR;                     /* 28 */
+       short points;                   /* 20 */
+       char loadL;                     /* 22 */
+       char loadR;                     /* 24 */
+       char readyL;                    /* 26 */
+       char readyR;                    /* 28 */
        struct BP OBP[NBP];             /* 30 */
        struct BP DBP[NBP];             /* 48 */
        struct BP OBP[NBP];             /* 30 */
        struct BP DBP[NBP];             /* 48 */
-       int struck;                     /* 66 */
+       char struck;                    /* 66 */
        struct ship *captured;          /* 68 */
        struct ship *captured;          /* 68 */
-       int pcrew;                      /* 70 */
-       char last[10];                  /* 72 */
-       int drift;                      /* 82 */
-       struct snag fouls[NSHIP];       /* 84 */
-       struct snag grapples[NSHIP];    /* 124 */
-       char signal[60];                /* 164 */
-       int RH;                         /* 224 */
-       int RG;                         /* 226 */
-       int RR;                         /* 228 */
-       int FS;                         /* 230 */
-       int explode;                    /* 232 */
-       int sink;                       /* 234 */
-       int dir;
-       int col;
-       int row;
-       int loadwith;
-       int stern;
+       short pcrew;                    /* 70 */
+       char movebuf[10];               /* 72 */
+       char drift;                     /* 82 */
+       short nfoul;
+       short ngrap;
+       struct snag foul[NSHIP];        /* 84 */
+       struct snag grap[NSHIP];        /* 124 */
+       char RH;                        /* 224 */
+       char RG;                        /* 226 */
+       char RR;                        /* 228 */
+       char FS;                        /* 230 */
+       char explode;                   /* 232 */
+       char sink;                      /* 234 */
+       char dir;
+       short col;
+       short row;
+       char loadwith;
+       char stern;
 };
 
 struct ship {
        char *shipname;                 /* 0 */
        struct shipspecs *specs;        /* 2 */
 };
 
 struct ship {
        char *shipname;                 /* 0 */
        struct shipspecs *specs;        /* 2 */
-       int nationality;                /* 4 */
-       int shiprow;                    /* 6 */
-       int shipcol;                    /* 8 */
-       int shipdir;                    /* 10 */
+       char nationality;               /* 4 */
+       short shiprow;                  /* 6 */
+       short shipcol;                  /* 8 */
+       char shipdir;                   /* 10 */
        struct File *file;              /* 12 */
 };
 
 struct scenario {
        struct File *file;              /* 12 */
 };
 
 struct scenario {
-       int winddir;                    /* 0 */
-       int windspeed;                  /* 2 */
-       int windchange;                 /* 4 */
-       int turn;                       /* 6 */
-       int people;                     /* 8 */
-       int time;                       /* 10 */
-       int vessels;                    /* 12 */
+       char winddir;                   /* 0 */
+       char windspeed;                 /* 2 */
+       char windchange;                /* 4 */
+       char vessels;                   /* 12 */
        char *name;                     /* 14 */
        struct ship ship[NSHIP];        /* 16 */
 };
        char *name;                     /* 14 */
        struct ship ship[NSHIP];        /* 16 */
 };
-struct scenario scene[NSCENE];
+struct scenario scene[];
+int nscene;
 
 struct shipspecs {
 
 struct shipspecs {
-       int bs;
-       int fs;
-       int ta;
-       int guns;
-       int class;
-       int hull;
-       int qual;
-       int crew1;
-       int crew2;
-       int crew3;
-       int gunL;
-       int gunR;
-       int carL;
-       int carR;
-       int rig1;
-       int rig2;
-       int rig3;
-       int rig4;
-       int pts;
+       char bs;
+       char fs;
+       char ta;
+       short guns;
+       char class;
+       char hull;
+       char qual;
+       char crew1;
+       char crew2;
+       char crew3;
+       char gunL;
+       char gunR;
+       char carL;
+       char carR;
+       char rig1;
+       char rig2;
+       char rig3;
+       char rig4;
+       short pts;
 };
 struct shipspecs specs[];
 
 };
 struct shipspecs specs[];
 
@@ -199,25 +234,21 @@ struct ship *ls;          /* &cc->ship[cc->vessels] */
 #define foreachship(sp)        for ((sp) = cc->ship; (sp) < ls; (sp)++)
 
 struct windeffects {
 #define foreachship(sp)        for ((sp) = cc->ship; (sp) < ls; (sp)++)
 
 struct windeffects {
-       int A, B, C, D;
+       char A, B, C, D;
 };
 struct windeffects WET[7][6];
 
 struct Tables {
 };
 struct windeffects WET[7][6];
 
 struct Tables {
-       int H, G, C, R;
+       char H, G, C, R;
 };
 struct Tables RigTable[11][6];
 struct Tables HullTable[11][6];
 
 };
 struct Tables RigTable[11][6];
 struct Tables HullTable[11][6];
 
-int AMMO[9][4];
-
-int HDT[9][10];
-
-int HDTrake[9][10];
-
-int QUAL[9][5];
-
-int MT[9][3];
+char AMMO[9][4];
+char HDT[9][10];
+char HDTrake[9][10];
+char QUAL[9][5];
+char MT[9][3];
 
 char *countryname[];
 char *classname[];
 
 char *countryname[];
 char *classname[];
@@ -225,15 +256,17 @@ char *directionname[];
 char *qualname[];
 char loadname[];
 
 char *qualname[];
 char loadname[];
 
-int rangeofshot[];
+char rangeofshot[];
 
 char dr[], dc[];
 
 
 char dr[], dc[];
 
-long lastsync;
-int winddir, windspeed, turn;
+int winddir;
+int windspeed;
+int turn;
 int game;
 int game;
-char Outbuf[BUFSIZE];
-FILE *syncfile;
+int alive;
+int people;
+char hasdriver;
 
 char *info();
 char *quality();
 
 char *info();
 char *quality();
@@ -242,6 +275,7 @@ char *saywhat();
 struct ship *closestenemy();
 
 char *calloc();
 struct ship *closestenemy();
 
 char *calloc();
+char *rindex();
 char *strcpy();
 char *strcat();
 char *strncpy();
 char *strcpy();
 char *strcat();
 char *strncpy();