Changeset 10838 for code/branches/campaignHS15/src/orxonox/controllers
- Timestamp:
- Nov 23, 2015, 3:50:59 PM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox/controllers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10834 r10838 38 38 39 39 #include "Scene.h" 40 #include <OgreRay.h> 41 #include <OgreSceneQuery.h> 42 #include <OgreCamera.h> 43 #include <OgreSceneManager.h> 40 41 #include "worldentities/pawns/TeamBaseMatchBase.h" 42 #include "gametypes/TeamDeathmatch.h" 43 #include "gametypes/Dynamicmatch.h" 44 #include "gametypes/Mission.h" 45 #include "gametypes/Gametype.h" 46 #include "controllers/WaypointPatrolController.h" 47 #include "controllers/NewHumanController.h" 48 #include "controllers/DroneController.h" 49 50 44 51 namespace orxonox 45 52 { … … 51 58 CommonController::CommonController( Context* context ): Controller( context ) 52 59 { 53 54 55 60 this->action_ = Action::FLY; 56 61 this->stopLookingAtTarget(); … … 70 75 XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode ); 71 76 XMLPortParam( CommonController, "action", setActionXML, getActionXML, xmlelement, mode ); 72 77 XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML, xmlelement, mode ); 78 //XMLPortParam ( CommonController, "enemy", setEnemyXML, getEnemyXML, xmlelement, mode ); 79 } 80 void CommonController::setProtectXML( std::string val ) 81 { 82 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 83 { 84 if ((*itP)->getName() == val) 85 { 86 this->setProtect (static_cast<ControllableEntity*>(*itP)); 87 } 88 } 89 } 90 std::string CommonController::getProtectXML () 91 { 92 if (!this->getProtect()) 93 return "noProtectWasSet"; 94 return this->getProtect()->getName(); 95 } 96 97 void CommonController::setProtect (ControllableEntity* protect) 98 { 99 this->protect_ = protect; 100 } 101 ControllableEntity* CommonController::getProtect () 102 { 103 return this->protect_; 73 104 } 74 105 void CommonController::setActionXML( std::string val) … … 205 236 Pawn* closestTarget = 0; 206 237 float minDistance = std::numeric_limits<float>::infinity(); 207 238 Gametype* gt = this->getGametype(); 208 239 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 209 240 { 210 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP) ) )241 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) ) 211 242 continue; 212 243 … … 669 700 return ( entity1->getPosition() - entity2->getPosition() ).length(); 670 701 } 671 bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2 )672 { 673 if (!entity1 || !entity2)702 bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 703 { 704 /*if (!entity1 || !entity2) 674 705 return false; 675 return entity1->getTeam() == entity2->getTeam(); 706 return entity1->getTeam() == entity2->getTeam();*/ 707 if (entity1 == entity2) 708 return true; 709 710 int team1 = entity1->getTeam(); 711 int team2 = entity2->getTeam(); 712 713 Controller* controller = 0; 714 if (entity1->getController()) 715 controller = entity1->getController(); 716 else 717 controller = entity1->getXMLController(); 718 if (controller) 719 { 720 CommonController* ac = orxonox_cast<CommonController*>(controller); 721 if (ac) 722 team1 = ac->getTeam(); 723 } 724 725 if (entity2->getController()) 726 controller = entity2->getController(); 727 else 728 controller = entity2->getXMLController(); 729 if (controller) 730 { 731 CommonController* ac = orxonox_cast<CommonController*>(controller); 732 if (ac) 733 team2 = ac->getTeam(); 734 } 735 736 TeamGametype* tdm = orxonox_cast<TeamGametype*>(gametype); 737 if (tdm) 738 { 739 if (entity1->getPlayer()) 740 team1 = tdm->getTeam(entity1->getPlayer()); 741 742 if (entity2->getPlayer()) 743 team2 = tdm->getTeam(entity2->getPlayer()); 744 } 745 746 TeamBaseMatchBase* base = 0; 747 base = orxonox_cast<TeamBaseMatchBase*>(entity1); 748 if (base) 749 { 750 switch (base->getState()) 751 { 752 case BaseState::ControlTeam1: 753 team1 = 0; 754 break; 755 case BaseState::ControlTeam2: 756 team1 = 1; 757 break; 758 case BaseState::Uncontrolled: 759 default: 760 team1 = -1; 761 } 762 } 763 base = orxonox_cast<TeamBaseMatchBase*>(entity2); 764 if (base) 765 { 766 switch (base->getState()) 767 { 768 case BaseState::ControlTeam1: 769 team2 = 0; 770 break; 771 case BaseState::ControlTeam2: 772 team2 = 1; 773 break; 774 case BaseState::Uncontrolled: 775 default: 776 team2 = -1; 777 } 778 } 779 780 DroneController* droneController = 0; 781 droneController = orxonox_cast<DroneController*>(entity1->getController()); 782 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) 783 return true; 784 droneController = orxonox_cast<DroneController*>(entity2->getController()); 785 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 786 return true; 787 DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController()); 788 DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController()); 789 if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner()) 790 return true; 791 792 Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype); 793 if (dynamic) 794 { 795 if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;} 796 797 if (entity1->getPlayer()) 798 team1 = dynamic->getParty(entity1->getPlayer()); 799 800 if (entity2->getPlayer()) 801 team2 = dynamic->getParty(entity2->getPlayer()); 802 803 if (team1 ==-1 ||team2 ==-1 ) {return false;} 804 else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;} 805 else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;} 806 else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;} 807 else return true; 808 } 809 810 return (team1 == team2 && team1 != -1); 676 811 } 677 812 void CommonController::doFire() -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10834 r10838 103 103 { return this->rank_; } 104 104 //----[/Rank data]---- 105 //----[Protect data]---- 106 void setProtectXML( std::string val ); 107 std::string getProtectXML (); 108 void setProtect (ControllableEntity* protect); 109 ControllableEntity* getProtect (); 110 //----[/Protect data]---- 105 111 //----[/XML data]---- 106 112 … … 124 130 float randomInRange(float a, float b); 125 131 static float distance(ControllableEntity* entity1, ControllableEntity* entity2); 126 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2 );132 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); 127 133 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; 128 134 … … 168 174 bool bHasTargetOrientation_; 169 175 Quaternion targetOrientation_; 170 // Vector3 destination_; 171 // bool bHasDestination; 176 177 Vector3 destination_; 178 bool bHasDestination; 172 179 //----[/where-to-fly information]---- 173 180 //----[protect information]---- 181 WeakPtr<ControllableEntity> protect_; 182 //----[/protect information]---- 174 183 //----[who-to-kill information]---- 175 184 WeakPtr<ControllableEntity> target_; 176 //WeakPtr<ControllableEntity> objectiveTarget_;185 WeakPtr<ControllableEntity> enemy_; 177 186 178 187 bool bHasPositionOfTarget_; -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10834 r10838 133 133 else if (this->action_ == Action::PROTECT) 134 134 { 135 135 if (this->getProtect()) 136 { 137 orxout(internal_error) << "PROTECT FOUND" << endl; 138 } 136 139 } 137 140 -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10834 r10838 168 168 //----new target should be close to division's target---- 169 169 Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition(); 170 170 Gametype* gt = this->getGametype(); 171 171 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 172 172 { 173 173 //----is enemy?---- 174 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP) ) )174 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) ) 175 175 continue; 176 176 //----in range?---- -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10834 r10838 135 135 CommonController* closestLeader = 0; 136 136 float minDistance = std::numeric_limits<float>::infinity(); 137 137 Gametype* gt = this->getGametype(); 138 138 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 139 139 { … … 145 145 146 146 //----same team?---- 147 if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity() ) )147 if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) ) 148 148 continue; 149 149
Note: See TracChangeset
for help on using the changeset viewer.