contactList = list()
for i in range(0, gc.getMAX_CIV_PLAYERS()) :
if( newPlayer.canContact( i ) ) :
contactList.append( i )
if( style == "Military" and not newPlayer.isMinorCiv() and not newPlayer.isHuman() ) :
# Declare war on prechosen target
if( (not iAttackPlayer == None) and iAttackPlayer >= 0 and iAttackPlayer < gc.getMAX_CIV_PLAYERS() ) :
newPlayer.AI_changeAttitudeExtra(iAttackPlayer, -5)
pyNewPlayer.getTeam().declareWar(gc.getPlayer(iAttackPlayer).getTeam(), True, WarPlanTypes.WARPLAN_TOTAL)
if( self.LOG_DEBUG ) : CvUtil.pyPrint(" BC - New civ declared war on the prechosen %s"%(PyPlayer(iAttackPlayer).getCivilizationName()))
else :
localWarChosen = (gc.getTeam(newPlayer.getTeam()).getAnyWarPlanCount(True) > 0)
area = newPlayer.getCapitalCity().area()
if( bNewWorldScenario and self.bFierceNatives ) :
# Fight any foreigners we can declare war on
for id in contactList :
playerI = gc.getPlayer(id)
capitalI = playerI.getCapitalCity()
if( (not area == None) and (not capitalI == None) ) :
if( not area.getID() == capitalI.area().getID() and playerI.getNumCities() > 3 ) :
if( area.getUnitsPerPlayer(id) > 2 or area.getCitiesPerPlayer(id) > 0 ) :
if( 50 > game.getSorenRandNum(100,'BarbarianCiv: attack colonists') ) :
newPlayer.AI_changeAttitudeExtra(id, -5)
pyNewPlayer.getTeam().declareWar(gc.getPlayer(id).getTeam(),True, WarPlanTypes.NO_WARPLAN)
if( self.LOG_DEBUG ) : CvUtil.pyPrint(" BC - New civ declared war on the foreign %s"%(PyPlayer(id).getCivilizationName()))
if( area.getCitiesPerPlayer(id) > 0 ) :
localWarChosen = True
if( pyNewPlayer.getTeam().getAnyWarPlanCount(True) > min([newPlayer.getNumCities()+1,4]) ) :
break
if( not localWarChosen ) :
# Give them some boats to go raiding!
if( self.LOG_DEBUG ) : CvUtil.pyPrint(" BC - No potential victim civ")
if( not iAssaultShip == UnitTypes.NO_UNIT ) :
for i,city in enumerate(cityList) :
if( city.GetCy().waterArea().getID() == gc.getMap().findBiggestArea(True).getID() ) :
if( self.LOG_DEBUG ) : CvUtil.pyPrint(" BC - Giving new civ some boats for raiding")
pyNewPlayer.initUnit(iAssaultShip,city.getX(),city.getY(),3)
newPlayer.initUnit(iAssaultShip,city.getX(),city.getY(),UnitAITypes.UNITAI_EXPLORE_SEA,DirectionTypes.DIRECTION_SOUTH )
break
SDTK.sdObjectSetVal( 'BarbarianCiv', newPlayer, 'DoSurpriseAttack', True )
warString = ""
for teamIdx in range(0,gc.getMAX_CIV_TEAMS()) :
if( not gc.getTeam(teamIdx).isMinorCiv() and pyNewPlayer.getTeam().isAtWar(teamIdx) ) :
warString += "%s, "%(gc.getTeam(teamIdx).getName())
if( self.LOG_DEBUG ) : CvUtil.pyPrint(" BC - New civ starting at war with (full only): " + warString)
SDTK.sdObjectSetVal( 'BarbarianCiv', newPlayer, 'SetupComplete', 1 )
# Add replay message
mess = localText.getText("TXT_KEY_BARBCIV_MINOR_SETTLE", ())%(leadName,newPlayer.getCivilizationAdjective(1),civName)
game.addReplayMessage( ReplayMessageTypes.REPLAY_MESSAGE_MAJOR_EVENT, newPlayer.getID(), mess, capital.getX(), capital.getY(), gc.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"))
# Announce the barb civ settling
if( self.LOG_BARB_SETTLE ) :
bodStr1 = localText.getText("TXT_KEY_BARBCIV_WORD_SPREADS", ())
bodStr2 = localText.getText("TXT_KEY_BARBCIV_MINOR_SETTLE", ())%(leadName,newPlayer.getCivilizationAdjective(1),civName)
bLaunchPopup = self.bBarbSettlePopup and (not self.blockPopupInAuto or game.getAIAutoPlay() == 0)
if( self.bNotifyOnlyClosePlayers ) :
bSentActiveMess = False
for idx in range(0,gc.getMAX_CIV_PLAYERS()) :
if( idx == newPlayer.getID() ) :
CyInterface().addMessage(idx, false, gc.getDefineINT("EVENT_MESSAGE_TIME"), localText.getText("TXT_KEY_BARBCIV_FULL_CIV", ()), None, InterfaceMessageTypes.MESSAGE_TYPE_MAJOR_EVENT, None, gc.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"), -1, -1, False, False)
continue
bSendMess = False
if( gc.getPlayer(idx).isAlive() and (idx in closePlayers or idx in contactList) ) :
bSendMess = True
elif( capital.plot().isRevealed(gc.getPlayer(idx).getTeam(),False) ) :
bSendMess = True
if( bSendMess ) :
CyInterface().addMessage(idx, false, gc.getDefineINT("EVENT_MESSAGE_TIME"), bodStr1 + " " + bodStr2, None, InterfaceMessageTypes.MESSAGE_TYPE_MAJOR_EVENT, None, gc.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"), -1, -1, False, False)
if( idx == game.getActivePlayer() ) :
bSentActiveMess = True
bLaunchPopup = (bLaunchPopup and bSentActiveMess)
else :
for idx in range(0,gc.getMAX_CIV_PLAYERS()) :
if( gc.getPlayer(idx).isAlive() ) :
if( idx == newPlayer.getID() ) :
CyInterface().addMessage(idx, false, gc.getDefineINT("EVENT_MESSAGE_TIME"), localText.getText("TXT_KEY_BARBCIV_FULL_CIV", ()), None, InterfaceMessageTypes.MESSAGE_TYPE_MAJOR_EVENT, None, gc.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"), -1, -1, False, False)
else :
CyInterface().addMessage(idx, false, gc.getDefineINT("EVENT_MESSAGE_TIME"), bodStr1 + " " + bodStr2, None, InterfaceMessageTypes.MESSAGE_TYPE_MAJOR_EVENT, None, gc.getInfoTypeForString("COLOR_HIGHLIGHT_TEXT"), -1, -1, False, False)
if( bLaunchPopup ) :
popup = PyPopup.PyPopup(RevDefs.barbSettlePopup,contextType = EventContextTypes.EVENTCONTEXT_ALL)
bodStr = bodStr1 + "\n\n" + bodStr2
if( self.offerControl ) :
bodStr += localText.getText("TXT_KEY_BARBCIV_SPREAD_OPT", ())%(leadName)
if( newPlayer.getID() == game.getActivePlayer() ) :
popup.setBodyString( localText.getText("TXT_KEY_BARBCIV_FULL_CIV", ()) )
popup.addButton( localText.getText("TXT_KEY_BARBCIV_OK", ()) )
else :
popup.setBodyString( bodStr )
popup.addButton( localText.getText("TXT_KEY_BARBCIV_OK", ()) )
if( self.offerControl ) :
popup.addButton(localText.getText("TXT_KEY_BARBCIV_OPT_AM", ())%(leadName))
self.newPlayerIdx = newPlayer.getID()
if( self.bCancelAutoForOffer ) :
game.setAIAutoPlay( 0 )
popup.launch(bCreateOkButton = False)
gc.getMap().verifyUnitValidPlot()
# Enable only for testing settling of barbcivs
if( False ) :
game.setAIAutoPlay( 0 )
iPrevHuman = game.getActivePlayer()
RevUtils.changeHuman( newPlayer.getID(), iPrevHuman )