Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/captureTheFlag/src/modules/pickup/items/FlagPickup.cc @ 9352

Last change on this file since 9352 was 9232, checked in by decapitb, 13 years ago

safety checkin

File size: 4.5 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 *      Nino Weingart
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file FlagPickup.cc
31    @brief Implementation of the FlagPickup class.
32*/
33
34#include "FlagPickup.h"
35
36#include <sstream>
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39
40#include "pickup/PickupIdentifier.h"
41
42namespace orxonox
43{
44
45    CreateFactory(FlagPickup);
46
47    /**
48    @brief
49        Constructor. Registers the object and initializes the member variables.
50    */
51    FlagPickup::FlagPickup(BaseObject* creator) : Pickup(creator)
52    {
53        RegisterObject(FlagPickup);
54
55        this->initialize();
56    }
57
58    /**
59    @brief
60        Destructor.
61    */
62    FlagPickup::~FlagPickup()
63    {
64
65    }
66
67    /**
68    @brief
69        Initializes the member variables.
70    */
71    void FlagPickup::initialize(void)
72    {
73        this->flagType_ = 0;
74
75        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
76    }
77
78    /**
79    @brief
80        Initializes the PickupIdentifier of this pickup.
81    */
82    void FlagPickup::initializeIdentifier(void)
83    {
84        std::stringstream stream;
85        int type = this->getFlagType();
86        stream << type;
87                std::string val = stream.str();
88               
89        std::string type1 = "flagType";
90        this->pickupIdentifier_->addParameter(type1, val);
91    }
92
93    /**
94    @brief
95        Method for creating a FlagPickup object through XML.
96    */
97    void FlagPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
98    {
99        SUPER(FlagPickup, XMLPort, xmlelement, mode);
100
101        XMLPortParam(FlagPickup, "flagType", setFlagType, getFlagType, xmlelement, mode);
102        //XMLPortParam(FlagPickup, "teamNumber", setTeamNumber, getTeamNumber, xmlelement, mode);
103
104        this->initializeIdentifier();
105    }
106
107
108    /**
109    @brief
110        Get the flag type of this pickup.
111    @return
112        Returns the falg type as a string.
113    */
114    const int FlagPickup::getFlagType(void) const
115    {
116                return this->flagType_;
117        }
118
119    /**
120    @brief
121        Set the type of the HealthPickup.
122    @param type
123        The type as a string.
124    */
125    void FlagPickup::setFlagType(int type)
126    {
127        if(type<3){
128                this->flagType_ = type;
129        }
130       
131        else{
132            orxout(internal_error, context::pickups) << "Invalid flagType '" << type << "' in FlagPickup." << endl;
133        }
134    }
135
136    /**
137       @brief
138           Is called when the pickup has transited from used to unused or the other way around.
139       */
140       void FlagPickup::changedUsed(void)
141       {
142           SUPER(FlagPickup, changedUsed);
143
144           Pawn* pawn = this->carrierToPawnHelper();
145
146           if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
147               this->Pickupable::destroy();
148
149           // If the pickup has transited to used.
150           if(this->isUsed())
151           {
152                 this->bPickedUp_ = true;
153                 this->pickedUpBy_ = pawn;
154           }
155       }
156
157       /**
158       @brief
159           Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
160       @return
161           A pointer to the Pawn, or NULL if the conversion failed.
162       */
163       Pawn* FlagPickup::carrierToPawnHelper(void)
164       {
165           PickupCarrier* carrier = this->getCarrier();
166           Pawn* pawn = dynamic_cast<Pawn*>(carrier);
167
168           if(pawn == NULL)
169               orxout(internal_error, context::pickups) << "Invalid PickupCarrier in HealthPickup." << endl;
170
171           return pawn;
172       }
173
174
175
176        void FlagPickup::tick(float dt)
177           {
178                   SUPER(FlagPickup, tick, dt);
179
180               Pawn* pawn = this->carrierToPawnHelper();
181
182                   if(pawn->isAlive() && pawn->hasFlag()){
183               this->Pickupable::destroy();
184                   }
185
186           }
187}
Note: See TracBrowser for help on using the repository browser.