Beispiel #1
0
def judge_self(life):
    _confidence = 0
    _limb_confidence = 0

    for limb in [life["body"][limb] for limb in life["body"]]:
        # TODO: Mark as target?
        if not limb["bleeding"]:
            _limb_confidence += 1

        if not limb["bruised"]:
            _limb_confidence += 2

        if not limb["broken"]:
            _limb_confidence += 3

            # TODO: There's a chance to fake confidence here
            # If we're holding a gun, that's all the other ALifes see
            # and they judge based on that (unless they've heard you run
            # out of ammo.)
            # For now we'll consider ammo just because we can...
    _self_armed = lfe.get_held_items(life, matches=[{"type": "gun"}])

    if _self_armed:
        _weapon = lfe.get_inventory_item(life, _self_armed[0])
        _feed = weapons.get_feed(_weapon)

        if _feed and _feed["rounds"]:
            _confidence += 30
        else:
            _confidence -= 30

    return _confidence + _limb_confidence
Beispiel #2
0
def judge_self(life):
	_confidence = 0
	_limb_confidence = 0
	
	for limb in [life['body'][limb] for limb in life['body']]:
		#TODO: Mark as target?
		if not limb['bleeding']:
			_limb_confidence += 1
		
		if not limb['bruised']:
			_limb_confidence += 2
		
		if not limb['broken']:
			_limb_confidence += 3
	
	#TODO: There's a chance to fake confidence here
	#If we're holding a gun, that's all the other ALifes see
	#and they judge based on that (unless they've heard you run
	#out of ammo.)
	#For now we'll consider ammo just because we can...
	_self_armed = lfe.get_held_items(life,matches=[{'type': 'gun'}])
	
	if _self_armed:
		_weapon = lfe.get_inventory_item(life,_self_armed[0])
		_feed = weapons.get_feed(_weapon)
		
		if _feed and _feed['rounds']:
			_confidence += 30
		else:
			_confidence -= 30
	
	return _confidence+_limb_confidence
Beispiel #3
0
def manage_hands(life):
    for item in [lfe.get_inventory_item(life, item) for item in lfe.get_held_items(life)]:
        judgement.judge_item(life, item["uid"])
        _known_item = brain.get_remembered_item(life, item["uid"])

        if _known_item["score"]:  # judgement.get_score_of_highest_scoring_item(life):
            continue

        _equip_action = {"action": "equipitem", "item": item["uid"]}

        if len(lfe.find_action(life, matches=[_equip_action])):
            return True

        if lfe.can_wear_item(life, item["uid"]):
            lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, item["uid"]))
            return True

        _storage = lfe.can_put_item_in_storage(life, item["uid"])
        if not "CAN_WEAR" in item["flags"] and _storage:
            _store_action = {"action": "storeitem", "item": item["uid"], "container": _storage}

            if len(lfe.find_action(life, matches=[_store_action])):
                continue

            lfe.add_action(life, _store_action, 401, delay=lfe.get_item_access_time(life, item["uid"]))
            return True

    return False
Beispiel #4
0
def manage_inventory(life):
	if manage_hands(life):
		return False
	
	for weapon_uid in combat.get_equipped_weapons(life):
		if not combat.weapon_is_working(life, weapon_uid):
			if combat.weapon_is_in_preferred_working_condition(life, weapon_uid):
				if not len(lfe.find_action(life,matches=[{'action': 'refillammo'}])):
					combat.reload_weapon(life, weapon_uid)
				
					return True
	
	_item_to_wear = {'score': 0, 'item_uid': None}
	_item_to_equip = {'score': 0, 'item_uid': None}
		
	for item in [lfe.get_inventory_item(life, item) for item in lfe.get_all_unequipped_items(life)]:
		judgement.judge_item(life, item['uid'])
		_known_item = brain.get_remembered_item(life, item['uid'])
		
		if _known_item['score']:
			if lfe.can_wear_item(life, item['uid']):
				if _known_item['score'] > _item_to_wear['score']:
					_item_to_wear['score'] = _known_item['score']
					_item_to_wear['item_uid'] = item['uid']
			else:
				if rawparse.raw_has_section(life, 'items') and rawparse.raw_section_has_identifier(life, 'items', item['type']):
					_action = lfe.execute_raw(life, 'items', item['type'])
					
					if item['type'] == 'gun' and lfe.get_all_equipped_items(life, matches=[{'type': 'gun'}]):
						continue
					
					if _action == 'equip':
						if _known_item['score'] > _item_to_equip['score']:
							_item_to_equip['score'] = _known_item['score']
							_item_to_equip['item_uid'] = item['uid']
	
	_item = None
	if _item_to_wear['score'] > _item_to_equip['score']:
		_item = _item_to_wear['item_uid']
	elif _item_to_equip['item_uid']:
		_item = _item_to_equip['item_uid']
	
	if _item:
		_equip_action = {'action': 'equipitem', 'item': _item}
		
		if len(lfe.find_action(life, matches=[_equip_action])):
			return False
		
		lfe.add_action(life,
			_equip_action,
			401,
			delay=lfe.get_item_access_time(life, _item))
		
		return False
	
	return True
