Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
dynamic_mission Namespace Reference

Functions

def formatShip
 
def formatCargoCategory
 
def getSystemsKAwayNoFaction
 
def getSystemsNAway
 
def GetRandomCompanyName
 
def GetRandomCargoBrief
 
def getCargoName
 
def getMissionDifficulty
 
def getPriceModifier
 
def howMuchHarder
 
def processSystem
 
def checkInsysNum
 
def checkMissionNum
 
def checkCreatedMission
 
def isFixerString
 
def writemissionname
 
def writedescription
 
def writemissionsavegame
 
def writemissionvars
 
def eraseExtras
 
def eraseExtrasOld
 
def restoreFixerPct
 
def mungeFixerPct
 
def generateCleansweepMission
 
def generatePatrolMission
 
def isNotWorthy
 
def generateEscortLocal
 
def generateEscortMission
 
def changecat
 
def pathWarning
 
def adjustQuantityDifficulty
 
def isHabitable
 
def generateCargoMission
 
def generateRescueMission
 
def generateBountyMission
 
def generateDefendMission
 
def generateWingmanMission
 
def GetFactionToDefend
 
def contractMissionsFor
 
def CreateMissions
 

Variables

tuple dnewsman_ = dynamic_news.NewsManager()
 
int plr = 0
 
string basefac = 'neutral'
 
tuple syscreds = int(VS.vsConfig("dynamic_universe","missions.defaults.jumpprice","3000"))
 

Function Documentation

def dynamic_mission.adjustQuantityDifficulty (   max)

Definition at line 425 of file dynamic_mission.py.

426 def adjustQuantityDifficulty(max):
427  return 3+int((max-3)*VS.GetDifficulty())
def dynamic_mission.changecat (   category)

Definition at line 392 of file dynamic_mission.py.

393 def changecat(category):
394  l=category.split('/')
395  if len(l)>1:
396  return l[-1]+'_'+l[0]
397  else:
398  return category
def dynamic_mission.checkCreatedMission ( )

Definition at line 166 of file dynamic_mission.py.

References checkInsysNum(), and checkMissionNum().

167 def checkCreatedMission():
168  if (checkMissionNum()+checkInsysNum()>0):
169  return True
170  return False
def dynamic_mission.checkInsysNum ( )

Definition at line 152 of file dynamic_mission.py.

153 def checkInsysNum():
154  global insysMissionNumber
155  if insysMissionNumber:
156  insysMissionNumber=0
157  return True
158  return False
def dynamic_mission.checkMissionNum ( )

Definition at line 159 of file dynamic_mission.py.

160 def checkMissionNum():
161  global totalMissionNumber
162  if totalMissionNumber:
163  totalMissionNumber=0
164  return True
165  return False
def dynamic_mission.contractMissionsFor (   fac,
  minsysaway,
  maxsysaway 
)

Definition at line 630 of file dynamic_mission.py.

References dynamic_battle.BattlesInSystem(), checkCreatedMission(), checkInsysNum(), checkMissionNum(), debug.debug, faction_ships.factionToInt(), fg_util.FGsInSystem(), generateBountyMission(), generateCargoMission(), generateCleansweepMission(), generateDefendMission(), generateEscortLocal(), generateEscortMission(), generatePatrolMission(), generateRescueMission(), generateWingmanMission(), faction_ships.get_enemy_of(), GetFactionToDefend(), getSystemsNAway(), faction_ships.intToFaction(), mungeFixerPct(), vsrandom.random(), vsrandom.randrange(), restoreFixerPct(), and locale.str().

