Class TCastleMoveAttack

Unit

Declaration

type TCastleMoveAttack = class(TCastleBehavior)

Description

Creature that can move around (navigating the 3D world), chasing the enemy, attacking the enemy (by short-range or long-range attack), running away from danger.

Optional dependencies: if present, this behavior will use other behaviors on the same parent:

  • TCastleSoundSource (to play spatial sounds; this creature is silent otherwise),

  • TCastleLiving (to account for the fact that current creature may be dead, or badly wounded; if the TCastleLiving is not present, this creature is assumed indestructible.)

Hierarchy

Overview

Nested Types

Public TState = (...);

Fields

Public nested const DefaultAnimationIdle = 'idle';
Public nested const DefaultAnimationMove = 'move';
Public nested const DefaultAnimationAttack = '';
Public nested const DefaultAnimationFireMissile = '';
Public nested const DefaultAnimationDie = 'die';
Public nested const DefaultAnimationDieBack = '';
Public nested const DefaultAnimationHurt = 'hurt';
Public nested const DefaultAttackTime = 0.0;
Public nested const DefaultAttackMinDelay = 2.0;
Public nested const DefaultAttackMaxDistance = 2.0;
Public nested const DefaultAttackMaxAngle = Pi / 6;
Public nested const DefaultFireMissileTime = 0.0;
Public nested const DefaultFireMissileMinDelay = DefaultAttackMinDelay;
Public nested const DefaultFireMissileMaxDistance = 30.0;
Public nested const DefaultFireMissileMaxAngle = DefaultAttackMaxAngle;
Public nested const DefaultFireMissileHeight = 0.5;
Public nested const DefaultMoveSpeed = 1.0;
Public nested const DefaultRunAwayLife = 0.3;
Public nested const DefaultRunAwayDistance = 10.0;
Public nested const DefaultPreferredDistance = DefaultAttackMaxDistance;
Public nested const DefaultRandomMoveDistance = 10.0;
Public nested const DefaultMaxHeightAcceptableToFall = 1.5;
Public nested const DefaultVisibilityAngle = Pi * 120 / 180;
Public nested const DefaultSmellDistance = 0.0;
Public nested const DefaultRemoveDead = false;

Methods

Protected procedure SetState(const Value: TState); virtual;
Protected procedure ParentAfterAttach; override;
Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override;
Protected procedure Attack; virtual;
Protected procedure FireMissile; virtual;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;
Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;

Properties

