def SpawnShips(self): debug.info("spawning\n %s" % (debug.pp(self.names))) playa = VS.getPlayer() if (playa): for n in self.names: if (len(n) > 0): self.winglist += [self.SpawnShip(playa, n)]
def on_item_dropped(self, url): """ triggered when an item is dropped in the qsteelwidget. """ print 'Weld.on_item_dropped:', url #make sure all struct are present if not (self.project and self.project.level): print >> sys.stderr, 'it\'s too early to drop stuff: '\ 'create a project and a level first !' return #retrieve data if it comes from weld if url in self.resMan: props = self.resMan.file_props(url) if props is None: print >> sys.stderr, curr_f(), ': url(\'%s\') in self.resMan '\ 'but can\'t retrieve props.' % (url) return props = self.project.level.resMan.add_resource( self.resMan.base_path, props) url = props['url'] if props == {} or url not in self.project.level.resMan: print >> sys.stderr, curr_f(), 'could not retrieve file and/or '\ 'dependencies for props:', pp(props) return #instanciate it if url in self.project.level.resMan: props = self.project.level.resMan.file_props(url) dtp = self.project.level.qsteelwidget.dropTargetPosition( Config.instance().drop_target_vec) props['position'] = dtp props[ 'rotation'] = self.project.level.qsteelwidget.dropTargetRotation( ) if props['resource_type'] == 'meshes': props['meshName'] = props['name'] self.project.level.instanciate(props) s = 'dropped agent \'%s\' with id %i' % (props['name'], props['agentId']) print s Ui.instance().show_status(s) else: Ui.instance().show_status('can only drop meshes so far')
def add_resource(self, srcpath, props): """ Retrieve into base_path the file descripted by the given props, as well as each file it may depends on, according to these rules: - <filename>.mesh files depend on <filename>.material Returns the full url to the new resource, if any. Also, it makes sure all needed resource are available in ogre (if props are valid). """ if props['ext'] not in Config.instance().res_dep: print curr_f( ), ': no recorded dependencies for extension \'%s\'.' % props['ext'] return #counts the number of dependencies retrieved cnt = 0 for ext in Config.instance().res_dep[props['ext']]: dir = Config.instance().resource_ext_to_dirs[ext] filename = props['name'] + '.' + ext src = os.path.join(srcpath, dir, filename) dst = os.path.join(self.base_path, dir, filename) if self.retrieve_resource(src, dst): cnt += 1 else: print >> sys.stderr, 'could not retrieve dependency \'%s\' for props' % ext, props #did we retrieve as many dependencies as needed ? if cnt == len(Config.instance().res_dep[props['ext']]): new_props = dict(props) new_props['url'] = 'file://' + os.path.join( self.base_path, Config.instance().resource_ext_to_dirs[props['ext']], props['name'] + '.' + props['ext']) return new_props print >> sys.stderr, curr_f( ), ': could not retrieve all dependencies for props:', pp(props) return {}
def instanciate(self, props, already_in=False): """ Make Steel instanciate an object according to the given props. If already_in is set to False (default), the object is saved for reload. """ print '<Level \'%s\'>.instanciate():\n%s' % (self.name, pp(props)) if props['resource_type'] == 'meshes': self.resMan.inc_refcount(props) modelId = self.qsteelwidget.createOgreModel( props['meshName'] + '.' + props['ext'], props['position'], props['rotation'], not already_in) print 'modelId: %(modelId)i' % locals() agentId = self.qsteelwidget.createAgent() print 'agentId: %(agentId)i' % locals() r = self.qsteelwidget.linkAgentToOgreModel(agentId, modelId) print 'could link: %s' % r props['agentId'] = agentId if not already_in: self.agents.append(dict(props)) else: print >> sys.__stderr__, 'Level.instanciate(): unknown resource type'
def on_item_dropped(self, url): """ triggered when an item is dropped in the qsteelwidget. """ print 'Weld.on_item_dropped:', url #make sure all struct are present if not(self.project and self.project.level): print >> sys.stderr, 'it\'s too early to drop stuff: '\ 'create a project and a level first !' return #retrieve data if it comes from weld if url in self.resMan: props = self.resMan.file_props(url) if props is None: print >> sys.stderr, curr_f(), ': url(\'%s\') in self.resMan '\ 'but can\'t retrieve props.' % (url) return props = self.project.level.resMan.add_resource(self.resMan.base_path, props) url = props['url'] if props == {} or url not in self.project.level.resMan: print >> sys.stderr, curr_f(), 'could not retrieve file and/or '\ 'dependencies for props:', pp(props) return #instanciate it if url in self.project.level.resMan: props = self.project.level.resMan.file_props(url) dtp = self.project.level.qsteelwidget.dropTargetPosition(Config.instance().drop_target_vec) props['position'] = dtp props['rotation'] = self.project.level.qsteelwidget.dropTargetRotation() if props['resource_type'] == 'meshes': props['meshName'] = props['name'] self.project.level.instanciate(props) s = 'dropped agent \'%s\' with id %i' % (props['name'], props['agentId']) print s Ui.instance().show_status(s) else: Ui.instance().show_status('can only drop meshes so far')
def instanciate(self, props, already_in=False): """ Make Steel instanciate an object according to the given props. If already_in is set to False (default), the object is saved for reload. """ print '<Level \'%s\'>.instanciate():\n%s' % (self.name, pp(props)) if props['resource_type'] == 'meshes': self.resMan.inc_refcount(props) modelId = self.qsteelwidget.createOgreModel(props['meshName'] + '.' + props['ext'], props['position'], props['rotation'], not already_in) print 'modelId: %(modelId)i' % locals() agentId = self.qsteelwidget.createAgent() print 'agentId: %(agentId)i' % locals() r = self.qsteelwidget.linkAgentToOgreModel(agentId, modelId) print 'could link: %s' % r props['agentId'] = agentId if not already_in: self.agents.append(dict(props)) else: print >> sys.__stderr__, 'Level.instanciate(): unknown resource type'
def drawobjs(self): debug.debug("len buttons: %d" % (len(self.buttons))) debug.debug("num missions: %d" % (self.guild.nummissions)) debug.debug("button list:\n %s" % (debug.pp(self.buttons))) for m in range(min(len(self.buttons), self.guild.nummissions)): debug.debug("draw button: %s" % (self.buttons[m].drawobjs()))
def contractMissionsFor(fac,baseship,minsysaway,maxsysaway): global totalMissionNumber global insysMissionNumber totalMissionNumber=0 insysMissionNumber=0 facnum=faction_ships.factionToInt(fac) enemies = list(faction_ships.enemies[facnum]) script='' cursystem = VS.getSystemFile() thisfaction = VS.GetGalaxyFaction (cursystem) preferredfaction=None if (VS.GetRelation (fac,thisfaction)>=0): preferredfaction=thisfaction #try to stay in this territory l=[] num_wingmen=2 num_rescue=2 num_defend=1 num_idefend=2 num_bounty=1 num_ibounty=1 num_patrol=1 num_ipatrol=1 num_escort=1 num_iescort=1 mincount=2 for i in range (minsysaway,maxsysaway+1): for j in getSystemsNAway(cursystem,i,preferredfaction): if (i<2 and num_rescue>0): if j[-1] in dynamic_battle.rescuelist: generateRescueMission(j,dynamic_battle.rescuelist[j[-1]]) if checkCreatedMission(): num_rescue-=1 # if (0 and i==0): # generateRescueMission(j,("confed","Shadow","pirates")) l = dynamic_battle.BattlesInSystem(j[-1]) nodefend=1 for k in l: if (VS.GetRelation(fac,k[1][1])>=0): if ((j[-1]==VS.getSystemFile() and num_idefend<=0) or (j[-1]!=VS.getSystemFile() and num_defend<=0)): mungeFixerPct() debug.debug("Munged") else: nodefend=0 generateDefendMission(j,k[1][0],k[1][1],k[0][0],k[0][1]) restoreFixerPct() if checkInsysNum(): num_idefend-=1 if checkMissionNum(): num_defend-=1 debug.debug("Generated defendX with insys at: "+str(num_idefend)+" and outsys at "+str (num_defend)) (m,nummerchant,numthisfac)=GetFactionToDefend(thisfaction, fac, j[-1]) if preferredfaction: for kk in faction_ships.enemies[faction_ships.factiondict[thisfaction]]: k=faction_ships.intToFaction(kk) for mm in fg_util.FGsInSystem(k,j[-1]): if (i==0 or vsrandom.randrange(0,4)==0):#fixme betterthan 4 if nodefend and len(m) and vsrandom.random()<.4: if 1:#for i in range(vsrandom.randrange(1,3)): insys=(j[-1]==VS.getSystemFile()) if (insys and num_idefend<=0): mungeFixerPct() elif (num_defend<=0 and not insys): mungeFixerPct() rnd=vsrandom.randrange(0,len(m)) def_fg=m[rnd] def_fac = "merchant" if rnd>=nummerchant: def_fac= thisfaction if rnd>=numthisfac: def_fac = fac generateDefendMission(j,def_fg,def_fac,mm,k) restoreFixerPct() if checkInsysNum(): num_idefend-=1 if checkMissionNum(): num_defend-=1 debug.debug("Generated defendY with insys at: "+str(num_idefend)+" and outsys at "+str (num_defend)) nodefend=0 elif ((i==0 or vsrandom.random()<.5)): if ((j[-1]==VS.getSystemFile() and num_ibounty<=0) or (j[-1]!=VS.getSystemFile() and num_bounty<=0)): mungeFixerPct() generateBountyMission(j,mm,k) restoreFixerPct() if checkInsysNum(): debug.debug(" decrementing INSYS bounty to "+str(num_ibounty)) num_ibounty-=1 if checkMissionNum(): debug.debug(" decrementing bounty to "+str(num_bounty)) num_bounty-=1 # mincount=-2 if i==0: mincount=1 for k in range(vsrandom.randrange(mincount,4)): ###FIXME: choose a better number than 4. if k<0: k=0 rnd=vsrandom.random() if (rnd<.15): # 15% - nothing pass if (rnd<.5 or i==0): # 35% - Patrol Mission if ((j[-1]==VS.getSystemFile() and num_ipatrol<=0) or (j[-1]!=VS.getSystemFile() and num_patrol<=0)): mungeFixerPct() if (vsrandom.randrange(0,2) or j[-1] in faction_ships.fortress_systems): generatePatrolMission(j,vsrandom.randrange(4,10)) else: generateCleansweepMission(j,vsrandom.randrange(4,10),faction_ships.get_enemy_of(fac)) restoreFixerPct() if checkInsysNum(): num_ipatrol-=1 if checkMissionNum(): num_patrol-=1 else: # 50% - Cargo mission numcargos=vsrandom.randrange(1,25) playership=VS.getPlayer().getName() try: hold=int(VS.LookupUnitStat(playership,"privateer","Hold_Volume")) except: hold=10; if hold<10: hold=10; if hold > 32000: hold = 32000 numcargos=vsrandom.randrange(hold//5, hold//2) if numcargos < 20: numcargos=vsrandom.randrange(hold//2, hold) category='' if (rnd>.87 and fac!='confed' and fac != "ISO" and fac!="militia" and fac!="homeland-security" and fac!="kilrathi" and fac!="merchant"): category='Contraband' else: for myiter in range (100): carg=VS.getRandCargo(numcargos,category) category=carg.GetCategory() if (category[:9] != 'Fragments' and category[:10]!='Contraband' and category.find('upgrades')!=0 and (category.find('starships')!=0 or rnd>.999)): break if (myiter!=99): category='' if baseship: faction=fac name=baseship.getName() if baseship.isPlanet(): faction="planets" name=baseship.getFullname() debug.info("TRADING") debug.debug("getFullname(): %s, getName(): %s, faction: %s" % (baseship.getFullname(), baseship.getName(), faction)) exports=trading.getNoStarshipExports(name,faction,20) debug.debug("exports:\n%s" % (debug.pp(exports))) if (category.find("assengers")==-1 and len(exports)): category=exports[vsrandom.randrange(0,len(exports))][0] #debug.debug("CATEGORY OK "+category) generateCargoMission(j,numcargos,category,fac) numescort = vsrandom.randrange(0,2) if (numescort>len(m)): numescort=len(m) count=0 for k in m: if (i==0): if vsrandom.random()<.92: count+=1 continue elif (vsrandom.random()<.97): count+=1 continue f = "merchant" if count>=nummerchant: f= thisfaction if count>=numthisfac: f = fac if (vsrandom.random()<.25): if (num_wingmen>0): generateWingmanMission(k,f) num_wingmen-=1 elif (i==0): if (vsrandom.random()<.25): if num_iescort<=0: mungeFixerPct() generateEscortLocal(j,k,f) restoreFixerPct() if checkCreatedMission(): num_iescort-=1 else: if num_escort<=0: mungeFixerPct() generateEscortMission(j,k,f) restoreFixerPct() if checkCreatedMission(): num_escort-=1 count+=1
def __init__(self, categories, pr, qr, ships, planets): debug.info("surplus %f %f" % (pr, qr)) debug.info(debug.pp(categories)) universe.systemCargoDemand(categories, pr, qr, ships, planets)
def contractMissionsFor(fac, baseship, minsysaway, maxsysaway): global totalMissionNumber global insysMissionNumber totalMissionNumber = 0 insysMissionNumber = 0 facnum = faction_ships.factionToInt(fac) enemies = list(faction_ships.enemies[facnum]) script = '' cursystem = VS.getSystemFile() thisfaction = VS.GetGalaxyFaction(cursystem) preferredfaction = None if (VS.GetRelation(fac, thisfaction) >= 0): preferredfaction = thisfaction #try to stay in this territory l = [] num_wingmen = 2 num_rescue = 2 num_defend = 1 num_idefend = 2 num_bounty = 1 num_ibounty = 1 num_patrol = 1 num_ipatrol = 1 num_escort = 1 num_iescort = 1 mincount = 2 for i in range(minsysaway, maxsysaway + 1): for j in getSystemsNAway(cursystem, i, preferredfaction): if (i < 2 and num_rescue > 0): if j[-1] in dynamic_battle.rescuelist: generateRescueMission(j, dynamic_battle.rescuelist[j[-1]]) if checkCreatedMission(): num_rescue -= 1 # if (0 and i==0): # generateRescueMission(j,("confed","Shadow","pirates")) l = dynamic_battle.BattlesInSystem(j[-1]) nodefend = 1 for k in l: if (VS.GetRelation(fac, k[1][1]) >= 0): if ((j[-1] == VS.getSystemFile() and num_idefend <= 0) or (j[-1] != VS.getSystemFile() and num_defend <= 0)): mungeFixerPct() debug.debug("Munged") else: nodefend = 0 generateDefendMission(j, k[1][0], k[1][1], k[0][0], k[0][1]) restoreFixerPct() if checkInsysNum(): num_idefend -= 1 if checkMissionNum(): num_defend -= 1 debug.debug("Generated defendX with insys at: " + str(num_idefend) + " and outsys at " + str(num_defend)) (m, nummerchant, numthisfac) = GetFactionToDefend(thisfaction, fac, j[-1]) if preferredfaction: for kk in faction_ships.enemies[ faction_ships.factiondict[thisfaction]]: k = faction_ships.intToFaction(kk) for mm in fg_util.FGsInSystem(k, j[-1]): if (i == 0 or vsrandom.randrange(0, 4) == 0): #fixme betterthan 4 if nodefend and len(m) and vsrandom.random() < .4: if 1: #for i in range(vsrandom.randrange(1,3)): insys = (j[-1] == VS.getSystemFile()) if (insys and num_idefend <= 0): mungeFixerPct() elif (num_defend <= 0 and not insys): mungeFixerPct() rnd = vsrandom.randrange(0, len(m)) def_fg = m[rnd] def_fac = "merchant" if rnd >= nummerchant: def_fac = thisfaction if rnd >= numthisfac: def_fac = fac generateDefendMission( j, def_fg, def_fac, mm, k) restoreFixerPct() if checkInsysNum(): num_idefend -= 1 if checkMissionNum(): num_defend -= 1 debug.debug( "Generated defendY with insys at: " + str(num_idefend) + " and outsys at " + str(num_defend)) nodefend = 0 elif ((i == 0 or vsrandom.random() < .5)): if ((j[-1] == VS.getSystemFile() and num_ibounty <= 0) or (j[-1] != VS.getSystemFile() and num_bounty <= 0)): mungeFixerPct() generateBountyMission(j, mm, k) restoreFixerPct() if checkInsysNum(): debug.debug( " decrementing INSYS bounty to " + str(num_ibounty)) num_ibounty -= 1 if checkMissionNum(): debug.debug(" decrementing bounty to " + str(num_bounty)) num_bounty -= 1 # mincount = -2 if i == 0: mincount = 1 for k in range(vsrandom.randrange( mincount, 4)): ###FIXME: choose a better number than 4. if k < 0: k = 0 rnd = vsrandom.random() if (rnd < .15): # 15% - nothing pass if (rnd < .5 or i == 0): # 35% - Patrol Mission if ((j[-1] == VS.getSystemFile() and num_ipatrol <= 0) or (j[-1] != VS.getSystemFile() and num_patrol <= 0)): mungeFixerPct() if (vsrandom.randrange(0, 2) or j[-1] in faction_ships.fortress_systems): generatePatrolMission(j, vsrandom.randrange(4, 10)) else: generateCleansweepMission( j, vsrandom.randrange(4, 10), faction_ships.get_enemy_of(fac)) restoreFixerPct() if checkInsysNum(): num_ipatrol -= 1 if checkMissionNum(): num_patrol -= 1 else: # 50% - Cargo mission numcargos = vsrandom.randrange(1, 25) playership = VS.getPlayer().getName() try: hold = int( VS.LookupUnitStat(playership, "privateer", "Hold_Volume")) except: hold = 10 if hold < 10: hold = 10 if hold > 32000: hold = 32000 numcargos = vsrandom.randrange(hold // 5, hold // 2) if numcargos < 20: numcargos = vsrandom.randrange(hold // 2, hold) category = '' if (rnd > .87 and fac != 'confed' and fac != "ISO" and fac != "militia" and fac != "homeland-security" and fac != "kilrathi" and fac != "merchant"): category = 'Contraband' else: for myiter in range(100): carg = VS.getRandCargo(numcargos, category) category = carg.GetCategory() if (category[:9] != 'Fragments' and category[:10] != 'Contraband' and category.find('upgrades') != 0 and (category.find('starships') != 0 or rnd > .999)): break if (myiter != 99): category = '' if baseship: faction = fac name = baseship.getName() if baseship.isPlanet(): faction = "planets" name = baseship.getFullname() debug.info("TRADING") debug.debug( "getFullname(): %s, getName(): %s, faction: %s" % (baseship.getFullname(), baseship.getName(), faction)) exports = trading.getNoStarshipExports( name, faction, 20) debug.debug("exports:\n%s" % (debug.pp(exports))) if (category.find("assengers") == -1 and len(exports)): category = exports[vsrandom.randrange( 0, len(exports))][0] #debug.debug("CATEGORY OK "+category) generateCargoMission(j, numcargos, category, fac) numescort = vsrandom.randrange(0, 2) if (numescort > len(m)): numescort = len(m) count = 0 for k in m: if (i == 0): if vsrandom.random() < .92: count += 1 continue elif (vsrandom.random() < .97): count += 1 continue f = "merchant" if count >= nummerchant: f = thisfaction if count >= numthisfac: f = fac if (vsrandom.random() < .25): if (num_wingmen > 0): generateWingmanMission(k, f) num_wingmen -= 1 elif (i == 0): if (vsrandom.random() < .25): if num_iescort <= 0: mungeFixerPct() generateEscortLocal(j, k, f) restoreFixerPct() if checkCreatedMission(): num_iescort -= 1 else: if num_escort <= 0: mungeFixerPct() generateEscortMission(j, k, f) restoreFixerPct() if checkCreatedMission(): num_escort -= 1 count += 1
def add_resource(self, srcpath, props): """ Retrieve into base_path the file descripted by the given props, as well as each file it may depends on, according to these rules: - <filename>.mesh files depend on <filename>.material Returns the full url to the new resource, if any. Also, it makes sure all needed resource are available in ogre (if props are valid). """ if props['ext'] not in Config.instance().res_dep: print curr_f(), ': no recorded dependencies for extension \'%s\'.' % props['ext'] return #counts the number of dependencies retrieved cnt = 0 for ext in Config.instance().res_dep[props['ext']]: dir = Config.instance().resource_ext_to_dirs[ext] filename = props['name'] + '.' + ext src = os.path.join(srcpath, dir, filename) dst = os.path.join(self.base_path, dir, filename) if self.retrieve_resource(src, dst): cnt += 1 else: print >> sys.stderr, 'could not retrieve dependency \'%s\' for props' % ext, props #did we retrieve as many dependencies as needed ? if cnt == len(Config.instance().res_dep[props['ext']]): new_props = dict(props) new_props['url'] = 'file://' + os.path.join(self.base_path, Config.instance().resource_ext_to_dirs[props['ext']], props['name'] + '.' + props['ext']) return new_props print >> sys.stderr, curr_f(), ': could not retrieve all dependencies for props:', pp(props) return {}
def drawobjs(self): debug.debug("len buttons: %d" % (len(self.buttons))) debug.debug("num missions: %d" % (self.guild.nummissions)) debug.debug("button list:\n %s" % (debug.pp(self.buttons))) for m in range(min(len(self.buttons),self.guild.nummissions)): debug.debug("draw button: %s" % (self.buttons[m].drawobjs()))