631 def contractMissionsFor(fac,minsysaway,maxsysaway):
632  global totalMissionNumber
633  global insysMissionNumber
634  totalMissionNumber=0
635  insysMissionNumber=0
636  facnum=faction_ships.factionToInt(fac)
637  enemies = list(faction_ships.enemies[facnum])
638  script=''
639  cursystem = VS.getSystemFile()
640  thisfaction = VS.GetGalaxyFaction (cursystem)
641  preferredfaction=None
642  if (VS.GetRelation (fac,thisfaction)>=0):
643  preferredfaction=thisfaction#try to stay in this territory
644  l=[]
645  num_wingmen=2
646  num_rescue=2
647  num_defend=1
648  num_idefend=2
649  num_bounty=1
650  num_ibounty=1
651  num_patrol=1
652  num_ipatrol=1
653  num_escort=1
654  num_iescort=1
655  mincount=2
656  usedcats={}
657  plr=VS.getPlayer()
658  if plr:
659  for i in range(plr.numCargo()):
660  usedcats[plr.GetCargoIndex(i).GetCategory()]=1
661  for i in range (minsysaway,maxsysaway+1):
662  for j in getSystemsNAway(cursystem,i,preferredfaction):
663  import dynamic_battle
664  if (i<2 and num_rescue>0):
665  if j[-1] in dynamic_battle.rescuelist:
666  generateRescueMission(j,dynamic_battle.rescuelist[j[-1]])
667  if checkCreatedMission():
668  num_rescue-=1
669 # if (0 and i==0):
670 # generateRescueMission(j,("confed","Shadow","pirates"))
672  nodefend=1
673  for k in l:
674  if (VS.GetRelation(fac,k[1][1])>=0):
675  if ((j[-1]==VS.getSystemFile() and num_idefend<=0) or (j[-1]!=VS.getSystemFile() and num_defend<=0)):
676  mungeFixerPct()
677  debug.debug("Munged")
678  else:
679  nodefend=0
680  generateDefendMission(j,k[1][0],k[1][1],k[0][0],k[0][1])
682  if checkInsysNum():
683  num_idefend-=1
684  if checkMissionNum():
685  num_defend-=1
686  debug.debug("Generated defendX with insys at: "+str(num_idefend)+" and outsys at "+str (num_defend))
687  (m,nummerchant,numthisfac)=GetFactionToDefend(thisfaction, fac, j[-1])
688 
689  if preferredfaction:
690  for kk in faction_ships.enemies[faction_ships.factiondict[thisfaction]]:
692  for mm in fg_util.FGsInSystem(k,j[-1]):
693  if (i==0 or vsrandom.randrange(0,4)==0):#fixme betterthan 4
694  if nodefend and len(m) and vsrandom.random()<.4:
695  if 1:#for i in range(vsrandom.randrange(1,3)):
696  insys=(j[-1]==VS.getSystemFile())
697  if (insys and num_idefend<=0):
698  mungeFixerPct()
699  elif (num_defend<=0 and not insys):
700  mungeFixerPct()
701  rnd=vsrandom.randrange(0,len(m))
702  def_fg=m[rnd]
703  def_fac = "merchant"
704  if rnd>=nummerchant:
705  def_fac= thisfaction
706  if rnd>=numthisfac:
707  def_fac = fac
708  generateDefendMission(j,def_fg,def_fac,mm,k)
710  if checkInsysNum():
711  num_idefend-=1
712  if checkMissionNum():
713  num_defend-=1
714  debug.debug("Generated defendY with insys at: "+str(num_idefend)+" and outsys at "+str (num_defend))
715  nodefend=0
716  elif ((i==0 or vsrandom.random()<.5)):
717  if ((j[-1]==VS.getSystemFile() and num_ibounty<=0) or (j[-1]!=VS.getSystemFile() and num_bounty<=0)):
718  mungeFixerPct()
719  generateBountyMission(j,mm,k)
721  if checkInsysNum():
722  debug.debug(" decrementing INSYS bounty to "+str(num_ibounty))
723  num_ibounty-=1
724  if checkMissionNum():
725  debug.debug(" decrementing bounty to "+str(num_bounty))
726  num_bounty-=1
727 
728 
729 
730  mincount=-2
731  if i==0:
732  mincount=1
733  for k in range(vsrandom.randrange(mincount,4)): ###FIXME: choose a better number than 4.
734  if k<0:
735  k=0
736  rnd=vsrandom.random()
737  if (rnd<.15): # 15% - nothing
738  pass
739  if (rnd<.5 or i==0): # 35% - Patrol Mission
740  if ((j[-1]==VS.getSystemFile() and num_ipatrol<=0) or (j[-1]!=VS.getSystemFile() and num_patrol<=0)):
741  mungeFixerPct()
742  if (vsrandom.randrange(0,2) or j[-1] in faction_ships.fortress_systems):
744  else:
747  if checkInsysNum():
748  num_ipatrol-=1
749  if checkMissionNum():
750  num_patrol-=1
751 
752  else: # 50% - Cargo mission
753  numcargos=vsrandom.randrange(1,25)
754  if numcargos>20:
755  numcargos=20
756  category=''
757  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"):
758  category='Contraband'
759  else:
760  for myiter in range (100):
761  carg=VS.getRandCargo(numcargos,category)
762  category=carg.GetCategory()
763  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)):
764  break
765  if (myiter!=99):
766  category=''
767 # debug.debug("CATEGORY OK "+category)
768  if not category in usedcats:
769  generateCargoMission(j,numcargos,category,fac)
770  usedcats[category]=1
771  numescort = vsrandom.randrange(0,2)
772  if (numescort>len(m)):
773  numescort=len(m)
774  count=0
775  for k in m:
776  if (i==0):
777  if vsrandom.random()<.92:
778  count+=1
779  continue
780  elif (vsrandom.random()<.97):
781  count+=1
782  continue
783  f = "merchant"
784  if count>=nummerchant:
785  f= thisfaction
786  if count>=numthisfac:
787  f = fac
788  if (vsrandom.random()<.25):
789  if (num_wingmen>0):
791  num_wingmen-=1
792  elif (i==0):
793  if (vsrandom.random()<.25):
794  if num_iescort<=0:
795  mungeFixerPct()
796  generateEscortLocal(j,k,f)
798  if checkCreatedMission():
799  num_iescort-=1
800  else:
801  if num_escort<=0:
802  mungeFixerPct()
803  generateEscortMission(j,k,f)
805  if checkCreatedMission():
806  num_escort-=1
807 
808  count+=1
def dynamic_mission.CreateMissions (   minsys = 0,
  maxsys = 4 
)

Definition at line 809 of file dynamic_mission.py.

References contractMissionsFor(), eraseExtras(), generate_dyn_universe.KeepUniverseGenerated(), and news.processNews().

810 def CreateMissions(minsys=0,maxsys=4):
812  if VS.networked():
813  # No generating stuff while networked.
814  return
815  eraseExtras()
816  global plr,basefac
817  plrun=VS.getPlayer()
818  plr=plrun.isPlayerStarship()
819  i = VS.getUnitList()
820  while(i.notDone() and not i.current().isDocked(plrun)):
821  i.advance()
822  if (i.notDone()):
823  basefac=i.current().getFactionName()
824  if (basefac=='neutral'):
825  basefac=VS.GetGalaxyFaction(VS.getSystemFile())
826  contractMissionsFor(basefac,minsys,maxsys)
827  import news
828  news.processNews(plr)
def dynamic_mission.eraseExtras ( )

Definition at line 201 of file dynamic_mission.py.

