Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup MP2 format and Maps::Tiles class #6940

Merged
merged 7 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/fheroes2/ai/ai_hero_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,14 @@ namespace

if ( tile.isWater() ) {
if ( gold ) {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( art.isValid() && !hero.PickupArtifact( art ) )
gold = GoldInsteadArtifact( objectType );
}
}
else {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( gold ) {
const uint32_t experience = gold > 500 ? gold - 500 : 500;
Expand Down Expand Up @@ -630,7 +630,7 @@ namespace
else {
// The army should include only the original monsters
const uint32_t monstersLeft = army.getTotalCount();
assert( monstersLeft == army.GetCountMonsters( tile.QuantityMonster() ) );
assert( monstersLeft == army.GetCountMonsters( getMonsterFromTile( tile ) ) );

Troop & troop = world.GetCapturedObject( dstIndex ).GetTroop();
troop.SetCount( monstersLeft );
Expand Down Expand Up @@ -679,7 +679,7 @@ namespace

// artifact
if ( tile.QuantityIsValid() ) {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( !hero.PickupArtifact( art ) ) {
uint32_t gold = GoldInsteadArtifact( objectType );
Expand All @@ -699,7 +699,7 @@ namespace
Maps::Tiles & tile = world.GetTiles( dst_index );

if ( tile.QuantityIsValid() ) {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( art.isValid() )
hero.PickupArtifact( art );
Expand Down Expand Up @@ -931,7 +931,7 @@ namespace

void AIToShrine( Heroes & hero, int32_t dst_index )
{
const Spell & spell = world.GetTiles( dst_index ).QuantitySpell();
const Spell & spell = getSpellFromTile( world.GetTiles( dst_index ) );
const uint32_t spell_level = spell.Level();

if ( spell.isValid() &&
Expand Down Expand Up @@ -1088,7 +1088,7 @@ namespace
if ( res.AttackerWins() ) {
hero.IncreaseExperience( res.GetExperienceAttacker() );
complete = true;
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( art.isValid() && !hero.PickupArtifact( art ) )
gold = GoldInsteadArtifact( objectType );
Expand All @@ -1114,7 +1114,7 @@ namespace
void AIToPyramid( Heroes & hero, int32_t dst_index )
{
Maps::Tiles & tile = world.GetTiles( dst_index );
const Spell & spell = tile.QuantitySpell();
const Spell & spell = getSpellFromTile( tile );

if ( spell.isValid() ) {
// battle
Expand Down Expand Up @@ -1374,7 +1374,7 @@ namespace
if ( hero.IsFullBagArtifacts() )
hero.GetKingdom().AddFundsResource( Funds( Resource::GOLD, GoldInsteadArtifact( objectType ) ) );
else
hero.PickupArtifact( tile.QuantityArtifact() );
hero.PickupArtifact( getArtifactFromTile( tile ) );

tile.RemoveObjectSprite();
tile.QuantityReset();
Expand All @@ -1388,7 +1388,7 @@ namespace

if ( !hero.IsFullBagArtifacts() ) {
uint32_t cond = tile.QuantityVariant();
Artifact art = tile.QuantityArtifact();
Artifact art = getArtifactFromTile( tile );

bool result = false;

Expand Down
20 changes: 10 additions & 10 deletions src/fheroes2/ai/normal/ai_normal_hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace

// WINS_ARTIFACT victory condition does not apply to AI-controlled players, we should leave this artifact untouched for the human player
if ( MP2::isArtifactObject( objectType ) ) {
const Artifact art = tile.QuantityArtifact();
const Artifact art = getArtifactFromTile( tile );

if ( art.isValid() && isFindArtifactVictoryConditionForHuman( art ) ) {
return false;
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace
case MP2::OBJ_SHRINE_FIRST_CIRCLE:
case MP2::OBJ_SHRINE_SECOND_CIRCLE:
case MP2::OBJ_SHRINE_THIRD_CIRCLE: {
const Spell & spell = tile.QuantitySpell();
const Spell & spell = getSpellFromTile( tile );
if ( !spell.isValid() ) {
// The spell cannot be invalid!
assert( 0 );
Expand Down Expand Up @@ -890,7 +890,7 @@ namespace AI
return 3000.0;
}
case MP2::OBJ_ARTIFACT: {
const Artifact art = tile.QuantityArtifact();
const Artifact art = getArtifactFromTile( tile );
assert( art.isValid() );

// WINS_ARTIFACT victory condition does not apply to AI-controlled players, we should leave this artifact untouched for the human player
Expand All @@ -905,8 +905,8 @@ namespace AI
case MP2::OBJ_TREASURE_CHEST: {
// TODO: add logic if the object contains an artifact and resources.

if ( tile.QuantityArtifact().isValid() ) {
const Artifact art = tile.QuantityArtifact();
if ( getArtifactFromTile( tile ).isValid() ) {
const Artifact art = getArtifactFromTile( tile );

// WINS_ARTIFACT victory condition does not apply to AI-controlled players, we should leave this artifact untouched for the human player
if ( isFindArtifactVictoryConditionForHuman( art ) ) {
Expand All @@ -925,12 +925,12 @@ namespace AI
case MP2::OBJ_SHIPWRECK:
case MP2::OBJ_SKELETON:
case MP2::OBJ_WAGON: {
if ( !tile.QuantityArtifact().isValid() ) {
if ( !getArtifactFromTile( tile ).isValid() ) {
// Don't waste time to go here.
return -dangerousTaskPenalty;
}

const Artifact art = tile.QuantityArtifact();
const Artifact art = getArtifactFromTile( tile );

// WINS_ARTIFACT victory condition does not apply to AI-controlled players, we should leave this artifact untouched for the human player
if ( isFindArtifactVictoryConditionForHuman( art ) ) {
Expand Down Expand Up @@ -964,7 +964,7 @@ namespace AI
case MP2::OBJ_SHRINE_FIRST_CIRCLE:
case MP2::OBJ_SHRINE_SECOND_CIRCLE:
case MP2::OBJ_SHRINE_THIRD_CIRCLE: {
const Spell & spell = tile.QuantitySpell();
const Spell & spell = getSpellFromTile( tile );
return spell.getStrategicValue( hero.GetArmy().GetStrength(), hero.GetMaxSpellPoints(), hero.GetPower() );
}
case MP2::OBJ_ARENA:
Expand Down Expand Up @@ -1305,7 +1305,7 @@ namespace AI
return 5000.0;
}
case MP2::OBJ_ARTIFACT: {
const Artifact art = tile.QuantityArtifact();
const Artifact art = getArtifactFromTile( tile );
assert( art.isValid() );

// WINS_ARTIFACT victory condition does not apply to AI-controlled players, we should leave this artifact untouched for the human player
Expand Down Expand Up @@ -1336,7 +1336,7 @@ namespace AI
case MP2::OBJ_SHRINE_FIRST_CIRCLE:
case MP2::OBJ_SHRINE_SECOND_CIRCLE:
case MP2::OBJ_SHRINE_THIRD_CIRCLE: {
const Spell & spell = tile.QuantitySpell();
const Spell & spell = getSpellFromTile( tile );
return spell.getStrategicValue( hero.GetArmy().GetStrength(), hero.GetMaxSpellPoints(), hero.GetPower() ) * 1.1;
}
case MP2::OBJ_ARENA:
Expand Down
6 changes: 3 additions & 3 deletions src/fheroes2/dialog/dialog_giftresources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ void Dialog::MakeGiftResource( Kingdom & kingdom )
EventDate event;

event.resource = funds2;
event.computer = true;
event.first = world.CountDay() + 1;
event.subsequent = 0;
event.isApplicableForAIPlayers = true;
event.firstOccurrenceDay = world.CountDay() + 1;
event.repeatPeriodInDays = 0;
event.colors = selector.recipients;
event.message = _( "Gift from %{name}" );
const Player * player = Players::Get( kingdom.GetColor() );
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ namespace
std::string str = MP2::StringObject( objectType );

if ( isVisited ) {
const Spell & spell = tile.QuantitySpell();
const Spell & spell = getSpellFromTile( tile );

str.append( "\n(" );
str.append( spell.GetName() );
Expand Down
24 changes: 12 additions & 12 deletions src/fheroes2/heroes/heroes_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ namespace
hero.GetKingdom().AddFundsResource( funds );
}
else {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );
message += '\n';
message.append( _( "Searching through the tattered clothing, you find the %{artifact}." ) );
StringReplace( message, "%{artifact}", art.GetName() );
Expand Down Expand Up @@ -810,7 +810,7 @@ namespace
const std::string title( MP2::StringObject( MP2::OBJ_WAGON ) );

if ( tile.QuantityIsValid() ) {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( art.isValid() ) {
if ( hero.IsFullBagArtifacts() ) {
Expand Down Expand Up @@ -891,7 +891,7 @@ namespace

void ActionToShrine( Heroes & hero, int32_t dst_index )
{
const Spell & spell = world.GetTiles( dst_index ).QuantitySpell();
const Spell & spell = getSpellFromTile( world.GetTiles( dst_index ) );
const uint32_t spell_level = spell.Level();

std::string head;
Expand Down Expand Up @@ -1055,7 +1055,7 @@ namespace
void ActionToPyramid( Heroes & hero, const MP2::MapObjectType objectType, int32_t dst_index )
{
Maps::Tiles & tile = world.GetTiles( dst_index );
const Spell & spell = tile.QuantitySpell();
const Spell & spell = getSpellFromTile( tile );

const std::string ask = _(
"You come upon the pyramid of a great and ancient king.\nYou are tempted to search it for treasure, but all the old stories warn of fearful curses and undead "
Expand Down Expand Up @@ -1295,7 +1295,7 @@ namespace

complete = true;

const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );
if ( art.isValid() ) {
if ( hero.IsFullBagArtifacts() ) {
gold = GoldInsteadArtifact( objectType );
Expand Down Expand Up @@ -1481,7 +1481,7 @@ namespace
hero.GetKingdom().AddFundsResource( Funds( Resource::GOLD, gold ) );
}
else {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );
std::string str = _(
"You've pulled a shipwreck survivor from certain death in an unforgiving ocean. Grateful, he rewards you for your act of kindness by giving you the %{art}." );
StringReplace( str, "%{art}", art.GetName() );
Expand Down Expand Up @@ -1514,7 +1514,7 @@ namespace
Dialog::Message( title, _( "You cannot pick up this artifact, you already have a full load!" ), Font::BIG, Dialog::OK );
else {
uint32_t cond = tile.QuantityVariant();
Artifact art = tile.QuantityArtifact();
Artifact art = getArtifactFromTile( tile );

bool result = false;
std::string msg;
Expand Down Expand Up @@ -1696,7 +1696,7 @@ namespace
// dialog
if ( tile.isWater() ) {
if ( gold ) {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( art.isValid() ) {
if ( hero.IsFullBagArtifacts() ) {
Expand Down Expand Up @@ -1738,7 +1738,7 @@ namespace
}
}
else {
const Artifact & art = tile.QuantityArtifact();
const Artifact & art = getArtifactFromTile( tile );

if ( gold ) {
const uint32_t expr = gold > 500 ? gold - 500 : 500;
Expand Down Expand Up @@ -2036,7 +2036,7 @@ namespace
else {
// The army should include only the original monsters
const uint32_t monstersLeft = army.getTotalCount();
assert( monstersLeft == army.GetCountMonsters( tile.QuantityMonster() ) );
assert( monstersLeft == army.GetCountMonsters( getMonsterFromTile( tile ) ) );

Troop & troop = world.GetCapturedObject( dstIndex ).GetTroop();
troop.SetCount( monstersLeft );
Expand Down Expand Up @@ -2899,7 +2899,7 @@ namespace
return Outcome::ExperienceAndGold;
}
case 3: {
const Artifact art = tile.QuantityArtifact();
const Artifact art = getArtifactFromTile( tile );
if ( !art.isValid() ) {
return Outcome::Invalid;
}
Expand Down Expand Up @@ -2990,7 +2990,7 @@ namespace
break;
}
case Outcome::ExperienceAndArtifact: {
const Artifact art = tile.QuantityArtifact();
const Artifact art = getArtifactFromTile( tile );

hero.IncreaseExperience( demonSlayingExperience );
hero.PickupArtifact( art );
Expand Down
Loading