Changeset 10898
- Timestamp:
- Nov 30, 2015, 4:04:16 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10888 r10898 36 36 ?> 37 37 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> 38 <TeamSpawnPoint team= 1position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />38 <TeamSpawnPoint team=0 position="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 39 39 40 40 <!-- … … 102 102 <actionpoints> 103 103 <Actionpoint position="0,0,0" action="FLY" /> 104 <Actionpoint position="-1000,750,-500" action="ATTACK" attack=" ss3" />104 <Actionpoint position="-1000,750,-500" action="ATTACK" attack="attack" /> 105 105 <Actionpoint position="-1000,750,-500" action="PROTECt" protectMe=true /> 106 <Actionpoint position="-1000,750,-500" action="PROTECt" protect=" fuck" />106 <Actionpoint position="-1000,750,-500" action="PROTECt" protect="protect" /> 107 107 <Actionpoint position="-1000,750,-500" action="FIGHTALL" /> 108 108 </actionpoints> … … 142 142 </templates> 143 143 </SpaceShip> 144 <SpaceShip position="3000, 1000, 2000" lookat="0,0,0" team=2 name=" ss3">145 <templates> 146 <Template link=spaceshipassff /> 147 </templates> 148 </SpaceShip> 149 <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=0 name=" fuck">150 <templates> 151 <Template link=spaceshipassff /> 152 </templates> 153 </SpaceShip> 154 155 -->144 <SpaceShip position="3000, 1000, 2000" lookat="0,0,0" team=2 name="attack"> 145 <templates> 146 <Template link=spaceshipassff /> 147 </templates> 148 </SpaceShip> 149 <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=0 name="protect"> 150 <templates> 151 <Template link=spaceshipassff /> 152 </templates> 153 </SpaceShip> 154 --> 155 156 156 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS --> 157 157 <!-- HERE STARTS DEMO FOR FIGHTING --> … … 253 253 </controller> 254 254 </SpaceShip> 255 <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1>255 <!-- <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1> 256 256 <templates> 257 257 <Template link=spaceshipassff /> … … 272 272 </controller> 273 273 </SpaceShip> 274 274 --> 275 275 276 276 <!-- HERE ENDS DEMO FOR FIGHTING --> -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10888 r10898 122 122 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 123 123 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); 124 if (this->actionCounter_ % 2 == 0) 125 this->startAttackingEnemiesThatAreClose(); 124 // if (this->actionCounter_ % 2 == 0) 126 125 //No action -> pop one from stack 127 126 if (this->action_ == Action::NONE || this->bTakenOver_) … … 133 132 // this->parsedActionpoints_.push_back(point); 134 133 // } 134 this->startAttackingEnemiesThatAreClose(); 135 135 136 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()) 136 137 { … … 209 210 else if (this->action_ == Action::FLY) 210 211 { 212 this->startAttackingEnemiesThatAreClose(); 211 213 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 212 214 { … … 217 219 else if (this->action_ == Action::PROTECT) 218 220 { 221 this->startAttackingEnemiesThatAreClose(); 219 222 if (!this->getProtect()) 220 223 { … … 226 229 else if (this->action_ == Action::ATTACK) 227 230 { 231 this->startAttackingEnemiesThatAreClose(); 228 232 if (!this->hasTarget()) 229 233 { -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10888 r10898 38 38 namespace orxonox 39 39 { 40 /** 41 @brief 42 ActionpointController is a state machine with states: 43 1) NONE 44 2) FLY: fly towards a point 45 3) FIGHT: fight enemies that are in attackRange_ (see FightingController) 46 4) PROTECT: follow this->protect_ 47 5) FIGHTALL: fight all enemies on the map 48 6) ATTACK: fight a specific spaceship 49 This controller always executes an action that is in the back of the vector being used. 50 After current this->action_ is completed, next action becomes the top action (one that will 51 be returned by someVector.back()), and current action either will be removed (if not looping), 52 or moved to the top (if looping). 53 54 Every second action(), which is once in two seconds, this searches the area for enemies that are in attack range, if finds anyone, 55 pushes Action::FIGHT to the stack. That makes spaceship fight enemies inside of a sphere, and when all enemies in range are dead, 56 Action::FIGHT is removed from the stack, and spaceship resumes doing whatever action was being executed before. 57 58 In XML one has to attack Actionpoints in order to achieve any complex behaviour, but in Controller all actionpoints are effectively 59 being stored in an array of type Point::Value. 60 */ 40 61 namespace Action 41 62 { … … 69 90 70 91 virtual void tick(float dt); 71 72 void addActionpoint(WorldEntity* waypoint); 92 /** 93 @brief 94 XML method, example XML usage: 95 <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2"> 96 <templates> 97 <Template link=spaceshipassff /> 98 </templates> 99 <controller> 100 <DivisionController team=0 formationMode="finger4"> 101 <actionpoints> 102 <Actionpoint position="0,0,0" action="FLY" /> 103 <Actionpoint position="-1000,750,-500" action="ATTACK" attack="attack" /> 104 <Actionpoint position="-1000,750,-500" action="PROTECt" protectMe=true /> 105 <Actionpoint position="-1000,750,-500" action="PROTECt" protect="protect" /> 106 <Actionpoint position="-1000,750,-500" action="FIGHTALL" /> 107 </actionpoints> 108 </DivisionController> 109 </controller> 110 </SpaceShip> 111 112 Full description: 113 Adds an Actionpoint to this->actionpoints_. Actionpoint can take arguments like action="attack" attack="name". 114 For documentation on Actionpoint XML arguments, check out Actionpoint.h class 115 If any WorldEntity that is not Actionpoint or its child being sent to actionpoints through XML, 116 action would be assumed to be Action::FLY and target position to be position of the entity. Also, if not Actionpoint 117 is passed, it is assumed to be in a loop. How it works is: in <actionpoints> first all Actionpoints between 118 first Actionpoint with loopStart=true and first following Actionpoint with loopEnd=true are included in a single loop. 119 If they are adjacent (in the input array) with WorldEntity, then WorldEntity is also in a loop. 120 All the Worldentities are assumed to be in loop. 121 122 Loop example: 123 <SpaceShip position="-1500, 1500, -1000" lookat="0,0,0" team=0 name="ss1"> 124 <templates> 125 <Template link=spaceshipassff /> 126 </templates> 127 <controller> 128 <DivisionController team=0 formationMode="wall"> 129 <actionpoints> 130 <Actionpoint position=" 0,2000,-600" action="FLY" loopStart=true/> 131 <Actionpoint position=" 0,2000,-1000" action="FLY" /> 132 <Actionpoint position="400,2000,-1000" action="FLY" /> 133 <Actionpoint position="400,2000,-600" action="FLY" loopEnd=true /> 134 </actionpoints> 135 </DivisionController> 136 </controller> 137 </SpaceShip> 138 139 other loop example: 140 <SpaceShip position="-1500, -1500, -1500" lookat="0,0,0" team=0 name="ss1"> 141 <templates> 142 <Template link=spaceshipassff /> 143 </templates> 144 <controller> 145 <DivisionController team=0 formationMode="diamond"> 146 <actionpoints> 147 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-600" /> 148 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-1000" /> 149 <Model mesh="cube.mesh" scale=8 position="400,2000,-1000" /> 150 <Model mesh="cube.mesh" scale=8 position="400,2000,-600" /> 151 </actionpoints> 152 </DivisionController> 153 </controller> 154 </SpaceShip> 155 156 @note 157 Don't use several loops, and don't use WorldEntities as input to <actionpoints> as I didn't test it well, but you 158 can try if feeling lucky. 159 */ 160 void addActionpoint(WorldEntity* actionpoint); 73 161 WorldEntity* getActionpoint(unsigned int index) const; 74 162 virtual void stayNearProtect(); … … 92 180 virtual bool hasFollower() 93 181 { return true; } 94 182 95 183 protected: 96 184 void startAttackingEnemiesThatAreClose(); … … 104 192 std::vector<WeakPtr<WorldEntity> > actionpoints_; 105 193 float squaredaccuracy_; 106 std::vector<Point > parsedActionpoints_; 107 std::vector<Point > loopActionpoints_; 194 std::vector<Point > parsedActionpoints_;//<! actionpoints as they are stored here after being parsed from XML 195 std::vector<Point > loopActionpoints_; //<! actionpoints that are to be looped 108 196 bool bInLoop_; 109 bool bLoop_; 110 bool bEndLoop_; 111 bool bTakenOver_; 197 bool bLoop_; //<! is state machine looping? 198 bool bEndLoop_; 199 bool bTakenOver_; //<! are actionpoints taken over from the leader when he died? if yes, top actionpoint 200 //<! is to be executed for the state machine to start working 112 201 //----[/Actionpoint information]---- 113 202 void setProtect (ControllableEntity* protect); 114 203 ControllableEntity* getProtect (); 115 WeakPtr<ControllableEntity> protect_; 116 void fillLoop(); 204 WeakPtr<ControllableEntity> protect_; //<! entity that is to be protected if this->action_ == Action::PROTECT 205 void fillLoop(); //<! moves actionpoints that are should be in loop from parsedActionpoints_ to loopActionpoints_ 117 206 void fillLoopReversed(); 118 void moveBackToTop(); 207 void moveBackToTop(); //<! analog of removing back actionpoint for loopActionpoints_: instead of removing it, 208 //<! move it to the top, so that it will be executed later on. 119 209 void setClosestTarget(); 120 210 Pawn* closestTarget(); 121 211 //----[Actionpoint methods]---- 122 void executeActionpoint(); 123 void nextActionpoint(); 124 void pushAction(Point& p); 125 void popAction(); 212 /** 213 @brief 214 Sets this->target_, this->targetPosition_, this->protect_ and this->action_ depending 215 on the current actionpoint in the vector parsedActionpoints_ if not looping or 216 loopActionpoints_ if looping. 217 @note 218 */ 219 void executeActionpoint(); 220 /** 221 @brief 222 If this->bLoop_, move back action to top (back is the current one, top is the last), 223 otherwise remove back actionpoint. 224 @note 225 actionpoints_ is only used for XML, real state stacks are parsedActionpoints_ and loopActionpoints_ 226 */ 227 void nextActionpoint(); 126 228 //----[Actionpoint methods]---- 127 229 bool bFirstTick_; -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10891 r10898 224 224 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f); 225 225 } 226 // void FightingController::doFire()227 // {228 // if ( !this->target_ || !this->getControllableEntity() )229 // {230 // return;231 // }232 233 // Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );234 235 // if ( pawn )236 // pawn->setAimPosition( this->positionOfTarget_ );237 // float distance = CommonController::distance (this->getControllableEntity(), this->target_);238 // this->getControllableEntity() ->fire(distance < 1500 ? (distance < 1000 && distance > 700 ? 3 : 0) : (1));239 // }240 226 241 227 -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10888 r10898 35 35 namespace orxonox 36 36 { 37 /** 38 @brief 39 FightingController stores all the fighting methods and member variables of AI. 40 Main methods here are maneuver() and dodge(). 41 */ 37 42 class _OrxonoxExport FightingController : public FlyingController 38 43 { … … 49 54 ControllableEntity* getTarget() const 50 55 { return this->target_; } 51 bool bKeepFormation_; 56 bool bKeepFormation_; //even if action_ == FIGHT, you might still want to keep formation if far enough form the target 52 57 53 58 protected: 54 void setTarget(ControllableEntity* target); 59 void setTarget(ControllableEntity* target); //set a target to shoot at 55 60 56 void setPositionOfTarget(const Vector3& target); 57 void setOrientationOfTarget(const Quaternion& orient); 58 void stopLookingAtTarget(); 59 void startLookingAtTarget(); 60 void lookAtTarget(float dt); 61 void setPositionOfTarget(const Vector3& target); //good to know where target is 62 void setOrientationOfTarget(const Quaternion& orient); //I don't really use that 63 void stopLookingAtTarget(); //<! target dead -> you need to be able to fly 64 void startLookingAtTarget(); //<! if close to target, no need to fly, just rotate yourself 65 void lookAtTarget(float dt); //<! rotate yourself towards target 61 66 62 void maneuver(); 63 void dodge(const Vector3& thisPosition, Vector3& diffUnit); 64 void dodgeTowards (Vector3& position); 65 bool canFire(); 66 void doFire(); 67 void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on 68 //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_. 69 void dodge(const Vector3& thisPosition, Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between 70 //<! this and target_ plus or minus some amount in difference vector direction, 71 //<! depending on whether it is better to close up or survive. 72 void dodgeTowards (Vector3& position); //fly towards position and awoid being hit 73 bool canFire(); //<! check if target_ is in radius and if this is looking at target_ 74 void doFire(); //<! choose weapon, set aim at target_ and fire 67 75 WeakPtr<ControllableEntity> target_; 68 76 void setClosestTarget(); -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
r10886 r10898 35 35 namespace orxonox 36 36 { 37 /** 38 @brief 39 FlyingController stores all the flying methods and member variables of AI. 40 */ 37 41 namespace FormationMode 38 42 { -
code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h
r10888 r10898 26 26 * 27 27 */ 28 29 /**30 @file Attacher.h31 @brief Definition of the Attacher class.32 @ingroup Objects33 */34 28 35 29 #ifndef _Actionpoint_H__
Note: See TracChangeset
for help on using the changeset viewer.