# Events for Andean Abyss.

# TODO: format prompt "Remove N Piece(s)"
# TODO: prompt wording to match card texts

# Notes on difficult events:
#
#   5.1.3 - must do max possible
#     event 14, shaded 14, shaded 34, shaded 49 - place base and N troops/guerrillas
#     shaded 24 - remove 2 troops
#     event 30 - remove farc zone and remove farc base
#     event 43 - place terror and remove farc base
#     event 65 - (place or remove shipment) and (place or remove insurgent base)
#
#   Replace pieces - may only remove when unable to place available piece (check stacking if piece is available)
#     35, shaded 39, 40, shaded 50, 54, 57, shaded 57, 72
#
#   Remove X or replace X - exclusive choices
#     shaded 50, 54
#

EVENT 1
	log "1 Civic Action space each Support Phase requires Government Control and any cube."
	capability CAP_1ST_DIV

SHADED 1
	log "Civic Action requires at least 2 Troops and 2 Police."
	capability S_CAP_1ST_DIV

EVENT 2
	log "Sweep costs 1 Resource per space."
	capability CAP_OSPINA

SHADED 2
	log "Sweep Operations may target only 1 space per card."
	capability S_CAP_OSPINA

EVENT 3
	log "Assault costs 1 Resource per space."
	capability CAP_TAPIAS

SHADED 3
	log "Assault Operations may target only 1 space per card."
	capability S_CAP_TAPIAS

EVENT 4
	prompt "Add twice Econ of unsabotaged pipelines to Government Resources."
	space 3 is_unsabotaged_pipeline(s)
		auto_resources GOVT (2*data.spaces[game.vm.s].econ)
	endspace

SHADED 4
	prompt "Sabotage the 3 pipelines with highest value and no cubes."
	space 3 is_highest_value_pipeline_without_cubes(s)
		sabotage
	endspace

EVENT 5
	prompt "Place Police onto Pipelines."
	repeat 6
		space 1 is_pipeline(s) && has_available_piece(GOVT, POLICE)
			auto_place GOVT POLICE
			mark_space
		endspace
	endrepeat
	prompt "Flip 3 Guerrillas there or adjacent to Active."
	piece 3 is_any_guerrilla(p) && is_underground(p) && is_with_or_adjacent_to_mark(s, game.vm.m)
		activate
	endpiece

SHADED 5
	prompt "Shift space adjacent to a 3-Econ LoC by 2 levels toward Active Opposition."
	space 1 can_shift_opposition(s) && is_adjacent_to_3econ_loc(s)
		shift_opposition
		shift_opposition
	endspace

EVENT 6
	prompt "Select Opposition or Neutral Departments adjacent to Sabotage."
	space 2 is_dept(s) && is_pop(s) && !is_support(s) && is_adjacent_to_sabotage(s)
		set_passive_support
	endspace

SHADED 6
	prompt "Sabotage a pipeline."
	space 1 is_pipeline(s) && !has_sabotage(s)
		sabotage
		mark_space
	endspace
	prompt "Shift an Adjacent Department."
	space 1 can_shift_opposition(s) && is_dept(s) && is_adjacent(s, game.vm.m[0])
		shift_opposition
	endspace

EVENT 7
	log "Each Sabotage phase, Government may remove 1-3 Terror or Sabotage."
	capability CAP_7TH_SF

SHADED 7
	log "Sabotage phase - Sabotage LoCs with any Guerrillas equal to cubes."
	capability S_CAP_7TH_SF

EVENT 8
	current GOVT
	repeat 3
		if can_air_strike()
			free_air_strike
		else
			log "Government cannot Air Strike."
		endif
	endrepeat

SHADED 8
	resources GOVT -9

EVENT 9
	log "Assault treats Mountain as City."
	capability CAP_MTN_BNS

SHADED 9
	log "Assault in Mountain removes only 1 piece for 4 Troops."
	capability S_CAP_MTN_BNS

EVENT 10
	log "Air Lift moves any number of Troops."
	capability CAP_BLACK_HAWKS

SHADED 10
	log "Air Lift moves only 1 Troops cube."
	capability S_CAP_BLACK_HAWKS

EVENT 11
	log "1 Police may enter each Sweep space."
	capability CAP_NDSC

SHADED 11
	log "Operation Activates Guerrillas via Troops or Police, not both."
	capability S_CAP_NDSC

EVENT 12
	resources GOVT (Math.min(game.aid,20))
	aid 10

SHADED 12
	log "No Air Strike or Activation by Patrol until next Propaganda."
	momentum MOM_PLAN_COLOMBIA

EVENT 13
	log "Patrol conducts a free Assault in each LoC."
	capability CAP_METEORO

SHADED 13
	log "Patrols do not conduct a free Assault."
	capability S_CAP_METEORO

EVENT 14
	current GOVT
	# 5.1.3 - place base if possible!
	prompt "Place 1 Base and 3 Troops into any Department."
	if_space is_dept(s) && can_place_base_and_n(s, GOVT, 3, TROOPS)
	or_space is_dept(s) && can_stack_any(s, GOVT)
		auto_place GOVT BASE
		auto_place GOVT TROOPS
		auto_place GOVT TROOPS
		auto_place GOVT TROOPS
	endspace

