@@ -314,7 +314,7 @@ CELL_DATA* CDriver2LevelRegion::GetCellData(int num) const
314314}
315315
316316// cell iterator
317- PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator (CELL_ITERATOR_D2* iterator, int cellNumber, int cellLevel ) const
317+ PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator (CELL_ITERATOR_D2* iterator, int cellNumber) const
318318{
319319 ushort cell_ptr = m_cellPointers[cellNumber];
320320
@@ -341,29 +341,18 @@ PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR_D2* iterato
341341 iterator->nearCell .z = (cellz - (mapInfo.cells_down / 2 ))* mapInfo.cell_size ;
342342
343343 // get the packed cell data start and near cell
344- CELL_DATA* cell = &m_cells[cell_ptr];
344+ CELL_DATA* celld = &m_cells[cell_ptr];
345345
346- if (cellLevel == 0 )
347- {
348- if (cell->num & 0x4000 )
349- return nullptr ;
350- }
351- else
352- {
353- ushort num = cell->num ;
354- cell++;
355- while (num != (cellLevel | 0x4000 ))
356- {
357- if (cell->num & 0x8000 )
358- return nullptr ;
346+ iterator->listType = 0 ;
359347
360- num = cell->num ;
361- cell++;
362- }
348+ if (celld->num & 0x4000 ) // if we immediately got to the typed list
349+ {
350+ iterator->listType = celld->num ;
351+ celld++; // get to the start
363352 }
364353
365- PACKED_CELL_OBJECT* ppco = GetCellObject (cell ->num & 0x3fff );
366- iterator->pcd = cell ;
354+ PACKED_CELL_OBJECT* ppco = GetCellObject (celld ->num & 0x3fff );
355+ iterator->pcd = celld ;
367356
368357 if (ppco->value == 0xffff && (ppco->pos .vy & 1 ))
369358 ppco = ((CDriver2LevelMap*)m_owner)->GetNextPackedCop (iterator);
@@ -542,7 +531,7 @@ int CDriver2LevelMap::MapHeight(const VECTOR_NOPAD& position) const
542531// -------------------------------------------------------------
543532// returns first cell object of cell
544533// -------------------------------------------------------------
545- PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop (CELL_ITERATOR_D2* iterator, const XZPAIR& cell, int cellLevel ) const
534+ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop (CELL_ITERATOR_D2* iterator, const XZPAIR& cell) const
546535{
547536 // lookup region
548537 const int region_x = cell.x / m_mapInfo.region_size ;
@@ -577,23 +566,23 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterat
577566 // get the packed cell data start and near cell
578567 CELL_DATA* celld = ®ion.m_cells [cell_ptr];
579568
580- if (cellLevel == 0 )
581- {
582- if (celld->num & 0x4000 )
583- return nullptr ;
584- }
585- else
586- {
587- ushort num = celld->num ;
588- celld++;
589- while (num != (cellLevel | 0x4000 ))
590- {
591- if (celld->num & 0x8000 )
592- return nullptr ;
569+ /*
570+ Data looks like this:
593571
594- num = celld->num ;
595- celld++;
596- }
572+ 45,34,773,456 - default list of cell objects
573+ 0x4000 | 100 - list 1 header - type 100
574+ 70,378,4557 - objects of list 1
575+ 0x4000 | 14 - list 2 header - type 14
576+ 8767,555,445,223 - objects of list 2
577+ 0x8000 - end of cell objects
578+ */
579+
580+ iterator->listType = 0 ;
581+
582+ if (celld->num & 0x4000 ) // if we immediately got to the typed list
583+ {
584+ iterator->listType = celld->num ;
585+ celld++; // get to the start
597586 }
598587
599588 PACKED_CELL_OBJECT* ppco = region.GetCellObject (celld->num & 0x3fff );
@@ -617,16 +606,35 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterato
617606 PACKED_CELL_OBJECT* ppco;
618607
619608 do {
620- if (iterator->pcd ->num & 0x8000 )
609+ CELL_DATA* celld = iterator->pcd ;
610+
611+ if (celld->num & 0x8000 ) // end of the cell objects?
621612 return nullptr ;
622613
623- iterator->pcd ++;
624- num = iterator->pcd ->num ;
614+ celld++;
625615
626- if (num & 0x4000 ) // start of new list
627- return nullptr ;
616+ if (celld->num & 0x4000 ) // if we got new list
617+ {
618+ iterator->listType = celld->num ;
619+ celld++; // get to the start
620+ }
621+
622+ iterator->pcd = celld;
623+
624+ /*
625+ celld++;
626+ num = celld->num;
628627
629- ppco = iterator->region ->GetCellObject (num & 0x3fff );
628+ if (celld->num & 0x4000) // if we immediately got to the typed list
629+ {
630+ iterator->listType = celld->num;
631+ celld++; // get to the start
632+ }
633+
634+ if(num & 0x4000) // start of new sub list?
635+ return nullptr;
636+ */
637+ ppco = iterator->region ->GetCellObject (celld->num & 0x3fff );
630638
631639 } while (ppco->value == 0xffff && (ppco->pos .vy & 1 ));
632640
0 commit comments