def tick(): global TIME for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) entities.trigger_event(_squad, 'logic') for x, y in MAP['grid'].keys(): _camp = MAP['grid'][x, y] if _camp['is_ownable'] and _camp['owned_by']: ai_factions.FACTIONS[_camp['owned_by']]['money'] += _camp['income'] for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) entities.trigger_event(_squad, 'tick') TIME += 0.01 if NEED_FADE_IN: fade_in() entities.trigger_event(FADER, 'tick')
def draw_long_range_life(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] _draw_life_targets = set() if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _draw_life.add(member_id) _draw_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES]) _draw_life_targets.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and _member['ai']['life_memory'][i]['is_target'] and i in entities.ENTITIES]) _draw_life = list(_draw_life) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: _x = numbers.clip(_x, 0, _width-1) _y = numbers.clip(_y, 0, _height-1) else: continue if time.time() % 1 >= .5: _char = 'X' else: _char = 'O' if entity_id in _draw_life_targets: _fore_color = (255, 0, 0) _back_color = (100, 0, 0) else: _fore_color = (255, 255, 255) _back_color = (100, 100, 100) display.write_string('ui', _x, _y, _char, fore_color=_fore_color, back_color=_back_color)
def create_noise(entity, text, volume, owner_can_hear=False, show_on_sight=False, direction=-1000, callback=None, context_callback=None): _x, _y = movement.get_position(entity) for entity_id in entities.get_entity_group('life'): if not owner_can_hear and entity['_id'] == entity_id: continue _target = entities.get_entity(entity_id) if entity['ai']['faction'] == _target['ai']['faction']: continue #TODO: Hearing stat _distance = numbers.distance(movement.get_position(entity), movement.get_position(_target)) _accuracy = 1 - numbers.clip(_distance / float(volume), 0, 1) entities.trigger_event(_target, 'heard_noise', x=_x, y=_y, text=text, direction=direction, show_on_sight=show_on_sight, accuracy=_accuracy, callback=callback, context_callback=context_callback)
def draw_item_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_items = entities.get_entity_group('items') else: _draw_items = [item for _items in PLAYER['ai']['visible_items'].values() for item in _items] for entity_id in _draw_items: if not entity_id in entities.ENTITIES: continue _entity = entities.get_entity(entity_id) if _entity['stats']['owner']: continue _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _label = _entity['stats']['name'] _render_x = numbers.clip(_x - len(_label)/2, 0, _width - len(_label)) _render_y = numbers.clip(_y + 2, 0, _height) if _render_y == _y: _render_y -= 1 display.write_string('ui', _render_x, _render_y, _label)
def build_item_list(entity): entity['ai']['visible_items'] = {'weapon': [], 'container': [], 'ammo': [], 'bullet': [], 'corpse': []} return _active_solids = zones.get_active_solids(entity) for entity_id in entities.get_entity_group('items'): _item = entities.get_entity(entity_id) if not _item['stats']['type'] in entity['ai']['visible_items']: continue if _item['stats']['owner']: continue _distance = numbers.distance(movement.get_position(entity), movement.get_position(_item)) if _distance >= stats.get_vision(entity): continue for pos in shapes.line(movement.get_position(entity), movement.get_position(_item)): if pos in _active_solids: break else: entity['ai']['visible_items'][_item['stats']['type']].append(entity_id) entities.trigger_event(_item, 'seen', target_id=entity['_id'])
def check_for_collisions(entity): _x, _y = movement.get_position(entity) if _x < 0 or _x >= zones.get_active_size( )[0] - 1 or _y < 0 or _y >= zones.get_active_size()[1] - 1: entities.delete_entity(entity) return if (_x, _y) in zones.get_active_solids(entity): entities.trigger_event(entity, 'collision_with_solid') return for entity_id in entities.get_entity_group('life'): if entity_id == entity['owner']: continue if movement.get_position(entity) == movement.get_position_via_id( entity_id): entities.trigger_event(entity, 'collision_with_entity', target_id=entity_id) return
def tick(): if entities.get_entity_group('bullets'): for i in range(4): for entity_id in entities.get_entity_group('bullets'): entities.trigger_event(entities.get_entity(entity_id), 'tick') else: ai_flow.tick() for entity_id in entities.get_entity_group('effects'): entities.trigger_event(entities.get_entity(entity_id), 'tick') for entity_id in entities.get_entity_group('ui_effects'): entities.trigger_event(entities.get_entity(entity_id), 'tick') ai_visuals.reset_moved_entities() post_tick()
def handle_keyboard_input(): if controls.get_input_char_pressed('\t'): if settings.TICK_MODE == 'strategy': if ui_panel.ACTIVE_MENU: ui_panel.close() else: ui_panel.show_inventory(entity) else: _x, _y = movement.get_position(entity) camera.set_pos(_x - constants.MAP_VIEW_WIDTH / 2, _y - constants.MAP_VIEW_HEIGHT / 2) if controls.get_input_char_pressed('O'): settings.toggle_show_node_grid() elif controls.get_input_char_pressed('o'): settings.toggle_observer_mode() if controls.get_input_char_pressed('d'): _mx, _my = ui_cursor.get_map_position() for entity_id in entities.get_entity_group('life'): _entity = entities.get_entity(entity_id) if not numbers.distance( (_mx, _my), movement.get_position(_entity)): _x, _y = ui_cursor.get_screen_position() _menu = ui_menu.create(_x, _y, title='Debug') ui_menu.add_selectable(_menu, 'Show Metas', lambda: _show_metas(_entity)) ui_menu.add_selectable( _menu, 'Kill', lambda: entities.trigger_event(_entity, 'kill')) ui_menu.add_selectable(_menu, 'Overwatch', lambda: ai_debugger.register(_entity)) break if controls.get_input_char_pressed('l'): _x, _y = ui_cursor.get_screen_position() _mx, _my = ui_cursor.get_map_position() _weight = zones.get_active_weight_map()[_my, _mx] _menu = ui_menu.create(_x, _y, title='Tile Info') ui_menu.add_selectable( _menu, 'Warp', lambda: entities.trigger_event( entity, 'set_position', x=_mx, y=_my)) ui_menu.add_selectable( _menu, 'Light', lambda: effects.light(_mx, _my, 15, r=random.uniform(1.0, 1.5), g=random.uniform(1.0, 1.5), light_map='static_lighting')) ui_menu.add_selectable(_menu, 'Weight: %s' % _weight, lambda: _)
def draw_life_memory(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] _draw_life = set() _can_see_life = set() _last_seen_locations = {} for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _can_see_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES]) _draw_life.update(_member['ai']['targets'] - _member['ai']['visible_life']) for memory_id in _member['ai']['life_memory'].keys(): if not member_id in _last_seen_locations and _member['ai']['life_memory'][memory_id]['last_seen_at']: _last_seen_locations[memory_id] = _member['ai']['life_memory'][memory_id]['last_seen_at'] _draw_life = list(_draw_life) for entity_id in _draw_life: if entity_id in _can_see_life or not entity_id in entities.ENTITIES: continue if not entity_id in _last_seen_locations: continue _entity = entities.get_entity(entity_id) _x, _y = _last_seen_locations[entity_id] _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue if time.time() % 1 >= .5: _char = _entity['tile']['char'] _fore_color = _entity['tile']['fore_color'] else: _char = '!' _fore_color = (255, 0, 0) _render_x = numbers.clip(_x - len(_char)/2, 0, _width - len(_char) - 1) _render_y = numbers.clip(_y, 0, _height) #if _x - len(_char)/2 < 0 or _x + len(_char)/2 >= _width: # continue if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _char, fore_color=_fore_color)
def handle_squad_member_select(x, y): for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for entity_id in _squad['members']: if movement.get_position_via_id(entity_id) == (x, y): select_squad_member(entity_id) return True
def get_active_solids(entity, ignore_entities=[], ignore_calling_entity=False, no_life=False): if not ACTIVE_ZONE: raise Exception('No zone is active.') _solids = ZONES[ACTIVE_ZONE]['solids'].copy() if not no_life: if not ignore_calling_entity: ignore_entities.append(entity['_id']) _solids.update([movement.get_position_via_id(p) for p in entities.get_entity_group('life') if not p in ignore_entities]) return _solids
def delete(dialog): global ACTIVE_DIALOG entities.delete_entity(dialog) if ACTIVE_DIALOG == dialog: _dialogs = entities.get_entity_group('ui_dialogs') if _dialogs: ACTIVE_DIALOG = entities.get_entity(_dialogs[len(_dialogs)-1]) entities.trigger_event(ACTIVE_DIALOG, 'reactivated') else: ACTIVE_DIALOG = None
def delete(dialog): global ACTIVE_DIALOG entities.delete_entity(dialog) if ACTIVE_DIALOG == dialog: _dialogs = entities.get_entity_group('ui_dialogs') if _dialogs: ACTIVE_DIALOG = entities.get_entity(_dialogs[len(_dialogs) - 1]) entities.trigger_event(ACTIVE_DIALOG, 'reactivated') else: ACTIVE_DIALOG = None
def handle_keyboard_input(): global SELECTED_SQUAD_MEMBER, WALK_PATH, WALK_DEST #TODO: Check for multiple movement changes at this location if not is_squad_member_selected(): return _entity = get_selected_squad_member() _x, _y = movement.get_position(_entity) if timers.has_timer_with_name(_entity, 'passout'): return if controls.get_input_char_pressed('z'): entities.trigger_event(_entity, 'set_motion', motion='crawl') settings.set_tick_mode('normal') elif controls.get_input_char_pressed('x'): entities.trigger_event(_entity, 'set_motion', motion='crouch') settings.set_tick_mode('normal') elif controls.get_input_char_pressed('c'): entities.trigger_event(_entity, 'set_motion', motion='stand') settings.set_tick_mode('normal') elif controls.get_input_char_pressed(' '): _entity['stats']['action_points'] = 0 SELECTED_SQUAD_MEMBER = None WALK_DEST = None WALK_PATH = [] _broken = False for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) if _entity['stats']['action_points'] > 0: _broken = True break if _broken: break else: settings.set_tick_mode('normal')
def logic(): for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) entities.trigger_event(_entity, 'logic') for squad_id in settings.TURN_QUEUE[:]: if not squad_id in entities.ENTITIES: settings.TURN_QUEUE.remove(squad_id) continue _squad = entities.get_entity(squad_id) for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) if _entity['stats']['action_points'] > 0: break else: if _squad['_id'] in settings.TURN_QUEUE: _was_leader = False if not settings.TURN_QUEUE.index(_squad['_id']): entities.trigger_event(FLOW, 'end_of_turn', squad_id=_squad['_id']) _was_leader = True settings.TURN_QUEUE.remove(_squad['_id']) if len(settings.TURN_QUEUE): settings.TURN_QUEUE.append(_squad['_id']) if settings.TURN_QUEUE and _was_leader: entities.trigger_event(FLOW, 'start_of_turn', squad_id=settings.TURN_QUEUE[0]) for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) _entity['stats']['action_points'] = _entity['stats'][ 'action_points_max']
def frag_grenade_explode(entity): _x, _y = movement.get_position(entity) _damage = entity['damage'] _size = 3 * int(round((_damage * .01))) effects.explosion(_x, _y, _size) for entity_id in entities.get_entity_group('life'): _entity = entities.get_entity(entity_id) _distance = numbers.distance((_x, _y), movement.get_position(_entity)) if _distance - 1 > _size or not life.can_see_position(_entity, (_x, _y)): continue entities.trigger_event(_entity, 'hit', projectile=entity, damage_mod=1 - ((_distance - 1) / float(_size)))
def delete(menu): global ACTIVE_MENU, DELAY entities.delete_entity(menu) if ACTIVE_MENU == menu: _menus = entities.get_entity_group('ui_menus') if _menus: ACTIVE_MENU = entities.get_entity(_menus[len(_menus) - 1]) entities.trigger_event(ACTIVE_MENU, 'reactivated') else: ACTIVE_MENU = None DELAY = 30
def delete(menu): global ACTIVE_MENU, DELAY entities.delete_entity(menu) if ACTIVE_MENU == menu: _menus = entities.get_entity_group('ui_menus') if _menus: ACTIVE_MENU = entities.get_entity(_menus[len(_menus)-1]) entities.trigger_event(ACTIVE_MENU, 'reactivated') else: ACTIVE_MENU = None DELAY = 30
def create(): global MAP, FADER worlds.create('strategy') words.reset() display.create_surface('background') display.create_surface('map', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('map_markers', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('map_squads', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('map_path', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('ui_bar', width=constants.WINDOW_WIDTH, height=constants.WINDOW_HEIGHT-constants.STRAT_MAP_HEIGHT) display.fill_surface('ui_bar', (30, 30, 30)) display.blit_background('background') register_input() entities.create_entity_group('life', static=True) entities.create_entity_group('items', static=True) entities.create_entity_group('factions', static=True) entities.create_entity_group('squads', static=True) entities.create_entity_group('systems') FADER = entities.create_entity() timers.register(FADER) fade_in() _grid = {} _color_map = {} MAP = {'grid': _grid, 'color_map': _color_map, 'astar_map': None, 'astar_weight_map': numpy.ones((constants.STRAT_MAP_HEIGHT/constants.MAP_CELL_SPACE, constants.STRAT_MAP_WIDTH/constants.MAP_CELL_SPACE))} for x in range(constants.STRAT_MAP_WIDTH/constants.MAP_CELL_SPACE): for y in range(constants.STRAT_MAP_HEIGHT/constants.MAP_CELL_SPACE): _grid[x, y] = {'owned_by': None, 'is_ownable': False, 'squads': [], 'income': .025} worldgen.generate() unregister_input() world_action._start_battle(attacking_squads=[entities.get_entity_group('squads')[0]], defending_squads=[entities.get_entity_group('squads')[1]])
def draw_life_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = [ i for i in PLAYER['ai']['life_memory'] if PLAYER['ai']['life_memory'][i]['can_see'] ] if PLAYER['_id'] in entities.ENTITIES: _draw_life.append(PLAYER['_id']) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _back_color = None if settings.OBSERVER_MODE: _label = _entity['ai']['current_action'] else: _label = life.get_status_string(_entity) if not PLAYER['_id'] == entity_id and PLAYER['ai']['life_memory'][ entity_id]['mission_related'] and time.time() % 1 >= .5: _back_color = (200, 0, 0) _render_x = numbers.clip(_x - len(_label) / 2, 0, _width - len(_label)) _render_y = numbers.clip(_y - 2, 0, _height) if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _label, back_color=_back_color)
def draw_squads(selected_squad=None): for entity_id in entities.get_entity_group("squads"): _squad = entities.get_entity(entity_id) if _squad["faction"] == "Terrorists": continue _x, _y = movement.get_position(_squad) _r_x = (_x * constants.MAP_CELL_SPACE) + constants.MAP_CELL_SPACE / 2 _r_y = (_y * constants.MAP_CELL_SPACE) + constants.MAP_CELL_SPACE / 2 _fore_color = (200, 200, 200) if selected_squad == entity_id: if time.time() % 1 >= 0.5: _fore_color = (100, 150, 100) display.write_char("map_squads", _r_x, _r_y, "S", fore_color=_fore_color)
def _push(entity, x, y): entity['movement']['next_x'] = entity['movement']['x'] + x entity['movement']['next_y'] = entity['movement']['y'] + y entities.trigger_event(entity, 'check_next_position') _nx = entity['movement']['next_x'] _ny = entity['movement']['next_y'] if entity['movement']['collisions']: _solids = [get_position_via_id(p) for p in entities.get_entity_group('life') if not p == entity['_id']] if (_nx, _ny) in _solids: entity['movement']['path']['refresh'] = True return set_position(entity, _nx, _ny)
def logic(): for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) entities.trigger_event(_entity, 'logic') for squad_id in settings.TURN_QUEUE[:]: if not squad_id in entities.ENTITIES: settings.TURN_QUEUE.remove(squad_id) continue _squad = entities.get_entity(squad_id) for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) if _entity['stats']['action_points'] > 0: break else: if _squad['_id'] in settings.TURN_QUEUE: _was_leader = False if not settings.TURN_QUEUE.index(_squad['_id']): entities.trigger_event(FLOW, 'end_of_turn', squad_id=_squad['_id']) _was_leader = True settings.TURN_QUEUE.remove(_squad['_id']) if len(settings.TURN_QUEUE): settings.TURN_QUEUE.append(_squad['_id']) if settings.TURN_QUEUE and _was_leader: entities.trigger_event(FLOW, 'start_of_turn', squad_id=settings.TURN_QUEUE[0]) for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) _entity['stats']['action_points'] = _entity['stats']['action_points_max']
def frag_grenade_explode(entity): _x, _y = movement.get_position(entity) _damage = entity['damage'] _size = 3 * int(round((_damage * .01))) effects.explosion(_x, _y, _size) for entity_id in entities.get_entity_group('life'): _entity = entities.get_entity(entity_id) _distance = numbers.distance((_x, _y), movement.get_position(_entity)) if _distance - 1 > _size or not life.can_see_position( _entity, (_x, _y)): continue entities.trigger_event(_entity, 'hit', projectile=entity, damage_mod=1 - ((_distance - 1) / float(_size)))
def handle_keyboard_input(): if controls.get_input_char_pressed('\t'): if settings.TICK_MODE == 'strategy': if ui_panel.ACTIVE_MENU: ui_panel.close() else: ui_panel.show_inventory(entity) else: _x, _y = movement.get_position(entity) camera.set_pos(_x - constants.MAP_VIEW_WIDTH/2, _y - constants.MAP_VIEW_HEIGHT/2) if controls.get_input_char_pressed('O'): settings.toggle_show_node_grid() elif controls.get_input_char_pressed('o'): settings.toggle_observer_mode() if controls.get_input_char_pressed('d'): _mx, _my = ui_cursor.get_map_position() for entity_id in entities.get_entity_group('life'): _entity = entities.get_entity(entity_id) if not numbers.distance((_mx, _my), movement.get_position(_entity)): _x, _y = ui_cursor.get_screen_position() _menu = ui_menu.create(_x, _y, title='Debug') ui_menu.add_selectable(_menu, 'Show Metas', lambda: _show_metas(_entity)) ui_menu.add_selectable(_menu, 'Kill', lambda: entities.trigger_event(_entity, 'kill')) ui_menu.add_selectable(_menu, 'Overwatch', lambda: ai_debugger.register(_entity)) break if controls.get_input_char_pressed('l'): _x, _y = ui_cursor.get_screen_position() _mx, _my = ui_cursor.get_map_position() _weight = zones.get_active_weight_map()[_my, _mx] _menu = ui_menu.create(_x, _y, title='Tile Info') ui_menu.add_selectable(_menu, 'Warp', lambda: entities.trigger_event(entity, 'set_position', x=_mx, y=_my)) ui_menu.add_selectable(_menu, 'Light', lambda: effects.light(_mx, _my, 15, r=random.uniform(1.0, 1.5), g=random.uniform(1.0, 1.5), light_map='static_lighting')) ui_menu.add_selectable(_menu, 'Weight: %s' % _weight, lambda: _)
def get_active_solids(entity, ignore_entities=[], ignore_calling_entity=False, no_life=False): if not ACTIVE_ZONE: raise Exception('No zone is active.') _solids = ZONES[ACTIVE_ZONE]['solids'].copy() if not no_life: if not ignore_calling_entity: ignore_entities.append(entity['_id']) _solids.update([ movement.get_position_via_id(p) for p in entities.get_entity_group('life') if not p in ignore_entities ]) return _solids
def _push(entity, x, y): entity['movement']['next_x'] = entity['movement']['x'] + x entity['movement']['next_y'] = entity['movement']['y'] + y entities.trigger_event(entity, 'check_next_position') _nx = entity['movement']['next_x'] _ny = entity['movement']['next_y'] if entity['movement']['collisions']: _solids = [ get_position_via_id(p) for p in entities.get_entity_group('life') if not p == entity['_id'] ] if (_nx, _ny) in _solids: entity['movement']['path']['refresh'] = True return set_position(entity, _nx, _ny)
def check_for_collisions(entity): _x, _y = movement.get_position(entity) if _x < 0 or _x >= zones.get_active_size()[0]-1 or _y < 0 or _y >= zones.get_active_size()[1]-1: entities.delete_entity(entity) return if (_x, _y) in zones.get_active_solids(entity): entities.trigger_event(entity, 'collision_with_solid') return for entity_id in entities.get_entity_group('life'): if entity_id == entity['owner']: continue if movement.get_position(entity) == movement.get_position_via_id(entity_id): entities.trigger_event(entity, 'collision_with_entity', target_id=entity_id) return
def draw_squads(selected_squad=None): for entity_id in entities.get_entity_group('squads'): _squad = entities.get_entity(entity_id) if _squad['faction'] == 'Terrorists': continue _x, _y = movement.get_position(_squad) _r_x = (_x * constants.MAP_CELL_SPACE) + constants.MAP_CELL_SPACE / 2 _r_y = (_y * constants.MAP_CELL_SPACE) + constants.MAP_CELL_SPACE / 2 _fore_color = (200, 200, 200) if selected_squad == entity_id: if time.time() % 1 >= .5: _fore_color = (100, 150, 100) display.write_char('map_squads', _r_x, _r_y, 'S', fore_color=_fore_color)
def draw_life_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') else: _draw_life = [i for i in PLAYER['ai']['life_memory'] if PLAYER['ai']['life_memory'][i]['can_see']] if PLAYER['_id'] in entities.ENTITIES: _draw_life.append(PLAYER['_id']) for entity_id in _draw_life: _entity = entities.get_entity(entity_id) _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _back_color = None if settings.OBSERVER_MODE: _label = _entity['ai']['current_action'] else: _label = life.get_status_string(_entity) if not PLAYER['_id'] == entity_id and PLAYER['ai']['life_memory'][entity_id]['mission_related'] and time.time() % 1 >= .5: _back_color = (200, 0, 0) _render_x = numbers.clip(_x - len(_label)/2, 0, _width - len(_label)) _render_y = numbers.clip(_y - 2, 0, _height) if _render_y == _y: _render_y += 2 display.write_string('ui', _render_x, _render_y, _label, back_color=_back_color)
def _handle_squad_position_update(entity): if len(entity['movement']['path']['positions']) == 1: world_strategy.news('Alert: Squad %s is arriving at %s, %s.' % (entity['squad_id'], entity['movement']['path']['destination'][0], entity['movement']['path']['destination'][1]), fore_color=(200, 40, 40), back_color=(80, 0, 0)) elif not len(entity['movement']['path']['positions']): _x, _y = movement.get_position(entity) _camp = world_strategy.MAP['grid'][_x, _y] if _camp['owned_by'] and not entity['faction'] == _camp['owned_by']: _defending_squads = [] for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if _squad['faction'] == _camp['owned_by']: _defending_squads.append(squad_id) world_strategy.unregister_input() world_strategy.world_action.start_battle(attacking_squads=[entity['_id']], defending_squads=_defending_squads)
def draw_item_labels(): _camera_x, _camera_y = camera.X, camera.Y _width = display.get_surface('life')['width'] _height = display.get_surface('life')['height'] if settings.OBSERVER_MODE: _draw_items = entities.get_entity_group('items') else: _draw_items = [ item for _items in PLAYER['ai']['visible_items'].values() for item in _items ] for entity_id in _draw_items: if not entity_id in entities.ENTITIES: continue _entity = entities.get_entity(entity_id) if _entity['stats']['owner']: continue _x, _y = movement.get_position(_entity) _x -= _camera_x _y -= _camera_y if _x < 0 or _y < 0 or _x >= _width or _y >= _height: continue _label = _entity['stats']['name'] _render_x = numbers.clip(_x - len(_label) / 2, 0, _width - len(_label)) _render_y = numbers.clip(_y + 2, 0, _height) if _render_y == _y: _render_y -= 1 display.write_string('ui', _render_x, _render_y, _label)
def draw_all(surface): for dialog_id in entities.get_entity_group('ui_dialogs'): draw(entities.get_entity(dialog_id), surface)
def draw(): global MOVIE_TIME, MOVIE_TIME_MAX if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') _draw_items = entities.get_entity_group('items') else: _draw_life = set() _draw_items = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _draw_life.add(member_id) _draw_life.update([ i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES ]) _draw_life = list(_draw_life) for entity_id in _draw_life: entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in entities.get_entity_group('nodes'): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) if settings.SHOW_NODE_GRID: for entity_id in zones.get_active_node_grid().values(): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in entities.get_entity_groups( ['ui_effects', 'ui_effects_freetick']): entities.trigger_event(entities.get_entity(entity_id), 'draw') for entity_id in entities.get_entity_groups( ['effects', 'effects_freetick']): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in entities.get_entity_group('contexts'): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in _draw_items: if not entity_id in entities.ENTITIES: continue _entity = entities.get_entity(entity_id) if _entity['stats']['owner']: continue entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) ui_draw.draw_status_bar(planning=settings.TICK_MODE == 'strategy', executing=not settings.TICK_MODE == 'strategy', execute_speed=settings.PLAN_TICK_RATE_STRING, selecting=nodes.SELECTING_TARGET_CALLBACK) #if settings.TICK_MODE == 'strategy': # ui_draw.draw_item_labels() if '--labels' in sys.argv: ui_draw.draw_life_labels() ui_draw.draw_long_range_life() ui_draw.draw_life_memory() ui_draw.draw_walk_path() #ui_draw.draw_mission_details() ui_draw.draw_turn_bar() if '--fps' in sys.argv: ui_draw.draw_fps() events.trigger_event('post_process') #display.reset_surface_shaders('tiles') #_zone = zones.ZONES[zones.ACTIVE_ZONE] #for shader in _zone['shaders']: # display.apply_surface_shader('tiles', shader, constants.MAP_VIEW_WIDTH, constants.MAP_VIEW_HEIGHT) if ui_director.HAS_FOCUS: ui_director.draw() display.blit_surface('effects') display.blit_surface('nodes') display.blit_surface('items') display.blit_surface('life') display.blit_surface('ui') display.blit_surface('ui_menus') display.blit_surface('ui_dialogs') if ui_panel.ACTIVE_MENU: display.blit_surface_viewport('ui_inventory', 0, 0, 35, constants.MAP_VIEW_HEIGHT, dx=constants.MAP_VIEW_WIDTH - 35) if settings.SHOW_NODE_GRID: display.blit_surface('node_grid') events.trigger_event('draw') if '--record' in sys.argv: MOVIE_TIME += 1 if MOVIE_TIME == MOVIE_TIME_MAX: display.screenshot('screenshot-%s.bmp' % time.time()) MOVIE_TIME = 0
def loop(): global PLAYER_HAS_SHOOT_TIMER events.trigger_event('input') if not settings.TICK_MODE == 'strategy' and not ( (ui_dialog.ACTIVE_DIALOG and ui_director.PAUSE) or ui_menu.ACTIVE_MENU or ui_director.PAUSE): _has_action = False _check_life = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _check_life.add(member_id) _check_life.update([ i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES ]) _check_life = list(_check_life) #_check_life = #_check_life.append(PLAYER['_id']) for entity_id in _check_life: if timers.has_timer_with_name(entities.get_entity(entity_id), 'shoot'): _has_action = True break if _has_action: _ticks_per_tick = 1 else: _ticks_per_tick = settings.PLAN_TICK_RATE for _ in range(_ticks_per_tick): if settings.TICK_MODE == 'strategy': break ai_flow.logic() events.trigger_event('logic') tick() free_tick() else: ai_flow.logic() free_tick() if pathfinding.wait_for_astar(): pass if not handle_input(): return False events.trigger_event('tick') events.trigger_event('camera') draw() return True
def handle_mouse_pressed(entity, x, y, button): global DRAGGING_NODE, LAST_CLICKED_POS, SELECTING_TARGET_CALLBACK if ui_menu.get_active_menu() or ui_menu.DELAY: return if timers.has_timer_with_name(entity, 'passout'): return _x = x+camera.X _y = y+camera.Y if button == 1: if DRAGGING_NODE: DRAGGING_NODE = None elif not (_x, _y) in zones.get_active_solids(entity): if not DRAGGING_NODE: for entity_id in [t for t in entity['ai']['visible_life'] if entity['ai']['life_memory'][t]['can_see']]: if entity['_id'] == entity_id: continue _entity = entities.get_entity(entity_id) _tx, _ty = movement.get_position(_entity) if (_x, _y) == (_tx, _ty): if SELECTING_TARGET_CALLBACK: SELECTING_TARGET_CALLBACK(entity, entity_id) SELECTING_TARGET_CALLBACK = None else: LAST_CLICKED_POS = (_x, _y) create_life_interact_menu(entity, entity_id) return else: for entity_id in entities.get_entity_group('contexts'): _entity = entities.get_entity(entity_id) if not _entity['callback']: continue if (_entity['tile']['x'], _entity['tile']['y']) == (_x, _y): _entity['callback'](x+2, y-3) return else: for entity_id in list(entity['ai']['targets'] - entity['ai']['visible_life']): _tx, _ty = entity['ai']['life_memory'][entity_id]['last_seen_at'] if (_tx, _ty-2) == (_x, _y): ui_dialog.create(x + 2, y - 3, '%s - Last seen <time>' % entities.get_entity(entity_id)['stats']['name']) return else: for entity_id in entities.get_entity_group('items'): _item = entities.get_entity(entity_id) if _item['stats']['owner']: continue if (_x, _y) == movement.get_position(_item): create_item_menu(entity, _item, _x, _y) return create_walk_node(entity, _x, _y, clear=True) return for node in entity['node_grid']['nodes'].values(): if (_x, _y) == (node['node']['x'], node['node']['y']): DRAGGING_NODE = node entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 0)) break if (_x, _y) in node['node']['path']: if not (_x, _y) in node['node']['busy_pos']: LAST_CLICKED_POS = (_x, _y) create_action_menu(entity, LAST_CLICKED_POS[0], LAST_CLICKED_POS[1], on_path=True) else: LAST_CLICKED_POS = None return elif button == 2: if DRAGGING_NODE: entities.trigger_event(DRAGGING_NODE['node'], 'set_fore_color', color=(255, 255, 255)) DRAGGING_NODE = None else: for node in entity['node_grid']['nodes'].values(): if (_x, _y) == (node['node']['x'], node['node']['y']): entity['node_grid']['path'].remove(node['node']['_id']) entities.delete_entity(node['node']) redraw_path(entity) del entity['node_grid']['nodes'][node['node']['_id']] if not entity['node_grid']['nodes']: clear_path(entity) break else: create_walk_node(entity, _x, _y)
def build_life_list(entity): entity['ai']['visible_targets'] = [] _nearest_target = {'target_id': None, 'distance': 0} _solids = zones.get_active_solids(entity) _visible_life = set() _vision = stats.get_vision(entity) _visible_by_friendlies = [entities.get_entity(e)['ai']['visible_targets'] for e in entity['ai']['life_memory'] if not entity['ai']['life_memory'][e]['is_target'] and e in entities.ENTITIES] #Warning: Makes AI super smart _visible_by_friendlies = [item for sublist in _visible_by_friendlies for item in sublist] for entity_id in entities.get_entity_group('life'): if entity['_id'] == entity_id: continue _target = entities.get_entity(entity_id) if not entity_id in entity['ai']['life_memory']: life.create_life_memory(entity, entity_id) if not ai_factions.is_enemy(entity, entity_id): _visible = True else: if numbers.distance(movement.get_position(entity), movement.get_position(_target)) > _vision: if entity['ai']['life_memory'][entity_id]['can_see'] and ai_factions.is_enemy(entity, _target['_id']): entities.trigger_event(entity, 'target_lost', target_id=entity_id) if entity_id in _visible_by_friendlies: entity['ai']['life_memory'][entity_id]['in_los'] = False entity['ai']['life_memory'][entity_id]['can_see'] = True _visible = True else: entity['ai']['life_memory'][entity_id]['can_see'] = False entity['ai']['life_memory'][entity_id]['in_los'] = False if entity_id in entity['ai']['visible_life']: entity['ai']['visible_life'].remove(entity_id) _visible = False else: for pos in shapes.line(movement.get_position(entity), movement.get_position(_target)): if pos in _solids: if entity['ai']['life_memory'][entity_id]['can_see'] and ai_factions.is_enemy(entity, _target['_id']): entities.trigger_event(entity, 'target_lost', target_id=entity_id) if entity_id in _visible_by_friendlies: entity['ai']['life_memory'][entity_id]['in_los'] = False entity['ai']['life_memory'][entity_id]['can_see'] = True _visible = True else: entity['ai']['life_memory'][entity_id]['can_see'] = False entity['ai']['life_memory'][entity_id]['in_los'] = False if entity_id in entity['ai']['visible_life']: entity['ai']['visible_life'].remove(entity_id) _visible = False break else: entity['ai']['life_memory'][entity_id]['in_los'] = True _visible = True if not _visible and entity['ai']['life_memory'][entity_id]['seen_time'] > 0: _visible = True entity['ai']['life_memory'][entity_id]['in_los'] = False entity['ai']['life_memory'][entity_id]['can_see'] = True entity['ai']['life_memory'][entity_id]['seen_time'] -= 1 if entity_id in entity['ai']['visible_life']: entity['ai']['visible_life'].remove(entity_id) elif not _visible and entity_id in entity['ai']['visible_life']: entity['ai']['visible_life'].remove(entity_id) if _visible: _previous_last_seen_at = entity['ai']['life_memory'][entity_id]['last_seen_at'] _target_position = movement.get_position(_target)[:] entity['ai']['life_memory'][entity_id]['is_lost'] = False if entity['ai']['life_memory'][entity_id]['in_los']: if entity['ai']['life_memory'][entity_id]['seen_time'] < 30: entity['ai']['life_memory'][entity_id]['seen_time'] += 1 else: entity['ai']['life_memory'][entity_id]['seen_time'] -= 1 if entity['ai']['life_memory'][entity_id]['seen_time'] < 0 and entity_id in entity['ai']['visible_life']: entity['ai']['visible_life'].remove(entity_id) entity['ai']['life_memory'][entity_id]['in_los'] = False if movement.get_position(_target) == _previous_last_seen_at: _new_last_seen_at = _previous_last_seen_at else: _new_last_seen_at = _target_position _is_target = ai_factions.is_enemy(entity, _target['_id']) _profile = {'distance': numbers.distance(movement.get_position(entity), movement.get_position(_target)), 'is_target': _is_target, 'is_armed': items.get_items_in_holder(_target, 'weapon'), 'is_lost': False, 'can_see': True, 'last_seen_at': _new_last_seen_at, 'last_seen_velocity': None} if not entity_id in entity['ai']['visible_life']: entities.trigger_event(entity, 'new_target_spotted', target_id=entity_id) if entity['ai']['life_memory'][entity_id]['in_los']: entity['ai']['visible_life'].add(entity_id) if _is_target: ai_flow.register_combat(entity, entity_id) if _is_target: entity['ai']['targets'].add(entity_id) _distance = numbers.distance(movement.get_position(entity), movement.get_position_via_id(entity_id)) if not _nearest_target['target_id'] or _distance < _nearest_target['distance']: _nearest_target['distance'] = _distance _nearest_target['target_id'] = entity_id if entity['ai']['life_memory'][entity_id]['last_seen_at']: _last_seen_at = entity['ai']['life_memory'][entity_id]['last_seen_at'][:] _velocity = (_profile['last_seen_at'][0]-_last_seen_at[0], _profile['last_seen_at'][1]-_last_seen_at[1]) _profile['last_seen_velocity'] = _velocity else: _profile['last_seen_velocity'] = None if not entity['ai']['life_memory'][entity_id]['can_see'] and _is_target: _could_not_see_target_before = True else: _could_not_see_target_before = False entity['ai']['life_memory'][entity_id].update(_profile) if _could_not_see_target_before: entities.trigger_event(entity, 'target_found', target_id=entity_id) #TODO: What? #for t in entity['ai']['life_memory']: # if not 'is_lost' in entity['ai']['life_memory'][t]: # print entity['ai']['life_memory'][t] entity['ai']['visible_targets'] = list(entity['ai']['visible_life'] & entity['ai']['targets']) entity['ai']['targets_to_search'] = [t for t in entity['ai']['life_memory'].keys() if entity['ai']['life_memory'][t]['is_lost'] and not entity['ai']['life_memory'][t]['searched_for'] and t in entities.ENTITIES] if _nearest_target['target_id']: if not entity['ai']['nearest_target'] == _nearest_target['target_id']: entity['ai']['meta']['has_firing_position'] = True entity['ai']['nearest_target'] = _nearest_target['target_id'] elif entity['ai']['targets']: for target_id in list(entity['ai']['targets']): _target = entity['ai']['life_memory'][target_id] if not target_id in entities.ENTITIES or _target['is_lost']: entity['ai']['targets'].remove(target_id) continue _distance = numbers.distance(movement.get_position(entity), _target['last_seen_at']) if not _nearest_target['target_id'] or _distance < _nearest_target['distance']: _nearest_target['target_id'] = target_id _nearest_target['distance'] = _distance if not entity['ai']['nearest_target'] == _nearest_target['target_id']: entity['ai']['meta']['has_firing_position'] = True entity['ai']['nearest_target'] = _nearest_target['target_id']
def get_active_life_positions(entity): return [ movement.get_position_via_id(p) for p in entities.get_entity_group('life') if not p == entity['_id'] ]
def all_logic(): for mission_id in entities.get_entity_group('missions'): _mission = entities.get_entity(mission_id) entities.trigger_event(_mission, 'logic')
def draw_all(): for menu_id in entities.get_entity_group('ui_menus'): draw(entities.get_entity(menu_id))
def loop(): global PLAYER_HAS_SHOOT_TIMER events.trigger_event('input') if not settings.TICK_MODE == 'strategy' and not ((ui_dialog.ACTIVE_DIALOG and ui_director.PAUSE) or ui_menu.ACTIVE_MENU or ui_director.PAUSE): _has_action = False _check_life = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _check_life.add(member_id) _check_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES]) _check_life = list(_check_life) #_check_life = #_check_life.append(PLAYER['_id']) for entity_id in _check_life: if timers.has_timer_with_name(entities.get_entity(entity_id), 'shoot'): _has_action = True break if _has_action: _ticks_per_tick = 1 else: _ticks_per_tick = settings.PLAN_TICK_RATE for _ in range(_ticks_per_tick): if settings.TICK_MODE == 'strategy': break ai_flow.logic() events.trigger_event('logic') tick() free_tick() else: ai_flow.logic() free_tick() if pathfinding.wait_for_astar(): pass if not handle_input(): return False events.trigger_event('tick') events.trigger_event('camera') draw() return True
def draw(): global MOVIE_TIME, MOVIE_TIME_MAX if settings.OBSERVER_MODE: _draw_life = entities.get_entity_group('life') _draw_items = entities.get_entity_group('items') else: _draw_life = set() _draw_items = set() for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _member = entities.get_entity(member_id) _draw_life.add(member_id) _draw_life.update([i for i in _member['ai']['life_memory'] if _member['ai']['life_memory'][i]['can_see'] and i in entities.ENTITIES]) _draw_life = list(_draw_life) for entity_id in _draw_life: entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in entities.get_entity_group('nodes'): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) if settings.SHOW_NODE_GRID: for entity_id in zones.get_active_node_grid().values(): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in entities.get_entity_groups(['ui_effects', 'ui_effects_freetick']): entities.trigger_event(entities.get_entity(entity_id), 'draw') for entity_id in entities.get_entity_groups(['effects', 'effects_freetick']): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in entities.get_entity_group('contexts'): entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) for entity_id in _draw_items: if not entity_id in entities.ENTITIES: continue _entity = entities.get_entity(entity_id) if _entity['stats']['owner']: continue entities.trigger_event(entities.get_entity(entity_id), 'draw', x_mod=camera.X, y_mod=camera.Y) ui_draw.draw_status_bar(planning=settings.TICK_MODE == 'strategy', executing=not settings.TICK_MODE == 'strategy', execute_speed=settings.PLAN_TICK_RATE_STRING, selecting=nodes.SELECTING_TARGET_CALLBACK) #if settings.TICK_MODE == 'strategy': # ui_draw.draw_item_labels() if '--labels' in sys.argv: ui_draw.draw_life_labels() ui_draw.draw_long_range_life() ui_draw.draw_life_memory() ui_draw.draw_walk_path() #ui_draw.draw_mission_details() ui_draw.draw_turn_bar() if '--fps' in sys.argv: ui_draw.draw_fps() events.trigger_event('post_process') #display.reset_surface_shaders('tiles') #_zone = zones.ZONES[zones.ACTIVE_ZONE] #for shader in _zone['shaders']: # display.apply_surface_shader('tiles', shader, constants.MAP_VIEW_WIDTH, constants.MAP_VIEW_HEIGHT) if ui_director.HAS_FOCUS: ui_director.draw() display.blit_surface('effects') display.blit_surface('nodes') display.blit_surface('items') display.blit_surface('life') display.blit_surface('ui') display.blit_surface('ui_menus') display.blit_surface('ui_dialogs') if ui_panel.ACTIVE_MENU: display.blit_surface_viewport('ui_inventory', 0, 0, 35, constants.MAP_VIEW_HEIGHT, dx=constants.MAP_VIEW_WIDTH-35) if settings.SHOW_NODE_GRID: display.blit_surface('node_grid') events.trigger_event('draw') if '--record' in sys.argv: MOVIE_TIME += 1 if MOVIE_TIME == MOVIE_TIME_MAX: display.screenshot('screenshot-%s.bmp' % time.time()) MOVIE_TIME = 0
def post_tick(): for entity_id in entities.get_entity_group('life'): entities.trigger_event(entities.get_entity(entity_id), 'post_tick')
def free_tick(): for entity_id in entities.get_entity_group('effects_freetick'): entities.trigger_event(entities.get_entity(entity_id), 'tick') entities.trigger_event(FADER, 'tick')
def handle_mouse_pressed(x, y, button): global SELECTED_SQUAD, SELECTED_CAMP, MAP_PATH _s1, _s2 = entities.get_entity_group('squads')[:2] _m_x, _m_y = x / constants.MAP_CELL_SPACE, y / constants.MAP_CELL_SPACE if button == 1: _camp = MAP['grid'][_m_x, _m_y] if _camp['owned_by'] == 'Rogues' and not SELECTED_CAMP: SELECTED_CAMP = (_m_x, _m_y) set_draw_mode('camp_info') elif not _camp['owned_by'] == 'Rogues': if SELECTED_SQUAD: if _camp['owned_by']: SELECTED_CAMP = (_m_x, _m_y) MAP_PATH = pathfinding.astar( movement.get_position_via_id(_s1), (_m_x, _m_y), MAP['astar_map'], MAP['astar_weight_map']) set_draw_mode('raid') elif _camp['is_ownable']: SELECTED_CAMP = (_m_x, _m_y) set_draw_mode('occupy') else: SELECTED_SQUAD = None SELECTED_CAMP = None set_draw_mode('news') #set_draw_mode('camp_info') else: for squad_id in entities.get_entity_group('squads'): if squad_id == SELECTED_SQUAD: continue _squad = entities.get_entity(squad_id) if not movement.get_position(_squad) == (_m_x, _m_y): continue if not _squad['faction'] == 'Rogues': continue SELECTED_SQUAD = squad_id SELECTED_CAMP = None set_draw_mode('squad_info') break elif button == 2: _camp = MAP['grid'][_m_x, _m_y] if not _camp['owned_by'] == 'Rogues': if SELECTED_SQUAD: if DRAW_MODE == 'raid': entities.trigger_event(entities.get_entity(SELECTED_SQUAD), 'raid', camp_id=(_m_x, _m_y)) SELECTED_SQUAD = None SELECTED_CAMP = None set_draw_mode('news')
def create(): global MAP, FADER worlds.create('strategy') words.reset() display.create_surface('background') display.create_surface('map', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('map_markers', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('map_squads', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('map_path', width=constants.STRAT_MAP_WIDTH, height=constants.STRAT_MAP_HEIGHT) display.create_surface('ui_bar', width=constants.WINDOW_WIDTH, height=constants.WINDOW_HEIGHT - constants.STRAT_MAP_HEIGHT) display.fill_surface('ui_bar', (30, 30, 30)) display.blit_background('background') register_input() entities.create_entity_group('life', static=True) entities.create_entity_group('items', static=True) entities.create_entity_group('factions', static=True) entities.create_entity_group('squads', static=True) entities.create_entity_group('systems') FADER = entities.create_entity() timers.register(FADER) fade_in() _grid = {} _color_map = {} MAP = { 'grid': _grid, 'color_map': _color_map, 'astar_map': None, 'astar_weight_map': numpy.ones((constants.STRAT_MAP_HEIGHT / constants.MAP_CELL_SPACE, constants.STRAT_MAP_WIDTH / constants.MAP_CELL_SPACE)) } for x in range(constants.STRAT_MAP_WIDTH / constants.MAP_CELL_SPACE): for y in range(constants.STRAT_MAP_HEIGHT / constants.MAP_CELL_SPACE): _grid[x, y] = { 'owned_by': None, 'is_ownable': False, 'squads': [], 'income': .025 } worldgen.generate() unregister_input() world_action._start_battle( attacking_squads=[entities.get_entity_group('squads')[0]], defending_squads=[entities.get_entity_group('squads')[1]])
def get_active_life_positions(entity): return [movement.get_position_via_id(p) for p in entities.get_entity_group('life') if not p == entity['_id']]
def handle_mouse_pressed(x, y, button): global SELECTED_SQUAD, SELECTED_CAMP, MAP_PATH _s1, _s2 = entities.get_entity_group('squads')[:2] _m_x, _m_y = x / constants.MAP_CELL_SPACE, y / constants.MAP_CELL_SPACE if button == 1: _camp = MAP['grid'][_m_x, _m_y] if _camp['owned_by'] == 'Rogues' and not SELECTED_CAMP: SELECTED_CAMP = (_m_x, _m_y) set_draw_mode('camp_info') elif not _camp['owned_by'] == 'Rogues': if SELECTED_SQUAD: if _camp['owned_by']: SELECTED_CAMP = (_m_x, _m_y) MAP_PATH = pathfinding.astar(movement.get_position_via_id(_s1), (_m_x, _m_y), MAP['astar_map'], MAP['astar_weight_map']) set_draw_mode('raid') elif _camp['is_ownable']: SELECTED_CAMP = (_m_x, _m_y) set_draw_mode('occupy') else: SELECTED_SQUAD = None SELECTED_CAMP = None set_draw_mode('news') #set_draw_mode('camp_info') else: for squad_id in entities.get_entity_group('squads'): if squad_id == SELECTED_SQUAD: continue _squad = entities.get_entity(squad_id) if not movement.get_position(_squad) == (_m_x, _m_y): continue if not _squad['faction'] == 'Rogues': continue SELECTED_SQUAD = squad_id SELECTED_CAMP = None set_draw_mode('squad_info') break elif button == 2: _camp = MAP['grid'][_m_x, _m_y] if not _camp['owned_by'] == 'Rogues': if SELECTED_SQUAD: if DRAW_MODE == 'raid': entities.trigger_event(entities.get_entity(SELECTED_SQUAD), 'raid', camp_id=(_m_x, _m_y)) SELECTED_SQUAD = None SELECTED_CAMP = None set_draw_mode('news')
def tick(): if settings.TURN_QUEUE: _squads = [settings.TURN_QUEUE[0]] else: _squads = entities.get_entity_group('squads') _found_able_player = False for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) _break = False if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _entity = entities.get_entity(member_id) if _entity['ai']['is_npc']: continue if timers.has_timer_with_name(_entity, 'shoot') or _entity['movement']['path']['positions'] or timers.has_timer_with_name(_entity, 'move'): _break = True break _found_able_player = True if _break: break else: if _found_able_player: settings.set_tick_mode('strategy') for squad_id in _squads: _squad = entities.get_entity(squad_id) _waiting = False #if not _squad['faction'] == 'Rogues': # settings.set_tick_mode('normal') for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) if not settings.TURN_QUEUE: _entity['stats']['action_points'] = _entity['stats']['action_points_max'] if _entity['ai']['is_npc']: continue if _entity['stats']['action_points'] <= 0: continue _had_action = False if timers.has_timer_with_name(_entity, 'shoot') or _entity['movement']['path']['positions'] or timers.has_timer_with_name(_entity, 'move'): _had_action = True elif _entity['ai']['is_player']: _waiting = True continue entities.trigger_event(_entity, 'tick') if _had_action and not timers.has_timer_with_name(_entity, 'shoot') and not _entity['movement']['path']['positions'] and not timers.has_timer_with_name(_entity, 'move') and _entity['stats']['action_points'] > 0: if _entity['ai']['is_player'] and (ui_squad_control.is_squad_member_selected() and _entity == ui_squad_control.get_selected_squad_member()): settings.set_tick_mode('strategy') break if _entity['ai']['is_player'] and _entity['stats']['action_points'] <= 0: ui_squad_control.reset_selected_squad_member() settings.set_tick_mode('strategy') if not _entity['movement']['path']['positions'] and not timers.has_timer_with_name(_entity, 'shoot') and not timers.has_timer_with_name(_entity, 'move'): _entity['stats']['action_points'] -= constants.IDLE_COST if _entity['stats']['action_points'] <= 0:# and list(_squad['members']).index(entity_id)+1 == len(_squad['members']): entities.trigger_event(_squad, 'update_position_map') #print _entity['stats']['name'], _entity['stats']['action_points'] break else: if _entity['ai']['is_player'] and not _waiting: settings.set_tick_mode('normal') print 'Normal...'
def tick(): if settings.TURN_QUEUE: _squads = [settings.TURN_QUEUE[0]] else: _squads = entities.get_entity_group('squads') _found_able_player = False for squad_id in entities.get_entity_group('squads'): _squad = entities.get_entity(squad_id) _break = False if not _squad['faction'] == 'Rogues': continue for member_id in _squad['members']: _entity = entities.get_entity(member_id) if _entity['ai']['is_npc']: continue if timers.has_timer_with_name( _entity, 'shoot') or _entity['movement']['path'][ 'positions'] or timers.has_timer_with_name( _entity, 'move'): _break = True break _found_able_player = True if _break: break else: if _found_able_player: settings.set_tick_mode('strategy') for squad_id in _squads: _squad = entities.get_entity(squad_id) _waiting = False #if not _squad['faction'] == 'Rogues': # settings.set_tick_mode('normal') for entity_id in _squad['members']: _entity = entities.get_entity(entity_id) if not settings.TURN_QUEUE: _entity['stats']['action_points'] = _entity['stats'][ 'action_points_max'] if _entity['ai']['is_npc']: continue if _entity['stats']['action_points'] <= 0: continue _had_action = False if timers.has_timer_with_name( _entity, 'shoot') or _entity['movement']['path'][ 'positions'] or timers.has_timer_with_name( _entity, 'move'): _had_action = True elif _entity['ai']['is_player']: _waiting = True continue entities.trigger_event(_entity, 'tick') if _had_action and not timers.has_timer_with_name( _entity, 'shoot') and not _entity['movement']['path'][ 'positions'] and not timers.has_timer_with_name( _entity, 'move') and _entity['stats']['action_points'] > 0: if _entity['ai']['is_player'] and ( ui_squad_control.is_squad_member_selected() and _entity == ui_squad_control.get_selected_squad_member()): settings.set_tick_mode('strategy') break if _entity['ai'][ 'is_player'] and _entity['stats']['action_points'] <= 0: ui_squad_control.reset_selected_squad_member() settings.set_tick_mode('strategy') if not _entity['movement']['path'][ 'positions'] and not timers.has_timer_with_name( _entity, 'shoot') and not timers.has_timer_with_name( _entity, 'move'): _entity['stats']['action_points'] -= constants.IDLE_COST if _entity['stats'][ 'action_points'] <= 0: # and list(_squad['members']).index(entity_id)+1 == len(_squad['members']): entities.trigger_event(_squad, 'update_position_map') #print _entity['stats']['name'], _entity['stats']['action_points'] break else: if _entity['ai']['is_player'] and not _waiting: settings.set_tick_mode('normal') print 'Normal...'