Class MapSquare<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<G,​A,​R>>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<G>

    public class MapSquare<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<G,​A,​R>>
    extends GameObjectContainer<G,​A,​R>
    A single Map Square. This class is implemented in a way that changes via some modifier methods in a map square will automatically fire events in the associated MapModel. A MapSquare always knows its model. It's not possible to create a MapSquare that is not associated to a model.

    The objects are stored bottom to top: GameObjectContainer.getFirst() returns the object at the bottom, GameObjectContainer.getLast() returns the object at the top of the square.

    See Also:
    Serialized Form
    • Constructor Detail

      • MapSquare

        public MapSquare​(@NotNull
                         @NotNull MapModel<G,​A,​R> mapModel,
                         int mapX,
                         int mapY)
        Creates a new instance.
        Parameters:
        mapModel - the map model this map square is part of
        mapX - the x coordinate of this map square within the model's grid
        mapY - the y coordinate of this map square within the model's grid
    • Method Detail

      • getMapModel

        @NotNull
        public @NotNull MapModel<G,​A,​R> getMapModel()
        Returns the MapModel this map square is part of.
        Returns:
        the map model
      • getMapX

        public int getMapX()
        Returns the x coordinate on the map.
        Returns:
        the x coordinate on map
      • getMapY

        public int getMapY()
        Returns the y coordinate on the map.
        Returns:
        the y coordinate on map
      • getMapLocation

        @NotNull
        public @NotNull java.awt.Point getMapLocation()
        Returns the coordinate on the map.
        Returns:
        the coordinate on the map
      • getMapLocation

        public void getMapLocation​(@NotNull
                                   @NotNull java.awt.Point pos)
        Returns the coordinate on the map.
        Parameters:
        pos - returns the coordinate on the map
      • getMapLocation

        public void getMapLocation​(@NotNull
                                   @NotNull java.awt.Point pos,
                                   int dx,
                                   int dy)
        Returns the coordinate with an offset on the map.
        Parameters:
        pos - returns the coordinate on the map
        dx - the x offset to add to the coordinate
        dy - the y offset to add to the coordinate
      • getLast

        @Nullable
        public G getLast​(@NotNull
                         @NotNull GameObjectMatcher gameObjectMatcher)
        Returns the last occurrence of a matching game object.
        Parameters:
        gameObjectMatcher - the matcher to use
        Returns:
        the last match, or null if no such game object exists
      • getAfterLast

        @Nullable
        public G getAfterLast​(@NotNull
                              @NotNull GameObjectMatcher gameObjectMatcher)
        Returns the game object after the last occurrence of a matching game object.
        Parameters:
        gameObjectMatcher - the matcher to use
        Returns:
        the game object after the last match, or null if no such game object exists
        No Inspection:
        TypeMayBeWeakened
      • getFirst

        @Nullable
        public G getFirst​(@NotNull
                          @NotNull GameObjectMatcher gameObjectMatcher)
        Returns the first occurrence of a matching game object.
        Parameters:
        gameObjectMatcher - the matcher to use
        Returns:
        the first match, or null if no such game object exists
        No Inspection:
        TypeMayBeWeakened
      • getBeforeFirst

        @Nullable
        public G getBeforeFirst​(@NotNull
                                @NotNull GameObjectMatcher gameObjectMatcher)
        Returns the game object before the first occurrence of a matching game object.
        Parameters:
        gameObjectMatcher - the matcher to use
        Returns:
        the game object before the first match, or null if no such game object exists
        No Inspection:
        TypeMayBeWeakened
      • getLastOfLeadingSpan

        @Nullable
        public G getLastOfLeadingSpan​(@NotNull
                                      @NotNull GameObjectMatcher gameObjectMatcher)
        Returns the last game object of the initial segment of matching game objects.
        Parameters:
        gameObjectMatcher - the matcher to use
        Returns:
        the result or null if the first game object does not match gameObjectMatcher
        No Inspection:
        TypeMayBeWeakened
      • beginSquareChange

        public void beginSquareChange()
        Method to notify the model that a map square is about to change.
      • endSquareChange

        public void endSquareChange()
        Method to notify the model that a map square was changed.
      • equals

        public boolean equals​(@Nullable
                              @Nullable java.lang.Object obj)
        }
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        }
        Overrides:
        hashCode in class java.lang.Object
      • getLightRadius

        public int getLightRadius()
        Returns the maximum light radius of all light emitting objects within this map square.
        Returns:
        the light radius or 0 if no light emitting objects are present
      • setLightRadius

        public void setLightRadius​(int lightRadius)
        Sets the maximum light radius of all light emitting objects within this map square.
        Parameters:
        lightRadius - the light radius or 0 if no light emitting objects are present
      • addLightSource

        public void addLightSource​(@NotNull
                                   @NotNull MapSquare<G,​A,​R> mapSquare)
        Adds a light emitting game object that affects this map square.
        Parameters:
        mapSquare - the map square that contains the game object
      • removeLightSource

        public void removeLightSource​(@NotNull
                                      @NotNull MapSquare<G,​A,​R> mapSquare)
        Removes a light emitting game object that affects this map square.
        Parameters:
        mapSquare - the map square that contains the game object
      • isLight

        public boolean isLight()
        Returns whether this map square is affected by any light emitting game objects.
        Returns:
        whether this map square is affected by any light emitting game objects