RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.world.region.Region Class Reference

Represents a single region. More...

Collaboration diagram for com.runehive.game.world.region.Region:

Public Member Functions

void addGroundItem (GroundItem item)
 Adds a ground item to this region.
void addNpc (Npc npc)
 Adds an npc to this region.
void addObject (GameObject object)
 Adds an object to this region.
void addPlayer (Player player)
 Adds a player to this region.
boolean contains (int x, int y)
boolean contains (Position position)
boolean containsNpc (int height, Npc npc)
boolean containsObject (int height, GameObject object)
boolean containsObject (Position position)
boolean containsPlayer (int height, Player player)
GameObject getCustomObject (int id, Position position)
int getFlags (int height, int x, int y)
 Gets a single tile in this region from the specified height, x and y coordinates.
GameObject getGameObject (int id, Position position)
GroundItem getGroundItem (int id, Position position)
Set< GroundItemgetGroundItems (Position position)
int getId ()
Collection< NpcgetNpcs (int height)
List< GameObjectgetObjects (Position position)
Collection< PlayergetPlayers (int height)
Optional< Region[]> getSurroundingRegions ()
int getX ()
int getY ()
 Region (int x, int y)
 Creates a region.
void removeGroundItem (GroundItem item)
 Adds a ground item to this region.
void removeNpc (Npc npc)
 Removes an npc from this region.
void removeObject (GameObject object)
 Removes an object from this region.
void removePlayer (Player player)
 Removes a player from this region.
void sendGameObjects (Player player)
 Sends game objects in this region to the player.
void sendGroundItems (Player player)
 Sends ground items in this region to the player.
void setFlags (int height, int x, int y, int flags)
 Gets a single tile in this region from the specified height, x and y coordinates.
void setSurroundingRegions (Optional< Region[]> surroundingRegions)
void skip (GameObject gameObject)
String toString ()
void unsetFlags (int height, int x, int y, int flags)
 Gets a single tile in this region from the specified height, x and y coordinates.

Static Public Member Functions

static boolean reachable (Interactable source, Interactable target)
static boolean reachable (Position source, int sourceWidth, int sourceLength, Position target, int targetWidth, int targetLength)

Static Public Attributes

static final Map< Position, GameObjectACTIVE_OBJECT = new HashMap<>()
static final int SIZE = CHUNK_SIZE * 8
static final Set< PositionSKIPPED_OBJECTS = new HashSet<>()
static final int VIEW_DISTANCE = SIZE / 4 - 1

Private Member Functions

RegionBlock getBlock (int height)

Private Attributes

final RegionBlock[] blocks = new RegionBlock[HEIGHT_LEVELS]
 The region blocks that execute different heights.
int id
 The region id.
Optional< Region[]> surroundingRegions = Optional.empty()
 The surrounded regions.
int x
 The region coordinates.
int y

Static Private Attributes

static final int CHUNK_SIZE = 8

Detailed Description

Represents a single region.

Author
Graham Edgecombe

Definition at line 21 of file Region.java.

Constructor & Destructor Documentation

◆ Region()

com.runehive.game.world.region.Region.Region ( int x,
int y )

Creates a region.

Definition at line 41 of file Region.java.

41 {
42 this.x = x;
43 this.y = y;
44 this.id = ((x >> 6) << 8) + (y >> 6);
45 }

References x, and y.

Referenced by setSurroundingRegions().

Here is the caller graph for this function:

Member Function Documentation

◆ addGroundItem()

void com.runehive.game.world.region.Region.addGroundItem ( GroundItem item)

Adds a ground item to this region.

Definition at line 150 of file Region.java.

150 {
151 getBlock(item.getHeight()).addGroundItem(item);
152 }

References com.runehive.game.world.region.RegionBlock.addGroundItem(), getBlock(), and com.runehive.game.world.entity.Entity.getHeight().

Here is the call graph for this function:

◆ addNpc()

void com.runehive.game.world.region.Region.addNpc ( Npc npc)

Adds an npc to this region.

Definition at line 130 of file Region.java.

130 {
131 getBlock(npc.getHeight()).addNpc(npc);
132 }

References com.runehive.game.world.region.RegionBlock.addNpc(), getBlock(), and com.runehive.game.world.entity.Entity.getHeight().

Here is the call graph for this function:

◆ addObject()

void com.runehive.game.world.region.Region.addObject ( GameObject object)

Adds an object to this region.

Definition at line 140 of file Region.java.