SHADED 14
	# 5.1.3 - remove both base and cube if possible
	prompt "Remove 1 Government Base and 1 cube from a Department."
	if_space is_dept(s) && ( has_govt_base(s) && has_cube(s) )
	or_space is_dept(s) && ( has_govt_base(s) || has_cube(s) )
		prompt "Remove 1 Government Base."
		piece 1 is_piece_in_event_space(p) && is_govt_base(p)
			remove
		endpiece
		prompt "Remove 1 cube."
		piece 1 is_piece_in_event_space(p) && is_cube(p)
			remove
		endpiece
	endspace

EVENT 15
	roll
	resources GOVT (game.vm.die*4)

SHADED 15
	prompt "Shift a City from Neutral or Passive Support to Passive Opposition."
	space 1 is_city(s) && (is_neutral(s) || is_passive_support(s))
		set_passive_opposition
	endspace

EVENT 16
	prompt "Each Mountain, +5 Resources to Faction with most pieces."
	space all is_mountain(s)
		auto_resources (faction_with_most_pieces(game.vm.s)) 5
	endspace

SHADED 16
	resources GOVT -10

EVENT 17
	resources GOVT (Math.min(game.aid,20))
	aid 6

SHADED 17
	log "No Sweep or Assault in Departments until next Propaganda."
	momentum MOM_MADRID_DONORS

EVENT 18
	resources GOVT (Math.min(game.aid,20))
	aid 20

SHADED 18
	resources GOVT -6
	roll
	aid (-game.vm.die)

EVENT 19
	if game.current === GOVT
		prompt "Free Sweep or Assault in each space possible."
		space all can_sweep_activate(s) || can_assault_in_space(s)
			free_sweep_assault
			# TODO transfer dropped shipments early
		endspace
	else
		prompt "Free Attack or Terror in each space possible."
		space all can_terror_in_space(s) || can_attack_in_space(s)
			free_attack_terror
			# TODO transfer dropped shipments early
		endspace
	endif

EVENT 20
	current GOVT
	prompt "Move up to 6 FARC Guerillas into adjacent spaces."
	piece_undo_opt 6 is_farc_guerrilla(p)
		prompt "Move FARC Guerilla into an adjacent space."
		space_no_undo 1 is_adjacent(s, piece_space(game.vm.p)) && can_stack_any(s, FARC)
			move
		endspace
	endpiece

SHADED 20
	current FARC
	if can_free_march()
		free_march
	else
		log "FARC cannot March."
	endif
	prompt "Flip up to 3 FARC Guerrillas Underground."
	piece_undo_opt 3 is_farc_guerrilla(p) && is_active(p)
		underground
	endpiece

EVENT 21
	resources FARC -6
	prompt "Remove 1 FARC Base."
	piece_undo 1 is_farc_base(p)
		remove
	endpiece

SHADED 21
	resources FARC 6
	prompt "Place a FARC Base in a City or Department"
	space 1 (is_city(s) || is_dept(s)) && can_stack_base(s, FARC)
		auto_place FARC BASE
	endspace

EVENT 22
	prompt "Shift an Opposition space to Neutral."
	space 1 is_opposition(s)
		set_neutral
	endspace

SHADED 22
	log "May Agitate also in up to 3 spaces with FARC piece and no Government Control."
	momentum MOM_ALFONSO_CANO

EVENT 23
	prompt "In a Department, Activate all Guerrillas and remove all Cartels Bases."
	space 1 is_dept(s) && (has_any_underground_guerrilla(s) || has_cartels_base(s))
		prompt "Activate all Guerrillas."
		piece all is_piece_in_event_space(p) && is_any_guerrilla(p) && is_underground(p)
			activate
		endpiece
		prompt "Remove all Cartels Bases."
		piece all is_piece_in_event_space(p) && is_cartels_base(p)
			remove
		endpiece
	endspace

SHADED 23
	current GOVT
	prompt "Remove 3 Troops."
	piece_undo 3 is_troops(p)
		remove
	endpiece
	ineligible GOVT
	ineligible FARC

EVENT 24
	prompt "Shift a City to Active Support."
	space 1 is_city(s) && can_shift_support(s)
		set_active_support
	endspace
	ineligible FARC

SHADED 24
	# 5.1.3 - 2 troops priority
	prompt "Remove 2 Troops from a space with FARC pieces."
	if_space has_farc_piece(s) && count_pieces(s, GOVT, TROOPS) >= 2
	or_space has_farc_piece(s) && has_troops(s)
		prompt "Remove 2 Troops."
		piece 2 is_piece_in_event_space(p) && is_troops(p)
			remove
		endpiece
	endspace
	prompt "Shift a City with Support to Neutral."
	space 1 is_city(s) && is_support(s)
		set_neutral
	endspace


EVENT 25
	prompt "Remove all FARC pieces from 1 Mountain."
	space 1 is_mountain(s) && has_faction_piece(s, FARC)
		prompt "Remove all FARC pieces."
		piece all is_piece_in_event_space(p) && is_farc_piece(p)
			remove
		endpiece
	endspace

SHADED 25
	prompt "Place 3 FARC pieces into Antioquia or an adjacent Department."
	space 1 (s === ANTIOQUIA || (is_dept(s) && is_adjacent(ANTIOQUIA, s))) && can_stack_any(s, FARC)
		place FARC BASE_GUERRILLA
		place FARC BASE_GUERRILLA
		place FARC BASE_GUERRILLA
	endspace

