"""
ProTRG Utility Functions
Release 3 07/23/2010

NOTE: With the exception of players, all applicable variables are 0-based.

SYNOPSIS:
dcList[53] - List of usable death counters.
trgEx - Constant passable parameter specifying exclusion. Value is 4294967295.
trgHyperCommon(to, qual, com) - Sets four common hyper triggers.
	[to: Trigger Owner]
	[qual: Qualification Conditions (list of conditions, excludable)]
	[com: Comment (excludable)]
trgHyperSwitch(to, to2, s, qual, com) - Sets a pair of switch hyper triggers.
	[to: Trigger Owner]
	[to2: Trigger Owner]
	[s: Switch]
	[qual: Qualification Conditions (list of conditions, excludable)]
	[com: Comment (excludable)]
epdKeypress(key) - Detects pressing of a key.
	[key: String ID of Key (refer to the declaration for a list)]
epdScreen(coLX, coLY, coMX, coMY) - Detects coordinates of the screen.
	[coLX: Screen Coordinate Least X (excludable)]
	[coLY: Screen Coordinate Least Y (excludable)]
	[coMX: Screen Coordinate Most X (excludable)]
	[coMY: Screen Coordinate Most Y (excludable)]
epdMouse(coLX, coLY, coMX, coMY) - Detects coordinates of the mouse.
	[coLX: Mouse Coordinate Least X (excludable)]
	[coLY: Mouse Coordinate Least Y (excludable)]
	[coMX: Mouse Coordinate Most X (excludable)]
	[coMY: Mouse Coordinate Most Y (excludable)]
epdSelection(p, slot, uiL, uiM) - Detects selection of a unit.
	[p: Player]
	[slot: Slot of Selection (0-11)]
	[uiL: Unit Index Least (excludable)]
	[uiM: Unit Index Most (excludable)]
epdHotkey(p, hkey, slot, uiL, uiM) - Detects hotkey of a unit.
	[p: Player]
	[hkey: Hotkey (0-9)]
	[slot: Slot of Hotkey (0-11)]
	[uiL: Unit Index Least (excludable)]
	[uiM: Unit Index Most (excludable)]
epdHealth(ui, hpL, decL, hpM, decM) - Detects health points of a unit.
	[ui: Unit Index]
	[hpL: Health Points Least (excludable)]
	[decL: Decimal Least (0-255, excludable ONLY if hpL is excluded)]
	[hpM: Health Points Most (excludable)]
	[decM: Decimal Most (0-255, excludable ONLY if hpM is excluded)]
epdShield(ui, spL, decL, spM, decM) - Detects shield points of a unit.
	[ui: Unit Index]
	[spL: Shield Points Least (excludable)]
	[decL: Decimal Least (0-255, excludable ONLY if spL is excluded)]
	[spM: Shield Points Most (excludable)]
	[decM: Decimal Most (0-255, excludable ONLY if spM is excluded)]
epdEnergy(ui, epL, decL, epM, decM) - Detects energy points of a unit.
	[ui: Unit Index]
	[epL: Energy Points Least (excludable)]
	[decL: Decimal Least (0-255, excludable ONLY if epL is excluded)]
	[epM: Energy Points Most (excludable)]
	[decM: Decimal Most (0-255, excludable ONLY if epM is excluded)]
epdCoordinate(ui, coLX, coLY, coMX, coMY) - Detects coordinates of a unit.
	[ui: Unit Index]
	[coLX: Coordinate Least X (excludable ONLY if coLY is excluded)]
	[coLY: Coordinate Least Y (excludable ONLY if coLX is excluded)]
	[coMX: Coordinate Most X (excludable ONLY if coMY is excluded)]
	[coMY: Coordinate Most Y (excludable ONLY if coMX is excluded)]
epdOrderCoordinate(ui, coLX, coLY, coMX, coMY) - Detects order coordinates of a unit.
	[ui: Unit Index]
	[coLX: Order Coordinate Least X (excludable ONLY if coLY is excluded)]
	[coLY: Order Coordinate Least Y (excludable ONLY if coLX is excluded)]
	[coMX: Order Coordinate Most X (excludable ONLY if coMY is excluded)]
	[coMY: Order Coordinate Most Y (excludable ONLY if coMX is excluded)]
epdRallyCoordinate(ui, coLX, coLY, coMX, coMY) - Detects rally coordinates of a unit.
	[ui: Unit Index]
	[coLX: Rally Coordinate Least X (excludable ONLY if coLY is excluded)]
	[coLY: Rally Coordinate Least Y (excludable ONLY if coLX is excluded)]
	[coMX: Rally Coordinate Most X (excludable ONLY if coMY is excluded)]
	[coMY: Rally Coordinate Most Y (excludable ONLY if coMX is excluded)]
epdDirection(ui, offL, offM) - Detects direction of a unit.
	[ui: Unit Index]
	[offL: Clockwise Offset Least (0-255, excludable)]
	[offM: Clockwise Offset Most (0-255, excludable)]
epdOwner(ui, pL, pM) - Detects owner of a unit.
	[ui: Unit Index]
	[pL: Player Least (excludable)]
	[pM: Player Most (excludable)]
epdTarget(ui, tuiL, tuiM) - Detects targeting unit of a unit.
	[ui: Unit Index]
	[tuiL: Target Unit Index Least (excludable)]
	[tuiM: Target Unit Index Most (excludable)]
epdAttackCooldown(ui, cdL, cdM) - Detects attack cooldown of a unit.
	[ui: Unit Index]
	[cdL: Cooldown Least (excludable)]
	[cdM: Cooldown Most (excludable)]
epdKillCount(ui, kcL, kcM) - Detects kill count of a unit.
	[ui: Unit Index]
	[kcL: Kill Count Least (excludable)]
	[kcM: Kill Count Most (excludable)]
epdBlind(ui, state) - Detects blind state of a unit.
	[ui: Unit Index]
	[state: Binary State]
epdMaelstrom(ui, tL, tM) - Detects maelstrom timer of a unit.
	[ui: Unit Index]
	[tL: Timer Least (excludable)]
	[tM: Time Most (excludable)]
dcAssign(src, dst, max, to, dco, qual, com, stor, ret) - Assigns a death counter to another death counter.
	[src: Source Death Counter]
	[dst: Destination Death Counter]
	[max: Maximum Value (power of 2)]
	[to: Trigger Owner]
	[dco: Death Counter Owner]
	[qual: Qualifying Conditions (list of conditions, excludable)]
	[com: Comment (excludable)]
	[stor: Storage Death Counter (excludable ONLY if ret is 0)]
	[ret: Binary Specifier to Retain Source Death Counter]
dcMultiply(mand, mier, prod, amax, imax, to, dco, qual, com, stor, stor2, aret, iret) - Multiplies two death counters.
	[mand: Multiplicand Death Counter]
	[mier: Multiplier Death Counter]
	[prod: Product Death Counter]
	[amax: Maximum Value of Multiplicand Death Counter (power of 2)]
	[imax: Maximum Value of Multiplier Death Counter (power of 2)]
	[to: Trigger Owner]
	[dco: Death Counter Owner]
	[qual: Qualifying Conditions (list of conditions, excludable)]
	[com: Comment (excludable)]
	[stor: Storage Death Counter]
	[stor2: Storage Death Counter (excludable ONLY if iret is 0]
	[aret: Binary Specifier to Retain Multiplicand Death Counter]
	[iret: Binary Specifier to Retain Multiplier Death Counter]
dcDivide(dend, dsor, quo, emax, smax, to, dco, qual, com, stor, stor2, stor3, eret, sret) - Divides two death counters.
	[dend: Dividend Death Counter]
	[dsor: Divisor Death Counter]
	[quo: Quotient Death Counter]
	[emax: Maximum Value of Dividend Death Counter (power of 2)]
	[smax: Maximum Value of Divisor Death Counter (power of 2)]
	[to: Trigger Owner]
	[dco: Death Counter Owner]
	[qual: Qualifying Conditions (list of conditions, excludable)]
	[com: Comment (excludable)]
	[stor: Storage Death Counter]
	[stor2: Storage Death Counter]
	[stor3: Storage Death Counter (excludable ONLY if eret is 0)]
	[eret: Binary Specifier to Retain Dividend Death Counter]
	[sret: Binary Specifier to Retain Divisor Death Counter]
dcResource(dc, res, max, to, dco, ro, qual, com, stor, ret, clear) - Sets a death counter to a resource.
	[dc: Death Counter]
	[res: Resource Type]
	[max: Maximum Value (power of 2)]
	[to: Trigger Owner]
	[dco: Death Counter Owner]
	[ro: Resource Owner]
	[qual: Qualifying Conditions (list of conditions, excludable)]
	[com: Comment (excludable)]
	[stor: Storage Death Couter (excludable ONLY if ret is 0)]
	[ret: Binary Specifier to Retain Death Counter]
	[clear: Binary Specifier to Initialize Resource to 0]
"""

