[9218] | 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 | /** |
---|
[9241] | 30 | @file FlagPickup.cc |
---|
| 31 | @brief Implementation of the FlagPickup class. |
---|
| 32 | */ |
---|
[9218] | 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 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[9241] | 43 | |
---|
[9218] | 44 | CreateFactory(FlagPickup); |
---|
[9241] | 45 | |
---|
[9218] | 46 | /** |
---|
[9241] | 47 | @brief |
---|
| 48 | Constructor. Registers the object and initializes the member variables. |
---|
| 49 | */ |
---|
[9218] | 50 | FlagPickup::FlagPickup(BaseObject* creator) : Pickup(creator) |
---|
| 51 | { |
---|
| 52 | RegisterObject(FlagPickup); |
---|
[9241] | 53 | |
---|
[9218] | 54 | this->initialize(); |
---|
| 55 | } |
---|
[9241] | 56 | |
---|
[9218] | 57 | /** |
---|
[9241] | 58 | @brief |
---|
| 59 | Destructor. |
---|
| 60 | */ |
---|
[9218] | 61 | FlagPickup::~FlagPickup() |
---|
| 62 | { |
---|
[9241] | 63 | |
---|
[9218] | 64 | } |
---|
[9241] | 65 | |
---|
[9218] | 66 | /** |
---|
[9241] | 67 | @brief |
---|
| 68 | Initializes the member variables. |
---|
| 69 | */ |
---|
[9218] | 70 | void FlagPickup::initialize(void) |
---|
| 71 | { |
---|
[9232] | 72 | this->flagType_ = 0; |
---|
[9241] | 73 | |
---|
[9218] | 74 | this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); |
---|
| 75 | } |
---|
[9241] | 76 | |
---|
[9218] | 77 | /** |
---|
[9241] | 78 | @brief |
---|
| 79 | Initializes the PickupIdentifier of this pickup. |
---|
| 80 | */ |
---|
[9218] | 81 | void FlagPickup::initializeIdentifier(void) |
---|
| 82 | { |
---|
[9232] | 83 | std::stringstream stream; |
---|
| 84 | int type = this->getFlagType(); |
---|
| 85 | stream << type; |
---|
| 86 | std::string val = stream.str(); |
---|
| 87 | |
---|
[9218] | 88 | std::string type1 = "flagType"; |
---|
[9232] | 89 | this->pickupIdentifier_->addParameter(type1, val); |
---|
[9218] | 90 | } |
---|
[9241] | 91 | |
---|
[9218] | 92 | /** |
---|
[9241] | 93 | @brief |
---|
| 94 | Method for creating a FlagPickup object through XML. |
---|
| 95 | */ |
---|
[9218] | 96 | void FlagPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) |
---|
| 97 | { |
---|
| 98 | SUPER(FlagPickup, XMLPort, xmlelement, mode); |
---|
[9241] | 99 | |
---|
[9218] | 100 | XMLPortParam(FlagPickup, "flagType", setFlagType, getFlagType, xmlelement, mode); |
---|
| 101 | //XMLPortParam(FlagPickup, "teamNumber", setTeamNumber, getTeamNumber, xmlelement, mode); |
---|
[9241] | 102 | |
---|
[9218] | 103 | this->initializeIdentifier(); |
---|
| 104 | } |
---|
[9241] | 105 | |
---|
| 106 | |
---|
[9218] | 107 | /** |
---|
[9241] | 108 | @brief |
---|
| 109 | Get the flag type of this pickup. |
---|
| 110 | @return |
---|
| 111 | Returns the falg type as a string. |
---|
| 112 | */ |
---|
[9232] | 113 | const int FlagPickup::getFlagType(void) const |
---|
[9218] | 114 | { |
---|
[9232] | 115 | return this->flagType_; |
---|
| 116 | } |
---|
[9241] | 117 | |
---|
[9218] | 118 | /** |
---|
[9241] | 119 | @brief |
---|
| 120 | Set the type of the FlagPickup. |
---|
| 121 | @param type |
---|
| 122 | The type as a string. |
---|
| 123 | */ |
---|
[9232] | 124 | void FlagPickup::setFlagType(int type) |
---|
[9218] | 125 | { |
---|
[9232] | 126 | if(type<3){ |
---|
| 127 | this->flagType_ = type; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | else{ |
---|
[9218] | 131 | orxout(internal_error, context::pickups) << "Invalid flagType '" << type << "' in FlagPickup." << endl; |
---|
[9232] | 132 | } |
---|
[9218] | 133 | } |
---|
[9241] | 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; |
---|
[9218] | 154 | |
---|
[9241] | 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
[9218] | 158 | /** |
---|
[9241] | 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 | |
---|
[9218] | 177 | void FlagPickup::tick(float dt) |
---|
[9241] | 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 | } |
---|
[9232] | 188 | } |
---|