Skip to content
This repository
Browse code

Made the elemental and status effects loaded in equipment, and displa…

…yed in the shop mode.

I also renamed the sockets -> shard slots, removed the lore aka long description
which is not used and won't likely be.

I also turned the elemental and status effect std::map into vector
to speed up the display time a bit.

I then added the Paladin Sword in the debug shop to show
the elements and status effects there.
  • Loading branch information...
commit 8756b802329aa7d69ad9942b9988ae2b6174e255 1 parent d62a02c
Yohann Ferreira authored
1  dat/debug/debug_shop.lua
@@ -22,6 +22,7 @@ function BootShopTest()
22 22 shop:AddObject(10001, 2);
23 23 shop:AddObject(10002, 4);
24 24 shop:AddObject(10003, 12);
  25 + shop:AddObject(10004, 1);
25 26 shop:AddObject(11001, 5);
26 27 shop:AddObject(20002, 1);
27 28 shop:AddObject(20003, 2);
20 dat/objects/weapons.lua
@@ -80,6 +80,26 @@ weapons[10003] = {
80 80 slots = 1
81 81 }
82 82
  83 +weapons[10004] = {
  84 + name = hoa_system.Translate("Paladin's Sword"),
  85 + description = hoa_system.Translate("A mythical weapon blessed with a magical fire."),
  86 + icon = "img/icons/weapons/paladin-sword.png",
  87 + physical_attack = 90,
  88 + metaphysical_attack = 30,
  89 + standard_price = 30800,
  90 + usable_by = BRONANN + THANIS,
  91 + slots = 3,
  92 +
  93 + elemental_effects = {
  94 + [hoa_global.GameGlobal.GLOBAL_ELEMENTAL_FIRE] = hoa_global.GameGlobal.GLOBAL_INTENSITY_POS_LESSER
  95 + },
  96 +
  97 + status_effects = {
  98 + [hoa_global.GameGlobal.GLOBAL_STATUS_PROTECTION_RAISE] = hoa_global.GameGlobal.GLOBAL_INTENSITY_POS_LESSER,
  99 + [hoa_global.GameGlobal.GLOBAL_STATUS_VIGOR_RAISE] = hoa_global.GameGlobal.GLOBAL_INTENSITY_POS_LESSER
  100 + }
  101 +}
  102 +
