Class TWalkAttackCreatureResource

Unit

Declaration

type TWalkAttackCreatureResource = class(TCreatureResource)

Description

Creature with smart walking and attacking intelligence. May stand still (idle), walk, attack, fire missiles, and die.

Tracks the enemy (remembers last seen enemy 3D position, walks/flies to it, possibly through sectors/waypoints — so it can pass through narrow doors in a labyrinth or walk over a narrow bridge). Attacks the enemy from the right distance (a short-range attack) and/or shoots a missile (adds a missile to the 3D world). Runs away from the enemy (when he's too close and/or our health is low).

There are a lot of settings to achieve particular behavior, e.g. cowardly/brave, offensive/defensive, melee/ranged, etc.

Hierarchy

Overview

Fields

Public nested const DefaultMoveSpeed = 10.0;
Public nested const DefaultMinLifeLossToHurt = 0.0;
Public nested const DefaultChanceToHurt = 1.0;
Public nested const DefaultMaxHeightAcceptableToFall = 1.5;
Public nested const DefaultRandomWalkDistance = 10.0;
Public nested const DefaultRemoveDead = false;
Public nested const DefaultPreferredDistance = 2.0;
Public nested const DefaultRunAwayLife = 0.3;
Public nested const DefaultRunAwayDistance = 10.0;
Public nested const DefaultVisibilityAngle = Pi * 2 / 3;
Public nested const DefaultSmellDistance = 0.0;
Public nested const DefaultAttackTime = 0.0;
Public nested const DefaultAttackMinDelay = 2.0;
Public nested const DefaultAttackMaxDistance = DefaultPreferredDistance;
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;

Methods

Protected function FlexibleUp: boolean; override;
Public constructor Create(const AName: string); override;
Public procedure LoadFromFile(ResourceConfig: TCastleConfig); override;
Public function CreatureClass: TCreatureClass; override;

Properties

Public property IdleAnimation: T3DResourceAnimation read FIdleAnimation;
Public property IdleToWalkAnimation: T3DResourceAnimation read FIdleToWalkAnimation;
Public property WalkAnimation: T3DResourceAnimation read FWalkAnimation;
Public property AttackAnimation: T3DResourceAnimation read FAttackAnimation;
Public property FireMissileAnimation: T3DResourceAnimation read FFireMissileAnimation;
Public property DieAnimation: T3DResourceAnimation read FDieAnimation;
Public property DieBackAnimation: T3DResourceAnimation read FDieBackAnimation;
Public property HurtAnimation: T3DResourceAnimation read FHurtAnimation;
Public property MoveSpeed: Single read FMoveSpeed write FMoveSpeed default DefaultMoveSpeed;
Public property PreferredDistance: Single read FPreferredDistance write FPreferredDistance default DefaultPreferredDistance;
Public property AttackMinDelay: Single read FAttackMinDelay write FAttackMinDelay default DefaultAttackMinDelay;
Public property AttackMaxDistance: Single read FAttackMaxDistance write FAttackMaxDistance default DefaultAttackMaxDistance;
Public property AttackTime: Single read FAttackTime write FAttackTime default DefaultAttackTime;
Public property AttackMaxAngle: Single read FAttackMaxAngle write FAttackMaxAngle default DefaultAttackMaxAngle;
Public property AttackSoundHit: TSoundType read FAttackSoundHit write FAttackSoundHit;
Public property AttackSoundStart: TSoundType read FAttackSoundStart write FAttackSoundStart;
Public property FireMissileTime: Single read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime;
Public property FireMissileMinDelay: Single read FFireMissileMinDelay write FFireMissileMinDelay default DefaultFireMissileMinDelay;
Public property FireMissileMaxDistance: Single read FFireMissileMaxDistance write FFireMissileMaxDistance default DefaultFireMissileMaxDistance;
Public property FireMissileMaxAngle: Single read FFireMissileMaxAngle write FFireMissileMaxAngle default DefaultFireMissileMaxAngle;
Public property FireMissileName: string read FFireMissileName write FFireMissileName;
Public property FireMissileHeight: Single read FFireMissileHeight write FFireMissileHeight default DefaultFireMissileHeight;
Public property FireMissileSound: TSoundType read FFireMissileSound write FFireMissileSound;
Public property RunAwayLife: Single read FRunAwayLife write FRunAwayLife default DefaultRunAwayLife;
Public property RunAwayDistance: Single read FRunAwayDistance write FRunAwayDistance default DefaultRunAwayDistance;
Public property VisibilityAngle: Single read FVisibilityAngle write FVisibilityAngle default DefaultVisibilityAngle;
Public property SmellDistance: Single read FSmellDistance write FSmellDistance default DefaultSmellDistance;
Public property MinLifeLossToHurt: Single read FMinLifeLossToHurt write FMinLifeLossToHurt default DefaultMinLifeLossToHurt;
Public property ChanceToHurt: Single read FChanceToHurt write FChanceToHurt default DefaultChanceToHurt;
Public property MaxHeightAcceptableToFall: Single read FMaxHeightAcceptableToFall write FMaxHeightAcceptableToFall default DefaultMaxHeightAcceptableToFall;
Public property RandomWalkDistance: Single read FRandomWalkDistance write FRandomWalkDistance default DefaultRandomWalkDistance;
Public property RemoveDead: boolean read FRemoveDead write FRemoveDead default DefaultRemoveDead;

Description

Fields

Public nested const DefaultMoveSpeed = 10.0;
 
Public nested const DefaultMinLifeLossToHurt = 0.0;
 
Public nested const DefaultChanceToHurt = 1.0;
 
Public nested const DefaultMaxHeightAcceptableToFall = 1.5;
 
Public nested const DefaultRandomWalkDistance = 10.0;
 
Public nested const DefaultRemoveDead = false;
 
Public nested const DefaultPreferredDistance = 2.0;
 
Public nested const DefaultRunAwayLife = 0.3;
 
Public nested const DefaultRunAwayDistance = 10.0;
 
Public nested const DefaultVisibilityAngle = Pi * 2 / 3;

120 degrees.

Public nested const DefaultSmellDistance = 0.0;
 
Public nested const DefaultAttackTime = 0.0;
 
Public nested const DefaultAttackMinDelay = 2.0;
 
Public nested const DefaultAttackMaxDistance = DefaultPreferredDistance;
 
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;
 

Methods

Protected function FlexibleUp: boolean; override;
 
Public constructor Create(const AName: string); override;
 
Public procedure LoadFromFile(ResourceConfig: TCastleConfig); override;
 
Public function CreatureClass: TCreatureClass; override;
 

Properties

Public property IdleAnimation: T3DResourceAnimation read FIdleAnimation;

An animation of standing still (being idle). Will be played in a loop, so for best look make sure that the beginning and end match.

Public property IdleToWalkAnimation: T3DResourceAnimation read FIdleToWalkAnimation;

An animation when creature changes from standing still to walking. Optional.

For best look: It's beginnig should glue with the end of IdleAnimation, it's ending should glue with beginning of WalkAnimation.

Public property WalkAnimation: T3DResourceAnimation read FWalkAnimation;

An animation of walking. Will be played in a loop, so for best look make sure that the beginning and end match.

Public property AttackAnimation: T3DResourceAnimation read FAttackAnimation;

An animation of short-range attacking. Optional.

For best look: Beginning and end of it should roughly glue with (any) frame of WalkAnimation and IdleAnimation.

Design notes: I used to have here property like AttacksWhenWalking for the creature, to indicate whether creature changes state like "csWalk -> csAttack -> csWalk" or "csIdle -> csAttack -> csIdle". But this wasn't good. Intelligent creature sometimes attacks when walking (e.g. if it just made the distance to the enemy closer) or when standing (when the distance was already close enough). And after performing the attack, the creature doesn't need to go back to the original state before the attack.

Public property FireMissileAnimation: T3DResourceAnimation read FFireMissileAnimation;

Firing missile animation. Optional. Similar rules like AttackAnimation, but here the "highlight" is not directly hurting enemy, but firing a new creature (missile).

You can always override TWalkAttackCreature.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 TWalkAttackCreature.FireMissile implementation, and it happens only if FireMissileName is not empty.

Public property DieAnimation: T3DResourceAnimation read FDieAnimation;

An animation of dying.

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

For best look: Beginning should roughly glue with any point of the idle/attack/walk animations.

Public property DieBackAnimation: T3DResourceAnimation read FDieBackAnimation;

An optional 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 DieAnimation is only used when creature is killed by hitting it from the front. The direction of last hit is taken from LastHurtDirection.

For best look: Just like DieAnimation, beginning should roughly glue with any point of the idle/attack/walk animations.

Public property HurtAnimation: T3DResourceAnimation read FHurtAnimation;

Animation when the creature will be hurt. Beginning and end should *more-or-less* look like any point of the idle/attack/walk animations.

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

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

Public 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.

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

Minimum delay between one attack and the other, in seconds. Note that the duration of AttackAnimation 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 AttackAnimation takes 1 second then at least this 1 second will have to pass between actual attack hits).

