note
	description: "[
		A {VIEW} that displays the Allied units that enter
		the {VITP_GAME} on turn 1.
		]"
	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
	ALLIED_STARTING_FORCES_VIEW

inherit

	ORDER_OF_APPEARANCE_VIEW
		redefine
			initialize,
			widget_factory,
			add_return_boxes,
			add_widgets,
			add_units,
			add_starting_control_widgets,
			add_miscellaneous_text,
			add_copyright_text
		end

create
	make

feature {NONE} -- Initialization

	initialize
			-- Set up attributes
		do
			nationality := {NATIONALITY_CONSTANTS}.allied
			Precursor
		end

	add_turns
			-- Add the "TURN X" and "TO date" texts
		local
			i: INTEGER
		do
			from i := 1
			until i > 1
			loop
				add_turn_text (i)
				i := i + 1
			end
		end

	add_return_boxes
			-- Add the "Returning Air/Land Units" boxes
			-- Redefined to do nothing
		do
		end

	add_widgets
			-- Create the EV_TEXT objects for the chart
		do
			Precursor
		end

	add_units
			-- Add {ATTACK_UNIT_WIDGETS} to Current
		local
			f: like widget_factory
		do
			Precursor
			f := widget_factory
				-- On Battleship Row (Pearl Harbor)
			add_model (positioned_widget (f.nevada_widget, nevada_cp))
			add_model (positioned_widget (f.arizona_widget, arizona_cp))
			add_model (positioned_widget (f.west_virginia_widget, west_virginia_cp))
			add_model (positioned_widget (f.tennessee_widget, tennessee_cp))
			add_model (positioned_widget (f.oklahoma_widget, oklahoma_cp))
			add_model (positioned_widget (f.maryland_widget, maryland_cp))
			add_model (positioned_widget (f.california_widget, california_cp))
			add_model (positioned_widget (f.pennsylvania_widget, pennsylvania_cp))
			add_model (positioned_widget (f.new_orleans_widget, new_orleans_cp))
			add_model (positioned_widget (f.san_francisco_widget, san_francisco_cp))
			add_model (positioned_widget (f.seventh_af_widget, seventh_af_cp))
				-- At Sea (cannot move)
			add_model (positioned_widget (f.hermes_widget, hermes_cp))
			add_model (positioned_widget (f.revenge_widget, revenge_cp))
			add_model (positioned_widget (f.prince_of_wales_widget, prince_of_wales_cp))
			add_model (positioned_widget (f.repulse_widget, repulse_cp))
			add_model (positioned_widget (f.fifth_af_widget, fifth_af_cp))
			add_model (positioned_widget (f.louisville_widget, louisville_cp))
			add_model (positioned_widget (f.pensacola_widget, pensacola_cp))
			add_model (positioned_widget (f.indianapolis_widget, indianapolis_cp))
			add_model (positioned_widget (f.minneapolis_widget, minneapolis_cp))
				-- In Port (may move)
			add_model (positioned_widget (f.houston_widget, houston_cp))
			add_model (positioned_widget (f.exeter_widget, exeter_cp))
			add_model (positioned_widget (f.de_ruyter_widget, de_ruyter_cp))
			add_model (positioned_widget (f.australia_ship_widget, australia_cp))
			add_model (positioned_widget (f.canberra_widget, canberra_cp))
				-- Group W
			add_model (positioned_widget (f.enterprise_widget, enterprise_cp))
			add_model (positioned_widget (f.salt_lake_city_widget, salt_lake_city_cp))
			add_model (positioned_widget (f.northampton_widget, northampton_cp))
			add_model (positioned_widget (f.chester_widget, chester_cp))
				-- Group X
			add_model (positioned_widget (f.lexington_widget, lexington_cp))
			add_model (positioned_widget (f.chicago_widget, chicago_cp))
			add_model (positioned_widget (f.portland_widget, portland_cp))
			add_model (positioned_widget (f.astoria_widget, astoria_cp))
				-- Group Y
			add_model (positioned_widget (f.saratoga_widget, saratoga_cp))
				-- Group Z
			add_model (positioned_widget (f.hornet_widget, hornet_cp))
			add_model (positioned_widget (f.yorktown_widget, yorktown_cp))
			add_model (positioned_widget (f.vincennes_widget, vincennes_cp))
			add_model (positioned_widget (f.quincy_widget, quincy_cp))
		end

	add_starting_control_widgets
			-- Add the "Starting Control" text and markers if required
		local
			cp:EV_COORDINATE
			t: EV_MODEL_TEXT
			s: STRING
			b: EV_MODEL_GROUP
		do
			Precursor
			create cp
				-- Add "Starting Control" widgets
			s := "STARTING %N CONTROL"
			t := new_text (s, turn_x_losses_font)
			cp.set (seventh_af_cp.x + 3 * air_size + air_size // 2, san_francisco_cp.y - ship_size // 3)
			t.set_x_y (cp.x, cp.y)
			world.extend (t)
				-- Position the `flag' marker
			cp.set (t.x, san_francisco_cp.y + air_size // 3)
			flag.set_x_y (cp.x, cp.y)
				-- Add boxes around the port names
			s := "Hawaian Islands %N%
					%U.S. Mandate %N%
					%Coral Sea %N%
					%South Pacific %N%
					%Central Pacific %N%
					%Indian Ocian %N%
					%Bay of Bengal %N%
					%Indonesia"
			b := new_jagged_box (s, 9, 9, 9, {MATH_CONST}.pi_2)
			b.set_x_y (flag.x, flag.y + air_size + 5 * gap_size)
			world.extend (b)
				-- Position `big_marker' and `little_marker' relative to `flag'
			big_marker.set_x_y (flag.x, chester_cp.y - ship_size // 4)
			little_marker.set_x_y (flag.x - air_size - air_size // 2, quincy_cp.y + air_size + air_size // 4)
				-- Add boxes around the port names
			s := "Pearl Harbor %N%
					%Samoa %N%
					%Australia %N%
					%Ceylon %N%
					%Singapore"
			b := new_jagged_box (s, 6, 9, 6, {MATH_CONST}.pi_2)
			b.set_x_y (flag.x, big_marker.y + ship_size - air_size // 3 )
			world.extend (b)
				-- Add boxes around the port names
			s := "%N%
					%Johnston Island %N%
					%Dutch Harbor %N%
					%Attu %N%
					%New Hebrides %N%
					%Guadalcanal %N%
					%Port Moreby %N%
					%Lae %N%
					%Midway %N%
					%Andaman Islands %N%
					%Phillipines"
			b := new_jagged_box (s, 9, 11, 9, 0)
			b.set_x_y (flag.x, little_marker.y)
			world.extend (b)
		end

	add_miscellaneous_text
			-- Create the remaining EV_TEXT objects for the chart
		local
			cp: EV_COORDINATE
			t: EV_MODEL_TEXT
			s: STRING
		do
			create cp
				-- On Battleship Row (Pearl Harbor)
			s := "ON BATTLESHIP ROW (PEARL HARBOR)"
			t := new_text (s, at_port_font)
			cp.set (west_virginia_cp.x, west_virginia_cp.y - air_size // 2)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- At Sea (cannot move)
			s := "AT SEA   (CANNOT MOVE)"
			t := new_text (s, at_port_font)
			cp.set (hermes_cp.x, hermes_cp.y - air_size // 2)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Bay of Bengal
			s := "BAY OF BENGAL"
			t := new_text (s, to_date_font)
			cp.set (hermes_cp.x, hermes_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Indonesia
			s := "INDONESIA"
			t := new_text (s, to_date_font)
			cp.set (prince_of_wales_cp.x, hermes_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Coral Sea
			s := "CORAL SEA"
			t := new_text (s, to_date_font)
			cp.set (louisville_cp.x, hermes_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- US Mandate
			s := "US MANDATE"
			t := new_text (s, to_date_font)
			cp.set (pensacola_cp.x, hermes_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Hawaiian Islands
			s := "HAWAIIAN ISLANDS"
			t := new_text (s, to_date_font)
			cp.set (indianapolis_cp.x, hermes_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- In Port (may move)
			s := "IN PORT   (MAY MOVE)"
			t := new_text (s, at_port_font)
			cp.set (houston_cp.x, houston_cp.y - air_size // 2)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Philippines
			s := "PHILIPPINES"
			t := new_text (s, to_date_font)
			cp.set (houston_cp.x, houston_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Singapore
			s := "SINGAPORE"
			t := new_text (s, to_date_font)
			cp.set (exeter_cp.x, houston_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Australia
			s := "AUSTRALIA"
			t := new_text (s, to_date_font)
			cp.set (australia_cp.x, houston_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Location Uncertain
			s := "LOCATION UNCERTAIN"
			t := new_text (s, at_port_font)
			cp.set (enterprise_cp.x, houston_cp.y - air_size // 2)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Group W
			s := "GROUP W"
			t := new_text (s, to_date_font)
			cp.set (enterprise_cp.x, houston_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Location Uncertain
			s := "LOCATION UNCERTAIN"
			t := new_text (s, at_port_font)
			cp.set (lexington_cp.x, lexington_cp.y - air_size // 2)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Group X
			s := "GROUP X"
			t := new_text (s, to_date_font)
			cp.set (lexington_cp.x, lexington_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Group Y
			s := "GROUP Y"
			t := new_text (s, to_date_font)
			cp.set (saratoga_cp.x, lexington_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- Group Z
			s := "GROUP Z"
			t := new_text (s, to_date_font)
			cp.set (hornet_cp.x, lexington_cp.y - air_size // 4)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
				-- 1 = Central Pacific...
			s := "1 = Central Pcific;  2,3 = Hawaiian Islands; 4-6 = U.S.A. -- arrival Turn 2"
			t := new_text (s, small_font)
			cp.set (astoria_cp.x + ship_size // 4, astoria_cp.y - air_size // 2)
			t.set_point_position (cp.x, cp.y)
			world.extend (t)
		end

	add_copyright_text
			-- Add the copy-right notices to each chart
		local
			rec: EV_MODEL_RECTANGLE
			w, h: INTEGER
			m: INTEGER		-- text margin in box
			cp: EV_COORDINATE
			t1, t2: EV_MODEL_TEXT
			s: STRING
			f: EV_FONT
		do
			create cp
			w := 5 * ship_size + air_size
			h := 2 * air_size
			m := gap_size
				-- Make the box
			cp.set (bottom_right_cp.x - w, bottom_right_cp.y + ship_size)
			create rec.make_rectangle (cp.x, cp.y, w, h)
			rec.set_foreground_color (color)
--			rec.set_background_color (lightened (color, 2.8))
			world.extend (rec)
				-- Design Department
			s := "DESIGN DEPARTMENT"
			f := small_font
			f.set_weight ({EV_FONT_CONSTANTS}.weight_bold)
			t1 := new_text (s, f)
			cp.set (rec.x , rec.point_a.y + 3 * m)
			t1.set_x_y (cp.x, cp.y)
			world.extend (t1)

				-- The left half of the text
			f.set_family ({EV_FONT_CONSTANTS}.family_modern)
			f.set_weight ({EV_FONT_CONSTANTS}.weight_thin)
			s := "%T We will answer questions about the play of this %N%
				%game at no charge but only if you enclose a %N%
				%stamped, self-addressed envelope with your query. %N%
				%Before writing to us however, we suggest %N%
				%thoughtful reference to the rules which should"
			t1 := new_text (s, f)
			cp.set (rec.point_a.x + m, rec.point_a.y + 5 * m)
			t1.set_point_position (cp.x, cp.y)
			world.extend (t1)
				-- The right half of the text
			s := "answer any question and save you time and %N%
				%postage.  For a current replacment parts price %N%
				%list send a stamped, self-addressed envelope to %N%
				%The Avalon Hill Co., 4517 Harford Rd.  Balti- %N%
				%more MD  21214"
			t2 := new_text (s, f)
			cp.set (rec.point_b.x - m - t2.width, t1.point_y)
			t2.set_point_position (cp.x, cp.y)
			world.extend (t2)
				-- The company name
			s := " The %N%
				%AVALON HILL %N%
				%Game Company"
			t2 := new_text (s, company_name_font)
			cp.set (0, bottom_right_cp.y + ship_size // 2)
			t2.set_point_position (cp.x, cp.y)
			world.extend (t2)
				-- The company address
			s := "4517 Harford Road, Baltimore, MD  21214"
			f.set_family ({EV_FONT_CONSTANTS}.family_modern)
			f.set_weight ({EV_FONT_CONSTANTS}.weight_bold)
			f.set_height (4)
			t2 := new_text (s, f)
			cp.set (top_left_cp.x + gap_size, bottom_right_cp.y + 3 * air_size)
			t2.set_point_position (cp.x, cp.y)
			world.extend (t2)
		end

feature -- Access

	location: LOCATION
			-- A {LOCATION} from the {VITP_GAME} used in `draw' to determine
			-- if a unit is on this chart or somewhere else (i.e. in the game.)
		do
			Result := game.allied_starting_forces_chart
		end

	title: STRING = "Allied Starting Forces"
			-- The text at the top of this chart

feature {NONE} -- Implementation

	widget_factory: ALLIED_FORCES_WIDGET_FACTORY
			-- Hold all the widgets

	company_name_font: EV_FONT
			-- Large, bold, and italic
		once
			create Result
			Result.set_height (11)
			Result.set_shape ({EV_FONT_CONSTANTS}.shape_italic)
			Result.set_weight ({EV_FONT_CONSTANTS}.weight_bold)
			Result.set_family ({EV_FONT_CONSTANTS}.family_roman)
		end

feature {NONE} -- Control point constants

	bottom_right_cp: EV_COORDINATE once create Result.make (254, 150) end
		-- Turn X text (not used)	
	turn_1_cp: EV_COORDINATE do create Result.make (7, 14) end
	turn_2_cp: EV_COORDINATE do create Result end
	turn_3_cp: EV_COORDINATE do create Result end
	turn_4_cp: EV_COORDINATE do create Result end
	turn_5_cp: EV_COORDINATE do create Result end
	turn_6_cp: EV_COORDINATE do create Result end
	turn_7_cp: EV_COORDINATE do create Result end
	turn_8_cp: EV_COORDINATE do create Result end
	turn_9_cp: EV_COORDINATE do create Result end
		-- To some date text (not used)
	to_dec_41_cp: EV_COORDINATE do create Result end
	to_may_42_cp: EV_COORDINATE do create Result end
	to_sep_42_cp: EV_COORDINATE do create Result end
	to_jan_43_cp: EV_COORDINATE do create Result end
	to_jun_43_cp: EV_COORDINATE do create Result end
	to_jan_44_cp: EV_COORDINATE do create Result end
	to_may_44_cp: EV_COORDINATE do create Result end
	to_oct_44_cp: EV_COORDINATE do create Result end
	to_jan_45_cp: EV_COORDINATE do create Result end
		-- Turn x losses (not used)
	turn_1_losses_cp: EV_COORDINATE do create Result end
	turn_2_losses_cp: EV_COORDINATE do create Result end
	turn_3_losses_cp: EV_COORDINATE do create Result end
	turn_4_losses_cp: EV_COORDINATE do create Result end
	turn_5_losses_cp: EV_COORDINATE do create Result end
	turn_6_losses_cp: EV_COORDINATE do create Result end
	turn_7_losses_cp: EV_COORDINATE do create Result end

		-- On Battleship Row
	nevada_cp: EV_COORDINATE do create Result.make (Turn_1_cp.x, Turn_1_cp.y + 12) end
	arizona_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 1 * ship_size, nevada_cp.y) end
	west_virginia_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 2 * ship_size, nevada_cp.y) end
	tennessee_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 3 * ship_size, nevada_cp.y) end
	oklahoma_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 4 * ship_size, nevada_cp.y) end
	maryland_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 5 * ship_size, nevada_cp.y) end
	california_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 6 * ship_size, nevada_cp.y) end
	pennsylvania_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 7 * ship_size, nevada_cp.y) end
	new_orleans_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 8 * ship_size, nevada_cp.y) end
	san_francisco_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 8 * ship_size, nevada_cp.y) end
	seventh_af_cp: EV_COORDINATE do create Result.make (nevada_cp.x + 9 * ship_size, nevada_cp.y + ship_size - air_size) end
		-- At Sea (cannot move)
	hermes_cp: EV_COORDINATE do create Result.make (turn_1_cp.x, nevada_cp.y + ship_size + 5 * gap_size) end
	revenge_cp: EV_COORDINATE do create Result.make (nevada_cp.x + ship_size, hermes_cp.y) end
	prince_of_wales_cp: EV_COORDINATE do create Result.make (revenge_cp.x + ship_size + 4 * gap_size, hermes_cp.y) end
	repulse_cp: EV_COORDINATE do create Result.make (prince_of_wales_cp.x + ship_size, hermes_cp.y) end
	fifth_af_cp: EV_COORDINATE do create Result.make (repulse_cp.x + ship_size, hermes_cp.y + ship_size - air_size) end
	louisville_cp: EV_COORDINATE do create Result.make (fifth_af_cp.x + air_size + 4 * gap_size, hermes_cp.y) end
	pensacola_cp: EV_COORDINATE do create Result.make (louisville_cp.x + ship_size + 4 * gap_size, hermes_cp.y) end
	indianapolis_cp: EV_COORDINATE do create Result.make (pensacola_cp.x + ship_size + 4 * gap_size, hermes_cp.y) end
	minneapolis_cp: EV_COORDINATE do create Result.make (indianapolis_cp.x + ship_size, hermes_cp.y) end
		-- In Port (may move)
	houston_cp: EV_COORDINATE do create Result.make (turn_1_cp.x, hermes_cp.y + ship_size + 5 * gap_size) end
	exeter_cp: EV_COORDINATE do create Result.make (houston_cp.x + ship_size + 4 * gap_size, houston_cp.y) end
	de_ruyter_cp: EV_COORDINATE do create Result.make (exeter_cp.x + ship_size, houston_cp.y) end
	australia_cp: EV_COORDINATE do create Result.make (de_ruyter_cp.x + ship_size + 4 * gap_size, houston_cp.y) end
	canberra_cp: EV_COORDINATE do create Result.make (australia_cp.x + ship_size, houston_cp.y) end
		-- Group W
	enterprise_cp: EV_COORDINATE do create Result.make (louisville_cp.x + ship_size, houston_cp.y) end
	salt_lake_city_cp: EV_COORDINATE do create Result.make (enterprise_cp.x + ship_size, houston_cp.y) end
	northampton_cp: EV_COORDINATE do create Result.make (salt_lake_city_cp.x + ship_size, houston_cp.y) end
	chester_cp: EV_COORDINATE do create Result.make (northampton_cp.x + ship_size, houston_cp.y) end
		-- Group X
	lexington_cp: EV_COORDINATE do create Result.make (turn_1_cp.x, houston_cp.y + ship_size + 5 * gap_size) end
	chicago_cp: EV_COORDINATE do create Result.make (lexington_cp.x + ship_size, lexington_cp.y) end
	portland_cp: EV_COORDINATE do create Result.make (chicago_cp.x + ship_size, lexington_cp.y) end
	astoria_cp: EV_COORDINATE do create Result.make (portland_cp.x + ship_size, lexington_cp.y) end
		-- Group Y
	saratoga_cp: EV_COORDINATE do create Result.make (astoria_cp.x + ship_size + 4 * gap_size, lexington_cp.y) end
		-- Group Z
	hornet_cp: EV_COORDINATE do create Result.make (saratoga_cp.x + ship_size + 4 * gap_size, lexington_cp.y) end
	yorktown_cp: EV_COORDINATE do create Result.make (hornet_cp.x + ship_size, lexington_cp.y) end
	vincennes_cp: EV_COORDINATE do create Result.make (yorktown_cp.x + ship_size, lexington_cp.y) end
	quincy_cp: EV_COORDINATE do create Result.make (vincennes_cp.x + ship_size, lexington_cp.y) end

end
