def chainpotiontimer( char, potion, bomb, outradius ):
	# Doing error checks first, makes it faster
	if not checkLoS( potion, bomb, outradius ):
		return
	if not bomb.hastag('potiontype'):
		return
	if not int( bomb.gettag('potiontype') ) in [ 11, 12, 13 ]:
		return
	if bomb.hastag('exploding'):
		return

	bomb.settag( 'exploding', char.serial )
	if bomb.hastag( 'kegfill' ) and int( bomb.gettag( 'kegfill' ) ) >= 1:
		bomb.addtimer( randint( 1000, 2250 ), "potions.potioncountdown", [ char, 0, int( bomb.gettag( 'kegfill' ) ) ] )
	else:
		bomb.addtimer( randint( 1000, 2250 ), "potions.potioncountdown", [ char, 0, bomb.amount ] )
	return
def potionregion( args ):
	char = args[0]
	potion = args[1]
	bonus = args[2]
	if potion.gettag('potiontype') == 11:
		outradius = 1
	elif potion.gettag('potiontype') == 12:
		outradius = 2
	elif potion.gettag('potiontype') == 13:
		outradius = randint(2,3)
	else:
		outradius = 1
	# Potion Keg Radius Override!
	if potion.hastag('kegfill') and potion.hastag('potiontype'):
		if potion.gettag('potiontype') in [11, 12, 13] and potion.gettag('kegfill') >= 1:
			kegfill = potion.gettag('kegfill')
			if kegfill == 100:
				outradius = 13
			elif kegfill >= 90:
				outradius = 12
			elif kegfill >= 80:
				outradius = 11
			elif kegfill >= 70:
				outradius = 10
			elif kegfill >= 60:
				outradius = 9
			elif kegfill >= 50:
				outradius = 8
			elif kegfill >= 40:
				outradius = 7
			elif kegfill >= 30:
				outradius = 6
			else:
				outradius = 5
	# Potion thrown on the ground
	if not potion.container:
		x1 = int(potion.pos.x - outradius)
		y1 = int(potion.pos.y - outradius)
		x2 = int(potion.pos.x + outradius)
		y2 = int(potion.pos.y + outradius)
		damageregion = wolfpack.charregion( x1, y1, x2, y2, potion.pos.map )
		# Character Bombing
		target = damageregion.first
		while target:
			if checkLoS( target, potion, outradius ):
				potiondamage(char, target, potion, bonus)
				target = damageregion.next
			else:
				target = damageregion.next

		# Chain Reaction Bombing
		chainregion = wolfpack.itemregion( x1, y1, x2, y2, potion.pos.map )
		chainbomb= chainregion.first
		while chainbomb:
			if checkLoS( potion, chainbomb, outradius ) and not chainbomb.hastag('exploding'):
				if chainbomb.baseid in explodables:
					chainbomb.settag('exploding', 'true')
					chainbomb.addtimer( randint(1000, 2250), "potions.potioncountdown", [char.serial, 0, chainbomb.amount] )
					chainbomb = chainregion.next
				# Potion Kegs
				elif (chainbomb.hastag('kegfill') and chainbomb.hastag('potiontype')) and ( chainbomb.gettag('potiontype') in [11, 12, 13] and chainbomb.gettag('kegfill') >= 1 ):
					chainbomb.settag('exploding', 'true')
					chainbomb.addtimer( randint(1000, 2250), "potions.potioncountdown", [char.serial, 11, chainbomb.gettag('kegfill') ] )
					chainbomb = chainregion.next
				else:
					chainbomb = chainregion.next
			else:
				chainbomb = chainregion.next
		return
	# Potion is in a container
	else:
		x1 = int(char.pos.x - outradius)
		y1 = int(char.pos.y - outradius)
		x2 = int(char.pos.x + outradius)
		y2 = int(char.pos.y + outradius)
		damageregion = wolfpack.charregion( x1, y1, x2, y2, char.pos.map )
		# Area Bombing
		target = damageregion.first
		while target:
			if checkLoS( char, target, outradius ):
				potiondamage(char, target, potion, bonus)
				target = damageregion.next
			else:
				target = damageregion.next

		# Chain Reaction Bombing
		chainregion = wolfpack.itemregion( x1, y1, x2, y2, char.pos.map )
		chainbomb = chainregion.first
		while chainbomb:
			if checkLoS( char, chainbomb, outradius ) and not chainbomb.hastag('exploding'):
				if chainbomb.baseid in explodables:
					chainbomb.settag('exploding', 'true')
					chainbomb.addtimer( randint(1000, 2250), "potions.potioncountdown", [char.serial, 0, chainbomb.amount] )
					chainbomb = chainregion.next
				elif ( chainbomb.hastag('kegfill') and chainbomb.hastag('potiontype') ) and ( chainbomb.gettag('potiontype') in [11, 12, 13] and chainbomb.gettag('kegfill') >= 1 ):
					chainbomb.settag('exploding', 'true')
					chainbomb.addtimer( randint(1000, 2250), "potions.potioncountdown", [char.serial, 11, chainbomb.gettag('kegfill') ] )
					chainbomb = chainregion.next
				else:
					chainbomb = chainregion.next
			else:
				chainbomb = chainregion.next
			# Potion Kegs
		return
