1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

vcmi: massive refactoring v1

This commit is contained in:
Konstantin
2023-04-05 03:26:29 +03:00
parent ee489f18d2
commit 11b237a23c
129 changed files with 803 additions and 762 deletions

View File

@ -1643,11 +1643,11 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa
if (clear)
{
ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = std::max((ui32)1, (VLC->creh->objects.at(creatureId)->growth)/2);
ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = std::max(1, (VLC->creh->objects.at(creatureId)->getGrowth())/2);
}
else
{
ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = VLC->creh->objects.at(creatureId)->growth;
ssi.creatures[GameConstants::CREATURES_PER_TOWN].first = VLC->creh->objects.at(creatureId)->getGrowth();
}
ssi.creatures[GameConstants::CREATURES_PER_TOWN].second.push_back(creatureId);
sendAndApply(&ssi);
@ -1732,7 +1732,7 @@ void CGameHandler::newTurn()
{
newMonster.second = VLC->creh->pickRandomMonster(getRandomGenerator());
} while (VLC->creh->objects[newMonster.second] &&
(*VLC->townh)[(*VLC->creh)[newMonster.second]->faction]->town == nullptr); // find first non neutral creature
(*VLC->townh)[VLC->creatures()->getById(newMonster.second)->getFactionIndex()]->town == nullptr); // find first non neutral creature
n.creatureid = newMonster.second;
}
}
@ -1767,7 +1767,7 @@ void CGameHandler::newTurn()
else if (elem.first >= PlayerColor::PLAYER_LIMIT)
assert(0); //illegal player number!
std::pair<PlayerColor, si32> playerGold(elem.first, elem.second.resources[Res::GOLD]);
std::pair<PlayerColor, si32> playerGold(elem.first, elem.second.resources[EGameResID::GOLD]);
hadGold.insert(playerGold);
if (newWeek) //new heroes in tavern
@ -1826,7 +1826,7 @@ void CGameHandler::newTurn()
}
}
if(hasCrystalGenCreature)
n.res[elem.first][Res::CRYSTAL] += 3;
n.res[elem.first][EGameResID::CRYSTAL] += 3;
}
for (CGHeroInstance *h : (elem).second.heroes)
@ -1863,7 +1863,7 @@ void CGameHandler::newTurn()
if (!firstTurn)
if (t->hasBuilt(BuildingSubID::TREASURY) && player < PlayerColor::PLAYER_LIMIT)
n.res[player][Res::GOLD] += hadGold.at(player)/10; //give 10% of starting gold
n.res[player][EGameResID::GOLD] += hadGold.at(player)/10; //give 10% of starting gold
if (!vstd::contains(n.cres, t->id))
{
@ -1884,7 +1884,7 @@ void CGameHandler::newTurn()
else
{
if (firstTurn) //first day of game: use only basic growths
availableCount = cre->growth;
availableCount = cre->getGrowth();
else
availableCount += t->creatureGrowth(k);
@ -1892,7 +1892,7 @@ void CGameHandler::newTurn()
if (n.specialWeek == NewTurn::DEITYOFFIRE && vstd::contains(t->creatures.at(k).second, n.creatureid))
availableCount += 15;
if (cre->idNumber == n.creatureid) //bonus week, effect applies only to identical creatures
if (cre->getId() == n.creatureid) //bonus week, effect applies only to identical creatures
{
if (n.specialWeek == NewTurn::DOUBLE_GROWTH)
availableCount *= 2;
@ -2495,7 +2495,7 @@ void CGameHandler::showTeleportDialog(TeleportDialog *iw)
sendToAllClients(iw);
}
void CGameHandler::giveResource(PlayerColor player, Res::ERes which, int val) //TODO: cap according to Bersy's suggestion
void CGameHandler::giveResource(PlayerColor player, GameResID which, int val) //TODO: cap according to Bersy's suggestion
{
if (!val) return; //don't waste time on empty call
@ -3452,8 +3452,8 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
ssi.tid = t->id;
ssi.creatures = t->creatures;
if (ssi.creatures[level].second.empty()) // first creature in a dwelling
ssi.creatures[level].first = crea->growth;
ssi.creatures[level].second.push_back(crea->idNumber);
ssi.creatures[level].first = crea->getGrowth();
ssi.creatures[level].second.push_back(crea->getId());
sendAndApply(&ssi);
}
if(t->town->buildings.at(buildingID)->subId == BuildingSubID::PORTAL_OF_SUMMONING)
@ -3630,7 +3630,7 @@ bool CGameHandler::recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst
}
//recruit
giveResources(dst->tempOwner, -(c->cost * cram));
giveResources(dst->tempOwner, -(c->getFullRecruitCost() * cram));
SetAvailableCreatures sac;
sac.tid = objid;
@ -3702,7 +3702,7 @@ bool CGameHandler::changeStackType(const StackLocation &sl, const CCreature *c)
SetStackType sst;
sst.army = sl.army->id;
sst.slot = sl.slot;
sst.type = c->idNumber;
sst.type = c->getId();
sendAndApply(&sst);
return true;
}
@ -4044,12 +4044,12 @@ bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
if (aid==ArtifactID::SPELLBOOK)
{
if ((!town->hasBuilt(BuildingID::MAGES_GUILD_1) && complain("Cannot buy a spellbook, no mage guild in the town!"))
|| (getResource(hero->getOwner(), Res::GOLD) < GameConstants::SPELLBOOK_GOLD_COST && complain("Cannot buy a spellbook, not enough gold!"))
|| (getResource(hero->getOwner(), EGameResID::GOLD) < GameConstants::SPELLBOOK_GOLD_COST && complain("Cannot buy a spellbook, not enough gold!"))
|| (hero->getArt(ArtifactPosition::SPELLBOOK) && complain("Cannot buy a spellbook, hero already has a one!"))
)
return false;
giveResource(hero->getOwner(),Res::GOLD,-GameConstants::SPELLBOOK_GOLD_COST);
giveResource(hero->getOwner(),EGameResID::GOLD,-GameConstants::SPELLBOOK_GOLD_COST);
giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
assert(hero->getArt(ArtifactPosition::SPELLBOOK));
giveSpells(town,hero);
@ -4062,12 +4062,12 @@ bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
COMPLAIN_RET_FALSE_IF(art->warMachine == CreatureID::NONE, "War machine artifact required");
COMPLAIN_RET_FALSE_IF(hero->hasArt(aid),"Hero already has this machine!");
const int price = art->price;
COMPLAIN_RET_FALSE_IF(getPlayerState(hero->getOwner())->resources[Res::GOLD] < price, "Not enough gold!");
COMPLAIN_RET_FALSE_IF(getPlayerState(hero->getOwner())->resources[EGameResID::GOLD] < price, "Not enough gold!");
if ((town->hasBuilt(BuildingID::BLACKSMITH) && town->town->warMachine == aid)
|| (town->hasBuilt(BuildingSubID::BALLISTA_YARD) && aid == ArtifactID::BALLISTA))
{
giveResource(hero->getOwner(),Res::GOLD,-price);
giveResource(hero->getOwner(),EGameResID::GOLD,-price);
return giveHeroNewArtifact(hero, art);
}
else
@ -4075,7 +4075,7 @@ bool CGameHandler::buyArtifact(ObjectInstanceID hid, ArtifactID aid)
}
}
bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, Res::ERes rid, ArtifactID aid)
bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, GameResID rid, ArtifactID aid)
{
if(!h)
COMPLAIN_RET("Only hero can buy artifacts!");
@ -4124,7 +4124,7 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, Res::E
return true;
}
bool CGameHandler::sellArtifact(const IMarket *m, const CGHeroInstance *h, ArtifactInstanceID aid, Res::ERes rid)
bool CGameHandler::sellArtifact(const IMarket *m, const CGHeroInstance *h, ArtifactInstanceID aid, GameResID rid)
{
COMPLAIN_RET_FALSE_IF((!h), "Only hero can sell artifacts!");
const CArtifactInstance *art = h->getArtByInstanceId(aid);
@ -4156,10 +4156,10 @@ bool CGameHandler::buySecSkill(const IMarket *m, const CGHeroInstance *h, Second
if (!vstd::contains(m->availableItemsIds(EMarketMode::RESOURCE_SKILL), skill))
COMPLAIN_RET("That skill is unavailable!");
if (getResource(h->tempOwner, Res::GOLD) < GameConstants::SKILL_GOLD_COST)//TODO: remove hardcoded resource\summ?
if (getResource(h->tempOwner, EGameResID::GOLD) < GameConstants::SKILL_GOLD_COST)//TODO: remove hardcoded resource\summ?
COMPLAIN_RET("You can't afford to buy this skill");
giveResource(h->tempOwner, Res::GOLD, -GameConstants::SKILL_GOLD_COST);
giveResource(h->tempOwner, EGameResID::GOLD, -GameConstants::SKILL_GOLD_COST);
changeSecSkill(h, skill, 1, true);
return true;
@ -4180,13 +4180,13 @@ bool CGameHandler::tradeResources(const IMarket *market, ui32 val, PlayerColor p
COMPLAIN_RET("Invalid deal, not all offered units of resource were used.");
}
giveResource(player, static_cast<Res::ERes>(id1), - b1 * units);
giveResource(player, static_cast<Res::ERes>(id2), b2 * units);
giveResource(player, GameResID(id1), - b1 * units);
giveResource(player, GameResID(id2), b2 * units);
return true;
}
bool CGameHandler::sellCreatures(ui32 count, const IMarket *market, const CGHeroInstance * hero, SlotID slot, Res::ERes resourceID)
bool CGameHandler::sellCreatures(ui32 count, const IMarket *market, const CGHeroInstance * hero, SlotID slot, GameResID resourceID)
{
if(!hero)
COMPLAIN_RET("Only hero can sell creatures!");
@ -4202,7 +4202,7 @@ bool CGameHandler::sellCreatures(ui32 count, const IMarket *market, const CGHero
}
int b1, b2; //base quantities for trade
market->getOffer(s.type->idNumber, resourceID, b1, b2, EMarketMode::CREATURE_RESOURCE);
market->getOffer(s.type->getId(), resourceID, b1, b2, EMarketMode::CREATURE_RESOURCE);
int units = count / b1; //how many base quantities we trade
if (count%b1) //all offered units of resource should be used, if not -> somewhere in calculations must be an error
@ -4246,7 +4246,7 @@ bool CGameHandler::transformInUndead(const IMarket *market, const CGHeroInstance
return true;
}
bool CGameHandler::sendResources(ui32 val, PlayerColor player, Res::ERes r1, PlayerColor r2)
bool CGameHandler::sendResources(ui32 val, PlayerColor player, GameResID r1, PlayerColor r2)
{
const PlayerState *p2 = getPlayerState(r2, false);
if (!p2 || p2->status != EPlayerStatus::INGAME)
@ -4288,9 +4288,9 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl
const CGTownInstance * t = getTown(obj->id);
//common preconditions
// if ((p->resources.at(Res::GOLD)<GOLD_NEEDED && complain("Not enough gold for buying hero!"))
// if ((p->resources.at(EGameResID::GOLD)<GOLD_NEEDED && complain("Not enough gold for buying hero!"))
// || (getHeroCount(player, false) >= GameConstants::MAX_HEROES_PER_PLAYER && complain("Cannot hire hero, only 8 wandering heroes are allowed!")))
if ((p->resources[Res::GOLD] < GameConstants::HERO_GOLD_COST && complain("Not enough gold for buying hero!"))
if ((p->resources[EGameResID::GOLD] < GameConstants::HERO_GOLD_COST && complain("Not enough gold for buying hero!"))
|| ((getHeroCount(player, false) >= VLC->settings()->getInteger(EGameSettings::HEROES_PER_PLAYER_ON_MAP_CAP) && complain("Cannot hire hero, too many wandering heroes already!")))
|| ((getHeroCount(player, true) >= VLC->settings()->getInteger(EGameSettings::HEROES_PER_PLAYER_TOTAL_CAP) && complain("Cannot hire hero, too many heroes garrizoned and wandering already!"))))
{
@ -4353,7 +4353,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl
sah.hid[!hid] = theOtherHero ? theOtherHero->subID : -1;
sendAndApply(&sah);
giveResource(player, Res::GOLD, -GameConstants::HERO_GOLD_COST);
giveResource(player, EGameResID::GOLD, -GameConstants::HERO_GOLD_COST);
if (t)
{
@ -4594,11 +4594,11 @@ bool CGameHandler::makeBattleAction(BattleAction &ba)
int cost = gs->curB->battleGetSurrenderCost(player);
if (cost < 0)
complain("Cannot surrender!");
else if (getResource(player, Res::GOLD) < cost)
else if (getResource(player, EGameResID::GOLD) < cost)
complain("Not enough gold to surrender!");
else
{
giveResource(player, Res::GOLD, -cost);
giveResource(player, EGameResID::GOLD, -cost);
setBattleResult(BattleResult::SURRENDER, !ba.side); //surrendering side loses
}
break;
@ -5961,8 +5961,8 @@ void CGameHandler::handleAfterAttackCasting(bool ranged, const CStack * attacker
int bonusAdditionalInfo = attacker->getBonus(Selector::type()(Bonus::TRANSMUTATION))->additionalInfo[0];
if(defender->getCreature()->idNumber == bonusAdditionalInfo ||
(bonusAdditionalInfo == CAddInfo::NONE && defender->getCreature()->idNumber == attacker->getCreature()->idNumber))
if(defender->getCreature()->getId() == bonusAdditionalInfo ||
(bonusAdditionalInfo == CAddInfo::NONE && defender->getCreature()->getId() == attacker->getCreature()->getId()))
return;
battle::UnitInfo resurrectInfo;
@ -6069,7 +6069,7 @@ bool CGameHandler::sacrificeCreatures(const IMarket * market, const CGHeroInstan
COMPLAIN_RET("Cannot sacrifice last creature!");
}
int crid = hero->getStack(slot[i]).type->idNumber;
int crid = hero->getStack(slot[i]).type->getId();
changeStackCount(StackLocation(hero, slot[i]), -(TQuantity)count[i]);
@ -6150,7 +6150,7 @@ bool CGameHandler::insertNewStack(const StackLocation &sl, const CCreature *c, T
InsertNewStack ins;
ins.army = sl.army->id;
ins.slot = sl.slot;
ins.type = c->idNumber;
ins.type = c->getId();
ins.count = count;
sendAndApply(&ins);
return true;
@ -6523,7 +6523,7 @@ void CGameHandler::runBattle()
}
const CGHeroInstance * curOwner = battleGetOwnerHero(next);
const int stackCreatureId = next->getCreature()->idNumber;
const int stackCreatureId = next->getCreature()->getId();
if ((stackCreatureId == CreatureID::ARROW_TOWERS || stackCreatureId == CreatureID::BALLISTA)
&& (!curOwner || getRandomGenerator().nextInt(99) >= curOwner->valOfBonuses(Bonus::MANUAL_CONTROL, stackCreatureId)))
@ -6539,7 +6539,7 @@ void CGameHandler::runBattle()
for(auto & elem : gs->curB->stacks)
{
if(elem->getCreature()->idNumber != CreatureID::CATAPULT
if(elem->getCreature()->getId() != CreatureID::CATAPULT
&& elem->owner != next->owner
&& elem->isValidTarget()
&& gs->curB->battleCanShoot(next, elem->getPosition()))
@ -6561,7 +6561,7 @@ void CGameHandler::runBattle()
continue;
}
if (next->getCreature()->idNumber == CreatureID::CATAPULT)
if (next->getCreature()->getId() == CreatureID::CATAPULT)
{
const auto & attackableBattleHexes = curB.getAttackableBattleHexes();
@ -6583,7 +6583,7 @@ void CGameHandler::runBattle()
}
}
if (next->getCreature()->idNumber == CreatureID::FIRST_AID_TENT)
if (next->getCreature()->getId() == CreatureID::FIRST_AID_TENT)
{
TStacks possibleStacks = battleGetStacksIf([=](const CStack * s)
{
@ -6988,8 +6988,8 @@ void CGameHandler::handleCheatCode(std::string & cheat, PlayerColor player, cons
cheated = true;
///Give resources to player
TResources resources;
resources[Res::GOLD] = 100000;
for (Res::ERes i = Res::WOOD; i < Res::GOLD; vstd::advance(i, 1))
resources[EGameResID::GOLD] = 100000;
for (auto i = EGameResID::WOOD; i < EGameResID::GOLD; vstd::advance(i, 1))
resources[i] = 100;
giveResources(player, resources);
@ -7205,7 +7205,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl
if(st->alive() && st->getCount() > 0)
{
logGlobal->debug("Permanently summoned %d units.", st->getCount());
const CreatureID summonedType = st->type->idNumber;
const CreatureID summonedType = st->type->getId();
summoned[summonedType] += st->getCount();
}
}