Index: /code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10761)
+++ /code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	(revision 10762)
@@ -242,14 +242,4 @@
     }
 
-
-    int CommonController::getFiremode(std::string name)
-    {
-        for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
-        {
-            if (it->first == name)
-                return it->second;
-        }
-        return -1;
-    }
     bool CommonController::isCloseAtTarget(float distance) const
     {
@@ -262,74 +252,51 @@
             return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
     }
-    void CommonController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
-    {
-        this->bSetupWorked = false;
-        if(this->getControllableEntity())
+    
+
+    bool CommonController::canFire()
+    {
+        //check pointers
+        if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity())
+            return false;
+        
+        //check if this points in the direction of target_
+
+        Vector3 myPosition = this->getControllableEntity()->getWorldPosition();
+        Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition();
+        Vector3 differenceVector = targetPosition - myPosition;
+        float scalarProduct = differenceVector * WorldEntity::FRONT;
+        Vector3 projection = scalarProduct * WorldEntity::FRONT;
+        if ((differenceVector - projection).length() > 50)
+            return false;
+       
+
+        //check if there are allies on the way
+        Vector3 allyPosition, allyDifference, allyProjection;
+        float allyScalarProduct;
+        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
-            Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
-            if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip
-            {
-                this->weaponModes_.clear(); // reset previous weapon information
-                WeaponSlot* wSlot = 0;
-                for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
-                {
-                    WeaponMode* wMode = 0;
-                    for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
-                    {
-                        std::string wName = wMode->getIdentifier()->getName();
-                        if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new"
-                            weaponModes_[wName] = wMode->getMode();
-                    }
-                }
-                if(weaponModes_.size())//at least one weapon detected
-                    this->bSetupWorked = true;
-            }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
-        }
+            if (!it->getControllableEntity())
+                continue;
+            if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
+            {
+                allyPosition = it->getControllableEntity()->getWorldPosition();
+                allyDifference = allyPosition - myPosition;
+                allyScalarProduct = allyDifference * WorldEntity::FRONT;
+                allyProjection = allyScalarProduct * WorldEntity::FRONT;
+                if (allyScalarProduct < 0 || allyScalarProduct > scalarProduct)
+                    continue;
+                if ((allyDifference - allyProjection).length() < 50)
+                    return false;
+            } 
+        }
+
+        return true;
+
     }
     void CommonController::doFire()
     {
-          if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
-        {
-            this->setupWeapons();
-        }
-        else if(this->getControllableEntity() && weaponModes_.size()&&this->bShooting_ && 
-            this->isCloseAtTarget((1 + 2)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
-        {
-            int firemode;
-            float random = rnd(1);//
-            if (this->isCloseAtTarget(130) && (firemode = getFiremode("LightningGun")) > -1 )
-            {//LENSFLARE: short range weapon
-                this->getControllableEntity()->fire(firemode); //ai uses lens flare if they're close enough to the target
-            }
-           
-            else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon
-                this->getControllableEntity()->fire(firemode);
-        
-        }
-    }
-    bool CommonController::isLookingAtTarget(float angle) const
-    {
-        if (!this->getControllableEntity())
-            return false;
-
-        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
-    }
-
-    void CommonController::aimAtTarget()
-    {
-        if (!this->target_ || !this->getControllableEntity())
-            return;
-
-        static const float hardcoded_projectile_speed = 750;
-
-        Vector3 aimPosition = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), 
-            hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
-
-        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
-        if (pawn)
-            pawn->setAimPosition(aimPosition);
-    }
-    
- 
+        this->getControllableEntity()->fire(0);
+    }
+   
 
 }
Index: /code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10761)
+++ /code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	(revision 10762)
@@ -133,5 +133,6 @@
             bool isLookingAtTarget(float angle) const;
 
-
+            //checks if spaceship points at enemy and if there are allies inbetween
+            bool canFire();
             std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
             //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
Index: /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10761)
+++ /code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	(revision 10762)
@@ -95,4 +95,7 @@
         }
            */
+        
+        if (canFire())
+            doFire();
       
     }
Index: /code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10761)
+++ /code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	(revision 10762)
@@ -58,10 +58,5 @@
             return;
         
-        /*if (this->target_)
-        {
-            this->aimAtTarget();
-            this->doFire();
-            this->bShooting_ = true;
-        }*/
+        
         if (this->bHasTargetPosition_)
         {
@@ -91,4 +86,7 @@
         if (this->target_ && this->myWingman_)
             this->myWingman_->setTarget(this->target_);
+
+        if (canFire())
+            doFire();
                 
 
Index: /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10761)
+++ /code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	(revision 10762)
@@ -111,15 +111,8 @@
     void WingmanController::tick(float dt)
     {   
-        //-------------------------------------------------------
-       /* if (this->target_)
-        {
-            this->aimAtTarget();
-            this->doFire();
-            this->bShooting_ = true;
-        }*/
+       
         
         if (!this->isActive())
             return;
-        //--------------------------Stay in formation--------------------------
         if (!this->target_)
         {
@@ -128,5 +121,5 @@
         else
         {
-            
+
         }
         if (this->bHasTargetPosition_)
@@ -135,15 +128,5 @@
         } 
         
-        //--------------------------Attack same target as the Leader--------------------------
-
-        /*if (this->target_)
-        {
-            this->aimAtTarget();
-            this->doFire();
-        }
-        */
-        
-        //orxout(internal_error) << "I am " << this << endl;
-
+       
         
         SUPER(WingmanController, tick, dt);
@@ -169,4 +152,7 @@
 
         }
+
+        if (canFire())
+            doFire();
     }
      
