missions

Discuss the Star Trek mod(s) for the Vega Strike Engine

Moderators: tillias, Jennos, peteyg

Post Reply
esgaroth
Confed Special Operative
Confed Special Operative
Posts: 317
Joined: Mon Jan 19, 2004 12:48 pm
Location: Konstanz, Germany

missions

Post by esgaroth »

AFAIK, the dynamic_mission.py script creates random missions and places the appropriate fixers in the bar. I would like to create different locations where to pick up missions- e.g. a klingon warrior club where to get only fighting missions or a federation exploratory service bureau where to get only exploration missions. Is there an easy way to modify the dynamic_mission.py to get only e.g. exploration missions ? I imagine i could create a dynamic_missions_ex.py for explorations etc. But how would I have to modify it ?
Any help ?

The dynamic_mission.py of vegatrek:

import VS
import Director
import fg_util
import vsrandom
import faction_ships
import universe
import dynamic_universe
import dynamic_news
global dnewsman_
dnewsman_ = dynamic_news.NewsManager()
baseship=None
plr=0
basefac='neutral'
def formatShip(ship):
where=ship.find(".blank")
if (where!=-1):
ship=ship[0:where]
return ship.capitalize()

def formatCargoCategory(ship):
where=ship.rfind("/")
if (where!=-1):
ship=ship[where+1:]
return ship.capitalize()

#Credit to Peter Trethewey, master of python and all things nefarious
def getSystemsKAwayNoFaction( start, k ):
set = [start]#set of systems that have been visited
pathset = [[start]]#parallel data structure to set, but with paths
pathtor = [[start]]#parallel data structure to raw return systems with path
r = [start] #raw data structure containing systems n away where n<=k
for n in range(0,k):
set.extend(r)
pathset.extend(pathtor)
r=[]
pathtor=[]
for iind in range(len(set)):
i = set[iind]
l = universe.getAdjacentSystemList(i)
for jind in range(len(l)):
j=l[jind]
if not (j in set or j in r):
r.append(j)
pathtor.append(pathset[iind]+[j])
return pathtor

def getSystemsNAway (start,k,preferredfaction):
l = getSystemsKAwayNoFaction(start,k)
if (preferredfaction==None):
return l
lbak=l
if (preferredfaction==''):
preferredfaction=VS.GetGalaxyFaction(start)
i=0
while i <len(l):
if (VS.GetRelation(preferredfaction,VS.GetGalaxyFaction(l[-1]))<0):
del l
i-=1
i+=1
if (len(l)):
return l
return lbak

syscreds=750

def GetRandomCompanyName():
bnl=[]
print 'reading company names '
filename = '../universe/companies.txt'
try:
f = open (filename,'r')
bnl = f.readlines()
f.close()
except:
return ''
for i in range(len(bnl)):
bnl=bnl.rstrip()
import vsrandom
idx = vsrandom.randint(0,len(bnl)-1)
return bnl[idx]

def GetRandomCargoBrief():
bnl=[]
brief=''
print 'generating cargo briefing'
filename = '../universe/cargo_brief.txt'
try:
f = open (filename,'r')
bnl = f.readlines()
f.close()
except:
return ''
for i in range(len(bnl)):
bnl=bnl.rstrip()
import vsrandom
idx = vsrandom.randint(0,len(bnl)-1)
brief = bnl[idx]
return brief

def getCargoName(category):
l=category.split('/')
if len(l)>1:
cargo = l[len(l)-1]+' '+l[0]
else:
cargo = category
cargo = cargo.replace('_',' ')
return cargo


def getMissionDifficulty ():
import difficulty
tmp=difficulty.getPlayerUnboundDifficulty(VS.getCurrentPlayer())
if (tmp>1.5):
tmp=1.5
return tmp

def getPriceModifier(isUncapped):
import difficulty
if (not difficulty.usingDifficulty()):
return 1.0
if (isUncapped):
return getMissionDifficulty()/.5+.9
return VS.GetDifficulty()/.5+.9

def howMuchHarder(makeharder):
import difficulty
if (makeharder==0):
return 0
udiff = getMissionDifficulty()
if (udiff<=1):
return 0
return int(udiff*2)-1

