| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #include "InvisiblePickup.h" |
|---|
| 35 | |
|---|
| 36 | #include "core/CoreIncludes.h" |
|---|
| 37 | #include "core/XMLPort.h" |
|---|
| 38 | #include "util/StringUtils.h" |
|---|
| 39 | |
|---|
| 40 | #include "worldentities/pawns/Pawn.h" |
|---|
| 41 | #include "pickup/PickupIdentifier.h" |
|---|
| 42 | |
|---|
| 43 | #include <sstream> |
|---|
| 44 | |
|---|
| 45 | #include <OgreEntity.h> |
|---|
| 46 | #include <Ogre.h> |
|---|
| 47 | |
|---|
| 48 | namespace orxonox |
|---|
| 49 | { |
|---|
| 50 | |
|---|
| 51 | CreateFactory(InvisiblePickup); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | InvisiblePickup::InvisiblePickup(BaseObject* creator) : Pickup(creator) |
|---|
| 58 | { |
|---|
| 59 | RegisterObject(InvisiblePickup); |
|---|
| 60 | |
|---|
| 61 | this->initialize(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | InvisiblePickup::~InvisiblePickup() |
|---|
| 69 | { |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | void InvisiblePickup::initializeIdentifier(void) |
|---|
| 74 | { |
|---|
| 75 | std::stringstream stream; |
|---|
| 76 | stream << this->getDuration(); |
|---|
| 77 | std::string type1 = "duration"; |
|---|
| 78 | std::string val1 = stream.str(); |
|---|
| 79 | this->pickupIdentifier_->addParameter(type1, val1); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | void InvisiblePickup::initialize(void) |
|---|
| 87 | { |
|---|
| 88 | this->duration_ = 0.0f; |
|---|
| 89 | this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) |
|---|
| 97 | { |
|---|
| 98 | SUPER(InvisiblePickup, XMLPort, xmlelement, mode); |
|---|
| 99 | XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode); |
|---|
| 100 | |
|---|
| 101 | this->initializeIdentifier(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | void InvisiblePickup::changedUsed(void) |
|---|
| 109 | { |
|---|
| 110 | SUPER(InvisiblePickup, changedUsed); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | if(!this->isPickedUp()) |
|---|
| 114 | return; |
|---|
| 115 | |
|---|
| 116 | if (this->isUsed()) |
|---|
| 117 | { |
|---|
| 118 | if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() > 0.0f) |
|---|
| 119 | { |
|---|
| 120 | this->getTimer()->unpauseTimer(); |
|---|
| 121 | } |
|---|
| 122 | else |
|---|
| 123 | { |
|---|
| 124 | this->startPickupTimer(this->getDuration()); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | this->setInvisible(true); |
|---|
| 128 | |
|---|
| 129 | } |
|---|
| 130 | else |
|---|
| 131 | { |
|---|
| 132 | this->setInvisible(false); |
|---|
| 133 | |
|---|
| 134 | if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration()) |
|---|
| 135 | { |
|---|
| 136 | this->destroy(); |
|---|
| 137 | } |
|---|
| 138 | else |
|---|
| 139 | { |
|---|
| 140 | this->getTimer()->pauseTimer(); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | Pawn* InvisiblePickup::carrierToPawnHelper(void) |
|---|
| 153 | { |
|---|
| 154 | PickupCarrier* carrier = this->getCarrier(); |
|---|
| 155 | Pawn* pawn = dynamic_cast<Pawn*>(carrier); |
|---|
| 156 | |
|---|
| 157 | if(pawn == NULL) |
|---|
| 158 | { |
|---|
| 159 | COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl; |
|---|
| 160 | } |
|---|
| 161 | return pawn; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | void InvisiblePickup::clone(OrxonoxClass*& item) |
|---|
| 171 | { |
|---|
| 172 | if(item == NULL) |
|---|
| 173 | item = new InvisiblePickup(this); |
|---|
| 174 | |
|---|
| 175 | SUPER(InvisiblePickup, clone, item); |
|---|
| 176 | |
|---|
| 177 | InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item); |
|---|
| 178 | pickup->setDuration(this->getDuration()); |
|---|
| 179 | pickup->initializeIdentifier(); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | bool InvisiblePickup::setInvisible(bool invisibility) |
|---|
| 189 | { |
|---|
| 190 | Pawn* pawn = this->carrierToPawnHelper(); |
|---|
| 191 | if(pawn == NULL) |
|---|
| 192 | return false; |
|---|
| 193 | |
|---|
| 194 | pawn->setVisible(!invisibility); |
|---|
| 195 | pawn->setRadarVisibility(!invisibility); |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | return true; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | void InvisiblePickup::setDuration(float duration) |
|---|
| 217 | { |
|---|
| 218 | if(duration >= 0.0f) |
|---|
| 219 | { |
|---|
| 220 | this->duration_ = duration; |
|---|
| 221 | } |
|---|
| 222 | else |
|---|
| 223 | { |
|---|
| 224 | COUT(1) << "Invalid duration in InvisiblePickup." << std::endl; |
|---|
| 225 | this->duration_ = 0.0f; |
|---|
| 226 | } |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | void InvisiblePickup::pickupTimerCallback(void) |
|---|
| 230 | { |
|---|
| 231 | this->setUsed(false); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | } |
|---|