예제 #1
0
 def playerIsUndocked(self):
   # dockedobject and dockeddistance must be global, i.e prefixed with self
   # otherwise the script will advance to next stage just after undocking
   # get the planet object 
   self.dockedobject = universe.getDockedBase()
   name = self.dockedobject.getName()
   # verify if player is still docked and set the reference distance
   if (not name==""):
     self.dockeddistance = self.dockedobject.getDistance(self.player)
     self.startobjectname = name
   # when starting from Atlantis, target the departing planet to see the distance
   if (name=="Atlantis"):
     self.player.SetTarget(self.dockedobject)
   # if the player was never docked or is not docked and at least 1km away then set next stage number
   if (name=="" or ((not self.startobjectname=="") and (not self.startobjectname=="Atlantis") and self.dockedobject.getDistance(self.player)>(self.dockeddistance+1000))):
     self.stage = STAGE_AWAY
     self.timer = VS.GetGameTime()+5
   return 0
예제 #2
0
 def playerIsUndocked(self):
     # dockedobject and dockeddistance must be global, i.e prefixed with self
     # otherwise the script will advance to next stage just after undocking
     # get the planet object
     self.dockedobject = universe.getDockedBase()
     name = self.dockedobject.getName()
     # verify if player is still docked and set the reference distance
     if (not name==""):
         self.dockeddistance = self.dockedobject.getDistance(self.player)
         self.startobjectname = name
     # when starting from Atlantis, target the departing planet to see the distance
     if (name=="Atlantis"):
         self.player.SetTarget(self.dockedobject)
     # if the player was never docked or is not docked and at least 1km away then set next stage number
     if (name=="" or ((not self.startobjectname=="") and (not self.startobjectname=="Atlantis") and self.dockedobject.getDistance(self.player)>(self.dockeddistance+1000))):
         self.stage = STAGE_AWAY
         self.timer = VS.GetGameTime()+5
     return 0
예제 #3
0
def get_base_text(current_base = None, str_system_file = None):
	if current_base is None:
		current_base = universe.getDockedBase()

	if not current_base:
		return ((0,"neutral"),("Unknown","Main Menu"))
	if str_system_file is None:
		# get sector, quadrant, system, and base name
		str_system_file = current_base.getUnitSystemFile()
	
	# get faction
	int_faction = current_base.getFactionIndex()
	str_faction = current_base.getFactionName()

	# bases and planets aren't consistent in their usage of Name and Fullname values
	if not current_base:
		import debug
		debug.error('getDockedBase() returns null Unit!')
	if current_base.isPlanet():
		str_base = current_base.getName()
		str_base_type = current_base.getFullname() + " planet"
	else:
		str_base = current_base.getFullname()
		str_base_type = current_base.getName()
		if str_base == '':
			str_base = 'Unknown'
			if str_faction == "pirates":
				try:
					str_base = pirate_bases[str_system_file]
				except KeyError:
					str_base = 'Unknown'

	# adjust the base type for certain planets
	if str_base_type == 'new_constantinople':
		str_base_type = "government base"
	elif str_base_type == 'perry':
		str_base_type = "military base"
	elif str_base_type == 'church_of_man planet':
		str_base_type = "agricultural planet"

	return ((int_faction,str_faction),(str_base,str_base_type))
예제 #4
0
def get_base_text(current_base = None, str_system_file = None):
    if current_base is None:
        current_base = universe.getDockedBase()

    if not current_base:
        return ((0,"neutral"),("Unknown","Main Menu"))
    if str_system_file is None:
        # get sector, quadrant, system, and base name
        str_system_file = current_base.getUnitSystemFile()

    # get faction
    int_faction = current_base.getFactionIndex()
    str_faction = current_base.getFactionName()

    # bases and planets aren't consistent in their usage of Name and Fullname values
    if not current_base:
        import debug
        debug.error('getDockedBase() returns null Unit!')
    if current_base.isPlanet():
        str_base = current_base.getName()
        str_base_type = current_base.getFullname() + " planet"
    else:
        str_base = current_base.getFullname()
        str_base_type = current_base.getName()
        if str_base == '':
            str_base = 'Unknown'
            if str_faction == "pirates":
                try:
                    str_base = pirate_bases[str_system_file]
                except KeyError:
                    str_base = 'Unknown'

    # adjust the base type for certain planets
    if str_base_type == 'new_constantinople':
        str_base_type = "government base"
    elif str_base_type == 'perry':
        str_base_type = "military base"
    elif str_base_type == 'church_of_man planet':
        str_base_type = "agricultural planet"

    return ((int_faction,str_faction),(str_base,str_base_type))
예제 #5
0
def get_system_text(str_system_file=None, current_base=None):
    if str_system_file is None:
        if current_base is None:
            current_base = universe.getDockedBase()
        # get sector, quadrant, system, and base name
        str_system_file = current_base.getUnitSystemFile()

    n = str_system_file.find('/')
    if (n >= 0):
        str_sector   = str_system_file[:n]
        str_system   = str_system_file[n+1:]
    else:
        str_sector   = 'Unknown'
        str_system   = 'Unknown'

    try:
        str_quadrant = quadrants[str_system_file]
    except KeyError:
        str_quadrant = 'Unknown'

    return (str_quadrant,str_sector,str_system)
