Code
7221/// Move Barbarian civilian to a camp (with escort if possible)7222void CvTacticalAI::ExecuteBarbarianCivilianEscortMove()7223{7224 UnitHandle pCivilian;7225 UnitHandle pEscort;7226 CvPlot* pTarget;7227 CvPlot* pCurrent;7228 CvPlot* pCivilianMove;7229 CvPlot* pEscortMove;7230 CvUnit* pLoopUnit;72317232 for(unsigned int iI = 0; iI < m_CurrentMoveUnits.size(); iI++)7233 {7234 pCivilian = m_pPlayer->getUnit(m_CurrentMoveUnits[iI].GetID());7235 if(pCivilian)7236 {7237 pTarget = FindNearbyTarget(pCivilian, MAX_INT, AI_TACTICAL_TARGET_BARBARIAN_CAMP, pCivilian.pointer());7238 if(pTarget)7239 {7240 // If we're not there yet, we have work to do7241 pCurrent = pCivilian->plot();7242 if(pCurrent == pTarget)7243 {7244 pCivilian->finishMoves();7245 UnitProcessed(pCivilian->GetID());7246 }7247 else7248 {7249 if(pCurrent->getNumUnits() > 1)7250 {7251 for(int iJ = 0; iJ < pCurrent->getNumUnits(); iJ++)7252 {7253 pLoopUnit = pCurrent->getUnitByIndex(iJ);7254 if(pLoopUnit->GetID() != pCivilian->GetID() &&7255 pLoopUnit->getOwner() == pCivilian->getOwner())7256 {7257 pEscort = UnitHandle(pLoopUnit);7258 break;7259 }7260 }7261 }72627263 // Look at where we'd move this turn taking units into consideration7264 int iFlags = 0;7265 if(pEscort)7266 {7267 iFlags = MOVE_UNITS_IGNORE_DANGER;7268 }72697270 // Handle case of no path found at all for civilian7271 if(!pCivilian->GeneratePath(pTarget, iFlags, false /*bReuse*/))7272 {7273 pCivilian->finishMoves();7274 if(pEscort)7275 {7276 pEscort->finishMoves();7277 }7278 if(GC.getLogging() && GC.getAILogging())7279 {7280 CvString strLogString;7281 strLogString.Format("Retargeting civilian escort operation (path lost to target), X: %d, Y: %d", pTarget->getX(), pTarget->getY());7282 LogTacticalMessage(strLogString);7283 }7284 }72857286 else7287 {7288 pCivilianMove = pCivilian->GetPathEndTurnPlot();72897290 // Can we reach our target this turn?7291 if(pCivilianMove == pTarget)7292 {7293 // See which defender is stronger7294 UnitHandle pCampDefender = pCivilianMove->getBestDefender(m_pPlayer->GetID());7295 if(!pCampDefender || (pEscort && pEscort->GetPower() > pCampDefender->GetPower()))7296 {7297 if(pEscort && (!pCampDefender || ExecuteMoveOfBlockingUnit(pCampDefender)))7298 {7299 ExecuteMoveToPlot(pEscort, pCivilianMove);7300 ExecuteMoveToPlot(pCivilian, pCivilianMove);7301 if(GC.getLogging() && GC.getAILogging())7302 {7303 CvString strTemp;7304 CvString strLogString;7305 strTemp = pEscort->getUnitInfo().GetDescription();7306 strLogString.Format("Moving escorting %s to take over camp defense, X: %d, Y: %d", strTemp.GetCString(), pEscort->getX(), pEscort->getY());7307 LogTacticalMessage(strLogString);7308 strTemp = pCivilian->getUnitInfo().GetDescription();7309 strLogString.Format("Moving %s to camp, X: %d, Y: %d", strTemp.GetCString(), pCivilian->getX(), pCivilian->getY());7310 LogTacticalMessage(strLogString);7311 }7312 }7313 else7314 {7315 ExecuteMoveToPlot(pCivilian, pCivilianMove);7316 if(GC.getLogging() && GC.getAILogging())7317 {7318 CvString strTemp;7319 CvString strLogString;7320 strTemp = pCivilian->getUnitInfo().GetDescription();7321 strLogString.Format("Moving %s to camp, X: %d, Y: %d", strTemp.GetCString(), pCivilian->getX(), pCivilian->getY());7322 LogTacticalMessage(strLogString);7323 }7324 }7325 }7326 else7327 {7328 ExecuteMoveToPlot(pCivilian, pCivilianMove);7329 if(GC.getLogging() && GC.getAILogging())7330 {7331 CvString strTemp;7332 CvString strLogString;7333 strTemp = pCivilian->getUnitInfo().GetDescription();7334 strLogString.Format("Moving %s to camp, X: %d, Y: %d", strTemp.GetCString(), pCivilian->getX(), pCivilian->getY());7335 LogTacticalMessage(strLogString);7336 }7337 }7338 }73397340 // Can't reach target and don't have escort...7341 else if(!pEscort)7342 {7343 ExecuteMoveToPlot(pCivilian, pCivilianMove);7344 if(GC.getLogging() && GC.getAILogging())7345 {7346 CvString strTemp;7347 CvString strLogString;7348 strTemp = pCivilian->getUnitInfo().GetDescription();7349 strLogString.Format("Moving %s without escort to target, X: %d, Y: %d", strTemp.GetCString(), pCivilian->plot()->getX(), pCivilian->plot()->getY());7350 LogTacticalMessage(strLogString);7351 }7352 }73537354 // Can't reach target and DO have escort...7355 else7356 {7357 // See if escort can move to the same location in one turn7358 if(TurnsToReachTarget(pEscort, pCivilianMove) <= 1)7359 {7360 ExecuteMoveToPlot(pEscort, pCivilianMove);7361 ExecuteMoveToPlot(pCivilian, pCivilianMove);7362 if(GC.getLogging() && GC.getAILogging())7363 {7364 CvString strTemp;7365 CvString strLogString;7366 strTemp = pEscort->getUnitInfo().GetDescription();7367 strLogString.Format("Moving escorting %s to target, X: %d, Y: %d", strTemp.GetCString(), pEscort->getX(), pEscort->getY());7368 LogTacticalMessage(strLogString);7369 strTemp = pCivilian->getUnitInfo().GetDescription();7370 strLogString.Format("Moving %s to target, X: %d, Y: %d", strTemp.GetCString(), pCivilian->getX(), pCivilian->getY());7371 LogTacticalMessage(strLogString);7372 }7373 }73747375 else7376 {7377 UnitHandle pBlockingUnit = pCivilianMove->getBestDefender(m_pPlayer->GetID());73787379 // See if friendly blocking unit is ending the turn there, or if no blocking unit (which indicates this is somewhere civilian7380 // can move that escort can't), then find a new path based on moving the escort7381 if(!pBlockingUnit || pBlockingUnit->getMoves() == 0)7382 {7383 if(!pEscort->GeneratePath(pTarget, 0, false /*bReuse*/))7384 {7385 pCivilian->finishMoves();7386 pEscort->finishMoves();7387 if(GC.getLogging() && GC.getAILogging())7388 {7389 CvString strLogString;7390 strLogString.Format("Retargeting civilian escort operation (path lost to target), X: %d, Y: %d", pTarget->getX(), pTarget->getY());7391 LogTacticalMessage(strLogString);7392 }7393 }7394 else7395 {7396 pEscortMove = pCivilian->GetPathEndTurnPlot();73977398 // See if civilian can move to the same location in one turn7399 if(TurnsToReachTarget(pCivilian, pEscortMove) <= 1)7400 {7401 ExecuteMoveToPlot(pEscort, pEscortMove);7402 ExecuteMoveToPlot(pCivilian, pEscortMove);7403 if(GC.getLogging() && GC.getAILogging())7404 {7405 CvString strTemp;7406 CvString strLogString;7407 strTemp = pEscort->getUnitInfo().GetDescription();7408 strLogString.Format("Moving escorting %s to target, X: %d, Y: %d", strTemp.GetCString(), pEscort->getX(), pEscort->getY());7409 LogTacticalMessage(strLogString);7410 strTemp = pCivilian->getUnitInfo().GetDescription();7411 strLogString.Format("Moving %s to target, X: %d, Y: %d", strTemp.GetCString(), pCivilian->getX(), pCivilian->getY());7412 LogTacticalMessage(strLogString);7413 }7414 }7415 else7416 {7417 pCivilian->finishMoves();7418 pEscort->finishMoves();7419 if(GC.getLogging() && GC.getAILogging())7420 {7421 CvString strLogString;7422 strLogString.Format("Retargeting civilian escort operation. Too many blocking units.");7423 LogTacticalMessage(strLogString);7424 }7425 }7426 }7427 }74287429 // Looks like we should be able to move the blocking unit out of the way7430 else7431 {7432 if(ExecuteMoveOfBlockingUnit(pBlockingUnit))7433 {7434 ExecuteMoveToPlot(pEscort, pCivilianMove);7435 ExecuteMoveToPlot(pCivilian, pCivilianMove);7436 if(GC.getLogging() && GC.getAILogging())7437 {7438 CvString strTemp;7439 CvString strLogString;7440 strTemp = pEscort->getUnitInfo().GetDescription();7441 strLogString.Format("Moving escorting %s to target, X: %d, Y: %d", strTemp.GetCString(), pEscort->getX(), pEscort->getY());7442 LogTacticalMessage(strLogString);7443 strTemp = pCivilian->getUnitInfo().GetDescription();7444 strLogString.Format("Moving %s to target, X: %d, Y: %d", strTemp.GetCString(), pCivilian->getX(), pCivilian->getY());7445 LogTacticalMessage(strLogString);7446 }7447 }7448 else7449 {7450 pCivilian->finishMoves();7451 pEscort->finishMoves();7452 if(GC.getLogging() && GC.getAILogging())7453 {7454 CvString strLogString;7455 strLogString.Format("Retargeting civilian escort operation. Could not move blocking unit.");7456 LogTacticalMessage(strLogString);7457 }7458 }7459 }7460 }7461 }7462 }7463 }7464 }7465 }7466 }7467}