EVENT 26
	current CARTELS
	prompt "All Cartels Guerrillas free Attack FARC."
	space all has_cartels_guerrilla(s) && has_farc_piece(s)
		free_attack_farc
		# TODO transfer dropped shipments early
	endspace

SHADED 26
	prompt "Transfer 6 Resources from Cartels to FARC for each space with Cartels Base and FARC Guerrilla."
	# prompt "Transfer 6 Resources from Cartels to FARC for each space with both."
	space all has_cartels_base(s) && has_farc_guerrilla(s) && game.resources[CARTELS] > 0
		auto_transfer CARTELS FARC 6
	endspace

EVENT 27
	current GOVT
	repeat 3
		if can_air_lift() || can_eradicate() || can_air_strike()
			free_govt_special_activity
		else
			log "Government cannot execute any Special Activities."
		endif
	endrepeat

SHADED 27
	log "Until next Propaganda, no Government Special Activities where Guerrilla."
	momentum MOM_MISIL_ANTIAEREO

EVENT 28
	prompt "Remove up to 3 Insurgent pieces from a space next to Venezuela."
	space 1 is_next_to_venezuela(s) && has_insurgent_piece(s)
		# Note: up to negates requirement for maximumum damage
		prompt "Remove up to 3 Insurgent pieces."
		piece_opt 3 is_piece_in_event_space(p) && is_insurgent_piece(p)
			remove
		endpiece
	endspace

SHADED 28
	prompt "Place FARC Base in a Department next to Venezuela."
	space 1 is_dept(s) && is_next_to_venezuela(s) && can_stack_base(s, FARC)
		auto_place FARC BASE
	endspace
	prompt "Sabotage each empty LoC touching Cúcuta."
	space all is_loc(s) && is_adjacent(CUCUTA, s) && is_empty(s) && !has_sabotage(s)
		sabotage
	endspace

EVENT 29
	current GOVT
	prompt "Activate all FARC and free Assault in 1 space."
	# TODO: Madrid Donors, Senado & Camara, etc
	space 1 has_underground_guerrilla(s, FARC) || ( assault_kill_count(s) > 0 && (has_farc_piece(s) || has_exposed_piece(s, AUC) || has_exposed_piece(s, CARTELS)) )
		prompt "Activate all FARC."
		piece all is_piece_in_event_space(p) && is_farc_guerrilla(p) && is_underground(p)
			activate
		endpiece
		if can_assault_in_space(game.vm.s)
			free_assault
		else
			log "Government cannot Assault."
		endif
	endspace

SHADED 29
	current FARC_AUC
	prompt "Execute 2 free Ambushes in 1 space."
	space 1 has_piece(s, game.current, GUERRILLA) && has_enemy_piece(s)
		repeat 2
			prompt "Execute 2 free Ambushes with any Guerrilla without Activating."
			piece_undo 1 is_piece_in_event_space(p) && is_piece(p, game.current, GUERRILLA) && has_enemy_piece(s)
				free_ambush_without_activating
			endpiece
		endrepeat
	endspace

EVENT 30
	# 5.1.3 - remove both farc zone and farc base if possible
	prompt "Remove 1 FARC Zone and 1 FARC Base there."
	if_space is_farc_zone(s) && has_piece(s, FARC, BASE)
	or_space is_farc_zone(s)
		remove_farc_zone
		prompt "Remove 1 FARC Base."
		piece 1 is_piece_in_event_space(p) && is_farc_base(p)
			remove
		endpiece
	endspace


SHADED 30
	current GOVT
	place_farc_zone
	set_space (game.vm.farc_zone)
	auto_place FARC BASE

EVENT 31
	prompt "Shift 2 Cities 1 level toward Active Support."
	space 2 is_city(s) && can_shift_support(s)
		shift_support
	endspace
	prompt "Shift 1 Department 1 level toward Active Support."
	space 1 is_dept(s) && can_shift_support(s)
		shift_support
	endspace

SHADED 31
	prompt "Shift 3 spaces from Passive Opposition to Active Opposition."
	space 3 is_passive_opposition(s)
		set_active_opposition
	endspace

EVENT 32
	prompt "Shift 2 spaces from Neutral or Passive Opposition to Passive Support."
	space 2 is_neutral(s) || is_passive_opposition(s)
		set_passive_support
	endspace

SHADED 32
	resources FARC 12

EVENT 33
	prompt "Remove up to 3 Insurgent pieces from a space bordering Ecuador."
	space 1 is_next_to_ecuador(s) && has_insurgent_piece(s)
		piece_opt 3 is_piece_in_event_space(p) && is_insurgent_piece(p)
			remove
		endpiece
	endspace

SHADED 33
	capability EVT_SUCUMBIOS
	set_space ECUADOR
	place (game.current) ANY_PIECE
	place (game.current) ANY_PIECE

EVENT 34
	# -1 = all insurgent factions
	resources -1 -5