Public property State: TState read FState default stateIdle;
Public property LifeTime: TFloatTime read FLifeTime;
Published property Enemy: TCastleLiving read FEnemy write SetEnemy;
Published property SoundAttackHit: TCastleSound read FSoundAttackHit write SetSoundAttackHit;
Published property SoundAttackStart: TCastleSound read FSoundAttackStart write SetSoundAttackStart;
Published property AnimationIdle: String read FAnimationIdle write FAnimationIdle stored AnimationIdleStored nodefault;
Published property AnimationMove: String read FAnimationMove write FAnimationMove stored AnimationMoveStored nodefault;
Published property AnimationAttack: String read FAnimationAttack write FAnimationAttack stored AnimationAttackStored nodefault;
Published property AnimationFireMissile: String read FAnimationFireMissile write FAnimationFireMissile stored AnimationFireMissileStored nodefault;
Published property AnimationDie: String read FAnimationDie write FAnimationDie stored AnimationDieStored nodefault;
Published property AnimationDieBack: String read FAnimationDieBack write FAnimationDieBack stored AnimationDieBackStored nodefault;
Published property AnimationHurt: String read FAnimationHurt write FAnimationHurt stored AnimationHurtStored nodefault;
Published property AttackMinDelay: Single read FAttackMinDelay write FAttackMinDelay default DefaultAttackMinDelay;
Published property AttackMaxDistance: Single read FAttackMaxDistance write FAttackMaxDistance default DefaultAttackMaxDistance;
Published property AttackTime: Single read FAttackTime write FAttackTime default DefaultAttackTime;
Published property AttackMaxAngle: Single read FAttackMaxAngle write FAttackMaxAngle default DefaultAttackMaxAngle;
Published property AttackDamage: TCastleDamage read FAttackDamage;
Published property FireMissileTime: Single read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime;
Published property FireMissileMinDelay: Single read FFireMissileMinDelay write FFireMissileMinDelay default DefaultFireMissileMinDelay;
Published property FireMissileMaxDistance: Single read FFireMissileMaxDistance write FFireMissileMaxDistance default DefaultFireMissileMaxDistance;
Published property FireMissileMaxAngle: Single read FFireMissileMaxAngle write FFireMissileMaxAngle default DefaultFireMissileMaxAngle;
Published property FireMissileHeight: Single read FFireMissileHeight write FFireMissileHeight default DefaultFireMissileHeight;
Published property MoveSpeed: Single read FMoveSpeed write FMoveSpeed default DefaultMoveSpeed;
Published property RunAwayLife: Single read FRunAwayLife write FRunAwayLife default DefaultRunAwayLife;
Published property RunAwayDistance: Single read FRunAwayDistance write FRunAwayDistance default DefaultRunAwayDistance;
Published property PreferredDistance: Single read FPreferredDistance write FPreferredDistance default DefaultPreferredDistance;
Published property RandomMoveDistance: Single read FRandomMoveDistance write FRandomMoveDistance default DefaultRandomMoveDistance;
Published property MaxHeightAcceptableToFall: Single read FMaxHeightAcceptableToFall write FMaxHeightAcceptableToFall default DefaultMaxHeightAcceptableToFall;
Published property VisibilityAngle: Single read FVisibilityAngle write FVisibilityAngle default DefaultVisibilityAngle;
Published property SmellDistance: Single read FSmellDistance write FSmellDistance default DefaultSmellDistance;
Published property RemoveDead: Boolean read FRemoveDead write FRemoveDead default DefaultRemoveDead;

Description

Nested Types

Public TState = (...);

This item has no description.

Values
  • stateIdle
  • stateMove
  • stateAttack
  • stateFireMissile
  • stateDie
  • stateDieBack
  • stateHurt

Fields

Public nested const DefaultAnimationIdle = 'idle';

This item has no description.

Public nested const DefaultAnimationMove = 'move';

This item has no description.

Public nested const DefaultAnimationAttack = '';

Default value of AnimationAttack, empty because it is an optional animation.

Public nested const DefaultAnimationFireMissile = '';

Default value of AnimationFireMissile, empty because it is an optional animation.

Public nested const DefaultAnimationDie = 'die';

This item has no description.

Public nested const DefaultAnimationDieBack = '';

Default value of AnimationDieBack, empty because it is an optional animation.

Public nested const DefaultAnimationHurt = 'hurt';

This item has no description.

Public nested const DefaultAttackTime = 0.0;

This item has no description.

Public nested const DefaultAttackMinDelay = 2.0;

This item has no description.

Public nested const DefaultAttackMaxDistance = 2.0;

This item has no description.

Public nested const DefaultAttackMaxAngle = Pi / 6;

This item has no description.

Public nested const DefaultFireMissileTime = 0.0;

This item has no description.

Public nested const DefaultFireMissileMinDelay = DefaultAttackMinDelay;

This item has no description.

Public nested const DefaultFireMissileMaxDistance = 30.0;

This item has no description.

Public nested const DefaultFireMissileMaxAngle = DefaultAttackMaxAngle;

This item has no description.

Public nested const DefaultFireMissileHeight = 0.5;

This item has no description.

Public nested const DefaultMoveSpeed = 1.0;

This item has no description.

Public nested const DefaultRunAwayLife = 0.3;

This item has no description.

Public nested const DefaultRunAwayDistance = 10.0;

This item has no description.

