[Orxonox-commit 4546] r9218 - in code/branches/captureTheFlag: data/levels src/modules/gametypes src/modules/pickup/items src/orxonox/gametypes

ninow at orxonox.net ninow at orxonox.net
Fri May 18 16:44:47 CEST 2012


Author: ninow
Date: 2012-05-18 16:44:47 +0200 (Fri, 18 May 2012)
New Revision: 9218

Added:
   code/branches/captureTheFlag/data/levels/captureTheFlag.oxw
   code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.cc
   code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.h
   code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.cc
   code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.h
   code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.cpp
   code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.h
Log:
Forgot to add Files

Added: code/branches/captureTheFlag/data/levels/captureTheFlag.oxw
===================================================================
--- code/branches/captureTheFlag/data/levels/captureTheFlag.oxw	                        (rev 0)
+++ code/branches/captureTheFlag/data/levels/captureTheFlag.oxw	2012-05-18 14:44:47 UTC (rev 9218)
@@ -0,0 +1,97 @@
+<LevelInfo
+ name = "Capture The Flag"
+ description = "Fight against each other in teams."
+ tags = "gametype"
+ screenshot = "teamdeathmatch.png"
+/>
+
+<?lua
+  include("HUDTemplates3.oxo")
+  include("stats.oxo")
+  include("templates/spaceshipAssff.oxt")
+  include("templates/spaceshipH2.oxt")
+  include("templates/spaceshipPirate.oxt")
+  include("templates/lodInformation.oxt")
+?>
+
+<Level
+ gametype = "captureTheFlag"
+>
+  <templates>
+    <Template link=lodtemplate_default />
+  </templates>
+  <?lua include("includes/notifications.oxi") ?>
+
+  <Scene
+   ambientlight = "0.7, 0.6, 0.6"
+   skybox       = "Orxonox/skypanoramagen1"
+  >
+
+    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+
+    <TeamSpawnPoint team=0 position="0,  0,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=0 position="0, 50,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=0 position="0,100,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=0 position="0,150,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+
+    <TeamSpawnPoint team=1 position="2000,  0,0" direction="-1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=1 position="2000, 50,0" direction="-1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=1 position="2000,100,0" direction="-1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    <TeamSpawnPoint team=1 position="2000,150,0" direction="-1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+
+    <TeamSpawnPoint team=2 position="1000,  0,1500" direction="0,0,-1" spawnclass=SpaceShip pawndesign=spaceshipHtwo />
+    <TeamSpawnPoint team=2 position="1000, 50,1500" direction="0,0,-1" spawnclass=SpaceShip pawndesign=spaceshipHtwo />
+    <TeamSpawnPoint team=2 position="1000,100,1500" direction="0,0,-1" spawnclass=SpaceShip pawndesign=spaceshipHtwo />
+    <TeamSpawnPoint team=2 position="1000,150,1500" direction="0,0,-1" spawnclass=SpaceShip pawndesign=spaceshipHtwo />
+
+    <!--PickupSpawner position="-25,-25,-125" triggerDistance="10" respawnTime="" maxSpawnedItems="9999">
+      <pickup>
+        <FlagPickup template=smallshieldpickup flagType=blue />
+      </pickup>
+    </PickupSpawner>
+
+    <PickupSpawner position="25,-25,-125" triggerDistance="10" respawnTime="" maxSpawnedItems="9999">
+      <pickup>
+        <FlagPickup template=smallshieldpickup flagType=red />
+      </pickup>
+    </PickupSpawner-->
+
+    <?lua
+      for i = 1, 70, 1 do
+    ?>
+      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 1000 + 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+        <attached>
+          <Model scale="<?lua print(math.random() * 50 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+        </attached>
+      </MovableEntity>
+      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * -1000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+        <attached>
+          <Model scale="<?lua print(math.random() * 50 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+        </attached>
+      </MovableEntity>
+
+      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 1000 + 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+        <attached>
+          <Model scale="<?lua print(math.random() * 50 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+        </attached>
+      </MovableEntity>
+      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * -1000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+        <attached>
+          <Model scale="<?lua print(math.random() * 50 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+        </attached>
+      </MovableEntity>
+
+      <MovableEntity position="<?lua print(math.random() * 1000 + 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+        <attached>
+          <Model scale="<?lua print(math.random() * 50 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+        </attached>
+      </MovableEntity>
+      <MovableEntity position="<?lua print(math.random() * -1000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+        <attached>
+          <Model scale="<?lua print(math.random() * 50 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+        </attached>
+      </MovableEntity>
+    <?lua end ?>
+
+  </Scene>
+</Level>

