示例#1
0
def BuyShip(shipname):
    """ Return whether the player could buy shipname.blank.

        Sell or don't sell the current ship according to the above
        and play the accompanying speech.

    """
    name = VS.getPlayer().getName()
    value = CargoValue(VS.getPlayer()) + ShipValue(name, used=True)
    oldcargo = []
    oldun = VS.getPlayer()
    for i in range(oldun.numCargo()):
        c = oldun.GetCargoIndex(i)
        if c.GetCategory().find("upgrades") != 0:
            oldcargo.append(c)
    debug.debug("value: %.1f" % (value))
    debug.debug("player credits before purchase: %.1f" %
                (VS.getPlayer().getCredits()))
    success = Base.BuyShip(shipname, False, True)
    if success:
        VS.getPlayer().addCredits(value)
        Base.SellShip(name)
        debug.debug("player credits after selling current ship: %.1f" %
                    (VS.getPlayer().getCredits()))
        #VS.getPlayer().addCredits(-ShipValue(shipname,False))
        #print VS.getPlayer().getCredits()
        #for carg in oldcargo:
        #   VS.getPlayer().addCargo(carg)
        where = shipname.find(".blank")
        if (where != -1):
            shipname = shipname[0:where]
        VS.playSound('sales/pitch' + shipname + 'accept.wav', (0, 0, 0),
                     (0, 0, 0))
        return True
    else:
        where = shipname.find(".blank")
        if (where != -1):
            shipname = shipname[0:where]
        VS.playSound("sales/pitch" + shipname + "duplicate.wav", (0, 0, 0),
                     (0, 0, 0))
        return False