Castle Game Engine: CastleCreatures: Class TWalkAttackCreatureResource

# Class TWalkAttackCreatureResource
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleCreatures ## 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 TObject T3DResource TCreatureResource TWalkAttackCreatureResource ## Overview ### Fields
| `internal const DefaultMoveSpeed = 10.0;`
| `internal const DefaultMinLifeLossToHurt = 0.0;`
| `internal const DefaultChanceToHurt = 1.0;`
| `internal const DefaultMaxHeightAcceptableToFall = 1.5;`
| `internal const DefaultRandomWalkDistance = 10.0;`
| `internal const DefaultRemoveDead = false;`
| `internal const DefaultPreferredDistance = 2.0;`
| `internal const DefaultRunAwayLife = 0.3;`
| `internal const DefaultRunAwayDistance = 10.0;`
| `internal const DefaultVisibilityAngle = Pi * 2 / 3;`
| `internal const DefaultSmellDistance = 0.0;`
| `internal const DefaultAttackTime = 0.0;`
| `internal const DefaultAttackMinDelay = 2.0;`
| `internal const DefaultAttackMaxDistance = DefaultPreferredDistance;`
| `internal const DefaultAttackMaxAngle = Pi / 6;`
| `internal const DefaultFireMissileTime = 0.0;`
| `internal const DefaultFireMissileMinDelay = DefaultAttackMinDelay;`
| `internal const DefaultFireMissileMaxDistance = 30.0;`
| `internal const DefaultFireMissileMaxAngle = DefaultAttackMaxAngle;`
| `internal const DefaultFireMissileHeight = 0.5;`
### Methods
| `function FlexibleUp: boolean; override;`
| `constructor Create(const AName: string); override;`
| `procedure LoadFromFile(ResourceConfig: TCastleConfig); override;`
| `function CreatureClass: TCreatureClass; override;`
### Properties
| `property IdleAnimation: T3DResourceAnimation read FIdleAnimation;`
| `property IdleToWalkAnimation: T3DResourceAnimation read FIdleToWalkAnimation;`
| `property WalkAnimation: T3DResourceAnimation read FWalkAnimation;`
| `property AttackAnimation: T3DResourceAnimation read FAttackAnimation;`
| `property FireMissileAnimation: T3DResourceAnimation read FFireMissileAnimation;`
| `property DieAnimation: T3DResourceAnimation read FDieAnimation;`
| `property DieBackAnimation: T3DResourceAnimation read FDieBackAnimation;`
| `property HurtAnimation: T3DResourceAnimation read FHurtAnimation;`
| `property MoveSpeed: Single read FMoveSpeed write FMoveSpeed default DefaultMoveSpeed;`
| `property PreferredDistance: Single read FPreferredDistance write FPreferredDistance default DefaultPreferredDistance;`
| `property AttackMinDelay: Single read FAttackMinDelay write FAttackMinDelay default DefaultAttackMinDelay;`
| `property AttackMaxDistance: Single read FAttackMaxDistance write FAttackMaxDistance default DefaultAttackMaxDistance;`
| `property AttackTime: Single read FAttackTime write FAttackTime default DefaultAttackTime;`
| `property AttackMaxAngle: Single read FAttackMaxAngle write FAttackMaxAngle default DefaultAttackMaxAngle;`
| `property AttackSoundHit: TSoundType read FAttackSoundHit write FAttackSoundHit default stNone;`
| `property AttackSoundStart: TSoundType read FAttackSoundStart write FAttackSoundStart default stNone;`
| `property FireMissileTime: Single read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime;`
| `property FireMissileMinDelay: Single read FFireMissileMinDelay write FFireMissileMinDelay default DefaultFireMissileMinDelay;`
| `property FireMissileMaxDistance: Single read FFireMissileMaxDistance write FFireMissileMaxDistance default DefaultFireMissileMaxDistance;`
| `property FireMissileMaxAngle: Single read FFireMissileMaxAngle write FFireMissileMaxAngle default DefaultFireMissileMaxAngle;`
| `property FireMissileName: string read FFireMissileName write FFireMissileName;`
| `property FireMissileHeight: Single read FFireMissileHeight write FFireMissileHeight default DefaultFireMissileHeight;`
| `property FireMissileSound: TSoundType read FFireMissileSound write FFireMissileSound default stNone;`
| `property RunAwayLife: Single read FRunAwayLife write FRunAwayLife default DefaultRunAwayLife;`
| `property RunAwayDistance: Single read FRunAwayDistance write FRunAwayDistance default DefaultRunAwayDistance;`
| `property VisibilityAngle: Single read FVisibilityAngle write FVisibilityAngle default DefaultVisibilityAngle;`
| `property SmellDistance: Single read FSmellDistance write FSmellDistance default DefaultSmellDistance;`
| `property MinLifeLossToHurt: Single read FMinLifeLossToHurt write FMinLifeLossToHurt default DefaultMinLifeLossToHurt;`
| `property ChanceToHurt: Single read FChanceToHurt write FChanceToHurt default DefaultChanceToHurt;`
| `property MaxHeightAcceptableToFall: Single read FMaxHeightAcceptableToFall write FMaxHeightAcceptableToFall default DefaultMaxHeightAcceptableToFall;`
| `property RandomWalkDistance: Single read FRandomWalkDistance write FRandomWalkDistance default DefaultRandomWalkDistance;`
| `property RemoveDead: boolean read FRemoveDead write FRemoveDead default DefaultRemoveDead;`
## Description ### Fields
| `internal const DefaultMoveSpeed = 10.0;`
| `internal const DefaultMinLifeLossToHurt = 0.0;`
| `internal const DefaultChanceToHurt = 1.0;`
| `internal const DefaultMaxHeightAcceptableToFall = 1.5;`
| `internal const DefaultRandomWalkDistance = 10.0;`
| `internal const DefaultRemoveDead = false;`
| `internal const DefaultPreferredDistance = 2.0;`
| `internal const DefaultRunAwayLife = 0.3;`
| `internal const DefaultRunAwayDistance = 10.0;`
| `internal const DefaultVisibilityAngle = Pi * 2 / 3;`
120 degrees.
| `internal const DefaultSmellDistance = 0.0;`
| `internal const DefaultAttackTime = 0.0;`
| `internal const DefaultAttackMinDelay = 2.0;`
| `internal const DefaultAttackMaxDistance = DefaultPreferredDistance;`
| `internal const DefaultAttackMaxAngle = Pi / 6;`
| `internal const DefaultFireMissileTime = 0.0;`
| `internal const DefaultFireMissileMinDelay = DefaultAttackMinDelay;`
| `internal const DefaultFireMissileMaxDistance = 30.0;`
| `internal const DefaultFireMissileMaxAngle = DefaultAttackMaxAngle;`
| `internal const DefaultFireMissileHeight = 0.5;`
### Methods
| `function FlexibleUp: boolean; override;`
| `constructor Create(const AName: string); override;`
| `procedure LoadFromFile(ResourceConfig: TCastleConfig); override;`
| `function CreatureClass: TCreatureClass; override;`
### Properties
| `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.
| `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.
| `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.
| `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.
| `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.
| `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.
| `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.
| `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.
| `property MoveSpeed: Single read FMoveSpeed write FMoveSpeed default DefaultMoveSpeed;`
The moving speed: how much Direction vector will be scaled when moving in csWalk.
| `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`.
| `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).
| `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 T3D.Middle) points.
| `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.
| `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.
| `property AttackSoundHit: TSoundType read FAttackSoundHit write FAttackSoundHit default stNone;`
Sound played when short-range attack hits.
| `property AttackSoundStart: TSoundType read FAttackSoundStart write FAttackSoundStart default stNone;`
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.
| `property FireMissileTime: Single read FFireMissileTime write FFireMissileTime default DefaultFireMissileTime;`
| `property FireMissileMinDelay: Single read FFireMissileMinDelay write FFireMissileMinDelay default DefaultFireMissileMinDelay;`
| `property FireMissileMaxDistance: Single read FFireMissileMaxDistance write FFireMissileMaxDistance default DefaultFireMissileMaxDistance;`
| `property FireMissileMaxAngle: Single read FFireMissileMaxAngle write FFireMissileMaxAngle default DefaultFireMissileMaxAngle;`
| `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.
| `property FireMissileHeight: Single read FFireMissileHeight write FFireMissileHeight default DefaultFireMissileHeight;`
Height (between Position and Middle, usually: legs and eyes) of the fired missile (see FireMissileName).
| `property FireMissileSound: TSoundType read FFireMissileSound write FFireMissileSound default stNone;`
Sound played when missile is fired, see FireMissileName.
| `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.
| `property RunAwayDistance: Single read FRunAwayDistance write FRunAwayDistance default DefaultRunAwayDistance;`
| `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.
| `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.
| `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.
| `property ChanceToHurt: Single read FChanceToHurt write FChanceToHurt default DefaultChanceToHurt;`
See MinLifeLossToHurt.
| `property MaxHeightAcceptableToFall: Single read FMaxHeightAcceptableToFall write FMaxHeightAcceptableToFall default DefaultMaxHeightAcceptableToFall;`
| `property RandomWalkDistance: Single read FRandomWalkDistance write FRandomWalkDistance default DefaultRandomWalkDistance;`
| `property RemoveDead: boolean read FRemoveDead write FRemoveDead default DefaultRemoveDead;`
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:09