Subversion Repositories eduke32

Rev

Rev 8459 | Rev 8471 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8459 Rev 8468
1
// Ken Silverman's official web site: "http://www.advsys.net/ken"
1
// Ken Silverman's official web site: "http://www.advsys.net/ken"
2
// See the included license file "BUILDLIC.TXT" for license info.
2
// See the included license file "BUILDLIC.TXT" for license info.
3
//
3
//
4
// This file has been modified from Ken Silverman's original release
4
// This file has been modified from Ken Silverman's original release
5
// by Jonathon Fowler (jf@jonof.id.au)
5
// by Jonathon Fowler (jf@jonof.id.au)
6
6
7
#include "compat.h"
7
#include "compat.h"
8
#include "build.h"
8
#include "build.h"
9
#include "names.h"
9
#include "names.h"
10
#include "pragmas.h"
10
#include "pragmas.h"
11
#include "cache1d.h"
11
#include "cache1d.h"
12
#include "game.h"
12
#include "game.h"
13
#include "osd.h"
13
#include "osd.h"
14
#include "mmulti.h"
14
#include "mmulti.h"
15
#include "common.h"
15
#include "common.h"
16
16
17
#include "renderlayer.h"
17
#include "renderlayer.h"
18
18
19
#include "common_game.h"
19
#include "common_game.h"
20
20
21
const char *AppProperName = "EKenBuild";
21
const char *AppProperName = "EKenBuild";
22
const char *AppTechnicalName = "ekenbuild";
22
const char *AppTechnicalName = "ekenbuild";
23
23
24
#define SETUPFILENAME "ekenbuild.cfg"
24
#define SETUPFILENAME "ekenbuild.cfg"
25
char setupfilename[BMAX_PATH] = SETUPFILENAME;
25
char setupfilename[BMAX_PATH] = SETUPFILENAME;
26
26
27
#define TIMERINTSPERSECOND 140 //280
27
#define TIMERINTSPERSECOND 140 //280
28
#define MOVESPERSECOND 40
28
#define MOVESPERSECOND 40
29
#define TICSPERFRAME 3
29
#define TICSPERFRAME 3
30
#define MOVEFIFOSIZ 256
30
#define MOVEFIFOSIZ 256
31
#define EYEHEIGHT (32<<8)   //Normally (32<<8), (51<<8) to make mirrors happy
31
#define EYEHEIGHT (32<<8)   //Normally (32<<8), (51<<8) to make mirrors happy
32
32
33
#define TILE_TILT           (MAXTILES-2)
33
#define TILE_TILT           (MAXTILES-2)
34
34
35
35
36
static int32_t setsprite_eyeheight(int16_t spritenum, const vec3_t *pos) ATTRIBUTE((nonnull(2)));
36
static int32_t setsprite_eyeheight(int16_t spritenum, const vec3_t *pos) ATTRIBUTE((nonnull(2)));
37
static int32_t setsprite_eyeheight(int16_t spritenum, const vec3_t *pos)
37
static int32_t setsprite_eyeheight(int16_t spritenum, const vec3_t *pos)
38
{
38
{
39
    vec3_t eyepos = *pos;
39
    vec3_t eyepos = *pos;
40
    eyepos.z += EYEHEIGHT;
40
    eyepos.z += EYEHEIGHT;
41
    return setsprite(spritenum, &eyepos);
41
    return setsprite(spritenum, &eyepos);
42
}
42
}
43
43
44
int ksqr(int eax)
44
int ksqr(int eax)
45
{
45
{
46
    return eax*eax;
46
    return eax*eax;
47
}
47
}
48
48
49
// declared in sound.c
49
// declared in sound.c
50
void initsb(char,char,int,char,char,char,char);
50
void initsb(char,char,int,char,char,char,char);
51
void uninitsb(void);
51
void uninitsb(void);
52
void setears(int,int,int,int);
52
void setears(int,int,int,int);
53
void wsayfollow(char const *,int,int,int *,int *,char);
53
void wsayfollow(char const *,int,int,int *,int *,char);
54
void wsay(char const *,int,int,int);
54
void wsay(char const *,int,int,int);
55
void loadwaves(char const *);
55
void loadwaves(char const *);
56
int loadsong(char const *);
56
int loadsong(char const *);
57
void musicon(void);
57
void musicon(void);
58
void musicoff(void);
58
void musicoff(void);
59
void refreshaudio(void);
59
void refreshaudio(void);
60
60
61
// declared in config.c
61
// declared in config.c
62
int Ken_loadsetup(const char *);
62
int Ken_loadsetup(const char *);
63
int Ken_writesetup(const char *);
63
int Ken_writesetup(const char *);
64
64
65
/***************************************************************************
65
/***************************************************************************
66
    KEN'S TAG DEFINITIONS:      (Please define your own tags for your games)
66
    KEN'S TAG DEFINITIONS:      (Please define your own tags for your games)
67

67

68
 sector[?].lotag = 0   Normal sector
68
 sector[?].lotag = 0   Normal sector
69
 sector[?].lotag = 1   If you are on a sector with this tag, then all sectors
69
 sector[?].lotag = 1   If you are on a sector with this tag, then all sectors
70
                       with same hi tag as this are operated.  Once.
70
                       with same hi tag as this are operated.  Once.
71
 sector[?].lotag = 2   Same as sector[?].tag = 1 but this is retriggable.
71
 sector[?].lotag = 2   Same as sector[?].tag = 1 but this is retriggable.
72
 sector[?].lotag = 3   A really stupid sector that really does nothing now.
72
 sector[?].lotag = 3   A really stupid sector that really does nothing now.
73
 sector[?].lotag = 4   A sector where you are put closer to the floor
73
 sector[?].lotag = 4   A sector where you are put closer to the floor
74
                       (such as the slime in DOOM1.DAT)
74
                       (such as the slime in DOOM1.DAT)
75
 sector[?].lotag = 5   A really stupid sector that really does nothing now.
75
 sector[?].lotag = 5   A really stupid sector that really does nothing now.
76
 sector[?].lotag = 6   A normal door - instead of pressing D, you tag the
76
 sector[?].lotag = 6   A normal door - instead of pressing D, you tag the
77
                       sector with a 6.  The reason I make you edit doors
77
                       sector with a 6.  The reason I make you edit doors
78
                       this way is so that can program the doors
78
                       this way is so that can program the doors
79
                       yourself.
79
                       yourself.
80
 sector[?].lotag = 7   A door the goes down to open.
80
 sector[?].lotag = 7   A door the goes down to open.
81
 sector[?].lotag = 8   A door that opens horizontally in the middle.
81
 sector[?].lotag = 8   A door that opens horizontally in the middle.
82
 sector[?].lotag = 9   A sliding door that opens vertically in the middle.
82
 sector[?].lotag = 9   A sliding door that opens vertically in the middle.
83
                       -Example of the advantages of not using BSP tree.
83
                       -Example of the advantages of not using BSP tree.
84
 sector[?].lotag = 10  A warping sector with floor and walls that shade.
84
 sector[?].lotag = 10  A warping sector with floor and walls that shade.
85
 sector[?].lotag = 11  A sector with all walls that do X-panning.
85
 sector[?].lotag = 11  A sector with all walls that do X-panning.
86
 sector[?].lotag = 12  A sector with walls using the dragging function.
86
 sector[?].lotag = 12  A sector with walls using the dragging function.
87
 sector[?].lotag = 13  A sector with some swinging doors in it.
87
 sector[?].lotag = 13  A sector with some swinging doors in it.
88
 sector[?].lotag = 14  A revolving door sector.
88
 sector[?].lotag = 14  A revolving door sector.
89
 sector[?].lotag = 15  A subway track.
89
 sector[?].lotag = 15  A subway track.
90
 sector[?].lotag = 16  A true double-sliding door.
90
 sector[?].lotag = 16  A true double-sliding door.
91

91

92
    wall[?].lotag = 0   Normal wall
92
    wall[?].lotag = 0   Normal wall
93
    wall[?].lotag = 1   Y-panning wall
93
    wall[?].lotag = 1   Y-panning wall
94
    wall[?].lotag = 2   Switch - If you flip it, then all sectors with same hi
94
    wall[?].lotag = 2   Switch - If you flip it, then all sectors with same hi
95
                        tag as this are operated.
95
                        tag as this are operated.
96
    wall[?].lotag = 3   Marked wall to detemine starting dir. (sector tag 12)
96
    wall[?].lotag = 3   Marked wall to detemine starting dir. (sector tag 12)
97
    wall[?].lotag = 4   Mark on the shorter wall closest to the pivot point
97
    wall[?].lotag = 4   Mark on the shorter wall closest to the pivot point
98
                        of a swinging door. (sector tag 13)
98
                        of a swinging door. (sector tag 13)
99
    wall[?].lotag = 5   Mark where a subway should stop. (sector tag 15)
99
    wall[?].lotag = 5   Mark where a subway should stop. (sector tag 15)
100
    wall[?].lotag = 6   Mark for true double-sliding doors (sector tag 16)
100
    wall[?].lotag = 6   Mark for true double-sliding doors (sector tag 16)
101
    wall[?].lotag = 7   Water fountain
101
    wall[?].lotag = 7   Water fountain
102
    wall[?].lotag = 8   Bouncy wall!
102
    wall[?].lotag = 8   Bouncy wall!
103

103

104
 sprite[?].lotag = 0   Normal sprite
104
 sprite[?].lotag = 0   Normal sprite
105
 sprite[?].lotag = 1   If you press space bar on an AL, and the AL is tagged
105
 sprite[?].lotag = 1   If you press space bar on an AL, and the AL is tagged
106
                       with a 1, he will turn evil.
106
                       with a 1, he will turn evil.
107
 sprite[?].lotag = 2   When this sprite is operated, a bomb is shot at its
107
 sprite[?].lotag = 2   When this sprite is operated, a bomb is shot at its
108
                       position.
108
                       position.
109
 sprite[?].lotag = 3   Rotating sprite.
109
 sprite[?].lotag = 3   Rotating sprite.
110
 sprite[?].lotag = 4   Sprite switch.
110
 sprite[?].lotag = 4   Sprite switch.
111
 sprite[?].lotag = 5   Basketball hoop score.
111
 sprite[?].lotag = 5   Basketball hoop score.
112

112

113
    KEN'S STATUS DEFINITIONS:  (Please define your own statuses for your games)
113
    KEN'S STATUS DEFINITIONS:  (Please define your own statuses for your games)
114
 status = 0            Inactive sprite
114
 status = 0            Inactive sprite
115
 status = 1            Active monster sprite
115
 status = 1            Active monster sprite
116
 status = 2            Monster that becomes active only when it sees you
116
 status = 2            Monster that becomes active only when it sees you
117
 status = 3            Smoke on the wall for chainguns
117
 status = 3            Smoke on the wall for chainguns
118
 status = 4            Splashing sprites (When you shoot slime)
118
 status = 4            Splashing sprites (When you shoot slime)
119
 status = 5            Explosion!
119
 status = 5            Explosion!
120
 status = 6            Travelling bullet
120
 status = 6            Travelling bullet
121
 status = 7            Bomb sprial-out explosion
121
 status = 7            Bomb sprial-out explosion
122
 status = 8            Player!
122
 status = 8            Player!
123
 status = 9            EVILALGRAVE shrinking list
123
 status = 9            EVILALGRAVE shrinking list
124
 status = 10           EVILAL list
124
 status = 10           EVILAL list
125
 status = 11           Sprite respawning list
125
 status = 11           Sprite respawning list
126
 status = 12           Sprite which does not respawn (Andy's addition)
126
 status = 12           Sprite which does not respawn (Andy's addition)
127
 status = MAXSTATUS    Non-existent sprite (this will be true for your
127
 status = MAXSTATUS    Non-existent sprite (this will be true for your
128
                       code also)
128
                       code also)
129
**************************************************************************/
129
**************************************************************************/
130
130
131
typedef struct
131
typedef struct
132
{
132
{
133
    signed char fvel, svel, avel;
133
    signed char fvel, svel, avel;
134
    short bits;
134
    short bits;
135
} input;
135
} input;
136
136
137
static int screentilt = 0, oscreentilt = 0;
137
static int screentilt = 0, oscreentilt = 0;
138
138
139
139
140
static int fvel, svel, avel;
140
static int fvel, svel, avel;
141
static int fvel2, svel2, avel2;
141
static int fvel2, svel2, avel2;
142
142
143
unsigned char option[NUMOPTIONS] = {0,0,1,1,0,0,1,1+4+(6<<4)};
143
unsigned char option[NUMOPTIONS] = {0,0,1,1,0,0,1,1+4+(6<<4)};
144
unsigned char keys[NUMGAMEKEYS] =
144
unsigned char keys[NUMGAMEKEYS] =
145
{
145
{
146
    0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
146
    0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
147
    0x1e,0x2c,0xd1,0xc9,0x33,0x34,
147
    0x1e,0x2c,0xd1,0xc9,0x33,0x34,
148
    0x9c,0x1c,0xd,0xc,0xf
148
    0x9c,0x1c,0xd,0xc,0xf
149
};
149
};
150
150
151
extern "C" {
151
extern "C" {
152
int xdimgame = 320, ydimgame = 200, bppgame = 8, xdim2d = 640, ydim2d = 480;    // JBF 20050318: config.c expects to find these
152
int xdimgame = 320, ydimgame = 200, bppgame = 8, xdim2d = 640, ydim2d = 480;    // JBF 20050318: config.c expects to find these
153
int forcesetup = 1;
153
int forcesetup = 1;
154
}
154
}
155
155
156
static int digihz[8] = {6000,8000,11025,16000,22050,32000,44100,48000};
156
static int digihz[8] = {6000,8000,11025,16000,22050,32000,44100,48000};
157
157
158
static char frame2draw[MAXPLAYERS];
158
static char frame2draw[MAXPLAYERS];
159
static int frameskipcnt[MAXPLAYERS];
159
static int frameskipcnt[MAXPLAYERS];
160
160
161
#define LAVASIZ 128
161
#define LAVASIZ 128
162
#define LAVALOGSIZ 7
162
#define LAVALOGSIZ 7
163
#define LAVAMAXDROPS 32
163
#define LAVAMAXDROPS 32
164
static char lavabakpic[(LAVASIZ+4)*(LAVASIZ+4)], lavainc[LAVASIZ];
164
static char lavabakpic[(LAVASIZ+4)*(LAVASIZ+4)], lavainc[LAVASIZ];
165
static int lavanumdrops, lavanumframes;
165
static int lavanumdrops, lavanumframes;
166
static int lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS];
166
static int lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS];
167
static int lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS];
167
static int lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS];
168
static int lavaradx[24][96], lavarady[24][96], lavaradcnt[32];
168
static int lavaradx[24][96], lavarady[24][96], lavaradcnt[32];
169
169
170
//Shared player variables
170
//Shared player variables
171
static vec3_t pos[MAXPLAYERS];
171
static vec3_t pos[MAXPLAYERS];
172
static int horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS];
172
static int horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS];
173
static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS];
173
static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS];
174
static short playersprite[MAXPLAYERS], deaths[MAXPLAYERS];
174
static short playersprite[MAXPLAYERS], deaths[MAXPLAYERS];
175
static int lastchaingun[MAXPLAYERS];
175
static int lastchaingun[MAXPLAYERS];
176
static int health[MAXPLAYERS], flytime[MAXPLAYERS];
176
static int health[MAXPLAYERS], flytime[MAXPLAYERS];
177
static short oflags[MAXPLAYERS];
177
static short oflags[MAXPLAYERS];
178
static short numbombs[MAXPLAYERS];
178
static short numbombs[MAXPLAYERS];
179
static short numgrabbers[MAXPLAYERS];   // Andy did this
179
static short numgrabbers[MAXPLAYERS];   // Andy did this
180
static short nummissiles[MAXPLAYERS];   // Andy did this
180
static short nummissiles[MAXPLAYERS];   // Andy did this
181
static char dimensionmode[MAXPLAYERS];
181
static char dimensionmode[MAXPLAYERS];
182
static char revolvedoorstat[MAXPLAYERS];
182
static char revolvedoorstat[MAXPLAYERS];
183
static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS];
183
static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS];
184
static int revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS];
184
static int revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS];
185
185
186
static int nummoves;
186
static int nummoves;
187
// Bug: NUMSTATS used to be equal to the greatest tag number,
187
// Bug: NUMSTATS used to be equal to the greatest tag number,
188
// so that the last statrate[] entry was random memory junk
188
// so that the last statrate[] entry was random memory junk
189
// because stats 0-NUMSTATS required NUMSTATS+1 bytes.   -Andy
189
// because stats 0-NUMSTATS required NUMSTATS+1 bytes.   -Andy
190
#define NUMSTATS 13
190
#define NUMSTATS 13
191
static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1};
191
static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1};
192
192
193
//Input structures
193
//Input structures
194
static char networkmode;     //0 is 2(n-1) mode, 1 is n(n-1) mode
194
static char networkmode;     //0 is 2(n-1) mode, 1 is n(n-1) mode
195
static int locselectedgun, locselectedgun2;
195
static int locselectedgun, locselectedgun2;
196
static input loc, oloc, loc2;
196
static input loc, oloc, loc2;
197
static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], ssync[MAXPLAYERS];
197
static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], ssync[MAXPLAYERS];
198
//Input faketimerhandler -> movethings fifo
198
//Input faketimerhandler -> movethings fifo
199
static int movefifoplc, movefifoend[MAXPLAYERS];
199
static int movefifoplc, movefifoend[MAXPLAYERS];
200
static input baksync[MOVEFIFOSIZ][MAXPLAYERS];
200
static input baksync[MOVEFIFOSIZ][MAXPLAYERS];
201
//Game recording variables
201
//Game recording variables
202
static int reccnt, recstat = 1;
202
static int reccnt, recstat = 1;
203
static input recsync[16384][2];
203
static input recsync[16384][2];
204
204
205
//static int myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1;
205
//static int myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1;
206
static signed char otherlag[MAXPLAYERS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
206
static signed char otherlag[MAXPLAYERS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
207
static int averagelag[MAXPLAYERS] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512};
207
static int averagelag[MAXPLAYERS] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512};
208
208
209
static int fakemovefifoplc;
209
static int fakemovefifoplc;
210
static vec3_t my, omy;
210
static vec3_t my, omy;
211
static int myzvel;
211
static int myzvel;
212
static int myhoriz, omyhoriz;
212
static int myhoriz, omyhoriz;
213
static short myang, omyang, mycursectnum;
213
static short myang, omyang, mycursectnum;
214
static vec3_t mybak[MOVEFIFOSIZ];
214
static vec3_t mybak[MOVEFIFOSIZ];
215
static int myhorizbak[MOVEFIFOSIZ];
215
static int myhorizbak[MOVEFIFOSIZ];
216
static short myangbak[MOVEFIFOSIZ];
216
static short myangbak[MOVEFIFOSIZ];
217
217
218
//GAME.C sync state variables
218
//GAME.C sync state variables
219
static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ];
219
static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ];
220
static int syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail;
220
static int syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail;
221
221
222
static char detailmode = 0, ready2send = 0;
222
static char detailmode = 0, ready2send = 0;
223
static int ototalclock = 0, gotlastpacketclock = 0, smoothratio;
223
static int ototalclock = 0, gotlastpacketclock = 0, smoothratio;
224
static vec3_t opos[MAXPLAYERS];
224
static vec3_t opos[MAXPLAYERS];
225
static int ohoriz[MAXPLAYERS], ozoom[MAXPLAYERS];
225
static int ohoriz[MAXPLAYERS], ozoom[MAXPLAYERS];
226
static short oang[MAXPLAYERS];
226
static short oang[MAXPLAYERS];
227
227
228
static vec3_t osprite[MAXSPRITES];
228
static vec3_t osprite[MAXSPRITES];
229
229
230
#define MAXINTERPOLATIONS 1024
230
#define MAXINTERPOLATIONS 1024
231
static int numinterpolations = 0, startofdynamicinterpolations = 0;
231
static int numinterpolations = 0, startofdynamicinterpolations = 0;
232
static int oldipos[MAXINTERPOLATIONS];
232
static int oldipos[MAXINTERPOLATIONS];
233
static int bakipos[MAXINTERPOLATIONS];
233
static int bakipos[MAXINTERPOLATIONS];
234
static int *curipos[MAXINTERPOLATIONS];
234
static int *curipos[MAXINTERPOLATIONS];
235
235
236
// extern int cachecount;
236
// extern int cachecount;
237
237
238
static char playerreadyflag[MAXPLAYERS];
238
static char playerreadyflag[MAXPLAYERS];
239
239
240
//Miscellaneous variables
240
//Miscellaneous variables
241
static unsigned char packbuf[MAXXDIM];
241
static unsigned char packbuf[MAXXDIM];
242
static char tempbuf[MAXXDIM];
242
static char tempbuf[MAXXDIM];
243
static char boardfilename[BMAX_PATH];
243
static char boardfilename[BMAX_PATH];
244
static short tempshort[MAXSECTORS];
244
static short tempshort[MAXSECTORS];
245
static short screenpeek = 0, oldmousebstatus = 0;
245
static short screenpeek = 0, oldmousebstatus = 0;
246
short brightness = 0;
246
short brightness = 0;
247
static short screensize, screensizeflag = 0;
247
static short screensize, screensizeflag = 0;
248
static short neartagsector, neartagwall, neartagsprite;
248
static short neartagsector, neartagwall, neartagsprite;
249
static int lockclock, neartagdist, neartaghitdist;
249
static int lockclock, neartagdist, neartaghitdist;
250
extern int pageoffset, ydim16;
250
extern int pageoffset, ydim16;
251
static int globhiz, globloz, globhihit, globlohit;
251
static int globhiz, globloz, globhihit, globlohit;
252
252
253
//Over the shoulder mode variables
253
//Over the shoulder mode variables
254
static int cameradist = -1, cameraang = 0, cameraclock = 0;
254
static int cameradist = -1, cameraang = 0, cameraclock = 0;
255
255
256
//Board animation variables
256
//Board animation variables
257
#define MAXMIRRORS 64
257
#define MAXMIRRORS 64
258
static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt;
258
static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt;
259
static short floormirrorsector[64], floormirrorcnt;
259
static short floormirrorsector[64], floormirrorcnt;
260
static short turnspritelist[16], turnspritecnt;
260
static short turnspritelist[16], turnspritecnt;
261
static short warpsectorlist[64], warpsectorcnt;
261
static short warpsectorlist[64], warpsectorcnt;
262
static short xpanningsectorlist[16], xpanningsectorcnt;
262
static short xpanningsectorlist[16], xpanningsectorcnt;
263
static short ypanningwalllist[64], ypanningwallcnt;
263
static short ypanningwalllist[64], ypanningwallcnt;
264
static short floorpanninglist[64], floorpanningcnt;
264
static short floorpanninglist[64], floorpanningcnt;
265
static short dragsectorlist[16], dragxdir[16], dragydir[16], dragsectorcnt;
265
static short dragsectorlist[16], dragxdir[16], dragydir[16], dragsectorcnt;
266
static int dragx1[16], dragy1[16], dragx2[16], dragy2[16], dragfloorz[16];
266
static int dragx1[16], dragy1[16], dragx2[16], dragy2[16], dragfloorz[16];
267
static short swingcnt, swingwall[32][5], swingsector[32];
267
static short swingcnt, swingwall[32][5], swingsector[32];
268
static short swingangopen[32], swingangclosed[32], swingangopendir[32];
268
static short swingangopen[32], swingangclosed[32], swingangopendir[32];
269
static short swingang[32], swinganginc[32];
269
static short swingang[32], swinganginc[32];
270
static int swingx[32][8], swingy[32][8];
270
static int swingx[32][8], swingy[32][8];
271
static short revolvesector[4], revolveang[4], revolvecnt;
271
static short revolvesector[4], revolveang[4], revolvecnt;
272
static int revolvex[4][16], revolvey[4][16];
272
static int revolvex[4][16], revolvey[4][16];
273
static int revolvepivotx[4], revolvepivoty[4];
273
static int revolvepivotx[4], revolvepivoty[4];
274
static short subwaytracksector[4][128], subwaynumsectors[4], subwaytrackcnt;
274
static short subwaytracksector[4][128], subwaynumsectors[4], subwaytrackcnt;
275
static int subwaystop[4][8], subwaystopcnt[4];
275
static int subwaystop[4][8], subwaystopcnt[4];
276
static int subwaytrackx1[4], subwaytracky1[4];
276
static int subwaytrackx1[4], subwaytracky1[4];
277
static int subwaytrackx2[4], subwaytracky2[4];
277
static int subwaytrackx2[4], subwaytracky2[4];
278
static int subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4];
278
static int subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4];
279
static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS];
279
static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS];
280
static short slimesoundcnt[MAXPLAYERS];
280
static short slimesoundcnt[MAXPLAYERS];
281
281
282
//Variables that let you type messages to other player
282
//Variables that let you type messages to other player
283
static char getmessage[162], getmessageleng;
283
static char getmessage[162], getmessageleng;
284
static int getmessagetimeoff;
284
static int getmessagetimeoff;
285
static char typemessage[162], typemessageleng = 0, typemode = 0;
285
static char typemessage[162], typemessageleng = 0, typemode = 0;
286
#if 0
286
#if 0
287
static char scantoasc[128] =
287
static char scantoasc[128] =
288
{
288
{
289
    0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0,
289
    0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0,
290
    'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s',
290
    'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s',
291
    'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v',
291
    'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v',
292
    'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0,
292
    'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0,
293
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
293
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
294
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
294
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
295
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
295
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
296
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
296
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
297
};
297
};
298
static char scantoascwithshift[128] =
298
static char scantoascwithshift[128] =
299
{
299
{
300
    0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0,
300
    0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0,
301
    'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S',
301
    'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S',
302
    'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V',
302
    'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V',
303
    'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0,
303
    'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0,
304
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
304
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
305
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
305
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
306
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
306
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
307
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
307
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
308
};
308
};
309
#endif
309
#endif
310
310
311
//These variables are for animating x, y, or z-coordinates of sectors,
311
//These variables are for animating x, y, or z-coordinates of sectors,
312
//walls, or sprites (They are NOT to be used for changing the [].picnum's)
312
//walls, or sprites (They are NOT to be used for changing the [].picnum's)
313
//See the setanimation(), and getanimategoal() functions for more details.
313
//See the setanimation(), and getanimategoal() functions for more details.
314
#define MAXANIMATES 512
314
#define MAXANIMATES 512
315
static int *animateptr[MAXANIMATES], animategoal[MAXANIMATES];
315
static int *animateptr[MAXANIMATES], animategoal[MAXANIMATES];
316
static int animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0;
316
static int animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0;
317
317
318
#if defined USE_OPENGL
318
#if defined USE_OPENGL
319
//These parameters are in exact order of sprite structure in BUILD.H
319
//These parameters are in exact order of sprite structure in BUILD.H
320
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2,        \
320
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2,        \
321
                    clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2,     \