Added: code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.cc
===================================================================
--- code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.cc	                        (rev 0)
+++ code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.cc	2012-05-18 14:44:47 UTC (rev 9218)
@@ -0,0 +1,328 @@
+/*
+ *   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:
+ *      Nino Weingart
+ *   Co-authors:
+ *      ...
+ *
+ */
+#include "CaptureTheFlag.h"
+
+#include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
+#include "interfaces/TeamColourable.h"
+#include "worldentities/TeamSpawnPoint.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+    CreateUnloadableFactory(CaptureTheFlag);
+
+    CaptureTheFlag::CaptureTheFlag(BaseObject* creator) : Deathmatch(creator)
+    {
+        RegisterObject(CaptureTheFlag);
+        //flagTeamBlue = new FlagPickup;
+        //flagTeamRed = new FlagPickup;
+
+        this->scoreTimer_.setTimer(10, true, createExecutor(createFunctor(&TeamBaseMatch::winPoints, this)));
+        this->outputTimer_.setTimer(10, true, createExecutor(createFunctor(&TeamBaseMatch::showPoints, this)));
+        
+        this->teams_ = 2;
+        this->pointsTeam1_ = 0;
+        this->pointsTeam2_ = 0;
+
+        this->setConfigValues();
+    }
+
+    void tick(float dt){
+    	if(flagTeamBlue->teamScore_ > pointsTeam1_){
+    		pointsTeam1_ = flagTeamBlue->teamScore_;
+    	}
+    	if(flagTeamRed->teamScore_ > pointsTeam2_){
+    		pointsTeam2_ = flagTeamRed->teamScore_;
+    	}
+    }
+    void CaptureTheFlag::setConfigValues()
+    {
+        SetConfigValue(teams_, 2);
+
+        static ColourValue colours[] =
+        {
+            ColourValue(1.0f, 0.3f, 0.3f),
+            ColourValue(0.3f, 0.3f, 1.0f),
+            ColourValue(0.3f, 1.0f, 0.3f),
+            ColourValue(1.0f, 1.0f, 0.0f)
+        };
+        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
+
+        SetConfigValue(teamcolours_, defaultcolours);
+    }
+
+    void CaptureTheFlag::playerEntered(PlayerInfo* player)
+    {
+        Deathmatch::playerEntered(player);
+
+        std::vector<unsigned int> playersperteam(this->teams_, 0);
+
+        for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
+            if (it->second < static_cast<int>(this->teams_) && it->second >= 0)
+                playersperteam[it->second]++;
+
+        unsigned int minplayers = static_cast<unsigned int>(-1);
+        size_t minplayersteam = 0;
+        for (size_t i = 0; i < this->teams_; ++i)
+        {
+            if (playersperteam[i] < minplayers)
+            {
+                minplayers = playersperteam[i];
+                minplayersteam = i;
+            }
+        }
+
+        this->teamnumbers_[player] = minplayersteam;
+    }
+
+    bool CaptureTheFlag::playerLeft(PlayerInfo* player)
+    {
+        bool valid_player = Deathmatch::playerLeft(player);
+
+        if (valid_player)
+            this->teamnumbers_.erase(player);
+
+        return valid_player;
+    }
+
+    bool CaptureTheFlag::allowPawnHit(Pawn* victim, Pawn* originator)
+    {
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
+    }
+
+    bool CaptureTheFlag::allowPawnDamage(Pawn* victim, Pawn* originator)
+    {
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
+    }
+
+    bool CaptureTheFlag::allowPawnDeath(Pawn* victim, Pawn* originator)
+    {
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !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()
+        {
+            if (!this->hasStarted() || this->hasEnded())
+                return;
+
+            orxout(message) << "Points standing:" << '\n' << "Team Blue: "<< pointsTeam1_ << '\n' << "Team Red: " << pointsTeam2_ << endl;
+            if(pointsTeam1_ >=1700 && pointsTeam1_ < 2000) orxout(message) << "Team Blue is near victory!" << endl;
+            if(pointsTeam2_ >=1700 && pointsTeam2_ < 2000) orxout(message) << "Team Red is near victory!" << endl;
+        }
+        
+        // end game if one team reaches 2000 points
+        void TeamBaseMatch::endGame()
+        {
+            if (this->pointsTeam1_ >= 2000 || this->pointsTeam2_ >= 2000)
+            {
+                int winningteam = -1;
+
+                if (this->pointsTeam1_ > this->pointsTeam2_)
+                {
+                    orxout(message) << "Team Blue has won the match" << endl;
+                    winningteam = 0;
+                }
+                else
+                {
+                    orxout(message) << "Team Red has won the match" << endl;
+                    winningteam = 1;
+                }
+
+                for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
+                {
+                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
+                        continue;
+
+                    if (it->second == winningteam)
+                        this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
+                    else
+                        this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+                }
+
+                this->end();
+                this->scoreTimer_.stopTimer();
+                this->outputTimer_.stopTimer();
+            }
+        }
+        
+        // this function is called by the function winPoints() which adds points to the teams for every base and killed openents at a certain time
+        void TeamBaseMatch::addTeamPoints(int team, int points)
+        {
+            if(team == 0)
+            {
+                this->pointsTeam1_ += points;
+            }
+            if(team == 1)
+            {
+                this->pointsTeam2_ += points;
+            }
+
+            this->endGame();
+        }
+
+        int TeamBaseMatch::getTeamPoints(int team)
+        {
+            if(team == 0)
+            {
+                return this->pointsTeam1_;
+            }
+            if(team == 1)
+            {
+                return this->pointsTeam2_;
+            }
+
+            return 0;
+        }
+        
+    SpawnPoint* CaptureTheFlag::getBestSpawnPoint(PlayerInfo* player) const
+    {
+        int desiredTeamNr = -1;
+        std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
+        if (it_player != this->teamnumbers_.end())
+            desiredTeamNr = it_player->second;
+
+        // Only use spawnpoints of the own team (or non-team-spawnpoints)
+        std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
+        for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
+        {
+            if ((*it)->isA(Class(TeamSpawnPoint)))
+            {
+                TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
+                if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)
+                {
+                    teamSpawnPoints.erase(it++);
+                    continue;
+                }
+            }
+
+            ++it;
+        }
+
+        SpawnPoint* fallbackSpawnPoint = NULL;
+        if (teamSpawnPoints.size() > 0)
+        {
+            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
+            unsigned int index = 0;
+            // Get random fallback spawnpoint in case there is no active SpawnPoint.
+            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
+            {
+                if (index == randomspawn)
+                {
+                    fallbackSpawnPoint = (*it);
+                    break;
+                }
+
+                ++index;
+            }
+
+            // Remove all inactive SpawnPoints from the list.
+            for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
+            {
+                if(!(*it)->isActive())
+                {
+                    teamSpawnPoints.erase(it++);
+                    continue;
+                }
+
+                ++it;
+            }
+
+            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
+            index = 0;
+            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
+            {
+                if (index == randomspawn)
+                    return (*it);
+
+                ++index;
+            }
+
+            return fallbackSpawnPoint;
+        }
+
+        return 0;
+    }
+
+    void CaptureTheFlag::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn)
+    {
+        if (!player)
+            return;
+
+        // Set the team colour
+        std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
+        if (it_player != this->teamnumbers_.end() && it_player->second >= 0 && it_player->second < static_cast<int>(this->teamcolours_.size()))
+        {
+            if (pawn)
+            {
+                pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
+
+                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
+                for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
+                {
+                    if ((*it)->isA(Class(TeamColourable)))
+                    {
+                        TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
+                        tc->setTeamColour(this->teamcolours_[it_player->second]);
+                    }
+                }
+            }
+        }
+    }
+
+    bool CaptureTheFlag::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2)
+    {
+        if (pawn1 && pawn2)
+        {
+            std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer());
+            std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer());
+
+            if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end())
+                return (it1->second == it2->second);
+        }
+        return false;
+    }
+
+    int CaptureTheFlag::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;
+    }
+}

