예제 #1
0
 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))
예제 #2
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
            if not self._shallShow(planet, player):
                continue
            # fill in data
            ownerID = getattr(planet, 'owner', Const.OID_NONE)
            if hasattr(planet, 'owner') and planet.owner == player.oid:
                constrInfo, etc, totalEtc = self._processProdQueue(planet)
            else:
                constrInfo = '?'
                etc = '?'
                totalEtc = '?'
            # used slots
            try:
                freeSlots = planet.plSlots - len(planet.slots)
            except AttributeError:
                freeSlots = '?'
            # morale
            try:
                morale = int(planet.morale)
            except AttributeError:
                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,
                           tTotalETC=totalEtc,
                           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.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
예제 #3
0
 def _processTarget(self, planet):
     ownerName = res.getUnknownName()
     ownerID = Const.OID_NONE
     if hasattr(planet, 'owner'):
         ownerID = planet.owner
         if planet.owner != Const.OID_NONE:
             ownerName = client.get(planet.owner, noUpdate=1).name
     if planet.plType in ("A", "G"):
         color = gdata.sevColors[gdata.DISABLED]
     else:
         color = res.getPlayerColor(ownerID)
     plname = getattr(planet, 'name', res.getUnknownName())
     item = ui.Item(plname,
                    text_raw=getattr(planet, 'plEn', plname),
                    planetID=planet.oid,
                    plOwner=ownerName,
                    foreground=color)
     return item
예제 #4
0
    def _analyzeRelations(self, playerID, fleet):
        # this evaluates color, and if it should be shown at all
        # get check box selections
        checkBoxes = [
            self.win.vEnemy.checked, self.win.vUnfriendy.checked,
            self.win.vNeutral.checked, self.win.vFriendly.checked,
            self.win.vAllied.checked
        ]

        # check fleet color and decide if display the fleet
        if hasattr(fleet, 'owner'):
            plRelation = client.getRelationTo(fleet.owner)
            fgColor = res.getPlayerColor(fleet.owner)
            if fleet.owner == playerID and self.win.vMine.checked:
                return fgColor
            return fgColor if checkBoxes[bisect.bisect(Const.REL_BOUNDARIES,
                                                       plRelation)] else None
        else:
            # with no owner assume enemy
            return res.getFFColorCode(
                Const.REL_ENEMY_LO) if checkBoxes[0] else None
