def ranged_attack():
		""" |  Perform a ranged attack.
			|  Checks for a ranged weapon in hand and then calls *input.target_tile* to determine a target.
		"""
		from input import target_tile
		from render import message
		from utils import is_player

		mobToHit = None
		if self.owner.get_equipped_in_slot('hand').ranged is not None:
			if is_player(self.owner):
				target = target_tile()
				if target == 'cancelled':
					return 'cancelled'
			else:
				target = 'closest'
			if target == 'closest':
				mobToHit = closest_mob(self.perception + self.skills['Awareness']*2)
			else:
				for hit in self.currentmap().objects:
					if target.x == hit.x and target.y == hit.y and hit.fighter is not None:
						mobToHit = hit

			if mobToHit is None:
				# @TODO No enemy found, drop arrow
				if is_player(self.owner):
					message('There is no enemy here!', libtcod.orange)
			else:
				self.attack(mobToHit.fighter, ranged=True)
				return self.owner.get_equipped_in_slot('hand').ranged.speed
		else:
			if is_player(self.owner):
				message('You do not have a ranged weapon equipped!', libtcod.orange)
		return 'cancelled'
def fall_into(entity):
    """ |  Step function:
            |  Fall into a hole. Takes an entity (player, mob) as input.
            |  Rolls Wits + Awareness to determine, if they see the hole.
            |  If they do and there is a ledge near (not diagonally), do a reflexive Wits+Awareness roll, to determine if they can hang down the ledge.
            |  Otherwise, kill them.
    """
    from utils import d10, is_player
    from render import message

    map = entity.currentmap()
    result = d10(entity.fighter.wits + entity.fighter.skills["Awareness"],
                 'Fall:',
                 botchable=True,
                 player=is_player(entity))
    if result[0] <= 3:
        ledge = False
        for spot in map.adjacent(entity.x, entity.y, diagonal=False):
            if map.map[spot[0]][spot[1]].tile_type == 'floor':
                ledge = True
        if ledge:
            # ledge near, do a reflex roll to catch it
            reflex = d10(entity.fighter.wits +
                         entity.fighter.skills["Awareness"],
                         'Reflex:',
                         botchable=True,
                         player=is_player(entity))
            if reflex[0] >= 2:
                if not is_player:
                    message(entity.name + " is hanging down the ledge",
                            libtcod.white)
                else:
                    message("You are hanging down the ledge", libtcod.white)
            else:
                if not is_player:
                    message(entity.name + " has fallen down the hole",
                            libtcod.red)
                else:
                    message("You have fallen down the hole", libtcod.red)
                    entity.fighter.death_function(entity)
        else:
            # no ledge near
            if not is_player:
                message(entity.name + " has fallen down the hole", libtcod.red)
            else:
                message("You have fallen down the hole", libtcod.red)
            entity.fighter.death_function(entity)
    else:
        if not is_player:
            message(entity.name + " is hanging down the ledge", libtcod.white)
        else:
            message("You are hanging down the ledge", libtcod.white)
	def attack(self, target, ranged=False):
		""" |  Performs an attack against the target.
			|  Melee or ranged indicated by ranged boolean
		"""
		from utils import d10, is_player
		from render import message

		activeWeapon = self.owner.get_equipped_in_slot('hand')
		if (activeWeapon is None):										# get equipped weapon from slot 'hand'
			activeWeapon = Equipment(slot='hand', weapon=Weapon())  	# Insert dummy weapon if no weapon is equipped
																		# @TODO Two-Handed Weapons

		weapon = activeWeapon.ranged if ranged else activeWeapon.weapon 				# determine weapon/ranged component to use

		hitroll = d10(self.dexterity + self.skills[weapon.skill], 'Hit', player=is_player(self.owner))
		if hitroll[0] != 'botch':
			hitroll[0] -= self.health_penalty()
			hitroll[0] = max(hitroll[0], 0)
		else:
			pass	# @TODO Botch Behaviour

		# Check for hit, if successes > enemy's dodge DV ( -onslaughtPenalty for player)
		threshold = target.dodgeDV()
		threshold -= target.onslaughtPenalty() if is_player(target.owner) else 0

		if hitroll[0] != 'botch' and hitroll[0] > threshold:	# target hit, roll damage
			if ranged:
				dmgroll = d10(weapon.damage, 'Damage', botchable=False, player=is_player(self.owner))
			else:
				dmgroll = d10(self.strength + weapon.damage, 'Damage', botchable=False, player=is_player(self.owner))
			damage = dmgroll[0] + (hitroll[0] - threshold)		# add remaining successes from hitroll

			if damage > target.hardness():						# check if damage is bigger than hardness
				if weapon.damage_type == 'bashing':				# apply soak
					damage -= target.bashing_soak()
				elif weapon.damage_type == 'lethal':
					damage -= target.lethal_soak()

				if damage > 0:									# apply damage
					message(self.owner.name.capitalize() + ' hits ' + target.owner.name + ' for ' + str(damage) + ' hit points.')
					target.take_damage(damage)
				else:
					message(self.owner.name.capitalize() + ' hits ' + target.owner.name + ' but the strike bounces off his armor!')
		else:
			message(self.owner.name.capitalize() + ' attacks ' + target.owner.name + ' but misses.')

		return weapon.speed
	def onslaughtPenalty(self):
		""" |  Returns the onslaught Penalty as an integer
			|  calculated from adjacent enemies - 1
		"""
		from utils import is_player

		penalty = -1
		for spot in self.owner.currentmap().adjacent(self.owner.x, self.owner.y):
			for obj in self.owner.currentmap().objects:
				if obj.fighter and not is_player(obj) and obj.x == spot[0] and obj.y == spot[1]:
					penalty += 1
		return penalty
	def take_damage(self, damage):
		""" |  Apply the given amount of damage
			|  and invoke the death_function, if necessary
		"""
		from utils import is_player

		for level in [0, 1, 2, 3]:					# go through all Health Levels
			if damage > 0 and self.hl[level] > 0:
				d = damage - self.hl[level]
				if d >= 0:
					self.hl[level] = 0
					damage = d
				else:
					self.hl[level] -= damage
					damage = 0
			if level == 3 and self.hl[level] <= 0:
				if self.death_function is not None:
					self.death_function(self.owner) 			# Apply Death Function if possible
		if is_player(self.owner):
			gvar.screen_impact = [libtcod.darker_red, 1]
	def join_battle(self):
		""" |  Decreases the overall tick level.
			|  Puts owner into global Tick counter
			|  with join battle roll as Priority
		"""
		from utils import d10, is_player, decrease_tick_level

		decrease_tick_level()
		# Roll Wits + Awareness as Join Battle
		roll = d10(self.wits + self.skills["Awareness"], 'Join Battle', botchable=False, player=is_player(self.owner))
		if not gvar.game.ticks.contains(self.owner):
			gvar.game.ticks.put(self.owner, roll[0])
	def jump(self, direction):
		""" |  Jump to the given direction
			|  checking for blocked spots and
			|  stopping if block is found

			|  **direction** -- tuple | relative x and y directions
		"""
		from utils import d10, is_player

		# Roll DEX + Athletics
		roll = d10(self.fighter.dexterity + self.fighter.skills["Athletics"], 'Jump', player=is_player(self))

		# Normalize directions
		for d in directions:
			if d > 0:
				d = 1
			elif d < 0:
				d = -1

		#Check for blocking Objects/Tiles
		max_distance = 0
		if roll[0] != 'botch':
			for d in range(1, roll[0]):
				max_distance = d
				if self.currentmap().is_blocked(self.x + direction[0] * (d+1), self.y + direction[1] * (d+1)):
					break
			self.move_to((self.x + direction[0]*max_distance, self.y + direction[1]*max_distance))
		else:
			#@TODO Botch Behaviour
			print "botch"

		return self.fighter.movement_speed()