[Orxonox-commit 2175] r6891 - in code/branches/ai: data/levels src/modules/pickup/items src/orxonox/controllers
gasserlu at orxonox.net
gasserlu at orxonox.net
Mon May 10 16:40:44 CEST 2010
Author: gasserlu
Date: 2010-05-10 16:40:44 +0200 (Mon, 10 May 2010)
New Revision: 6891
Modified:
code/branches/ai/data/levels/pickup.oxw
code/branches/ai/src/modules/pickup/items/DronePickup.cc
code/branches/ai/src/orxonox/controllers/AIController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
code/branches/ai/src/orxonox/controllers/DroneController.cc
code/branches/ai/src/orxonox/controllers/DroneController.h
Log:
DroneController modified, sameTeam() mod.// hack
Modified: code/branches/ai/data/levels/pickup.oxw
===================================================================
--- code/branches/ai/data/levels/pickup.oxw 2010-05-10 14:34:39 UTC (rev 6890)
+++ code/branches/ai/data/levels/pickup.oxw 2010-05-10 14:40:44 UTC (rev 6891)
@@ -23,12 +23,12 @@
?>
<Template name=droneTemplate>
- <Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
+ <Drone name="meineDrohne" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
<attached>
- <Model scale="10" mesh="drone.mesh"/>
+ <Model scale="1" mesh="drone.mesh"/>
</attached>
<collisionShapes>
- <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" />
+ <BoxCollisionShape position="0,0,0" halfExtents="1, 1, 1" />
</collisionShapes>
Modified: code/branches/ai/src/modules/pickup/items/DronePickup.cc
===================================================================
--- code/branches/ai/src/modules/pickup/items/DronePickup.cc 2010-05-10 14:34:39 UTC (rev 6890)
+++ code/branches/ai/src/modules/pickup/items/DronePickup.cc 2010-05-10 14:40:44 UTC (rev 6891)
@@ -133,16 +133,19 @@
this->destroy();
//Attach to pawn
- Drone* drone = new Drone(this);
+ Drone* drone = new Drone(pawn->getCreator()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
drone->addTemplate(this->getDroneTemplate());
- pawn->attach(drone);
+
Controller* controller = drone->getController();
DroneController* droneController = dynamic_cast<DroneController*>(controller);
if(droneController != NULL)
{
droneController->setOwner(pawn);
}
-
+
+ Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30);
+ drone->setPosition(spawnPosition);
+
//! The pickup has been used up.
this->setUsed(false);
}
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2010-05-10 14:34:39 UTC (rev 6890)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2010-05-10 14:40:44 UTC (rev 6891)
@@ -101,7 +101,7 @@
if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
this->searchRandomTargetPosition();
-
+/*
random = rnd(maxrand);
if (random < 75 && (this->target_ && !this->bShooting_))
this->bShooting_ = true;
@@ -109,7 +109,7 @@
// stop shooting
random = rnd(maxrand);
if (random < 25 && (this->bShooting_))
- this->bShooting_ = false;
+ this->bShooting_ = false; */
}
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-05-10 14:34:39 UTC (rev 6890)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-05-10 14:40:44 UTC (rev 6891)
@@ -500,6 +500,14 @@
}
}
+ DroneController* droneController = 0;
+ droneController = orxonox_cast<DroneController*>(entity1->getController());
+ if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+ return true;
+ droneController = orxonox_cast<DroneController*>(entity2->getController());
+ if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+ return true;
+
return (team1 == team2 && team1 != -1);
}
}
Modified: code/branches/ai/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/DroneController.cc 2010-05-10 14:34:39 UTC (rev 6890)
+++ code/branches/ai/src/orxonox/controllers/DroneController.cc 2010-05-10 14:40:44 UTC (rev 6891)
@@ -58,6 +58,8 @@
this->drone_ = 0;
this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this)));
+
+ this->owner_.setCallback(createFunctor(&DroneController::ownerDied, this));
}
DroneController::~DroneController()
@@ -82,24 +84,37 @@
const Vector3& ownerPosition = getOwner()->getWorldPosition();
const Vector3& dronePosition = getDrone()->getWorldPosition();
- const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(dronePosition-ownerPosition); //Vector from Drone To Owner out of drones local coordinate system
+ const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(ownerPosition-dronePosition); //Vector from Drone To Owner out of drones local coordinate system
int distance = sqrt( (ownerPosition.x-dronePosition.x)*(ownerPosition.x-dronePosition.x)
+ (ownerPosition.y-dronePosition.y)*(ownerPosition.y-dronePosition.y)
+ (ownerPosition.z-dronePosition.z)*(ownerPosition.z-dronePosition.z)); //distance to Owner
if (distance > 500) { //TODO: variable implementation of maxdistance
- drone_->moveUpDown(-locOwnerDir.y);
- drone_->moveFrontBack(locOwnerDir.z);
- drone_->moveRightLeft(-locOwnerDir.x);
+ drone_->moveUpDown(locOwnerDir.y);
+ drone_->moveFrontBack(-locOwnerDir.z);
+ drone_->moveRightLeft(locOwnerDir.x);
}
+
+ random = rnd(maxrand);
+ if ( random < 30 && (!this->target_))
+ this->searchNewTarget();
+
+
+ this->aimAtTarget();
+ drone_->fire(0);
+
+
+
+
+ //COUT(0) << "Drone: " << dronePosition << endl;
+ //COUT(0) << "Distance: " << distance << endl;
+ COUT(0) << "locDrone: " << locOwnerDir << endl;
+ COUT(0) << "target: " << targetPosition_ << endl;
COUT(0) << "Owner: " << ownerPosition << endl;
- COUT(0) << "Drone: " << dronePosition << endl;
- COUT(0) << "Distance: " << distance << endl;
- COUT(0) << "locDrone: " << locOwnerDir << endl;
+ COUT(0) << "Rand: " << random << endl;
-
/*
// search enemy
random = rnd(maxrand);
@@ -159,17 +174,17 @@
setTargetPosition(this->getControllableEntity()->getPosition());
-/* myDrone->setRotationThrust(25);
- myDrone->setAuxilaryThrust(30);
- myDrone->rotateYaw(10*dt); */
}
SUPER(AIController, tick, dt);
- // you can use the following commands for steering
- // - moveFrontBack, moveRightLeft, moveUpDown
- // - rotatePitch, rotateYaw, rotateRoll
- // - apply the to myDrone (e.g. myDrone->rotateYaw(..) )
+ }
+ void DroneController::ownerDied()
+ {
+ if (this->drone_)
+ this->drone_->destroy();
+ else
+ this->destroy();
}
}
Modified: code/branches/ai/src/orxonox/controllers/DroneController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/DroneController.h 2010-05-10 14:34:39 UTC (rev 6890)
+++ code/branches/ai/src/orxonox/controllers/DroneController.h 2010-05-10 14:40:44 UTC (rev 6891)
@@ -32,6 +32,7 @@
#include "OrxonoxPrereqs.h"
#include "AIController.h"
+#include "core/WeakPtr.h"
#include "tools/interfaces/Tickable.h"
#include "tools/Timer.h"
@@ -63,10 +64,11 @@
protected:
virtual void action();
+ void ownerDied();
private:
Timer actionTimer_;
- Pawn* owner_;
+ WeakPtr<Pawn> owner_;
Drone* drone_;
};
}
More information about the Orxonox-commit
mailing list