Beispiel #5
0
def _get_feed(life, weapon):
	_feeds = lfe.get_all_inventory_items(life, matches=[{'type': weapon['feed'], 'ammotype': weapon['ammotype']}], ignore_actions=False)

	_highest_feed = {'rounds': -1, 'feed': None}
	for feed in [lfe.get_inventory_item(life, _feed['uid']) for _feed in _feeds]:
		if feed['rounds']>_highest_feed['rounds']:
			_highest_feed['rounds'] = feed['rounds']
			_highest_feed['feed'] = feed
	
	return _highest_feed['feed']
Beispiel #6
0
def _get_feed(life, weapon):
	_feeds = lfe.get_all_inventory_items(life, matches=[{'type': weapon['feed'], 'ammotype': weapon['ammotype']}], ignore_actions=False)

	_highest_feed = {'rounds': -1, 'feed': None}
	for feed in [lfe.get_inventory_item(life, _feed['uid']) for _feed in _feeds]:
		if feed['rounds']>_highest_feed['rounds']:
			_highest_feed['rounds'] = feed['rounds']
			_highest_feed['feed'] = feed
	
	return _highest_feed['feed']
Beispiel #7
0
def get_recoil(life):
    _guns = lfe.get_held_items(life, matches=[{'type': 'gun'}])

    if not _guns:
        return 0

    weapon = lfe.get_inventory_item(life, _guns[0])
    _recoil = weapon['recoil']

    _recoil *= get_stance_recoil_mod(life)

    return _recoil
Beispiel #8
0
def get_recoil(life):
	_guns = lfe.get_held_items(life,matches=[{'type': 'gun'}])
	
	if not _guns:
		return 0
	
	weapon = lfe.get_inventory_item(life, _guns[0])
	_recoil = weapon['recoil']
	
	_recoil *= get_stance_recoil_mod(life)
	
	return _recoil
Beispiel #9
0
def manage_inventory(life):
    if manage_hands(life):
        return False

    for weapon_uid in combat.get_equipped_weapons(life):
        if not combat.weapon_is_working(life, weapon_uid):
            if combat.weapon_is_in_preferred_working_condition(life, weapon_uid):
                combat.reload_weapon(life, weapon_uid)
                return True

    _item_to_wear = {"score": 0, "item_uid": None}
    _item_to_equip = {"score": 0, "item_uid": None}

    for item in [lfe.get_inventory_item(life, item) for item in lfe.get_all_unequipped_items(life)]:
        judgement.judge_item(life, item["uid"])
        _known_item = brain.get_remembered_item(life, item["uid"])

        if _known_item["score"]:
            if lfe.can_wear_item(life, item["uid"]):
                if _known_item["score"] > _item_to_wear["score"]:
                    _item_to_wear["score"] = _known_item["score"]
                    _item_to_wear["item_uid"] = item["uid"]
            else:
                if rawparse.raw_has_section(life, "items") and rawparse.raw_section_has_identifier(
                    life, "items", item["type"]
                ):
                    _action = lfe.execute_raw(life, "items", item["type"])

                    if _action == "equip":
                        if _known_item["score"] > _item_to_equip["score"]:
                            _item_to_equip["score"] = _known_item["score"]
                            _item_to_equip["item_uid"] = item["uid"]

    _item = None
    if _item_to_wear["score"] > _item_to_equip["score"]:
        _item = _item_to_wear["item_uid"]
    elif _item_to_equip["item_uid"]:
        _item = _item_to_equip["item_uid"]

    if _item:
        _equip_action = {"action": "equipitem", "item": _item}

        if len(lfe.find_action(life, matches=[_equip_action])):
            return False

        lfe.add_action(life, _equip_action, 401, delay=lfe.get_item_access_time(life, _item))

        return True

    return False
Beispiel #10
0
def manage_hands(life):
    for item in [
            lfe.get_inventory_item(life, item)
            for item in lfe.get_held_items(life)
    ]:
        judgement.judge_item(life, item['uid'])
        _known_item = brain.get_remembered_item(life, item['uid'])

        for weapon in combat.get_equipped_weapons(life):
            if item['type'] == ITEMS[weapon]['feed'] and len(
                    item['rounds']) >= 5:
                combat.load_feed(life, weapon, item['uid'])

                return True

        if _known_item[
                'score']:  #judgement.get_score_of_highest_scoring_item(life):
            continue

        _equip_action = {'action': 'equipitem', 'item': item['uid']}

        if len(lfe.find_action(life, matches=[_equip_action])):
            return True

        if lfe.can_wear_item(life, item['uid']):
            lfe.add_action(life,
                           _equip_action,
                           401,
                           delay=lfe.get_item_access_time(life, item['uid']))
            return True

        _storage = lfe.can_put_item_in_storage(life, item['uid'])
        if not 'CAN_WEAR' in item['flags'] and _storage:
            _store_action = {
                'action': 'storeitem',
                'item': item['uid'],
                'container': _storage
            }

            if len(lfe.find_action(life, matches=[_store_action])):
                continue

            lfe.add_action(life,
                           _store_action,
                           401,
                           delay=lfe.get_item_access_time(life, item['uid']))
            return True

    return False
