def init_handlers(config_str, search_dir): handlers = split(get_option_dict()[HANDLERS]) for handler in handlers: module = os.path.basename(handler)[:-3] # There is 3 way to specify path: # - absolute path to module # - single name, then module should be in same directory as config # - relative path, then use python as base path. if os.path.exists(handler): module_path = os.path.dirname(handler) elif not os.path.dirname(handler): module_path = os.path.dirname(config_str) else: module_path = os.path.join(search_dir, '..', os.path.dirname(handler)) sys.path.insert(0, module_path) try: __import__(module) except Exception as e: for p in sys.path: print p print >> sys.stderr, "Fail to import handler %s with error %s" % ( handler, e) print_exc() exit(1) register_pre_handler('generateOrders', charting_text)
def init_handlers(config_str, search_dir): handlers = split(get_option_dict()[HANDLERS]) for handler in handlers: module = os.path.basename(handler)[:-3] # There is 3 way to specify path: # - absolute path to module # - single name, then module should be in same directory as config # - relative path, then use python as base path. if os.path.exists(handler): module_path = os.path.dirname(handler) elif not os.path.dirname(handler): module_path = os.path.dirname(config_str) else: module_path = os.path.join(search_dir, '..', os.path.dirname(handler)) sys.path.insert(0, module_path) try: __import__(module) except Exception as e: for p in sys.path: print p print >> sys.stderr, "Fail to import handler %s with error %s" % (handler, e) print_exc() exit(1) register_pre_handler('generateOrders', charting_text)
from empire.growth_specials import set_growth_special from empire.pilot_rating import set_pilot_rating_for_planet from empire.ship_builders import get_ship_builder_locations, set_ship_builders from empire.survey_lock import survey_universe_lock from EnumsAI import FocusType from freeorion_tools import get_partial_visibility_turn, get_species_tag_grade from freeorion_tools.timers import AITimer from turn_state import ( get_empire_planets_by_species, get_owned_planets, set_have_asteroids, set_have_gas_giant, set_have_nest, ) register_pre_handler("generateOrders", survey_universe_lock.lock) survey_timer = AITimer("empire.surver_universe()") def survey_universe(): survey_timer.start("Categorizing Visible Planets") universe = fo.getUniverse() empire_id = fo.empireID() current_turn = fo.currentTurn() # set up / reset various variables; the 'if' is purely for code folding convenience if True: AIstate.empireStars.clear() empire_metabolisms.clear() active_growth_specials.clear()
fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptPeaceProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building) ], classes_to_ignore=( 'IntSet', 'StringSet', 'IntIntMap', 'ShipSlotVec', 'VisibilityIntMap', 'IntDblMap', 'IntBoolMap', 'ItemSpecVec', 'PairIntInt_IntMap', 'IntSetSet', 'StringVec', 'IntPairVec', 'IntFltMap', 'MeterTypeStringPair', 'MeterTypeMeterMap', 'universeObject', # this item cannot be get from generate orders 'diplomaticStatusUpdate', ), path='AI' ) exit(1) # exit game to main menu no need to play anymore. register_pre_handler('generateOrders', inspect_ai_interface)