Example #1
0
def buy_ship(idx):
    """ FIXME replace current ship by new one """
    new_ship = captain.location.shipyard[idx]
    old_ship = captain.ship
    # transfert fuel (only if new.reservoir >= old.reservoir)
    if old_ship.reservoir <= new_ship.reservoir:
        new_ship.reservoir = old_ship.reservoir
    # transfert cargo
    for index in range(old_ship.model['cargo']):
        if old_ship.cargo[index]['type'] is not None:
            new_ship.cargo[index]['type'] = old_ship.cargo[index]['type']
            new_ship.cargo[index]['value'] = old_ship.cargo[index]['value']
    # transfert gadget
    new_ship.gadget = old_ship.gadget
    # TODO transfert crew(s)

    invoice = core.Transaction('-', new_ship.model['model'],
                               new_ship.model['price'], 1)
    captain.ship = new_ship
    captain.location.shipyard[idx] = old_ship
    captain.account.cash -= invoice.total_value
    captain.account.log.append(invoice)
    update_cargo_board()
    update_docks_board(captain.location)
    update_bank()
    update_captain_ship()
    update_shipyard(captain.location)
Example #2
0
def sell_cargo(pods, dump=False):
    """ sell (or dump) good from list of pods """

    # pprint(pods)
    ordlist = sorted(pods, key=lambda x: x[1])  # sort on good_type
    for key, value in groupby(
            ordlist,
            lambda x: [x[1], x[2]]):  # sort on [good_type, good_value]
        idx = []
        valeurs = list(value)
        for items in valeurs:
            idx.append(items[0])
        good_type = key[0]
        good_price = captain.location.price_slip[good_type][0]
        qty = len(idx)
        facture = core.Transaction('+', good_type, good_price, qty)
        if not dump:
            captain.account.log.append(facture)
            captain.account.cash += facture.total_value

        captain.location.price_slip[good_type][2] += qty
        for index in idx:
            captain.ship.unload_cargo(index)

    update_gui()
Example #3
0
    def _generate_tx(self, **kw):
        """
		Generate a transaction with wallet key(s)
		"""
        tx = core.Transaction(**kw)
        object.__setattr__(tx, "key_one", self.K1)
        object.__setattr__(tx, "address", core.getAddress(self.K1))
        if hasattr(self, "K2"):
            object.__setattr__(tx, "key_two", self.K2)
        return tx
Example #4
0
def sell_cargo(pods):
    """ FIXME use Transaction() """

    # ça marche pour transaction, mais il manque les indices des pods
    # pour les vidanger...

    a = sorted(pods)
    for key, value in groupby(a, lambda x: [x[1], x[2]]):
        print(key[0], key[1], value)
        # print(len(list(value)), key)
        captain.account.log.append(
            core.Transaction(key[0], key[1], len(list(value))))
Example #5
0
def sell_cargo(pods):
    """ use Transaction() """

    # avec une transaction, et les indices des pods
    # pour les vidanger...
    # /!\ groupby est un générateur -> purge à l'appel

    a = sorted(pods, key=lambda x: x[1])  # tri sur good_type
    for key, value in groupby(a, lambda x: [x[1], x[2]]):  # tri sur good_type, good_value
        idx = []
        valeurs = list(value)
        pprint(valeurs)
        for items in valeurs:
            idx.append(items[0])
        print(f'key: {key[0]}, {key[1]}, {list(valeurs)}')
        print(f'len: {len(list(valeurs))}')
        print(f'idx: {idx}')
        captain.account.log.append(core.Transaction(key[0], key[1], len(list(valeurs))))
Example #6
0
def update_invoice(good_type, qty):
    """ calculate the invoice, update the relevant GUI elements

    return a core.Transaction() object
    """
    good_price = captain.location.price_slip[good_type][1]
    invoice = core.Transaction('-', good_type, good_price, qty)
    cargo_value = invoice.total_value

    if cargo_value > captain.account.cash:
        window['-IN-INVOICE-'].update(value=f'{cargo_value:.2f}',
                                      text_color='red')
        window['-BUY-CARGO-'].update(disabled=True)
    else:
        window['-IN-INVOICE-'].update(value=f'{cargo_value:.2f}',
                                      text_color='black')
        window['-BUY-CARGO-'].update(disabled=False)

    # print(f'{invoice}')
    return invoice
Example #7
0
def refuel():
    """ refuel the captain.ship according to captain.account.cash,
    captain.ship.reservoir and planete.fuel_price
    """
    capacity = int(captain.ship.model['efficiency'] * MAXP)
    quantity = captain.location.price_slip['fuel'][2]
    fuel_price = captain.location.price_slip['fuel'][1]
    reserve = captain.ship.reservoir

    if reserve < capacity:
        fuel_deficit = capacity - reserve

        if fuel_deficit > quantity:
            fuel_deficit = quantity

        fuel_invoice = core.Transaction('-', 'fuel', fuel_price, fuel_deficit)

        if fuel_invoice.total_value <= captain.account.cash:
            captain.account.cash -= fuel_invoice.total_value
            captain.ship.reservoir = reserve + fuel_deficit
            captain.account.log.append(fuel_invoice)
            captain.location.price_slip['fuel'][2] -= fuel_deficit
            draw_limite(captain.location, captain.ship.reservoir)
            update_trading(window['-LOC-TABLE-'], captain.location)
            update_affiche(captain)
            update_cargo_board()
            update_planet_selector()
            update_bank()
            window['-REFUEL-'].update(disabled=True)

        else:
            # FIXME/TODO: how much can I buy?
            # and buy only that much or else 'not enought Cr'
            sg.popup(f'Cannot buy fuel: not enought credit')
    else:
        sg.popup(f'Cannot buy fuel: full capacity')
Example #8
0
        pprint(valeurs)
        for items in valeurs:
            idx.append(items[0])
        print(f'key: {key[0]}, {key[1]}, {list(valeurs)}')
        print(f'len: {len(list(valeurs))}')
        print(f'idx: {idx}')
        captain.account.log.append(core.Transaction(key[0], key[1], len(list(valeurs))))


if __name__ == '__main__':
    """ """
    captain = core.Captain()
    captain.ship = core.Ship()
    captain.account = core.BankAccount(captain.name, [])

    invoice = core.Transaction('fuel', 13.00, 2.00)
    inv2 = core.Transaction('fur', 7.00, 3)

    captain.account.log.append(invoice)
    captain.account.log.append(inv2)

    total = []
    for item in captain.account.log:
        total.append(item.total_value)
        print(item.total_value)

    print(f'Total: {sum(total)}')

    # print(list(convert(PODS)))

    sell_cargo(PODS2)