note description: "[ A list of ships that move as a unit. ]" author: "Jimmy J. Johnson" class TASK_FORCE inherit VITP_ITEM undefine copy, is_equal redefine make end JJ_SORTABLE_SET [ATTACK_UNIT] rename make as list_make, extend as list_extend -- to strengthen the precondition export -- {TASK_FORCE} -- all -- {ATTACK_UNIT} {ANY} item, -- count, -- i_th, -- first, start, is_after, forth -- has, -- prunable, -- is_empty redefine -- default_create, -- make, -- make_filled, -- prune, new_filled_list end create make feature {NONE} -- Initialization make (a_game: like game) -- Initialize Current do list_make (10) Precursor {VITP_ITEM} (a_game) -- column_count := 1 -- name := "No name" end -- make (a_count: INTEGER) -- -- Initialize Current to initial capacity of `a_count' -- do -- item_make ("No name", Nobody) -- Precursor {JJ_SORTABLE_SET} (a_count) -- column_count := 1 -- end -- make_filled (a_count: INTEGER) -- -- Initialize Current to initial capacity of `a_count' -- do -- item_make ("No name", Nobody) -- Precursor (a_count) -- column_count := 1 -- end new_filled_list (n: INTEGER): like Current -- Redefined to get past void-safety issues, but `duplicate' -- from {ARRAYED_LIST} will not work do check do_not_call: False then -- because redefined to appease void safety end end feature -- Access name: STRING_8 -- The displayed name for this widget do Result := "{" + generating_type + "} " if count >= 1 then Result := Result + i_th (1).name else Result := Result + " not named" end end feature {ATTACK_UNIT} -- Basic operations extend (a_unit: like item) -- Ensure `a_unit' is included in the force require unit_exists: a_unit /= Void correct_nationality: not is_empty implies not a_unit.is_opposed (first) same_location: not is_empty implies a_unit.location = first.location local old_f: detachable like item do is_stable := false if not is_empty and then not (a_unit.location = first.location) then a_unit.set_location (first.location) end list_extend (a_unit) -- name := " Task Force " + id.out + " " + first.name nationality := first.nationality is_stable := true end assemble -- Bring all units close together. -- Graphical elements will be stacked do is_dispersed := false end disperse -- Spread units out. -- Graphical elements will be tiled do is_dispersed := true end feature -- Status report is_dispersed: BOOLEAN -- Are the units spread apart? -- Changed with `disperse' and `assemble'. is_stable: BOOLEAN -- Used by invariant for referential integrity checking feature {NONE} -- Implementation -- column_count: INTEGER -- -- The number of columns in which to arrange the force -- counter: INTEGER_32_REF -- -- Used to create a unique name when a group is created -- once -- create Result -- end -- has_invalid_unit: BOOLEAN -- -- Does Current contain a unit that does not refer back to Current -- -- For invariant checking -- -- Should be False -- require -- call_only_when_stable: is_stable -- local -- u: ATTACK_UNIT -- c: CURSOR -- do -- c := cursor -- from start -- until after or Result -- loop -- u := item -- Result := u.is_stable implies u.task_force /= Current -- forth -- end -- go_to (c) -- end invariant -- column_count_big_enough: column_count >= 1 -- column_count_small_enough: column_count <= count end