note
	description: "[
		A command to cause a {ATTACK_UNIT} to join another as a task force,
		If Current `is_task_force' already and make is called with `a_transfer'
		set to true it will first leave its current task force before joining
		the other; if `a_transfer' is false, all the units in Current's force
		will join the other.
		]"
	author: "Jimmy J. Johnson"

class
	LEAVE_TASK_FORCE_COMMAND

inherit

	VITP_COMMAND
		redefine
--			default_create,
			text,
			execute,
			undo
		end

--	LOCATION_CONSTANTS
--		undefine
--			default_create
--		end

--	ATTACK_UNIT_CONSTANTS		-- needed for `Default_ship' in `default_create'
--		undefine
--			default_create
--		end

create
--	default_create,
	make

feature {NONE} -- Initialization

--	default_create
--			-- Create an instance
--		do
--			Precursor {VITP_COMMAND}
--			unit := Default_ship
--			saved_unit := Default_ship
--			task_force_name := "No name:  (from {LEAVE_TASK_FORCE_COMMAND}.default_create"
--		end

	make (a_unit: like unit)
			-- Initialize a command that causes `a_unit' to leave its current task force.
		require
			unit_exists: a_unit /= Void
			unit_not_submarine: not attached {SUBMARINE} a_unit
			is_task_force: a_unit.is_task_force
		do
			default_create
			unit := a_unit
			task_force_name := unit.task_force.name
			saved_unit := unit.task_force.i_th(1)
			if saved_unit = unit then
				saved_unit := unit.task_force.i_th (2)
			end
			affected_objects.extend (unit.game)
		end

feature -- Access

	text: STRING
			-- Description of the command
		do
			Result := "COMMAND:  Leave Task Force -- "+ unit.name + " leaves " + task_force_name
		end

	unit: ATTACK_UNIT
			-- The unit to be moved

	task_force_name: STRING
			-- The name of the task force that `unit' leaves

feature -- Basic operations

	execute
			-- Perform the action
		do
			Precursor {VITP_COMMAND}
			unit.leave_force
		end

	undo
			-- Reverse the effects of executing the command
		do
			Precursor {VITP_COMMAND}
			unit.join_force (saved_unit)
		end

feature {NONE} -- Implementation

	saved_unit: ATTACK_UNIT
			-- Must save a unit from the Current task force in case of `undo'

end