SHADED 34
	current FARC_AUC_CARTELS
	# 5.1.3 - place base if possible
	prompt "Place 2 Guerrillas and 1 Base into a 0 Population Department."
	if_space is_zero_pop_dept(s) && can_place_base_and_n(s, game.current, 2, GUERRILLA)
	or_space is_zero_pop_dept(s) && can_stack_any(s, game.current)
		auto_place (game.current) BASE
		auto_place (game.current) GUERRILLA
		auto_place (game.current) GUERRILLA
	endspace

EVENT 35
	prompt "Replace Cartels Bases in 1 Department with Police."
	space 1 is_dept(s) && has_cartels_base(s) && can_replace_with(s, GOVT, POLICE)
		prompt "Replace Cartels Bases with Police."
		piece all is_piece_in_event_space(p) && is_cartels_base(p) && can_replace_with(s, GOVT, POLICE)
			remove
			auto_place GOVT POLICE
		endpiece
	endspace
	aid 3

SHADED 35
	prompt "Shift a Department with a Cartels Base 2 levels toward Active Opposition."
	space 1 is_dept(s) && has_cartels_base(s) && can_shift_opposition(s)
		shift_opposition
		shift_opposition
	endspace

EVENT 36
	eligible (game.current)
	asm game.vm.zona_de_convivencia = 1
	asm game.vm.save_current = game.current
	current GOVT
	place_farc_zone
	set_space (game.vm.farc_zone)
	auto_place FARC BASE
	current (game.vm.save_current)
	prompt "Shift 2 adjacent spaces 1 level toward Active Support."
	space 2 is_adjacent(game.vm.farc_zone, s) && can_shift_support(s)
		shift_support
	endspace

EVENT 37
	current GOVT
	prompt "Free Sweep or Assault FARC within each space; AUC Guerrillas act as Troops."
	space all can_sweep_activate(s, FARC) || can_assault_in_space_faction(s, FARC)
		free_sweep_assault_farc
		# TODO transfer dropped shipments early
	endspace

SHADED 37
	current AUC
	if can_free_march()
		free_march
		prompt "Free Ambush at any 1 destination."
		space 1 set_has(game.vm.march, s) && has_underground_guerrilla(s, AUC) && has_enemy_piece(s)
			prompt "Free Ambush."
			piece 1 is_piece_in_event_space(p) && is_underground_guerrilla(p, AUC)
				free_ambush
			endpiece
		endspace
	else
		log "AUC cannot March."
	endif

EVENT 38
	prompt "Remove all Active AUC Guerrillas from up to 3 spaces with cubes or Support."
	space_opt 3 (has_cube(s) || is_support(s)) && has_active_guerrilla(s, AUC)
		prompt "Remove all AUC Guerrillas."
		piece all is_piece_in_event_space(p) && is_active_guerrilla(p, AUC)
			remove
		endpiece
	endspace

SHADED 38
	prompt "All AUC Guerrillas in spaces with cubes or Support to Underground."
	space all (has_cube(s) || is_support(s)) && has_active_guerrilla(s, AUC)
		prompt "All AUC Guerrillas to Underground."
		piece all is_piece_in_event_space(p) && is_active_guerrilla(p, AUC)
			underground
		endpiece
	endspace

EVENT 39
	prompt "Place Police into each of 6 Departments."
	space 6 is_dept(s) && can_stack_any(s, GOVT) && has_available_piece(GOVT, POLICE)
		auto_place GOVT POLICE
	endspace

SHADED 39
	prompt "In up to 3 Departments, replace 1 Police with AUC Guerrilla."
	space_opt 3 is_dept(s) && has_police(s) && can_replace_with(s, AUC, GUERRILLA)
		prompt "Replace 1 Police with AUC Guerrilla."
		piece 1 is_piece_in_event_space(p) && is_police(p) && can_replace_with(s, AUC, GUERRILLA)
			remove
			auto_place AUC GUERRILLA
		endpiece
	endspace

EVENT 40
	prompt "Replace 3 AUC Guerrillas with Police."
	piece_undo 3 is_auc_guerrilla(p) && can_replace_with(s, GOVT, POLICE)
		set_piece_space
		remove
		auto_place GOVT POLICE
		set_space -1
	endpiece

SHADED 40
	prompt "Move all cubes in a Department with AUC to any Cities."
	space 1 is_dept(s) && has_auc_piece(s) && has_cube(s)
		prompt "Move all cubes to any Cities."
		piece all is_piece_in_event_space(p) && is_cube(p)
			save_space
			prompt "Move cube to any City."
			space_no_undo 1 is_city(s)
				move
			endspace
			restore_space
		endpiece
	endspace
	prompt "Place 1 AUC piece in each of 2 Cities."
	space 2 is_city(s)
		place AUC BASE_GUERRILLA
	endspace

EVENT 41
	resources AUC -6
	prompt "Remove all AUC pieces from 1 space."
	space 1 has_auc_piece(s)
		prompt "Remove all AUC pieces."
		piece all is_piece_in_event_space(p) && is_auc_piece(p)
			remove
		endpiece
	endspace

SHADED 41
	count_spaces has_auc_piece(s) && has_cartels_piece(s)
	log `${game.vm.count} spaces with AUC and Cartels pieces.`
	resources AUC (3*game.vm.count)

EVENT 42
	prompt "Shift 2 Neutral spaces to Passive Support."
	space 2 is_neutral(s)
		set_passive_support
	endspace
	resources GOVT 3

