Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
def _create_animal(x, y, health, speed, name, vision=65, faction='Mutants', has_ai=False, char='m', fore_color=(255, 255, 255)):
	_entity = entities.create_entity(group='life')
	
	entities.create_event(_entity, 'damage')
	entities.create_event(_entity, 'did_damage')
	entities.create_event(_entity, 'receive_memory')
	entities.create_event(_entity, 'handle_corpse')
	entities.create_event(_entity, 'finish_turn')

	tile.register(_entity, surface='life', char=char, fore_color=fore_color)
	movement.register(_entity, collisions=True)
	timers.register(_entity)
	stats.register(_entity, health, speed, vision, name=name, kind='animal')
	nodes.register(_entity)
	items.register(_entity)
	flags.register(_entity)
	noise.register(_entity)
	skeleton.register(_entity)
	ai_factions.register(_entity, faction)

	if has_ai:
		ai.register_animal(_entity)
	
	_entity['ai']['is_npc'] = True

	entities.register_event(_entity, 'finish_turn', finish_turn)
	entities.create_event(_entity, 'get_and_store_item')
	entities.create_event(_entity, 'get_and_hold_item')
	entities.create_event(_entity, 'reload')
	entities.create_event(_entity, 'shoot')
	entities.create_event(_entity, 'damage')
	entities.register_event(_entity, 'post_tick', ai_visuals.cleanup)
	entities.register_event(_entity, 'get_and_store_item', get_and_store_item)
	entities.register_event(_entity, 'get_and_hold_item', get_and_hold_item)
	entities.register_event(_entity, 'reload', reload_weapon)
	entities.register_event(_entity, 'shoot', shoot_weapon)
	entities.register_event(_entity, 'heard_noise', handle_heard_noise)
	entities.register_event(_entity, 'position_changed',
	                        lambda e, **kwargs: entities.trigger_event(e,
	                                                                   'create_noise',
	                                                                   volume=25,
	                                                                   text='?',
	                                                                   owner_can_hear=False,
	                                                                   callback=lambda t, x, y: entities.trigger_event(t,
	                                                                                                            'update_target_memory',
	                                                                                                            target_id=_entity['_id'],
	                                                                                                            key='last_seen_at',
	                                                                                                            value=[x, y])))
	#entities.register_event(_entity, 'position_changed', lambda e, **kwargs: ai_visuals.add_to_moved_life(e))
	entities.register_event(_entity, 'push', lambda e, **kwargs: movement.sub_move_cost(e))
	                        
	entities.trigger_event(_entity, 'set_position', x=x, y=y)
	entities.trigger_event(_entity, 'create_holder', name='weapon', max_weight=10)
	entities.trigger_event(_entity, 'create_holder', name='backpack', max_weight=10)

	return _entity
Exemple #7
0
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))
Exemple #8
0
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))
Exemple #9
0
def blood_splatter(x, y, direction):
	_blood = _create(x, y)
	_x, _y = (int(round(x)), int(round(y)))
	
	blood(_x, _y)
	
	flags.register(_blood)
	timers.register(_blood)
	
	entities.trigger_event(_blood, 'set_direction', direction=direction)
	#entities.trigger_event(_blood, 'set_flag', flag='speed', value=random.)
	
	entities.trigger_event(_blood, 'create_timer', time=random.randint(24, 32), repeat=random.randint(2, 3), repeat_callback=_blood_splatter_push,
	                       exit_callback=entities.delete_entity)
Exemple #10
0
def smoke_shooter(x, y, direction):
	_blood = _create(x, y)
	_x, _y = (int(round(x)), int(round(y)))
	
	_v_x, _v_y = numbers.velocity(direction, random.randint(4, 6))
	
	_x = int(round(_x + _v_x))
	_y = int(round(_y + _v_y))
	
	flags.register(_blood)
	timers.register(_blood)
	
	entities.trigger_event(_blood, 'set_flag', flag='alpha', value=1.0)
	
	entities.trigger_event(_blood, 'set_direction', direction=direction)
	
	entities.trigger_event(_blood, 'create_timer', time=random.randint(3, 6), repeat=random.randint(2, 4), repeat_callback=_smoke_shooter_push,
	                       exit_callback=entities.delete_entity)
