1 /* 2 * Copyright (C) 2011-2016 OpenDungeons Team 3 * 4 * This program 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 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef CREATUREDEFINITION_H 19 #define CREATUREDEFINITION_H 20 21 #include <OgreVector3.h> 22 23 #include <string> 24 #include <iosfwd> 25 #include <cstdint> 26 27 class CreatureBehaviour; 28 class CreatureMood; 29 class CreatureSkill; 30 class ODPacket; 31 32 enum class RoomType; 33 34 //! \brief The maximum level of a creature 35 static const uint32_t MAX_LEVEL = 30; 36 37 class CreatureRoomAffinity 38 { 39 public: CreatureRoomAffinity(RoomType roomType,int32_t likeness,double efficiency)40 CreatureRoomAffinity(RoomType roomType, int32_t likeness, double efficiency): 41 mRoomType(roomType), 42 mLikeness(likeness), 43 mEfficiency(efficiency) 44 { 45 } 46 getRoomType()47 inline RoomType getRoomType() const 48 { return mRoomType; } 49 getLikeness()50 inline int32_t getLikeness() const 51 { return mLikeness; } 52 getEfficiency()53 inline double getEfficiency() const 54 { return mEfficiency; } 55 56 bool operator==(const CreatureRoomAffinity& creatureRoomAffinity) const 57 { 58 return mRoomType == creatureRoomAffinity.mRoomType && 59 mLikeness == creatureRoomAffinity.mLikeness && 60 mEfficiency == creatureRoomAffinity.mEfficiency; 61 } 62 63 private: 64 RoomType mRoomType; 65 int32_t mLikeness; 66 double mEfficiency; 67 }; 68 69 class CreatureDefinition 70 { 71 public: 72 enum CreatureJob 73 { 74 Worker = 1, // Dig, claim tile and deposit gold. Only fights workers 75 Fighter, // Sleep, eat, train and fight any enemy thing. 76 }; 77 78 CreatureDefinition( 79 const std::string& className = std::string(), 80 CreatureJob job = Fighter, 81 const std::string& meshName = std::string(), 82 const std::string& bedMeshName = std::string(), 83 int bedDim1 = 1, 84 int bedDim2 = 1, 85 int bedPosX = 1, 86 int bedPosY = 1, 87 double bedOrientX = 0, 88 double bedOrientY = -1, 89 double sightRadius = 15.0, 90 91 int maxGoldCarryable = 0, 92 double digRate = 10.0, 93 double digRatePerLevel = 2.1, 94 double claimRate = 0.35, 95 double claimRatePerLevel = 0.06, 96 97 double minHP = 1.0, 98 double hpPerLevel = 5.0, 99 double hpHealPerTurn = 0.1, 100 101 double wakefulnessLostPerTurn = 0.1, 102 double hungerGrowthPerTurn = 0.1, 103 104 double moveSpeedGround = 1.0, 105 double moveSpeedWater = 0.0, 106 double moveSpeedLava = 0.0, 107 double groundSpeedPerLevel = 0.02, 108 double waterSpeedPerLevel = 0.0, 109 double lavaSpeedPerLevel = 0.0, 110 111 double physicalDefense = 3.0, 112 double physicalDefPerLevel = 0.2, 113 double magicalDefense = 1.5, 114 double magicalDefPerLevel = 0.1, 115 double elementDefense = 1.5, 116 double elementDefPerLevel = 0.1, 117 int32_t fightIdleDist = 1, 118 int32_t feeBase = 0, 119 int32_t feePerLevel = 0, 120 int32_t sleepHeal = 1.0, 121 int32_t turnsStunDropped = 0); 122 123 CreatureDefinition(const CreatureDefinition& def); 124 125 virtual ~CreatureDefinition(); 126 127 static CreatureJob creatureJobFromString(const std::string& s); 128 static std::string creatureJobToString(CreatureJob c); 129 //! \brief Writes the differences between def1 and def2 in the given file. Note that def1 can be null. In 130 //! this case, every parameters in def2 will be written. def2 cannot be null. 131 static void writeCreatureDefinitionDiff( 132 const CreatureDefinition* def1, const CreatureDefinition* def2, std::ostream& file, const std::map<std::string, CreatureDefinition*>& defMap); 133 isWorker()134 inline bool isWorker() const 135 { return (mCreatureJob == Worker); } 136 137 friend ODPacket& operator <<(ODPacket& os, const CreatureDefinition *c); 138 friend ODPacket& operator >>(ODPacket& is, CreatureDefinition *c); 139 140 //! \brief Loads a definition from the creature definition file sub [Creature][/Creature] part 141 //! \returns A creature definition if valid, nullptr otherwise. 142 static CreatureDefinition* load(std::stringstream& defFile, const std::map<std::string, CreatureDefinition*>& defMap); 143 static bool update(CreatureDefinition* creatureDef, std::stringstream& defFile, const std::map<std::string, CreatureDefinition*>& defMap); 144 getCreatureJob()145 inline CreatureJob getCreatureJob () const { return mCreatureJob; } getClassName()146 inline const std::string& getClassName () const { return mClassName; } 147 getMeshName()148 inline const std::string& getMeshName () const { return mMeshName; } 149 getBedMeshName()150 inline const std::string& getBedMeshName () const { return mBedMeshName; } getBedDim1()151 inline int getBedDim1 () const { return mBedDim1; } getBedDim2()152 inline int getBedDim2 () const { return mBedDim2; } getBedPosX()153 inline int getBedPosX () const { return mBedPosX; } getBedPosY()154 inline int getBedPosY () const { return mBedPosY; } getBedOrientX()155 inline double getBedOrientX () const { return mBedOrientX; } getBedOrientY()156 inline double getBedOrientY () const { return mBedOrientY; } 157 getSightRadius()158 inline int getSightRadius () const { return mSightRadius; } 159 getClaimRate()160 inline double getClaimRate () const { return mClaimRate; } getClaimRatePerLevel()161 inline double getClaimRatePerLevel() const{ return mClaimRatePerLevel; } getMaxGoldCarryable()162 inline int getMaxGoldCarryable () const { return mMaxGoldCarryable; } getDigRate()163 inline double getDigRate () const { return mDigRate; } getDigRatePerLevel()164 inline double getDigRatePerLevel() const { return mDigRatePerLevel; } 165 getMinHp()166 inline double getMinHp () const { return mMinHP; } getHpPerLevel()167 inline double getHpPerLevel () const { return mHpPerLevel; } getHpHealPerTurn()168 inline double getHpHealPerTurn() const { return mHpHealPerTurn; } 169 getWakefulnessLostPerTurn()170 inline double getWakefulnessLostPerTurn() const{ return mWakefulnessLostPerTurn; } getHungerGrowthPerTurn()171 inline double getHungerGrowthPerTurn() const { return mHungerGrowthPerTurn; } 172 getMoveSpeedGround()173 inline double getMoveSpeedGround () const { return mMoveSpeedGround; } getMoveSpeedWater()174 inline double getMoveSpeedWater () const { return mMoveSpeedWater; } getMoveSpeedLava()175 inline double getMoveSpeedLava () const { return mMoveSpeedLava; } 176 getGroundSpeedPerLevel()177 inline double getGroundSpeedPerLevel() const { return mGroundSpeedPerLevel; } getWaterSpeedPerLevel()178 inline double getWaterSpeedPerLevel () const { return mWaterSpeedPerLevel; } getLavaSpeedPerLevel()179 inline double getLavaSpeedPerLevel () const { return mLavaSpeedPerLevel; } 180 getPhysicalDefense()181 inline double getPhysicalDefense() const { return mPhysicalDefense; } getPhysicalDefPerLevel()182 inline double getPhysicalDefPerLevel () const { return mPhysicalDefPerLevel; } getMagicalDefense()183 inline double getMagicalDefense () const { return mMagicalDefense; } getMagicalDefPerLevel()184 inline double getMagicalDefPerLevel () const { return mMagicalDefPerLevel; } getElementDefense()185 inline double getElementDefense () const { return mElementDefense; } getElementDefPerLevel()186 inline double getElementDefPerLevel () const { return mElementDefPerLevel; } 187 getFightIdleDist()188 inline int32_t getFightIdleDist() const { return mFightIdleDist; } 189 getWeaponSpawnL()190 inline const std::string& getWeaponSpawnL () const { return mWeaponSpawnL; } getWeaponSpawnR()191 inline const std::string& getWeaponSpawnR () const { return mWeaponSpawnR; } 192 193 int32_t getFee (unsigned int level) const; 194 getSleepHeal()195 inline double getSleepHeal () const { return mSleepHeal; } 196 getTurnsStunDropped()197 inline int32_t getTurnsStunDropped () const { return mTurnsStunDropped; } 198 199 double getXPNeededWhenLevel(unsigned int level) const; 200 201 //! \brief Returns the creature affinity. The returned vector is assumed to be 202 //! sorted so that highest likeness is at first getRoomAffinity()203 inline const std::vector<CreatureRoomAffinity>& getRoomAffinity() const 204 { return mRoomAffinity; } 205 getCreatureSkills()206 inline const std::vector<const CreatureSkill*>& getCreatureSkills() const 207 { return mCreatureSkills; } 208 getCreatureBehaviours()209 inline const std::vector<const CreatureBehaviour*>& getCreatureBehaviours() const 210 { return mCreatureBehaviours; } 211 getCreatureMoods()212 inline const std::vector<const CreatureMood*>& getCreatureMoods() const 213 { return mCreatureMoods; } 214 215 const CreatureRoomAffinity& getRoomAffinity(RoomType roomType) const; 216 getMoodModifierName()217 inline const std::string& getMoodModifierName() const 218 { return mMoodModifierName; } 219 getSoundFamilyPickup()220 inline const std::string& getSoundFamilyPickup() const 221 { return mSoundFamilyPickup; } getSoundFamilyDrop()222 inline const std::string& getSoundFamilyDrop() const 223 { return mSoundFamilyDrop; } getSoundFamilyAttack()224 inline const std::string& getSoundFamilyAttack() const 225 { return mSoundFamilyAttack; } getSoundFamilyDie()226 inline const std::string& getSoundFamilyDie() const 227 { return mSoundFamilyDie; } getSoundFamilySlap()228 inline const std::string& getSoundFamilySlap() const 229 { return mSoundFamilySlap; } 230 231 private: 232 //! \brief The job of the creature (e.g. worker, fighter, ...) 233 CreatureJob mCreatureJob; 234 235 //! \brief The name of the creatures class 236 std::string mClassName; 237 238 //! \brief The name of the creature definition this one is based on (can be empty if no base class) 239 std::string mBaseDefinition; 240 241 //! \brief The name of the model file 242 std::string mMeshName; 243 244 //! \brief The name of the bed model file 245 std::string mBedMeshName; 246 247 //! \brief size of the bed (x) 248 int mBedDim1; 249 250 //! \brief size of the bed (y) 251 int mBedDim2; 252 253 //! \brief Position and orientation of the creature when it goes to sleep 254 int mBedPosX; 255 int mBedPosY; 256 double mBedOrientX; 257 double mBedOrientY; 258 259 //! \brief The inner radius where the creature sees everything 260 int mSightRadius; 261 262 //! \brief Maximum gold amount a worker can carry before having to deposit it into a treasury 263 int mMaxGoldCarryable; 264 265 //! \brief Fullness removed per turn of digging 266 double mDigRate; 267 268 //! \brief How much dig rate is earned at each level up. 269 double mDigRatePerLevel; 270 271 //! \brief How quick a worker can claim a ground or wall tile. 272 double mClaimRate; 273 274 //! \brief How much claim rate is earned at each level up. 275 double mClaimRatePerLevel; 276 277 //! \brief The minimum HP the creature can ever have 278 double mMinHP; 279 280 //! \brief How much HP the creature gets per level up 281 double mHpPerLevel; 282 283 //! \brief How much HP are healed per turn. 284 double mHpHealPerTurn; 285 286 //! \brief How much wakefulness is lost per turn. 287 double mWakefulnessLostPerTurn; 288 289 //! \brief How fast hunger grows per turn. 290 double mHungerGrowthPerTurn; 291 292 //! \brief How fast the creature moves (0 -> The creature cannot go through corresponding tile) 293 double mMoveSpeedGround; 294 double mMoveSpeedWater; 295 double mMoveSpeedLava; 296 297 //! \brief how much speed is earn per level on each tile type. 298 double mGroundSpeedPerLevel; 299 double mWaterSpeedPerLevel; 300 double mLavaSpeedPerLevel; 301 302 //! \brief Defense stats (without equipment) 303 double mPhysicalDefense; 304 double mPhysicalDefPerLevel; 305 double mMagicalDefense; 306 double mMagicalDefPerLevel; 307 double mElementDefense; 308 double mElementDefPerLevel; 309 310 //! \brief Distance from the nearest enemy creature that the creature will try to let when no skill can be used 311 int32_t mFightIdleDist; 312 313 //! \brief The base fee for this creature. 314 int32_t mFeeBase; 315 int32_t mFeePerLevel; 316 317 //! \brief How many HP the creature will get per turn while sleeping 318 double mSleepHeal; 319 320 //! \brief Number of turns the creature will stay stunned after being dropped 321 int32_t mTurnsStunDropped; 322 323 //! \brief Weapons a creature should spawn with ("none" if no weapon) 324 std::string mWeaponSpawnL; 325 std::string mWeaponSpawnR; 326 327 //! \brief The XP table, used to know how XP is needed to reach the next level. 328 //! \note The creature starting at level 1, it can only change its level MAX_LEVEL - 1 times. 329 std::vector<double> mXPTable; 330 331 //! \brief Skills the creature can use 332 std::vector<const CreatureSkill*> mCreatureSkills; 333 334 //! \brief Creature specific behaviours 335 std::vector<const CreatureBehaviour*> mCreatureBehaviours; 336 337 //! \brief Creature specific mood modifiers 338 std::vector<const CreatureMood*> mCreatureMoods; 339 340 //! \brief The rooms the creature should choose according to availability 341 std::vector<CreatureRoomAffinity> mRoomAffinity; 342 343 //! \brief The rooms the creature mood modifier that should be used to compute 344 //! creature mood 345 std::string mMoodModifierName; 346 347 //! \brief Sound family used by the creature 348 std::string mSoundFamilyPickup; 349 std::string mSoundFamilyDrop; 350 std::string mSoundFamilyAttack; 351 std::string mSoundFamilyDie; 352 std::string mSoundFamilySlap; 353 354 //! \brief Loads the creature XP values for the given definition. 355 static void loadXPTable(std::stringstream& defFile, CreatureDefinition* creatureDef); 356 357 //! \brief Loads the creature skills for the given definition. 358 static void loadCreatureSkills(std::stringstream& defFile, CreatureDefinition* creatureDef); 359 360 //! \brief Loads the creature specific behaviours for the given definition. 361 static void loadCreatureBehaviours(std::stringstream& defFile, CreatureDefinition* creatureDef); 362 363 //! \brief Loads the creature specific mood modifiers for the given definition. 364 static void loadCreatureMoods(std::stringstream& defFile, CreatureDefinition* creatureDef); 365 366 //! \brief Loads the creature room affinity for the given definition. 367 static void loadRoomAffinity(std::stringstream& defFile, CreatureDefinition* creatureDef); 368 }; 369 370 #endif // CREATUREDEFINITION_H 371