Ejemplo n.º 1
0
def register_combat(entity, target_id):
	_target = entities.get_entity(target_id)
	_squad_1 = ai_squads.get_assigned_squad(entity)
	_squad_2 = ai_squads.get_assigned_squad(_target)['_id']

	FIGHTING_SQUADS.add(_squad_1['_id'])
	FIGHTING_SQUADS.add(_squad_2)
	
	if not settings.TURN_QUEUE:
		entities.trigger_event(FLOW, 'start_of_turn', squad_id=_squad_1['_id'])
	
	if not _squad_1['_id'] in settings.TURN_QUEUE:
		settings.TURN_QUEUE.append(_squad_1['_id'])
	
	if not _squad_2 in settings.TURN_QUEUE:
		settings.TURN_QUEUE.append(_squad_2)
Ejemplo n.º 2
0
def register_combat(entity, target_id):
    _target = entities.get_entity(target_id)
    _squad_1 = ai_squads.get_assigned_squad(entity)
    _squad_2 = ai_squads.get_assigned_squad(_target)['_id']

    FIGHTING_SQUADS.add(_squad_1['_id'])
    FIGHTING_SQUADS.add(_squad_2)

    if not settings.TURN_QUEUE:
        entities.trigger_event(FLOW, 'start_of_turn', squad_id=_squad_1['_id'])

    if not _squad_1['_id'] in settings.TURN_QUEUE:
        settings.TURN_QUEUE.append(_squad_1['_id'])

    if not _squad_2 in settings.TURN_QUEUE:
        settings.TURN_QUEUE.append(_squad_2)
Ejemplo n.º 3
0
def member_handle_found_target(entity, target_id):
    for member_id in ai_squads.get_assigned_squad(entity)["members"]:
        if member_id == entity["_id"]:
            continue

        _member = entities.get_entity(member_id)

        entities.trigger_event(_member, "squad_inform_found_target", member_id=entity["_id"], target_id=target_id)
Ejemplo n.º 4
0
def leader_handle_raid_camp(entity, camp):
    for member_id in ai_squads.get_assigned_squad(entity)['members']:
        _member = entities.get_entity(member_id)

        entities.trigger_event(_member,
                               'squad_inform_raid',
                               member_id=entity['_id'],
                               camp=camp)
Ejemplo n.º 5
0
def populate_life(zone_id):
	_zone = ZONES[zone_id]
	
	for faction_name in _zone['faction_spawn_list']:
		_spawn_profile = _zone['faction_spawn_list'][faction_name]
		
		if _spawn_profile['bases']:
			for b in range(_spawn_profile['bases']):
				for node_set_id in _zone['node_sets']:
					_node_set = _zone['node_sets'][node_set_id]
					_set_center_x, _set_center_y = _node_set['center']
					_spawn_pos = []
					
					for x, y in shapes.circle(_set_center_x, _set_center_y, 5):
						if (x, y) in _zone['solids']:
							continue
						
						_spawn_pos.append((x, y))
					
					_min_squad_size, _max_squad_size = ai_factions.FACTIONS[faction_name]['base_size_range']
					
					for i in range(random.randint(_min_squad_size, _max_squad_size)):
						_x, _y = _spawn_pos.pop(random.randint(0, len(_spawn_pos)-1))
						_e = _spawn_profile['type'](_x, _y, 'Test NPC %s' % str(i+1))
						
						if _e['ai']['meta']['is_squad_leader']:
							_squad = ai_squads.get_assigned_squad(_e)
							_squad['camp_id'] = node_set_id
							_node_set['owner'] = {'faction': faction_name,
							                      'squad': _e['ai']['squad']}
			
					if _spawn_profile['trader']:
						_x, _y = _spawn_pos.pop(random.randint(0, len(_spawn_pos)-1))
						_e = _spawn_profile['type'](_x, _y, 'Trader')
						
		
		else:
			for b in range(_spawn_profile['squads']):
				_spawn_pos = []
				
				if 'spawn_pos' in _spawn_profile:
					_center_x, _center_y = _spawn_profile['spawn_pos']
				
				else:
					_center_x, _center_y = random.sample([_zone['width'] - 50, _zone['height'] - 50, 50, 50], 2)
						
				for x, y in shapes.circle(_center_x, _center_y, 5):
					if (x, y) in _zone['solids']:
						continue
					
					_spawn_pos.append((x, y))
				
				_min_squad_size, _max_squad_size = ai_factions.FACTIONS[faction_name]['squad_size_range']
				
				for i in range(random.randint(_min_squad_size, _max_squad_size)):
					_x, _y = _spawn_pos.pop(random.randint(0, len(_spawn_pos)-1))
					_e = _spawn_profile['type'](_x, _y, 'Test NPC %s' % str(i+1))