Exemple #11
0
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
Exemple #12
0
def _create_human(x, y, health, speed, name, vision=50, faction='Rogues', is_player=False, has_ai=False, fore_color=(255, 255, 255)):
	_entity = entities.create_entity(group='life')
	
	entities.create_event(_entity, 'get_and_store_item')
	entities.create_event(_entity, 'get_and_hold_item')
	entities.create_event(_entity, 'reload')
	entities.create_event(_entity, 'shoot')
	entities.create_event(_entity, 'damage')
	entities.create_event(_entity, 'did_damage')
	entities.create_event(_entity, 'receive_memory')
	entities.create_event(_entity, 'handle_corpse')
	entities.create_event(_entity, 'finish_turn')

	tile.register(_entity, surface='life', char='@', fore_color=fore_color)
	movement.register(_entity, collisions=True)
	timers.register(_entity)
	stats.register(_entity, health, speed, vision, name=name, kind='human')
	nodes.register(_entity)
	items.register(_entity)
	flags.register(_entity)
	noise.register(_entity)
	missions.register(_entity)
	skeleton.register(_entity)
	skeleton.create_motion(_entity, 'stand')
	skeleton.create_motion(_entity, 'crouch', stat_mod={'mobility': 1.55})
	skeleton.create_motion(_entity, 'crawl', stat_mod={'mobility': 2.3})
	skeleton.create_limb(_entity, 'head', [], True, 0.1, stat_mod={'vision': .75})
	skeleton.create_limb(_entity, 'chest', ['head'], True, 0.88, stat_mod={'mobility': .1})
	skeleton.create_limb(_entity, 'torso', ['chest'], True, 0.75, stat_mod={'mobility': .6})
	skeleton.create_limb(_entity, 'left arm', ['chest'], False, 0.3, can_sever=True, stat_mod={'accuracy': .22})
	skeleton.create_limb(_entity, 'right arm', ['chest'], False, 0.3, can_sever=True, stat_mod={'accuracy': .22})
	skeleton.create_limb(_entity, 'left leg', ['torso'], False, 0.45, can_sever=True, stat_mod={'mobility': .4})
	skeleton.create_limb(_entity, 'right leg', ['torso'], False, 0.45, can_sever=True, stat_mod={'mobility': .4})

	if has_ai:
		ai.register_human(_entity)
	
	ai_factions.register(_entity, faction)
	
	_entity['ai']['is_player'] = is_player
	_entity['ai']['is_npc'] = not is_player
	
	if faction == 'Rogues':
		entities.register_event(_entity,
		                        'did_damage',
		                        lambda e, target_id, damage: effects.printer(entities.get_entity(target_id)['tile']['x'],
		                                            entities.get_entity(target_id)['tile']['y']-1,
		                                            '%s' % damage,
		                                            fore_color=(200, 0, 0),
		                                            speed_mod=0.3,
		                                            show_mod=1.0,
		                                            moving=True,
		                                            center=True))
		entities.register_event(_entity,
		                        'log_kill',
		                        lambda e, target_id: effects.printer(entities.get_entity(target_id)['tile']['x'],
		                                            entities.get_entity(target_id)['tile']['y']-1,
		                                            'KILL',
		                                            fore_color=(255, 0, 0),
		                                            speed_mod=0.3,
		                                            show_mod=1.0,
		                                            moving=True,
		                                            center=True))

	entities.register_event(_entity, 'finish_turn', finish_turn)
	entities.register_event(_entity, 'post_tick', ai_visuals.cleanup)
	entities.register_event(_entity, 'get_and_store_item', get_and_store_item)
	entities.register_event(_entity, 'get_and_hold_item', get_and_hold_item)
	entities.register_event(_entity, 'reload', reload_weapon)
	entities.register_event(_entity, 'shoot', shoot_weapon)
	entities.register_event(_entity, 'heard_noise', handle_heard_noise)
	entities.register_event(_entity, 'position_changed',
	                        lambda e, **kwargs: entities.trigger_event(e,
	                                                                   'create_noise',
	                                                                   volume=25,
	                                                                   text='?',
	                                                                   callback=lambda t, x, y: entities.trigger_event(t,
	                                                                                                            'update_target_memory',
	                                                                                                            target_id=_entity['_id'],
	                                                                                                            key='last_seen_at',
	                                                                                                            value=[x, y])))
	#entities.register_event(_entity, 'damage',
	#                        lambda e, **kwargs: entities.trigger_event(e,
	#                                                                   'create_noise',
	#                                                                   volume=12,
	#                                                                   text='Ow!',
	#                                                                   owner_can_hear=True,
	#                                                                   show_on_sight=True,
	#                                                                   callback=lambda t, x, y: entities.trigger_event(t,
	#                                                                                                            'update_target_memory',
	#                                                                                                            target_id=_entity['_id'],
	#                                                                                                            key='last_seen_at',
	#                                                                                                            value=[x, y])))
	#entities.register_event(_entity, 'position_changed', lambda e, **kwargs: ai_visuals.add_to_moved_life(e))
	entities.register_event(_entity, 'push', lambda e, **kwargs: movement.sub_move_cost(e))
	                        
	entities.trigger_event(_entity, 'set_position', x=x, y=y)
	entities.trigger_event(_entity, 'create_holder', name='weapon', max_weight=10)
	entities.trigger_event(_entity, 'create_holder', name='backpack', max_weight=10)
	
	_get_and_hold_item(_entity, items.leather_backpack(20, 20)['_id'])

	return _entity