321
                    clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2,     \
322
                    xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
322
                    xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
323
    {                                                                       \
323
    {                                                                       \
324
        spritetype *spr2;                                                   \
324
        spritetype *spr2;                                                   \
325
        newspriteindex2 = insertsprite(sectnum2,statnum2);                  \
325
        newspriteindex2 = insertsprite(sectnum2,statnum2);                  \
326
        spr2 = &sprite[newspriteindex2];                                    \
326
        spr2 = &sprite[newspriteindex2];                                    \
327
        spr2->x = x2; spr2->y = y2; spr2->z = z2;                           \
327
        spr2->x = x2; spr2->y = y2; spr2->z = z2;                           \
328
        spr2->cstat = cstat2; spr2->shade = shade2;                         \
328
        spr2->cstat = cstat2; spr2->shade = shade2;                         \
329
        spr2->pal = pal2; spr2->clipdist = clipdist2;                       \
329
        spr2->pal = pal2; spr2->clipdist = clipdist2;                       \
330
        spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2;                 \
330
        spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2;                 \
331
        spr2->xoffset = xoffset2; spr2->yoffset = yoffset2;                 \
331
        spr2->xoffset = xoffset2; spr2->yoffset = yoffset2;                 \
332
        spr2->picnum = picnum2; spr2->ang = ang2;                           \
332
        spr2->picnum = picnum2; spr2->ang = ang2;                           \
333
        spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2;         \
333
        spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2;         \
334
        spr2->owner = owner2;                                               \
334
        spr2->owner = owner2;                                               \
335
        spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2;   \
335
        spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2;   \
336
        copybuf(&spr2->x,&osprite[newspriteindex2].x,3);                    \
336
        copybuf(&spr2->x,&osprite[newspriteindex2].x,3);                    \
337
        show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7));      \