global dcList
global trgEx
global trgHyperCommon
global trgHyperSwitch
global epdKeypress
global epdScreen
global epdMouse
global epdSelection
global epdHotkey
global epdHealth
global epdShield
global epdEnergy
global epdCoordinate
global epdOrderCoordinate
global epdRallyCoordinate
global epdDirection
global epdOwner
global epdTarget
global epdAttackCooldown
global epdKillCount
global epdBlind
global epdMaelstrom
global dcAssign
global dcMultiply
global dcDivide
global dcResource

dcList = [Unused1, Unused2, UnusedBldg_Terran1, UnusedBldg_Terran2, UnusedBldg_Zerg1, UnusedBldg_Zerg2, Unused_Protoss1, Unused_Protoss2, ZergBeacon, TerranBeacon, ProtossBeacon, ZergFlagBeacon, TerranFlagBeacon, ProtossFlagBeacon, ZergMarker, TerranMarker, ProtossMarker, AlanTurret, DukeTurret, DukeTurret_SiegeMode, GoliathTurret, ScannerSweep, TankTurret, TankTurret_SiegeMode, NuclearMissile, FloorHatch, LeftPitDoor, RightPitDoor, LeftUpperLevelDoor, RightUpperLevelDoor, Cantina, Cave, Cavein, JumpGate, KyadarinCrystalFormation, MiningPlatform, Ruins, DataDisc, KhalisCrystal, KhaydarinCrystal, PsiEmitter, UrajCrystal, DisruptionField, MineralField1, MineralField2, MineralField3, VespeneGeyser, Flag, MapRevealer, StartLocation, DarkSwarm, IndependentCommandCenter, IndependentStarport]
trgEx = 4294967295

