Class UnitBehavior
- Direct Known Subclasses:
UnitOrdersBehavior
This is Princess's original approach: each unit's waypoints are held here, in the bot's own memory, and the
unit heads for the first one until it is within Princess.DISTANCE_TO_WAYPOINT hexes of it. CASPAR uses
UnitOrdersBehavior instead, which reads the unit orders stored on each unit.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddEntityWaypoint(Entity entity, List<Coords> waypoints, Princess owner) Adds waypoints to the end of the unit's list, dropping any the unit cannot reach.booleanaddEntityWaypoint(Entity entity, Coords destination, Princess owner) Deprecated, for removal: This API element is subject to removal in a future version.voidbeginRanking(Entity entity, Princess owner) Called before a unit's moves are ranked.protected UnitBehavior.BehaviorTypecalculateUnitBehavior(Entity entity, Princess owner) Worker function that calculates a unit's desired behavior.voidclear()Clears the entity behavior cache, should be done at the start of each movement phasevoidclearWaypoints(Princess owner) Clears the waypoints of every unit of the bot.voidclearWaypoints(Entity entity, Princess owner) Clears all of one unit's waypoints.voidCalled once a unit's moves are ranked; seebeginRanking(megamek.common.units.Entity, megamek.client.bot.princess.Princess).getActiveWaypoint(Entity entity, Princess owner) Returns the waypoint that decides where the unit moves this phase, if a waypoint does.getBehaviorType(Entity entity, Princess owner) Gets (and calculates, if necessary), the behavior type for the given entity.getCachedBehaviorType(Entity entity) The behavior already worked out for this unit, without working one out if none has been.getWaypointForEntity(Entity entity) booleanisDestinationUnreachable(Entity entity, Coords destination, Princess owner) static booleanisFleeOrdered(Princess owner) Returns whether the bot has a standing order to flee toward an edge, given from the Bot Commands panel or thefleechat command.booleanisFollowingOrdersOverWithdrawal(Entity entity, Princess owner) Returns whether a withdrawing unit follows the player's waypoints instead of heading for its retreat edge.protected static voidlogDecision(Entity entity, String rule, String detail) Logs which rule decided a unit's movement this phase, so a playtest log shows why a unit did or did not follow the player's orders.voidoverrideBehaviorType(Entity entity, UnitBehavior.BehaviorType behaviorType) voidremoveHeadWaypoint(Entity entity) Removes the head waypoint from the entity's waypoint queue If waypoints were added (1,1) then (2,2), then (3,3), this would remove (1,1)voidremoveTailWaypoint(Entity entity, Princess owner) Removes the tail waypoint from the entity's waypoint queue If waypoints were added (1,1) then (2,2) then (3,3), this would remove (3,3), good for an "undo" behavior.intsetEntityWaypoints(Entity entity, List<Coords> waypoints, Princess owner) Replaces the unit's waypoints with the given ones, dropping any the unit cannot reach.
-
Constructor Details
-
UnitBehavior
public UnitBehavior()
-
-
Method Details
-
calculateUnitBehavior
Worker function that calculates a unit's desired behavior. -
logDecision
Logs which rule decided a unit's movement this phase, so a playtest log shows why a unit did or did not follow the player's orders. -
isFleeOrdered
Returns whether the bot has a standing order to flee toward an edge, given from the Bot Commands panel or thefleechat command.- Parameters:
owner- the bot- Returns:
trueif every unit of the bot is ordered toward the bot's destination edge
-
isFollowingOrdersOverWithdrawal
Returns whether a withdrawing unit follows the player's waypoints instead of heading for its retreat edge.A player's direct order outranks the unit's own Forced Withdrawal: a crippled unit sent to a hex goes there (issue #9038). Two orders still win over the waypoints: a gamemaster's order to withdraw, and the bot-wide flee order, which a withdrawing unit follows toward the ordered edge.
- Parameters:
entity- the unitowner- the bot that owns the unit- Returns:
trueif the unit is withdrawing under the bot's rules but has a waypoint to follow instead
-
getActiveWaypoint
Returns the waypoint that decides where the unit moves this phase, if a waypoint does. A bot-wide flee order and a withdrawal the player has not overridden both send the unit to an edge instead, so they return empty.- Parameters:
entity- the unitowner- the bot that owns the unit- Returns:
- the unit's current waypoint when it is following its waypoints, otherwise empty
-
beginRanking
Called before a unit's moves are ranked. Princess's waypoints need no preparation;UnitOrdersBehaviorworks out the unit's active waypoint once here.- Parameters:
entity- the unit about to have its moves rankedowner- the bot that owns the unit
-
endRanking
public void endRanking()Called once a unit's moves are ranked; seebeginRanking(megamek.common.units.Entity, megamek.client.bot.princess.Princess). -
getBehaviorType
Gets (and calculates, if necessary), the behavior type for the given entity. -
getCachedBehaviorType
The behavior already worked out for this unit, without working one out if none has been.For logging and analysis only.
getBehaviorType(megamek.common.units.Entity, megamek.client.bot.princess.Princess)computes and caches on a miss, and what it computes depends on where everything is standing at the time - so asking early, for a unit that has not moved yet, would pin an answer the bot would otherwise have reached later with better information.- Parameters:
entity- the unit to look up- Returns:
- the cached behavior, or
nullif this unit has not been evaluated this turn
-
overrideBehaviorType
-
getWaypointForEntity
- Parameters:
entity- the unit- Returns:
- the unit's first waypoint, or empty when it has none
-
isDestinationUnreachable
- Returns:
truewhen the unit cannot reach the destination, so a waypoint there should be dropped
-
addEntityWaypoint
Adds waypoints to the end of the unit's list, dropping any the unit cannot reach.- Returns:
- how many of the given waypoints were kept;
0when none of them can be reached
-
addEntityWaypoint
@Deprecated(since="0.51.0", forRemoval=true) public boolean addEntityWaypoint(Entity entity, Coords destination, Princess owner) Deprecated, for removal: This API element is subject to removal in a future version. -
removeHeadWaypoint
Removes the head waypoint from the entity's waypoint queue If waypoints were added (1,1) then (2,2), then (3,3), this would remove (1,1)- Parameters:
entity- the entity to remove the waypoint from
-
removeTailWaypoint
Removes the tail waypoint from the entity's waypoint queue If waypoints were added (1,1) then (2,2) then (3,3), this would remove (3,3), good for an "undo" behavior.- Parameters:
entity- the entity to remove the waypoint fromowner- the bot that owns the unit
-
setEntityWaypoints
Replaces the unit's waypoints with the given ones, dropping any the unit cannot reach.- Returns:
- how many of the given waypoints were kept;
0when none of them can be reached
-
clearWaypoints
Clears all of one unit's waypoints.- Parameters:
entity- the unitowner- the bot that owns the unit
-
clearWaypoints
Clears the waypoints of every unit of the bot.- Parameters:
owner- the bot
-
clear
public void clear()Clears the entity behavior cache, should be done at the start of each movement phase
-