def AddNewMission(which,
                  args,
                  constructor=None,
                  briefing0='',
                  briefing1='',
                  vars0=None,
                  vars1=None):
    """ Adds a mission to the list of missions stored in playerInfo. """
    if not isinstance(vars0, dict):
        vars0 = dict()
        vars1 = vars0
    if VS.isserver():
        lenvars0 = len(vars0)
        sendargs = ["AddNewMission", which, briefing0, briefing1, lenvars0]
        for key in vars0:
            sendargs.append(key)
            sendargs.append(vars0[key])
        custom.run("mission_lib", sendargs, None)

    plr = getMissionPlayer()
    addPlayer(plr, False)
    playerInfo = players[plr]

    which = str(which)
    playerInfo.last_constructor[which] = constructor
    playerInfo.last_args[which] = args
    playerInfo.last_briefing[0][which] = briefing0
    playerInfo.last_briefing[1][which] = briefing1
    playerInfo.last_briefing_vars[0][which] = vars0
    playerInfo.last_briefing_vars[1][which] = vars1
	def sendGotoMessage(self, newnodenum):
		plr = VS.getCurrentPlayer()
		#if VS.isserver():
		#	if not self.isDocked():
		#		debug.debug("Not notifying client of setCurrentNode(%d) because not fully docked yet"%(newnodenum))
		#		return
		custom.run("campaign", [self.name, "goto", newnodenum], None)
	def readPositionFromSavegame(self, savegamelist=None):
		import VS
		import Director
		
		plr=VS.getCurrentPlayer()
		self.InitPlayer(plr)
		player = self.players[plr]
		player.savegame=[]
		player.current=self.root
		if savegamelist:
			length=len(savegamelist)
		else:
			length=Director.getSaveDataLength(plr,self.name)
		for i in range(length):
			if savegamelist:
				newnodenum=int(savegamelist[i])
			else:
				newnodenum=int(Director.getSaveData(plr,self.name,i))
			if newnodenum>=0:
				if newnodenum>=len(player.current.subnodes):
					debug.debug(str(player.savegame)+': current has '+str(player.current.subnodes))
					debug.warn('Error: save game index out of bounds: '+str(newnodenum))
					return
				player.current=player.current.subnodes[newnodenum]
			elif newnodenum==-2:
				if not player.current.contingency:
					debug.debug(str(player.savegame))
					debug.warn('Error: save game moves to invalid contengency node!')
					return
				player.current=player.current.contingency
			player.savegame.append(newnodenum)
		if VS.isserver():
			custom.run("campaign", [self.name, "setsavegame"] + player.savegame, None)
		debug.debug('*** read position from save game: for '+self.name+': '+str(player.savegame))
		debug.debug(player.current)
Example #4
0
def CreateCampaignFixers(room,locations,j=0):
    if VS.networked():
        import campaign_lib
        def cont(args):
            CreateCampaignFixers_real(room,locations,j)
        campaign_lib.default_room = room # Don't want stuff appearing in the launch pad.
        custom.run("campaign_readsave",[],cont)
    else:
        CreateCampaignFixers_real(room,locations,j)
Example #5
0
def getTargetShipInfo(plr):
	print 'running getTargetShipInfo'
	newTarget = plr.myTarget
	fg = newTarget.getFlightgroupName()
	def targetResponse(args):
		plr.sendingShipinfoRequest=False;
		if (newTarget == plr.myUnit.GetTarget()):
			VS.setTargetLabel('\n'.join(args))
		else: # Our target changed... try again:
			getTargetShipInfo(plr)
	if fg and fg!='Base' and not plr.sendingShipinfoRequest:
		custom.run("shipinfo",[fg],targetResponse)
		plr.sendingShipinfoRequest=True
Example #6
0
def getTargetShipInfo(plr):
    print('running getTargetShipInfo')
    newTarget = plr.myTarget
    fg = newTarget.getFlightgroupName()
    def targetResponse(args):
        plr.sendingShipinfoRequest=False;
        if (newTarget == plr.myUnit.GetTarget()):
            VS.setTargetLabel('\n'.join(args))
        else: # Our target changed... try again:
            getTargetShipInfo(plr)
    if fg and fg!='Base' and not plr.sendingShipinfoRequest:
        custom.run("shipinfo",[fg],targetResponse)
        plr.sendingShipinfoRequest=True