SHADED 42
	log `No Sweep or Assault against ${faction_name[game.current]} until next Propaganda.`
	if game.current === GOVT
		log "No effect."
	endif
	if game.current === FARC
		momentum MOM_SENADO_FARC
	endif
	if game.current === AUC
		momentum MOM_SENADO_AUC
	endif
	if game.current === CARTELS
		momentum MOM_SENADO_CARTELS
	endif

EVENT 43
	# 5.1.3 - farc bases if possible
	prompt "Place 2 Terror and remove all FARC Bases from a Department with Troops."
	if_space is_dept(s) && has_troops(s) && has_piece(s, FARC, BASE)
	or_space is_dept(s) && has_troops(s)
		terror
		terror
		prompt "Remove all FARC Bases."
		piece all is_piece_in_event_space(p) && is_farc_base(p)
			remove
		endpiece
	endspace

SHADED 43
	prompt "Place 2 Terror in a Department with Troops."
	space 1 is_dept(s) && has_troops(s)
		terror
		terror
	endspace
	aid -9

EVENT 44
	prompt "Shift a non-Opposition City to Active Support."
	space 1 is_city(s) && !is_opposition(s) && can_shift_support(s)
		set_active_support
	endspace
	resources GOVT 3

SHADED 44
	prompt "Shift a City from Support to Neutral."
	space 1 is_city(s) && is_support(s)
		set_neutral
	endspace
	resources GOVT -3

EVENT 45
	prompt "Shift each space with cubes and Terror 1 level toward Active Support."
	space all has_cube(s) && has_terror(s) && can_shift_support(s)
		shift_support
	endspace

SHADED 45
	count_spaces has_faction_piece(s, AUC)
	log `${game.vm.count} spaces with AUC pieces.`
	aid (-game.vm.count)
	roll
	resources GOVT (-game.vm.die)

EVENT 46
	current FARC_AUC_CARTELS
	prompt "Execute free Terror with any Guerrilla."
	space 1 has_piece(s, game.current, GUERRILLA)
		piece 1 is_piece_in_event_space(p) && is_piece(p, game.current, GUERRILLA)
			free_terror_with_piece
			terror
			terror_aid_cut
		endpiece
		prompt "Remove enemy pieces."
		piece_undo 2 is_piece_in_event_space(p) && is_enemy_piece(p)
			remove
		endpiece
		if is_pop(game.vm.s)
			set_passive_support_or_passive_opposition
		endif
	endspace

EVENT 47
	# Note: see event 59
	if AUTOMATIC
		log "All AUC Guerrillas to Active."
		asm for_each_piece(AUC, GUERRILLA, p => { if (piece_space(p) !== AVAILABLE) set_active(p) })
	else
		prompt "All AUC Guerrillas to Active."
		piece all is_auc_guerrilla(p) && is_underground(p)
			activate
		endpiece
	endif
	current GOVT
	prompt "All Police free Assault AUC as if Troops."
	space all can_assault_in_space_faction(s, AUC)
		free_assault_auc
		# TODO transfer dropped shipments early
	endspace

SHADED 47
	current AUC
	prompt "Place 2 AUC Guerrillas in Cúcuta."
	space 1 s === CUCUTA
		auto_place AUC GUERRILLA
		auto_place AUC GUERRILLA
		if has_underground_guerrilla(game.vm.s, AUC)
			prompt "Execute free Terror in Cúcuta."
			piece 1 is_piece_in_event_space(p) && is_auc_guerrilla(p) && is_underground(p)
				free_terror_with_piece
				terror_aid_cut
			endpiece
		else
			# Special case: Free Terror without a piece.
			terror
			shift_neutral
			aid -3
		endif
	endspace
	prompt "Flip any 2 AUC Guerrillas Underground."
	piece 2 is_auc_guerrilla(p) && is_active(p)
		underground
	endpiece

EVENT 48
	prompt "Remove Opposition or FARC Base adjacent to 3-Econ pipeline."
	select_space_or_piece (s)=>(is_opposition(s)&&is_adjacent_to_3econ_pipeline(s)) (p,s)=>(is_farc_base(p)&&is_adjacent_to_3econ_pipeline(s))
	if game.vm.p >= 0
		remove
	endif
	if game.vm.s >= 0
		# https://boardgamegeek.com/thread/1132718/article/15062894#15062894
		set_neutral
	endif

SHADED 48
	prompt "Shift 2 Cities other than Bogotá 1 level toward Active Opposition."
	space 2 s !== BOGOTA && is_city(s) && can_shift_opposition(s)
		shift_opposition
	endspace

EVENT 49
	prompt "Permanently remove 3 available AUC Guerrillas."
	remove_permanently AUC GUERRILLA
	remove_permanently AUC GUERRILLA
	remove_permanently AUC GUERRILLA

SHADED 49
	# 5.1.3 - place base if possible
	prompt "Place an AUC Guerrilla and Base in any Department."
	if_space is_dept(s) && can_place_base_and_n(s, AUC, 1, GUERRILLA)
	or_space is_dept(s) && can_stack_any(s, AUC)
		auto_place AUC BASE
		auto_place AUC GUERRILLA
	endspace

EVENT 50
	current GOVT
	repeat 3
		if !game.vm.opt
			prompt "Place up to 3 Police into any Departments."
			space_opt 1 is_dept(s) && can_stack_any(s, GOVT)
				auto_place GOVT POLICE
			endspace
		endif
	endrepeat

