Changeset 10855 for code/branches
- Timestamp:
- Nov 25, 2015, 1:51:10 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10854 r10855 62 62 </controller> 63 63 </SpaceShip> --> 64 <SpaceShip position="-1500, 1500, -1000" lookat="0,0,0" team=0 name="ss1"> 65 <templates> 66 <Template link=spaceshipassff /> 67 </templates> 68 <controller> 69 <DivisionController team=0 formationMode="finger4"> 70 <actionpoints> 71 <Actionpoint position="-1000,1000,-1000" action="FLY" loopStart=true /> 72 <Actionpoint position="-1250,1250,-500" action="FLY" /> 73 <Actionpoint position="-1500,1500,-1000" action="FLY" loopEnd=true /> 74 </actionpoints> 75 </DivisionController> 76 </controller> 77 </SpaceShip> 64 78 <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2"> 65 79 <templates> -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10854 r10855 69 69 this->stopLookingAtTarget(); 70 70 this->attackRange_ = 2500; 71 this->bInLoop_ = false; 72 this->bLoop_ = false; 71 73 RegisterObject( CommonController ); 72 74 } … … 159 161 Vector3 position; 160 162 std::string targetName; 163 bool inLoop; 161 164 Point p; 162 165 if (static_cast<Actionpoint*> (actionpoint)) … … 166 169 targetName = ap->getName(); 167 170 position = ap->getWorldPosition(); 171 172 if (!this->bInLoop_ && ap->getStartLoop()) 173 { 174 this->bInLoop_ = true; 175 } 176 if (this->bInLoop_ && ap->getEndLoop()) 177 { 178 this->bInLoop_ = false; 179 } 180 inLoop = this->bInLoop_; 168 181 169 182 Action::Value value; … … 183 196 else 184 197 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." ); 185 p.action = value; p.name = targetName; p.position = position; 198 p.action = value; p.name = targetName; p.position = position; p.inLoop = inLoop; 186 199 parsedActionpoints_.push_back(p); 187 200 } 188 201 else 189 202 { 190 p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); 203 p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); p.inLoop = inLoop; 191 204 } 192 205 parsedActionpoints_.push_back(p); … … 752 765 <= this->attackRange_ ) 753 766 { 754 Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO };767 Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO, false }; 755 768 this->parsedActionpoints_.push_back(p); 756 769 this->executeActionpoint(); … … 768 781 void CommonController::executeActionpoint() 769 782 { 770 if (!this->parsedActionpoints_.empty()) 771 { 772 this->action_ = this->parsedActionpoints_.back().action; 773 774 switch ( this->action_ ) 775 { 776 case Action::FIGHT: 783 if (this->bLoop_) 784 { 785 if (!this->loopActionpoints_.empty()) 786 { 787 this->action_ = this->loopActionpoints_.back().action; 788 switch ( this->action_ ) 777 789 { 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)); 790 case Action::FIGHT: 791 { 792 std::string targetName = this->loopActionpoints_.back().name; 793 if (targetName == "") 794 { 795 break; 788 796 } 789 } 790 break; 797 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 798 { 799 if (CommonController::getName(*itP) == targetName) 800 { 801 this->setTarget (static_cast<ControllableEntity*>(*itP)); 802 } 803 } 804 break; 805 } 806 case Action::FLY: 807 { 808 this->setTargetPosition( this->loopActionpoints_.back().position ); 809 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 810 { 811 this->nextActionpoint(); 812 this->executeActionpoint(); 813 } 814 break; 815 } 816 case Action::PROTECT: 817 { 818 std::string protectName = this->loopActionpoints_.back().name; 819 820 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 821 { 822 if (CommonController::getName(*itP) == protectName) 823 { 824 this->setProtect (static_cast<ControllableEntity*>(*itP)); 825 } 826 } 827 if (!this->getProtect()) 828 { 829 this->nextActionpoint(); 830 this->executeActionpoint(); 831 } 832 break; 833 } 834 case Action::NONE: 835 { 836 break; 837 } 838 case Action::FIGHTALL: 839 { 840 break; 841 } 842 case Action::ATTACK: 843 { 844 std::string targetName = this->loopActionpoints_.back().name; 845 846 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 847 { 848 if (CommonController::getName(*itP) == targetName) 849 { 850 this->setTarget (static_cast<ControllableEntity*>(*itP)); 851 } 852 } 853 if (!this->hasTarget()) 854 { 855 this->nextActionpoint(); 856 this->executeActionpoint(); 857 } 858 break; 859 } 860 default: 861 break; 791 862 } 792 case Action::FLY: 863 } 864 else 865 { 866 this->bLoop_ = false; 867 } 868 } 869 else 870 { 871 if (!this->parsedActionpoints_.empty()) 872 { 873 if (this->parsedActionpoints_.back().inLoop) 793 874 { 794 this->setTargetPosition( this->parsedActionpoints_.back().position ); 795 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 796 { 797 this->nextActionpoint(); 798 this->executeActionpoint(); 799 } 800 break; 875 //MOVES all points that are in loop to a loop vector 876 this->fillLoop(); 877 this->bLoop_ = true; 878 executeActionpoint(); 879 return; 801 880 } 802 case Action::PROTECT: 881 this->action_ = this->parsedActionpoints_.back().action; 882 switch ( this->action_ ) 803 883 { 804 std::string protectName = this->parsedActionpoints_.back().name; 805 806 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 807 { 808 if (CommonController::getName(*itP) == protectName) 809 { 810 this->setProtect (static_cast<ControllableEntity*>(*itP)); 884 case Action::FIGHT: 885 { 886 std::string targetName = this->parsedActionpoints_.back().name; 887 if (targetName == "") 888 { 889 break; 811 890 } 812 } 813 if (!this->getProtect()) 814 { 815 this->nextActionpoint(); 816 this->executeActionpoint(); 817 } 818 break; 891 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 892 { 893 if (CommonController::getName(*itP) == targetName) 894 { 895 this->setTarget (static_cast<ControllableEntity*>(*itP)); 896 } 897 } 898 break; 899 } 900 case Action::FLY: 901 { 902 this->setTargetPosition( this->parsedActionpoints_.back().position ); 903 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 904 { 905 this->nextActionpoint(); 906 this->executeActionpoint(); 907 } 908 break; 909 } 910 case Action::PROTECT: 911 { 912 std::string protectName = this->parsedActionpoints_.back().name; 913 914 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 915 { 916 if (CommonController::getName(*itP) == protectName) 917 { 918 this->setProtect (static_cast<ControllableEntity*>(*itP)); 919 } 920 } 921 if (!this->getProtect()) 922 { 923 this->nextActionpoint(); 924 this->executeActionpoint(); 925 } 926 break; 927 } 928 case Action::NONE: 929 { 930 break; 931 } 932 case Action::FIGHTALL: 933 { 934 break; 935 } 936 case Action::ATTACK: 937 { 938 std::string targetName = this->parsedActionpoints_.back().name; 939 940 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 941 { 942 if (CommonController::getName(*itP) == targetName) 943 { 944 this->setTarget (static_cast<ControllableEntity*>(*itP)); 945 } 946 } 947 if (!this->hasTarget()) 948 { 949 this->nextActionpoint(); 950 this->executeActionpoint(); 951 } 952 break; 953 } 954 default: 955 break; 819 956 } 820 case Action::NONE: 821 { 822 break; 823 } 824 case Action::FIGHTALL: 825 { 826 break; 827 } 828 case Action::ATTACK: 829 { 830 std::string targetName = this->parsedActionpoints_.back().name; 831 832 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 833 { 834 if (CommonController::getName(*itP) == targetName) 835 { 836 this->setTarget (static_cast<ControllableEntity*>(*itP)); 837 } 838 } 839 if (!this->hasTarget()) 840 { 841 this->nextActionpoint(); 842 this->executeActionpoint(); 843 } 844 break; 845 } 846 default: 847 break; 848 } 849 } 850 else 851 { 852 this->setTarget(0); 853 this->setTargetPosition(this->getControllableEntity()->getWorldPosition()); 854 this->action_ = Action::NONE; 855 } 957 } 958 else 959 { 960 this->setTarget(0); 961 this->setTargetPosition(this->getControllableEntity()->getWorldPosition()); 962 this->action_ = Action::NONE; 963 } 964 } 965 856 966 } 857 967 void CommonController::stayNearProtect() … … 865 975 void CommonController::nextActionpoint() 866 976 { 867 if (!this->parsedActionpoints_.empty()) 868 { 869 this->parsedActionpoints_.pop_back(); 977 if (this->bLoop_) 978 { 979 if (!this->loopActionpoints_.empty()) 980 { 981 this->moveBackToTop(); 982 } 983 } 984 else 985 { 986 if (!this->parsedActionpoints_.empty()) 987 { 988 this->parsedActionpoints_.pop_back(); 989 } 870 990 } 871 991 this->setAction(Action::NONE); 992 } 993 void CommonController::moveBackToTop() 994 { 995 Point temp = loopActionpoints_.back(); 996 loopActionpoints_.pop_back(); 997 std::reverse (loopActionpoints_.begin(), loopActionpoints_.end()); 998 loopActionpoints_.push_back(temp); 999 std::reverse (loopActionpoints_.begin(), loopActionpoints_.end()); 1000 } 1001 void CommonController::fillLoop() 1002 { 1003 loopActionpoints_.clear(); 1004 fillLoopReversed(); 1005 std::reverse (loopActionpoints_.begin(), loopActionpoints_.end()); 1006 } 1007 void CommonController::fillLoopReversed() 1008 { 1009 if (parsedActionpoints_.back().inLoop) 1010 { 1011 loopActionpoints_.push_back(parsedActionpoints_.back()); 1012 parsedActionpoints_.pop_back(); 1013 } 1014 if (parsedActionpoints_.back().inLoop) 1015 { 1016 fillLoopReversed(); 1017 } 872 1018 } 873 1019 void CommonController::action() -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10854 r10855 74 74 std::string name; 75 75 Vector3 position; 76 bool inLoop; 76 77 } ; 77 78 … … 202 203 float squaredaccuracy_; 203 204 std::vector<Point > parsedActionpoints_; 205 std::vector<Point > loopActionpoints_; 204 206 205 207 //----[/Actionpoint information]---- … … 207 209 void executeActionpoint(); 208 210 void nextActionpoint(); 211 void fillLoop(); 212 void fillLoopReversed(); 213 void moveBackToTop(); 209 214 //----[Actionpoint methods]---- 210 215 //----["Private" variables]---- … … 219 224 int maneuverCounter_; 220 225 int tolerance_; 221 bool bFirstTick_; 226 bool bFirstTick_; 227 bool bInLoop_; 228 bool bLoop_; 222 229 //----[/"Private" variables]---- 223 230 }; -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10854 r10855 78 78 { 79 79 CommonController::action(); 80 81 80 } 82 81 void DivisionController::stayNearProtect() -
code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc
r10847 r10855 72 72 XMLPortParam( Actionpoint, "protectMe", setProtectMeXML, getProtectMeXML, xmlelement, mode ).defaultValues(false); 73 73 XMLPortParam( Actionpoint, "fightAll", setFightAllXML, getFightAllXML, xmlelement, mode ).defaultValues(false); 74 XMLPortParam( Actionpoint, "loopStart", setLoopStart, getLoopStart, xmlelement, mode ).defaultValues(false); 75 XMLPortParam( Actionpoint, "loopEnd", setLoopEnd, getLoopEnd, xmlelement, mode ).defaultValues(false); 74 76 75 77 } -
code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
r10848 r10855 68 68 inline void setProtectMeXML(bool c) 69 69 { 70 this-> protectMe_ = c;70 this->bProtectMe_ = c; 71 71 } 72 72 inline bool getProtectMeXML () 73 73 { 74 return this-> protectMe_;74 return this->bProtectMe_; 75 75 } 76 76 … … 79 79 inline void setFightAllXML(bool c) 80 80 { 81 this-> fightAll_ = c;81 this->bFightAll_ = c; 82 82 } 83 83 inline bool getFightAllXML () 84 84 { 85 return this-> fightAll_;85 return this->bFightAll_; 86 86 } 87 87 //----[/FightAll data]---- … … 102 102 return ""; 103 103 } 104 void setLoopStart(bool value) 105 { 106 this->bLoopStart_ = value; 107 } 108 void setLoopEnd (bool value) 109 { 110 this->bLoopEnd_ = value; 111 } 104 112 //----["Waypoints" data]---- 105 113 void setTargetPosition(const Vector3& target); … … 107 115 //----[/"Waypoints" data]---- 108 116 117 bool getLoopStart() 118 { 119 return this->bLoopStart_; 120 } 121 bool getLoopEnd(); 122 { 123 return this->bLoopEnd_; 124 } 109 125 private: 110 126 … … 115 131 WeakPtr<ControllableEntity> enemy_; 116 132 117 bool protectMe_; 118 bool fightAll_; 133 bool bLoopStart_; 134 bool bLoopEnd_; 135 bool bProtectMe_; 136 bool bFightAll_; 119 137 Vector3 targetPosition_; 120 138 };
Note: See TracChangeset
for help on using the changeset viewer.