예제 #5
0
    def showTechs(self):
        # techs
        items = []
        select = None

        showMilitary = self.win.vMilitary.checked
        showBio = self.win.vBioProduction.checked
        showEn = self.win.vEnProduction.checked
        showCP = self.win.vCPProduction.checked
        showRP = self.win.vRPProduction.checked
        showMorale = self.win.vMorale.checked

        showSmall = self.win.vSmall.checked
        showMed = self.win.vMedium.checked
        showLarge = self.win.vLarge.checked
        showCivShip = self.win.vCivShip.checked
        showMilShip = self.win.vMilShip.checked

        for techID in client.getPlayer().techs.keys():
            tech = client.getTechInfo(techID)

            # hide pirate techs from ships and miscs view
            if not self.showStructures and tech.level == 99:
                continue

            if tech.isStructure:
                if (tech.isMilitary or getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0 or \
                        getattr(tech, "prodEn", 0) > 0 or getattr(tech, "prodProd", 0) > 0 or \
                        getattr(tech, "prodSci", 0) > 0 or getattr(tech, "moraleTrgt", 0) > 0):
                    if not ((tech.isMilitary and showMilitary) or \
                           ((getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0) and showBio) or \
                            (getattr(tech, "prodEn", 0) > 0 and showEn) or \
                            (getattr(tech, "prodProd", 0) > 0 and showCP) or \
                            (getattr(tech, "prodSci", 0) > 0 and showRP) or \
                            (getattr(tech, "moraleTrgt", 0) > 0 and showMorale)):
                        continue

            if self.prodProd > 0:
                etc = math.ceil(float(tech.buildProd) / self.prodProd)
                if self.targetID != self.planetID:
                    etc *= Rules.buildOnAnotherPlanetMod
                etc = res.formatTime(etc)
            else:
                etc = _("N/A")
            item = ui.Item(tech.name,
                tLevel = tech.level,
                tProd = tech.buildProd,
                techID = techID,
                tIsShip = 0,
                tETC = etc,
            )
            if item.tLevel > self.maxTechLevel:
                self.maxTechLevel = item.tLevel

            if item.tLevel in self.showLevels and \
                ((self.showStructures and tech.isStructure) or \
                (self.showOther and (tech.isProject))):
                items.append(item)
                if techID == self.techID:
                    select = item

        # special handling for ships
        player = client.getPlayer()
        if self.showShips:
            for designID in player.shipDesigns.keys():
                tech = player.shipDesigns[designID]

                if not ((tech.combatClass == 0 and showSmall) or (tech.combatClass == 1 and showMed) or (tech.combatClass == 2 and showLarge)):
                    continue

                if not ((tech.isMilitary and showMilShip) or (not tech.isMilitary and showCivShip)):
                    continue

                if tech.upgradeTo != OID_NONE:
                    # skip ships that are set to upgrade
                    continue
                if self.prodProd > 0:
                    etc = res.formatTime(math.ceil(float(tech.buildProd) / self.prodProd))
                else:
                    etc = _("N/A")
                item = ui.Item(tech.name,
                    tLevel = tech.level,
                    tProd = tech.buildProd,
                    techID = designID,
                    tIsShip = 1,
                    tETC = etc,
                )
                items.append(item)
                if designID == self.techID:
                    select = item
        # sort it by level and then by name
        items.sort(lambda a, b: cmp((100 - a.tLevel, a.text), (100 - b.tLevel, b.text)))
        self.win.vTechs.items = items
        self.win.vTechs.itemsChanged()
        self.win.vTechs.selectItem(select)
        # filter
        for i in xrange(1, 10):
            widget = getattr(self.win, 'vLevel%d' % i)
            if i in self.showLevels and i <= self.maxTechLevel:
                widget.visible = 1
                widget.pressed = 1
            elif i not in self.showLevels and i <= self.maxTechLevel:
                widget.visible = 1
                widget.pressed = 0
            else:
                widget.visible = 0
        self.win.vStructuresToggle.pressed = self.showStructures
        self.win.vShipsToggle.pressed = self.showShips
        self.win.vOtherToggle.pressed = self.showOther
        # targets
        info = []
        system = client.get(self.systemID, noUpdate = 1)
        select = None
        if hasattr(system, 'planets'):
            for planetID in system.planets:
                planet = client.get(planetID, noUpdate = 1)
                owner = res.getUnknownName()
                #rel = REL_UNDEF
                ownerID = OID_NONE
                if hasattr(planet, 'owner'):
                    ownerID = planet.owner
                    if planet.owner != OID_NONE:
                        owner = client.get(planet.owner, noUpdate = 1).name
                        #rel = client.getRelationTo(planet.owner)
                    else:
                        owner = _('[Nobody]')
                if planet.plType in ("A", "G"):
                    color = gdata.sevColors[gdata.DISABLED]
                else:
                    #color = res.getFFColorCode(rel)
                    color = res.getPlayerColor(ownerID)
                plname = getattr(planet, 'name', res.getUnknownName())
                item = ui.Item(
                    plname,
                    text_raw = getattr(planet, 'plEn', plname),
                    planetID = planetID,
                    plOwner = owner,
                    foreground = color,
                )
                info.append(item)
                if planetID == self.targetID:
                    select = item
        self.win.vTargets.items = info
        self.win.vTargets.itemsChanged()
        self.win.vTargets.selectItem(select)
        # quantity
        self.win.vQuantity.text = str(self.quantity)
