Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gametypes/src/orxonox/objects/gametypes/TeamBaseMatch.cc @ 2903

Last change on this file since 2903 was 2903, checked in by scheusso, 15 years ago

merged changes made to trunk (r2902) into branch

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