Skip to content

Commit

Permalink
Misc sanity checks in equipment data loading.
Browse files Browse the repository at this point in the history
- Items without icons aren't invalidated anymore.
- Items will be capped to a max of 5 shards.
(Note that the shards data will only be loaded for equipped items.)
- The loader will check for opposite status effects.
  • Loading branch information
Yohann Ferreira committed Mar 29, 2013
1 parent e804bcb commit d146afa
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/common/global/global_objects.cpp
Expand Up @@ -41,9 +41,11 @@ void GlobalObject::_LoadObjectData(hoa_script::ReadScriptDescriptor &script)
std::string icon_file = script.ReadString("icon");
if (script.DoesBoolExist("key_item"))
_is_key_item = script.ReadBool("key_item");
if(_icon_image.Load(icon_file) == false) {
IF_PRINT_WARNING(GLOBAL_DEBUG) << "failed to load icon image for item: " << _id << std::endl;
_InvalidateObject();
if(!_icon_image.Load(icon_file)) {
PRINT_WARNING << "failed to load icon image for item: " << _id << std::endl;

// try a default icon in that case
_icon_image.Load("img/icons/battle/default_special.png");
}
}

Expand Down Expand Up @@ -100,6 +102,21 @@ void GlobalObject::_LoadStatusEffects(hoa_script::ReadScriptDescriptor &script)
if(intensity < GLOBAL_INTENSITY_NEUTRAL || intensity >= GLOBAL_INTENSITY_TOTAL)
continue;

// Check whether an opposite effect exists.
bool effect_replaced = false;
for (uint32 j = 0; j < _status_effects.size(); ++j) {
GLOBAL_STATUS opposite_effect = GetOppositeStatusEffect((GLOBAL_STATUS) key);
if (_status_effects[j].first != opposite_effect)
continue;

PRINT_WARNING << "The item (id:" << _id << ") has opposing passive status effects." << std::endl;
effect_replaced = true;
break;
}

if (effect_replaced)
continue;

_status_effects.push_back(std::pair<GLOBAL_STATUS, GLOBAL_INTENSITY>((GLOBAL_STATUS)key, (GLOBAL_INTENSITY)intensity));
}

Expand Down Expand Up @@ -240,8 +257,12 @@ GlobalWeapon::GlobalWeapon(uint32 id, uint32 count) :
_usable_by = script_file.ReadUInt("usable_by");

uint32 shards_number = script_file.ReadUInt("slots");
// Only permit a max of 5 shards for equipment
if (shards_number > 5) {
shards_number = 5;
PRINT_WARNING << "More than 5 shards declared in item " << _id << std::endl;
}
_shard_slots.resize(shards_number, NULL);
// TODO: Load equipped shards data

// Load the possible battle ammo animated image filename.
_ammo_image_file = script_file.ReadString("battle_ammo_animation_file");
Expand Down Expand Up @@ -364,8 +385,12 @@ GlobalArmor::GlobalArmor(uint32 id, uint32 count) :
_usable_by = script_file->ReadUInt("usable_by");

uint32 shards_number = script_file->ReadUInt("slots");
// Only permit a max of 5 shards for equipment
if (shards_number > 5) {
shards_number = 5;
PRINT_WARNING << "More than 5 shards declared in item " << _id << std::endl;
}
_shard_slots.resize(shards_number, NULL);
// TODO: Load equipped shards data

script_file->CloseTable();
if(script_file->IsErrorDetected()) {
Expand Down
48 changes: 48 additions & 0 deletions src/common/global/global_utils.cpp
Expand Up @@ -193,6 +193,54 @@ bool DecrementIntensity(GLOBAL_INTENSITY &intensity, uint8 amount)
return true;
}

GLOBAL_STATUS GetOppositeStatusEffect(GLOBAL_STATUS status_effect)
{
switch (status_effect) {
default:
return GLOBAL_STATUS_INVALID;

case GLOBAL_STATUS_STRENGTH_RAISE:
return GLOBAL_STATUS_STRENGTH_LOWER;
case GLOBAL_STATUS_STRENGTH_LOWER:
return GLOBAL_STATUS_STRENGTH_RAISE;

case GLOBAL_STATUS_VIGOR_RAISE:
return GLOBAL_STATUS_VIGOR_LOWER;
case GLOBAL_STATUS_VIGOR_LOWER:
return GLOBAL_STATUS_VIGOR_RAISE;

case GLOBAL_STATUS_FORTITUDE_RAISE:
return GLOBAL_STATUS_FORTITUDE_LOWER;
case GLOBAL_STATUS_FORTITUDE_LOWER:
return GLOBAL_STATUS_FORTITUDE_RAISE;

case GLOBAL_STATUS_PROTECTION_RAISE:
return GLOBAL_STATUS_PROTECTION_LOWER;
case GLOBAL_STATUS_PROTECTION_LOWER:
return GLOBAL_STATUS_PROTECTION_RAISE;

case GLOBAL_STATUS_AGILITY_RAISE:
return GLOBAL_STATUS_AGILITY_LOWER;
case GLOBAL_STATUS_AGILITY_LOWER:
return GLOBAL_STATUS_AGILITY_RAISE;

case GLOBAL_STATUS_EVADE_RAISE:
return GLOBAL_STATUS_EVADE_LOWER;
case GLOBAL_STATUS_EVADE_LOWER:
return GLOBAL_STATUS_EVADE_RAISE;

case GLOBAL_STATUS_HP_REGEN:
return GLOBAL_STATUS_HP_DRAIN;
case GLOBAL_STATUS_HP_DRAIN:
return GLOBAL_STATUS_HP_REGEN;

case GLOBAL_STATUS_SP_REGEN:
return GLOBAL_STATUS_SP_DRAIN;
case GLOBAL_STATUS_SP_DRAIN:
return GLOBAL_STATUS_SP_REGEN;
}
}

// GlobalMedia functions

void GlobalMedia::Initialize()
Expand Down
3 changes: 3 additions & 0 deletions src/common/global/global_utils.h
Expand Up @@ -293,6 +293,9 @@ bool IncrementIntensity(GLOBAL_INTENSITY &intensity, uint8 amount = 1);
**/
bool DecrementIntensity(GLOBAL_INTENSITY &intensity, uint8 amount = 1);

//! Give the opposite status effect if there is one of GLOBAL_STATUS_INVALID if none.
GLOBAL_STATUS GetOppositeStatusEffect(GLOBAL_STATUS status_effect);

/** \brief A simple class used to store commonly used media files.
*** It is used as a member of the game global class.
**/
Expand Down

0 comments on commit d146afa

Please sign in to comment.