Subversion Repositories Games.Rick Dangerous

Rev

Rev 1 | Details | Compare with Previous | 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
 
11 pmbaty 48
extern U8 want_last_submap;
1 pmbaty 49
 
11 pmbaty 50
 
1 pmbaty 51
/*
52
 * prototypes
53
 */
54
static void map_eflg_expand (U8);
55
 
56
 
57
/*
58
 * Fill in map_map with tile numbers by expanding blocks.
59
 *
60
 * add map_submaps[].bnum to map_frow to find out where to start from.
61
 * We need to /4 map_frow to convert from tile rows to block rows, then
62
 * we need to *8 to convert from block rows to block numbers (there
63
 * are 8 blocks per block row). This is achieved by *2 then &0xfff8.
64
 */
65
void map_expand (void)
66
{
67
   U8 i, j, k, l;
68
   U8 row, col;
69
   U16 pbnum;
70
 
71
   pbnum = map_submaps[game_submap].bnum + ((2 * map_frow) & 0xfff8);
72
   row = col = 0;
73
 
74
   for (i = 0; i < 0x0b; i++)
75
   {
76
      /* 0x0b rows of blocks */
77
      for (j = 0; j < 0x08; j++)
78
      {
79
         /* 0x08 blocks per row */
80
         for (k = 0, l = 0; k < 0x04; k++)
81
         {
82
            /* expand one block */
83
            map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
84
            map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
85
            map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++];
86
            map_map[row][col]   = map_blocks[map_bnums[pbnum]][l++];
87
            row += 1;
88
            col -= 3;
89
         }
90
 
91
         row -= 4;
92
         col += 4;
93
         pbnum++;
94
      }
95
 
96
      row += 4;
97
      col = 0;
98
   }
99
}
100
 
101
 
102
/*
103
 * Initialize a new submap
104
 *
105
 * ASM 0cc3
106
 */
107
void map_init (void)
108
{
109
   map_tilesBank = (map_submaps[game_submap].page == 1) ? 2 : 1;
110
   map_eflg_expand ((U8) ((map_submaps[game_submap].page == 1) ? 0x10 : 0x00));
111
   map_expand ();
112
   ent_reset ();
113
   ent_actvis ((U8) (map_frow + MAP_ROW_SCRTOP), (U8) (map_frow + MAP_ROW_SCRBOT));
114
   ent_actvis ((U8) (map_frow + MAP_ROW_HTTOP), (U8) (map_frow + MAP_ROW_HTBOT));
115
   ent_actvis ((U8) (map_frow + MAP_ROW_HBTOP), (U8) (map_frow + MAP_ROW_HBBOT));
116
}
117
 
118
 
119
/*
120
 * Expand entity flags for this map
121
 *
122
 * ASM 1117
123
 */
124
void map_eflg_expand (U8 offs)
125
{
126
   U8 i, j, k;
127
 
128
   for (i = 0, k = 0; i < 0x10; i++)
129
   {
130
      j = map_eflg_c[offs + i++];
131
 
132
      while (j--)
133
         map_eflg[k++] = map_eflg_c[offs + i];
134
   }
135
}
136
 
137
 
138
/*
139
 * Chain (sub)maps
140
 *
141
 * ASM 0c08
142
 * return: TRUE/next submap OK, FALSE/map finished
143
 */
144
U8 map_chain (void)
145
{
146
   U16 c, t;
147
 
148
   game_chsm = 0;
149
   e_sbonus_counting = FALSE;
150
 
151
   /* find connection */
152
   c = map_submaps[game_submap].connect;
153
   t = 3;
154
 
155
   /*
156
    * look for the first connector with compatible row number. if none
157
    * found, then panic
158
    */
159
   for (c = map_submaps[game_submap].connect; ; c++)
160
   {
161
      if (map_connect[c].dir == 0xff)
162
         sys_panic ("(map_chain) can not find connector\n");
163
 
164
      if (map_connect[c].dir != game_dir)
165
         continue;
166
 
167
      t = (ent_ents[1].y >> 3) + map_frow - map_connect[c].rowout;
168
 
169
      if (t < 3)
170
         break;
171
   }
172
 
173
   /* got it */
174
   if (map_connect[c].submap == 0xff)
175
      return FALSE; // no next submap - request next map
176
   else
177
   {
178
      /* next submap */
179
      map_frow = map_frow - map_connect[c].rowout + map_connect[c].rowin;
180
      game_submap = map_connect[c].submap;
11 pmbaty 181
      if (want_last_submap)
182
      {
183
         sysarg_args_map = game_map;
184
         sysarg_args_submap = game_submap;
185
      }
1 pmbaty 186
      return TRUE;
187
   }
188
}
189
 
190
 
191
/*
192
 * Reset all marks, i.e. make them all active again.
193
 *
194
 * ASM 0025
195
 *
196
 */
197
void map_resetMarks (void)
198
{
199
   U16 i;
200
 
201
   for (i = 0; i < MAP_NBR_MARKS; i++)
202
      map_marks[i].ent &= ~MAP_MARK_NACT;
203
}