megamek.server
Class Server

java.lang.Object
  extended by megamek.server.Server
All Implemented Interfaces:
java.lang.Runnable

public class Server
extends java.lang.Object
implements java.lang.Runnable

Author:
Ben Mazur

Nested Class Summary
(package private)  class Server.ConnectionWatchdog
           
static class Server.DamageType
          The DamageType enumeration is used for the damageEntity function.
 
Field Summary
(package private)  java.util.Hashtable<java.lang.Integer,IConnection> connectionIds
           
(package private)  java.util.Vector<IConnection> connections
           
(package private)  java.util.Vector<IConnection> connectionsPending
           
static java.lang.String DEFAULT_BOARD
           
(package private)  IGame game
           
 
Constructor Summary
Server(java.lang.String password, int port)
          Construct a new GameHost and begin listening for incoming clients.
 
Method Summary
 java.util.Vector<Report> abandonEntity(Entity entity)
          Abandon an Entity.
 void addMovementHeat()
          Add heat from the movement phase
 void addScheduledNuke(int[] nuke)
          add a nuke to be exploded in the next weapons attack phase
 void addSmoke(java.util.ArrayList<Coords> coords, int windDir, boolean bInferno)
          Called when a fire is burning.
 void applyBoardSettings()
          Applies board settings.
 java.util.Vector<Report> applyCriticalHit(Entity en, int loc, CriticalSlot cs, boolean secondaryEffects)
          Apply a single critical hit.
 java.util.Vector<Report> applyCriticalHit(Entity en, int loc, CriticalSlot cs, boolean secondaryEffects, int damageCaused, boolean isCapital)
          Apply a single critical hit.
 void applySecondaryNuclearEffects(Entity entity, Coords position, java.util.Vector<Report> vDesc)
          Handles secondary effects from nuclear blasts against all units in range.
 void artilleryDamageArea(Coords centre, Coords attackSource, AmmoType ammo, int subjectId, Entity killer, boolean flak, int altitude, boolean mineClear, java.util.Vector<Report> vPhaseReport, boolean asfFlak)
          deal area saturation damage to the map, used for artillery
 void artilleryDamageArea(Coords centre, Coords attackSource, AmmoType ammo, int subjectId, Entity killer, int damage, int falloff, boolean flak, int altitude, java.util.Vector<Report> vPhaseReport, boolean asfFlak)
          Deals area-saturation damage to an area of the board.
(package private)  void artilleryDamageHex(Coords coords, Coords attackSource, int damage, AmmoType ammo, int subjectId, Entity killer, Entity exclude, boolean flak, int altitude, java.util.Vector<Report> vPhaseReport, boolean asfFlak)
          deal area saturation damage to an individual hex
 void autoSave()
          automatically save the game
 void calculatePlayerBVs()
          Calculates all players initial BV, should only be called at start of game
 void cancelVictory()
          Cancels the force victory
 boolean canShelter(Coords entityPosition, Coords position, int entityAbsHeight)
          Check if an Entity of the passed height can find shelter from a nukeblast
 void checkEntityExchange()
          loop through entitis in the exchange phase (i.e. after leaving chatlounge) and do any actions that need to be done
 void checkExplodeIndustrialZone(Coords c, java.util.Vector<Report> vDesc)
          checks for unintended exposion of heavy industrial zone hex and applies damage to entities occupying the hex
 boolean checkForCollapse(Building bldg, java.util.Hashtable<Coords,java.util.Vector<Entity>> positionMap, Coords coords, boolean checkBecauseOfDamage)
          Determine if the given building should collapse.
 void checkForFlamingDamage()
          Checks to see if any non-mech units are standing in fire.
 void checkForObservers()
          Checks each player to see if he has no entities, and if true, sets the observer flag for that player.
 java.util.Vector<Report> checkForVehicleFire(Tank tank, boolean inferno)
          check for vehicle fire, according to the MaxTech rules