337
        show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7));      \
338
        if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7)))                    \
338
        if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7)))                    \
339
            show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7));   \
339
            show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7));   \
340
        clearbufbyte(&spriteext[newspriteindex2], sizeof(spriteext_t), 0);  \
340
        clearbufbyte(&spriteext[newspriteindex2], sizeof(spriteext_t), 0);  \
341
    }
341
    }
342
#else
342
#else
343
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2,        \
343
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2,        \
344
                    clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2,     \
344
                    clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2,     \
345
                    xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
345
                    xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
346
    {                                                                       \
346
    {                                                                       \
347
        spritetype *spr2;                                                   \
347
        spritetype *spr2;                                                   \
348
        newspriteindex2 = insertsprite(sectnum2,statnum2);                  \
348
        newspriteindex2 = insertsprite(sectnum2,statnum2);                  \
349
        spr2 = &sprite[newspriteindex2];                                    \
349
        spr2 = &sprite[newspriteindex2];                                    \
350
        spr2->x = x2; spr2->y = y2; spr2->z = z2;                           \
350
        spr2->x = x2; spr2->y = y2; spr2->z = z2;                           \
351
        spr2->cstat = cstat2; spr2->shade = shade2;                         \
351
        spr2->cstat = cstat2; spr2->shade = shade2;                         \
352
        spr2->pal = pal2; spr2->clipdist = clipdist2;                       \
352
        spr2->pal = pal2; spr2->clipdist = clipdist2;                       \
353
        spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2;                 \
353
        spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2;                 \
354
        spr2->xoffset = xoffset2; spr2->yoffset = yoffset2;                 \
354
        spr2->xoffset = xoffset2; spr2->yoffset = yoffset2;                 \
355
        spr2->picnum = picnum2; spr2->ang = ang2;                           \
355
        spr2->picnum = picnum2; spr2->ang = ang2;                           \
356
        spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2;         \
356
        spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2;         \
357
        spr2->owner = owner2;                                               \
357
        spr2->owner = owner2;                                               \
358
        spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2;   \
358
        spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2;   \
359
        copybuf(&spr2->x,&osprite[newspriteindex2].x,3);                    \
359
        copybuf(&spr2->x,&osprite[newspriteindex2].x,3);                    \
360
        show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7));      \
360
        show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7));      \
361
        if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7)))                    \
361
        if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7)))                    \
362
            show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7));   \
362
            show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7));   \
363
    }
363
    }
364
#endif
364
#endif
365
365
366
int nextvoxid = 0;
366
int nextvoxid = 0;
367
367
368
int osdcmd_restartvid(const osdfuncparm_t *parm)
368
int osdcmd_restartvid(const osdfuncparm_t *parm)
369
{
369
{
370
    UNREFERENCED_PARAMETER(parm);
370
    UNREFERENCED_PARAMETER(parm);
371
371
372
    videoResetMode();
372
    videoResetMode();
373
    if (videoSetGameMode(fullscreen, xdim, ydim, bpp, upscalefactor))
373
    if (videoSetGameMode(fullscreen, xdim, ydim, bpp, upscalefactor))
374
        buildputs("restartvid: Reset failed...\n");
374
        buildputs("restartvid: Reset failed...\n");
375
375
376
    return OSDCMD_OK;
376
    return OSDCMD_OK;
377
}
377
}
378
378
379
static int osdcmd_vidmode(const osdfuncparm_t *parm)
379
static int osdcmd_vidmode(const osdfuncparm_t *parm)
380
{
380
{
381
    int newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen;
381
    int newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen;
382
382
383
    if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP;
383
    if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP;
384
384
385
    switch (parm->numparms)
385
    switch (parm->numparms)
386
    {
386
    {
387
    case 1:   // bpp switch
387
    case 1:   // bpp switch
388
        newbpp = Batol(parm->parms[0]);
388
        newbpp = Batol(parm->parms[0]);
389
        break;
389
        break;
390
    case 2: // res switch
390
    case 2: // res switch
391
        newx = Batol(parm->parms[0]);
391
        newx = Batol(parm->parms[0]);
392
        newy = Batol(parm->parms[1]);
392
        newy = Batol(parm->parms[1]);
393
        break;
393
        break;
394
    case 3:   // res & bpp switch
394
    case 3:   // res & bpp switch
395
    case 4:
395
    case 4:
396
        newx = Batol(parm->parms[0]);
396
        newx = Batol(parm->parms[0]);
397
        newy = Batol(parm->parms[1]);
397
        newy = Batol(parm->parms[1]);
398
        newbpp = Batol(parm->parms[2]);
398
        newbpp = Batol(parm->parms[2]);
399
        if (parm->numparms == 4)
399
        if (parm->numparms == 4)
400
            newfullscreen = (Batol(parm->parms[3]) != 0);
400
            newfullscreen = (Batol(parm->parms[3]) != 0);
401
        break;
401
        break;
402
    }
402
    }
403
403
404
    if (videoSetGameMode(newfullscreen, newx, newy, newbpp, upscalefactor))
404
    if (videoSetGameMode(newfullscreen, newx, newy, newbpp, upscalefactor))
405
        buildputs("vidmode: Mode change failed!\n");
405
        buildputs("vidmode: Mode change failed!\n");
406
    screensize = xdim+1;
406
    screensize = xdim+1;
407
    return OSDCMD_OK;
407
    return OSDCMD_OK;
408
}
408
}
409
409
410
static int osdcmd_map(const osdfuncparm_t *parm)
410
static int osdcmd_map(const osdfuncparm_t *parm)
411
{
411
{
412
    int i;
412
    int i;
413
    char *dot, namebuf[BMAX_PATH+1];
413
    char *dot, namebuf[BMAX_PATH+1];
414
414
415
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
415
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
416
416
417
    strncpy(namebuf, parm->parms[0], BMAX_PATH);
417
    strncpy(namebuf, parm->parms[0], BMAX_PATH);
418
    namebuf[BMAX_PATH] = 0;
418
    namebuf[BMAX_PATH] = 0;
419
    dot = strrchr(namebuf, '.');
419
    dot = strrchr(namebuf, '.');
420
    if ((!dot || Bstrcasecmp(dot, ".map")) && strlen(namebuf) <= BMAX_PATH-4)
420
    if ((!dot || Bstrcasecmp(dot, ".map")) && strlen(namebuf) <= BMAX_PATH-4)
421
    {
421
    {
422
        strcat(namebuf, ".map");
422
        strcat(namebuf, ".map");
423
    }
423
    }
424
424
425
    prepareboard(namebuf);
425
    prepareboard(namebuf);
426
426
427
    screenpeek = myconnectindex;
427
    screenpeek = myconnectindex;
428
    reccnt = 0;
428
    reccnt = 0;
429
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
429
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
430
430
431
    waitforeverybody();
431
    waitforeverybody();
432
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
432
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
433
433
434
    ready2send = 1;
434
    ready2send = 1;
435
    drawscreen(screenpeek,65536L);
435
    drawscreen(screenpeek,65536L);
436
436
437
    return OSDCMD_OK;
437
    return OSDCMD_OK;
438
}
438
}
439
439
440
static void Ken_UninitAll(void)
440
static void Ken_UninitAll(void)
441
{
441
{
442
    sendlogoff();         //Signing off
442
    sendlogoff();         //Signing off
443
    musicoff();
443
    musicoff();
444
    uninitmultiplayers();
444
    uninitmultiplayers();
445
    timerUninit();
445
    timerUninit();
446
    uninitinput();
446
    uninitinput();
447
    uninitsb();
447
    uninitsb();
448
    engineUnInit();
448
    engineUnInit();
449
    uninitgroupfile();
449
    uninitgroupfile();
450
}
450
}
451
451
452
static void Ken_FatalEngineError(void)
452
static void Ken_FatalEngineError(void)
453
{
453
{
454
    buildprintf("There was a problem initialising the engine: %s.\n", engineerrstr);
454
    buildprintf("There was a problem initialising the engine: %s.\n", engineerrstr);
455
}
455
}
456
456
457
int32_t app_main(int32_t argc, char const * const * argv)
457
int32_t app_main(int32_t argc, char const * const * argv)
458
{
458
{
459
#if defined STARTUP_SETUP_WINDOW
459
#if defined STARTUP_SETUP_WINDOW
460
    int cmdsetup = 0;
460
    int cmdsetup = 0;
461
#endif
461
#endif
462
    int i, j, k /*, l, fil, waitplayers, x1, y1, x2, y2*/;
462
    int i, j, k /*, l, fil, waitplayers, x1, y1, x2, y2*/;
463
    int /*other, packleng,*/ netparm;
463
    int /*other, packleng,*/ netparm;
464
464
465
    OSD_SetLogFile("ekenbuild.log");
465
    OSD_SetLogFile("ekenbuild.log");
466
466
467
    initprintf("%s %s\n", AppProperName, s_buildRev);
467
    initprintf("%s %s\n", AppProperName, s_buildRev);
468
    PrintBuildInfo();
468
    PrintBuildInfo();
469
469
-
 
470
    if (enginePreInit())
-
 
471
    {
-
 
472
        wm_msgbox("Build Engine Initialisation Error",
-
 
473
                  "There was a problem initialising the Build engine: %s", engineerrstr);
-
 
474
        exit(1);
-
 
475
    }
-
 
476
470
#ifdef USE_OPENGL
477
#ifdef USE_OPENGL
471
    OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid);
478
    OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid);
472
    OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode);
479
    OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode);
473
    OSD_RegisterFunction("map", "map [filename]: load a map", osdcmd_map);
480
    OSD_RegisterFunction("map", "map [filename]: load a map", osdcmd_map);
474
#endif
481
#endif
475
482
476
    wm_setapptitle(AppProperName);
483
    wm_setapptitle(AppProperName);
477
484
478
    Bstrcpy(boardfilename, "nukeland.map");
485
    Bstrcpy(boardfilename, "nukeland.map");
479
    j = 0; netparm = argc;
486
    j = 0; netparm = argc;
480
    for (i=1; i<argc; i++)
487
    for (i=1; i<argc; i++)
481
    {
488
    {
482
        if ((!Bstrcasecmp("-net",argv[i])) || (!Bstrcasecmp("/net",argv[i]))) { j = 1; netparm = i; continue; }
489
        if ((!Bstrcasecmp("-net",argv[i])) || (!Bstrcasecmp("/net",argv[i]))) { j = 1; netparm = i; continue; }
483
        if (j)
490
        if (j)
484
        {
491
        {
485
            if (argv[i][0] == '-' || argv[i][0] == '/')
492
            if (argv[i][0] == '-' || argv[i][0] == '/')
486
            {
493
            {
487
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '0')) { networkmode = 0; continue; }
494
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '0')) { networkmode = 0; continue; }
488
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '1')) { networkmode = 1; continue; }
495
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '1')) { networkmode = 1; continue; }
489
            }
496
            }
490
            if (isvalidipaddress(argv[i])) continue;
497
            if (isvalidipaddress(argv[i])) continue;
491
        }
498
        }
492
        else
499
        else
493
        {
500
        {
494
            if (!Bstrcasecmp(argv[i], "-setup"))
501
            if (!Bstrcasecmp(argv[i], "-setup"))
495
            {
502
            {
496
#if defined STARTUP_SETUP_WINDOW
503
#if defined STARTUP_SETUP_WINDOW
497
                cmdsetup = 1;
504
                cmdsetup = 1;
498
#endif
505
#endif
499
            }
506
            }
500
            else
507
            else
501
            {
508
            {
502
                Bstrcpy(boardfilename, argv[i]);
509
                Bstrcpy(boardfilename, argv[i]);
503
                if (!Bstrrchr(boardfilename,'.')) Bstrcat(boardfilename,".map");
510
                if (!Bstrrchr(boardfilename,'.')) Bstrcat(boardfilename,".map");
504
            }
511
            }
505
        }
512
        }