Added: code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.h
===================================================================
--- code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.h	                        (rev 0)
+++ code/branches/captureTheFlag/src/modules/gametypes/captureTheFlag.h	2012-05-18 14:44:47 UTC (rev 9218)
@@ -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:
+ *      Nino Weingart
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _CaptureTheFlag__
+#define _CaptureTheFlag__
+
+#include "OrxonoxPrereqs.h"
+#include "FlagPickup.h"
+#include <set>
+#include "tools/Timer.h"
+#include "Gametype.h"
+
+
+namespace orxonox
+{
+    class _OrxonoxExport CaptureTheFlag : public Gametype
+    {
+    public:
+    	CaptureTheFlag(BaseObject* creator);
+                virtual ~CaptureTheFlag() {}
+
+                void tick(float dt);
+
+                void setConfigValues();
+
+                virtual void playerEntered(PlayerInfo* player);
+                virtual bool playerLeft(PlayerInfo* player);
+
+                virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
+                virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
+                virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
+
+                virtual void playerScored(PlayerInfo* player);
+                virtual void showPoints();
+                virtual void endGame();
+
+                void addTeamPoints(int team, int points);
+                int getTeamPoints(int team);
+
+                virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
+
+                int getTeam(PlayerInfo* player);
+                inline const ColourValue& getTeamColour(int teamnr) const
+                    { return this->teamcolours_[teamnr]; }
+
+            protected:
+                virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
+                bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
+
+                std::map<PlayerInfo*, int> teamnumbers_;
+                std::vector<ColourValue> teamcolours_;
+                unsigned int teams_;
+
+                FlagPickup* flagTeamBlue;
+                FlagPickup* flagTeamRed;
+                //points for each team
+                int pointsTeam1_;
+                int pointsTeam2_;
+
+    };
+}
+
+#endif /* _CaptureTheFlag_H__ */
+

