Esempio n. 1
0
 def display(self,
             techType,
             techSubtype,
             selectCallback,
             selected=0,
             hullID=0):
     self.techID = OID_NONE
     self.selectCallback = selectCallback
     self.techType = techType
     self.techSubtype = techSubtype
     self.selected = selected
     if hullID:
         self.hullType = client.getFullTechInfo(hullID).combatClass
     else:
         self.hullType = 0
     self.typeFilter = ENGINE | SMALL | MEDIUM | LARGE | PLANET | OTHER
     self.win.vEngine.checked = self.typeFilter & ENGINE
     self.win.vSmall.checked = self.typeFilter & SMALL
     self.win.vMedium.checked = self.typeFilter & MEDIUM
     self.win.vLarge.checked = self.typeFilter & LARGE
     self.win.vPlanet.checked = self.typeFilter & PLANET
     self.win.vOther.checked = self.typeFilter & OTHER
     self.show()
     self.win.show()
     # register for updates
     if self not in gdata.updateDlgs:
         gdata.updateDlgs.append(self)
Esempio n. 2
0
 def _processProdQueue(self, planet):
     player = client.getPlayer()
     if planet.prodQueue and planet.effProdProd > 0:
         index = 0
         totalProd = 0
         for task in planet.prodQueue:
             if task.isShip:
                 tech = player.shipDesigns[task.techID]
             else:
                 tech = client.getFullTechInfo(task.techID)
             prodFirst, prodNext = self._getTaskProd(task, tech, planet.oid)
             if index == 0:
                 constrInfo = tech.name
                 etc = math.ceil(float(prodFirst) / planet.effProdProd)
             totalProd += prodFirst + prodNext
             index += 1
         etc = res.formatTime(etc)
         totalEtc = res.formatTime(math.ceil(float(totalProd) / planet.effProdProd))
     elif planet.prodQueue:
         task = planet.prodQueue[0]
         if task.isShip:
             tech = player.shipDesigns[task.techID]
         else:
             tech = client.getTechInfo(task.techID)
         constrInfo = tech.name
         etc = _('N/A')
         totalEtc = _("N/A")
     else:
         constrInfo = _("-")
         etc = "-"
         totalEtc = _("-")
     return constrInfo, etc, totalEtc
Esempio n. 3
0
    def showDesigns(self):
        player = client.getPlayer()
        # check if highlighted ship design exists
        if self.highlightedDesignID not in player.shipDesigns:
            self.highlightedDesignID = None
        # designs
        highlighted = None
        items = []
        for designID in player.shipDesigns:
            spec = player.shipDesigns[designID]

            countInService = self._getNumberInFleets(designID)
            countInBuild = self._getNumberInBuild(designID)

            # ui list item
            hullTech = client.getFullTechInfo(spec.hullID)
            item = ui.Item(spec.name,
                           tDesignID=designID,
                           tClass="%s/%s%d" %
                           (_(gdata.shipClasses[spec.combatClass][:1].upper()),
                            _("TL"), hullTech.level),
                           tNumber=countInService,
                           tInBuild=countInBuild)
            if spec.upgradeTo:
                item.foreground = gdata.sevColors[gdata.NONE]
            if designID == self.highlightedDesignID:
                highlighted = item
            items.append(item)
        self.win.vDesigns.items = items
        self.win.vDesigns.itemsChanged()
        self.win.vDesigns.highlightItem(highlighted, 0)
Esempio n. 4
0
    def showProdQueue(self, id):
        # construction queue
        prodQueue = self.player.prodQueues[id]
        items = []

        index = 0
        for task in prodQueue:
            if task.isShip:
                tech = self.player.shipDesigns[task.techID]
                icons = ((res.getShipImg(tech.combatClass, tech.isMilitary), ui.ALIGN_NONE),)
            else:
                tech = client.getFullTechInfo(task.techID)
                icons = ((res.getTechImg(task.techID), ui.ALIGN_NONE),)
            item = ui.Item(text = str(task.quantity), font = 'small', align = ui.ALIGN_NE, icons = icons, tooltipTitle = "", tooltip = tech.name, statustip = tech.name, index = index, const = tech.buildProd*task.quantity)
            if task.isShip:
                item.background = None
            else:
                item.background = (0x44, 0x44, 0x44)
            items.append(item)
            index += 1
        icons = ((res.getTechImg(1), ui.ALIGN_NONE),)
        item = ui.Item(_('New'), font = 'small-bold', align = ui.ALIGN_SW, icons = icons, index = None)
        items.append(item)
        self.vPQueues[id].items = items
        self.vPQueues[id].itemsChanged()
Esempio n. 5
0
 def calcDesign(self, designID, count=1, addHP=True):
     player = client.getPlayer()
     spec = player.shipDesigns[designID]
     size = spec.combatClass
     eqIDs = spec.weaponIDs  #equipment list
     for eqID in eqIDs:
         tech = client.getFullTechInfo(eqID)
         if tech.subtype == "seq_wpn":
             try:
                 level = player.techs[eqID]
             except:
                 level = 1  #tech not researched
             improvement = Rules.techImprEff[level]
             dmgMin = tech.weaponDmgMin * tech.weaponROF
             dmgMax = tech.weaponDmgMax * tech.weaponROF
             weaponclass = tech.weaponClass
             if self.showOnlyShieldPiercing and not tech.weaponIgnoreShield:
                 continue
             if size == 0:
                 self.sm_min[weaponclass] += int(count * dmgMin *
                                                 improvement)
                 self.sm_max[weaponclass] += int(count * dmgMax *
                                                 improvement)
             elif size == 1:
                 self.med_min[weaponclass] += int(count * dmgMin *
                                                  improvement)
                 self.med_max[weaponclass] += int(count * dmgMax *
                                                  improvement)
             elif size == 2:
                 self.lg_min[weaponclass] += int(count * dmgMin *
                                                 improvement)
                 self.lg_max[weaponclass] += int(count * dmgMax *
                                                 improvement)
     if addHP:
         if size == 0:
             self.sm['num'] += count
             self.sm['hp'] += spec.maxHP * count
             self.sm['sh'] += spec.shieldHP * count
         elif size == 1:
             self.med['num'] += count
             self.med['hp'] += spec.maxHP * count
             self.med['sh'] += spec.shieldHP * count
         elif size == 2:
             self.lg['num'] += count
             self.lg['hp'] += spec.maxHP * count
             self.lg['sh'] += spec.shieldHP * count
     if size == 0:
         self.sm['catt'] += spec.combatAtt * count
         self.sm['cdef'] += spec.combatDef * count
         self.sm['mdef'] += spec.missileDef * count
     elif size == 1:
         self.med['catt'] += spec.combatAtt * count
         self.med['cdef'] += spec.combatDef * count
         self.med['mdef'] += spec.missileDef * count
     elif size == 2:
         self.lg['catt'] += spec.combatAtt * count
         self.lg['cdef'] += spec.combatDef * count
         self.lg['mdef'] += spec.missileDef * count
     return size
Esempio n. 6
0
def getTechShortname(techid):
    try:
        tech = client.getFullTechInfo(techid)
        if (tech.shortname != ''):
            return tech.shortname
        return tech.name
    except:
        return _('Unknown')
Esempio n. 7
0
def getTechShortname(techid):
    try:
        tech = client.getFullTechInfo(techid)
        if (tech.shortname != ''):
            return tech.shortname
        return tech.name
    except:
        return _('Unknown')
Esempio n. 8
0
 def showDesigns(self):
     player = client.getPlayer()
     # check if highlighted ship design exists
     if self.highlightedDesignID not in player.shipDesigns:
         self.highlightedDesignID = None
     # designs
     highlighted = None
     items = []
     for designID in player.shipDesigns:
         spec = player.shipDesigns[designID]
         # number of ships with this design in fleet
         countInService = 0
         for fleetID in player.fleets:
             fleet = client.get(fleetID)
             for tmpDesignID, hp, shieldHP, exp in fleet.ships:
                 if tmpDesignID == designID:
                     countInService += 1
         hullTech = client.getFullTechInfo(spec.hullID)
         # number of ships in build queue
         countInBuild = 0
         for planetID in client.db.keys():
             planet = client.get(planetID, noUpdate=1)
             # skip non-planets
             if not hasattr(planet, "type") or planet.type != Const.T_PLANET \
                 or not hasattr(planet, 'owner') or not planet.owner == player.oid \
                 or not planet.prodQueue:
                 continue
             for task in planet.prodQueue:
                 if task.isShip and task.techID == designID:
                     countInBuild += task.quantity
         # plus ships in global queue
         for queue in player.prodQueues:
             for task in queue:
                 if task.isShip and task.techID == designID:
                     countInBuild += task.quantity
         # ui list item
         item = ui.Item(
             spec.name,
             tDesignID=designID,
             tClass="%s/%s%d" % (
                 _(gdata.shipClasses[spec.combatClass][:1].upper()),
                 _("TL"),
                 hullTech.level,
             ),
             tNumber=countInService,
             tInBuild=countInBuild)
         if spec.upgradeTo:
             item.foreground = gdata.sevColors[gdata.NONE]
         if designID == self.highlightedDesignID:
             highlighted = item
         items.append(item)
     self.win.vDesigns.items = items
     self.win.vDesigns.itemsChanged()
     self.win.vDesigns.highlightItem(highlighted, 0)
Esempio n. 9
0
	def calcDesign(self,designID,count=1,addHP=True):
		player = client.getPlayer()
		spec = player.shipDesigns[designID]
		size = spec.combatClass
		eqIDs = spec.weaponIDs #equipment list
		for eqID in eqIDs:
			tech = client.getFullTechInfo(eqID)
			if tech.subtype == "seq_wpn":
				try:
					level = player.techs[eqID]
				except:
					level = 1 #tech not researched
				improvement = Rules.techImprEff[level]
				dmgMin = tech.weaponDmgMin * tech.weaponROF
				dmgMax = tech.weaponDmgMax * tech.weaponROF
				weaponclass = tech.weaponClass
				if self.showOnlyShieldPiercing and not tech.weaponIgnoreShield:
					continue
				if size==0:
					self.sm_min[weaponclass] += int(count * dmgMin * improvement)
					self.sm_max[weaponclass] += int(count * dmgMax * improvement)
				elif size==1:
					self.med_min[weaponclass] += int(count * dmgMin * improvement)
					self.med_max[weaponclass] += int(count * dmgMax * improvement)
				elif size==2:
					self.lg_min[weaponclass] += int(count * dmgMin * improvement)
					self.lg_max[weaponclass] += int(count * dmgMax * improvement)
		if addHP:
			if size==0:
				self.sm['num'] += count
				self.sm['hp'] += spec.maxHP*count
				self.sm['sh'] += spec.shieldHP*count
			elif size==1:
				self.med['num'] += count
				self.med['hp'] += spec.maxHP*count
				self.med['sh'] += spec.shieldHP*count
			elif size==2:
				self.lg['num'] += count
				self.lg['hp'] += spec.maxHP*count
				self.lg['sh'] += spec.shieldHP*count
		if size==0:
			self.sm['catt'] += spec.combatAtt*count
			self.sm['cdef'] += spec.combatDef*count
			self.sm['mdef'] += spec.missileDef*count
		elif size==1:
			self.med['catt'] += spec.combatAtt*count
			self.med['cdef'] += spec.combatDef*count
			self.med['mdef'] += spec.missileDef*count
		elif size==2:
			self.lg['catt'] += spec.combatAtt*count
			self.lg['cdef'] += spec.combatDef*count
			self.lg['mdef'] += spec.missileDef*count
		return size