def processSystem(sys):
k= sys.split('/')
if (len(k)>1):
k=k[1]
else:
k=k[0]
return k
totalMissionNumber=0
insysMissionNumber=0
def checkInsysNum():
global insysMissionNumber
if insysMissionNumber:
insysMissionNumber=0
return True
return False
def checkMissionNum():
global totalMissionNumber
if totalMissionNumber:
totalMissionNumber=0
return True
return False
def checkCreatedMission():
if (checkMissionNum()+checkInsysNum()>0):
return True
return False
def isFixerString(s):
k=str(s)
if (len(k)<2):
return 0
if (k[1]=='F'):
return 1
if (k[1]=='G'):
return 2
return 0
def writemissionname(name,path,isfixer):
if (isfixer==0):
if path[-1]==VS.getSystemFile():
name="In_System_"+name
global insysMissionNumber
insysMissionNumber+=1
else:
global totalMissionNumber
totalMissionNumber+=1
Director.pushSaveString(plr, "mission_names", name)


def writedescription(name):
Director.pushSaveString(plr, "mission_descriptions", name.replace("_"," "))
def writemissionsavegame (name):
Director.pushSaveString(plr, "mission_scripts", name)
def eraseExtras():
import sys
len=Director.getSaveStringLength(plr, "mission_scripts")
if (len!=Director.getSaveStringLength(plr, "mission_names") or len!=Director.getSaveStringLength(plr, "mission_descriptions")):
sys.stdout.write("Warning: Number of mission descs., names and scripts are unequal.\n")
if len>0:
for i in range(len-1,-1,-1):
Director.eraseSaveString(plr, "mission_scripts", i)
Director.eraseSaveString(plr, "mission_names", i)
Director.eraseSaveString(plr, "mission_descriptions", i)

fixerpct=0.02
guildpct=0.4
def restoreFixerPct():
global fixerpct
global guildpct
fixerpct=.0625
guildpct=.4
def mungeFixerPct():
global fixerpct
global guildpct
fixerpct=.0375
guildpct=1

def generateCleansweepMission(path,numplanets,enemy):
fighterprob=vsrandom.random()*.75+.25;
capshipprob=0.0
if (vsrandom.random()<.2):
capshipprob=vsrandom.random()*.25;
forceattack=vsrandom.randrange(0,2)
cleansweep=vsrandom.randrange(0,2)
minships=maxships=vsrandom.randrange(1,4)
creds = 6*(cleansweep*4+1+capshipprob*4+.25*forceattack)*800*minships*fighterprob+1.2*syscreds*len(path)
creds*=getPriceModifier(False)
addstr=""
isFixer=vsrandom.random()
if isFixer<fixerpct:
creds*=2
addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n"
elif isFixer<guildpct:
creds*=1.5
if (cleansweep):
addstr+="#G#Bounty#\n"
else:
addstr+="#G#Patrol#\n"
missiontype="patrol_enemies"
additional=""
additionalinstructions=""
patrolorclean="Patrol"
dist=1000
if (cleansweep):
dist=1500
additional=",1"
patrolorclean="Clean_Sweep"
missiontype="cleansweep"
additionalinstructions+=" Eliminate all such forces encountered to receive payment."
if (capshipprob):
additionalinstructions+=" Capital ships possibly in the area."

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))
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))
ispoint="s"
if numplanets==1:
ispoint=""
writemissionname("%s/%s_%d_Point%s_in_%s"%(patrolorclean,patrolorclean,numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr))

def generatePatrolMission (path, numplanets):
dist=400
creds = numplanets*100+3*800+syscreds*len(path)
creds*=getPriceModifier(False)
addstr=""
isFixer=vsrandom.random()
if isFixer<fixerpct:
creds*=2
addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n"
elif isFixer<guildpct:
creds*=1.5
addstr+="#G#Patrol#\n"
writemissionsavegame (addstr+"import patrol\ntemp=patrol.patrol(0, %d, %d, %d, %s)\ntemp=0\n"%(numplanets, dist, creds, str(path)))
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))
ispoint="s"
if numplanets==1:
ispoint=""
writemissionname("Patrol/Patrol_%d_Point%s_in_%s"%(numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr))

def isNotWorthy(fac):
return VS.GetRelation(fac,VS.getPlayer().getFactionName())<0
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#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"
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 generateEscortMission (path,fg,fac):
###
if (isNotWorthy(fac)):
return
typ = fg_util.RandomShipIn(fg,fac)
if typ in faction_ships.unescortable:
typ = faction_ships.unescortable[typ]
diff=vsrandom.randrange(0,6)
creds=500*diff+1.2*syscreds*len(path)
creds*=getPriceModifier(False)
addstr=""
isFixer=vsrandom.random()
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 you reach the destination.#\n"
elif isFixer<guildpct:
creds*=1.5
addstr+="#G#Escort#\n"
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))
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))
writemissionname("Escort/Escort_%s_%s_to_%s"%(fac,fg,processSystem(path[-1])),path,isFixerString(addstr))

