***triggers specifications for PRO users only****

War2mod reads bytes from OILM section of Warcraft2 PUD map

War2mod triggers function called by War2 each 200 game cycles by default
this function have variables:
	local = id of local player
	units_list - list of found units, using with trigger 6
	byte TIMER[16] ; decreasing on each call if >0
	int  VAL[256]
	bool FLAG[256]
	int  GVAL[96]

at each call of this function:
	units_list resets to empty
	all VALs resets to 0
	all TIMERs -=1 if >0
	FLAGs not changes between function calls
	GVALs not changes between function calls and game save/load (its saved into .sav file)

VALs and FLAGs can have custom names in Triggers Editor program
names not saved in *.PUD files, only in *.w2tr


readed bytes interpretations (byte+N means N-th byte readed after current):

0	program exit (ALL triggers after this are ignored)
	size: 1	(but it gives +=MAX SIZE for readed bytes counter)
	
1	show menu-dialog at victory/loss (by default disabled in multiplayer, enabled in single)
	size: 2
	byte+1 (bool)
	
2	set mission objective id
	size: 2
	mission objective id = byte+1 (0-52) (255 - default kill all) (53-254 game crash?)
	* stored in: Rez/objectives.tbl in MPQ

3	mutual alliance
	size: 4
	player1= byte+1 (0-15)
	player2= byte+2 (0-15)
	allied = byte+3 (bool)
	
4	mutual vision
	size: 4
	player1= byte+1 (0-7)
	player2= byte+2 (0-7)
	shared vision = byte+3 (bool)
	
5	set VAL[a] to n
	size: 3
	VAL[byte+1]=byte+2 (0-255) (0-255)
	
6	units_list operations
	size: 2+sub zize
	
	sub byte+1 = 0
		sub size: 1
		unit=byte+2 (0-110)
		units_list=find_all_alive_units(unit)
	
	sub byte+1 = 1
		sub size: 0
		sort_in_region
		only units that have X Y draw coords inside of region will stay in units_list
		its left up corner for buildings
		
	sub byte+1 = 2
		sub size: 4
		stat_id = byte+2 (0-152)
		stat = WORD (byte+3,byte+4) (0-65535)
		cmp = byte+5
		sort_stat
		only units will stay in units_list
		that have chosen stat compared with some number using <cmp> method
		
	sub byte+1 = 3
		sub size: 3
		stat_id = byte+2 (0-152)
		stat = WORD (byte+3,byte+4) (0-65535)
		set_stat
		all units in units_list will have chosen stat_id = stat number
		HP = 100
		Mana = 255
		and etc
		
	sub byte+1 = 4
		sub size: 0
		kill_all
		
	sub byte+1 = 5
		sub size: 0
		flame_shield_all
		
	sub byte+1 = 6
		sub size: 1
		heal amount = byte+2 (0-255)
		heal_all
		
	sub byte+1 = 7
		sub size: 0
		sort_complete (buildings)
		only completed units will stay in units list
		
	sub byte+1 = 8
		sub size: 2
		x = byte+2 (0-127)
		y = byte+3 (0-127)
		teleport_all
		
	sub byte+1 = 9
		sub size: 1
		player = byte+2 (0-15)
		give_all (to player)
		
	sub byte+1 = 10
		sub size: 2
		max_size = WORD (byte+2,byte+3) (0-1600)
		if sizeof(units_list)>max_size
			remove (max_size-sizeof(units_list)) units from list
			
	sub byte+1 = 11
		sub size: 0
		AI autocast spells
		
	sub byte+1 = 12
		sub size: 3
		Order = byte+2
		X = byte+3
		Y = byte+4
		give Order to all units (order position X Y)
	
	sub byte+1 = 13
		sub size: 2
		damage amount = WORD (byte+2, byte+3)(0-65535)
		damage_all
	
	sub byte+1 = 14
		sub size: 0
		Remove all units in list from map (hide units then kill)
		
	sub byte+1 = 15
		sub size: 1
		resource type = byte+2 (0 gold, 1 lumber)
		load all units in list with peon_loaded flag with resource
	
	sub byte+1 = 16
		sub size: 1
		resource type = byte+2 (0 gold, 1 lumber, 2 any)
		only units will stay in units_list
		that have peon_loaded flag with resource
		
	sub byte+1 = 17
		sub size: 1
		resource type = byte+2 (0 gold, 1 lumber, 2 any)
		only units will stay in units_list
		that NOT have peon_loaded flag with resource
		
	sub byte+1 = 18
		sub size: 2
		players = byte+2 (0-255 bitmask 1 bit for each player)
		reveal_size = byte+3 (0-9)
		reveal map around all units in list with reveal_size

	sub byte+1 = 19
		sub size: 1
		set area around first unit in list (if not empty) with radius byte+2 (0-127)
		
