@@ -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) const
317+ PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator (CELL_ITERATOR_D2* iterator, int cellNumber, int cellLevel ) const
318318{
319319 ushort cell_ptr = m_cellPointers[cellNumber];
320320
@@ -343,8 +343,6 @@ PACKED_CELL_OBJECT* CDriver2LevelRegion::StartIterator(CELL_ITERATOR_D2* iterato
343343 // get the packed cell data start and near cell
344344 CELL_DATA* cell = &m_cells[cell_ptr];
345345
346- int cellLevel = iterator->cellLevel ;
347-
348346 if (cellLevel == 0 )
349347 {
350348 if (cell->num & 0x4000 )
@@ -544,11 +542,11 @@ int CDriver2LevelMap::MapHeight(const VECTOR_NOPAD& position) const
544542// -------------------------------------------------------------
545543// returns first cell object of cell
546544// -------------------------------------------------------------
547- PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop (CELL_ITERATOR_D2* iterator, int cellx , int cellz ) const
545+ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop (CELL_ITERATOR_D2* iterator, const XZPAIR& cell , int cellLevel ) const
548546{
549547 // lookup region
550- const int region_x = cellx / m_mapInfo.region_size ;
551- const int region_z = cellz / m_mapInfo.region_size ;
548+ const int region_x = cell. x / m_mapInfo.region_size ;
549+ const int region_z = cell. z / m_mapInfo.region_size ;
552550
553551 int regionIdx = region_x + region_z * m_regions_across;
554552
@@ -561,8 +559,8 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterat
561559 return nullptr ;
562560
563561 // get cell index on the region
564- const int region_cell_x = cellx % m_mapInfo.region_size ;
565- const int region_cell_z = cellz % m_mapInfo.region_size ;
562+ const int region_cell_x = cell. x % m_mapInfo.region_size ;
563+ const int region_cell_z = cell. z % m_mapInfo.region_size ;
566564
567565 // FIXME: might be incorrect
568566 int cell_index = region_cell_x + region_cell_z * m_mapInfo.region_size ;
@@ -573,36 +571,34 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetFirstPackedCop(CELL_ITERATOR_D2* iterat
573571 return nullptr ;
574572
575573 // get the near cell cPosition in the world
576- iterator->nearCell .x = (cellx - (m_mapInfo.cells_across / 2 )) * m_mapInfo.cell_size ;
577- iterator->nearCell .z = (cellz - (m_mapInfo.cells_down / 2 )) * m_mapInfo.cell_size ;
574+ iterator->nearCell .x = (cell. x - (m_mapInfo.cells_across / 2 )) * m_mapInfo.cell_size ;
575+ iterator->nearCell .z = (cell. z - (m_mapInfo.cells_down / 2 )) * m_mapInfo.cell_size ;
578576
579577 // get the packed cell data start and near cell
580- CELL_DATA* cell = ®ion.m_cells [cell_ptr];
581-
582- int cellLevel = iterator->cellLevel ;
578+ CELL_DATA* celld = ®ion.m_cells [cell_ptr];
583579
584580 if (cellLevel == 0 )
585581 {
586- if (cell ->num & 0x4000 )
582+ if (celld ->num & 0x4000 )
587583 return nullptr ;
588584 }
589585 else
590586 {
591- ushort num = cell ->num ;
592- cell ++;
587+ ushort num = celld ->num ;
588+ celld ++;
593589 while (num != (cellLevel | 0x4000 ))
594590 {
595- if (cell ->num & 0x8000 )
591+ if (celld ->num & 0x8000 )
596592 return nullptr ;
597593
598- num = cell ->num ;
599- cell ++;
594+ num = celld ->num ;
595+ celld ++;
600596 }
601597 }
602598
603- PACKED_CELL_OBJECT* ppco = region.GetCellObject (cell ->num & 0x3fff );
599+ PACKED_CELL_OBJECT* ppco = region.GetCellObject (celld ->num & 0x3fff );
604600
605- iterator->pcd = cell ;
601+ iterator->pcd = celld ;
606602
607603 if (ppco->value == 0xffff && (ppco->pos .vy & 1 ))
608604 ppco = GetNextPackedCop (iterator);
@@ -620,8 +616,6 @@ PACKED_CELL_OBJECT* CDriver2LevelMap::GetNextPackedCop(CELL_ITERATOR_D2* iterato
620616 ushort num;
621617 PACKED_CELL_OBJECT* ppco;
622618
623- int cellLevel = iterator->cellLevel ;
624-
625619 do {
626620 if (iterator->pcd ->num & 0x8000 )
627621 return nullptr ;
@@ -652,7 +646,9 @@ bool CDriver2LevelMap::UnpackCellObject(CELL_OBJECT& co, PACKED_CELL_OBJECT* pco
652646 co.pos .vx = nearCell.x + (((pco->pos .vx - nearCell.x ) << 0x10 ) >> 0x10 );
653647 co.pos .vz = nearCell.z + (((pco->pos .vz - nearCell.z ) << 0x10 ) >> 0x10 );
654648
655- co.pos .vy = (pco->pos .vy << 0x10 ) >> 0x11 ;
649+ // cell height should be negated
650+ co.pos .vy = -((pco->pos .vy << 0x10 ) >> 0x11 );
651+
656652 co.yang = pco->value & 0x3f ;
657653 co.type = (pco->value >> 6 ) | ((pco->pos .vy & 1 ) << 10 );
658654
0 commit comments