Changeset 10912
- Timestamp:
- Dec 1, 2015, 7:03:32 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10909 r10912 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=0 position=" 1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />38 <TeamSpawnPoint team=0 position="2000, 2000, 2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 39 39 40 40 <!-- … … 53 53 </templates> 54 54 <controller> 55 <DivisionController team= 0formationMode="finger4">55 <DivisionController team=1 formationMode="finger4"> 56 56 <actionpoints> 57 57 <Model mesh="cube.mesh" scale=8 position=" 0,2000,-600" /> … … 307 307 </controller> 308 308 </SpaceShip> 309 <!-- <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1> 310 <templates> 311 <Template link=spaceshipassff /> 312 </templates> 313 <controller> 314 <DivisionController team=1 formationMode="WALL"> 315 316 </DivisionController> 317 </controller> 318 </SpaceShip> 319 <SpaceShip position="2000, -1900, 3000" lookat="0,0,0" team=1> 320 <templates> 321 <Template link=spaceshipassff /> 322 </templates> 323 <controller> 324 <SectionController team=1> 325 </SectionController> 326 </controller> 327 </SpaceShip> 328 --> 329 309 330 310 <!-- HERE ENDS DEMO FOR FIGHTING --> 331 311 <!-- HERE STARTS DEMO FOR FORMATIONS --> -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10910 r10912 32 32 #include <algorithm> 33 33 #include "worldentities/Actionpoint.h" 34 34 35 namespace orxonox 35 36 { … … 55 56 this->bStartedDodging_ = false; 56 57 this->timeDodged_ = 0; 58 this->bDefaultPatrol_ = true; 59 this->bDefaultFightAll_ = true; 60 this->stop_ = false; 57 61 RegisterObject(ActionpointController); 58 62 … … 61 65 { 62 66 SUPER( ActionpointController, XMLPort, xmlelement, mode ); 67 // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode); 68 // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode); 69 63 70 XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint, xmlelement, mode); 64 } 71 XMLPortParam(ActionpointController, "defaultFightAll", setDefaultFightAll, getDefaultFightAll, xmlelement, mode).defaultValues(true); 72 XMLPortParam(ActionpointController, "defaultPatrol", setDefaultPatrol, getDefaultPatrol, xmlelement, mode).defaultValues(true); 73 } 74 // void ActionpointController::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 75 // { 76 // SUPER(ActionpointController, XMLEventPort, xmlelement, mode); 77 // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode); 78 // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode); 79 80 // } 81 // bool ActionpointController::stop(bool bTriggered, BaseObject* trigger) 82 // { 83 // this->stop_ = true; 84 // return true; 85 // } 86 // bool ActionpointController::go(bool bTriggered, BaseObject* trigger) 87 // { 88 // this->stop_ = false; 89 // return true; 90 // } 65 91 ActionpointController::~ActionpointController() 66 92 { … … 74 100 void ActionpointController::tick(float dt) 75 101 { 76 102 if (stop_) 103 return; 77 104 if (this->timeout_ > 0 && this->bFiredRocket_) 78 105 { … … 143 170 SUPER(ActionpointController, tick, dt); 144 171 } 145 std::pair <ControllableEntity*, ControllableEntity*> ActionpointController::closestTargets() 146 { 147 WeakPtr<ControllableEntity> firstTarget, secondTarget, tempTarget; 148 float firstDistance = std::numeric_limits<float>::infinity(), secondDistance = std::numeric_limits<float>::infinity(), tempDistance = 0; 149 Gametype* gt = this->getGametype(); 150 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 151 { 152 tempTarget = static_cast<ControllableEntity*>(*itP); 153 if (CommonController::sameTeam (this->getControllableEntity(), tempTarget, gt)) 154 continue; 155 156 tempDistance = CommonController::distance (*itP, this->getControllableEntity()); 157 if (tempDistance < firstDistance) 158 { 159 secondDistance = firstDistance; 160 secondTarget = firstTarget; 161 162 firstDistance = tempDistance; 163 firstTarget = tempTarget; 164 } 165 else if (tempDistance < secondDistance) 166 { 167 secondDistance = tempDistance; 168 secondTarget = tempTarget; 169 } 170 } 171 return std::make_pair (firstTarget, secondTarget); 172 } 173 174 //patrol can only be called by divisionController or others if they don't have a leader 175 //searches for closest enemy and sets target to it. If wasn't fighting, pushes Action::FIGHT on a stack. 176 //patrol gets called constantly either if this is fighting or if this->bDefaultPatrol_ is set to true via XML 177 bool ActionpointController::patrol() 178 { 179 std::pair <ControllableEntity*, ControllableEntity*> newTargets = this->closestTargets(); 180 if (!newTargets.first) 181 return false; 182 ControllableEntity* newTarget = newTargets.first; 183 184 float distance = CommonController::distance (this->getControllableEntity(), newTarget); 185 if (distance < this->attackRange_ && distance < CommonController::distance(this->getControllableEntity(), this->target_)) 186 { 187 this->setTarget (newTarget); 188 189 if (this->getIdentifier()->getName() == "DivisionController") 190 { 191 if (!newTargets.second) 192 { 193 if (this->myFollower_) 194 this->myFollower_->setTarget(newTargets.first); 195 } 196 else 197 { 198 if (this->myFollower_ && CommonController::distance(this->getControllableEntity(), newTargets.second) < this->attackRange_ + 600.0f) 199 this->myFollower_->setTarget(newTargets.second); 200 else if (this->myFollower_) 201 this->myFollower_->setTarget(newTargets.first); 202 } 203 } 204 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 205 { 206 this->bPatrolling_ = true; 207 if (this->bLoop_) 208 { 209 Point p = { Action::FIGHT, "", Vector3::ZERO, true }; 210 this->loopActionpoints_.push_back(p); 211 this->executeActionpoint(); 212 } 213 else 214 { 215 Point p = { Action::FIGHT, "", Vector3::ZERO, false }; 216 this->parsedActionpoints_.push_back(p); 217 this->executeActionpoint(); 218 } 219 } 220 return true; 221 } 222 else 223 { 224 return false; 225 } 226 } 227 //checks if state is still to be executed and makes a transition otherwise. 228 //if this->bDefaultPatrol_ == true, patrols area for enemies and, if not fighting, pushes a state with action = FIGHT 229 void ActionpointController::stateMachine() 230 { 231 //Check if calculations needed 232 if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()) || !this->isActive()) 233 return; 234 235 //state NONE means that either previous state finished executing and next state is to be fetched or no states are left to execute 236 //NONE is never on a stack -> it is only a transition state saved in a variable 237 if (this->action_ == Action::NONE || this->bTakenOver_) 238 { 239 //no actionpoints a.k.a. states left to execute 240 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()) 241 { 242 //default action is fighting 243 if (this->bDefaultFightAll_) 244 { 245 //make state 246 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false }; 247 //push it on the stack 248 this->parsedActionpoints_.push_back (p); 249 } 250 //default action is nothing 251 else 252 { 253 this->bActive_ = false; 254 return; 255 } 256 } 257 //switch to the new state 258 this->executeActionpoint(); 259 this->bTakenOver_ = false; 260 } 261 if (this->action_ == Action::FIGHTALL) 262 { 263 if (!this->hasTarget()) 264 { 265 ControllableEntity* newTarget = this->closestTarget(); 266 if (newTarget) 267 { 268 this->setTarget (newTarget); 269 } 270 else 271 { 272 this->nextActionpoint(); 273 this->executeActionpoint(); 274 } 275 } 276 else 277 { 278 bool b = this->patrol(); 279 } 280 281 } 282 if (this->action_ == Action::FIGHT) 283 { 284 if (!this->hasTarget() ) 285 { 286 if (!this->patrol()) 287 { 288 if (this->bPatrolling_) 289 { 290 if (this->bLoop_) 291 { 292 if (!this->loopActionpoints_.empty()) 293 { 294 this->loopActionpoints_.pop_back(); 295 } 296 } 297 else 298 { 299 if (!this->parsedActionpoints_.empty()) 300 { 301 this->parsedActionpoints_.pop_back(); 302 } 303 } 304 this->setAction(Action::NONE); 305 this->bHasTargetPosition_ = false; 306 this->bPatrolling_ = false; 307 } 308 else 309 { 310 this->nextActionpoint(); 311 } 312 this->executeActionpoint(); 313 } 314 } 315 else if (this->hasTarget()) 316 { 317 if (CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 318 { 319 this->setTarget(0); 320 this->stateMachine(); 321 } 322 } 323 } 324 if (this->action_ == Action::FLY) 325 { 326 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 327 { 328 this->nextActionpoint(); 329 this->executeActionpoint(); 330 } 331 else if (this->bDefaultPatrol_) 332 { 333 bool b = this->patrol(); 334 } 335 } 336 if (this->action_ == Action::PROTECT) 337 { 338 if (!this->getProtect()) 339 { 340 this->nextActionpoint(); 341 this->executeActionpoint(); 342 } 343 else 344 { 345 this->stayNearProtect(); 346 } 347 if (this->bDefaultPatrol_) 348 { 349 bool b = this->patrol(); 350 } 351 } 352 if (this->action_ == Action::ATTACK) 353 { 354 if (!this->hasTarget()) 355 { 356 this->nextActionpoint(); 357 this->executeActionpoint(); 358 } 359 if (this->bDefaultPatrol_) 360 { 361 bool b = this->patrol(); 362 } 363 } 364 } 365 172 366 173 367 174 … … 372 179 if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity())) 373 180 return; 374 this->startAttackingEnemiesThatAreClose(); 181 if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE)) 182 { 183 this->startAttackingEnemiesThatAreClose(); 184 } 375 185 376 186 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; … … 388 198 // } 389 199 390 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() )200 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_) 391 201 { 392 202 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false }; … … 395 205 this->executeActionpoint(); 396 206 this->bTakenOver_ = false; 397 this->action();207 // this->action(); 398 208 } 399 209 //Action fightall -> fight till nobody alive -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10910 r10912 35 35 #include "../modules/pickup/PickupSpawner.h" 36 36 #include <map> 37 38 37 39 38 40 namespace orxonox … … 159 161 */ 160 162 void addActionpoint(WorldEntity* actionpoint); 161 WorldEntity* getActionpoint(unsigned int index) const; 163 WorldEntity* getActionpoint(unsigned int index) const; 164 void setDefaultFightAll(bool value) 165 { this->bDefaultFightAll_ = value; } 166 bool getDefaultFightAll () 167 { return this->bDefaultFightAll_; } 168 void setDefaultPatrol(bool value) 169 { this->bDefaultPatrol_ = value; } 170 bool getDefaultPatrol () 171 { return this->bDefaultPatrol_; } 172 // Trigger interface 173 // bool stop(bool bTriggered, BaseObject* trigger); 174 // bool go(bool bTriggered, BaseObject* trigger); 175 // virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 176 162 177 virtual void stayNearProtect(); 163 178 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. … … 180 195 virtual bool hasFollower() 181 196 { return true; } 182 void stateMachine(); 183 bool patrol(); 184 std::pair <ControllableEntity*, ControllableEntity*> closestTargets(); 197 185 198 186 199 protected: … … 243 256 bool bManeuverCalled_; 244 257 bool bDefaultFightAll_; 258 245 259 bool bActive_; 246 260 bool bPatrolling_; 247 261 bool bDefaultPatrol_; 262 bool stop_; 248 263 249 264 private: -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10909 r10912 60 60 { 61 61 SUPER(DivisionController, XMLPort, xmlelement, mode); 62 62 63 63 //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 64 64 } -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10909 r10912 125 125 { 126 126 this->keepFormation(); 127 //orxout (internal_error) << "Keeping formation" << endl; 128 127 129 } 128 130 else if (!this->myDivisionLeader_->bKeepFormation_) … … 130 132 if (!this->hasTarget()) 131 133 { 132 this->chooseTarget(); 134 //this->chooseTarget(); 135 //orxout (internal_error) << "Section ain't got no target" << endl; 133 136 } 134 137 if (this->hasTarget())
Note: See TracChangeset
for help on using the changeset viewer.