예제 #6
0
    def show(self):
        items = []
        player = client.getPlayer()
        #
        for systemID in client.db.keys():
            if systemID == player.oid:
                continue
            system = client.get(systemID, noUpdate=1)

            if not hasattr(system, 'planets'):
                continue
            planetsMine = 0
            planetsOwned = 0
            planetsUnowned = 0
            planetsGA = 0
            planetsNotMine = 0
            en = 0
            bio = 0
            enres = 0
            biores = 0
            stratRes = Const.SR_NONE
            refuelMax = 0
            refuelInc = 0
            upgradeShip = 0
            repairShip = 0
            speedBoost = 0
            useOwner = Const.OID_NONE
            for planetID in system.planets:
                planet = client.get(planetID, noUpdate=1)
                owner = getattr(planet, 'owner', Const.OID_NONE)
                if owner != Const.OID_NONE:
                    useOwner = owner
                    if owner == player.oid:
                        planetsMine += 1
                    else:
                        planetsOwned += 1
                        if self.showOtherPlayers:
                            planetsNotMine += 1
                    en += getattr(planet, 'changeEn', 0)
                    bio += getattr(planet, 'changeBio', 0)
                    enres += getattr(planet, 'storEn', 0)
                    biores += getattr(planet, 'storBio', 0)
                    stratRes = getattr(planet, 'plStratRes', Const.SR_NONE) if stratRes == Const.SR_NONE else stratRes
                    refuelMax = max(getattr(planet, 'refuelMax', 0), refuelMax)
                    refuelInc = max(getattr(planet, 'refuelInc', 0), refuelInc)
                    upgradeShip += getattr(planet, 'upgradeShip', 0)
                    repairShip = max(getattr(planet, 'repairShip', 0), repairShip)
                    speedBoost = max(getattr(planet, 'fleetSpeedBoost', 0), speedBoost)
                else:
                    if hasattr(planet, "plType") and planet.plType in ("A", "G"):
                        planetsGA += 1
                        if self.showUncolonizable:
                            planetsNotMine += 1
                    else:
                        planetsUnowned += 1
                        if self.showColonizable:
                            planetsNotMine += 1
            if planetsMine == 0:  # fix no-data systems
                en = '?'
                bio = '?'
                enres = '?'
                biores = '?'
            if ((planetsMine and self.showMine)
                    or (planetsOwned and self.showOtherPlayers)
                    or (planetsUnowned and self.showColonizable)
                    or (planetsGA and self.showUncolonizable)):
                if stratRes == Const.SR_NONE:
                    stratResText = ' '
                else:
                    stratResText = gdata.stratRes[stratRes]
                problem = (bio < 0 or en < 0)
                if planetsMine > 0:  # make sure you own it
                    useOwner = player.oid
                if speedBoost > 1:
                    speedBoost = int((speedBoost - 1) * 100)
                else:
                    speedBoost = ''
                if self.showProblems:
                    color = res.getSystemOverviewProblemColor(useOwner, problem)
                else:
                    color = res.getPlayerColor(useOwner)
                item = ui.Item(
                    getattr(system, 'name', res.getUnknownName()),
                    tSyPnum=planetsMine + planetsOwned + planetsUnowned + planetsGA,
                    tSyPTnum=planetsNotMine,
                    tSyPYnum=planetsMine,
                    tSyBioRes=biores,
                    tSyEnRes=enres,
                    tSyBio=bio,
                    tSyEn=en,
                    tSyRefuel=refuelInc,
                    tSyRefuelMax=refuelMax,
                    tSyRepair=(repairShip * 100),
                    tSyUpgrade=int(upgradeShip),
                    tSyGate=speedBoost,
                    tStRes=_(stratResText),
                    tSysID=systemID,
                    foreground=color,
                )
                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
        self.win.vProblems = self.showProblems
