Changeset 10953
- Timestamp:
- Dec 7, 2015, 8:42:03 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10925 r10953 38 38 <TeamSpawnPoint team=0 position="2000, 2000, 2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 39 39 40 40 <Pawn position = "100000, 100000, 100000"> 41 <controller> 42 <MasterController> 43 </MasterController> 44 </controller> 45 </Pawn> 41 46 <!-- 42 47 <PickupSpawner pickup=largedamageboostpickup position="0,0,0" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" /> -
code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw
r10932 r10953 1026 1026 </Pawn> 1027 1027 <!--SHIPS --> 1028 1028 <!-- one Controller to rule them all --> 1029 <Pawn position = "100000, 100000, 100000"> 1030 <controller> 1031 <MasterController> 1032 </MasterController> 1033 </controller> 1034 </Pawn> 1029 1035 <!--Allied units--> 1030 1036 -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10946 r10953 32 32 #include <algorithm> 33 33 #include "worldentities/Actionpoint.h" 34 35 34 namespace orxonox 36 35 { … … 40 39 ActionpointController::ActionpointController(Context* context) : FightingController(context) 41 40 { 42 this->actionpointControllerId_ = 0;43 ActionpointController::sTicks_ = 0;44 ActionpointController::nextActionpointControllerId_ = 0;45 41 this->ticks_ = 0; 46 42 this->bPatrolling_ = false; … … 75 71 parsedActionpoints_.clear(); 76 72 actionpoints_.clear(); 77 this->actionpointControllerId_ = 0;78 73 79 74 } … … 82 77 if (!this || !this->getControllableEntity() || !this->isActive() || this->stop_) 83 78 return; 79 84 80 ++this->ticks_; 85 // orxout (internal_error) << "this id = " << this->actionpointControllerId_ << endl; 86 if (ActionpointController::sTicks_ < this->ticks_) 87 { 88 // orxout (internal_error) << "total id's = " << ActionpointController::nextActionpointControllerId_ << endl; 89 ++ActionpointController::sTicks_; 90 } 91 92 if (!this || !this->getControllableEntity()) 93 return; 94 95 if (ActionpointController::sTicks_ == 1) 96 { 97 98 this->actionpointControllerId_ = ActionpointController::nextActionpointControllerId_++; 81 if (this->ticks_ == 1) 82 { 99 83 std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end()); 100 84 std::reverse(actionpoints_.begin(), actionpoints_.end()); … … 103 87 this->action_ = Action::FIGHTALL; 104 88 } 105 //orxout (internal_error) << "first tick was called by id = " << this->actionpointControllerId_ << ", total = " << ActionpointController::nextActionpointControllerId_ << endl;106 89 } 107 90 … … 113 96 this->moveToTargetPosition(dt); 114 97 } 115 if (!this || !this->getControllableEntity())116 return;117 98 else if (this->bLookAtTarget_) 118 99 { … … 125 106 126 107 if (timeout_ <= 0) 108 { 127 109 this->bFiredRocket_ = false; 128 129 130 if (!this || !this->getControllableEntity()) 131 return; 132 if (this->timeout_ > 0 && this->bFiredRocket_) 110 } 111 else if (this->bFiredRocket_) 133 112 { 134 113 --this->timeout_; 135 114 } 136 137 138 if (!this || !this->getControllableEntity()) 139 return; 140 //maneuver every 0.25 sec -> 141 int step = 4; 142 if (ActionpointController::sTicks_ % 100 <= 10) 115 116 if (!this || !this->getControllableEntity()) 117 return; 118 119 if (this->ticks_ % 80 <= 10) 143 120 { 144 121 this->bDodge_ = false; … … 148 125 this->bDodge_ = true; 149 126 } 150 if (!this || !this->getControllableEntity()) 151 return; 152 if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1) 153 { 154 //orxout (internal_error) << "Team " << this->getControllableEntity()->getTeam() << (this->hasTarget() ? ", got " : ", don't have") << " target" << endl; 155 this->action(); 156 } 157 158 159 if (!this || !this->getControllableEntity()) 160 return; 161 /* orxout (internal_error) << "id = " << this->actionpointControllerId_ << ", in total # ids = " << ActionpointController::nextActionpointControllerId_ 162 << ", I " << (this->hasTarget() ? "have" : "don't have") << " a target, my team is " << this->getControllableEntity()->getTeam() << endl; 163 */ if (this->hasTarget() && ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_ + 1) == (this->actionpointControllerId_)) 164 { 165 166 167 if (!this || !this->getControllableEntity()) 168 return; 169 this->maneuver(); 170 if (!this || !this->getControllableEntity()) 171 return; 172 this->bShooting_ = this->canFire(); 173 174 if (!this || !this->getControllableEntity()) 175 return; 176 177 if (this->bShooting_) 178 { 179 this->doFire(); 180 } 181 if (!this || !this->getControllableEntity()) 182 return; 183 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 184 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); 185 } 186 187 127 128 if (!this || !this->getControllableEntity()) 129 return; 130 131 if (this->bShooting_) 132 { 133 this->doFire(); 134 } 188 135 SUPER(ActionpointController, tick, dt); 189 136 } … … 193 140 void ActionpointController::action() 194 141 { 195 if (!this || !this->getControllableEntity()) 196 return; 197 142 if (!this || !this->getControllableEntity() || !this->isActive()) 143 return; 144 145 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 146 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); 198 147 if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE)) 199 148 { … … 798 747 } 799 748 } 800 unsigned int ActionpointController::nextActionpointControllerId_ = 0;801 unsigned int ActionpointController::sTicks_ = 0;802 749 } -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10946 r10953 35 35 #include "../modules/pickup/PickupSpawner.h" 36 36 #include <map> 37 38 #include <boost/shared_ptr.hpp> 37 39 38 40 … … 246 248 bool bDefaultPatrol_; 247 249 bool stop_; 248 static unsigned int sTicks_; //<! a hack? I don't want action() and maneuver() to be called multiple times in a tick, so I keep249 //<! track of ticks and if current tick is "assigned" to this object, than I call maneuver()/action()250 static unsigned int nextActionpointControllerId_; //<! if level has 16 ActionpointControllers, than this variable equals to 17 after first tick251 unsigned int actionpointControllerId_; //<! integer from 0 to nextActionpointControllerId_, different for every ActionpointController in level252 250 unsigned int ticks_; //<! local tick counter 251 253 252 }; 254 253 } -
code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
r10886 r10953 18 18 FlyingController.cc 19 19 FightingController.cc 20 MasterController.cc 20 21 ) -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10946 r10953 40 40 41 41 RegisterClass(CommonController); 42 43 42 CommonController::CommonController(Context* context): Controller(context) 44 43 { … … 93 92 if (controller) 94 93 { 94 if (controller->getIdentifier()->getName() == "MasterController") 95 return true; 95 96 CommonController* ac = orxonox_cast<CommonController*>(controller); 96 97 if (ac) … … 104 105 if (controller) 105 106 { 107 if (controller->getIdentifier()->getName() == "MasterController") 108 return true; 106 109 CommonController* ac = orxonox_cast<CommonController*>(controller); 107 110 if (ac) -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10946 r10953 49 49 CommonController(Context* context); 50 50 virtual ~CommonController(); 51 51 virtual void action(){}; //<! action() is called in regular intervals managing the bot's behaviour. 52 52 static float randomInRange(float a, float b); 53 53 static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2); -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10946 r10953 65 65 if (!this->isActive()) 66 66 return; 67 67 68 SUPER(DivisionController, tick, dt); 68 69 -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10935 r10953 143 143 else 144 144 { 145 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/ 10.0f)145 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f) 146 146 || this->deltaHp < 0; 147 147 this->bKeepFormation_ = false; … … 220 220 } 221 221 222 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 10.0f);222 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f); 223 223 } 224 224 -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10934 r10953 55 55 { return this->target_; } 56 56 bool bKeepFormation_; //even if action_ == FIGHT, you might still want to keep formation if far enough form the target 57 57 virtual void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on 58 //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_. 59 bool bShooting_; 60 bool canFire(); //<! check if target_ is in radius and if this is looking at target_ 61 58 62 protected: 59 63 void setTarget(ControllableEntity* target); //set a target to shoot at … … 65 69 void lookAtTarget(float dt); //<! rotate yourself towards target 66 70 67 void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on68 //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.69 71 void dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between 70 72 //<! this and target_ plus or minus some amount in difference vector direction, 71 73 //<! depending on whether it is better to close up or survive. 72 74 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 75 void doFire(); //<! choose weapon, set aim at target_ and fire 75 76 WeakPtr<ControllableEntity> target_; … … 84 85 bool bDodge_; 85 86 int attackRange_; 86 bool bShooting_;87 87 bool bLookAtTarget_; 88 88 float deltaHp; -
code/branches/campaignHS15/src/orxonox/controllers/FormationController.cc
r10834 r10953 970 970 if (controller) 971 971 { 972 if (controller->getIdentifier()->getName() == "MasterController") 973 return true; 972 974 FormationController* ac = orxonox_cast<FormationController*>(controller); 973 975 if (ac) … … 981 983 if (controller) 982 984 { 985 if (controller->getIdentifier()->getName() == "MasterController") 986 return true; 983 987 FormationController* ac = orxonox_cast<FormationController*>(controller); 984 988 if (ac) -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10946 r10953 95 95 if (!this->myLeader_) 96 96 { 97 ActionpointController::action(); 98 if (!this || !this->getControllableEntity()) 99 return; 100 97 ActionpointController::action(); 101 98 } 102 99 else if (this->myLeader_)
Note: See TracChangeset
for help on using the changeset viewer.