def trgHyperCommon(to, qual, com):
	if com == trgEx:
		count = 63
	else:
		count = 62
	trig = Trigger(to)
	if qual != trgEx:
		for i in range(len(qual)):
			trig.add(qual[i])
	for _ in range(count):
		Wait(0)
	PreserveTrigger()
	if com != trgEx:
		Comment(com)
	for _ in range(3):
		trig.addTrigger()
		
def trgHyperSwitch(to, to2, s, qual, com):
	trig = Trigger(to)
	if qual != trgEx:
		for i in range(len(qual)):
			trig.add(qual[i])
	Switch(s, IsSet)
	Wait(0)
	SetSwitch(s, Cleared)
	PreserveTrigger()
	if com != trgEx:
		Comment(com)
	trig = Trigger(to2)
	if qual != trgEx:
		for i in range(len(qual)):
			trig.add(qual[i])
	Wait(0)
	SetSwitch(s, Set)
	Wait(0)
	PreserveTrigger()
	if com != trgEx:
		Comment(com)

def epdKeypress(key):
	if key == "Backspace":
		Memory(12719, Exactly, 1)
	elif "Tab":
		Memory(12719, Exactly, 256)
	elif "Enter":
		Memory(12720, Exactly, 256)
	elif "Shift":
		Memory(12721, Exactly, 1)
	elif "Ctrl":
		Memory(12721, Exactly, 256)
	elif "Alt":
		Memory(12721, Exactly, 65536)
	elif "Caps Lock":
		Memory(12722, Exactly, 1)
	elif "Esc":
		Memory(12723, Exactly, 16777216)
	elif "Space":
		Memory(12725, Exactly, 1)
	elif "Page Up":
		Memory(12725, Exactly, 256)
	elif "Page Down":
		Memory(12725, Exactly, 65536)
	elif "End":
		Memory(12725, Exactly, 16777216)
	elif "Home":
		Memory(12726, Exactly, 1)
	elif "Left":
		Memory(12726, Exactly, 256)
	elif "Up":
		Memory(12726, Exactly, 65536)
	elif "Right":
		Memory(12726, Exactly, 16777216)
	elif "Down":
		Memory(12727, Exactly, 1)
	elif "Insert":
		Memory(12728, Exactly, 256)
	elif "Delete":
		Memory(12728, Exactly, 65536)
	elif "0":
		Memory(12729, Exactly, 1)
	elif "1":
		Memory(12729, Exactly, 256)
	elif "2":
		Memory(12729, Exactly, 65536)
	elif "3":
		Memory(12729, Exactly, 16777216)
	elif "4":
		Memory(12730, Exactly, 1)
	elif "5":
		Memory(12730, Exactly, 256)
	elif "6":
		Memory(12730, Exactly, 65536)
	elif "7":
		Memory(12730, Exactly, 16777216)
	elif "8":
		Memory(12731, Exactly, 1)
	elif "9":
		Memory(12731, Exactly, 256)
	elif "A":
		Memory(12733, Exactly, 256)
	elif "B":
		Memory(12733, Exactly, 65536)
	elif "C":
		Memory(12733, Exactly, 16777216)
	elif "D":
		Memory(12734, Exactly, 1)
	elif "E":
		Memory(12734, Exactly, 256)
	elif "F":
		Memory(12734, Exactly, 65536)
	elif "G":
		Memory(12734, Exactly, 16777216)
	elif "H":
		Memory(12735, Exactly, 1)
	elif "I":
		Memory(12735, Exactly, 256)
	elif "J":
		Memory(12735, Exactly, 65536)
	elif "K":
		Memory(12735, Exactly, 16777216)
	elif "L":
		Memory(12736, Exactly, 1)
	elif "M":
		Memory(12736, Exactly, 256)
	elif "N":
		Memory(12736, Exactly, 65536)
	elif "O":
		Memory(12736, Exactly, 16777216)
	elif "P":
		Memory(12737, Exactly, 1)
	elif "Q":
		Memory(12737, Exactly, 256)
	elif "R":
		Memory(12737, Exactly, 65536)
	elif "S":
		Memory(12737, Exactly, 16777216)
	elif "T":
		Memory(12738, Exactly, 1)
	elif "U":
		Memory(12738, Exactly, 256)
	elif "V":
		Memory(12738, Exactly, 65536)
	elif "W":
		Memory(12738, Exactly, 16777216)
	elif "X":
		Memory(12739, Exactly, 1)
	elif "Y":
		Memory(12739, Exactly, 256)
	elif "Z":
		Memory(12739, Exactly, 65536)
	elif "Print":
		Memory(12740, Exactly, 256)
	elif "Numpad 0":
		Memory(12741, Exactly, 1)
	elif "Numpad 1":
		Memory(12741, Exactly, 256)
	elif "Numpad 2":
		Memory(12741, Exactly, 65536)
	elif "Numpad 3":
		Memory(12741, Exactly, 16777216)
	elif "Numpad 4":
		Memory(12742, Exactly, 1)
	elif "Numpad 5":
		Memory(12742, Exactly, 256)
	elif "Numpad 6":
		Memory(12742, Exactly, 65536)
	elif "Numpad 7":
		Memory(12742, Exactly, 16777216)
	elif "Numpad 8":
		Memory(12743, Exactly, 1)
	elif "Numpad 9":
		Memory(12743, Exactly, 256)
	elif "F1":
		Memory(12745, Exactly, 1)
	elif "F2":
		Memory(12745, Exactly, 256)
	elif "F3":
		Memory(12745, Exactly, 65536)
	elif "F4":
		Memory(12745, Exactly, 16777216)
	elif "F5":
		Memory(12746, Exactly, 1)
	elif "F6":
		Memory(12746, Exactly, 256)
	elif "F7":
		Memory(12746, Exactly, 65536)
	elif "F8":
		Memory(12746, Exactly, 16777216)
	elif "F9":
		Memory(12747, Exactly, 1)
	elif "F10":
		Memory(12747, Exactly, 256)
	elif "F11":
		Memory(12747, Exactly, 65536)
	elif "F12":
		Memory(12747, Exactly, 16777216)
	elif "Num Lock":
		Memory(12753, Exactly, 1)
	elif "Scroll Lock":
		Memory(12753, Exactly, 256)
	elif ";":
		Memory(12763, Exactly, 65536)
	elif "+":
		Memory(12763, Exactly, 16777216)
	elif ",":
		Memory(12764, Exactly, 1)
	elif "-":
		Memory(12764, Exactly, 256)
	elif ".":
		Memory(12764, Exactly, 65536)
	elif "/":
		Memory(12764, Exactly, 16777216)
	elif "`":
		Memory(12765, Exactly, 1)
	elif "[":
		Memory(12771, Exactly, 16777216)
	elif "\\":
		Memory(12772, Exactly, 1)
	elif "]":
		Memory(12772, Exactly, 256)
	elif "'":
		Memory(12772, Exactly, 65536)

