Index: /branches/adm/src/world_entities/WorldEntities.am
===================================================================
--- /branches/adm/src/world_entities/WorldEntities.am	(revision 10688)
+++ /branches/adm/src/world_entities/WorldEntities.am	(revision 10689)
@@ -34,4 +34,5 @@
                 world_entities/weapons/spike_thrower.cc \
                 world_entities/weapons/acid_launcher.cc \
+                world_entities/weapons/bsp_weapon.cc \
                 \
                 world_entities/projectiles/lbolt.cc \
@@ -187,4 +188,5 @@
                 weapons/spike_thrower.h \
                 weapons/acid_launcher.h \
+                weapons/bsp_weapon.h \
                 \
                 projectiles/lbolt.h \
Index: /branches/adm/src/world_entities/npcs/adm_turret.cc
===================================================================
--- /branches/adm/src/world_entities/npcs/adm_turret.cc	(revision 10688)
+++ /branches/adm/src/world_entities/npcs/adm_turret.cc	(revision 10689)
@@ -139,4 +139,6 @@
         this->bFire = false;
         this->playerVisible = false;
+
+	
 }
 
@@ -151,8 +153,21 @@
 
 
-  Vector playerPos = this->myTarget->getAbsCoor();
+  Vector playerPos = this->myTarget->getAbsCoor() + Vector(0, 12, 0);
   Vector ds = playerPos - ( this->cannons->getAbsCoor() );
-  if ( isActive && ds.len() <= range )
+  if ( isActive && ds.len() <= range && playerVisible )
+  {
     this->moveTowards( ds,  dt);
+
+  //if target within +/- 2.5 degrees of aim -> fire
+  Vector dv1 = ds;
+  dv1.normalize();
+  Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0));
+  dv2.normalize();
+  float angle = dv1.dot(dv2);
+  if (angle > 0.999)
+	{
+	this->fire();
+	}
+  }
   else
     this->moveTowards( Vector(0, -1, 0), dt );
@@ -212,25 +227,6 @@
 }
 
-bool AdmTurret::isVisible(const WorldEntity myTarget)
-{
-return true;
-}
-
-float AdmTurret::aim(const WorldEntity Target)
-{
-return 0;
-}
-
 void AdmTurret::fire()
 {
-	// Projectile* pj =  this->getProjectile();
-	// if (pj == NULL) return;
-
-	//pj->setOwner(this->getOwner());
-	//pj->setParent(PNode::getNullParent());
-	//pj->setVelocity(this->getAbsDir().apply(Vector( , , )) );
-	//pj->setAbsCoor(this->getEmissionPoint());
-	//pj->setAbsDir(this->getAbsDir());
-	//pj->activate();
 }
 
@@ -245,4 +241,10 @@
 	
 	this->cannons->toList( getOMListNumber() );
+
+	this->weapon = new BspWeapon();
+	this->weapon->setParent( this->cannons );
+	this->weapon->toList( getOMListNumber() );
+	this->weapon->setAbsCoor( this->cannons->getAbsCoor() );
+	this->weapon->setAbsDir( this->weapon->getAbsDir() * Quaternion( PI, Vector(0, 1, 0) ) );
 }
 
@@ -257,5 +259,4 @@
 	this->sensor->toList( getOMListNumber() );
 }
-
 
 void AdmTurret::moveTowards( Vector targetDir, float dt )
@@ -336,4 +337,5 @@
   Vector dir = this->myTarget->getAbsCoor() - pos;
 
+
   this->playerVisible = true;
   for( ObjectList<BspEntity>::const_iterator bspIterator = BspEntity::objectList().begin();
Index: /branches/adm/src/world_entities/npcs/adm_turret.h
===================================================================
--- /branches/adm/src/world_entities/npcs/adm_turret.h	(revision 10688)
+++ /branches/adm/src/world_entities/npcs/adm_turret.h	(revision 10689)
@@ -11,5 +11,5 @@
 
 #include "world_entity.h"
-#include "weapons/light_blaster.h"
+#include "weapons/bsp_weapon.h"
 
 class AdmTurret : public WorldEntity
@@ -37,6 +37,4 @@
                    WorldEntity* sensor;
                    WorldEntity* myTarget;
-                   bool isVisible(const WorldEntity myTarget);
-                   float aim(const WorldEntity Target);
                    void fire();
 
@@ -58,4 +56,6 @@
                    bool playerVisible;
                    void updatePlayerVisible();
+
+		BspWeapon* weapon;
       };
 
