Index: code/branches/merge/src/orxonox/objects/SpaceShip.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/SpaceShip.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/SpaceShip.cc	(revision 1264)
@@ -23,5 +23,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht
  *
  */
@@ -37,4 +37,5 @@
 #include <OgreSceneNode.h>
 
+#include "CameraHandler.h"
 #include "tinyxml/tinyxml.h"
 #include "ois/OIS.h"
@@ -50,4 +51,5 @@
 #include "core/XMLPort.h"
 #include "core/ConsoleCommand.h"
+#include "network/Client.h"
 
 namespace orxonox
@@ -64,5 +66,10 @@
     SpaceShip::SpaceShip()
     {
+        RegisterObject(SpaceShip);
+        this->registerAllVariables();
+
         SpaceShip::instance_s = this;
+
+        this->setConfigValues();
 
         this->setMouseEventCallback_ = false;
@@ -73,4 +80,5 @@
 
         this->camNode_ = 0;
+        this->camName_ = "camNode";
 
         this->tt_ = 0;
@@ -96,45 +104,7 @@
         this->setRotationAxis(1, 0, 0);
         this->setStatic(false);
-/*
-        this->moveForward_ = 0;
-        this->rotateUp_ = 0;
-        this->rotateDown_ = 0;
-        this->rotateRight_ = 0;
-        this->rotateLeft_ = 0;
-        this->loopRight_ = 0;
-        this->loopLeft_ = 0;
-        this->brakeForward_ = 0;
-        this->brakeRotate_ = 0;
-        this->brakeLoop_ = 0;
-        this->speedForward_ = 0;
-        this->speedRotateUpDown_ = 0;
-        this->speedRotateRightLeft_ = 0;
-        this->speedLoopRightLeft_ = 0;
-        this->maxSpeedForward_ = 0;
-        this->maxSpeedRotateUpDown_ = 0;
-        this->maxSpeedRotateRightLeft_ = 0;
-        this->maxSpeedLoopRightLeft_ = 0;
-        this->accelerationForward_ = 0;
-        this->accelerationRotateUpDown_ = 0;
-        this->accelerationRotateRightLeft_ = 0;
-        this->accelerationLoopRightLeft_ = 0;
-
-        this->speed = 250;
-        this->loop = 100;
-        this->rotate = 10;
-        this->mouseX = 0;
-        this->mouseY = 0;
-        this->maxMouseX = 0;
-        this->minMouseX = 0;
-        this->moved = false;
-
-        this->brakeRotate(rotate*10);
-        this->brakeLoop(loop);
-*/
-//         this->create();
-
-        RegisterObject(SpaceShip);
-        this->registerAllVariables();
-        this->setConfigValues();
+
+        server_=false;
+
 
         COUT(3) << "Info: SpaceShip was loaded" << std::endl;
@@ -156,7 +126,14 @@
 
     void SpaceShip::registerAllVariables(){
-      Model::registerAllVariables();
-
-
+      registerVar( &camName_, camName_.length()+1, network::STRING, 0x1);
+      registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
+      registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
+      registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
+      registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
+      registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
+      registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
+      registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
+      registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
+      registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
 
     }
@@ -164,9 +141,12 @@
     void SpaceShip::init()
     {
-        if (!setMouseEventCallback_)
-        {
-          InputManager::addMouseHandler(this, "SpaceShip");
-          setMouseEventCallback_ = true;
-        }
+		if ((!network::Client::getSingleton() || network::Client::getSingleton()->getShipID()==objectID ))
+		{
+        	if (!setMouseEventCallback_)
+        	{
+          		InputManager::addMouseHandler(this, "SpaceShip");
+          		setMouseEventCallback_ = true;
+        	}
+		}
 
         // START CREATING THRUSTER
@@ -222,4 +202,5 @@
         this->chFarNode_->setScale(0.4, 0.4, 0.4);
 
+        createCamera();
         // END of testing crosshair
     }
@@ -236,4 +217,5 @@
         Model::loadParams(xmlElem);
         this->create();
+        this->getFocus();
 /*
         if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
@@ -286,6 +268,21 @@
     void SpaceShip::setCamera(const std::string& camera)
     {
-        Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
-        this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
+      camName_=camera;
+      // change camera attributes here, if you want to ;)
+    }
+    
+    void SpaceShip::getFocus(){
+      COUT(4) << "requesting focus" << std::endl;
+      if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID)
+        CameraHandler::getInstance()->requestFocus(cam_);
+      
+    }
+    
+    void SpaceShip::createCamera(){
+//       COUT(4) << "begin camera creation" << std::endl;
+      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
+      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
+      this->camNode_->setPosition(/*this->getNode()->getPosition() +*/ Vector3(-50,0,10));
+      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
 /*
 //        node->setInheritOrientation(false);
@@ -293,13 +290,14 @@
         cam->lookAt(Vector3(0,20,0));
         cam->roll(Degree(0));
-*/
-
-        cam->setPosition(Vector3(-200,0,35));
+      *//*COUT(4) << "creating new camera" << std::endl;*/
+      cam_ = new Camera(this->camNode_);
+
+      cam_->setTargetNode(this->getNode());
 //        cam->setPosition(Vector3(0,-350,0));
-        cam->lookAt(Vector3(0,0,35));
-        cam->roll(Degree(-90));
-
-        this->camNode_->attachObject(cam);
-        GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
+      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
+        this->setBacksync(true);
+        CameraHandler::getInstance()->requestFocus(cam_);
+      }
+
     }
 
@@ -337,4 +335,7 @@
         XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
         XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
+        server_=true; // TODO: this is only a hack
+        SpaceShip::create();
+        getFocus();
     }
 
@@ -448,5 +449,6 @@
         if (this->bLMousePressed_ && this->timeToReload_ <= 0)
         {
-            new Projectile(this);
+            Projectile *p = new Projectile(this);
+            p->setBacksync(true);
             this->timeToReload_ = this->reloadTime_;
         }
@@ -520,24 +522,28 @@
         }
 
-        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
+        if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ ){
+          COUT(4) << "steering our ship: " << objectID << " mkeyboard: " << mKeyboard << std::endl;
+          if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
             this->acceleration_.x = this->translationAcceleration_;
-        else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
+          else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
             this->acceleration_.x = -this->translationAcceleration_;
-        else
+          else
             this->acceleration_.x = 0;
 
-        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
+          if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
             this->acceleration_.y = -this->translationAcceleration_;
-        else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
+          else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
             this->acceleration_.y = this->translationAcceleration_;
-        else
+          else
             this->acceleration_.y = 0;
 
-        if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
+          if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
             this->momentum_ = Radian(-this->rotationAccelerationRadian_);
-        else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
+          else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
             this->momentum_ = Radian(this->rotationAccelerationRadian_);
-        else
+          else
             this->momentum_ = 0;
+        }/*else
+          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
 
         WorldEntity::tick(dt);
