init
This commit is contained in:
204
jj_vitp/Interface/commands/join_task_force_command.e
Normal file
204
jj_vitp/Interface/commands/join_task_force_command.e
Normal file
@@ -0,0 +1,204 @@
|
||||
note
|
||||
description: "[
|
||||
A command to cause a {ATTACK_UNIT} to join another as a task force,
|
||||
If Current `is_task_force' already and make is called with `a_transfer'
|
||||
set to true it will first leave its current task force before joining
|
||||
the other; if `a_transfer' is false, all the units in Current's force
|
||||
will join the other.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
JOIN_TASK_FORCE_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
-- LOCATION_CONSTANTS
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
-- ATTACK_UNIT_CONSTANTS -- needed for `Default_ship' in `default_create'
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- create saved_units.make
|
||||
-- unit := Default_ship
|
||||
-- other_unit := Default_ship
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit; a_other_unit: like unit; a_transfer: BOOLEAN)
|
||||
-- Initialize a command that causes `a_unit' to join `a_other_unit' as a task_force
|
||||
-- If `a_transfer' then `a_unit' leaves its task force before joining `a_other_unit'.
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
other_exists: a_other_unit /= Void
|
||||
unit_not_submarine: not attached {SUBMARINE} a_unit
|
||||
other_not_submarine: not attached {SUBMARINE} a_other_unit
|
||||
not_same_task_force: (a_unit.is_task_force and a_other_unit.is_task_force) implies
|
||||
a_unit.task_force /= a_other_unit.task_force
|
||||
local
|
||||
tf: TASK_FORCE
|
||||
i: INTEGER
|
||||
do
|
||||
default_create
|
||||
create saved_units.make
|
||||
is_transferring := a_transfer
|
||||
unit := a_unit
|
||||
other_unit := a_other_unit
|
||||
-- If both units comprise a task force, then must mark so the units
|
||||
-- comprising the task force of `unit' are saved for undo purposes.
|
||||
if a_other_unit.is_task_force then
|
||||
if a_unit.is_task_force then
|
||||
if is_transferring then
|
||||
saved_other_unit_imp := some_other_unit_in_task_force
|
||||
else
|
||||
is_two_task_forces := true
|
||||
tf := a_unit.task_force
|
||||
from i := 1
|
||||
until i > tf.count
|
||||
loop
|
||||
-- Save units to be removed from `other_unit' on `undo'
|
||||
saved_units.extend (tf.i_th (i))
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
affected_objects.extend (unit.game)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Join Task Force -- "+ unit.name + " joins "
|
||||
if other_unit.is_task_force then
|
||||
Result := Result + other_unit.task_force.first.name
|
||||
else
|
||||
Result := Result + other_unit.name
|
||||
end
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit to be moved
|
||||
|
||||
other_unit: ATTACK_UNIT
|
||||
-- The other unit to which `unit' is to be joined as a task force
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
if is_transferring then
|
||||
unit.leave_force
|
||||
end
|
||||
unit.join_force (other_unit)
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
local
|
||||
m1, m2: detachable ATTACK_UNIT
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
-- Removed the saved_units from the task force
|
||||
from saved_units.start
|
||||
until saved_units.exhausted
|
||||
loop
|
||||
saved_units.item.leave_force
|
||||
saved_units.forth
|
||||
end
|
||||
unit.leave_force
|
||||
-- Restore the saved units to their own task force
|
||||
if is_transferring then
|
||||
unit.join_force (saved_other_unit)
|
||||
else
|
||||
-- Must restore all the units to their own task force
|
||||
check
|
||||
multiple_units: saved_units.count >= 2
|
||||
-- because it would not have been a task force during creation,
|
||||
-- leading to creation and saving of the list of units
|
||||
end
|
||||
from
|
||||
saved_units.start
|
||||
m1 := saved_units.first
|
||||
saved_units.forth
|
||||
until saved_units.exhausted
|
||||
loop
|
||||
m2 := saved_units.item
|
||||
m2.join_force (m1)
|
||||
saved_units.forth
|
||||
end
|
||||
check
|
||||
unit.task_force /= other_unit.task_force
|
||||
-- because original task force was restored
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_transferring: BOOLEAN
|
||||
-- Is `unit' being transferred out of its task force?
|
||||
|
||||
is_two_task_forces: BOOLEAN
|
||||
-- Will the command, at creation, join two task forces?
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
some_other_unit_in_task_force: ATTACK_UNIT
|
||||
-- A unit other than `unit' that is in the `task_force' of `unit'
|
||||
require
|
||||
is_task_force: unit.is_task_force
|
||||
local
|
||||
tf: TASK_FORCE
|
||||
i: INTEGER
|
||||
do
|
||||
tf := unit.task_force
|
||||
Result := tf.i_th (1)
|
||||
from i := 1
|
||||
until Result /= unit
|
||||
loop
|
||||
Result := tf.i_th (i)
|
||||
i := i + 1
|
||||
end
|
||||
end
|
||||
|
||||
saved_other_unit: ATTACK_UNIT
|
||||
-- In case we need to restore during an undo
|
||||
do
|
||||
check attached saved_other_unit_imp as ou then
|
||||
Result := ou
|
||||
end
|
||||
end
|
||||
|
||||
saved_other_unit_imp: detachable ATTACK_UNIT
|
||||
-- In case we need to restore during an undo
|
||||
|
||||
saved_units: LINKED_LIST [ATTACK_UNIT]
|
||||
-- Used during undo when `unit' was a task force
|
||||
|
||||
end
|
120
jj_vitp/Interface/commands/leave_task_force_and_move_command.e
Normal file
120
jj_vitp/Interface/commands/leave_task_force_and_move_command.e
Normal file
@@ -0,0 +1,120 @@
|
||||
note
|
||||
description: "[
|
||||
A {VITP_COMMAND} that removes a unit from its current task
|
||||
force and changes the unit's position and location.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
LEAVE_TASK_FORCE_AND_MOVE_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- create leave_command
|
||||
-- create reposition_command
|
||||
-- create move_command
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit; a_position: like position; a_location: LOCATION)
|
||||
-- Initialize a command that can reposition `a_unit' to `a_position'
|
||||
-- and move it to `a_location'.
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
position_exists: a_position /= Void
|
||||
location_exists: a_location /= Void
|
||||
do
|
||||
default_create
|
||||
create leave_command.make (a_unit)
|
||||
create reposition_command.make (a_unit, a_position)
|
||||
create move_command.make (a_unit, a_location)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Leave Task Force & Move -- "+ unit.name + " from " + old_location.name
|
||||
Result := Result + " to " + location.name
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit that this command operates on
|
||||
do
|
||||
Result := leave_command.unit
|
||||
end
|
||||
|
||||
position: VITP_POSITION
|
||||
-- The position to which `unit' is to be moved
|
||||
do
|
||||
Result := reposition_command.position
|
||||
end
|
||||
|
||||
location: LOCATION
|
||||
-- The location to which `unit' is to be moved
|
||||
do
|
||||
Result := move_command.location
|
||||
end
|
||||
|
||||
old_position: VITP_POSITION
|
||||
-- The position from which `unit' was moved
|
||||
do
|
||||
Result := reposition_command.old_position
|
||||
end
|
||||
|
||||
old_location: LOCATION
|
||||
-- The locatiopn from which `unit' was moved
|
||||
do
|
||||
Result := move_command.old_location
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
leave_command.execute
|
||||
move_command.execute
|
||||
reposition_command.execute
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
reposition_command.undo
|
||||
move_command.undo
|
||||
leave_command.undo
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
leave_command: LEAVE_TASK_FORCE_COMMAND
|
||||
-- Command whose execution removes the unit from its task force
|
||||
|
||||
reposition_command: REPOSITION_COMMAND
|
||||
-- Command whose execution changes the unit's `position'
|
||||
|
||||
move_command: MOVE_COMMAND
|
||||
-- Command whose execution changes the unit's `location'.
|
||||
|
||||
end
|
@@ -0,0 +1,99 @@
|
||||
note
|
||||
description: "[
|
||||
A {VITP_COMMAND} that removes a unit from its current task force
|
||||
and changes the unit's `position'.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
LEAVE_TASK_FORCE_AND_REPOSITION_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- create leave_command
|
||||
-- create reposition_command
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit; a_position: like position)
|
||||
-- Initialize a command that can reposition `a_unit' to `a_position'
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
location_exists: a_position /= Void
|
||||
do
|
||||
default_create
|
||||
create leave_command.make (a_unit)
|
||||
create reposition_command.make (a_unit, a_position)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Leave Task Force & Reposition -- "+ unit.name + " from " + old_position.out
|
||||
Result := Result + " to " + position.out
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit that this command operates on
|
||||
do
|
||||
Result := leave_command.unit
|
||||
end
|
||||
|
||||
position: VITP_POSITION
|
||||
-- The position to which `unit' is to be moved
|
||||
do
|
||||
Result := reposition_command.position
|
||||
end
|
||||
|
||||
old_position: VITP_POSITION
|
||||
-- The position from which `unit' was moved
|
||||
do
|
||||
Result := reposition_command.old_position
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
leave_command.execute
|
||||
reposition_command.execute
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
reposition_command.undo
|
||||
leave_command.undo
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
leave_command: LEAVE_TASK_FORCE_COMMAND
|
||||
-- Command whose execution removes the unit from its task force
|
||||
|
||||
reposition_command: REPOSITION_COMMAND
|
||||
-- Command whose execution changes the units `position'
|
||||
|
||||
end
|
101
jj_vitp/Interface/commands/leave_task_force_command.e
Normal file
101
jj_vitp/Interface/commands/leave_task_force_command.e
Normal file
@@ -0,0 +1,101 @@
|
||||
note
|
||||
description: "[
|
||||
A command to cause a {ATTACK_UNIT} to join another as a task force,
|
||||
If Current `is_task_force' already and make is called with `a_transfer'
|
||||
set to true it will first leave its current task force before joining
|
||||
the other; if `a_transfer' is false, all the units in Current's force
|
||||
will join the other.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
LEAVE_TASK_FORCE_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
-- LOCATION_CONSTANTS
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
-- ATTACK_UNIT_CONSTANTS -- needed for `Default_ship' in `default_create'
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- unit := Default_ship
|
||||
-- saved_unit := Default_ship
|
||||
-- task_force_name := "No name: (from {LEAVE_TASK_FORCE_COMMAND}.default_create"
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit)
|
||||
-- Initialize a command that causes `a_unit' to leave its current task force.
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
unit_not_submarine: not attached {SUBMARINE} a_unit
|
||||
is_task_force: a_unit.is_task_force
|
||||
do
|
||||
default_create
|
||||
unit := a_unit
|
||||
task_force_name := unit.task_force.name
|
||||
saved_unit := unit.task_force.i_th(1)
|
||||
if saved_unit = unit then
|
||||
saved_unit := unit.task_force.i_th (2)
|
||||
end
|
||||
affected_objects.extend (unit.game)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Leave Task Force -- "+ unit.name + " leaves " + task_force_name
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit to be moved
|
||||
|
||||
task_force_name: STRING
|
||||
-- The name of the task force that `unit' leaves
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
unit.leave_force
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
unit.join_force (saved_unit)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
saved_unit: ATTACK_UNIT
|
||||
-- Must save a unit from the Current task force in case of `undo'
|
||||
|
||||
end
|
94
jj_vitp/Interface/commands/move_command.e
Normal file
94
jj_vitp/Interface/commands/move_command.e
Normal file
@@ -0,0 +1,94 @@
|
||||
note
|
||||
description: "[
|
||||
Command used to move widgets in VITP
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
MOVE_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
-- LOCATION_CONSTANTS
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
-- ATTACK_UNIT_CONSTANTS
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- unit := Default_ship
|
||||
-- location := Still_in_box
|
||||
-- old_location := Still_in_box
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit; a_location: like location)
|
||||
-- Initialize a command that can move `a_unit' to `a_to_location'
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
location_exists: a_location /= Void
|
||||
do
|
||||
default_create
|
||||
unit := a_unit
|
||||
location := a_location
|
||||
old_location := a_unit.game.still_in_box
|
||||
affected_objects.extend (unit)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Move -- "+ unit.name + " from " + old_location.name + " to " + location.name
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit to be moved
|
||||
|
||||
location: LOCATION
|
||||
-- The location to which `unit' is to be moved
|
||||
|
||||
old_location: LOCATION
|
||||
-- The location from which `unit' was moved
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
old_location := unit.location
|
||||
unit.set_location (location)
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
unit.set_location (old_location)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
end
|
95
jj_vitp/Interface/commands/rebase_command.e
Normal file
95
jj_vitp/Interface/commands/rebase_command.e
Normal file
@@ -0,0 +1,95 @@
|
||||
note
|
||||
description: "[
|
||||
Command for changing the `home_base' of units.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
REBASE_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
-- LOCATION_CONSTANTS
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
-- ATTACK_UNIT_CONSTANTS
|
||||
-- undefine
|
||||
-- default_create
|
||||
-- end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- unit := Default_ship
|
||||
-- -- Just pick a port
|
||||
-- port := Attu
|
||||
-- old_port := Attu
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit; a_port: like port)
|
||||
-- Initialize a command that can change the `home_port of `a_unit'
|
||||
-- to `a_port'
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
port_exists: a_port /= Void
|
||||
do
|
||||
default_create
|
||||
unit := a_unit
|
||||
port := a_port
|
||||
old_port := a_port
|
||||
affected_objects.extend (unit)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Rebase -- "+ unit.name + " from " + old_port.name + " to " + port.name
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit to be moved
|
||||
|
||||
port: PORT
|
||||
-- The port to which `unit' is to be rebased
|
||||
|
||||
old_port: PORT
|
||||
-- The port from which `unit' was rebased
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
old_port := unit.home_port
|
||||
unit.set_home_port (port)
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
unit.set_home_port (old_port)
|
||||
end
|
||||
|
||||
|
||||
end
|
171
jj_vitp/Interface/commands/reinforce_command.e
Normal file
171
jj_vitp/Interface/commands/reinforce_command.e
Normal file
@@ -0,0 +1,171 @@
|
||||
note
|
||||
description: "[
|
||||
Command for moving groups of ships from the turn card to the board.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
REINFORCE_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
text,
|
||||
execute,
|
||||
undo,
|
||||
is_executable
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_game: VITP_GAME)
|
||||
-- Create an instance
|
||||
do
|
||||
default_create
|
||||
create moves.make
|
||||
create repositions.make
|
||||
create joins.make
|
||||
create rebasings.make
|
||||
vitp_game := a_game
|
||||
affected_objects.extend (a_game)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
vitp_game: VITP_GAME
|
||||
-- The game in which this command executes.
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "Reinforce"
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
-- Multiple ships come on as a task force, multiple LBA come
|
||||
-- on together, as do multiple amphibious units.
|
||||
local
|
||||
sop: VITP_SEQUENCE_OF_PLAY
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
-- Get the ships
|
||||
sop := vitp_game.sequence_of_play
|
||||
if sop.player = {NATIONALITY_CONSTANTS}.japanese then
|
||||
place_units (vitp_game.arriving_japanese_ships (sop.turn))
|
||||
place_units (vitp_game.arriving_japanese_air_units (sop.turn))
|
||||
place_units (vitp_game.arriving_japanese_amphibious_units (sop.turn))
|
||||
place_units (vitp_game.arriving_japanese_submarines (sop.turn))
|
||||
else
|
||||
place_units (vitp_game.arriving_allied_ships (sop.turn))
|
||||
place_units (vitp_game.arriving_allied_air_units (sop.turn))
|
||||
place_units (vitp_game.arriving_allied_amphibious_units (sop.turn))
|
||||
place_units (vitp_game.arriving_allied_submarines (sop.turn))
|
||||
end
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
from joins.start
|
||||
until joins.after
|
||||
loop
|
||||
joins.item.undo
|
||||
joins.forth
|
||||
end
|
||||
from repositions.start
|
||||
until repositions.after
|
||||
loop
|
||||
repositions.item.undo
|
||||
repositions.forth
|
||||
end
|
||||
from moves.start
|
||||
until moves.after
|
||||
loop
|
||||
moves.item.undo
|
||||
moves.forth
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_executable: BOOLEAN
|
||||
-- Can the command be executed?
|
||||
local
|
||||
sop: VITP_SEQUENCE_OF_PLAY
|
||||
do
|
||||
sop := vitp_game.sequence_of_play
|
||||
Result := Precursor {VITP_COMMAND} and
|
||||
sop.is_reinforcement_step
|
||||
end
|
||||
|
||||
moves: LINKED_LIST [MOVE_COMMAND]
|
||||
-- List of commands that move all the reinforcements
|
||||
|
||||
repositions: LINKED_LIST [REPOSITION_COMMAND]
|
||||
-- List of commands that change the position of the reinforcements
|
||||
|
||||
rebasings: LINKED_LIST [REBASE_COMMAND]
|
||||
-- List of commands that change the `home_port' of the reinforcement
|
||||
|
||||
joins: LINKED_LIST [JOIN_TASK_FORCE_COMMAND]
|
||||
-- List of commands that cause units to form a task force
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
|
||||
place_units (a_group: VITP_TABLE [ATTACK_UNIT])
|
||||
-- Get `a_group' [i.e. a unit type] and place in game
|
||||
require
|
||||
group_exists: a_group /= Void
|
||||
local
|
||||
sop: VITP_SEQUENCE_OF_PLAY
|
||||
u, u2: ATTACK_UNIT
|
||||
tab: VITP_TABLE [ATTACK_UNIT]
|
||||
move_com: MOVE_COMMAND
|
||||
pos_com: REPOSITION_COMMAND
|
||||
rebase_com: REBASE_COMMAND
|
||||
join_com: JOIN_TASK_FORCE_COMMAND
|
||||
ht: HASH_TABLE [LINKED_LIST [ATTACK_UNIT], LOCATION] -- units entering given location
|
||||
u_list: LINKED_LIST [ATTACK_UNIT]
|
||||
do
|
||||
sop := vitp_game.sequence_of_play
|
||||
create ht.make (100)
|
||||
tab := vitp_game.turn_x_units (sop.turn, a_group)
|
||||
from tab.start
|
||||
until tab.after
|
||||
loop
|
||||
u := tab.item_for_iteration
|
||||
create move_com.make (u, u.arrival_location)
|
||||
create pos_com.make (u, u.arrival_position)
|
||||
create rebase_com.make (u, u.arrival_port)
|
||||
moves.extend (move_com)
|
||||
repositions.extend (pos_com)
|
||||
rebasings.extend (rebase_com)
|
||||
move_com.execute
|
||||
pos_com.execute
|
||||
rebase_com.execute
|
||||
if ht.has (u.arrival_location) then
|
||||
check attached {LINKED_LIST [ATTACK_UNIT]} ht.item (u.arrival_location) as otl_list then
|
||||
u2 := otl_list.first
|
||||
create join_com.make (u, u2, false)
|
||||
joins.extend (join_com)
|
||||
join_com.execute
|
||||
end
|
||||
else
|
||||
create u_list.make
|
||||
u_list.extend (u)
|
||||
ht.extend (u_list, u.arrival_location)
|
||||
end
|
||||
tab.forth
|
||||
end
|
||||
end
|
||||
|
||||
end
|
96
jj_vitp/Interface/commands/reposition_command.e
Normal file
96
jj_vitp/Interface/commands/reposition_command.e
Normal file
@@ -0,0 +1,96 @@
|
||||
note
|
||||
description: "[
|
||||
A {VITP_COMMAND} that changes the `position' of a unit.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
REPOSITION_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
VITP_COMMAND
|
||||
redefine
|
||||
-- default_create,
|
||||
text,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
create
|
||||
-- default_create,
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
-- default_create
|
||||
-- -- Create an instance
|
||||
-- do
|
||||
-- Precursor {VITP_COMMAND}
|
||||
-- unit := Default_ship
|
||||
-- create old_position.set_xy (0, 0)
|
||||
-- create position.set_xy (0, 0)
|
||||
-- end
|
||||
|
||||
make (a_unit: like unit; a_position: like position)
|
||||
-- Initialize a command that can reposition `a_unit' to `a_position'
|
||||
require
|
||||
unit_exists: a_unit /= Void
|
||||
location_exists: a_position /= Void
|
||||
do
|
||||
default_create
|
||||
unit := a_unit
|
||||
-- unit.set_position (a_position)
|
||||
create old_position.set_xy (0, 0)
|
||||
create position.set_xy (a_position.longitude, a_position.latitude)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
text: STRING
|
||||
-- Description of the command
|
||||
do
|
||||
Result := "COMMAND: Reposition -- "+ unit.name + " from " + old_position.out
|
||||
Result := Result + " to " + position.out
|
||||
end
|
||||
|
||||
unit: ATTACK_UNIT
|
||||
-- The unit to be moved
|
||||
|
||||
position: VITP_POSITION
|
||||
-- The position to which `unit' is to be moved
|
||||
|
||||
old_position: VITP_POSITION
|
||||
-- The position from which `unit' was moved
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the action
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
old_position := unit.position
|
||||
if unit.is_task_force then
|
||||
from i := 1
|
||||
until i > unit.task_force.count
|
||||
loop
|
||||
unit.task_force.i_th (i).set_position (position)
|
||||
i := i + 1
|
||||
end
|
||||
else
|
||||
unit.set_position (position)
|
||||
end
|
||||
end
|
||||
|
||||
undo
|
||||
-- Reverse the effects of executing the command
|
||||
do
|
||||
Precursor {VITP_COMMAND}
|
||||
unit.set_position (old_position)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
end
|
59
jj_vitp/Interface/commands/vitp_command.e
Normal file
59
jj_vitp/Interface/commands/vitp_command.e
Normal file
@@ -0,0 +1,59 @@
|
||||
note
|
||||
description: "[
|
||||
A {JJ_COMMAND} applicable to the VITP game
|
||||
See {GAME_SEQUENCE} for explanation of "phase" and "stage".
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
deferred class
|
||||
VITP_COMMAND
|
||||
|
||||
inherit
|
||||
|
||||
JJ_COMMAND
|
||||
redefine
|
||||
is_executable,
|
||||
execute,
|
||||
undo
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_executable: BOOLEAN
|
||||
-- Can the command be executed?
|
||||
do
|
||||
Result := Precursor {JJ_COMMAND} and is_allowed_by_sop
|
||||
end
|
||||
|
||||
is_allowed_by_sop: BOOLEAN
|
||||
-- Can the command of this type be executed at this phase
|
||||
-- in the game play? The command may not be completely
|
||||
-- ready for execution, but if it were, execution would
|
||||
-- not be vetoed by the sequence of play.
|
||||
do
|
||||
Result := True
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
execute
|
||||
-- Perform the actions
|
||||
do
|
||||
Precursor {JJ_COMMAND}
|
||||
io.put_string ("{VITP_COMMAND}.execute: ")
|
||||
io.put_string (text)
|
||||
io.new_line
|
||||
end
|
||||
|
||||
undo
|
||||
-- Perform the actions
|
||||
do
|
||||
Precursor {JJ_COMMAND}
|
||||
io.put_string ("{VITP_COMMAND}.undo: ")
|
||||
io.put_string (text)
|
||||
io.new_line
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user