Example #7
0
def CreateMissionFixers (room,locations,j=0):
    fixerinfo = []
    if VS.networked():
        def mademissions(args):
            num = int(args[0])
            for i in range(num):
                f = (args[1+3*i],args[2+3*i],args[3+3*i])
                fixerinfo.append(f)
            CreateMissionFixers_real(room,locations,j,fixerinfo)
        custom.run("mission_lib",['CreateFixerMissions'],mademissions)
    else:
        fixerinfo = mission_lib.CreateFixerMissions()
        CreateMissionFixers_real(room,locations,j,fixerinfo)
Example #8
0
def CreateJoinedGuild(guildname,guildroom):
    print('has joined.')
    if not VS.networked():
        print('make missions')
        guildroom.guild.MakeMissions()
        guildroom.drawobjs()
    else:
        def MakeStatus(args):
            if args[0]=='success':
                guildroom.guild.nummissions = int(args[1])
                guildroom.drawobjs()
            else:
                print("MakeMissions call returned "+str(args))
        custom.run('guilds',[guildname,'MakeMissions'], MakeStatus)
Example #9
0
def CreateJoinedGuild(guildname,guildroom):
	print 'has joined.'
	if not VS.networked():
		print 'make missions'
		guildroom.guild.MakeMissions()
		guildroom.drawobjs()
	else:
		def MakeStatus(args):
			if args[0]=='success':
				guildroom.guild.nummissions = int(args[1])
				guildroom.drawobjs()
			else:
				print "MakeMissions call returned "+str(args)
		custom.run('guilds',[guildname,'MakeMissions'], MakeStatus)
Example #10
0
 def RequestJoin(self):
     def JoinStatus(args):
         if args[0]=="success":
             Base.Message('Thank you for joining the '+str(self.name)+' Guild! Feel free to accept any of our large quantity of high-paying missions.')
             VS.playSound("guilds/"+str(self.name).lower()+"accept.wav",(0,0,0),(0,0,0))
         else:
             Base.Message('We have checked your account and it appears that you do not have enough credits to join this guild. Please come back and reconsider our offer when you have received more credits.')
             VS.playSound("guilds/"+str(self.name).lower()+"notenoughmoney.wav",(0,0,0),(0,0,0))
     plr=VS.getPlayer()
     plrnum=plr.isPlayerStarship()
     VS.StopAllSounds()
     if self.CanPay():
         custom.run('guilds',[self.name,'join'], JoinStatus)
     else:
         joinStatus(["failure"])
Example #11
0
	def RequestJoin(self):
		def JoinStatus(args):
			if args[0]=="success":
				Base.Message('Thank you for joining the '+str(self.name)+' Guild! Feel free to accept any of our large quantity of high-paying missions.')
				VS.playSound("guilds/"+str(self.name).lower()+"accept.wav",(0,0,0),(0,0,0))
			else:
				Base.Message('We have checked your account and it appears that you do not have enough credits to join this guild. Please come back and reconsider our offer when you have received more credits.')
				VS.playSound("guilds/"+str(self.name).lower()+"notenoughmoney.wav",(0,0,0),(0,0,0))
		plr=VS.getPlayer()
		plrnum=plr.isPlayerStarship()
		VS.StopAllSounds()
		if self.CanPay():
			custom.run('guilds',[self.name,'join'], JoinStatus)
		else:
			joinStatus(["failure"])
Example #12
0
 def accept(self):
     if not self.guild.CanTakeMoreMissions():
         self.guild.TooManyMissions()
     else:
         self.isactive=True
         self.removeobjs()
         mission_lib.SetLastMission(self.missionname);
         def completeAccept(args):
             if VS.networked():
                 if args[0]=="success" or args[0]=="notavailable":
                     mission_lib.BriefLastMission(self.missionname,1,self.guild.textbox)
                     mission_lib.RemoveLastMission(self.missionname)
             if args[0]=="toomany":
                 self.guild.TooManyMissions()
         if not VS.networked():
             mission_lib.BriefLastMission(self.missionname,1,self.guild.textbox)
         custom.run("guilds",[self.guild.guild.name,"accept",self.missionname],completeAccept)
