wyvern.kernel.motion
Class Mover

java.lang.Object
  extended bywyvern.kernel.motion.Mover
Direct Known Subclasses:
WaterMover

public class Mover
extends java.lang.Object

This class contains all the contorted logic for deciding whether a monster can move into a particular square, and how fast it can do so.

Version:
1.0, Dec 03, 1997
Author:
Steve Yegge

Field Summary
static int FASTEST_MOVE_SPEED
          It puts a HUGE load on the server if your move speed is too fast, since player movement is the largest consumer of CPU and network bandwidth.
 
Constructor Summary
Mover()
           
 
Method Summary
 boolean canMove(GameObject agent, Terrain t)
          Returns true if the agent can move onto the specified terrain at all.
 boolean canWalk(GameObject obj, int x, int y)
          Checks to see if the object is walkable at the specified map location.
 void checkAllLocations(MoveEvent event)
          Checks every destination location to make sure it's a valid move.
 boolean checkPreconditions(MoveEvent event, GameMap map, java.util.List dest_objs, int x, int y)
          Examines the destination of the move to see if we should do anything "special".
static Mover getInstance()
           
 int getSpeed(Commandable agent, Terrain t)
          Gets the speed across this Terrain.
 boolean isWater(Terrain t)
          Checks if it's water.
 void setNoPassDelay(MoveEvent event)
          Sets the delay for a blocked move.
 boolean terrainCheck(GameObject agent, Terrain t, java.util.List objects, int x, int y)
          Returns true if the monster can move into the specified square.
 GameObject terrainCheckBlockedBy(GameObject agent, Terrain terrain, java.util.List objects, int x, int y)
          Returns whatever's in our way, null if nothing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FASTEST_MOVE_SPEED

public static final int FASTEST_MOVE_SPEED
It puts a HUGE load on the server if your move speed is too fast, since player movement is the largest consumer of CPU and network bandwidth. As speed approaches zero, number of moves per second approaches infinity. Look how it changes:

move-speed moves per second
50 20
30 33
20 50
10 100
5 200
1 1000

It's important that players aren't able to move faster than this cap. Back when players could get move speeds of zero, we were adding thousands of events per second to the game scheduler, which effectively cut the total number of simultaneous players by half (or more).

So tuning this parameter has a big impact on the server performance. I've put it as low (fast) as I think I can justify. It's twice the speed of an unencumbered human.

See Also:
Constant Field Values
Constructor Detail

Mover

public Mover()
Method Detail

getInstance

public static Mover getInstance()

checkAllLocations

public void checkAllLocations(MoveEvent event)
Checks every destination location to make sure it's a valid move. It should be OK to check the preconditions now, because the map won't actually change between now and when we execute the event. (Actually, a pre-hook could change it, but they're expected to know what they're doing).

Parameters:
event - the MoveEvent we're building

checkPreconditions

public boolean checkPreconditions(MoveEvent event,
                                  GameMap map,
                                  java.util.List dest_objs,
                                  int x,
                                  int y)
Examines the destination of the move to see if we should do anything "special". These checks will take player and monster skills and abilities into account.

Parameters:
event - the MoveEvent
map - the map the agent is in
dest_objs - the objects at the destination location
x - the destination x coordinate
y - the destination y coordinate
Returns:
vetoes the event if the agent can't move there, and returns false. If true is returned, it's OK to move there. This method is also expected to set the speed for the event.

terrainCheck

public boolean terrainCheck(GameObject agent,
                            Terrain t,
                            java.util.List objects,
                            int x,
                            int y)
Returns true if the monster can move into the specified square.

Parameters:
t - the Terrain in question
objects - the other objects at that location
x - the x map location we're checking
y - the y map location we're checking
Returns:
true if the square can be entered; false if not.

terrainCheckBlockedBy

public GameObject terrainCheckBlockedBy(GameObject agent,
                                        Terrain terrain,
                                        java.util.List objects,
                                        int x,
                                        int y)
Returns whatever's in our way, null if nothing

Parameters:
agent - the agent that's moving
terrain - the terrain at this square
objects - the objects in this square
x - the x map location we're checking
y - the y map location we're checking
Returns:
blocker if blocked, otherwise null

canMove

public boolean canMove(GameObject agent,
                       Terrain t)
Returns true if the agent can move onto the specified terrain at all. This check only examines the terrain in question and the skills & abilities of the agent.

Commandables may make a subclass of Mover that overrides this method if they want to constrain their movement in some way; e.g. a Shark might have a WaterMover subclass that only lets it move in water-type terrain.

I had really high hopes for this method, by the way. I wanted to have a general extension mechanism by which you could see who was preventing (or allowing) a move, and veto them. The team couldn't think of a satisfactory mechanism, though.

Parameters:
agent - the Commandable trying to move there
t - the Terrain to examine

getSpeed

public int getSpeed(Commandable agent,
                    Terrain t)
Gets the speed across this Terrain. Takes into account the agent's base move speed, their encumbrance, the terrain cost, and their skill with that terrain type, if any.

Parameters:
agent - the agent that's trying to move
t - the terrain into which the agent is moving
Returns:
the speed at which the agent may move across that terrain

isWater

public boolean isWater(Terrain t)
Checks if it's water.

Parameters:
t - the the Terrain to check
Returns:
true if it's liquid (has the "liquid" property).

canWalk

public boolean canWalk(GameObject obj,
                       int x,
                       int y)
Checks to see if the object is walkable at the specified map location.

Parameters:
x - the map x location
y - the map y location
obj - the object to check
Returns:
true if you can walk on the object there.

setNoPassDelay

public void setNoPassDelay(MoveEvent event)
Sets the delay for a blocked move.

Parameters:
event - the event in which to set the delay. Sets the delay in the event.