140 {
141 getBlock(object.getHeight()).addObject(object);
142 }

References com.runehive.game.world.region.RegionBlock.addObject(), and getBlock().

Here is the call graph for this function:

◆ addPlayer()

void com.runehive.game.world.region.Region.addPlayer ( Player player)

Adds a player to this region.

Definition at line 120 of file Region.java.

120 {
121 getBlock(player.getHeight()).addPlayer(player);
122 }

References com.runehive.game.world.region.RegionBlock.addPlayer(), getBlock(), and com.runehive.game.world.entity.Entity.getHeight().

Here is the call graph for this function:

◆ contains() [1/2]

boolean com.runehive.game.world.region.Region.contains ( int x,
int y )
Returns
true if the region contains the position

Definition at line 211 of file Region.java.

211 {
212 return getX() == ((x >> 3) - 6) >> 3 && getY() == ((y >> 3) - 6) >> 3;
213 }

References getX(), getY(), x, and y.

Here is the call graph for this function:

◆ contains() [2/2]

boolean com.runehive.game.world.region.Region.contains ( Position position)
Returns
true if the region contains the position

Definition at line 206 of file Region.java.

206 {
207 return getX() == position.getRegionX() && getY() == position.getRegionY();
208 }

References getX(), and getY().

Here is the call graph for this function:

◆ containsNpc()

boolean com.runehive.game.world.region.Region.containsNpc ( int height,
Npc npc )

Definition at line 159 of file Region.java.

159 {
160 return getBlock(height).containsNpc(npc);
161 }

References com.runehive.game.world.region.RegionBlock.containsNpc(), and getBlock().

Here is the call graph for this function:

◆ containsObject() [1/2]

boolean com.runehive.game.world.region.Region.containsObject ( int height,
GameObject object )
Returns
true if object is in region

Definition at line 168 of file Region.java.

168 {
169 return getBlock(height).containsObject(object);
170 }

References com.runehive.game.world.region.RegionBlock.containsObject(), and getBlock().

Referenced by com.runehive.game.world.object.StaticGameObject.active(), com.runehive.game.world.object.CustomGameObject.addToRegion(), com.runehive.content.skill.impl.firemaking.FiremakingAction.canInit(), com.runehive.content.combat.cannon.Cannon.register(), com.runehive.game.world.object.StaticGameObject.register(), com.runehive.game.world.object.CustomGameObject.removeFromRegion(), and com.runehive.game.world.object.StaticGameObject.unregister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsObject() [2/2]

boolean com.runehive.game.world.region.Region.containsObject ( Position position)
Returns
true if object occupies position

Definition at line 173 of file Region.java.

173 {
174 return getBlock(position.getHeight()).containsObject(position);
175 }

References com.runehive.game.world.region.RegionBlock.containsObject(), and getBlock().

Here is the call graph for this function:

◆ containsPlayer()

boolean com.runehive.game.world.region.Region.containsPlayer ( int height,
Player player )

Definition at line 163 of file Region.java.

163 {
164 return getBlock(height).containsPlayer(player);
165 }

References com.runehive.game.world.region.RegionBlock.containsPlayer(), and getBlock().

Here is the call graph for this function:

◆ getBlock()

RegionBlock com.runehive.game.world.region.Region.getBlock ( int height)
private

Definition at line 215 of file Region.java.

215 {
216 if (height > HEIGHT_LEVELS || height < 0) {
217 throw new IllegalArgumentException("Height is out of bounds. Received (" + height + "), expected range [0, " + HEIGHT_LEVELS + "].");
218 }
219
220 if (blocks[height] == null) {
221 blocks[height] = new RegionBlock();
222 }
223
224 return blocks[height];
225 }

References blocks.

Referenced by addGroundItem(), addNpc(), addObject(), addPlayer(), containsNpc(), containsObject(), containsObject(), containsPlayer(), getCustomObject(), getFlags(), getGameObject(), getGroundItem(), getGroundItems(), getNpcs(), getObjects(), getPlayers(), removeGroundItem(), removeNpc(), removeObject(), removePlayer(), sendGameObjects(), sendGroundItems(), setFlags(), skip(), and unsetFlags().

Here is the caller graph for this function:

◆ getCustomObject()

GameObject com.runehive.game.world.region.Region.getCustomObject ( int id,
Position position )

Definition at line 187 of file Region.java.

