1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef ULTIMA4_GAME_WEAPON_H 24 #define ULTIMA4_GAME_WEAPON_H 25 26 #include "ultima/ultima4/filesys/savegame.h" 27 #include "ultima/shared/std/containers.h" 28 29 namespace Ultima { 30 namespace Ultima4 { 31 32 class ConfigElement; 33 class Weapons; 34 35 class Weapon { 36 friend class Weapons; 37 public: 38 /**< Flags affecting weapon's behavior. @see Weapon::flags */ 39 enum Flags { 40 WEAP_LOSE = 0x0001, /**< lost when used */ 41 WEAP_LOSEWHENRANGED = 0x0002, /**< lost when used for ranged attack */ 42 WEAP_CHOOSEDISTANCE = 0x0004, /**< allows player to choose attack distance */ 43 WEAP_ALWAYSHITS = 0x0008, /**< always hits it's target */ 44 WEAP_MAGIC = 0x0010, /**< is magical */ 45 WEAP_ATTACKTHROUGHOBJECTS = 0x0040, /**< can attack through solid objects */ 46 WEAP_ABSOLUTERANGE = 0x0080, /**< range is absolute (only works at specific distance) */ 47 WEAP_RETURNS = 0x0100, /**< returns to user after used/thrown */ 48 WEAP_DONTSHOWTRAVEL = 0x0200 /**< do not show animations when attacking */ 49 }; 50 51 public: getType()52 WeaponType getType() const { 53 return _type; 54 } getName()55 const Common::String &getName() const { 56 return _name; 57 } getAbbrev()58 const Common::String &getAbbrev() const { 59 return _abbr; 60 } canReady(ClassType klass)61 bool canReady(ClassType klass) const { 62 return (_canUse & (1 << klass)) != 0; 63 } getRange()64 int getRange() const { 65 return _range; 66 } getDamage()67 int getDamage() const { 68 return _damage; 69 } getHitTile()70 const Common::String &getHitTile() const { 71 return _hitTile; 72 } getMissTile()73 const Common::String &getMissTile() const { 74 return _missTile; 75 } leavesTile()76 const Common::String &leavesTile() const { 77 return _leaveTile; 78 } getFlags()79 unsigned short getFlags() const { 80 return _flags; 81 } 82 loseWhenUsed()83 bool loseWhenUsed() const { 84 return _flags & WEAP_LOSE; 85 } loseWhenRanged()86 bool loseWhenRanged() const { 87 return _flags & WEAP_LOSEWHENRANGED; 88 } canChooseDistance()89 bool canChooseDistance() const { 90 return _flags & WEAP_CHOOSEDISTANCE; 91 } alwaysHits()92 bool alwaysHits() const { 93 return _flags & WEAP_ALWAYSHITS; 94 } isMagic()95 bool isMagic() const { 96 return _flags & WEAP_MAGIC; 97 } canAttackThroughObjects()98 bool canAttackThroughObjects() const { 99 return _flags & WEAP_ATTACKTHROUGHOBJECTS; 100 } rangeAbsolute()101 bool rangeAbsolute() const { 102 return _flags & WEAP_ABSOLUTERANGE; 103 } returns()104 bool returns() const { 105 return _flags & WEAP_RETURNS; 106 } showTravel()107 bool showTravel() const { 108 return !(_flags & WEAP_DONTSHOWTRAVEL); 109 } 110 111 private: 112 Weapon(WeaponType weaponType, const ConfigElement &conf); 113 114 WeaponType _type; 115 Common::String _name; 116 Common::String _abbr; /**< abbreviation for the weapon */ 117 byte _canUse; /**< bitmask of classes that can use weapon */ 118 int _range; /**< range of weapon */ 119 int _damage; /**< damage of weapon */ 120 Common::String _hitTile; /**< tile to display a hit */ 121 Common::String _missTile; /**< tile to display a miss */ 122 Common::String _leaveTile; /**< if the weapon leaves a tile, the tile #, zero otherwise */ 123 unsigned short _flags; 124 }; 125 126 class Weapons : public Common::Array<Weapon *> { 127 private: 128 bool _confLoaded; 129 130 void loadConf(); 131 public: 132 /** 133 * Constructor 134 */ 135 Weapons(); 136 137 /** 138 * Destructor 139 */ 140 ~Weapons(); 141 142 /** 143 * Returns weapon by WeaponType. 144 */ 145 const Weapon *get(WeaponType w); 146 147 /** 148 * Returns weapon that has the given name 149 */ 150 const Weapon *get(const Common::String &name); 151 }; 152 153 extern Weapons *g_weapons; 154 155 } // End of namespace Ultima4 156 } // End of namespace Ultima 157 158 #endif 159