Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/src/modules/pickup/items/DronePickup.cc @ 9352

Last change on this file since 9352 was 9320, checked in by landauf, 12 years ago

removed Pickupable::clone() because it is not needed anymore

  • Property svn:eol-style set to native
File size: 4.8 KB
RevLine 
[6782]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 *      Lukas Gasser
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file DronePickup.cc
31    @brief Implementation of the DronePickup class.
32*/
33
34#include "DronePickup.h"
35
[7541]36#include <sstream>
[6782]37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39
[7541]40#include "controllers/DroneController.h"
[7547]41#include "worldentities/Drone.h"
[6782]42#include "worldentities/pawns/Pawn.h"
43
44namespace orxonox
45{
46
47    CreateFactory(DronePickup);
[7127]48
[6782]49    /**
50    @brief
51        Constructor. Registers the object and initializes the member variables.
52    */
53    DronePickup::DronePickup(BaseObject* creator) : Pickup(creator)
54    {
55        RegisterObject(DronePickup);
[7127]56
[6782]57        this->initialize();
58    }
[7127]59
[6782]60    /**
61    @brief
62        Destructor.
63    */
64    DronePickup::~DronePickup()
65    {
[7127]66
[6782]67    }
[7127]68
[6782]69    /**
[7127]70    @brief
[6782]71        Initializes the member variables.
72    */
73    void DronePickup::initialize(void)
74    {
75        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
[9313]76        this->setDurationType(pickupDurationType::once);
[6782]77        this->droneTemplate_ = "";
78    }
[7127]79
[6782]80    /**
81    @brief
82        Method for creating a DronePickup object through XML.
83    */
84    void DronePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
85    {
86        SUPER(DronePickup, XMLPort, xmlelement, mode);
87        XMLPortParam(DronePickup, "droneTemplate", setDroneTemplate, getDroneTemplate, xmlelement, mode);
88    }
[7127]89
[7541]90    /**
91    @brief
92        Set the droneTemplate.
93    @param templatename
94        The name of the Template to e set.
95    */
[9312]96    void DronePickup::setDroneTemplate(const std::string& templatename){
[6782]97        droneTemplate_ = templatename;
[7127]98    }
99
[7541]100    /**
101    @brief
102        Get the name of the droneTemplate.
103    @return
104        Returns the name of the droneTemplate.
105    */
[6782]106    const std::string& DronePickup::getDroneTemplate() const
107    {
108        return droneTemplate_;
109    }
110
111    /**
112    @brief
113        Is called when the pickup has transited from used to unused or the other way around.
114    */
115    void DronePickup::changedUsed(void)
116    {
117        SUPER(DronePickup, changedUsed);
[7127]118
[7541]119        // If the pickup has transited to used.
[6782]120        if(this->isUsed())
121        {
122
123                Pawn* pawn = this->carrierToPawnHelper();
[7541]124                if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
[7162]125                    this->Pickupable::destroy();
[7127]126
[6782]127                //Attach to pawn
[6891]128                Drone* drone = new Drone(pawn->getCreator()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
[6782]129                drone->addTemplate(this->getDroneTemplate());
[6891]130
[6782]131                Controller* controller = drone->getController();
[9279]132                DroneController* droneController = orxonox_cast<DroneController*>(controller);
[6782]133                if(droneController != NULL)
134                {
[6847]135                    droneController->setOwner(pawn);
[6782]136                }
[7127]137
[6891]138                Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30);
139                drone->setPosition(spawnPosition);
[7127]140
[7541]141                // The pickup has been used up.
[6782]142                this->setUsed(false);
143        }
144        else
145        {
[7541]146            // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
[6782]147            if(this->isOnce() || (this->isContinuous() ))
148            {
[7162]149                this->Pickupable::destroy();
[6782]150            }
151        }
152    }
[7127]153
[6782]154    /**
155    @brief
156        Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
157    @return
158        A pointer to the Pawn, or NULL if the conversion failed.
159    */
160    Pawn* DronePickup::carrierToPawnHelper(void)
161    {
162        PickupCarrier* carrier = this->getCarrier();
[9279]163        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
[7127]164
[6782]165        if(pawn == NULL)
166        {
[8858]167            orxout(internal_error, context::pickups) << "Invalid PickupCarrier in DronePickup." << endl;
[6782]168        }
[7127]169
[6782]170        return pawn;
171    }
172}
Note: See TracBrowser for help on using the repository browser.