4 // Copyright 2007, 2008 Lancer-X/ASCEAI
6 // This file is part of Meritous.
8 // Meritous is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
13 // Meritous is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with Meritous. If not, see <http://www.gnu.org/licenses/>.
26 #include <SDL_image.h>
28 #include "levelblit.h"
33 SDL_Surface
*automap
= NULL
;
34 void RecordRoom(int room_id
);
37 int c_scroll_x
=0, c_scroll_y
=0;
38 SDL_Surface
*overview
= NULL
;
43 if (automap
!= NULL
) SDL_FreeSurface(automap
);
44 if (overview
!= NULL
) SDL_FreeSurface(overview
);
46 automap
= IMG_Load("dat/i/automap.png"); //520x520
47 overview
= IMG_Load("dat/i/overview.png"); //200x200
49 //SDL_SetColorKey(automap, SDL_SRCCOLORKEY | SDL_RLEACCEL, 255);
56 for (i
= 0; i
< 3000; i
++) {
57 if (rooms
[i
].visited
) {
61 RecordRoom(player_room
);
71 for (y
= 0; y
< map
.h
; y
++) {
72 for (x
= 0; x
< map
.w
; x
++) {
73 if (TileData
[Get(x
, y
)].Is_Solid
) {
74 if (Get(x
, y
) != 17) {
75 pix
= automap
->pixels
;
76 pix
+= automap
->w
* (y
+ 4);
81 pix
= automap
->pixels
;
82 pix
+= automap
->w
* (y
+ 4);
89 for (i
= 0; i
< 3000; i
++) {
90 if (rooms
[i
].visited
) {
94 RecordRoom(player_room
);
101 DrawRect(0, 466, 640, 14, 0);
102 DrawRect(1, 467, 638, 12, 32);
103 DrawRect(2, 468, 636, 10, 64);
105 draw_text(115, 470, "Scroll: [Arrow keys]. Scroll faster: hold [Space]. Close: [Tab].", 200);
106 draw_text(3, 469, "Map", 200);
108 draw_text(3, 469, "Teleport to checkpoint", 200);
112 void DisplayRoom(int room_id
, Uint8 room_bg
)
119 for (y
= 0; y
< rooms
[room_id
].h
; y
++) {
120 for (x
= 0; x
< rooms
[room_id
].w
; x
++) {
121 rx
= x
+ rooms
[room_id
].x
;
122 ry
= y
+ rooms
[room_id
].y
;
124 pix
= automap
->pixels
;
125 pix
+= automap
->w
* (ry
+ 4);
128 *pix
= automap_cols
[TileData
[Get(rx
, ry
)].Type
];
129 if (*pix
== 192) *pix
= room_bg
;
133 fill
.x
= rooms
[room_id
].x
* 200 / 512;
134 fill
.y
= rooms
[room_id
].y
* 200 / 512;
135 fill
.w
= rooms
[room_id
].w
* 200 / 512;
136 fill
.h
= rooms
[room_id
].h
* 200 / 512;
138 SDL_FillRect(overview
, &fill
, 200);
141 void RecordRoom(int room_id
)
143 static int last_player_room
= -1;
144 if (last_player_room
!= -1) {
145 if (rooms
[last_player_room
].checkpoint
) DisplayRoom(last_player_room
, 150 - (rooms
[last_player_room
].s_dist
/5*12));
146 else DisplayRoom(last_player_room
, 192 - (rooms
[last_player_room
].s_dist
/5*12));
148 last_player_room
= room_id
;
149 DisplayRoom(room_id
, 0);
152 void DisplayAutomap()
161 int nearest_checkpoint
;
163 unsigned char xcol
= 0;
165 int minimap_scroll_x
, minimap_scroll_y
;
168 c_scroll_y
-= 32 + (HoldsPsi()*64);
171 c_scroll_y
+= 32 + (HoldsPsi()*64);
174 c_scroll_x
-= 32 + (HoldsPsi()*64);
177 c_scroll_x
+= 32 + (HoldsPsi()*64);
180 if (c_scroll_x
< 0) c_scroll_x
= 0;
181 if (c_scroll_y
< 0) c_scroll_y
= 0;
182 if (c_scroll_x
>= 512*32) c_scroll_x
= 512*32 - 32;
183 if (c_scroll_y
>= 512*32) c_scroll_y
= 512*32 - 32;
185 nearest_checkpoint
= GetNearestCheckpoint(c_scroll_x
, c_scroll_y
);
187 if (artifacts
[0] && (!full_rend
)) FullRender();
189 minimap_scroll_x
= c_scroll_x
/ 32 - 200 / 2;
190 minimap_scroll_y
= c_scroll_y
/ 32 - 229 / 2;
191 if (minimap_scroll_x
< 0) minimap_scroll_x
= 0;
192 if (minimap_scroll_y
< 0) minimap_scroll_y
= 0;
194 if (minimap_scroll_x
>= 512 - 200) minimap_scroll_x
= 512 - 200 - 1;
195 if (minimap_scroll_y
>= 512 - 229) minimap_scroll_y
= 512 - 229 - 1;
202 from
.x
= minimap_scroll_x
+ 4;
203 from
.y
= minimap_scroll_y
+ 4;
207 SDL_FillRect(screen
, &position
, 255);
208 SDL_BlitSurface(automap
, &from
, screen
, &position
);
210 rx
= c_scroll_x
/ 32 - 27 - minimap_scroll_x
+ 437;
211 ry
= c_scroll_y
/ 32 - 27 - minimap_scroll_y
+ 235;
213 DrawRect(rx
, ry
, 55, 1, 50);
214 DrawRect(rx
, ry
+54, 55, 1, 50);
215 DrawRect(rx
, ry
, 1, 55, 50);
216 DrawRect(rx
+54, ry
, 1, 55, 50);
226 SDL_BlitSurface(overview
, &from
, screen
, &position
);
228 rx
= (c_scroll_x
/ 32 - 27) * 200 / 512 + 437;
229 ry
= (c_scroll_y
/ 32 - 27) * 200 / 512 + 32;
241 if (rx
+rw
>= 437 + 200 - 1) {
242 rw
-= ((rx
+rw
) - (437 + 200 - 1));
244 if (ry
+rh
>= 32 + 200 - 1) {
245 rh
-= ((ry
+rh
) - (32 + 200 - 1));
248 DrawRect(rx
, ry
, rw
+ 1, 1, 50);
249 DrawRect(rx
, ry
+ rh
, rw
+ 1, 1, 50);
250 DrawRect(rx
, ry
, 1, rh
+ 1, 50);
251 DrawRect(rx
+ rw
, ry
, 1, rh
+ 1, 50);
253 DrawRect(2, 31, 432, 432, 255);
255 for (y
= 0; y
< 54; y
++) {
256 for (x
= 0; x
< 54; x
++) {
261 rx
= c_scroll_x
/ 32 - 27 + x
;
262 ry
= c_scroll_y
/ 32 - 27 + y
;
263 if ((rx
>= 0)&&(ry
>= 0)&&(rx
< 512)&&(ry
< 512)) {
264 if (rooms
[GetRoom(rx
, ry
)].visited
) {
266 if (tele_select
&& (nearest_checkpoint
== GetRoom(rx
, ry
)) && ((t
/ 3) % 2)) {
269 col
= automap_cols
[TileData
[tile
].Type
];
270 DrawRect(df_x
, df_y
, 8, 8, col
^ xcol
);
274 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
275 draw_char(df_x
, df_y
, '*', 0 ^ xcol
);
278 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
279 draw_char(df_x
, df_y
, '+', 0 ^ xcol
);
282 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
283 draw_char(df_x
, df_y
, 's', 0 ^ xcol
);
286 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
287 draw_char(df_x
, df_y
, 'c', 0 ^ xcol
);
290 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
291 draw_char(df_x
, df_y
, 'r', 0 ^ xcol
);
294 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
295 draw_char(df_x
, df_y
, 'S', 0 ^ xcol
);
298 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
299 draw_char(df_x
, df_y
, 29, 0 ^ xcol
);
302 DrawRect(df_x
, df_y
, 8, 8, 192 ^ xcol
);
303 draw_char(df_x
, df_y
, 28, 0 ^ xcol
);
308 DrawRect(df_x
, df_y
, 8, 8, 0 ^ xcol
);
309 draw_char(df_x
, df_y
, tile
+ 10, 255 ^ xcol
);
312 if ((tile
>= 45)&&(tile
<= 52)) {
313 DrawRect(df_x
, df_y
, 8, 8, 0 ^ xcol
);
314 draw_char(df_x
, df_y
, (tile
- 45)%4 + 14, 255 ^ xcol
);
317 if ((tile
>= 13)&&(tile
< 17)) {
318 DrawRect(df_x
, df_y
, 8, 8, 0 ^ xcol
);
319 draw_char(df_x
, df_y
, tile
- 13 + 22, 255 ^ xcol
);
321 if ((tile
>= 21)&&(tile
< 25)) {
322 DrawRect(df_x
, df_y
, 8, 8, 0 ^ xcol
);
323 draw_char(df_x
, df_y
, tile
- 13 + 22, 255 ^ xcol
);
325 if ((tile
>= 38)&&(tile
< 42)) {
326 DrawRect(df_x
, df_y
, 8, 8, 0 ^ xcol
);
327 draw_char(df_x
, df_y
, tile
- 13 + 22, 255 ^ xcol
);
328 draw_char(df_x
, df_y
, 26, 255 ^ xcol
);
331 if (( (player_x
/ 32) == rx
)&&( (player_y
/ 32) == ry
)) {
332 DrawRect(df_x
, df_y
, 8, 8, 0 ^ xcol
);
333 draw_char(df_x
, df_y
, 30, 255 ^ xcol
);
341 // Now, to cover up the gaps!
343 //DrawRect(0, 29, 640, 437, 230);
345 // +-------1----+-----+
351 // +-------2----+-----+
353 DrawRect(0, 29, 640, 3, 230); // 1
354 DrawRect(0, 463, 640, 4, 230); // 2
355 DrawRect(0, 29, 2, 437, 230); // 3
356 DrawRect(434, 29, 3, 437, 230); // 4
357 DrawRect(637, 29, 3, 437, 230); // 5
358 DrawRect(437, 232, 200, 3, 230); // 6
359 DrawMapFooter(); // right below 2