Hooks
static bool BeforeCvBuilderTaskingAI_ConnectCitiesForScenario(CvBuilderTaskingAI* self, CvCity* pCity1, CvCity* pCity2, RouteTypes eRoute);static void AfterCvBuilderTaskingAI_ConnectCitiesForScenario(CvBuilderTaskingAI* self, CvCity* pCity1, CvCity* pCity2, RouteTypes eRoute);static void ReplaceCvBuilderTaskingAI_ConnectCitiesForScenario(void (*original)(CvBuilderTaskingAI*, CvCity*, CvCity*, RouteTypes), CvBuilderTaskingAI* self, CvCity* pCity1, CvCity* pCity2, RouteTypes eRoute);CivRegisterBefore<CivHooks::CvBuilderTaskingAI_ConnectCitiesForScenario>(host, &BeforeCvBuilderTaskingAI_ConnectCitiesForScenario);CivRegisterAfter<CivHooks::CvBuilderTaskingAI_ConnectCitiesForScenario>(host, &AfterCvBuilderTaskingAI_ConnectCitiesForScenario);CivRegisterReplace<CivHooks::CvBuilderTaskingAI_ConnectCitiesForScenario>(host, &ReplaceCvBuilderTaskingAI_ConnectCitiesForScenario);
Code
460void CvBuilderTaskingAI::ConnectCitiesForScenario(CvCity* pCity1, CvCity* pCity2, RouteTypes eRoute)461{462 // don't connect cities from different owners463 if(pCity1->getOwner() != pCity2->getOwner())464 {465 return;466 }467468 // if we already have a connection, bail out469 if (m_pPlayer->IsCityConnectedToCity(pCity1, pCity2, eRoute, true))470 {471 return;472 }473474 // build a path between the two cities475 int iPathfinderFlags = m_pPlayer->GetID();476 int iRouteValue = eRoute + 1;477 // assuming that there are fewer than 256 players478 iPathfinderFlags |= (iRouteValue << 8);479 bool bFoundPath = GC.GetBuildRouteFinder().GeneratePath(pCity1->plot()->getX(), pCity1->plot()->getY(), pCity2->plot()->getX(), pCity2->plot()->getY(), iPathfinderFlags);480481 // if no path, then bail!482 if(!bFoundPath)483 {484 return;485 }486487 CvPlot* pPlot = NULL;488 CvAStarNode* pNode = GC.GetBuildRouteFinder().GetLastNode();489 int iGameTurn = GC.getGame().getGameTurn();490491 while(pNode)492 {493 pPlot = GC.getMap().plotCheckInvalid(pNode->m_iX, pNode->m_iY);494 pNode = pNode->m_pParent;495496 if(!pPlot)497 {498 break;499 }500501 if(pPlot->getRouteType() == eRoute && !pPlot->IsRoutePillaged())502 {503 continue;504 }505506 // if we already know about this plot, continue on507 if(pPlot->GetBuilderAIScratchPadTurn() == iGameTurn && pPlot->GetBuilderAIScratchPadPlayer() == m_pPlayer->GetID())508 {509 continue;510 }511512 // mark nodes and reset values513 pPlot->SetBuilderAIScratchPadTurn(iGameTurn);514 pPlot->SetBuilderAIScratchPadPlayer(m_pPlayer->GetID());515 pPlot->SetBuilderAIScratchPadValue(1000);516 pPlot->SetBuilderAIScratchPadRoute(eRoute);517518 // add nodes that are not in territory to extra list519 if(pPlot->getOwner() != m_pPlayer->GetID())520 {521 m_aiNonTerritoryPlots.push_back(GC.getMap().plotNum(pPlot->getX(), pPlot->getY()));522 }523 }524}