Ejemplo n.º 6
0
def handle_player_end_of_turn(entity, squad_id):
	_squad = ai_squads.get_assigned_squad(entity)
	
	if not _squad:
		return
	
	if _squad['_id'] == squad_id:
		settings.set_tick_mode('normal')
		
		return False
Ejemplo n.º 7
0
def member_handle_failed_target_search(entity, target_id):
    for member_id in ai_squads.get_assigned_squad(entity)["members"]:
        if member_id == entity["_id"]:
            continue

        _member = entities.get_entity(member_id)

        entities.trigger_event(_member, "squad_inform_failed_search", member_id=entity["_id"], target_id=target_id)

    entity["ai"]["life_memory"][target_id]["searched_for"] = True
Ejemplo n.º 8
0
def can_act(entity):
	_squad = ai_squads.get_assigned_squad(entity)['_id']
	
	if not _squad in FIGHTING_SQUADS:
		return True
	
	if _squad in settings.TURN_QUEUE:
		return _squad == get_active_squad() and entity['stats']['action_points'] > 0
	
	return True
Ejemplo n.º 9
0
def handle_player_end_of_turn(entity, squad_id):
    _squad = ai_squads.get_assigned_squad(entity)

    if not _squad:
        return

    if _squad['_id'] == squad_id:
        settings.set_tick_mode('normal')

        return False
Ejemplo n.º 10
0
def member_handle_found_target(entity, target_id):
    for member_id in ai_squads.get_assigned_squad(entity)['members']:
        if member_id == entity['_id']:
            continue

        _member = entities.get_entity(member_id)

        entities.trigger_event(_member,
                               'squad_inform_found_target',
                               member_id=entity['_id'],
                               target_id=target_id)
Ejemplo n.º 11
0
def can_act(entity):
    _squad = ai_squads.get_assigned_squad(entity)['_id']

    if not _squad in FIGHTING_SQUADS:
        return True

    if _squad in settings.TURN_QUEUE:
        return _squad == get_active_squad(
        ) and entity['stats']['action_points'] > 0

    return True
Ejemplo n.º 12
0
def member_handle_failed_target_search(entity, target_id):
    for member_id in ai_squads.get_assigned_squad(entity)['members']:
        if member_id == entity['_id']:
            continue

        _member = entities.get_entity(member_id)

        entities.trigger_event(_member,
                               'squad_inform_failed_search',
                               member_id=entity['_id'],
                               target_id=target_id)

    entity['ai']['life_memory'][target_id]['searched_for'] = True
Ejemplo n.º 13
0
def handle_player_start_of_turn(entity, squad_id):
	if ai_squads.get_assigned_squad(entity)['_id'] == squad_id:
		settings.set_tick_mode('strategy')
	
		_squad = entities.get_entity(squad_id)
		
		if not ai_factions.is_enemy(entity, _squad['leader']) and entity['_id'] == _squad['leader']:
			if _squad['meta']['is_squad_combat_ready']:
				_message = random.choice(['Locked and loaded.',
					                      'Nuke \'em!',
					                      'No mercy, boys...'])
			
			elif _squad['meta']['is_squad_overwhelmed']:
				_message = random.choice(['We\'re outnumbered!',
					                      'Fall back!'])
				
			else:
				return
			
			effects.message(_message, time=120, center=True)
Ejemplo n.º 14
0
def handle_player_start_of_turn(entity, squad_id):
    if ai_squads.get_assigned_squad(entity)['_id'] == squad_id:
        settings.set_tick_mode('strategy')

        _squad = entities.get_entity(squad_id)

        if not ai_factions.is_enemy(
                entity,
                _squad['leader']) and entity['_id'] == _squad['leader']:
            if _squad['meta']['is_squad_combat_ready']:
                _message = random.choice(
                    ['Locked and loaded.', 'Nuke \'em!', 'No mercy, boys...'])

            elif _squad['meta']['is_squad_overwhelmed']:
                _message = random.choice(['We\'re outnumbered!', 'Fall back!'])

            else:
                return

            effects.message(_message, time=120, center=True)
