Subversion Repositories Games.Rick Dangerous

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * src/maps.c
3
 *
4
 * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
5
 *
6
 * The use and distribution terms for this software are contained in the file
7
 * named README, which can be found in the root of this distribution. By
8
 * using this software in any fashion, you are agreeing to be bound by the
9
 * terms of this license.
10
 *
11
 * You must not remove this notice, or any other, from this software.
12
 */
13
 
14
/*
15
 * NOTES
16
 *
17
 * A map is composed of submaps, which in turn are composed of rows of
18
 * 0x20 tiles. map_map contains the tiles for the current portion of the
19
 * current submap, i.e. a little bit more than what appear on the screen,
20
 * but not the whole submap.
21
 *
22
 * map_frow is map_map top row within the submap.
23
 *
24
 * Submaps are stored as arrays of blocks, each block being a 4x4 tile
25
 * array. map_submaps[].bnum points to the first block of the array.
26
 *
27
 * Before a submap can be played, it needs to be expanded from blocks
28
 * to map_map.
29
 */
30
 
31
#include "system.h"
32
#include "game.h"
33
#include "maps.h"
34
 
35
#include "ents.h"
36
#include "draw.h"
37
#include "screens.h"
38
#include "e_sbonus.h"
39
 
40
/*
41
 * global vars
42
 */
43
U8 map_map[0x2C][0x20];
44
U8 map_eflg[0x100];
45
U8 map_frow;
46
U8 map_tilesBank;
47
 
48
 
49
/*
50
 * prototypes
51
 */
52
static void map_eflg_expand (U8);
53
 
54
 
55
/*
56
 * Fill in map_map with tile numbers by expanding blocks.
57
 *
58
 * add map_submaps[].bnum to map_frow to find out where to start from.
59
 * We need to /4 map_frow to convert from tile rows to block rows, then
60
 * we need to *8 to convert from block rows to block numbers (there
61
 * are 8 blocks per block row). This is achieved by *2 then &0xfff8.
62
 */
63
void map_expand (void)
64
{
65
   U8 i, j, k, l;
66
   U8 row, col;
67
   U16 pbnum;
68
 
69
   pbnum = map_submaps[game_submap].bnum + ((2 * map_frow) & 0xfff8);
70
   row = col = 0;
71
 
72
   for (i = 0; i < 0x0b; i++)
73
   {
74
      /* 0x0b rows of blocks */
75
      for (j = 0; j < 0x08; j++)
76
      {
77
         /* 0x08 blocks per row */
78
         for (k = 0, l = 0; k < 0x04; k++)
79
         {
80
            /* expand one block */
81
            map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
82
            map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
83
            map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
84
            map_map[row][col]   = map_blocks[map_bnums[pbnum]][l++];
85
            row += 1;
86
            col -= 3;
87
         }
88
 
89
         row -= 4;
90
         col += 4;
91
         pbnum++;
92
      }
93
 
94
      row += 4;
95
      col = 0;
96
   }
97
}
98
 
99
 
100
/*
101
 * Initialize a new submap
102
 *
103
 * ASM 0cc3
104
 */
105
void map_init (void)
106
{
107
   map_tilesBank = (map_submaps[game_submap].page == 1) ? 2 : 1;
108
   map_eflg_expand ((U8) ((map_submaps[game_submap].page == 1) ? 0x10 : 0x00));
109
   map_expand ();
110
   ent_reset ();
111
   ent_actvis ((U8) (map_frow + MAP_ROW_SCRTOP), (U8) (map_frow + MAP_ROW_SCRBOT));
112
   ent_actvis ((U8) (map_frow + MAP_ROW_HTTOP), (U8) (map_frow + MAP_ROW_HTBOT));
113
   ent_actvis ((U8) (map_frow + MAP_ROW_HBTOP), (U8) (map_frow + MAP_ROW_HBBOT));
114
}
115
 
116
 
117
/*
118
 * Expand entity flags for this map
119
 *
120
 * ASM 1117
121
 */
122
void map_eflg_expand (U8 offs)
123
{
124
   U8 i, j, k;
125
 
126
   for (i = 0, k = 0; i < 0x10; i++)
127
   {
128
      j = map_eflg_c[offs + i++];
129
 
130
      while (j--)
131
         map_eflg[k++] = map_eflg_c[offs + i];
132
   }
133
}
134
 
135
 
136
/*
137
 * Chain (sub)maps
138
 *
139
 * ASM 0c08
140
 * return: TRUE/next submap OK, FALSE/map finished
141
 */
142
U8 map_chain (void)
143
{
144
   U16 c, t;
145
 
146
   game_chsm = 0;
147
   e_sbonus_counting = FALSE;
148
 
149
   /* find connection */
150
   c = map_submaps[game_submap].connect;
151
   t = 3;
152
 
153
   /*
154
    * look for the first connector with compatible row number. if none
155
    * found, then panic
156
    */
157
   for (c = map_submaps[game_submap].connect; ; c++)
158
   {
159
      if (map_connect[c].dir == 0xff)
160
         sys_panic ("(map_chain) can not find connector\n");
161
 
162
      if (map_connect[c].dir != game_dir)
163
         continue;
164
 
165
      t = (ent_ents[1].y >> 3) + map_frow - map_connect[c].rowout;
166
 
167
      if (t < 3)
168
         break;
169
   }
170
 
171
   /* got it */
172
   if (map_connect[c].submap == 0xff)
173
      return FALSE; // no next submap - request next map
174
   else
175
   {
176
      /* next submap */
177
      map_frow = map_frow - map_connect[c].rowout + map_connect[c].rowin;
178
      game_submap = map_connect[c].submap;
179
      return TRUE;
180
   }
181
}
182
 
183
 
184
/*
185
 * Reset all marks, i.e. make them all active again.
186
 *
187
 * ASM 0025
188
 *
189
 */
190
void map_resetMarks (void)
191
{
192
   U16 i;
193
 
194
   for (i = 0; i < MAP_NBR_MARKS; i++)
195
      map_marks[i].ent &= ~MAP_MARK_NACT;
196
}