Class Force

java.lang.Object
megamek.common.force.Force
All Implemented Interfaces:
Serializable

public final class Force extends Object implements Serializable
A representation of a force or part of a force. Very similar to MHQ's Force. A Force in MM belongs to a player. It can hold units of the owner's team.
See Also:
  • Field Details

  • Constructor Details

    • Force

      public Force(String name, int id, Camouflage camouflage, Player owner)
      Creates a top-level (no parent) force
    • Force

      public Force(String name, int id, Camouflage camouflage, Force parent)
      Creates a sub force.
    • Force

      public Force(String name, int id, Camouflage camouflage)
      Creates a force with name n and id nId. Without either a parent or owner this force is a stub and should not be added to a Forces object. Used to parse the forceString, e.g. when loading a MUL.
  • Method Details

    • createSubforce

      public static Force createSubforce(String name, Force fParent)
      Creates a force object that is not integrated into any forces. Used to send a new force to the server. In other cases, use Forces.add.
    • createToplevelForce

      public static Force createToplevelForce(String name, Player owner)
      Creates a force object that is not integrated into any forces. Used to send a new force to the server. In other cases, use Forces.add.
    • getName

      public String getName()
    • setName

      public void setName(String n)
    • getId

      public int getId()
    • getCamouflage

      public Camouflage getCamouflage()
    • getCamouflageOrElse

      public Camouflage getCamouflageOrElse(Game game, Camouflage camouflage)
    • setCamouflage

      public void setCamouflage(Camouflage camouflage)
    • getOwnerId

      public int getOwnerId()
      Returns the player ID of the owner of this force.
    • getParentId

      public int getParentId()
      Returns the Force ID of this force's parent force; -1 if top-level.
    • getParent

      @Nullable public Force getParent(Game game)
    • isTopLevel

      public boolean isTopLevel()
    • subForceCount

      public int subForceCount()
    • entityCount

      public int entityCount()
    • getChildCount

      public int getChildCount()
      Returns the number of direct children of this force, i.e. the number of direct members + the number of direct subForces.
    • isEmpty

      public boolean isEmpty()
      Returns true if the force contains neither units nor subForces.
    • getEntityId

      public int getEntityId(int index)
      Returns the id of the entity at the provided index from the list of direct members of this force (not subForces). Indices outside 0 ... entityCount() - 1 will result in an exception.
    • getSubForceId

      public int getSubForceId(int index)
      Returns the id of the force at the provided index from the list of subForces of this force. Indices outside 0 ... subForceCount() - 1 will result in an exception.
    • containsEntity

      @Deprecated(since="0.51.0", forRemoval=true) public boolean containsEntity(ForceAssignable unit)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns true if the provided unit is among the force's direct members. Does NOT check if the unit is part of any sub force.
    • containsEntity

      public boolean containsEntity(int id)
      Returns true if the provided entity is among the force's direct members. Does NOT check if the entity is part of any sub force.
    • entityIndex

      public int entityIndex(ForceAssignable unit)
      Returns the index of the provided unit in the list of direct members of this force. Returns -1 if the unit is no direct member of this force.
    • containsSubForce

      public boolean containsSubForce(Force force)
      Returns true if the provided force is among this force's direct subForces.
    • subForceIndex

      public int subForceIndex(Force force)
      Returns the index of the provided force in the list of direct subForces of this force. Returns -1 if the force is no direct sub force of this force.
    • getEntities

      public List<Integer> getEntities()
    • getSubForces

      public List<Integer> getSubForces()
    • clone

      protected Force clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object