Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial6/src/modules/pickup/items/MunitionContainer.cc @ 11479

Last change on this file since 11479 was 11052, checked in by landauf, 9 years ago

merged branch presentationHS15 back to trunk

  • Property svn:eol-style set to native
File size: 3.4 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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file MunitionContainer.cc
31    @brief Implementation of the MunitionContainer class. This class is only used by the MunitionPickup class to defines  how much munition of what type the pickup contains.
32*/
33
34#include "MunitionContainer.h"
35
36#include <sstream>
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39
40namespace orxonox
41{
42    RegisterClass(MunitionContainer);
43
44    /**
45    @brief
46        Constructor. Registers the object and initializes the member variables.
47    */
48    MunitionContainer::MunitionContainer(Context* context) : BaseObject(context)
49    {
50        RegisterObject(MunitionContainer);
51
52        this->munitionName_ = "";
53        this->munitionAmount_ = 1;
54        this->magazinesAmount_ = 1;
55    }
56
57    /**
58    @brief
59        Destructor.
60    */
61    MunitionContainer::~MunitionContainer()
62    {
63    }   
64
65    /**
66    @brief
67        Method for creating a MunitionContainer object through XML.
68    */
69    void MunitionContainer::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
70    {
71        SUPER(MunitionContainer, XMLPort, xmlelement, mode);
72
73        XMLPortParam(MunitionContainer, "munitiontype", setMunitionName, getMunitionName, xmlelement, mode).defaultValues("LaserMunition");
74        XMLPortParam(MunitionContainer, "munitionamount", setMunitionAmount, getMunitionAmount, xmlelement, mode).defaultValues(1);
75        XMLPortParam(MunitionContainer, "magazinesamount", setMagazinesAmount, getMagazinesAmount, xmlelement, mode).defaultValues(0);
76    }
77
78    void MunitionContainer::setMunitionName(const std::string& munitionName)
79    {
80        Identifier* identifier = ClassByString(munitionName);
81        if (identifier)
82        {
83            this->munitionName_ = munitionName;
84            this->munitionType_ = identifier;
85        }
86        else
87        {
88            this->munitionName_ = "";           
89            orxout(internal_warning) << "Invalid munition class defined in MunitionContainer." << endl;
90        }
91    }   
92
93    void MunitionContainer::setMunitionAmount(int munitionAmount)
94    {
95        if (munitionAmount > 0)
96        {
97            munitionAmount_ = munitionAmount;
98        }
99        else
100        {
101            munitionAmount_ = 0;
102        }
103    }
104
105    void MunitionContainer::setMagazinesAmount(int magazinesAmount)
106    {
107        if (magazinesAmount > 0)
108        {
109            magazinesAmount_ = magazinesAmount;
110        }
111        else
112        {
113            magazinesAmount_ = 0;
114        }
115    }         
116}
117
Note: See TracBrowser for help on using the repository browser.