def epdScreen(coLX, coLY, coMX, coMY):
	if coLX == coMX and coLX != trgEx:
		Memory(161849, Exactly, coLX)
	else:
		if coLX != trgEx and coLX:
			Memory(161849, AtLeast, coLX)
		if coMX != trgEx:
			Memory(161849, AtMost, coMX)
	if coLY == coMY and coLY != trgEx:
		Memory(161859, Exactly, coLY)
	else:
		if coLY != trgEx and coLY:
			Memory(161859, AtLeast, coLY)
		if coMY != trgEx:
			Memory(161859, AtMost, coMY)

def epdMouse(coLX, coLY, coMX, coMY):
	if coLX == coMX and coLX != trgEx:
		Memory(331416, Exactly, coLX)
	else:
		if coLX != trgEx and coLX:
			Memory(331416, AtLeast, coLX)
		if coMX != trgEx:
			Memory(331416, AtMost, coMX)
	if coLY == coMY and coLY != trgEx:
		Memory(331417, Exactly, coLY)
	else:
		if coLY != trgEx and coLY:
			Memory(331417, AtLeast, coLY)
		if coMY != trgEx:
			Memory(331417, AtMost, coMY)

def epdSelection(p, slot, uiL, uiM):
	if uiL == 0:
		uipL = 5885096
	elif uiL != trgEx:
		uipL = 6455960 - 336*(uiL-1)
	if uiM == 0:
		uipM = 5885096
	elif uiM != trgEx:
		uipM = 6455960 - 336*(uiM-1)
	if uiL == uiM and uiL != trgEx:
		Memory(161889+slot+(p-1)*12, Exactly, uipL)
	else:
		if uiM != trgEx:
			Memory(161889+slot+(p-1)*12, AtLeast, uipM)
		if uiL != trgEx:
			Memory(161889+slot+(p-1)*12, AtMost, uipL)
			
