note
	description: "[
		A single cell contained in a {VITP_GRID}.
		The cell is one location at which an {ATTACK_UNIT} may be
		positioned.
		]"
	author:    "Jimmy J. Johnson"
	date:      "4/11/24"
	copyright: "Copyright (c) 2024, Jimmy J. Johnson"
	license:   "Eiffel Forum v2 (http://www.eiffel.com/licensing/forum.txt)"

class
	VITP_CELL

create
	make

feature {NONE} -- Initialization

	make (a_index: like index)
			-- Create a cell at x/y coordinates in `a_index'
		do
			index := a_index
		ensure
			position_assigned: index = a_index
		end

feature -- Access

	index: TUPLE [x, y: INTEGER]
			-- The location/row-column of this cell

	occupant: ATTACK_UNIT
			-- The unit that is at the location represented by Current
		require
			is_occupied: is_occupied
		do
			check attached occupant_imp as u then
				Result := u
			end
		end

feature -- Element change

	occupy (a_unit: like occupant)
			-- Place `a_unit' into Current
		require
			not_occupied: not is_occupied
		do
			occupant_imp := a_unit
		ensure
			is_occupied: is_occupied
			correct_occupier: occupant = a_unit
		end

	vacate
			-- Remove any `occupier' from Current
		do
			occupant_imp := Void
		ensure
			not_occupied: not is_occupied
		end

feature -- Status report

	is_occupied: BOOLEAN
			-- Is there a unit positioned in this cell?
		do
			Result := attached occupant_imp
		ensure
			definition: Result implies attached occupant_imp
		end

feature {NONE} -- Implementation

	occupant_imp: detachable like occupant
			-- Implementation for `occupant'

end