예제 #6
0
def get_system_text(str_system_file=None, current_base=None):
    if str_system_file is None:
        if current_base is None:
            current_base = universe.getDockedBase()
        # get sector, quadrant, system, and base name
        str_system_file = current_base.getUnitSystemFile()

    n = str_system_file.find('/')
    if (n >= 0):
        str_sector   = str_system_file[:n]
        str_system   = str_system_file[n+1:]
    else:
        str_sector   = 'Unknown'
        str_system   = 'Unknown'

    try:
        str_quadrant = quadrants[str_system_file]
    except KeyError:
        str_quadrant = 'Unknown'

    return (str_quadrant,str_sector,str_system)
def get_base_text(current_base=None, str_system_file=None):
    if current_base is None:
        current_base = universe.getDockedBase()

    if str_system_file is None:
        # get sector, quadrant, system, and base name
        str_system_file = current_base.getUnitSystemFile()

        # get faction
    int_faction = current_base.getFactionIndex()
    str_faction = current_base.getFactionName()

    # bases and planets aren't consistent in their usage of Name and Fullname values
    if current_base.isPlanet():
        str_base = current_base.getName()
        str_base_type = current_base.getFullname() + " planet"
    else:
        str_base = current_base.getFullname()
        str_base_type = current_base.getName()
        if str_base == "":
            str_base = "Unknown"
            if str_faction == "pirates":
                try:
                    str_base = pirate_bases[str_system_file]
                except KeyError:
                    str_base = "Unknown"

                # adjust the base type for certain planets
    if str_base_type == "new_constantinople":
        str_base_type = "government base"
    elif str_base_type == "perry":
        str_base_type = "military base"
    elif str_base_type == "church_of_man planet":
        str_base_type = "agricultural planet"

    return ((int_faction, str_faction), (str_base, str_base_type))
