1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Val Mikos |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "TeamBaseMatch.h" |
---|
30 | |
---|
31 | #include "objects/worldentities/pawns/TeamBaseMatchBase.h" |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | |
---|
34 | namespace orxonox |
---|
35 | { |
---|
36 | CreateUnloadableFactory(TeamBaseMatch); |
---|
37 | |
---|
38 | TeamBaseMatch::TeamBaseMatch(BaseObject* creator) : TeamDeathmatch(creator) |
---|
39 | { |
---|
40 | RegisterObject(TeamBaseMatch); |
---|
41 | |
---|
42 | this->scoreTimer_.setTimer(10, true, this, createExecutor(createFunctor(&TeamBaseMatch::winPoints))); |
---|
43 | this->outputTimer_.setTimer(30, true, this, createExecutor(createFunctor(&TeamBaseMatch::showPoints))); |
---|
44 | |
---|
45 | this->pointsTeam1_ = 0; |
---|
46 | this->pointsTeam2_ = 0; |
---|
47 | } |
---|
48 | |
---|
49 | // Change the control of the defeated base and respawn it with its initial health |
---|
50 | bool TeamBaseMatch::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
51 | { |
---|
52 | TeamBaseMatchBase* base = dynamic_cast<TeamBaseMatchBase*>(victim); |
---|
53 | if (base) |
---|
54 | { |
---|
55 | std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.find(base); |
---|
56 | if (it != this->bases_.end()) |
---|
57 | { |
---|
58 | int teamnr = this->getTeam(originator->getPlayer()); |
---|
59 | if (teamnr == 0) |
---|
60 | base->setState(BaseState::controlTeam1); |
---|
61 | if (teamnr == 1) |
---|
62 | base->setState(BaseState::controlTeam2); |
---|
63 | } |
---|
64 | |
---|
65 | victim->setHealth(victim->getInitialHealth()); |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | return TeamDeathmatch::allowPawnDeath(victim, originator); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | // if the player is in the same team as the base, he can't make any damage to it |
---|
74 | bool TeamBaseMatch::allowPawnDamage(Pawn* victim, Pawn* originator) |
---|
75 | { |
---|
76 | TeamBaseMatchBase* base = dynamic_cast<TeamBaseMatchBase*>(victim); |
---|
77 | if (base) |
---|
78 | { |
---|
79 | std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.find(base); |
---|
80 | if (it != this->bases_.end()) |
---|
81 | return (!this->pawnsAreInTheSameTeam(victim, base)); |
---|
82 | } |
---|
83 | return (!this->pawnsAreInTheSameTeam(victim, originator)); |
---|
84 | } |
---|
85 | |
---|
86 | bool TeamBaseMatch::pawnsAreInTheSameTeam(Pawn* pawn1, TeamBaseMatchBase* base) |
---|
87 | { |
---|
88 | if (pawn1 && base) |
---|
89 | { |
---|
90 | std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer()); |
---|
91 | int teamnrbase = -1; |
---|
92 | int teamnrplayer = getTeam(pawn1->getPlayer()); |
---|
93 | |
---|
94 | switch (base->getState()) |
---|
95 | { |
---|
96 | case BaseState::controlTeam1: |
---|
97 | teamnrbase = 0; |
---|
98 | break; |
---|
99 | case BaseState::controlTeam2: |
---|
100 | teamnrbase = 1; |
---|
101 | break; |
---|
102 | case BaseState::uncontrolled: |
---|
103 | default: |
---|
104 | teamnrbase = -1; |
---|
105 | } |
---|
106 | |
---|
107 | if (teamnrbase == teamnrplayer) |
---|
108 | return false; |
---|
109 | } |
---|
110 | return true; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | // collect Points for killing oppenents |
---|
118 | void TeamBaseMatch::playerScored(PlayerInfo* player) |
---|
119 | { |
---|
120 | int teamnr = this->getTeam(player); |
---|
121 | this->addTeamPoints(teamnr, 5); |
---|
122 | } |
---|
123 | |
---|
124 | // show points or each interval of time |
---|
125 | void TeamBaseMatch::showPoints() |
---|
126 | { |
---|
127 | |
---|
128 | COUT(0) << "Points standing:" << std::endl << "Team 1: "<< pointsTeam1_ << std::endl << "Team 2: " << pointsTeam2_ << std::endl; |
---|
129 | if(pointsTeam1_ >=1700) COUT(0) << "Team 1 is near victory!" << std::endl; |
---|
130 | if(pointsTeam2_ >=1700) COUT(0) << "Team 2 is near victory!" << std::endl; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | // collect Points while controlling Bases |
---|
135 | void TeamBaseMatch::winPoints() |
---|
136 | { |
---|
137 | int amountControlled = 0; |
---|
138 | int amountControlled2 = 0; |
---|
139 | |
---|
140 | for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it) |
---|
141 | { |
---|
142 | if((*it)->getState() == BaseState::controlTeam1) |
---|
143 | { |
---|
144 | amountControlled++; |
---|
145 | } |
---|
146 | if((*it)->getState() == BaseState::controlTeam2) |
---|
147 | { |
---|
148 | amountControlled2++; |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | this->addTeamPoints(0, (amountControlled * 30)); |
---|
153 | this->addTeamPoints(1, (amountControlled2 * 30)); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | // end game if one team reaches 2000 points |
---|
158 | void TeamBaseMatch::endGame() |
---|
159 | { |
---|
160 | if(this->pointsTeam1_>=2000 || this->pointsTeam2_ >=2000) |
---|
161 | { |
---|
162 | this->end(); |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | // this function is called by the function winPoints() which adds points to the teams for every base and killed openents at a certain time |
---|
168 | void TeamBaseMatch::addTeamPoints(int team, int points) |
---|
169 | { |
---|
170 | if(team == 0) |
---|
171 | { |
---|
172 | this->pointsTeam1_ += points; |
---|
173 | } |
---|
174 | if(team == 1) |
---|
175 | { |
---|
176 | this->pointsTeam2_ += points; |
---|
177 | } |
---|
178 | |
---|
179 | this->endGame(); |
---|
180 | } |
---|
181 | |
---|
182 | void TeamBaseMatch::addBase(TeamBaseMatchBase* base) |
---|
183 | { |
---|
184 | this->bases_.insert(base); |
---|
185 | base->setState(BaseState::uncontrolled); |
---|
186 | } |
---|
187 | |
---|
188 | TeamBaseMatchBase* TeamBaseMatch::getBase(unsigned int index) const |
---|
189 | { |
---|
190 | unsigned int i = 0; |
---|
191 | for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it) |
---|
192 | { |
---|
193 | i++; |
---|
194 | if (i > index) |
---|
195 | return (*it); |
---|
196 | } |
---|
197 | return 0; |
---|
198 | } |
---|
199 | |
---|
200 | } |
---|
201 | |
---|
202 | |
---|