Example #1
0
def resources_reception_and_construction():
    logger.debug("### Resources reception and construction")
    waited_constructs = {}
    empire = Factory().empire

    for fleet in empire.missions.arrived:
        if not fleet.travel_id in empire.waiting_for:
            continue  # no one cares about this fleet
        planet = empire.cond(key=fleet.dst).first
        assert planet, "no planet at %s" % fleet.dst
        if not planet.idle:  # construction has began
            continue
        if not fleet.dst in waited_constructs:
            waited_constructs[fleet.dst] = []
        # we list the constructions fleets have delivered resources for
        logger.info("A fleet has arrived on %s to construct %s", planet, planet.waiting_for[fleet.travel_id])
        waited_constructs[planet.key].append(planet.waiting_for[fleet.travel_id])

    for planet in empire:
        if not planet.key in waited_constructs:
            continue
        for construct in set(waited_constructs[planet.key]):
            # we count how many constructions resources
            # have been delivered for on this planet
            waited_constr = waited_constructs[planet.key].count(construct)
            # we count how many of this construction are waiting on this planet
            waited_travel = planet.waiting_for.values().count(construct)
            if waited_constr == waited_travel:
                logger.warn("All fleet arrived to construct %s on %s, " "launching construction.", construct, planet)
                Factory().interface.construct(construct, planet)
                for travel_id, c in planet.waiting_for.items():
                    if c == construct:
                        del planet.waiting_for[travel_id]
Example #2
0
def check_neighborhood(area=[0, 20], mission=BOTH, planet=None):
    interface = Factory().interface
    if planet is None:
        planet = Factory().empire.capital
    galaxy, system_origin, position = planet.coords

    for distance in range(*area):
        for factor in (1, -1):
            system = system_origin + distance * factor
            if not 0 <= system <= 500:
                continue
            for row in interface.browse_galaxy(galaxy, system, planet):
                if mission in (SPY, BOTH) and row.inactive \
                        and not (row.vacation or row.noob):
                    spy(planet, row.coords)
                if mission in (RECYCLE, BOTH) \
                        and row.debris_content.total > 20000:
                    recycle(planet, row.coords, row.debris_content)