130 lines
3.2 KiB
C
130 lines
3.2 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 "server.H"
|
|
#include <math.h>
|
|
#include <iostream.h>
|
|
#include "player.H"
|
|
#include "srvclimanager.H"
|
|
|
|
CPlayer::CPlayer(DWORD objectId,CWorldObject * parent, DWORD geometryId,const CPosition & position, const CDirection & direction )
|
|
:CSrvObject(objectId,parent,geometryId,position,direction){
|
|
|
|
cdebug << "CPlayer::CPlayer\n";
|
|
|
|
m_manager = NULL;
|
|
|
|
// setPosition ( CPosition(0,3.5,0) );
|
|
// setDirection ( CDirection(0.0,0.0,0.0) );
|
|
}
|
|
|
|
CPlayer::~CPlayer(){
|
|
}
|
|
|
|
char * CPlayer::getObjectType(){
|
|
return "player";
|
|
}
|
|
|
|
void CPlayer::setManager(CClientManager * manager){
|
|
m_manager = manager;
|
|
}
|
|
|
|
CClientManager * CPlayer::getManager(){
|
|
return m_manager;
|
|
}
|
|
|
|
void CPlayer::updatePosition( const CPosition & position ){
|
|
CSrvObject::updatePosition(position);
|
|
}
|
|
|
|
int CPlayer::moveTo( CWorldObject * parent ){
|
|
int result = CSrvObject::moveTo(parent);
|
|
getManager()->updateMasterCell((CSrvObject*)getMasterCell());
|
|
return result;
|
|
}
|
|
|
|
|
|
double CPlayer::getPosX(){
|
|
return getPosition().getX();
|
|
}
|
|
|
|
double CPlayer::getPosY(){
|
|
return getPosition().getY();
|
|
}
|
|
|
|
double CPlayer::getPosZ(){
|
|
return getPosition().getZ();
|
|
}
|
|
|
|
double CPlayer::getAngle(){
|
|
return getDirection().getHeading();
|
|
}
|
|
|
|
void CPlayer::move(double length){
|
|
BYTE playercollidable;
|
|
|
|
double angle = getAngle();
|
|
CPosition position(getPosX()+length*sin(-angle*PI/180.0),getPosY()+length*cos(-angle*PI/180.0),getPosZ());
|
|
|
|
playercollidable=getCollidable();
|
|
setCollidable(-1);
|
|
CSrvObject * masterCell = (CSrvObject*)getMasterCell();
|
|
if (masterCell == NULL) {
|
|
cout << "ERROR: Cant find master cell!\n";
|
|
return ;
|
|
}
|
|
CDoubleArray * distances =
|
|
masterCell->getDistances(CBeam(position,CVector(0,0,-1)),-5.0,5.0);
|
|
setCollidable(playercollidable);
|
|
if (distances == NULL) return;
|
|
|
|
double dist = 5.0;
|
|
cdebug << "Move : Distances :";
|
|
|
|
int index = distances->getNumElements();
|
|
if (index != 0){
|
|
while (index-- >0){
|
|
|
|
cdebug << " " << distances->get(index);
|
|
|
|
if (distances->get(index) < dist) dist = distances->get(index);
|
|
}
|
|
} else {
|
|
dist = 5.0;
|
|
}
|
|
position.setValue(2,position.getZ()-dist);
|
|
|
|
cdebug << "\n";
|
|
|
|
delete distances;
|
|
|
|
updatePosition ( position );
|
|
}
|
|
|
|
void CPlayer::turn(double angle){
|
|
updateDirection ( CDirection(getAngle()+angle,0.0,0.0) );
|
|
}
|
|
|
|
int CPlayer::objectReachable( CWorldObject * worldObject ){
|
|
cdebug << "CPlayer::objectReachable: Not implemented!!! Player reach everything :)\n";
|
|
return TRUE;
|
|
}
|
|
|
|
|