83 103 -- -----------------------------------------------------------------------------
84 104 -- IDs 11,001 - 11,500 are reserved for arbalests
85 105 -- -----------------------------------------------------------------------------
16 src/common/global/global_effects.h
@@ -69,18 +69,18 @@ class GlobalElementalEffect {
69 69 _type(type), _intensity(intensity) {}
70 70
71 71 ~GlobalElementalEffect()
72   - {}
  72 + {}
73 73
74 74 //! \brief Class Member Access Functions
75 75 //@{
76 76 GLOBAL_ELEMENTAL GetType() const
77   - { return _type; }
  77 + { return _type; }
78 78
79 79 GLOBAL_INTENSITY GetIntensity() const
80   - { return _intensity; }
  80 + { return _intensity; }
81 81
82 82 void SetIntensity(GLOBAL_INTENSITY intensity)
83   - { _intensity = intensity; }
  83 + { _intensity = intensity; }
84 84 //@}
85 85
86 86 /** \brief Increments the elemental effect's intensity
@@ -122,18 +122,18 @@ class GlobalStatusEffect {
122 122 _type(type), _intensity(intensity) {}
123 123
124 124 virtual ~GlobalStatusEffect()
125   - {}
  125 + {}
126 126
127 127 //! \brief Class Member Access Functions
128 128 //@{
129 129 GLOBAL_STATUS GetType() const
130   - { return _type; }
  130 + { return _type; }
131 131
132 132 GLOBAL_INTENSITY GetIntensity() const
133   - { return _intensity; }
  133 + { return _intensity; }
134 134
135 135 virtual void SetIntensity(GLOBAL_INTENSITY intensity)
136   - { _intensity = intensity; }
  136 + { _intensity = intensity; }
137 137 //@}
138 138
139 139 /** \brief Increments the status effect intensity by a positive amount
91 src/common/global/global_objects.cpp
@@ -41,6 +41,63 @@ void GlobalObject::_LoadObjectData(hoa_script::ReadScriptDescriptor& script) {
41 41 }
42 42 }
43 43
  44 +void GlobalObject::_LoadElementalEffects(hoa_script::ReadScriptDescriptor& script) {
  45 + if (!script.DoesTableExist("elemental_effects"))
  46 + return;
  47 +
  48 + std::vector<int32> elemental_effects;
  49 + script.ReadTableKeys("elemental_effects", elemental_effects);
  50 +
  51 + if (elemental_effects.empty())
  52 + return;
  53 +
  54 + script.OpenTable("elemental_effects");
  55 +
  56 + for (uint32 i = 0; i < elemental_effects.size(); ++i) {
  57 +
  58 + int32 key = elemental_effects[i];
  59 + if (key <= GLOBAL_ELEMENTAL_INVALID || key >= GLOBAL_ELEMENTAL_TOTAL)
  60 + continue;
  61 +
  62 + int32 intensity = script.ReadInt(key);
  63 + if (intensity <= GLOBAL_INTENSITY_INVALID || intensity >= GLOBAL_INTENSITY_TOTAL)
  64 + continue;
  65 +
  66 + _elemental_effects.push_back(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>((GLOBAL_ELEMENTAL)key, (GLOBAL_INTENSITY)intensity));
  67 + }
  68 +
  69 + script.CloseTable(); // elemental_effects
  70 +}
  71 +
  72 +void GlobalObject::_LoadStatusEffects(hoa_script::ReadScriptDescriptor& script) {
  73 + if (!script.DoesTableExist("status_effects"))
  74 + return;
  75 +
  76 + std::vector<int32> status_effects;
  77 + script.ReadTableKeys("status_effects", status_effects);
  78 +
  79 + if (status_effects.empty())
  80 + return;
  81 +
  82 + script.OpenTable("status_effects");
  83 +
  84 + for (uint32 i = 0; i < status_effects.size(); ++i) {
  85 +
  86 + int32 key = status_effects[i];
  87 + if (key <= GLOBAL_STATUS_INVALID || key >= GLOBAL_STATUS_TOTAL)
  88 + continue;
  89 +
  90 + int32 intensity = script.ReadInt(key);
  91 + // Note: The intensity of a status effect can only be positive
  92 + if (intensity < GLOBAL_INTENSITY_NEUTRAL || intensity >= GLOBAL_INTENSITY_TOTAL)
  93 + continue;
  94 +
  95 + _status_effects.push_back(std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY>((GLOBAL_STATUS)key, (GLOBAL_INTENSITY)intensity));
  96 + }
  97 +
  98 + script.CloseTable(); // status_effects
  99 +}
  100 +
44 101 ////////////////////////////////////////////////////////////////////////////////
45 102 // GlobalItem class
46 103 ////////////////////////////////////////////////////////////////////////////////
@@ -122,16 +179,6 @@ GlobalItem& GlobalItem::operator=(const GlobalItem& copy) {
122 179 GlobalWeapon::GlobalWeapon(uint32 id, uint32 count) :
123 180 GlobalObject(id, count)
124 181 {
125   - // Initialize all elemental effects as neutral
126   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_FIRE, GLOBAL_INTENSITY_NEUTRAL));
127   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_WATER, GLOBAL_INTENSITY_NEUTRAL));
128   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_VOLT, GLOBAL_INTENSITY_NEUTRAL));
129   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_EARTH, GLOBAL_INTENSITY_NEUTRAL));
130   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_SLICING, GLOBAL_INTENSITY_NEUTRAL));
131   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_SMASHING, GLOBAL_INTENSITY_NEUTRAL));
132   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_MAULING, GLOBAL_INTENSITY_NEUTRAL));
133   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_PIERCING, GLOBAL_INTENSITY_NEUTRAL));
134   -
135 182 if ((_id <= MAX_ITEM_ID) || (_id > MAX_WEAPON_ID)) {
136 183 IF_PRINT_WARNING(GLOBAL_DEBUG) << "invalid id in constructor: " << _id << std::endl;
137 184 _InvalidateObject();
@@ -149,10 +196,17 @@ GlobalWeapon::GlobalWeapon(uint32 id, uint32 count) :
149 196 script_file.OpenTable(_id);
150 197 _LoadObjectData(script_file);
151 198
  199 + _LoadElementalEffects(script_file);
  200 + _LoadStatusEffects(script_file);
  201 +
152 202 _physical_attack = script_file.ReadUInt("physical_attack");
153 203 _metaphysical_attack = script_file.ReadUInt("metaphysical_attack");
154 204 _usable_by = script_file.ReadUInt("usable_by");
155 205
  206 + uint32 shards_number = script_file.ReadUInt("slots");
  207 + _shard_slots.resize(shards_number, NULL);
  208 + // TODO: Load equipped shards data
  209 +
156 210 // Load the possible battle ammo animated image filename.
157 211 _ammo_image_file = script_file.ReadString("battle_ammo_animation_file");
158 212
@@ -173,16 +227,6 @@ GlobalWeapon::GlobalWeapon(uint32 id, uint32 count) :
173 227 GlobalArmor::GlobalArmor(uint32 id, uint32 count) :
174 228 GlobalObject(id, count)
175 229 {
176   - // Initialize all elemental effects as neutral
177   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_FIRE, GLOBAL_INTENSITY_NEUTRAL));
178   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_WATER, GLOBAL_INTENSITY_NEUTRAL));
179   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_VOLT, GLOBAL_INTENSITY_NEUTRAL));
180   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_EARTH, GLOBAL_INTENSITY_NEUTRAL));
181   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_SLICING, GLOBAL_INTENSITY_NEUTRAL));
182   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_SMASHING, GLOBAL_INTENSITY_NEUTRAL));
183   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_MAULING, GLOBAL_INTENSITY_NEUTRAL));
184   - _elemental_effects.insert(std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>(GLOBAL_ELEMENTAL_PIERCING, GLOBAL_INTENSITY_NEUTRAL));
185   -
186 230 if ((_id <= MAX_WEAPON_ID) || (_id > MAX_LEG_ARMOR_ID)) {
187 231 IF_PRINT_WARNING(GLOBAL_DEBUG) << "invalid id in constructor: " << _id << std::endl;
188 232 _InvalidateObject();
@@ -220,10 +264,17 @@ GlobalArmor::GlobalArmor(uint32 id, uint32 count) :
220 264 script_file->OpenTable(_id);
221 265 _LoadObjectData(*script_file);
222 266
  267 + _LoadElementalEffects(*script_file);
  268 + _LoadStatusEffects(*script_file);
  269 +
223 270 _physical_defense = script_file->ReadUInt("physical_defense");
224 271 _metaphysical_defense = script_file->ReadUInt("metaphysical_defense");
225 272 _usable_by = script_file->ReadUInt("usable_by");
226 273
  274 + uint32 shards_number = script_file->ReadUInt("slots");
  275 + _shard_slots.resize(shards_number, NULL);
  276 + // TODO: Load equipped shards data
  277 +
227 278 script_file->CloseTable();
228 279 if (script_file->IsErrorDetected()) {
229 280 if (GLOBAL_DEBUG) {
102 src/common/global/global_objects.h
@@ -58,11 +58,11 @@ class GlobalObject {
58 58 _id(id), _count(count), _price(0) {}
59 59
60 60 virtual ~GlobalObject()
61   - {}
  61 + {}
62 62
63 63 //! \brief Returns true if the object is properly initialized and ready to be used
64 64 bool IsValid() const
65   - { return (_id != 0); }
  65 + { return (_id != 0); }
66 66
67 67 /** \brief Purely virtual function used to distinguish between object types
68 68 *** \return A value that represents the type of object
@@ -73,7 +73,7 @@ class GlobalObject {
73 73 *** \param count The count increment value (default value == 1)
74 74 **/
75 75 void IncrementCount(uint32 count = 1)
76   - { _count += count; }
  76 + { _count += count; }
77 77
78 78 /** \brief Decrements the number of objects represented by this class
79 79 *** \param count The count decrement value (default value == 1)
@@ -81,33 +81,36 @@ class GlobalObject {
81 81 *** responsiblity to check if the count becomes zero, and to destroy the object if it is appropriate to do so.
82 82 **/
83 83 void DecrementCount(uint32 count = 1)
84   - { if (count > _count) _count = 0; else _count -= count; }
  84 + { if (count > _count) _count = 0; else _count -= count; }
85 85
86 86 //! \name Class Member Access Functions
87 87 //@{
88 88 uint32 GetID() const
89   - { return _id; }
  89 + { return _id; }
90 90
91 91 const hoa_utils::ustring& GetName() const
92   - { return _name; }
  92 + { return _name; }
93 93
94 94 const hoa_utils::ustring& GetDescription() const
95   - { return _description; }
96   -
97   - const hoa_utils::ustring& GetLore() const
98   - { return _lore; }
  95 + { return _description; }
99 96
100 97 void SetCount(uint32 count)
101   - { _count = count; }
  98 + { _count = count; }
102 99
103 100 uint32 GetCount() const
104   - { return _count; }
  101 + { return _count; }
105 102
106 103 uint32 GetPrice() const
107   - { return _price; }
  104 + { return _price; }
108 105
109 106 const hoa_video::StillImage& GetIconImage() const
110   - { return _icon_image; }
  107 + { return _icon_image; }
  108 +
  109 + const std::vector<std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> >& GetElementalEffects() const
  110 + { return _elemental_effects; }
  111 +
  112 + const std::vector<std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY> >& GetStatusEffects() const
  113 + { return _status_effects; }
111 114 //@}
112 115
113 116 protected:
@@ -122,9 +125,6 @@ class GlobalObject {
122 125 //! \brief A short description of the item to display on the screen
123 126 hoa_utils::ustring _description;
124 127
125   - //! \brief A detailed description of the object's history, culture, and how it fits into the game world
126   - hoa_utils::ustring _lore;
127   -
128 128 //! \brief Retains how many occurences of the object are represented by this class object instance
129 129 uint32 _count;
130 130
@@ -134,19 +134,35 @@ class GlobalObject {
134 134 //! \brief A loaded icon image of the object at its original size of 60x60 pixels
135 135 hoa_video::StillImage _icon_image;
136 136
  137 + /** \brief Container that holds the intensity of each type of elemental effect of the object
  138 + *** Elements with an intensity of GLOBAL_INTENSITY_NEUTRAL indicate no elemental bonus
  139 + **/
  140 + std::vector<std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> > _elemental_effects;
  141 +
  142 + /** \brief Container that holds the intensity of each type of status effect of the object
  143 + *** Effects with an intensity of GLOBAL_INTENSITY_NEUTRAL indicate no status effect bonus
  144 + **/
  145 + std::vector<std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY> > _status_effects;
  146 +
137 147 //! \brief Causes the object to become invalid due to a loading error or other significant issue
138 148 void _InvalidateObject()
139   - { _id = 0; }
  149 + { _id = 0; }
140 150
141 151 /** \brief Reads object data from an open script file
142 152 *** \param script A reference to a script file that has been opened and prepared
143 153 ***
144   - *** This method does not do any of its own error case checking. Only dervied classes may call this
  154 + *** This method does not do any of its own error case checking. Only derived classes may call this
145 155 *** protected function and they are expected to have the script file successfully opened and the correct
146 156 *** table context prepared. This function will do nothing more but read the expected key/values of
147 157 *** the open table in the script file and return.
148 158 **/
149 159 void _LoadObjectData(hoa_script::ReadScriptDescriptor& script);
  160 +
  161 + //! \brief Loads elemental effects data
  162 + void _LoadElementalEffects(hoa_script::ReadScriptDescriptor& script);
  163 +
  164 + //! \brief Loads status effects data
  165 + void _LoadStatusEffects(hoa_script::ReadScriptDescriptor& script);
150 166 }; // class GlobalObject
151 167
152 168
@@ -267,11 +283,8 @@ class GlobalWeapon : public GlobalObject {
267 283 uint32 GetUsableBy() const
268 284 { return _usable_by; }
269 285
270   - const std::vector<GlobalShard*>& GetSockets() const
271   - { return _sockets; }
272   -
273   - const std::map<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>& GetElementalEffects() const
274   - { return _elemental_effects; }
  286 + const std::vector<GlobalShard*>& GetShardSlots() const
  287 + { return _shard_slots; }
275 288
276 289 const std::string& GetAmmoImageFile() const
277 290 { return _ammo_image_file; }
@@ -292,20 +305,12 @@ class GlobalWeapon : public GlobalObject {
292 305 **/
293 306 uint32 _usable_by;
294 307
295   - /** \brief Sockets which may be used to place shards on the weapon
296   - *** Weapons may have no sockets, so it is not uncommon for the size of this vector to be zero.
297   - *** When a socket is available but empty (has no attached shard), the pointer at that index
  308 + /** \brief Shard slots which may be used to place shards on the weapon
  309 + *** Weapons may have no slots, so it is not uncommon for the size of this vector to be zero.
  310 + *** When shard slots are available but empty (has no attached shard), the pointer at that index
298 311 *** will be NULL.
299 312 **/
300   - std::vector<GlobalShard*> _sockets;
301   -
302   - /** \brief Container that holds the intensity of each type of elemental effect of the weapon
303   - *** Elements with an intensity of GLOBAL_INTENSITY_NEUTRAL indicate no elemental bonus
304   - **/
305   - std::map<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> _elemental_effects;
306   -
307   - // TODO: Add status effects to weapons
308   - // std::map<GLOBAL_STATUS, GLOBAL_INTENSITY> _status_effects;
  313 + std::vector<GlobalShard*> _shard_slots;
309 314 }; // class GlobalWeapon : public GlobalObject
310 315
311 316
@@ -330,25 +335,22 @@ class GlobalArmor : public GlobalObject {
330 335 GlobalArmor(uint32 id, uint32 count = 1);
331 336
332 337 ~GlobalArmor()
333   - {}
  338 + {}
334 339
335 340 //! \brief Returns the approriate armor type (head, torso, arm, leg) depending on the object ID
336 341 GLOBAL_OBJECT GetObjectType() const;
337 342
338 343 uint32 GetPhysicalDefense() const
339   - { return _physical_defense; }
  344 + { return _physical_defense; }
340 345
341 346 uint32 GetMetaphysicalDefense() const
342   - { return _metaphysical_defense; }
  347 + { return _metaphysical_defense; }
343 348
344 349 uint32 GetUsableBy() const
345   - { return _usable_by; }
346   -
347   - const std::vector<GlobalShard*>& GetSockets() const
348   - { return _sockets; }
  350 + { return _usable_by; }
349 351
350   - const std::map<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>& GetElementalEffects() const
351   - { return _elemental_effects; }
  352 + const std::vector<GlobalShard*>& GetShardSlots() const
  353 + { return _shard_slots; }
352 354
353 355 private:
354 356 //! \brief The amount of physical defense that the armor provides
@@ -367,15 +369,7 @@ class GlobalArmor : public GlobalObject {
367 369 *** When a socket is available but empty (has no attached shard), the pointer at that index
368 370 *** will be NULL.
369 371 **/
370   - std::vector<GlobalShard*> _sockets;
371   -
372   - /** \brief Container that holds the intensity of each type of elemental effect of the armor
373   - *** Elements with an intensity of GLOBAL_INTENSITY_NEUTRAL indicate no elemental bonus
374   - **/
375   - std::map<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> _elemental_effects;
376   -
377   - // TODO: Add status effects to weapons
378   - // std::map<GLOBAL_STATUS, GLOBAL_INTENSITY> _status_effects;
  372 + std::vector<GlobalShard*> _shard_slots;
379 373 }; // class GlobalArmor : public GlobalObject
380 374
381 375
3  src/modes/battle/battle.cpp
@@ -244,9 +244,10 @@ StillImage* BattleMedia::GetStatusIcon(GLOBAL_STATUS type, GLOBAL_INTENSITY inte
244 244 return NULL;
245 245 }
246 246
  247 + const uint32 IMAGE_ROWS = 5;
247 248 uint32 status_index = status_entry->second;
248 249 uint32 intensity_index = static_cast<uint32>(intensity);
249   - return &(_status_icons[(status_index * 5) + intensity_index]); // TODO: use an appropriate constant instead of the "5" value here
  250 + return &(_status_icons[(status_index * IMAGE_ROWS) + intensity_index]);
250 251 }
251 252
252 253 } // namespace private_battle
216 src/modes/shop/shop.cpp
@@ -76,16 +76,17 @@ ShopMedia::ShopMedia() {
76 76 if (_x_icon.Load("img/menus/red_x.png") == false)
77 77 IF_PRINT_WARNING(SHOP_DEBUG) << "failed to load x icon image" << std::endl;
78 78
79   - if (_socket_icon.Load("img/menus/socket.png") == false)
80   - IF_PRINT_WARNING(SHOP_DEBUG) << "failed to load socket icon image" << std::endl;
  79 + if (!_shard_slot_icon.Load("img/menus/shard_slot.png"))
  80 + IF_PRINT_WARNING(SHOP_DEBUG) << "failed to load shard slot icon image" << std::endl;
81 81
82 82 if (_equip_icon.Load("img/menus/equip.png") == false)
83 83 IF_PRINT_WARNING(SHOP_DEBUG) << "failed to load equip icon image" << std::endl;
84 84
85   - if (ImageDescriptor::LoadMultiImageFromElementGrid(_elemental_icons, "img/icons/effects/elemental.png", 8, 9) == false) {
  85 + if (!ImageDescriptor::LoadMultiImageFromElementGrid(_elemental_icons, "img/icons/effects/elemental.png", 8, 9))
86 86 IF_PRINT_WARNING(SHOP_DEBUG) << "failed to load elemental icon images" << std::endl;
87   - return;
88   - }
  87 +
  88 + if (!ImageDescriptor::LoadMultiImageFromElementSize(_status_icons, "img/icons/effects/status.png", 25, 25))
  89 + PRINT_ERROR << "failed to load status icon images" << std::endl;
89 90
90 91 _sounds["confirm"] = new SoundDescriptor();
91 92 _sounds["cancel"] = new SoundDescriptor();
@@ -116,15 +117,41 @@ ShopMedia::ShopMedia() {
116 117 _all_category_names.push_back(UTranslate("Key Items"));
117 118 _all_category_names.push_back(UTranslate("All Wares"));
118 119
119   - if (ImageDescriptor::LoadMultiImageFromElementGrid(_all_category_icons, "img/icons/object_category_icons.png", 3, 4) == false) {
  120 + if (!ImageDescriptor::LoadMultiImageFromElementGrid(_all_category_icons, "img/icons/object_category_icons.png", 3, 4))
120 121 IF_PRINT_WARNING(SHOP_DEBUG) << "failed to load object category icon images" << std::endl;
121   - return;
122   - }
  122 +
123 123 // The last three images in this multi image are blank, so they are removed
124 124 _all_category_icons.pop_back();
125 125 _all_category_icons.pop_back();
126 126 _all_category_icons.pop_back();
127 127
  128 + // Determine which status effects correspond to which icons and store the result in the _status_indices container
  129 + hoa_script::ReadScriptDescriptor& script_file = GlobalManager->GetStatusEffectsScript();
  130 +
  131 + std::vector<int32> status_types;
  132 + script_file.ReadTableKeys(status_types);
  133 +
  134 + for (uint32 i = 0; i < status_types.size(); ++i) {
  135 + GLOBAL_STATUS status = static_cast<GLOBAL_STATUS>(status_types[i]);
  136 +
  137 + // Check for duplicate entries of the same status effect
  138 + if (_status_indeces.find(status) != _status_indeces.end()) {
  139 + IF_PRINT_WARNING(SHOP_DEBUG) << "duplicate entry found in file " << script_file.GetFilename() <<
  140 + " for status type: " << status_types[i] << std::endl;
  141 + continue;
  142 + }
  143 +
  144 + script_file.OpenTable(status_types[i]);
  145 + if (script_file.DoesIntExist("icon_index") == true) {
  146 + uint32 icon_index = script_file.ReadUInt("icon_index");
  147 + _status_indeces.insert(std::pair<GLOBAL_STATUS, uint32>(status, icon_index));
  148 + }
  149 + else {
  150 + IF_PRINT_WARNING(SHOP_DEBUG) << "no icon_index member was found for status effect: " << status_types[i] << std::endl;
  151 + }
  152 + script_file.CloseTable();
  153 + }
  154 +
128 155 // Initialize the character's prites images.
129 156 _InitializeCharacters();
130 157 }
@@ -309,12 +336,27 @@ StillImage* ShopMedia::GetElementalIcon(GLOBAL_ELEMENTAL element_type, GLOBAL_IN
309 336 return &(_elemental_icons[(row * NUMBER_INTENSTIY_LEVELS) + col]);
310 337 }
311 338
  339 +StillImage* ShopMedia::GetStatusIcon(GLOBAL_STATUS type, GLOBAL_INTENSITY intensity) {
  340 + if ((type <= GLOBAL_STATUS_INVALID) || (type >= GLOBAL_STATUS_TOTAL)) {
  341 + PRINT_WARNING << "type argument was invalid: " << type << std::endl;
  342 + return NULL;
  343 + }
  344 + if ((intensity < GLOBAL_INTENSITY_NEUTRAL) || (intensity >= GLOBAL_INTENSITY_TOTAL)) {
  345 + PRINT_WARNING << "type argument was invalid: " << intensity << std::endl;
  346 + return NULL;
  347 + }
312 348
313   -StillImage* GetStatusIcon(GLOBAL_STATUS status_type, GLOBAL_INTENSITY intensity) {
314   - // TODO: implement this function once status effects are ready
315   - return NULL;
316   -}
  349 + std::map<GLOBAL_STATUS, uint32>::iterator status_entry = _status_indeces.find(type);
  350 + if (status_entry == _status_indeces.end()) {
  351 + PRINT_WARNING << "no entry in the status icon index for status type: " << type << std::endl;
  352 + return NULL;
  353 + }
317 354
  355 + const uint32 IMAGE_ROWS = 5;
  356 + uint32 status_index = status_entry->second;
  357 + uint32 intensity_index = static_cast<uint32>(intensity);
  358 + return &(_status_icons[(status_index * IMAGE_ROWS) + intensity_index]);
  359 +}
318 360
319 361 SoundDescriptor* ShopMedia::GetSound(const std::string& identifier) {
320 362 std::map<std::string, SoundDescriptor*>::iterator sound = _sounds.find(identifier);
@@ -348,14 +390,6 @@ ShopObjectViewer::ShopObjectViewer() :
348 390 _description_text.SetTextAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
349 391 _SetDescriptionText(); // Will set the position and dimensions of _description_text
350 392
351   - _lore_text.SetOwner(ShopMode::CurrentInstance()->GetMiddleWindow());
352   - _lore_text.SetPosition(25.0f, 100.0f);
353   - _lore_text.SetDimensions(760.0f, 80.0f);
354   - _lore_text.SetTextStyle(TextStyle("text20"));
355   - _lore_text.SetDisplayMode(VIDEO_TEXT_INSTANT);
356   - _lore_text.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
357   - _lore_text.SetTextAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
358   -
359 393 _field_use_header.SetStyle(TextStyle("text22"));
360 394 _field_use_header.SetText(UTranslate("Field Use:"));
361 395 _battle_use_header.SetStyle(TextStyle("text22"));
@@ -380,12 +414,7 @@ ShopObjectViewer::ShopObjectViewer() :
380 414
381 415 _phys_rating.SetStyle(TextStyle("text22"));
382 416 _meta_rating.SetStyle(TextStyle("text22"));
383   - _socket_text.SetStyle(TextStyle("text22"));
384   -
385   - // Size elemental and status icon containers to the total number of available elementals/status effects
386   - _elemental_icons.resize(GLOBAL_ELEMENTAL_TOTAL, 0);
387   - // TODO
388   -// _status_icons.resize(GLOBAL_STATUS_TOTAL, StillImage());
  417 + _shard_slot_text.SetStyle(TextStyle("text22"));
389 418 }
390 419
391 420
@@ -395,7 +424,7 @@ void ShopObjectViewer::Initialize() {
395 424
396 425 _check_icon = ShopMode::CurrentInstance()->Media()->GetCheckIcon();
397 426 _x_icon = ShopMode::CurrentInstance()->Media()->GetXIcon();
398   - _socket_icon = ShopMode::CurrentInstance()->Media()->GetSocketIcon();
  427 + _shard_slot_icon = ShopMode::CurrentInstance()->Media()->GetShardSlotIcon();
399 428 _equip_icon = ShopMode::CurrentInstance()->Media()->GetEquipIcon();
400 429
401 430 std::vector<hoa_video::AnimatedImage>* animations = ShopMode::CurrentInstance()->Media()->GetCharacterSprites();
@@ -420,7 +449,6 @@ void ShopObjectViewer::Update() {
420 449 }
421 450
422 451 _description_text.Update();
423   - _lore_text.Update();
424 452 }
425 453
426 454
@@ -467,7 +495,6 @@ void ShopObjectViewer::Draw() {
467 495 // In the info view mode, description text and lore text is always drawn near the bottom of the middle window
468 496 if (_view_mode == SHOP_VIEW_MODE_INFO) {
469 497 _description_text.Draw();
470   - _lore_text.Draw();
471 498 }
472 499 }
473 500
@@ -599,21 +626,19 @@ void ShopObjectViewer::_SetEquipmentData() {
599 626
600 627 // ---------- (2): Determine equipment's rating, socket, elemental effects, and status effects to report
601 628
602   - if (selected_weapon != NULL) {
  629 + if (selected_weapon) {
603 630 _phys_rating.SetText(NumberToString(selected_weapon->GetPhysicalAttack()));
604 631 _meta_rating.SetText(NumberToString(selected_weapon->GetMetaphysicalAttack()));
605   - _socket_text.SetText("x" + NumberToString(selected_weapon->GetSockets().size()));
  632 + _shard_slot_text.SetText("x" + NumberToString(selected_weapon->GetShardSlots().size()));
606 633 _SetElementalIcons(selected_weapon->GetElementalEffects());
607   - // TODO
608   - //_SetStatusIcons(selected_weapon->GetStatusEffects());
  634 + _SetStatusIcons(selected_weapon->GetStatusEffects());
609 635 }
610   - else if (selected_armor != NULL) {
  636 + else if (selected_armor) {
611 637 _phys_rating.SetText(NumberToString(selected_armor->GetPhysicalDefense()));
612 638 _meta_rating.SetText(NumberToString(selected_armor->GetMetaphysicalDefense()));
613   - _socket_text.SetText("x" + NumberToString(selected_armor->GetSockets().size()));
  639 + _shard_slot_text.SetText("x" + NumberToString(selected_armor->GetShardSlots().size()));
614 640 _SetElementalIcons(selected_armor->GetElementalEffects());
615   - // TODO
616   - //_SetStatusIcons(selected_weapon->GetStatusEffects());
  641 + _SetStatusIcons(selected_armor->GetStatusEffects());
617 642 }
618 643
619 644 // ---------- (3): For each character, determine if they already have the selection equipped or determine the change in pricing
@@ -780,58 +805,24 @@ void ShopObjectViewer::_SetChangeText(uint32 index, int32 phys_diff, int32 meta_
780 805 }
781 806 }
782 807
783   -
784   -
785   -void ShopObjectViewer::_SetElementalIcons(const std::map<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>& elemental_effects) {
786   - uint32 index = 0;
787   -
788   - for (std::map<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY>::const_iterator i = elemental_effects.begin(); i != elemental_effects.end(); i++) {
789   - switch (i->first) {
790   - case GLOBAL_ELEMENTAL_FIRE:
791   - index = 0;
792   - break;
793   - case GLOBAL_ELEMENTAL_WATER:
794   - index = 1;
795   - break;
796   - case GLOBAL_ELEMENTAL_VOLT:
797   - index = 2;
798   - break;
799   - case GLOBAL_ELEMENTAL_EARTH:
800   - index = 3;
801   - break;
802   - case GLOBAL_ELEMENTAL_SLICING:
803   - index = 4;
804   - break;
805   - case GLOBAL_ELEMENTAL_SMASHING:
806   - index = 5;
807   - break;
808   - case GLOBAL_ELEMENTAL_MAULING:
809   - index = 6;
810   - break;
811   - case GLOBAL_ELEMENTAL_PIERCING:
812   - index = 7;
813   - break;
814   - default:
815   - IF_PRINT_WARNING(SHOP_DEBUG) << "invalid elemental type: " << i->first << std::endl;
816   - break;
817   - }
818   -
819   - _elemental_icons[index] = ShopMode::CurrentInstance()->Media()->GetElementalIcon(i->first, i->second);
820   - if (i->second == GLOBAL_INTENSITY_NEUTRAL) {
821   - _elemental_icons[index]->EnableGrayScale();
822   - }
  808 +void ShopObjectViewer::_SetElementalIcons(const std::vector<std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> >& elemental_effects) {
  809 + _elemental_icons.clear();
  810 + for (std::vector<std::pair<GLOBAL_ELEMENTAL, GLOBAL_INTENSITY> >::const_iterator it = elemental_effects.begin();
  811 + it != elemental_effects.end(); ++it) {
  812 + if (it->second != GLOBAL_INTENSITY_NEUTRAL)
  813 + _elemental_icons.push_back(ShopMode::CurrentInstance()->Media()->GetElementalIcon(it->first, it->second));
823 814 }
824 815 }
825 816
826   -
827   -
828   -void ShopObjectViewer::_SetStatusIcons(const std::map<GLOBAL_STATUS, GLOBAL_INTENSITY>& status_effects) {
829   - // TODO: Implement this method when status effects are available.
830   - // It should work very much the same way as _SetElementalIcons()
  817 +void ShopObjectViewer::_SetStatusIcons(const std::vector<std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY> >& status_effects) {
  818 + _status_icons.clear();
  819 + for (std::vector<std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY> >::const_iterator it = status_effects.begin();
  820 + it != status_effects.end(); ++it) {
  821 + if (it->second != GLOBAL_INTENSITY_NEUTRAL)
  822 + _status_icons.push_back(ShopMode::CurrentInstance()->Media()->GetStatusIcon(it->first, it->second));
  823 + }
831 824 }
832 825
833   -
834   -
835 826 void ShopObjectViewer::_DrawItem() {
836 827 float move_offset = 0.0f; // Used to save image widths in determining relative movement
837 828 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_CENTER, 0);
@@ -879,43 +870,54 @@ void ShopObjectViewer::_DrawEquipment() {
879 870 VideoManager->MoveRelative(90.0f, 30.0f);
880 871 _phys_rating.Draw();
881 872 VideoManager->MoveRelative(0.0f, -30.0f);
882   - _meta_rating.Draw();
  873 + _meta_rating.Draw();
883 874
884 875 VideoManager->SetDrawFlags(VIDEO_X_LEFT, 0);
885 876 VideoManager->MoveRelative(20.0f, 15.0f);
886   - _socket_icon->Draw();
887   - VideoManager->MoveRelative(20.0f, 0.0f);
888   - _socket_text.Draw();
  877 + _shard_slot_icon->Draw();
  878 + VideoManager->MoveRelative(30.0f, 0.0f);
  879 + _shard_slot_text.Draw();
889 880
890 881 VideoManager->SetDrawFlags(VIDEO_X_CENTER, 0);
891   - VideoManager->MoveRelative(50.0f, 55.0f);
892   - for (uint32 i = 0; i < GLOBAL_ELEMENTAL_TOTAL / 2; ++i) {
  882 + VideoManager->MoveRelative(40.0f, 55.0f);
  883 +
  884 + // Draw up to two columns of 4 elemental effects icons
  885 + uint32 element_size = _elemental_icons.size();
  886 + for (uint32 i = 0; i < 4 && i < element_size; ++i) {
893 887 _elemental_icons[i]->Draw();
894 888 VideoManager->MoveRelative(0.0f, -25.0f);
895 889 }
896   - VideoManager->MoveRelative(40.0f, 100.0f);
897   - for (uint32 i = GLOBAL_ELEMENTAL_TOTAL / 2; i < GLOBAL_ELEMENTAL_TOTAL; i++) {
898   - _elemental_icons[i]->Draw();
899   - VideoManager->MoveRelative(0.0f, -25.0f);
  890 + VideoManager->MoveRelative(40.0f, 25.0f * (element_size > 4 ? 4 : element_size));
  891 +
  892 + // Draw a second column when there are many elemental effects.
  893 + if (element_size > 4) {
  894 + for (uint32 i = 4; i < 8 && i < element_size; ++i) {
  895 + _elemental_icons[i]->Draw();
  896 + VideoManager->MoveRelative(0.0f, -25.0f);
  897 + }
  898 +
  899 + VideoManager->MoveRelative(40.0f, 25.0f * (element_size > 8 ? 8 : element_size - 4));
900 900 }
901 901
902   - // TODO: Draw two columns of status icons
903   - VideoManager->MoveRelative(80.0f, 0.0f); // TEMP: remove once commented code block below is added
904   -// VideoManager->MoveRelative(40.0f, 100.0f);
905   -// for (uint32 i = 0; i < 4; i++) {
906   -// _status_icons[i].Draw();
907   -// VideoManager->MoveRelative(0.0f, -25.0f);
908   -// }
909   -// VideoManager->MoveRelative(40.0f, 100.0f);
910   -// for (uint32 i = 4; i < 8; i++) {
911   -// _status_icons[i].Draw();
912   -// VideoManager->MoveRelative(0.0f, -25.0f);
913   -// }
  902 + // Draw up to two columns of 4 status effects icons
  903 + element_size = _status_icons.size();
  904 + for (uint32 i = 0; i < 4 && i < element_size; ++i) {
  905 + _status_icons[i]->Draw();
  906 + VideoManager->MoveRelative(0.0f, -25.0f);
  907 + }
  908 + VideoManager->MoveRelative(40.0f, 25.0f * (element_size > 4 ? 4 : element_size));
  909 + if (element_size > 4) {
  910 + for (uint32 i = 4; i < 8 && i < element_size; ++i) {
  911 + _status_icons[i]->Draw();
  912 + VideoManager->MoveRelative(0.0f, -25.0f);
  913 + }
  914 + VideoManager->MoveRelative(40.0f, 25.0f * (element_size > 8 ? 8 : element_size - 4));
  915 + }
914 916
915 917 VideoManager->SetDrawFlags(VIDEO_Y_TOP, 0);
916 918 if (_view_mode == SHOP_VIEW_MODE_LIST) {
917 919 // In list view mode, draw the sprites to the right of the icons
918   - VideoManager->MoveRelative(60.0f, 115.0f);
  920 + VideoManager->MoveRelative(60.0f, 15.0f);
919 921 }
920 922 else { // (_view_mode == SHOP_VIEW_MODE_INFO)
921 923 // In info view mode, draw the spites centered on the screen in a row below the other equipment data
29 src/modes/shop/shop.h
@@ -74,8 +74,8 @@ class ShopMedia {
74 74 hoa_video::StillImage* GetXIcon()
75 75 { return &_x_icon; }
76 76
77   - hoa_video::StillImage* GetSocketIcon()
78   - { return &_socket_icon; }
  77 + hoa_video::StillImage* GetShardSlotIcon()
  78 + { return &_shard_slot_icon; }
79 79
80 80 hoa_video::StillImage* GetEquipIcon()
81 81 { return &_equip_icon; }
@@ -124,6 +124,12 @@ class ShopMedia {
124 124 hoa_audio::SoundDescriptor* GetSound(const std::string& identifier);
125 125
126 126 private:
  127 + /** \brief Container used to find the appropriate row index for each status type
  128 + *** Status icons for all types of status are all contained within a single image. This container is used to
  129 + *** quickly determine which row of icons in that image corresponds to each status type.
  130 + **/
  131 + std::map<hoa_global::GLOBAL_STATUS, uint32> _status_indeces;
  132 +
127 133 //! \brief Retains text names for all possible object categories, including "all wares"
128 134 std::vector<hoa_utils::ustring> _all_category_names;
129 135
@@ -142,8 +148,8 @@ class ShopMedia {
142 148 //! \brief Image icon of a red x
143 149 hoa_video::StillImage _x_icon;
144 150
145   - //! \brief Image icon representing open sockets available on weapons and armor
146   - hoa_video::StillImage _socket_icon;
  151 + //! \brief Image icon representing open shard slots available on weapons and armors
  152 + hoa_video::StillImage _shard_slot_icon;
147 153
148 154 //! \brief Image icon that represents when a character has a weapon or armor equipped
149 155 hoa_video::StillImage _equip_icon;
@@ -238,9 +244,6 @@ class ShopObjectViewer {
238 244
239 245 //! \brief A summary description of the object to display
240 246 hoa_gui::TextBox _description_text;
241   -
242   - //! \brief A more detailed "lore" description about the object's origins and connections with the world
243   - hoa_gui::TextBox _lore_text;
244 247 //@}
245 248
246 249 //! \name Data used only for item object types
@@ -270,11 +273,11 @@ class ShopObjectViewer {
270 273 //! \brief A rendering of the physical and metaphysical attack/defense ratings
271 274 hoa_video::TextImage _phys_rating, _meta_rating;
272 275
273   - //! \brief An icon image of a shard socket
274   - hoa_video::StillImage* _socket_icon;
  276 + //! \brief An icon image of a shard slot
  277 + hoa_video::StillImage* _shard_slot_icon;
275 278
276   - //! \brief Text indicating how many sockets the selected equipment has available
277   - hoa_video::TextImage _socket_text;
  279 + //! \brief Text indicating how many shards the selected equipment can support
  280 + hoa_video::TextImage _shard_slot_text;
278 281
279 282 //! \brief Icon images representing elemental effects and intensity properties of the selected object
280 283 std::vector<hoa_video::StillImage*> _elemental_icons;
@@ -330,7 +333,7 @@ class ShopObjectViewer {
330 333 *** The format of the parameter comes from the global object code, as object classes return a const std::map reference
331 334 *** of this type to indicate their elemental effects.
332 335 **/
333   - void _SetElementalIcons(const std::map<hoa_global::GLOBAL_ELEMENTAL, hoa_global::GLOBAL_INTENSITY>& elemental_effects);
  336 + void _SetElementalIcons(const std::vector<std::pair<hoa_global::GLOBAL_ELEMENTAL, hoa_global::GLOBAL_INTENSITY> >& elemental_effects);
334 337
335 338 /** \brief Sets all statusicons to the proper image when given a container
336 339 *** \param status_effects A const reference to a map of status effect types and their associated intensities
@@ -339,7 +342,7 @@ class ShopObjectViewer {
339 342 *** The format of the parameter comes from the global object code, as object classes return a const std::map reference
340 343 *** of this type to indicate their status effects.
341 344 **/
342   - void _SetStatusIcons(const std::map<hoa_global::GLOBAL_STATUS, hoa_global::GLOBAL_INTENSITY>& status_effects);
  345 + void _SetStatusIcons(const std::vector<std::pair<hoa_global::GLOBAL_STATUS, hoa_global::GLOBAL_INTENSITY> >& status_effects);
343 346
344 347 //! \brief Helper function that draws information specific to items
345 348 void _DrawItem();

0 comments on commit 8756b80

Please sign in to comment.
Something went wrong with that request. Please try again.