165 lines
3.6 KiB
Plaintext
165 lines
3.6 KiB
Plaintext
|
note
|
||
|
description: "[
|
||
|
Representation of a ship in VITP.
|
||
|
]"
|
||
|
author: "Jimmy J. Johnson"
|
||
|
|
||
|
deferred class
|
||
|
SHIP
|
||
|
|
||
|
inherit
|
||
|
|
||
|
ATTACK_UNIT
|
||
|
redefine
|
||
|
is_bottomed,
|
||
|
internal_is_movable
|
||
|
end
|
||
|
|
||
|
feature -- Status report
|
||
|
|
||
|
is_sunk: BOOLEAN
|
||
|
-- Has this ship been sunk?
|
||
|
do
|
||
|
Result := (is_at_sea and damage > defense_factor) or
|
||
|
(not is_at_sea and damage > 2 * defense_factor)
|
||
|
end
|
||
|
|
||
|
is_bottomed: BOOLEAN
|
||
|
-- Is this ship in port with too much damage to sail?
|
||
|
do
|
||
|
Result := is_in_port and damage <= 2 * defense_factor
|
||
|
end
|
||
|
|
||
|
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
|
||
|
|
||
|
set_patrolling
|
||
|
-- Make Current [and other `task_force' units] a patrol force
|
||
|
require
|
||
|
can_patrol: is_patrollable
|
||
|
do
|
||
|
from task_force.start
|
||
|
until task_force.is_after
|
||
|
loop
|
||
|
if attached {SHIP} task_force.item as s and then s.is_patrollable then
|
||
|
s.internal_set_raiding (false)
|
||
|
end
|
||
|
task_force.forth
|
||
|
end
|
||
|
is_raiding := False
|
||
|
ensure
|
||
|
is_patrolling: is_patrolling
|
||
|
end
|
||
|
|
||
|
set_raiding
|
||
|
-- Make Current [and other `task_force' units] a raid force
|
||
|
require
|
||
|
can_raid: is_raidable
|
||
|
do
|
||
|
from task_force.start
|
||
|
until task_force.is_after
|
||
|
loop
|
||
|
if attached {SHIP} task_force.item as s and then s.is_raidable then
|
||
|
s.internal_set_raiding (true)
|
||
|
end
|
||
|
task_force.forth
|
||
|
end
|
||
|
is_raiding := true
|
||
|
ensure
|
||
|
is_raiding: is_raiding
|
||
|
end
|
||
|
|
||
|
feature -- Status report
|
||
|
|
||
|
is_patrolling: BOOLEAN
|
||
|
-- Is this unit a patroller (as opposed to a raider)?
|
||
|
do
|
||
|
Result := not is_raiding
|
||
|
end
|
||
|
|
||
|
is_raiding: BOOLEAN
|
||
|
-- Is this unit a raider?
|
||
|
|
||
|
is_patrollable: BOOLEAN = True
|
||
|
-- Can this unit be a patroller for area control purposes?
|
||
|
|
||
|
is_raidable: BOOLEAN
|
||
|
-- Can this unit be a raider?
|
||
|
|
||
|
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
|
||
|
tf: TASK_FORCE
|
||
|
u_list: VITP_TABLE [ATTACK_UNIT]
|
||
|
au: ATTACK_UNIT
|
||
|
do
|
||
|
if not is_in_game then
|
||
|
Result := false
|
||
|
-- elseif i_boat.contains_position (a_position) or f_boat.contains_position (a_position) then
|
||
|
-- Result := true
|
||
|
else
|
||
|
if nationality = game.japanese then
|
||
|
u_list := game.allied_attack_units
|
||
|
else
|
||
|
u_list := game.japanese_attack_units
|
||
|
end
|
||
|
from u_list.start
|
||
|
until u_list.after or else Result
|
||
|
loop
|
||
|
au := u_list.item_for_iteration
|
||
|
Result := au.is_in_game and then au.contains_position (a_position)
|
||
|
u_list.forth
|
||
|
end
|
||
|
end
|
||
|
-- Temp for testing
|
||
|
Result := false
|
||
|
end
|
||
|
|
||
|
feature {SHIP} -- Implementation
|
||
|
|
||
|
internal_set_raiding (a_value: BOOLEAN)
|
||
|
-- Used by `set_patrolling' and `set_raiding' to change
|
||
|
-- status of a single unit in Current's `task_force'
|
||
|
do
|
||
|
is_raiding := a_value
|
||
|
end
|
||
|
|
||
|
feature {NONE} -- Implmentation
|
||
|
|
||
|
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 := Precursor {ATTACK_UNIT}
|
||
|
-- Account for turn-1 ships that can't move.
|
||
|
if Result and then sop.turn = 1 and sop.is_allied_player then
|
||
|
-- Only some allied ships can move on turn 1
|
||
|
Result := (Current = game.de_ruyter or Current = game.exeter or
|
||
|
Current = game.houston or Current = game.australia or
|
||
|
Current = game.canberra)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|