Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012/src/modules/pickup/items/FlagPickup.cc @ 9241

Last change on this file since 9241 was 9241, checked in by decapitb, 12 years ago

tower defense update

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