506
    }
513
    }
507
514
508
    if ((i = Ken_loadsetup(setupfilename)) < 0)
515
    if ((i = Ken_loadsetup(setupfilename)) < 0)
509
        buildputs("Configuration file not found, using defaults.\n");
516
        buildputs("Configuration file not found, using defaults.\n");
510
517
511
    wm_msgbox("Pre-Release Software Warning", "%s is not ready for public use. Proceed with caution!", AppProperName);
518
    wm_msgbox("Pre-Release Software Warning", "%s is not ready for public use. Proceed with caution!", AppProperName);
512
519
513
#if defined STARTUP_SETUP_WINDOW
520
#if defined STARTUP_SETUP_WINDOW
514
    if (i || forcesetup || cmdsetup)
521
    if (i || forcesetup || cmdsetup)
515
    {
522
    {
516
        if (quitevent || !startwin_run()) return -1;
523
        if (quitevent || !startwin_run()) return -1;
517
    }
524
    }
518
#endif
525
#endif
519
    Ken_writesetup(setupfilename);
526
    Ken_writesetup(setupfilename);
520
527
521
    initgroupfile(G_GrpFile());
528
    initgroupfile(G_GrpFile());
522
    if (engineInit())
529
    if (engineInit())
523
    {
530
    {
524
        Ken_FatalEngineError();
531
        Ken_FatalEngineError();
525
        return -1;
532
        return -1;
526
    }
533
    }
527
534
528
    Ken_InitMultiPsky();
535
    Ken_InitMultiPsky();
529
536
530
    initinput();
537
    initinput();
531
    if (option[3] != 0) mouseInit();
538
    if (option[3] != 0) mouseInit();
532
    timerInit(TIMERINTSPERSECOND);
539
    timerInit(TIMERINTSPERSECOND);
533
540
534
    //initmultiplayers(argc-netparm,&argv[netparm],option[4],option[5],0);
541
    //initmultiplayers(argc-netparm,&argv[netparm],option[4],option[5],0);
535
    if (initmultiplayersparms(argc-netparm,&argv[netparm]))
542
    if (initmultiplayersparms(argc-netparm,&argv[netparm]))
536
    {
543
    {
537
        buildputs("Waiting for players...\n");
544
        buildputs("Waiting for players...\n");
538
        while (initmultiplayerscycle())
545
        while (initmultiplayerscycle())
539
        {
546
        {
540
            handleevents();
547
            handleevents();
541
            if (quitevent)
548
            if (quitevent)
542
            {
549
            {
543
                Ken_UninitAll();
550
                Ken_UninitAll();
544
                return 0;
551
                return 0;
545
            }
552
            }
546
        }
553
        }
547
    }
554
    }
548
    option[4] = (numplayers >= 2);
555
    option[4] = (numplayers >= 2);
549
556
550
    artLoadFiles("tiles000.art",1048576);                      //Load artwork
557
    artLoadFiles("tiles000.art",1048576);                      //Load artwork
551
    if (!qloadkvx(nextvoxid,"voxel000.kvx"))
558
    if (!qloadkvx(nextvoxid,"voxel000.kvx"))
552
        tiletovox[PLAYER] = nextvoxid++;
559
        tiletovox[PLAYER] = nextvoxid++;
553
    if (!qloadkvx(nextvoxid,"voxel001.kvx"))
560
    if (!qloadkvx(nextvoxid,"voxel001.kvx"))
554
        tiletovox[BROWNMONSTER] = nextvoxid++;
561
        tiletovox[BROWNMONSTER] = nextvoxid++;
555
    if (!loaddefinitionsfile(G_DefFile())) buildputs("Definitions file loaded.\n");
562
    if (!loaddefinitionsfile(G_DefFile())) buildputs("Definitions file loaded.\n");
556
563
557
    if (enginePostInit())
564
    if (enginePostInit())
558
    {
565
    {
559
        Ken_UninitAll();
566
        Ken_UninitAll();
560
        Ken_FatalEngineError();
567
        Ken_FatalEngineError();
561
        return -1;
568
        return -1;
562
    }
569
    }
563
570
564
    OSD_SetFunctions(
571
    OSD_SetFunctions(
565
        NULL, NULL, NULL, NULL, NULL,
572
        NULL, NULL, NULL, NULL, NULL,
566
        COMMON_clearbackground,
573
        COMMON_clearbackground,
567
        BGetTime,
574
        BGetTime,
568
        NULL
575
        NULL
569
        );
576
        );
570
577
571
    {
578
    {
572
        char tempbuf[256];
579
        char tempbuf[256];
573
        snprintf(tempbuf, ARRAY_SIZE(tempbuf), "%s %s", AppProperName, s_buildRev);
580
        snprintf(tempbuf, ARRAY_SIZE(tempbuf), "%s %s", AppProperName, s_buildRev);
574
        OSD_SetVersion(tempbuf, 10,0);
581
        OSD_SetVersion(tempbuf, 10,0);
575
    }
582
    }
576
    OSD_SetParameters(0,2, 0,0, 4,0, 0, 0, 0); // TODO: Add error and red palookup IDs.
583
    OSD_SetParameters(0,2, 0,0, 4,0, 0, 0, 0); // TODO: Add error and red palookup IDs.
577
584
578
    //Here's an example of TRUE ornamented walls
585
    //Here's an example of TRUE ornamented walls
579
    //The tileCreate should be called right after artLoadFiles
586
    //The tileCreate should be called right after artLoadFiles
580
    //Since it resets the tile cache for each call.
587
    //Since it resets the tile cache for each call.
581
    if (tileCreate(SLIME,128,128) == 0)    //If enough memory
588
    if (tileCreate(SLIME,128,128) == 0)    //If enough memory
582
    {
589
    {
583
        buildputs("Not enough memory for slime!\n");
590
        buildputs("Not enough memory for slime!\n");
584
        exit(0);
591
        exit(0);
585
    }
592
    }
586
    if (tileCreate(MAXTILES-1,64,64) != 0)    //If enough memory
593
    if (tileCreate(MAXTILES-1,64,64) != 0)    //If enough memory
587
    {
594
    {
588
        //My face with an explosion written over it
595
        //My face with an explosion written over it
589
        tileCopySection(KENPICTURE,0,0,64,64,MAXTILES-1,0,0);
596
        tileCopySection(KENPICTURE,0,0,64,64,MAXTILES-1,0,0);
590
        tileCopySection(EXPLOSION,0,0,64,64,MAXTILES-1,0,0);
597
        tileCopySection(EXPLOSION,0,0,64,64,MAXTILES-1,0,0);
591
    }
598
    }
592
599
593
    initlava();
600
    initlava();
594
601
595
    for (j=0; j<256; j++)
602
    for (j=0; j<256; j++)
596
        tempbuf[j] = ((j+32)&255);  //remap colors for screwy palette sectors
603
        tempbuf[j] = ((j+32)&255);  //remap colors for screwy palette sectors
597
    paletteMakeLookupTable(16,tempbuf,0,0,0,1);
604
    paletteMakeLookupTable(16,tempbuf,0,0,0,1);
598
605
599
    for (j=0; j<256; j++) tempbuf[j] = j;
606
    for (j=0; j<256; j++) tempbuf[j] = j;
600
    paletteMakeLookupTable(17,tempbuf,96,96,96,1);
607
    paletteMakeLookupTable(17,tempbuf,96,96,96,1);
601
608
602
    for (j=0; j<256; j++) tempbuf[j] = j; //(j&31)+32;
609
    for (j=0; j<256; j++) tempbuf[j] = j; //(j&31)+32;
603
    paletteMakeLookupTable(18,tempbuf,32,32,192,1);
610
    paletteMakeLookupTable(18,tempbuf,32,32,192,1);
604
611
605
    palettePostLoadLookups();
612
    palettePostLoadLookups();
606
613
607
    prepareboard(boardfilename);                   //Load board
614
    prepareboard(boardfilename);                   //Load board
608
615
609
    initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1);
616
    initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1);
610
    //if (Bstrcmp(boardfilename,"klab.map") == 0)
617
    //if (Bstrcmp(boardfilename,"klab.map") == 0)
611
    //   loadsong("klabsong.kdm");
618
    //   loadsong("klabsong.kdm");
612
    //else
619
    //else
613
    loadsong("neatsong.kdm");
620
    loadsong("neatsong.kdm");
614
    musicon();
621
    musicon();
615
622
616
#if 0
623
#if 0
617
    if (option[4] > 0)
624
    if (option[4] > 0)
618
    {
625
    {
619
        x1 = ((xdim-screensize)>>1);
626
        x1 = ((xdim-screensize)>>1);
620
        x2 = x1+screensize-1;
627
        x2 = x1+screensize-1;
621
        y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
628
        y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
622
        y2 = y1 + scale(screensize,ydim-32,xdim)-1;
629
        y2 = y1 + scale(screensize,ydim-32,xdim)-1;
623
630
624
        drawtilebackground(/*0L,0L,*/ BACKGROUND,8,x1,y1,x2,y2,0);
631
        drawtilebackground(/*0L,0L,*/ BACKGROUND,8,x1,y1,x2,y2,0);
625
632
626
        sendlogon();
633
        sendlogon();
627
634
628
        if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3;
635
        if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3;
629
        while (numplayers < waitplayers)
636
        while (numplayers < waitplayers)
630
        {
637
        {
631
            sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers);
638
            sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers);
632
            printext256(68L,84L,31,0,tempbuf,0);
639
            printext256(68L,84L,31,0,tempbuf,0);
633
            videoNextPage();
640
            videoNextPage();
634
641
635
            if (getpacket(&other,packbuf) > 0)
642
            if (getpacket(&other,packbuf) > 0)
636
                if (packbuf[0] == 255)
643
                if (packbuf[0] == 255)
637
                    keystatus[1] = 1;
644
                    keystatus[1] = 1;
638
645
639
            if (handleevents())
646
            if (handleevents())
640
            {
647
            {
641
                if (quitevent)
648
                if (quitevent)
642
                {
649
                {
643
                    keystatus[1] = 1;
650
                    keystatus[1] = 1;
644
                    quitevent = 0;
651
                    quitevent = 0;
645
                }
652
                }
646
            }
653
            }
647
654
648
            if (keystatus[1])
655
            if (keystatus[1])
649
            {
656
            {
650
                Ken_UninitAll();
657
                Ken_UninitAll();
651
                return 0;
658
                return 0;
652
            }
659
            }
653
        }
660
        }
654
        screenpeek = myconnectindex;
661
        screenpeek = myconnectindex;
655
662
656
        if (numplayers <= 3)
663
        if (numplayers <= 3)
657
            networkmode = 1;
664
            networkmode = 1;
658
        else
665
        else
659
            networkmode = 0;
666
            networkmode = 0;
660
667
661
        j = 1;
668
        j = 1;
662
        for (i=connecthead; i>=0; i=connectpoint2[i])
669
        for (i=connecthead; i>=0; i=connectpoint2[i])
663
        {
670
        {
664
            if (myconnectindex == i) break;
671
            if (myconnectindex == i) break;
665
            j++;
672
            j++;
666
        }
673
        }
667
        sprintf(getmessage,"Player %ld",j);
674
        sprintf(getmessage,"Player %ld",j);
668
        if (networkmode == 0)
675
        if (networkmode == 0)
669
        {
676
        {
670
            if (j == 1) Bstrcat(getmessage," (Master)");
677
            if (j == 1) Bstrcat(getmessage," (Master)");
671
            else Bstrcat(getmessage," (Slave)");
678
            else Bstrcat(getmessage," (Slave)");
672
        }
679
        }
673
        else
680
        else
674
            Bstrcat(getmessage," (Even)");
681
            Bstrcat(getmessage," (Even)");
675
        getmessageleng = Bstrlen(getmessage);
682
        getmessageleng = Bstrlen(getmessage);
676
        getmessagetimeoff = totalclock+120;
683
        getmessagetimeoff = totalclock+120;
677
    }
684
    }
678
#endif
685
#endif
679
    screenpeek = myconnectindex;
686
    screenpeek = myconnectindex;
680
    reccnt = 0;
687
    reccnt = 0;
681
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
688
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
682
689
683
    waitforeverybody();
690
    waitforeverybody();
684
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
691
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
685
692
686
    ready2send = 1;
693
    ready2send = 1;
687
    drawscreen(screenpeek,65536L);
694
    drawscreen(screenpeek,65536L);
688
695
689
    while (!keystatus[1])       //Main loop starts here
696
    while (!keystatus[1])       //Main loop starts here
690
    {
697
    {
691
        if (handleevents())
698
        if (handleevents())
692
        {
699
        {
693
            if (quitevent)
700
            if (quitevent)
694
            {
701
            {
695
                keystatus[1] = 1;
702
                keystatus[1] = 1;
696
                quitevent = 0;
703
                quitevent = 0;
697
            }
704
            }
698
        }
705
        }
699
706
700
        refreshaudio();
707
        refreshaudio();
701
        OSD_DispatchQueued();
708
        OSD_DispatchQueued();
702
709
703
        // backslash (useful only with KDM)
710
        // backslash (useful only with KDM)
704
//      if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); }
711
//      if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); }
705
712
706
        if ((networkmode == 1) || (myconnectindex != connecthead))
713
        if ((networkmode == 1) || (myconnectindex != connecthead))
707
            while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings();
714
            while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings();
708
715
709
        getpackets();
716
        getpackets();
710
717
711
        if (typemode == 0)           //if normal game keys active
718
        if (typemode == 0)           //if normal game keys active
712
        {
719
        {
713
            if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0)   //Sh.Sh.R (replay)
720
            if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0)   //Sh.Sh.R (replay)
714
            {
721
            {
715
                keystatus[0x13] = 0;
722
                keystatus[0x13] = 0;
716
                playback();
723
                playback();
717
            }
724
            }
718
725
719
            if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game
726
            if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game
720
            {
727
            {
721
                keystatus[0x26] = 0;
728
                keystatus[0x26] = 0;
722
                loadgame();
729
                loadgame();
723
                drawstatusbar(screenpeek);   // Andy did this
730
                drawstatusbar(screenpeek);   // Andy did this
724
            }
731
            }
725
732
726
            if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game
733
            if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game
727
            {
734
            {
728
                keystatus[0x1f] = 0;
735
                keystatus[0x1f] = 0;
729
                savegame();
736
                savegame();
730
            }
737
            }
731
        }
738
        }