def changecat(category):
l=category.split('/')
if len(l)>1:
return l[-1]+'_'+l[0]
else:
return category

def pathWarning(path,isFixer):
global dnewsman_
message = str()
factions = list()
if isFixer:
message+="\nPrecautions taken to ensure the success of this mission should be taken at your expense."
else:
for system in path:
sysfac = VS.GetGalaxyFaction(system)
if sysfac not in factions:
factions.append(sysfac)
message+="\n\nYou are responsible for the success of this mission. Precautions taken to ensure this outcome will be taken at your expense. With that in mind, I will advise you that you will be travalling through systems dominated by the "
if len(factions) == 1:
message+=dnewsman_.data.getFactionData(factions[0],'full')[0]+"."
else:
message+="following factions: "
jj=0
for fac in factions:
jj+=1
message+=dnewsman_.data.getFactionData(fac,'full')[0]
if jj<len(factions)-1:
message+=", "
elif jj<len(factions):
message+=" and "
return message
def adjustQuantityDifficulty(max):
return 3+int((max-3)*VS.GetDifficulty())
def isHabitable (system):
planetlist=VS.GetGalaxyProperty(system,"planets")
if (len(planetlist)==0):
return False
planets=planetlist.split(' ')
for planet in planets:
if planet=="h" or planet=="k" or planet=="m" or planet=="l" or planet=="o" :
return True
print str(planets)+ " Not in Habitable List"
return False
def generateCargoMission (path, numcargos,category, fac):
#if (isNotWorthy(fac)):
# return
launchcap=(vsrandom.random()>=.97)
if (not launchcap) and not isHabitable(path[-1]):
return
diff=vsrandom.randrange(0,adjustQuantityDifficulty(6))
creds=250*numcargos+500*diff+syscreds*len(path)+5000*(category[:10]=="Contraband")+20000*(category[:9]=="starships")
addstr=""
creds*=getPriceModifier(False)
isFixer=vsrandom.random()
if isFixer<fixerpct:
creds*=2
addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n"
elif isFixer<guildpct:
creds*=1.5
addstr+="#G#Cargo#\n"
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)))
if (category==''):
category='generic'
randCompany = GetRandomCompanyName()
if (randCompany==''):
strStart = "We need to deliver some "
else:
strStart = randCompany+" seeks delivery of "
brief = GetRandomCargoBrief()
if (brief<>''):
composedBrief = brief.replace('$CL',randCompany)
composedBrief = composedBrief.replace('$CG',formatCargoCategory(category))
composedBrief = composedBrief.replace(' $DB','')
composedBrief = composedBrief.replace('$DS',processSystem(path[-1]))
composedBrief = composedBrief.replace('$PY',str(int(creds)))
writedescription(composedBrief)
else:
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)))
writemissionname("Cargo/Deliver_%s_to_%s"%(changecat(category),processSystem(path[-1])),path,isFixerString(addstr))

def generateRescueMission(path,rescuelist):
makemissionharder=vsrandom.randrange(0,2)
numships = vsrandom.randrange(1,adjustQuantityDifficulty(6))+howMuchHarder(makemissionharder)
creds = (numships+len(path))*vsrandom.randrange(1041,1640)
creds*=getPriceModifier(makemissionharder!=0)
if (creds>20000):
creds=21000
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)))
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))
writemissionname("Rescue/Rescue_%s_from_%s_ships"%(rescuelist[0],rescuelist[2]),path,0)

def generateBountyMission (path,fg,fac):
typ = fg_util.RandomShipIn(fg,fac)
cap = faction_ships.isCapital(typ)
makemissionharder=vsrandom.randrange(0,2)
diff=vsrandom.randrange(0,adjustQuantityDifficulty(7))+howMuchHarder(makemissionharder)
runaway=(vsrandom.random()>=.75)
creds=1200+1000*runaway+450*diff+syscreds*len(path)
if (cap):
creds*=4

finalprice=creds+syscreds*len(path)
finalprice*=getPriceModifier(False)
addstr=""
isFixer=vsrandom.random()
if isFixer<fixerpct:
finalprice*=2
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."
if (runaway):
addstr += '#Also-- we have information that the target may be informed about your attack and may be ready to run. Be quick!'
addstr+="#\n"
elif isFixer<guildpct:
creds*=1.5
addstr+="#G#Bounty#\n"
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))
diffstr = ""
if (diff>0):
diffstr=" The ship in question is thought to have %d starships for protection."%diff
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))
if (cap):
writemissionname ("Bounty/on_%s_Capital_Vessel_in_%s"%(fac,processSystem(path[-1])),path,isFixerString(addstr))
else:
writemissionname ("Bounty/on_%s_starship_in_%s"%(fac,processSystem(path[-1])),path,isFixerString(addstr))

def generateDefendMission (path,defendfg,defendfac, attackfg,attackfac):
if (isNotWorthy(defendfac)):
return
#defendtyp = fg_util.RandomShipIn(defendfg,defendfac)
attacktyp = fg_util.RandomShipIn(attackfg,attackfac)
isbase=fg_util.BaseFGInSystemName(path[-1])==defendfg
creds=1200
minq = 1
maxq = adjustQuantityDifficulty(5)
makemissionharder=vsrandom.randrange(0,2)
quantity = vsrandom.randrange(minq,maxq)+howMuchHarder(makemissionharder)
reallydefend = "1"
if (vsrandom.randrange(0,4)==0):
reallydefend="0"
addstr=""
creds=creds*quantity+syscreds*len(path)
creds*=getPriceModifier(makemissionharder)
isFixer=vsrandom.random()
if isFixer<fixerpct:
creds*=2
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"
elif isFixer<guildpct:
creds*=1.5
addstr+="#G#Defend#\n"
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"%
(attackfac, 0, quantity, creds, reallydefend, isbase, defendfac, str(path), '',attackfg, attacktyp,defendfg))
iscapitol=""
if isbase:
iscapitol="capital "
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))
writemissionname("Defend/Defend_%s_from_%s"%(defendfac, attackfac),path,isFixerString(addstr))


def generateWingmanMission(fg, faction):
numships=vsrandom.randrange(1,4)
creds=10000+15000*numships
writemissionsavegame("import wingman\newmission = wingman.wingman (%f, '%s', %d, 0)\newmission=0"%(creds, faction, numships))
s="A pilot"
EorA="a"
are="is"
if numships > 1:
s=str(numships)+" pilots"
EorA="e"
are="are"
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))
writemissionname("Wingmen/Hire_%d_%s_Wingm%sn"%(numships,faction,EorA),[VS.getSystemFile()],0)


def GetFactionToDefend(thisfaction, fac, cursys):
m = fg_util.FGsInSystem ("merchant",cursys)
nummerchant=len(m)
m+=fg_util.FGsInSystem (thisfaction,cursys)
numthisfac=len(m)
m+=fg_util.FGsInSystem (fac,cursys)
return (m,nummerchant,numthisfac)

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):
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,("federation","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()
print "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
print "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
print "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():
print " decrementing INSYS bounty to "+str(num_ibounty)
num_ibounty-=1
if checkMissionNum():
print " 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==0:
hold=10;
numcargos=vsrandom.randrange(hold/5, hold/2)

if numcargos < 20:
numcargos=vsrandom.randrange(hold/2, hold)
category=''
if (rnd>.87 and fac!='federation' and fac != "ISO" and fac!="starfleet" and fac!="homeland-security" and fac!="romulan" 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()
print "TRADING"
import trading
print name
print faction
exports=trading.getNoStarshipExports(name,faction,20)
print exports
if (category.find("assengers")==-1 and len(exports)):
category=exports[vsrandom.randrange(0,len(exports))][0]

# print "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 CreateMissions(minsys=0,maxsys=4):
eraseExtras()
i=0
global plr,basefac,baseship
plrun=VS.getPlayer()
plr=plrun.isPlayerStarship()
un=VS.getUnit(i)
while(un):
i+=1
if (un.isDocked(plrun)):
break
un=VS.getUnit(i)
if (un):
baseship=un
basefac=un.getFactionName()
if (basefac=='neutral'):
basefac=VS.GetGalaxyFaction(VS.getSystemFile())
contractMissionsFor(basefac,baseship,minsys,maxsys)
import news
news.processNews(plr)
TBeholder
Elite Venturer
Elite Venturer
Posts: 753
Joined: Sat Apr 15, 2006 2:40 am
Location: chthonic safety

Re: missions

Post by TBeholder »

esgaroth wrote:AFAIK, the dynamic_mission.py script creates random missions and places the appropriate fixers in the bar. I would like to create different locations where to pick up missions- e.g. a klingon warrior club where to get only fighting missions or a federation exploratory service bureau where to get only exploration missions. Is there an easy way to modify the dynamic_mission.py to get only e.g. exploration missions ? I imagine i could create a dynamic_missions_ex.py for explorations etc. But how would I have to modify it ?
Any help ?
You need certain types of fixers to show in certain rooms.
Meaning, in addition to modules/dynamic_missions_ex.py you may need to look into modules/mission_lib.py, modules/fixer_lib.py, bases/bar.py and bases/fixers.py and bases/fixers/*.py (campaign fixers) as well.

To implement filtering the type of fixers by base and room... Perhaps we need to add a parameter or two for fixers.CreateMissionFixers (called from bar.MakeBar and its copies for other fixer-using rooms) - which have to be passed down to mission_lib.CreateFixerMissions() and then to mission_lib.CreateRandomMission - so it would know possible subsets of the missions it needs to generate and proper factions giving them.
esgaroth wrote:The dynamic_mission.py of vegatrek:

Code: Select all

        addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you.  Your help makes space a safer place.#\n"
        addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n"
        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."
In case you didn't notice, it's not even customized. So you may as well remove the mis-tagged code, since it's not like anyone able and willing to help with it doesn't have a copy already, and it's not like anyone would prefer this dump over IDE or at least syntax-highlighting editor.
"Two Eyes Good, Eleven Eyes Better." -Michele Carter
esgaroth
Confed Special Operative
Confed Special Operative
Posts: 317
Joined: Mon Jan 19, 2004 12:48 pm
Location: Konstanz, Germany

Re: missions

Post by esgaroth »

Hi TBeholder,
I know that I need special fixers for these different locations. I have modified the respective files alredy for my purposes (e.g. I have made a klingon bar with klingon fixers, a federation bar with federation fixers etc.). However, the script creates random missions and I would like to diversify these different bars (e.g. more fighting missions in a klingon bar and more exploration missions in a federation bar). In addition, as mentioned above, I would like to have different rooms (which i would create after the model of the bar) with fixers offering only one type of mission (as explaind, an exploratory service bureau where to get only exploration missions). I have only a very very rudimentary python knowledge, so I was only asking whether there is a simple way to achieve this...
CLoneWolf
ISO Party Member
ISO Party Member
Posts: 443
Joined: Thu May 01, 2008 5:14 pm

Re: missions

Post by CLoneWolf »

So, generally speaking, you need each kind of bar to carry along a vector of "weights" to be used for the random choice, to the extreme of (0, 100, 0, 0...) for single type mission.
esgaroth
Confed Special Operative
Confed Special Operative
Posts: 317
Joined: Mon Jan 19, 2004 12:48 pm
Location: Konstanz, Germany

Re: missions

Post by esgaroth »

So, generally speaking, you need each kind of bar to carry along a vector of "weights" to be used for the random choice, to the extreme of (0, 100, 0, 0...) for single type mission.
That would be the elegant way to do it, yes. My primary goal, however, is more simple. If there would be a kind of "randomizer" in the script where the probabilities of the different missions are coded (in my good old basic days 25 years ago, i would have created a random number between 0 and 1 and then, if this number is smaller .20 create escort mission, if smaller .40 create cargo etc.), i could simply make a dynamic_mission_federation.py with some tweaked values, a dynamic_mission_klingon.py etc. However, i have not found out the way the script decides which kind of mission it creates and hoped someone with python knowledge could tell me by looking at it.
There could be another way to achieve something rather similar in effect. In PU (where vegatrek is derived from), we have the merchant guild and the mercenary guild. There only a restricted range of missions are available, and i have found out how to change these mission types. I guess I could simply copy the relevant parts and create a kind of explorer guild where only exploration missions are available, to begin with. One part of the code, however, I do not understand.

Code: Select all

def CanMerchantGuild():
	import universe
	basename=universe.getDockedBaseName()
	if (len(basename[0])==0 or len(basename[1])==0):
		return 0
	return (hashLetter(basename[0][0])+hashLetter(basename[1][0]))%2==0
def CanMercenaryGuild():
	import universe
	basename=universe.getDockedBaseName()
	if (len(basename[0])==0 or len(basename[1])==0):
		return 0	
	return (hashLetter(basename[0][0])+hashLetter(basename))%4<=1
In most parts of the code, mercenary and merchant guild are completely the same, so I could simply duplicate and rename it (exchange "merchant" with "explorer" etc. Here, however, there is a diffenence. If I would add a new explorer guild, how would the code (def CanExplorerGuild ) look like ?
What does this part of the script actually do ? Any idea ?
CLoneWolf
ISO Party Member
ISO Party Member
Posts: 443
Joined: Thu May 01, 2008 5:14 pm

Re: missions

Post by CLoneWolf »

It all depends on what ends up in basename; sorry but I currently lack the brain juice to trace back the calls in vi, I stopped at getDockedBaseName calling getDockedBase calling VS.getUnitList :D

Unless the strings in basename are aptly chosen to give particular results (or coincidentally unbalanced), the 2 Can* returns look like different ways to give a 50% chance.
...or, if the faction/species name appears in one of those strings, we've just discovered that the alien names were chosen so that these functions would output the desired result for each of them :mrgreen:

More specifically, as they sum the indexes of the first letter of the strings returned by getName() and getFullname(), in a window of 4 consecutive possible results, say 0 1 2 3, they'd return
yes no yes no
yes yes no no
combining those 50% chances in a theoretically equal distribution, given a high number of different returned strings.
esgaroth
Confed Special Operative
Confed Special Operative
Posts: 317
Joined: Mon Jan 19, 2004 12:48 pm
Location: Konstanz, Germany

Re: missions

Post by esgaroth »

OK, dont understand too much of what you are saying, so I simply play a bit around with the good and time-proven "try and error" method....
CLoneWolf
ISO Party Member
ISO Party Member
Posts: 443
Joined: Thu May 01, 2008 5:14 pm

Re: missions

Post by CLoneWolf »

My bad, forgive my laziness :mrgreen:
basename=universe.getDockedBaseName() returns 2 strings into basename, say "First string" and "Another string"
hashLetter returns the position of a letter in the string "123456789a0bcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" (a before 0? a typo or intentional? most probably not relevant anyway)
hashLetter(basename[0][0])+hashLetter(basename[1][0]) equals to summing the position of the first character of the two strings, F and A, which in this case is 42 + 37 = 80 (hoping I counted right, but the example is still valid :D )
CanMerchantGuild takes the number 80 and confronts its modulo 2 with 0, basically returning true for even numbers and false for odd ones.
CanMercenaryGuild takes the number 80 and checks if its modulo 4 is 0 or 1 returning true for them and false for 2 and 3.

If you created a custom CanExplorerGuild you could simply return (hashLetter(basename[0][0])+hashLetter(basename))%8<=3
expanding on the previous concept, but then you'd have to see where to implement the call to it by hunting the calls to CanMerchantGuild and CanMercenaryGuild

EDIT: EEK bad copy/paste in the suggested line, it should obviously be
return (hashLetter(basename[0][0])+hashLetter(basename[1][0]))%8<=3
esgaroth
Confed Special Operative
Confed Special Operative
Posts: 317
Joined: Mon Jan 19, 2004 12:48 pm
Location: Konstanz, Germany

Re: missions

Post by esgaroth »

Ok, thanx for the detailed explanation. Still dont know why this part is necessary, probably (just a guess from how the call looks like) just a way to decide whether there is such a guild or not. The calls are in the base scripts, e.g.:

Code: Select all

import mercenary_guild
if (mercenary_guild.Can()):
	merchant = mercenary_guild.MakeMercenaryGuild (room1,time_of_day)
	Base.Link (room1, 'mercenary', 0.2625, 0.196667, 0.225, 0.203333, 'Mercenary_Guild', merchant)
else:
	Base.Texture(room1,'nomercenary','bases/mining_base/nomercenary.spr', 0.41225, 0.2716)
If this is true, I could just copy one or the other cause in my hand-made base scripts, the guild is called independent of this mercenary_guild.can so it should hopefully work (will try it....).
CLoneWolf
ISO Party Member
ISO Party Member
Posts: 443
Joined: Thu May 01, 2008 5:14 pm

Re: missions

Post by CLoneWolf »

You're welcome. Well yes, my guess too is that the intention was to add some random variety without forcing the coder to decide who can be there for every base type like it would be with the vector of weights I suggested.
The bit of code you located seems exactly what you need to replicate (huge disclaimer: I have no previous knowledge of the VS code :mrgreen: ), just make sure to pick a free table for your explorer fixer :)
Post Reply