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 | */ |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | #include "TeamBaseMatch.h" |
---|
28 | |
---|
29 | |
---|
30 | //implement this! not done yet! |
---|
31 | #include "objects/worldentities/pawns/TeamBaseMatchBase.h" |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/XMLPort.h" |
---|
34 | |
---|
35 | |
---|
36 | namespace orxonox |
---|
37 | { |
---|
38 | CreateUnloadableFactory(TeamBaseMatch); |
---|
39 | |
---|
40 | |
---|
41 | // Timer and Creator |
---|
42 | TeamBaseMatch::TeamBaseMatch(BaseObject* creator) : TeamDeathmatch(creator) |
---|
43 | { |
---|
44 | RegisterObject(TeamBaseMatch); |
---|
45 | |
---|
46 | this->scoreTimer_.setTimer(10, true, this, createExecutor(createFunctor(&TeamBaseMatch::winPoints))); |
---|
47 | this->outputTimer_.setTimer(30, true, this, createExecutor(createFunctor(&TeamBaseMatch::showPoints))); |
---|
48 | |
---|
49 | this->pointsTeam1_ = 0; |
---|
50 | this->pointsTeam2_ = 0; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | // set the Bases positions using XML |
---|
55 | void TeamBaseMatch::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
56 | { |
---|
57 | SUPER(TeamBaseMatch, XMLPort, xmlelement, mode); |
---|
58 | |
---|
59 | // XMLPortObject(TeamBaseMatch, WorldEntity, setNeutralshape, getNeturalshape, xmlelement, mode); |
---|
60 | // XMLPortObject(TeamBaseMatch, WorldEntity, setTeam1shape, getTeam1shape, xmlelement, mode); |
---|
61 | // XMLPortObject(TeamBaseMatch, WorldEntity, setTeam2shape, getTeam2shape, xmlelement, mode); |
---|
62 | |
---|
63 | // XMLPortObject(TeamBaseMatch, TeamBaseMatchBase, addBase, getBase, xmlelement, mode); |
---|
64 | } |
---|
65 | |
---|
66 | /* |
---|
67 | // pretty useless at the moment...should be implemented in the TeamBaseMatchBase class headerfile |
---|
68 | // State of the Base (controlled, uncontrolled) |
---|
69 | int TeamBaseMatch::baseState(Base) |
---|
70 | { |
---|
71 | if(Enum state_==uncontrolled) return 0; |
---|
72 | if(Enum state_==controlTeam1) return 1; |
---|
73 | if(Enum state_==controlTeam2) return 2; |
---|
74 | } |
---|
75 | */ |
---|
76 | |
---|
77 | |
---|
78 | // Change the control of the defeated base and respawn it with its initial health |
---|
79 | bool TeamBaseMatch::allowPawnDeath(Pawn* victim, Pawn* originator) |
---|
80 | { |
---|
81 | TeamBaseMatchBase* base = dynamic_cast<TeamBaseMatchBase*>(victim); |
---|
82 | if (base) |
---|
83 | { |
---|
84 | std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.find(base); |
---|
85 | if (it != this->bases_.end()) |
---|
86 | { |
---|
87 | int teamnr = this->getTeam(originator->getPlayer()); |
---|
88 | if (teamnr == 0) |
---|
89 | base->setState(BaseState::controlTeam1); |
---|
90 | if (teamnr == 1) |
---|
91 | base->setState(BaseState::controlTeam2); |
---|
92 | } |
---|
93 | |
---|
94 | victim->setHealth(victim->getInitialHealth()); |
---|
95 | return false; |
---|
96 | } |
---|
97 | |
---|
98 | return TeamDeathmatch::allowPawnDeath(victim, originator); |
---|
99 | } |
---|
100 | |
---|
101 | // collect Points for killing oppenents |
---|
102 | void TeamBaseMatch::playerScored(PlayerInfo* player) |
---|
103 | { |
---|
104 | int teamnr = this->getTeam(player); |
---|
105 | this->addTeamPoints(teamnr, 5); |
---|
106 | } |
---|
107 | |
---|
108 | // show points or each interval of time |
---|
109 | void TeamBaseMatch::showPoints() |
---|
110 | { |
---|
111 | |
---|
112 | COUT(0) << "Points standing:" << std::endl << "Team 1: "<< pointsTeam1_ << std::endl << "Team 2: " << pointsTeam2_ << std::endl; |
---|
113 | if(pointsTeam1_ >=1700) COUT(0) << "Team 1 is near victory!" << std::endl; |
---|
114 | if(pointsTeam2_ >=1700) COUT(0) << "Team 2 is near victory!" << std::endl; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | // collect Points while controlling Bases |
---|
119 | void TeamBaseMatch::winPoints() |
---|
120 | { |
---|
121 | int amountControlled = 0; |
---|
122 | int amountControlled2 = 0; |
---|
123 | |
---|
124 | for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it) |
---|
125 | { |
---|
126 | if((*it)->getState() == BaseState::controlTeam1) |
---|
127 | { |
---|
128 | amountControlled++; |
---|
129 | } |
---|
130 | if((*it)->getState() == BaseState::controlTeam2) |
---|
131 | { |
---|
132 | amountControlled2++; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | this->addTeamPoints(0, (amountControlled * 30)); |
---|
137 | this->addTeamPoints(1, (amountControlled2 * 30)); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | // end game if one team reaches 2000 points |
---|
142 | void TeamBaseMatch::endGame() |
---|
143 | { |
---|
144 | if(this->pointsTeam1_>=2000 || this->pointsTeam2_ >=2000) |
---|
145 | { |
---|
146 | this->end(); |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | // this function is called by the function winPoints() which adds points to the teams for every base and killed openents at a certain time |
---|
152 | void TeamBaseMatch::addTeamPoints(int team, int points) |
---|
153 | { |
---|
154 | if(team == 0) |
---|
155 | { |
---|
156 | this->pointsTeam1_ += points; |
---|
157 | } |
---|
158 | if(team == 1) |
---|
159 | { |
---|
160 | this->pointsTeam2_ += points; |
---|
161 | } |
---|
162 | |
---|
163 | this->endGame(); |
---|
164 | } |
---|
165 | |
---|
166 | void TeamBaseMatch::addBase(TeamBaseMatchBase* base) |
---|
167 | { |
---|
168 | this->bases_.insert(base); |
---|
169 | base->setState(BaseState::uncontrolled); |
---|
170 | } |
---|
171 | |
---|
172 | TeamBaseMatchBase* TeamBaseMatch::getBase(unsigned int index) const |
---|
173 | { |
---|
174 | unsigned int i = 0; |
---|
175 | for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it) |
---|
176 | { |
---|
177 | i++; |
---|
178 | if (i > index) |
---|
179 | return (*it); |
---|
180 | } |
---|
181 | return 0; |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | // declare the functions 'getshape' and 'setshape' from the XML function here |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|