Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/src/orxonox/LevelInfo.h @ 9274

Last change on this file since 9274 was 9272, checked in by landauf, 12 years ago

replaced tabs with spaces (no code changed)

  • Property svn:eol-style set to native
File size: 13.4 KB
RevLine 
[7614]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 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
[9272]26 *
[7614]27 */
28
[7625]29/**
30    @file LevelInfo.h
31    @brief Definition of the LevelInfo and LevelInfoItem class.
32    @ingroup Orxonox
33*/
34
[7614]35#ifndef _LevelInfo_H__
36#define _LevelInfo_H__
37
38#include "OrxonoxPrereqs.h"
39
40#include <set>
41#include <string>
[7802]42#include "util/StringUtils.h"
[7625]43
[7614]44#include "core/BaseObject.h"
[9269]45#include <iostream>
46#include <fstream>
[7625]47#include "core/OrxonoxClass.h"
[7614]48
[7626]49namespace orxonox // tolua_export
50{ // tolua_export
[7625]51
52    /**
53    @brief
[7804]54        The LevelInfoItem class stores information regarding a @ref orxonox::Level "Level" and makes that information accessible through the @ref orxonox::LevelManager "LevelManager".
[7625]55        A LevelInfoItem object is commonly created from a @ref orxonox::LevelInfo "LevelInfo" object, using its <code>copy()</code> method.
56
57    @author
58        Damian 'Mozork' Frick
[7804]59
60    @ingroup Orxonox
[7625]61    */
[7626]62    class _OrxonoxExport LevelInfoItem // tolua_export
63        : virtual public OrxonoxClass
64    { // tolua_export
[7614]65        public:
[7625]66            LevelInfoItem(); //!< Default constructor.
67            LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object.
68            virtual ~LevelInfoItem(); //!< Destructor.
[7614]69
[7625]70            /**
71            @brief Set the name of the Level.
72            @param name The name to be set.
73            */
74            inline void setName(const std::string& name)
75                { this->name_ = std::string(name); }
76            /**
77            @brief Get the name of the Level.
78            @return Returns the name of the Level.
79            */
[7802]80            inline const std::string& getName(void) const { return this->name_; } // tolua_export
[9272]81
[9016]82            /**
83            @brief Set the screenshot of the Level.
84            @param screenshot The screenshot to be set.
85            */
86            inline void setScreenshot(const std::string& screenshot) { this->screenshot_ = std::string(screenshot); }
87            /**
88            @brief Get the screenshot of the Level.
89            @return Returns the screenshot of the Level.
90            */
91            inline const std::string& getScreenshot() const { return this->screenshot_; } // tolua_export
[7625]92
93            /**
94            @brief Set the description of the Level.
95            @param description The description to be set.
96            */
[7614]97            inline void setDescription(const std::string& description)
[7625]98                { this->description_ = std::string(description); }
99            /**
100            @brief Get the description of the Level.
101            @return Returns the description of the Level.
102            */
[7626]103            inline const std::string& getDescription() const { return this->description_; } // tolua_export
[7625]104
105            void setTags(const std::string& tags); //!< Set the tags the Level is tagged with.
106            bool addTag(const std::string& tag, bool update = true); //!< Add a tag to the set of tags the Level is tagged with.
107            /**
108            @brief Get the lis of the tags the Level is tagged with.
109            @return Returns a comma-seperated string of all the tags the Level is tagged with.
110            */
[7614]111            inline const std::string& getTags(void) const
112                { return this->tagsString_; }
[7625]113            /**
114            @brief Get whether the Level has a specific tag.
115            @param tag The tag for which is checked.
116            @return Returns true if the Level is tagged with the input tag.
117            */
[7626]118            inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
[9272]119
[9269]120            void setShips(const std::string& ships); //!< Set the starting ship models of the level
121            bool addShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
[7625]122            /**
[9269]123            @brief Get the set of starting ship models the Level allows
124            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
125            */
126            inline const std::string& getShips(void) const
[9272]127                { return this->startingShipsString_; }
[9269]128            /**
129            @brief Get whether the Level allows a specific starting ship model
130            @param ship The ship model for which is checked.
131            @return Returns true if the Level allows the input ship model
132            */
[9272]133            inline bool hasShip(const std::string& ship) const { return this->ships_.find(ship) != this->ships_.end(); } // tolua_export
[9269]134            /**
[7625]135            @brief Get the XML-filename of the Level.
136            @return Returns the XML-filename (including *.oxw extension) of the Level.
137            */
[9269]138
[8079]139            inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
[9272]140            inline void selectShip (const std::string& ship) { this->changeShip(ship); } // tolua_export
[7625]141
[9269]142
[7625]143        protected:
144            /**
145            @brief Set the XML-filename of the Level.
146            @param filename The XML-filename to be set.
147            */
148            inline void setXMLFilename(const std::string& filename)
149                { this->xmlfilename_ = std::string(filename); }
150
151            std::string xmlfilename_; //!< The XML-filename of the Level.
152
[7614]153        private:
[9269]154
[9272]155            inline void changeShip (const std::string& model) {
156                static std::string shipSelectionTag = "shipselection";
157                //HACK: Read Level XML File, find "shipselection", replace with ship model
158                std::string levelPath = "../levels/";
159                levelPath.append(this->getXMLFilename());
160                std::string tempPath = "../levels/";
161                tempPath.append("_temp.oxw");
162                orxout(user_status) << levelPath << endl;
163                orxout(user_status) << tempPath << endl;
164                std::ifstream myLevel (levelPath.c_str());
165                std::ofstream tempLevel (tempPath.c_str());
166                while(!myLevel.eof())
167                {
168                    std::string buff;
169                    std::getline(myLevel, buff);
170                    std::string pawndesignString = "pawndesign=";
171                    size_t found = buff.find(pawndesignString.append(shipSelectionTag));
172                    if (found!= std::string::npos)
173                        buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
174                    tempLevel.write(buff.c_str(), buff.length());
175                    tempLevel << std::endl;
176                }
177                myLevel.close();
178                tempLevel.close();
179                orxout(user_status) << "done" << endl;
180            }
[7625]181            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
[9269]182            void shipsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
[7645]183            static void initializeTags(void); //!< Initialize the set of allowed tags.
184            /**
185            @brief Check whether an input tag is allowed.
186            @param tag The tag to check.
187            @return Returns true if the input tag is allowed, false if not.
188            */
189            static bool validateTag(const std::string& tag)
190                { LevelInfoItem::initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); }
191
192            static std::set<std::string> possibleTags_s; //!< The set of allowed tags.
193            static const bool initialized_s = false; //!< Whether the set of allowed tags has been inizialized.
194
[7625]195            std::string name_; //!< The name of the Level.
196            std::string description_; //!< The description of the Level.
[9016]197            std::string screenshot_; //!< The screenshot of the Level.
[7625]198            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
199            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
[9269]200            std::set<std::string> ships_; //!< The set of starting ship models the Level allows.
[9272]201            std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection.
[7626]202    }; // tolua_export
[7625]203
204    /**
205    @brief
206        The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file.
207        The following parameters can be specified:
208        - @b name The name of the level.
209        - @b description The description of the level.
[9016]210        - @b screenshot The screenshot of the level.
[9269]211        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>, <em>shipselection</em>.
[9272]212        - @b (optional) startingships The comma-seperated string of starting ship models
[7625]213        An example would be:
214        @code
215        <LevelInfo
[7802]216            name = "Levelname"lhs->compare(rhs) < 0
[7625]217            description = "This is just some awesome level."
[9016]218            screenshot = "Screenshot.png"
[7625]219            tags = "test, awesome"
220        />
221        @endcode
222        The LevelInfo is best located at the top of the level file.
223
224    @author
225        Damian 'Mozork' Frick
[9272]226    @edit
227        Matthias Hutter
[7804]228    @ingroup Orxonox
[7625]229    */
230    class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
231    {
232        public:
233            LevelInfo(BaseObject* creator);
234            virtual ~LevelInfo();
235
236            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
[9272]237
[9016]238            /**
239            @brief Set the screenshot of the Level.
240            @param screenshot The screenshot to be set.
241            */
242            inline void setScreenshot(const std::string& screenshot) { this->LevelInfoItem::setScreenshot(screenshot); }
243            /**
244            @brief Get the screenshot of the Level.
245            @return Returns the screenshot of the Level.
246            */
247            inline const std::string& getScreenshot() const { return this->LevelInfoItem::getScreenshot(); }
[7625]248
249            /**
250            @brief Set the description of the Level.
251            @param description The description to be set.
252            */
253            inline void setDescription(const std::string& description)
254                { this->LevelInfoItem::setDescription(description); }
255            /**
256            @brief Get the description of the Level.
257            @return Returns the description of the Level.
258            */
259            inline const std::string& getDescription() const
260                { return this->LevelInfoItem::getDescription(); }
261
262            /**
263            @brief Set the tags the Level is tagged with.
264            @param tags A comma-seperated string of all the tags to be set.
265            */
266            inline void setTags(const std::string& tags)
267                { this->LevelInfoItem::setTags(tags); }
268            /**
269            @brief Get the lis of the tags the Level is tagged with.
270            @return Returns a comma-seperated string of all the tags the Level is tagged with.
271            */
272            inline const std::string& getTags(void) const
273                { return this->LevelInfoItem::getTags(); }
[9269]274            /**
275            @brief Set the starting ship models of the level
276            @param A comma-seperated string of all the allowed ship models for the shipselection.
277            */
278            inline void setShips(const std::string& ships)
279                { this->LevelInfoItem::setShips(ships); }
280            /**
281            @brief Get the starting ship models of the level
282            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
283            */
284            inline const std::string& getShips(void) const
[9272]285                { return this->LevelInfoItem::getShips(); }
[7625]286            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
287    };
[7802]288
289    /**
290    @brief
291        Struct that overloads the compare operation between two @ref orxonox::LevelInfoItem "LevelInfoItem" pointers.
[7804]292
293    @ingroup Orxonox
[7802]294    */
295    struct LevelInfoCompare
296    {
297        bool operator() (const LevelInfoItem* lhs, const LevelInfoItem* rhs) const
[8079]298            {
299                if(getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) == 0)
300                    return getLowercase(lhs->getXMLFilename()).compare(getLowercase(rhs->getXMLFilename())) < 0;
301                return getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) < 0;
302            }
[7802]303    };
[9272]304
[7626]305} // tolua_export
[7625]306
307#endif /* _LevelInfo_H__ */
Note: See TracBrowser for help on using the repository browser.