Added: code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.cc
===================================================================
--- code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.cc	                        (rev 0)
+++ code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.cc	2012-05-18 14:44:47 UTC (rev 9218)
@@ -0,0 +1,219 @@
+/*
+ *   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:
+ *      Nino Weingart
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file FlagPickup.cc
+    @brief Implementation of the FlagPickup class.
+*/
+
+#include "FlagPickup.h"
+
+#include <sstream>
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "pickup/PickupIdentifier.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+
+    /*static*/ const std::string FlagPickup::flagTypeBlue_s = "blue";
+    /*static*/ const std::string FlagPickup::flagTypeRed_s = "red";
+    /*static*/ const std::string FlagPickup::flagTypeNeutral_s = "neutral";
+
+    CreateFactory(FlagPickup);
+
+    /**
+    @brief
+        Constructor. Registers the object and initializes the member variables.
+    */
+    FlagPickup::FlagPickup(BaseObject* creator) : Pickup(creator)
+    {
+        RegisterObject(FlagPickup);
+
+        this->initialize();
+    }
+
+    /**
+    @brief
+        Destructor.
+    */
+    FlagPickup::~FlagPickup()
+    {
+
+    }
+
+    /**
+    @brief
+        Initializes the member variables.
+    */
+    void FlagPickup::initialize(void)
+    {
+        this->flagType_ = pickupFlagType::0;
+
+        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+    }
+
+    /**
+    @brief
+        Initializes the PickupIdentifier of this pickup.
+    */
+    void FlagPickup::initializeIdentifier(void)
+    {
+        std::string val1 = this->getFlagType();
+        std::string type1 = "flagType";
+        this->pickupIdentifier_->addParameter(type1, val1);
+    }
+
+    /**
+    @brief
+        Method for creating a FlagPickup object through XML.
+    */
+    void FlagPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
+    {
+        SUPER(FlagPickup, XMLPort, xmlelement, mode);
+
+        XMLPortParam(FlagPickup, "flagType", setFlagType, getFlagType, xmlelement, mode);
+        //XMLPortParam(FlagPickup, "teamNumber", setTeamNumber, getTeamNumber, xmlelement, mode);
+
+        this->initializeIdentifier();
+    }
+
+
+    /**
+    @brief
+        Get the flag type of this pickup.
+    @return
+        Returns the falg type as a string.
+    */
+    const std::string& FlagPickup::getFlagType(void) const
+    {
+        switch(this->getFlagTypeDirect())
+        {
+            case pickupFlagType::blue:
+                return FlagPickup::flagTypeBlue_s;
+            case pickupFlagType::red:
+                return FlagPickup::flagTypeRed_s;
+            case pickupFlagType::neutral:
+                return FlagPickup::flagTypeNeutral_s;
+            default:
+                orxout(internal_error, context::pickups) << "Invalid flagType in FlagPickup." << endl;
+                return BLANKSTRING;
+        }
+    }
+
+    /**
+    @brief
+        Set the type of the HealthPickup.
+    @param type
+        The type as a string.
+    */
+    void FlagPickup::setFlagType(std::string type)
+    {
+        if(type == FlagPickup::flagTypeRed_s)
+            this->setFlagTypeDirect(pickupFlagType::2);
+        else if(type == FlagPickup::flagTypeBlue_s)
+            this->setFlagTypeDirect(pickupFlagType::1);
+        else if(type == FlagPickup::flagTypeNeutral_s)
+            this->setFlagTypeDirect(pickupFlagType::0);
+        else
+            orxout(internal_error, context::pickups) << "Invalid flagType '" << type << "' in FlagPickup." << endl;
+    }
+
+    /**
+       @brief
+           Is called when the pickup has transited from used to unused or the other way around.
+       */
+       void FlagPickup::changedUsed(void)
+       {
+           SUPER(FlagPickup, changedUsed);
+
+           Pawn* pawn = this->carrierToPawnHelper();
+
+           if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+               this->Pickupable::destroy();
+
+           // If the pickup has transited to used.
+           if(this->isUsed())
+           {
+               int team = getTeam(pawn->getPlayer);
+
+               if(this->flagType_ == team){
+            	   if(pawn->hasFlag_){
+               		   teamScore_ = TeamScore_ + 1000;
+                	   pawn->hasFlag_ = false;
+                   }
+               this->Pickupable::destroy();
+               }else{
+            	   pawn->hasFlag_ = true;
+               }
+           }
+       }
+
+
+
+       /**
+       @brief
+           Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
+       @return
+           A pointer to the Pawn, or NULL if the conversion failed.
+       */
+       Pawn* FlagPickup::carrierToPawnHelper(void)
+       {
+           PickupCarrier* carrier = this->getCarrier();
+           Pawn* pawn = dynamic_cast<Pawn*>(carrier);
+
+           if(pawn == NULL)
+               orxout(internal_error, context::pickups) << "Invalid PickupCarrier in HealthPickup." << endl;
+
+           return pawn;
+       }
+
+    int FlagPickup::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;
+    }
+
+}
+
+	void FlagPickup::tick(float dt)
+	   {
+		   SUPER(FlagPickup, tick, dt);
+
+	       Pawn* pawn = this->carrierToPawnHelper();
+
+		   if(pawn->isAlive() && pawn->hasFlag_){
+               this->Pickupable::destroy();
+		   }
+
+	   }