7
	size: 5
	id = byte+1 (0-255)
	players_flag = byte+2 (0-255)
	neutral_local_flag = byte+3 (0-3)
	param_id = byte+4 (0-60)
	
	if neutral_local_flag&1==1
	VAL[id] += get_param(neutral_player,param_id)
	
	if neutral_local_flag&2==1 AND players_flag==0
	{
	for each bit in players_flag
	if player != local player
	VAL[id] += get_param(player,param_id)
	}
	else
	{
	for each bit in players_flag
	VAL[id] += get_param(player,param_id)
	}
	
	
byte 8
	size: 5
	cmp=byte+1 (0-5) //compare method
	val1_id = byte+2 (0-255)
	val2_id = byte+3 (0-255)
	flag_id = byte+4 (0-255)
	FLAG[flag_id]=TRUE if VAL[val1_id] <cmp> VAL[val2_id]
	
b 9	set region
	size: 5
	x1 = byte+1 (0-127)
	y1 = byte+2 (0-127)
	x2 = byte+3 (0-127)
	y2 = byte+4 (0-127)
	
b 10	comps vision to allies
	size: 2
	byte+1 (bool)
	
b 11    set GVAL[byte+2]=VAL[byte+1]
	size: 3
	
b 12    set VAL[byte+1]=GVAL[byte+2]
	size: 3
	
b 13	add VAL[b] to VAL[a]
	size: 3
	VAL[byte+1] += VAL[byte+2]
	if VAL[byte+1]>255
		VAL[byte+1]=255
	
b 14	substract VAL[b] from VAL[a]
	size: 3
	if VAL[byte+1]>VAL[byte+2]
		VAL[byte+1] -= VAL[byte+2]
	else
		VAL[byte+1]=0
	
b 15	multiply VAL[a] by VAL[b]
	size: 3
	VAL[byte+1] *= VAL[byte+2]
	if VAL[byte+1]>255
		VAL[byte+1]=255
	
b 16	DIV VAL[a]/VAL[b]
	size: 3
	if VAL[byte+2]!=0
		VAL[byte+1] /= VAL[byte+2] // DIV
	
b 17	MOD VAL[a]/VAL[b]
	size: 3
	if VAL[byte+2]!=0
		VAL[byte+1] %= VAL[byte+2] // MOD
	
b 18	transform ALL units owned by player, from type1 to type2 (calls standart War2 function unit_transform)
	size: 4
	player = byte+1 (0-15)
	unit1 = byte+2 (0-104)
	unit2 = byte+3 (0-104)
	
b 19	create VAL[N] Units for Player at X,Y (calls standart War2 function unit_create)
	size: 6
	x = byte+1 (0-127)
	y = byte+2 (0-127)
	unit = byte+3 (0-106)
	player = byte+4 (0-15)
	N = byte+5 (0-255)
	
b 20	create N Units for Player at X,Y (calls standart War2 function unit_create)
	size: 6
	x = byte+1 (0-127)
	y = byte+2 (0-127)
	unit = byte+3 (0-106)
	player = byte+4 (0-15)
	N = byte+5 (0-255)
	
b 21	set FLAG[byte+1]=byte+2 (bool)
	size: 3
	
	
byte 22
	size: 2
	if FLAG[byte+1]!=TRUE
		skip+=1
	(skip all next readed commands 
	exept byte = 23 or 22(33)
	until skip=0)
	
byte 23
	size: 1
	skip-=1
	
b 24	instant victory
	size: 1
	
b 25	instant defeat
	size: 1
	
b 26	change resource of player
	size: 5
	player = byte+1 (0-7)
	resource = byte+2 (0-5)
	amount = byte+3 (0-255)
	if resource<3
		resource += amount*VAL[byte+4]
	else
		resource -= amount*VAL[byte+4]
	0-2 gold lumber oil (ADD)
	3-5 gold lumber oil (SUBSTRACT)
	
