def LookForTrouble (faction): global lftiter key = fg_util.MakeFactionKey(faction) numfg=Director.getSaveStringLength(fg_util.ccp,key) if (lftiter>=numfg): lftiter=0 if (0 and numfg): AddFighterTo(Director.getSaveString(fg_util.ccp,key,vsrandom.randrange(0,numfg)),faction,False) if faction in faction_ships.fighterProductionRate: AddFighterTo("Alpha",faction,True) return 0 i = Director.getSaveString(fg_util.ccp,key,lftiter) lftiter+=1 sys = fg_util.FGSystem (i,faction) citizen=VS.isCitizen(faction) if (sys!='nil'): if not citizen: enfac = faction_ships.get_enemy_of(faction) foundanyone=0 l=fg_util.AllFGsInSystem(enfac,sys) j=vsrandom.randrange(0,len(l)+3) if (j<len(l)): foundanyone=1 #FIXME include some sort of measure "can I win" if (vsrandom.randrange(0,5)==0): initiateAttack(i,faction,sys,l[j],enfac) elif (vsrandom.randrange(0,3)==0): randomMovement (i,faction) elif (vsrandom.randrange(0,3)==0): randomMovement (i,faction) return 1
def generateEscortLocal(path,fg,fac): if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] enfac = faction_ships.get_enemy_of(fac) diff=vsrandom.randrange(1,4) waves=vsrandom.randrange(0,5-diff) incoming=vsrandom.randrange(0,2) enfg =fg_util.AllFGsInSystem(enfac,path[-1]) creds=3500.0*diff*(1+waves); if (len(enfg)): enfg=enfg[vsrandom.randrange(0,len(enfg))] else: enfg='' isFixer=vsrandom.random() addstr="" if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Unterhalte Dich mit dem Kaufmann#Danke. Ich vertraue dir, dass du meinen Geschaeftspartner sicher geleiten wirst, bis er sein Ziel erreicht.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" additionalinfo="zu dem Sprungpunkt" if (incoming): additionalinfo="von dem Sprungpunkt zu einer nahen Basis" writemissionsavegame(addstr+"import escort_local\ntemp=escort_local.escort_local('%s',0,%d,%d,500,%d,%d,'%s',(),'','%s','','%s','%s')"%(enfac,diff,waves,creds,incoming,fac,enfg,fg,typ)) # From plueschinger to avoid sometimes squadrons and sometimes not # we mention the squadrons or konvois later in the following message if "Squadron" == fg[-8:]: fg = fg[:-9] # end of plueschingers addition writedescription("Eine Eskorte %s ist erforderlich fuer die %s Klasse %s der Raumschiffe aus der %s Schwadron in diesem System. Angriffe von der %s Gruppe sind moeglich. Sie werden bezahlt mit %d Krediten, falls das Raumschiff in diesem Sternensystem ueberlebt, bis es seinen Zielort erreicht."%(additionalinfo,formatShip(typ),fac,fg,enfac,int(creds))) writemissionname("Eskorte/Eskortiere den_%s in dem_%s Konvoi"%(fac,fg),[path[-1]],isFixerString(addstr))
def generateEscortLocal(path,fg,fac, waveprice=3500.0 ): if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: return enfac = faction_ships.get_enemy_of(fac) diff=vsrandom.randrange(1,4) waves=vsrandom.randrange(0,5-diff) incoming=vsrandom.randrange(0,2) enfg =fg_util.AllFGsInSystem(enfac,path[-1]) creds=waveprice*diff*(1+waves); if (len(enfg)): enfg=enfg[vsrandom.randrange(0,len(enfg))] else: enfg='' isFixer=vsrandom.random() addstr="" if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I trust that you will safely escort my colleague to the destination.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" additionalinfo="to the jump point" if (incoming): additionalinfo="from the jump point to a nearby base" writemissionsavegame(addstr+"import escort_local\ntemp=escort_local.escort_local('%s',0,%d,%d,500,%d,%d,'%s',(),'','%s','','%s','%s')"%(enfac,diff,waves,creds,incoming,fac,enfg,fg,typ)) writedescription("Escort %s is required for the %s type %s starship from the %s flightgroup in this system. Attacks from the %s faction are likely. You will be paid %d credits if the starship survives in this starsystem until it reaches its destination."%(additionalinfo,formatShip(typ),fac,fg,enfac,int(creds))) writemissionname("Escort/Escort_%s_%s"%(fac,fg),[path[-1]],isFixerString(addstr))
def launch_new_wave(self): un = VS.getPlayer() if (vsrandom.randrange(0,4)==0): if (un): currentsystem = VS.getSystemFile() numadj=VS.GetNumAdjacentSystems(currentsystem) if (numadj): cursys=VS.GetAdjacentSystem(currentsystem,vsrandom.randrange(0,numadj)) else: cursys = 'enigma_sector/heavens_gate' debug.info("TJ: jumping to "+cursys) un.JumpTo(cursys) else: debug.info("TJ: jumping to [ERROR: you are null]") side = vsrandom.randrange(0,2) faction="confed" ai = vsrandom.randrange(0,6) if (0 and ai==0): ai = "printhello.py" else: ai = "default" if (side==0): faction=faction_ships.get_enemy_of("confed") else: faction=faction_ships.get_friend_of("confed") launched = launch.launch_wave_around_unit ("Shadow",faction,faction_ships.getRandomFighter(faction),ai,vsrandom.randrange(1,10),100.0,2000.0,VS.getPlayer(),'') if (vsrandom.randrange(0,10)==0): launch.launch_wave_around_unit ("ShadowCap",faction,faction_ships.getRandomCapitol(faction),ai,1,2000.0,4000.0,VS.getPlayer(),'')
def Execute(self): if (self.you.isNull() or (self.arrived and self.defendee.isNull())): VS.IOmessage( 0, "defend", self.mplay, "#ff0000You were unable to arrive in time to help. Mission failed." ) self.SetVarValue(-1) VS.terminateMission(0) return if (not self.adjsys.Execute()): return if (not self.arrived): self.arrived = 1 tempfaction = '' if (self.defend_base): tempfaction = self.protectivefaction if (tempfaction == ''): tempfaction = faction_ships.get_enemy_of(self.faction) self.adjsys = go_somewhere_significant( self.you, self.defend_base or self.defend, self.distance_from_base, self.defend, tempfaction, self.dyndeffg, 1, not self.defend_base) self.adjsys.Print("You must visit the %s", "defend", "near the %s", 0) self.defendee = self.adjsys.SignificantUnit() else: if (self.defendee.isNull()): if (self.defend): self.FailMission(you) else: self.SuccessMission() return else: if (self.quantity > 0): self.GenerateEnemies(self.defendee, self.you) if (self.ship_check_count == 0 and self.dedicatedattack): if (self.targetiter >= len(self.attackers)): self.targetiter = 0 else: un = self.attackers[self.targetiter] if (not un.isNull()): if (self.defend): # if (not un.isNull() if (un.getName() in faction_ships.isBomber): if (self.quantity >= faction_ships. isBomber[un.getName()]): un.SetTarget(self.defendee) else: un.setFgDirective('b') else: un.setFgDirective('b') else: un.SetTarget(self.you) self.targetiter = self.targetiter + 1 if (self.NoEnemiesInArea(self.defendee)): if (self.waves > 0): self.quantity = self.savedquantity self.waves -= 1 else: self.SuccessMission()
def Execute (self): if (self.you.isNull() or (self.arrived and self.defendee.isNull())): VS.IOmessage (0,"defend",self.mplay,"#ff0000You were unable to arrive in time to help. Mission failed.") self.SetVarValue(-1) VS.terminateMission(0) return global running_defend_missions if running_defend_missions[self.key]!=self.run_def_mis: print "ABORTING DEFEND MISSION WITH PARAMS "+self.key+" because another is running " VS.terminateMission(1) return running_defend_missions[self.key]+=1 self.run_def_mis+=1 if (not self.adjsys.Execute()): return if (not self.arrived): self.arrived=1 tempfaction='' if (self.defend_base): tempfaction=self.protectivefaction if (tempfaction==''): tempfaction = faction_ships.get_enemy_of(self.faction) self.adjsys=go_somewhere_significant (self.you,self.defend_base or self.defend,self.distance_from_base,self.defend,tempfaction,self.dyndeffg,1,not self.defend_base) self.adjsys.Print ("You must visit the %s","defend","near the %s", 0) self.defendee=self.adjsys.SignificantUnit() else: if (self.defendee.isNull ()): if (self.defend): self.FailMission(you) else: self.SuccessMission() return else: if (self.quantity>0): self.GenerateEnemies (self.defendee,self.you) if (self.ship_check_count==0 and self.dedicatedattack): if (self.targetiter>=len(self.attackers)): self.targetiter=0 else: un = self.attackers[self.targetiter] if (not un.isNull()): if (self.defend):# if (not un.isNull() if (un.getName() in faction_ships.isBomber): if (self.quantity >= faction_ships.isBomber[un.getName()]): un.SetTarget (self.defendee) else: un.setFgDirective('b') else: un.setFgDirective('b') else: un.SetTarget (self.you) self.targetiter=self.targetiter+1 if (self.NoEnemiesInArea (self.defendee)): if (self.waves>0): self.quantity=self.savedquantity self.waves-=1 else: self.SuccessMission()
def LookForSystemWideTrouble(faction,sys): fg = fg_util.FGsInSystem(faction,sys) for i in fg: enemyfac = faction_ships.get_enemy_of (faction) efg = fg_util.AllFGsInSystem(enemy,sys) if (len(efg)): index=vsrandom.randrange(0,len(efg))#FIXME include some sort of measure "can I win" initiateAttack(fg,faction,sys,efg[index],enemyfac)
def Check(self): dead = not self.un if (not dead): dead = self.un.GetHull() <= 0 if (dead): debug.debug("Uunit died") if (VS.systemInMemory(self.starsystem)): if fg_util.RemoveShipFromFG(self.fgname, self.faction, self.type) != 0: if (VS.getPlayerX(0)): debug.debug('unit died for real') if (VS.GetRelation(self.faction, VS.getPlayerX(0).getFactionName()) > 0): dynamic_battle.rescuelist[self.starsystem] = ( self.faction, "Shadow", faction_ships.get_enemy_of(self.faction)) debug.debug("friend in trouble") global dnewsman_ numships = updatePlayerKillList(0, self.faction) debug.debug("num ships killed ") debug.debug(numships) if ((numships > 0 and VS.getPlayer()) or fg_util.NumShipsInFG(self.fgname, self.faction) == 0): #generate news here fg killed IRL varList = [ str(Director.getSaveData(0, "stardate", 0)), dnewsman_.TYPE_DESTROYED, dnewsman_.STAGE_END, "unknown", self.faction, dnewsman_.SUCCESS_WIN, str(dynamic_battle.getImportanceOfType(self.type)), self.starsystem, dnewsman_.KEYWORD_DEFAULT, "unknown", "unknown", self.fgname, self.type ] if (numships > 0 and VS.getPlayer()): varList = [ str(Director.getSaveData(0, "stardate", 0)), dnewsman_.TYPE_DESTROYED, dnewsman_.STAGE_END, VS.getPlayer().getFactionName(), self.faction, dnewsman_.SUCCESS_WIN, str( dynamic_battle.getImportanceOfType( self.type)), self.starsystem, dnewsman_.KEYWORD_DEFAULT, VS.getPlayer().getFlightgroupName(), VS.getPlayer().getName(), self.fgname, self.type ] dnewsman_.writeDynamicString(varList) debug.debug('news about unit dying') else: fg_util.LandShip(self.fgname, self.faction, self.type) return 0 else: sys = self.un.getUnitSystemFile() if (len(sys)): self.starsystem = sys return 1
def generateEscortLocal(path, fg, fac): if isNotWorthy(fac): return typ = fg_util.RandomShipIn(fg, fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] enfac = faction_ships.get_enemy_of(fac) diff = vsrandom.randrange(1, 4) waves = vsrandom.randrange(0, 5 - diff) incoming = vsrandom.randrange(0, 2) enfg = fg_util.AllFGsInSystem(enfac, path[-1]) creds = 1050.0 * diff * (1 + waves) if len(enfg): enfg = enfg[vsrandom.randrange(0, len(enfg))] else: enfg = "" isFixer = vsrandom.random() addstr = "" if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until he reaches the destination.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Escort#\n" elif use_missioncomputer: addstr += "#C#Escort#\n" additionalinfo = "to the jump point" if incoming: additionalinfo = "from the jump point to a nearby base" randCompany = GetRandomCompanyName() escortb = GetRandomEscortBrief() composedBrief = escortb.replace("$CL", randCompany) composedBrief = composedBrief.replace("$MT", enfac) composedBrief = composedBrief.replace("$DS", processSystem(path[-1])) composedBrief = composedBrief.replace("$PY", str(int(creds))) composedBrief = composedBrief.replace("$AI", additionalinfo) composedBrief = composedBrief.replace("$ET", formatShip(typ)) if len(path) == 1: mistype = "IN-SYSTEM ESCORT" else: mistype = "ESCORT" writedescription(composedBrief) writemissionsavegame( addstr + mission_script_template % dict( module="escort_local", constructor="escort_local", args=(enfac, 0, diff, waves, 500, creds, incoming, fac, (), "", enfg, "", fg, typ), ) ) writemissionname("Escort/Escort_%s_%s" % (fac, fg), [path[-1]], isFixerString(addstr)) writemissionvars({"MISSION_TYPE": mistype})
def launch_new_wave(self): side = vsrandom.randrange(0, 2) faction = "confed" ai = vsrandom.randrange(0, 2) if (ai == 0): ai = "printhello.py" else: ai = "default" if (side == 0): faction = faction_ships.get_enemy_of("confed") else: faction = faction_ships.get_friend_of("confed") launched = launchShip(faction_ships.getRandomFighter(faction), faction)
def launch_new_wave(self): side = vsrandom.randrange(0,2) faction="confed" ai = vsrandom.randrange(0,2) if (ai==0): ai = "printhello.py" else: ai = "default" if (side==0): faction=faction_ships.get_enemy_of("confed") else: faction=faction_ships.get_friend_of("confed") launched = launchShip(faction_ships.getRandomFighter(faction),faction);
def launch_new_wave(self): side = vsrandom.randrange(0,2) faction="confed" ai = vsrandom.randrange(0,8) if (0 and ai==0): ai = "printhello.py" else: ai = "default" if (side==0): faction=faction_ships.get_enemy_of("confed") else: faction="merchant" launched = launch.launch_wave_around_unit ("Shadow",faction,faction_ships.getRandomFighter(faction),ai,vsrandom.randrange(1,5),100.0,2000.0,VS.getPlayer(),'') if (vsrandom.randrange(0,10)==0 or faction=="luddites"): launch.launch_wave_around_unit ("ShadowCap"+str(vsrandom.randrange(0,10)),faction,faction_ships.getRandomCapitol(faction),ai,1,2000.0,4000.0,VS.getPlayer(),'')
def generateEscortLocal(path, fg, fac, waveprice=float( VS.vsConfig("dynamic_universe", "missions.escort.local.waveprice", "5500"))): if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg, fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] enfac = faction_ships.get_enemy_of(fac) diff = vsrandom.randrange(1, 4) waves = vsrandom.randrange(0, 5 - diff) incoming = vsrandom.randrange(0, 2) enfg = fg_util.AllFGsInSystem(enfac, path[-1]) creds = waveprice * diff * (1 + waves) if (len(enfg)): enfg = enfg[vsrandom.randrange(0, len(enfg))] else: enfg = '' isFixer = vsrandom.random() addstr = "" if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until he reaches the destination.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Escort#\n" additionalinfo = "to the jump point" if (incoming): additionalinfo = "from the jump point to a nearby base" if len(path) == 1: mistype = 'IN-SYSTEM ESCORT' else: mistype = 'ESCORT' writemissionsavegame( addstr + "import escort_local\ntemp=escort_local.escort_local('%s',0,%d,%d,500,%d,%d,'%s',(),'','%s','','%s','%s')" % (enfac, diff, waves, creds, incoming, fac, enfg, fg, typ)) writedescription( "Escort %s is required for the %s type %s starship from the %s flightgroup in this system. Attacks from the %s faction are likely. You will be paid %d credits if the starship survives in this starsystem until it reaches its destination." % (additionalinfo, formatShip(typ), fac, fg, enfac, int(creds))) writemissionname("Escort/Escort_%s_%s" % (fac, fg), [path[-1]], isFixerString(addstr)) writemissionvars({'MISSION_TYPE': mistype})
def generateEscortLocal( path, fg, fac, waveprice=float(VS.vsConfig("dynamic_universe", "missions.escort.local.waveprice", "5500")) ): if isNotWorthy(fac): return typ = fg_util.RandomShipIn(fg, fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] enfac = faction_ships.get_enemy_of(fac) diff = vsrandom.randrange(1, 4) waves = vsrandom.randrange(0, 5 - diff) incoming = vsrandom.randrange(0, 2) enfg = fg_util.AllFGsInSystem(enfac, path[-1]) creds = waveprice * diff * (1 + waves) if len(enfg): enfg = enfg[vsrandom.randrange(0, len(enfg))] else: enfg = "" isFixer = vsrandom.random() addstr = "" if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until he reaches the destination.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Escort#\n" additionalinfo = "to the jump point" if incoming: additionalinfo = "from the jump point to a nearby base" if len(path) == 1: mistype = "IN-SYSTEM ESCORT" else: mistype = "ESCORT" writemissionsavegame( addstr + "import escort_local\ntemp=escort_local.escort_local('%s',0,%d,%d,500,%d,%d,'%s',(),'','%s','','%s','%s')" % (enfac, diff, waves, creds, incoming, fac, enfg, fg, typ) ) writedescription( "Escort %s is required for the %s type %s starship from the %s flightgroup in this system. Attacks from the %s faction are likely. You will be paid %d credits if the starship survives in this starsystem until it reaches its destination." % (additionalinfo, formatShip(typ), fac, fg, enfac, int(creds)) ) writemissionname("Escort/Escort_%s_%s" % (fac, fg), [path[-1]], isFixerString(addstr)) writemissionvars({"MISSION_TYPE": mistype})
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 contractMissionsFor(fac, 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 usedcats = {} plr = VS.getPlayer() if plr: for i in range(plr.numCargo()): usedcats[plr.GetCargoIndex(i).GetCategory()] = 1 for i in range(minsysaway, maxsysaway + 1): for j in list(getSystemsNAway(cursystem, i, preferredfaction)): import dynamic_battle 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() < 0.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() < 0.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 < 0.15: # 15% - nothing pass if rnd < 0.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) if numcargos > 20: numcargos = 20 category = "" if ( rnd > 0.87 and fac != "confed" and fac != "ISO" and fac != "militia" and fac != "homeland-security" and fac != "kilrathi" and fac != "merchant" and fac != "klkk" ): category = "Contraband" else: for myiter in range(100): carg = VS.getRandCargo(numcargos, category) category = carg.GetCategory() if ( (not category in usedcats) and category[:9] != "Fragments" and category[:10] != "Contraband" and category.find("upgrades") != 0 and (category.find("starships") != 0 or rnd > 0.999) ): break if myiter != 99: category = "" # debug.debug("CATEGORY OK "+category) if not category in usedcats: generateCargoMission(j, numcargos, category, fac) usedcats[category] = 1 numescort = vsrandom.randrange(0, 2) if numescort > len(m): numescort = len(m) count = 0 for k in m: if i == 0: if vsrandom.random() < 0.92: count += 1 continue elif vsrandom.random() < 0.97: count += 1 continue f = "merchant" if count >= nummerchant: f = thisfaction if count >= numthisfac: f = fac if vsrandom.random() < 0.25: if num_wingmen > 0: generateWingmanMission(k, f) num_wingmen -= 1 elif i == 0: if vsrandom.random() < 0.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 Check(self): import fg_util dead=not self.un if (not dead): dead = self.un.GetHull()<=0 if (dead): debug.debug("Uunit died") if (VS.systemInMemory (self.starsystem)): import dynamic_battle if fg_util.RemoveShipFromFG(self.fgname,self.faction,self.type)!=0: if (VS.getPlayerX(0)): debug.debug('unit died for real') if (VS.GetRelation(self.faction,VS.getPlayerX(0).getFactionName())>0): import faction_ships dynamic_battle.rescuelist[self.starsystem]=(self.faction,"Shadow",faction_ships.get_enemy_of(self.faction)) debug.debug("friend in trouble") global dnewsman_ import dynamic_battle numships = updatePlayerKillList(0,self.faction) debug.debug("num ships killed ") debug.debug(numships) if ((numships>0 and VS.getPlayer()) or fg_util.NumShipsInFG(self.fgname,self.faction)==0): #generate news here fg killed IRL varList=[str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_DESTROYED,dnewsman_.STAGE_END,"unknown",self.faction,dnewsman_.SUCCESS_WIN,str(dynamic_battle.getImportanceOfType(self.type)),self.starsystem,dnewsman_.KEYWORD_DEFAULT,"unknown","unknown",self.fgname,self.type] if (numships>0 and VS.getPlayer()): varList=[str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_DESTROYED,dnewsman_.STAGE_END,VS.getPlayer().getFactionName(),self.faction,dnewsman_.SUCCESS_WIN,str(dynamic_battle.getImportanceOfType(self.type)),self.starsystem,dnewsman_.KEYWORD_DEFAULT,VS.getPlayer().getFlightgroupName(),VS.getPlayer().getName(),self.fgname,self.type] dnewsman_.writeDynamicString(varList) debug.debug('news about unit dying') else: fg_util.LandShip(self.fgname,self.faction,self.type) return 0 else: sys=self.un.getUnitSystemFile() if (len(sys)): self.starsystem=sys return 1
def contractMissionsFor(fac, 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 usedcats = {} plr = VS.getPlayer() if plr: for i in range(plr.numCargo()): usedcats[plr.GetCargoIndex(i).GetCategory()] = 1 for i in range(minsysaway, maxsysaway + 1): for j in getSystemsNAway(cursystem, i, preferredfaction): import dynamic_battle 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) if numcargos > 20: numcargos = 20 category = '' if (rnd > .87 and fac != 'confed' and fac != "ISO" and fac != "militia" and fac != "homeland-security" and fac != "kilrathi" and fac != "merchant" and fac != "klkk"): category = 'Contraband' else: for myiter in range(100): carg = VS.getRandCargo(numcargos, category) category = carg.GetCategory() if ((not category in usedcats) and 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 = '' # debug.debug("CATEGORY OK "+category) if not category in usedcats: generateCargoMission(j, numcargos, category, fac) usedcats[category] = 1 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