- Timestamp:
- Dec 7, 2015, 4:06:37 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10935 r10946 113 113 this->moveToTargetPosition(dt); 114 114 } 115 if (!this || !this->getControllableEntity()) 116 return; 115 117 else if (this->bLookAtTarget_) 116 118 { … … 146 148 this->bDodge_ = true; 147 149 } 150 if (!this || !this->getControllableEntity()) 151 return; 148 152 if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1) 149 153 { … … 175 179 this->doFire(); 176 180 } 181 if (!this || !this->getControllableEntity()) 182 return; 177 183 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 178 184 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); … … 202 208 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_) 203 209 { 210 if (!this || !this->getControllableEntity()) 211 return; 204 212 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false }; 205 213 this->parsedActionpoints_.push_back (p); 206 214 } 215 if (!this || !this->getControllableEntity()) 216 return; 207 217 this->executeActionpoint(); 218 if (!this || !this->getControllableEntity()) 219 return; 208 220 this->bTakenOver_ = false; 209 221 } … … 220 232 if (newTarget) 221 233 { 234 if (!this || !this->getControllableEntity()) 235 return; 222 236 this->setAction (Action::FIGHTALL, newTarget); 223 237 } 224 238 else 225 239 { 240 if (!this || !this->getControllableEntity()) 241 return; 226 242 this->nextActionpoint(); 243 if (!this || !this->getControllableEntity()) 244 return; 227 245 this->executeActionpoint(); 228 246 … … 233 251 else if (this->action_ == Action::FIGHT) 234 252 { 235 236 253 if (!this->hasTarget() ) 237 254 { 238 255 //----find a target---- 239 ControllableEntity* newTarget = this->closestTarget(); 256 ControllableEntity* newTarget = this->closestTarget(); 257 if (!this || !this->getControllableEntity()) 258 return; 240 259 if (newTarget && 241 260 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 242 261 { 262 if (!this || !this->getControllableEntity()) 263 return; 243 264 this->setAction (Action::FIGHT, newTarget); 244 265 } 245 266 else 246 267 { 268 if (!this || !this->getControllableEntity()) 269 return; 247 270 this->nextActionpoint(); 271 if (!this || !this->getControllableEntity()) 272 return; 248 273 this->executeActionpoint(); 249 274 } … … 257 282 { 258 283 ControllableEntity* newTarget = this->closestTarget(); 259 284 if (!this || !this->getControllableEntity()) 285 return; 260 286 if (newTarget && 261 287 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 262 288 { 289 if (!this || !this->getControllableEntity()) 290 return; 263 291 this->setAction (Action::FIGHT, newTarget); 264 292 } 265 293 else 266 294 { 295 if (!this || !this->getControllableEntity()) 296 return; 267 297 this->nextActionpoint(); 298 if (!this || !this->getControllableEntity()) 299 return; 268 300 this->executeActionpoint(); 269 301 } … … 275 307 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 276 308 { 309 if (!this || !this->getControllableEntity()) 310 return; 277 311 this->nextActionpoint(); 312 if (!this || !this->getControllableEntity()) 313 return; 278 314 this->executeActionpoint(); 279 315 } … … 283 319 if (!this->getProtect()) 284 320 { 321 if (!this || !this->getControllableEntity()) 322 return; 285 323 this->nextActionpoint(); 324 if (!this || !this->getControllableEntity()) 325 return; 286 326 this->executeActionpoint(); 287 327 } 328 if (!this || !this->getControllableEntity()) 329 return; 288 330 this->stayNearProtect(); 289 331 } 290 332 else if (this->action_ == Action::ATTACK) 291 333 { 292 334 if (!this || !this->getControllableEntity()) 335 return; 293 336 if (!this->hasTarget()) 294 337 { 338 if (!this || !this->getControllableEntity()) 339 return; 295 340 this->nextActionpoint(); 341 if (!this || !this->getControllableEntity()) 342 return; 296 343 this->executeActionpoint(); 297 344 } … … 302 349 void ActionpointController::setProtect (ControllableEntity* protect) 303 350 { 351 304 352 this->protect_ = protect; 305 353 } 306 354 ControllableEntity* ActionpointController::getProtect () 307 355 { 356 308 357 return this->protect_; 309 358 } … … 401 450 void ActionpointController::setAction (Action::Value action, ControllableEntity* target) 402 451 { 452 if (!this || !this->getControllableEntity()) 453 return; 403 454 this->action_ = action; 404 455 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) … … 415 466 void ActionpointController::setAction (Action::Value action, const Vector3& target) 416 467 { 468 if (!this || !this->getControllableEntity()) 469 return; 417 470 this->action_ = action; 418 471 if (action == Action::FLY) … … 423 476 void ActionpointController::setAction (Action::Value action, const Vector3& target, const Quaternion& orient ) 424 477 { 478 if (!this || !this->getControllableEntity()) 479 return; 425 480 this->action_ = action; 426 481 if (action == Action::FLY) … … 466 521 return; 467 522 } 523 if (!this || !this->getControllableEntity()) 524 return; 468 525 if (!this->bLoop_ && this->parsedActionpoints_.back().inLoop) 469 526 { 470 527 //MOVES all points that are in loop to a loop vector 471 528 this->fillLoop(); 529 if (!this || !this->getControllableEntity()) 530 return; 472 531 this->bLoop_ = true; 473 532 executeActionpoint(); 474 533 return; 475 534 } 535 if (!this || !this->getControllableEntity()) 536 return; 476 537 this->setAction (p.action); 477 538 if (!this || !this->getControllableEntity()) … … 487 548 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 488 549 { 550 if (!this || !this->getControllableEntity()) 551 return; 489 552 if (CommonController::getName(*itP) == targetName) 490 553 { … … 497 560 { 498 561 this->setTargetPosition( p.position ); 562 if (!this || !this->getControllableEntity()) 563 return; 499 564 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 500 565 { 566 if (!this || !this->getControllableEntity()) 567 return; 501 568 this->nextActionpoint(); 569 if (!this || !this->getControllableEntity()) 570 return; 502 571 this->executeActionpoint(); 503 572 } … … 553 622 if (CommonController::getName(*itP) == targetName) 554 623 { 624 if (!this || !this->getControllableEntity()) 625 return; 555 626 this->setTarget (static_cast<ControllableEntity*>(*itP)); 556 627 } … … 559 630 { 560 631 this->nextActionpoint(); 632 if (!this || !this->getControllableEntity()) 633 return; 561 634 this->executeActionpoint(); 562 635 } … … 648 721 void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b) 649 722 { 650 this->parsedActionpoints_ = vector; 651 this->loopActionpoints_ = loop; 652 this->bLoop_ = b; 653 this->bTakenOver_ = true; 723 if (!this || !this->getControllableEntity()) 724 return; 725 this->parsedActionpoints_ = vector; 726 if (!this || !this->getControllableEntity()) 727 return; 728 this->loopActionpoints_ = loop; 729 this->bLoop_ = b; 730 this->bTakenOver_ = true; 654 731 } 655 732 void ActionpointController::setClosestTarget() … … 667 744 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 668 745 { 746 if (!this || !this->getControllableEntity()) 747 return 0; 669 748 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) ) 670 749 continue; … … 692 771 if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)) 693 772 { 773 if (!this || !this->getControllableEntity()) 774 return; 694 775 Pawn* newTarget = this->closestTarget(); 695 776 if ( newTarget &&
Note: See TracChangeset
for help on using the changeset viewer.