b 27	build sheeps allowed
	size: 1
	
b 28	additional build button for peons
	size: 1
	
b 29	call default misson objective "kill all" trigger
	size: 1
	
b 30	count total units in units_list
	size: 2
	VAL[byte+1]=sizeof(units_list)
	
b 31	change mana cost of spell
	size: 3
	spell_id = byte+1 (0-18)
	cost = byte+2 (0-255)
	
b 32	center view (move camera) to x,y
	size: 3
	x = byte+1 (0-119)
	y = byte+2 (0-119)

	
byte 33
	size: 2
	if FLAG[byte+1]==TRUE
		skip+=1
	(skip all next readed commands 
	exept byte = 23 or 22(33)
	until skip=0)
	

b 34	set resource of player to value
	size: 7
	player = byte+1 (0-7)
	resource = byte+2 (0-2)
	amount = DWORD (byte+3,byte+4,byte+5,byte+6)
	
b 35	compare resource of player and change FLAG accordingly
	size: 9
	player = byte+1 (0-7)
	resource = byte+2 (0-2)
	amount = DWORD (byte+3,byte+4,byte+5,byte+6)
	cmp = byte+7
	FLAG[byte+8]=TRUE if resource of player <cmp> amount
	
b 36	clear chat
	size: 1
	
b 37	display message on screen
	size: 3+(message size)
	display time = byte+1 (0-20) (time in seconds)
	message size = byte+2 (* max length 60)
	message text = all next bytes

b 38	set speed value for "fastest speed"
	size: 2
	change speed of fastest to byte+1 (0 = instant game; default values: fastest 13, ef 20, 26, 33, normal 40, 46, 53, 60, evenslower 80)

b 39	set pair of units: attacker-target, where only 'attacker type' can deal damage to 'target type'
	size: 4
	id = byte+1 (0-255) ; * ids must start from 0 and be continuous (+1 for each next pair) ; * using existing id will replace old pair assigned for it
	attacker unit type = byte+2 (0-104) (255 cancel)
	target unit type = byte+3 (0-104) (255 cancel)
	
b 40	peon can repair all
	size: 2
	byte+1 (bool)
	
b 41	runestone features enabled
	size: 1
	
b 42	runestone effect change
	size: 3
	runestone_effect = byte+1 (0-8)
	rune[runestone_effect] = byte+2 (bool) for most and (0-255) for 5 and 6
	0 inviz			bool
	1 shield		bool
	2 blood 		bool
	3 haste			bool
	4 flameshied	bool
	5 mana regen	(0-255)
	6 heal			(0-255)
	7 kill enemy	bool
	8 allied buf	bool
	
b 43	change power of upgrade
	size: 3
	upgrade = byte+1 (0-6)
	power = byte+2 (0-127)
	
byte 44
	size: 4
	tid = byte+1 (0-16)
	time = byte+2 (0-255)
	if TIMER[tid]==0
		TIMER[tid]=time
	if TIMER[tid]==1
		FLAG[byte+3]=TRUE 
	
byte 45	
	size: 3
	player = byte+1 (0-8)
	if player==8
		FLAG[byte+2]=check_opponents(local)
	else
		FLAG[byte+2]=check_opponents(player)
	check_opponents(X) return TRUE if X-th player have 0 opponents
	* opponents are:
	not allied comps
	players that not aved (not allied and not set AV) (X player must be allied and set AV too)
	
b 46	allied comps can aggro
	size: 2
	byte+1 (bool)
	
b 47	set FLAG[n] if specified Players allied
	size: 3
	player1 = byte+1 (0-15)
	player2 = byte+2 (0-15)
	FLAG[byte+3]=TRUE if player1 and player2 allied
	
b 48	can capture low hp buildings
	size: 2
	byte+1 (bool)
	
b 49	only peons can capture low hp buildings
	size: 2
	byte+1 (bool)
	
b 50    capture all player if main base captured
	size: 2
	byte+1 (bool)
	
b 51	portal_trigger = true
	size: 1
	
b 52	can repair catapults
	size: 2
	byte+1 (bool)
	
b 53	wharf_trigger = true
	size: 1
	* ships near wharfs autorepair
	
