100 lines
2.4 KiB
C
100 lines
2.4 KiB
C
/*
|
|
* PVVMUD a 3D MUD
|
|
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
*/
|
|
#include "pvvmud.H"
|
|
#include "cellpvs.H"
|
|
#include "worldworld.H"
|
|
#include "worldobject.H"
|
|
|
|
|
|
|
|
CPVCell::CPVCell(DWORD cellId, const CPosition & position){
|
|
m_cellId = cellId;
|
|
m_position = position;
|
|
}
|
|
|
|
|
|
DWORD CPVCell::getCellId(){
|
|
return m_cellId;
|
|
}
|
|
|
|
CPosition CPVCell::getPosition(){
|
|
return m_position;
|
|
}
|
|
|
|
CCellPVS::CCellPVS(CWorldWorld * world){
|
|
m_world = world;
|
|
}
|
|
|
|
CWorldWorld * CCellPVS::getWorld(){
|
|
return m_world;
|
|
}
|
|
|
|
CPVCell* CCellPVS::addPVCell(DWORD cellId, const CPosition & position){
|
|
CPVCell * pvCell = new CPVCell(cellId,position);
|
|
addLast((CObject*)pvCell);
|
|
return pvCell;
|
|
}
|
|
|
|
CObjectListItem * CCellPVS::getFirstPVCell(){
|
|
return getFirst();
|
|
}
|
|
|
|
CPosition CCellPVS::getPVCellPosition(CWorldObject * cell){
|
|
CPosition position;
|
|
CObjectListItem * item = getFirstPVCell();
|
|
while (item != NULL){
|
|
CPVCell * pvCell = (CPVCell*)item->getObject();
|
|
|
|
if (pvCell->getCellId() == cell->getObjectId()){
|
|
return pvCell->getPosition();
|
|
}
|
|
|
|
item = item->getNext();
|
|
}
|
|
return position;
|
|
}
|
|
|
|
CWorldObject * CCellPVS::findCell(CPosition * position){
|
|
|
|
cdebug << "Check if pos : " << *position << "\n";
|
|
|
|
CObjectListItem * item = getFirstPVCell();
|
|
while (item != NULL){
|
|
CPVCell * pvCell = (CPVCell*)item->getObject();
|
|
CWorldObject * cell;
|
|
cell = getWorld()->getObject(pvCell->getCellId());
|
|
|
|
CPosition newpos = *position - pvCell->getPosition();
|
|
|
|
cdebug << "Check " << cell->getName() << " Pos : " << newpos << "\n";
|
|
|
|
if (cell->checkPosition(newpos)){
|
|
*position = newpos;
|
|
return cell;
|
|
}
|
|
|
|
item = item->getNext();
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|