def write(self, f, plot): "write out city data" city = plot.getPlotCity() CvUtil.pyAssert(city.isNone()==0, "null city?") f.write("\tBeginCity\n") f.write("\t\tCityOwner=%d\n" %(city.getOwner(),)) f.write("\t\tCityName=%s\n" %(city.getNameKey().encode(fileencoding),)) f.write("\t\tCityPopulation=%d\n" %(city.getPopulation(),)) if (city.isProductionUnit()): f.write("\t\tProductionUnit=%s\n" %(gc.getUnitInfo(city.getProductionUnit()).getType(),)) elif (city.isProductionBuilding()): f.write("\t\tProductionBuilding=%s\n" %(gc.getBuildingInfo(city.getProductionBuilding()).getType(),)) for iI in range(gc.getNumBuildingInfos()): if city.isHasRealBuilding(iI): f.write("\t\tBuildingType=%s\n" %(gc.getBuildingInfo(iI).getType())) for iI in range(city.getPopulation()): pUnit = city.getPopulationUnitByIndex(iI) f.write("\t\tCitizenType=%s\n" %(gc.getUnitInfo(pUnit.getUnitType()).getType())) if city.getScriptData(): f.write("\t\tScriptData=%s\n" %city.getScriptData()) # Player culture for iPlayerLoop in range(gc.getMAX_CIV_PLAYERS()): iPlayerCulture = city.getCulture(iPlayerLoop) if (iPlayerCulture > 0): f.write("\t\tPlayer%dCulture=%d\n" %(iPlayerLoop, iPlayerCulture)) f.write("\tEndCity\n")
def getDiplomacyComment(self, eComment): "Function to get the user String" debugString = "CvDiplomacy.getDiplomacyComment: %s" % (eComment, ) eComment = int(eComment) if DebugLogging: print debugString, eComment szString = "" szFailString = "Error***: No string found for eComment: %s" if (gc.getDiplomacyInfo(eComment)): DiplomacyTextInfo = gc.getDiplomacyInfo(eComment) if (not DiplomacyTextInfo): print "%s IS AN INVALID DIPLOCOMMENT" % (eComment, ) CvUtil.pyAssert( True, "CvDiplomacy.getDiplomacyComment: %s does not have a DiplomacyTextInfo" % (eComment, )) return szFailString % (eComment, ) szString = self.filterUserResponse(DiplomacyTextInfo) else: szString = szFailString % (eComment, ) return szString
def beginDiplomacy (argsList): """ This is what gets called when you first begin diplomacy The first parameter argsList[0] is the 'comment type', or how they feel about you """ eComment = argsList[0] commentArgsSize = argsList[1] if (commentArgsSize): commentArgs = argsList[2:] CvUtil.pyAssert(len(commentArgs)==commentArgsSize, "comment args tuple size mismatch") print "tuple size", len(commentArgs), ", commentArgsSize ", commentArgsSize else: commentArgs=[] # BUG - Diplomacy Events - start DiplomacyUtil.handleAIComment(eComment, commentArgs) # BUG - Diplomacy Events - end diploClass = CvDiplomacy.CvDiplomacy() diploClass.setAIComment(eComment, *commentArgs) #unpack args tuple
def apply(self): "after reading, this will actually apply the data" player = getPlayer(self.owner) if (player): CvUtil.pyAssert(self.plotX>=0 and self.plotY>=0, "invalid plot coords") unitTypeNum = CvUtil.findInfoTypeNum(self.unitType) if (unitTypeNum < 0): unit = None else: if (self.szUnitAIType != "NO_UNITAI"): eUnitAI = CvUtil.findInfoTypeNum(self.szUnitAIType) else: eUnitAI = UnitAITypes.NO_UNITAI unit = player.initUnit(unitTypeNum, ProfessionTypes.NO_PROFESSION, self.plotX, self.plotY, UnitAITypes(eUnitAI), self.facingDirection, self.iYieldStored) if (unit): #profession if(self.profession != None): unit.setProfession(CvUtil.findInfoTypeNum(self.profession)) #leader unit type if(self.leaderUnitType != None): leaderUnitTypeNum = CvUtil.findInfoTypeNum(self.leaderUnitType) if leaderUnitTypeNum >= 0: unit.setLeaderUnitType(leaderUnitTypeNum); #other properties if self.damage != 0: unit.setDamage(self.damage) if self.level != -1: unit.setLevel(self.level) if self.experience != -1: unit.setExperience(self.experience, -1) for promo in self.promotionType: promotionTypeNum = CvUtil.findInfoTypeNum(promo) unit.setHasRealPromotion(promotionTypeNum, true) if self.isSleep: unit.getGroup().setActivityType(ActivityTypes.ACTIVITY_SLEEP) if self.szScriptData != "NONE": unit.setScriptData(self.szScriptData)
def getDiplomacyComment (self, eComment): "Function to get the user String" debugString = "CvDiplomacy.getDiplomacyComment: %s" %(eComment,) eComment = int(eComment) if DebugLogging: print debugString, eComment szString = "" szFailString = "Error***: No string found for eComment: %s" if ( gc.getDiplomacyInfo(eComment) ): DiplomacyTextInfo = gc.getDiplomacyInfo(eComment) if ( not DiplomacyTextInfo ): print "%s IS AN INVALID DIPLOCOMMENT" %(eComment,) CvUtil.pyAssert(True, "CvDiplomacy.getDiplomacyComment: %s does not have a DiplomacyTextInfo" %(eComment,)) return szFailString %(eComment,) szString = self.filterUserResponse(DiplomacyTextInfo) else: szString = szFailString %(eComment,) return szString
def read(self, f, pX, pY): "read in unit data - at this point the first line 'BeginUnit' has already been read" self.__init__() self.plotX = pX self.plotY = pY CvUtil.pyAssert(self.plotX>=0 and self.plotY>=0, "invalid plot coords") parser = CvWBParser() while (true): nextLine = parser.getNextLine(f) toks = parser.getTokens(nextLine) if (len(toks)==0): break v = parser.findTokenValue(toks, "UnitType") vOwner = parser.findTokenValue(toks, "UnitOwner") if (v!=-1 and vOwner != -1): self.unitType = v self.owner = int(vOwner) continue v = parser.findTokenValue(toks, "Profession") if (v != -1): self.profession = v continue v = parser.findTokenValue(toks, "LeaderUnitType") if (v != -1): self.leaderUnitType = v continue v = parser.findTokenValue(toks, "Damage") if (v != -1): self.damage = (int(v)) continue v = parser.findTokenValue(toks, "Level") if (v != -1): self.level = (int(v)) self.experience = int(parser.findTokenValue(toks, "Experience")) continue # Units - Promotions v = parser.findTokenValue(toks, "PromotionType") if v!=-1: self.promotionType.append(v) continue v = parser.findTokenValue(toks, "FacingDirection") if (v != -1): self.facingDirection = (DirectionTypes(v)) continue if (parser.findTokenValue(toks, "Sleep"))!=-1: self.isSleep = True continue v = parser.findTokenValue(toks, "UnitAIType") if (v != -1): self.szUnitAIType = v continue v = parser.findTokenValue(toks, "ScriptData") if v!=-1: print("found script data: %s" %(v)) self.szScriptData = v continue v = parser.findTokenValue(toks, "YieldStored") if v != -1: self.iYieldStored = (int(v)) continue if parser.findTokenValue(toks, "EndUnit") != -1: break
def beginDiplomacy(argsList): """ This is what gets called when you first begin diplomacy The first parameter argsList[0] is the 'comment type', or how they feel about you """ global ShowOCA eComment = argsList[0] commentArgsSize = argsList[1] if (commentArgsSize): commentArgs = argsList[2:] CvUtil.pyAssert( len(commentArgs) == commentArgsSize, "comment args tuple size mismatch") print "tuple size", len( commentArgs), ", commentArgsSize ", commentArgsSize else: commentArgs = [] diploClass = CvDiplomacy.CvDiplomacy() screen = CyGInterfaceScreen("MainInterface", CvScreenEnums.MAIN_INTERFACE) iCenterX = screen.centerX(0) iY = screen.centerY(0) + 60 screen.addPanel("OCABackground1", "", "", True, True, iCenterX + 685, iY, 80, 455, PanelStyles.PANEL_STYLE_EMPTY) screen.addPanel("OCABackground2", "", "", True, True, iCenterX + 245, iY, 80, 455, PanelStyles.PANEL_STYLE_EMPTY) screen.hide("OCABackground1") screen.hide("OCABackground2") eGetActivePlayer = gc.getGame().getActivePlayer() iActiveTeam = gc.getPlayer(eGetActivePlayer).getTeam() eWhoTradingWith = CyDiplomacy().getWhoTradingWith() eTeamTradingWith = gc.getPlayer(eWhoTradingWith).getTeam() iPlayerCount = 0 for iLoopPlayer in xrange(gc.getMAX_PLAYERS()): eGetLoopPlayer = gc.getPlayer(iLoopPlayer) eGetLoopTeam = gc.getTeam(eGetLoopPlayer.getTeam()) if (iLoopPlayer != eWhoTradingWith and iLoopPlayer != eGetActivePlayer and eGetLoopPlayer.isAlive() and eGetLoopTeam.isHasMet(eTeamTradingWith) and (eGetLoopTeam.isHasMet(iActiveTeam) or gc.getGame().isDebugMode()) and not eGetLoopPlayer.isBarbarian() and not eGetLoopPlayer.isMinorCiv()): szPlayerCount = str(iPlayerCount) playerPanelName1 = "PlayerPanel1" + szPlayerCount szGFCName1 = "PLayerPanelGFC1" + szPlayerCount szTextName1 = "PLayerPanelText1" + szPlayerCount screen.attachPanel("OCABackground1", playerPanelName1, "", "", False, True, PanelStyles.PANEL_STYLE_EMPTY) screen.attachImageButton( playerPanelName1, szGFCName1, gc.getLeaderHeadInfo( eGetLoopPlayer.getLeaderType()).getButton(), GenericButtonSizes.BUTTON_SIZE_24, WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, eWhoTradingWith, False) if (eGetLoopTeam.isAtWar(eTeamTradingWith)): screen.addDDSGFCAt( szGFCName1 + "_1", playerPanelName1, ArtFileMgr.getInterfaceArtInfo( "CGE_RED_BUTTON_HILITE").getPath(), 20, 6, 24, 24, WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, eWhoTradingWith, True) screen.addDDSGFCAt( szTextName1, playerPanelName1, AttitudeFontMap[ eGetLoopPlayer.AI_getAttitude(eWhoTradingWith)], 45, 6, 20, 20, WidgetTypes.WIDGET_GENERAL, -1, -1, False) if (ShowOCA): playerPanelName2 = "PlayerPanel2" + szPlayerCount szGFCName2 = "PLayerPanelGFC2" + szPlayerCount szTextName2 = "PLayerPanelText2" + szPlayerCount screen.attachPanel("OCABackground2", playerPanelName2, "", "", False, True, PanelStyles.PANEL_STYLE_EMPTY) screen.attachImageButton( playerPanelName2, szGFCName2, gc.getLeaderHeadInfo( eGetLoopPlayer.getLeaderType()).getButton(), GenericButtonSizes.BUTTON_SIZE_24, WidgetTypes.WIDGET_LEADERHEAD, eWhoTradingWith, iLoopPlayer, False) screen.addDDSGFCAt( szTextName2, playerPanelName2, AttitudeFontMap[gc.getPlayer( eWhoTradingWith).AI_getAttitude(iLoopPlayer)], 45, 6, 20, 20, WidgetTypes.WIDGET_GENERAL, -1, -1, False) iPlayerCount += 1 if (iPlayerCount < 13): screen.setPanelSize("OCABackground1", iCenterX + 685, iY, 80, 35 * iPlayerCount) screen.show("OCABackground1") if (ShowOCA): if (iPlayerCount < 13): screen.setPanelSize("OCABackground2", iCenterX + 245, iY, 80, 35 * iPlayerCount) screen.show("OCABackground2") diploClass.setAIComment(eComment, *commentArgs) #unpack args tuple
def beginDiplomacy (argsList): """ This is what gets called when you first begin diplomacy The first parameter argsList[0] is the 'comment type', or how they feel about you """ global ShowOCA eComment = argsList[0] commentArgsSize = argsList[1] if (commentArgsSize): commentArgs = argsList[2:] CvUtil.pyAssert(len(commentArgs)==commentArgsSize, "comment args tuple size mismatch") print "tuple size", len(commentArgs), ", commentArgsSize ", commentArgsSize else: commentArgs=[] diploClass = CvDiplomacy.CvDiplomacy() screen = CyGInterfaceScreen( "MainInterface", CvScreenEnums.MAIN_INTERFACE ) iCenterX = screen.centerX(0) iY = screen.centerY(0) + 60 screen.addPanel("OCABackground1", "", "", True, True, iCenterX + 685, iY, 80, 455, PanelStyles.PANEL_STYLE_EMPTY) screen.addPanel("OCABackground2", "", "", True, True, iCenterX + 245, iY, 80, 455, PanelStyles.PANEL_STYLE_EMPTY) screen.hide("OCABackground1") screen.hide("OCABackground2") eGetActivePlayer = gc.getGame().getActivePlayer() iActiveTeam = gc.getPlayer(eGetActivePlayer).getTeam() eWhoTradingWith = CyDiplomacy().getWhoTradingWith() eTeamTradingWith = gc.getPlayer(eWhoTradingWith).getTeam() iPlayerCount = 0 for iLoopPlayer in xrange(gc.getMAX_PLAYERS()): eGetLoopPlayer = gc.getPlayer(iLoopPlayer) eGetLoopTeam = gc.getTeam(eGetLoopPlayer.getTeam()) if (iLoopPlayer != eWhoTradingWith and iLoopPlayer != eGetActivePlayer and eGetLoopPlayer.isAlive() and eGetLoopTeam.isHasMet(eTeamTradingWith) and (eGetLoopTeam.isHasMet(iActiveTeam) or gc.getGame().isDebugMode()) and not eGetLoopPlayer.isBarbarian() and not eGetLoopPlayer.isMinorCiv()): szPlayerCount = str(iPlayerCount) playerPanelName1 = "PlayerPanel1" + szPlayerCount szGFCName1 = "PLayerPanelGFC1" + szPlayerCount szTextName1 = "PLayerPanelText1" + szPlayerCount screen.attachPanel("OCABackground1", playerPanelName1, "", "", False, True, PanelStyles.PANEL_STYLE_EMPTY) screen.attachImageButton(playerPanelName1, szGFCName1, gc.getLeaderHeadInfo(eGetLoopPlayer.getLeaderType()).getButton(), GenericButtonSizes.BUTTON_SIZE_24, WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, eWhoTradingWith, False) if (eGetLoopTeam.isAtWar(eTeamTradingWith)): screen.addDDSGFCAt(szGFCName1 + "_1", playerPanelName1, ArtFileMgr.getInterfaceArtInfo("CGE_RED_BUTTON_HILITE").getPath(), 20, 6, 24, 24, WidgetTypes.WIDGET_LEADERHEAD, iLoopPlayer, eWhoTradingWith, True) screen.addDDSGFCAt(szTextName1, playerPanelName1, AttitudeFontMap[eGetLoopPlayer.AI_getAttitude(eWhoTradingWith)], 45, 6, 20, 20, WidgetTypes.WIDGET_GENERAL, -1, -1, False) if (ShowOCA): playerPanelName2 = "PlayerPanel2" + szPlayerCount szGFCName2 = "PLayerPanelGFC2" + szPlayerCount szTextName2 = "PLayerPanelText2" + szPlayerCount screen.attachPanel("OCABackground2", playerPanelName2, "", "", False, True, PanelStyles.PANEL_STYLE_EMPTY) screen.attachImageButton(playerPanelName2, szGFCName2, gc.getLeaderHeadInfo(eGetLoopPlayer.getLeaderType()).getButton(), GenericButtonSizes.BUTTON_SIZE_24, WidgetTypes.WIDGET_LEADERHEAD, eWhoTradingWith, iLoopPlayer, False) screen.addDDSGFCAt(szTextName2, playerPanelName2, AttitudeFontMap[gc.getPlayer(eWhoTradingWith).AI_getAttitude(iLoopPlayer)], 45, 6, 20, 20, WidgetTypes.WIDGET_GENERAL, -1, -1, False) iPlayerCount += 1 if (iPlayerCount < 13): screen.setPanelSize("OCABackground1", iCenterX + 685, iY, 80, 35*iPlayerCount) screen.show("OCABackground1") if (ShowOCA): if (iPlayerCount < 13): screen.setPanelSize("OCABackground2", iCenterX + 245, iY, 80, 35*iPlayerCount) screen.show("OCABackground2") diploClass.setAIComment(eComment, *commentArgs) #unpack args tuple