void Kitchen::communicate() { struct timeval time; time_t lastSec = 0; if (gettimeofday(&time, NULL)) std::cerr << "gettimeofday fail.\n"; while (time.tv_sec - _lastTick.tv_sec < 5) { if (lastSec == 0 || time.tv_sec - lastSec > 0) { _waiter->take<report>(_infos); lastSec = time.tv_sec; } if (_waiter->checkDelivery()) { pushOrder(_waiter->deliver<ushort>()); _waiter->take<report>(_infos); _timeLock.lock(); _lastTick = time; _timeLock.unlock(); } if (gettimeofday(&time, NULL)) std::cerr << "gettimeofday fail.\n"; } demolish(); }
void CvCityAI::AI_chooseProduction(bool bInterruptWonders) { VALIDATE_OBJECT CvPlayerAI& kOwner = GET_PLAYER(getOwner()); CvCitySpecializationAI* pSpecializationAI = kOwner.GetCitySpecializationAI(); bool bBuildWonder = false; // See if this is the one AI city that is supposed to be building wonders if(pSpecializationAI->GetWonderBuildCity() == this) { // Is it still working on that wonder and we don't want to interrupt it? if(!bInterruptWonders) { const BuildingTypes eBuilding = getProductionBuilding(); CvBuildingEntry* pkBuilding = (eBuilding != NO_BUILDING)? GC.getBuildingInfo(eBuilding) : NULL; if(pkBuilding && kOwner.GetWonderProductionAI()->IsWonder(*pkBuilding)) { return; // Stay the course } } // So we're the wonder building city but it is not underway yet... // Has the designated wonder been poached by another civ? BuildingTypes eNextWonder = pSpecializationAI->GetNextWonderDesired(); if(!canConstruct(eNextWonder)) { // Reset city specialization kOwner.GetCitySpecializationAI()->SetSpecializationsDirty(SPECIALIZATION_UPDATE_WONDER_BUILT_BY_RIVAL); } else { // to prevent us from continuously locking into building wonders in one city when there are other high priority items to build int iFlavorWonder = kOwner.GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_WONDER")); int iFlavorGP = kOwner.GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_GREAT_PEOPLE")); int iFlavor = (iFlavorWonder > iFlavorGP ) ? iFlavorWonder : iFlavorGP; if (GC.getGame().getJonRandNum(11, "Random roll for whether to continue building wonders") <= iFlavor) bBuildWonder = true; } } if(bBuildWonder) { CvCityBuildable buildable; buildable.m_eBuildableType = CITY_BUILDABLE_BUILDING; buildable.m_iIndex = pSpecializationAI->GetNextWonderDesired(); buildable.m_iTurnsToConstruct = getProductionTurnsLeft((BuildingTypes)buildable.m_eBuildableType, 0); pushOrder(ORDER_CONSTRUCT, buildable.m_iIndex, -1, false, false, false, false); if(GC.getLogging() && GC.getAILogging()) { CvString playerName; FILogFile* pLog; CvString strBaseString; CvString strOutBuf; m_pCityStrategyAI->LogCityProduction(buildable, false); playerName = kOwner.getCivilizationShortDescription(); pLog = LOGFILEMGR.GetLog(kOwner.GetCitySpecializationAI()->GetLogFileName(playerName), FILogFile::kDontTimeStamp); strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns()); strBaseString += playerName + ", "; strOutBuf.Format("%s, WONDER - Started %s, Turns: %d", getName().GetCString(), GC.getBuildingInfo((BuildingTypes)buildable.m_iIndex)->GetDescription(), buildable.m_iTurnsToConstruct); strBaseString += strOutBuf; pLog->Msg(strBaseString); } } else { m_pCityStrategyAI->ChooseProduction(false); AI_setChooseProductionDirty(false); } return; }