def onPactSelected(self, widget, action, data): if self.win.vPacts.selection: self.selectedPactID = self.win.vPacts.selection[0].tPactID else: self.selectedPactID = None self.win.vChangePactState.enabled = 0 self.win.vPactConditions.enabled = 0 self.win.vPactCondReset.enabled = 0 self.win.vConditions.items = [] self.win.vConditions.itemsChanged() return self.win.vChangePactState.enabled = 1 self.win.vPactConditions.enabled = 1 self.win.vPactCondReset.enabled = 1 item = self.win.vPacts.selection[0] if item.tPactState == Const.PACT_OFF: self.win.vChangePactState.text = _("Enable") self.win.vChangePactState.data = "ENABLE" else: self.win.vChangePactState.text = _("Disable") self.win.vChangePactState.data = "DISABLE" # show conditions items = [] selected = [] dipl = client.getDiplomacyWith(self.selectedPartyID) conditions = dipl.pacts.get(item.tPactID, [0, item.tPactID])[1:] if self.partyDipl: partnerConditions = self.partyDipl.pacts.get(item.tPactID, [0])[1:] else: partnerConditions = [] states = (_(" "), _("Required")) self.win.vCondTitle.text = _('Conditions for pact: %s') % _( gdata.pactNames[item.tPactID]) for pactID in gdata.pacts: item = ui.Item(_(gdata.pactNames[pactID]), tState1=states[pactID in conditions], tState2=states[pactID in partnerConditions], tPactID=pactID, foreground=gdata.sevColors[( gdata.NONE, gdata.MAJ, gdata.MIN)[(pactID in conditions) + (pactID in partnerConditions)]]) items.append(item) if pactID in conditions: selected.append(item) self.win.vConditions.items = items for item in selected: self.win.vConditions.selectItem(item) self.win.vConditions.itemsChanged()
def onPactSelected(self, widget, action, data): if self.win.vPacts.selection: self.selectedPactID = self.win.vPacts.selection[0].tPactID else: self.selectedPactID = None self.win.vChangePactState.enabled = 0 self.win.vPactConditions.enabled = 0 self.win.vPactCondReset.enabled = 0 self.win.vConditions.items = [] self.win.vConditions.itemsChanged() return self.win.vChangePactState.enabled = 1 self.win.vPactConditions.enabled = 1 self.win.vPactCondReset.enabled = 1 item = self.win.vPacts.selection[0] if item.tPactState == Const.PACT_OFF: self.win.vChangePactState.text = _("Enable") self.win.vChangePactState.data = "ENABLE" else: self.win.vChangePactState.text = _("Disable") self.win.vChangePactState.data = "DISABLE" # show conditions items = [] selected = [] dipl = client.getDiplomacyWith(self.selectedPartyID) conditions = dipl.pacts.get(item.tPactID, [0, item.tPactID])[1:] if self.partyDipl: partnerConditions = self.partyDipl.pacts.get(item.tPactID, [0])[1:] else: partnerConditions = [] states = (_(" "), _("Required")) self.win.vCondTitle.text = _('Conditions for pact: %s') % _(gdata.pactNames[item.tPactID]) for pactID in gdata.pacts: item = ui.Item( _(gdata.pactNames[pactID]), tState1 = states[pactID in conditions], tState2 = states[pactID in partnerConditions], tPactID = pactID, foreground = gdata.sevColors[(gdata.NONE, gdata.MAJ, gdata.MIN)\ [(pactID in conditions) + (pactID in partnerConditions)]], ) items.append(item) if pactID in conditions: selected.append(item) self.win.vConditions.items = items for item in selected: self.win.vConditions.selectItem(item) self.win.vConditions.itemsChanged()
def _getContactEntry(self, contactID): contact = client.get(contactID, publicOnly=1) dipl = client.getDiplomacyWith(contactID) if dipl.relChng > 0: suffix = _(" +") elif dipl.relChng < 0: suffix = _(" -") else: suffix = _("") relation = _("%s%s") % (_(gdata.relationNames[int( dipl.relation / 125)]), suffix) contactName = _("%s [elect]") % contact.name if client.getPlayer( ).voteFor == contactID else contact.name if getattr(dipl, "stats", None): return ui.Item(contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation=dipl.stats.storPop, tPlanets=dipl.stats.planets, tStructures=dipl.stats.structs, tProduction=dipl.stats.prodProd, tScience=dipl.stats.prodSci, tFleetPwr=dipl.stats.fleetPwr, tContact=(_("-"), _("Mobile"), _("Static"))[dipl.contactType], foreground=res.getPlayerColor(contactID), tooltipTitle=_("Relation"), tooltip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng), statustip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng)) else: return ui.Item(contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation="-", tPlanets="-", tStructures="-", tProduction="-", tScience="-", tFleetPwr="-", tContact=(_("None"), _("Mobile"), _("Static"))[dipl.contactType], foreground=res.getPlayerColor(contactID))
def _processPacts(self): player = client.getPlayer() items = [] selected = None if self.selectedPartyID and self.selectedPartyID != player.oid: dipl = client.cmdProxy.getPartyDiplomacyRels( player.oid, self.selectedPartyID)[0] if not dipl: dipl = client.getDiplomacyWith(self.selectedPartyID) for pactID in gdata.pacts: pactSpec = Rules.pactDescrs[pactID] if not pactSpec.validityInterval[ 0] < dipl.relation < pactSpec.validityInterval[1]: continue items.append(self._getPactsEntry(pactID, dipl)) self.win.vPacts.items = items self.win.vPacts.selectItem(selected) self.win.vPacts.itemsChanged()
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()
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()
def show(self): player_highlight = -1 if gdata.config.game.highlight != None: player_highlight = gdata.config.game.highlight player = client.getPlayer() # build contact list items = [] if self.win.vContacts.selection: self.selectedPartyID = self.win.vContacts.selection[0].tContactID else: self.selectedPartyID = None selected = None for contactID in player.diplomacyRels: contact = client.get(contactID, publicOnly=1) dipl = client.getDiplomacyWith(contactID) if dipl.relChng > 0: relation = _("%s +") % _(gdata.relationNames[int( dipl.relation / 125)]) elif dipl.relChng < 0: relation = _("%s -") % _(gdata.relationNames[int( dipl.relation / 125)]) else: relation = _("%s") % _(gdata.relationNames[int( dipl.relation / 125)]) if player.voteFor == contactID: contactName = _("%s [elect]") % contact.name else: contactName = contact.name #f int(player_highlight) == (contactID): # colortemp = gdata.playerHighlightColor #lse: # colortemp = res.getFFColorCode(dipl.relation) colortemp = res.getPlayerColor(contactID) if hasattr(dipl, "stats") and dipl.stats: item = ui.Item( contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation=dipl.stats.storPop, tPlanets=dipl.stats.planets, tStructures=dipl.stats.structs, tProduction=dipl.stats.prodProd, tScience=dipl.stats.prodSci, tFleetPwr=dipl.stats.fleetPwr, tContact=(_("-"), _("Mobile"), _("Static"))[dipl.contactType], foreground=colortemp, tooltipTitle=_("Relation"), tooltip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng), statustip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng), ) else: item = ui.Item( contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation="-", tPlanets="-", tStructures="-", tProduction="-", tScience="-", tFleetPwr="-", tContact=(_("None"), _("Mobile"), _("Static"))[dipl.contactType], foreground=colortemp, ) items.append(item) if self.selectedPartyID == contactID: selected = item # player if player.voteFor == player.oid: contactName = _("%s [elect]") % player.name else: contactName = player.name item = ui.Item( contactName, tContactID=player.oid, tRelation="-", tRelation_raw=10000, tPopulation=getattr(player.stats, "storPop", "?"), tPlanets=getattr(player.stats, "planets", "?"), tStructures=getattr(player.stats, "structs", "?"), tProduction=getattr(player.stats, "prodProd", "?"), tScience=getattr(player.stats, "prodSci", "?"), tFleetPwr=getattr(player.stats, "fleetPwr", "?"), tContact="-", foreground=res.getFFColorCode(Const.REL_UNITY), ) items.append(item) if self.selectedPartyID == player.oid: selected = item self.win.vContacts.items = items self.win.vContacts.selectItem(selected) self.win.vContacts.itemsChanged() # voting if self.galaxyScenario == Const.SCENARIO_OUTERSPACE: # this is just in case we reloged self.win.vAbstain.visible = 1 self.win.vVoteFor.visible = 1 self.win.vAbstain.enabled = player.voteFor != Const.OID_NONE if selected: self.win.vVoteFor.enabled = selected.tContactID != player.voteFor else: self.win.vVoteFor.enabled = 0 else: self.win.vAbstain.visible = 0 self.win.vVoteFor.visible = 0 # pacts items = [] selected = None if self.selectedPartyID and self.selectedPartyID != player.oid: dipl, self.partyDipl = client.cmdProxy.getPartyDiplomacyRels( player.oid, self.selectedPartyID) if not dipl: dipl = client.getDiplomacyWith(self.selectedPartyID) for pactID in gdata.pacts: pactSpec = Rules.pactDescrs[pactID] if dipl.relation < pactSpec.validityInterval[0] or \ dipl.relation > pactSpec.validityInterval[1]: continue if pactID in dipl.pacts: pactState1 = dipl.pacts[pactID][0] if self.partyDipl: pactState2 = self.partyDipl.pacts.get( pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item( _(gdata.pactNames[pactID]), tState1=_(gdata.pactStates[pactState1]), tState2=pactState2Text, tPactState=pactState1, foreground=gdata.sevColors[(gdata.DISABLED, gdata.INFO, gdata.MIN)[min( pactState1, pactState2)]]) else: if self.partyDipl: pactState2 = self.partyDipl.pacts.get( pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item(_(gdata.pactNames[pactID]), tState1=_(gdata.pactStates[Const.PACT_OFF]), tState2=pactState2Text, tPactState=Const.PACT_OFF, foreground=gdata.sevColors[gdata.DISABLED]) item.tPactID = pactID if pactID == self.selectedPactID: selected = item items.append(item) self.win.vPacts.items = items self.win.vPacts.selectItem(selected) self.win.vPacts.itemsChanged() # Higlight buttons if gdata.config.defaults.highlights == 'yes': self.win.vHighlight.enabled = 0 self.win.vUHighlight.enabled = 1 else: self.win.vHighlight.enabled = 1 self.win.vUHighlight.enabled = 0 self.onPactSelected(None, None, None)
def show(self): player_highlight = -1 if gdata.config.game.highlight != None: player_highlight = gdata.config.game.highlight player = client.getPlayer() # build contact list items = [] if self.win.vContacts.selection: self.selectedPartyID = self.win.vContacts.selection[0].tContactID else: self.selectedPartyID = None selected = None for contactID in player.diplomacyRels: contact = client.get(contactID,publicOnly = 1) dipl = client.getDiplomacyWith(contactID) if dipl.relChng > 0: relation = _("%s +") % _(gdata.relationNames[int(dipl.relation / 125)]) elif dipl.relChng < 0: relation = _("%s -") % _(gdata.relationNames[int(dipl.relation / 125)]) else: relation = _("%s") % _(gdata.relationNames[int(dipl.relation / 125)]) if player.voteFor == contactID: contactName = _("%s [elect]") % contact.name else: contactName = contact.name #f int(player_highlight) == (contactID): # colortemp = gdata.playerHighlightColor #lse: # colortemp = res.getFFColorCode(dipl.relation) colortemp = res.getPlayerColor(contactID) if hasattr(dipl, "stats") and dipl.stats: item = ui.Item(contactName, tContactID = contactID, tRelation = relation, tRelation_raw = dipl.relation, tPopulation = dipl.stats.storPop, tPlanets = dipl.stats.planets, tStructures = dipl.stats.structs, tProduction = dipl.stats.prodProd, tScience = dipl.stats.prodSci, tFleetPwr = dipl.stats.fleetPwr, tContact = (_("-"), _("Mobile"), _("Static"))[dipl.contactType], foreground = colortemp, tooltipTitle = _("Relation"), tooltip = _("Relation %d, change %+d") % (dipl.relation, dipl.relChng), statustip = _("Relation %d, change %+d") % (dipl.relation, dipl.relChng), ) else: item = ui.Item(contactName, tContactID = contactID, tRelation = relation, tRelation_raw = dipl.relation, tPopulation = "-", tPlanets = "-", tStructures = "-", tProduction = "-", tScience = "-", tFleetPwr = "-", tContact = (_("None"), _("Mobile"), _("Static"))[dipl.contactType], foreground = colortemp, ) items.append(item) if self.selectedPartyID == contactID: selected = item # player if player.voteFor == player.oid: contactName = _("%s [elect]") % player.name else: contactName = player.name item = ui.Item(contactName, tContactID = player.oid, tRelation = "-", tRelation_raw = 10000, tPopulation = getattr(player.stats, "storPop", "?"), tPlanets = getattr(player.stats, "planets", "?"), tStructures = getattr(player.stats, "structs", "?"), tProduction = getattr(player.stats, "prodProd", "?"), tScience = getattr(player.stats, "prodSci", "?"), tFleetPwr = getattr(player.stats, "fleetPwr", "?"), tContact = "-", foreground = res.getFFColorCode(Const.REL_UNITY), ) items.append(item) if self.selectedPartyID == player.oid: selected = item self.win.vContacts.items = items self.win.vContacts.selectItem(selected) self.win.vContacts.itemsChanged() # voting if self.galaxyScenario == Const.SCENARIO_OUTERSPACE: # this is just in case we reloged self.win.vAbstain.visible = 1 self.win.vVoteFor.visible = 1 self.win.vAbstain.enabled = player.voteFor != Const.OID_NONE if selected: self.win.vVoteFor.enabled = selected.tContactID != player.voteFor else: self.win.vVoteFor.enabled = 0 else: self.win.vAbstain.visible = 0 self.win.vVoteFor.visible = 0 # pacts items = [] selected = None if self.selectedPartyID and self.selectedPartyID != player.oid: dipl, self.partyDipl = client.cmdProxy.getPartyDiplomacyRels(player.oid, self.selectedPartyID) if not dipl: dipl = client.getDiplomacyWith(self.selectedPartyID) for pactID in gdata.pacts: pactSpec = Rules.pactDescrs[pactID] if dipl.relation < pactSpec.validityInterval[0] or \ dipl.relation > pactSpec.validityInterval[1]: continue if pactID in dipl.pacts: pactState1 = dipl.pacts[pactID][0] if self.partyDipl: pactState2 = self.partyDipl.pacts.get(pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item( _(gdata.pactNames[pactID]), tState1 = _(gdata.pactStates[pactState1]), tState2 = pactState2Text, tPactState = pactState1, foreground = gdata.sevColors[(gdata.DISABLED, gdata.INFO, gdata.MIN)[min(pactState1, pactState2)]] ) else: if self.partyDipl: pactState2 = self.partyDipl.pacts.get(pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item( _(gdata.pactNames[pactID]), tState1 = _(gdata.pactStates[Const.PACT_OFF]), tState2 = pactState2Text, tPactState = Const.PACT_OFF, foreground = gdata.sevColors[gdata.DISABLED] ) item.tPactID = pactID if pactID == self.selectedPactID: selected = item items.append(item) self.win.vPacts.items = items self.win.vPacts.selectItem(selected) self.win.vPacts.itemsChanged() # Higlight buttons if gdata.config.defaults.highlights == 'yes': self.win.vHighlight.enabled = 0 self.win.vUHighlight.enabled = 1 else: self.win.vHighlight.enabled = 1 self.win.vUHighlight.enabled = 0 self.onPactSelected(None, None, None)