Постройка в городе только одного здания из нескольких разных (Питон, на примере национальных религиозных святынь)

  1. Snake_B
    Snake_B
    Постройка в городе только одного здания из нескольких разных (Питон, на примере национальных религиозных святынь)...
    Civ4 BTS

    Дано: несколько зданий, строятся как национальное чудо (т.е. можно построить только одно такое здание в империи)...
    Нужно: сделать, чтобы при постройке такого здания для одной религии, другое здание (для другой религии) построить было нельзя...

    Изменения в файлах:
    1. Assets\XML\PythonCallbackDefines.xml
    Код:
     <Define>
      <DefineName>USE_CANNOT_HANDLE_ACTION_CALLBACK</DefineName>
      <iDefineIntVal>1</iDefineIntVal>
     </Define>
    2. Assets\Python\CvGameUtils.py

    Код:
    import CvUtil
    from CvPythonExtensions import *
    import CvEventInterface
    # religions NATIONAL_SHRINE RedForce.SB 1/2 - begin
    from PyHelpers import PyPlayer
    # religions NATIONAL_SHRINE RedForce.SB 1/2 - end
    # globals
    gc = CyGlobalContext()
    Код:
     def cannotHandleAction(self,argsList):
      pPlot = argsList[0]
      iAction = argsList[1]
      bTestVisible = argsList[2]
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - begin
    if gc.getActionInfo(iAction).getMissionType() == gc.getInfoTypeForString('MISSION_CONSTRUCT'):
    eBuilding = gc.getActionInfo(iAction).getMissionData()
    if gc.getBuildingInfo(eBuilding).getReligionType() > ReligionTypes.NO_RELIGION:
     iBUILDING_JEWISH_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_JEWISH_NATIONAL_SHRINE')
     iBUILDING_CHRISTIAN_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_CHRISTIAN_NATIONAL_SHRINE')
     iBUILDING_ISLAMIC_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_ISLAMIC_NATIONAL_SHRINE')
     iBUILDING_HINDU_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_HINDU_NATIONAL_SHRINE')
     iBUILDING_BUDDHIST_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_BUDDHIST_NATIONAL_SHRINE')
     iBUILDING_CONFUCIAN_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_CONFUCIAN_NATIONAL_SHRINE')
     iBUILDING_TAOIST_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_TAOIST_NATIONAL_SHRINE')
     if eBuilding == iBUILDING_JEWISH_NATIONAL_SHRINE or eBuilding == iBUILDING_CHRISTIAN_NATIONAL_SHRINE or eBuilding == iBUILDING_ISLAMIC_NATIONAL_SHRINE or eBuilding == iBUILDING_HINDU_NATIONAL_SHRINE or eBuilding == iBUILDING_BUDDHIST_NATIONAL_SHRINE or eBuilding == iBUILDING_CONFUCIAN_NATIONAL_SHRINE or eBuilding == iBUILDING_TAOIST_NATIONAL_SHRINE:
      pPlayer = CyGame().getActivePlayer()
      apCityList = PyPlayer(pPlayer).getCityList()
      for pLoopCity in apCityList:
       for iBuilding in range(gc.getNumBuildingInfos()):
        if iBuilding == iBUILDING_JEWISH_NATIONAL_SHRINE or iBuilding == iBUILDING_CHRISTIAN_NATIONAL_SHRINE or iBuilding == iBUILDING_ISLAMIC_NATIONAL_SHRINE or iBuilding == iBUILDING_HINDU_NATIONAL_SHRINE or iBuilding == iBUILDING_BUDDHIST_NATIONAL_SHRINE or iBuilding == iBUILDING_CONFUCIAN_NATIONAL_SHRINE or iBuilding == iBUILDING_TAOIST_NATIONAL_SHRINE:
         if pLoopCity.getNumBuilding(iBuilding) > 0:
          return True
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - end
      return False
    'BUILDING_JEWISH_NATIONAL_SHRINE' - из файла "CIV4BuildingInfos.xml"

    п.с. данный пример реализован совместными усилиями с NeseryozniyVET, за что ему отдельное спасибо
  2. NeseryozniyVET
    NeseryozniyVET
    pPlayer = CyGame().getActivePlayer() - это активный игрок. То есть им всегда будет хозяин кампа. ИИ сможет строить!!
    Игрок у которого активный ход находится так:
    Код:
    for iPlayer in range(gc.getMAX_CIV_PLAYERS()):
      pPlayer = gc.getPlayer(iPlayer)
      if pPlayer.isTurnActive():
        break
  3. Snake_B
    Snake_B
    Код:
     
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - begin
      if gc.getActionInfo(iAction).getMissionType() == gc.getInfoTypeForString('MISSION_CONSTRUCT'):
       eBuilding = gc.getActionInfo(iAction).getMissionData()
       if gc.getBuildingInfo(eBuilding).getReligionType() > ReligionTypes.NO_RELIGION:
        iBUILDING_JEWISH_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_JEWISH_NATIONAL_SHRINE')
        iBUILDING_CHRISTIAN_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_CHRISTIAN_NATIONAL_SHRINE')
        iBUILDING_ISLAMIC_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_ISLAMIC_NATIONAL_SHRINE')
        iBUILDING_HINDU_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_HINDU_NATIONAL_SHRINE')
        iBUILDING_BUDDHIST_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_BUDDHIST_NATIONAL_SHRINE')
        iBUILDING_CONFUCIAN_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_CONFUCIAN_NATIONAL_SHRINE')
        iBUILDING_TAOIST_NATIONAL_SHRINE = gc.getInfoTypeForString('BUILDING_TAOIST_NATIONAL_SHRINE')
        if eBuilding == iBUILDING_JEWISH_NATIONAL_SHRINE or eBuilding == iBUILDING_CHRISTIAN_NATIONAL_SHRINE or eBuilding == iBUILDING_ISLAMIC_NATIONAL_SHRINE or eBuilding == iBUILDING_HINDU_NATIONAL_SHRINE or eBuilding == iBUILDING_BUDDHIST_NATIONAL_SHRINE or eBuilding == iBUILDING_CONFUCIAN_NATIONAL_SHRINE or eBuilding == iBUILDING_TAOIST_NATIONAL_SHRINE:
         for iPlayer in range(gc.getMAX_CIV_PLAYERS()):
          pPlayer = gc.getPlayer(iPlayer)
          if pPlayer.isTurnActive():
           apCityList = PyPlayer(pPlayer).getCityList()
           for pLoopCity in apCityList:
            for iBuilding in range(gc.getNumBuildingInfos()):
             if iBuilding == iBUILDING_JEWISH_NATIONAL_SHRINE or iBuilding == iBUILDING_CHRISTIAN_NATIONAL_SHRINE or iBuilding == iBUILDING_ISLAMIC_NATIONAL_SHRINE or iBuilding == iBUILDING_HINDU_NATIONAL_SHRINE or iBuilding == iBUILDING_BUDDHIST_NATIONAL_SHRINE or iBuilding == iBUILDING_CONFUCIAN_NATIONAL_SHRINE or iBuilding == iBUILDING_TAOIST_NATIONAL_SHRINE:
              if pLoopCity.getNumBuilding(iBuilding) > 0:
               return True
           break
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - end
    так?
  4. NeseryozniyVET
    NeseryozniyVET
    Кстате, проверочный код можно ускорить. Для этого в файле Assets\XML\Buildings\CIV4SpecialBuildingInfos.XML надо создать новое спецздание SPECIALBUILDING_NATIONAL_SHRINE и указать его новым зданиям в теге <SpecialBuildingType> в CIV4BuildingInfos.XML
    Код:
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - begin
    if gc.getActionInfo(iAction).getMissionType() == gc.getInfoTypeForString('MISSION_CONSTRUCT'):
    	eBuilding = gc.getActionInfo(iAction).getMissionData()
    	eSPECIALBUILDING_NATIONAL_SHRINE = gc.getInfoTypeForString('SPECIALBUILDING_NATIONAL_SHRINE')
    	if gc.getBuildingInfo(eBuilding).getSpecialBuildingType() == eSPECIALBUILDING_NATIONAL_SHRINE:
    		for ePlayer in range(gc.getMAX_CIV_PLAYERS()):
    			pPlayer = gc.getPlayer(ePlayer)
    			if pPlayer.isTurnActive():
    				apCityList = PyPlayer(pPlayer).getCityList()
    				for pLoopCity in apCityList:
    					for eBuilding in range(gc.getNumBuildingInfos()):
    						if gc.getBuildingInfo(eBuilding).getSpecialBuildingType() == eSPECIALBUILDING_NATIONAL_SHRINE:
    							if pLoopCity.getNumBuilding(eBuilding) > 0:
    								return True
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - end
  5. Snake_B
    Snake_B
    apCityList = PyPlayer(pPlayer).getCityList()
    в этой строке даёт ошибку...
  6. NeseryozniyVET
    NeseryozniyVET
    Попробуй так
    Код:
    (pLoopCity, iter) = pPlayer.firstCity(false)
    while pLoopCity:
    	for eBuilding in range(gc.getNumBuildingInfos()):
    		if gc.getBuildingInfo(eBuilding).getSpecialBuildingType() == eSPECIALBUILDING_NATIONAL_SHRINE:
    			if pLoopCity.getNumBuilding(eBuilding) > 0:
    				return True
    	(pLoopCity, iter) = pPlayer.nextCity(iter, false)
  7. Snake_B
    Snake_B
    игра задумывается при попытке построить город...
  8. NeseryozniyVET
    NeseryozniyVET
    Что значит, задумывается?
  9. Snake_B
    Snake_B
    я так понимаю уходит в бесконечный цикл... загрузка процессора есть, резельтата нет...
  10. NeseryozniyVET
    NeseryozniyVET
    Попробуй так
    Код:
    iMax = pPlayer.getNumCities()
    iCity = 0
    (pLoopCity, iter) = pPlayer.firstCity(false)
    while pLoopCity:
    	iCity += 1
    	for eBuilding in range(gc.getNumBuildingInfos()):
    		if gc.getBuildingInfo(eBuilding).getSpecialBuildingType() == eSPECIALBUILDING_NATIONAL_SHRINE:
    			if pLoopCity.getNumBuilding(eBuilding) > 0:
    				return True
    	if iCity == iMax:
    		break
    	(pLoopCity, iter) = pPlayer.nextCity(iter, false)
  11. Snake_B
    Snake_B
    Код:
     
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - begin
      if gc.getActionInfo(iAction).getMissionType() == gc.getInfoTypeForString('MISSION_CONSTRUCT'):
       eBuilding = gc.getActionInfo(iAction).getMissionData()
       eSPECIALBUILDING_NATIONAL_SHRINE = gc.getInfoTypeForString('SPECIALBUILDING_NATIONAL_SHRINE')
       if gc.getBuildingInfo(eBuilding).getSpecialBuildingType() == eSPECIALBUILDING_NATIONAL_SHRINE:
        for ePlayer in range(gc.getMAX_CIV_PLAYERS()):
         pPlayer = gc.getPlayer(ePlayer)
         if pPlayer.isTurnActive():
          iMax = pPlayer.getNumCities()
          iCity = 0
          (pLoopCity, iter) = pPlayer.firstCity(false)
          while pLoopCity:
           iCity += 1
           for iBuilding in range(gc.getNumBuildingInfos()):
            if gc.getBuildingInfo(iBuilding).getSpecialBuildingType() == eSPECIALBUILDING_NATIONAL_SHRINE:
             if pLoopCity.getNumBuilding(iBuilding) > 0:
              return True
           if iCity == iMax:
            break
           (pLoopCity, iter) = pPlayer.nextCity(iter, false)
    # religions NATIONAL_SHRINE RedForce.SB 2/2 - end
    работает... вроде ))
Показано с 1 по 11 из 11
Настольные игры стратегии: Цивилизация Сида Мейера. Продажа в Украине. Сайт об играх серии Game-paradox К.О.Д. — браузерная массовая многопользовательская игра, сочетание стратегии и RPG (role-playing game)

Рейтинг@Mail.ru

free counters