732
739
733
        if ((networkmode == 0) || (option[4] == 0))
740
        if ((networkmode == 0) || (option[4] == 0))
734
        {
741
        {
735
            while (movefifoplc != movefifoend[0]) domovethings();
742
            while (movefifoplc != movefifoend[0]) domovethings();
736
        }
743
        }
737
        else
744
        else
738
        {
745
        {
739
            j = connecthead;
746
            j = connecthead;
740
            if (j == myconnectindex) j = connectpoint2[j];
747
            if (j == myconnectindex) j = connectpoint2[j];
741
            averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3);
748
            averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3);
742
            j = max(averagelag[j]>>9,1);
749
            j = max(averagelag[j]>>9,1);
743
            while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j)
750
            while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j)
744
            {
751
            {
745
                for (i=connecthead; i>=0; i=connectpoint2[i])
752
                for (i=connecthead; i>=0; i=connectpoint2[i])
746
                    if (movefifoplc == movefifoend[i]) break;
753
                    if (movefifoplc == movefifoend[i]) break;
747
                if (i >= 0) break;
754
                if (i >= 0) break;
748
                if (myconnectindex != connecthead)
755
                if (myconnectindex != connecthead)
749
                {
756
                {
750
                    k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255);
757
                    k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255);
751
                    if (k > 128+1) ototalclock++;
758
                    if (k > 128+1) ototalclock++;
752
                    if (k < 128-1) ototalclock--;
759
                    if (k < 128-1) ototalclock--;
753
                }
760
                }
754
                domovethings();
761
                domovethings();
755
            }
762
            }
756
        }
763
        }
757
        i = ((int32_t) totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND));
764
        i = ((int32_t) totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND));
758
765
759
        drawscreen(screenpeek,i);
766
        drawscreen(screenpeek,i);
760
    }
767
    }
761
768
762
    Ken_UninitAll();
769
    Ken_UninitAll();
763
770
764
    return 0;
771
    return 0;
765
}
772
}
766
773
767
void operatesector(short dasector)
774
void operatesector(short dasector)
768
{
775
{
769
    //Door code
776
    //Door code
770
    int i, j, /*k, s, nexti, good, cnt,*/ datag;
777
    int i, j, /*k, s, nexti, good, cnt,*/ datag;
771
    int /*dax, day,*/ daz, dax2, day2, /*daz2,*/ centx, centy;
778
    int /*dax, day,*/ daz, dax2, day2, /*daz2,*/ centx, centy;
772
    short startwall, endwall, wallfind[2];
779
    short startwall, endwall, wallfind[2];
773
780
774
    datag = sector[dasector].lotag;
781
    datag = sector[dasector].lotag;
775
782
776
    startwall = sector[dasector].wallptr;
783
    startwall = sector[dasector].wallptr;
777
    endwall = startwall + sector[dasector].wallnum;
784
    endwall = startwall + sector[dasector].wallnum;
778
    centx = 0L, centy = 0L;
785
    centx = 0L, centy = 0L;
779
    for (i=startwall; i<endwall; i++)
786
    for (i=startwall; i<endwall; i++)
780
    {
787
    {
781
        centx += wall[i].x;
788
        centx += wall[i].x;
782
        centy += wall[i].y;
789
        centy += wall[i].y;
783
    }
790
    }
784
    centx /= (endwall-startwall);
791
    centx /= (endwall-startwall);
785
    centy /= (endwall-startwall);
792
    centy /= (endwall-startwall);
786
793
787
    //Simple door that moves up  (tag 8 is a combination of tags 6 & 7)
794
    //Simple door that moves up  (tag 8 is a combination of tags 6 & 7)
788
    if ((datag == 6) || (datag == 8))    //If the sector in front is a door
795
    if ((datag == 6) || (datag == 8))    //If the sector in front is a door
789
    {
796
    {
790
        i = getanimationgoal(&sector[dasector].ceilingz);
797
        i = getanimationgoal(&sector[dasector].ceilingz);
791
        if (i >= 0)      //If door already moving, reverse its direction
798
        if (i >= 0)      //If door already moving, reverse its direction
792
        {
799
        {
793
            if (datag == 8)
800
            if (datag == 8)
794
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
801
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
795
            else
802
            else
796
                daz = sector[dasector].floorz;
803
                daz = sector[dasector].floorz;
797
804
798
            if (animategoal[i] == daz)
805
            if (animategoal[i] == daz)
799
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
806
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
800
            else
807
            else
801
                animategoal[i] = daz;
808
                animategoal[i] = daz;
802
            animatevel[i] = 0;
809
            animatevel[i] = 0;
803
        }
810
        }
804
        else      //else insert the door's ceiling on the animation list
811
        else      //else insert the door's ceiling on the animation list
805
        {
812
        {
806
            if (sector[dasector].ceilingz == sector[dasector].floorz)
813
            if (sector[dasector].ceilingz == sector[dasector].floorz)
807
                daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
814
                daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
808
            else
815
            else
809
            {
816
            {
810
                if (datag == 8)
817
                if (datag == 8)
811
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
818
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
812
                else
819
                else
813
                    daz = sector[dasector].floorz;
820
                    daz = sector[dasector].floorz;
814
            }
821
            }
815
            if ((j = setanimation(&sector[dasector].ceilingz,daz,6L,6L)) >= 0)
822
            if ((j = setanimation(&sector[dasector].ceilingz,daz,6L,6L)) >= 0)
816
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
823
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
817
        }
824
        }
818
    }
825
    }
819
    //Simple door that moves down
826
    //Simple door that moves down
820
    if ((datag == 7) || (datag == 8)) //If the sector in front's elevator
827
    if ((datag == 7) || (datag == 8)) //If the sector in front's elevator
821
    {
828
    {
822
        i = getanimationgoal(&sector[dasector].floorz);
829
        i = getanimationgoal(&sector[dasector].floorz);
823
        if (i >= 0)      //If elevator already moving, reverse its direction
830
        if (i >= 0)      //If elevator already moving, reverse its direction
824
        {
831
        {
825
            if (datag == 8)
832
            if (datag == 8)
826
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
833
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
827
            else
834
            else
828
                daz = sector[dasector].ceilingz;
835
                daz = sector[dasector].ceilingz;
829
836
830
            if (animategoal[i] == daz)
837
            if (animategoal[i] == daz)
831
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
838
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
832
            else
839
            else
833
                animategoal[i] = daz;
840
                animategoal[i] = daz;
834
            animatevel[i] = 0;
841
            animatevel[i] = 0;
835
        }
842
        }
836
        else      //else insert the elevator's ceiling on the animation list
843
        else      //else insert the elevator's ceiling on the animation list
837
        {
844
        {
838
            if (sector[dasector].floorz == sector[dasector].ceilingz)
845
            if (sector[dasector].floorz == sector[dasector].ceilingz)
839
                daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
846
                daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
840
            else
847
            else
841
            {
848
            {
842
                if (datag == 8)
849
                if (datag == 8)
843
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
850
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
844
                else
851
                else
845
                    daz = sector[dasector].ceilingz;
852
                    daz = sector[dasector].ceilingz;
846
            }
853
            }
847
            if ((j = setanimation(&sector[dasector].floorz,daz,6L,6L)) >= 0)
854
            if ((j = setanimation(&sector[dasector].floorz,daz,6L,6L)) >= 0)
848
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
855
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
849
        }
856
        }
850
    }
857
    }
851
858
852
    if (datag == 9)   //Smooshy-wall sideways double-door
859
    if (datag == 9)   //Smooshy-wall sideways double-door
853
    {
860
    {
854
        //find any points with either same x or same y coordinate
861
        //find any points with either same x or same y coordinate
855
        //  as center (centx, centy) - should be 2 points found.
862
        //  as center (centx, centy) - should be 2 points found.
856
        wallfind[0] = -1;
863
        wallfind[0] = -1;
857
        wallfind[1] = -1;
864
        wallfind[1] = -1;
858
        for (i=startwall; i<endwall; i++)
865
        for (i=startwall; i<endwall; i++)
859
            if ((wall[i].x == centx) || (wall[i].y == centy))
866
            if ((wall[i].x == centx) || (wall[i].y == centy))
860
            {
867
            {
861
                if (wallfind[0] == -1)
868
                if (wallfind[0] == -1)
862
                    wallfind[0] = i;
869
                    wallfind[0] = i;
863
                else
870
                else
864
                    wallfind[1] = i;
871
                    wallfind[1] = i;
865
            }
872
            }
866
873
867
        for (j=0; j<2; j++)
874
        for (j=0; j<2; j++)
868
        {
875
        {
869
            if ((wall[wallfind[j]].x == centx) && (wall[wallfind[j]].y == centy))
876
            if ((wall[wallfind[j]].x == centx) && (wall[wallfind[j]].y == centy))
870
            {
877
            {
871
                //find what direction door should open by averaging the
878
                //find what direction door should open by averaging the
872
                //  2 neighboring points of wallfind[0] & wallfind[1].
879
                //  2 neighboring points of wallfind[0] & wallfind[1].
873
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
880
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
874
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
881
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
875
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
882
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
876
                if (dax2 != 0)
883
                if (dax2 != 0)
877
                {
884
                {
878
                    dax2 = wall[wall[wall[wallfind[j]].point2].point2].x;
885
                    dax2 = wall[wall[wall[wallfind[j]].point2].point2].x;
879
                    dax2 -= wall[wall[wallfind[j]].point2].x;
886
                    dax2 -= wall[wall[wallfind[j]].point2].x;
880
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
887
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
881
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
888
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
882
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
889
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
883
                }
890
                }
884
                else if (day2 != 0)
891
                else if (day2 != 0)
885
                {
892
                {
886
                    day2 = wall[wall[wall[wallfind[j]].point2].point2].y;
893
                    day2 = wall[wall[wall[wallfind[j]].point2].point2].y;
887
                    day2 -= wall[wall[wallfind[j]].point2].y;
894
                    day2 -= wall[wall[wallfind[j]].point2].y;
888
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
895
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
889
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
896
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
890
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
897
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
891
                }
898
                }
892
            }
899
            }
893
            else
900
            else
894
            {
901
            {
895
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
902
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
896
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
903
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
897
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
904
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
898
                if (dax2 != 0)
905
                if (dax2 != 0)
899
                {
906
                {
900
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
907
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
901
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
908
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
902
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L);
909
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L);
903
                }
910
                }
904
                else if (day2 != 0)
911
                else if (day2 != 0)
905
                {
912
                {
906
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
913
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
907
                    setanimation(&wall[i].y,centy+day2,4L,0L);
914
                    setanimation(&wall[i].y,centy+day2,4L,0L);
908
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L);
915
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L);
909
                }
916
                }
910
            }
917
            }
911
        }
918
        }
912
        wsayfollow("updowndr.wav",4096L-256L,256L,&centx,&centy,0);
919
        wsayfollow("updowndr.wav",4096L-256L,256L,&centx,&centy,0);
913
        wsayfollow("updowndr.wav",4096L+256L,256L,&centx,&centy,0);
920
        wsayfollow("updowndr.wav",4096L+256L,256L,&centx,&centy,0);
914
    }
921
    }
915
922
916
    if (datag == 13)  //Swinging door
923
    if (datag == 13)  //Swinging door
917
    {
924
    {
918
        for (i=0; i<swingcnt; i++)
925
        for (i=0; i<swingcnt; i++)
919
        {
926
        {
920
            if (swingsector[i] == dasector)
927
            if (swingsector[i] == dasector)
921
            {
928
            {
922
                if (swinganginc[i] == 0)
929
                if (swinganginc[i] == 0)
923
                {
930
                {
924
                    if (swingang[i] == swingangclosed[i])
931
                    if (swingang[i] == swingangclosed[i])
925
                    {
932
                    {
926
                        swinganginc[i] = swingangopendir[i];
933
                        swinganginc[i] = swingangopendir[i];
927
                        wsayfollow("opendoor.wav",4096L+(krand()&511)-256,256L,&centx,&centy,0);
934
                        wsayfollow("opendoor.wav",4096L+(krand()&511)-256,256L,&centx,&centy,0);
928
                    }
935
                    }
929
                    else
936
                    else
930
                        swinganginc[i] = -swingangopendir[i];
937
                        swinganginc[i] = -swingangopendir[i];
931
                }
938
                }
932
                else
939
                else
933
                    swinganginc[i] = -swinganginc[i];
940
                    swinganginc[i] = -swinganginc[i];
934
941
935
                for (j=1; j<=3; j++)
942
                for (j=1; j<=3; j++)
936
                {
943
                {
937
                    setinterpolation(&wall[swingwall[i][j]].x);
944
                    setinterpolation(&wall[swingwall[i][j]].x);
938
                    setinterpolation(&wall[swingwall[i][j]].y);
945
                    setinterpolation(&wall[swingwall[i][j]].y);
939
                }
946
                }
940
            }
947
            }
941
        }
948
        }
942
    }
949
    }