187 {
188 return getBlock(position.getHeight()).getCustomObject(id, position);
189 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getCustomObject().

Here is the call graph for this function:

◆ getFlags()

int com.runehive.game.world.region.Region.getFlags ( int height,
int x,
int y )

Gets a single tile in this region from the specified height, x and y coordinates.

Parameters
heightThe height.
xThe x coordinate.
yThe y coordinate.
Returns
The tile in this region for the specified attributes.

Definition at line 66 of file Region.java.

66 {
67 return getBlock(height).getFlags(x, y);
68 }

References getBlock(), com.runehive.game.world.region.RegionBlock.getFlags(), x, and y.

Here is the call graph for this function:

◆ getGameObject()

GameObject com.runehive.game.world.region.Region.getGameObject ( int id,
Position position )
Returns
true if object with given id occupies position

Definition at line 183 of file Region.java.

183 {
184 return getBlock(position.getHeight()).getGameObject(id, position);
185 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getGameObject().

Referenced by com.runehive.content.Obelisks.activate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGroundItem()

GroundItem com.runehive.game.world.region.Region.getGroundItem ( int id,
Position position )
Returns
the ground item with the given id at the given position

Definition at line 115 of file Region.java.

115 {
116 return getBlock(position.getHeight()).getGroundItem(id, position);
117 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getGroundItem().

Here is the call graph for this function:

◆ getGroundItems()

Set< GroundItem > com.runehive.game.world.region.Region.getGroundItems ( Position position)
Returns
a set of ground items on the position

Definition at line 178 of file Region.java.

178 {
179 return getBlock(position.getHeight()).getGroundItems(position);
180 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getGroundItems().

Here is the call graph for this function:

◆ getId()

int com.runehive.game.world.region.Region.getId ( )

Definition at line 282 of file Region.java.

282 {
283 return id;
284 }

References id.

◆ getNpcs()

Collection< Npc > com.runehive.game.world.region.Region.getNpcs ( int height)
Returns
the npcs in this region

Definition at line 110 of file Region.java.

110 {
111 return getBlock(height).getNpcs();
112 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getNpcs().

Referenced by com.runehive.game.world.entity.combat.CombatTarget.checkAggression().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getObjects()

List< GameObject > com.runehive.game.world.region.Region.getObjects ( Position position)

Definition at line 191 of file Region.java.

191 {
192 return getBlock(position.getHeight()).getGameObjects(position);
193 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getGameObjects().

Here is the call graph for this function:

◆ getPlayers()

Collection< Player > com.runehive.game.world.region.Region.getPlayers ( int height)
Returns
the players in this region

Definition at line 105 of file Region.java.

105 {
106 return getBlock(height).getPlayers();
107 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.getPlayers().

Referenced by com.runehive.content.combat.cannon.Cannon.addToRegion(), com.runehive.content.combat.cannon.Cannon.removeFromRegion(), and com.runehive.game.world.entity.combat.strategy.npc.boss.StoneGuardian.BoomAttack.start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSurroundingRegions()

Optional< Region[]> com.runehive.game.world.region.Region.getSurroundingRegions ( )

Definition at line 96 of file Region.java.

96 {
97 return surroundingRegions;
98 }

References surroundingRegions.

Referenced by com.runehive.game.world.region.RegionManager.forNearbyPlayer(), and com.runehive.game.world.region.RegionManager.getSurroundingRegions().

Here is the caller graph for this function:

◆ getX()

int com.runehive.game.world.region.Region.getX ( )
Returns
region x-coordinate

Definition at line 48 of file Region.java.

48 {
49 return x;
50 }

References x.

Referenced by contains(), and contains().

Here is the caller graph for this function:

◆ getY()

int com.runehive.game.world.region.Region.getY ( )
Returns
region y-coordinate

Definition at line 53 of file Region.java.

53 {
54 return y;
55 }

References y.

Referenced by contains(), and contains().

Here is the caller graph for this function:

◆ reachable() [1/2]

boolean com.runehive.game.world.region.Region.reachable ( Interactable source,
Interactable target )
static

Definition at line 227 of file Region.java.

227 {
228 return reachable(source.getPosition(), source.width(), source.length(), target.getPosition(), target.width(), target.length());
229 }

References com.runehive.game.world.Interactable.getPosition(), com.runehive.game.world.Interactable.length(), reachable(), and com.runehive.game.world.Interactable.width().

Referenced by com.runehive.game.world.pathfinding.path.impl.SimplePathFinder.addWalks(), com.runehive.game.world.pathfinding.path.impl.DijkstraPathFinder.find(), and reachable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reachable() [2/2]

boolean com.runehive.game.world.region.Region.reachable ( Position source,
int sourceWidth,
int sourceLength,
Position target,
int targetWidth,
int targetLength )
static

Definition at line 231 of file Region.java.

231 {
232 if (Utility.inside(source, sourceWidth, sourceLength, target, targetWidth, targetLength)) {
233 return targetWidth == 0 || targetLength == 0;
234 }
235
236 int x, y;
237 int sourceTopX = source.getX() + sourceWidth - 1;
238 int sourceTopY = source.getY() + sourceLength - 1;
239 int targetTopX = target.getX() + targetWidth - 1;
240 int targetTopY = target.getY() + targetLength - 1;
241
242 if (sourceTopY == target.getY() - 1 && source.getX() >= target.getX() && source.getX() <= targetTopX) {
243 for (x = 0, y = sourceLength - 1; x < sourceWidth; x++)
244 if (TraversalMap.blockedNorth(source.transform(x, y)))
245 return false;
246 return true;
247 }
248
249 if (sourceTopX == target.getX() - 1 && source.getY() >= target.getY() && source.getY() <= targetTopY) {
250 for (x = 0, y = 0; y < sourceLength; y++)
251 if (TraversalMap.blockedEast(source.transform(x, y)))
252 return false;
253 return true;
254 }
255
256 if (source.getY() == targetTopY + 1 && source.getX() >= target.getX() && source.getX() <= targetTopX) {
257 for (x = 0, y = 0; x < sourceWidth; x++)
258 if (TraversalMap.blockedSouth(source.transform(x, y)))
259 return false;
260 return true;
261 }
262
263 if (source.getX() == targetTopX + 1 && source.getY() >= target.getY() && source.getY() <= targetTopY) {
264 for (x = sourceWidth - 1, y = 0; y < sourceLength; y++)
265 if (TraversalMap.blockedWest(source.transform(x, y)))
266 return false;
267 return true;
268 }
269
270 return false;
271 }

References com.runehive.game.world.pathfinding.TraversalMap.blockedEast(), com.runehive.game.world.pathfinding.TraversalMap.blockedNorth(), com.runehive.game.world.pathfinding.TraversalMap.blockedSouth(), com.runehive.game.world.pathfinding.TraversalMap.blockedWest(), com.runehive.game.world.position.Position.getX(), com.runehive.game.world.position.Position.getY(), com.runehive.util.Utility.inside(), com.runehive.game.world.position.Position.transform(), x, and y.

Here is the call graph for this function:

◆ removeGroundItem()

void com.runehive.game.world.region.Region.removeGroundItem ( GroundItem item)

Adds a ground item to this region.

Definition at line 155 of file Region.java.

155 {
156 getBlock(item.getHeight()).removeGroundItem(item);
157 }

References getBlock(), com.runehive.game.world.entity.Entity.getHeight(), and com.runehive.game.world.region.RegionBlock.removeGroundItem().

Here is the call graph for this function:

◆ removeNpc()

void com.runehive.game.world.region.Region.removeNpc ( Npc npc)

Removes an npc from this region.

Definition at line 135 of file Region.java.

135 {
136 getBlock(npc.getHeight()).removeNpc(npc);
137 }

References getBlock(), com.runehive.game.world.entity.Entity.getHeight(), and com.runehive.game.world.region.RegionBlock.removeNpc().

Here is the call graph for this function:

◆ removeObject()

void com.runehive.game.world.region.Region.removeObject ( GameObject object)

Removes an object from this region.

Definition at line 145 of file Region.java.

145 {
146 getBlock(object.getHeight()).removeObject(object);
147 }

References getBlock(), and com.runehive.game.world.region.RegionBlock.removeObject().

Here is the call graph for this function:

◆ removePlayer()

void com.runehive.game.world.region.Region.removePlayer ( Player player)

Removes a player from this region.

Definition at line 125 of file Region.java.

125 {
126 getBlock(player.getHeight()).removePlayer(player);
127 }

References getBlock(), com.runehive.game.world.entity.Entity.getHeight(), and com.runehive.game.world.region.RegionBlock.removePlayer().

Here is the call graph for this function:

◆ sendGameObjects()

void com.runehive.game.world.region.Region.sendGameObjects ( Player player)

Sends game objects in this region to the player.

Definition at line 201 of file Region.java.

201 {
202 getBlock(player.getHeight()).sendGameObjects(player);
203 }

References getBlock(), com.runehive.game.world.entity.Entity.getHeight(), and com.runehive.game.world.region.RegionBlock.sendGameObjects().

Here is the call graph for this function:

◆ sendGroundItems()

void com.runehive.game.world.region.Region.sendGroundItems ( Player player)

Sends ground items in this region to the player.

Definition at line 196 of file Region.java.

196 {
197 getBlock(player.getHeight()).sendGroundItems(player);
198 }

References getBlock(), com.runehive.game.world.entity.Entity.getHeight(), and com.runehive.game.world.region.RegionBlock.sendGroundItems().

Here is the call graph for this function:

◆ setFlags()

void com.runehive.game.world.region.Region.setFlags ( int height,
int x,
int y,
int flags )

Gets a single tile in this region from the specified height, x and y coordinates.

Parameters
heightThe height.
xThe x coordinate.
yThe y coordinate.
Returns
The tile in this region for the specified attributes.

Definition at line 79 of file Region.java.

79 {
80 getBlock(height).setFlags(x, y, flags);
81 }

References getBlock(), com.runehive.game.world.region.RegionBlock.setFlags(), x, and y.

Here is the call graph for this function:

◆ setSurroundingRegions()

void com.runehive.game.world.region.Region.setSurroundingRegions ( Optional< Region[]> surroundingRegions)

Definition at line 100 of file Region.java.

100 {
101 this.surroundingRegions = surroundingRegions;
102 }

References Region(), and surroundingRegions.

Referenced by com.runehive.game.world.region.RegionManager.getSurroundingRegions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skip()

void com.runehive.game.world.region.Region.skip ( GameObject gameObject)

Definition at line 273 of file Region.java.

273 {
274 getBlock(gameObject.getHeight()).skip(gameObject);
275 }

References getBlock(), com.runehive.game.world.Interactable.getHeight(), and com.runehive.game.world.region.RegionBlock.skip().

Here is the call graph for this function:

◆ toString()

String com.runehive.game.world.region.Region.toString ( )

Definition at line 278 of file Region.java.

278 {
279 return "Region[" + x + "_" + y + "]";
280 }

References x, and y.

◆ unsetFlags()

void com.runehive.game.world.region.Region.unsetFlags ( int height,
int x,
int y,
int flags )

Gets a single tile in this region from the specified height, x and y coordinates.

Parameters
heightThe height.
xThe x coordinate.
yThe y coordinate.
Returns
The tile in this region for the specified attributes.

Definition at line 92 of file Region.java.

92 {
93 getBlock(height).unsetFlags(x, y, flags);
94 }

References getBlock(), com.runehive.game.world.region.RegionBlock.unsetFlags(), x, and y.

Here is the call graph for this function:

Member Data Documentation

◆ ACTIVE_OBJECT

final Map<Position, GameObject> com.runehive.game.world.region.Region.ACTIVE_OBJECT = new HashMap<>()
static

◆ blocks

final RegionBlock [] com.runehive.game.world.region.Region.blocks = new RegionBlock[HEIGHT_LEVELS]
private

The region blocks that execute different heights.

Definition at line 35 of file Region.java.

Referenced by getBlock().

◆ CHUNK_SIZE

final int com.runehive.game.world.region.Region.CHUNK_SIZE = 8
staticprivate

Definition at line 22 of file Region.java.

◆ id

int com.runehive.game.world.region.Region.id
private

The region id.

Definition at line 29 of file Region.java.

Referenced by getId().

◆ SIZE

◆ SKIPPED_OBJECTS

final Set<Position> com.runehive.game.world.region.Region.SKIPPED_OBJECTS = new HashSet<>()
static

◆ surroundingRegions

Optional<Region[]> com.runehive.game.world.region.Region.surroundingRegions = Optional.empty()
private

The surrounded regions.

Definition at line 38 of file Region.java.

Referenced by getSurroundingRegions(), and setSurroundingRegions().

◆ VIEW_DISTANCE

◆ x

int com.runehive.game.world.region.Region.x
private

The region coordinates.

Definition at line 32 of file Region.java.

Referenced by contains(), getFlags(), getX(), reachable(), Region(), setFlags(), toString(), and unsetFlags().

◆ y

int com.runehive.game.world.region.Region.y
private

Definition at line 32 of file Region.java.

Referenced by contains(), getFlags(), getY(), reachable(), Region(), setFlags(), toString(), and unsetFlags().


The documentation for this class was generated from the following file: