def CreateRandomMission(whichnum): """ This function gets a random mission and saves the information in an array as the which element. Returns the sprite file and text.""" which = str(whichnum) missiontype = vsrandom.random() fac = VS.GetGalaxyFaction(VS.getSystemFile()) if fac == "pirates": if (missiontype > .5): return None missiontype *= .2 elif (VS.GetRelation(fac, "pirates") < -.8 and missiontype < .1): missiontype = 0.1 + 0.9 * missiontype plr = getMissionPlayer() if (missiontype < .05): return MakePlunder(which) elif (missiontype < .1): return MakeContraband(which) else: goodlist = [] for indx in range(Director.getSaveStringLength(plr, "mission_scripts")): script = Director.getSaveString(plr, "mission_scripts", indx) if script.find("#F#") != -1: goodlist.append(indx) goodlist.sort() goodlist.reverse() if len(goodlist): i = goodlist[vsrandom.randrange(len(goodlist))] script = Director.getSaveString(plr, "mission_scripts", i) desc = Director.getSaveString(plr, "mission_descriptions", i) vars = PickleTools.decodeMap( Director.getSaveString(plr, "mission_vars", i)) vars.setdefault('MISSION_SHORTDESC', Director.getSaveString(plr, "mission_names", i)) Director.eraseSaveString(plr, "misson_scripts", i) Director.eraseSaveString(plr, "misson_descriptions", i) Director.eraseSaveString(plr, "misson_names", i) Director.eraseSaveString(plr, "misson_vars", i) mylist = script.split( "#" ) ###Skip the first two because first is always '' and second is always 'F' try: vars['MISSION_ID'] = vars['MISSION_ID'] except: vars['MISSION_ID'] = which description = vars['MISSION_SHORTDESC'].split("/")[1] vars['MISSION_NAME'] = description AddNewMission(description, script, None, desc, mylist[4], vars, vars) return (mylist[2], mylist[3], which, description) else: # It should only get here if no fixer missions were found return None # Fixer code will generate a NoFixer hopefully.
def CreateGuildMissions(guildname, nummissions, accepttypes, prefix="#G#", acceptmsg=''): plr = getMissionPlayer() addPlayer(plr, False) goodlist = [] for indx in range(Director.getSaveStringLength(plr, "mission_scripts")): script = Director.getSaveString(plr, "mission_scripts", indx) if (script.find(prefix) != -1): missiontype = script[3:script.find('#', 3)] freq = 0 if (accepttypes == None): freq = 1 elif (missiontype in accepttypes): freq = accepttypes[missiontype] elif ('*' in accepttypes): freq = accepttypes['*'] if freq: goodlist.append((indx, freq)) if len(goodlist) < nummissions: nummissions = len(goodlist) delit = [] for missionnum in range(0, nummissions): goodi = PickRandomMission(goodlist) if goodi == None: break i = goodlist[goodi][0] which = guildname + '/' + str(missionnum) script = Director.getSaveString(plr, "mission_scripts", i) desc = Director.getSaveString(plr, "mission_descriptions", i) vars = PickleTools.decodeMap( Director.getSaveString(plr, "mission_vars", i)) vars.setdefault('MISSION_SHORTDESC', Director.getSaveString(plr, "mission_names", i)) delit.append(i) AddNewMission(which, script, None, desc, acceptmsg, vars, vars) goodlist.pop(goodi) delit.sort() delit.reverse() for i in delit: Director.eraseSaveString(plr, "mission_scripts", i) Director.eraseSaveString(plr, "mission_descriptions", i) Director.eraseSaveString(plr, "mission_names", i) Director.eraseSaveString(plr, "mission_vars", i) #more reliable... sometimes we run out of good missions, #sometimes we have preexistent missions (!) return CountMissions(0, guildname)
def CreateRandomMission(whichnum): """ This function gets a random mission and saves the information in an array as the which element. Returns the sprite file and text.""" which = str(whichnum) missiontype = vsrandom.random(); fac = VS.GetGalaxyFaction(VS.getSystemFile()) if fac=="pirates": if (missiontype>.5): return None missiontype*=.2; elif (VS.GetRelation(fac,"pirates")<-.8 and missiontype<.1): missiontype = 0.1 + 0.9 * missiontype plr = getMissionPlayer() if (missiontype<.05): return MakePlunder(which) elif (missiontype<.1): return MakeContraband(which) else: goodlist = [] for indx in range(Director.getSaveStringLength(plr, "mission_scripts")): script=Director.getSaveString(plr,"mission_scripts",indx) if script.find("#F#")!=-1: goodlist.append(indx) goodlist.sort() goodlist.reverse() if len(goodlist): i = goodlist[vsrandom.randrange(len(goodlist))] script = Director.getSaveString(plr,"mission_scripts",i) desc = Director.getSaveString(plr,"mission_descriptions",i) vars = PickleTools.decodeMap( Director.getSaveString(plr,"mission_vars",i) ) vars.setdefault('MISSION_SHORTDESC',Director.getSaveString(plr, "mission_names",i)) Director.eraseSaveString(plr,"misson_scripts",i) Director.eraseSaveString(plr,"misson_descriptions",i) Director.eraseSaveString(plr,"misson_names",i) Director.eraseSaveString(plr,"misson_vars",i) mylist = script.split("#") ###Skip the first two because first is always '' and second is always 'F' try: vars['MISSION_ID'] = vars['MISSION_ID'] except: vars['MISSION_ID'] = which description = vars['MISSION_SHORTDESC'].split("/")[1] vars['MISSION_NAME'] = description AddNewMission(description,script,None,desc,mylist[4],vars,vars) return (mylist[2], mylist[3], which, description) else: # It should only get here if no fixer missions were found return None # Fixer code will generate a NoFixer hopefully.
def CreateGuildMissions(guildname,nummissions,accepttypes,prefix="#G#",acceptmsg=''): plr=getMissionPlayer() addPlayer(plr, False) goodlist=[] for indx in range(Director.getSaveStringLength(plr, "mission_scripts")): script=Director.getSaveString(plr,"mission_scripts",indx) if (script.find(prefix)!=-1): missiontype=script[3:script.find('#',3)] freq = 0 if (accepttypes==None): freq = 1 elif (missiontype in accepttypes): freq = accepttypes[missiontype] elif ('*' in accepttypes): freq = accepttypes['*'] if freq: goodlist.append( (indx,freq) ) if len(goodlist)<nummissions: nummissions=len(goodlist) delit=[] for missionnum in range(0,nummissions): goodi=PickRandomMission(goodlist) if goodi == None: break i=goodlist[goodi][0] which=guildname+'/'+str(missionnum) script=Director.getSaveString(plr,"mission_scripts",i) desc=Director.getSaveString(plr,"mission_descriptions",i) vars=PickleTools.decodeMap( Director.getSaveString(plr,"mission_vars",i) ) vars.setdefault('MISSION_SHORTDESC',Director.getSaveString(plr,"mission_names",i)) delit.append(i) AddNewMission(which,script,None,desc,acceptmsg,vars,vars) goodlist.pop(goodi) delit.sort() delit.reverse() for i in delit: Director.eraseSaveString(plr,"mission_scripts",i) Director.eraseSaveString(plr,"mission_descriptions",i) Director.eraseSaveString(plr,"mission_names",i) Director.eraseSaveString(plr,"mission_vars",i) #more reliable... sometimes we run out of good missions, #sometimes we have preexistent missions (!) return CountMissions(0,guildname)
def writemissionvars(vars): Director.pushSaveString(plr, "mission_vars", PickleTools.encodeMap(vars))
def writemissionvars (vars): Director.pushSaveString(plr, "mission_vars", PickleTools.encodeMap(vars))