예제 #7
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
예제 #8
0
 def show(self):
     items = []
     player = client.getPlayer()
     #
     for systemID in client.db.keys():
         if systemID == player.oid:
             continue
         system = client.get(systemID, noUpdate=1)
         if hasattr(system, "planets"):
             planetsMine = 0
             planetsOwned = 0
             planetsUnowned = 0
             planetsGA = 0
             planetsNotMine = 0
             en = 0
             bio = 0
             enres = 0
             biores = 0
             stratRes = SR_NONE
             refuelMax = 0
             refuelInc = 0
             upgradeShip = 0
             repairShip = 0
             speedBoost = 0
             useOwner = OID_NONE
             for planetID in system.planets:
                 planet = client.get(planetID, noUpdate=1)
                 owner = getattr(planet, "owner", OID_NONE)
                 if owner != OID_NONE:
                     useOwner = owner
                     if owner == player.oid:
                         planetsMine += 1
                     else:
                         planetsOwned += 1
                         if self.showOtherPlayers:
                             planetsNotMine += 1
                     if hasattr(planet, "changeEn"):
                         en += planet.changeEn
                     if hasattr(planet, "changeBio"):
                         bio += planet.changeBio
                     if hasattr(planet, "storEn"):
                         enres += planet.storEn
                     if hasattr(planet, "storBio"):
                         biores += planet.storBio
                     if hasattr(planet, "plStratRes") and planet.plStratRes != SR_NONE:
                         stratRes = gdata.stratRes[planet.plStratRes]
                     if hasattr(planet, "refuelMax"):
                         refuelMax = max(refuelMax, planet.refuelMax)
                         refuelInc = max(refuelInc, planet.refuelInc)
                     if hasattr(planet, "repairShip"):
                         upgradeShip += planet.upgradeShip
                         repairShip = max(repairShip, planet.repairShip)
                     if hasattr(planet, "fleetSpeedBoost"):
                         speedBoost = max(speedBoost, planet.fleetSpeedBoost)
                 else:
                     if hasattr(planet, "plType") and planet.plType in ("A", "G"):
                         planetsGA += 1
                         if self.showUncolonizable:
                             planetsNotMine += 1
                     else:
                         planetsUnowned += 1
                         if self.showColonizable:
                             planetsNotMine += 1
             if planetsMine == 0:  # fix no-data systems
                 en = "?"
                 bio = "?"
                 enres = "?"
                 biores = "?"
             if (
                 (planetsMine and self.showMine)
                 or (planetsOwned and self.showOtherPlayers)
                 or (planetsUnowned and self.showColonizable)
                 or (planetsGA and self.showUncolonizable)
             ):
                 if stratRes == SR_NONE:
                     stratRes = " "
                 problem = bio < 0 or en < 0
                 if planetsMine > 0:  # make sure you own it
                     useOwner = player.oid
                 if speedBoost > 1:
                     speedBoost = (int)((speedBoost - 1) * 100)
                 else:
                     speedBoost = ""
                 if self.showProblems:
                     color = res.getSystemOverviewProblemColor(useOwner, problem)
                 else:
                     color = res.getPlayerColor(useOwner)
                 item = ui.Item(
                     getattr(system, "name", res.getUnknownName()),
                     tSyPnum=planetsMine + planetsOwned + planetsUnowned + planetsGA,
                     tSyPTnum=planetsNotMine,
                     tSyPYnum=planetsMine,
                     tSyBioRes=biores,
                     tSyEnRes=enres,
                     tSyBio=bio,
                     tSyEn=en,
                     tSyRefuel=refuelInc,
                     tSyRefuelMax=refuelMax,
                     tSyRepair=(repairShip * 100),
                     tSyUpgrade=int(upgradeShip),  # return an integer version
                     tSyGate=speedBoost,
                     tStRes=_(stratRes),
                     tSysID=systemID,
                     foreground=color,
                 )
                 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
     self.win.vProblems = self.showProblems
예제 #9
0
 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)