Ejemplo n.º 15
0
def cleanup(entity):
    _squad = ai_squads.get_assigned_squad(entity)

    _squad['members'].remove(entity['_id'])

    if _squad['leader'] == entity['_id']:
        logging.warning('Leader of squad died. Handle this.')

        if _squad['members']:
            _squad['leader'] = list(_squad['members'])[0]

        else:
            _squad['leader'] = None

    if entity['_id'] in _squad['member_info']:
        del _squad['member_info'][entity['_id']]

    if not _squad['members']:
        del FACTIONS[_squad['faction']]['squads'][_squad['squad_id']]

        entities.delete_entity(_squad)
Ejemplo n.º 16
0
def cleanup(entity):
	_squad = ai_squads.get_assigned_squad(entity)
	
	_squad['members'].remove(entity['_id'])
	
	if _squad['leader'] == entity['_id']:
		logging.warning('Leader of squad died. Handle this.')
		
		if _squad['members']:
			_squad['leader'] = list(_squad['members'])[0]
		
		else:
			_squad['leader'] = None
	
	if entity['_id'] in _squad['member_info']:
		del _squad['member_info'][entity['_id']]
	
	if not _squad['members']:
		del FACTIONS[_squad['faction']]['squads'][_squad['squad_id']]
		
		entities.delete_entity(_squad)
Ejemplo n.º 17
0
def populate_life(zone_id):
    _zone = ZONES[zone_id]

    for faction_name in _zone['faction_spawn_list']:
        _spawn_profile = _zone['faction_spawn_list'][faction_name]

        if _spawn_profile['bases']:
            for b in range(_spawn_profile['bases']):
                for node_set_id in _zone['node_sets']:
                    _node_set = _zone['node_sets'][node_set_id]
                    _set_center_x, _set_center_y = _node_set['center']
                    _spawn_pos = []

                    for x, y in shapes.circle(_set_center_x, _set_center_y, 5):
                        if (x, y) in _zone['solids']:
                            continue

                        _spawn_pos.append((x, y))

                    _min_squad_size, _max_squad_size = ai_factions.FACTIONS[
                        faction_name]['base_size_range']

                    for i in range(
                            random.randint(_min_squad_size, _max_squad_size)):
                        _x, _y = _spawn_pos.pop(
                            random.randint(0,
                                           len(_spawn_pos) - 1))
                        _e = _spawn_profile['type'](_x, _y,
                                                    'Test NPC %s' % str(i + 1))

                        if _e['ai']['meta']['is_squad_leader']:
                            _squad = ai_squads.get_assigned_squad(_e)
                            _squad['camp_id'] = node_set_id
                            _node_set['owner'] = {
                                'faction': faction_name,
                                'squad': _e['ai']['squad']
                            }

                    if _spawn_profile['trader']:
                        _x, _y = _spawn_pos.pop(
                            random.randint(0,
                                           len(_spawn_pos) - 1))
                        _e = _spawn_profile['type'](_x, _y, 'Trader')

        else:
            for b in range(_spawn_profile['squads']):
                _spawn_pos = []

                if 'spawn_pos' in _spawn_profile:
                    _center_x, _center_y = _spawn_profile['spawn_pos']

                else:
                    _center_x, _center_y = random.sample(
                        [_zone['width'] - 50, _zone['height'] - 50, 50, 50], 2)

                for x, y in shapes.circle(_center_x, _center_y, 5):
                    if (x, y) in _zone['solids']:
                        continue

                    _spawn_pos.append((x, y))

                _min_squad_size, _max_squad_size = ai_factions.FACTIONS[
                    faction_name]['squad_size_range']

                for i in range(random.randint(_min_squad_size,
                                              _max_squad_size)):
                    _x, _y = _spawn_pos.pop(
                        random.randint(0,
                                       len(_spawn_pos) - 1))
                    _e = _spawn_profile['type'](_x, _y,
                                                'Test NPC %s' % str(i + 1))
Ejemplo n.º 18
0
def leader_handle_raid_camp(entity, camp):
    for member_id in ai_squads.get_assigned_squad(entity)["members"]:
        _member = entities.get_entity(member_id)

        entities.trigger_event(_member, "squad_inform_raid", member_id=entity["_id"], camp=camp)