def potionregion( char, potion, bonus=0 ):
	if potion.gettag('potiontype') == 11:
		outradius = 1
	elif potion.gettag('potiontype') == 12:
		outradius = 2
	elif potion.gettag('potiontype') == 13:
		outradius = randint(2,3)
	else:
		outradius = 1
	# Potion Keg Radius Override!
	if potion.hastag('kegfill') and potion.hastag('potiontype'):
		if potion.gettag('potiontype') in [11, 12, 13] and potion.gettag('kegfill') >= 1:
			kegfill = potion.gettag('kegfill')
			if kegfill == 100:
				outradius = 13
			elif kegfill >= 90:
				outradius = 12
			elif kegfill >= 80:
				outradius = 11
			elif kegfill >= 70:
				outradius = 10
			elif kegfill >= 60:
				outradius = 9
			elif kegfill >= 50:
				outradius = 8
			elif kegfill >= 40:
				outradius = 7
			elif kegfill >= 30:
				outradius = 6
			else:
				outradius = 5

	outradius = max( 1, outradius )
	# Potion is thrown on the ground
	if not potion.container:
		x1 = min( int(potion.pos.x - outradius), int(potion.pos.x + outradius) )
		x2 = max( int(potion.pos.x - outradius), int(potion.pos.x + outradius) )
		y1 = min( int(potion.pos.y - outradius), int(potion.pos.y + outradius) )
		y2 = max( int(potion.pos.y - outradius), int(potion.pos.y + outradius) )
		# Character Bombing
		damageregion = wolfpack.charregion( x1, y1, x2, y2, potion.pos.map )
		target = damageregion.first
		while target:
			if not target.ischar:
				target = damageregion.next
			if checkLoS( target, potion, outradius ):
				potiondamage( char, target, potion, bonus )
				target = damageregion.next
			else:
				target = damageregion.next

		# Chain Reaction Bombing
		chainregion = wolfpack.itemregion( x1, y1, x2, y2, potion.pos.map )
		chainbomb = chainregion.first
		# Scan the region, build a list of explosives
		while chainbomb:
			chainpotiontimer( char, potion, chainbomb, outradius )
			chainbomb = chainregion.next
		return
	# Potion is in a container
	else:
		x1 = min( int(char.pos.x - outradius), int(char.pos.x + outradius) )
		x2 = max( int(char.pos.x - outradius), int(char.pos.x + outradius) )
		y1 = min( int(char.pos.y - outradius), int(char.pos.y + outradius) )
		y2 = max( int(char.pos.y - outradius), int(char.pos.y + outradius) )
		# Area Bombing
		damageregion = wolfpack.charregion( x1, y1, x2, y2, potion.pos.map )
		target = damageregion.first
		while target:
			if not target.ischar:
				target = damageregion.next
			if checkLoS( char, target, outradius ):
				potiondamage( char, target, potion, bonus )
				target = damageregion.next
			else:
				target = damageregion.next

		potion_chainlist = []
		# Chain Reaction Bombing
		chainregion = wolfpack.itemregion( x1, y1, x2, y2, char.pos.map )
		chainbomb = chainregion.first
		# Scan the region, build a list of explosives
		while chainbomb:
			chainpotiontimer( char, potion, chainbomb, outradius )
			chainbomb = chainregion.next
		return