예제 #10
0
    def show(self):
        # get check box selections
        mine = self.win.vMine.checked
        enemy = self.win.vEnemy.checked
        unfriendly = self.win.vUnfriendy.checked
        neutral = self.win.vNeutral.checked
        friendly = self.win.vFriendly.checked
        allied = self.win.vAllied.checked
        redirects = self.win.vRedirects.checked

        player = client.getPlayer()
        #
        items = []
        for fleetID in client.db.keys():
            fleet = client.get(fleetID, noUpdate = 1)
            # skip non-fleets
            if not hasattr(fleet, "type") or (fleet.type != T_FLEET and fleet.type != T_ASTEROID):
                continue
            # shall be shown?
            fgColor = None

            ownerName = ""
            ownerNameTip = ""

            # check fleet color and if display fleet
            if hasattr(fleet, 'owner'):
                plRelation = client.getRelationTo(fleet.owner)
                fgColor = res.getPlayerColor(fleet.owner)
                ok = 0
                if mine and fleet.owner == player.oid:
                    ok = 1
                elif enemy and plRelation >= REL_ENEMY_LO and plRelation < REL_ENEMY_HI:
                    ok = 1
                elif unfriendly and plRelation >= REL_UNFRIENDLY_LO and plRelation < REL_UNFRIENDLY_HI:
                    ok = 1
                elif neutral and plRelation >= REL_NEUTRAL_LO and plRelation < REL_NEUTRAL_HI:
                    ok = 1
                elif friendly and plRelation >= REL_FRIENDLY_LO and plRelation < REL_FRIENDLY_HI:
                    ok = 1
                elif allied and plRelation >= REL_ALLY_LO and plRelation < REL_ALLY_HI:
                    ok = 1

                if not ok:
                    continue

                if fleet.owner != player.oid:
                    owner = getattr(client.get(fleet.owner, noUpdate = 1), "name", res.getUnknownName())
                    ownerName = " (%s)" % owner
                    ownerNameTip = owner
            else:
                # asteroids has no owner
                fgColor = res.getFFColorCode(0) #enemy
                if not enemy:
                    continue

            # check position of fleet
            system = None
            systemName = "-"
            if hasattr(fleet, 'orbiting') and fleet.orbiting:
                system = client.get(fleet.orbiting, noUpdate = 1)
                systemName = getattr(system, "name", res.getUnknownName())
            elif hasattr(fleet, 'closeSystem'):
                system = client.get(fleet.closeSystem, noUpdate = 1)
                systemName = _("%s (dst)") % getattr(system, "name", res.getUnknownName())

            # get fleet current action and target of action
            order = "-"
            targetName = "-"
            if hasattr(fleet, 'actions'):
                if fleet.actionIndex < len(fleet.actions):
                    action, target, data  = fleet.actions[fleet.actionIndex]
                    if action == FLACTION_REDIRECT and not redirects:
                        continue
                    order = gdata.fleetActions[action]
                    if target != OID_NONE:
                        targetName = getattr(client.get(target, noUpdate = 1), 'name', res.getUnknownName())
                        order = "%s %s" % (order, targetName)
            # eta
            if hasattr(fleet, "eta"): eta = res.formatTime(fleet.eta)
            else: eta = "?"

            # fuel
            if hasattr(fleet, "storEn"):
                if fleet.maxEn > 0: fuel = 100 * fleet.storEn / fleet.maxEn
                else: fuel = 0
            else:
                fuel = "?"

            # operational time
            if hasattr(fleet, 'storEn') and hasattr(fleet, 'operEn'):
                turns = 100000
                if fleet.operEn > 0: turns = fleet.storEn / fleet.operEn
                rawRange = turns * fleet.speed / Rules.turnsPerDay
                range = "%.2f" % rawRange
                opTime = res.formatTime(turns)
            else:
                rawRange = 0
                range = "?"
                opTime = "?"

            # last upgrade
            if hasattr(fleet, "lastUpgrade"):
                lastUpgrade = res.formatTime(fleet.lastUpgrade)
            else:
                lastUpgrade = "?"

            if hasattr(fleet,'customname') and fleet.customname:
                fleetname = fleet.customname
            else:
                fleetname = getattr(fleet, 'name', res.getUnknownName())

            # create ListBox Item for fleet
            item = ui.Item(
                "%s %s" % (fleetname, ownerName),
                tooltip = ownerNameTip,
                tLocation = systemName,
                tOrder = order,
                tMP = getattr(fleet, "combatPwr", "?"),
                tETA = eta,
                tETA_raw = getattr(fleet, "eta", 0),
                tSignature = getattr(fleet, "signature", "?"),
                tFuel = fuel,
                tOpTime = opTime,
                tRange = range,
                tRange_raw = rawRange,
                tLastUpgrade = lastUpgrade,
                tFleetID = fleetID,
                foreground = fgColor)
            items.append(item)

        self.win.vFleets.items = items
        self.win.vFleets.itemsChanged()
