1 /* 2 * This file is part of Dune Legacy. 3 * 4 * Dune Legacy is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * Dune Legacy is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with Dune Legacy. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef OBJECTDATA_H 19 #define OBJECTDATA_H 20 21 #include <string> 22 23 #include <misc/InputStream.h> 24 #include <misc/OutputStream.h> 25 #include <fixmath/FixPoint.h> 26 #include <data.h> 27 #include <DataTypes.h> 28 29 #include <bitset> 30 31 class INIFile; 32 33 /// This class stores all the unit/structure data 34 class ObjectData { 35 public: 36 /** 37 Default constructur. Initializes everything with zero 38 */ 39 ObjectData(); 40 41 /** 42 Destructor. 43 */ 44 virtual ~ObjectData(); 45 46 /** 47 This method loads all data from an INI-File specified by filename. There should be two sections 48 in the INI-File for default values: "default structure" and "default unit". The other sections are 49 for exactly one unit. 50 Example:<br> 51 [structure name]<br> 52 Enabled = true<br> 53 HitPoints = 500<br> 54 Price = 300<br> 55 Power = 10<br> 56 ViewRange = 3<br> 57 Capacity = 1000<br> 58 BuildTime = 80<br> 59 InfSpawnProp = 45<br> 60 <br> 61 [unit name] 62 Enabled = true<br> 63 HitPoints = 100<br> 64 Price = 100<br> 65 ViewRange = 5<br> 66 WeaponDamage = 10<br> 67 WeaponRange = 4<br> 68 WeaponReloadTime = 100<br> 69 Speed = 3.0<br> 70 TurnSpeed = 0.25<br> 71 BuildTime = 56<br> 72 InfSpawnProp = 45<br> 73 \param filename the INI-File to load. 74 */ 75 void loadFromINIFile(const std::string& filename); 76 77 /** 78 Saves all stored data out into a binary stream. 79 \param stream the stream to save to 80 \see load 81 */ 82 void save(OutputStream& stream) const; 83 84 /** 85 Loads all stored data from a stream. 86 \param stream the stream to load from 87 \see save 88 */ 89 void load(InputStream& stream); 90 91 struct ObjectDataStruct { 92 bool enabled; ///< is this unit/structure available? 93 Sint32 hitpoints; ///< what is the maximum health of this unit/structure? 94 Sint32 price; ///< how much does this structure cost? 95 Sint32 power; ///< how much power do this structure require. Wind traps have negative values because they produce power? 96 Sint32 viewrange; ///< much terrain is revealed when this structure is placed or this unit moves? 97 Sint32 capacity; ///< how much spice can this structure contain? 98 Sint32 weapondamage; ///< how much damage does the weapon of this unit/structure have? 99 Sint32 weaponrange; ///< how far can this unit/structure shoot? 100 Sint32 weaponreloadtime; ///< how many frames does it take to reload the weapon? 101 FixPoint maxspeed; ///< how fast can this unit move? 102 FixPoint turnspeed; ///< how fast can this unit turn around? 103 Sint32 buildtime; ///< how much time does the production of this structure/unit take? 104 Sint32 infspawnprop; ///< what is the probability (in percent) that a infantry soldier is spawn on destruction? 105 int builder; ///< In which building can this item be built 106 std::bitset<Structure_LastID> prerequisiteStructuresSet; ///< What buildings are prerequisite for building this item 107 Sint8 techLevel; ///< What techLevel is needed to build this item (in campaign mode this equals to mission number) 108 Sint8 upgradeLevel; ///< How many upgrades must the builder already have made 109 }; 110 111 ObjectDataStruct data[Num_ItemID][NUM_HOUSES]; ///< here is all the data stored. It is public for easy and fast access. Use only read-only. 112 113 private: 114 115 int loadIntValue(const INIFile& objectDataFile, const std::string& section, const std::string& key, char houseChar, int defaultValue = 0); 116 bool loadBoolValue(const INIFile& objectDataFile, const std::string& section, const std::string& key, char houseChar, bool defaultValue = false); 117 FixPoint loadFixPointValue(const INIFile& objectDataFile, const std::string& section, const std::string& key, char houseChar, FixPoint defaultValue = 0); 118 std::string loadStringValue(const INIFile& objectDataFile, const std::string& section, const std::string& key, char houseChar, const std::string& defaultValue = ""); 119 int loadItemID(const INIFile& objectDataFile, const std::string& section, const std::string& key, char houseChar, int defaultValue = ItemID_Invalid); 120 std::bitset<Structure_LastID> loadPrerequisiteStructuresSet(const INIFile& objectDataFile, const std::string& section, const std::string& key, char houseChar, std::bitset<Structure_LastID> defaultValue = std::bitset<Structure_LastID>()); 121 }; 122 123 #endif // OBJECTDATA_H 124