SHADED 50
	# Note: strictly remove or replace (see event 54)
	prompt "Remove any 2 Police or replace them with available AUC Guerrillas."
	piece_undo 1 is_police(p)
		set_piece_space
		remove
		place_opt AUC GUERRILLA
		set_space -1
	endpiece
	if game.vm.opt
		prompt "Remove 1 more Police."
		piece_undo 1 is_police(p)
			remove
		endpiece
	else
		prompt "Replace 1 more Police with AUC Guerrilla."
		piece_undo 1 is_police(p) && can_replace_with(s, AUC, GUERRILLA)
			set_piece_space
			remove
			auto_place AUC GUERRILLA
			set_space -1
		endpiece
	endif

EVENT 51
	if is_any_pipeline_sabotaged()
		prompt "Remove all Pipeline Sabotage."
		space all is_pipeline(s) && has_sabotage(s)
			remove_sabotage
		endspace
	else
		resources GOVT 12
	endif

SHADED 51
	prompt "Sabotage 3 Pipelines with or adjacent to FARC Guerrillas."
	space 3 is_pipeline(s) && is_with_or_adjacent_to_farc_guerrilla(s)
		sabotage
	endspace

EVENT 52
	prompt "Shift 2 City or Mountain each 1 level toward Active Support."
	space 2 (is_city(s) || is_mountain(s)) && can_shift_support(s)
		shift_support
	endspace

SHADED 52
	prompt "Place an AUC Base into a space with AUC."
	space 1 has_auc_piece(s) && can_stack_base(s, AUC)
		auto_place AUC BASE
	endspace
	resources AUC (count_pieces_on_map(AUC,BASE))

EVENT 53
	current FARC_AUC_CARTELS
	prompt "Select Departments to move Guerrillas between."
	space 1 is_dept(s)
		mark_space
	endspace
	if has_piece(game.vm.m[0], game.current, GUERRILLA)
		prompt "Select Departments to move Guerrillas between."
		space 1 (s !== game.vm.m[0]) && is_dept(s)
			mark_space
		endspace
	else
		prompt "Select Departments to move Guerrillas between."
		space 1 is_dept(s) && has_piece(s, game.current, GUERRILLA)
			mark_space
		endspace
	endif
	prompt "Move Guerrillas between Departments."
	piece_range 1 2 is_piece(p, game.current, GUERRILLA) && (s === game.vm.m[0] || s === game.vm.m[1])
		if piece_space(game.vm.p) === game.vm.m[0]
			set_space (game.vm.m[1])
		else
			set_space (game.vm.m[0])
		endif
		move
		underground
		set_space -1
	endpiece

EVENT 54
	# Note: strictly remove or replace (see shaded 50)
	prompt "Remove up to 2 Guerrillas or replace them with with another Faction's Guerrillas."
	piece_undo 1 is_any_guerrilla(p)
		set_piece_space
		remove
		place_opt (piece_enemy_factions(game.vm.p)) GUERRILLA
		set_space -1
	endpiece
	if game.vm.opt
		prompt "Remove 1 more Guerrilla."
		# TODO: don't remove just placed piece
		piece_undo_opt 1 is_any_guerrilla(p)
			remove
		endpiece
	else
		prompt "Replace 1 more Guerrilla."
		# TODO: don't replace just placed piece
		piece_undo_opt 1 is_any_guerrilla(p) && ( can_replace_with(s, FARC, GUERRILLA) || can_replace_with(s, AUC, GUERRILLA) || can_replace_with(s, CARTELS, GUERRILLA) )
			set_piece_space
			remove
			place_opt (piece_enemy_factions(game.vm.p)) GUERRILLA
			set_space -1
		endpiece
	endif

EVENT 55
	prompt "Remove 2 Shipments."
	shipment 2 true
		remove_shipment
	endshipment
	prompt "Remove 5 Cartels Guerrillas."
	piece 5 is_cartels_guerrilla(p)
		remove
	endpiece
	aid 3

SHADED 55
	prompt "Shift 3 spaces with Cartels pieces 1 level toward Active Opposition."
	space 3 can_shift_opposition(s) && has_cartels_piece(s)
		shift_opposition
	endspace

EVENT 56
	transfer CARTELS GOVT 15

SHADED 56
	count_pieces is_cartels_piece(p) && is_city(s)
	log `${game.vm.count} Cartels pieces in Cities.`
	resources CARTELS (2*game.vm.count)
	prompt "Place a Cartels Base in each of 2 Cities."
	space 2 is_city(s) && can_stack_base(s, CARTELS)
		auto_place CARTELS BASE
	endspace

EVENT 57
	prompt "Replace up to 3 Cartels pieces with Police."
	piece_undo_opt 3 is_cartels_piece(p) && can_replace_with(s, GOVT, POLICE)
		set_piece_space
		remove
		auto_place GOVT POLICE
		set_space -1
	endpiece

SHADED 57
	prompt "In each of 2 spaces replace a Police with any Cartels piece."
	# TODO: prompt "Replace a Police with any Cartels piece in 2 spaces."
	space 2 has_police(s)
		prompt "Replace a Police with any Cartels piece."
		piece 1 is_piece_in_event_space(p) && is_police(p) && (can_replace_with(s, CARTELS, GUERRILLA) || can_replace_with(s, CARTELS, BASE))
			remove
			place CARTELS BASE_GUERRILLA
		endpiece
	endspace