(package private)  void checkForWashedInfernos(Entity entity, Coords coords)
          Checks to see if we may have just washed off infernos.
 boolean checkIgnition(Coords c, TargetRoll roll)
          Returns true if the hex is set on fire with the specified roll.
 boolean checkIgnition(Coords c, TargetRoll roll, boolean bInferno)
          Returns true if the hex is set on fire with the specified roll.
 boolean checkIgnition(Coords c, TargetRoll roll, boolean bInferno, int entityId, java.util.Vector<Report> vPhaseReport)
          Checks for fire ignition based on a given target roll.
 boolean clearMinefield(Minefield mf, Entity en, int target, int botch, java.util.Vector<Report> vClearReport)
          attempt to clear a minefield We don't actually remove the minefield here, because if this is called up from within a loop, that will cause problems
 boolean clearMinefield(Minefield mf, Entity en, int target, java.util.Vector<Report> vClearReport)
          attempt to clear a minefield
 void collapseBuilding(Building bldg, java.util.Hashtable<Coords,java.util.Vector<Entity>> positionMap, Coords coords)
           
 void collapseBuilding(Building bldg, java.util.Hashtable<Coords,java.util.Vector<Entity>> positionMap, Coords coords, boolean collapseAll)
          Collapse a building hex.
 void createSmoke(java.util.ArrayList<Coords> coords, int level, int duration)
          create a SmokeCloud object and add it to the server list
 void createSmoke(Coords coords)
          create a SmokeCloud object and add it to the server list
 void createSmoke(Coords coords, int level)
          create a SmokeCloud object and add it to the server list
 void createSmoke(Coords coords, int level, int duration)
          create a SmokeCloud object and add it to the server list
 void creditKill(Entity target, Entity attacker)
          Credits a Kill for an entity, if the target got killed.
 java.util.Vector<Report> criticalEntity(Entity en, int loc, int critMod)
          Rolls and resolves critical hits with a die roll modifier.
 java.util.Vector<Report> criticalEntity(Entity en, int loc, int critMod, boolean rollNumber, boolean isCapital)
          Rolls and resolves critical hits on mechs or vehicles. if rollNumber is false, a single hit is applied - needed for MaxTech Heat Scale rule.
 java.util.Vector<Report> damageBuilding(Building bldg, int damage, Coords coords)
          Apply the given amount of damage to the building.
 java.util.Vector<Report> damageBuilding(Building bldg, int damage, java.lang.String why, Coords coords)
          Apply the given amount of damage to the building.
 java.util.Vector<Report> damageEntity(Entity te, HitData hit, int damage)
          Deals the listed damage to an entity.
 java.util.Vector<Report> damageEntity(Entity te, HitData hit, int damage, boolean ammoExplosion, Server.DamageType bFrag, boolean damageIS)
          Deals the listed damage to an entity.
 java.util.Vector<Report> damageEntity(Entity te, HitData hit, int damage, boolean ammoExplosion, Server.DamageType bFrag, boolean damageIS, boolean areaSatArty, boolean throughFront)
          Deals the listed damage to an entity.
 java.util.Vector<Report> damageEntity(Entity te, HitData hit, int damage, boolean ammoExplosion, Server.DamageType bFrag, boolean damageIS, boolean areaSatArty, boolean throughFront, boolean underWater)
          Deals the listed damage to an entity.
 java.util.Vector<Report> damageEntity(Entity te, HitData hit, int damage, boolean ammoExplosion, Server.DamageType bFrag, boolean damageIS, boolean areaSatArty, boolean throughFront, boolean underWater, boolean nukeS2S)
          Deals the listed damage to an entity.
 void damageInfantryIn(Building bldg, int damage, Coords hexCoords)
          Apply the correct amount of damage that passes on to any infantry unit in the given building, based upon the amount of damage the building just sustained.
 void deliverArtilleryFlare(Coords coords, int radius)
          Creates an artillery flare of the given radius above the target
 void deliverArtilleryInferno(Coords coords, Entity ae, int subjectId, java.util.Vector<Report> vPhaseReport)
          deliver artillery inferno
 void deliverArtillerySmoke(Coords coords, java.util.Vector<Report> vPhaseReport)
          deliver artillery smoke
 void deliverBombDamage(Coords centre, int type, int subjectId, Entity killer, java.util.Vector<Report> vPhaseReport)
           
 void deliverBombInferno(Coords coords, Entity ae, int subjectId, java.util.Vector<Report> vPhaseReport)
          deliver inferno bomb
 void deliverFASCAMMinefield(Coords coords, int playerId, int damage, int entityId)
          Delivers a Arrow IV FASCAM shot to the targetted hex area.
 java.util.Vector<Report> deliverInfernoMissiles(Entity ae, Targetable t, int missiles)
          deliver inferno missiles
 java.util.Vector<Report> deliverInfernoMissiles(Entity ae, Targetable t, int missiles, int called)
          deliver inferno missiles
 void deliverScreen(Coords coords, java.util.Vector<Report> vPhaseReport)
           
 void deliverThunderActiveMinefield(Coords coords, int playerId, int damage, int entityId)
          Adds a Thunder-Active minefield to the hex.
 void deliverThunderAugMinefield(Coords coords, int playerId, int damage, int entityId)
          Delivers a thunder-aug shot to the targetted hex area.
 void deliverThunderInfernoMinefield(Coords coords, int playerId, int damage, int entityId)
          Adds a Thunder Inferno minefield to the hex.
 void deliverThunderMinefield(Coords coords, int playerId, int damage, int entityId)
          Adds a Thunder minefield to the hex.
 void deliverThunderVibraMinefield(Coords coords, int playerId, int damage, int sensitivity, int entityId)
          Adds a Thunder-Vibrabomb minefield to the hex.
 void deployTeleMissile(Entity ae, AmmoType atype, int wId, int capMisMod, java.util.Vector<Report> vPhaseReport)
          deploys a new tele-missile entity onto the map
 void die()
          Shuts down the server.
(package private)  void disconnected(Player player)
          Called when it's been determined that an actual player disconnected.
(package private)  void doAllAssaultDrops()
          resolve assault drops for all entities
 void doAssaultDrop(Entity entity)
          resolve the landing of an assault drop
 void doExplosion(int[] damages, boolean autoDestroyInSameHex, Coords position, boolean allowShelter, java.util.Vector<Report> vDesc, java.util.Vector<java.lang.Integer> vUnits, int clusterAmt)
          General function to cause explosions in areas.
 void doExplosion(int damage, int degredation, boolean autoDestroyInSameHex, Coords position, boolean allowShelter, java.util.Vector<Report> vDesc, java.util.Vector<java.lang.Integer> vUnits)
          General function to cause explosions in areas.
 void doFusionEngineExplosion(int engineRating, Coords position, java.util.Vector<Report> vDesc, java.util.Vector<java.lang.Integer> vUnits)
          Extract explosion functionality for generalized explosions in areas.
(package private)  void doMagmaDamage(Entity en, boolean eruption)
          do damage from magma
 void doNuclearExplosion(Coords position, int baseDamage, int degredation, int secondaryRadius, int craterDepth, java.util.Vector<Report> vDesc)
          explode a nuke
 void doNuclearExplosion(Coords position, int nukeType, java.util.Vector<Report> vDesc)
          do a nuclear explosion
 java.util.Vector<Report> doSetLocationsExposure(Entity entity, IHex hex, boolean isJump, int elevation)
          Set the locationsexposure of an entity
 void doSinkEntity(Entity en)
          sink any entities in quicksand in the current hex
 void dropUnit(Entity drop, Entity entity, Coords curPos, int altitude)
           
 java.util.Vector<Report> ejectEntity(Entity entity, boolean autoEject)
          Eject an Entity.
 void entityUpdate(int nEntityID)
          In a double-blind game, update only visible entities.
 void entityUpdate(int nEntityID, java.util.Vector<UnitLocation> movePath)
          In a double-blind game, update only visible entities.
 void forceVictory(Player victor)
          Forces victory for the specified player, or his/her team at the end of the round.
 java.util.Enumeration<java.lang.String> getAllCommandNames()
          Returns an enumeration of all the command names
 ServerCommand getCommand(java.lang.String name)
          Returns the command associated with the specified name
 IConnection getConnection(int connId)
          Returns a connection, indexed by id
 java.util.Enumeration<IConnection> getConnections()
          Returns a connection, indexed by id
 int getFreeConnectionId()
          Returns a free connection id.
 int getFreeEntityId()
          Returns a free entity id.
 IGame getGame()
          Returns the current game object
 java.lang.String getHost()
           
