1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

code review

This commit is contained in:
Laserlicht
2024-10-01 16:32:28 +02:00
parent 31f87cb6ed
commit 9c6bd20159
5 changed files with 18 additions and 14 deletions

View File

@@ -2041,8 +2041,7 @@ void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition)
if(vstd::find_pos(town->spells[i], spell->id) != -1)
level = i;
int today = LOCPLINT->cb->getDate(Date::DAY);
if(town->spellResearchActionsPerDay.find(today) != town->spellResearchActionsPerDay.end() && town->spellResearchActionsPerDay.at(today) >= LOCPLINT->cb->getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_PER_DAY).Vector()[level].Float())
if(town->spellResearchCounterDay >= LOCPLINT->cb->getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_PER_DAY).Vector()[level].Float())
{
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.spellResearch.comeAgain"));
return;
@@ -2050,7 +2049,7 @@ void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition)
auto costBase = TResources(LOCPLINT->cb->getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_COST).Vector()[level]);
auto costExponent = LOCPLINT->cb->getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_COST_EXPONENT_PER_RESEARCH).Vector()[level].Float();
auto cost = costBase * std::pow(town->spellResearchCounter + 1, costExponent);
auto cost = costBase * std::pow(town->spellResearchAcceptedCounter + 1, costExponent);
std::vector<std::shared_ptr<CComponent>> resComps;
auto newSpell = town->spells[level].at(town->spellsAtLevel(level, false));

View File

@@ -269,7 +269,8 @@ CGTownInstance::CGTownInstance(IGameCallback *cb):
destroyed(0),
identifier(0),
alignmentToPlayer(PlayerColor::NEUTRAL),
spellResearchCounter(0),
spellResearchCounterDay(0),
spellResearchAcceptedCounter(0),
spellResearchAllowed(true)
{
this->setNodeType(CBonusSystemNode::TOWN);

View File

@@ -73,8 +73,8 @@ public:
std::vector<std::vector<SpellID> > spells; //spells[level] -> vector of spells, first will be available in guild
std::vector<CCastleEvent> events;
std::pair<si32, si32> bonusValue;//var to store town bonuses (rampart = resources from mystic pond, factory = save debts);
std::map<int, int> spellResearchActionsPerDay;
int spellResearchCounter;
int spellResearchCounterDay;
int spellResearchAcceptedCounter;
bool spellResearchAllowed;
//////////////////////////////////////////////////////////////////////////
@@ -98,8 +98,8 @@ public:
if (h.version >= Handler::Version::SPELL_RESEARCH)
{
h & spellResearchActionsPerDay;
h & spellResearchCounter;
h & spellResearchCounterDay;
h & spellResearchAcceptedCounter;
h & spellResearchAllowed;
}

View File

@@ -944,9 +944,9 @@ void SetResearchedSpells::applyGs(CGameState *gs)
CGTownInstance *town = gs->getTown(tid);
town->spells[level] = spells;
town->spellResearchActionsPerDay[gs->getDate(Date::DAY)]++;
town->spellResearchCounterDay++;
if(accepted)
town->spellResearchCounter++;
town->spellResearchAcceptedCounter++;
}
void SetMana::applyGs(CGameState *gs)
@@ -1941,7 +1941,10 @@ void NewTurn::applyGs(CGameState *gs)
creatureSet.applyGs(gs);
for(CGTownInstance* t : gs->map->towns)
{
t->built = 0;
t->spellResearchCounterDay = 0;
}
if(newRumor)
gs->currentRumor = *newRumor;

View File

@@ -2247,7 +2247,9 @@ bool CGameHandler::spellResearch(ObjectInstanceID tid, SpellID spellAtSlot, bool
{
CGTownInstance *t = gs->getTown(tid);
if(!(getSettings().getBoolean(EGameSettings::TOWNS_SPELL_RESEARCH) && t->spellResearchAllowed) && complain("Spell research not allowed!"))
if(!getSettings().getBoolean(EGameSettings::TOWNS_SPELL_RESEARCH) && complain("Spell research not allowed!"))
return false;
if (!t->spellResearchAllowed && complain("Spell research not allowed in this town!"))
return false;
int level = -1;
@@ -2260,8 +2262,7 @@ bool CGameHandler::spellResearch(ObjectInstanceID tid, SpellID spellAtSlot, bool
auto spells = t->spells.at(level);
int today = getDate(Date::DAY);
bool researchLimitExceeded = t->spellResearchActionsPerDay.find(today) != t->spellResearchActionsPerDay.end() && t->spellResearchActionsPerDay.at(today) >= getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_PER_DAY).Vector()[level].Float();
bool researchLimitExceeded = t->spellResearchCounterDay >= getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_PER_DAY).Vector()[level].Float();
if(researchLimitExceeded && complain("Already researched today!"))
return false;
@@ -2275,7 +2276,7 @@ bool CGameHandler::spellResearch(ObjectInstanceID tid, SpellID spellAtSlot, bool
auto costBase = TResources(getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_COST).Vector()[level]);
auto costExponent = getSettings().getValue(EGameSettings::TOWNS_SPELL_RESEARCH_COST_EXPONENT_PER_RESEARCH).Vector()[level].Float();
auto cost = costBase * std::pow(t->spellResearchCounter + 1, costExponent);
auto cost = costBase * std::pow(t->spellResearchAcceptedCounter + 1, costExponent);
if(!getPlayerState(t->getOwner())->resources.canAfford(cost) && complain("Spell replacement cannot be afforded!"))
return false;