Esempio n. 10
0
 def showDesigns(self):
     player = client.getPlayer()
     # check if highlighted ship design exists
     if self.highlightedDesignID not in player.shipDesigns:
         self.highlightedDesignID = None
     # designs
     highlighted = None
     items = []
     for designID in player.shipDesigns:
         spec = player.shipDesigns[designID]
         # number of ships with this design in fleet
         countInService = 0
         for fleetID in player.fleets:
             fleet = client.get(fleetID)
             for tmpDesignID, hp, shieldHP, exp in fleet.ships:
                 if tmpDesignID == designID:
                     countInService += 1
         hullTech = client.getFullTechInfo(spec.hullID)
         # number of ships in build queue
         countInBuild = 0
         for planetID in client.db.keys():
             planet = client.get(planetID, noUpdate = 1)
             # skip non-planets
             if not hasattr(planet, "type") or planet.type != Const.T_PLANET \
                 or not hasattr(planet, 'owner') or not planet.owner == player.oid \
                 or not planet.prodQueue:
                 continue
             for task in planet.prodQueue:
                 if task.isShip and task.techID == designID:
                     countInBuild += task.quantity
         # plus ships in global queue
         for queue in player.prodQueues:
             for task in queue:
                 if task.isShip and task.techID == designID:
                     countInBuild += task.quantity
         # ui list item
         item = ui.Item(spec.name, tDesignID = designID,
             tClass = "%s/%s%d" % (
                 _(gdata.shipClasses[spec.combatClass][:1].upper()),_("TL"),
                 hullTech.level,
             ),
             tNumber = countInService,
             tInBuild = countInBuild
         )
         if spec.upgradeTo:
             item.foreground = gdata.sevColors[gdata.NONE]
         if designID == self.highlightedDesignID:
             highlighted = item
         items.append(item)
     self.win.vDesigns.items = items
     self.win.vDesigns.itemsChanged()
     self.win.vDesigns.highlightItem(highlighted, 0)
Esempio n. 11
0
 def display(self, techType, techSubtype, selectCallback, selected = 0, hullID = 0):
     self.techID = Const.OID_NONE
     self.selectCallback = selectCallback
     self.techType = techType
     self.techSubtype = techSubtype
     self.selected = selected
     if hullID:
         self.hullType = client.getFullTechInfo(hullID).combatClass
     else:
         self.hullType = 0
     self.typeFilter = ENGINE | \
                       SMALL | MEDIUM | LARGE | PLANET | \
                       OTHER | ARMOR | SHIELD | POD | SCANNER
     self.show()
     self.win.show()
     # register for updates
     if self not in gdata.updateDlgs:
         gdata.updateDlgs.append(self)
Esempio n. 12
0
    def _processResearchableTech(self, tech):
        player = client.getPlayer()

        item = ui.Item(tech.name, tLevel=tech.level, techID=tech.id)
        item.tStruct = '*' if getattr(tech, 'isStructure', None) else ''
        item.tShip = '*' if getattr(tech, 'isShipEquip', None) else ''

        neededSci = Utils.getTechRCost(player, tech.id)
        item.tETC = res.formatTime(
            float(neededSci) /
            player.effSciPoints) if player.effSciPoints > 0 else _("N/A")
        item.foreground = None

        if client.getFullTechInfo(
                tech.id
        ).finishResearchHandler == TechHandlers.finishResTLAdvance:
            item.foreground = gdata.sevColors[gdata.CRI]
        elif getattr(tech, "researchDisables", None):
            item.foreground = (0xff, 0xff, 0x00)
        return item
Esempio n. 13
0
 def show(self):
     self.precompute()
     keys = self._mines.keys()
     keys.sort()
     items = []
     for minetech in keys:
         num = self._mines[minetech]
         tech = client.getFullTechInfo(minetech)
         if tech.weaponIgnoreShield:
             igsh = _('Yes')
         else:
             igsh = _('No')
         items.append(
             ui.Item(tech.name,
                     tNum=num,
                     tMinDmg=tech.weaponDmgMin,
                     tMaxDmg=tech.weaponDmgMax,
                     tAtt=tech.weaponAtt,
                     tIS=igsh))
     self.win.vMines.items = items
     self.win.vMines.itemsChanged()
Esempio n. 14
0
	def show(self):
		self.precompute()
		keys = self._mines.keys()
		keys.sort()
		items = []
		for minetech in keys:
			num = self._mines[minetech]
			tech = client.getFullTechInfo(minetech)
			if tech.weaponIgnoreShield:
				igsh = _('Yes')
			else:
				igsh = _('No')
			items.append(ui.Item(tech.name,
				tNum = num,
				tMinDmg = tech.weaponDmgMin,
				tMaxDmg = tech.weaponDmgMax,
				tAtt = tech.weaponAtt,
				tIS = igsh
			))
		self.win.vMines.items = items
		self.win.vMines.itemsChanged()
Esempio n. 15
0
    def _processResearchQueueTask(self, task):
        player = client.getPlayer()
        tech = client.getTechInfo(task.techID)
        fulltech = client.getFullTechInfo(task.techID)
        researchSci = Utils.getTechRCost(player, task.techID, task.improvement)
        item = ui.Item(tech.name, techID=task.techID)
        item.tooltipTitle = _("Details")
        item.tooltip = _("Research points %d/%d, change %d pts/turn.") % (
            task.currSci, researchSci, task.changeSci)
        item.statustip = item.tooltip
        item.tImpToMax = "*" if task.improveToMax else ""
        item.tImproveToMax = task.improveToMax
        item.tProgress = _("%d %%") % int(
            task.currSci * 100 / researchSci) if task.currSci > 0 else _("-")
        totalSci = 0
        if task.changeSci > 0:
            etc = float(researchSci - task.currSci) / max(
                task.changeSci, player.effSciPoints)
            totalSci += researchSci - task.currSci
            if player.effSciPoints > 0:
                item.tETC = res.formatTime(etc)
            else:
                item.tETC = res.getNA()
        elif task.changeSci < 0:
            etc = -float(task.currSci) / min(task.changeSci,
                                             player.effSciPoints)
            item.tETC = _("[%s]") % res.formatTime(etc)
        elif player.effSciPoints > 0:
            etc = float(researchSci) / player.effSciPoints
            totalSci += researchSci
            item.tETC = res.formatTime(etc)
        else:
            item.tETC = res.getNA()

        if task.improveToMax:
            for impr in range(task.improvement + 1,
                              fulltech.maxImprovement + 1):
                totalSci += Utils.getTechRCost(player, task.techID, impr)
        item.tLevel = _("%d-%d") % (tech.level, task.improvement)
        return item, totalSci
Esempio n. 16
0
	def display(self, techType, techSubtype, selectCallback, selected = 0, hullID = 0):
		self.techID = OID_NONE
		self.selectCallback = selectCallback
		self.techType = techType
		self.techSubtype = techSubtype
		self.selected = selected
		if hullID:
			self.hullType = client.getFullTechInfo(hullID).combatClass
		else:
			self.hullType = 0
		self.typeFilter = ENGINE | SMALL | MEDIUM | LARGE | PLANET | OTHER
		self.win.vEngine.checked = self.typeFilter & ENGINE
		self.win.vSmall.checked = self.typeFilter & SMALL
		self.win.vMedium.checked = self.typeFilter & MEDIUM
		self.win.vLarge.checked = self.typeFilter & LARGE
		self.win.vPlanet.checked = self.typeFilter & PLANET
		self.win.vOther.checked = self.typeFilter & OTHER
		self.show()
		self.win.show()
		# register for updates
		if self not in gdata.updateDlgs:
			gdata.updateDlgs.append(self)
Esempio n. 17
0
    def showProdQueue(self, id):
        # construction queue
        prodQueue = self.player.prodQueues[id]
        items = []

        index = 0
        for task in prodQueue:
            if task.isShip:
                tech = self.player.shipDesigns[task.techID]
                icons = ((res.getShipImg(tech.combatClass,
                                         tech.isMilitary), ui.ALIGN_NONE), )
            else:
                tech = client.getFullTechInfo(task.techID)
                icons = ((res.getTechImg(task.techID), ui.ALIGN_NONE), )
            item = ui.Item(text=str(task.quantity),
                           font='small',
                           align=ui.ALIGN_NE,
                           icons=icons,
                           tooltipTitle="",
                           tooltip=tech.name,
                           statustip=tech.name,
                           index=index,
                           const=tech.buildProd * task.quantity)
            if task.isShip:
                item.background = None
            else:
                item.background = (0x44, 0x44, 0x44)
            items.append(item)
            index += 1
        icons = ((res.getTechImg(1), ui.ALIGN_NONE), )
        item = ui.Item(_('New'),
                       font='small-bold',
                       align=ui.ALIGN_SW,
                       icons=icons,
                       index=None)
        items.append(item)
        self.vPQueues[id].items = items
        self.vPQueues[id].itemsChanged()
Esempio n. 18
0
 def display(self,
             techType,
             techSubtype,
             selectCallback,
             selected=0,
             hullID=0):
     self.techID = Const.OID_NONE
     self.selectCallback = selectCallback
     self.techType = techType
     self.techSubtype = techSubtype
     self.selected = selected
     if hullID:
         self.hullType = client.getFullTechInfo(hullID).combatClass
     else:
         self.hullType = 0
     self.typeFilter = ENGINE | \
                       SMALL | MEDIUM | LARGE | PLANET | \
                       OTHER | ARMOR | SHIELD | POD | SCANNER
     self.show()
     self.win.show()
     # register for updates
     if self not in gdata.updateDlgs:
         gdata.updateDlgs.append(self)