Exemple #13
0
def _create_robot(x, y, health, speed, name, vision=30, faction='Rogues', is_player=False, has_ai=True, fore_color=(200, 200, 200)):
	_entity = entities.create_entity(group='life')
	
	entities.create_event(_entity, 'get_and_store_item')
	entities.create_event(_entity, 'get_and_hold_item')
	entities.create_event(_entity, 'reload')
	entities.create_event(_entity, 'shoot')
	entities.create_event(_entity, 'damage')
	entities.create_event(_entity, 'did_damage')
	entities.create_event(_entity, 'receive_memory')
	entities.create_event(_entity, 'handle_corpse')
	entities.create_event(_entity, 'finish_turn')

	tile.register(_entity, surface='life', char='@', fore_color=fore_color)
	movement.register(_entity, collisions=True)
	timers.register(_entity)
	stats.register(_entity, health, speed, vision, name=name, kind='human')
	nodes.register(_entity)
	items.register(_entity)
	flags.register(_entity)
	noise.register(_entity)
	missions.register(_entity)
	skeleton.register(_entity)

	if has_ai:
		ai.register_robot(_entity)
	
	ai_factions.register(_entity, faction)
	
	_entity['ai']['is_player'] = is_player
	_entity['ai']['is_npc'] = not is_player
	
	if is_player:
		entities.register_event(_entity,
		                        'did_damage',
		                        lambda e, target_id, damage: effects.printer(entities.get_entity(target_id)['tile']['x'],
		                                            entities.get_entity(target_id)['tile']['y']-1,
		                                            '%s' % damage,
		                                            fore_color=(200, 0, 0),
		                                            speed_mod=0.3,
		                                            show_mod=1.0,
		                                            moving=True,
		                                            center=True))
		entities.register_event(_entity,
		                        'log_kill',
		                        lambda e, target_id: effects.printer(entities.get_entity(target_id)['tile']['x'],
		                                            entities.get_entity(target_id)['tile']['y']-1,
		                                            'KILL',
		                                            fore_color=(255, 0, 0),
		                                            speed_mod=0.3,
		                                            show_mod=1.0,
		                                            moving=True,
		                                            center=True))

	entities.register_event(_entity, 'delete', _handle_robot_death)
	entities.register_event(_entity, 'finish_turn', finish_turn)
	entities.register_event(_entity, 'post_tick', ai_visuals.cleanup)
	entities.register_event(_entity, 'get_and_store_item', get_and_store_item)
	entities.register_event(_entity, 'get_and_hold_item', get_and_hold_item)
	entities.register_event(_entity, 'reload', reload_weapon)
	entities.register_event(_entity, 'shoot', shoot_weapon)
	entities.register_event(_entity, 'heard_noise', handle_heard_noise)
	entities.register_event(_entity, 'position_changed',
	                        lambda e, **kwargs: entities.trigger_event(e,
	                                                                   'create_noise',
	                                                                   volume=25,
	                                                                   text='?',
	                                                                   callback=lambda t, x, y: entities.trigger_event(t,
	                                                                                                            'update_target_memory',
	                                                                                                            target_id=_entity['_id'],
	                                                                                                            key='last_seen_at',
	                                                                                                            value=[x, y])))
	entities.register_event(_entity, 'push', lambda e, **kwargs: movement.sub_move_cost(e))
	                        
	entities.trigger_event(_entity, 'set_position', x=x, y=y)
	entities.trigger_event(_entity, 'create_holder', name='weapon', max_weight=10)
	entities.trigger_event(_entity, 'create_holder', name='backpack', max_weight=10)
	
	_get_and_hold_item(_entity, items.leather_backpack(20, 20)['_id'])

	return _entity