예제 #11
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
예제 #12
0
    def showTechs(self):
        # techs
        items = []
        select = None

        showMilitary = self.win.vMilitary.checked
        showBio = self.win.vBioProduction.checked
        showEn = self.win.vEnProduction.checked
        showCP = self.win.vCPProduction.checked
        showRP = self.win.vRPProduction.checked
        showMorale = self.win.vMorale.checked

        showSmall = self.win.vSmall.checked
        showMed = self.win.vMedium.checked
        showLarge = self.win.vLarge.checked
        showCivShip = self.win.vCivShip.checked
        showMilShip = self.win.vMilShip.checked

        for techID in client.getPlayer().techs.keys():
            tech = client.getTechInfo(techID)

            # hide pirate techs from ships and miscs view
            if not self.showStructures and tech.level == 99:
                continue

            if tech.isStructure:
                if (tech.isMilitary or getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0 or \
                        getattr(tech, "prodEn", 0) > 0 or getattr(tech, "prodProd", 0) > 0 or \
                        getattr(tech, "prodSci", 0) > 0 or getattr(tech, "moraleTrgt", 0) > 0):
                    if not ((tech.isMilitary and showMilitary) or \
                           ((getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0) and showBio) or \
                            (getattr(tech, "prodEn", 0) > 0 and showEn) or \
                            (getattr(tech, "prodProd", 0) > 0 and showCP) or \
                            (getattr(tech, "prodSci", 0) > 0 and showRP) or \
                            (getattr(tech, "moraleTrgt", 0) > 0 and showMorale)):
                        continue

            if self.prodProd > 0:
                etc = math.ceil(float(tech.buildProd) / self.prodProd)
                if self.targetID != self.planetID:
                    etc *= Rules.buildOnAnotherPlanetMod
                etc = res.formatTime(etc)
            else:
                etc = _("N/A")
            item = ui.Item(
                tech.name,
                tLevel=tech.level,
                tProd=tech.buildProd,
                techID=techID,
                tIsShip=0,
                tETC=etc,
            )
            if item.tLevel > self.maxTechLevel:
                self.maxTechLevel = item.tLevel

            if item.tLevel in self.showLevels and \
                ((self.showStructures and tech.isStructure) or \
                (self.showOther and (tech.isProject))):
                items.append(item)
                if techID == self.techID:
                    select = item

        # special handling for ships
        player = client.getPlayer()
        if self.showShips:
            for designID in player.shipDesigns.keys():
                tech = player.shipDesigns[designID]

                if not ((tech.combatClass == 0 and showSmall) or
                        (tech.combatClass == 1 and showMed) or
                        (tech.combatClass == 2 and showLarge)):
                    continue

                if not ((tech.isMilitary and showMilShip) or
                        (not tech.isMilitary and showCivShip)):
                    continue

                if tech.upgradeTo != Const.OID_NONE:
                    # skip ships that are set to upgrade
                    continue
                if self.prodProd > 0:
                    etc = res.formatTime(
                        math.ceil(float(tech.buildProd) / self.prodProd))
                else:
                    etc = _("N/A")
                item = ui.Item(
                    tech.name,
                    tLevel=tech.level,
                    tProd=tech.buildProd,
                    techID=designID,
                    tIsShip=1,
                    tETC=etc,
                )
                items.append(item)
                if designID == self.techID:
                    select = item
        # sort it by level and then by name
        items.sort(key=lambda a: (100 - a.tLevel, a.text))
        self.win.vTechs.items = items
        self.win.vTechs.itemsChanged()
        self.win.vTechs.selectItem(select)
        # filter
        for i in xrange(1, 10):
            widget = getattr(self.win, 'vLevel%d' % i)
            if i in self.showLevels and i <= self.maxTechLevel:
                widget.visible = 1
                widget.pressed = 1
            elif i not in self.showLevels and i <= self.maxTechLevel:
                widget.visible = 1
                widget.pressed = 0
            else:
                widget.visible = 0
        self.win.vStructuresToggle.pressed = self.showStructures
        self.win.vShipsToggle.pressed = self.showShips
        self.win.vOtherToggle.pressed = self.showOther
        # targets
        info = []
        system = client.get(self.systemID, noUpdate=1)
        select = None
        if hasattr(system, 'planets'):
            for planetID in system.planets:
                planet = client.get(planetID, noUpdate=1)
                owner = res.getUnknownName()
                #rel = Const.REL_UNDEF
                ownerID = Const.OID_NONE
                if hasattr(planet, 'owner'):
                    ownerID = planet.owner
                    if planet.owner != Const.OID_NONE:
                        owner = client.get(planet.owner, noUpdate=1).name
                        #rel = client.getRelationTo(planet.owner)
                    else:
                        owner = _('[Nobody]')
                if planet.plType in ("A", "G"):
                    color = gdata.sevColors[gdata.DISABLED]
                else:
                    #color = res.getFFColorCode(rel)
                    color = res.getPlayerColor(ownerID)
                plname = getattr(planet, 'name', res.getUnknownName())
                item = ui.Item(
                    plname,
                    text_raw=getattr(planet, 'plEn', plname),
                    planetID=planetID,
                    plOwner=owner,
                    foreground=color,
                )
                info.append(item)
                if planetID == self.targetID:
                    select = item
        self.win.vTargets.items = info
        self.win.vTargets.itemsChanged()
        self.win.vTargets.selectItem(select)
        # quantity
        self.win.vQuantity.text = str(self.quantity)
