
#include "GameObject.h"
#include "GameWorld.h"
#include "GameNetInterface.h"

namespace DinastyOnline {
	namespace Network {

		// Player constructor
		GameObject::GameObject() {
			// assign a random starting position for the player.
			position.x = TNL::Random::readI();
			position.y = TNL::Random::readI();
			
			mObjectTypeMask = UnknownType;
			
			mNetFlags.set(Ghostable);
			world = NULL;
		}
	
		GameObject::~GameObject() {
			if(!world)
				return;
	
			// remove the player from the list of players in the game.
			world->removeFromGameObjectList(this);
		}
	
		void GameObject::addToWorld(GameWorld *theWorld) {
			// add the player to the list of players in the game.
			theWorld->addToGameObjectList(this);
			this->world = theWorld;
		}
	
		bool GameObject::onGhostAdd(TNL::GhostConnection *theConnection) {
			TNL::logprintf("Ghost added!");
			addToWorld(((GameNetInterface *) theConnection->getInterface())->world);
			return true;
		}
		
		void GameObject::setScopeAlways() {
			if(!world)
				return;
			
			world->setScopeAlwaysObject(this);
		}
	}
}

