netwar.game
Class Command
java.lang.Object
|
+--netwar.game.Command
- All Implemented Interfaces:
- java.io.Serializable
- public class Command
- extends java.lang.Object
- implements java.io.Serializable
A collection of Integers to indicate a player's decision to influence the game.
The action codes are as follows:
0 = No command. Used for synchronizing games over the network.
1 = New game object.
Param 1 = x, Param 2 = y (in hex coordinates).
In this case, selection[0] identifies the type to be created.
2 = Set goal: location. Selected units try to get to a location.
Param 1 = x, Param 2 = y (in hex coordinates).
3 = Set goal: unit. Selected units try to approach/follow a Unit.
If that Unit is an enemy, the units will try to destroy it.
Param 1 = unit index for target. Param 2 not used.
Additional action codes will be added as needed. Keep in mind that these will
never include interface controls (such as zooming or scrolling) nor will it
include all of the detail actions Units can perform, only the macroscopic
actions that can be assigned by a player.
Note: The index used by command will be a unique identifier for the GameObject, not
merely the array index, which would be easy to look up. This is because indices could
change before the Command is executed. The GameObject referenced could even be deleted
in that time!
- Author:
- Group N2 - Project Netwar, Daniel Grund
- See Also:
- Serialized Form
|
Constructor Summary |
Command(int a,
int pl,
int[] sel,
int p1,
int p2)
Create the command. |
|
Method Summary |
void |
execute()
Execute the command. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
pendingCommands
public static Queue pendingCommands
- The set of local commands which need to be sent to other players.
These will not be executed until they are echoed from the server.
These commands are queued as they are generated and sent to the
server at a fixed rate (expected to be one per frame).
The array queue was deemed optimal for this, as it will not usually
grow very large, but should have the capacity for extra growth.
currentCommands
public static Command[] currentCommands
- The set of commands collected from the network.
This includes one command sent from this computer and echoed by the server.
These will be executed this cycle, and replaced before the next cycle.
The number needed for this collection equals to number of players, and will
not increase, so a basic array is adequate.
commandsUpToDate
public static boolean commandsUpToDate
- Indicates that the currentCommands contains the Command objects for
the next cycle.
empty
public static Command empty
Command
public Command(int a,
int pl,
int[] sel,
int p1,
int p2)
- Create the command.
- Parameters:
a - action code.pl - player number.sel - array of indices for the selected game objects.p1 - parameter 1 for the command.p2 - parameter 2 for the command.
execute
public void execute()
- Execute the command. Makes the command take effect.
What the command will do depends primarily on the action code.
This should be called once per Command, then the Command should be discarded.
As a precaution, the action will be set to 0 after executing the action.