1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +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:
DjWarmonger
2013-02-02 08:29:57 +00:00
parent c4e03ef0de
commit beb1ca1bf8
12 changed files with 58 additions and 46 deletions

View File

@@ -980,7 +980,7 @@ void VCAI::makeTurn()
BNLOG("Player %d starting turn", playerID); BNLOG("Player %d starting turn", playerID);
INDENT; INDENT;
switch(cb->getDate(1)) switch(cb->getDate(Date::DAY_OF_WEEK))
{ {
case 1: case 1:
{ {
@@ -1374,15 +1374,15 @@ void VCAI::buildStructure(const CGTownInstance * t)
if (tryBuildNextStructure(t, std::vector<int>(goldSource, goldSource + ARRAY_COUNT(goldSource)))) if (tryBuildNextStructure(t, std::vector<int>(goldSource, goldSource + ARRAY_COUNT(goldSource))))
return; 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)) if (tryBuildNextStructure(t, std::vector<int>(unitGrowth, unitGrowth + ARRAY_COUNT(unitGrowth)), 2))
return; return;
} }
// first in-game week or second half of any week: try build dwellings // first in-game week or second half of any week: try build dwellings
if (cb->getDate(0) < 7 || cb->getDate(1) > 3) 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(1))) if (tryBuildAnyStructure(t, std::vector<int>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 8 - cb->getDate(Date::DAY_OF_WEEK)))
return; return;
//try to upgrade dwelling //try to upgrade dwelling

View File

@@ -675,13 +675,13 @@ void CInfoBar::CVisibleInfo::loadTown(const CGTownInstance *town)
void CInfoBar::CVisibleInfo::playNewDaySound() 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); CCS->soundh->playSound(soundBase::newDay);
else 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); CCS->soundh->playSound(soundBase::newWeek);
else 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); CCS->soundh->playSound(soundBase::newMonth);
else else
CCS->soundh->playSound(soundBase::newDay); CCS->soundh->playSound(soundBase::newDay);
@@ -689,13 +689,13 @@ void CInfoBar::CVisibleInfo::playNewDaySound()
std::string CInfoBar::CVisibleInfo::getNewDayName() std::string CInfoBar::CVisibleInfo::getNewDayName()
{ {
if (LOCPLINT->cb->getDate(0) == 1) if (LOCPLINT->cb->getDate(Date::DAY) == 1)
return "NEWDAY"; return "NEWDAY";
if (LOCPLINT->cb->getDate(1) != 1) if (LOCPLINT->cb->getDate(Date::DAY) != 1)
return "NEWDAY"; return "NEWDAY";
switch(LOCPLINT->cb->getDate(2)) switch(LOCPLINT->cb->getDate(Date::WEEK))
{ {
case 1: return "NEWWEEK1"; case 1: return "NEWWEEK1";
case 2: return "NEWWEEK2"; case 2: return "NEWWEEK2";
@@ -715,10 +715,10 @@ void CInfoBar::CVisibleInfo::loadDay()
new CShowableAnim(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE); new CShowableAnim(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE);
std::string labelText; std::string labelText;
if (LOCPLINT->cb->getDate(1) == 1 && LOCPLINT->cb->getDate(0) != 1) // monday of any week but first - show new week info 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(2)); labelText = CGI->generaltexth->allTexts[63] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK));
else 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)); forceRefresh.push_back(new CLabel(95, 31, FONT_MEDIUM, CENTER, Colors::WHITE, labelText));
} }

View File

@@ -343,9 +343,9 @@ void CResDataBar::draw(SDL_Surface * to)
} }
std::vector<std::string> temp; 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(Date::MONTH)));
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(2))); temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK)));
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(1))); 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)); graphics->fonts[FONT_SMALL]->renderTextLeft(to, processStr(datetext,temp), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
} }

View File

@@ -1761,9 +1761,9 @@ void CMinorResDataBar::showAll(SDL_Surface * to)
} }
std::vector<std::string> temp; 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(Date::MONTH)));
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(2))); temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK)));
temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(1))); 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] std::string datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
+ ": %s, " + CGI->generaltexth->allTexts[64] + ": %s"; + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";

View File