Esempio n. 19
0
def getTechName(techID):
    try:
        return client.getFullTechInfo(techID).name
    except:
        return _('Unknown')
Esempio n. 20
0
def getTechShortname(techID):
    tech = client.getFullTechInfo(techID)
    try:
        return tech.shortname if tech.shortname else tech.name
    except:
        return _('Unknown')
Esempio n. 21
0
def getTechName(techid):
    try:
        tech = client.getFullTechInfo(techid)
        return tech.name
    except:
        return _('Unknown')
Esempio n. 22
0
def getTechName(techid):
    try:
        tech = client.getFullTechInfo(techid)
        return tech.name
    except:
        return _('Unknown')
Esempio n. 23
0
 def show(self):
     player = client.getPlayer()
     # title
     self.win.vRQueueTitle.text = _('Research queue [%d pts/turn]') % (
         player.effSciPoints,
     )
     self.win.title = _("Research [TL%d]") % player.techLevel
     # Known techs
     items = []
     #~researchable = {}
     disabled = []
     taskIDs = {}
     for task in player.rsrchQueue:
         taskIDs[task.techID] = None
     for techID in player.techs.keys():
         if techID in player.obsoleteTechs and not self.showObsolete:
             continue
         tech = client.getTechInfo(techID)
         improvement = player.techs[techID]
         item = ui.Item(tech.name,
             techID = techID,
             tLevel = '%d-%d' % (tech.level, improvement),
             tStruct = (' ', '*')[tech.isStructure],
             tShip = (' ', '*')[tech.isShipEquip],
         )
         if improvement < Rules.techMaxImprovement and improvement < tech.maxImprovement:
             neededSci = Utils.getTechRCost(player, techID)
             if player.effSciPoints > 0:
                 item.tETC = res.formatTime(float(neededSci) / player.effSciPoints)
             else:
                 item.tETC = _("N/A")
             found = 0
             if taskIDs.has_key(techID):
                 item.foreground = (0xd0, 0xd0, 0xd0)
             else:
                 item.foreground = None
         else:
             item.tETC = res.getNA()
             item.foreground = (0x80, 0x80, 0x80)
             if not self.showCompleted:
                 # skip this item
                 continue
         if techID in player.obsoleteTechs:
             item.foreground = (0x80, 0x40, 0x40)
         items.append(item)
         disabled.extend(tech.researchDisables)
         #~for improvement in range(1, improvement + 1):
         #~    for techID in tech.researchEnables[improvement]:
         #~        researchable[techID] = 1
     self.win.vKTechs.items = items
     self.win.vKTechs.itemsChanged()
     # Research queue
     items = []
     index = 0
     queueTechs = []
     total = 0
     for task in player.rsrchQueue:
         tech = client.getTechInfo(task.techID)
         fulltech = client.getFullTechInfo(task.techID)
         queueTechs.append(task.techID)
         item = ui.Item(tech.name, techID = task.techID, index = index)
         researchSci = Utils.getTechRCost(player, task.techID, task.improvement)
         maxImprovement = min(Rules.techMaxImprovement,fulltech.maxImprovement)
         maxImpTotalSci = 0
         if task.improveToMax and task.improvement < maxImprovement:
             for impr in range(task.improvement+1,maxImprovement+1):
                 maxImpTotalSci += Utils.getTechRCost(player, task.techID, impr)
         item.tooltipTitle = _("Details")
         item.tooltip = _("Research points %d/%d, change %d pts/turn.") % (task.currSci, researchSci, task.changeSci)
         item.statustip = item.tooltip
         item.tImpToMax = ["", "*"][task.improveToMax]
         item.tImproveToMax = task.improveToMax
         if task.currSci > 0:
             item.tProgress = _("%d %%") % int(task.currSci * 100 / researchSci)
         else:
             item.tProgress = _("-")
         if task.changeSci > 0:
             value = float(researchSci - task.currSci) / max(task.changeSci, player.effSciPoints)
             total += int(value + 1)
             if player.effSciPoints > 0:
                 total += float(maxImpTotalSci) / player.effSciPoints
                 item.tETC = res.formatTime(value)
             else:
                 total = 0
                 item.tETC = res.getNA()
         elif task.changeSci < 0:
             value = - float(task.currSci) / min(task.changeSci, player.effSciPoints)
             item.tETC = _("[%s]") % res.formatTime(value)
         elif player.effSciPoints > 0:
             value = float(researchSci) / player.effSciPoints
             total += int(value + 1)
             total += float(maxImpTotalSci) / player.effSciPoints
             item.tETC = res.formatTime(value)
         else:
             item.tETC = res.getNA()
         item.tLevel = _("%d-%d") % (tech.level, task.improvement)
         items.append(item)
         index += 1
     self.win.vRQueue.items = items
     self.win.vRQueue.itemsChanged()
     self.win.vRQueueTop.enabled = 0
     self.win.vRQueueUp.enabled = 0
     self.win.vRQueueDown.enabled = 0
     self.win.vRQueueAbort.enabled = 0
     self.win.vRQueueRepat.enabled = 0
     self.win.vRQueueRepat.pressed = 0
     self.win.vRQueueInfo.enabled = 0
     if total == 0:
         self.win.vRTotal.text = _("N/A")
     else:
         self.win.vRTotal.text = res.formatTime(total)
     # Researchable techs
     items = []
     for techID in client.getAllTechIDs():
         if player.techs.has_key(techID) or techID in queueTechs \
             or techID in disabled:
             continue
         # can check requirements
         tech = client.getTechInfo(techID)
         if not hasattr(tech, "partialData"):
             continue
         item = ui.Item(tech.name, tLevel = tech.level, techID = techID)
         if hasattr(tech, 'isStructure'): item.tStruct = ('', '*')[tech.isStructure]
         else: item.tStruct = ''
         if hasattr(tech, 'isShipEquip'): item.tShip = ('', '*')[tech.isShipEquip]
         else: item.tShip = ''
         if hasattr(tech, 'researchMod'):
             neededSci = Utils.getTechRCost(player, techID)
             if player.effSciPoints > 0:
                 item.tETC = res.formatTime(float(neededSci) / player.effSciPoints)
             else:
                 item.tETC = _("N/A")
             item.foreground = None
         else:
             item.tSci = res.getNA()
             item.foreground = (0xc0, 0xc0, 0xc0)
             # skip this item
             continue
         if hasattr(tech, "researchDisables") and tech.researchDisables:
             item.foreground = (0xff, 0xff, 0x00)
         if client.getFullTechInfo(techID).finishResearchHandler == TechHandlers.finishResTLAdvance:
             item.foreground = gdata.sevColors[gdata.CRI]
         items.append(item)
     self.win.vRTechs.items = items
     self.win.vRTechs.itemsChanged()
