Example #1
0
def count_stuff(v, data):
    nbr_men = int(0)
    enemy_found = False
    ships_found = False
    seen_here_list = []
    level = 0
    k = u.return_unitid(v)
    seen_here_list = loop_here(data, k, False, True)
    list_length = len(seen_here_list)
    if list_length >= 1:
        for un in seen_here_list:
            unit = data[un]
            if 'char' in u.return_kind(unit):
                if 'il' in unit:
                    item_list = unit['il']
                    if len(item_list) > 0:
                        for itemz in range(0, len(item_list), 2):
                            itemz_rec = data[item_list[itemz]]
                            if 'IT' in itemz_rec and 'pr' in itemz_rec['IT']:
                                if itemz_rec['IT']['pr'][0] == '1':
                                    if 'an' in itemz_rec['IT']:
                                        if itemz_rec['IT']['an'][0] != '1':
                                            nbr_men = nbr_men + int(
                                                item_list[itemz + 1])
                                    else:
                                        nbr_men = nbr_men + int(
                                            item_list[itemz + 1])
                if 'CH' in unit:
                    if 'lo' in unit['CH'] and unit['CH']['lo'][0] == '100':
                        enemy_found = True
            elif u.return_kind(unit) == 'ship':
                ships_found = True
    return nbr_men, enemy_found, ships_found
Example #2
0
def calc_ship_pct_loaded(data, k, v):
    total_weight = 0
    try:
        damaged = int(v['SL']['da'][0])
    except KeyError:
        damaged = 0
    level = 0
    seen_here_list = loop_here(data, k, False, True)
    list_length = len(seen_here_list)
    if list_length > 1:
        for un in seen_here_list:
            char = data[un]
            if return_kind(char) == 'char':
                unit_type = '10'
                if 'CH' in char and 'ni' in char['CH']:
                    unit_type = char['CH']['ni'][0]
                base_unit = data[unit_type]
                if 'IT' in base_unit and 'wt' in base_unit['IT']:
                    item_weight = int(base_unit['IT']['wt'][0]) * 1
                    total_weight = total_weight + item_weight
                if 'il' in char:
                    item_list = char['il']
                    for itm in range(0, len(item_list), 2):
                        itemz = data[item_list[itm]]
                        try:
                            item_weight = int(itemz['IT']['wt'][0])
                        except KeyError:
                            item_weight = int(0)
                        qty = int(item_list[itm + 1])
                        total_weight = total_weight + int(qty * item_weight)
    ship_capacity = int(v['SL']['ca'][0])
    actual_capacity = int(ship_capacity - ((ship_capacity * damaged) / 100))
    pct_loaded = math.floor((total_weight * 100) / actual_capacity)
    return pct_loaded
Example #3
0
def build_non_prominent_items_dict(k, v, data):
    npi_list = []
    seen_here_list = loop_here(data, k, False, True)
    list_length = len(seen_here_list)
    if list_length > 1:
        for un in seen_here_list:
            unit_rec = data[un]
            if 'il' in unit_rec:
                item_list = unit_rec['il']
                for items in range(0, len(item_list), 2):
                    item_rec = data[item_list[items]]
                    if 'IT' in item_rec and 'pr' in item_rec[
                            'IT'] and item_rec['IT']['pr'][0] == '1':
                        pass
                    else:
                        if int(item_list[items + 1]) > 0:
                            weight = 0
                            qty = int(item_list[items + 1])
                            if 'wt' in item_rec['IT']:
                                weight = int(item_rec['IT']['wt'][0])
                            total_weight = int(qty * weight)
                            if total_weight > 0:
                                npi_entry = {
                                    'possessor_oid': to_oid(un),
                                    'possessor_name': unit_rec['na'][0],
                                    'item_oid': to_oid(item_list[items]),
                                    'item_name': item_rec['na'][0],
                                    'qty': qty,
                                    'weight': total_weight
                                }
                                npi_list.append(npi_entry)
    return npi_list
Example #4
0
def test_loop_here():
    data = {
        '1001': {
            'firstline': ['1001 loc forest'],
            'LI': {
                'hl': ['1002', '1003', '1006']
            }
        },
        '1002': {
            'firstline': ['1002 char 0'],
            'LI': {
                'hl': ['1004']
            }
        },
        '1003': {
            'firstline': ['1003 loc tower'],
            'LI': {
                'hl': ['1005']
            }
        },
        '1004': {
            'firstline': ['1004 char 0']
        },
        '1005': {
            'firstline': ['1005 char 0']
        },
        '1006': {
            'firstline': ['1006 loc city'],
            'LI': {
                'hl': ['1007']
            }
        },
        '1007': {
            'firstline': ['1007 char 0']
        }
    }
    assert loop_here(data, '1001') == ['1002', '1004', '1003', '1005', '1006']
    assert loop_here(data, '1001', fog=True) == ['1003', '1005', '1006']
    assert loop_here(data, '1001', into_city=True) == [
        '1002', '1004', '1003', '1005', '1006', '1007'
    ]
    assert loop_here(data, '1003') == ['1005']

    if loop_here(data, '1003', fog=True) == ['1005']:
        pytest.xfail('have not implemented non-province fog yet')
Example #5
0
def write_ship_non_prominent(v, k, data, outf):
    seen_here_list = loop_here(data, k, False, True)
    list_length = len(seen_here_list)
    if list_length > 1:
        first_time = True
        printed_items = False
        for un in seen_here_list:
            unit_rec = data[un]
            if 'il' in unit_rec:
                item_list = unit_rec['il']
                for items in range(0, len(item_list), 2):
                    item_rec = data[item_list[items]]
                    if 'IT' in item_rec and 'pr' in item_rec[
                            'IT'] and item_rec['IT']['pr'][0] == '1':
                        pass
                    else:
                        if int(item_list[items + 1]) > 0:
                            weight = 0
                            qty = int(item_list[items + 1])
                            if 'wt' in item_rec['IT']:
                                weight = int(item_rec['IT']['wt'][0])
                            total_weight = int(qty * weight)
                            if first_time and total_weight > 0:
                                outf.write(
                                    '<p>Non-Prominent Items Onboard:</p>\n')
                                outf.write(
                                    '<table border="1" cellpadding="5">\n')
                                outf.write(
                                    '<tr><th>Possessor</th><th>Item</th><th>Qty</th><th>Weight</th></tr>'
                                )
                                first_time = False
                            if total_weight > 0:
                                printed_items = True
                                outf.write('<tr>')
                                outf.write('<td>{} [{}]</td>'.format(
                                    unit_rec['na'][0], anchor(to_oid(un))))
                                outf.write('<td>{} [{}]</td>'.format(
                                    item_rec['na'][0],
                                    anchor(to_oid(item_list[items]))))
                                outf.write(
                                    f'<td style="text-align:right">{qty:,d}</td>'
                                )
                                outf.write(
                                    f'<td style="text-align:right">{total_weight:,d}</td>'
                                )
                                outf.write('</tr>\n')
        if printed_items:
            outf.write('</table>\n')