Example #13
0
	def accept(self):
		if not self.guild.CanTakeMoreMissions():
			self.guild.TooManyMissions()
		else:
			self.isactive=True
			self.removeobjs()
			mission_lib.SetLastMission(self.missionname);
			def completeAccept(args):
				if VS.networked():
					if args[0]=="success" or args[0]=="notavailable":
						mission_lib.BriefLastMission(self.missionname,1,self.guild.textbox)
						mission_lib.RemoveLastMission(self.missionname)
				if args[0]=="toomany":
					self.guild.TooManyMissions()
			if not VS.networked():
				mission_lib.BriefLastMission(self.missionname,1,self.guild.textbox)
			custom.run("guilds",[self.guild.guild.name,"accept",self.missionname],completeAccept)
def AddNewMission(which,args,constructor=None,briefing0='',briefing1='',vars0=None,vars1=None):
	if VS.isserver():
		sendargs = ["AddNewMission", which, briefing0, briefing1, len(vars0)]
		for key in vars0:
			sendargs.append(key)
			sendargs.append(vars0[key])
		custom.run("mission_lib", sendargs, None)
	
	plr = getMissionPlayer()
	addPlayer(plr, False)
	playerInfo = players[plr]
	
	which=str(which)
	playerInfo.last_constructor[which]=constructor
	playerInfo.last_args[which]=args
	playerInfo.last_briefing[0][which]=briefing0
	playerInfo.last_briefing[1][which]=briefing1
	playerInfo.last_briefing_vars[0][which]=vars0
	playerInfo.last_briefing_vars[1][which]=vars1
Example #15
0
def walk(inputFile):

    ### Acquiring the initial time
    t0 = time.time()

    #    ###PreParsing
    par.preParsing(inputFile)

    ### Parsing the input file
    par.parsingFile(inputFile)

    ### Setting work path
    io.directory_Creation()

    ### Generating some files for Quantum Walk
    io.initializeFiles()

    if cfg.ADJMATRIX_PATH != "@NON_INICIALIZED@":
        dist.generateDistance()

    if cfg.WALK == "DTQW1D":
        cfg.RETURN_SIMULATION_FLAG = dtqw1d.run()

    elif cfg.WALK == "DTQW2D":
        cfg.RETURN_SIMULATION_FLAG = dtqw2d.run()

    elif cfg.WALK == "STAGGERED1D":
        cfg.RETURN_SIMULATION_FLAG = staggered1d.run()

    elif cfg.WALK == "STAGGERED2D":
        cfg.RETURN_SIMULATION_FLAG = staggered2d.run()

    elif cfg.WALK == "SZEGEDY":
        cfg.RETURN_SIMULATION_FLAG = szegedy.run()

    elif cfg.WALK == "CUSTOM":
        cfg.RETURN_SIMULATION_FLAG = custom.run()

    ### Cleaning temporary files
    if not cfg.DEBUG:
        io.cleaningTemporaryFiles()

    os.chdir(cfg.OLD_DIRECTORY)

    ### End runtime
    t1 = time.time()

    print("[HIPERWALK] Runtime: ", t1 - t0)

    return cfg.RETURN_SIMULATION_FLAG
Example #16
0
def dialog(args, callback, room=None):
    global _gui_has_initted

    db = DialogBox(parse_dialog_box(args), callback)
    if VS.isserver():
        db.id = custom.run("dialog_box", args, lambda data: callback(db, data))
        return db.id
    if not room:
        room = Base.GetCurRoom()
    if not _gui_has_initted:
        GUI.GUIInit(320, 200)
        _gui_has_initted = True
    db.create(room)
    db.draw()
    GUI.GUIRootSingleton.broadcastMessage('draw', None)
Example #17
0
def dialog(args, callback, room=None):
    global _gui_has_initted

    db = DialogBox(parse_dialog_box(args),callback)
    if VS.isserver():
        db.id = custom.run("dialog_box",args,lambda data:callback(db,data))
        return db.id
    if not room:
        room=Base.GetCurRoom()
    if not _gui_has_initted:
        GUI.GUIInit(320,200)
        _gui_has_initted=True
    db.create(room)
    db.draw()
    GUI.GUIRootSingleton.broadcastMessage('draw',None)
