Hooks
static bool BeforeCvHomelandAI_ExecuteWorkerMoves(CvHomelandAI* self, bool bSecondary);static void AfterCvHomelandAI_ExecuteWorkerMoves(CvHomelandAI* self, bool bSecondary);static void ReplaceCvHomelandAI_ExecuteWorkerMoves(void (*original)(CvHomelandAI*, bool), CvHomelandAI* self, bool bSecondary);CivRegisterBefore<CivHooks::CvHomelandAI_ExecuteWorkerMoves>(host, &BeforeCvHomelandAI_ExecuteWorkerMoves);CivRegisterAfter<CivHooks::CvHomelandAI_ExecuteWorkerMoves>(host, &AfterCvHomelandAI_ExecuteWorkerMoves);CivRegisterReplace<CivHooks::CvHomelandAI_ExecuteWorkerMoves>(host, &ReplaceCvHomelandAI_ExecuteWorkerMoves);
Code
2814/// Moves units to explore the map2815#if defined(MOD_AI_SECONDARY_WORKERS)2816void CvHomelandAI::ExecuteWorkerMoves(bool bSecondary)2817#else2818void CvHomelandAI::ExecuteWorkerMoves()2819#endif2820{2821 CvString strLogString;28222823 FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator it;2824 for(it = m_CurrentMoveUnits.begin(); it != m_CurrentMoveUnits.end(); ++it)2825 {2826 UnitHandle pUnit = m_pPlayer->getUnit(it->GetID());2827 if(pUnit)2828 {2829 CvPlot* pPlot = pUnit->plot();28302831 AI_PERF_FORMAT("Homeland-ExecuteWorkerMoves-perf.csv", ("ExecuteWorkerMoves, Turn %03d, %s, Unit %d, at x=%d, y=%d", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription(), pUnit->GetID(), pUnit->getX(), pUnit->getY()) );28322833 if(pPlot && m_pPlayer->IsPlotUnderImmediateThreat(*pPlot) && !pPlot->getBestDefender(m_pPlayer->GetID()))2834 {2835#if defined(MOD_AI_SECONDARY_WORKERS)2836 if(MoveCivilianToSafety(pUnit.pointer(), false, bSecondary))2837#else2838 if(MoveCivilianToSafety(pUnit.pointer()))2839#endif2840 {2841 if(GC.getLogging() && GC.GetBuilderAILogging())2842 {2843 // Open the log file2844 CvString strFileName = "BuilderTaskingLog.csv";2845 FILogFile* pLog;2846 pLog = LOGFILEMGR.GetLog(strFileName, FILogFile::kDontTimeStamp);28472848 // write in data2849 CvString strLog;2850 CvString strTemp;28512852 CvString strPlayerName;2853 strPlayerName = m_pPlayer->getCivilizationShortDescription();2854 strLog += strPlayerName;2855 strLog += ",";28562857 strTemp.Format("%d,", GC.getGame().getGameTurn()); // turn2858 strLog += strTemp;28592860 strTemp.Format("%d,", pUnit->GetID()); // unit id2861 strLog += strTemp;28622863 strLog += "1st Safety,";28642865 pLog->Msg(strLog);2866 }28672868 pUnit->finishMoves();2869 UnitProcessed(pUnit->GetID());2870 continue;2871 }2872 }28732874#if defined(MOD_AI_SECONDARY_WORKERS)2875 bool bActionPerformed = ExecuteWorkerMove(pUnit.pointer(), bSecondary);2876#else2877 bool bActionPerformed = ExecuteWorkerMove(pUnit.pointer());2878#endif2879 if(bActionPerformed)2880 {2881 continue;2882 }28832884 // if there's nothing else to do, move to the safest spot nearby2885#if defined(MOD_AI_SECONDARY_WORKERS)2886 // Only move primary workers (actual civilian workers/workboats) or embarked secondary workers (combat units) to safety2887 if (bSecondary && !pUnit.pointer()->isEmbarked())2888 {2889 continue;2890 }28912892 if(MoveCivilianToSafety(pUnit.pointer(), true /*bIgnoreUnits*/), bSecondary)2893#else2894 if(MoveCivilianToSafety(pUnit.pointer(), true /*bIgnoreUnits*/))2895#endif2896 {2897 if(GC.getLogging() && GC.GetBuilderAILogging())2898 {2899 // Open the log file2900 CvString strFileName = "BuilderTaskingLog.csv";2901 FILogFile* pLog;2902 pLog = LOGFILEMGR.GetLog(strFileName, FILogFile::kDontTimeStamp);29032904 // write in data2905 CvString strLog;2906 CvString strTemp;29072908 CvString strPlayerName;2909 strPlayerName = m_pPlayer->getCivilizationShortDescription();2910 strLog += strPlayerName;2911 strLog += ",";29122913 strTemp.Format("%d,", GC.getGame().getGameTurn()); // turn2914 strLog += strTemp;29152916 strTemp.Format("%d,", pUnit->GetID()); // unit id2917 strLog += strTemp;29182919 strLog += "2nd Safety,";29202921 pLog->Msg(strLog);2922 }29232924 // slewis - this was removed because a unit would eat all its moves. So if it didn't do anything this turn, it wouldn't be able to work 2925 pUnit->PushMission(CvTypes::getMISSION_SKIP());2926 if (!m_pPlayer->isHuman())2927 {2928 pUnit->finishMoves();2929 }2930 UnitProcessed(pUnit->GetID());2931 continue;2932 }29332934 pUnit->PushMission(CvTypes::getMISSION_SKIP());2935 pUnit->finishMoves();2936 UnitProcessed(pUnit->GetID());2937 }2938 }2939}