Provides an individual viewpoint in a larger game--or fog-of-war. It provides limited visibility in a game, showing a player only a part of the whole. Multiple IntelCenters can provide each player in a game with their own personal view.
I developed IntelCenter originally for a network game. Each active unit regularly reported on everything it could see to its side's IntelCenter. (The ability of any such unit to see something was based on distance and terrain: spotting distances would be shorter in forests than on open ground.) Each IntelCenter then provided all the information needed to develop and maintain a map for its player showing only what that player could see. The data coming from an IntelCenter was not retained in the host program but sent directly via a socket to another program running on another computer, providing that program with all the information available to the player.
An IntelCenter itself works only via spotting reports. It does not know or care what the spotting rules are. (Distance need not be involved.) Information on spotted objects is passed through an IntelCenter without the IntelCenter itself knowing or caring what that information is. It will report, in a timely manner, on all appearences, disappearances, and changes--with the changes, like the data, being defined entirely outside IntelCenter.
The contents of an IntelCenter may, at any time, be written to an ObjectOutputStream as part of saving a game so a player's complete view is remembered.
An IntelCenter runs its own thread, and expects to receive its reports from many other threads. It is designed to do this with high efficiency and safety. It is fully Javadoc'ed. It uses java.util.concurrent.ConcurrentSkipListMap, and so requires Java 1.6. It includes ListStack, which is also available independently. The source code includes a sample program that demonstrates all IntelCenter's features.
TeamItemSet is at the core of IntelCenter and does the work. Data is provided by the addSpotted method. Results are sent to the BaseTeam implementation.
rrc12.host Class TeamItemSet
java.lang.Object rrc12.host.TeamItemSet
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, InformationCenter
public class TeamItemSet extends java.lang.Object implements InformationCenter
Maintains a set of items, or MapContent instances, that the owning BaseTeam instance knows about. Thrives in a multi-threaded environment, with a minimum of synchronization and resultant blocking.
This class starts to maintain information on items once they have been reported as sighted by addSpotted. Friendly items will always be tracked. Otherwise, items are forgotten once they are no longer being reported. However, data on immobile items, based on their state when last seen, will be retained.
To use this TeamItemSet, start by using the activate method to provide it with a setting and team. Then use the addSpotted methods to inform this TeamItemSet of observed items. addSpotted (and isSpotted) expect to be called from many different threads simultaneously. Reports about appearances, changes, and disappearances will be sent to BaseTeam. To find out if something is currently observed by this team, call isKnown. Runs a timer, so do not activate until necessary.
To summarize: TeamItemSet is the core class in a set that are used to track what one player or team or individual can see of a greater universe. For input it receives reports of spotted items. For output, it reports on appearances, disappearances, and changes from its owner's point of view.
Method Detail
activate()
public void activate(Setting s,
BaseTeam t,
int delay)
Sets the team. Until this method is called, this TeamItemSet will do nothing.
Parameters:
s - the Setting instance for this TeamItemSet. Must not be null!t - the team that knows about the items contained herein. Must not be null!delay - the length of time in real seconds between the last time a moving object was spotted and the time at which it disappears.wake()
public void wake(int delay)
Activates this TeamItemSet. The setting and team must already be set by a previous call to activate. This method is only needed if an active IC has been disabled. Currently, this can only happen if the IC has just been read in via ObjectInputStream.
Parameters:
delay - the length of time in real seconds between the last time a moving object was spotted and the time at which it disappears.addSpotted()
public void addSpotted(MapContent item)
Informs this TeamItemSet that a MapContent instance has been located. This method needs to be called once for things belonging to the team or things that do not move or change. Unowned objects that move will be forgotten by this TeamItemSet unless continuous reports are received. As for immobile items, their location will be remembered but changes in their state will be ignored in the absence of calls to this method.
Parameters:
item - the MapContent instance suspected of changing its status.addSpotted()
public void addSpotted(java.util.Collection c)
Informs this TeamItemSet that a collection of MapContent instances have been spotted. Works just like addSpotted( MapContent ), but takes a collection.
Parameters:
c - a collection of MapContent instances.isSpotted()
public boolean isSpotted(java.lang.Comparable key)
Returns true if the item whose key is passed is already spotted during the current cycle. Calling this method can save extensive checks to see if the item can be spotted. This method does some work, so quick, basic checks (such as distance) should be carried out first.
Parameters:
key - the key of the query item.Returns: true if item is spotted, false if not.
isKnown
public boolean isKnown(java.lang.Comparable key)
Returns true if the passed item is already known to this TeamItemSet. This includes items that have not been spotted during recent cycles, but were once spotted and are either immobile or were spotted recently enough that they are considered to be still there. If isSpotted returns true, everything possible has been done to assure that item will not disappear from this TeamItemSet. This method may well return true on something that will be gone from this TeamItemSet in another millisecond.
Use this method to find out if something is visible. Use isSpotted to see if you should do serious work to decide if you should report something as spotted.
Parameters:
key - the key of the query item.Returns: true if item is known, false if not.
reportAll()
public void reportAll(BasePlayer p)
Posts all existing known items in the form of ContentData objects to the specified player using BasePlayer's sendData method.
readExternal()
public final void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
Supports the Externalizable interface.
Specified by: readExternal in interface java.io.Externalizable
writeExternal()
public final void writeExternal(java.io.ObjectOutputout)
throws java.io.IOException
Supports the Externalizable interface.
Specified by: writeExternal in interface java.io.Externalizable
BaseTeam is the primary interface for output from IntelCenter.
rrc12.host Interface BaseTeam
public interface BaseTeam
A team or side. Will have one or more associated BasePlayer instances. All information available to the team will be made available to all its players.
Method Detail
sendData()
void sendData(ContentData cd)
Delivers data to this BaseTeam. It may either be requested data or data the sender thinks it is necessary for this BaseTeam to have. This method must return immediately and not block.
Parameters:
cd - the ContentData instance being sent. May be null, in which case nothing will be done.hasDisappeared()
void hasDisappeared(MapContent mc, boolean posIsKnow n)
Informs this BaseTeam that the passed MapContent instance has disappeared from view.
Parameters:
mc - the MapContent instance.posIsKnown - true if the item is known to be still on the map and its location is known because it cannot move. false if the item may be gone completely or if it can move so that its location is not known. This value is provided by MapContent.canMove.isMember()
boolean isMember(BasePlayer p)
Returns true if the specified BasePlayer instance is a member of this Team and false if not.
Questions & Comments