def loadAmmo(self): """Load Ammunition into weapon chamber, only grab proper ammo from same quadrant""" if type(self.myWeaponData) == types.StringType: return 1 if self.currentAmmo == 1: return 1 else: # go through all components in ship, look for ammo components that match weapon ABR self.availAmmo = 0 for position in self.myQuad.myParent.positions: myQuad = self.myQuad.myParent.quads[position] componentIDList = funcs.sortStringList( myQuad.components.keys()) for componentID in componentIDList: myComponent = myQuad.components[componentID] if (myComponent.myComponentData.abr == (self.myWeaponData.abr + 'A') and myComponent.currentAmount > 0): self.availAmmo += myComponent.currentAmount if self.currentAmmo == 0: myComponent.currentAmount -= 1 self.currentAmmo += 1 self.availAmmo -= 1 if self.availAmmo == 0 and self.currentAmmo == 0: self.operational = 0 return self.currentAmmo
def populateDronesToList(self): """Carriers or Platforms can add drones as weapons""" if self.myShipHull.function in ('carrier', 'platform'): for droneDesignID in funcs.sortStringList(self.mode.game.droneDesigns.keys()): myDroneDesign = self.mode.game.droneDesignObjects[droneDesignID] if self.mode.allTech == 1 or myDroneDesign.hasAllTech == 1: self.weaponlist.myScrolledList.addItem(text=myDroneDesign.name, extraArgs='D' + droneDesignID)
def populateShipDesignList(self): """Fill the list with Ship designs""" for shipDesignID in funcs.sortStringList(self.game.shipDesigns.keys()): myShipDesign = self.game.shipDesignObjects[shipDesignID] if self.allTech == 1 or myShipDesign.hasAllTech == 1: self.shipdesignList.myScrolledList.addItem( text=myShipDesign.name, extraArgs=shipDesignID)
def createShips(self): """Take shipBattle ships dict and add Ships to Simulator""" for shipID in funcs.sortStringList(self.shipBattle.shipsDict.keys()): myShipDict = self.shipBattle.shipsDict[shipID] myShip = ship.Ship(myShipDict) myShip.setMyGalaxy(self) myShip.targets = myShipDict['targets'] myCaptain = self.captains[myShip.captainID] myShip.setMyCaptain(myCaptain) myEmpire = self.empires[myShip.empireID] myShipDesign = myEmpire.shipDesigns[myShip.designID] myShip.setFromDict(myShipDesign, myShipDict) myShip.setKObj() if globals.serverMode == 0: myShip.sim = shipsim.ShipSim(self.guiMediaPath, self, myShip) myShip.setShipsim(myShip.sim) if myShip.isTransport == 1: texture = myShip.shipsim.texture[:-9] + 'transport_%s.png' % myShip.empireID myShip.shipsim.texture = texture myShip.shipsim.loadMyTexture() self.kworld.addShip(myShip) if globals.serverMode == 0: self.setPlanePickable(myShip, 'ships') self.sims.append(myShip.sim)
def clearIndustrySims(self): """Remove all Industry Indicator Sims""" for id in funcs.sortStringList(self.mode.game.industrydata.keys()): industryData = self.mode.game.industrydata[id] code = self.mode.game.industrydata[id].abr[1:] myAttr = getattr(self, 'sim%s' % code) if myAttr != None: myAttr.removeNode()
def resetTopIndustry(self): """Reset the dict of topIndustry to see what is available to build based on current tech""" self.topIndustry = {} for dataID in funcs.sortStringList(self.myGalaxy.industrydata.keys()): myIndustryData = self.myGalaxy.industrydata[dataID] if self.myEmpire.techTree[myIndustryData.techReq].complete == 1: id = myIndustryData.abr[1:] self.topIndustry[id] = myIndustryData
def populateDroneDesignList(self): """Fill the list with Drone designs""" for droneDesignID in funcs.sortStringList( self.game.droneDesigns.keys()): myDroneDesign = self.game.droneDesignObjects[droneDesignID] if self.allTech == 1 or myDroneDesign.hasAllTech == 1: self.dronedesignList.myScrolledList.addItem( text=myDroneDesign.name, extraArgs=droneDesignID)
def populateRepairFrom(self): self.repairFrom = [] for industryID in funcs.sortStringList( self.mode.game.myEmpire['industryOrders'].keys()): myOrder = self.mode.game.myEmpire['industryOrders'][industryID] if myOrder['type'] == 'Repair Starship' and myOrder[ 'round'] == self.mode.game.currentRound and myOrder[ 'system'] == self.mySystemDict['id']: self.repairFrom.append(myOrder)
def genDroneDesign(self, myEmpire): """Generate Drone Design for Empire""" droneIDs = funcs.sortStringList(self.myGalaxy.droneDesigns.keys()) for key in droneIDs: droneDesignDict = self.myGalaxy.droneDesigns[key] myEmpire.genDroneDesign(droneDesignDict['name'], droneDesignDict['hull'], droneDesignDict['compDict'], droneDesignDict['weapDict'], 1)
def populateDamagedFrom(self): self.damagedFrom = [] for shipID in funcs.sortStringList(self.mode.game.myShips.keys()): myShip = self.mode.game.myShips[shipID] if (myShip['fromSystem'] == myShip['toSystem'] and myShip['fromSystem'] == self.mySystemDict['id'] and myShip['strength'] < 100 and self.isNotBeingRepaired(shipID)): self.damagedFrom.append(myShip)
def populateRegimentList(self): """Fill the list with available regiments""" for regimentdataID in funcs.sortStringList( self.mode.game.regimentdata.keys()): myRegimentData = self.mode.game.regimentdata[regimentdataID] if (self.mode.game.myTech[myRegimentData.techReq].complete == 1 and myRegimentData.abr[2] != 'L'): self.regimentList.myScrolledList.addItem( text=myRegimentData.name, extraArgs=regimentdataID)
def powerWeapons(self, interval, availPower): """Power all available weapons, then return any unused power""" if self.allWeaponsPowered == 0: weaponList = [] for position, myQuad in self.quads.iteritems(): weaponIDList = [] weaponIDList.extend(funcs.sortStringList( myQuad.weapons.keys())) for wID in weaponIDList: weaponList.append(myQuad.weapons[wID]) while availPower > 0 and self.allWeaponsPowered == 0: toCharge = [] toChargeAMS = [] # go through each quadrant looking for weapons to power for myWeapon in weaponList: if myWeapon.operational == 1 and myWeapon.currentPower < myWeapon.myWeaponData.maxPower: if 1 == myWeapon.myWeaponData.AMS: toChargeAMS.append(myWeapon) else: toCharge.append(myWeapon) if len(toChargeAMS) == 0 and len(toCharge) == 0: self.allWeaponsPowered = 1 return availPower #AMS are charged first and sequentially if len(toChargeAMS) != 0: if availPower != 0: for myW in toChargeAMS: defecit = myW.myWeaponData.maxPower - myW.currentPower if defecit >= availPower: myW.currentPower += availPower availPower = 0 break else: myW.currentPower = myW.myWeaponData.maxPower availPower -= defecit #non-AMS weapons are charged concurrently; each gets an equal share of the available power if len(toCharge) != 0: kW = availPower / len(toCharge) if kW != 0: #print "tT:",len(toCharge),"aP:",availPower,"kW each:",kW for myW in toCharge: defecit = myW.myWeaponData.maxPower - myW.currentPower if defecit >= kW: myW.currentPower += kW availPower -= kW else: myW.currentPower = myW.myWeaponData.maxPower availPower -= kW - defecit else: availPower = 0 return availPower
def populateNewShipDesignList(self): """Fill the list with Ship designs""" for shipDesignID in funcs.sortStringList(self.mode.game.shipDesigns.keys()): myShipDesign = self.mode.game.shipDesignObjects[shipDesignID] if myShipDesign.hasAllTech == 1: color = 'guiwhite' else: color = 'guigrey' self.newShipDesignList.myScrolledList.addItem(text=myShipDesign.name, extraArgs=shipDesignID, textColorName=color)
def populateDamagedFrom(self): self.damagedFrom = [] for shipID in funcs.sortStringList(self.mode.game.myShips.keys()): myShip = self.mode.game.myShips[shipID] myShipDesign = self.mode.game.shipDesignObjects[myShip['designID']] if (myShip['fromSystem'] == myShip['toSystem'] and myShip['fromSystem'] == self.mySystemDict['id'] and (myShip['strength'] == 100 or (myShip['strength'] < 100 and myShipDesign.hasAllTech == 0)) and self.isNotBeingRepaired(shipID) and self.shipCanBeUpgradedToDesign(myShip)): self.damagedFrom.append(myShip)
def getMarketData(self): """Get the market Data""" rounds = funcs.sortStringList(self.game.marketStats.keys()) for round in rounds: marketStat = self.game.marketStats[round] self.prices['AL'].append(marketStat['avgSoldAL']) self.prices['EC'].append(marketStat['avgSoldEC']) self.prices['IA'].append(marketStat['avgSoldIA']) self.volume['AL'].append(marketStat['volSoldAL']) self.volume['EC'].append(marketStat['volSoldEC']) self.volume['IA'].append(marketStat['volSoldIA'])
def genShipDesign(self, myEmpire): """Generate Drone Design for Empire""" shipIDs = funcs.sortStringList(self.myGalaxy.shipDesigns.keys()) for key in shipIDs: shipDesignDict = self.myGalaxy.shipDesigns[key] myEmpire.genShipDesign(shipDesignDict['name'], shipDesignDict['hull'], shipDesignDict['compDict'], shipDesignDict['weapDict'], 1) for key, shipDesign in myEmpire.shipDesigns.iteritems(): if 'Marine Transport' in shipDesign.name: shipDesign.obsolete = 1
def populateDamagedFrom(self): self.damagedFrom = [] for regID in funcs.sortStringList(self.mode.game.myRegiments.keys()): myRegiment = self.mode.game.myRegiments[regID] myRegimentData = self.mode.game.regimentdata[myRegiment['typeID']] regType = myRegimentData.abr[1] if (myRegiment['fromSystem'] == myRegiment['toSystem'] and myRegiment['fromSystem'] == self.mySystemDict['id'] and myRegiment['strength'] == 100 and regType != 'P' and self.isNotBeingRepaired(regID)): if self.techAvailableForUpgrade(myRegiment): self.damagedFrom.append(myRegiment)
def populateRegimentBuildList(self): """Fill the list with Regiment Build Orders""" for industryID in funcs.sortStringList( self.mode.game.myEmpire['industryOrders'].keys()): myOrder = self.mode.game.myEmpire['industryOrders'][industryID] if myOrder['type'] == 'Add Regiment' and myOrder[ 'round'] == self.mode.game.currentRound and myOrder[ 'system'] == self.mySystemDict['id']: (amount, regimentDataID) = string.split(myOrder['value'], '-') self.cadetsNeeded += int(amount) myRegimentData = self.mode.game.regimentdata[regimentDataID] self.regimentBuildList.myScrolledList.addItem( text='Add %s %s' % (amount, myRegimentData.name), extraArgs=industryID)
def populateShipBuildList(self): """Fill the list with Ship Build Orders""" for industryID in funcs.sortStringList( self.mode.game.myEmpire['industryOrders'].keys()): myOrder = self.mode.game.myEmpire['industryOrders'][industryID] if myOrder['type'] == 'Add Ship' and myOrder[ 'round'] == self.mode.game.currentRound and myOrder[ 'system'] == self.mySystemDict['id']: (amount, shipDesignID) = string.split(myOrder['value'], '-') self.cadetsNeeded += int(amount) myShipDesign = self.mode.game.shipDesignObjects[shipDesignID] self.shipbuildList.myScrolledList.addItem( text='Add %s %s' % (amount, myShipDesign.name), extraArgs=industryID)
def populateWeaponList(self): """Add Weapons to List based on alltech or mytech""" myWeaponList = funcs.sortStringList(self.weapondata.keys()) myAges = self.getDataIntoTechAges(myWeaponList, self.weapondata) count = 0 for AgeList in myAges: for myWeaponData in AgeList: if self.mode.allTech == 1 or self.mode.game.myTech[myWeaponData.techReq].complete == 1: if (myWeaponData.abr not in globals.weaponLimitations[self.myShipHull.function] and myWeaponData.abr[2:] != 'L'): self.weaponlist.myScrolledList.addItem(text=myWeaponData.name, extraArgs='W' + myWeaponData.id, textColorName=self.ageColor[count]) count += 1 self.populateDronesToList()
def createDroneHulls(self, droneHullDict): """Create all the drone hulls""" positions = {'drone': [-2.6, 0.75]} myList = funcs.sortStringList(droneHullDict.keys()) for id in myList: myDroneHullDict = droneHullDict[id] (x, z) = positions[myDroneHullDict.function] myDroneHull = shiphull.DroneHull(self.guiMediaPath, self, self.game.myEmpireID, myDroneHullDict, x, z) myDroneHull.setMyMode(self) myDroneHull.setMyGame(self.game) self.dronehulls[myDroneHull.id] = myDroneHull self.gui.append(myDroneHull) positions[myDroneHullDict.function] = [x + 1.1, z] self.setPlanePickable(myDroneHull, 'dronehulls')
def updateWeaponStatus(self): """Update Weapons status if ship selected""" if self.myGalaxy.shipSelected == self: for position in self.positions: myQuad = self.quads[position] for id in funcs.sortStringList(myQuad.weapons.keys()): myWeapon = myQuad.weapons[id] self.updateMyGUIValue('%sweapon%sStatus' % (position, id), myWeapon.operational) self.updateMyGUIValue('%sweapon%sLock' % (position, id), myWeapon.currentLock) self.updateMyGUIValue('%sweapon%sPower' % (position, id), myWeapon.currentPower) if myWeapon.myWeaponData.ammo == 1 or myWeapon.droneID != '': self.updateMyGUIValue( '%sweapon%sAmmo' % (position, id), myWeapon.availAmmo)
def populateComponentList(self): """Add Components based on alltech or mytech""" myComponentList = funcs.sortStringList(self.componentdata.keys()) myAges = self.getDataIntoTechAges(myComponentList, self.componentdata) count = 0 for AgeList in myAges: for myComponentData in AgeList: if myComponentData.name != 'Weapon Component': if self.mode.allTech == 1 or self.mode.game.myTech[myComponentData.techReq].complete == 1: if (myComponentData.abr not in globals.componentLimitations[self.myShipHull.function] and myComponentData.abr not in ['CSE','CRT']): self.componentlist.myScrolledList.addItem(text=myComponentData.name, extraArgs='%s' % myComponentData.id, textColorName=self.ageColor[count]) elif (myComponentData.abr not in globals.componentLimitations[self.myShipHull.function] and self.id in ['8','9','10','11','12'] ): self.componentlist.myScrolledList.addItem(text=myComponentData.name, extraArgs='%s' % myComponentData.id, textColorName=self.ageColor[count]) count += 1
def createShipHulls(self, shipHullDict): """Create all the ship hulls, group by function type""" self.createHullTypeTitles() positions = { 'warship': [-6, 2.75], 'carrier': [-6, 0.75], 'assault': [-6, -1.25], 'platform': [-6, -3.25] } myList = funcs.sortStringList(shipHullDict.keys()) for id in myList: myShipHullDict = shipHullDict[id] (x, z) = positions[myShipHullDict.function] myShipHull = shiphull.ShipHull(self.guiMediaPath, self, self.game.myEmpireID, myShipHullDict, x, z) myShipHull.setMyMode(self) myShipHull.setMyGame(self.game) self.shiphulls[myShipHull.id] = myShipHull self.gui.append(myShipHull) positions[myShipHullDict.function] = [x + 1.1, z] self.setPlanePickable(myShipHull, 'shiphulls')
def createIndustrySims(self): """Create all Industry Indicator Sims""" count = 0 count2 = 0 hasSY = 0 for id in funcs.sortStringList(self.mode.game.industrydata.keys()): industryData = self.mode.game.industrydata[id] oldNum = self.systemDict['myOldIndustry'][id] newNum = self.systemDict['myIndustry'][id] if oldNum > 0 or newNum > 0: code = self.mode.game.industrydata[id].abr[1:] color = funcs.getFutureColor(newNum, oldNum) if code == 'SY': hasSY = 1 if code not in ['AF', 'CM', 'SS', 'SC', 'DC', 'RC']: myMethod = getattr(self, 'createSim%s' % code) myMethod(color, count) count += 1 else: myMethod = getattr(self, 'createSim%s' % code) myMethod(color, count2) count2 += 1 if hasSY == 0 and self.systemDict['availSYC'] > 0: self.createSimSY(globals.colors['guiwhite'], count)
def begin(self): """Start Simulation""" shipList = funcs.sortStringList(self.ships.keys()) for shipID in shipList: myShip = self.ships[shipID] myShip.begin()
def populateAllDesignsList(self): """Add All Designs to the List""" for shipDesignID in funcs.sortStringList(self.game.shipDesigns.keys()): myShipDesign = self.game.shipDesignObjects[shipDesignID] if self.mode.allTech == 1 or myShipDesign.hasAllTech == 1: self.allDesignsList.myScrolledList.addItem(text=myShipDesign.name, extraArgs=shipDesignID)
def populateBattleInfo(self): """Fill Battle Info with all past battles""" for key in funcs.sortStringList(self.game.shipBattleDict.keys()): name = self.game.shipBattleDict[key] self.battleInfo.myScrolledList.addItem(text=name, extraArgs=key)
def setMyChangingAttributes(self): """Setup all attributes that can change when ship is in simulation""" self.shipinfo = [[ 'shipISP', self.myShip.currentISP, self.myShip.myDesign.myShipHull.maxISP, 'STRUCTURE' ], ['shipStrength', self.myShip.strength, 100.0, '% STRENGTH'], [ 'shipAccel', self.myShip.accel, self.myShip.myDesign.accel, 'THRUST' ], [ 'shipRotation', self.myShip.rotation, self.myShip.myDesign.rotation, 'ROTATION' ], [ 'shipPower', self.myShip.currentPower, self.myShip.myDesign.maxPower, 'POWER' ], [ 'shipBattery', self.myShip.currentBattery, self.myShip.maxBattery, 'BATTERY' ], [ 'maxAssault', self.myShip.maxAssault, self.myShip.myDesign.maxAssault, 'MARINE ASSAULT' ]] self.quadinfo = [] for position in self.myShip.positions: if position in self.myShip.quads.keys(): shipQuad = self.myShip.quads[position] designQuad = self.myShip.myDesign.quads[position] self.quadinfo.append([ position + 'Shields', shipQuad.currentSP, designQuad.maxSP, '%s SHIELDS' % string.upper(position) ]) self.quadinfo.append([ position + 'Armor', shipQuad.currentAP, designQuad.maxAP, '%s ARMOR' % string.upper(position) ]) self.quadinfo.append([ position + 'Comps', shipQuad.currentComps, self.myShip.myDesign.myShipHull.componentNum, '%s COMPONENTS' % string.upper(position) ]) for id in funcs.sortStringList(shipQuad.weapons.keys()): myWeapon = shipQuad.weapons[id] self.weapinfo.append([ '%sweapon%sStatus' % (position, id), myWeapon.operational, 1, myWeapon.myWeaponData.name ]) self.weapinfo.append([ '%sweapon%sLock' % (position, id), myWeapon.currentLock, myWeapon.maxLock, 'LOCK' ]) self.weapinfo.append([ '%sweapon%sPower' % (position, id), myWeapon.currentPower, myWeapon.myWeaponData.maxPower, 'POWER' ]) if myWeapon.droneID != '': self.weapinfo.append([ '%sweapon%sAmmo' % (position, id), 1, 1, 'DRONE LAUNCH' ]) elif myWeapon.myWeaponData.ammo == 0: self.weapinfo.append([ '%sweapon%sAmmo' % (position, id), 1, 1, 'UNLIMITED AMMO' ]) else: self.weapinfo.append([ '%sweapon%sAmmo' % (position, id), myWeapon.availAmmo, myWeapon.availAmmo, 'AMMO' ]) self.createAttributes(self.shipinfo) self.createAttributes(self.quadinfo) self.createAttributes(self.weapinfo)
def populateMultiShipDesignList(self): """Fill the list with Ship designs""" for shipDesignID in funcs.sortStringList(self.game.shipDesigns.keys()): myShipDesign = self.game.shipDesignObjects[shipDesignID] self.multidesignList.myScrolledList.addItem(text=myShipDesign.name, extraArgs=shipDesignID)