- Timestamp:
- Nov 25, 2015, 12:07:22 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10851 r10854 65 65 this->squaredaccuracy_ = 10000; 66 66 this->bFirstTick_ = true; 67 this->tolerance_ = 65;67 this->tolerance_ = 50; 68 68 this->action_ = Action::NONE; 69 69 this->stopLookingAtTarget(); … … 73 73 CommonController::~CommonController() 74 74 { 75 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 76 { 77 if(this->actionpoints_[i]) 78 this->actionpoints_[i]->destroy(); 79 } 80 this->parsedActionpoints_.clear(); 81 this->actionpoints_.clear(); 75 82 76 } 83 77 void CommonController::tick(float dt) … … 492 486 } 493 487 } 494 if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))488 if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01)) 495 489 this->getControllableEntity() ->moveFrontBack( SPEED * dt ); 496 490 } … … 746 740 return 0; 747 741 } 748 boolCommonController::startAttackingEnemiesThatAreClose()742 void CommonController::startAttackingEnemiesThatAreClose() 749 743 { 750 744 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) … … 761 755 this->parsedActionpoints_.push_back(p); 762 756 this->executeActionpoint(); 763 return true; 764 } 765 } 766 } 767 return false; 757 } 758 } 759 } 768 760 } 769 761 … … 783 775 { 784 776 case Action::FIGHT: 785 { 777 { 778 std::string targetName = this->parsedActionpoints_.back().name; 779 if (targetName == "") 780 { 781 break; 782 } 783 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 784 { 785 if (CommonController::getName(*itP) == targetName) 786 { 787 this->setTarget (static_cast<ControllableEntity*>(*itP)); 788 } 789 } 786 790 break; 787 791 } … … 851 855 } 852 856 } 857 void CommonController::stayNearProtect() 858 { 859 Vector3* targetRelativePosition; 860 targetRelativePosition = new Vector3 (0, 300, 300); 861 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 862 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 863 this->setTargetPosition(targetAbsolutePosition); 864 } 853 865 void CommonController::nextActionpoint() 854 866 { … … 859 871 this->setAction(Action::NONE); 860 872 } 873 void CommonController::action() 874 { 875 this->startAttackingEnemiesThatAreClose(); 876 //No action -> pop one from stack 877 if (this->action_ == Action::NONE) 878 { 879 this->executeActionpoint(); 880 } 881 //Action fightall -> fight till nobody alive 882 if (this->action_ == Action::FIGHTALL) 883 { 884 if (!this->hasTarget()) 885 { 886 //----find a target---- 887 ControllableEntity* newTarget = this->closestTarget(); 888 if (newTarget) 889 { 890 this->setAction (Action::FIGHTALL, newTarget); 891 } 892 else 893 { 894 this->nextActionpoint(); 895 return; 896 } 897 } 898 else if (this->hasTarget()) 899 { 900 901 } 902 } 903 //Action fight -> fight as long as enemies in range 904 else if (this->action_ == Action::FIGHT) 905 { 906 if (!this->hasTarget()) 907 { 908 //----find a target---- 909 ControllableEntity* newTarget = this->closestTarget(); 910 if (newTarget && 911 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 912 { 913 this->setAction (Action::FIGHT, newTarget); 914 } 915 else 916 { 917 this->nextActionpoint(); 918 return; 919 } 920 } 921 else if (this->hasTarget()) 922 { 923 //----fly in formation if far enough---- 924 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 925 926 if (diffVector.length() > this->attackRange_) 927 { 928 ControllableEntity* newTarget = this->closestTarget(); 929 930 if (newTarget && 931 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 932 { 933 this->setAction (Action::FIGHT, newTarget); 934 } 935 else 936 { 937 this->nextActionpoint(); 938 return; 939 } 940 } 941 } 942 } 943 else if (this->action_ == Action::FLY) 944 { 945 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 946 { 947 this->nextActionpoint(); 948 return; 949 } 950 } 951 else if (this->action_ == Action::PROTECT) 952 { 953 if (!this->getProtect()) 954 { 955 this->nextActionpoint(); 956 return; 957 } 958 this->stayNearProtect(); 959 } 960 else if (this->action_ == Action::ATTACK) 961 { 962 if (!this->hasTarget()) 963 { 964 this->nextActionpoint(); 965 return; 966 } 967 } 968 if (this->hasTarget()) 969 { 970 //----choose where to go---- 971 this->maneuver(); 972 //----fire if you can---- 973 this->bShooting_ = this->canFire(); 974 } 975 } 861 976 }
Note: See TracChangeset
for help on using the changeset viewer.