2025-03-05 08:37:43 +01:00

147 lines
3.9 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 "worldsrvobject.H"
#include "worldclimanager.H"
#include "worldsrvlistenerlist.H"
#include "waupdateclientposition.H"
#include "wacreateclientobject.H"
#include "waremoveclientobject.H"
CWorldSrvObject::CWorldSrvObject(DWORD objectId, CWorldWorld * world, DWORD geometryId,const CPosition & position, const CDirection & direction ):CWorldObject(objectId,world,geometryId,position,direction){
m_listenerList = new CWorldSrvListenerList();
}
CWorldSrvObject::CWorldSrvObject(DWORD objectId, CWorldObject * parent, DWORD geometryId,const CPosition & position, const CDirection & direction ):CWorldObject(objectId,parent,geometryId,position,direction){
m_listenerList = NULL;
}
CWorldSrvObject::~CWorldSrvObject(){
}
CPosition CWorldSrvObject::getPosition(CWorldSrvObject * masterCell){
CPosition position = CWorldObject::getPosition();
if (masterCell != this) {
CCellPVS * pvs = masterCell->getPVS();
CObjectListItem * item = pvs->getFirstPVCell();
while (item != NULL){
CPVCell * pv = (CPVCell*)item->getObject();
if (pv->getCellId() == getObjectId()){
position = pv->getPosition();
break;
}
item = item->getNext();
}
}
return position;
}
void CWorldSrvObject::addListener(CWorldCliManager * listener){
cdebug << "CWorldSrvObject::addListener( " << listener->getName() << " ) to object " << getObjectId() << "\n";
m_listenerList->add(listener);
sendHierarchy(listener);
}
void CWorldSrvObject::sendHierarchy(CWorldCliManager * listener){
// Send object
CWACreateClientObject * wacreate = new CWACreateClientObject(getObjectId(),
getGeometryId(),getParentId(),
getPosition(listener->getMasterCell()),
getDirection());
listener->sendAnimation( wacreate );
delete wacreate;
// Find and send animations
CWorldSrvWorld * world = (CWorldSrvWorld*)getWorld();
world->sendObjectAnimation(getObjectId(),listener);
// Send sub objects
CObjectListItem * item = getFirst();
while (item != NULL){
CWorldSrvObject * object = (CWorldSrvObject*)item->getObject();
item = item->getNext();
object->sendHierarchy(listener);
}
}
void CWorldSrvObject::removeListener(CWorldCliManager * listener){
m_listenerList->remove(listener);
CWorldWorld * world = getWorld();
CWARemoveClientObject * waremove = new CWARemoveClientObject(getObjectId(),
getParentId());
listener->sendAnimation( waremove );
delete waremove;
}
void CWorldSrvObject::updateListener(CWorldCliManager * listener){
CWorldWorld * world = getWorld();
CWAUpdateClientPosition * waupdate =
new CWAUpdateClientPosition(getObjectId(),
getPosition(listener->getMasterCell()));
listener->sendAnimation( waupdate );
delete waupdate;
}
CListener* CWorldSrvObject::getListener(){
CWorldSrvObject * parent;
cdebug << "Object " << getObjectId() << " asked for listeners!\n";
if (m_listenerList != NULL) return m_listenerList;
parent = (CWorldSrvObject*)getParent();
if (parent != NULL){
return parent->getListener();
}
cdebug << "Failed to find listener!\n";
return NULL;
}