-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbolo.h
513 lines (443 loc) · 11.1 KB
/
bolo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/*
* bolo.h
* XBolo
*
* Created by Robert Chrzanowski on 11/1/04.
* Copyright 2004 Robert Chrzanowski. All rights reserved.
*
*/
#ifndef __BOLO__
#define __BOLO__
#include "vector.h"
#include "rect.h"
#include "list.h"
#include "io.h"
#include "errchk.h"
#include "timing.h"
#include "terrain.h"
#include "tiles.h"
#include "images.h"
#include <stdint.h>
#include <errno.h>
#define CURRENT_MAP_VERSION (1)
#define NET_GAME_VERSION (1)
#define MAXPLAYERS (16)
#define MAXPILLS (16)
#define MAXBASES (16)
#define MAX_STARTS (16)
#define MINEWIDTH (10)
#define X_MIN_MINE (10)
#define Y_MIN_MINE (10)
#define X_MAX_MINE (245)
#define Y_MAX_MINE (245)
#define NET_GAME_IDENT ("XBOLOGAM")
#define MAP_FILE_IDENT ("BMAPBOLO")
#define MAP_FILE_IDENT_LEN (8)
#define NEUTRAL (0xff)
#define TICKSPERSEC (50)
#define MAXTICKSPERSHOT (100)
#define MINTICKSPERSHOT (6)
#define COOLPILLTICKS (32)
#define EXPLODETICKS (45)
#define REPLENISHBASETICKS (600)
#define REFUELARMOURTICKS (46)
#define REFUELSHELLSTICKS (7)
#define REFUELMINESTICKS (7)
#define DRAINTICKS (15)
#define TICKS_PER_FRAME (USEC_PER_SEC / TICKSPERSEC)
#define ONBOARD (0xff)
#define MAXSHELLS (40)
#define MAXMINES (40)
#define MAXARMOUR (40)
#define MAXTREES (40)
#define MAXNAME (16)
#define MAXPASS (32)
#define MAXHOST (32)
#define CLUPDATEMAXSHELLS (255)
#define CLUPDATEMAXEXPLOSIONS (255)
#define RECVMAPBLOCKSIZE (1024)
#define NOPILL (0xff)
#define WIDTH (256)
#define FWIDTH (256.0)
#define PLANTERWIDTH (32) /* must divide width evenly */
#define SHELLVEL (7.0)
#define SHELLRATE (4)
#define DRANGE (TICKSPERSEC / 6.0) /* 1 tile per 12 ticks */
#define MINRANGE (1.0)
#define MAXRANGE (7.0)
#define TANKRADIUS (0.375)
#define BUILDERRADIUS (0.125)
#define EXPLOSIONRADIUS (0.5)
#define BOATMAXSPEED (3.125) /* squares per second */
#define ROADMAXSPEED BOATMAXSPEED
#define GRASSMAXSPEED (2.34375)
#define FORESTMAXSPEED (1.171875)
#define RUBBLEMAXSPEED (0.5859375)
#define TICKS_FOR_COMPLETE_STOP (64)
#define ACCEL (BOATMAXSPEED * TICKSPERSEC / TICKS_FOR_COMPLETE_STOP) /* squares per second per second */
#define ANGULARACCEL (12.5663706143592) /* radians per second per second */
#define BUILDERMAXSPEED ROADMAXSPEED
#define PARACHUTESPEED RUBBLEMAXSPEED
#define MAXANGULARVELOCITY (2.5)
#define PUSHFORCE (1.5625)
#define KICKFORCE (3.125)
#define BUILDERBUILDTIME (20)
#define CHAINTICKS (6)
#define FLOODTICKS (12)
#define RESPAWN_TICKS (150)
#define EXPLOSIONTICKS (24)
#define MAXPILLARMOUR (15)
#define FORRESTTREES (4)
#define ROADTREES (2)
#define WALLTREES (2)
#define BOATTREES (20)
#define PILLTREES (4)
#define MAXBASEARMOUR (90)
#define MAXBASESHELLS (90)
#define MAXBASEMINES (90)
#define MINBASEARMOUR (5)
#define MINBASESHELLS (1)
#define MINBASEMINES (1)
#define TREESBESTOF (4200) /* works best if is multiple of TREESPLANTRATE*TICKSPERSEC */
#define TREESPLANTRATE (10)
/* key masks */
#define ACCELMASK (0x00000001)
#define BRAKEMASK (0x00000002)
#define TURNLMASK (0x00000004)
#define TURNRMASK (0x00000008)
#define LMINEMASK (0x00000010)
#define SHOOTMASK (0x00000020)
#define INCREMASK (0x00000040)
#define DECREMASK (0x00000080)
/* regular expression errors */
#define EREG_OFFSET (ELAST + 16) /* Add this to regualar expression errors */
#define EREG_NOMATCH (EREG_OFFSET + EREG_NOMATCH) /* The regexec() function failed to match */
#define EREG_BADPAT (EREG_OFFSET + EREG_BADPAT) /* invalid regular expression */
#define EREG_ECOLLATE (EREG_OFFSET + EREG_ECOLLATE) /* invalid collating element */
#define EREG_ECTYPE (EREG_OFFSET + EREG_ECTYPE) /* invalid character class */
#define EREG_EESCAPE (EREG_OFFSET + EREG_EESCAPE) /* `\' applied to unescapable character */
#define EREG_ESUBREG (EREG_OFFSET + EREG_ESUBREG) /* invalid backreference number */
#define EREG_EBRACK (EREG_OFFSET + EREG_EBRACK) /* brackets `[ ]' not balanced */
#define EREG_EPAREN (EREG_OFFSET + EREG_EPAREN) /* parentheses `( )' not balanced */
#define EREG_EBRACE (EREG_OFFSET + EREG_EBRACE) /* braces `{ }' not balanced */
#define EREG_BADBR (EREG_OFFSET + EREG_BADBR) /* invalid repetition count(s) in `{ }' */
#define EREG_ERANGE (EREG_OFFSET + EREG_ERANGE) /* invalid character range in `[ ]' */
#define EREG_ESPACE (EREG_OFFSET + EREG_ESPACE) /* ran out of memory */
#define EREG_BADRPT (EREG_OFFSET + EREG_BADRPT) /* `?', `*', or `+' operand invalid */
#define EREG_EMPTY (EREG_OFFSET + EREG_EMPTY) /* empty (sub)expression */
#define EREG_ASSERT (EREG_OFFSET + EREG_ASSERT) /* cannot happen - you found a bug */
#define EREG_INVARG (EREG_OFFSET + EREG_INVARG) /* invalid argument, e.g. negative-length string */
#define EREG_ILLSEQ (EREG_OFFSET + EREG_ILLSEQ) /* illegal byte sequence (bad multibyte character) */
enum {
BUILDERNILL = -1,
BUILDERTREE,
BUILDERROAD,
BUILDERWALL,
BUILDERPILL,
BUILDERMINE,
} ;
enum {
MSGEVERYONE,
MSGALLIES,
MSGNEARBY,
MSGGAME,
} ;
/* client message types */
enum {
kHangupClientMessage,
CLSENDMESG,
CLDROPBOAT,
CLDROPPILLS,
CLDROPMINE,
CLTOUCH,
CLGRABTILE,
CLGRABTREES,
CLBUILDROAD,
CLBUILDWALL,
CLBUILDBOAT,
CLBUILDPILL,
CLREPAIRPILL,
CLPLACEMINE,
CLDAMAGE,
CLSMALLBOOM,
CLSUPERBOOM,
CLREFUEL,
CLHITTANK,
CLSETALLIANCE,
} ;
/* join messages */
enum {
kBadVersionJOIN,
kDisallowJOIN,
kBadPasswordJOIN,
kServerFullJOIN,
kServerTimeLimitReachedJOIN,
kBannedPlayerJOIN,
kSendingPreambleJOIN,
} ;
/* server messages */
enum {
SRPLAYERJOIN,
SRPLAYERREJOIN,
SRPLAYEREXIT,
SRPLAYERDISC,
SRPLAYERKICK,
SRPLAYERBAN,
SRHANGUP, // not used
SRSENDMESG,
SRDAMAGE,
SRGRABTREES,
SRBUILD,
SRGROW,
SRFLOOD,
SRPLACEMINE,
SRDROPMINE,
SRDROPBOAT,
SRREPAIRPILL,
SRCOOLPILL,
SRCAPTUREPILL,
SRBUILDPILL,
SRDROPPILL,
SRREPLENISHBASE,
SRCAPTUREBASE,
SRREFUEL,
SRGRABBOAT,
SRMINEACK,
SRBUILDERACK,
SRSMALLBOOM,
SRSUPERBOOM,
SRHITTANK,
SRSETALLIANCE,
SRTIMELIMIT,
SRBASECONTROL,
SRPAUSE,
} ;
/* join status */
enum {
kJoinRESOLVING,
kJoinCONNECTING,
kJoinSENDJOIN,
kJoinRECVPREAMBLE,
kJoinRECVMAP,
kJoinSUCCESS,
/* errors */
/* dns errors */
kJoinEHOSTNOTFOUND,
kJoinEHOSTNORECOVERY,
kJoinEHOSTNODATA,
/* connecion errors */
kJoinETIMEOUT,
kJoinECONNREFUSED,
kJoinENETUNREACH,
kJoinEHOSTUNREACH,
/* other errors */
kJoinEBADVERSION,
kJoinEDISALLOW,
kJoinEBADPASS,
kJoinESERVERFULL,
kJoinETIMELIMIT,
kJoinEBANNEDPLAYER,
/* server errors */
kJoinESERVERERROR,
kJoinECONNRESET,
} ;
/* register tracker status */
enum {
kRegisterRESOLVING,
kRegisterCONNECTING,
kRegisterSENDINGDATA,
kRegisterTESTINGTCP,
kRegisterTESTINGUDP,
kRegisterSUCCESS,
/* dns errors */
kRegisterEHOSTNOTFOUND,
kRegisterEHOSTNORECOVERY,
kRegisterEHOSTNODATA,
/* connection errors */
kRegisterETIMEOUT,
kRegisterECONNREFUSED,
kRegisterEHOSTDOWN,
kRegisterEHOSTUNREACH,
kRegisterEBADVERSION,
kRegisterETCPCLOSED,
kRegisterEUDPCLOSED,
kRegisterECONNRESET,
} ;
enum {
kGetListTrackerRESOLVING,
kGetListTrackerCONNECTING,
kGetListTrackerREGISTERING,
kGetListTrackerGETTINGLIST,
kGetListTrackerSUCCESS,
/* dns errors */
kGetListTrackerEHOSTNOTFOUND,
kGetListTrackerEHOSTNORECOVERY,
kGetListTrackerEHOSTNODATA,
/* connection errors */
kGetListTrackerECONNABORTED,
kGetListTrackerETIMEOUT,
kGetListTrackerECONNREFUSED,
kGetListTrackerEHOSTDOWN,
kGetListTrackerEHOSTUNREACH,
kGetListTrackerEPIPE,
/* version error */
kGetListTrackerEBADVERSION,
} ;
/* game types */
enum {
kDominationGameType = 0,
kCTFGameType,
kKOTHGameType,
kBallGameType,
kBodyGameType,
} ;
/* domination types */
enum {
kOpenGame = 0,
kTournamentGame,
kStrictGame,
} ;
/* udp updates */
enum {
kTankDead = 0,
kTankFireball,
kTankOnBoat,
kTankNormal,
} ;
/* builder status */
enum {
kBuilderReady = 0,
kBuilderGoto,
kBuilderWork,
kBuilderWait,
kBuilderReturn,
kBuilderParachute,
} ;
/* builder tasks */
enum {
kBuilderDoNothing,
kBuilderGetTree,
kBuilderBuildRoad,
kBuilderBuildWall,
kBuilderBuildBoat,
kBuilderBuildPill,
kBuilderRepairPill,
kBuilderPlaceMine,
} ;
/* sounds */
enum {
kBubblesSound,
kBuildSound,
kBuilderDeathSound,
kExplosionSound,
kFarBuildSound,
kFarBuilderDeathSound,
kFarExplosionSound,
kFarHitTankSound,
kFarHitTerrainSound,
kFarHitTreeSound,
kFarShotSound,
kFarSinkSound,
kFarSuperBoomSound,
kFarTreeSound,
kHitTankSound,
kHitTerrainSound,
kHitTreeSound,
kMineSound,
kMsgReceivedSound,
kPillShotSound,
kSinkSound,
kSuperBoomSound,
kTankShotSound,
kTreeSound
} ;
/* shared data structures */
struct Pill {
int x;
int y;
int owner;
int armour;
int speed;
int counter;
} ;
struct Base {
int x;
int y;
int owner;
int armour;
int shells;
int mines;
int counter;
} ;
struct Start {
int x;
int y;
int dir;
} ;
struct Shell {
int owner;
Vec2f point;
int boat;
int pill;
float dir;
float range;
} ;
struct Explosion {
Vec2f point;
int counter;
} ;
struct Domination {
int type;
int basecontrol;
} ;
struct JOIN_Preamble {
uint8_t ident[8]; /* "XBOLOGAM" */
uint8_t version; /* currently 0 */
char name[MAXNAME]; /* NULL terminated name */
char pass[MAXPASS]; /* NULL terminated password */
} __attribute__((__packed__));
/*
* Runningbolo() returns true if there is a game in progress.
*/
int allowjoinserver();
/*
* Initbolo() needs to be called once to initialize bolo. Returns 0 on
* success or -1 on failure and sets errno.
*/
int initbolo(
void (*setplayerstatusfunc)(int player),
void (*setpillstatusfunc)(int pill),
void (*setbasestatusfunc)(int base),
void (*settankstatusfunc)(),
void (*playsound)(int sound),
void (*printmessagefunc)(int type, const char *text),
void (*joinprogress)(int statuscode, float scale),
void (*clientloopupdate)(void)
);
/*
* Closegame() closes the game and releases all game resources.
* Returns 0 on success -1 on failure and sets errno.
*/
void pauseresumegame();
void togglejoingame();
int listtracker(
const char trackerhostname[], struct ListNode *node,
void(*trackerprogress)(int statuscode)
);
void stoptracker();
Vec2f dir2vec(float dir);
/*
* Calcvis() returns a value between 0.0 and 1.0 based on how visible it is.
*/
float fogvis(Vec2f v);
float forestvis(Vec2f v);
float calcvis(Vec2f v);
float vec2dir(Vec2f v);
Vec2f dir2vec(float f);
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
#endif /* __BOLO__ */