202 def eraseExtras():
203  Director.clearSaveString(plr, "mission_scripts")
204  Director.clearSaveString(plr, "mission_names")
205  Director.clearSaveString(plr, "mission_descriptions")
206  Director.clearSaveString(plr, "mission_vars")
def dynamic_mission.eraseExtrasOld ( )

Definition at line 207 of file dynamic_mission.py.

208 def eraseExtrasOld():
209  import sys
210  len=Director.getSaveStringLength(plr, "mission_scripts")
211  if (len!=Director.getSaveStringLength(plr, "mission_names") or len!=Director.getSaveStringLength(plr, "mission_descriptions")):
212  sys.stdout.write("Warning: Number of mission descs., names and scripts are unequal.\n")
213  if len>0:
214  for i in range(len-1,-1,-1):
215  Director.eraseSaveString(plr, "mission_scripts", i)
216  Director.eraseSaveString(plr, "mission_names", i)
217  Director.eraseSaveString(plr, "mission_descriptions", i)
218  Director.eraseSaveString(plr, "mission_vars", i)
219 
220 fixerpct=0.02
221 guildpct=0.4
def dynamic_mission.formatCargoCategory (   ship)

Definition at line 27 of file dynamic_mission.py.

27 
28 def formatCargoCategory(ship):
29  where=ship.rfind("/")
30  if (where!=-1):
31  ship=ship[where+1:]
32  return ship.capitalize()
33 
#Credit to Peter Trethewey, master of python and all things nefarious
def dynamic_mission.formatShip (   ship)

Definition at line 21 of file dynamic_mission.py.