Exemple #14
0
def _create_human(x,
                  y,
                  health,
                  speed,
                  name,
                  vision=50,
                  faction='Rogues',
                  is_player=False,
                  has_ai=False,
                  fore_color=(255, 255, 255)):
    _entity = entities.create_entity(group='life')

    entities.create_event(_entity, 'get_and_store_item')
    entities.create_event(_entity, 'get_and_hold_item')
    entities.create_event(_entity, 'reload')
    entities.create_event(_entity, 'shoot')
    entities.create_event(_entity, 'damage')
    entities.create_event(_entity, 'did_damage')
    entities.create_event(_entity, 'receive_memory')
    entities.create_event(_entity, 'handle_corpse')
    entities.create_event(_entity, 'finish_turn')

    tile.register(_entity, surface='life', char='@', fore_color=fore_color)
    movement.register(_entity, collisions=True)
    timers.register(_entity)
    stats.register(_entity, health, speed, vision, name=name, kind='human')
    nodes.register(_entity)
    items.register(_entity)
    flags.register(_entity)
    noise.register(_entity)
    missions.register(_entity)
    skeleton.register(_entity)
    skeleton.create_motion(_entity, 'stand')
    skeleton.create_motion(_entity, 'crouch', stat_mod={'mobility': 1.55})
    skeleton.create_motion(_entity, 'crawl', stat_mod={'mobility': 2.3})
    skeleton.create_limb(_entity,
                         'head', [],
                         True,
                         0.1,
                         stat_mod={'vision': .75})
    skeleton.create_limb(_entity,
                         'chest', ['head'],
                         True,
                         0.88,
                         stat_mod={'mobility': .1})
    skeleton.create_limb(_entity,
                         'torso', ['chest'],
                         True,
                         0.75,
                         stat_mod={'mobility': .6})
    skeleton.create_limb(_entity,
                         'left arm', ['chest'],
                         False,
                         0.3,
                         can_sever=True,
                         stat_mod={'accuracy': .22})
    skeleton.create_limb(_entity,
                         'right arm', ['chest'],
                         False,
                         0.3,
                         can_sever=True,
                         stat_mod={'accuracy': .22})
    skeleton.create_limb(_entity,
                         'left leg', ['torso'],
                         False,
                         0.45,
                         can_sever=True,
                         stat_mod={'mobility': .4})
    skeleton.create_limb(_entity,
                         'right leg', ['torso'],
                         False,
                         0.45,
                         can_sever=True,
                         stat_mod={'mobility': .4})

    if has_ai:
        ai.register_human(_entity)

    ai_factions.register(_entity, faction)

    _entity['ai']['is_player'] = is_player
    _entity['ai']['is_npc'] = not is_player

    if faction == 'Rogues':
        entities.register_event(
            _entity, 'did_damage', lambda e, target_id, damage: effects.
            printer(entities.get_entity(target_id)['tile']['x'],
                    entities.get_entity(target_id)['tile']['y'] - 1,
                    '%s' % damage,
                    fore_color=(200, 0, 0),
                    speed_mod=0.3,
                    show_mod=1.0,
                    moving=True,
                    center=True))
        entities.register_event(
            _entity, 'log_kill', lambda e, target_id: effects.printer(
                entities.get_entity(target_id)['tile']['x'],
                entities.get_entity(target_id)['tile']['y'] - 1,
                'KILL',
                fore_color=(255, 0, 0),
                speed_mod=0.3,
                show_mod=1.0,
                moving=True,
                center=True))

    entities.register_event(_entity, 'finish_turn', finish_turn)
    entities.register_event(_entity, 'post_tick', ai_visuals.cleanup)
    entities.register_event(_entity, 'get_and_store_item', get_and_store_item)
    entities.register_event(_entity, 'get_and_hold_item', get_and_hold_item)
    entities.register_event(_entity, 'reload', reload_weapon)
    entities.register_event(_entity, 'shoot', shoot_weapon)
    entities.register_event(_entity, 'heard_noise', handle_heard_noise)
    entities.register_event(
        _entity, 'position_changed', lambda e, **kwargs: entities.
        trigger_event(e,
                      'create_noise',
                      volume=25,
                      text='?',
                      callback=lambda t, x, y: entities.trigger_event(
                          t,
                          'update_target_memory',
                          target_id=_entity['_id'],
                          key='last_seen_at',
                          value=[x, y])))
    #entities.register_event(_entity, 'damage',
    #                        lambda e, **kwargs: entities.trigger_event(e,
    #                                                                   'create_noise',
    #                                                                   volume=12,
    #                                                                   text='Ow!',
    #                                                                   owner_can_hear=True,
    #                                                                   show_on_sight=True,
    #                                                                   callback=lambda t, x, y: entities.trigger_event(t,
    #                                                                                                            'update_target_memory',
    #                                                                                                            target_id=_entity['_id'],
    #                                                                                                            key='last_seen_at',
    #                                                                                                            value=[x, y])))
    #entities.register_event(_entity, 'position_changed', lambda e, **kwargs: ai_visuals.add_to_moved_life(e))
    entities.register_event(_entity, 'push',
                            lambda e, **kwargs: movement.sub_move_cost(e))

    entities.trigger_event(_entity, 'set_position', x=x, y=y)
    entities.trigger_event(_entity,
                           'create_holder',
                           name='weapon',
                           max_weight=10)
    entities.trigger_event(_entity,
                           'create_holder',
                           name='backpack',
                           max_weight=10)

    _get_and_hold_item(_entity, items.leather_backpack(20, 20)['_id'])

    return _entity