Esempio n. 24
0
 def show(self):
     player = client.getPlayer()
     #
     items = []
     for planetID in client.db.keys():
         planet = client.get(planetID, noUpdate = 1)
         # skip non-planets
         if not hasattr(planet, "type") or planet.type != T_PLANET:
             continue
         # shall be shown?
         ok = 0
         if hasattr(planet, 'owner'):
             if self.showMine and planet.owner == player.oid:
                 ok = 1
             if self.showOtherPlayers and planet.owner != OID_NONE and \
                 planet.owner != player.oid:
                 ok = 1
             if self.showColonizable and planet.owner == OID_NONE and \
                 planet.plType not in ('G', 'A'):
                 ok = 1
             if self.showUncolonizable and planet.plType in ('G', 'A'):
                 ok = 1
         elif hasattr(planet, 'plType'):
             if self.showColonizable and planet.plType not in ('G', 'A'):
                 ok = 1
             if self.showUncolonizable and planet.plType in ('G', 'A'):
                 ok = 1
         if not ok:
             continue
         # fill in data
         #rel = REL_UNDEF
         maxNA = 999999
         maxNone = 99999
         ownerID = OID_NONE
         if hasattr(planet, 'owner'):
             ownerID = planet.owner
             #if planet.owner != OID_NONE:
             #    rel = client.getRelationTo(planet.owner)
             if planet.owner == OID_NONE:
             #else:
                 owner = _('[Nobody]')
         if hasattr(planet, 'owner') and planet.owner == player.oid:
             if planet.prodQueue and planet.effProdProd > 0:
                 index = 0
                 totalEtc = 0
                 for task in planet.prodQueue:
                     if task.isShip:
                         tech = client.getPlayer().shipDesigns[task.techID]
                     else:
                         tech = client.getFullTechInfo(task.techID)
                     if index == 0:
                         constrInfo = tech.name
                     # etc
                     if task.targetID != planetID:
                         if index == 0:
                             etc = math.ceil(float(tech.buildProd * Rules.buildOnAnotherPlanetMod - task.currProd) / planet.effProdProd)
                             totalEtc += etc
                             totalEtc += math.ceil((task.quantity - 1) * float(tech.buildProd * Rules.buildOnAnotherPlanetMod) / planet.effProdProd)
                         else:
                             totalEtc += math.ceil(float(tech.buildProd * Rules.buildOnAnotherPlanetMod - task.currProd) / planet.effProdProd)
                             totalEtc += math.ceil((task.quantity - 1) * float(tech.buildProd * Rules.buildOnAnotherPlanetMod) / planet.effProdProd)
                     else:
                         if index == 0:
                             etc = math.ceil(float(tech.buildProd - task.currProd) / planet.effProdProd)
                             totalEtc += etc
                             totalEtc += math.ceil((task.quantity - 1)* float(tech.buildProd) / planet.effProdProd)
                         else:
                             totalEtc += math.ceil(task.quantity * float(tech.buildProd - task.currProd) / planet.effProdProd)
                             totalEtc += math.ceil((task.quantity - 1) * float(tech.buildProd) / planet.effProdProd)
                     index += 1
                 etc_raw = etc
                 etc = res.formatTime(etc)
                 totalEtc_raw = totalEtc
                 totalEtc = res.formatTime(totalEtc)
             elif planet.prodQueue:
                 task = planet.prodQueue[0]
                 if task.isShip:
                     tech = client.getPlayer().shipDesigns[task.techID]
                 else:
                     tech = client.getTechInfo(task.techID)
                 constrInfo = tech.name
                 etc = _('N/A')
                 etc_raw = maxNA
                 totalEtc = _("N/A")
                 totalEtc_raw = maxNA
             elif planet.effProdProd > 0:
                 constrInfo = _("-")
                 etc = "-"
                 etc_raw = 0
                 totalEtc = _("-")
                 totalEtc_raw = 0
             else:
                 constrInfo = _("-")
                 etc = "-"
                 etc_raw = maxNone
                 totalEtc = _("-")
                 totalEtc_raw = maxNone
         else:
             constrInfo = '?'
             etc = '?'
             etc_raw = maxNA
             totalEtc = '?'
             totalEtc_raw = maxNA
         # used slots
         if hasattr(planet, 'slots'):
             freeSlots = planet.plSlots - len(planet.slots)
         else:
             freeSlots = '?'
         # morale
         if hasattr(planet, "morale"):
             morale = int(planet.morale)
         else:
             morale = "?"
         #
         plType = gdata.planetTypes[getattr(planet, 'plType', None)]
         # list item
         item = ui.Item(
             getattr(planet, 'name', res.getUnknownName()),
             tPlType = _(plType),
             tPlBio = getattr(planet, 'plBio', '?'),
             tPlMin = getattr(planet, 'plMin', '?'),
             tPlEn = getattr(planet, 'plEn', '?'),
             tChangeBio = getattr(planet, 'changeBio', '?'),
             tChangeEn = getattr(planet, 'changeEn', '?'),
             tETC = etc,
             tETC_raw = etc_raw,
             tTotalETC = totalEtc,
             tTotalETC_raw = totalEtc_raw,
             tConstrInfo = constrInfo,
             tFree = freeSlots,
             tMorale = morale,
             tSpace = getattr(planet, 'plSlots', '?'),
             tDiam = getattr(planet, 'plDiameter',0)/1000,
             tProd = getattr(planet, 'effProdProd', '?'),
             tSci = getattr(planet, 'effProdSci', '?'),
             tPlanetID = planetID,
             #foreground = res.getFFColorCode(rel),
             foreground = res.getPlayerColor(ownerID),
         )
         items.append(item)
     self.win.vPlanets.items = items
     self.win.vPlanets.itemsChanged()
     # buttons
     self.win.vMine.pressed = self.showMine
     self.win.vOtherPlayers = self.showOtherPlayers
     self.win.vColonizable = self.showColonizable
     self.win.vUncolonizable = self.showUncolonizable
	def show(self):
		player = client.getPlayer()
		# check if selected ship design exists
		if self.selectedDesignID not in player.shipDesigns:
			self.selectedDesignID = None
		# designs
		items = []
		selected = None
		items = []
		for designID in player.shipDesigns:
			spec = player.shipDesigns[designID]
			# number of ships with this design in fleet
			countInService = 0
			for fleetID in player.fleets:
				fleet = client.get(fleetID)
				for tmpDesignID, hp, shieldHP, exp in fleet.ships:
					if tmpDesignID == designID:
						countInService += 1
			hullTech = client.getFullTechInfo(spec.hullID)
			# number of ships in build queue
			countInBuild = 0
			for planetID in client.db.keys():
				planet = client.get(planetID, noUpdate = 1)
				# skip non-planets
				if not hasattr(planet, "type") or planet.type != T_PLANET \
					or not hasattr(planet, 'owner') or not planet.owner == player.oid \
					or not planet.prodQueue:
					continue
				for task in planet.prodQueue:
					if task.isShip and task.techID == designID:
						countInBuild += task.quantity
			# ui list item
			item = ui.Item(spec.name, tDesignID = designID,
				tClass = "%s/%s%d" % (
					_(gdata.shipClasses[spec.combatClass][:1].upper()),_("TL"),
					hullTech.level,
				),
				tNumber = countInService,
				tInBuild = countInBuild
			)
			if spec.upgradeTo:
				item.foreground = gdata.sevColors[gdata.NONE]
			if designID == self.selectedDesignID:
				selected = item
			items.append(item)
		self.win.vDesigns.items = items
		self.win.vDesigns.itemsChanged()
		self.win.vDesigns.selectItem(selected)
		# compute
		if self.selectedDesignID == None:
			if self.ctrlID:
				eqIDs = {self.ctrlID : 1}
			else:
				eqIDs = {}
			for eqID in self.eqIDs:
				eqIDs[eqID] = self.eqIDs[eqID]
			improvements = []
			self.win.vUpgrade.enabled = 0
			self.win.vUpgrade.text = _("Upgrade")
			self.win.vScrap.enabled = 0
			self.win.vConstruct.enabled = 1
		else:
			spec = player.shipDesigns[self.selectedDesignID]
			self.hullID = spec.hullID
			eqIDs = spec.eqIDs
			improvements = spec.improvements
			self.win.vName.text = spec.name
			self.win.vHull.text = client.getTechInfo(self.hullID).name
			self.eqIDs = {}
			for eqID in eqIDs:
				tech = client.getTechInfo(eqID)
				if tech.subtype == "seq_ctrl":
					self.ctrlID = eqID
					self.win.vCtrl.text = tech.name
				else:
					self.eqIDs[eqID] = eqIDs[eqID]
			if player.shipDesigns[self.selectedDesignID].upgradeTo == 0:
				self.win.vUpgrade.enabled = 1
				self.win.vUpgrade.text = _("Upgrade")
			else:
				self.win.vUpgrade.enabled = 1
				self.win.vUpgrade.text = _("Cancel Upgrd")
			self.win.vScrap.enabled = 1
			self.win.vConstruct.enabled = 0
		try:
			result = ShipUtils.makeShipFullSpec(player, None, self.hullID, eqIDs, improvements)
		except GameException, e:
			self.win.setStatus(e.args[0])
			try:
				result = ShipUtils.makeShipFullSpec(player, None, self.hullID, eqIDs,
					improvements, raiseExs = False)
			except GameException:
				result = None
Esempio n. 26
0
 def show(self):
     player = client.getPlayer()
     #
     items = []
     for planetID in client.db.keys():
         planet = client.get(planetID, noUpdate=1)
         # skip non-planets
         if not hasattr(planet, "type") or planet.type != Const.T_PLANET:
             continue
         # shall be shown?
         ok = 0
         if hasattr(planet, 'owner'):
             if self.showMine and planet.owner == player.oid:
                 ok = 1
             if self.showOtherPlayers and planet.owner != Const.OID_NONE and \
                 planet.owner != player.oid:
                 ok = 1
             if self.showColonizable and planet.owner == Const.OID_NONE and \
                 planet.plType not in ('G', 'A'):
                 ok = 1
             if self.showUncolonizable and planet.plType in ('G', 'A'):
                 ok = 1
         elif hasattr(planet, 'plType'):
             if self.showColonizable and planet.plType not in ('G', 'A'):
                 ok = 1
             if self.showUncolonizable and planet.plType in ('G', 'A'):
                 ok = 1
         if not ok:
             continue
         # fill in data
         #rel = Const.REL_UNDEF
         maxNA = 999999
         maxNone = 99999
         ownerID = Const.OID_NONE
         if hasattr(planet, 'owner'):
             ownerID = planet.owner
             #if planet.owner != Const.OID_NONE:
             #    rel = client.getRelationTo(planet.owner)
             if planet.owner == Const.OID_NONE:
                 #else:
                 owner = _('[Nobody]')
         if hasattr(planet, 'owner') and planet.owner == player.oid:
             if planet.prodQueue and planet.effProdProd > 0:
                 index = 0
                 totalEtc = 0
                 for task in planet.prodQueue:
                     if task.isShip:
                         tech = client.getPlayer().shipDesigns[task.techID]
                     else:
                         tech = client.getFullTechInfo(task.techID)
                     if index == 0:
                         constrInfo = tech.name
                     # etc
                     if task.targetID != planetID:
                         if index == 0:
                             etc = math.ceil(
                                 float(tech.buildProd *
                                       Rules.buildOnAnotherPlanetMod -
                                       task.currProd) / planet.effProdProd)
                             totalEtc += etc
                             totalEtc += math.ceil(
                                 (task.quantity - 1) *
                                 float(tech.buildProd *
                                       Rules.buildOnAnotherPlanetMod) /
                                 planet.effProdProd)
                         else:
                             totalEtc += math.ceil(
                                 float(tech.buildProd *
                                       Rules.buildOnAnotherPlanetMod -
                                       task.currProd) / planet.effProdProd)
                             totalEtc += math.ceil(
                                 (task.quantity - 1) *
                                 float(tech.buildProd *
                                       Rules.buildOnAnotherPlanetMod) /
                                 planet.effProdProd)
                     else:
                         if index == 0:
                             etc = math.ceil(
                                 float(tech.buildProd - task.currProd) /
                                 planet.effProdProd)
                             totalEtc += etc
                             totalEtc += math.ceil(
                                 (task.quantity - 1) *
                                 float(tech.buildProd) / planet.effProdProd)
                         else:
                             totalEtc += math.ceil(
                                 task.quantity *
                                 float(tech.buildProd - task.currProd) /
                                 planet.effProdProd)
                             totalEtc += math.ceil(
                                 (task.quantity - 1) *
                                 float(tech.buildProd) / planet.effProdProd)
                     index += 1
                 etc_raw = etc
                 etc = res.formatTime(etc)
                 totalEtc_raw = totalEtc
                 totalEtc = res.formatTime(totalEtc)
             elif planet.prodQueue:
                 task = planet.prodQueue[0]
                 if task.isShip:
                     tech = client.getPlayer().shipDesigns[task.techID]
                 else:
                     tech = client.getTechInfo(task.techID)
                 constrInfo = tech.name
                 etc = _('N/A')
                 etc_raw = maxNA
                 totalEtc = _("N/A")
                 totalEtc_raw = maxNA
             elif planet.effProdProd > 0:
                 constrInfo = _("-")
                 etc = "-"
                 etc_raw = 0
                 totalEtc = _("-")
                 totalEtc_raw = 0
             else:
                 constrInfo = _("-")
                 etc = "-"
                 etc_raw = maxNone
                 totalEtc = _("-")
                 totalEtc_raw = maxNone
         else:
             constrInfo = '?'
             etc = '?'
             etc_raw = maxNA
             totalEtc = '?'
             totalEtc_raw = maxNA
         # used slots
         if hasattr(planet, 'slots'):
             freeSlots = planet.plSlots - len(planet.slots)
         else:
             freeSlots = '?'
         # morale
         if hasattr(planet, "morale"):
             morale = int(planet.morale)
         else:
             morale = "?"
         #
         plType = gdata.planetTypes[getattr(planet, 'plType', None)]
         # list item
         item = ui.Item(
             getattr(planet, 'name', res.getUnknownName()),
             tPlType=_(plType),
             tPlBio=getattr(planet, 'plBio', '?'),
             tPlMin=getattr(planet, 'plMin', '?'),
             tPlEn=getattr(planet, 'plEn', '?'),
             tChangeBio=getattr(planet, 'changeBio', '?'),
             tChangeEn=getattr(planet, 'changeEn', '?'),
             tETC=etc,
             tETC_raw=etc_raw,
             tTotalETC=totalEtc,
             tTotalETC_raw=totalEtc_raw,
             tConstrInfo=constrInfo,
             tFree=freeSlots,
             tMorale=morale,
             tSpace=getattr(planet, 'plSlots', '?'),
             tDiam=getattr(planet, 'plDiameter', 0) / 1000,
             tProd=getattr(planet, 'effProdProd', '?'),
             tSci=getattr(planet, 'effProdSci', '?'),
             tPlanetID=planetID,
             #foreground = res.getFFColorCode(rel),
             foreground=res.getPlayerColor(ownerID),
         )
         items.append(item)
     self.win.vPlanets.items = items
     self.win.vPlanets.itemsChanged()
     # buttons
     self.win.vMine.pressed = self.showMine
     self.win.vOtherPlayers = self.showOtherPlayers
     self.win.vColonizable = self.showColonizable
     self.win.vUncolonizable = self.showUncolonizable