Public nested const DefaultPreferredDistance = DefaultAttackMaxDistance;

This item has no description.

Public nested const DefaultRandomMoveDistance = 10.0;

This item has no description.

Public nested const DefaultMaxHeightAcceptableToFall = 1.5;

This item has no description.

Public nested const DefaultVisibilityAngle = Pi * 120 / 180;

This item has no description.

Public nested const DefaultSmellDistance = 0.0;

This item has no description.

Public nested const DefaultRemoveDead = false;

This item has no description.

Methods

Protected procedure SetState(const Value: TState); virtual;

This item has no description.

Protected procedure ParentAfterAttach; override;

This item has no description. Showing description inherited from TCastleBehavior.ParentAfterAttach.

Called after Parent changed, e.g. at the end of TCastleTransform.AddBehavior.

Protected function CanAttachToParent(const NewParent: TCastleTransform; out ReasonWhyCannot: String): Boolean; override;

This item has no description. Showing description inherited from TCastleBehavior.CanAttachToParent.

Check can this behavior be added to NewParent. When this returns False, it has to set also ReasonWhyCannot. When overriding this, you can use e.g. this code to make sure we are the only behavior of given class:

function TCastleBillboard.CanAttachToParent(const NewParent: TCastleTransform;
  out ReasonWhyCannot: String): Boolean;
begin
  Result := inherited;
  if not Result then Exit;

  if NewParent.FindBehavior(TCastleBillboard) <> nil then
  begin
    ReasonWhyCannot := 'Only one TCastleBillboard behavior can be added to a given TCastleTransform';
    Result := false;
  end;
end;

Protected procedure Attack; virtual;

Actually do the attack indicated by AnimationAttack and AttackTime and other AttackXxx properties. This happens in the middle of AnimationAttack, at the time see AttackTime.

This can happen only if you defined AnimationAttack (it is <> '').

The default implementation here performs a short range attack, if enemy is still within reach (AttackMaxDistance; even if it was within reach at the start of stateAttack state, the enemy could step back, so we need to check AttackMaxDistance again). The damage and knockback are defined by AttackDamage.

Protected procedure FireMissile; virtual;

Actually do the attack indicated by AnimationFireMissile and FireMissileTime and other FireMissileXxx properties. This happens in the middle of AnimationFireMissile, at the time FireMissileTime.

This can happen only if you defined AnimationFireMissile (it is <> '').

The default implementation here creates a new missile using FireMissileFactory, if FireMissileFactory is not Nil.

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;

This item has no description. Showing description inherited from TCastleBehavior.Update.

Continuously occuring event, for various tasks.

Properties

Public property State: TState read FState default stateIdle;

Current state of the creature, automatically changing.

Public property LifeTime: TFloatTime read FLifeTime;

Life, in seconds.

Published property Enemy: TCastleLiving read FEnemy write SetEnemy;

Enemy that is being chased and attacked by this creature. May be Nil, which means that the creature is not chasing anybody.

Published property SoundAttackHit: TCastleSound read FSoundAttackHit write SetSoundAttackHit;

Sound played when short-range attack hits.

Published property SoundAttackStart: TCastleSound read FSoundAttackStart write SetSoundAttackStart;

Played at the start of attack animation, that is when entering stateAttack state. To play a sound when the actual hit happens (at AttackTime) see SoundAttackHit.

