note description: "[ Representation of a submarine in VITP. ]" author: "Jimmy J. Johnson" deferred class SUBMARINE inherit ATTACK_UNIT redefine patrol_distance, raid_distance, -- arrival_position, join_force, -- inapplicable leave_force, -- inapplicable internal_is_movable end feature -- Access patrol_distance: INTEGER = 1000 -- How may sea areas can Current move through as patroller? -- Just set to a very large number. raid_distance: INTEGER = 1000 -- How may sea areas can Current move through as raider? -- Just set to a very large number. -- arrival_position: like position -- -- The location (latitude/longitude-like coordinates) where Current -- -- will enter the game. Redefine to make it enter at its own position. -- do -- if nationality = game.japanese then -- Result := [200, 50] -- else -- Result := [750, 600] -- end -- end patrollable_sea_areas: LINKED_SET [SEA_AREA] -- A list containing each {SEA_AREA} which Current can patrol -- from its `home_port' at this point in the game do create Result.make end raidable_sea_areas: LINKED_SET [SEA_AREA] -- A list containing each {SEA_AREA} which Current can raid -- from its `home_port' at this point in the game do create Result.make from game.sea_areas.start until game.sea_areas.after loop Result.extend (game.sea_areas.item_for_iteration) game.sea_areas.forth end end feature -- Status report is_sunk: BOOLEAN = False -- Submarines do not take fire is_patrollable: BOOLEAN = False -- Can this unit be a patroller for area control purposes? is_raidable: BOOLEAN = False -- Can this unit be a raider? is_patrolling: BOOLEAN = False -- Is this unit a patroller (as opposed to a raider)? -- Air units a `is_patrollable' but don't move as patrollers. is_raiding: BOOLEAN = False -- Is this unit a raider? feature -- Basic operations return_to_port (a_port: PORT) require -- is_return_allowed: is_at_sea and then a_port.controller = nationality and then -- (location.adjoins (a_port) or else a_port.is_major) do location := a_port end repair -- Do repairs on the ship require -- is_in_port: location.is_port port_has_repair_capability: do end join_force (a_other: ATTACK_UNIT) -- Join forces with `a_other' as a single `task_force' do check do_not_call: false then -- Because inapplicable to {AIR_UNIT} end end leave_force -- Remove Current from the `task_force' to which it belongs, but only -- if there are other ships in the force, and put it in its own. do check do_not_call: false then -- Because inapplicable to {AIR_UNIT} end end feature -- Query is_incompatible_position (a_position: VITP_POSITION): BOOLEAN -- Is `a_position' located on a unit with which Current is NOT -- allowed to `join_force' (e.g. on a submarine or an enemy)? local u_list: VITP_TABLE [ATTACK_UNIT] au: ATTACK_UNIT do if not is_in_game then Result := false else u_list := game.all_attack_units from u_list.start until u_list.after or else Result loop au := u_list.item_for_iteration Result := au.contains_position (a_position) u_list.forth end end -- Temp for testing Result := false end feature {NONE} -- Implementation internal_is_movable: BOOLEAN -- Can Current (not the `task_force') move at this time? local sop: VITP_SEQUENCE_OF_PLAY do sop := game.sequence_of_play Result := not is_sunk and (sop.is_moving_submarine_step) -- or else -- sop.is_returning_submarine_to_port_step) end end