Hooks
static bool BeforeCvUnit_LogWorkerEvent(CvUnit* self, BuildTypes eBuildType, bool bStartingConstruction);static void AfterCvUnit_LogWorkerEvent(CvUnit* self, BuildTypes eBuildType, bool bStartingConstruction);static void ReplaceCvUnit_LogWorkerEvent(void (*original)(CvUnit*, BuildTypes, bool), CvUnit* self, BuildTypes eBuildType, bool bStartingConstruction);CivRegisterBefore<CivHooks::CvUnit_LogWorkerEvent>(host, &BeforeCvUnit_LogWorkerEvent);CivRegisterAfter<CivHooks::CvUnit_LogWorkerEvent>(host, &AfterCvUnit_LogWorkerEvent);CivRegisterReplace<CivHooks::CvUnit_LogWorkerEvent>(host, &ReplaceCvUnit_LogWorkerEvent);
Code
5484/// Logs information about when a worker begins and finishes construction of an improvement5485void CvUnit::LogWorkerEvent(BuildTypes eBuildType, bool bStartingConstruction)5486{5487 VALIDATE_OBJECT5488 // if not logging, don't log!5489 if(!GC.getLogging() || !GC.GetBuilderAILogging())5490 {5491 return;5492 }54935494 CvString strLog;5495 CvString strTemp;54965497 strTemp.Format("%d,", GC.getGame().getGameTurn()); // turn5498 strLog += strTemp;54995500 CvString strPlayerName;5501 strPlayerName = GET_PLAYER(getOwner()).getCivilizationShortDescription();5502 strLog += strPlayerName;5503 strLog += ",";55045505 strTemp.Format("%d,", GetID()); // unit id5506 strLog += strTemp;55075508 CvString strLoc; // location5509 strLoc.Format("%d,%d,", getX(), getY());5510 strLog += strLoc;55115512 strLog += GC.getBuildInfo(eBuildType)->GetType(); // what is being constructed5513 strLog += ",";55145515 // beginning or completing construction5516 if(bStartingConstruction)5517 {5518 strLog += "begin,";5519 }5520 else5521 {5522 strLog += "complete,";5523 }55245525 // drawing improvement information5526 CvString strResource = ",";5527 CvString strCanSee = ",";55285529 ImprovementTypes eImprovement = (ImprovementTypes)GC.getBuildInfo(eBuildType)->getImprovement();5530 if(eImprovement != NO_IMPROVEMENT)5531 {5532 ResourceTypes eResource = plot()->getResourceType(getTeam());5533 if(eResource != NO_RESOURCE)5534 {5535 strResource = GC.getResourceInfo(eResource)->GetType();5536 strResource += ",";5537 }5538 else if(plot()->getResourceType(NO_TEAM) != NO_RESOURCE)5539 {5540 eResource = plot()->getResourceType(NO_TEAM);5541 strResource = GC.getResourceInfo(eResource)->GetType();5542 strResource += ",";55435544 strCanSee = "Can't see!,";5545 }5546 }55475548 strLog += strResource;5549 strLog += strCanSee;55505551 // gold cost5552 CvString strCost = ",";5553 if(bStartingConstruction)5554 {5555 strCost.Format("%d,", GET_PLAYER(getOwner()).getBuildCost(plot(), eBuildType));5556 }5557 strLog += strCost;55585559 // gold amount5560 CvString strGoldAmount = ",";5561 if(bStartingConstruction)5562 {5563 strGoldAmount.Format("%d,", GET_PLAYER(getOwner()).GetTreasury()->GetGold());5564 }5565 strLog += strGoldAmount;55665567 // Open the log file5568 CvString strFileName;5569 if(GC.getPlayerAndCityAILogSplit())5570 {5571 strFileName = "BuilderEventLog_" + strPlayerName + ".csv";5572 }5573 else5574 {5575 strFileName = "BuilderEventLog.csv";5576 }557755785579 // Open the log file5580 FILogFile* pLog;5581 pLog = LOGFILEMGR.GetLog(strFileName, FILogFile::kDontTimeStamp);5582 pLog->Msg(strLog);5583}