def epdHotkey(p, hkey, slot, uiL, uiM):
	if uiL == 0:
		uipL = 2049
	elif uiL != trgEx:
		uipL = 3748 - (uiL-1)
	if uiM == 0:
		uipM = 2049
	elif uiM != trgEx:
		uipM = 3748 - (uiM-1)
	if uiL == uiM and uiL != trgEx:
		Memory(4294956735+slot+hkey*12+(p-1)*216, Exactly, uipL)
	else:
		if uiM != trgEx:
			Memory(4294956735+slot+hkey*12+(p-1)*216, AtLeast, uipM)
		if uiL != trgEx:
			Memory(4294956735+slot+hkey*12+(p-1)*216, AtMost, uipL)

def epdHealth(ui, hpL, decL, hpM, decM):
	if ui == 0:
		uin = 19027
	else:
		uin = 19027 + 142716 - 84*(ui-1)
	if hpL == hpM and decL == decM:
		Memory(uin, Exactly, hpL*256+decL)
	else:
		if hpL != trgEx and hpL*256+decL:
			Memory(uin, AtLeast, hpL*256+decL)
		if hpM != trgEx:
			Memory(uin, AtMost, hpM*256+decM)

def epdShield(ui, spL, decL, spM, decM):
	if ui == 0:
		uin = 19049
	else:
		uin = 19049 + 142716 - 84*(ui-1)
	if spL == spM and decL == decM:
		Memory(uin, Exactly, spL*256+decL)
	else:
		if spL != trgEx and spL*256+decL:
			Memory(uin, AtLeast, spL*256+decL)
		if spM != trgEx:
			Memory(uin, AtMost, spM*256+decM)

def epdEnergy(ui, epL, decL, epM, decM):
	if ui == 0:
		uin = 19065
	else:
		uin = 19065 + 142716 - 84*(ui-1)
	if epL == epM and decL == decM:
		Memory(uin, Exactly, epL*256+decL)
	else:
		if epL != trgEx and epL*256+decL:
			Memory(uin, AtLeast, epL*256+decL)
		if epM != trgEx:
			Memory(uin, AtMost, epM*256+decM)

def epdCoordinate(ui, coLX, coLY, coMX, coMY):
	if ui == 0:
		uin = 19035
	else:
		uin = 19035 + 142716 - 84*(ui-1)
	if coLX == coMX and coLY == coMY and coLX != trgEx and coLY != trgEx:
		Memory(uin, Exactly, coLX+coLY*65536)
	else:
		if coLX != trgEx and coLY != trgEx and coLX+coLY*65536:
			Memory(uin, AtLeast, coLX+coLY*65536)
		if coMX != trgEx and coMY != trgEx:
			Memory(uin, AtMost, coMX+coMY*65536)

def epdOrderCoordinate(ui, coLX, coLY, coMX, coMY):
	if ui == 0:
		uin = 19047
	else:
		uin = 19047 + 142716 - 84*(ui-1)
	if coLX == coMX and coLY == coMY and coLX != trgEx and coLY != trgEx:
		Memory(uin, Exactly, coLX+coLY*65536)
	else:
		if coLX != trgEx and coLY != trgEx and coLX+coLY*65536:
			Memory(uin, AtLeast, coLX+coLY*65536)
		if coMX != trgEx and coMY != trgEx:
			Memory(uin, AtMost, coMX+coMY*65536)

def epdRallyCoordinate(ui, coLX, coLY, coMX, coMY):
	if ui == 0:
		uin = 19087
	else:
		uin = 19087 + 142716 - 84*(ui-1)
	if coLX == coMX and coLY == coMY and coLX != trgEx and coLY != trgEx:
		Memory(uin, Exactly, coLX+coLY*65536)
	else:
		if coLX != trgEx and coLY != trgEx and coLX+coLY*65536:
			Memory(uin, AtLeast, coLX+coLY*65536)
		if coMX != trgEx and coMY != trgEx:
			Memory(uin, AtMost, coMX+coMY*65536)

def epdDirection(ui, offL, offM):
	if ui == 0:
		uin = 19043
	else:
		uin = 19043 + 142716 - 84*(ui-1)
	if offL != trgEx and offL:
		Memory(uin, AtLeast, offL*16777216)
	if offM != trgEx:
		Memory(uin, AtMost, offM*16777216+16777215)

def epdOwner(ui, pL, pM):
	if ui == 0:
		uin = 19044
	else:
		uin = 19044 + 142716 - 84*(ui-1)
	if pL == pM and pL != trgEx:
		Memory(uin, Exactly, 768 + pL)
	else:
		if pL != trgEx:
			Memory(uin, AtLeast, 768 + pL)
		if pM != trgEx:
			Memory(uin, AtMost, 768 + pM)

