Changeset 8957 for code/branches/formation/src/orxonox
- Timestamp:
- Dec 7, 2011, 1:50:40 PM (13 years ago)
- Location:
- code/branches/formation/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/formation/src/orxonox/controllers/Masterable.cc
r8953 r8957 40 40 #include "gametypes/TeamDeathmatch.h" 41 41 #include "gametypes/Dynamicmatch.h" 42 #include "gametypes/Gametype.h" 42 43 #include "controllers/WaypointPatrolController.h" 43 44 #include "controllers/NewHumanController.h" … … 393 394 394 395 //same team? 395 if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 396 Gametype* gt=this->getGametype(); 397 if (!gt) 398 { 399 gt=it->getGametype(); 400 } 401 if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it),gt)) 396 402 continue; 397 403 … … 898 904 } 899 905 900 bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 901 { 902 if (entity1 == entity2) 903 return true; 906 /* 907 bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 908 { 909 if (!entity1 || !entity2) return false; 910 if (entity1 == entity2) return true; 911 912 if (!gametype) 913 orxout(debug_output) << "gametype NULL"<< endl; 904 914 905 915 int team1 = -1; 906 916 int team2 = -1; 907 917 908 Controller* controller = 0;909 if (entity1->getController())910 controller = entity1->getController();911 else912 controller = entity1->getXMLController();913 if (controller)914 {915 Masterable* ac = orxonox_cast<Masterable*>(controller);916 if (ac)917 team1 = ac->getTeam();918 }919 920 if (entity2->getController())921 controller = entity2->getController();922 else923 controller = entity2->getXMLController();924 if (controller)925 {926 Masterable* ac = orxonox_cast<Masterable*>(controller);927 if (ac)928 team2 = ac->getTeam();929 }930 931 918 TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype); 932 919 if (tdm) … … 937 924 if (entity2->getPlayer()) 938 925 team2 = tdm->getTeam(entity2->getPlayer()); 939 return (team1 == team2 && team1 != -1); //temp solution 940 } 941 926 orxout(debug_output) << "teamdeath okay"<< endl; 927 } 928 929 if (team1!=-1 && team2!=-1) 930 { 931 orxout(debug_output) << "Sameteam: decided in TeamDeathmatch. return "<<(team1 == team2 && team1 != -1)<< endl; 932 return (team1 == team2 && team1 != -1); 933 } 934 team1=team2=-1; 935 orxout(debug_output) << "Sameteam: not in teamdeathmatch."<< endl; 942 936 TeamBaseMatchBase* base = 0; 943 937 base = orxonox_cast<TeamBaseMatchBase*>(entity1); … … 973 967 } 974 968 } 969 970 if (team1!=-1 && team2!=-1) 971 return (team1 == team2 && team1 != -1); 972 team1=team2=-1; 973 975 974 976 975 DroneController* droneController = 0; … … 1005 1004 1006 1005 return (team1 == team2 && team1 != -1); 1006 1007 }*/ 1008 1009 bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 1010 { 1011 if (entity1 == entity2) 1012 return true; 1013 1014 int team1 = -1; 1015 int team2 = -1; 1016 1017 Controller* controller = 0; 1018 if (entity1->getController()) 1019 controller = entity1->getController(); 1020 else 1021 controller = entity1->getXMLController(); 1022 if (controller) 1023 { 1024 Masterable* ac = orxonox_cast<Masterable*>(controller); 1025 if (ac) 1026 team1 = ac->getTeam(); 1027 } 1028 1029 if (entity2->getController()) 1030 controller = entity2->getController(); 1031 else 1032 controller = entity2->getXMLController(); 1033 if (controller) 1034 { 1035 Masterable* ac = orxonox_cast<Masterable*>(controller); 1036 if (ac) 1037 team2 = ac->getTeam(); 1038 } 1039 1040 TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype); 1041 if (tdm) 1042 { 1043 if (entity1->getPlayer()) 1044 team1 = tdm->getTeam(entity1->getPlayer()); 1045 1046 if (entity2->getPlayer()) 1047 team2 = tdm->getTeam(entity2->getPlayer()); 1048 return (team1 == team2 && team1 != -1); //temp solution 1049 } 1050 1051 TeamBaseMatchBase* base = 0; 1052 base = orxonox_cast<TeamBaseMatchBase*>(entity1); 1053 if (base) 1054 { 1055 switch (base->getState()) 1056 { 1057 case BaseState::ControlTeam1: 1058 team1 = 0; 1059 break; 1060 case BaseState::ControlTeam2: 1061 team1 = 1; 1062 break; 1063 case BaseState::Uncontrolled: 1064 default: 1065 team1 = -1; 1066 } 1067 } 1068 base = orxonox_cast<TeamBaseMatchBase*>(entity2); 1069 if (base) 1070 { 1071 switch (base->getState()) 1072 { 1073 case BaseState::ControlTeam1: 1074 team2 = 0; 1075 break; 1076 case BaseState::ControlTeam2: 1077 team2 = 1; 1078 break; 1079 case BaseState::Uncontrolled: 1080 default: 1081 team2 = -1; 1082 } 1083 } 1084 1085 DroneController* droneController = 0; 1086 droneController = orxonox_cast<DroneController*>(entity1->getController()); 1087 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) 1088 return true; 1089 droneController = orxonox_cast<DroneController*>(entity2->getController()); 1090 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 1091 return true; 1092 DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController()); 1093 DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController()); 1094 if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner()) 1095 return true; 1096 1097 Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype); 1098 if (dynamic) 1099 { 1100 if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;} 1101 1102 if (entity1->getPlayer()) 1103 team1 = dynamic->getParty(entity1->getPlayer()); 1104 1105 if (entity2->getPlayer()) 1106 team2 = dynamic->getParty(entity2->getPlayer()); 1107 1108 if (team1 ==-1 ||team2 ==-1 ) {return false;} 1109 else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;} 1110 else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;} 1111 else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;} 1112 else return true; 1113 } 1114 1115 return (team1 == team2 && team1 != -1); 1007 1116 } 1008 1117 -
code/branches/formation/src/orxonox/controllers/Masterable.h
r8953 r8957 77 77 78 78 inline void setTeam(int team) 79 { this->team_ = team; } 79 { this->team_ = team; 80 orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;} 80 81 inline int getTeam() const 81 82 { return this->team_; }
Note: See TracChangeset
for help on using the changeset viewer.