EVENT 58
	resources CARTELS -6
	prompt "Remove all Cartels Guerrillas."
	piece all is_cartels_guerrilla(p)
		remove
	endpiece

SHADED 58
	current CARTELS
	prompt "Relocate up to 4 Police to any spaces."
	piece_undo_opt 4 is_police(p)
		prompt "Relocate Police to any space."
		space_no_undo 1 can_stack_piece(s, GOVT, POLICE)
			move
		endspace
	endpiece

EVENT 59
	# Note: see event 47
	if AUTOMATIC
		log "All Cartels Guerrillas to Active."
		asm for_each_piece(CARTELS, GUERRILLA, p => { if (piece_space(p) !== AVAILABLE) set_active(p) })
	else
		prompt "All Cartels Guerrillas to Active."
		piece all is_cartels_guerrilla(p) && is_underground(p)
			activate
		endpiece
	endif
	current GOVT
	prompt "Free Assault against Cartels in each space."
	space all can_assault_in_space_faction(s, CARTELS)
		free_assault_cartels
		# TODO transfer dropped shipments early
	endspace

SHADED 59
	if AUTOMATIC
		log "All Cartels Guerrillas to Underground."
		asm for_each_piece(CARTELS, GUERRILLA, set_underground)
	else
		prompt "Flip all Cartels Guerrillas Underground."
		piece all is_cartels_guerrilla(p) && is_active(p)
			underground
		endpiece
	endif
	current CARTELS
	prompt "Relocate up to 3 Cartels Guerrillas anywhere."
	piece_undo_opt 3 is_cartels_guerrilla(p)
		prompt "Relocate Cartels Guerrilla anywhere."
		space_no_undo 1 !is_event_piece_space(s) && can_stack_piece(s, CARTELS, GUERRILLA)
			move
		endspace
	endpiece

EVENT 60
	prompt "Remove all Cartels pieces from 2 Cities or 1 Department."
	space 2 has_cartels_piece(s) && ((is_city(s) && (game.vm.ss.length === 0 || is_city(game.vm.ss[0]))) || (is_dept(s) && game.vm.ss.length === 0))
		prompt "Remove all Cartels pieces."
		piece all is_piece_in_event_space(p) && is_cartels_piece(p)
			remove
		endpiece
	endspace
	resources GOVT 6

SHADED 60
	current CARTELS
	prompt "Place a Cartels Base in each of 2 Cities."
	space 2 is_city(s) && can_stack_base(s, CARTELS)
		auto_place CARTELS BASE
	endspace
	prompt "Free Bribe in 1 space."
	space 1 !is_empty(s)
		free_bribe
	endspace

EVENT 61
	prompt "Remove all Cartels pieces from 1 City."
	space 1 is_city(s) && has_cartels_piece(s)
		prompt "Remove all Cartels pieces."
		piece all is_piece_in_event_space(p) && is_cartels_piece(p)
			remove
		endpiece
	endspace
	resources CARTELS -6

SHADED 61
	prompt "Place 1 Cartels Base into each of 3 Departments with no Cartels pieces."
	space 3 is_dept(s) && !has_cartels_piece(s) && can_stack_base(s, CARTELS)
		auto_place CARTELS BASE
	endspace

EVENT 62
	prompt "Remove up to 3 Insurgent pieces for 0 Population Forests."
	piece_undo_opt 3 is_insurgent_piece(p) && is_zero_pop_forest(s)
		remove
	endpiece

SHADED 62
	prompt "Place 1 Cartels Base each in Guainia, Vaupés, and Amazonas."
	space 3 (s === GUAINIA || s === VAUPES || s === AMAZONAS) && can_stack_base(s, CARTELS)
		auto_place CARTELS BASE
	endspace

EVENT 63
	current CARTELS
	prompt "In each space with Cartels Guerrillas..."
	space all has_cartels_guerrilla(s)
		prompt "Remove all but one Cartels Guerrilla."
		piece all is_piece_in_event_space(p) && is_cartels_guerrilla(p) && count_pieces(s, CARTELS, GUERRILLA) > 1
			remove
		endpiece
		prompt "Free Terror with remaining Cartels Guerrilla."
		piece 1 is_piece_in_event_space(p) && is_cartels_guerrilla(p)
			free_terror_with_piece
		endpiece
	endspace
	terror_aid_cut
	ineligible CARTELS

EVENT 64
	repeat 2
		prompt "Place 2 Shipments with FARC Guerrillas in the same spaces as Cartels Bases."
		if has_available_shipment()
			asm game.vm.shipment = find_available_shipment()
			piece_undo 1 is_farc_guerrilla(p) && has_cartels_base(s)
				place_shipment
			endpiece
		endif
	endrepeat

SHADED 64
	asm game.vm.total = 0
	count_pieces is_cartels_base(p) && is_city(s)
	log `${game.vm.count} Cartels Bases in Cities.`
	asm game.vm.total += 2 * game.vm.count
	count_pieces is_cartels_base(p) && is_dept(s)
	log `${game.vm.count} Cartels Bases in Departments.`
	asm game.vm.total += game.vm.count
	resources CARTELS (game.vm.total)

