-
Notifications
You must be signed in to change notification settings - Fork 0
/
automap.c
319 lines (275 loc) · 7.88 KB
/
automap.c
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
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (C) 1995 Ronny Wester
Copyright (C) 2003 Jeremy Chin
Copyright (C) 2003-2007 Lucas Martin-King
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------
automap.c - automatic map generation stuff
Author: $Author: lmartinking $
Rev: $Revision: 250 $
URL: $HeadURL: svn://svn.icculus.org/cdogs-sdl/trunk/src/automap.c $
ID: $Id: automap.c 250 2007-07-06 16:38:43Z lmartinking $
*/
#include <stdio.h>
#include <string.h>
#include "defs.h"
#include "pics.h"
#include "map.h"
#include "actors.h"
#include "blit.h"
#include "automap.h"
#include "sounds.h"
#include "text.h"
#include "gamedata.h"
#include "input.h"
#include "mission.h"
#include "keyboard.h"
#include "objs.h"
#include "grafx.h"
#define MAP_XOFFS 60
#define MAP_YOFFS 10
#define MAP_FACTOR 2
#define WALL_COLOR 85
#define FLOOR_COLOR 88
#define DOOR_COLOR 36
#define YELLOW_DOOR_COLOR 16
#define GREEN_DOOR_COLOR 11
#define BLUE_DOOR_COLOR 14
#define RED_DOOR_COLOR 134
#define EXIT_COLOR 255
#define KEY_COLOR 255
static void DisplayPlayer(TActor * player)
{
int x, y;
struct CharacterDescription *c;
int pic;
if (player) {
c = &characterDesc[player->character];
pic = cHeadPic[c->facePic][DIRECTION_DOWN][STATE_IDLE];
x = MAP_XOFFS +
MAP_FACTOR * player->tileItem.x / TILE_WIDTH;
y = MAP_YOFFS +
MAP_FACTOR * player->tileItem.y / TILE_HEIGHT;
x -= PicWidth(gPics[pic]) / 2;
y -= PicHeight(gPics[pic]) / 2;
DrawTTPic(x, y, gPics[pic], c->table, gRLEPics[pic]);
}
}
static void DrawCross(TTileItem * t, int color)
{
unsigned char *scr = GetDstScreen();
scr += MAP_XOFFS + MAP_FACTOR * t->x / TILE_WIDTH;
scr += (MAP_YOFFS + MAP_FACTOR * t->y / TILE_HEIGHT) * SCREEN_WIDTH;
*scr = color;
*(scr - 1) = color;
*(scr + 1) = color;
*(scr - SCREEN_WIDTH) = color;
*(scr + SCREEN_WIDTH) = color;
}
static void DisplayObjective(TTileItem * t, int objectiveIndex)
{
DrawCross(t, gMission.objectives[objectiveIndex].color);
}
static void DisplayExit(void)
{
unsigned char *scr = GetDstScreen();
int i;
int x1, x2, y1, y2;
for (i = 0; i < gMission.missionData->objectiveCount; i++)
if (gMission.objectives[i].done <
gMission.objectives[i].required)
return;
x1 = MAP_FACTOR * gMission.exitLeft / TILE_WIDTH + MAP_XOFFS;
y1 = MAP_FACTOR * gMission.exitTop / TILE_HEIGHT + MAP_YOFFS;
x2 = MAP_FACTOR * gMission.exitRight / TILE_WIDTH + MAP_XOFFS;
y2 = MAP_FACTOR * gMission.exitBottom / TILE_HEIGHT + MAP_YOFFS;
for (i = x1; i <= x2; i++) {
*(scr + i + y1 * SCREEN_WIDTH) = EXIT_COLOR;
*(scr + i + y2 * SCREEN_WIDTH) = EXIT_COLOR;
}
for (i = y1 + 1; i < y2; i++) {
*(scr + x1 + i * SCREEN_WIDTH) = EXIT_COLOR;
*(scr + x2 + i * SCREEN_WIDTH) = EXIT_COLOR;
}
}
static void DisplaySummary()
{
int i, y;
char sScore[20];
unsigned char *scr = GetDstScreen();
unsigned char color;
y = SCREEN_HEIGHT - 20 - TextHeight(); // 10 pixels from bottom
for (i = 0; i < gMission.missionData->objectiveCount; i++) {
if (gMission.objectives[i].required > 0 ||
gMission.objectives[i].done > 0) {
// Objective color dot
color = gMission.objectives[i].color;
scr[5 + (y + 3) * SCREEN_WIDTH] = color;
scr[6 + (y + 3) * SCREEN_WIDTH] = color;
scr[5 + (y + 2) * SCREEN_WIDTH] = color;
scr[6 + (y + 2) * SCREEN_WIDTH] = color;
sprintf(sScore, "(%d)", gMission.objectives[i].done);
if (gMission.objectives[i].required <= 0) {
TextStringWithTableAt(20, y,
gMission.missionData->objectives[i].description,
&tablePurple);
TextStringWithTableAt(SCREEN_WIDTH - 30, y, sScore, &tablePurple);
} else if (gMission.objectives[i].done >= gMission.objectives[i].required) {
TextStringWithTableAt(20, y,
gMission.missionData->objectives[i].description,
&tableFlamed);
TextStringWithTableAt(SCREEN_WIDTH - 30, y, sScore, &tableFlamed);
} else {
TextStringAt(20, y, gMission.missionData->objectives[i].description);
TextStringAt(SCREEN_WIDTH - 30, y, sScore);
}
y -= (TextHeight() + 1);
}
}
}
static int MapLevel(int x, int y)
{
int l;
l = MapAccessLevel(x - 1, y);
if (l)
return l;
l = MapAccessLevel(x + 1, y);
if (l)
return l;
l = MapAccessLevel(x, y - 1);
if (l)
return l;
return MapAccessLevel(x, y + 1);
}
static int DoorColor(int x, int y)
{
int l = MapLevel(x, y);
switch (l) {
case FLAGS_KEYCARD_YELLOW:
return YELLOW_DOOR_COLOR;
case FLAGS_KEYCARD_GREEN:
return GREEN_DOOR_COLOR;
case FLAGS_KEYCARD_BLUE:
return BLUE_DOOR_COLOR;
case FLAGS_KEYCARD_RED:
return RED_DOOR_COLOR;
default:
return DOOR_COLOR;
}
}
static void DrawDot(TTileItem * t, int color)
{
unsigned char *scr = GetDstScreen();
scr += MAP_XOFFS + MAP_FACTOR * t->x / TILE_WIDTH;
scr += (MAP_YOFFS + MAP_FACTOR * t->y / TILE_HEIGHT) * SCREEN_WIDTH;
*scr = color;
*(scr - 1) = color;
*(scr + SCREEN_WIDTH) = color;
*(scr + 319) = color;
}
void DisplayAutoMap(int showAll)
{
unsigned char *screen = GetDstScreen();
int x, y, i, j;
TTile *tile;
unsigned char *p;
TTileItem *t;
int cmd1, cmd2;
int obj;
p = GetDstScreen();
for (x = 0; x < SCREEN_MEMSIZE; x++)
p[x] = tableGreen[p[x] & 0xFF];
screen += MAP_YOFFS * SCREEN_WIDTH + MAP_XOFFS;
for (y = 0; y < YMAX; y++)
for (i = 0; i < MAP_FACTOR; i++) {
for (x = 0; x < XMAX; x++)
if (AutoMap(x, y) || showAll) {
tile = &Map(x, y);
for (j = 0; j < MAP_FACTOR; j++)
if ((tile->
flags & IS_WALL) != 0)
*screen++ =
WALL_COLOR;
else if ((tile->
flags & NO_WALK)
!= 0)
*screen++ =
DoorColor(x,
y);
else
*screen++ =
FLOOR_COLOR;
} else
screen += MAP_FACTOR;
screen += SCREEN_WIDTH - XMAX * MAP_FACTOR;
}
for (y = 0; y < YMAX; y++)
for (x = 0; x < XMAX; x++) {
t = Map(x, y).things;
while (t) {
if ((t->flags & TILEITEM_OBJECTIVE) != 0) {
obj =
ObjectiveFromTileItem(t->
flags);
if ((gMission.missionData->
objectives[obj].
flags & OBJECTIVE_HIDDEN) == 0
|| showAll) {
if ((gMission.missionData->
objectives[obj].
flags &
OBJECTIVE_POSKNOWN) !=
0 || AutoMap(x, y)
|| showAll)
DisplayObjective(t,
obj);
}
} else if (t->kind == KIND_OBJECT
&& t->data && AutoMap(x, y)) {
TObject *o = t->data;
if (o->objectIndex ==
OBJ_KEYCARD_RED)
DrawDot(t, RED_DOOR_COLOR);
else if (o->objectIndex ==
OBJ_KEYCARD_BLUE)
DrawDot(t,
BLUE_DOOR_COLOR);
else if (o->objectIndex ==
OBJ_KEYCARD_GREEN)
DrawDot(t,
GREEN_DOOR_COLOR);
else if (o->objectIndex ==
OBJ_KEYCARD_YELLOW)
DrawDot(t,
YELLOW_DOOR_COLOR);
}
t = t->next;
}
}
DisplayPlayer(gPlayer1);
DisplayPlayer(gPlayer2);
DisplayExit();
DisplaySummary();
CopyToScreen();
if (!showAll) {
do {
cmd1 = cmd2 = 0;
GetPlayerCmd(gPlayer1 ? &cmd1 : NULL,
gPlayer2 ? &cmd2 : NULL);
}
while (((cmd1 | cmd2) & CMD_BUTTON3) != 0 || KeyDown(gOptions.mapKey));
memset(GetDstScreen(), 0, SCREEN_MEMSIZE);
}
}