(package private)  IConnection getPendingConnection(int connId)
          Returns a pending connection
 Player getPlayer(int id)
          Shortcut to game.getPlayer(id)
 int getPort()
           
static Server getServerInstance()
           
 java.util.List<SmokeCloud> getSmokeCloudList()
           
(package private)  void greeting(int cn)
          Sent when a client attempts to connect.
protected  void handle(int connId, Packet packet)
          Process a packet from a connection.
 void ignite(Coords c, boolean bInferno, java.util.Vector<Report> vReport)
          add fire to a hex
 boolean isPassword(java.lang.Object guess)
           
 boolean isPassworded()
           
 boolean isTurnSkippable()
          Returns true if the current turn may be skipped.
 boolean loadGame(java.io.File f)
          load the game
 void removeFire(Coords fireCoords, java.lang.String reason)
          remove fire from a hex
 void removeMinefield(Minefield mf)
          Removes the minefield from the game.
 void removeSmokeTerrain(SmokeCloud cloud)
          remove a cloud from the map
 void reportRoll(Roll roll)
           
 void resetConnections()
          Resets all the connections.
 void resetGame()
          Reset the game back to the lounge.
(package private)  void resolveFortify()
          Resolve any Infantry units which are fortifying hexes
 void run()
          Listen for incoming clients.
 void saveGame(java.lang.String sFile)
          save the game
 void saveGame(java.lang.String sFile, boolean sendChat)
          save the game
 void sendChangedCFBuildings(java.util.Vector<Building> buildings)
           
 void sendChangedHex(Coords coords)
          Sends notification to clients that the specified hex has changed.
 void sendChangedMines(Coords coords)
          Sends notification to clients that the specified hex has changed.
 void sendChat(int connId, java.lang.String origin, java.lang.String message)
          Transmits a chat message to all players
 void sendEntities(int connId)
          Resend entities to the player called by seeall command
 void sendLoadGame(int connId, java.lang.String sFile)
          send a packet to the connection tells it load a locally saved game
 void sendSaveGame(int connId, java.lang.String sFile)
          save the game and send it to the sepecified connection
 void sendServerChat(int connId, java.lang.String message)
           
 void sendServerChat(java.lang.String message)
           
 void sendVisibilityIndicator(Entity e)
           
 void setGame(IGame g)
          Sets the game for this server.
 void skipCurrentTurn()
          Skips the current turn.
 java.util.Vector<Report> tryClearHex(Coords c, int nDamage, int entityId)
           
 boolean tryIgniteHex(Coords c, int entityId, boolean bHotGun, boolean bInferno, TargetRoll nTargetRoll, boolean bReportAttempt, int accidentTarget, java.util.Vector<Report> vPhaseReport)
          Try to ignite the hex, taking into account exisiting fires and the effects of Inferno rounds.
 boolean tryIgniteHex(Coords c, int entityId, boolean bHotGun, boolean bInferno, TargetRoll nTargetRoll, int accidentTarget, java.util.Vector<Report> vPhaseReport)
          Try to ignite the hex, taking into account exisiting fires and the effects of Inferno rounds.
 void updateSmoke(SmokeCloud cloud, java.util.ArrayList<Coords> newCoords)
          Update the map with a new set of coords.
 void validatePlayerInfo(int playerId)
          Validates the player info.
 boolean victory()
          Returns true if victory conditions have been met.
(package private)  void washInferno(Entity entity, Coords coords)
          Washes off an inferno from a mech and adds it to the (water) hex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BOARD

public static final java.lang.String DEFAULT_BOARD
See Also:
Constant Field Values

connections

java.util.Vector<IConnection> connections

connectionsPending

java.util.Vector<IConnection> connectionsPending

connectionIds

java.util.Hashtable<java.lang.Integer,IConnection> connectionIds

game

IGame game
Constructor Detail

Server

public Server(java.lang.String password,
              int port)
       throws java.io.IOException
Construct a new GameHost and begin listening for incoming clients.

Parameters:
password - the String that is set as a password
port - the int value that specifies the port that is used
Throws:
java.io.IOException
Method Detail

setGame

public void setGame(IGame g)
Sets the game for this server. Restores any transient fields, and sets all players as ghosts. This should only be called during server initialization before any players have connected.


resetConnections

public void resetConnections()
Resets all the connections. The only use of this right now is when games are loaded after clients have connected


getGame

public IGame getGame()
Returns the current game object


isPassworded

public boolean isPassworded()
Returns:
true if the server has a password

isPassword

public boolean isPassword(java.lang.Object guess)
Returns:
true if the password matches

getCommand

public ServerCommand getCommand(java.lang.String name)
Returns the command associated with the specified name


die

public void die()
Shuts down the server.


getAllCommandNames

public java.util.Enumeration<java.lang.String> getAllCommandNames()
Returns an enumeration of all the command names


greeting

void greeting(int cn)
Sent when a client attempts to connect.


getFreeConnectionId

public int getFreeConnectionId()
Returns a free connection id.


getFreeEntityId

public int getFreeEntityId()
Returns a free entity id. Perhaps this should be in Game instead.


sendEntities

public void sendEntities(int connId)
Resend entities to the player called by seeall command


validatePlayerInfo

public void validatePlayerInfo(int playerId)
Validates the player info.


disconnected

void disconnected(Player player)
Called when it's been determined that an actual player disconnected. Notifies the other players and does the appropriate housekeeping.


checkForObservers

public void checkForObservers()
Checks each player to see if he has no entities, and if true, sets the observer flag for that player. An exception is that there are no observers during the lounge phase.


resetGame

public void resetGame()
Reset the game back to the lounge. TODO: couldn't this be a hazard if there are other things executing at the same time?


autoSave

public void autoSave()
automatically save the game


sendSaveGame

public void sendSaveGame(int connId,
                         java.lang.String sFile)
save the game and send it to the sepecified connection

Parameters:
connId - The int connection id to send to
sFile - The String filename to use

saveGame

public void saveGame(java.lang.String sFile,
                     boolean sendChat)
