[Orxonox-commit 245] r2902 - in trunk/src/orxonox/objects: gametypes worldentities/pawns
vmikos at orxonox.net
vmikos at orxonox.net
Mon Apr 6 16:25:45 CEST 2009
Author: vmikos
Date: 2009-04-06 16:25:45 +0200 (Mon, 06 Apr 2009)
New Revision: 2902
Added:
trunk/src/orxonox/objects/gametypes/TeamBaseMatch.cc
trunk/src/orxonox/objects/gametypes/TeamBaseMatch.h
trunk/src/orxonox/objects/worldentities/pawns/TeamBaseMatchBase.h
Modified:
trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc
trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h
trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
Log:
this is my first upload of the basematchfile
Added: trunk/src/orxonox/objects/gametypes/TeamBaseMatch.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/TeamBaseMatch.cc (rev 0)
+++ trunk/src/orxonox/objects/gametypes/TeamBaseMatch.cc 2009-04-06 14:25:45 UTC (rev 2902)
@@ -0,0 +1,185 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ */
+
+
+
+#include TeamBaseMatch.h
+
+
+//implement this! not done yet!
+#include "objects/worldentities/pawns/TeamBaseMatchBase.h"
+
+
+namespace orxonox
+{
+ CreateUnloadableFactory(TeamBaseMatch);
+
+
+ // Timer and Creator
+ TeamBaseMatch::TeamBaseMatch(BaseObject* creator) : TeamDeathMatch(creator)
+ {
+ RegisterObject(TeamBaseMatch);
+
+ this->scoreTimer_.setTimer(10, true, this, createExecutor(createFunctor(&TeamBaseMatch::winPoints)));
+ this->outputTimer_.setTimer(30, true, this, createExecutor(createFunctor(&TeamBaseMatch::showPoints)));
+
+ this->pointsTeam1_ = 0;
+ this->pointsTeam2_ = 0;
+ }
+
+
+ // set the Bases positions using XML
+ void TeamBaseMatch::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+// XMLPortObject(TeamBaseMatch, WorldEntity, setNeutralshape, getNeturalshape, xmlelement, mode);
+// XMLPortObject(TeamBaseMatch, WorldEntity, setTeam1shape, getTeam1shape, xmlelement, mode);
+// XMLPortObject(TeamBaseMatch, WorldEntity, setTeam2shape, getTeam2shape, xmlelement, mode);
+
+ XMLPortObject(TeamBaseMatch, TeamBaseMatchBase, addBase, getBase, xmlelement, mode);
+ }
+
+ // pretty useless at the moment...should be implemented in the TeamBaseMatchBase class headerfile
+ // State of the Base (controlled, uncontrolled)
+ int TeamBaseMatch::baseState(Base)
+ {
+ if(Enum state_==uncontrolled) return 0;
+ if(Enum state_==controlTeam1) return 1;
+ if(Enum state_==controlTeam2) return 2;
+ }
+
+ bool TeamBaseMatch::allowPawnDeath(Pawn* victim, Pawn* originator)
+ {
+ set::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.find(victim);
+ if (it != this->bases_.end() && victim)
+ {
+ TeamBaseMatchBase* base = dynamic_cast<TeamBaseMatchBase*>(victim);
+ if (base)
+ {
+ int teamnr = this->getTeam(originator->getPlayer());
+ if (teamnr == 0)
+ base->setState(BaseState::controlTeam1);
+ if (teamnr == 1)
+ base->setState(BaseState::controlTeam2);
+ }
+
+ victim->setHealth(victim->getInitialHealth());
+ return false;
+ }
+
+ return TeamDeathmatch::allowPawnDeath(victim, originator);
+ }
+
+ // collect Points for killing oppenents
+ void TeamBaseMatch::playerScored(PlayerInfo* player)
+ {
+ int teamnr = this->getTeam(player);
+ this->addTeamPoints(teamnr, 5);
+ }
+
+ // show points or each interval of time
+ void TeamBaseMatch::showPoints()
+ {
+
+ COUT(0) << "Points standing:" << std::endl << "Team 1: "<< pointsTeam1_ << std::endl << "Team 2: " << pointsTeam2_ << std::endl;
+ if(pointsTeam1_ >=1700) COUT(0) << "Team 1 is near victory!" << std::endl;
+ if(pointsTeam2_ >=1700) COUT(0) << "Team 2 is near victory!" << std::endl;
+ }
+
+
+ // collect Points while controlling Bases
+ void TeamBaseMatch::winPoints()
+ {
+ int amountControlled = 0;
+ int amountControlled2 = 0;
+
+ for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it)
+ {
+ if((*it)->getState() == BaseState::controlTeam1)
+ {
+ amountControlled++;
+ }
+ if((*it)->getState() == BaseState::controlTeam2)
+ {
+ amountControlled2++;
+ }
+ }
+
+ this->addTeamPoints(0, (amountControlled * 30));
+ this->addTeamPoints(1, (amountControlled2 * 30));
+ }
+
+
+ // end game if one team reaches 2000 points
+ void TeamBaseMatch::endGame()
+ {
+ if(this->pointsTeam1_>=2000 || this->pointsTeam2_ >=2000)
+ {
+ this->end();
+ }
+ }
+
+ void addTeamPoints(int team, int points)
+ {
+ if(player && teamnr == 0)
+ {
+ this->pointsTeam1_ += points;
+ }
+ if(player && teamnr == 1)
+ {
+ this->pointsTeam2_ += points;
+ }
+
+ this->endGame();
+ }
+
+ void TeamBaseMatch::addBase(TeamBaseMatchBase* base)
+ {
+ this->bases_.insert(base);
+ base->setState(BaseState::uncontrolled);
+ }
+
+ TeamBaseMatchBase* TeamBaseMatch::getBase(unsigned int index) const
+ {
+ unsigned int i = 0;
+ for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it)
+ {
+ i++;
+ if (i > index)
+ return (*it);
+ }
+ return 0;
+ }
+
+
+ // declare the functions 'getshape' and 'setshape' from the XML function here
+
+
+
+
+
+}
+
+
+
+
Added: trunk/src/orxonox/objects/gametypes/TeamBaseMatch.h
===================================================================
--- trunk/src/orxonox/objects/gametypes/TeamBaseMatch.h (rev 0)
+++ trunk/src/orxonox/objects/gametypes/TeamBaseMatch.h 2009-04-06 14:25:45 UTC (rev 2902)
@@ -0,0 +1,89 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _TeamBaseMatch_H__
+#define _TeamBaseMatch_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <vector>
+#include <set>
+
+#include "TeamDeathmatch.h"
+#include "util/Timer.h"
+
+
+
+namespace orxonox
+{
+
+
+
+ class _OrxonoxExport TeamBaseMatch : public TeamDeathmatch
+ {
+ public:
+ TeamBasematch(BaseObject* creator);
+
+ // if class closes, close everything
+ virtual ~TeamBaseMatch() {}
+
+
+ // set Base positions with XML
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+ virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
+
+ // give information about the state of a base
+ virtual int baseState(Base);
+
+ virtual void playerScored(PlayerInfo* player);
+ virtual void showPoints();
+ virtual void endGame();
+
+ void addBase(TeamBaseMatchBase* base);
+ TeamBaseMatchBase* getBase(unsigned int index) const;
+
+ void addTeamPoints(int team, int points);
+
+
+
+
+ protected:
+ void winPoints();
+
+ std::set<TeamBaseMatchBase*> bases_;
+ Timer<TeamBaseMatch> scoreTimer_;
+ Timer<TeamBaseMatch> outputTimer_;
+
+ //points for each team
+ int pointsTeam1_;
+ int pointsTeam2_;
+ };
+}
+
+#endif /* _TeamBaseMatch_H__ */
Modified: trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc 2009-04-06 14:23:16 UTC (rev 2901)
+++ trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc 2009-04-06 14:25:45 UTC (rev 2902)
@@ -188,4 +188,13 @@
}
return false;
}
+
+ int TeamDeathmatch::getTeam(PlayerInfo* player)
+ {
+ std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
+ if (it_player != this->teamnumbers_.end())
+ return it_player->second;
+ else
+ return -1;
+ }
}
Modified: trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h
===================================================================
--- trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h 2009-04-06 14:23:16 UTC (rev 2901)
+++ trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h 2009-04-06 14:25:45 UTC (rev 2902)
@@ -57,6 +57,7 @@
protected:
virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
+ int getTeam(PlayerInfo* player);
std::map<PlayerInfo*, int> teamnumbers_;
std::vector<ColourValue> teamcolours_;
Modified: trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-04-06 14:23:16 UTC (rev 2901)
+++ trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-04-06 14:25:45 UTC (rev 2902)
@@ -197,6 +197,7 @@
void Pawn::death()
{
+ this->setHealth(1);
if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
{
// Set bAlive_ to false and wait for PawnManager to do the destruction
@@ -213,8 +214,6 @@
if (GameMode::isMaster())
this->deatheffect();
}
- else
- this->setHealth(1);
}
void Pawn::deatheffect()
Added: trunk/src/orxonox/objects/worldentities/pawns/TeamBaseMatchBase.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/pawns/TeamBaseMatchBase.h (rev 0)
+++ trunk/src/orxonox/objects/worldentities/pawns/TeamBaseMatchBase.h 2009-04-06 14:25:45 UTC (rev 2902)
@@ -0,0 +1,95 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+
+
+// setState und getState functions declare here
+// TeamBaseMatchBase class
+
+
+// save as TeamBaseMatchBase.h in objects/worldentities/pawns/TeamBaseMatchBase.h
+
+
+#ifndef _TeamBaseMatchBase_H__
+#define _TeamBaseMatchBase_H__
+
+#include "pawn.h"
+
+namespace orxonox
+{
+
+
+ namespace BaseState
+ {
+ enum Enum
+ {
+ uncontrolled,
+ controlTeam1,
+ controlTeam2,
+ };
+ }
+
+ struct Base
+ {
+ BaseState::Enum state_;
+ };
+
+
+
+
+
+
+ class _OrxonoxExport TeamBaseMatchBase : public RadarViewable
+ {
+ public:
+ TeamBaseMatchBase(BaseObject* creator);
+
+ // if class closes, close everything
+ virtual ~TeamBaseMatchBase();
+
+ virtual void setState(base)
+ {
+
+
+ }
+ virtual enum getState(base);
+
+
+
+
+
+ protected:
+
+
+
+
+
+
+}
+
+#endif /* _TeamBaseMatchBase_H__ */
More information about the Orxonox-commit
mailing list