Copy editing
[meritous_recharged.git] / src / gamemap.c
blob3c72f3711aefbaf7bbed4d7f96e5116589e53a49
1 //
2 // gamemap.c
3 //
4 // Copyright 2007, 2008 Lancer-X/ASCEAI
5 //
6 // This file is part of Meritous.
7 //
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/>.
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
25 #include <SDL.h>
26 #include <SDL_image.h>
28 #include "levelblit.h"
29 #include "mapgen.h"
30 #include "tiles.h"
31 #include "save.h"
33 SDL_Surface *automap = NULL;
34 void RecordRoom(int room_id);
35 int full_rend = 0;
36 void FullRender();
37 int c_scroll_x=0, c_scroll_y=0;
38 SDL_Surface *overview = NULL;
40 void InitAutomap()
42 int i;
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);
51 full_rend = 0;
52 if (game_load) {
53 if (artifacts[0]) {
54 FullRender();
55 } else {
56 for (i = 0; i < 3000; i++) {
57 if (rooms[i].visited) {
58 RecordRoom(i);
61 RecordRoom(player_room);
66 void FullRender()
68 int x, y, i;
69 Uint8 *pix;
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);
77 pix += x + 4;
78 *pix = 128;
80 } else {
81 pix = automap->pixels;
82 pix += automap->w * (y + 4);
83 pix += x + 4;
84 *pix = 235;
89 for (i = 0; i < 3000; i++) {
90 if (rooms[i].visited) {
91 RecordRoom(i);
94 RecordRoom(player_room);
96 full_rend = 1;
99 void DrawMapFooter()
101 DrawRect(0, 466, 640, 14, 0);
102 DrawRect(1, 467, 638, 12, 32);
103 DrawRect(2, 468, 636, 10, 64);
104 if(!tele_select) {
105 draw_text(115, 470, "Scroll: [Arrow keys]. Scroll faster: hold [Space]. Close: [Tab].", 200);
106 draw_text(3, 469, "Map", 200);
107 } else {
108 draw_text(3, 469, "Teleport to checkpoint", 200);
112 void DisplayRoom(int room_id, Uint8 room_bg)
114 int x, y;
115 int rx, ry;
116 SDL_Rect fill;
117 Uint8 *pix;
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);
126 pix += rx + 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()
154 SDL_Rect from;
155 SDL_Rect position;
156 int x, y;
157 int df_x, df_y;
158 int rx, ry;
159 int rw, rh;
160 int tile;
161 int nearest_checkpoint;
162 unsigned char col;
163 unsigned char xcol = 0;
164 static int t = 0;
165 int minimap_scroll_x, minimap_scroll_y;
167 if (HoldsUp()) {
168 c_scroll_y -= 32 + (HoldsPsi()*64);
170 if (HoldsDown()) {
171 c_scroll_y += 32 + (HoldsPsi()*64);
173 if (HoldsLeft()) {
174 c_scroll_x -= 32 + (HoldsPsi()*64);
176 if (HoldsRight()) {
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;
197 position.x = 437;
198 position.y = 235;
199 position.w = 200;
200 position.h = 229;
202 from.x = minimap_scroll_x + 4;
203 from.y = minimap_scroll_y + 4;
204 from.w = 200;
205 from.h = 229;
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);
218 from.x = 0;
219 from.y = 0;
220 from.w = 200;
221 from.h = 200;
223 position.x = 437;
224 position.y = 32;
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;
230 rw = 54 * 200 / 512;
231 rh = 54 * 200 / 512;
233 if (rx < 437) {
234 rw -= (437 - rx);
235 rx = 437;
237 if (ry < 32) {
238 rh -= (32 - ry);
239 ry = 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);
254 t++;
255 for (y = 0; y < 54; y++) {
256 for (x = 0; x < 54; x++) {
257 xcol = 0;
258 df_x = x * 8 + 2;
259 df_y = y * 8 + 32;
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) {
265 tile = Get(rx, ry);
266 if (tele_select && (nearest_checkpoint == GetRoom(rx, ry)) && ((t / 3) % 2)) {
267 xcol = 255;
269 col = automap_cols[TileData[tile].Type];
270 DrawRect(df_x, df_y, 8, 8, col ^ xcol);
272 switch (tile) {
273 case 25:
274 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
275 draw_char(df_x, df_y, '*', 0 ^ xcol);
276 break;
277 case 26:
278 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
279 draw_char(df_x, df_y, '+', 0 ^ xcol);
280 break;
281 case 28:
282 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
283 draw_char(df_x, df_y, 's', 0 ^ xcol);
284 break;
285 case 29:
286 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
287 draw_char(df_x, df_y, 'c', 0 ^ xcol);
288 break;
289 case 30:
290 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
291 draw_char(df_x, df_y, 'r', 0 ^ xcol);
292 break;
293 case 31:
294 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
295 draw_char(df_x, df_y, 'S', 0 ^ xcol);
296 break;
297 case 32:
298 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
299 draw_char(df_x, df_y, 29, 0 ^ xcol);
300 break;
301 case 53:
302 DrawRect(df_x, df_y, 8, 8, 192 ^ xcol);
303 draw_char(df_x, df_y, 28, 0 ^ xcol);
304 break;
307 if (tile < 12) {
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----+-----+
346 // | | |
347 // 3 4 5
348 // | +--6--+
349 // | | |
350 // | | |
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