note
	description: "[
		The Sequence of Play step in VITP in which the Japanese
		player moves his arriving and returning units to the
		game board.
		]"
	author:    "Jimmy J. Johnson"
	date:      "11/11/23"
	copyright: "Copyright (c) 2023, Jimmy J. Johnson"
	license:   "Eiffel Forum v2 (http://www.eiffel.com/licensing/forum.txt)"

class
	JAPANESE_REINFORCEMENT_STEP

inherit

	GAME_STEP
		redefine
			player,
			is_completed,
			is_executable,
			execute
		end

create
	make

feature -- Access

	name: STRING
			-- Displayable name of Current step
		do
			Result := "Japanese Placing Arriving and Returning Units"
		end

	player: like {NATIONALITY_CONSTANTS}.Japanese
			-- The player to which this step applies
		do
			Result := {NATIONALITY_CONSTANTS}.japanese
		end

feature -- Status report

	is_completed: BOOLEAN
			-- Are all actions to be accomplished in this
			-- state finished, allowing `advance' to the
			-- next state?
		local
			sop: VITP_SEQUENCE_OF_PLAY
			p: like {NATIONALITY_CONSTANTS}.japanese
			i: INTEGER
			tab: VITP_TABLE [ATTACK_UNIT]
			u: ATTACK_UNIT
		do
			sop := game.sequence_of_play
			tab := game.turn_x_units (sop.turn, game.japanese_attack_units)
			Result := true
			from tab.start
			until not Result or else tab.after
			loop
				u := tab.item_for_iteration
				Result := u.is_in_game
				tab.forth
			end
			io.put_string (generating_type.name + ".is_completed:  " + Result.out + "%N")
		end

	is_executable: BOOLEAN
			-- Does this step have actions that can be
			-- automatically executed?
		local
			t: INTEGER
		do
			t := game.sequence_of_play.turn
			Result := not game.arriving_japanese_submarines (t).is_empty or else
					not game.arriving_japanese_amphibious_units (t).is_empty or else
					not game.arriving_japanese_air_units (t).is_empty or else
					not game.arriving_japanese_ships (t).is_empty
		end

feature -- Basic_operations

	execute
			-- Move remaining Japanese reinforcements to the board
		local
			com: REINFORCE_COMMAND
		do
			create com.make (game)
			game.command_manager.add_command (com)
		end

end