@@ -717,31 +717,31 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
map->addBlockVisTiles(cur); map->addBlockVisTiles(cur);
} }
int CGameState::getDate(int mode) const int CGameState::getDate(Date::EDateType mode) const
{ {
int temp; int temp;
switch (mode) switch (mode)
{ {
case 0: //day number case Date::DAY:
return day; return day;
break; break;
case 1: //day of week case Date::DAY_OF_WEEK: //day of week
temp = (day)%7; // 1 - Monday, 7 - Sunday temp = (day)%7; // 1 - Monday, 7 - Sunday
if (temp) if (temp)
return temp; return temp;
else return 7; else return 7;
break; break;
case 2: //current week case Date::WEEK: //current week
temp = ((day-1)/7)+1; temp = ((day-1)/7)+1;
if (!(temp%4)) if (!(temp%4))
return 4; return 4;
else else
return (temp%4); return (temp%4);
break; break;
case 3: //current month case Date::MONTH: //current month
return ((day-1)/28)+1; return ((day-1)/28)+1;
break; break;
case 4: //day of month case Date::DAY_OF_MONTH: //day of month
temp = (day)%28; temp = (day)%28;
if (temp) if (temp)
return temp; return temp;

View File

@@ -444,7 +444,7 @@ public:
virtual ~CGameState(); //d-tor virtual ~CGameState(); //d-tor
void getNeighbours(const TerrainTile &srct, int3 tile, std::vector<int3> &vec, const boost::logic::tribool &onLand, bool limitCoastSailing); 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 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) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & scenarioOps & initialOpts & currentPlayer & day & map & players & teams & hpool & globalEffects; h & scenarioOps & initialOpts & currentPlayer & day & map & players & teams & hpool & globalEffects;

View File

@@ -1723,7 +1723,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
void CGDwelling::newTurn() 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; return;
//town growths and War Machines Factories are handled separately //town growths and War Machines Factories are handled separately
@@ -2136,11 +2136,11 @@ void CGTownInstance::initObj()
void CGTownInstance::newTurn() const 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 //give resources for Rampart, Mystic Pond
if (hasBuilt(EBuilding::MYSTIC_POND, ETownType::RAMPART) 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 int resID = rand()%4+2;//bonus to random rare resource
resID = (resID==2)?1:resID; 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 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]; TCreature c = town->creatures[i][0];
TSlot n = -1; TSlot n = -1;
@@ -3120,7 +3120,7 @@ void CGCreature::initObj()
} }
void CGCreature::newTurn() const void CGCreature::newTurn() const
{//Works only for stacks of single type of size up to 2 millions {//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; 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 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 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); cb->setObjProperty(id, ObjProperty::VISITED, false);
MetaString ms; //set text to "not visited" MetaString ms; //set text to "not visited"
@@ -3613,7 +3613,7 @@ void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
case Obj::WATER_WHEEL: case Obj::WATER_WHEEL:
mid = 164; mid = 164;
sub = 6; sub = 6;
if(cb->getDate(0)<8) if(cb->getDate(Date::DAY)<8)
val = 500; val = 500;
else else
val = 1000; val = 1000;
@@ -4563,7 +4563,7 @@ void CGSeerHut::setPropertyDer (ui8 what, ui32 val)
} }
void CGSeerHut::newTurn() const 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, 11, 0);
cb->setObjProperty (id, 10, 0); cb->setObjProperty (id, 10, 0);
@@ -4883,7 +4883,7 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
gbonus.bonus.val = 1; gbonus.bonus.val = 1;
descr_id = 68; 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; gbonus.bonus.type = Bonus::MORALE;
second = true; second = true;
@@ -4892,7 +4892,7 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
} }
else 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; break;
case Obj::MERMAID: case Obj::MERMAID:
@@ -4926,7 +4926,7 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
messageID = 140; messageID = 140;
iw.soundID = soundBase::temple; iw.soundID = soundBase::temple;
gbonus.bonus.type = Bonus::MORALE; gbonus.bonus.type = Bonus::MORALE;
if(cb->getDate(1)==7) //sunday if(cb->getDate(Date::DAY_OF_WEEK)==7) //sunday
{ {
gbonus.bonus.val = 2; gbonus.bonus.val = 2;
descr_id = 97; descr_id = 97;
@@ -5982,13 +5982,13 @@ void CBank::newTurn() const
{ {
if (bc == NULL) if (bc == NULL)
{ {
if (cb->getDate(0) == 1) if (cb->getDate() == 1)
initialize(); //initialize on first day initialize(); //initialize on first day
else if (daycounter >= 28 && (subID < 13 || subID > 16)) //no reset for Emissaries else if (daycounter >= 28 && (subID < 13 || subID > 16)) //no reset for Emissaries
{ {
initialize(); initialize();
cb->setObjProperty (id, 11, 0); //daycounter 0 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, 12, 0);//ugly hack to make derelict ships usable only once
cb->setObjProperty (id, 16, 0); cb->setObjProperty (id, 16, 0);
@@ -7162,7 +7162,7 @@ std::vector<int> CGBlackMarket::availableItemsIds(EMarketMode::EMarketMode mode)
void CGBlackMarket::newTurn() const void CGBlackMarket::newTurn() const
{ {
if(cb->getDate(2) != 1) if(cb->getDate(Date::DAY_OF_MONTH) != 1) //new month
return; return;
SetAvailableArtifacts saa; SetAvailableArtifacts saa;

View File

@@ -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 declarations
typedef si8 TFaction; typedef si8 TFaction;
typedef si64 TExpType; typedef si64 TExpType;

View File

@@ -407,7 +407,7 @@ bool CGameInfoCallback::getHeroInfo( const CGObjectInstance *hero, InfoAboutHero
return true; return true;
} }
int CGameInfoCallback::getDate(int mode) const int CGameInfoCallback::getDate(Date::EDateType mode) const
{ {
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->getDate(mode); return gs->getDate(mode);

View File

@@ -75,7 +75,7 @@ protected:
public: public:
//various //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; const StartInfo * getStartInfo(bool beforeRandomization = false)const;
bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill

View File

@@ -891,7 +891,7 @@ DLL_LINKAGE void NewTurn::applyGs( CGameState *gs )
h.applyGs(gs); h.applyGs(gs);
gs->globalEffects.popBonuses(Bonus::OneDay); //works for children -> all game objs 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 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...] //TODO not really a single root hierarchy, what about bonuses placed elsewhere? [not an issue with H3 mechanics but in the future...]

View File

@@ -1126,9 +1126,9 @@ void CGameHandler::newTurn()
n.creatureid = -1; n.creatureid = -1;
n.day = gs->day + 1; n.day = gs->day + 1;
bool firstTurn = !getDate(0); bool firstTurn = !getDate(Date::DAY);
bool newWeek = getDate(1) == 7; //day numbers are confusing, as day was not yet switched bool newWeek = getDate(Date::DAY_OF_WEEK) == 7; //day numbers are confusing, as day was not yet switched
bool newMonth = getDate(4) == 28; bool newMonth = getDate(Date::DAY_OF_MONTH) == 28;
std::map<ui8, si32> hadGold;//starting gold - for buildings like dwarven treasury std::map<ui8, si32> hadGold;//starting gold - for buildings like dwarven treasury
srand(time(NULL)); srand(time(NULL));