save the game

Parameters:
sFile - The String filename to use
sendChat - A boolean value wether or not to announce the saving to the server chat.

saveGame

public void saveGame(java.lang.String sFile)
save the game

Parameters:
sFile - The String filename to use

sendLoadGame

public void sendLoadGame(int connId,
                         java.lang.String sFile)
send a packet to the connection tells it load a locally saved game

Parameters:
connId - The int connection id to send to
sFile - The String filename to use

loadGame

public boolean loadGame(java.io.File f)
load the game

Parameters:
f - The File to load
Returns:
A boolean value wether or not the loading was successfull

getPlayer

public Player getPlayer(int id)
Shortcut to game.getPlayer(id)


getConnections

public java.util.Enumeration<IConnection> getConnections()
Returns a connection, indexed by id


getConnection

public IConnection getConnection(int connId)
Returns a connection, indexed by id


getPendingConnection

IConnection getPendingConnection(int connId)
Returns a pending connection


forceVictory

public void forceVictory(Player victor)
Forces victory for the specified player, or his/her team at the end of the round.


cancelVictory

public void cancelVictory()
Cancels the force victory


calculatePlayerBVs

public void calculatePlayerBVs()
Calculates all players initial BV, should only be called at start of game


checkEntityExchange

public void checkEntityExchange()
loop through entitis in the exchange phase (i.e. after leaving chatlounge) and do any actions that need to be done


skipCurrentTurn

public void skipCurrentTurn()
Skips the current turn. This only makes sense in phases that have turns. Operates by finding an entity to move and then doing nothing with it.


isTurnSkippable

public boolean isTurnSkippable()
Returns true if the current turn may be skipped. Ghost players' turns are skippable, and a turn should be skipped if there's nothing to move.


victory

public boolean victory()
Returns true if victory conditions have been met. Victory conditions are when there is only one player left with mechs or only one team. will also add some reports to reporting


applyBoardSettings

public void applyBoardSettings()
Applies board settings. This loads and combines all the boards that were specified into one mega-board and sets that board as current.


dropUnit

public void dropUnit(Entity drop,
                     Entity entity,
                     Coords curPos,
                     int altitude)

deliverThunderAugMinefield

public void deliverThunderAugMinefield(Coords coords,
                                       int playerId,
                                       int damage,
                                       int entityId)
Delivers a thunder-aug shot to the targetted hex area. Thunder-Augs are 7 hexes, though, so...


deliverThunderMinefield

public void deliverThunderMinefield(Coords coords,
                                    int playerId,
                                    int damage,
                                    int entityId)
Adds a Thunder minefield to the hex.

Parameters:
coords -
playerId -
damage -

deliverThunderInfernoMinefield

public void deliverThunderInfernoMinefield(Coords coords,
                                           int playerId,
                                           int damage,
                                           int entityId)
Adds a Thunder Inferno minefield to the hex.

Parameters:
coords -
playerId -
damage -

deliverFASCAMMinefield

public void deliverFASCAMMinefield(Coords coords,
                                   int playerId,
                                   int damage,
                                   int entityId)
Delivers a Arrow IV FASCAM shot to the targetted hex area.


deliverThunderActiveMinefield

public void deliverThunderActiveMinefield(Coords coords,
                                          int playerId,
                                          int damage,
                                          int entityId)
Adds a Thunder-Active minefield to the hex.


deliverThunderVibraMinefield

public void deliverThunderVibraMinefield(Coords coords,
                                         int playerId,
                                         int damage,
                                         int sensitivity,
                                         int entityId)
Adds a Thunder-Vibrabomb minefield to the hex.


deliverArtilleryFlare

public void deliverArtilleryFlare(Coords coords,
                                  int radius)
Creates an artillery flare of the given radius above the target


deliverArtillerySmoke

public void deliverArtillerySmoke(Coords coords,
                                  java.util.Vector<Report> vPhaseReport)
deliver artillery smoke

Parameters:
coords - the Coords where to deliver

deliverArtilleryInferno

public void deliverArtilleryInferno(Coords coords,
                                    Entity ae,
                                    int subjectId,
                                    java.util.Vector<Report> vPhaseReport)
deliver artillery inferno

Parameters:
coords - the Coords where to deliver
ae - the attacking entity
subjectId - the int id of the target

deliverScreen

public void deliverScreen(Coords coords,
                          java.util.Vector<Report> vPhaseReport)

deployTeleMissile

public void deployTeleMissile(Entity ae,
                              AmmoType atype,
                              int wId,
                              int capMisMod,
                              java.util.Vector<Report> vPhaseReport)
deploys a new tele-missile entity onto the map


deliverInfernoMissiles

public java.util.Vector<Report> deliverInfernoMissiles(Entity ae,
                                                       Targetable t,
                                                       int missiles)
deliver inferno missiles

Parameters:
ae - the Entity that fired the missiles
t - the Targetable that is the target
missiles - the int amount of missiles

deliverInfernoMissiles

public java.util.Vector<Report> deliverInfernoMissiles(Entity ae,
                                                       Targetable t,
                                                       int missiles,
                                                       int called)
deliver inferno missiles

Parameters:
ae - the Entity that fired the missiles
t - the Targetable that is the target
missiles - the int amount of missiles
aimingMode - an int indicated the aiming mode used to fire the inferno missiles (for called shots)
aimAt - an int indicating the location being aimed at (for called shots)

clearMinefield

public boolean clearMinefield(Minefield mf,
                              Entity en,
                              int target,
                              java.util.Vector<Report> vClearReport)
attempt to clear a minefield

Parameters:
mf - - a Minefield to clear
en - - entity doing the clearing
target - - int needed to roll for a successful clearance
Returns:
true if clearance successful

clearMinefield

public boolean clearMinefield(Minefield mf,
                              Entity en,
                              int target,
                              int botch,
                              java.util.Vector<Report> vClearReport)
attempt to clear a minefield We don't actually remove the minefield here, because if this is called up from within a loop, that will cause problems

Parameters:
mf - - a Minefield to clear
en - - entity doing the clearing
target - - int needed to roll for a successful clearance
botch - - int that indicates an accidental detonation
Returns:
true if clearance successful

