@@ -22,6 +22,9 @@ void CDriver1LevelRegion::FreeAll()
2222
2323 delete[] m_roadMap;
2424 m_roadMap = nullptr ;
25+
26+ delete[] m_surfaceRoads;
27+ m_surfaceRoads = nullptr ;
2528}
2629
2730void CDriver1LevelRegion::LoadRegionData (const SPOOL_CONTEXT& ctx)
@@ -58,8 +61,8 @@ void CDriver1LevelRegion::LoadRegionData(const SPOOL_CONTEXT& ctx)
5861 const int pvsDataOffset = cellObjectsOffset + m_spoolInfo->cell_data_size [2 ]; // FIXME: is it even there in Driver 1?
5962
6063 // read roadm (map?)
61- // pFile->Seek(ctx.lumpInfo->spooled_offset + roadMOffset * SPOOL_CD_BLOCK_SIZE, VS_SEEK_SET);
62- // pFile->Read(roadMapData, m_spoolInfo->roadm_size * SPOOL_CD_BLOCK_SIZE, sizeof(char) );
64+ pFile->Seek (ctx.lumpInfo ->spooled_offset + roadMOffset * SPOOL_CD_BLOCK_SIZE, VS_SEEK_SET);
65+ LoadRoadCellsData (pFile );
6366
6467 // read roadh (heights?)
6568 pFile->Seek (ctx.lumpInfo ->spooled_offset + roadHOffset * SPOOL_CD_BLOCK_SIZE, VS_SEEK_SET);
@@ -137,6 +140,30 @@ void CDriver1LevelRegion::LoadRoadHeightMapData(IVirtualStream* pFile)
137140 delete[] roadMapData;
138141}
139142
143+ void CDriver1LevelRegion::LoadRoadCellsData (IVirtualStream* pFile)
144+ {
145+ m_surfaceRoads = new ushort[ROAD_MAP_REGION_CELLS];
146+ ushort* pRoadIds = m_surfaceRoads;
147+ int i = ROAD_MAP_REGION_CELLS;
148+
149+ do {
150+ short length;
151+ pFile->Read (&length, 1 , sizeof (short ));
152+
153+ if (length == -1 )
154+ break ;
155+
156+ ushort value;
157+ pFile->Read (&value, 1 , sizeof (short ));
158+
159+ int count = length;
160+ for (i = i - count; count > 0 ; count--)
161+ {
162+ *pRoadIds++ = value;
163+ }
164+ } while (i > 0 );
165+ }
166+
140167// ----------------------------------------
141168// cell iterator
142169CELL_OBJECT* CDriver1LevelRegion::StartIterator (CELL_ITERATOR_D1* iterator, int cellNumber) const
@@ -175,6 +202,18 @@ void CDriver1LevelMap::FreeAll()
175202 Memory::free (m_surfaceData);
176203 m_surfaceData = nullptr ;
177204
205+ delete[] m_roads;
206+ m_roads = nullptr ;
207+
208+ delete[] m_roadBounds;
209+ m_roadBounds = nullptr ;
210+
211+ delete[] m_junctions;
212+ m_junctions = nullptr ;
213+
214+ delete[] m_junctionBounds;
215+ m_junctionBounds = nullptr ;
216+
178217 CBaseLevelMap::FreeAll ();
179218}
180219
@@ -225,6 +264,36 @@ void CDriver1LevelMap::LoadRoadMapLump(IVirtualStream* pFile)
225264 // m_roadMapLumpData.unitZMid = 1500 * height / 2;
226265}
227266
267+ void CDriver1LevelMap::LoadRoadsLump (IVirtualStream* pFile)
268+ {
269+ pFile->Read (&m_numRoads, 1 , sizeof (int ));
270+ m_roads = new DRIVER1_ROAD[m_numRoads];
271+ pFile->Read (m_roads, m_numRoads, sizeof (DRIVER1_ROAD));
272+ }
273+
274+ void CDriver1LevelMap::LoadJunctionsLump (IVirtualStream* pFile)
275+ {
276+ pFile->Read (&m_numJunctions, 1 , sizeof (int ));
277+ m_junctions = new DRIVER1_JUNCTION[m_numJunctions];
278+ pFile->Read (m_junctions, m_numJunctions, sizeof (DRIVER1_JUNCTION));
279+ }
280+
281+ void CDriver1LevelMap::LoadRoadBoundsLump (IVirtualStream* pFile)
282+ {
283+ int numRoadBounds;
284+ pFile->Read (&numRoadBounds, 1 , sizeof (int ));
285+ m_roadBounds = new DRIVER1_ROADBOUNDS[numRoadBounds];
286+ pFile->Read (m_roadBounds, numRoadBounds, sizeof (DRIVER1_ROADBOUNDS));
287+ }
288+
289+ void CDriver1LevelMap::LoadJuncBoundsLump (IVirtualStream* pFile)
290+ {
291+ int numJuncBounds;
292+ pFile->Read (&numJuncBounds, 1 , sizeof (int ));
293+ m_junctionBounds = new XYPAIR[numJuncBounds];
294+ pFile->Read (m_junctionBounds, numJuncBounds, sizeof (XYPAIR));
295+ }
296+
228297void CDriver1LevelMap::LoadRoadSurfaceLump (IVirtualStream* pFile, int size)
229298{
230299 int numSurfaces;
@@ -252,6 +321,12 @@ CBaseLevelRegion* CDriver1LevelMap::GetRegion(const XZPAIR& cell) const
252321 const int region_x = cell.x / m_mapInfo.region_size ;
253322 const int region_z = cell.z / m_mapInfo.region_size ;
254323
324+ if (region_x < 0 ||
325+ region_z < 0 ||
326+ region_x >= m_regions_across ||
327+ region_z >= m_regions_down)
328+ return nullptr ;
329+
255330 return GetRegion (region_x + region_z * m_regions_across);
256331}
257332
@@ -370,13 +445,15 @@ bool CDriver1LevelMap::GetRoadInfo(ROUTE_DATA& outData, const VECTOR_NOPAD& posi
370445 return false ;
371446 }
372447
373- const uint value = region->m_roadMap [(cpos.x % road_region_size) +
374- (cpos.z % road_region_size) * road_region_size];
448+ const int cellIdx = (cpos.x % road_region_size) + (cpos.z % road_region_size) * road_region_size;
449+
450+ const uint value = region->m_roadMap [cellIdx];
375451
376452 outData.height = *(short *)&value;
377- outData.type = value >> 16 & 0x3ff ;
453+ outData.type = value >> 16 & 1023 ;
378454 outData.objectAngle = (value >> 30 ) * 1024 ;
379455 outData.value = value;
456+ outData.roadIndex = region->m_surfaceRoads [cellIdx];
380457
381458 return true ;
382459}
0 commit comments