Exemple #15
0
def _create_robot(x,
                  y,
                  health,
                  speed,
                  name,
                  vision=30,
                  faction='Rogues',
                  is_player=False,
                  has_ai=True,
                  fore_color=(200, 200, 200)):
    _entity = entities.create_entity(group='life')

    entities.create_event(_entity, 'get_and_store_item')
    entities.create_event(_entity, 'get_and_hold_item')
    entities.create_event(_entity, 'reload')
    entities.create_event(_entity, 'shoot')
    entities.create_event(_entity, 'damage')
    entities.create_event(_entity, 'did_damage')
    entities.create_event(_entity, 'receive_memory')
    entities.create_event(_entity, 'handle_corpse')
    entities.create_event(_entity, 'finish_turn')

    tile.register(_entity, surface='life', char='@', fore_color=fore_color)
    movement.register(_entity, collisions=True)
    timers.register(_entity)
    stats.register(_entity, health, speed, vision, name=name, kind='human')
    nodes.register(_entity)
    items.register(_entity)
    flags.register(_entity)
    noise.register(_entity)
    missions.register(_entity)
    skeleton.register(_entity)

    if has_ai:
        ai.register_robot(_entity)

    ai_factions.register(_entity, faction)

    _entity['ai']['is_player'] = is_player
    _entity['ai']['is_npc'] = not is_player

    if is_player:
        entities.register_event(
            _entity, 'did_damage', lambda e, target_id, damage: effects.
            printer(entities.get_entity(target_id)['tile']['x'],
                    entities.get_entity(target_id)['tile']['y'] - 1,
                    '%s' % damage,
                    fore_color=(200, 0, 0),
                    speed_mod=0.3,
                    show_mod=1.0,
                    moving=True,
                    center=True))
        entities.register_event(
            _entity, 'log_kill', lambda e, target_id: effects.printer(
                entities.get_entity(target_id)['tile']['x'],
                entities.get_entity(target_id)['tile']['y'] - 1,
                'KILL',
                fore_color=(255, 0, 0),
                speed_mod=0.3,
                show_mod=1.0,
                moving=True,
                center=True))

    entities.register_event(_entity, 'delete', _handle_robot_death)
    entities.register_event(_entity, 'finish_turn', finish_turn)
    entities.register_event(_entity, 'post_tick', ai_visuals.cleanup)
    entities.register_event(_entity, 'get_and_store_item', get_and_store_item)
    entities.register_event(_entity, 'get_and_hold_item', get_and_hold_item)
    entities.register_event(_entity, 'reload', reload_weapon)
    entities.register_event(_entity, 'shoot', shoot_weapon)
    entities.register_event(_entity, 'heard_noise', handle_heard_noise)
    entities.register_event(
        _entity, 'position_changed', lambda e, **kwargs: entities.
        trigger_event(e,
                      'create_noise',
                      volume=25,
                      text='?',
                      callback=lambda t, x, y: entities.trigger_event(
                          t,
                          'update_target_memory',
                          target_id=_entity['_id'],
                          key='last_seen_at',
                          value=[x, y])))
    entities.register_event(_entity, 'push',
                            lambda e, **kwargs: movement.sub_move_cost(e))

    entities.trigger_event(_entity, 'set_position', x=x, y=y)
    entities.trigger_event(_entity,
                           'create_holder',
                           name='weapon',
                           max_weight=10)
    entities.trigger_event(_entity,
                           'create_holder',
                           name='backpack',
                           max_weight=10)

    _get_and_hold_item(_entity, items.leather_backpack(20, 20)['_id'])

    return _entity