removeMinefield

public void removeMinefield(Minefield mf)
Removes the minefield from the game.

Parameters:
mf - The Minefield to remove

checkForWashedInfernos

void checkForWashedInfernos(Entity entity,
                            Coords coords)
Checks to see if we may have just washed off infernos. Call after a step which may have done this.

Parameters:
entity - The Entity that is being checked
coords - The Coords the entity is at

washInferno

void washInferno(Entity entity,
                 Coords coords)
Washes off an inferno from a mech and adds it to the (water) hex.

Parameters:
entity - The Entity that is taking a bath
coords - The Coords the entity is at

addMovementHeat

public void addMovementHeat()
Add heat from the movement phase


doSetLocationsExposure

public java.util.Vector<Report> doSetLocationsExposure(Entity entity,
                                                       IHex hex,
                                                       boolean isJump,
                                                       int elevation)
Set the locationsexposure of an entity

Parameters:
entity - The Entity who's exposure is being set
hex - The IHex the entity is in
isJump - a boolean value wether the entity is jumping
elevation - the elevation the entity should be at.

tryIgniteHex

public boolean tryIgniteHex(Coords c,
                            int entityId,
                            boolean bHotGun,
                            boolean bInferno,
                            TargetRoll nTargetRoll,
                            boolean bReportAttempt,
                            int accidentTarget,
                            java.util.Vector<Report> vPhaseReport)
Try to ignite the hex, taking into account exisiting fires and the effects of Inferno rounds.

Parameters:
c - - the Coords of the hex being lit.
entityId - - the int id of the entity involved.
bInferno - - true if the weapon igniting the hex is an Inferno round. If some other weapon or ammo is causing the roll, this should be false.
bHotGun - - true if the weapon is plasma/flamer/incendiary LRM/etc
nTargetRoll - - the TargetRoll for the ignition roll.
bReportAttempt - - true if the attempt roll should be added to the report.
accidentTarget - - int the target number below which a roll has to be made in order to try igniting a hex accidently. -1 for intentional

tryIgniteHex

public boolean tryIgniteHex(Coords c,
                            int entityId,
                            boolean bHotGun,
                            boolean bInferno,
                            TargetRoll nTargetRoll,
                            int accidentTarget,
                            java.util.Vector<Report> vPhaseReport)
Try to ignite the hex, taking into account exisiting fires and the effects of Inferno rounds. This version of the method will not report the attempt roll.

Parameters:
c - - the Coords of the hex being lit.
entityId - - the int id of the entity involved.
bInferno - - true if the weapon igniting the hex is an Inferno round. If some other weapon or ammo is causing the roll, this should be false.
nTargetRoll - - the int roll target for the attempt.

tryClearHex

public java.util.Vector<Report> tryClearHex(Coords c,
                                            int nDamage,
                                            int entityId)

checkForFlamingDamage

public void checkForFlamingDamage()
Checks to see if any non-mech units are standing in fire. Called at the end of the movement phase


damageEntity

public java.util.Vector<Report> damageEntity(Entity te,
                                             HitData hit,
                                             int damage)
Deals the listed damage to an entity. Returns a vector of Reports for the phase report

Parameters:
te - the target entity
hit - the hit data for the location hit
damage - the damage to apply
Returns:
a Vector of Reports

damageEntity

public java.util.Vector<Report> damageEntity(Entity te,
                                             HitData hit,
                                             int damage,
                                             boolean ammoExplosion,
                                             Server.DamageType bFrag,
                                             boolean damageIS)
Deals the listed damage to an entity. Returns a vector of Reports for the phase report

Parameters:
te - the target entity
hit - the hit data for the location hit
damage - the damage to apply
ammoExplosion - ammo explosion type damage is applied directly to the IS, hurts the pilot, causes auto-ejects, and can blow the unit to smithereens
bFrag - The DamageType of the attack.
damageIS - Should the target location's internal structure be damaged directly?
Returns:
a Vector of Reports

damageEntity

public java.util.Vector<Report> damageEntity(Entity te,
                                             HitData hit,
                                             int damage,
                                             boolean ammoExplosion,
                                             Server.DamageType bFrag,
                                             boolean damageIS,
                                             boolean areaSatArty,
                                             boolean throughFront)
Deals the listed damage to an entity. Returns a vector of Reports for the phase report

Parameters:
te - the target entity
hit - the hit data for the location hit
damage - the damage to apply
ammoExplosion - ammo explosion type damage is applied directly to the IS, hurts the pilot, causes auto-ejects, and can blow the unit to smithereens
bFrag - The DamageType of the attack.
damageIS - Should the target location's internal structure be damaged directly?
areaSatArty - Is the damage from an area saturating artillery attack?
throughFront - Is the damage coming through the hex the unit is facing?
Returns:
a Vector of Reports

damageEntity

public java.util.Vector<Report> damageEntity(Entity te,
                                             HitData hit,
                                             int damage,
                                             boolean ammoExplosion,
                                             Server.DamageType bFrag,
                                             boolean damageIS,
                                             boolean areaSatArty,
                                             boolean throughFront,
                                             boolean underWater)
Deals the listed damage to an entity. Returns a vector of Reports for the phase report

Parameters:
te - the target entity
hit - the hit data for the location hit
damage - the damage to apply
ammoExplosion - ammo explosion type damage is applied directly to the IS, hurts the pilot, causes auto-ejects, and can blow the unit to smithereens
bFrag - The DamageType of the attack.
damageIS - Should the target location's internal structure be damaged directly?
areaSatArty - Is the damage from an area saturating artillery attack?
throughFront - Is the damage coming through the hex the unit is facing?
underWater - Is the damage coming from an underwater attack
Returns:
a Vector of Reports

damageEntity

public java.util.Vector<Report> damageEntity(Entity te,
                                             HitData hit,
                                             int damage,
                                             boolean ammoExplosion,
                                             Server.DamageType bFrag,
                                             boolean damageIS,
                                             boolean areaSatArty,
                                             boolean throughFront,
                                             boolean underWater,
                                             boolean nukeS2S)
Deals the listed damage to an entity. Returns a vector of Reports for the phase report