b 54	teleport only for allies
	size: 2
	byte+1 (bool)
	
b 55	teleport only for mages
	size: 2
	byte+1 (bool)
	
b 56	allow cheats in multiplayer = true
	size: 1
	
	
b 57	can build demons = true
	size: 1
	
	
b 58	set heroes
	size: 3
	slot = byte+1 (0-15)
	unit = byte+2 (0-104) (only hero units works normal)
	build hero unit from TH in slot
	slots 0-7 for human
	slots 8-15 for orc
	1 tier TH = first 2 hero available to build
	2 tier TH = first 5 hero available to build
	3 tier TH = all slots available to build
	
b 59	autoheal allowed (autoheal button enable/disable added to church)
	size: 1
	
b 60	all players allied from the start of game (for campaigns)
	size: 1
	* pre-load trigger
	
b 61	set firebal damage
	size: 2
	byte+1 (0-255)
	
b 62	change effect duration time
	size: 4
	effect = byte+1 (0-4) ; * effects: Inviz,Shield,Blood,Haste,Slow
	time = WORD (byte+1,byte+2) (0-25000)
	
b 63	transport allied units allowed
	size: 1
	
b 64	resources exchange allowed
	size: 1
	
b 65	can build runestone
	size: 2
	byte+1 (bool)
	
b 66	can build portal
	size: 2
	byte+1 (bool)
	
b 67	can build circle
	size: 2
	byte+1 (bool)
	
b 69	add button for attak mode to TH
	size: 2
	attack peons have attack mode = byte+1 (bool)
	
b 70	demons attacks have manaburn effect
	size: 2
	byte+1 (bool)
	
b 71	allow peons steal resources from other peons when attack
	size: 1
	
	
b 72
	size: 3
	if local player == byte+2 (0-7)
		FLAG[byte+1]=TRUE  

	
b 73	set restrictions (spells, upgrades, units)
	size: 5
	player = byte+1 (0-7)
	table_id = byte+2 (0-3)
	N = byte+3 (0-8)
	allow = byte+4 (bool)
	
	table = (DWORD) (table_id + 4 *player)
	set N bit in table = allow
	tables ids:
	0 allowed units
	1 allowed upgrades
	2 allowed spells
	3 learned spells
	
	
byte 74
	size: 4
	i = byte+1 (0-120)
	p1 = byte+2 (0-8)
	p2 = byte+3 (0-8)
	A[2*i]=p1
	A[2*i+1]=p2
	
	for k from 0 to 240
		player A[k] controlling player A[k+1]
		k+=2
	
b 75	can build gold mine
	size: 2
	byte+1 (bool)
	
b 76	can grow forest
	size: 2
	byte+1 (bool)
	
b 77	rally point and tower control = true
	size: 1
	
b 78	no random damage = true
	size: 1
	
b 79	blood always x2 = true
	size: 1
	
b 80    allow change game speed in multiplayer
	size: 1
	
byte 81
	size: 3
	n = byte+1 (0-255)
	unit = byte+2 (0-104)
	slow_aura[n]=unit
	for i from 0 to 255
		all enemy units around 5 cells distance from slow_aura[i] will get slow
	
byte 82
	size: 3
	n = byte+1 (0-255)
	unit = byte+2 (0-104)
	death_aura[n]=unit
	for i from 0 to 255
		all dead body around 5 cells distance from death_aura[i] will stand skeletons
	
byte 83
	size: 3
	n = byte+1 (0-255)
	unit = byte+2 (0-104)
	defence_aura[n]=unit
	for i from 0 to 255
		all allied units around 5 cells distance from defence_aura[i] will receive 3 less damage
	
byte 84
	size: 3
	n = byte+1 (0-255)
	unit = byte+2 (0-104)
	vampire_aura[n]=unit
	for i from 0 to 255
		all allied units around 5 cells distance from vampire_aura[i] will heal itself to 50% of damage dealt
		only works for fleshy units (not ships and catapults)
	
byte 85
	size: 3
	n = byte+1 (0-255)
	unit = byte+2 (0-104)
	prevent_loss[n]=unit
	for i from 0 to 255
		prevent_loss[i] will survive with 0 hp and receive unholy armor and fireshield
		they can be killed only if they have 0 hp after unholy armor gone
		(or polymorphed)
	