def epdTarget(ui, tuiL, tuiM):
	if ui == 0:
		uin = 19048
	else:
		uin = 19048 + 142716 - 84*(ui-1)
	if tuiL == 0:
		tuipL = 5885096
	elif tuiL != trgEx:
		tuipL = 6455960 - 336*(tui-1)
	if tuiM == 0:
		tuipM = 5885096
	elif tuiM != trgEx:
		tuipM = 6455960 - 336*(tui-1)
	if tuiL == tuiM and tuiL != trgEx:
		Memory(uin, Exactly, tuipL)
	else:
		if tuiM != trgEx:
			Memory(uin, AtLeast, tuipM)
		if tuiL != trgEx:
			Memory(uin, AtMost, tuipL)

def epdAttackCooldown(ui, cdL, cdM):
	if ui == 0:
		uin = 19046
	else:
		uin = 19046 + 142716 - 84*(ui-1)
	if cdL == cdM and cdL != trgEx:
		Memory(uin, Exactly, cdL*65536)
	else:
		if cdL != trgEx and cdL:
			Memory(uin, AtLeast, cdL*65536)
		if cdM != trgEx:
			Memory(uin, AtMost, cdM*65536)

def epdKillCount(ui, kcL, kcM):
	if ui == 0:
		uin = 19060
	else:
		uin = 19060 + 142716 - 84*(ui-1)
	if kcL != trgEx and kcL:
		Memory(uin, AtLeast, kcL*16777216)
	if kcM != trgEx:
		Memory(uin, AtMost, kcM*16777216+16777215)

def epdBlind(ui, state):
	if ui == 0:
		uin = 19097
	else:
		uin = 19097 + 142716 - 84*(ui-1)
	if state:
		Memory(uin, AtLeast, 16777216)
	else:
		Memory(uin, AtMost, 16777215)

def epdMaelstrom(ui, tL, tM):
	if ui == 0:
		uin = 19098
	else:
		uin = 19098 + 142716 - 84*(ui-1)
	if tL == tM and tL != trgEx:
		Memory(uin, Exactly, tL)
	else:
		if tL != trgEx and tL:
			Memory(uin, AtLeast, tL)
		if tM != trgEx:
			Memory(uin, AtMost, tM)

def dcAssign(src, dst, max, to, dco, qual, com, stor, ret):
	l_max = max
	while l_max:
		trig = Trigger(to)
		if qual != trgEx:
			for i in range(len(qual)):
				trig.add(qual[i])
		Deaths(dco, src, AtLeast, l_max)
		SetDeaths(dco, src, Subtract, l_max)
		if ret:
			SetDeaths(dco, stor, Add, l_max)
		SetDeaths(dco, dst, Add, l_max)
		PreserveTrigger()
		if com != trgEx:
			Comment(com)
		l_max/=2
	if ret:
		l_max = max
		while l_max:
			trig = Trigger(to)
			if qual != trgEx:
				for i in range(len(qual)):
					trig.add(qual[i])
			Deaths(dco, stor, AtLeast, l_max)
			SetDeaths(dco, stor, Subtract, l_max)
			SetDeaths(dco, src, Add, l_max)
			PreserveTrigger()
			if com != trgEx:
				Comment(com)
			l_max/=2
			
def dcMultiply(mand, mier, prod, amax, imax, to, dco, qual, com, stor, stor2, aret, iret):
	l_max = imax
	while l_max:
		ll_max = amax
		while ll_max: #decrement mand, add to prod
			trig = Trigger(to)
			if qual != trgEx:
				for i in range(len(qual)):
					trig.add(qual[i])
			Deaths(dco, mand, AtLeast, ll_max)
			Deaths(dco, mier, AtLeast, l_max)
			SetDeaths(dco, mand, Subtract, ll_max)
			SetDeaths(dco, stor, Add, ll_max)
			SetDeaths(dco, prod, Add, ll_max*l_max)
			PreserveTrigger()
			if com != trgEx:
				Comment(com)
			ll_max/=2
		trig = Trigger(to) #decrement mier
		if qual != trgEx:
				for i in range(len(qual)):
					trig.add(qual[i])
		Deaths(dco, mier, AtLeast, l_max)
		SetDeaths(dco, mier, Subtract, l_max)
		if iret:
			SetDeaths(dco, stor2, Add, l_max)
		PreserveTrigger()
		if com != trgEx:
			Comment(com)
		ll_max = amax
		if l_max != 1 or aret:
			while ll_max: #restore mand
				trig = Trigger(to)
				if qual != trgEx:
					for i in range(len(qual)):
						trig.add(qual[i])
				Deaths(dco, stor, AtLeast, ll_max)
				SetDeaths(dco, stor, Subtract, ll_max)
				SetDeaths(dco, mand, Add, ll_max)
				PreserveTrigger()
				if com != trgEx:
					Comment(com)
				ll_max/=2
		l_max/=2
	if iret:
		l_max = imax
		while l_max:
			trig = Trigger(to)
			if qual != trgEx:
					for i in range(len(qual)):
						trig.add(qual[i])
			Deaths(dco, stor2, AtLeast, l_max)
			SetDeaths(dco, stor2, Subtract, l_max)
			SetDeaths(dco, mier, Add, l_max)
			PreserveTrigger()
			if com != trgEx:
					Comment(com)
			l_max/=2
		