예제 #8
0
    def __init__(self, room_start, room_exit_to, enable_missions, enable_finances, enable_manifest, enable_load, enable_save):
        # Quine computer is made up of several "rooms" aka screens
        # the room_start show the user's location
        # this is made a lot more complex because of the need to update the cargo manifest
        guiroom = GUI.GUIRoom(room_start)
        self.guiroom = guiroom

        # when a button is clicked, this will allow us to get the QuineComputer instance from the x_click functions
        guiroom.owner = self

        # add background sprite; no need to keep a variable around for this, as it doesn't change
        GUI.GUIStaticImage(guiroom, 'background', ( 'interfaces/quine/main.spr' , GUI.GUIRect(0, 0, 1, 1, "normalized") )).draw()

        # add buttons
        self.buttons = {}
        self.mode = ''
        self.saveGameNameEntryBox = None

        if enable_finances:
            hot_loc = GUI.GUIRect(547, 279, 105, 60, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/fin_pressed.spr",spr_loc)
            spr_disabled = ("interfaces/quine/fin_disabled.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':spr_disabled, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXFinances','btn_finances', sprites, hot_loc), change_text_click )
        if enable_manifest:
            hot_loc = GUI.GUIRect(646, 279, 96, 64, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/man_pressed.spr",spr_loc)
            spr_disabled = ("interfaces/quine/man_disabled.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':spr_disabled, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXManifest','btn_manifest', sprites, hot_loc), change_text_click )
        if enable_load:
            hot_loc = GUI.GUIRect(635, 166, 97, 55, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/load_pressed.spr",spr_loc)
            spr_disabled = ("interfaces/quine/load_disabled.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':spr_disabled, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXLoad'    ,'btn_load'    , sprites, hot_loc), change_text_click )
        if enable_save:
            hot_loc = GUI.GUIRect(541, 166, 97, 55, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/save_pressed.spr",spr_loc)
            spr_disabled = ("interfaces/quine/save_disabled.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':spr_disabled, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXSave'    ,'btn_save'    , sprites, hot_loc), change_text_click )
        if enable_missions:
            hot_loc = GUI.GUIRect(543, 220, 100, 60,"pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/missions_pressed.spr",spr_loc)
            spr_disabled = ("interfaces/quine/missions_disabled.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':spr_disabled, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXMissions','btn_missions', sprites, hot_loc), change_text_click )

        if enable_load or enable_save:
            hot_loc = [ GUI.GUIRect(631, 346, 51, 69, "pixel", (800,600)), #up-arrow
                        GUI.GUIRect(629, 410, 55, 69, "pixel", (800,600)), #down-
                        GUI.GUIRect(560, 383, 72, 57, "pixel", (800,600)), #left-
                        GUI.GUIRect(684, 383, 72, 57, "pixel", (800,600)) ] #right-
            spr_loc = hot_loc
            spr = [ ("interfaces/quine/up_pressed.spr"   ,spr_loc[0]),
                    ("interfaces/quine/down_pressed.spr" ,spr_loc[1]),
                    ("interfaces/quine/left_pressed.spr" ,spr_loc[2]),
                    ("interfaces/quine/right_pressed.spr",spr_loc[3])
                  ]
            spr_disabled = [ ("interfaces/quine/up_disabled.spr"   ,spr_loc[0]),
                             ("interfaces/quine/down_disabled.spr" ,spr_loc[1]),
                             ("interfaces/quine/left_disabled.spr" ,spr_loc[2]),
                             ("interfaces/quine/right_disabled.spr",spr_loc[3])
                           ]
            sprites = [ { 'enabled':None, 'disabled':spr_disabled[0], 'down':spr[0] },
                        { 'enabled':None, 'disabled':spr_disabled[1], 'down':spr[1] },
                        { 'enabled':None, 'disabled':spr_disabled[2], 'down':spr[2] },
                        { 'enabled':None, 'disabled':spr_disabled[3], 'down':spr[3] }
                      ]
            self.add_button( GUI.GUIButton(guiroom,'XXXUp'   ,'btn_up'   , sprites[0], hot_loc[0]), scroll_click )
            self.add_button( GUI.GUIButton(guiroom,'XXXDown' ,'btn_down' , sprites[1], hot_loc[1]), scroll_click )
            self.add_button( GUI.GUIButton(guiroom,'XXXLeft' ,'btn_left' , sprites[2], hot_loc[2]), scroll_click )
            self.add_button( GUI.GUIButton(guiroom,'XXXRight','btn_right', sprites[3], hot_loc[3]), scroll_click )

        current_base = universe.getDockedBase()
        player = VS.getPlayer()

        # this doesn't change while docked, so only call it once
        self.str_start = get_location_text(current_base)

        screen_loc = GUI.GUIRect(80,90,350,380,"pixel",(800,600))
        screen_color = GUI.GUIColor(20/255.0, 22/255.0 ,10/255.0)
        self.screen_color = screen_color;
        self.screen_loc = screen_loc;

        # first I tried rgb(56 60 24) and rgb(40 44 20); both were too light
        screen_bgcolor = GUI.GUIColor.clear()
        screen_bgcolor_nc = GUI.GUIColor(0.44,0.47,0.17)
        self.screen_bgcolor = screen_bgcolor;

        # text screen
        self.txt_screen = GUI.GUIStaticText(guiroom, 'txt_screen', self.str_start, screen_loc,
            color=screen_color,
            bgcolor=screen_bgcolor)
        self.txt_screen.hide()

        # picker screen
        self.picker_screen = GUI.GUISimpleListPicker(guiroom,'XXXSelect item','picker_screen', screen_loc,
            textcolor    =screen_color     , textbgcolor    =screen_bgcolor,
            selectedcolor=screen_bgcolor_nc, selectedbgcolor=screen_color   )
        self.picker_screen.hide()

        #
        # much of this is temporary, until something better can be worked out:
        #

        # Save/Load screen
        #if enable_save:
        #   x, y, w, h = GUI.GUIRect(217, 56, 40, 18).getHotRect()
        #   Base.Comp (room_start, 'save_comp', x, y, w, h, 'XXXSave/Load/Quit', 'LoadSave')
        #if enable_load:
        #   x, y, w, h = GUI.GUIRect(257, 56, 39, 18).getHotRect()
        #   Base.Comp (room_start, 'load_comp', x, y, w, h, 'XXXSave/Load/Quit', 'LoadSave')

        # Missions
        #if enable_missions:
        #   x, y, w, h = GUI.GUIRect(217, 75, 79, 18).getHotRect()
        #   Base.Comp (room_start, 'missions', x, y, w, h, 'XXXMissions', 'Missions Info Cargo ')

        # Finances
        #if enable_finances:
        #   x, y, w, h = GUI.GUIRect(219, 94, 40, 18).getHotRect()
        #   Base.Comp (room_start, 'missions', x, y, w, h, 'Finances', 'Info ')

        # Manifest
        #if enable_manifest:
        #   x, y, w, h = GUI.GUIRect(260, 94, 40, 18).getHotRect()
        #   Base.Comp (room_start, 'missions', x, y, w, h, 'Manifest', 'Cargo ')

        # Exit button, returns us to concourse
        self.room_id = room_start
        self.exit_room_id = room_exit_to
        self.setExitLinkState(True)
	def select(self,select_all=False): 
		if self.state == "buy":
			# if player has sufficient cargo space and credits:
			# remove x items from exports
			# add x items to imports/player manifest
			# remove credits from players account
			if self.current_item < len(self.exports):
				# we have to call this, in case player has bought or sold ship or cargo expansion
				self.update_player_manifest()
				try:
					player = VS.getPlayer()
					current_base = universe.getDockedBase()
					category = self.exports[self.current_item][0]
					quantity = self.exports[self.current_item][1]
					price = self.prices[category]
					if (self.import_count >= self.player_hold_volume):
						self.draw("NO ROOM ON SHIP")
						
					elif (price > VS.getPlayer().getCredits()):
						self.draw("INSUFFICIENT CREDITS")

					else:
						if (quantity > 0):
							# commodity exchange has items to sell
							# if select_all is True, then do loop here, incrementing count while hold has space and user has sufficient credits
							if price > 0:
								count = max( 1, min(
									quantity,
									(self.player_hold_volume - self.import_count),
									int(player.getCredits() / price) ))
							else:
								count = max( 1, min(
									quantity,
									(self.player_hold_volume - self.import_count) ))

							#
							# transfer cargo from exchange to players ship
							#
							if not select_all:
								count=1
							elif count > PURCHASE_MAX:
								count = PURCHASE_MAX
							transfer_count = transfer_cargo(current_base, player, category, price, count, self.player_hold_volume, self.import_count)

							# update the commodity exchange exports list
							self.exports[self.current_item][1] = quantity - transfer_count

							# update the players imports list and
							# increment the import_count value
							self.import_count = self.import_count + transfer_count
							import_index = -1
							for i in range(len(self.imports)):
								if self.imports[i][0] == category:
									import_index = i
							if import_index == -1:
								self.imports.append([category,transfer_count])
							else:
								self.imports[import_index][1] = self.imports[import_index][1] + transfer_count

							# remove credits from players account
							player.addCredits(-1 * transfer_count * price)
							
							# remove sprite from exports list if necessary
							quantity = self.exports[self.current_item][1]
							if quantity <= 0:
								self.exports.pop(self.current_item)
								if self.current_item >= len(self.exports):
									self.current_item = 0
						self.draw()
				except:
					pass
		elif self.state == "sell":
			# remove x items from imports
			# add x items to exports
			# add credits to players account
			if self.current_item < len(self.imports):
				try:
					player = VS.getPlayer()
					current_base = universe.getDockedBase()
					category = self.imports[self.current_item][0]
					quantity = self.imports[self.current_item][1]
					price = self.prices[category]
					if (select_all):
						count = quantity
						if count > PURCHASE_MAX:
							count = PURCHASE_MAX
					else:
						count = 1
						
					if ((quantity > 0) and (count <= quantity)):

						#
						# transfer cargo from players ship to exchange
						#
						transfer_count = transfer_cargo(player, current_base, category, price, count)

						# update the players imports list
						self.imports[self.current_item][1] = quantity - transfer_count
	
						# update the commodity exchanges exports list
						export_index = -1
						for i in range(len(self.exports)):
							if self.exports[i][0] == category:
								export_index = i
						if export_index == -1:
							self.exports.append([category,transfer_count])
						else:
							self.exports[export_index][1] = self.exports[export_index][1] + transfer_count
	
						# add credits to players account
						player.addCredits(transfer_count * price)
	
						# clean up if necessary
						quantity = self.imports[self.current_item][1]
						if quantity <= 0:
							self.imports.pop(self.current_item)
							if self.current_item >= len(self.imports):
								self.current_item = 0

				except:
					pass
				self.draw()
	def __init__(self,room_id):
		self.room_id  = room_id

		# initial state is "buy"
		self.state = "buy"
		self.current_item = 0

		# add GUI to commodity computer
		guiroom  = GUI.GUIRoom(room_id)
		self.guiroom = guiroom


		# when a button is clicked, this will allow us to get the CommodityComputer instance from the x_click functions
		guiroom.owner = self

		# draw the background images
		background = GUI.GUIStaticImage(guiroom, 'background', ( 'interfaces/commodity/Commodity.spr', GUI.GUINPOTRect(0, 0, 320, 200, 320, 200, "pixel") ))
#		computer   = GUI.GUIStaticImage(guiroom, 'computer', ( 'interfaces/commodity/Commodity_Computer.spr', GUI.GUINPOTRect(0, 0, 320, 200, 320, 200, "pixel") ))
		computer   = GUI.GUIStaticImage(guiroom, 'computer', ( 'interfaces/commodity/Commodity_Computer_hi.spr', GUI.GUIRect(0, 0, 132, 100, "pixel") ))

		self.buttons = {}

#		buy_sprite  = ('interfaces/commodity/buy.spr',  GUI.GUINPOTRect(0, 0, 320, 200, 320, 200))
#		sell_sprite = ('interfaces/commodity/sell.spr', GUI.GUINPOTRect(0, 0, 320, 200, 320, 200))
		# pixel coordinates fractional because art is 1024x1024 and screen is at 320x200
		buy_sprite  = ('interfaces/commodity/buy_hi.spr' , GUI.GUIRect(71.5625, 79.4921875, 25.3125, 8.984375))
		sell_sprite = ('interfaces/commodity/sell_hi.spr', GUI.GUIRect(26.8750, 79.4921875, 25.3125, 9.1796875)) 
		buy_sprset  = { 'checked': buy_sprite, 'unchecked': None, 'hot': buy_sprite }
		sell_sprset = { 'checked': sell_sprite, 'unchecked': None, 'hot': sell_sprite }
		prev_sprset = {'enabled':None, 'disabled':None }
		next_sprset = {'disabled':None }
		self.add_button( GUI.GUIButton     (guiroom, 'Next Item',          'btn_next',   next_sprset, GUI.GUIRect(122, 26, 7, 14)                  ), next_click )
		self.add_button( GUI.GUIButton     (guiroom, 'Previous Item',      'btn_prev',   prev_sprset, GUI.GUIRect(122, 44, 7, 14)                  ), prev_click )
		self.add_button( GUI.GUIRadioButton(guiroom, 'Activate Buy Mode',  'btn_buy',    buy_sprset,  GUI.GUIRect( 72, 80, 25, 9), 'commodity_mode'), mode_click )
		self.add_button( GUI.GUIRadioButton(guiroom, 'Activate Sell Mode', 'btn_sell',   sell_sprset, GUI.GUIRect( 27, 80, 25, 9), 'commodity_mode'), mode_click )
		self.add_button( GUI.GUIButton     (guiroom, 'Select Items',       'btn_select', {},          GUI.GUIRect(13, 13, 97, 60)                  ), select_click )

		# set the check button state
		if (self.state == "buy"):
			GUI.GUIRootSingleton.broadcastRoomMessage(guiroom.index,'check',{'index':'btn_buy'})
		elif (self.state == "sell"):
			GUI.GUIRootSingleton.broadcastRoomMessage(guiroom.index,'check',{'index':'btn_sell'})
	
		# add the text labels
		txt_color = GUI.GUIColor(0.7,0.7,0.7)
		txt_warning_color = GUI.GUIColor(0.7,0,0)
		self.txt_name     = GUI.GUIStaticText(guiroom,'txt_name',    '', GUI.GUIRect(15, 12, 98, 10), txt_color)
		self.txt_quantity = GUI.GUIStaticText(guiroom,'txt_quantity','', GUI.GUIRect(15, 17, 98, 10), txt_color)
		self.txt_cost     = GUI.GUIStaticText(guiroom,'txt_cost',    '', GUI.GUIRect(15, 62, 98, 10), txt_color)
		self.txt_credits  = GUI.GUIStaticText(guiroom,'txt_credits', '', GUI.GUIRect(15, 67, 98, 10), txt_color)

		# add the item sprite (a blank sprite for now)
		self.img_item_rect = GUI.GUIRect(15, 9, 90, 67)
		self.img_item  = GUI.GUIStaticImage(guiroom, 'img_item', None)

		# error messages should appear above item images
		# something wrong with z-ordering here, so img_item will appear above txt_message
		# instead, set the y coord lower, so the text is readable
#		self.txt_message  = GUI.GUIStaticText(guiroom,'txt_message', '', GUI.GUIRect(15, 43, 98, 10), txt_color)
		self.txt_message  = GUI.GUIStaticText(guiroom,'txt_message', '', GUI.GUIRect(15, 57, 98, 10), txt_warning_color)

		# get the currently docked planet/space station
		current_base = universe.getDockedBase()

		# generate the global price list
		# if item doesn't appear on this list, it can't be bought or sold
		self.prices, self.exports = get_commodity_lists(current_base)
		self.imports, self.import_not_for_sale = get_player_manifest(self.prices)
		# sprites for cargo items
		self.sprites = get_sprite_info()

		# draw now
		GUI.GUIRootSingleton.broadcastRoomMessage(guiroom.index, 'draw', None)

		self.reset()
	def select(self,select_all=False):
		if self.state == "buy":
			# if player has sufficient cargo space and credits:
			# remove x items from exports
			# add x items to imports/player manifest
			# remove credits from players account
			if self.current_item < len(self.exports):
				# we have to call this, in case player has bought or sold ship or cargo expansion
				self.update_player_manifest()
				try:
					player = VS.getPlayer()
					current_base = universe.getDockedBase()
					category = self.exports[self.current_item][0]
					quantity = self.exports[self.current_item][1]
					price = self.prices[category]
					if (self.import_count >= self.player_hold_volume):
						# if hold is full, display "NO ROOM"
						self.draw("NO ROOM ON SHIP")

					elif (price > VS.getPlayer().getCredits()):
						# if player doesn't have enough credits, display "YOU'RE BROKE"
						self.draw("INSUFFICIENT CREDITS")

					else:
						# otherwise, player has room and credits for at least 1 item
						if (quantity > 0):
							# commodity exchange has items to sell - item shouldn't be displayed if quantity is 0 anyway
							
							# calculate maximum player is able to buy; that is limited by:
							# 		quantity for sale
							#		player's available storage
							#		player's available credits
							if price > 0:
								count = min(
									quantity,
									(self.player_hold_volume - self.import_count),
									int(player.getCredits() / price) )
							else:
								# price should never be <= 0; just in case, avoid divide-by-zero or a negative count
								trace(_trace_level, "::: commodity buy - price <= 0 : %s, %s" %(category, price))
								count = min(
									quantity,
									(self.player_hold_volume - self.import_count) )

							#
							# transfer cargo from exchange to players ship
							#
							if not select_all:
								# select_all == false means buying 1 at a time
								if (count > 1):
									count=1
							elif count > PURCHASE_MAX:
								count = PURCHASE_MAX
							transfer_count = transfer_cargo(current_base, player, category, price, count, self.player_hold_volume, self.import_count)

							# update the commodity exchange exports list
							self.exports[self.current_item][1] = quantity - transfer_count

							# update the players imports list and
							# increment the import_count value
							self.import_count = self.import_count + transfer_count
							import_index = -1
							for i in range(len(self.imports)):
								if self.imports[i][0] == category:
									import_index = i
							if import_index == -1:
								self.imports.append([category,transfer_count])
							else:
								self.imports[import_index][1] = self.imports[import_index][1] + transfer_count

							# remove credits from players account
							player.addCredits(-1 * transfer_count * price)
							
							# remove sprite from exports list if necessary
							quantity = self.exports[self.current_item][1]
							if quantity <= 0:
								self.exports.pop(self.current_item)
								if self.current_item >= len(self.exports):
									self.current_item = 0
						else:
							# quantity should never be <= 0
							trace(_trace_level, "::: commodity buy - quantity <= 0 : %s, %s" %(category, quantity))
						self.draw()
				except:
					pass
		elif self.state == "sell":
			# remove x items from imports
			# add x items to exports
			# add credits to players account
			if self.current_item < len(self.imports):
				try:
					player = VS.getPlayer()
					current_base = universe.getDockedBase()
					category = self.imports[self.current_item][0]
					quantity = self.imports[self.current_item][1]
					price = self.prices[category]
					if (select_all):
						count = quantity
						if count > PURCHASE_MAX:
							count = PURCHASE_MAX
					else:
						count = 1
						
					if ((quantity > 0) and (count <= quantity)):

						#
						# transfer cargo from players ship to exchange
						#
						transfer_count = transfer_cargo(player, current_base, category, price, count)

						# update the players imports list
						self.imports[self.current_item][1] = quantity - transfer_count
	
						# update the commodity exchanges exports list
						export_index = -1
						for i in range(len(self.exports)):
							if self.exports[i][0] == category:
								export_index = i
						if export_index == -1:
							self.exports.append([category,transfer_count])
						else:
							self.exports[export_index][1] = self.exports[export_index][1] + transfer_count
	
						# add credits to players account
						player.addCredits(transfer_count * price)
	
						# clean up if necessary
						quantity = self.imports[self.current_item][1]
						if quantity <= 0:
							self.imports.pop(self.current_item)
							if self.current_item >= len(self.imports):
								self.current_item = 0

				except:
					pass
				self.draw()
    def __init__(
        self, room_start, room_exit_to, enable_missions, enable_finances, enable_manifest, enable_load, enable_save
    ):
        # Quine computer is made up of several "rooms" aka screens
        # the room_start show the user's location
        # this is made a lot more complex because of the need to update the cargo manifest
        guiroom = GUI.GUIRoom(room_start)
        self.guiroom = guiroom

        # when a button is clicked, this will allow us to get the QuineComputer instance from the x_click functions
        guiroom.owner = self

        # add background sprite; no need to keep a variable around for this, as it doesn't change
        GUI.GUIStaticImage(
            guiroom, "background", ("interfaces/quine/main.spr", GUI.GUIRect(0, 0, 1, 1, "normalized"))
        ).draw()

        # add buttons
        self.buttons = {}
        self.mode = ""
        self.saveGameNameEntryBox = None

        # in the following,
        #   coordinates are given in a GUI.GUIRect(left,right,width,height, "pixel", (screen_W, screen_H)
        #      where left/right/width/height are in pixels, assuming the screen is at resolution screen_W, screen_H
        #      (if not, proper conversions will be applied)
        #
        #   hot_loc is the clickable area
        #   spr_loc is where the sprite image goes
        #   spr specifies (<sprite file>, spr_loc) - the second item is where the image in <sprite_file> goes
        #   spr_disabled is as spr, but when the button is disabled
        #   sprites is a mapping from state to a 'spr'-like tuple (image and location), that is
        #      the state-appearance mapping.
        #
        #   Most buttons in the following screen have been already painted as part of the background, so
        #   button classes that will be created next only specify an image for a "down" and "disabled"
        #   state, and specifying None (no sprite) for "enabled" (not pressed) state so that only
        #   the background is visible.
        #
        #   Buttons are ultimately created with the GUI.GUIButton class, which takes a room where
        #   the button belongs, a label (the 'XXX' prefix makes the label invisible), a unique id
        #   so that reactive code can identify it (ie: btn_finances), the 'sprites' state-appearance
        #   mapping, and the clickable area.
        #
        #   Later the self.add_button function will provide the button with a custom click callback
        #   that will be called when the button is clicked

        if enable_finances:
            hot_loc = GUI.GUIRect(545, 287, 105, 60, "pixel", (800, 600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/fin_pressed.spr", spr_loc)
            spr_disabled = ("interfaces/quine/fin_disabled.spr", spr_loc)
            sprites = {"enabled": None, "disabled": spr_disabled, "down": spr}
            self.add_button(GUI.GUIButton(guiroom, "XXXFinances", "btn_finances", sprites, hot_loc), change_text_click)
        if enable_manifest:
            hot_loc = GUI.GUIRect(644, 285, 96, 64, "pixel", (800, 600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/man_pressed.spr", spr_loc)
            spr_disabled = ("interfaces/quine/man_disabled.spr", spr_loc)
            sprites = {"enabled": None, "disabled": spr_disabled, "down": spr}
            self.add_button(GUI.GUIButton(guiroom, "XXXManifest", "btn_manifest", sprites, hot_loc), change_text_click)
        if enable_load:
            hot_loc = GUI.GUIRect(635, 173, 97, 55, "pixel", (800, 600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/load_pressed.spr", spr_loc)
            spr_disabled = ("interfaces/quine/load_disabled.spr", spr_loc)
            sprites = {"enabled": None, "disabled": spr_disabled, "down": spr}
            self.add_button(GUI.GUIButton(guiroom, "XXXLoad", "btn_load", sprites, hot_loc), change_text_click)
        if enable_save:
            hot_loc = GUI.GUIRect(541, 173, 97, 55, "pixel", (800, 600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/save_pressed.spr", spr_loc)
            spr_disabled = ("interfaces/quine/save_disabled.spr", spr_loc)
            spr_warning = None
            if (not VS.getPlayer()) or (VS.getPlayer().hasCargo("jump_drive") == 0 and not weapons_lib.CanRepair()):
                spr_warning = ("interfaces/quine/save_warning.spr", spr_loc)
            sprites = {"enabled": spr_warning, "disabled": spr_disabled, "down": spr}
            self.add_button(GUI.GUIButton(guiroom, "XXXSave", "btn_save", sprites, hot_loc), change_text_click)
        if enable_missions:
            hot_loc = GUI.GUIRect(540, 227, 200, 60, "pixel", (800, 600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/missions_pressed.spr", spr_loc)
            spr_disabled = ("interfaces/quine/missions_disabled.spr", spr_loc)
            sprites = {"enabled": None, "disabled": spr_disabled, "down": spr}
            self.add_button(GUI.GUIButton(guiroom, "XXXMissions", "btn_missions", sprites, hot_loc), change_text_click)

        if enable_load or enable_save:
            hot_loc = [
                GUI.GUIRect(621, 349, 55, 69, "pixel", (800, 600)),
                GUI.GUIRect(621, 413, 55, 69, "pixel", (800, 600)),
                GUI.GUIRect(553, 389, 73, 56, "pixel", (800, 600)),
                GUI.GUIRect(675, 389, 73, 56, "pixel", (800, 600)),
            ]
            spr_loc = hot_loc
            spr = [
                ("interfaces/quine/up_pressed.spr", spr_loc[0]),
                ("interfaces/quine/down_pressed.spr", spr_loc[1]),
                ("interfaces/quine/left_pressed.spr", spr_loc[2]),
                ("interfaces/quine/right_pressed.spr", spr_loc[3]),
            ]
            spr_disabled = [
                ("interfaces/quine/up_disabled.spr", spr_loc[0]),
                ("interfaces/quine/down_disabled.spr", spr_loc[1]),
                ("interfaces/quine/left_disabled.spr", spr_loc[2]),
                ("interfaces/quine/right_disabled.spr", spr_loc[3]),
            ]
            sprites = [
                {"enabled": None, "disabled": spr_disabled[0], "down": spr[0]},
                {"enabled": None, "disabled": spr_disabled[1], "down": spr[1]},
                {"enabled": None, "disabled": spr_disabled[2], "down": spr[2]},
                {"enabled": None, "disabled": spr_disabled[3], "down": spr[3]},
            ]
            self.add_button(GUI.GUIButton(guiroom, "XXXUp", "btn_up", sprites[0], hot_loc[0]), scroll_click)
            self.add_button(GUI.GUIButton(guiroom, "XXXDown", "btn_down", sprites[1], hot_loc[1]), scroll_click)
            self.add_button(GUI.GUIButton(guiroom, "XXXLeft", "btn_left", sprites[2], hot_loc[2]), scroll_click)
            self.add_button(GUI.GUIButton(guiroom, "XXXRight", "btn_right", sprites[3], hot_loc[3]), scroll_click)

            # this doesn't change while docked, so only call it once
        current_base = universe.getDockedBase()
        self.str_start = get_location_text(current_base)

        screen_loc = GUI.GUIRect(80, 90, 350, 380, "pixel", (800, 600))
        screen_color = GUI.GUIColor(20 / 255.0, 22 / 255.0, 10 / 255.0)
        self.screen_color = screen_color
        self.screen_loc = screen_loc

        # first I tried rgb(56 60 24) and rgb(40 44 20); both were too light
        # screen_bgcolor = GUI.GUIColor.clear()
        screen_bgcolor_nc = GUI.GUIColor(0.44, 0.47, 0.17)  # roughly equal to rgb(111, 119, 43)
        screen_bgcolor = screen_bgcolor_nc
        self.screen_bgcolor = screen_bgcolor

        # text screen
        self.txt_screen = GUI.GUIStaticText(
            guiroom, "txt_screen", self.str_start, screen_loc, color=screen_color, bgcolor=GUI.GUIColor.clear()
        )
        self.txt_screen.show()  # display start text

        # picker screen
        self.picker_screen = GUI.GUISimpleListPicker(
            guiroom,
            "XXXSelect item",
            "picker_screen",
            screen_loc,
            textcolor=screen_color,
            textbgcolor=GUI.GUIColor.clear(),
            selectedcolor=screen_bgcolor_nc,
            selectedbgcolor=screen_color,
            hotcolor=screen_bgcolor_nc,
            hotbgcolor=GUI.GUIColor(40 / 255.0, 44 / 255.0, 20 / 255.0),
        )
        self.picker_screen.hide()

        #
        # much of this is temporary, until something better can be worked out:
        #

        # Save/Load screen
        # if enable_save:
        # 	x, y, w, h = GUI.GUIRect(217, 56, 40, 18).getHotRect()
        # 	Base.Comp (room_start, 'save_comp', x, y, w, h, 'XXXSave/Load/Quit', 'LoadSave')
        # if enable_load:
        # 	x, y, w, h = GUI.GUIRect(257, 56, 39, 18).getHotRect()
        # 	Base.Comp (room_start, 'load_comp', x, y, w, h, 'XXXSave/Load/Quit', 'LoadSave')

        # Missions
        # if enable_missions:
        # 	x, y, w, h = GUI.GUIRect(217, 75, 79, 18).getHotRect()
        # 	Base.Comp (room_start, 'missions', x, y, w, h, 'XXXMissions', 'Missions Info Cargo ')

        # Finances
        # if enable_finances:
        # 	x, y, w, h = GUI.GUIRect(219, 94, 40, 18).getHotRect()
        # 	Base.Comp (room_start, 'missions', x, y, w, h, 'Finances', 'Info ')

        # Manifest
        # if enable_manifest:
        # 	x, y, w, h = GUI.GUIRect(260, 94, 40, 18).getHotRect()
        # 	Base.Comp (room_start, 'missions', x, y, w, h, 'Manifest', 'Cargo ')

        # Exit button, returns us to concourse
        self.room_id = room_start
        self.exit_room_id = room_exit_to
        self.setExitLinkState(True)
예제 #13
0
    def __init__(self, room_start, room_exit_to, enable_missions, enable_finances, enable_manifest, enable_load, enable_save):
        # Quine computer is made up of several "rooms" aka screens
        # the room_start show the user's location
        # this is made a lot more complex because of the need to update the cargo manifest
        guiroom = GUI.GUIRoom(room_start)
        self.guiroom = guiroom

        # when a button is clicked, this will allow us to get the QuineComputer instance from the x_click functions
        guiroom.owner = self

        # add background sprite; no need to keep a variable around for this, as it doesn't change
        GUI.GUIStaticImage(guiroom, 'background', ( 'interfaces/quine/main.spr' , GUI.GUIRect(0, 0, 1, 1, "normalized") )).draw()

        # add buttons
        self.buttons = {}
        self.mode = ''

        if enable_finances:
            hot_loc = GUI.GUIRect(545, 287, 105, 60, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/fin_pressed.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':None, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXFinances','btn_finances', sprites, hot_loc), change_text_click )
        if enable_manifest:
            hot_loc = GUI.GUIRect(644, 285, 96, 64, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/man_pressed.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':None, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXManifest','btn_manifest', sprites, hot_loc), change_text_click )
        if enable_load:
            hot_loc = GUI.GUIRect(610, 185, 97, 55, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/load_pressed.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':None, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXLoad'    ,'btn_load'    , sprites, hot_loc), change_text_click )
        if enable_save:
            hot_loc = GUI.GUIRect(541, 173, 97, 55, "pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/save_pressed.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':None, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXSave'    ,'btn_save'    , sprites, hot_loc), change_text_click )
        if enable_missions:
            hot_loc = GUI.GUIRect(540, 227, 200, 60,"pixel", (800,600))
            spr_loc = hot_loc
            spr = ("interfaces/quine/missions_pressed.spr",spr_loc)
            sprites = { 'enabled':None, 'disabled':None, 'down':spr }
            self.add_button( GUI.GUIButton(guiroom,'XXXMissions','btn_missions', sprites, hot_loc), change_text_click )

        if enable_load or enable_save:
            hot_loc = [ GUI.GUIRect(624, 346, 55, 69, "pixel", (800,600)),
                                    GUI.GUIRect(624, 412, 55, 69, "pixel", (800,600)),
                                    GUI.GUIRect(553, 389, 73, 56, "pixel", (800,600)),
                                    GUI.GUIRect(675, 389, 73, 56, "pixel", (800,600)) ]
            spr_loc = hot_loc
            spr = [ ("interfaces/quine/up_pressed.spr"   ,spr_loc[0]),
                            ("interfaces/quine/down_pressed.spr" ,spr_loc[1]),
                            ("interfaces/quine/left_pressed.spr" ,spr_loc[2]),
                            ("interfaces/quine/right_pressed.spr",spr_loc[3]) ]
            sprites = [ { 'enabled':None, 'disabled':None, 'down':spr[0] },
                                    { 'enabled':None, 'disabled':None, 'down':spr[1] },
                                    { 'enabled':None, 'disabled':None, 'down':spr[2] },
                                    { 'enabled':None, 'disabled':None, 'down':spr[3] } ]
            self.add_button( GUI.GUIButton(guiroom,'XXXUp'   ,'btn_up'   , sprites[0], hot_loc[0]), scroll_click )
            self.add_button( GUI.GUIButton(guiroom,'XXXDown' ,'btn_down' , sprites[1], hot_loc[1]), scroll_click )
#                       self.add_button( GUI.GUIButton(guiroom,'XXXLeft' ,'btn_left' , sprites[2], hot_loc[2]), scroll_click )
#                       self.add_button( GUI.GUIButton(guiroom,'XXXRight','btn_right', sprites[3], hot_loc[3]), scroll_click )

        current_base = universe.getDockedBase()
        player = VS.getPlayer()

        # this doesn't change while docked, so only call it once
        self.str_start = get_location_text(current_base)

        screen_loc = GUI.GUIRect(80,90,350,380,"pixel",(800,600))
        screen_color = GUI.GUIColor(20/255.0, 22/255.0 ,10/255.0)               # first I tried rgb(56 60 24) and rgb(40 44 20); both were too light
        screen_bgcolor = GUI.GUIColor.clear()
        screen_bgcolor_nc = GUI.GUIColor(0.44,0.47,0.17)

        # text screen
        self.txt_screen = GUI.GUIStaticText(guiroom, 'txt_screen', self.str_start, screen_loc,
                color=screen_color,
                bgcolor=screen_bgcolor)
        self.txt_screen.hide()

        # picker screen
        self.picker_screen = GUI.GUISimpleListPicker(guiroom,'XXXSelect item','picker_screen', screen_loc,
                textcolor    =screen_color     , textbgcolor    =screen_bgcolor,
                selectedcolor=screen_bgcolor_nc, selectedbgcolor=screen_color   )
        self.picker_screen.hide()

        #
        # much of this is temporary, until something better can be worked out:
        #

        # Save/Load screen
        #if enable_save:
        #       x, y, w, h = GUI.GUIRect(217, 56, 40, 18).getHotRect()
        #       Base.Comp (room_start, 'save_comp', x, y, w, h, 'XXXSave/Load/Quit', 'LoadSave')
        #if enable_load:
        #       x, y, w, h = GUI.GUIRect(257, 56, 39, 18).getHotRect()
        #       Base.Comp (room_start, 'load_comp', x, y, w, h, 'XXXSave/Load/Quit', 'LoadSave')

        # Missions
        #if enable_missions:
        #       x, y, w, h = GUI.GUIRect(217, 75, 79, 18).getHotRect()
        #       Base.Comp (room_start, 'missions', x, y, w, h, 'XXXMissions', 'Missions Info Cargo ')

        # Finances
        #if enable_finances:
        #       x, y, w, h = GUI.GUIRect(219, 94, 40, 18).getHotRect()
        #       Base.Comp (room_start, 'missions', x, y, w, h, 'Finances', 'Info ')

        # Manifest
        #if enable_manifest:
        #       x, y, w, h = GUI.GUIRect(260, 94, 40, 18).getHotRect()
        #       Base.Comp (room_start, 'missions', x, y, w, h, 'Manifest', 'Cargo ')


        # Exit button, returns us to concourse
        rect = GUI.GUIRect(227, 165, 35, 14, "pixel", (320,200))
        x, y, w, h = rect.getHotRect()
#               Base.Link (room_start, 'exit', x, y, w, h, 'Exit', room_exit_to)
        Base.LinkPython (room_start, 'exit', "#\nimport GUI\nGUI.GUIRootSingleton.getRoomById(%r).owner.reset()\n" %(guiroom.getIndex()), x, y, w, h, 'XXXExit', room_exit_to)