1 #ifndef MAP_H
2 #define MAP_H
3 
4 /** The protocol supports 10 layers, so set MAXLAYERS accordingly.
5  */
6 #define MAXLAYERS 10
7 
8 /**
9  * Maximum size of view area a server could support.
10  */
11 #define MAX_VIEW 64
12 
13 /* Map1 only used 3 layers.  Trying to use 10 seems to cause
14  * problems for that code.
15  */
16 #define MAP1_LAYERS 3
17 
18 struct MapCellLayer {
19     gint16 face;
20     gint8 size_x;
21     gint8 size_y;
22 
23     /* Link into animation information.
24      * animation is provided to us from the server in the map2 command.
25      * animation_speed is also provided.
26      * animation_left is how many ticks until animation changes - generated
27      *  by client.
28      * animation_phase is current phase.
29      */
30     gint16  animation;
31     guint8   animation_speed;
32     guint8   animation_left;
33     guint8   animation_phase;
34 };
35 
36 struct MapCellTailLayer {
37     gint16 face;
38     gint8 size_x;
39     gint8 size_y;
40 };
41 
42 /** The heads[] in the mapcell is used for single part objects
43  * or the head piece for multipart.  The easiest way to think about
44  * it is that the heads[] contains the map information as specifically
45  * sent from the server.  For the heads value, the size_x and size_y
46  * represent how many spaces (up and to the left) that image extends
47  * into.
48  * The tails are values that the client fills in - if we get
49  * a big head value, we fill in the tails value so that the display
50  * logic can easily redraw one space.  In this case, the size_ values
51  * are offsets that point to the head.  In this way, the draw logic
52  * can look at the size of the image, look at these values, and
53  * know what portion of it to draw.
54  */
55 struct MapCell
56 {
57     struct MapCellLayer heads[MAXLAYERS];
58     struct MapCellTailLayer tails[MAXLAYERS];
59     guint8 smooth[MAXLAYERS];
60     guint8 darkness;         /* darkness: 0=fully illuminated, 255=pitch black */
61     guint8 need_update:1;    /* set if tile should be redrawn */
62     guint8 have_darkness:1;  /* set if darkness information was set */
63     guint8 need_resmooth:1;  /* same has need update but for smoothing only */
64     guint8 cleared:1;        /* If set, this is a fog cell. */
65 };
66 
67 struct Map
68 {
69     struct MapCell **_cells; //< data, access via mapdata_cells()
70     int width;  //< width of cells array
71     int height; //< height of cells array
72 };
73 
74 struct MapCell *mapdata_cell(int x, int y);
75 bool mapdata_contains(int x, int y);
76 void mapdata_size(int *x, int *y);
77 bool mapdata_can_smooth(int x, int y, int layer);
78 
79 /**
80  * Initializes the module. Allocates memory for the_map. This functions must be
81  * called before any other function is used, and whenever a new display size
82  * was negotiated with the server.
83  */
84 void mapdata_set_size(int viewx, int viewy);
85 
86 /**
87  * Deallocate map data. Do not call functions other than mapdata_set_size()
88  * after calling mapdata_free().
89  */
90 void mapdata_free(void);
91 
92 /**
93  * Scrolls the map view. Must be called whenever a map_scroll command was
94  * received from the server.
95  */
96 void mapdata_scroll(int dx, int dy);
97 
98 /**
99  * Clears the map view. Must be called whenever a newmap command was received
100  * from the server.
101  */
102 void mapdata_newmap(void);
103 
104 /**
105  * Checks whether the given coordinates are within the current display size (as
106  * set by mapdata_set_size).
107  */
108 int mapdata_is_inside(int x, int y);
109 
110 /**
111  * Returns the face to display at a given location. This function returns the
112  * "head" information, i.e. the face information sent by the server.
113  */
114 gint16 mapdata_face(int x, int y, int layer) __attribute__((deprecated));
115 
116 /**
117  * Return the face number of the pixmap in the given map cell and set the
118  * offset pointers to indicate where to correctly draw the face. Offsets are
119  * zero for single-tile maps and negative for multi-tile maps. This provides
120  * a consistent way to draw tiles no matter single or multi part.
121  * @param mx Virtual map x-coordinate
122  * @param my Virtual map y-coordinate
123  * @param layer Map layer number
124  * @param dx Pointer to store x-offset
125  * @param dy Pointer to store y-offset
126  * @return Pixmap face number, zero if the tile does not exist
127  */
128 gint16 mapdata_face_info(int mx, int my, int layer, int *dx, int *dy);
129 
130 /**
131  * Returns the face to display at a given location. This function returns the
132  * "tail" information, i.e. big faces expanded by the client.
133  *
134  * *ww and *hh return the offset of the current tile relative to the head;
135  * 0 <= *ww < (width of face), 0 <= *hh < (height of face).
136  *
137  * When drawing the map view, this function must be used instead than a direct
138  * access to the_map.cells[]. This is because the_map.cells[] eventually still
139  * contains obsolete (fog of war) big face information; this function detects
140  * and clears such faces.
141  */
142 gint16 mapdata_bigface(int x, int y, int layer, int *ww, int *hh);
143 
144 void mapdata_clear_space(int x, int y);
145 void mapdata_set_check_space(int x, int y);
146 void mapdata_set_darkness(int x, int y, int darkness);
147 void mapdata_set_smooth(int x, int y, guint8 smooth, int layer);
148 void mapdata_clear_old(int x, int y);
149 void mapdata_set_face_layer(int x, int y, gint16 face, int layer);
150 void mapdata_set_anim_layer(int x, int y, guint16 anim, guint8 anim_speed, int layer);
151 gint16 mapdata_bigface_head(int x, int y, int layer, int *ww, int *hh);
152 void mapdata_animation(void);
153 
154 extern PlayerPosition script_pos;
155 
156 extern int global_offset_x, want_offset_x;
157 extern int global_offset_y, want_offset_y;
158 
159 #endif
160