Parameters:
te - the target entity
hit - the hit data for the location hit
damage - the damage to apply
ammoExplosion - ammo explosion type damage is applied directly to the IS, hurts the pilot, causes auto-ejects, and can blow the unit to smithereens
bFrag - The DamageType of the attack.
damageIS - Should the target location's internal structure be damaged directly?
areaSatArty - Is the damage from an area saturating artillery attack?
throughFront - Is the damage coming through the hex the unit is facing?
underWater - Is the damage coming from an underwater attack?
nukeS2s - is this a ship-to-ship nuke?
Returns:
a Vector of Reports

doFusionEngineExplosion

public void doFusionEngineExplosion(int engineRating,
                                    Coords position,
                                    java.util.Vector<Report> vDesc,
                                    java.util.Vector<java.lang.Integer> vUnits)
Extract explosion functionality for generalized explosions in areas.


doExplosion

public void doExplosion(int damage,
                        int degredation,
                        boolean autoDestroyInSameHex,
                        Coords position,
                        boolean allowShelter,
                        java.util.Vector<Report> vDesc,
                        java.util.Vector<java.lang.Integer> vUnits)
General function to cause explosions in areas.


doExplosion

public void doExplosion(int[] damages,
                        boolean autoDestroyInSameHex,
                        Coords position,
                        boolean allowShelter,
                        java.util.Vector<Report> vDesc,
                        java.util.Vector<java.lang.Integer> vUnits,
                        int clusterAmt)
General function to cause explosions in areas.


canShelter

public boolean canShelter(Coords entityPosition,
                          Coords position,
                          int entityAbsHeight)
Check if an Entity of the passed height can find shelter from a nukeblast

Parameters:
entityPosition - the Coords the Entity is at
position - the Coords of the explosion
entityAbsHeight - the int height of the entity
Returns:
a boolean value indicating if the entity of the given height can find shelter

addScheduledNuke

public void addScheduledNuke(int[] nuke)
add a nuke to be exploded in the next weapons attack phase

Parameters:
nuke - the nuke paramater either 3 or 6 ints 0 and 1 being X and Y when 3 ints: third is nuketype (from HS:3070) if 6 ints: third is damage fourth is degradation fifth is secondary radius sixth is crater depth

doNuclearExplosion

public void doNuclearExplosion(Coords position,
                               int nukeType,
                               java.util.Vector<Report> vDesc)
do a nuclear explosion

Parameters:
position -
nukeType -
vDesc -

doNuclearExplosion

public void doNuclearExplosion(Coords position,
                               int baseDamage,
                               int degredation,
                               int secondaryRadius,
                               int craterDepth,
                               java.util.Vector<Report> vDesc)
explode a nuke

Parameters:
position -
baseDamage -
degredation -
secondaryRadius -
craterDepth -
vDesc -

applySecondaryNuclearEffects

public void applySecondaryNuclearEffects(Entity entity,
                                         Coords position,
                                         java.util.Vector<Report> vDesc)
Handles secondary effects from nuclear blasts against all units in range.

Parameters:
entity - The entity to affect.
position - The coordinates of the nuclear blast, for to-hit directions.
vDesc - a description vector to use for reports.

applyCriticalHit

public java.util.Vector<Report> applyCriticalHit(Entity en,
                                                 int loc,
                                                 CriticalSlot cs,
                                                 boolean secondaryEffects)
Apply a single critical hit. The following private member of Server are accessed from this function, preventing it from being factored out of the Server class: destroyEntity() destroyLocation() checkEngineExplosion() damageCrew() explodeEquipment() game

Parameters:
en - the Entity that is being damaged. This value may not be null.
loc - the int location of critical hit. This value may be Entity.NONE for hits to Tanks and for hits to a Protomech torso weapon.
cs - the CriticalSlot being damaged. This value may not be null. For critical hits on a Tank, the index of the slot should be the index of the critical hit table.
secondaryEffects - the boolean flag that indicates whether to allow critical hits to cause secondary effects (such as triggering an ammo explosion, sending hovercraft to watery graves, or damaging Protomech torso weapons). This value is normally true, but it will be false when the hit is being applied from a saved game or scenario.

applyCriticalHit

public java.util.Vector<Report> applyCriticalHit(Entity en,
                                                 int loc,
                                                 CriticalSlot cs,
                                                 boolean secondaryEffects,
                                                 int damageCaused,
                                                 boolean isCapital)
Apply a single critical hit. The following private member of Server are accessed from this function, preventing it from being factored out of the Server class: destroyEntity() destroyLocation() checkEngineExplosion() damageCrew() explodeEquipment() game

Parameters:
en - the Entity that is being damaged. This value may not be null.
loc - the int location of critical hit. This value may be Entity.NONE for hits to Tanks and for hits to a Protomech torso weapon.
cs - the CriticalSlot being damaged. This value may not be null. For critical hits on a Tank, the index of the slot should be the index of the critical hit table.
secondaryEffects - the boolean flag that indicates whether to allow critical hits to cause secondary effects (such as triggering an ammo explosion, sending hovercraft to watery graves, or damaging Protomech torso weapons). This value is normally true, but it will be false when the hit is being applied from a saved game or scenario.
damageCaused - the amount of damage causing this critical. Necessary for Aeros, but may be -1 for other units.
isCapital - whether it was capital scale damage that caused critical

criticalEntity

public java.util.Vector<Report> criticalEntity(Entity en,
                                               int loc,
                                               int critMod)
Rolls and resolves critical hits with a die roll modifier.


criticalEntity

public java.util.Vector<Report> criticalEntity(Entity en,
                                               int loc,
                                               int critMod,
                                               boolean rollNumber,
                                               boolean isCapital)
Rolls and resolves critical hits on mechs or vehicles. if rollNumber is false, a single hit is applied - needed for MaxTech Heat Scale rule.


checkIgnition

public boolean checkIgnition(Coords c,
                             TargetRoll roll,
                             boolean bInferno,
                             int entityId,
                             java.util.Vector<Report> vPhaseReport)
Checks for fire ignition based on a given target roll. If successful, lights a fire also checks to see that fire is possible in the specified hex.