Example #18
0
def AddNewMission(which,args,constructor=None,briefing0='',briefing1='',vars0=None,vars1=None):
    """ Adds a mission to the list of missions stored in playerInfo. """
    if not isinstance(vars0,dict):
        vars0 = dict()
        vars1 = vars0
    if VS.isserver():
        lenvars0=len(vars0)
        sendargs = ["AddNewMission", which, briefing0, briefing1,lenvars0]
        for key in vars0:
            sendargs.append(key)
            sendargs.append(vars0[key])
        custom.run("mission_lib", sendargs, None)

    plr = getMissionPlayer()
    addPlayer(plr, False)
    playerInfo = players[plr]

    which = str(which)
    playerInfo.last_constructor[which] = constructor
    playerInfo.last_args[which] = args
    playerInfo.last_briefing[0][which] = briefing0
    playerInfo.last_briefing[1][which] = briefing1
    playerInfo.last_briefing_vars[0][which] = vars0
    playerInfo.last_briefing_vars[1][which] = vars1
def dialog(args, callback, room=None):

    if args[0] == "position":
        xcent = float(args[1])
        ycent = float(args[2])
    else:
        xcent = 0.0
        ycent = 0.0
    db = DialogBox(parse_dialog_box(args), callback, position=(xcent, ycent))
    if VS.isserver():
        db.id = custom.run("dialog_box", args, lambda data: callback(db, data))
        return db.id
    if not room:
        room = Base.GetCurRoom()
    if not GUI.GUIRootSingleton:
        GUI.GUIInit(320, 200)
    db.create(room)
    db.draw()
    GUI.GUIRootSingleton.broadcastMessage("draw", None)
def LoadLastMission(which=None):
	plr = getMissionPlayer()
	if which is None:
		which=players[plr].lastMission
	if VS.networked():
		custom.run('mission_lib', ['LoadLastMission',which], None)
		return
	
	last_constructor = players[plr].last_constructor
	last_args = players[plr].last_args
	last_briefing_vars = players[plr].last_briefing_vars
	last_briefing = players[plr].last_briefing

	ret = True
	if len(last_briefing_vars) and which in last_briefing_vars[0] and 'MISSION_TYPE' in last_briefing_vars[0][which] and last_briefing_vars[0][which]['MISSION_TYPE']=='CARGO' and NotEnoughCargoRoom(plr):
		ret= False
	elif which in last_constructor and which in last_args:
		if last_constructor[which]==None:
			if type(last_args[which])==str:
				script = "%(args)s"
			else:
				script = "%(args)r()"
			vars = dict(args=last_args[which])
		else:
			script = '''#
import %(constructor)s
temp=%(constructor)s.%(constructor)s%(args)s
mission_lib.AddMissionHooks(temp)
temp=0
'''
			cons=last_constructor[which]
			if type(cons)!=str:
				cons=cons.__name__
			if type(last_args[which])==str:
				args = last_args[which]
			else:
				args = repr(last_args[which])
			vars = dict(constructor=cons,args=args)
		script = script % vars
		if script[:1] == '#':
			prescript = '''#
import mission_lib
mission_lib.SetMissionHookArgs(%(amentry)r)
%(postscript)s'''
			amentry = last_briefing_vars[0].get(which,dict())
			try:
				amentry.update(last_briefing_vars[1].get(which,dict()).iteritems())
				amentry.update([
					('MISSION_NAME',which),
					('DESCRIPTION',last_briefing[0].get(which,'')),
					('ACCEPT_MESSAGE',last_briefing[1].get(which,'')) 
					])
			except:
				print "TRACING BACK"
				import sys
				print sys.exc_info()[0]
				print sys.exc_info()[1]
				print "BACKTRACE done"
				ret = False
			vars = dict(amentry=amentry,postscript=script)
			script = prescript % vars
		print "Loading mission:\n%s" % script
		VS.LoadMissionScript(script)
	else:
		print 'No last mission with name "'+str(which)+'"'
		ret = False
	RemoveLastMission(which)
	return ret