This is a sound name from sound repository (see https://castle-engine.io/manual_sound.php). None by default.

Published property AnimationIdle: String read FAnimationIdle write FAnimationIdle stored AnimationIdleStored nodefault;

An animation of being idle (standing / floating in place). Will be played in a loop.

Published property AnimationMove: String read FAnimationMove write FAnimationMove stored AnimationMoveStored nodefault;

Animation of moving, will be played in a loop.

Published property AnimationAttack: String read FAnimationAttack write FAnimationAttack stored AnimationAttackStored nodefault;

An animation of short-range attacking. Optional, it may be '' if creature doesn't make short-range attack.

Published property AnimationFireMissile: String read FAnimationFireMissile write FAnimationFireMissile stored AnimationFireMissileStored nodefault;

Firing missile animation. Optional, it may be '' if creature doesn't fire missiles.

You can always override TCastleMoveAttack.FireMissile to do pretty much anything you want, and this way treat this as an "alternate attack", not necessarily firing a missile. It's not really required to actually fire a missile — it's only what happens at the default TCastleMoveAttack.FireMissile implementation.

Published property AnimationDie: String read FAnimationDie write FAnimationDie stored AnimationDieStored nodefault;

An animation of dying.

Dying animation is not displayed in a loop, after it runs it's duration we constantly show the final frame. Unless you set RemoveDead to True, then the dead creature will be completely removed from the level.

Published property AnimationDieBack: String read FAnimationDieBack write FAnimationDieBack stored AnimationDieBackStored nodefault;

Alternative optional (may be '') dying animation, used when the creature is killed by hitting it in the back. This may be useful if you want your creature to fall face-down when killed from the back or face-up when killed from the front. If this is defined, then AnimationDie is only used when creature is killed by hitting it from the front. The direction of last hit is taken from LastHurtDirection.

Published property AnimationHurt: String read FAnimationHurt write FAnimationHurt stored AnimationHurtStored nodefault;

Animation when the creature will be hurt.

Published property AttackMinDelay: Single read FAttackMinDelay write FAttackMinDelay default DefaultAttackMinDelay;

Minimum delay between one attack and the other, in seconds. Note that the duration of AnimationAttack also limits how often creature can do an attack (so e.g. setting this to 0.0 doesn't mean that creature can constantly attack, if AnimationAttack takes 1 second then at least this 1 second will have to pass between actual attack hits).

Published property AttackMaxDistance: Single read FAttackMaxDistance write FAttackMaxDistance default DefaultAttackMaxDistance;

Maximum distance between enemy and creature to allow creature to start attack. The distance is measured between enemy (see TCastleMoveAttack.Enemy) and current creature Middle (see TCastleTransform.Middle) points.

Published property AttackTime: Single read FAttackTime write FAttackTime default DefaultAttackTime;

The time point within AnimationAttack at which the short-range attack happens. When exactly happens depends on the virtual TCastleMoveAttack.Attack method implementation, in the base TCastleMoveAttack it is a short-range attack.

Published property AttackMaxAngle: Single read FAttackMaxAngle write FAttackMaxAngle default DefaultAttackMaxAngle;

Since most of the creatures will have their weapon on their front (teeth, shooting hands, claws, whatever), they can attack enemy only when they are facing the enemy.

More precisely, the attack is allowed to start only when the angle between current creature Direction and the vector from creature's Middle to the enemy's Middle (see TCastleTransform.Middle) is <= AttackMaxAngle.

This is in radians.

Published property AttackDamage: TCastleDamage read FAttackDamage;

Attack damage. Used by the creatures that do short-range attack (when AnimationAttack is set).

Published property FireMissileTime: Single read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime;

The time (in seconds) since the AnimationFireMissile start when we actually spawn a missile. By default zero, which means that we spawn the missile right when AnimationFireMissile starts. Must be < than the AnimationFireMissile duration, otherwise we will never reach tthis time and missile will never be fired.

Published property FireMissileMinDelay: Single read FFireMissileMinDelay write FFireMissileMinDelay default DefaultFireMissileMinDelay;

Minimum delay (in seconds) between firing of the missiles. The missile will not be fired if a previous missile was fired within last FireMissileMinDelay seconds. (Even if all other conditions for firing the missile are satisfied.)

Published property FireMissileMaxDistance: Single read FFireMissileMaxDistance write FFireMissileMaxDistance default DefaultFireMissileMaxDistance;

Maximum distance to the enemy to make firing missiles sensible. The creature will only fire the missile if enemy is within this distance. The creature will also try to shorten distance to the enemy, to get within this distance.

Published property FireMissileMaxAngle: Single read FFireMissileMaxAngle write FFireMissileMaxAngle default DefaultFireMissileMaxAngle;

Maximum angle (in radians) between current direction and the direction toward enemy to make firing missiles sensible. The creature will only fire the missile if enemy is within a cone of this angle.

Published property FireMissileHeight: Single read FFireMissileHeight write FFireMissileHeight default DefaultFireMissileHeight;

Height (between Position and Middle, usually: legs and eyes) of the fired missile (see FireMissileFactory).

Published property MoveSpeed: Single read FMoveSpeed write FMoveSpeed default DefaultMoveSpeed;

The moving speed: how much Direction vector will be scaled when moving in csWalk.

Published property RunAwayLife: Single read FRunAwayLife write FRunAwayLife default DefaultRunAwayLife;

Portion of life and distance when the creature decides it's best to run away from the enemy. RunAwayLife is expressed as a fraction of MaxLife. We run if our Life <= MaxLife * RunAwayLife and the distance to the (last seen) enemy is < RunAwayDistance. Set RunAwayLife = 1 to make the creature always try to keep a safe distance from the enemy.

Published property RunAwayDistance: Single read FRunAwayDistance write FRunAwayDistance default DefaultRunAwayDistance;

This item has no description.

Published property PreferredDistance: Single read FPreferredDistance write FPreferredDistance default DefaultPreferredDistance;

The preferred distance between enemy and the creature. The creature will try to walk closer to the enemy if the distance is larger. (If you want to make the creature to also walk father from the enemy when necessary, then set RunAwayLife and RunAwayDistance.)

This should be <= AttackMaxDistance or FireMissileMaxDistance, if you hope to actually perform a short-range or firing missile attack. The creature can attack enemy from AttackMaxDistance or fire missile from FireMissileMaxDistance, but it will walk closer to the enemy if possible — until the distance is PreferredDistance.

Published property RandomMoveDistance: Single read FRandomMoveDistance write FRandomMoveDistance default DefaultRandomMoveDistance;

Distance to point to move to, when creature wanders aimlessly unable to reach the target, but also wanting to move somewhere.

Published property MaxHeightAcceptableToFall: Single read FMaxHeightAcceptableToFall write FMaxHeightAcceptableToFall default DefaultMaxHeightAcceptableToFall;

When considering possible movement, creature is OK to fall down from this height. It should be small enough to not let creature to jump into chasms, but also large enough to enable creature to get down e.g. stairs.

Published property VisibilityAngle: Single read FVisibilityAngle write FVisibilityAngle default DefaultVisibilityAngle;

Creature sees other things (like enemies) only within a cone of this angle. This way, the creature only looks forward, and you can sneak upon a creature from the back. Simply set this to >= 2 * Pi to remove this limit.

Note that the creature also becomes aware of the enemy when it is hurt by a direct attack, regardless of VisibilityAngle. This way if you sneak and attack a creature from the back, it will turn around and fight you.

Creature can also smell others, see SmellDistance.

Published property SmellDistance: Single read FSmellDistance write FSmellDistance default DefaultSmellDistance;

Creature smells other things (like enemies) within a sphere of this radius. This allows to detect enemy regardless of which direction the creature is facing, regardless of whether there is a line of sight to the enemy, regardless if enemy is moving.

This is quite powerful ability to detect enemies, if you set this to something large (by default it's zero). Detecting enemies allows to more accurately/faster attack them and/or run away from them.

Note: If you want the creature to nicely run from behind the corner, be sure to setup good sectors/waypoints in your level.

Published property RemoveDead: Boolean read FRemoveDead write FRemoveDead default DefaultRemoveDead;

Should dead creature instances be automatically freed and thus removed from the viewport. The default False means that corpses lie in the world forever (or until you manually remove them).


Generated by PasDoc 0.16.0-snapshot.