Parameters:
hex - - the IHex to be lit.
roll - - the TargetRoll for the ignition roll
bInferno - - true if the fire is an inferno fire. If this value is false the hex will be lit only if it contains Woods,jungle or a Building.
entityId - - the entityId responsible for the ignite attempt. If the value is Entity.NONE, then the roll attempt will not be included in the report.

checkIgnition

public boolean checkIgnition(Coords c,
                             TargetRoll roll,
                             boolean bInferno)
Returns true if the hex is set on fire with the specified roll. Of course, also checks to see that fire is possible in the specified hex. This version of the method will not report the attempt roll.

Parameters:
hex - - the IHex to be lit.
roll - - the int target number for the ignition roll
bAnyTerrain - - true if the fire can be lit in any terrain. If this value is false the hex will be lit only if it contains Woods, jungle or a Building.

checkIgnition

public boolean checkIgnition(Coords c,
                             TargetRoll roll)
Returns true if the hex is set on fire with the specified roll. Of course, also checks to see that fire is possible in the specified hex. This version of the method will not report the attempt roll.

Parameters:
hex - - the IHex to be lit.
roll - - the int target number for the ignition roll

ignite

public void ignite(Coords c,
                   boolean bInferno,
                   java.util.Vector<Report> vReport)
add fire to a hex

Parameters:
c - - the Coords of the hex to be set on fire
bInferno - - true if the fire to be set is an inferno

removeFire

public void removeFire(Coords fireCoords,
                       java.lang.String reason)
remove fire from a hex

Parameters:
x -
y -
hex -

addSmoke

public void addSmoke(java.util.ArrayList<Coords> coords,
                     int windDir,
                     boolean bInferno)
Called when a fire is burning. Called 3 times per fire hex.

Parameters:
x - The int x-coordinate of the hex
y - The int y-coordinate of the hex

entityUpdate

public void entityUpdate(int nEntityID)
In a double-blind game, update only visible entities. Otherwise, update everyone


entityUpdate

public void entityUpdate(int nEntityID,
                         java.util.Vector<UnitLocation> movePath)
In a double-blind game, update only visible entities. Otherwise, update everyone


sendChat

public void sendChat(int connId,
                     java.lang.String origin,
                     java.lang.String message)
Transmits a chat message to all players


sendServerChat

public void sendServerChat(int connId,
                           java.lang.String message)

sendServerChat

public void sendServerChat(java.lang.String message)

sendChangedHex

public void sendChangedHex(Coords coords)
Sends notification to clients that the specified hex has changed.


sendChangedMines

public void sendChangedMines(Coords coords)
Sends notification to clients that the specified hex has changed.


sendVisibilityIndicator

public void sendVisibilityIndicator(Entity e)

handle

protected void handle(int connId,
                      Packet packet)
Process a packet from a connection.

Parameters:
connId - - the int ID the connection that received the packet.
packet - - the Packet to be processed.

run

public void run()
Listen for incoming clients.

Specified by:
run in interface java.lang.Runnable

checkExplodeIndustrialZone

public void checkExplodeIndustrialZone(Coords c,
                                       java.util.Vector<Report> vDesc)
checks for unintended exposion of heavy industrial zone hex and applies damage to entities occupying the hex


damageInfantryIn

public void damageInfantryIn(Building bldg,
                             int damage,
                             Coords hexCoords)
Apply the correct amount of damage that passes on to any infantry unit in the given building, based upon the amount of damage the building just sustained. This amount is a percentage dictated by pg. 52 of BMRr.

Parameters:
bldg - - the Building that sustained the damage.
damage - - the int amount of damage.

checkForCollapse

public boolean checkForCollapse(Building bldg,
                                java.util.Hashtable<Coords,java.util.Vector<Entity>> positionMap,
                                Coords coords,
                                boolean checkBecauseOfDamage)
Determine if the given building should collapse. If so, inflict the appropriate amount of damage on each entity in the building and update the clients. If the building does not collapse, determine if any entities crash through its floor into its basement. Again, apply appropriate damage.

Parameters:
bldg - - the Building being checked. This value should not be null.
positionMap - - a Hashtable that maps the Coords positions or each unit in the game to a Vector of Entitys at that position. This value should not be null.
coords - - the Coords of the building hex to be checked
Returns:
true if the building collapsed.

collapseBuilding

public void collapseBuilding(Building bldg,
                             java.util.Hashtable<Coords,java.util.Vector<Entity>> positionMap,
                             Coords coords)

collapseBuilding

public void collapseBuilding(Building bldg,
                             java.util.Hashtable<Coords,java.util.Vector<Entity>> positionMap,
                             Coords coords,
                             boolean collapseAll)
Collapse a building hex. Inflict the appropriate amount of damage on all entities in the building. Update all clients.

Parameters:
bldg - - the Building that has collapsed.
positionMap - - a Hashtable that maps the Coords positions or each unit in the game to a Vector of Entitys at that position. This value should not be null.
coords - - The Coords> of the building hex that has collapsed
collapseAll - - A boolean indicating wether or not this collapse of a hex should be able to collapse the whole building

damageBuilding

public java.util.Vector<Report> damageBuilding(Building bldg,
                                               int damage,
                                               Coords coords)
Apply the given amount of damage to the building. Please note, this method does not apply any damage to units inside the building, update the clients, or check for the building's collapse.

A default message will be used to describe why the building took the damage.

Parameters:
bldg - - the Building that has been damaged. This value should not be null, but no exception will occur.
damage - - the int amount of damage.
coords - - the Coords of the building hex to be damaged
Returns:
a Report to be shown to the players.

damageBuilding

public java.util.Vector<Report> damageBuilding(Building bldg,
                                               int damage,
                                               java.lang.String why,
                                               Coords coords)
Apply the given amount of damage to the building. Please note, this method does not apply any damage to units inside the building, update the clients, or check for the building's collapse.

Parameters:
bldg - - the Building that has been damaged. This value should not be null, but no exception will occur.
damage - - the int amount of damage.
why - - the String message that describes why the building took the damage.
coords - - the Coords of the building hex to be damaged
Returns:
a Report to be shown to the players.

sendChangedCFBuildings

public void sendChangedCFBuildings(java.util.Vector<Building> buildings)