def dcDivide(dend, dsor, quo, emax, smax, to, dco, qual, com, stor, stor2, stor3, eret, sret):
	l_max = smax
	while l_max: #dsor*emax
		trig = Trigger(to)
		if qual != trgEx:
			for i in range(len(qual)):
				trig.add(qual[i])
		Deaths(dco, dsor, AtLeast, l_max)
		SetDeaths(dco, dsor, Subtract, l_max)
		SetDeaths(dco, stor, Add, l_max*emax)
		SetDeaths(dco, stor2, Add, l_max*emax)
		PreserveTrigger()
		if com != trgEx:
			Comment(com)
		l_max/=2
	l_max = emax
	while l_max:
		ll_max = emax
		while ll_max:
			trig = Trigger(to)
			if qual != trgEx:
				for i in range(len(qual)):
					trig.add(qual[i])
			Deaths(dco, dend, AtLeast, ll_max)
			Deaths(dco, stor, AtLeast, ll_max)
			SetDeaths(dco, dend, Subtract, ll_max)
			SetDeaths(dco, stor, Subtract, ll_max)
			if l_max > 1:
				SetDeaths(dco, dsor, Add, ll_max)
			if eret:
				SetDeaths(dco, stor3, Add, ll_max)
			PreserveTrigger()
			if com != trgEx:
				Comment(com)
			ll_max/=2
		trig = Trigger(to) #check if dend > dsor*emax
		if qual != trgEx:
			for i in range(len(qual)):
				trig.add(qual[i])
		Deaths(dco, stor, Exactly, 0)
		SetDeaths(dco, quo, Add, l_max)
		PreserveTrigger()
		if com != trgEx:
			Comment(com)
		if l_max > 1:
			ll_max = emax
			while ll_max:
				trig = Trigger(to)
				if qual != trgEx:
					for i in range(len(qual)):
						trig.add(qual[i])
				Deaths(dco, stor, AtLeast, 1)
				Deaths(dco, dsor, AtLeast, ll_max)
				SetDeaths(dco, dsor, Subtract, ll_max)
				if eret:
					SetDeaths(dco, stor3, Subtract, ll_max)
				SetDeaths(dco, dend, Add, ll_max)
				PreserveTrigger()
				if com != trgEx:
					Comment(com)
				ll_max/=2
			trig = Trigger(to)
			if qual != trgEx:
				for i in range(len(qual)):
					trig.add(qual[i])
			SetDeaths(dco, stor, SetTo, 0)
			SetDeaths(dco, dsor, SetTo, 0)
			PreserveTrigger()
			if com != trgEx:
				Comment(com)
			ll_max = emax*smax
			while ll_max > 1:
				trig = Trigger(to)
				if qual != trgEx:
					for i in range(len(qual)):
						trig.add(qual[i])
				Deaths(dco, stor2, AtLeast, ll_max)
				SetDeaths(dco, stor2, Subtract, ll_max)
				SetDeaths(dco, dsor, Add, ll_max/2)
				SetDeaths(dco, stor, Add, ll_max/2)
				PreserveTrigger()
				if com != trgEx:
					Comment(com)
				ll_max/=2
			if l_max > 2:
				ll_max = emax*smax
				while ll_max > 1:
					trig = Trigger(to)
					if qual != trgEx:
						for i in range(len(qual)):
							trig.add(qual[i])
					Deaths(dco, dsor, AtLeast, ll_max)
					SetDeaths(dco, dsor, Subtract, ll_max)
					SetDeaths(dco, stor2, Add, ll_max)
					PreserveTrigger()
					if com != trgEx:
						Comment(com)
					ll_max/=2
		else:
			if eret:
				ll_max = emax
				while ll_max:
					trig = Trigger(to)
					if qual != trgEx:
						for i in range(len(qual)):
							trig.add(qual[i])
					Deaths(dco, stor3, AtLeast, ll_max)
					SetDeaths(dco, stor3, Subtract, ll_max)
					SetDeaths(dco, dend, Add, ll_max)
					PreserveTrigger()
					if com != trgEx:
						Comment(com)
					ll_max/=2
		l_max/=2
		