943
950
944
    if (datag == 16)  //True sideways double-sliding door
951
    if (datag == 16)  //True sideways double-sliding door
945
    {
952
    {
946
        //get 2 closest line segments to center (dax, day)
953
        //get 2 closest line segments to center (dax, day)
947
        wallfind[0] = -1;
954
        wallfind[0] = -1;
948
        wallfind[1] = -1;
955
        wallfind[1] = -1;
949
        for (i=startwall; i<endwall; i++)
956
        for (i=startwall; i<endwall; i++)
950
            if (wall[i].lotag == 6)
957
            if (wall[i].lotag == 6)
951
            {
958
            {
952
                if (wallfind[0] == -1)
959
                if (wallfind[0] == -1)
953
                    wallfind[0] = i;
960
                    wallfind[0] = i;
954
                else
961
                else
955
                    wallfind[1] = i;
962
                    wallfind[1] = i;
956
            }
963
            }
957
964
958
        for (j=0; j<2; j++)
965
        for (j=0; j<2; j++)
959
        {
966
        {
960
            if ((((wall[wallfind[j]].x+wall[wall[wallfind[j]].point2].x)>>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy))
967
            if ((((wall[wallfind[j]].x+wall[wall[wallfind[j]].point2].x)>>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy))
961
            {
968
            {
962
                //door was closed
969
                //door was closed
963
                //find what direction door should open
970
                //find what direction door should open
964
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
971
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
965
                dax2 = wall[i].x-wall[wallfind[j]].x;
972
                dax2 = wall[i].x-wall[wallfind[j]].x;
966
                day2 = wall[i].y-wall[wallfind[j]].y;
973
                day2 = wall[i].y-wall[wallfind[j]].y;
967
                if (dax2 != 0)
974
                if (dax2 != 0)
968
                {
975
                {
969
                    dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x;
976
                    dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x;
970
                    dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x;
977
                    dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x;
971
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
978
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
972
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
979
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
973
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
980
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
974
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L);
981
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L);
975
                }
982
                }
976
                else if (day2 != 0)
983
                else if (day2 != 0)
977
                {
984
                {
978
                    day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y;
985
                    day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y;
979
                    day2 -= wall[wall[wall[wallfind[j]].point2].point2].y;
986
                    day2 -= wall[wall[wall[wallfind[j]].point2].point2].y;
980
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
987
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
981
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
988
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
982
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
989
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
983
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L);
990
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L);
984
                }
991
                }
985
            }
992
            }
986
            else
993
            else
987
            {
994
            {
988
                //door was not closed
995
                //door was not closed
989
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
996
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
990
                dax2 = wall[i].x-wall[wallfind[j]].x;
997
                dax2 = wall[i].x-wall[wallfind[j]].x;
991
                day2 = wall[i].y-wall[wallfind[j]].y;
998
                day2 = wall[i].y-wall[wallfind[j]].y;
992
                if (dax2 != 0)
999
                if (dax2 != 0)
993
                {
1000
                {
994
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
1001
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
995
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
1002
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
996
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L);
1003
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L);
997
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L);
1004
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L);
998
                }
1005
                }
999
                else if (day2 != 0)
1006
                else if (day2 != 0)
1000
                {
1007
                {
1001
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
1008
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
1002
                    setanimation(&wall[i].y,centy+day2,4L,0L);
1009
                    setanimation(&wall[i].y,centy+day2,4L,0L);
1003
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L);
1010
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L);
1004
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L);
1011
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L);
1005
                }
1012
                }
1006
            }
1013
            }
1007
        }
1014
        }
1008
        wsayfollow("updowndr.wav",4096L-64L,256L,&centx,&centy,0);
1015
        wsayfollow("updowndr.wav",4096L-64L,256L,&centx,&centy,0);
1009
        wsayfollow("updowndr.wav",4096L+64L,256L,&centx,&centy,0);
1016
        wsayfollow("updowndr.wav",4096L+64L,256L,&centx,&centy,0);
1010
    }
1017
    }