Example #21
0
def LoadLastMission(which=None):
    """ Makes a mission an active mission. """
    print("#given mission argument: ", which)
    plr = getMissionPlayer()
    if which is None:
        which = str(players[plr].lastMission)
        print("#loading mission: ", which)
    if VS.networked():
        custom.run('mission_lib', ['LoadLastMission',which], None)
        return

    last_constructor = players[plr].last_constructor
    last_args = players[plr].last_args
    last_briefing_vars = players[plr].last_briefing_vars
    last_briefing = players[plr].last_briefing
    ret = True
    if which in last_constructor and which in last_args:
        if last_constructor[which]==None:
            if type(last_args[which])==str:
                script = "%(args)s"
            else:
                script = "%(args)r()"
            vars = dict(args=last_args[which])
        else:
            script = '''#
import %(constructor)s
temp=%(constructor)s.%(constructor)s%(args)s
mission_lib.AddMissionHooks(temp)
temp=0
'''
            cons=last_constructor[which]
            if type(cons)!=str:
                cons=cons.__name__
            if type(last_args[which])==str:
                args = last_args[which]
            else:
                args = repr(last_args[which])
            vars = dict(constructor=cons,args=args)
        script = script % vars
        if script[:1] == '#':
            prescript = '''#
import mission_lib
mission_lib.SetMissionHookArgs(%(amentry)r)
%(postscript)s'''
            amentry = last_briefing_vars[0].get(which,dict())
            try:
                amentry.update(iter(last_briefing_vars[1].get(which,dict()).items()))
                amentry.update([
                    #('MISSION_NAME',which),
                    ('DESCRIPTION',last_briefing[0].get(which,'')),
                    ('ACCEPT_MESSAGE',last_briefing[1].get(which,''))
                    ])
            except:
                debug.error("TRACING BACK")
                import sys
                debug.error(sys.exc_info()[0])
                debug.error(sys.exc_info()[1])
                debug.error("BACKTRACE done")
                ret = False
            vars = dict(amentry=amentry,postscript=script)
            script = prescript % vars
        debug.debug("Loading mission:\n%s" % script)
        VS.LoadNamedMissionScript(which, script)
    else:
        debug.debug('No last mission with name "'+str(which)+'"')
        ret = False
    RemoveLastMission(which)
    return ret
def LoadLastMission(which=None):
    """ Makes a mission an active mission. """
    print("#given mission argument: ", which)
    plr = getMissionPlayer()
    if which is None:
        which = str(players[plr].lastMission)
        print("#loading mission: ", which)
    if VS.networked():
        custom.run('mission_lib', ['LoadLastMission', which], None)
        return

    last_constructor = players[plr].last_constructor
    last_args = players[plr].last_args
    last_briefing_vars = players[plr].last_briefing_vars
    last_briefing = players[plr].last_briefing
    ret = True
    if which in last_constructor and which in last_args:
        if last_constructor[which] == None:
            if type(last_args[which]) == str:
                script = "%(args)s"
            else:
                script = "%(args)r()"
            vars = dict(args=last_args[which])
        else:
            script = '''#
import %(constructor)s
temp=%(constructor)s.%(constructor)s%(args)s
mission_lib.AddMissionHooks(temp)
temp=0
'''
            cons = last_constructor[which]
            if type(cons) != str:
                cons = cons.__name__
            if type(last_args[which]) == str:
                args = last_args[which]
            else:
                args = repr(last_args[which])
            vars = dict(constructor=cons, args=args)
        script = script % vars
        if script[:1] == '#':
            prescript = '''#
import mission_lib
mission_lib.SetMissionHookArgs(%(amentry)r)
%(postscript)s'''
            amentry = last_briefing_vars[0].get(which, dict())
            try:
                amentry.update(
                    iter(last_briefing_vars[1].get(which, dict()).items()))
                amentry.update([
                    #('MISSION_NAME',which),
                    ('DESCRIPTION', last_briefing[0].get(which, '')),
                    ('ACCEPT_MESSAGE', last_briefing[1].get(which, ''))
                ])
            except:
                debug.error("TRACING BACK")
                import sys
                debug.error(sys.exc_info()[0])
                debug.error(sys.exc_info()[1])
                debug.error("BACKTRACE done")
                ret = False
            vars = dict(amentry=amentry, postscript=script)
            script = prescript % vars
        debug.debug("Loading mission:\n%s" % script)
        VS.LoadNamedMissionScript(which, script)
    else:
        debug.debug('No last mission with name "' + str(which) + '"')
        ret = False
    RemoveLastMission(which)
    return ret