mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- getDate function now uses enum for different modes
- Fixed Black Market (#1195) - Fixed one-week bonuses removed eveyr day (#976)
This commit is contained in:
parent
c4e03ef0de
commit
beb1ca1bf8
@ -980,7 +980,7 @@ void VCAI::makeTurn()
|
||||
BNLOG("Player %d starting turn", playerID);
|
||||
INDENT;
|
||||
|
||||
switch(cb->getDate(1))
|
||||
switch(cb->getDate(Date::DAY_OF_WEEK))
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@ -1374,15 +1374,15 @@ void VCAI::buildStructure(const CGTownInstance * t)
|
||||
if (tryBuildNextStructure(t, std::vector<int>(goldSource, goldSource + ARRAY_COUNT(goldSource))))
|
||||
return;
|
||||
|
||||
if (cb->getDate(1) > 6)// last 2 days of week - try to focus on growth
|
||||
if (cb->getDate(Date::DAY_OF_WEEK) > 6)// last 2 days of week - try to focus on growth
|
||||
{
|
||||
if (tryBuildNextStructure(t, std::vector<int>(unitGrowth, unitGrowth + ARRAY_COUNT(unitGrowth)), 2))
|
||||
return;
|
||||
}
|
||||
|
||||
// first in-game week or second half of any week: try build dwellings
|
||||
if (cb->getDate(0) < 7 || cb->getDate(1) > 3)
|
||||
if (tryBuildAnyStructure(t, std::vector<int>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 8 - cb->getDate(1)))
|
||||
if (cb->getDate(Date::DAY) < 7 || cb->getDate(Date::DAY_OF_WEEK) > 3)
|
||||
if (tryBuildAnyStructure(t, std::vector<int>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 8 - cb->getDate(Date::DAY_OF_WEEK)))
|
||||
return;
|
||||
|
||||
//try to upgrade dwelling
|
||||
|
@ -675,13 +675,13 @@ void CInfoBar::CVisibleInfo::loadTown(const CGTownInstance *town)
|
||||
|
||||
void CInfoBar::CVisibleInfo::playNewDaySound()
|
||||
{
|
||||
if (LOCPLINT->cb->getDate(1) != 1) // not first day of the week
|
||||
if (LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) != 1) // not first day of the week
|
||||
CCS->soundh->playSound(soundBase::newDay);
|
||||
else
|
||||
if (LOCPLINT->cb->getDate(2) != 1) // not first week in month
|
||||
if (LOCPLINT->cb->getDate(Date::WEEK) != 1) // not first week in month
|
||||
CCS->soundh->playSound(soundBase::newWeek);
|
||||
else
|
||||
if (LOCPLINT->cb->getDate(3) != 1) // not first month
|
||||
if (LOCPLINT->cb->getDate(Date::MONTH) != 1) // not first month
|
||||
CCS->soundh->playSound(soundBase::newMonth);
|
||||
else
|
||||
CCS->soundh->playSound(soundBase::newDay);
|
||||
@ -689,13 +689,13 @@ void CInfoBar::CVisibleInfo::playNewDaySound()
|
||||
|
||||
std::string CInfoBar::CVisibleInfo::getNewDayName()
|
||||
{
|
||||
if (LOCPLINT->cb->getDate(0) == 1)
|
||||
if (LOCPLINT->cb->getDate(Date::DAY) == 1)
|
||||
return "NEWDAY";
|
||||
|
||||
if (LOCPLINT->cb->getDate(1) != 1)
|
||||
if (LOCPLINT->cb->getDate(Date::DAY) != 1)
|
||||
return "NEWDAY";
|
||||
|
||||
switch(LOCPLINT->cb->getDate(2))
|
||||
switch(LOCPLINT->cb->getDate(Date::WEEK))
|
||||
{
|
||||
case 1: return "NEWWEEK1";
|
||||
case 2: return "NEWWEEK2";
|
||||
@ -715,10 +715,10 @@ void CInfoBar::CVisibleInfo::loadDay()
|
||||
new CShowableAnim(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE);
|
||||
|
||||
std::string labelText;
|
||||
if (LOCPLINT->cb->getDate(1) == 1 && LOCPLINT->cb->getDate(0) != 1) // monday of any week but first - show new week info
|
||||
labelText = CGI->generaltexth->allTexts[63] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(2));
|
||||
if (LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) == 1 && LOCPLINT->cb->getDate(Date::DAY) != 1) // monday of any week but first - show new week info
|
||||
labelText = CGI->generaltexth->allTexts[63] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK));
|
||||
else
|
||||
labelText = CGI->generaltexth->allTexts[64] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(1));
|
||||
labelText = CGI->generaltexth->allTexts[64] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK));
|
||||
|
||||
forceRefresh.push_back(new CLabel(95, 31, FONT_MEDIUM, CENTER, Colors::WHITE, labelText));
|
||||
}
|
||||
|
@ -343,9 +343,9 @@ void CResDataBar::draw(SDL_Surface * to)
|
||||
}
|
||||
std::vector<std::string> temp;
|
||||
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(3)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(2)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(1)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::MONTH)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK)));
|
||||
|
||||
graphics->fonts[FONT_SMALL]->renderTextLeft(to, processStr(datetext,temp), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
|
||||
}
|
||||
|
@ -1761,9 +1761,9 @@ void CMinorResDataBar::showAll(SDL_Surface * to)
|
||||
}
|
||||
std::vector<std::string> temp;
|
||||
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(3)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(2)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(1)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::MONTH)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK)));
|
||||
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK)));
|
||||
|
||||
std::string datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
|
||||
+ ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
|
||||
|
@ -717,31 +717,31 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
|
||||
map->addBlockVisTiles(cur);
|
||||
}
|
||||
|
||||
int CGameState::getDate(int mode) const
|
||||
int CGameState::getDate(Date::EDateType mode) const
|
||||
{
|
||||
int temp;
|
||||
switch (mode)
|
||||
{
|
||||
case 0: //day number
|
||||
case Date::DAY:
|
||||
return day;
|
||||
break;
|
||||
case 1: //day of week
|
||||
case Date::DAY_OF_WEEK: //day of week
|
||||
temp = (day)%7; // 1 - Monday, 7 - Sunday
|
||||
if (temp)
|
||||
return temp;
|
||||
else return 7;
|
||||
break;
|
||||
case 2: //current week
|
||||
case Date::WEEK: //current week
|
||||
temp = ((day-1)/7)+1;
|
||||
if (!(temp%4))
|
||||
return 4;
|
||||
else
|
||||
return (temp%4);
|
||||
break;
|
||||
case 3: //current month
|
||||
case Date::MONTH: //current month
|
||||
return ((day-1)/28)+1;
|
||||
break;
|
||||
case 4: //day of month
|
||||
case Date::DAY_OF_MONTH: //day of month
|
||||
temp = (day)%28;
|
||||
if (temp)
|
||||
return temp;
|
||||
|
@ -444,7 +444,7 @@ public:
|
||||
virtual ~CGameState(); //d-tor
|
||||
void getNeighbours(const TerrainTile &srct, int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand, bool limitCoastSailing);
|
||||
int getMovementCost(const CGHeroInstance *h, const int3 &src, const int3 &dest, int remainingMovePoints=-1, bool checkLast=true);
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
int getDate(Date::EDateType mode=Date::DAY) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & scenarioOps & initialOpts & currentPlayer & day & map & players & teams & hpool & globalEffects;
|
||||
|
@ -1723,7 +1723,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
void CGDwelling::newTurn() const
|
||||
{
|
||||
if(cb->getDate(1) != 1) //not first day of week
|
||||
if(cb->getDate(Date::DAY_OF_WEEK) != 1) //not first day of week
|
||||
return;
|
||||
|
||||
//town growths and War Machines Factories are handled separately
|
||||
@ -2136,11 +2136,11 @@ void CGTownInstance::initObj()
|
||||
|
||||
void CGTownInstance::newTurn() const
|
||||
{
|
||||
if (cb->getDate(1) == 1) //reset on new week
|
||||
if (cb->getDate(Date::DAY_OF_WEEK) == 1) //reset on new week
|
||||
{
|
||||
//give resources for Rampart, Mystic Pond
|
||||
if (hasBuilt(EBuilding::MYSTIC_POND, ETownType::RAMPART)
|
||||
&& cb->getDate(0) != 1 && (tempOwner < GameConstants::PLAYER_LIMIT))
|
||||
&& cb->getDate(Date::DAY) != 1 && (tempOwner < GameConstants::PLAYER_LIMIT))
|
||||
{
|
||||
int resID = rand()%4+2;//bonus to random rare resource
|
||||
resID = (resID==2)?1:resID;
|
||||
@ -2184,7 +2184,7 @@ void CGTownInstance::newTurn() const
|
||||
}
|
||||
if ((stacksCount() < GameConstants::ARMY_SIZE && rand()%100 < 25) || Slots().empty()) //add new stack
|
||||
{
|
||||
int i = rand() % std::min (GameConstants::ARMY_SIZE, cb->getDate(3)<<1);
|
||||
int i = rand() % std::min (GameConstants::ARMY_SIZE, cb->getDate(Date::MONTH)<<1);
|
||||
TCreature c = town->creatures[i][0];
|
||||
TSlot n = -1;
|
||||
|
||||
@ -3120,7 +3120,7 @@ void CGCreature::initObj()
|
||||
}
|
||||
void CGCreature::newTurn() const
|
||||
{//Works only for stacks of single type of size up to 2 millions
|
||||
if (stacks.begin()->second->count < VLC->modh->settings.CREEP_SIZE && cb->getDate(1) == 1 && cb->getDate(0) > 1)
|
||||
if (stacks.begin()->second->count < VLC->modh->settings.CREEP_SIZE && cb->getDate(Date::DAY_OF_WEEK) == 1 && cb->getDate(Date::DAY) > 1)
|
||||
{
|
||||
ui32 power = temppower * (100 + VLC->modh->settings.WEEKLY_GROWTH)/100;
|
||||
cb->setObjProperty(id, ObjProperty::MONSTER_COUNT, std::min (power/1000 , (ui32)VLC->modh->settings.CREEP_SIZE)); //set new amount
|
||||
@ -3545,7 +3545,7 @@ void CGResource::endBattle( BattleResult *result, const CGHeroInstance *h ) cons
|
||||
|
||||
void CGVisitableOPW::newTurn() const
|
||||
{
|
||||
if (cb->getDate(1) == 1) //first day of week = 1
|
||||
if (cb->getDate(Date::DAY_OF_WEEK) == 1) //first day of week = 1
|
||||
{
|
||||
cb->setObjProperty(id, ObjProperty::VISITED, false);
|
||||
MetaString ms; //set text to "not visited"
|
||||
@ -3613,7 +3613,7 @@ void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
|
||||
case Obj::WATER_WHEEL:
|
||||
mid = 164;
|
||||
sub = 6;
|
||||
if(cb->getDate(0)<8)
|
||||
if(cb->getDate(Date::DAY)<8)
|
||||
val = 500;
|
||||
else
|
||||
val = 1000;
|
||||
@ -4563,7 +4563,7 @@ void CGSeerHut::setPropertyDer (ui8 what, ui32 val)
|
||||
}
|
||||
void CGSeerHut::newTurn() const
|
||||
{
|
||||
if (quest->lastDay >= 0 && quest->lastDay < cb->getDate(0)) //time is up
|
||||
if (quest->lastDay >= 0 && quest->lastDay < cb->getDate()) //time is up
|
||||
{
|
||||
cb->setObjProperty (id, 11, 0);
|
||||
cb->setObjProperty (id, 10, 0);
|
||||
@ -4883,7 +4883,7 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
gbonus.bonus.val = 1;
|
||||
descr_id = 68;
|
||||
if(cb->getDate(1) == 7) //7th day of week
|
||||
if(cb->getDate(Date::DAY_OF_WEEK) == 7) //7th day of week
|
||||
{
|
||||
gbonus.bonus.type = Bonus::MORALE;
|
||||
second = true;
|
||||
@ -4892,7 +4892,7 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
|
||||
}
|
||||
else
|
||||
{
|
||||
gbonus.bonus.type = (cb->getDate(1)%2) ? Bonus::LUCK : Bonus::MORALE;
|
||||
gbonus.bonus.type = (cb->getDate(Date::DAY_OF_WEEK)%2) ? Bonus::LUCK : Bonus::MORALE;
|
||||
}
|
||||
break;
|
||||
case Obj::MERMAID:
|
||||
@ -4926,7 +4926,7 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
|
||||
messageID = 140;
|
||||
iw.soundID = soundBase::temple;
|
||||
gbonus.bonus.type = Bonus::MORALE;
|
||||
if(cb->getDate(1)==7) //sunday
|
||||
if(cb->getDate(Date::DAY_OF_WEEK)==7) //sunday
|
||||
{
|
||||
gbonus.bonus.val = 2;
|
||||
descr_id = 97;
|
||||
@ -5982,13 +5982,13 @@ void CBank::newTurn() const
|
||||
{
|
||||
if (bc == NULL)
|
||||
{
|
||||
if (cb->getDate(0) == 1)
|
||||
if (cb->getDate() == 1)
|
||||
initialize(); //initialize on first day
|
||||
else if (daycounter >= 28 && (subID < 13 || subID > 16)) //no reset for Emissaries
|
||||
{
|
||||
initialize();
|
||||
cb->setObjProperty (id, 11, 0); //daycounter 0
|
||||
if (ID == Obj::DERELICT_SHIP && cb->getDate(0) > 1)
|
||||
if (ID == Obj::DERELICT_SHIP && cb->getDate() > 1)
|
||||
{
|
||||
cb->setObjProperty (id, 12, 0);//ugly hack to make derelict ships usable only once
|
||||
cb->setObjProperty (id, 16, 0);
|
||||
@ -7162,7 +7162,7 @@ std::vector<int> CGBlackMarket::availableItemsIds(EMarketMode::EMarketMode mode)
|
||||
|
||||
void CGBlackMarket::newTurn() const
|
||||
{
|
||||
if(cb->getDate(2) != 1)
|
||||
if(cb->getDate(Date::DAY_OF_MONTH) != 1) //new month
|
||||
return;
|
||||
|
||||
SetAvailableArtifacts saa;
|
||||
|
@ -422,6 +422,18 @@ namespace BattlefieldBI
|
||||
};
|
||||
}
|
||||
|
||||
namespace Date
|
||||
{
|
||||
enum EDateType
|
||||
{
|
||||
DAY = 0,
|
||||
DAY_OF_WEEK = 1,
|
||||
WEEK = 2,
|
||||
MONTH = 3,
|
||||
DAY_OF_MONTH
|
||||
};
|
||||
}
|
||||
|
||||
// Typedef declarations
|
||||
typedef si8 TFaction;
|
||||
typedef si64 TExpType;
|
||||
|
@ -407,7 +407,7 @@ bool CGameInfoCallback::getHeroInfo( const CGObjectInstance *hero, InfoAboutHero
|
||||
return true;
|
||||
}
|
||||
|
||||
int CGameInfoCallback::getDate(int mode) const
|
||||
int CGameInfoCallback::getDate(Date::EDateType mode) const
|
||||
{
|
||||
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
return gs->getDate(mode);
|
||||
|
@ -75,7 +75,7 @@ protected:
|
||||
|
||||
public:
|
||||
//various
|
||||
int getDate(int mode=0)const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
int getDate(Date::EDateType mode=Date::DAY)const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
const StartInfo * getStartInfo(bool beforeRandomization = false)const;
|
||||
bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill
|
||||
|
||||
|
@ -891,7 +891,7 @@ DLL_LINKAGE void NewTurn::applyGs( CGameState *gs )
|
||||
h.applyGs(gs);
|
||||
|
||||
gs->globalEffects.popBonuses(Bonus::OneDay); //works for children -> all game objs
|
||||
if(gs->getDate(1)) //new week
|
||||
if(gs->getDate(Date::DAY_OF_WEEK) == 1) //new week
|
||||
gs->globalEffects.popBonuses(Bonus::OneWeek); //works for children -> all game objs
|
||||
|
||||
//TODO not really a single root hierarchy, what about bonuses placed elsewhere? [not an issue with H3 mechanics but in the future...]
|
||||
|
@ -1126,9 +1126,9 @@ void CGameHandler::newTurn()
|
||||
n.creatureid = -1;
|
||||
n.day = gs->day + 1;
|
||||
|
||||
bool firstTurn = !getDate(0);
|
||||
bool newWeek = getDate(1) == 7; //day numbers are confusing, as day was not yet switched
|
||||
bool newMonth = getDate(4) == 28;
|
||||
bool firstTurn = !getDate(Date::DAY);
|
||||
bool newWeek = getDate(Date::DAY_OF_WEEK) == 7; //day numbers are confusing, as day was not yet switched
|
||||
bool newMonth = getDate(Date::DAY_OF_MONTH) == 28;
|
||||
|
||||
std::map<ui8, si32> hadGold;//starting gold - for buildings like dwarven treasury
|
||||
srand(time(NULL));
|
||||
|
Loading…
Reference in New Issue
Block a user