EVENT 65
	# 5.1.3 - do both shipment and base if possible
	prompt "Place or remove 1 Shipment and Insurgent Base in any Mountain Department."
	if_space is_mountain(s) && ( can_place_or_remove_shipment(s) && can_place_or_remove_insurgent_base(s) )
	or_space is_mountain(s) && ( can_place_or_remove_shipment(s) || can_place_or_remove_insurgent_base(s) )
		place_or_remove_shipment
		place_or_remove_insurgent_base
	endspace

EVENT 66
	prompt "Remove 3 Cartels Bases from Forest."
	piece_undo 3 is_cartels_base(p) && is_forest(s)
		remove
	endpiece

SHADED 66
	prompt "Place Cartels Base into each Forest that already has one."
	space all is_forest(s) && has_cartels_base(s) && can_stack_base(s, CARTELS)
		auto_place CARTELS BASE
	endspace

EVENT 67
	resources CARTELS -20

SHADED 67
	log "This Resources phase, Cartels add Resources equal to 4 x Bases."
	momentum MOM_MEXICAN_TRAFFICKERS

EVENT 68
	prompt "Remove 2 Cartels pieces or up to 2 Shipments from coastal spaces."
	select_shipment_or_cartels_piece_in_coastal_space
	if game.vm.p >= 0
		remove
		prompt "Remove 1 more Cartels piece from coastal spaces."
		piece 1 is_coastal_space(s) && is_cartels_piece(p)
			remove
		endpiece
	endif
	if game.vm.sh >= 0
		remove_shipment
		prompt "Remove up to 1 more Shipment from coastal spaces."
		shipment_opt 1 is_coastal_space(s)
			remove_shipment
		endshipment
	endif

SHADED 68
	count_pieces is_cartels_piece(p) && is_coastal_space(s)
	log `${game.vm.count} Cartels pieces in coastal spaces.`
	resources CARTELS (2*game.vm.count)

EVENT 69
	prompt "Select source space."
	if game.current === GOVT
		space 1 has_cube(s)
			mark_space
		endspace
	else
		space 1 has_piece(s, game.current, GUERRILLA)
			mark_space
		endspace
	endif
	prompt "Select destination Department."
	space 1 game.vm.m && (s !== game.vm.m[0]) && is_within_adjacent_depts(s, game.vm.m[0], 3) && can_stack_any(s, game.current)
		if game.current === GOVT
			prompt "Move cubes to destination."
			piece_undo_opt all (s === game.vm.m[0]) && is_cube(p) && can_stack_any(game.vm.s, GOVT)
				move
			endpiece
			free_train_sweep_assault
		else
			prompt "Move Guerrillas to destination."
			piece_undo_opt all (s === game.vm.m[0]) && is_piece(p, game.current, GUERRILLA) && can_stack_any(game.vm.s, game.current)
				move
			endpiece
			free_rally_attack_terror
		endif
	endspace

EVENT 70
	count_spaces is_forest(s) && !has_any_guerrilla(s)
	log `${game.vm.count} Forests without Guerrillas.`
	resources GOVT (6*game.vm.count)

SHADED 70
	current FARC_AUC_CARTELS
	prompt "Free Terror in each Forest and +3 Resources per Terror."
	space all is_forest(s) && has_piece(s, game.current, GUERRILLA)
		prompt "Free Terror with any 1 Guerrilla."
		piece 1 is_piece_in_event_space(p) && is_piece(p, game.current, GUERRILLA)
			free_terror_with_piece
			auto_resources (game.current) 3
		endpiece
	endspace
	terror_aid_cut

EVENT 71
	prompt "Remove a Guerrilla from Chocó."
	set_space CHOCO
	piece 1 is_any_guerrilla(p) && s === CHOCO
		remove
		resources (piece_faction(game.vm.p)) -5
	endpiece

SHADED 71
	capability EVT_DARIEN
	prompt "Place 1-2 Bases in Panamá."
	space 1 s === PANAMA
		auto_place (game.current) BASE
		place_opt (game.current) BASE
	endspace

EVENT 72
	prompt "Replace all Cartels Guerrillas in 2 spaces with other Guerrillas."
	space 2 has_cartels_guerrilla(s) && ( can_replace_with(s, FARC, GUERRILLA) || can_replace_with(s, AUC, GUERRILLA) )
		prompt "Replace all Cartels Guerrillas with other Guerrillas."
		piece_undo all is_piece_in_event_space(p) && is_cartels_guerrilla(p) && ( can_replace_with(s, FARC, GUERRILLA) || can_replace_with(s, AUC, GUERRILLA) )
			remove
			place FARC_AUC GUERRILLA
		endpiece
	endspace

SHADED 72
	if has_pieces_on_map(CARTELS, BASE)
		while has_piece(AVAILABLE, CARTELS, GUERRILLA)
			prompt "Place all available Cartels Guerrillas into spaces with Cartels Bases."
			asm game.vm.p = find_piece(AVAILABLE, CARTELS, GUERRILLA)
			space 1 has_cartels_base(s) && can_stack_piece(s, CARTELS, GUERRILLA)
				auto_place CARTELS GUERRILLA
			endspace
		endwhile
	endif