BaseNpc::BaseNpc(Ogre::String name, Ogre::SceneManager* m_pSceneMgr, Ogre::Vector3 start)
{
  // Create renderable
  m_pNPC = m_pSceneMgr->createEntity(name, "robot.mesh");
  //m_pNPC->setCastShadows(true);
  m_pNpcNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode(name + "Node");
  m_pNpcNode->attachObject(m_pNPC);
  m_pNpcNode->setPosition(start);

  m_pCurrentState = Idle::Instance();

  // Show name
  Ogre::MovableText* msg = new Ogre::MovableText("TXT_001", "this is the caption");
  msg->setTextAlignment(Ogre::MovableText::H_CENTER, Ogre::MovableText::V_ABOVE); // Center horizontally and display above the node
  m_pNpcNode->attachObject(msg);

  // Create the walking list
  // mWalkList.push_back(Ogre::Vector3(400.0f,  0.0f,  0.0f ));
  // mWalkList.push_back(Ogre::Vector3(400.0f,  0.0f, -200.0f));
  // mWalkList.push_back(Ogre::Vector3(0.0f,  0.0f, -200.0f));
  // mWalkList.push_back(Ogre::Vector3(0.0f,  0.0f, 0.0f));
  // mWalkList.push_back(Ogre::Vector3(400.0f,  0.0f, 400.0f));

  // Set idle animation
  mAnimationState = m_pNPC->getAnimationState("Idle");
  mAnimationState->setLoop(true);
  mAnimationState->setEnabled(true);

  // Set default values for variables
  mWalkSpeed = 35.0f;
  mDirection = Ogre::Vector3::ZERO;
  isMoving = false;
  mName = name;
}
int HOO::allocateEntityToNode(Ogre::SceneManager *& SceneManager,  Ogre::SceneNode *& node, Ogre::Entity*& Ent ,  const Ogre::String& entityName, const Ogre::String& meshName, HOO::entityVector * debugEntityVector){
	try{
		Ent = SceneManager->createEntity( entityName, meshName );
		node->attachObject(Ent);

	} catch( Ogre::Exception & e ){
		Ent = SceneManager->createEntity( entityName, "cube.mesh");

		debugEntityVector->push_back(Ent);
		Ogre::String message = "WARNING ! Failed to load the following mesh : ";
		message += meshName;
		Ogre::LogManager::getSingletonPtr()->logMessage( message);
		node->attachObject(Ent);
		float scale=0.2f;
		node->setScale(scale,scale,scale);

		Ogre::String txtName = "ErrorTxtObject_n";
		txtName += debugEntityVector->size();
		Ogre::MovableText* msg = new Ogre::MovableText(txtName, message ,"BlueHighway-8",int(2/scale),Ogre::ColourValue::Green);
		msg->setTextAlignment(Ogre::MovableText::H_CENTER, Ogre::MovableText::V_CENTER); // Center horizontally and display above the node
		Ogre::AxisAlignedBox AABB =Ent->getWorldBoundingBox(true);
		msg->setLocalTranslation(Ogre::Vector3(0.0f,AABB.getHalfSize()[2]+0.1f,0.0f));
		node->attachObject(msg);
		return HOO::ALLOCATEFAIL;
	}
	return HOO::SUCCESS;
}
void ScoreScreen::LoadLevel(Ogre::String levelName)
{
	ResetCamera();

	Ogre::DotSceneLoader a;
	a.parseDotScene(levelName + ".scene", "General", mSceneMgr.get());

	labels.clear();

	for (unsigned int i = 0; i < mGameClient->raceResults.size(); ++i)
	{
		//make the node
		char name[128];
		sprintf_s(name, 128, "playerResult%i", i);

		if (mSceneMgr->hasSceneNode(name))
			mSceneMgr->destroySceneNode(name);

		Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(name);

		Ogre::Entity* ent = mSceneMgr->createEntity("checkBox.mesh");

		//Make the text
		char words[128];
		sprintf_s(words, 128, "Player %i = %d:%d.%d", i + 1, mGameClient->raceResults[i].minutes, mGameClient->raceResults[i].seconds, mGameClient->raceResults[i].ms);

		Ogre::MovableText* text = new Ogre::MovableText(name, words);
		text->setTextAlignment(Ogre::MovableText::H_LEFT, Ogre::MovableText::V_CENTER);
		node->setPosition(-3, 1.5 - (i*0.6), -5);
		node->scale(1, 0.5, 1);

		std::shared_ptr<PlayerLabel> p = std::shared_ptr<PlayerLabel>(new PlayerLabel(node, ent, text));

		labels.push_back(p);
	}

	//Reset the server
	mGameClient->SendString("reset");

	//Reset the local client stuff
	mGameClient->raceComplete = false;
	mGameClient->raceResults.clear();
	mGameClient->allReady = false;
	mGameClient->allDoneLoading = false;
	mGameClient->startingIndex = 999;
	mGameClient->totalPlayers = 0;
	mGameClient->mConnectedPlayers = NULL;
	mGameClient->id = 0;
}