Added: code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.h
===================================================================
--- code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.h	                        (rev 0)
+++ code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.h	2012-05-18 14:44:47 UTC (rev 9218)
@@ -0,0 +1,109 @@
+/*
+ *   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:
+ *      Nino Weingart
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file FlagPickup.h
+    @brief Declaration of the FlagPickup class.
+    @ingroup PickupItems
+*/
+
+#ifndef _FlagPickup_H__
+#define _FlagPickup_H__
+
+#include "pickup/PickupPrereqs.h"
+
+#include <string>
+
+#include "pickup/Pickup.h"
+
+namespace orxonox {
+
+    @ingroup PickupItems
+    */
+    namespace pickupFlagType
+    {
+        enum Value
+        {
+            blue, //!< Means that the @ref orxonox::FlagPickup "FlagPickup" is the flag of the blue team.
+            red, //!< Means that the @ref orxonox::FlagPickup "FlagPickup" is the flag of the red team.
+	        neutral //!< Means that the @ref orxonox::FlagPickup "FlagPickup" is a neutral flag.
+        };
+    }
+
+    /**
+
+    @author
+        Nino Weingart
+
+    @ingroup PickupItems
+    */
+    class _PickupExport FlagPickup : public Pickup, public Tickable
+    {
+        public:
+
+            FlagPickup(BaseObject* creator); //!< Constructor.
+            virtual ~FlagPickup(); //!< Destructor.
+
+            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a FlagPickup object through XML.
+
+            virtual void tick(float dt);
+
+	    const std::string& getFlagType(void) const; //!< Get the flag type of this pickup.
+
+
+	    virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
+
+        protected:
+            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
+
+            /**
+            @brief Set the flag type of this pickup.
+            @param type The type of this pickup as an enum.
+            */
+            inline void setFlagTypeDirect(pickupFlagType::Value type)
+                { this->flagType_ = type; }
+            void setFlagType(std::string type); //!< Set the type of the FlagPickup.
+
+        private:
+            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
+            int getTeam(PlayerInfo* player);
+            void initialize(void); //!< Initializes the member variables.
+
+            pickupFlagType::Value flagType_; //!< The type of the FlagPickup.
+
+            int teamScore_;
+
+            //! Strings for the flag types.
+            static const std::string flagTypeBlue_s;
+            static const std::string flagTypeRed_s;
+	        static const std::string flagTypeNeutral_s;
+
+    };
+}
+
+#endif // _FlagPickup_H__

