-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbmap.h
123 lines (95 loc) · 3.47 KB
/
bmap.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
//
// bmap.h
// XBolo Map Editor
//
// Created by Robert Chrzanowski on 10/11/09.
// Copyright 2009 Robert Chrzanowski. All rights reserved.
//
#ifndef __BMAP__
#define __BMAP__
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#define CURRENT_MAP_VERSION (1)
#define MAX_PLAYERS (16)
#define MAX_PILLS (16)
#define MAX_BASES (16)
#define MAX_STARTS (16)
#define MAX_PILL_ARMOUR (15)
#define MAX_PILL_SPEED (50)
#define MAX_BASE_ARMOUR (90)
#define MAX_BASE_SHELLS (90)
#define MAX_BASE_MINES (90)
#define MINE_BORDER_WIDTH (10)
#define X_MIN_MINE (10)
#define Y_MIN_MINE (10)
#define X_MAX_MINE (245)
#define Y_MAX_MINE (245)
#define MAP_FILE_IDENT ("BMAPBOLO")
#define MAP_FILE_IDENT_LEN (8)
#define WIDTH (256)
#define FWIDTH (256.0)
#define NEUTRAL (0xff)
struct BMAP_Preamble {
uint8_t ident[8]; // "BMAPBOLO"
uint8_t version; // currently 0
uint8_t npills; // maximum 16 (at the moment)
uint8_t nbases; // maximum 16 (at the moment)
uint8_t nstarts; // maximum 16 (at the moment)
} __attribute__((__packed__));
struct BMAP_PillInfo {
uint8_t x;
uint8_t y;
uint8_t owner; // should be 0xFF except in speciality maps
uint8_t armour; // range 0-15 (dead pillbox = 0, full strength = 15)
uint8_t speed; // typically 50. Time between shots, in 20ms units
// Lower values makes the pillbox start off 'angry'
} __attribute__((__packed__));
struct BMAP_BaseInfo {
uint8_t x;
uint8_t y;
uint8_t owner; // should be 0xFF except in speciality maps
uint8_t armour; // initial stocks of base. Maximum value 90
uint8_t shells; // initial stocks of base. Maximum value 90
uint8_t mines; // initial stocks of base. Maximum value 90
} __attribute__((__packed__));
struct BMAP_StartInfo {
uint8_t x;
uint8_t y;
uint8_t dir; // Direction towards land from this start. Range 0-15
} __attribute__((__packed__));
struct BMAP_Run {
uint8_t datalen; // length of the data for this run
// INCLUDING this 4 byte header
uint8_t y; // y co-ordinate of this run.
uint8_t startx; // first square of the run
uint8_t endx; // last square of run + 1
// (ie first deep sea square after run)
// uint8_t data[0xFF]; // actual length of data is always much less than 0xFF
} __attribute__((__packed__));
#include "rect.h"
#include "tiles.h"
#include "images.h"
extern const GSRect kWorldRect;
extern const GSRect kSeaRect;
extern const float k2Pif;
GSTile defaultTile(int x, int y);
int readRun(size_t *y, size_t *x, struct BMAP_Run *run, void *data, GSTile tiles[][WIDTH]);
int writeRun(struct BMAP_Run run, const void *buf, GSTile tiles[][WIDTH]);
// load/save map
int loadMap(const void *buf, size_t nbytes, struct BMAP_Preamble *preamble,
struct BMAP_PillInfo pills[], struct BMAP_BaseInfo bases[],
struct BMAP_StartInfo starts[], GSTile tiles[][WIDTH]);
ssize_t saveMap(void **data, struct BMAP_Preamble *preamble,
struct BMAP_PillInfo pills[], struct BMAP_BaseInfo bases[],
struct BMAP_StartInfo starts[], GSTile tiles[][WIDTH]);
GSTile appropriateTileForPill(GSTile tile);
GSTile appropriateTileForBase(GSTile tile);
GSTile appropriateTileForStart(GSTile tile);
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
#endif // __BMAP__