Hooks
static bool BeforeCvPlayerCulture_MoveWorks(CvPlayerCulture* self, GreatWorkSlotType eType, vector<CvGreatWorkBuildingInMyEmpire> & buildings, vector<CvGreatWorkInMyEmpire> & works1, vector<CvGreatWorkInMyEmpire> & works2, YieldTypes eFocusYield);static void AfterCvPlayerCulture_MoveWorks(CvPlayerCulture* self, GreatWorkSlotType eType, vector<CvGreatWorkBuildingInMyEmpire> & buildings, vector<CvGreatWorkInMyEmpire> & works1, vector<CvGreatWorkInMyEmpire> & works2, YieldTypes eFocusYield);static void ReplaceCvPlayerCulture_MoveWorks(void (*original)(CvPlayerCulture*, GreatWorkSlotType, vector<CvGreatWorkBuildingInMyEmpire> &, vector<CvGreatWorkInMyEmpire> &, vector<CvGreatWorkInMyEmpire> &, YieldTypes), CvPlayerCulture* self, GreatWorkSlotType eType, vector<CvGreatWorkBuildingInMyEmpire> & buildings, vector<CvGreatWorkInMyEmpire> & works1, vector<CvGreatWorkInMyEmpire> & works2, YieldTypes eFocusYield);CivRegisterBefore<CivHooks::CvPlayerCulture_MoveWorks>(host, &BeforeCvPlayerCulture_MoveWorks);CivRegisterAfter<CivHooks::CvPlayerCulture_MoveWorks>(host, &AfterCvPlayerCulture_MoveWorks);CivRegisterReplace<CivHooks::CvPlayerCulture_MoveWorks>(host, &ReplaceCvPlayerCulture_MoveWorks);
Code
1208/// Overall routine that orchestrates all the maneuvering of Great Works between buildings and players for one AI turn1209#if defined(MOD_GLOBAL_GREATWORK_YIELDTYPES)1210void CvPlayerCulture::MoveWorks (GreatWorkSlotType eType, vector<CvGreatWorkBuildingInMyEmpire> &buildings, vector<CvGreatWorkInMyEmpire> &works1, vector<CvGreatWorkInMyEmpire> &works2, YieldTypes eFocusYield)1211#else1212void CvPlayerCulture::MoveWorks (GreatWorkSlotType eType, vector<CvGreatWorkBuildingInMyEmpire> &buildings, vector<CvGreatWorkInMyEmpire> &works1, vector<CvGreatWorkInMyEmpire> &works2)1213#endif1214{1215 // CUSTOMLOG("Move Works for slot type %i", ((int) eType));1216 std::sort (buildings.begin(), buildings.end(), SortThemingBonus);12171218#if defined(MOD_GLOBAL_GREATWORK_YIELDTYPES)1219 /*1220 * The order is1221 * - theme homeland and puppet buildings1222 * - theme endangered buildings1223 * - work out the swaps1224 * - fill single homeland buildings with a focused yield1225 * - fill single puppet buildings with a focused yield1226 * - fill single homeland buildings with any yield1227 * - fill single puppet buildings with any yield1228 * - fill single homeland buildings with no yield1229 * - fill single puppet buildings with no yield1230 * - fill single endangered buildings with a focused yield1231 * - fill single endangered buildings with any yield1232 * - fill single endangered buildings with no yield1233 */1234#endif12351236 // First building that are not endangered1237 // CUSTOMLOG(" ... theming safe buildings");1238 vector<CvGreatWorkBuildingInMyEmpire>::iterator itBuilding;1239 for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)1240 {1241 if (!itBuilding->m_bEndangered)1242 {1243 itBuilding->m_bThemed = false;1244 if (ThemeBuilding(itBuilding, works1, works2, false /*bConsiderOtherPlayers*/))1245 {1246 itBuilding->m_bThemed = true;1247 }1248 }1249 }12501251 // Then endangered ones1252 // CUSTOMLOG(" ... theming endangered buildings");1253 for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)1254 {1255 if (itBuilding->m_bEndangered)1256 {1257 itBuilding->m_bThemed = false;1258 if (ThemeBuilding(itBuilding, works1, works2, false /*bConsiderOtherPlayers*/))1259 {1260 itBuilding->m_bThemed = true;1261 }1262 }1263 }12641265 // One more pass through those that are not endangered to see if swapping with another player would help (as long as this isn't Music)1266 if (eType != CvTypes::getGREAT_WORK_SLOT_MUSIC())1267 {1268 // CUSTOMLOG(" ... checking safe buildings for swaps");1269 for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)1270 {1271 if (!itBuilding->m_bEndangered && !itBuilding->m_bThemed)1272 {1273 if (ThemeBuilding(itBuilding, works1, works2, true /*bConsiderOtherPlayers*/))1274 {1275 itBuilding->m_bThemed = true;1276 }1277 }1278 }1279 }12801281 // Set the first work left that we haven't themed as something we'd be willing to trade1282 // CUSTOMLOG("Setting available swaps");1283 // for Writing1284 if (eType == CvTypes::getGREAT_WORK_SLOT_LITERATURE())1285 {1286 if (works1.size() > 0)1287 {1288 // CUSTOMLOG(" ... for writing to %i", works1[0].m_iGreatWorkIndex);1289 SetSwappableWritingIndex(works1[0].m_iGreatWorkIndex);1290 }1291 else1292 {1293 SetSwappableWritingIndex(-1);1294 }1295 }12961297 // for Art and Artifacts1298 else1299 {1300 if (eType == CvTypes::getGREAT_WORK_SLOT_ART_ARTIFACT())1301 {1302 if (works1.size() > 0)1303 {1304 // CUSTOMLOG(" ... for art(ifact) to %i", works1[0].m_iGreatWorkIndex);1305 SetSwappableArtIndex(works1[0].m_iGreatWorkIndex);1306 }1307 else1308 {1309 SetSwappableArtIndex(-1);1310 }1311 }1312 if (eType == CvTypes::getGREAT_WORK_SLOT_ART_ARTIFACT())1313 {1314 if (works2.size() > 0)1315 {1316 // CUSTOMLOG(" ... for art(ifact) to %i", works2[0].m_iGreatWorkIndex);1317 SetSwappableArtifactIndex(works2[0].m_iGreatWorkIndex);1318 }1319 else1320 {1321 SetSwappableArtifactIndex(-1);1322 }1323 }1324 }13251326#if defined(MOD_GLOBAL_GREATWORK_YIELDTYPES)1327 MoveSingleWorks(buildings, works1, works2, eFocusYield);1328#else1329 // Fill unthemed buildings, first those that aren't endangered1330 for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)1331 {1332 if (!itBuilding->m_bEndangered && !itBuilding->m_bThemed)1333 {1334 FillBuilding(itBuilding, works1, works2);1335 }1336 }1337 for (itBuilding = buildings.begin(); itBuilding != buildings.end(); itBuilding++)1338 {1339 if (itBuilding->m_bEndangered && !itBuilding->m_bThemed)1340 {1341 FillBuilding(itBuilding, works1, works2);1342 }1343 }1344#endif1345}