Public 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 TWalkAttackCreature.Enemy) and current creature Middle (see TCastleTransform.Middle) points.

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

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

Public 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 T3D.Middle) is <= AttackMaxAngle.

This is in radians.

Public property AttackSoundHit: TSoundType read FAttackSoundHit write FAttackSoundHit;

Sound played when short-range attack hits. None (stNone) by default.

Public property AttackSoundStart: TSoundType read FAttackSoundStart write FAttackSoundStart;

Played at the start of attack animation, that is when entering csAttack state. To play a sound when the actual hit happens (at AttackTime) see AttackSoundHit. None (stNone) by default.

Public property FireMissileTime: Single read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime;
 
Public property FireMissileMinDelay: Single read FFireMissileMinDelay write FFireMissileMinDelay default DefaultFireMissileMinDelay;
 
Public property FireMissileMaxDistance: Single read FFireMissileMaxDistance write FFireMissileMaxDistance default DefaultFireMissileMaxDistance;
 
Public property FireMissileMaxAngle: Single read FFireMissileMaxAngle write FFireMissileMaxAngle default DefaultFireMissileMaxAngle;
 
Public property FireMissileName: string read FFireMissileName write FFireMissileName;

Name of the creature to fire as missile, at AttackTime during AttackAnimation. Leave empty to not fire any missile.

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

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