Esempio n. 27
0
    def show(self):
        critical = self.win.vCritical.checked
        major = self.win.vMajor.checked
        minor = self.win.vMinor.checked
        info = self.win.vInfo.checked

        disp = 1

        player = client.getPlayer()
        items = []
        # object list (all player's objects + systems)
        objects = player.fleets[:]
        objects += player.planets[:]
        systems = {}
        for planetID in player.planets:
            planet = client.get(planetID)
            if planet.compOf not in systems:
                systems[planet.compOf] = None
        objects += systems.keys()

        # counting construction points value of each global production queue
        # holder for (number , eff production) of planets set to each queue
        globalQueueStats=[(0,0), (0,0), (0,0), (0,0), (0,0)]
        prodQueueProblems = []


        # go through all objects
        for objID in objects:
            if objID < OID_FREESTART:
                continue
            obj = client.get(objID, noUpdate = 1)
            if not hasattr(obj, "type"):
                continue
            if obj.type == T_SYSTEM:
                if not hasattr(obj, 'planets'):
                    continue
                bio = 0
                totalBio = 0
                en = 0
                totalEn = 0
                buildingQuantity = {}
                buildingInfo = {}
                # holds modified planets
                planetCopies = {}

                for planetID in obj.planets:
                    planet = client.get(planetID, noUpdate = 1)
                    # copy of planet to change plSlots count
                    if not planetID in planetCopies:
                        cPlanet = copy.deepcopy(planet)
                        planetCopies[planetID] = cPlanet
                    else:
                        cPlanet = planetCopies[planetID]
                    if hasattr(planet, 'owner') and planet.owner == player.oid:
                        queuePlanetNumber, queueEffProd = globalQueueStats[planet.globalQueue]
                        queuePlanetNumber += 1
                        queueEffProd += planet.effProdProd
                        globalQueueStats[planet.globalQueue] = (queuePlanetNumber, queueEffProd)
                        # compute bio and en for system
                        bio += planet.changeBio
                        totalBio += max(0, planet.storBio - planet.minBio)
                        en  += planet.changeEn
                        totalEn += max(0, planet.storEn - planet.minEn)
                        # the planet needs to have global queue 0 - the default one - to have its queue reported
                        if hasattr(planet, 'prodQueue') and self.win.vPlanets.checked and not planet.globalQueue:
                            totalEtc = 0
                            # compute length of production queue
                            if cPlanet.prodQueue and cPlanet.effProdProd > 0:
                                for task in cPlanet.prodQueue:
                                    if task.isShip:
                                        tech = client.getPlayer().shipDesigns[task.techID]
                                    else:
                                        tech = client.getFullTechInfo(task.techID)
                                        if tech.isStructure and hasattr(task, "demolishStruct") and task.demolishStruct == 0:
                                            # total count of constructing buildings on target
                                            if buildingQuantity.has_key(task.targetID):
                                                buildingQuantity[task.targetID] += task.quantity
                                            else:
                                                buildingQuantity[task.targetID] = task.quantity

                                            # information about source and target of constructing
                                            if buildingInfo.has_key((planetID, task.targetID)):
                                                buildingInfo[(planetID, task.targetID)] += task.quantity
                                            else:
                                                buildingInfo[(planetID, task.targetID)] = task.quantity
                                        elif tech.isProject and tech.id == 3802:
                                            # we are constructing Habitable Surface Expansion
                                            # so after construction we got some new slots on planet
                                            if not task.targetID in planetCopies:
                                                targetPlanet = client.get(task.targetID, noUpdate = 1)
                                                cPlanet = copy.deepcopy(targetPlanet)
                                                planetCopies[task.targetID] = cPlanet

                                            planetCopies[task.targetID].plSlots += task.quantity

                                    if task.targetID != planetID:
                                        totalEtc += math.ceil(float(tech.buildProd * Rules.buildOnAnotherPlanetMod - task.currProd) / planet.effProdProd)
                                        totalEtc += math.ceil((task.quantity - 1) * float(tech.buildProd * Rules.buildOnAnotherPlanetMod) / planet.effProdProd)
                                    else:
                                        totalEtc += math.ceil(task.quantity * float(tech.buildProd - task.currProd) / planet.effProdProd)
                                        totalEtc += math.ceil((task.quantity - 1) * float(tech.buildProd) / planet.effProdProd)
                            else:
                                totalEtc = 99999

                            prodQueueProblems.append((planetID, totalEtc, len(planet.prodQueue)))


                        # check for structures status
                        if hasattr(planet, 'slots') and self.win.vPlanets.checked:
                            for struct in planet.slots:
                                status = struct[STRUCT_IDX_STATUS]
                                problem = None
                                tech = client.getFullTechInfo(struct[STRUCT_IDX_TECHID])

                                if hasattr(player, 'techs'):
                                    techEff = Rules.techImprEff[player.techs.get(struct[STRUCT_IDX_TECHID], Rules.techBaseImprovement)]
                                else:
                                    techEff = Rules.techImprEff[Rules.techBaseImprovement]

                                HPturn = max(1, int(0.02 * tech.maxHP * techEff))
                                turnsToDestroy = math.ceil(struct[STRUCT_IDX_HP] / HPturn)

                                if turnsToDestroy < 48:
                                    dispDestr = major
                                    fgColorDestr = gdata.sevColors[gdata.MAJ]
                                    if turnsToDestroy < 24:
                                        dispDestr = critical
                                        fgColorDestr = gdata.sevColors[gdata.CRI]
                                else:
                                    dispDestr = minor
                                    fgColorDestr = None

                                if not status & STRUCT_STATUS_ON:
                                    # structure is off
                                    if dispDestr:
                                        items.append(ui.Item(planet.name, tOID = planetID, tType = T_PLANET, foreground = fgColorDestr,
                                            vDescription = _('Structure (%s) is off and will be destroyed in %s turns.') % (tech.name, res.formatTime(turnsToDestroy))))

                                elif status & STRUCT_STATUS_DETER:
                                    problem = _('is deteriorating and will be destroyed in %s turns') % res.formatTime(turnsToDestroy)
                                    disp = major
                                    fgColor = gdata.sevColors[gdata.MAJ]
                                elif status & STRUCT_STATUS_NOBIO:
                                    problem = _('has insufficient supply of biomatter')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]
                                elif status & STRUCT_STATUS_NOEN:
                                    problem = _('has insufficient supply of energy')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]
                                elif status & STRUCT_STATUS_NOPOP:
                                    problem = _('has insufficient supply of workers')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]
                                elif status & STRUCT_STATUS_REPAIRING:
                                    problem = _('is repairing')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]

                                if problem and disp:
                                    items.append(ui.Item(planet.name, tOID = planetID, tType = T_PLANET, foreground = fgColor,
                                        vDescription = _('Structure (%s) %s.') % (tech.name, problem)))

                for planetID, quantity in buildingQuantity.items():
                    planet = planetCopies[planetID]
                    # test, if there is total quantity of building as target for this planet
                    if planet.plSlots < len(planet.slots) + quantity and major:
                        # walk infos and search for all planets, that are building
                        # on planet founded above
                        for (sourceID, targetID), quantity in buildingInfo.items():
                            if planetID == targetID:
                                source = client.get(sourceID, noUpdate = 1)
                                items.append(ui.Item(source.name, tOID = sourceID, tType = T_PLANET, foreground = gdata.sevColors[gdata.MAJ],
                                            vDescription = _('There is no space for all constructed buildings on %s.') % (planet.name)))

                # check bio for system
                if bio < 0 and self.win.vSystems.checked:
                    disp = minor
                    fgColor = None
                    surplusTurns = totalBio / (-bio)
                    if surplusTurns < 168:
                        disp = major
                        fgColor = gdata.sevColors[gdata.MAJ]
                    if surplusTurns < 48:
                        disp = critical
                        fgColor = gdata.sevColors[gdata.CRI]

                    if disp:
                        if totalBio > 0:
                            items.append(ui.Item(obj.name, tOID = obj.oid, tType = T_SYSTEM, foreground = fgColor,
                                         vDescription = _('Bio decreasing - last turn change %d, surplus %d (%s).') % (bio, totalBio,res.formatTime(surplusTurns))))
                        else:
                            items.append(ui.Item(obj.name, tOID = obj.oid, tType = T_SYSTEM, foreground = fgColor,
                                         vDescription = _('Bio decreasing - last turn change %d, surplus %d.') % (bio, totalBio)))

                #check en for system
                if en < 0 and self.win.vSystems.checked:
                    disp = minor
                    fgColor = None
                    surplusTurns = totalEn / (-en)
                    if surplusTurns < 168:
                        disp = major
                        fgColor = gdata.sevColors[gdata.MAJ]
                    if surplusTurns < 48:
                        disp = critical
                        fgColor = gdata.sevColors[gdata.CRI]

                    if disp:
                        if totalEn > 0:
                            items.append(ui.Item(obj.name, tOID = obj.oid, tType = T_SYSTEM, foreground = fgColor,
                                        vDescription = _('Energy decreasing - last turn change %d, surplus %d (%s).') % (en, totalEn,res.formatTime(surplusTurns))))
                        else:
                            items.append(ui.Item(obj.name, tOID = obj.oid, tType = T_SYSTEM, foreground = fgColor,
                                         vDescription = _('Energy decreasing - last turn change %d, surplus %d.') % (en, totalEn)))

            # check fleets
            elif obj.type == T_FLEET and self.win.vFleets.checked:
                if hasattr(obj, 'owner') and obj.owner == player.oid:
                    energyReserve = obj.storEn  * 100 / obj.maxEn
                    system = None
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]
                    note = _(' and IS NOT refueling')

                    maxRefuelMax = 0
                    if hasattr(obj, 'orbiting') and obj.orbiting:
                        system = client.get(obj.orbiting, noUpdate = 1)
                        if hasattr(system, 'planets'):
                            for planetID in system.planets:
                                planet = client.get(planetID, noUpdate = 1)
                                if hasattr(planet, 'owner') and hasattr(planet, 'refuelMax'):
                                    if player.diplomacyRels.has_key(planet.owner):
                                        dipl = client.getDiplomacyWith(planet.owner)
                                        if dipl.pacts.has_key(PACT_ALLOW_TANKING) and dipl.pacts[PACT_ALLOW_TANKING][0] == PACT_ACTIVE:
                                            maxRefuelMax = max(maxRefuelMax, planet.refuelMax)
                                    else:
                                        if planet.owner == player.oid:
                                            maxRefuelMax = max(maxRefuelMax, planet.refuelMax)

                            if maxRefuelMax > 0:
                                disp = info
                                fgColor = gdata.sevColors[gdata.INFO]
                                note = _(' and IS refueling')
                                if maxRefuelMax <= energyReserve:
                                    note = _(' and CAN refuel, but reach planet maximum refuel amount')

                    else:
                        continue

                    systemName = res.getUnknownName()
                    if system and hasattr(system, "name"):
                        systemName = system.name

                    # check fleets energy reserve
                    if energyReserve < 50 and maxRefuelMax == 0:
                        disp = major
                        fgColor = gdata.sevColors[gdata.MAJ]
                        if energyReserve < 25 and maxRefuelMax == 0:
                            disp = critical
                            fgColor = gdata.sevColors[gdata.CRI]
                    else:
                        fgColor = gdata.sevColors[gdata.INFO]
                        disp = info

                    # is fleet named?
                    if hasattr(obj,'customname') and obj.customname:
                        name = obj.customname
                    else:
                        name = getattr(obj, "name", None)

                    if energyReserve == 100 and info and disp:
                        items.append(ui.Item(systemName, tOID = obj.oid, tType = T_FLEET,foreground = gdata.sevColors[gdata.INFO],
                                    vDescription = _('Fleet "%s" has full fuel tanks.') % (name)))
                    elif disp:
                        items.append(ui.Item(systemName, tOID = obj.oid, tType = T_FLEET,foreground = fgColor,
                                    vDescription = _('Fleet "%s" is low on fuel [%d %%]%s.') % (name, energyReserve, note)))


        queConstValues = [0, 0, 0, 0, 0]
        queEtc = [0, 0, 0, 0, 0]
        for queue in xrange(5):
            quePlanets, queEffProd = globalQueueStats[queue]
            for task in player.prodQueues[queue]:
                if task.isShip:
                    tech = client.getPlayer().shipDesigns[task.techID]
                else:
                    tech = client.getFullTechInfo(task.techID)
                queConstValues[queue] += task.quantity * tech.buildProd
            if queEffProd > 0:
                queEtc[queue] = math.ceil(float(queConstValues[queue])/queEffProd)
            else:
                queEtc[queue] = 99999

        # creation of items with production queue [default one] problems
        for planetID, totalEtc, queueLen in prodQueueProblems:
            planet = client.get(planetID, noUpdate = 1)

            # check empty production queue
            if queueLen == 0 and planet.effProdProd > 0 and queConstValues[0] == 0 and critical:
                items.append(ui.Item(planet.name, tOID = planetID, tType = T_PLANET,
                    foreground = gdata.sevColors[gdata.CRI],
                    vDescription = _('Production queue is empty.')))

            # check end of production queue
            if totalEtc+queEtc[0] < 48:
                fgColor = None
                disp = minor
                if totalEtc+queEtc[0] < 24:
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]
                    if disp:
                        items.append(ui.Item(planet.name, tOID = planetID, tType = T_PLANET, foreground = fgColor,
                            vDescription = _('Production queue may end in {0} turns ({1} directly in planet queue), {2} item(s) on list.'.format(res.formatTime(totalEtc+queEtc[0]), res.formatTime(totalEtc), queueLen))))

        # creation of items with global queue problems
        for queue in xrange(1, 5):
            queName = res.globalQueueName(queue)
            quePlanets = globalQueueStats[queue][0]
            # check empty global production queue with at least one planet [so its relevant]
            if queConstValues[queue] == 0 and  quePlanets > 0 and critical:
                items.append(ui.Item(_('Global queue ' + queName), tType = T_QUEUE,
                    foreground = gdata.sevColors[gdata.CRI],
                    vDescription = _('Global production queue {0} used by {1} planet(s) is empty.'.format(queName, quePlanets))))

            # check end of global production queue
            elif queEtc[queue] < 48:
                fgColor = None
                disp = minor
                if queEtc[queue] < 24:
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]
                if disp:
                    items.append(ui.Item(_('Global queue ' + queName), tType = T_QUEUE, foreground = fgColor,
                        vDescription = _('Global production queue {0} used by {1} planet(s) runs out in {2} turns.'.format(queName, quePlanets, res.formatTime(queEtc[queue])))))

        # check research queue
        if self.win.vResearch.checked:
            totalEtc = 0
            # compute length of research queue
            for task in player.rsrchQueue:
                tech = client.getTechInfo(task.techID)
                fulltech = client.getFullTechInfo(task.techID)
                researchSci = Utils.getTechRCost(player, task.techID, task.improvement)
                maxImprovement = min(Rules.techMaxImprovement,fulltech.maxImprovement)
                maxImpTotalSci = 0
                if task.improveToMax and task.improvement < maxImprovement:
                    for impr in range(task.improvement+1,maxImprovement+1):
                        maxImpTotalSci += Utils.getTechRCost(player, task.techID, impr)
                if task.changeSci > 0:
                    value = float(researchSci - task.currSci) / max(task.changeSci, player.effSciPoints)
                    totalEtc += int(value + 1)
                    if player.effSciPoints != 0:
                        totalEtc += float(maxImpTotalSci) / player.effSciPoints
                elif task.changeSci < 0:
                    totalEtc -= float(task.currSci) / min(task.changeSci, player.effSciPoints)
                elif player.effSciPoints > 0:
                    value = float(researchSci) / player.effSciPoints
                    totalEtc += int(value + 1)
                    totalEtc += float(maxImpTotalSci) / player.effSciPoints
                else:
                    totalEtc = 99999
                    break

            # check empty research queue
            if totalEtc == 0 and len(player.rsrchQueue) == 0 and player.effSciPoints > 0 and major:
                items.append(ui.Item(_('Research'), tType = T_TECHNOLOGY, foreground = gdata.sevColors[gdata.MAJ],
                    vDescription = _('Research queue is empty.')))
            # check short reseach queue
            elif totalEtc < 48:
                disp = minor
                fgColor = None
                if totalEtc < 24:
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]

                if disp:
                    items.append(ui.Item(_('Research'), tType = T_TECHNOLOGY, foreground = fgColor,
                                vDescription = _('Research queue ends in %s turns, %d item(s) on list.') % (res.formatTime(totalEtc), len(player.rsrchQueue))))

        self.win.vProblems.items = items
        self.win.vProblems.itemsChanged()