Added: code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.cpp
===================================================================
--- code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.cpp	                        (rev 0)
+++ code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.cpp	2012-05-18 14:44:47 UTC (rev 9218)
@@ -0,0 +1,230 @@
+/*
+ *   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:
+ *      Nino Weingart
+ *   Co-authors:
+ *      ...
+ *
+ */
+#include "CaptureTheFlag.h"
+
+#include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
+#include "interfaces/TeamColourable.h"
+#include "worldentities/TeamSpawnPoint.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+    CreateUnloadableFactory(CaptureTheFlag);
+
+    CaptureTheFlag::CaptureTheFlag(BaseObject* creator) : Deathmatch(creator)
+    {
+        RegisterObject(CaptureTheFlag);
+
+        this->teams_ = 2;
+
+        this->setConfigValues();
+    }
+
+    void CaptureTheFlag::setConfigValues()
+    {
+        SetConfigValue(teams_, 2);
+
+        static ColourValue colours[] =
+        {
+            ColourValue(1.0f, 0.3f, 0.3f),
+            ColourValue(0.3f, 0.3f, 1.0f),
+            ColourValue(0.3f, 1.0f, 0.3f),
+            ColourValue(1.0f, 1.0f, 0.0f)
+        };
+        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
+
+        SetConfigValue(teamcolours_, defaultcolours);
+    }
+
+    void CaptureTheFlag::playerEntered(PlayerInfo* player)
+    {
+        Deathmatch::playerEntered(player);
+
+        std::vector<unsigned int> playersperteam(this->teams_, 0);
+
+        for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
+            if (it->second < static_cast<int>(this->teams_) && it->second >= 0)
+                playersperteam[it->second]++;
+
+        unsigned int minplayers = static_cast<unsigned int>(-1);
+        size_t minplayersteam = 0;
+        for (size_t i = 0; i < this->teams_; ++i)
+        {
+            if (playersperteam[i] < minplayers)
+            {
+                minplayers = playersperteam[i];
+                minplayersteam = i;
+            }
+        }
+
+        this->teamnumbers_[player] = minplayersteam;
+    }
+
+    bool CaptureTheFlag::playerLeft(PlayerInfo* player)
+    {
+        bool valid_player = Deathmatch::playerLeft(player);
+
+        if (valid_player)
+            this->teamnumbers_.erase(player);
+
+        return valid_player;
+    }
+
+    bool CaptureTheFlag::allowPawnHit(Pawn* victim, Pawn* originator)
+    {
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
+    }
+
+    bool CaptureTheFlag::allowPawnDamage(Pawn* victim, Pawn* originator)
+    {
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
+    }
+
+    bool CaptureTheFlag::allowPawnDeath(Pawn* victim, Pawn* originator)
+    {
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
+    }
+
+    SpawnPoint* CaptureTheFlag::getBestSpawnPoint(PlayerInfo* player) const
+    {
+        int desiredTeamNr = -1;
+        std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
+        if (it_player != this->teamnumbers_.end())
+            desiredTeamNr = it_player->second;
+
+        // Only use spawnpoints of the own team (or non-team-spawnpoints)
+        std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
+        for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
+        {
+            if ((*it)->isA(Class(TeamSpawnPoint)))
+            {
+                TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
+                if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)
+                {
+                    teamSpawnPoints.erase(it++);
+                    continue;
+                }
+            }
+
+            ++it;
+        }
+
+        SpawnPoint* fallbackSpawnPoint = NULL;
+        if (teamSpawnPoints.size() > 0)
+        {
+            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
+            unsigned int index = 0;
+            // Get random fallback spawnpoint in case there is no active SpawnPoint.
+            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
+            {
+                if (index == randomspawn)
+                {
+                    fallbackSpawnPoint = (*it);
+                    break;
+                }
+
+                ++index;
+            }
+
+            // Remove all inactive SpawnPoints from the list.
+            for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
+            {
+                if(!(*it)->isActive())
+                {
+                    teamSpawnPoints.erase(it++);
+                    continue;
+                }
+
+                ++it;
+            }
+
+            randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
+            index = 0;
+            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
+            {
+                if (index == randomspawn)
+                    return (*it);
+
+                ++index;
+            }
+
+            return fallbackSpawnPoint;
+        }
+
+        return 0;
+    }
+
+    void CaptureTheFlag::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn)
+    {
+        if (!player)
+            return;
+
+        // Set the team colour
+        std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
+        if (it_player != this->teamnumbers_.end() && it_player->second >= 0 && it_player->second < static_cast<int>(this->teamcolours_.size()))
+        {
+            if (pawn)
+            {
+                pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
+
+                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
+                for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
+                {
+                    if ((*it)->isA(Class(TeamColourable)))
+                    {
+                        TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
+                        tc->setTeamColour(this->teamcolours_[it_player->second]);
+                    }
+                }
+            }
+        }
+    }
+
+    bool CaptureTheFlag::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2)
+    {
+        if (pawn1 && pawn2)
+        {
+            std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer());
+            std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer());
+
+            if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end())
+                return (it1->second == it2->second);
+        }
+        return false;
+    }
+
+    int CaptureTheFlag::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;
+    }
+}