creditKill

public void creditKill(Entity target,
                       Entity attacker)
Credits a Kill for an entity, if the target got killed.

Parameters:
target - The Entity that got killed.
attacker - The Entity that did the killing.

ejectEntity

public java.util.Vector<Report> ejectEntity(Entity entity,
                                            boolean autoEject)
Eject an Entity.

Parameters:
entity - The Entity to eject.
autoEject - The boolean state of the entity's auto- ejection system
Returns:
a Vector of report objects for the gamelog.

abandonEntity

public java.util.Vector<Report> abandonEntity(Entity entity)
Abandon an Entity.

Parameters:
entity - The Entity to abandon.
Returns:
a Vector of report objects for the gamelog.

checkForVehicleFire

public java.util.Vector<Report> checkForVehicleFire(Tank tank,
                                                    boolean inferno)
check for vehicle fire, according to the MaxTech rules

Parameters:
tank - the Tank to be checked
inferno - a boolean parameter wether or not this check is because of inferno fire

doAssaultDrop

public void doAssaultDrop(Entity entity)
resolve the landing of an assault drop

Parameters:
entity - the Entity for which to resolve it

doAllAssaultDrops

void doAllAssaultDrops()
resolve assault drops for all entities


doMagmaDamage

void doMagmaDamage(Entity en,
                   boolean eruption)
do damage from magma

Parameters:
en - the affected Entity
eruption - boolean indicating wether or not this is because of an eruption

doSinkEntity

public void doSinkEntity(Entity en)
sink any entities in quicksand in the current hex


artilleryDamageHex

void artilleryDamageHex(Coords coords,
                        Coords attackSource,
                        int damage,
                        AmmoType ammo,
                        int subjectId,
                        Entity killer,
                        Entity exclude,
                        boolean flak,
                        int altitude,
                        java.util.Vector<Report> vPhaseReport,
                        boolean asfFlak)
deal area saturation damage to an individual hex

Parameters:
coords - The hex being hit
attackSource - The location the attack came from. For hit table resolution
damage - Amount of damage to deal to each entity
ammo - The ammo type being used
subjectId - Subject for reports
killer - Who should be credited with kills
exclude - Entity that should take no damage (used for homing splash)
flak - Flak, hits flying units only, instead of flyers being immune
altitude - Absolute altitude for flak attack
vPhaseReport - The Vector of Reports for the phasereport
asfFlak - Is this flak against ASF?

artilleryDamageArea

public void artilleryDamageArea(Coords centre,
                                Coords attackSource,
                                AmmoType ammo,
                                int subjectId,
                                Entity killer,
                                boolean flak,
                                int altitude,
                                boolean mineClear,
                                java.util.Vector<Report> vPhaseReport,
                                boolean asfFlak)
deal area saturation damage to the map, used for artillery

Parameters:
centre - The hex on which damage is centred
attackSource - The position the attack came from
ammo - The ammo type doing the damage
subjectId - Subject for reports
killer - Who should be credited with kills
flak - Flak, hits flying units only, instead of flyers being immune
altitude - Absolute altitude for flak attack
mineclear - Does this clear mines?
vPhaseReport - The Vector of Reports for the phasereport
asfFlak - Is this flak against ASF?

artilleryDamageArea

public void artilleryDamageArea(Coords centre,
                                Coords attackSource,
                                AmmoType ammo,
                                int subjectId,
                                Entity killer,
                                int damage,
                                int falloff,
                                boolean flak,
                                int altitude,
                                java.util.Vector<Report> vPhaseReport,
                                boolean asfFlak)
Deals area-saturation damage to an area of the board. Used for artillery, bombs, or anything else with linear decreas in damage

Parameters:
centre - The hex on which damage is centred
attackSource - The position the attack came from
ammo - The ammo type doing the damage
subjectId - Subject for reports
killer - Who should be credited with kills
damage - Damage at ground zero
falloff - Reduction in damage for each hex of distance
flak - Flak, hits flying units only, instead of flyers being immune
altitude - Absolute altitude for flak attack
vPhaseReport - The Vector of Reports for the phasereport
asfFlak - Is this flak against ASF?

deliverBombDamage

public void deliverBombDamage(Coords centre,
                              int type,
                              int subjectId,
                              Entity killer,
                              java.util.Vector<Report> vPhaseReport)

deliverBombInferno

public void deliverBombInferno(Coords coords,
                               Entity ae,
                               int subjectId,
                               java.util.Vector<Report> vPhaseReport)
deliver inferno bomb

Parameters:
coords - the Coords where to deliver
ae - the attacking entity
subjectId - the int id of the target

resolveFortify

void resolveFortify()
Resolve any Infantry units which are fortifying hexes


getHost

public java.lang.String getHost()
Returns:
a String representing the hostname

getPort

public int getPort()
Returns:
the int this server is listening on

getServerInstance

public static Server getServerInstance()
Returns:

createSmoke

public void createSmoke(Coords coords)
create a SmokeCloud object and add it to the server list

Parameters:
coords -

createSmoke

public void createSmoke(Coords coords,
                        int level)
create a SmokeCloud object and add it to the server list

Parameters:
coords -
level - 1=Light 2=Heavy Smoke

createSmoke

public void createSmoke(Coords coords,
                        int level,
                        int duration)
create a SmokeCloud object and add it to the server list

Parameters:
coords -
level - 1=Light 2=Heavy Smoke
duration - How long the smoke will last.

createSmoke

public void createSmoke(java.util.ArrayList<Coords> coords,
                        int level,
                        int duration)
create a SmokeCloud object and add it to the server list

Parameters:
coords -
level - 1=Light 2=Heavy Smoke
duration - duration How long the smoke will last.

updateSmoke

public void updateSmoke(SmokeCloud cloud,
                        java.util.ArrayList<Coords> newCoords)
Update the map with a new set of coords.

Parameters:
newCoords -

removeSmokeTerrain

public void removeSmokeTerrain(SmokeCloud cloud)
remove a cloud from the map

Parameters:
cloud -

getSmokeCloudList

public java.util.List<SmokeCloud> getSmokeCloudList()

reportRoll

public void reportRoll(Roll roll)