21 
22 def formatShip(ship):
23  where=ship.find(".blank")
24  if (where!=-1):
25  ship=ship[0:where]
26  return ship.capitalize()
def dynamic_mission.generateBountyMission (   path,
  fg,
  fac,
  baseprice = float(VS.vsConfig("dynamic_universe","missions.bounty.baseprice","20000",
  runawayprice = float(VS.vsConfig("dynamic_universe","missions.bounty.runaway","5000",
  diffprice = float(VS.vsConfig("dynamic_universe","missions.bounty.diffprice","500",
  jumpscale = float(VS.vsConfig("dynamic_universe","missions.bounty.jumpscale","1",
  capscale = float(VS.vsConfig("dynamic_universe","missions.bounty.capscale","4" 
)

Definition at line 522 of file dynamic_mission.py.

References adjustQuantityDifficulty(), formatShip(), generateDefendMission(), getPriceModifier(), howMuchHarder(), faction_ships.isCapital(), isFixerString(), processSystem(), vsrandom.random(), fg_util.RandomShipIn(), vsrandom.randrange(), locale.str(), writedescription(), writemissionsavegame(), and writemissionvars().

523  ):
524  typ = fg_util.RandomShipIn(fg,fac)
525  cap = faction_ships.isCapital(typ)
526  makemissionharder=vsrandom.randrange(0,2)
527  diff=vsrandom.randrange(0,adjustQuantityDifficulty(7))+howMuchHarder(makemissionharder)
528  runaway=(vsrandom.random()>=.75)
529  creds = (
530  baseprice
531  +runawayprice*runaway
532  +diffprice*diff
533  +jumpscale*syscreds*len(path)
534  )
535  if (cap):
536  creds *= capscale
537 
538  finalprice=creds*getPriceModifier(False)
539  addstr=""
540  isFixer=vsrandom.random()
541  if isFixer<fixerpct:
542  finalprice*=2
543  addstr+="#F#bases/fixers/hunter.spr#Talk with the Bounty Hunter#We will pay you on mission completion. And as far as anyone knows - we never met."
544  if (runaway):
545  addstr += '#Also-- we have information that the target may be informed about your attack and may be ready to run. Be quick!'
546  addstr+="#\n"
547  elif isFixer<guildpct:
548  creds*=1.5
549  addstr+="#G#Bounty#\n"
550  writemissionsavegame(addstr+"import bounty\ntemp=bounty.bounty(0, 0, %g, %d, %d, '%s', %s, '', '%s','%s')\ntemp=0\n"%(finalprice, runaway, diff, fac, str(path), fg,typ))
551  diffstr = ""
552  if (diff>0):
553  diffstr=" The ship in question is thought to have %d starships for protection."%diff
554  if len(path)==1:
555  mistype = 'IN-SYSTEM BOUNTY'
556  else:
557  mistype = 'BOUNTY'
558  writedescription("A %s starship in the %s flightgroup has been harassing operations in the %s system. Reward for the termination of said ship is %d credits.%s"%(formatShip(typ),fg, processSystem(path[-1]), finalprice,diffstr))
559  if (cap):
560  writemissionname ("Bounty/on_%s_Capital_Vessel_in_%s"%(fac,processSystem(path[-1])),path,isFixerString(addstr))
561  else:
562  writemissionname ("Bounty/Bounty_on_%s_starship_in_%s"%(fac,processSystem(path[-1])),path,isFixerString(addstr))
563  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateCargoMission (   path,
  numcargos,
  category,
  fac,
  baseprice = float(VS.vsConfig("dynamic_universe","missions.cargo.waveprice","500",
  jumpscale = float(VS.vsConfig("dynamic_universe","missions.cargo.jumpscale","0.2",
  cargoprice = float(VS.vsConfig("dynamic_universe","missions.cargo.cargoprice","250",
  contrabandprice = float(VS.vsConfig("dynamic_universe","missions.cargo.contrabandprice","5000",
  starshipprice = float(VS.vsConfig("dynamic_universe","missions.cargo.starshipprice","20000" 
)

Definition at line 445 of file dynamic_mission.py.

References adjustQuantityDifficulty(), changecat(), formatCargoCategory(), generateRescueMission(), getPriceModifier(), GetRandomCargoBrief(), GetRandomCompanyName(), isFixerString(), isHabitable(), pathWarning(), processSystem(), vsrandom.random(), vsrandom.randrange(), locale.str(), writedescription(), writemissionname(), and writemissionvars().

446  ):
447  #if (isNotWorthy(fac)):
448  # return
449  launchcap=0 #(vsrandom.random()>=.97) #currently no delivering to capships, maybe only from
450  if (not launchcap) and not isHabitable(path[-1]):
451  return
453  creds = (
454  cargoprice*numcargos
455  +baseprice*diff
456  +jumpscale*syscreds*len(path)
457  +contrabandprice*(category[:10]=="Contraband")
458  +starshipprice*(category[:9]=="starships")
459  )
460  addstr=""
461  creds*=getPriceModifier(False)
462  isFixer=vsrandom.random()
463  if isFixer<fixerpct:
464  creds*=2
465  addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n"
466  elif isFixer<guildpct:
467  creds*=1.5
468  addstr+="#G#Cargo#\n"
469  writemissionsavegame (addstr+"import cargo_mission\ntemp=cargo_mission.cargo_mission('%s', 0, %d, %d, %g, %d, 0, '%s', %s, '')\ntemp=0\n"%(fac, numcargos, diff, creds, launchcap, category, str(path)))
470  if (category==''):
471  category='generic'
472  randCompany = GetRandomCompanyName()
473  if (randCompany==''):
474  strStart = "We need to deliver some "
475  else:
476  strStart = randCompany+" seeks delivery of "
477  brief = GetRandomCargoBrief()
478  if (brief<>''):
479  composedBrief = brief.replace('$CL',randCompany)
480  composedBrief = composedBrief.replace('$CG',formatCargoCategory(category))
481  composedBrief = composedBrief.replace(' $DB','')
482  composedBrief = composedBrief.replace('$DS',processSystem(path[-1]))
483  composedBrief = composedBrief.replace('$PY',str(int(creds)))
484  writedescription(composedBrief)
485  else:
486  writedescription(strStart+"%s cargo to the %s system. The mission is worth %d credits to us. You will deliver it to a base owned by the %s.%s"%(formatCargoCategory(category), processSystem(path[-1]),creds,fac,pathWarning(path,isFixer<guildpct)))
487  writemissionname("Cargo/Deliver_%s_to_%s"%(changecat(category),processSystem(path[-1])),path,isFixerString(addstr))
488 
489  if len(path)==1:
490  mistype = 'IN-SYSTEM CARGO'
491  else:
492  mistype = 'CARGO'
493  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateCleansweepMission (   path,
  numplanets,
  enemy,
  pricescale = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricescale","16000",
  jumpscale = float(VS.vsConfig("dynamic_universe","missions.cleansweep.jumpscale","1.2",
  sweepmod = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricemod.sweep","4",
  capshipmod = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricemod.capship","4",
  forceattackmod = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricemod.forceattack","0.25" 
)

Definition at line 240 of file dynamic_mission.py.

References generatePatrolMission(), getPriceModifier(), isFixerString(), processSystem(), vsrandom.random(), vsrandom.randrange(), locale.str(), writedescription(), writemissionname(), and writemissionvars().

241  ):
242  fighterprob=vsrandom.random()*.75+.25;
243  capshipprob=0.0
244  if (vsrandom.random()<.2):
245  capshipprob=vsrandom.random()*.25;
246  forceattack=vsrandom.randrange(0,2)
247  cleansweep=vsrandom.randrange(0,2)
248  minships=maxships=vsrandom.randrange(1,4)
249  creds = ( pricescale * (
250  1+
251  cleansweep*sweepmod+
252  capshipprob*capshipmod+
253  forceattack*forceattackmod
254  ) * minships * fighterprob
255  + jumpscale * syscreds * len(path) )
256  creds*=getPriceModifier(False)
257  addstr=""
258  isFixer=vsrandom.random()
259  if isFixer<fixerpct:
260  creds*=2
261  addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n"
262  elif isFixer<guildpct:
263  creds*=1.5
264  if (cleansweep):
265  addstr+="#G#Bounty#\n"
266  else:
267  addstr+="#G#Patrol#\n"
268  missiontype="patrol_enemies"
269  additional=""
270  additionalinstructions=""
271  patrolorclean="Patrol"
272  dist=1000
273  if (cleansweep):
274  dist=1500
275  additional=",1"
276  patrolorclean="Clean_Sweep"
277  missiontype="cleansweep"
278  additionalinstructions+=" Eliminate all such forces encountered to receive payment."
279  if (capshipprob):
280  additionalinstructions+=" Capital ships are possibly in the area."
281 
282  writemissionsavegame (addstr+"import %s\ntemp=%s.%s(0, %d, %d, %d, %s,'',%d,%d,%f,%f,'%s',%d%s)\ntemp=0\n"%(missiontype,missiontype,missiontype,numplanets, dist, creds, str(path),minships,maxships,fighterprob,capshipprob,enemy,forceattack,additional))
283  writedescription("Authorities would like a detailed scan of the %s system. We require %d nav locations be visited on the scanning route. The pay for this mission is %d. Encounters with %s forces likely.%s"%(processSystem(path[-1]),numplanets,creds,enemy,additionalinstructions))
284  ispoint="s"
285  if numplanets==1:
286  ispoint=""
287  if len(path)==1:
288  mistype = 'IN-SYSTEM ATTACK'
289  else:
290  mistype = 'ATTACK'
291  writemissionname("%s/%s_%d_Point%s_in_%s"%(patrolorclean,patrolorclean,numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr))
292  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateDefendMission (   path,
  defendfg,
  defendfac,
  attackfg,
  attackfac,
  baseprice = float(VS.vsConfig("dynamic_universe","missions.defend.baseprice","5000",
  jumpscale = float(VS.vsConfig("dynamic_universe","missions.defend.jumpscale","1" 
)

Definition at line 567 of file dynamic_mission.py.

References adjustQuantityDifficulty(), fg_util.BaseFGInSystemName(), formatShip(), generateWingmanMission(), getPriceModifier(), howMuchHarder(), isFixerString(), isNotWorthy(), processSystem(), vsrandom.random(), fg_util.RandomShipIn(), vsrandom.randrange(), locale.str(), writedescription(), writemissionname(), writemissionsavegame(), and writemissionvars().

568  ):
569  if (isNotWorthy(defendfac)):
570  return
571  #defendtyp = fg_util.RandomShipIn(defendfg,defendfac)
572  attacktyp = fg_util.RandomShipIn(attackfg,attackfac)
573  isbase=fg_util.BaseFGInSystemName(path[-1])==defendfg
574  creds=baseprice
575  minq = 1
576  maxq = adjustQuantityDifficulty(5)
577  makemissionharder=vsrandom.randrange(0,2)
578  quantity = vsrandom.randrange(minq,maxq)+howMuchHarder(makemissionharder)
579  reallydefend = "1"
580  if (vsrandom.randrange(0,4)==0):
581  reallydefend="0"
582  addstr=""
583  creds=creds*quantity+jumpscale*syscreds*len(path)
584  creds*=getPriceModifier(makemissionharder)
585  isFixer=vsrandom.random()
586  if isFixer<fixerpct:
587  creds*=2
588  addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your defense will help confed in the long run. We appreciate the support of the bounty hunting community.#\n"
589  elif isFixer<guildpct:
590  creds*=1.5
591  addstr+="#G#Defend#\n"
592  writemissionsavegame(addstr+"import defend\ntemp=defend.defend('%s', %d, %d, 8000.0, 100000.0, %g, %s, %d, '%s', %s, '%s', '%s', '%s', '%s')\ntemp=0\n"%
593  (attackfac, 0, quantity, creds, reallydefend, isbase, defendfac, str(path), '',attackfg, attacktyp,defendfg))
594  iscapitol=""
595  if isbase:
596  iscapitol="capital "
597  if len(path)==1:
598  mistype = 'IN-SYSTEM DEFEND'
599  else:
600  mistype = 'DEFEND'
601  writedescription("A %s assault wing named %s has jumped in and is moving for an attack on one of our %sassets in the %s system.\nYour task is to eradicate them before they eliminate our starship.\nIntelligence shows that they have %d starships of type %s. Your reward is %d credits."%(attackfac, attackfg, iscapitol, processSystem(path[-1]),quantity, formatShip(attacktyp),creds))
602  writemissionname("Defend/Defend_%s_from_%s"%(defendfac, attackfac),path,isFixerString(addstr))
603  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateEscortLocal (   path,
  fg,
  fac,
  waveprice = float(VS.vsConfig("dynamic_universe","missions.escort.local.waveprice","5500" 
)

Definition at line 326 of file dynamic_mission.py.

References fg_util.AllFGsInSystem(), formatShip(), generateEscortMission(), faction_ships.get_enemy_of(), isFixerString(), isNotWorthy(), vsrandom.random(), fg_util.RandomShipIn(), vsrandom.randrange(), writedescription(), writemissionname(), writemissionsavegame(), and writemissionvars().

327  ):
328  if (isNotWorthy(fac)):
329  return
330  typ = fg_util.RandomShipIn(fg,fac)
331  if typ in faction_ships.unescortable:
332  typ = faction_ships.unescortable[typ]
333  enfac = faction_ships.get_enemy_of(fac)
334  diff=vsrandom.randrange(1,4)
335  waves=vsrandom.randrange(0,5-diff)
336  incoming=vsrandom.randrange(0,2)
337  enfg =fg_util.AllFGsInSystem(enfac,path[-1])
338  creds=waveprice*diff*(1+waves);
339  if (len(enfg)):
340  enfg=enfg[vsrandom.randrange(0,len(enfg))]
341  else:
342  enfg=''
343  isFixer=vsrandom.random()
344  addstr=""
345  if isFixer<fixerpct:
346  creds*=2
347  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"
348  elif isFixer<guildpct:
349  creds*=1.5
350  addstr+="#G#Escort#\n"
351  additionalinfo="to the jump point"
352  if (incoming):
353  additionalinfo="from the jump point to a nearby base"
354  if len(path)==1:
355  mistype = 'IN-SYSTEM ESCORT'
356  else:
357  mistype = 'ESCORT'
358  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))
359  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)))
360  writemissionname("Escort/Escort_%s_%s"%(fac,fg),[path[-1]],isFixerString(addstr))
361  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateEscortMission (   path,
  fg,
  fac,
  baseprice = float(VS.vsConfig("dynamic_universe","missions.escort.waveprice","500",
  jumpscale = float(VS.vsConfig("dynamic_universe","missions.escort.jumpscale","0.5" 
)

Definition at line 365 of file dynamic_mission.py.

References formatShip(), getPriceModifier(), isFixerString(), isNotWorthy(), processSystem(), vsrandom.random(), fg_util.RandomShipIn(), vsrandom.randrange(), locale.str(), writedescription(), writemissionname(), and writemissionvars().

366  ):
367  ###
368  if (isNotWorthy(fac)):
369  return
370  typ = fg_util.RandomShipIn(fg,fac)
371  if typ in faction_ships.unescortable:
372  typ = faction_ships.unescortable[typ]
373  diff=vsrandom.randrange(0,6)
374  creds=baseprice*diff+jumpscale*syscreds*len(path)
375  creds*=getPriceModifier(False)
376  addstr=""
377  isFixer=vsrandom.random()
378  if isFixer<fixerpct:
379  creds*=2
380  addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until you reach the destination.#\n"
381  elif isFixer<guildpct:
382  creds*=1.5
383  addstr+="#G#Escort#\n"
384  if len(path)==1:
385  mistype = 'IN-SYSTEM ESCORT'
386  else:
387  mistype = 'ESCORT'
388  writemissionsavegame (addstr+"import escort_mission\ntemp=escort_mission.initrandom('%s', %d, %g, 0, 0, %s, '','%s','%s')\ntemp=0\n"%(fac, diff, float(creds), str(path),fg,typ))
389  writedescription("The %s %s in the %s flightgroup requres an escort to %s. The reward for a successful escort is %d credits."%(fac,formatShip(typ),fg, processSystem(path[-1]),creds))
390  writemissionname("Escort/Escort_%s_%s_to_%s"%(fac,fg,processSystem(path[-1])),path,isFixerString(addstr))
391  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generatePatrolMission (   path,
  numplanets,
  planetprice = float(VS.vsConfig("dynamic_universe","missions.patrol.planetprice","100",
  baseprice = float(VS.vsConfig("dynamic_universe","missions.patrol.baseprice","2400",
  jumpscale = float(VS.vsConfig("dynamic_universe","missions.patrol.jumpscale","1" 
)

Definition at line 297 of file dynamic_mission.py.

References getPriceModifier(), isFixerString(), processSystem(), vsrandom.random(), locale.str(), writedescription(), writemissionname(), and writemissionvars().

298  ):
299  dist=400
300  creds = numplanets*planetprice+baseprice+jumpscale*syscreds*len(path)
301  creds*=getPriceModifier(False)
302  addstr=""
303  isFixer=vsrandom.random()
304  if isFixer<fixerpct:
305  creds*=2
306  addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n"
307  elif isFixer<guildpct:
308  creds*=1.5
309  addstr+="#G#Patrol#\n"
310  writemissionsavegame (addstr+"import patrol\ntemp=patrol.patrol(0, %d, %d, %d, %s)\ntemp=0\n"%(numplanets, dist, creds, str(path)))
311  writedescription("Insystem authorities would like a detailed scan of the %s system. We require %d nav locations be visited on the scanning route. The pay for this mission is %d."%(processSystem(path[-1]),numplanets,creds))
312  ispoint="s"
313  if numplanets==1:
314  ispoint=""
315  if len(path)==1:
316  mistype = 'IN-SYSTEM PATROL'
317  else:
318  mistype = 'PATROL'
319  writemissionname("Patrol/Patrol_%d_Point%s_in_%s"%(numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr))
320  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateRescueMission (   path,
  rescuelist,
  totmaxprice = int(VS.vsConfig("dynamic_universe","missions.rescue.totmaxprice","21000",
  shipminprice = int(VS.vsConfig("dynamic_universe","missions.rescue.pership.minprice","4041",
  shipmaxprice = int(VS.vsConfig("dynamic_universe","missions.rescue.pership.maxprice","8640",
  jumpminprice = int(VS.vsConfig("dynamic_universe","missions.rescue.perjump.minprice","4041",
  jumpmaxprice = int(VS.vsConfig("dynamic_universe","missions.rescue.perjump.maxprice","8640" 
)

Definition at line 500 of file dynamic_mission.py.

References adjustQuantityDifficulty(), generateBountyMission(), getPriceModifier(), howMuchHarder(), sre_parse.min, processSystem(), vsrandom.randrange(), locale.str(), writedescription(), writemissionname(), writemissionsavegame(), and writemissionvars().

501  ):
502  makemissionharder=vsrandom.randrange(0,2)
503  numships = vsrandom.randrange(1,adjustQuantityDifficulty(6))+howMuchHarder(makemissionharder)
504  creds = numships*vsrandom.randrange(shipminprice,shipmaxprice)
505  creds += len(path)*vsrandom.randrange(jumpminprice,jumpmaxprice)
506  creds = min(totmaxprice, creds)
507  creds *= getPriceModifier(makemissionharder!=0)
508  if len(path)==1:
509  mistype = 'IN-SYSTEM RESCUE'
510  else:
511  mistype = 'RESCUE'
512  writemissionsavegame("import rescue\nntemp=rescue.rescue(%d,0,'%s',%d,'%s','%s',%s)\nntemp=0"%(creds,rescuelist[0],numships,rescuelist[2],rescuelist[1],str(path)))
513  writedescription("SOS! This is an ejected %s pilot under attack by at least %d %s craft. I request immediate assistance to the %s system and will offer %d credits for a safe return to the local planet where I may recover."%(rescuelist[0],numships,rescuelist[2],processSystem(path[-1]),creds))
514  writemissionname("Rescue/Rescue_%s_from_%s_ships"%(rescuelist[0],rescuelist[2]),path,0)
515  writemissionvars( { 'MISSION_TYPE' : mistype } )
def dynamic_mission.generateWingmanMission (   fg,
  faction,
  baseprice = float(VS.vsConfig("dynamic_universe","missions.wingman.baseprice","10000",
  shipprice = float(VS.vsConfig("dynamic_universe","missions.wingman.shipprice","15000" 
)

Definition at line 607 of file dynamic_mission.py.

References vsrandom.randrange(), locale.str(), writedescription(), writemissionname(), writemissionsavegame(), and writemissionvars().

608  ):
609  numships=vsrandom.randrange(1,4)
610  creds=baseprice+shipprice*numships
611  writemissionsavegame("import wingman\newmission = wingman.wingman (%f, '%s', %d, 0)\newmission=0"%(creds, faction, numships))
612  s="A pilot"
613  EorA="a"
614  are="is"
615  if numships > 1:
616  s=str(numships)+" pilots"
617  EorA="e"
618  are="are"
619  writedescription(s+" in the %s faction %s willing to help you out and fight with you as long as you pay %d credits."%(faction, are, creds))
620  writemissionname("Wingmen/Hire_%d_%s_Wingm%sn"%(numships,faction,EorA),[VS.getSystemFile()],0)
621  writemissionvars( { 'MISSION_TYPE' : 'WINGMAN' } )
def dynamic_mission.getCargoName (   category)

Definition at line 108 of file dynamic_mission.py.

109 def getCargoName(category):
110  l=category.split('/')
111  if len(l)>1:
112  cargo = l[len(l)-1]+' '+l[0]
113  else:
114  cargo = category
115  cargo = cargo.replace('_',' ')
116  return cargo
def dynamic_mission.GetFactionToDefend (   thisfaction,
  fac,
  cursys 
)

Definition at line 622 of file dynamic_mission.py.

623 def GetFactionToDefend(thisfaction, fac, cursys):
624  m = fg_util.FGsInSystem ("merchant",cursys)
625  nummerchant=len(m)
626  m+=fg_util.FGsInSystem (thisfaction,cursys)
627  numthisfac=len(m)
628  m+=fg_util.FGsInSystem (fac,cursys)
629  return (m,nummerchant,numthisfac)
def dynamic_mission.getMissionDifficulty ( )

Definition at line 117 of file dynamic_mission.py.

References difficulty.getPlayerUnboundDifficulty().

118 def getMissionDifficulty ():
119  import difficulty
120  tmp=difficulty.getPlayerUnboundDifficulty(VS.getCurrentPlayer())
121  if (tmp>1.5):
122  tmp=1.5
123  return tmp
def dynamic_mission.getPriceModifier (   isUncapped)

Definition at line 124 of file dynamic_mission.py.

References getMissionDifficulty(), and difficulty.usingDifficulty().

125 def getPriceModifier(isUncapped):
126  import difficulty
127  if (not difficulty.usingDifficulty()):
128  return 1.0
129  if (isUncapped):
130  return getMissionDifficulty()/.5+.9
131  return VS.GetDifficulty()/.5+.9
def dynamic_mission.GetRandomCargoBrief ( )

Definition at line 90 of file dynamic_mission.py.

References debug.debug, vsrandom.randint(), and string.rstrip().

90 
92  bnl=[]
93  brief=''
94  debug.debug('generating cargo briefing')
95  filename = '../universe/cargo_brief.txt'
96  try:
97  f = open (filename,'r')
98  bnl = f.readlines()
99  f.close()
100  except:
101  return ''
102  for i in range(len(bnl)):
103  bnl[i]=bnl[i].rstrip()
104  import vsrandom
105  idx = vsrandom.randint(0,len(bnl)-1)
106  brief = bnl[idx]
107  return brief
def dynamic_mission.GetRandomCompanyName ( )

Definition at line 74 of file dynamic_mission.py.

References debug.debug, vsrandom.randint(), and string.rstrip().

74 
76  bnl=[]
77  debug.debug('reading company names ')
78  filename = '../universe/companies.txt'
79  try:
80  f = open (filename,'r')
81  bnl = f.readlines()
82  f.close()
83  except:
84  return ''
85  for i in range(len(bnl)):
86  bnl[i]=bnl[i].rstrip()
87  import vsrandom
88  idx = vsrandom.randint(0,len(bnl)-1)
89  return bnl[idx]
def dynamic_mission.getSystemsKAwayNoFaction (   start,
  k 
)

Definition at line 34 of file dynamic_mission.py.

References universe.getAdjacentSystemList().

34 
35 def getSystemsKAwayNoFaction( start, k ):
36  set = [start]#set of systems that have been visited
37  pathset = [[start]]#parallel data structure to set, but with paths
38  pathtor = [[start]]#parallel data structure to raw return systems with path
39  r = [start] #raw data structure containing systems n away where n<=k
40  for n in range(0,k):
41  set.extend(r)
42  pathset.extend(pathtor)
43  r=[]
44  pathtor=[]
45  for iind in range(len(set)):
46  i = set[iind]
48  for jind in range(len(l)):
49  j=l[jind]
50  if not (j in set or j in r):
51  r.append(j)
52  pathtor.append(pathset[iind]+[j])
53  return pathtor
def dynamic_mission.getSystemsNAway (   start,
  k,
  preferredfaction 
)

Definition at line 54 of file dynamic_mission.py.

References getSystemsKAwayNoFaction().

54 
55 def getSystemsNAway (start,k,preferredfaction):
56  l = getSystemsKAwayNoFaction(start,k)
57  if (preferredfaction==None):
58  return l
59  lbak=l
60  if (preferredfaction==''):
61  preferredfaction=VS.GetGalaxyFaction(start)
62  i=0
63  while i <len(l):
64  if (VS.GetRelation(preferredfaction,VS.GetGalaxyFaction(l[i][-1]))<0):
65  del l[i]
66  i-=1
67  i+=1
68  if (len(l)):
69  return l
70  return lbak
def dynamic_mission.howMuchHarder (   makeharder)

Definition at line 132 of file dynamic_mission.py.

References getMissionDifficulty().

133 def howMuchHarder(makeharder):
134  import difficulty
135  if (makeharder==0):
136  return 0
137  udiff = getMissionDifficulty()
138  if (udiff<=1):
139  return 0
140  return int(udiff*2)-1
def dynamic_mission.isFixerString (   s)

Definition at line 171 of file dynamic_mission.py.

References locale.str().

172 def isFixerString(s):
173  k=str(s)
174  if (len(k)<2):
175  return 0
176  if (k[1]=='F'):
177  return 1
178  if (k[1]=='G'):
179  return 2
return 0
def dynamic_mission.isHabitable (   system)

Definition at line 428 of file dynamic_mission.py.

References debug.debug, generateCargoMission(), and locale.str().

429 def isHabitable (system):
430  planetlist=VS.GetGalaxyProperty(system,"planets")
431  if (len(planetlist)==0):
432  return False
433  planets=planetlist.split(' ')
434  for planet in planets:
435  if planet=="i" or planet=="a" or planet=="am" or planet=="u" or planet=="com" or planet=="bd" or planet=="s" or planet=="o" or planet=="at" or planet=="bs" or planet=="bdm" or planet=="bsm" or planet=="f" or planet=="fm" or planet=="t":
436  return True
437  debug.debug(str(planets)+ " Not in Habitable List")
438  return False
def dynamic_mission.isNotWorthy (   fac)

Definition at line 321 of file dynamic_mission.py.

References generateEscortLocal().

322 def isNotWorthy(fac):
323  return VS.GetRelation(fac,VS.getPlayer().getFactionName())<0
def dynamic_mission.mungeFixerPct ( )

Definition at line 228 of file dynamic_mission.py.

References generateCleansweepMission().

229 def mungeFixerPct():
230  global fixerpct
231  global guildpct
232  fixerpct=.0375
233  guildpct=1
def dynamic_mission.pathWarning (   path,
  isFixer 
)

Definition at line 399 of file dynamic_mission.py.

References locale.str().

400 def pathWarning(path,isFixer):
401  global dnewsman_
402  message = str()
403  factions = list()
404  if isFixer:
405  message+="\nPrecautions to ensure the success of this mission should be taken at your expense."
406  else:
407  for system in path:
408  sysfac = VS.GetGalaxyFaction(system)
409  if sysfac not in factions:
410  factions.append(sysfac)
411  message+="\n\nYou are responsible for the success of this mission. Precautions taken to ensure this outcome will be at your expense. With that in mind, I will advise you that you will be travelling through systems dominated by the "
412  if len(factions) == 1:
413  message+=dnewsman_.data.getFactionData(factions[0],'full')[0]+"."
414  else:
415  message+="following factions: "
416  jj=0
417  for fac in factions:
418  jj+=1
419  message+=dnewsman_.data.getFactionData(fac,'full')[0]
420  if jj<len(factions)-1:
421  message+=", "
422  elif jj<len(factions):
423  message+=" and "
424  return message
def dynamic_mission.processSystem (   sys)

Definition at line 141 of file dynamic_mission.py.

142 def processSystem(sys):
143  k= sys.split('/')
144  if (len(k)>1):
145  k=k[1]
146  else:
147  k=k[0]
148  return k
149 
150 totalMissionNumber=0
151 insysMissionNumber=0
def dynamic_mission.restoreFixerPct ( )

Definition at line 222 of file dynamic_mission.py.

223 def restoreFixerPct():
224  global fixerpct
225  global guildpct
226  fixerpct=.0625
227  guildpct=.4
def dynamic_mission.writedescription (   name)

Definition at line 192 of file dynamic_mission.py.

193 def writedescription(name):
194  Director.pushSaveString(plr, "mission_descriptions", name.replace("_"," "))
def dynamic_mission.writemissionname (   name,
  path,
  isfixer 
)

Definition at line 180 of file dynamic_mission.py.

181 def writemissionname(name,path,isfixer):
182  if (isfixer==0):
183  if path[-1]==VS.getSystemFile():
184  name="In_System_"+name
185  global insysMissionNumber
186  insysMissionNumber+=1
187  else:
188  global totalMissionNumber
189  totalMissionNumber+=1
190  Director.pushSaveString(plr, "mission_names", name)
191 
def dynamic_mission.writemissionsavegame (   name)

Definition at line 195 of file dynamic_mission.py.

196 def writemissionsavegame (name):
197  Director.pushSaveString(plr, "mission_scripts", name)
def dynamic_mission.writemissionvars (   vars)

Definition at line 198 of file dynamic_mission.py.

References PickleTools.encodeMap().

199 def writemissionvars (vars):
200  Director.pushSaveString(plr, "mission_vars", PickleTools.encodeMap(vars))

Variable Documentation

string basefac = 'neutral'

Definition at line 19 of file dynamic_mission.py.

tuple dnewsman_ = dynamic_news.NewsManager()

Definition at line 16 of file dynamic_mission.py.

int plr = 0

Definition at line 18 of file dynamic_mission.py.

tuple syscreds = int(VS.vsConfig("dynamic_universe","missions.defaults.jumpprice","3000"))

Definition at line 71 of file dynamic_mission.py.