Class ExtendedCommandsHelper


  • public class ExtendedCommandsHelper
    extends java.lang.Object
    A Helper class to have some shortcuts.
    Version:
    1.0, 11.09.2007
    Author:
    Thoralf Rickert
    • Method Detail

      • getData

        protected GameData getData()
      • getSkillType

        public SkillType getSkillType​(java.lang.String typeName)
        The SkillType with the given name.
        Parameters:
        typeName -
        Returns:
        The SkillType or null if no such skill is known.
      • getItemType

        public ItemType getItemType​(java.lang.String typeName)
        The ItemType with the given name.
        Parameters:
        typeName -
        Returns:
        The ItemType or null if no such Item is known.
      • getBuildingType

        public BuildingType getBuildingType​(java.lang.String typeName)
        The BuildingType with the given name.
        Parameters:
        typeName -
        Returns:
        The BuildingType or null if no such Building is known.
      • getRace

        public Race getRace​(java.lang.String typeName)
        The Race with the given name.
        Parameters:
        typeName -
        Returns:
        The Race or null if no such race is known.
      • getRegionType

        public RegionType getRegionType​(java.lang.String typeName)
        The RegionType with the given name.
        Parameters:
        typeName -
        Returns:
        The RegionType or null if no such Region is known.
      • getCurrentRegion

        public Region getCurrentRegion()
        Returns the region of the active unit or container.
        Returns:
        the region of the active unit or container or null if there is no active unit or container
      • getRegion

        public Region getRegion​(java.lang.String regionName)
        Return a region with the given name. Attention: There may be more than one region with the given name. In that case there is no guarantee which of those regions is returned.
        Parameters:
        regionName -
        Returns:
        A region with the given name or null if no such region exists.
      • getUnit

        public Unit getUnit​(java.lang.String unitId)
        Returns the unit object of the given unit with the given id.
        Returns:
        A unit with the given name or null if no such unit exists.
        Throws:
        java.lang.NumberFormatException - if unit id is not parseable
        java.lang.NullPointerException - if unit id is null
      • getFaction

        public Faction getFaction​(java.lang.String factionID)
        Returns the faction object with the given id.
        Returns:
        A faction with the given name or null if no such faction exists.
      • getBuilding

        public Building getBuilding​(java.lang.String buildingID)
        Returns the building object with the given id.
        Returns:
        A building with the given name or null if no such building exists.
      • getShip

        public Ship getShip​(java.lang.String shipID)
        Returns the ship object with the given id.
        Returns:
        A ship with the given name or null if no such ship exists.
      • getUnitInRegion

        public Unit getUnitInRegion​(java.lang.String unitId)
        Returns the unit with the given Unit ID in the current region.
        Parameters:
        unitId - non-null
        Returns:
        the unit with the given Unit ID in the current region or null if no such unit is in the current region.
        Throws:
        java.lang.NullPointerException - if Unit ID is null
      • getUnitInRegion

        public Unit getUnitInRegion​(Region region,
                                    java.lang.String unitId)
        Returns the unit with the given Unit-ID in the given region.
        Parameters:
        region - non-null
        unitId - non-null
        Returns:
        the unit with the given Unit-ID in the given region or null if no such unit is in the given region.
      • isUnitInRegion

        public boolean isUnitInRegion​(java.lang.String regionName)
        Returns true, if the current unit is in the region with the given name.
        Parameters:
        regionName - non-null
        Returns:
        true, if the current unit is in the region with the given name, null if the current unit is null.
      • unitIsInRegion

        @Deprecated
        public boolean unitIsInRegion​(java.lang.String regionName)
        Deprecated.
        Returns true, if the current unit is in the region with the given name.
        Parameters:
        regionName - non-null
      • unitPerceivesOtherUnit

        public boolean unitPerceivesOtherUnit​(java.lang.String unitId)
        Returns true, if the unit with unitId is in the same region as the active unit and perception skill of the current unit' faction is greater than the other unit.
        Returns:
        NullPointerException if there is no active unit.
      • unitSeesOtherUnit

        public boolean unitSeesOtherUnit​(java.lang.String unitId)
        Returns true, if the current unit sees another unit with the given unit id. This method does not compare the the perception skill level. It uses the default tree information inside a region (so if you just want to know if the unit can give something to another unit, this is the right method).
      • getRegionSkillLevel

        public int getRegionSkillLevel​(Region region,
                                       Faction faction,
                                       SkillType skill)
        Returns the maximum skill level of any unit of a faction in a region.
        Parameters:
        region -
        faction -
        skill -
        Returns:
        the maximum skill level in the specified skill of any unit of the specified faction in the specified region.
        Throws:
        java.lang.NullPointerException - if any of the arguments is null
      • getLevel

        public int getLevel​(Unit unit,
                            java.lang.String skillName)
        Returns the skill level of a unit. For example getLevel(unit,"Unterhaltung")
      • getItemCount

        public int getItemCount​(Unit unit,
                                java.lang.String itemTypeName)
        Returns the number of items of a unit with the given item name. For example: int horses = getItemCount(unit,"Pferd") returns the number of horses of the given unit.
      • getSilver

        public int getSilver​(Unit unit)
        This method returns the amount of silver of the given unit. This is a shortcut for getItemCount(unit,"Silber")
      • getModifiedItemCount

        public int getModifiedItemCount​(Unit unit,
                                        java.lang.String itemTypeName)
        Returns the number of items of a unit with the given item name after execution of orders. For example: int horses = getModifiedItemCount(unit,"Pferd") returns the number of horses of the given unit.
      • getRegionLuxuryItem

        public ItemType getRegionLuxuryItem​(Region region)
        Returns the luxury item for the given unit that you can purchase.
      • getResourceAmount

        public int getResourceAmount​(java.lang.String resourceName)
        Returns the available amount for a resource, e.g. getResourceAmount("Bäume").
        Parameters:
        resourceName -
        Returns:
        the available amount for a resource
      • getResourceLevel

        public int getResourceLevel​(java.lang.String resourceName)
        Returns the current required skill level ("depth") for a resource, e.g. getResourceLevel("Eisen").
        Parameters:
        resourceName -
        Returns:
        The current skill level for a resource. Integer.MAX_VALUE if there is no info about the resource.
      • getRegionResource

        public RegionResource getRegionResource​(java.lang.String resourceName)
        Returns a RegionResource object for the resource with the specified name.
        Parameters:
        resourceName -
        Returns:
        a RegionResource object for the resource with the specified name or null if the resource doesn't exist.
      • getPersons

        public int getPersons​(Unit unit)
        Returns the number of persons in this unit.
      • addOrder

        public void addOrder​(java.lang.String order)
        Adds an order to the current unit.
      • addOrder

        public void addOrder​(Unit unit,
                             java.lang.String order)
        Adds an order to the given unit.
      • setOrder

        public void setOrder​(java.lang.String order)
        Sets the command for the current unit and replaces all given commands.
      • setOrder

        public void setOrder​(Unit unit,
                             java.lang.String order)
        Sets the command for the given unit and replaces all given commands.
      • getOrderTranslation

        @Deprecated
        public java.lang.String getOrderTranslation​(Unit unit,
                                                    java.lang.String orderConstant)
        Returns an order in the order locale of the specified unit's faction.
        Parameters:
        unit - This order will be converted into this unit's faction's order locale
        orderConstant - Use one of the EresseaConstants.O_... constants here
        Returns:
        A localized order constant. If no translation can be found, the orderConstant is returned.
        See Also:
        EresseaConstants
      • getOrderTranslation

        public java.lang.String getOrderTranslation​(Unit unit,
                                                    StringID orderConstant,
                                                    java.lang.Object... args)
        Returns an order in the order locale of the specified unit's faction. If opional arguments are present, they are appended (separated by spaces). If they are of type StringID, they are translated as well.
        Parameters:
        unit - This order will be converted into this unit's faction's order locale
        orderConstant - Use one of the EresseaConstants.OC_... constants here
        args - optional parameters.
        Returns:
        A localized order constant. If no translation can be found, the orderConstant is returned.
        See Also:
        EresseaConstants
      • getGiveOrder

        public java.lang.String getGiveOrder​(Unit unit,
                                             java.lang.String receiver,
                                             java.lang.String item,
                                             int amount,
                                             boolean each)
        Returns a line like GIVE receiver [EACH] amount item in the locale of the given unit.
        Parameters:
        unit -
        receiver -
        item -
        amount - If amount == Integer.MAX_VALUE, amount is replaced by ALL
        each -
        Returns:
        a line like GIVE receiver [EACH] amount item.
      • getReserveOrder

        public java.lang.String getReserveOrder​(Unit unit,
                                                java.lang.String item,
                                                int amount,
                                                boolean each)
        Returns a line like RESERVE [EACH] amount item.
        Parameters:
        unit -
        item -
        amount -
        each -
        Returns:
        a line like GIVE receiver [EACH] amount item.
      • isSoldier

        public boolean isSoldier()
        This method tries to find out, if the current unit has a weapon and a skill to use this weapon.
      • getRegions

        @Deprecated
        public java.util.List<Region> getRegions​(GameData world)
        Deprecated.
        This method is inefficient. Use world.getRegions();
        This method returns a list of all regions in the given world. It's a workaround for the complex iteration thru the map.
      • getPathToRegion

        @Deprecated
        public java.lang.String getPathToRegion​(Unit unit,
                                                Region destination,
                                                int speed,
                                                boolean makeRoute)
        Searches the best path from the current position of a unit to the given region.
        This method is only useful for persons on land!
        Parameters:
        unit - The unit that should go to another region
        destination - The destination region which should be reached
        speed - The desired speed per week. This value is ignored! This method uses no speed.
        makeRoute - If true, then this unit returns to the current region.
      • getPathToRegion

        public java.lang.String getPathToRegion​(Unit unit,
                                                Region destination,
                                                boolean useSpeed,
                                                boolean makeRoute)
        Searches the best path from the current position of an unit to the given region.
        This method is only useful for persons on land!
        Parameters:
        unit - The unit that should go to another region
        destination - The destination region which should be reached
        useSpeed - If this is true, this method uses the current calculated ship range. Otherwise, no range is used.
        makeRoute - If true, then this unit returns to the current region.
      • getPathToRegion

        @Deprecated
        public java.lang.String getPathToRegion​(Ship ship,
                                                Region destination,
                                                int speed,
                                                boolean makeRoute)
        Searches the best path from the current position of a ship to the given region.
        This method is only useful for ships!
        Parameters:
        ship - The ship that should go to another region
        destination - The destination region which should be reached
        speed - The desired speed per week. This value is ignored! This method uses no speed.
        makeRoute - If true, then this unit returns to the current region.
      • getPathToRegion

        public java.lang.String getPathToRegion​(Ship ship,
                                                Region destination,
                                                boolean useSpeed,
                                                boolean makeRoute)
        Searches the best path from the current position of a ship to the given region.
        This method is only useful for ships!
        Parameters:
        ship - The ship that should go to another region
        destination - The destination region which should be reached
        useSpeed - If this is true, this method uses the current calculated ship range. Otherwise, no range is used.
        makeRoute - If true, then this unit returns to the current region.
      • getConfiguration

        public java.util.Map<java.lang.String,​java.lang.String> getConfiguration​(Unit unit)
        This method reads the orders of a unit and extracts all lines with the syntax '// extcmds:"":value'. This method returns always a map and never null.
      • setConfiguration

        public void setConfiguration​(Unit unit,
                                     java.util.Map<java.lang.String,​java.lang.String> configuration)
        This method writes the configuration of a unit into its orders based on the syntax: '// extcmds:"":value'
      • updateUnit

        public void updateUnit​(Unit u)
        This method notifies the GUI that the unit's orders have changed. Call it whenever you change orders of a unit from a script. You don't have to call it when you change the unit's orders from the unit's own script.
        Parameters:
        u - The unit that shall be updated in the GUI.
      • hasScript

        public boolean hasScript​(Unit u)
        Returns true if the unit u has an ExtendedCommands script.
      • hasScript

        public boolean hasScript​(UnitContainer c)
        Returns true if the container c has an ExtendedCommands script.
      • getGameSpecificRules

        public GameSpecificRules getGameSpecificRules()
        Returns a game specific rule manager that provides a few utility methods that differ from game to game.
      • getMovementEvaluator

        public MovementEvaluator getMovementEvaluator()
        Returns a MovementEvaluator that provides utility methods concerning the movement of units.
      • setUI

        public void setUI​(UserInterface ui)
        Sets the value of the current UserInterface ("progress bar"). This method is not for users.
        Parameters:
        ui - The value for ui.
      • getUI

        public UserInterface getUI()
        Returns the current UserInterface ("progress bar").
        Returns:
        the current UserInterface ("progress bar").
      • invoke

        public static java.lang.Object invoke​(java.lang.Object object,
                                              java.lang.String name,
                                              java.lang.Class<?>[] parameterTypes,
                                              java.lang.Object[] arguments)
                                       throws java.lang.SecurityException,
                                              java.lang.NoSuchMethodException,
                                              java.lang.IllegalArgumentException,
                                              java.lang.IllegalAccessException,
                                              java.lang.reflect.InvocationTargetException
        Invoke public method called name on object with given parameters. Warning: Only use if you know what you're doing!
        Parameters:
        object -
        name -
        parameterTypes -
        arguments -
        Returns:
        The result of the invoked method, or null if it doesn't return a value
        Throws:
        java.lang.SecurityException
        java.lang.NoSuchMethodException
        java.lang.IllegalArgumentException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
        See Also:
        Class.getMethod(String, Class...), Method.invoke(Object, Object...)
      • getPlugin

        public MagellanPlugIn getPlugin​(java.lang.String string)
        Get plugin with given name.
        Parameters:
        string - The fully qualified plugin class name (e.g. "magellan.plugin.foo.FooPlugin")
        Returns:
        The plugin or null if no such plugin is active