Esempio n. 28
0
    def show(self):
        critical = self.win.vCritical.checked
        major = self.win.vMajor.checked
        minor = self.win.vMinor.checked
        info = self.win.vInfo.checked

        disp = 1

        player = client.getPlayer()
        items = []
        # object list (all player's objects + systems)
        objects = player.fleets[:]
        objects += player.planets[:]
        systems = {}
        for planetID in player.planets:
            planet = client.get(planetID)
            if planet.compOf not in systems:
                systems[planet.compOf] = None
        objects += systems.keys()

        # counting construction points value of each global production queue
        # holder for (number , eff production) of planets set to each queue
        globalQueueStats = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
        prodQueueProblems = []

        # go through all objects
        for objID in objects:
            if objID < Const.OID_FREESTART:
                continue
            obj = client.get(objID, noUpdate=1)
            if not hasattr(obj, "type"):
                continue
            if obj.type == Const.T_SYSTEM:
                if not hasattr(obj, 'planets'):
                    continue
                bio = 0
                totalBio = 0
                en = 0
                totalEn = 0
                buildingQuantity = {}
                buildingInfo = {}
                # holds modified planets
                planetCopies = {}

                for planetID in obj.planets:
                    planet = client.get(planetID, noUpdate=1)
                    # copy of planet to change plSlots count
                    if not planetID in planetCopies:
                        cPlanet = copy.deepcopy(planet)
                        planetCopies[planetID] = cPlanet
                    else:
                        cPlanet = planetCopies[planetID]
                    if hasattr(planet, 'owner') and planet.owner == player.oid:
                        queuePlanetNumber, queueEffProd = globalQueueStats[
                            planet.globalQueue]
                        queuePlanetNumber += 1
                        queueEffProd += planet.effProdProd
                        globalQueueStats[planet.globalQueue] = (
                            queuePlanetNumber, queueEffProd)
                        # compute bio and en for system
                        bio += planet.changeBio
                        totalBio += max(0, planet.storBio - planet.minBio)
                        en += planet.changeEn
                        totalEn += max(0, planet.storEn - planet.minEn)
                        # the planet needs to have global queue 0 - the default one - to have its queue reported
                        if hasattr(
                                planet, 'prodQueue'
                        ) and self.win.vPlanets.checked and not planet.globalQueue:
                            totalEtc = 0
                            # compute length of production queue
                            if cPlanet.prodQueue and cPlanet.effProdProd > 0:
                                for task in cPlanet.prodQueue:
                                    if task.isShip:
                                        tech = client.getPlayer().shipDesigns[
                                            task.techID]
                                    else:
                                        tech = client.getFullTechInfo(
                                            task.techID)
                                        if tech.isStructure and hasattr(
                                                task, "demolishStruct"
                                        ) and task.demolishStruct == 0:
                                            # total count of constructing buildings on target
                                            if buildingQuantity.has_key(
                                                    task.targetID):
                                                buildingQuantity[
                                                    task.
                                                    targetID] += task.quantity
                                            else:
                                                buildingQuantity[
                                                    task.
                                                    targetID] = task.quantity

                                            # information about source and target of constructing
                                            if buildingInfo.has_key(
                                                (planetID, task.targetID)):
                                                buildingInfo[(
                                                    planetID, task.targetID
                                                )] += task.quantity
                                            else:
                                                buildingInfo[(
                                                    planetID, task.targetID
                                                )] = task.quantity
                                        elif tech.isProject and tech.id == 3802:
                                            # we are constructing Habitable Surface Expansion
                                            # so after construction we got some new slots on planet
                                            if not task.targetID in planetCopies:
                                                targetPlanet = client.get(
                                                    task.targetID, noUpdate=1)
                                                cPlanet = copy.deepcopy(
                                                    targetPlanet)
                                                planetCopies[
                                                    task.targetID] = cPlanet

                                            planetCopies[
                                                task.
                                                targetID].plSlots += task.quantity

                                    if task.targetID != planetID:
                                        totalEtc += math.ceil(
                                            float(tech.buildProd *
                                                  Rules.buildOnAnotherPlanetMod
                                                  - task.currProd) /
                                            planet.effProdProd)
                                        totalEtc += math.ceil(
                                            (task.quantity - 1) * float(
                                                tech.buildProd *
                                                Rules.buildOnAnotherPlanetMod)
                                            / planet.effProdProd)
                                    else:
                                        totalEtc += math.ceil(
                                            task.quantity *
                                            float(tech.buildProd -
                                                  task.currProd) /
                                            planet.effProdProd)
                                        totalEtc += math.ceil(
                                            (task.quantity - 1) *
                                            float(tech.buildProd) /
                                            planet.effProdProd)
                            else:
                                totalEtc = 99999

                            prodQueueProblems.append(
                                (planetID, totalEtc, len(planet.prodQueue)))

                        # check for structures status
                        if hasattr(planet,
                                   'slots') and self.win.vPlanets.checked:
                            for struct in planet.slots:
                                status = struct[Const.STRUCT_IDX_STATUS]
                                problem = None
                                tech = client.getFullTechInfo(
                                    struct[Const.STRUCT_IDX_TECHID])

                                if hasattr(player, 'techs'):
                                    techEff = Rules.techImprEff[
                                        player.techs.get(
                                            struct[Const.STRUCT_IDX_TECHID],
                                            Rules.techBaseImprovement)]
                                else:
                                    techEff = Rules.techImprEff[
                                        Rules.techBaseImprovement]

                                HPturn = max(1,
                                             int(0.02 * tech.maxHP * techEff))
                                turnsToDestroy = math.ceil(
                                    struct[Const.STRUCT_IDX_HP] / HPturn)

                                if turnsToDestroy < 48:
                                    dispDestr = major
                                    fgColorDestr = gdata.sevColors[gdata.MAJ]
                                    if turnsToDestroy < 24:
                                        dispDestr = critical
                                        fgColorDestr = gdata.sevColors[
                                            gdata.CRI]
                                else:
                                    dispDestr = minor
                                    fgColorDestr = None

                                if not status & Const.STRUCT_STATUS_ON:
                                    # structure is off
                                    if dispDestr:
                                        items.append(
                                            ui.Item(
                                                planet.name,
                                                tOID=planetID,
                                                tType=Const.T_PLANET,
                                                foreground=fgColorDestr,
                                                vDescription=
                                                _('Structure (%s) is off and will be destroyed in %s turns.'
                                                  ) %
                                                (tech.name,
                                                 res.formatTime(turnsToDestroy)
                                                 )))

                                elif status & Const.STRUCT_STATUS_DETER:
                                    problem = _('is deteriorating')
                                    disp = major
                                    fgColor = gdata.sevColors[gdata.MAJ]
                                elif status & Const.STRUCT_STATUS_NOBIO:
                                    problem = _(
                                        'has insufficient supply of biomatter')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]
                                elif status & Const.STRUCT_STATUS_NOEN:
                                    problem = _(
                                        'has insufficient supply of energy')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]
                                elif status & Const.STRUCT_STATUS_NOPOP:
                                    problem = _(
                                        'has insufficient supply of workers')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]
                                elif status & Const.STRUCT_STATUS_REPAIRING:
                                    problem = _('is repairing')
                                    disp = info
                                    fgColor = gdata.sevColors[gdata.INFO]

                                if problem and disp:
                                    items.append(
                                        ui.Item(planet.name,
                                                tOID=planetID,
                                                tType=Const.T_PLANET,
                                                foreground=fgColor,
                                                vDescription=_(
                                                    'Structure (%s) %s.') %
                                                (tech.name, problem)))

                for planetID, quantity in buildingQuantity.items():
                    planet = planetCopies[planetID]
                    # test, if there is total quantity of building as target for this planet
                    if planet.plSlots < len(planet.slots) + quantity and major:
                        # walk infos and search for all planets, that are building
                        # on planet founded above
                        for (sourceID,
                             targetID), quantity in buildingInfo.items():
                            if planetID == targetID:
                                source = client.get(sourceID, noUpdate=1)
                                items.append(
                                    ui.Item(
                                        source.name,
                                        tOID=sourceID,
                                        tType=Const.T_PLANET,
                                        foreground=gdata.sevColors[gdata.MAJ],
                                        vDescription=
                                        _('There is no space for all constructed buildings on %s.'
                                          ) % (planet.name)))

                # check bio for system
                if bio < 0 and self.win.vSystems.checked:
                    disp = minor
                    fgColor = None
                    surplusTurns = totalBio / (-bio)
                    if surplusTurns < 168:
                        disp = major
                        fgColor = gdata.sevColors[gdata.MAJ]
                    if surplusTurns < 48:
                        disp = critical
                        fgColor = gdata.sevColors[gdata.CRI]

                    if disp:
                        if totalBio > 0:
                            items.append(
                                ui.Item(
                                    obj.name,
                                    tOID=obj.oid,
                                    tType=Const.T_SYSTEM,
                                    foreground=fgColor,
                                    vDescription=
                                    _('Bio decreasing - last turn change %d, surplus %d (%s).'
                                      ) % (bio, totalBio,
                                           res.formatTime(surplusTurns))))
                        else:
                            items.append(
                                ui.Item(
                                    obj.name,
                                    tOID=obj.oid,
                                    tType=Const.T_SYSTEM,
                                    foreground=fgColor,
                                    vDescription=
                                    _('Bio decreasing - last turn change %d, surplus %d.'
                                      ) % (bio, totalBio)))

                #check en for system
                if en < 0 and self.win.vSystems.checked:
                    disp = minor
                    fgColor = None
                    surplusTurns = totalEn / (-en)
                    if surplusTurns < 168:
                        disp = major
                        fgColor = gdata.sevColors[gdata.MAJ]
                    if surplusTurns < 48:
                        disp = critical
                        fgColor = gdata.sevColors[gdata.CRI]

                    if disp:
                        if totalEn > 0:
                            items.append(
                                ui.Item(
                                    obj.name,
                                    tOID=obj.oid,
                                    tType=Const.T_SYSTEM,
                                    foreground=fgColor,
                                    vDescription=
                                    _('Energy decreasing - last turn change %d, surplus %d (%s).'
                                      ) % (en, totalEn,
                                           res.formatTime(surplusTurns))))
                        else:
                            items.append(
                                ui.Item(
                                    obj.name,
                                    tOID=obj.oid,
                                    tType=Const.T_SYSTEM,
                                    foreground=fgColor,
                                    vDescription=
                                    _('Energy decreasing - last turn change %d, surplus %d.'
                                      ) % (en, totalEn)))

            # check fleets
            elif obj.type == Const.T_FLEET and self.win.vFleets.checked:
                if hasattr(obj, 'owner') and obj.owner == player.oid:
                    energyReserve = obj.storEn * 100 / obj.maxEn
                    system = None
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]
                    note = _(' and IS NOT refueling')

                    maxRefuelMax = 0
                    if hasattr(obj, 'orbiting') and obj.orbiting:
                        system = client.get(obj.orbiting, noUpdate=1)
                        if hasattr(system, 'planets'):
                            for planetID in system.planets:
                                planet = client.get(planetID, noUpdate=1)
                                if hasattr(planet, 'owner') and hasattr(
                                        planet, 'refuelMax'):
                                    if player.diplomacyRels.has_key(
                                            planet.owner):
                                        dipl = client.getDiplomacyWith(
                                            planet.owner)
                                        if dipl.pacts.has_key(
                                                Const.PACT_ALLOW_TANKING
                                        ) and dipl.pacts[
                                                Const.PACT_ALLOW_TANKING][
                                                    0] == Const.PACT_ACTIVE:
                                            maxRefuelMax = max(
                                                maxRefuelMax, planet.refuelMax)
                                    else:
                                        if planet.owner == player.oid:
                                            maxRefuelMax = max(
                                                maxRefuelMax, planet.refuelMax)

                            if maxRefuelMax > 0:
                                disp = info
                                fgColor = gdata.sevColors[gdata.INFO]
                                note = _(' and IS refueling')
                                if maxRefuelMax <= energyReserve:
                                    note = _(
                                        ' and CAN refuel, but reach planet maximum refuel amount'
                                    )

                    else:
                        continue

                    systemName = res.getUnknownName()
                    if system and hasattr(system, "name"):
                        systemName = system.name

                    # check fleets energy reserve
                    if energyReserve < 50 and maxRefuelMax == 0:
                        disp = major
                        fgColor = gdata.sevColors[gdata.MAJ]
                        if energyReserve < 25 and maxRefuelMax == 0:
                            disp = critical
                            fgColor = gdata.sevColors[gdata.CRI]
                    else:
                        fgColor = gdata.sevColors[gdata.INFO]
                        disp = info

                    # is fleet named?
                    if hasattr(obj, 'customname') and obj.customname:
                        name = obj.customname
                    else:
                        name = getattr(obj, "name", None)

                    if energyReserve == 100 and info and disp:
                        items.append(
                            ui.Item(systemName,
                                    tOID=obj.oid,
                                    tType=Const.T_FLEET,
                                    foreground=gdata.sevColors[gdata.INFO],
                                    vDescription=_(
                                        'Fleet "%s" has full fuel tanks.') %
                                    (name)))
                    elif disp:
                        items.append(
                            ui.Item(
                                systemName,
                                tOID=obj.oid,
                                tType=Const.T_FLEET,
                                foreground=fgColor,
                                vDescription=_(
                                    'Fleet "%s" is low on fuel [%d %%]%s.') %
                                (name, energyReserve, note)))

        queConstValues = [0, 0, 0, 0, 0]
        queEtc = [0, 0, 0, 0, 0]
        for queue in xrange(5):
            quePlanets, queEffProd = globalQueueStats[queue]
            for task in player.prodQueues[queue]:
                if task.isShip:
                    tech = client.getPlayer().shipDesigns[task.techID]
                else:
                    tech = client.getFullTechInfo(task.techID)
                queConstValues[queue] += task.quantity * tech.buildProd
            if queEffProd > 0:
                queEtc[queue] = math.ceil(
                    float(queConstValues[queue]) / queEffProd)
            else:
                queEtc[queue] = 99999

        # creation of items with production queue [default one] problems
        for planetID, totalEtc, queueLen in prodQueueProblems:
            planet = client.get(planetID, noUpdate=1)

            # check empty production queue
            if queueLen == 0 and planet.effProdProd > 0 and queConstValues[
                    0] == 0 and critical:
                items.append(
                    ui.Item(planet.name,
                            tOID=planetID,
                            tType=Const.T_PLANET,
                            foreground=gdata.sevColors[gdata.CRI],
                            vDescription=_('Production queue is empty.')))

            # check end of production queue
            if totalEtc + queEtc[0] < 48:
                fgColor = None
                disp = minor
                if totalEtc + queEtc[0] < 24:
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]
                    if disp:
                        items.append(
                            ui.Item(
                                planet.name,
                                tOID=planetID,
                                tType=Const.T_PLANET,
                                foreground=fgColor,
                                vDescription=_(
                                    'Production queue may end in {0} turns ({1} directly in planet queue), {2} item(s) on list.'
                                    .format(
                                        res.formatTime(totalEtc + queEtc[0]),
                                        res.formatTime(totalEtc), queueLen))))

        # creation of items with global queue problems
        for queue in xrange(1, 5):
            queName = res.globalQueueName(queue)
            quePlanets = globalQueueStats[queue][0]
            # check empty global production queue with at least one planet [so its relevant]
            if queConstValues[queue] == 0 and quePlanets > 0 and critical:
                items.append(
                    ui.Item(
                        _('Global queue ' + queName),
                        tType=Const.T_QUEUE,
                        foreground=gdata.sevColors[gdata.CRI],
                        vDescription=_(
                            'Global production queue {0} used by {1} planet(s) is empty.'
                            .format(queName, quePlanets))))

            # check end of global production queue
            elif queEtc[queue] < 48:
                fgColor = None
                disp = minor
                if queEtc[queue] < 24:
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]
                if disp:
                    items.append(
                        ui.Item(
                            _('Global queue ' + queName),
                            tType=Const.T_QUEUE,
                            foreground=fgColor,
                            vDescription=_(
                                'Global production queue {0} used by {1} planet(s) runs out in {2} turns.'
                                .format(queName, quePlanets,
                                        res.formatTime(queEtc[queue])))))

        # check research queue
        if self.win.vResearch.checked:
            totalEtc = 0
            # compute length of research queue
            for task in player.rsrchQueue:
                tech = client.getTechInfo(task.techID)
                fulltech = client.getFullTechInfo(task.techID)
                researchSci = Utils.getTechRCost(player, task.techID,
                                                 task.improvement)
                maxImprovement = min(Rules.techMaxImprovement,
                                     fulltech.maxImprovement)
                maxImpTotalSci = 0
                if task.improveToMax and task.improvement < maxImprovement:
                    for impr in range(task.improvement + 1,
                                      maxImprovement + 1):
                        maxImpTotalSci += Utils.getTechRCost(
                            player, task.techID, impr)
                if task.changeSci > 0:
                    value = float(researchSci - task.currSci) / max(
                        task.changeSci, player.effSciPoints)
                    totalEtc += int(value + 1)
                    if player.effSciPoints != 0:
                        totalEtc += float(maxImpTotalSci) / player.effSciPoints
                elif task.changeSci < 0:
                    totalEtc -= float(task.currSci) / min(
                        task.changeSci, player.effSciPoints)
                elif player.effSciPoints > 0:
                    value = float(researchSci) / player.effSciPoints
                    totalEtc += int(value + 1)
                    totalEtc += float(maxImpTotalSci) / player.effSciPoints
                else:
                    totalEtc = 99999
                    break

            # check empty research queue
            if totalEtc == 0 and len(
                    player.rsrchQueue
            ) == 0 and player.effSciPoints > 0 and major:
                items.append(
                    ui.Item(_('Research'),
                            tType=Const.T_TECHNOLOGY,
                            foreground=gdata.sevColors[gdata.MAJ],
                            vDescription=_('Research queue is empty.')))
            # check short reseach queue
            elif totalEtc < 48:
                disp = minor
                fgColor = None
                if totalEtc < 24:
                    disp = major
                    fgColor = gdata.sevColors[gdata.MAJ]

                if disp:
                    items.append(
                        ui.Item(
                            _('Research'),
                            tType=Const.T_TECHNOLOGY,
                            foreground=fgColor,
                            vDescription=
                            _('Research queue ends in %s turns, %d item(s) on list.'
                              ) % (res.formatTime(totalEtc),
                                   len(player.rsrchQueue))))

        self.win.vProblems.items = items
        self.win.vProblems.itemsChanged()