예제 #13
0
 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)
예제 #14
0
    def show(self):
        # get check box selections
        mine = self.win.vMine.checked
        enemy = self.win.vEnemy.checked
        unfriendly = self.win.vUnfriendy.checked
        neutral = self.win.vNeutral.checked
        friendly = self.win.vFriendly.checked
        allied = self.win.vAllied.checked
        redirects = self.win.vRedirects.checked

        player = client.getPlayer()
        #
        items = []
        for fleetID in client.db.keys():
            fleet = client.get(fleetID, noUpdate=1)
            # skip non-fleets
            if not hasattr(fleet, "type") or (fleet.type != Const.T_FLEET and
                                              fleet.type != Const.T_ASTEROID):
                continue
            # shall be shown?
            fgColor = None

            ownerTipTitle = ""
            ownerName = ""
            ownerNameTip = ""

            # check fleet color and if display fleet
            if hasattr(fleet, 'owner'):
                plRelation = client.getRelationTo(fleet.owner)
                fgColor = res.getPlayerColor(fleet.owner)
                ok = 0
                if mine and fleet.owner == player.oid:
                    ok = 1
                elif enemy and plRelation >= Const.REL_ENEMY_LO and plRelation < Const.REL_ENEMY_HI:
                    ok = 1
                elif unfriendly and plRelation >= Const.REL_UNFRIENDLY_LO and plRelation < Const.REL_UNFRIENDLY_HI:
                    ok = 1
                elif neutral and plRelation >= Const.REL_NEUTRAL_LO and plRelation < Const.REL_NEUTRAL_HI:
                    ok = 1
                elif friendly and plRelation >= Const.REL_FRIENDLY_LO and plRelation < Const.REL_FRIENDLY_HI:
                    ok = 1
                elif allied and plRelation >= Const.REL_ALLY_LO and plRelation < Const.REL_ALLY_HI:
                    ok = 1

                if not ok:
                    continue

                if fleet.owner != player.oid:
                    owner = getattr(client.get(fleet.owner, noUpdate=1),
                                    "name", res.getUnknownName())
                    ownerName = " (%s)" % owner
                    ownerNameTip = owner
                    ownerTipTitle = _("Owner")
            else:
                # asteroids has no owner
                fgColor = res.getFFColorCode(0)  #enemy
                if not enemy:
                    continue

            # check position of fleet
            system = None
            systemName = "-"
            if hasattr(fleet, 'orbiting') and fleet.orbiting:
                system = client.get(fleet.orbiting, noUpdate=1)
                systemName = getattr(system, "name", res.getUnknownName())
            elif hasattr(fleet, 'closeSystem'):
                system = client.get(fleet.closeSystem, noUpdate=1)
                systemName = _("%s (dst)") % getattr(system, "name",
                                                     res.getUnknownName())

            # get fleet current action and target of action
            order = "-"
            targetName = "-"
            if hasattr(fleet, 'actions'):
                if fleet.actionIndex < len(fleet.actions):
                    action, target, data = fleet.actions[fleet.actionIndex]
                    if action == Const.FLACTION_REDIRECT and not redirects:
                        continue
                    order = gdata.fleetActions[action]
                    if target != Const.OID_NONE:
                        targetName = getattr(client.get(target, noUpdate=1),
                                             'name', res.getUnknownName())
                        order = "%s %s" % (order, targetName)
            # eta
            if hasattr(fleet, "eta"): eta = res.formatTime(fleet.eta)
            else: eta = "?"

            # fuel
            if hasattr(fleet, "storEn"):
                if fleet.maxEn > 0: fuel = 100 * fleet.storEn / fleet.maxEn
                else: fuel = 0
            else:
                fuel = "?"

            # operational time
            if hasattr(fleet, 'storEn') and hasattr(fleet, 'operEn'):
                turns = 100000
                if fleet.operEn > 0: turns = fleet.storEn / fleet.operEn
                rawRange = turns * fleet.speed / Rules.turnsPerDay
                range = "%.2f" % rawRange
                opTime = res.formatTime(turns)
            else:
                rawRange = 0
                range = "?"
                opTime = "?"

            # last upgrade
            if hasattr(fleet, "lastUpgrade"):
                lastUpgrade = res.formatTime(fleet.lastUpgrade)
            else:
                lastUpgrade = "?"

            if hasattr(fleet, 'customname') and fleet.customname:
                fleetname = fleet.customname
            else:
                fleetname = getattr(fleet, 'name', res.getUnknownName())

            # create ListBox Item for fleet
            item = ui.Item("%s %s" % (fleetname, ownerName),
                           tooltipTitle=ownerTipTitle,
                           tooltip=ownerNameTip,
                           tLocation=systemName,
                           tOrder=order,
                           tMP=getattr(fleet, "combatPwr", "?"),
                           tETA=eta,
                           tETA_raw=getattr(fleet, "eta", 0),
                           tSignature=getattr(fleet, "signature", "?"),
                           tFuel=fuel,
                           tOpTime=opTime,
                           tRange=range,
                           tRange_raw=rawRange,
                           tLastUpgrade=lastUpgrade,
                           tFleetID=fleetID,
                           foreground=fgColor)
            items.append(item)

        self.win.vFleets.items = items
        self.win.vFleets.itemsChanged()