Public property FireMissileSound: TSoundType read FFireMissileSound write FFireMissileSound;

Sound played when missile is fired, see FireMissileName. None (stNone) by default.

Public 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.

Public property RunAwayDistance: Single read FRunAwayDistance write FRunAwayDistance default DefaultRunAwayDistance;
 
Public 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.

Public 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.

Public property MinLifeLossToHurt: Single read FMinLifeLossToHurt write FMinLifeLossToHurt default DefaultMinLifeLossToHurt;

When creature is wounded for more than MaxLife * MinLifeLossToHurt points and moreover Random < ChanceToHurt then creature will change to csHurt state and be knocked back. Changing to csHurt state means that any other state will be interrupted (e.g. enemy can interrupt creature's attack this way if AttackTime > 0).

It's expected that "tougher" creatures will have MinLifeLossToHurt somewhat higher than DefaultMinLifeLossToHurt and ChanceToHurt significantly lower than DefaultChanceToHurt.

Public property ChanceToHurt: Single read FChanceToHurt write FChanceToHurt default DefaultChanceToHurt;

See MinLifeLossToHurt.

Public property MaxHeightAcceptableToFall: Single read FMaxHeightAcceptableToFall write FMaxHeightAcceptableToFall default DefaultMaxHeightAcceptableToFall;
 
Public property RandomWalkDistance: Single read FRandomWalkDistance write FRandomWalkDistance default DefaultRandomWalkDistance;
 
Public property RemoveDead: boolean read FRemoveDead write FRemoveDead default DefaultRemoveDead;
 

Generated by PasDoc 0.15.0.