b 86	sneak_hide unit
	size: 3
	n = byte+1 (0-255)
	unit = byte+2 (0-104)
	sneak_hide[n]=unit
	for i from 0 to 255
		sneak_hide[i] will get very short inviz when received "stand ground" order
		if they move it dissappears very fast
	
b 87	TH-first restriction = True (by default TH-first is False in War2Mod)
	size: 1
	* pre-load stage trigger
	
b 88	can place fireshield to flying units
	size: 2
	byte+1 (bool)

b 89	more resources income with special buildings (each building gives res)
	size: 1
	*ex:	4 lumbermills give +100 wood (+25+25+25+25)
		2 castle and 1 keep give +50 gold (+20+20+10)

b 90	easy multicast for mages = true
	size: 1
	
b 91	special alliance
	size: 4
	player1= byte+1 (0-15)
	player2= byte+2 (0-15)
	player1 ally status for player2 = byte+3 (bool)
	
b 92	special vision
	size: 4
	player1= byte+1 (0-7)
	player2= byte+2 (0-7)
	player1 shared vision  status for player2 = byte+3 (bool)

b 93	pathfinding improve fix
	* pre-load stage trigger
	size: 1
	
b 94	ai fix
	* pre-load stage trigger
	size: 1
	
b 95	terrain remove
	terrain type = byte+1 (0 trees, 1 rocks, 2 walls)
	x = byte+2 (0-127)
	y = byte+3 (0-127)
	size: 4
	
b 96	reveal map
	x = byte+1 (0-127)
	y = byte+2 (0-127)
	players = byte+3 (0-255 bitmask 1 bit for each player)
	reveal_size = byte+4 (0-9)
	size: 5
	reveal map for players on coords with reveal_size
	
b 97	save/load ai broken bug fix
	* pre-load stage trigger
	size: 1

b 98	unit capture
	can units be captured on low hp
	size: 2
	byte+1 (bool)
	
b 99	value get unit stat
	size: 3
	if units list is not empty
		VAL[byte+1]=stat[byte+2] of first unit in list
	
100	show briefing
	size: 2
	briefing id = byte+1 (0-52)
	* pre-load stage trigger for campaign missions
	
101	victory = true
	size: 2
	show video id = byte+1 (0-16)
	
102   defeat = true
	size: 2
	show video id = byte+1 (0-16)
	
103	War2mod function call period
	size: 2
	call period = byte+1 (0-255) game cycles (200 by default in normal War2, 100 in War2Mod)
	* low values = faster triggers, but very low values in multiplayer = game can desync and all players drop
	* do not set smaller than 80 for multiplayer (99% game will drop if players have bad internet)
	
104	campaign = true
	size: 1
	* pre-load stage trigger
	
105	external level is completed? (check if another campaign level was completed)
	size: 5
	CRC of map = DWORD (byte+1,byte+2,byte+3,byte+4)
	* completed maps saved in recod.save file)
	* pre-load stage trigger
	
106	force set player race (only working if campaign trigger(104) was set)
	size: 3
	player = byte+1 (0-7)
	race = byte+2 (1-2)
	* pre-load stage trigger

107 create bullet
	size 6
	x = word+1 (0-4096)
	y = word+3 (0-4096)
	bullet type = byte+5 (0-28)

108 play sound
	size 5
	x = word+1 (0-127)
	y = word+3 (0-127)
	sound = word+5 (0-65535)

109 set upgrade
	size 4
	upgr = byte+1 (0-6)
	player = byte+2 (0-15)
	value = val[byte+3]
	
110 get upgrade
	size 4
	upgr = byte+1 (0-6)
	player = byte+2 (0-15)
	val[byte+3] will be = value

111 get kills of this trigger cycle
	size 5
	unit = byte+2
	player killer = byte+3
	player targer = byte+4
	val[byte+1] = amount of units player_target killed by player_killer in this current trigger cycle
	
112 get region center
	size 3
	val[byte+1] = X region center
	val[byte+2] = y region center

113 remove terrain in region
	size 2
	terrain type = byte+1 (0-2)
	
114-253	unused
	size: 1
	just skip doing nothing

254 then 255	end of triggers (used in replace stage to find end)
	size: 2
	* if this found in the game triggers itself then just skip and doing nothing