Beispiel #11
0
def get_weapon_to_fire(life):
    if 'player' in life:
        return life['firing']

    _item = lfe.get_held_items(life, matches=[{'type': 'gun'}])

    if _item:
        _item = _item[0]
    else:
        return False

    if not _item:
        if 'player' in life:
            gfx.message('You aren\'t holding a weapon!')

        life['firing'] = None
        return False

    return lfe.get_inventory_item(life, _item)
Beispiel #12
0
def get_weapon_to_fire(life):
	if 'player' in life:
		return life['firing']
		
	_item = lfe.get_held_items(life,matches=[{'type': 'gun'}])
		
	if _item:
		_item = _item[0]
	else:
		return False
	
	if not _item:
		if 'player' in life:
			gfx.message('You aren\'t holding a weapon!')
		
		life['firing'] = None
		return False
	
	return lfe.get_inventory_item(life, _item)
Beispiel #13
0
def manage_hands(life):
	for item in [lfe.get_inventory_item(life, item) for item in lfe.get_held_items(life)]:
		judgement.judge_item(life, item['uid'])
		_known_item = brain.get_remembered_item(life, item['uid'])
		
		for weapon in combat.get_equipped_weapons(life):
			if item['type'] == ITEMS[weapon]['feed'] and len(item['rounds'])>=5:
				combat.load_feed(life, weapon, item['uid'])
				
				return True
		
		if _known_item['score']:#judgement.get_score_of_highest_scoring_item(life):
			continue
		
		_equip_action = {'action': 'equipitem',
				'item': item['uid']}
		
		if len(lfe.find_action(life, matches=[_equip_action])):
			return True
		
		if lfe.can_wear_item(life, item['uid']):
			lfe.add_action(life, _equip_action,
				401,
				delay=lfe.get_item_access_time(life, item['uid']))
			return True
		
		_storage = lfe.can_put_item_in_storage(life, item['uid'])
		if not 'CAN_WEAR' in item['flags'] and _storage:
			_store_action = {'action': 'storeitem',
				'item': item['uid'],
				'container': _storage}
			
			if len(lfe.find_action(life, matches=[_store_action])):
				continue
			
			lfe.add_action(life,_store_action,
				401,
				delay=lfe.get_item_access_time(life, item['uid']))
			return True
	
	return False
Beispiel #14
0
def dismantle_item(life, item_id):
	_item = lfe.get_inventory_item(life, item_id)
	
	scripting.execute(_item['flags']['CANDISMANTLE'], owner=life, item_uid=item_id)
Beispiel #15
0
def manage_inventory(life):
    if manage_hands(life):
        return False

    for weapon_uid in combat.get_equipped_weapons(life):
        if not combat.weapon_is_working(life, weapon_uid):
            if combat.weapon_is_in_preferred_working_condition(
                    life, weapon_uid):
                if not len(
                        lfe.find_action(life,
                                        matches=[{
                                            'action': 'refillammo'
                                        }])):
                    combat.reload_weapon(life, weapon_uid)

                    return True

    _item_to_wear = {'score': 0, 'item_uid': None}
    _item_to_equip = {'score': 0, 'item_uid': None}

    for item in [
            lfe.get_inventory_item(life, item)
            for item in lfe.get_all_unequipped_items(life)
    ]:
        judgement.judge_item(life, item['uid'])
        _known_item = brain.get_remembered_item(life, item['uid'])

        if _known_item['score']:
            if lfe.can_wear_item(life, item['uid']):
                if _known_item['score'] > _item_to_wear['score']:
                    _item_to_wear['score'] = _known_item['score']
                    _item_to_wear['item_uid'] = item['uid']
            else:
                if rawparse.raw_has_section(
                        life, 'items') and rawparse.raw_section_has_identifier(
                            life, 'items', item['type']):
                    _action = lfe.execute_raw(life, 'items', item['type'])

                    if item['type'] == 'gun' and lfe.get_all_equipped_items(
                            life, matches=[{
                                'type': 'gun'
                            }]):
                        continue

                    if _action == 'equip':
                        if _known_item['score'] > _item_to_equip['score']:
                            _item_to_equip['score'] = _known_item['score']
                            _item_to_equip['item_uid'] = item['uid']

    _item = None
    if _item_to_wear['score'] > _item_to_equip['score']:
        _item = _item_to_wear['item_uid']
    elif _item_to_equip['item_uid']:
        _item = _item_to_equip['item_uid']

    if _item:
        _equip_action = {'action': 'equipitem', 'item': _item}

        if len(lfe.find_action(life, matches=[_equip_action])):
            return False

        lfe.add_action(life,
                       _equip_action,
                       401,
                       delay=lfe.get_item_access_time(life, _item))

        return False

    return True