Added: code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.h
===================================================================
--- code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.h	                        (rev 0)
+++ code/branches/captureTheFlag/src/orxonox/gametypes/captureTheFlag.h	2012-05-18 14:44:47 UTC (rev 9218)
@@ -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:
+ *      Nino Weingart
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _CaptureTheFlag__
+#define _CaptureTheFlag__
+
+#include "OrxonoxPrereqs.h"
+#include "FlagPickup.h"
+#include <set>
+#include "tools/Timer.h"
+#include "Gametype.h"
+
+
+namespace orxonox
+{
+    class _OrxonoxExport CaptureTheFlag : public Gametype
+    {
+    public:
+    	CaptureTheFlag(BaseObject* creator);
+                virtual ~CaptureTheFlag() {}
+
+                void tick(float dt);
+
+                void setConfigValues();
+
+                virtual void playerEntered(PlayerInfo* player);
+                virtual bool playerLeft(PlayerInfo* player);
+
+                virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
+                virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
+                virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
+
+                virtual void playerScored(PlayerInfo* player);
+                virtual void showPoints();
+                virtual void endGame();
+
+                void addTeamPoints(int team, int points);
+                int getTeamPoints(int team);
+
+                virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
+
+                int getTeam(PlayerInfo* player);
+                inline const ColourValue& getTeamColour(int teamnr) const
+                    { return this->teamcolours_[teamnr]; }
+
+            protected:
+                virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
+                bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
+
+                std::map<PlayerInfo*, int> teamnumbers_;
+                std::vector<ColourValue> teamcolours_;
+                unsigned int teams_;
+
+                FlagPickup flagTeamBlue;
+                FlagPickup flagTeamBlue;
+                //points for each team
+                int pointsTeam1_;
+                int pointsTeam2_;
+
+    };
+}
+
+#endif /* _CaptureTheFlag_H__ */
+




More information about the Orxonox-commit mailing list