Esempio n. 29
0
	def show(self):
		player = client.getPlayer()
		# title
		self.win.vRQueueTitle.text = _('Research queue [%d pts/turn]') % (
			player.effSciPoints,
		)
		self.win.title = _("Research [TL%d]") % player.techLevel
		# Known techs
		items = []
		#~researchable = {}
		disabled = []
		taskIDs = {}
		for task in player.rsrchQueue:
			taskIDs[task.techID] = None
		for techID in player.techs.keys():
			tech = client.getTechInfo(techID)
			improvement = player.techs[techID]
			item = ui.Item(tech.name,
				techID = techID,
				tLevel = '%d-%d' % (tech.level, improvement),
				tStruct = (' ', '*')[tech.isStructure],
				tShip = (' ', '*')[tech.isShipEquip],
			)
			if improvement < Rules.techMaxImprovement and improvement < tech.maxImprovement:
				neededSci = Utils.getTechRCost(player, techID)
				if player.effSciPoints > 0:
					item.tETC = res.formatTime(float(neededSci) / player.effSciPoints)
				else:
					item.tETC = _("N/A")
				found = 0
				if taskIDs.has_key(techID):
					item.foreground = (0xd0, 0xd0, 0xd0)
				else:
					item.foreground = None
			else:
				item.tETC = res.getNA()
				item.foreground = (0x80, 0x80, 0x80)
				if not self.showCompleted:
					# skip this item
					continue
			items.append(item)
			disabled.extend(tech.researchDisables)
			#~for improvement in range(1, improvement + 1):
			#~	for techID in tech.researchEnables[improvement]:
			#~		researchable[techID] = 1
		self.win.vKTechs.items = items
		self.win.vKTechs.itemsChanged()
		# Research queue
		items = []
		index = 0
		queueTechs = []
		total = 0
		for task in player.rsrchQueue:
			tech = client.getTechInfo(task.techID)
			fulltech = client.getFullTechInfo(task.techID)
			queueTechs.append(task.techID)
			item = ui.Item(tech.name, techID = task.techID, index = index)
			researchSci = Utils.getTechRCost(player, task.techID, task.improvement)
			maxImprovement = min(Rules.techMaxImprovement,fulltech.maxImprovement)
			maxImpTotalSci = 0
			if task.improveToMax and task.improvement < maxImprovement:
				for impr in range(task.improvement+1,maxImprovement+1):
					maxImpTotalSci += Utils.getTechRCost(player, task.techID, impr)
			item.tooltip = _("Research points %d/%d, change %d pts/turn.") % (task.currSci, researchSci, task.changeSci)
			item.statustip = item.tooltip
			item.tImpToMax = ["", "*"][task.improveToMax]
			item.tImproveToMax = task.improveToMax
			if task.currSci > 0:
				item.tProgress = _("%d %%") % int(task.currSci * 100 / researchSci)
			else:
				item.tProgress = _("-")
			if task.changeSci > 0:
				value = float(researchSci - task.currSci) / max(task.changeSci, player.effSciPoints)
				total += int(value + 1)
				if player.effSciPoints > 0:
					total += float(maxImpTotalSci) / player.effSciPoints
					item.tETC = res.formatTime(value)
				else:
					total = 0
					item.tETC = res.getNA()
			elif task.changeSci < 0:
				value = - float(task.currSci) / min(task.changeSci, player.effSciPoints)
				item.tETC = _("[%s]") % res.formatTime(value)
			elif player.effSciPoints > 0:
				value = float(researchSci) / player.effSciPoints
				total += int(value + 1)
				total += float(maxImpTotalSci) / player.effSciPoints
				item.tETC = res.formatTime(value)
			else:
				item.tETC = res.getNA()
			item.tLevel = _("%d-%d") % (tech.level, task.improvement)
			items.append(item)
			index += 1
		self.win.vRQueue.items = items
		self.win.vRQueue.itemsChanged()
		self.win.vRQueueTop.enabled = 0
		self.win.vRQueueUp.enabled = 0
		self.win.vRQueueDown.enabled = 0
		self.win.vRQueueAbort.enabled = 0
		self.win.vRQueueRepat.enabled = 0
		self.win.vRQueueRepat.pressed = 0
		self.win.vRQueueInfo.enabled = 0
		if total == 0:
			self.win.vRTotal.text = _("N/A")
		else:
			self.win.vRTotal.text = res.formatTime(total)
		# Researchable techs
		items = []
		for techID in client.getAllTechIDs():
			if player.techs.has_key(techID)	or techID in queueTechs \
				or techID in disabled:
				continue
			# can check requirements
			tech = client.getTechInfo(techID)
			if not hasattr(tech, "partialData"):
				continue
			item = ui.Item(tech.name, tLevel = tech.level, techID = techID)
			if hasattr(tech, 'isStructure'): item.tStruct = ('', '*')[tech.isStructure]
			else: item.tStruct = ''
			if hasattr(tech, 'isShipEquip'): item.tShip = ('', '*')[tech.isShipEquip]
			else: item.tShip = ''
			if hasattr(tech, 'researchMod'):
				neededSci = Utils.getTechRCost(player, techID)
				if player.effSciPoints > 0:
					item.tETC = res.formatTime(float(neededSci) / player.effSciPoints)
				else:
					item.tETC = _("N/A")
				item.foreground = None
			else:
				item.tSci = res.getNA()
				item.foreground = (0xc0, 0xc0, 0xc0)
				# skip this item
				continue
			if hasattr(tech, "researchDisables") and tech.researchDisables:
				item.foreground = (0xff, 0xff, 0x00)
			if client.getFullTechInfo(techID).finishResearchHandler == TechHandlers.finishResTLAdvance:
					item.foreground = gdata.sevColors[gdata.CRI]
			items.append(item)
		self.win.vRTechs.items = items
		self.win.vRTechs.itemsChanged()