def setStartingShipDesigns(obj): obj.shipDesigns[1] = ShipUtils.makeShipMinSpec( obj, 'Fighter', Rules.Tech.SMALLHULL1, { Rules.Tech.SCOCKPIT1: 1, Rules.Tech.CANNON1: 1, Rules.Tech.STLENG1: 2 }, []) obj.shipDesigns[2] = ShipUtils.makeShipMinSpec( obj, 'Corvette', Rules.Tech.SMALLHULL1, { Rules.Tech.SCOCKPIT1: 1, Rules.Tech.CANNON1: 2, Rules.Tech.STLENG1: 1, Rules.Tech.STEELARM2: 1 }, []) obj.shipDesigns[3] = ShipUtils.makeShipMinSpec( obj, 'Frigate', Rules.Tech.MEDIUMHULL2, { Rules.Tech.SBRIDGE1: 1, Rules.Tech.CANNON1: 2, Rules.Tech.SSROCKET: 2, Rules.Tech.STLENG1: 2 }, []) obj.shipDesigns[4] = ShipUtils.makeShipMinSpec( obj, 'Destroyer', Rules.Tech.MEDIUMHULL2, { Rules.Tech.SBRIDGE1: 1, Rules.Tech.CANNON1: 4, Rules.Tech.SSROCKET: 2, Rules.Tech.NSTLENG2: 3 }, []) obj.shipDesigns[5] = ShipUtils.makeShipMinSpec( obj, 'Armored Cruiser', Rules.Tech.RENEGADETITANIUMMHULL, { Rules.Tech.SBRIDGE1: 1, Rules.Tech.CANNON1: 5, Rules.Tech.SSROCKET: 3, Rules.Tech.STLENG1: 4 }, [])
def update(self, tran, obj): obj.techLevel = 99 obj.race = "m" # grant technologies obj.techs[Rules.Tech.EMCANNON] = Rules.techMaxImprovement obj.techs[Rules.Tech.SSROCKET] = Rules.techMaxImprovement obj.techs[Rules.Tech.TORPEDO] = Rules.techMaxImprovement obj.techs[Rules.Tech.FTLENG1] = 3 obj.techs[Rules.Tech.SMALLHULL1] = 3 obj.techs[Rules.Tech.SCOCKPIT1] = 3 obj.techs[Rules.Tech.SCANNERMOD1] = 3 obj.techs[Rules.Tech.CONBOMB1] = 3 obj.techs[Rules.Tech.MUTANTBASE] = 3 obj.techs[Rules.Tech.MUTANTBASE2] = 3 obj.techs[Rules.Tech.MUTANTBASE3] = 3 obj.techs[Rules.Tech.MUTANTBASE4] = 3 obj.techs[Rules.Tech.MUTANTPP1] = 3 obj.techs[Rules.Tech.MUTANTPP2] = 3 obj.techs[Rules.Tech.MUTANTFACT1] = 3 obj.techs[Rules.Tech.MUTANTFACT2] = 3 obj.techs[Rules.Tech.MUTANTMINES] = 3 # create two basic designs [they use modules not available to the # player otherwise so it has to be done this way] obj.shipDesigns[1] = ShipUtils.makeShipMinSpec(obj, 'Swarmer', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.EMCANNON:2, Rules.Tech.FTLENG1:2}, []) obj.shipDesigns[2] = ShipUtils.makeShipMinSpec(obj, 'Seeder', Rules.Tech.MEDIUMHULL2, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.MUTANTPOD:1, Rules.Tech.FTLENG1:4}, []) obj.shipDesigns[3] = ShipUtils.makeShipMinSpec(obj, 'Seeker', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.SCANNERMOD1:1, Rules.Tech.FTLENG1:2}, []) obj.shipDesigns[4] = ShipUtils.makeShipMinSpec(obj, 'Sower', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CONBOMB1:1, Rules.Tech.FTLENG1:2}, []) # call super method IPlayer.update(self, tran, obj)
def setStartingShipDesigns(obj): obj.shipDesigns[1] = ShipUtils.makeShipMinSpec(obj, 'Swarmer', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.EMCANNON:2, Rules.Tech.STLENG1:1, Rules.Tech.FTLENG1:2}, []) obj.shipDesigns[2] = ShipUtils.makeShipMinSpec(obj, 'Seeder', Rules.Tech.MEDIUMHULL2, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.MUTANTPOD:1, Rules.Tech.FTLENG1:4}, []) obj.shipDesigns[3] = ShipUtils.makeShipMinSpec(obj, 'Seeker', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.SCANNERMOD1:1, Rules.Tech.FTLENG1:2}, []) obj.shipDesigns[4] = ShipUtils.makeShipMinSpec(obj, 'Sower', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CONBOMB1:1, Rules.Tech.STLENG1:1, Rules.Tech.FTLENG1:2}, [])
def setStartingShipDesigns(obj): obj.shipDesigns[1] = ShipUtils.makeShipMinSpec(obj, 'Fighter', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CANNON1:1, Rules.Tech.STLENG1:2}, []) obj.shipDesigns[2] = ShipUtils.makeShipMinSpec(obj, 'Corvette', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CANNON1:2, Rules.Tech.STLENG1:1, Rules.Tech.STEELARM2:1}, []) obj.shipDesigns[3] = ShipUtils.makeShipMinSpec(obj, 'Frigate', Rules.Tech.MEDIUMHULL2, {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:2, Rules.Tech.SSROCKET:2, Rules.Tech.STLENG1:2}, []) obj.shipDesigns[4] = ShipUtils.makeShipMinSpec(obj, 'Destroyer', Rules.Tech.MEDIUMHULL2, {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:4, Rules.Tech.SSROCKET:2, Rules.Tech.NSTLENG2:3}, []) obj.shipDesigns[5] = ShipUtils.makeShipMinSpec(obj, 'Armored Cruiser', Rules.Tech.RENEGADETITANIUMMHULL, {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:5, Rules.Tech.SSROCKET:3, Rules.Tech.STLENG1:4}, [])
def addShipDesign(self, tran, obj, name, hullID, eqIDs): """Add ship design to the database of designs.""" # normalize design name = name.strip() # check technologies if hullID not in obj.techs: raise GameException("You do not posses this hull type.") for techID in eqIDs: if techID not in obj.techs: raise GameException("You do not posses technology(ies) to construct this ship.") # create spec (throws exception for invad ones) spec = ShipUtils.makeShipMinSpec(obj, name, hullID, eqIDs, []) # check number of designs if len(obj.shipDesigns) > Rules.shipMaxDesigns: raise GameException("No space to store design.") # check name of designs for designID in obj.shipDesigns: if obj.shipDesigns[designID].name == name: raise GameException("Design name is already used.") if re.match("^\s*$",name): raise GameException("Design name must not be entirely whitespace.") # find free design id index = 1 ids = obj.shipDesigns.keys() while 1: if index not in ids: break index += 1 # add design obj.shipDesigns[index] = spec return obj.shipDesigns, index
def update(self, tran, obj): obj.techLevel = 99 obj.race = "r" # grant technologies obj.techs[Rules.Tech.CANNON1] = 3 obj.techs[Rules.Tech.SSROCKET] = 3 obj.techs[Rules.Tech.RENEGADEBASE] = 3 obj.techs[Rules.Tech.RENEGADEBASE2] = 3 obj.techs[Rules.Tech.RENEGADEBASE2MINOR] = 3 obj.techs[Rules.Tech.RENEGADEBASE3] = 3 obj.techs[Rules.Tech.RENEGADEBASE3MINOR] = 3 obj.techs[Rules.Tech.RENEGADECOSMODROME] = 3 if not len(obj.shipDesigns) == 3: # three basic designs [they use modules not available to the player otherwise # so it has to be done this way] obj.shipDesigns[1] = ShipUtils.makeShipMinSpec(obj, 'Fighter', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CANNON1:1}, []) obj.shipDesigns[2] = ShipUtils.makeShipMinSpec(obj, 'Corvette', Rules.Tech.SMALLHULL1, {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CANNON1:2, Rules.Tech.STEELARM2:1}, []) obj.shipDesigns[3] = ShipUtils.makeShipMinSpec(obj, 'Frigate', Rules.Tech.MEDIUMHULL2, {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:2, Rules.Tech.SSROCKET:2}, []) # call super method IPlayer.update(self, tran, obj)
def update(self, tran, obj): # update all designs for designID in obj.shipDesigns: old = obj.shipDesigns[designID] new = ShipUtils.makeShipMinSpec(obj, old.name, old.hullID, old.eqIDs, old.improvements, raiseExs = False) new.built = old.built if hasattr(old, "upgradeTo"): new.upgradeTo = old.upgradeTo obj.shipDesigns[designID] = new # check all diplomacyRels for partyID in obj.diplomacyRels.keys(): party = tran.db.get(partyID, None) if not party or party.type not in PLAYER_TYPES: log.debug("Deleting party", obj.oid, partyID) del obj.diplomacyRels[partyID] # delete obj with low scan pwr # check type of the objects in the map for objID in obj.staticMap.keys(): obj.staticMap[objID] = min(obj.staticMap[objID], Rules.maxScanPwr) if obj.staticMap[objID] < Rules.level1InfoScanPwr: del obj.staticMap[objID] if not tran.db.has_key(objID) or tran.db[objID].type not in (T_SYSTEM, T_WORMHOLE): log.debug("Deleting non system %d from static map of player %d" % (objID, obj.oid)) del obj.staticMap[objID] for objID in obj.dynamicMap.keys(): if obj.dynamicMap[objID] < Rules.level1InfoScanPwr: del obj.dynamicMap[objID] if not tran.db.has_key(objID) or tran.db[objID].type not in (T_FLEET, T_ASTEROID): log.debug("Deleting obj %d from dynamic map of player %d" % (objID, objID)) del obj.dynamicMap[objID] # check if all planets are planets for objID in obj.planets[:]: try: if not tran.db.has_key(objID): log.debug("Planet does not exists - removing", obj.oid, objID) obj.planets.remove(objID) if tran.db[objID].type != T_PLANET: log.debug("Planet is not a planet - removing", obj.oid, objID) obj.planets.remove(objID) except: log.warning("There is a problem when processing planet - removing", obj.oid, objID) obj.planets.remove(objID) # check if systems in buoys are systems for objID in obj.buoys.keys(): try: if not tran.db.has_key(objID): log.debug("System for buoy does not exists - removing", obj.oid, objID) del obj.buoys[objID] if tran.db[objID].type not in (T_SYSTEM, T_WORMHOLE): log.debug("System for buoy is not a system - removing", obj.oid, objID) del obj.buoys[objID] except: log.warning("There is a problem when processing system for buoy - removing", obj.oid, objID) del obj.buoys[objID] # check if fleets are fleets for objID in obj.fleets[:]: try: if not tran.db.has_key(objID): log.debug("Fleet does not exists - removing", obj.oid, objID) obj.fleets.remove(objID) if tran.db[objID].type not in (T_FLEET, T_ASTEROID): log.debug("Fleet is not a fleet - removing", obj.oid, objID) obj.fleets.remove(objID) except: log.warning("There is a problem when processing planet - removing", obj.oid, objID) # check accessible technologies wip = 1 while wip: wip = 0 for techID in obj.techs.keys(): if techID not in Rules.techs: wip = 1 log.debug("Deleting nonexistent tech", techID, "player", obj.oid) del obj.techs[techID] continue tech = Rules.techs[techID] # check tech level if tech.level > obj.techLevel: wip = 1 log.debug("Deleting tech", techID, "player", obj.oid) if techID in obj.techs: del obj.techs[techID] # disabled? #for tmpTechID in obj.techs.keys(): # if techID in Rules.techs[tmpTechID].researchDisables: # wip = 1 # log.debug("Deleting tech", techID, "player", obj.oid) # if techID in obj.techs: del obj.techs[techID] # break # check requirements #for tmpTechID, improvement in tech.researchRequires: # if not obj.techs.has_key(tmpTechID) or obj.techs[tmpTechID] < improvement: # wip = 1 # log.debug("Deleting tech", techID, "player", obj.oid) # if techID in obj.techs: del obj.techs[techID] # break for rTask in obj.rsrchQueue[:]: if rTask.techID not in Rules.techs: log.debug("Deleting res task for nonexistent tech", rTask.techID, "player", obj.oid) obj.rsrchQueue.remove(rTask) continue tech = Rules.techs[rTask.techID] if tech.level == 99: log.debug("Deleting res task", rTask.techID, "player", obj.oid) obj.rsrchQueue.remove(rTask) # check if player is in the universe universe = tran.db[OID_UNIVERSE] if obj.oid not in universe.players and obj.oid not in (OID_NATURE, OID_ADMIN): log.debug(obj.oid, "Adding player to the universe") universe.players.append(obj.oid) # check nick (TODO remove in 0.5.33) if not hasattr(obj, "fullName"): obj.fullName = obj.name # check if player is a leader if not obj.galaxies: log.debug(obj.oid, obj.name, "IS NOT IN ANY GALAXY") else: galaxy = tran.db[obj.galaxies[0]] if galaxy.imperator != obj.oid and obj.imperator > 0: log.debug(obj.oid, "Removing imperator/leader bonus") obj.imperator = 0 ## NON VALIDATING CODE (DERIVED ATTRS AND SO ON) # get best technologies for planet weapons bestScores = [0, 0, 0, 0] obj.planetWeapons = [None, None, None, None, None] for techID in obj.techs: tech = Rules.techs[techID] if tech.isShipEquip and tech.weaponDmgMin > 0 and not tech.buildSRes\ and tech.weaponGoodForFlak: # compute score weaponEff = Rules.techImprEff[obj.techs.get(techID, Rules.techBaseImprovement)] score = (tech.weaponDmgMin + tech.weaponDmgMax) / 2.0 * \ tech.weaponROF * (tech.weaponAtt + 10.0)/10 * weaponEff if score > bestScores[tech.weaponClass]: obj.planetWeapons[tech.weaponClass] = techID bestScores[tech.weaponClass] = score #@log.debug(obj.oid, "Planet weapons", obj.planetWeapons) # update all ship designs for designID in obj.shipDesigns: old = obj.shipDesigns[designID] new = ShipUtils.makeShipMinSpec(obj, old.name, old.hullID, old.eqIDs, old.improvements, raiseExs = False) new.built = old.built new.upgradeTo = old.upgradeTo obj.shipDesigns[designID] = new