Skip to content

Commit

Permalink
Remove unnecessary emptiness check.
Browse files Browse the repository at this point in the history
There is a check for whether the array has more entries. That one will catch empty array.
  • Loading branch information
BevapDin committed Dec 18, 2019
1 parent b396d12 commit d098134
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,20 +1826,18 @@ void monster::load( const JsonObject &data )
// sp_timeout indicates an old save, prior to the special_attacks refactor
if( data.has_array( "sp_timeout" ) ) {
JsonArray parray = data.get_array( "sp_timeout" );
if( !parray.empty() ) {
int index = 0;
int ptimeout = 0;
while( parray.has_more() && index < static_cast<int>( type->special_attacks_names.size() ) ) {
if( parray.read_next( ptimeout ) ) {
// assume timeouts saved in same order as current monsters.json listing
const std::string &aname = type->special_attacks_names[index++];
auto &entry = special_attacks[aname];
if( ptimeout >= 0 ) {
entry.cooldown = ptimeout;
} else { // -1 means disabled, unclear what <-1 values mean in old saves
entry.cooldown = type->special_attacks.at( aname )->cooldown;
entry.enabled = false;
}
int index = 0;
int ptimeout = 0;
while( parray.has_more() && index < static_cast<int>( type->special_attacks_names.size() ) ) {
if( parray.read_next( ptimeout ) ) {
// assume timeouts saved in same order as current monsters.json listing
const std::string &aname = type->special_attacks_names[index++];
auto &entry = special_attacks[aname];
if( ptimeout >= 0 ) {
entry.cooldown = ptimeout;
} else { // -1 means disabled, unclear what <-1 values mean in old saves
entry.cooldown = type->special_attacks.at( aname )->cooldown;
entry.enabled = false;
}
}
}
Expand Down

0 comments on commit d098134

Please sign in to comment.