Exemple #16
0
def _create_animal(x,
                   y,
                   health,
                   speed,
                   name,
                   vision=65,
                   faction='Mutants',
                   has_ai=False,
                   char='m',
                   fore_color=(255, 255, 255)):
    _entity = entities.create_entity(group='life')

    entities.create_event(_entity, 'damage')
    entities.create_event(_entity, 'did_damage')
    entities.create_event(_entity, 'receive_memory')
    entities.create_event(_entity, 'handle_corpse')
    entities.create_event(_entity, 'finish_turn')

    tile.register(_entity, surface='life', char=char, fore_color=fore_color)
    movement.register(_entity, collisions=True)
    timers.register(_entity)
    stats.register(_entity, health, speed, vision, name=name, kind='animal')
    nodes.register(_entity)
    items.register(_entity)
    flags.register(_entity)
    noise.register(_entity)
    skeleton.register(_entity)
    ai_factions.register(_entity, faction)

    if has_ai:
        ai.register_animal(_entity)

    _entity['ai']['is_npc'] = True

    entities.register_event(_entity, 'finish_turn', finish_turn)
    entities.create_event(_entity, 'get_and_store_item')
    entities.create_event(_entity, 'get_and_hold_item')
    entities.create_event(_entity, 'reload')
    entities.create_event(_entity, 'shoot')
    entities.create_event(_entity, 'damage')
    entities.register_event(_entity, 'post_tick', ai_visuals.cleanup)
    entities.register_event(_entity, 'get_and_store_item', get_and_store_item)
    entities.register_event(_entity, 'get_and_hold_item', get_and_hold_item)
    entities.register_event(_entity, 'reload', reload_weapon)
    entities.register_event(_entity, 'shoot', shoot_weapon)
    entities.register_event(_entity, 'heard_noise', handle_heard_noise)
    entities.register_event(
        _entity, 'position_changed', lambda e, **kwargs: entities.
        trigger_event(e,
                      'create_noise',
                      volume=25,
                      text='?',
                      owner_can_hear=False,
                      callback=lambda t, x, y: entities.trigger_event(
                          t,
                          'update_target_memory',
                          target_id=_entity['_id'],
                          key='last_seen_at',
                          value=[x, y])))
    #entities.register_event(_entity, 'position_changed', lambda e, **kwargs: ai_visuals.add_to_moved_life(e))
    entities.register_event(_entity, 'push',
                            lambda e, **kwargs: movement.sub_move_cost(e))

    entities.trigger_event(_entity, 'set_position', x=x, y=y)
    entities.trigger_event(_entity,
                           'create_holder',
                           name='weapon',
                           max_weight=10)
    entities.trigger_event(_entity,
                           'create_holder',
                           name='backpack',
                           max_weight=10)

    return _entity