A multipurpose unit. Can be either a fighting or a producting unit.

Variables

read onlyassignTo:Building

At which building is the unit assigned.

canPatrol:Bool

[HostOnly] Allow a unit to patrol in a zone. Jobless units in a friendly zones automatically starts patrolling when out of combat.

read onlyhasNoWork:Bool

Does the unit don't have any work to do. Example : A woodcutter without woodlodge.

read onlyisFoe:Bool

Is the unit a Northgard foe, a.k.a a Wolf, Draugr, etc...

read onlyisMilitary:Bool

Is the unit military. Military units can attack other units.

kind:UnitKind

[HostOnly] The kind of unit, define the behaviour and appearance of this unit.

owner:Player

[HostOnly] The player owning this unit. Neutral units or foe don't have one.

targetPlayer:Player

[HostOnly] The player the unit is set to attack. The unit will travel to the player's territory to attack him automatically.

targetZone:Zone

[HostOnly] For foes and neutral units, make them attack the specified zone.

read onlyteam:Faction

The team the unit is part of.

Methods

hideWeapons():Void

Hide the weapons of the unit. The weapons will reappear at the next attack action.

isOwner(p:Player):Bool

Tell if the given player is the owner of this unit.

Parameters:

p

Returns:

Bool

moveToZone(zone:Zone, canAttack:Bool, ?position:{y:Float, x:Float}, ?target:BaseUnit):Void

[HostOnly] Move the unit to a specific zone.

Parameters:

zone
canAttack

Can the unit attack or retaliate when travelling.

position

[Optional] Target position inside the zone.

target

[Optional] A unit or hittable building to attack once inside the zone.

moveUnit(x:Float, y:Float, ?walk:Bool):Void

[HostOnly] Make the unit move to the given coordinates.

Parameters:

x
y
walk

true to have the unit walk instead of run, default at false.

@:value({ nbFrames : 60. })orientToPosSmooth(x:Float, y:Float, nbFrames:Float = 60.):Void

[HostOnly] Turn the unit toward the given coordinates over time.

Parameters:

x
y
nbFrames

[Optional] The number of frames it takes, on a 60 frames per second base, for the units to rotate toward the target.

@:value({ nbFrames : 60. })orientToTargetSmooth(target:Entity, nbFrames:Float = 60.):Void

[HostOnly] Turn the unit toward a target over time.

Parameters:

e
nbFrames

[Optional] The number of frames it takes, on a 60 frames per second base, for the units to rotate toward the target.

pauseJob(pause:Bool):Void

[HostOnly] Pause or unpause a unit's job.

Parameters:

null

pause

setControlable(b:Bool):Void

[HostOnly] Allow or forbid a unit to be given orders by a player.

Parameters:

b

true to allow, false to forbid

showDefaultWeapons():Void

Make the weapons visible again after a use a hideWeapons()

stopJob():Void

[HostOnly] Make the unit stop the current action, be it a player order or an autonomous action like fishing or harvesting. This doesn't prevent the unit to automatically choose something else to do.