def focus_on_entity(entity, target_id, show_line=False, pause=False): global HAS_FOCUS, PAUSE if HAS_FOCUS or '--no-fx' in sys.argv: return HAS_FOCUS = target_id PAUSE = pause _entity = ui_dialog.create(18, 7, 'Enemy spotted!') entities.register_event(_entity, 'delete', lambda e: lose_focus()) entities.trigger_event(DIRECTOR, 'create_timer', time=120, exit_callback=lambda e: ui_dialog.delete(_entity)) if show_line: for x, y in shapes.line(movement.get_position(entity), movement.get_position_via_id(target_id)): effects.vapor(x, y, group='effects_freetick', start_alpha=1.0, fade_rate=.01)
def message(text, fore_color=(255, 255, 255), back_color=(10, 10, 10), time=-1, center=False, vert_center=False): global MESSAGES_ACTIVE _entity = entities.create_entity(group='ui_effects_freetick') if time == -1: _time = 30 * constants.SHOW_MESSAGES_FOR else: _time = time timers.register(_entity, use_system_event='draw') flags.register(_entity) entities.create_event(_entity, 'draw') entities.register_event(_entity, 'draw', _message_draw) entities.register_event(_entity, 'delete', _message_delete) entities.trigger_event(_entity, 'create_timer', time=_time, exit_callback=entities.delete_entity) entities.trigger_event(_entity, 'set_flag', flag='text', value=text) entities.trigger_event(_entity, 'set_flag', flag='index', value=MESSAGES_ACTIVE) entities.trigger_event(_entity, 'set_flag', flag='center', value=center) entities.trigger_event(_entity, 'set_flag', flag='vert_center', value=vert_center) MESSAGES_ACTIVE += 1 return _entity
def register_human(entity, player=False): _register(entity, player=player) _ai = entity["ai"] # Healing _ai["brain"].add_planner(brains.heal()) # Combat _ai["brain"].add_planner(brains.combat()) # Regrouping # NOTE: Not sure what I want this functionality to do # Maybe once squads have evolved a bit more I will approach # it again. # _ai['brain'].add_planner(brains.squad_leader_regroup()) # Panic # _ai['brain'].add_planner(brains.panic()) # Food # _ai['brain'].add_planner(brains.food()) # Search # _ai['brain'].add_planner(brains.search_for_weapon()) # _ai['brain'].add_planner(brains.search_for_ammo()) # _ai['brain'].add_planner(brains.search_for_container()) _ai["brain"].add_planner(brains.search_for_target()) # Reload _ai["brain"].add_planner(brains.reload()) entities.register_event(entity, "logic", _human_logic) entities.register_event(entity, "logic_offline", _human_logic_offline)
def fire(x, y, amount): _blood = _create(x, y) _x, _y = (int(round(x)), int(round(y))) flags.register(_blood) timers.register(_blood) entities.trigger_event(_blood, 'set_flag', flag='alpha', value=amount) entities.trigger_event(_blood, 'set_flag', flag='alpha_max', value=amount) entities.trigger_event(_blood, 'set_char', char=' ') _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], random.choice([constants.FIRE_1, constants.FIRE_2, constants.FIRE_3]), amount) _color[1] = numbers.interp_velocity(_color[1], random.choice([constants.FIRE_1, constants.FIRE_2, constants.FIRE_3]), amount) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) #display._set_char('tiles', _x, _y, random.choice([',', '.', '^']), _color[0], _color[1]) entities.register_event(_blood, 'tick', _tick_fire) entities.register_event(_blood, 'position_changed', lambda e, x, y, **kwargs: char(x, y, flags.get_flag(e, 'alpha'))) entities.trigger_event(_blood, 'create_timer', time=120, repeat=-1, repeat_callback=lambda e: movement.push(e, random.randint(-1, 1), random.randint(-1, 1), time=1)) entities.trigger_event(_blood, 'set_fore_color', color=_color[0]) entities.trigger_event(_blood, 'set_back_color', color=_color[1]) entities.trigger_event(_blood, 'set_position', x=_x, y=_y) #light(_x, _y, random.randint(5, 7), r=1.5, g=.1, b=.1) return _blood
def printer(x, y, text, center=True, fore_color=(255, 255, 255), moving=True, move_direction=90, back_color=(10, 10, 10), speed_mod=1.0, show_mod=1.0, free_tick=True): if '--no-fx' in sys.argv: return _entity = entities.create_entity(group='ui_effects' + ('_freetick' * free_tick)) timers.register(_entity) flags.register(_entity) entities.create_event(_entity, 'draw') entities.register_event(_entity, 'draw', _printer_draw) entities.trigger_event(_entity, 'set_flag', flag='text', value=text) entities.trigger_event(_entity, 'set_flag', flag='text_index', value=0) entities.trigger_event(_entity, 'set_flag', flag='text_center', value=center) entities.trigger_event(_entity, 'set_flag', flag='text_pos', value=(x, y)) entities.trigger_event(_entity, 'set_flag', flag='text_orig_pos', value=(x, y)) entities.trigger_event(_entity, 'set_flag', flag='text_fore_color', value=fore_color) entities.trigger_event(_entity, 'set_flag', flag='text_back_color', value=back_color) entities.trigger_event(_entity, 'set_flag', flag='move_direction', value=move_direction) entities.trigger_event(_entity, 'create_timer', time=12*speed_mod, repeat=len(text), repeat_callback=_printer_tick) entities.trigger_event(_entity, 'create_timer', time=((10*speed_mod)*len(text))+(60*show_mod), exit_callback=_printer_exit) if moving: entities.trigger_event(_entity, 'create_timer', time=25, repeat=len(text)/2, repeat_callback=_printer_move) return _entity
def smoke(x, y, amount, start_amount=0.0, decay_amount=1.0): _blood = _create(x, y) _x, _y = (int(round(x)), int(round(y))) _fore_color = random.choice([constants.BLACK_1, constants.BLACK_2, constants.BLACK_3]) _back_color = random.choice([constants.BLACK_1, constants.BLACK_2, constants.BLACK_3]) amount = numbers.clip(amount + random.uniform(-.1, .1), 0, 1) entities.trigger_event(_blood, 'set_char', char=' ') flags.register(_blood) flags.set_flag(_blood, 'alpha', value=start_amount) flags.set_flag(_blood, 'decay', value=decay_amount) flags.set_flag(_blood, 'alpha_mode', value=0) flags.set_flag(_blood, 'alpha_max', value=amount) flags.set_flag(_blood, 'fore_color', value=_fore_color) flags.set_flag(_blood, 'back_color', value=_back_color) _color = list(display.get_color_at('tiles', _x, _y)) _color[0] = numbers.interp_velocity(_color[0], _fore_color, amount) _color[1] = numbers.interp_velocity(_color[1], _back_color, amount) for c in range(len(_color)): for i in range(len(_color)): _color[c][i] = int((round(_color[c][i]))) entities.trigger_event(_blood, 'set_fore_color', color=_color[0]) entities.trigger_event(_blood, 'set_back_color', color=_color[1]) entities.register_event(_blood, 'tick', _tick_smoke) return _blood
def _create_squad(faction_name, x, y): _faction = FACTIONS[faction_name] _squad = entities.create_entity(group='squads') _squad.update({ 'members': set(), 'faction': faction_name, 'leader': None, 'member_info': {}, 'camp_id': None, 'squad_id': _faction['squad_id'], 'task': None, 'brain': None, 'position_map': {}, 'member_position_maps': {}, 'member_los_maps': {}, 'coverage_positions': set(), 'known_targets': set(), 'known_squads': set(), 'position_map_scores': {}, 'meta': { 'is_squad_combat_ready': False, 'is_squad_mobile_ready': False, 'is_squad_overwhelmed': False, 'is_squad_forcing_surrender': False, 'has_camp': False, 'wants_artifacts': False, 'wants_weapons': False }, 'weights': {} }) timers.register(_squad, use_entity_event='logic') movement.register(_squad, x, y) entities.create_event(_squad, 'meta_change') entities.create_event(_squad, 'raid') entities.create_event(_squad, 'update_position_map') entities.create_event(_squad, 'new_squad_member') entities.register_event(_squad, 'raid', handle_raid) entities.register_event(_squad, 'update_position_map', ai_squad_director.create_position_map) _faction['squads'][_faction['squad_id']] = _squad['_id'] #entity['ai']['meta']['is_squad_leader'] = True #register_with_squad(entity, _faction['squad_id']) _faction['squad_id'] += 1 entities.register_event(_squad, 'new_squad_member', update_squad_member_snapshot) entities.register_event(_squad, 'new_squad_member', lambda e, **kwargs: update_group_status(e)) entities.register_event( ai_flow.FLOW, 'start_of_turn', lambda e, squad_id: handle_start_of_turn(_squad, squad_id)) logging.info('Faction \'%s\' created new squad.' % faction_name) return _squad
def add_member(entity, member_id): entities.register_event(entities.get_entity(member_id), 'killed_by', lambda e, target_id, **kwargs: handle_member_killed(entity, member_id, target_id)) entities.register_event(entities.get_entity(member_id), 'new_target_spotted', lambda e, target_id: handle_new_target(entity, target_id))
def _handle_mutated_wild_dog_corpse(entity, corpse_id): _corpse = entities.get_entity(corpse_id) entities.register_event( _corpse, 'get_interactions', lambda e, menu, target_id: ui_menu.add_selectable( menu, 'Cut off tail', lambda: _handle_cut_tail(e, target_id)))
def register_human(entity): entity["brain"] = goapy.World() entity["brain"].add_planner(brains.squad_capture_camp()) entities.register_event(entity, "logic", _human_logic) return entity
def register_human(entity): entity['brain'] = goapy.World() entity['brain'].add_planner(brains.squad_capture_camp()) entities.register_event(entity, 'logic', _human_logic) return entity
def create_factions(): _ownable_spots = [p for p in world_strategy.MAP['grid'].keys() if world_strategy.MAP['grid'][p]['is_ownable'] and not world_strategy.MAP['grid'][p]['owned_by']] for faction_name in ['Rogues', 'Terrorists']: _plot_pos = _ownable_spots.pop(0) _plot = world_strategy.MAP['grid'][_plot_pos] _squad = ai_squads.create_human_squad(faction_name, _plot_pos[0], _plot_pos[1]) _plot['owned_by'] = faction_name if faction_name == 'Rogues': entities.register_event(_squad, 'raid', lambda e, **kwargs: world_strategy.news('Order: Squad %s is raiding %s, %s.' % (e['squad_id'], _plot_pos[0], _plot_pos[1]), fore_color=(200, 40, 40))) entities.register_event(_squad, 'position_changed', lambda e, **kwargs: _handle_squad_position_update(e)) for i in range(3): if faction_name == 'Rogues': if i == 0: _e = life.engineer(30 + i * 2, 7, 'Good Dude %i' % i, faction_name, is_player=True) else: continue #_e = life.turret(30, 7 + i * 2, 'Turret %i' % i, faction_name) #_e = life.engineer(30 + i * 2, 17, 'Good Dude %i' % i, faction_name) else: if random.randint(0, 1): #_e = life.sniper(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name) #_e = life.turret(10, 70 + i * 2, 'Turret', faction_name) #_e = life.engineer(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name) _e = life.grenadier(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name) else: _e = life.grenadier(50 + i * 2, 50, 'Bad Dude %i' % i, faction_name) #_e = life.turret(10, 70 + i * 2, 'Turret', faction_name) ai_squads.register_with_squad(_e, _squad['squad_id'])
def select_squad_member(entity_id): global SELECTED_SQUAD_MEMBER SELECTED_SQUAD_MEMBER = entity_id entities.register_event(entities.get_entity(SELECTED_SQUAD_MEMBER), 'delete', reset_selected_squad_member)
def _create(x, y, name, char, weight, item_type, equip_to=None, fore_color=(255, 255, 255), kind=None): _entity = entities.create_entity(group='items') _entity['stats'] = {'name': name, 'display_name': name, 'type': item_type, 'weight': weight, 'owner': None, 'kind': kind, 'equip_to': equip_to, 'in_container': None} movement.register(_entity) flags.register(_entity) tile.register(_entity, surface='items', char=char, fore_color=fore_color) entities.create_event(_entity, 'collision_with_solid') entities.create_event(_entity, 'collision_with_entity') entities.create_event(_entity, 'get_interactions') entities.create_event(_entity, 'get_actions') entities.create_event(_entity, 'get_display_name') entities.create_event(_entity, 'seen') entities.register_event(_entity, 'get_display_name', get_display_name) entities.trigger_event(_entity, 'set_position', x=x, y=y) return _entity
def register_human(entity, player=False): _register(entity, player=player) _ai = entity['ai'] #Healing _ai['brain'].add_planner(brains.heal()) #Combat _ai['brain'].add_planner(brains.combat()) #Regrouping #NOTE: Not sure what I want this functionality to do #Maybe once squads have evolved a bit more I will approach #it again. #_ai['brain'].add_planner(brains.squad_leader_regroup()) #Panic #_ai['brain'].add_planner(brains.panic()) #Food #_ai['brain'].add_planner(brains.food()) #Search #_ai['brain'].add_planner(brains.search_for_weapon()) #_ai['brain'].add_planner(brains.search_for_ammo()) #_ai['brain'].add_planner(brains.search_for_container()) _ai['brain'].add_planner(brains.search_for_target()) #Reload _ai['brain'].add_planner(brains.reload()) entities.register_event(entity, 'logic', _human_logic) entities.register_event(entity, 'logic_offline', _human_logic_offline)
def mutated_wild_dog(x, y, name): _entity = wild_dog(x, y, name) entities.trigger_event(_entity, 'set_char', char='D') entities.register_event(_entity, 'handle_corpse', _handle_mutated_wild_dog_corpse) return _entity
def add_member(entity, member_id): entities.register_event( entities.get_entity(member_id), 'killed_by', lambda e, target_id, **kwargs: handle_member_killed( entity, member_id, target_id)) entities.register_event( entities.get_entity(member_id), 'new_target_spotted', lambda e, target_id: handle_new_target(entity, target_id))
def register_robot(entity, player=False): _register(entity, player=player) _ai = entity['ai'] #Combat _ai['brain'].add_planner(brains.robot_combat()) #Reload _ai['brain'].add_planner(brains.reload()) entities.register_event(entity, 'logic', _human_logic) entities.register_event(entity, 'logic_offline', _human_logic_offline)
def handle_player_heard_noise(entity, x, y, text, direction, accuracy, show_on_sight, callback, context_callback): _entity = effects.show_noise(entity, x, y, accuracy, direction, text, show_on_sight, callback) if not _entity: return if not context_callback: return _x, _y = flags.get_flag(_entity, 'text_orig_pos') entities.register_event(_entity, 'delete', lambda e: noise.create_context(_x, _y, text, context_callback))
def _create_node(node_grid, x, y): _entity = entities.create_entity() flags.register(_entity) tile.register(_entity, surface='node_grid', fore_color=(255, 0, 255)) entities.trigger_event(_entity, 'set_position', x=x, y=y) entities.trigger_event(_entity, 'set_flag', flag='owner', value=None) entities.register_event(_entity, 'flag_changed', handle_node_flag_change) node_grid[(x, y)] = _entity['_id'] UNCLAIMED_NODES.add((x, y))
def corpse(x, y, char, owner_id): _entity = _create(x, y, '', char, 4, 'corpse', fore_color=(130, 110, 110)) _entity['owner_id'] = owner_id entities.register_event(_entity, 'seen', _corpse_seen) entities.register_event(_entity, 'get_interactions', lambda e, menu, target_id: ui_menu.add_selectable(menu, 'Examine', lambda: ui_dialog.create(x-camera.X, y-camera.Y, 'Dead?'))) return _entity
def counter_2d(x, y, passes, callback): _entity = _create() _entity['x'] = {'current': 0, 'max': x} _entity['y'] = {'current': 0, 'max': y} _entity['callback'] = callback _entity['passes'] = (x*y) / float(passes) entities.register_event(_entity, 'tick', _counter_2d_tick) return _entity
def register_robot(entity, player=False): _register(entity, player=player) _ai = entity["ai"] # Combat _ai["brain"].add_planner(brains.robot_combat()) # Reload _ai["brain"].add_planner(brains.reload()) entities.register_event(entity, "logic", _human_logic) entities.register_event(entity, "logic_offline", _human_logic_offline)
def corpse(x, y, char, owner_id): _entity = _create(x, y, '', char, 4, 'corpse', fore_color=(130, 110, 110)) _entity['owner_id'] = owner_id entities.register_event(_entity, 'seen', _corpse_seen) entities.register_event( _entity, 'get_interactions', lambda e, menu, target_id: ui_menu.add_selectable( menu, 'Examine', lambda: ui_dialog.create(x - camera.X, y - camera. Y, 'Dead?'))) return _entity
def register(entity, faction): if not faction in FACTIONS: raise Exception('Invalid faction: %s' % faction) #TODO: Move this to ai_squads at some point entities.register_event(entity, 'delete', cleanup) entity['ai']['faction'] = faction entity['ai']['squad'] = -1 FACTIONS[entity['ai']['faction']]['members'].add(entity['_id']) entities.trigger_event(FACTIONS[entity['ai']['faction']], 'add_member', member_id=entity['_id'] )
def register(entity): entity['inventory'] = {'items': [], 'holders': {}, 'containers': {}} entities.create_event(entity, 'give_item') entities.register_event(entity, 'give_item', give_item) entities.create_event(entity, 'disown_item') entities.register_event(entity, 'disown_item', disown_item) entities.create_event(entity, 'store_item') entities.register_event(entity, 'store_item', store_item) entities.create_event(entity, 'hold_item') entities.register_event(entity, 'hold_item', hold_item) entities.create_event(entity, 'create_holder') entities.register_event(entity, 'create_holder', add_holder)
def _create_squad(faction_name, x, y): _faction = FACTIONS[faction_name] _squad = entities.create_entity(group='squads') _squad.update({'members': set(), 'faction': faction_name, 'leader': None, 'member_info': {}, 'camp_id': None, 'squad_id': _faction['squad_id'], 'task': None, 'brain': None, 'position_map': {}, 'member_position_maps': {}, 'member_los_maps': {}, 'coverage_positions': set(), 'known_targets': set(), 'known_squads': set(), 'position_map_scores': {}, 'meta': {'is_squad_combat_ready': False, 'is_squad_mobile_ready': False, 'is_squad_overwhelmed': False, 'is_squad_forcing_surrender': False, 'has_camp': False, 'wants_artifacts': False, 'wants_weapons': False}, 'weights': {}}) timers.register(_squad, use_entity_event='logic') movement.register(_squad, x, y) entities.create_event(_squad, 'meta_change') entities.create_event(_squad, 'raid') entities.create_event(_squad, 'update_position_map') entities.create_event(_squad, 'new_squad_member') entities.register_event(_squad, 'raid', handle_raid) entities.register_event(_squad, 'update_position_map', ai_squad_director.create_position_map) _faction['squads'][_faction['squad_id']] = _squad['_id'] #entity['ai']['meta']['is_squad_leader'] = True #register_with_squad(entity, _faction['squad_id']) _faction['squad_id'] += 1 entities.register_event(_squad, 'new_squad_member', update_squad_member_snapshot) entities.register_event(_squad, 'new_squad_member', lambda e, **kwargs: update_group_status(e)) entities.register_event(ai_flow.FLOW, 'start_of_turn', lambda e, squad_id: handle_start_of_turn(_squad, squad_id)) logging.info('Faction \'%s\' created new squad.' % faction_name) return _squad
def register(entity): entities.register_event(entity, 'target_found', _target_found) entities.register_event(entity, 'target_lost', _target_lost) entities.register_event(entity, 'target_search_failed', _target_search_failed) entities.register_event(entity, 'squad_inform_lost_target', _squad_inform_lost_target) WATCHING.append(entity['_id'])
def register(entity, faction): if not faction in FACTIONS: raise Exception('Invalid faction: %s' % faction) #TODO: Move this to ai_squads at some point entities.register_event(entity, 'delete', cleanup) entity['ai']['faction'] = faction entity['ai']['squad'] = -1 FACTIONS[entity['ai']['faction']]['members'].add(entity['_id']) entities.trigger_event(FACTIONS[entity['ai']['faction']], 'add_member', member_id=entity['_id'])
def handle_player_heard_noise(entity, x, y, text, direction, accuracy, show_on_sight, callback, context_callback): _entity = effects.show_noise(entity, x, y, accuracy, direction, text, show_on_sight, callback) if not _entity: return if not context_callback: return _x, _y = flags.get_flag(_entity, 'text_orig_pos') entities.register_event( _entity, 'delete', lambda e: noise.create_context(_x, _y, text, context_callback))
def add_goal_get_item(mission, item_name, return_to_life_id): create_goal(mission, 'locate_item', 'Locate item: %s' % item_name, _locate_item_logic, _locate_item_message, item_name=item_name, details=[]) _goal = create_goal(mission, 'return_item', 'Return item: %s' % item_name, _return_item_logic, _return_item_message, draw=True, item_name=item_name, target_id=return_to_life_id, details=[{ 'intent': 'return_item', 'message': 'Return item', 'callback': lambda member_id, life_id: ai_dialog.give_item( entities.get_entity(member_id), life_id, {'name': 'Mutated Wild Dog Tail'}) }]) _event_id = entities.register_event(_goal, 'member_added', _handle_return_item_member_added)
def register(entity): entity['missions'] = {'active': {}, 'inactive': {}, 'complete': []} entities.create_event(entity, 'add_mission') entities.create_event(entity, 'complete_mission') entities.create_event(entity, 'complete_goal') entities.create_event(entity, 'uncomplete_goal') entities.register_event(entity, 'complete_goal', complete_goal) entities.register_event(entity, 'uncomplete_goal', uncomplete_goal) entities.register_event(entity, 'add_mission', add_mission) entities.register_event(entity, 'complete_mission', member_complete_mission) entities.register_event( entity, 'complete_mission', lambda e, mission_id: entities. trigger_event(entities.get_entity(mission_id), 'remove_member', target_id=e['_id']))
def register(entity): entity['missions'] = {'active': {}, 'inactive': {}, 'complete': []} entities.create_event(entity, 'add_mission') entities.create_event(entity, 'complete_mission') entities.create_event(entity, 'complete_goal') entities.create_event(entity, 'uncomplete_goal') entities.register_event(entity, 'complete_goal', complete_goal) entities.register_event(entity, 'uncomplete_goal', uncomplete_goal) entities.register_event(entity, 'add_mission', add_mission) entities.register_event(entity, 'complete_mission', member_complete_mission) entities.register_event(entity, 'complete_mission', lambda e, mission_id: entities.trigger_event(entities.get_entity(mission_id), 'remove_member', target_id=e['_id']))
def register_animal(entity, player=False): _register_animal(entity, player=player) _ai = entity["ai"] # Combat _ai["brain"].add_planner(brains.dog_combat()) # Panic _ai["brain"].add_planner(brains.panic()) # Food _ai["brain"].add_planner(brains.food()) # Search # TODO: Adopt for mutants # _ai['brain'].add_planner(brains.search_for_target()) entities.register_event(entity, "logic", _animal_logic) entities.register_event(entity, "logic_offline", _animal_logic_offline)
def register_animal(entity, player=False): _register_animal(entity, player=player) _ai = entity['ai'] #Combat _ai['brain'].add_planner(brains.dog_combat()) #Panic _ai['brain'].add_planner(brains.panic()) #Food _ai['brain'].add_planner(brains.food()) #Search #TODO: Adopt for mutants #_ai['brain'].add_planner(brains.search_for_target()) entities.register_event(entity, 'logic', _animal_logic) entities.register_event(entity, 'logic_offline', _animal_logic_offline)
def _handle_return_item_member_added(goal, member_id): _member = entities.get_entity(member_id) _event_id = entities.register_event( _member, 'give_item', lambda entity, item_id, target_id: _handle_return_item_item_given( goal, member_id, item_id, target_id)) entities.trigger_event(goal, 'add_goal_cleanup_event', member_id=member_id, event_pair=('give_item', _event_id))
def create_goal(mission, intent, message, logic_callback, message_callback, draw=True, details=[], **kwargs): _goal = entities.create_entity() _goal['intent'] = intent _goal['mission_id'] = mission['_id'] _goal['message'] = message _goal['draw'] = draw _goal['details'] = details _goal.update(kwargs) entities.create_event(_goal, 'get_message') entities.create_event(_goal, 'member_added') entities.create_event(_goal, 'add_goal_cleanup_event') entities.register_event(_goal, 'logic', logic_callback) entities.register_event(_goal, 'get_message', message_callback) entities.register_event(_goal, 'add_goal_cleanup_event', add_goal_cleanup_event) mission['goals'].append(_goal['_id']) logging.info('Creating goal \'%s\' for mission %s: %s' % (intent, mission['_id'], kwargs)) return _goal
def register(entity): entity['node_grid'] = {'nodes': {}, 'path': [], 'redraw_path': True} entities.register_event(entity, 'logic', logic) entities.register_event(entity, 'draw', draw_path) entities.register_event(entity, 'position_changed', _redraw_first_node)
def glock(x, y, ammo=0): _entity = _create(x, y, 'Glock', 'P', 4, 'weapon', equip_to='weapon', kind='pistol') entities.trigger_event(_entity, 'set_flag', flag='ammo', value=ammo) entities.trigger_event(_entity, 'set_flag', flag='ammo_max', value=17) entities.trigger_event(_entity, 'set_flag', flag='damage', value=135) entities.trigger_event(_entity, 'set_flag', flag='accuracy', value=2.35) entities.trigger_event(_entity, 'set_flag', flag='shoot_cost', value=15) entities.trigger_event(_entity, 'set_flag', flag='rounds_per_shot', value=3) entities.trigger_event(_entity, 'set_flag', flag='is_throwable', value=False) entities.register_event(_entity, 'get_display_name', _handle_weapon_display_name) #entities.register_event(_entity, 'get_actions', lambda e, menu: ui_menu.add_selectable(menu, # 'Single shot', # lambda: ui_dialog.create(x-camera.X, # y-camera.Y, # 'Dead?'))) #entities.register_event(_entity, 'get_actions', lambda e, menu: ui_menu.add_selectable(menu, # '3-burst', # lambda: ui_dialog.create(x-camera.X, # y-camera.Y, # 'Dead?'))) return _entity
def _create(x, y, name, char, weight, item_type, equip_to=None, fore_color=(255, 255, 255), kind=None): _entity = entities.create_entity(group='items') _entity['stats'] = { 'name': name, 'display_name': name, 'type': item_type, 'weight': weight, 'owner': None, 'kind': kind, 'equip_to': equip_to, 'in_container': None } movement.register(_entity) flags.register(_entity) tile.register(_entity, surface='items', char=char, fore_color=fore_color) entities.create_event(_entity, 'collision_with_solid') entities.create_event(_entity, 'collision_with_entity') entities.create_event(_entity, 'get_interactions') entities.create_event(_entity, 'get_actions') entities.create_event(_entity, 'get_display_name') entities.create_event(_entity, 'seen') entities.register_event(_entity, 'get_display_name', get_display_name) entities.trigger_event(_entity, 'set_position', x=x, y=y) return _entity
def add_goal_get_item(mission, item_name, return_to_life_id): create_goal(mission, 'locate_item', 'Locate item: %s' % item_name, _locate_item_logic, _locate_item_message, item_name=item_name, details=[]) _goal = create_goal(mission, 'return_item', 'Return item: %s' % item_name, _return_item_logic, _return_item_message, draw=True, item_name=item_name, target_id=return_to_life_id, details=[{'intent': 'return_item', 'message': 'Return item', 'callback': lambda member_id, life_id: ai_dialog.give_item(entities.get_entity(member_id), life_id, {'name': 'Mutated Wild Dog Tail'})}]) _event_id = entities.register_event(_goal, 'member_added', _handle_return_item_member_added)
def _create(name, squad_size_range, base_size_range, enemy_factions): _entity = entities.create_entity(group='factions') _faction = { 'members': set(), 'squads': {}, 'squad_id': 1, 'faction_memory': {}, 'brains': [], 'meta': {}, 'money': 1200, 'squad_size_range': squad_size_range, 'base_size_range': base_size_range, 'enemies': enemy_factions, 'relations': {} } for faction_name in FACTIONS: _other_faction = FACTIONS[faction_name] if name in _other_faction['enemies']: _other_score = 0 else: _other_score = 25 if faction_name in enemy_factions: _score = 0 else: _score = 25 _other_faction['relations'][name] = _other_score _faction['relations'][faction_name] = _score _faction['faction_memory'][faction_name] = {'squads': {}} _other_faction['faction_memory'][name] = {'squads': {}} _entity.update(_faction) entities.create_event(_entity, 'add_member') entities.create_event(_entity, 'faction_raid_incoming') entities.create_event(_entity, 'broadcast') entities.register_event(_entity, 'add_member', add_member) entities.register_event(_entity, 'broadcast', handle_broadcast) entities.register_event(_entity, 'faction_raid_incoming', handle_raid_incoming) FACTIONS[name] = _entity return _entity
def _create(name, squad_size_range, base_size_range, enemy_factions): _entity = entities.create_entity(group='factions') _faction = {'members': set(), 'squads': {}, 'squad_id': 1, 'faction_memory': {}, 'brains': [], 'meta': {}, 'money': 1200, 'squad_size_range': squad_size_range, 'base_size_range': base_size_range, 'enemies': enemy_factions, 'relations': {}} for faction_name in FACTIONS: _other_faction = FACTIONS[faction_name] if name in _other_faction['enemies']: _other_score = 0 else: _other_score = 25 if faction_name in enemy_factions: _score = 0 else: _score = 25 _other_faction['relations'][name] = _other_score _faction['relations'][faction_name] = _score _faction['faction_memory'][faction_name] = {'squads': {}} _other_faction['faction_memory'][name] = {'squads': {}} _entity.update(_faction) entities.create_event(_entity, 'add_member') entities.create_event(_entity, 'faction_raid_incoming') entities.create_event(_entity, 'broadcast') entities.register_event(_entity, 'add_member', add_member) entities.register_event(_entity, 'broadcast', handle_broadcast) entities.register_event(_entity, 'faction_raid_incoming', handle_raid_incoming) FACTIONS[name] = _entity return _entity
def explosive(entity, x, y, tx, ty, speed, accuracy, damage): _entity = _create(x, y, 'Explosive', '.', 0, 'bullet') _entity['owner'] = entity['_id'] _entity['start_position'] = (x, y) _entity['end_position'] = (tx, ty) _entity['speed'] = speed _entity['damage'] = damage _toss_distance = numbers.distance(_entity['start_position'], _entity['end_position']) _entity['accuracy'] = numbers.clip(random.randint(int(round(accuracy * .25)), accuracy), 0, 100) - (accuracy * (1 - (_toss_distance / 20.0))) _entity['slow_down'] = False _direction_mod = random.uniform(-accuracy, accuracy) * 2 entities.create_event(_entity, 'explode') entities.create_event(_entity, 'activate_explosive') entities.register_event(_entity, 'explode', frag_grenade_explode) entities.register_event(_entity, 'explode', entities.delete_entity) entities.register_event(_entity, 'activate_explosive', lambda e: entities.trigger_event(e, 'create_timer', time=90, exit_callback=lambda ee: entities.trigger_event(ee, 'explode'))) entities.register_event(_entity, 'check_next_position', check_next_position) entities.add_entity_to_group(_entity, 'bullets') timers.register(_entity) entities.trigger_event(_entity, 'set_direction', direction=numbers.direction_to((x, y), (tx, ty)) + _direction_mod) entities.trigger_event(_entity, 'create_timer', time=speed, enter_callback=_explosive_tick, name='movement') entities.register_event(_entity, 'position_changed', lambda e, **kwargs: check_for_collisions(e)) if not '--no-fx' in sys.argv: entities.register_event(_entity, 'position_changed', lambda e, x, y, **kwargs: _bullet_effects(e, x, y)) entities.register_event(_entity, 'collision_with_entity', lambda e, **kwargs: entities.trigger_event(e, 'activate_explosive')) entities.register_event(_entity, 'collision_with_entity', lambda e, **kwargs: _explosive_stop_dumb_hack(e)) entities.register_event(_entity, 'collision_with_solid', lambda e: timers.stop_timer(e, 'movement')) entities.register_event(_entity, 'collision_with_solid', _explosive_stop_dumb_hack) entities.register_event(_entity, 'collision_with_solid', lambda e: entities.trigger_event(e, 'activate_explosive'))
def _handle_mutated_wild_dog_corpse(entity, corpse_id): _corpse = entities.get_entity(corpse_id) entities.register_event(_corpse, 'get_interactions', lambda e, menu, target_id: ui_menu.add_selectable(menu, 'Cut off tail', lambda: _handle_cut_tail(e, target_id)))
def bullet(entity, x, y, tx, ty, speed, accuracy, damage): _entity = _create(x, y, 'Bullet', '.', 0, 'bullet') _entity['owner'] = entity['_id'] _entity['start_position'] = (x, y) _entity['end_position'] = (tx, ty) _entity['speed'] = speed _entity['damage'] = damage entities.add_entity_to_group(_entity, 'bullets') timers.register(_entity) entities.trigger_event(_entity, 'set_direction', direction=numbers.direction_to((x, y), (tx, ty))+random.uniform(-accuracy, accuracy)) entities.trigger_event(_entity, 'create_timer', time=speed, repeat=-1, enter_callback=_bullet_tick, repeat_callback=_bullet_tick) entities.register_event(_entity, 'position_changed', lambda e, **kwargs: check_for_collisions(e)) entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.trigger_event(entities.get_entity(target_id), 'hit', projectile=e)) entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.delete_entity(e)) entities.register_event(_entity, 'collision_with_solid', lambda e: effects.light(movement.get_position(e)[0], movement.get_position(e)[1], random.randint(3, 4))) entities.register_event(_entity, 'collision_with_solid', lambda e: entities.delete_entity(e)) entities.register_event(_entity, 'collision_with_solid', lambda e: effects.smoke_cloud(movement.get_position(e)[0], movement.get_position(e)[1], random.uniform(2, 2.75), start_alpha=random.uniform(0.45, .65), decay_amount=1.5)) entities.register_event(_entity, 'check_next_position', check_next_position) if not '--no-fx' in sys.argv: entities.register_event(_entity, 'position_changed', lambda e, x, y, **kwargs: _bullet_effects(e, x, y))
def register(entity): entity['skeleton'] = {'limbs': {}, 'motions': {}, 'motion': None} entities.create_event(entity, 'hit') entities.create_event(entity, 'force') entities.create_event(entity, 'set_motion') entities.register_event(entity, 'hit', hit) entities.register_event(entity, 'force', force) entities.register_event(entity, 'get_mobility', get_mobility_mod) entities.register_event(entity, 'get_accuracy', get_accuracy_mod) entities.register_event(entity, 'get_vision', get_vision_mod) entities.register_event(entity, 'set_motion', set_motion) entities.register_event(entity, 'damage', handle_pain) entities.register_event(entity, 'tick', tick) return entity