1011
}
1018
}
1012
1019
1013
void operatesprite(short dasprite)
1020
void operatesprite(short dasprite)
1014
{
1021
{
1015
    int datag;
1022
    int datag;
1016
1023
1017
    datag = sprite[dasprite].lotag;
1024
    datag = sprite[dasprite].lotag;
1018
1025
1019
    if (datag == 2)    //A sprite that shoots a bomb
1026
    if (datag == 2)    //A sprite that shoots a bomb
1020
    {
1027
    {
1021
        vec3_t vector = { sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z };
1028
        vec3_t vector = { sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z };
1022
        shootgun(dasprite, &vector,
1029
        shootgun(dasprite, &vector,
1023
                 sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2);
1030
                 sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2);
1024
    }
1031
    }
1025
}
1032
}
1026
1033
1027
int changehealth(short snum, short deltahealth)
1034
int changehealth(short snum, short deltahealth)
1028
{
1035
{
1029
    // int dax, day;
1036
    // int dax, day;
1030
    // short good, k, startwall, endwall, s;
1037
    // short good, k, startwall, endwall, s;
1031
1038
1032
    if (health[snum] > 0)
1039
    if (health[snum] > 0)
1033
    {
1040
    {
1034
        health[snum] += deltahealth;
1041
        health[snum] += deltahealth;
1035
        if (health[snum] > 999) health[snum] = 999;
1042
        if (health[snum] > 999) health[snum] = 999;
1036
1043
1037
        if (health[snum] <= 0)
1044
        if (health[snum] <= 0)
1038
        {
1045
        {
1039
            health[snum] = -1;
1046
            health[snum] = -1;
1040
            wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1047
            wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1041
            sprite[playersprite[snum]].picnum = SKELETON;
1048
            sprite[playersprite[snum]].picnum = SKELETON;
1042
        }
1049
        }
1043
1050
1044
        if ((snum == screenpeek) && (screensize <= xdim))
1051
        if ((snum == screenpeek) && (screensize <= xdim))
1045
        {
1052
        {
1046
            if (health[snum] > 0)
1053
            if (health[snum] > 0)
1047
                sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1054
                sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1048
            else
1055
            else
1049
                sprintf((char *)tempbuf,"YOU STINK!");
1056
                sprintf((char *)tempbuf,"YOU STINK!");
1050
1057
1051
            printext((xdim>>1)-(Bstrlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
1058
            printext((xdim>>1)-(Bstrlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
1052
        }
1059
        }
1053
    }
1060
    }
1054
    return health[snum] <= 0;       //You were just injured
1061
    return health[snum] <= 0;       //You were just injured
1055
}
1062
}
1056
1063
1057
void changenumbombs(short snum, short deltanumbombs)     // Andy did this
1064
void changenumbombs(short snum, short deltanumbombs)     // Andy did this
1058
{
1065
{
1059
    numbombs[snum] += deltanumbombs;
1066
    numbombs[snum] += deltanumbombs;
1060
    if (numbombs[snum] > 999) numbombs[snum] = 999;
1067
    if (numbombs[snum] > 999) numbombs[snum] = 999;
1061
    if (numbombs[snum] <= 0)
1068
    if (numbombs[snum] <= 0)
1062
    {
1069
    {
1063
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1070
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1064
        numbombs[snum] = 0;
1071
        numbombs[snum] = 0;
1065
    }
1072
    }
1066
1073
1067
    if ((snum == screenpeek) && (screensize <= xdim))
1074
    if ((snum == screenpeek) && (screensize <= xdim))
1068
    {
1075
    {
1069
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1076
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1070
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1077
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1071
    }
1078
    }
1072
}
1079
}
1073
1080
1074
void changenummissiles(short snum, short deltanummissiles)     // Andy did this
1081
void changenummissiles(short snum, short deltanummissiles)     // Andy did this
1075
{
1082
{
1076
    nummissiles[snum] += deltanummissiles;
1083
    nummissiles[snum] += deltanummissiles;
1077
    if (nummissiles[snum] > 999) nummissiles[snum] = 999;
1084
    if (nummissiles[snum] > 999) nummissiles[snum] = 999;
1078
    if (nummissiles[snum] <= 0)
1085
    if (nummissiles[snum] <= 0)
1079
    {
1086
    {
1080
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1087
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1081
        nummissiles[snum] = 0;
1088
        nummissiles[snum] = 0;
1082
    }
1089
    }
1083
1090
1084
    if ((snum == screenpeek) && (screensize <= xdim))
1091
    if ((snum == screenpeek) && (screensize <= xdim))
1085
    {
1092
    {
1086
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1093
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1087
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1094
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1088
    }
1095
    }
1089
}
1096
}
1090
1097
1091
void changenumgrabbers(short snum, short deltanumgrabbers)     // Andy did this
1098
void changenumgrabbers(short snum, short deltanumgrabbers)     // Andy did this
1092
{
1099
{
1093
    numgrabbers[snum] += deltanumgrabbers;
1100
    numgrabbers[snum] += deltanumgrabbers;
1094
    if (numgrabbers[snum] > 999) numgrabbers[snum] = 999;
1101
    if (numgrabbers[snum] > 999) numgrabbers[snum] = 999;
1095
    if (numgrabbers[snum] <= 0)
1102
    if (numgrabbers[snum] <= 0)
1096
    {
1103
    {
1097
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1104
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1098
        numgrabbers[snum] = 0;
1105
        numgrabbers[snum] = 0;
1099
    }
1106
    }
1100
1107
1101
    if ((snum == screenpeek) && (screensize <= xdim))
1108
    if ((snum == screenpeek) && (screensize <= xdim))
1102
    {
1109
    {
1103
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1110
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1104
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
1111
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
1105
    }
1112
    }
1106
}
1113
}
1107
1114
1108
static int ostatusflytime = 0x80000000;
1115
static int ostatusflytime = 0x80000000;
1109
void drawstatusflytime(short snum)     // Andy did this
1116
void drawstatusflytime(short snum)     // Andy did this
1110
{
1117
{
1111
    int nstatusflytime;
1118
    int nstatusflytime;
1112
1119
1113
    if ((snum == screenpeek) && (screensize <= xdim))
1120
    if ((snum == screenpeek) && (screensize <= xdim))
1114
    {
1121
    {
1115
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1122
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1116
        if (nstatusflytime > 1000) nstatusflytime = 1000;
1123
        if (nstatusflytime > 1000) nstatusflytime = 1000;
1117
        else if (nstatusflytime < 0) nstatusflytime = 0;
1124
        else if (nstatusflytime < 0) nstatusflytime = 0;
1118
        if (nstatusflytime != ostatusflytime)
1125
        if (nstatusflytime != ostatusflytime)
1119
        {
1126
        {
1120
            if (nstatusflytime > 999) sprintf((char *)tempbuf,"FT:BIG");
1127
            if (nstatusflytime > 999) sprintf((char *)tempbuf,"FT:BIG");
1121
            else sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1128
            else sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1122
            printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1129
            printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1123
            ostatusflytime = nstatusflytime;
1130
            ostatusflytime = nstatusflytime;
1124
        }
1131
        }
1125
    }
1132
    }
1126
}
1133
}
1127
1134
1128
void drawstatusbar(short snum)     // Andy did this
1135
void drawstatusbar(short snum)     // Andy did this
1129
{
1136
{
1130
    int nstatusflytime;
1137
    int nstatusflytime;
1131
1138
1132
    if ((snum == screenpeek) && (screensize <= xdim))
1139
    if ((snum == screenpeek) && (screensize <= xdim))
1133
    {
1140
    {
1134
        sprintf((char *)tempbuf,"Deaths:%d",deaths[snum]);
1141
        sprintf((char *)tempbuf,"Deaths:%d",deaths[snum]);
1135
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-16,(char *)tempbuf,ALPHABET /*,80*/);
1142
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-16,(char *)tempbuf,ALPHABET /*,80*/);
1136
        sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1143
        sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1137
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
1144
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
1138
1145
1139
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1146
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1140
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1147
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1141
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1148
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1142
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1149
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1143
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1150
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1144
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
1151
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
1145
1152
1146
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1153
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1147
        if (nstatusflytime < 0)
1154
        if (nstatusflytime < 0)
1148
        {
1155
        {
1149
            sprintf((char *)tempbuf,"FT:  0");
1156
            sprintf((char *)tempbuf,"FT:  0");
1150
            ostatusflytime = 0;
1157
            ostatusflytime = 0;
1151
        }
1158
        }
1152
        else if (nstatusflytime > 999)
1159
        else if (nstatusflytime > 999)
1153
        {
1160
        {
1154
            sprintf((char *)tempbuf,"FT:BIG");
1161
            sprintf((char *)tempbuf,"FT:BIG");
1155
            ostatusflytime = 999;
1162
            ostatusflytime = 999;
1156
        }
1163
        }
1157
        else
1164
        else
1158
        {
1165
        {
1159
            sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1166
            sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1160
            ostatusflytime = nstatusflytime;
1167
            ostatusflytime = nstatusflytime;
1161
        }
1168
        }
1162
        printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1169
        printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1163
    }
1170
    }
1164
}
1171
}
1165
1172
1166
void prepareboard(char *daboardfilename)
1173
void prepareboard(char *daboardfilename)
1167
{
1174
{
1168
    short startwall, endwall, dasector;
1175
    short startwall, endwall, dasector;
1169
    int i, j, k=0, s, dax, day, /*daz,*/ dax2, day2;
1176
    int i, j, k=0, s, dax, day, /*daz,*/ dax2, day2;
1170
1177
1171
    getmessageleng = 0;
1178
    getmessageleng = 0;
1172
    typemessageleng = 0;
1179
    typemessageleng = 0;
1173
1180
1174
    randomseed = 17L;
1181
    randomseed = 17L;
1175
1182
1176
    //Clear (do)animation's list
1183
    //Clear (do)animation's list
1177
    animatecnt = 0;
1184
    animatecnt = 0;
1178
    typemode = 0;
1185
    typemode = 0;
1179
    locselectedgun = 0;
1186
    locselectedgun = 0;
1180
    locselectedgun2 = 0;
1187
    locselectedgun2 = 0;
1181
1188
1182
    if (engineLoadBoard(daboardfilename,0,&pos[0],&ang[0],&cursectnum[0]) == -1)
1189
    if (engineLoadBoard(daboardfilename,0,&pos[0],&ang[0],&cursectnum[0]) == -1)
1183
    {
1190
    {
1184
        musicoff();
1191
        musicoff();
1185
        uninitmultiplayers();
1192
        uninitmultiplayers();
1186
        timerUninit();
1193
        timerUninit();
1187
        uninitinput();
1194
        uninitinput();
1188
        uninitsb();
1195
        uninitsb();
1189
        engineUnInit();
1196
        engineUnInit();
1190
        uninitgroupfile();
1197
        uninitgroupfile();
1191
        printf("Board not found\n");
1198
        printf("Board not found\n");
1192
        exit(0);
1199
        exit(0);
1193
    }
1200
    }
1194
    else
1201
    else
1195
    {
1202
    {
1196
        char tempfn[BMAX_PATH + 1], *fp;
1203
        char tempfn[BMAX_PATH + 1], *fp;
1197
1204
1198
        strncpy(tempfn, daboardfilename, BMAX_PATH);
1205
        strncpy(tempfn, daboardfilename, BMAX_PATH);
1199
        tempfn[BMAX_PATH] = 0;
1206
        tempfn[BMAX_PATH] = 0;
1200
1207
1201
        fp = strrchr(tempfn,'.');
1208
        fp = strrchr(tempfn,'.');
1202
        if (fp) *fp = 0;
1209
        if (fp) *fp = 0;
1203
1210
1204
        if (strlen(tempfn) <= BMAX_PATH-4)
1211
        if (strlen(tempfn) <= BMAX_PATH-4)
1205
        {
1212
        {
1206
            strcat(tempfn,".mhk");
1213
            strcat(tempfn,".mhk");
1207
            engineLoadMHK(tempfn);
1214
            engineLoadMHK(tempfn);
1208
        }
1215
        }
1209
    }
1216
    }
1210
1217
1211
    setup3dscreen();
1218
    setup3dscreen();
1212
1219
1213
    for (i=0; i<MAXPLAYERS; i++)
1220
    for (i=0; i<MAXPLAYERS; i++)
1214
    {
1221
    {
1215
        pos[i] = pos[0];
1222
        pos[i] = pos[0];
1216
        ang[i] = ang[0];
1223
        ang[i] = ang[0];
1217
        cursectnum[i] = cursectnum[0];
1224
        cursectnum[i] = cursectnum[0];
1218
        ocursectnum[i] = cursectnum[0];
1225
        ocursectnum[i] = cursectnum[0];
1219
        horiz[i] = 100;
1226
        horiz[i] = 100;
1220
        lastchaingun[i] = 0;
1227
        lastchaingun[i] = 0;
1221
        health[i] = 100;
1228
        health[i] = 100;
1222
        dimensionmode[i] = 3;
1229
        dimensionmode[i] = 3;
1223
        numbombs[i] = 0;
1230
        numbombs[i] = 0;
1224
        numgrabbers[i] = 0;
1231
        numgrabbers[i] = 0;
1225
        nummissiles[i] = 0;
1232
        nummissiles[i] = 0;
1226
        flytime[i] = 0L;
1233
        flytime[i] = 0L;
1227
        zoom[i] = 768L;
1234
        zoom[i] = 768L;
1228
        deaths[i] = 0L;
1235
        deaths[i] = 0L;
1229
        playersprite[i] = -1;
1236
        playersprite[i] = -1;
1230
        screensize = xdim;
1237
        screensize = xdim;
1231
1238
1232
        opos[i] = pos[0];
1239
        opos[i] = pos[0];
1233
        ohoriz[i] = horiz[0];
1240
        ohoriz[i] = horiz[0];
1234
        ozoom[i] = zoom[0];
1241
        ozoom[i] = zoom[0];
1235
        oang[i] = ang[0];
1242
        oang[i] = ang[0];
1236
    }
1243
    }
1237
1244
1238
    my = omy = pos[myconnectindex];
1245
    my = omy = pos[myconnectindex];
1239
    myhoriz = omyhoriz = horiz[myconnectindex];
1246
    myhoriz = omyhoriz = horiz[myconnectindex];
1240
    myang = omyang = ang[myconnectindex];
1247
    myang = omyang = ang[myconnectindex];
1241
    mycursectnum = cursectnum[myconnectindex];
1248
    mycursectnum = cursectnum[myconnectindex];
1242
    myzvel = 0;
1249
    myzvel = 0;
1243
1250
1244
    movefifoplc = fakemovefifoplc = 0;
1251
    movefifoplc = fakemovefifoplc = 0;
1245
    syncvalhead = 0L; othersyncvalhead = 0L;
1252
    syncvalhead = 0L; othersyncvalhead = 0L;
1246
    syncvaltottail = 0L; syncvaltail = 0L;
1253
    syncvaltottail = 0L; syncvaltail = 0L;
1247
    numinterpolations = 0;
1254
    numinterpolations = 0;
1248
1255
1249
    clearbufbyte(&oloc,sizeof(input),0L);
1256
    clearbufbyte(&oloc,sizeof(input),0L);
1250
    for (i=0; i<MAXPLAYERS; i++)
1257
    for (i=0; i<MAXPLAYERS; i++)
1251
    {
1258
    {
1252
        movefifoend[i] = 0;
1259
        movefifoend[i] = 0;
1253
        clearbufbyte(&ffsync[i],sizeof(input),0L);
1260
        clearbufbyte(&ffsync[i],sizeof(input),0L);
1254
        clearbufbyte(&ssync[i],sizeof(input),0L);
1261
        clearbufbyte(&ssync[i],sizeof(input),0L);
1255
        clearbufbyte(&osync[i],sizeof(input),0L);
1262
        clearbufbyte(&osync[i],sizeof(input),0L);
1256
    }
1263
    }
1257
1264
1258
    //Scan sector tags
1265
    //Scan sector tags
1259
1266
1260
    for (i=0; i<MAXPLAYERS; i++)
1267
    for (i=0; i<MAXPLAYERS; i++)
1261
    {
1268
    {
1262
        waterfountainwall[i] = -1;
1269
        waterfountainwall[i] = -1;
1263
        waterfountaincnt[i] = 0;
1270
        waterfountaincnt[i] = 0;
1264
        slimesoundcnt[i] = 0;
1271
        slimesoundcnt[i] = 0;
1265
    }
1272
    }
1266
    warpsectorcnt = 0;      //Make a list of warping sectors
1273
    warpsectorcnt = 0;      //Make a list of warping sectors
1267
    xpanningsectorcnt = 0;  //Make a list of wall x-panning sectors
1274
    xpanningsectorcnt = 0;  //Make a list of wall x-panning sectors
1268
    floorpanningcnt = 0;    //Make a list of slime sectors
1275
    floorpanningcnt = 0;    //Make a list of slime sectors
1269
    dragsectorcnt = 0;      //Make a list of moving platforms
1276
    dragsectorcnt = 0;      //Make a list of moving platforms
1270
    swingcnt = 0;           //Make a list of swinging doors
1277
    swingcnt = 0;           //Make a list of swinging doors
1271
    revolvecnt = 0;         //Make a list of revolving doors
1278
    revolvecnt = 0;         //Make a list of revolving doors
1272
    subwaytrackcnt = 0;     //Make a list of subways
1279
    subwaytrackcnt = 0;     //Make a list of subways
1273
1280
1274
    floormirrorcnt = 0;
1281
    floormirrorcnt = 0;
1275
    tilesiz[FLOORMIRROR].x = 0;
1282
    tilesiz[FLOORMIRROR].x = 0;
1276
    tilesiz[FLOORMIRROR].y = 0;
1283
    tilesiz[FLOORMIRROR].y = 0;
1277
1284
1278
    for (i=0; i<numsectors; i++)
1285
    for (i=0; i<numsectors; i++)
1279
    {
1286
    {
1280
        switch (sector[i].lotag)
1287
        switch (sector[i].lotag)
1281
        {
1288
        {
1282
        case 4:
1289
        case 4:
1283
            floorpanninglist[floorpanningcnt++] = i;
1290
            floorpanninglist[floorpanningcnt++] = i;
1284
            break;
1291
            break;
1285
        case 10:
1292
        case 10:
1286
            warpsectorlist[warpsectorcnt++] = i;
1293
            warpsectorlist[warpsectorcnt++] = i;
1287
            break;
1294
            break;
1288
        case 11:
1295
        case 11:
1289
            xpanningsectorlist[xpanningsectorcnt++] = i;
1296
            xpanningsectorlist[xpanningsectorcnt++] = i;
1290
            break;
1297
            break;
1291
        case 12:
1298
        case 12:
1292
            dasector = i;
1299
            dasector = i;
1293
            dax = 0x7fffffff;
1300
            dax = 0x7fffffff;
1294
            day = 0x7fffffff;
1301
            day = 0x7fffffff;
1295
            dax2 = 0x80000000;
1302
            dax2 = 0x80000000;
1296
            day2 = 0x80000000;
1303
            day2 = 0x80000000;
1297
            startwall = sector[i].wallptr;
1304
            startwall = sector[i].wallptr;
1298
            endwall = startwall+sector[i].wallnum;
1305
            endwall = startwall+sector[i].wallnum;
1299
            for (j=startwall; j<endwall; j++)
1306
            for (j=startwall; j<endwall; j++)
1300
            {
1307
            {
1301
                if (wall[j].x < dax) dax = wall[j].x;
1308
                if (wall[j].x < dax) dax = wall[j].x;
1302
                if (wall[j].y < day) day = wall[j].y;
1309
                if (wall[j].y < day) day = wall[j].y;
1303
                if (wall[j].x > dax2) dax2 = wall[j].x;
1310
                if (wall[j].x > dax2) dax2 = wall[j].x;
1304
                if (wall[j].y > day2) day2 = wall[j].y;
1311
                if (wall[j].y > day2) day2 = wall[j].y;
1305
                if (wall[j].lotag == 3) k = j;
1312
                if (wall[j].lotag == 3) k = j;
1306
            }
1313
            }
1307
            if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16;
1314
            if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16;
1308
            if (wall[k].y == day) dragydir[dragsectorcnt] = -16;
1315
            if (wall[k].y == day) dragydir[dragsectorcnt] = -16;
1309
            if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16;
1316
            if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16;
1310
            if (wall[k].y == day2) dragydir[dragsectorcnt] = 16;
1317
            if (wall[k].y == day2) dragydir[dragsectorcnt] = 16;
1311
1318
1312
            dasector = wall[startwall].nextsector;
1319
            dasector = wall[startwall].nextsector;
1313
            dragx1[dragsectorcnt] = 0x7fffffff;
1320
            dragx1[dragsectorcnt] = 0x7fffffff;
1314
            dragy1[dragsectorcnt] = 0x7fffffff;
1321
            dragy1[dragsectorcnt] = 0x7fffffff;
1315
            dragx2[dragsectorcnt] = 0x80000000;
1322
            dragx2[dragsectorcnt] = 0x80000000;
1316
            dragy2[dragsectorcnt] = 0x80000000;
1323
            dragy2[dragsectorcnt] = 0x80000000;
1317
            startwall = sector[dasector].wallptr;
1324
            startwall = sector[dasector].wallptr;
1318
            endwall = startwall+sector[dasector].wallnum;
1325
            endwall = startwall+sector[dasector].wallnum;
1319
            for (j=startwall; j<endwall; j++)
1326
            for (j=startwall; j<endwall; j++)
1320
            {
1327
            {
1321
                if (wall[j].x < dragx1[dragsectorcnt]) dragx1[dragsectorcnt] = wall[j].x;
1328
                if (wall[j].x < dragx1[dragsectorcnt]) dragx1[dragsectorcnt] = wall[j].x;
1322
                if (wall[j].y < dragy1[dragsectorcnt]) dragy1[dragsectorcnt] = wall[j].y;
1329
                if (wall[j].y < dragy1[dragsectorcnt]) dragy1[dragsectorcnt] = wall[j].y;
1323
                if (wall[j].x > dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x;
1330
                if (wall[j].x > dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x;
1324
                if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y;
1331
                if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y;
1325
1332
1326
                setinterpolation(&sector[dasector].floorz);
1333
                setinterpolation(&sector[dasector].floorz);
1327
                setinterpolation(&wall[j].x);
1334
                setinterpolation(&wall[j].x);
1328
                setinterpolation(&wall[j].y);
1335
                setinterpolation(&wall[j].y);
1329
                auto const nextwall = wall[j].nextwall;
1336
                auto const nextwall = wall[j].nextwall;
1330
                if ((unsigned)nextwall < MAXWALLS)
1337
                if ((unsigned)nextwall < MAXWALLS)
1331
                {
1338
                {
1332
                    setinterpolation(&wall[nextwall].x);
1339
                    setinterpolation(&wall[nextwall].x);
1333
                    setinterpolation(&wall[nextwall].y);
1340
                    setinterpolation(&wall[nextwall].y);
1334
                }
1341
                }
1335
            }
1342
            }
1336
1343
1337
            dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax);
1344
            dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax);
1338
            dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day);
1345
            dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day);
1339
            dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x);
1346
            dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x);
1340
            dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y);
1347
            dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y);
1341
1348
1342
            dragfloorz[dragsectorcnt] = sector[i].floorz;
1349
            dragfloorz[dragsectorcnt] = sector[i].floorz;
1343
1350
1344
            dragsectorlist[dragsectorcnt++] = i;
1351
            dragsectorlist[dragsectorcnt++] = i;
1345
            break;
1352
            break;
1346
        case 13:
1353
        case 13:
1347
            startwall = sector[i].wallptr;
1354
            startwall = sector[i].wallptr;
1348
            endwall = startwall+sector[i].wallnum;
1355
            endwall = startwall+sector[i].wallnum;
1349
            for (j=startwall; j<endwall; j++)
1356
            for (j=startwall; j<endwall; j++)
1350
            {
1357
            {
1351
                if (wall[j].lotag == 4)
1358
                if (wall[j].lotag == 4)
1352
                {
1359
                {
1353
                    k = wall[wall[wall[wall[j].point2].point2].point2].point2;
1360
                    k = wall[wall[wall[wall[j].point2].point2].point2].point2;
1354
                    if ((wall[j].x == wall[k].x) && (wall[j].y == wall[k].y))
1361
                    if ((wall[j].x == wall[k].x) && (wall[j].y == wall[k].y))
1355
                    {
1362
                    {
1356
                        //Door opens counterclockwise
1363
                        //Door opens counterclockwise
1357
                        swingwall[swingcnt][0] = j;
1364
                        swingwall[swingcnt][0] = j;
1358
                        swingwall[swingcnt][1] = wall[j].point2;
1365
                        swingwall[swingcnt][1] = wall[j].point2;
1359
                        swingwall[swingcnt][2] = wall[wall[j].point2].point2;
1366
                        swingwall[swingcnt][2] = wall[wall[j].point2].point2;
1360
                        swingwall[swingcnt][3] = wall[wall[wall[j].point2].point2].point2;
1367
                        swingwall[swingcnt][3] = wall[wall[wall[j].point2].point2].point2;
1361
                        swingangopen[swingcnt] = 1536;
1368
                        swingangopen[swingcnt] = 1536;
1362
                        swingangclosed[swingcnt] = 0;
1369
                        swingangclosed[swingcnt] = 0;
1363
                        swingangopendir[swingcnt] = -1;
1370
                        swingangopendir[swingcnt] = -1;
1364
                    }
1371
                    }
1365
                    else
1372
                    else
1366
                    {
1373
                    {
1367
                        //Door opens clockwise
1374
                        //Door opens clockwise
1368
                        swingwall[swingcnt][0] = wall[j].point2;
1375
                        swingwall[swingcnt][0] = wall[j].point2;
1369
                        swingwall[swingcnt][1] = j;
1376
                        swingwall[swingcnt][1] = j;
1370
                        swingwall[swingcnt][2] = lastwall(j);
1377
                        swingwall[swingcnt][2] = lastwall(j);
1371
                        swingwall[swingcnt][3] = lastwall(swingwall[swingcnt][2]);
1378
                        swingwall[swingcnt][3] = lastwall(swingwall[swingcnt][2]);
1372
                        swingwall[swingcnt][4] = lastwall(swingwall[swingcnt][3]);
1379
                        swingwall[swingcnt][4] = lastwall(swingwall[swingcnt][3]);
1373
                        swingangopen[swingcnt] = 512;
1380
                        swingangopen[swingcnt] = 512;
1374
                        swingangclosed[swingcnt] = 0;
1381
                        swingangclosed[swingcnt] = 0;
1375
                        swingangopendir[swingcnt] = 1;
1382
                        swingangopendir[swingcnt] = 1;
1376
                    }
1383
                    }
1377
                    for (k=0; k<4; k++)
1384
                    for (k=0; k<4; k++)
1378
                    {
1385
                    {
1379
                        swingx[swingcnt][k] = wall[swingwall[swingcnt][k]].x;
1386
                        swingx[swingcnt][k] = wall[swingwall[swingcnt][k]].x;
1380
                        swingy[swingcnt][k] = wall[swingwall[swingcnt][k]].y;
1387
                        swingy[swingcnt][k] = wall[swingwall[swingcnt][k]].y;
1381
                    }
1388
                    }
1382
1389
1383
                    swingsector[swingcnt] = i;
1390
                    swingsector[swingcnt] = i;
1384
                    swingang[swingcnt] = swingangclosed[swingcnt];
1391
                    swingang[swingcnt] = swingangclosed[swingcnt];
1385
                    swinganginc[swingcnt] = 0;
1392
                    swinganginc[swingcnt] = 0;
1386
                    swingcnt++;
1393
                    swingcnt++;
1387
                }
1394
                }
1388
            }
1395
            }
1389
            break;
1396
            break;
1390
        case 14:
1397
        case 14:
1391
            startwall = sector[i].wallptr;
1398
            startwall = sector[i].wallptr;
1392
            endwall = startwall+sector[i].wallnum;
1399
            endwall = startwall+sector[i].wallnum;
1393
            dax = 0L;
1400
            dax = 0L;
1394
            day = 0L;
1401
            day = 0L;
1395
            for (j=startwall; j<endwall; j++)
1402
            for (j=startwall; j<endwall; j++)
1396
            {
1403
            {
1397
                dax += wall[j].x;
1404
                dax += wall[j].x;
1398
                day += wall[j].y;
1405
                day += wall[j].y;
1399
            }
1406
            }
1400
            revolvepivotx[revolvecnt] = dax / (endwall-startwall);
1407
            revolvepivotx[revolvecnt] = dax / (endwall-startwall);
1401
            revolvepivoty[revolvecnt] = day / (endwall-startwall);
1408
            revolvepivoty[revolvecnt] = day / (endwall-startwall);
1402
1409
1403
            k = 0;
1410
            k = 0;
1404
            for (j=startwall; j<endwall; j++)
1411
            for (j=startwall; j<endwall; j++)
1405
            {
1412
            {
1406
                revolvex[revolvecnt][k] = wall[j].x;
1413
                revolvex[revolvecnt][k] = wall[j].x;
1407
                revolvey[revolvecnt][k] = wall[j].y;
1414
                revolvey[revolvecnt][k] = wall[j].y;
1408
1415
1409
                setinterpolation(&wall[j].x);
1416
                setinterpolation(&wall[j].x);
1410
                setinterpolation(&wall[j].y);
1417
                setinterpolation(&wall[j].y);
1411
                setinterpolation(&wall[wall[j].nextwall].x);
1418
                setinterpolation(&wall[wall[j].nextwall].x);
1412
                setinterpolation(&wall[wall[j].nextwall].y);
1419
                setinterpolation(&wall[wall[j].nextwall].y);
1413
1420
1414
                k++;
1421
                k++;
1415
            }
1422
            }
1416
            revolvesector[revolvecnt] = i;
1423
            revolvesector[revolvecnt] = i;
1417
            revolveang[revolvecnt] = 0;
1424
            revolveang[revolvecnt] = 0;
1418
1425
1419
            revolvecnt++;
1426
            revolvecnt++;
1420
            break;
1427
            break;
1421
        case 15:
1428
        case 15:
1422
            subwaytracksector[subwaytrackcnt][0] = i;
1429
            subwaytracksector[subwaytrackcnt][0] = i;
1423
1430
1424
            subwaystopcnt[subwaytrackcnt] = 0;
1431
            subwaystopcnt[subwaytrackcnt] = 0;
1425
            dax = 0x7fffffff;
1432
            dax = 0x7fffffff;
1426
            day = 0x7fffffff;
1433
            day = 0x7fffffff;
1427
            dax2 = 0x80000000;
1434
            dax2 = 0x80000000;
1428
            day2 = 0x80000000;
1435
            day2 = 0x80000000;
1429
            startwall = sector[i].wallptr;
1436
            startwall = sector[i].wallptr;
1430
            endwall = startwall+sector[i].wallnum;
1437
            endwall = startwall+sector[i].wallnum;
1431
            for (j=startwall; j<endwall; j++)
1438
            for (j=startwall; j<endwall; j++)
1432
            {
1439
            {
1433
                if (wall[j].x < dax) dax = wall[j].x;
1440
                if (wall[j].x < dax) dax = wall[j].x;
1434
                if (wall[j].y < day) day = wall[j].y;
1441
                if (wall[j].y < day) day = wall[j].y;
1435
                if (wall[j].x > dax2) dax2 = wall[j].x;
1442
                if (wall[j].x > dax2) dax2 = wall[j].x;
1436
                if (wall[j].y > day2) day2 = wall[j].y;
1443
                if (wall[j].y > day2) day2 = wall[j].y;
1437
            }
1444
            }
1438
            for (j=startwall; j<endwall; j++)
1445
            for (j=startwall; j<endwall; j++)
1439
            {
1446
            {
1440
                if (wall[j].lotag == 5)
1447
                if (wall[j].lotag == 5)
1441
                {
1448
                {
1442
                    if ((wall[j].x > dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2))
1449
                    if ((wall[j].x > dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2))
1443
                    {
1450
                    {
1444
                        subwayx[subwaytrackcnt] = wall[j].x;
1451
                        subwayx[subwaytrackcnt] = wall[j].x;
1445
                    }
1452
                    }
1446
                    else
1453
                    else
1447
                    {
1454
                    {
1448
                        subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x;
1455
                        subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x;
1449
                        subwaystopcnt[subwaytrackcnt]++;
1456
                        subwaystopcnt[subwaytrackcnt]++;
1450
                    }
1457
                    }
1451
                }
1458
                }
1452
            }
1459
            }
1453
1460
1454
            for (j=1; j<subwaystopcnt[subwaytrackcnt]; j++)
1461
            for (j=1; j<subwaystopcnt[subwaytrackcnt]; j++)
1455
                for (k=0; k<j; k++)
1462
                for (k=0; k<j; k++)
1456
                    if (subwaystop[subwaytrackcnt][j] < subwaystop[subwaytrackcnt][k])
1463
                    if (subwaystop[subwaytrackcnt][j] < subwaystop[subwaytrackcnt][k])
1457
                    {
1464
                    {
1458
                        s = subwaystop[subwaytrackcnt][j];
1465
                        s = subwaystop[subwaytrackcnt][j];
1459
                        subwaystop[subwaytrackcnt][j] = subwaystop[subwaytrackcnt][k];
1466
                        subwaystop[subwaytrackcnt][j] = subwaystop[subwaytrackcnt][k];
1460
                        subwaystop[subwaytrackcnt][k] = s;
1467
                        subwaystop[subwaytrackcnt][k] = s;
1461
                    }
1468
                    }
1462
1469
1463
            subwaygoalstop[subwaytrackcnt] = 0;
1470
            subwaygoalstop[subwaytrackcnt] = 0;
1464
            for (j=0; j<subwaystopcnt[subwaytrackcnt]; j++)
1471
            for (j=0; j<subwaystopcnt[subwaytrackcnt]; j++)
1465
                if (klabs(subwaystop[subwaytrackcnt][j]-subwayx[subwaytrackcnt]) < klabs(subwaystop[subwaytrackcnt][subwaygoalstop[subwaytrackcnt]]-subwayx[subwaytrackcnt]))
1472
                if (klabs(subwaystop[subwaytrackcnt][j]-subwayx[subwaytrackcnt]) < klabs(subwaystop[subwaytrackcnt][subwaygoalstop[subwaytrackcnt]]-subwayx[subwaytrackcnt]))
1466
                    subwaygoalstop[subwaytrackcnt] = j;
1473
                    subwaygoalstop[subwaytrackcnt] = j;
1467
1474
1468
            subwaytrackx1[subwaytrackcnt] = dax;
1475
            subwaytrackx1[subwaytrackcnt] = dax;
1469
            subwaytracky1[subwaytrackcnt] = day;
1476
            subwaytracky1[subwaytrackcnt] = day;
1470
            subwaytrackx2[subwaytrackcnt] = dax2;
1477
            subwaytrackx2[subwaytrackcnt] = dax2;
1471
            subwaytracky2[subwaytrackcnt] = day2;
1478
            subwaytracky2[subwaytrackcnt] = day2;
1472
1479
1473
            subwaynumsectors[subwaytrackcnt] = 1;
1480
            subwaynumsectors[subwaytrackcnt] = 1;
1474
            for (j=0; j<numsectors; j++)
1481
            for (j=0; j<numsectors; j++)
1475
                if (j != i)
1482
                if (j != i)
1476
                {
1483
                {
1477
                    startwall = sector[j].wallptr;
1484
                    startwall = sector[j].wallptr;
1478
                    if (wall[startwall].x > subwaytrackx1[subwaytrackcnt])
1485
                    if (wall[startwall].x > subwaytrackx1[subwaytrackcnt])
1479
                        if (wall[startwall].y > subwaytracky1[subwaytrackcnt])
1486
                        if (wall[startwall].y > subwaytracky1[subwaytrackcnt])
1480
                            if (wall[startwall].x < subwaytrackx2[subwaytrackcnt])
1487
                            if (wall[startwall].x < subwaytrackx2[subwaytrackcnt])
1481
                                if (wall[startwall].y < subwaytracky2[subwaytrackcnt])
1488
                                if (wall[startwall].y < subwaytracky2[subwaytrackcnt])
1482
                                {
1489
                                {
1483
                                    if (sector[j].floorz != sector[i].floorz)
1490
                                    if (sector[j].floorz != sector[i].floorz)
1484
                                    {
1491
                                    {
1485
                                        sector[j