Index: /branches/adm/src/world_entities/weapons/aiming_system.cc
===================================================================
--- /branches/adm/src/world_entities/weapons/aiming_system.cc	(revision 10688)
+++ /branches/adm/src/world_entities/weapons/aiming_system.cc	(revision 10689)
@@ -112,5 +112,5 @@
 void AimingSystem::hit(float damage, WorldEntity* killer)
 {
-  if( this->owner != killer)
+  if( this->owner != killer && killer != this && !killer->isA( AimingSystem::staticClassID() ) )
   {
     //PRINTF(0)("real hit: %s\n", killer->getClassCName());
@@ -127,6 +127,4 @@
 void AimingSystem::tick(float dt)
 {
-
-
 }
 
Index: /branches/adm/src/world_entities/weapons/bsp_weapon.cc
===================================================================
--- /branches/adm/src/world_entities/weapons/bsp_weapon.cc	(revision 10689)
+++ /branches/adm/src/world_entities/weapons/bsp_weapon.cc	(revision 10689)
@@ -0,0 +1,191 @@
+/*
+* orxonox - the future of 3D-vertical-scrollers
+*
+* Copyright (C) 2004 orx
+*
+* 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, or (at your option)
+* any later version.
+*
+*     ### File Specific:
+*     main-programmer: Reto Luechinger
+*/
+
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
+#include "bsp_weapon.h"
+#include "loading/load_param.h"
+#include "debug.h"
+#include "loading/load_param_xml.h"
+
+#include "environments/bsp_entity.h"
+
+ObjectListDefinition(BspWeapon);
+CREATE_FACTORY(BspWeapon);
+
+/**
+*  Standard constructor
+*/
+BspWeapon::BspWeapon ()
+{
+	this->init();
+}
+
+/**
+* destructs the BspWeapon, deletes allocated memory
+*/
+BspWeapon::~BspWeapon ()
+{
+          // will be deleted
+}
+
+/**
+* Constructor with XML Element
+*/
+BspWeapon::BspWeapon (const  TiXmlElement* root)
+{
+	this->init();
+	if (root != NULL)
+        {
+		this->loadParams(root);
+	}
+}
+/**
+* XML Loader
+*/
+void BspWeapon::loadParams(const TiXmlElement* root)
+{
+	if (root != NULL)
+	{
+		WorldEntity::loadParams(root);
+
+		LoadParam(root, "Range", this, BspWeapon, setRange)
+			.describe("the range after which the Weapon hits no more")
+		.defaultValues("");
+                LoadParam(root, "Damage", this, BspWeapon, setDamage)
+                        .describe("Damage that the weapon inflicts"); 
+		LoadParam(root, "FireRate", this, BspWeapon, setFireRate)
+  			.describe("how fast it shoots");
+		LoadParam(root, "AlwaysHits", this, BspWeapon, setAlwaysHits)
+  			.describe("No, if the weapon should hit with a probability");
+	}
+}
+
+	
+
+void BspWeapon::tick( float dt )
+{
+	if (bFire) {
+		if (bRate < 0) {
+			bRate += fireRate;
+			this->shoot();
+		}
+		else {
+			bRate = bRate - dt;
+		}	
+	}
+	else {
+		bRate -= dt;
+		if (bRate < 0)
+			bRate = 0;
+	}
+}
+
+void BspWeapon::init()
+{
+	bRate = 0;
+	bFire = true;
+	range = 1000;
+	damage = 10;
+	fireRate = 0.5;
+	alwaysHits = true;
+
+	this->registerObject(this, BspWeapon::_objectList);
+	this->aimingSystem = new AimingSystem( this );
+	this->aimingSystem->setParent( this );
+	this->aimingSystem->toList(OM_GROUP_00);
+}
+
+void BspWeapon::shoot()
+{
+	std::list<WorldEntity*>::iterator entityIterator;
+	// for all bsp managers check all entities
+	Vector pos = this->getAbsCoor();
+	Vector dir = pos + this->getAbsDir().apply( Vector( 1, 0, 0 ) )*range;
+	
+	
+	float shortestDist = range;
+	for( ObjectList<BspEntity>::const_iterator bspIterator = BspEntity::objectList().begin();
+		bspIterator != BspEntity::objectList().end();
+		bspIterator++) {
+		float res = (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollisionRay( pos, dir, dir.len() + 1 );
+	
+		if ( res < shortestDist )
+			shortestDist = res;
+	}
+
+	WorldEntity* target = aimingSystem->getNearestTarget();
+	aimingSystem->flushList();
+
+	bool hit = false;
+
+	if ( target == NULL )
+		printf("NOTING HIT\n");
+	else
+	{
+		printf( "HIT %s\n", target->getClassName().c_str() );
+
+		if (!alwaysHits){
+			float r = rand();
+			r = r/RAND_MAX;
+			float res = (target->getAbsCoor() - this->getAbsCoor()).len();
+			float p = 1 - res*res/range/range;
+			if (r < p )
+				hit = true;
+		}
+		else hit = true;
+	}
+
+	if ( !hit )
+	{
+		Vector explosionPos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 1, 0, 0 ) )*shortestDist;
+
+		//TODO create explosion at explosionPos
+	}
+
+	
+}
+
+void BspWeapon::draw() const
+{
+  WorldEntity::draw();
+
+
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+
+  glPushAttrib(GL_ENABLE_BIT);
+
+  glDisable(GL_LIGHTING);
+  glDisable(GL_TEXTURE_2D);
+  glDisable(GL_BLEND);
+  glLineWidth(2.0);
+
+
+  Vector mp = this->getAbsCoor();
+  Vector op = this->getAbsDir().apply( Vector(1, 0, 0) );
+  op *= 100;
+  op += mp;
+
+  glColor3f(1.0, 1.0, 1.0 );
+  glBegin(GL_LINE_STRIP);
+    glVertex3f(mp.x, mp.y, mp.z);
+    glVertex3f(op.x, op.y, op.z);
+  glEnd();
+
+  
+  glPopAttrib();
+  glPopMatrix();
+  
+}
Index: /branches/adm/src/world_entities/weapons/bsp_weapon.h
===================================================================
--- /branches/adm/src/world_entities/weapons/bsp_weapon.h	(revision 10689)
+++ /branches/adm/src/world_entities/weapons/bsp_weapon.h	(revision 10689)
@@ -0,0 +1,45 @@
+/*
+* file bsp_weapon.h
+* A weapon that shoots both at player and environment (pnode and bsp).
+*/
+
+#ifndef _BSP_WEAPON_H
+#define _BSP_WEAPON_H
+
+#include "world_entity.h"
+#include "aiming_system.h"
+
+class BspWeapon : public WorldEntity
+	{
+		ObjectListDeclaration(BspWeapon);
+	public:
+		BspWeapon ();
+		BspWeapon (const  TiXmlElement* root);
+		virtual ~BspWeapon();
+
+		void init();
+		void loadParams(const TiXmlElement* root);
+		void fire(bool fire){ bFire = fire; }
+		virtual void tick(float dt);
+		virtual void draw() const;
+
+
+	private:
+
+		void shoot();
+		float range;
+		void setRange( float r ){ this->range = r; }
+		float damage;
+		void setDamage( float d ){ this->damage = d; }
+		float fireRate;
+		void setFireRate( float r ){ this->fireRate = r; }
+		bool alwaysHits;
+		void setAlwaysHits( bool r ){ this->alwaysHits = r; }
+
+		float bRate;
+		bool bFire;
+
+		AimingSystem* aimingSystem;
+	};
+
+#endif