def dcResource(dc, res, max, to, dco, ro, qual, com, stor, ret, clear):
	if clear:
		trig = Trigger(to)
		if qual != trgEx:
			for i in range(len(qual)):
				trig.add(qual[i])
		SetResources(ro, SetTo, 0, res)
		PreserveTrigger()
		if com != trgEx:
			Comment(com)
	l_max = max
	while l_max:
		trig = Trigger(to)
		if qual != trgEx:
			for i in range(len(qual)):
				trig.add(qual[i])
		Deaths(dco, dc, AtLeast, l_max)
		SetDeaths(dco, dc, Subtract, l_max)
		if ret:
			SetDeaths(dco, stor, Add, l_max)
		SetResources(ro, Add, l_max, res)
		PreserveTrigger()
		if com != trgEx:
			Comment(com)
		l_max/=2
	if ret:
		l_max = max
		while l_max:
			trig = Trigger(to)
			if qual != trgEx:
				for i in range(len(qual)):
					trig.add(qual[i])
			Deaths(dco, stor, AtLeast, l_max)
			SetDeaths(dco, stor, Subtract, l_max)
			SetDeaths(dco, dc, Add, l_max)
			PreserveTrigger()
			if com != trgEx:
				Comment(com)
			l_max/=2

for i, j in enumerate(dcList):
	try:
		min, gas, stor1 = dcList[:i]
		break
	except ValueError:
		pass
		
m = 15
f = (Force1)
fqc = (1,2,3,4,5,6,7,8,f,AllPlayers)

for i in range(m, -1, -1):  ###DIFF OF RES AND DC
	Trigger(*fqc)
	Accumulate(CurrentPlayer, AtLeast, 4**i, Ore)
	Deaths(CurrentPlayer, min, AtLeast, 4**i)
	SetResources(CurrentPlayer, Subtract, 4**i, Ore)
	SetDeaths(CurrentPlayer, min, Subtract, 4**i)
	SetDeaths(CurrentPlayer, stor1, Add, 4**i)
	PreserveTrigger()
	
for i in range(m, -1, -1):   ####IF DC IS MORE
	Trigger(*fqc)
	Deaths(CurrentPlayer, min, AtLeast, 4**i)
	SetDeaths(f, min, Subtract, 4**i)
	SetResources(f, Subtract, 4**i, Ore)
	PreserveTrigger()
	
for i in range(m, -1, -1):   ###IF RES IS MORE
	Trigger(*fqc)
	Accumulate(CurrentPlayer, AtLeast, 4**i, Ore)
	SetResources(f, Add, 4**i, Ore)
	SetResources(CurrentPlayer, Subtract, 2*(4**i), Ore)
	SetDeaths(f, min, Add, 4**i)
	SetDeaths(CurrentPlayer, min, Subtract, 4**i)
	SetDeaths(CurrentPlayer, stor1, Add, 4**i)
	PreserveTrigger()

for i in range(m, -1, -1):   ###RESTORE RES AND DC
	Trigger(*fqc)
	Deaths(CurrentPlayer, stor1, AtLeast, 4**i)
	SetDeaths(CurrentPlayer, stor1, Subtract, 4**i)
	SetDeaths(CurrentPlayer, min, Add, 4**i)
	SetResources(CurrentPlayer, Add, 4**i, Ore)
	PreserveTrigger()
	
	
	
for i in range(m, -1, -1):  ###DIFF OF RES AND DC
	Trigger(*fqc)
	Accumulate(CurrentPlayer, AtLeast, 4**i, Gas)
	Deaths(CurrentPlayer, gas, AtLeast, 4**i)
	SetResources(CurrentPlayer, Subtract, 4**i, Gas)
	SetDeaths(CurrentPlayer, gas, Subtract, 4**i)
	SetDeaths(CurrentPlayer, stor1, Add, 4**i)
	PreserveTrigger()
	
for i in range(m, -1, -1):   ####IF DC IS MORE
	Trigger(*fqc)
	Deaths(CurrentPlayer, gas, AtLeast, 4**i)
	SetDeaths(f, gas, Subtract, 4**i)
	SetResources(f, Subtract, 4**i, Gas)
	PreserveTrigger()
	
for i in range(m, -1, -1):   ###IF RES IS MORE
	Trigger(*fqc)
	Accumulate(CurrentPlayer, AtLeast, 4**i, Gas)
	SetResources(f, Add, 4**i, Gas)
	SetResources(CurrentPlayer, Subtract, 2*(4**i), Gas)
	SetDeaths(f, gas, Add, 4**i)
	SetDeaths(CurrentPlayer, gas, Subtract, 4**i)
	SetDeaths(CurrentPlayer, stor1, Add, 4**i)
	PreserveTrigger()

for i in range(m, -1, -1):   ###RESTORE RES AND DC
	Trigger(*fqc)
	Deaths(CurrentPlayer, stor1, AtLeast, 4**i)
	SetDeaths(CurrentPlayer, stor1, Subtract, 4**i)
	SetDeaths(CurrentPlayer, gas, Add, 4**i)
	SetResources(CurrentPlayer, Add, 4**i, Gas)
	PreserveTrigger()
	
trgHyperCommon(f, trgEx, trgEx)