Castle Game Engine: CastleCreatures: Class TCreatureResource

# Class TCreatureResource
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleCreatures ## Declaration `type TCreatureResource = class(T3DResource)` ## Description Basic abstract resource used by all creatures. Basic creature can walk or fly, has life and can be hurt, can fall down because of gravity and such. A "resource" is an information shared by all creatures of given type, for example you can have two instances of `TCreatureResource`: Werewolf and Knight. Actually, they would have to be instances of one of the `TCreatureResource` descendants, like TWalkAttackCreatureResource, as `TCreatureResource` is abstract. Using them you can create and place on your your level milions of actual werewolves and knights (for example instances of TWalkAttackCreature). Every werewolf on the level will have potentially different life and state (attacking, walking), but all werewolves will share the same resource, so e.g. all werewolves will use the same dying animation (TWalkAttackCreatureResource.DieAnimation) and dying sound (TCreatureResource.SoundDie). Note that some of the information stored in resource is only used to initialize new creatures and can be changed later during creature life, for example TCreatureResource.DefaultMaxLife and TCreatureResource.Flying. ## Hierarchy TObject T3DResource TCreatureResource ## Overview ### Fields
| `internal const DefaultDefaultMaxLife = 100.0;`
| `internal const DefaultFlying = false;`
| `internal const DefaultKnockBackDistance = 4.0;`
| `internal const DefaultSoundDieTiedToCreature = true;`
| `internal const DefaultAttackDamageConst = 0.0;`
| `internal const DefaultAttackDamageRandom = 0.0;`
| `internal const DefaultAttackKnockbackDistance = 0.0;`
### Methods
| `function RadiusCalculate(const GravityUp: TVector3Single): Single; virtual;`
| `procedure PrepareCore(const BaseLights: TAbstractLightInstancesList; const GravityUp: TVector3Single; const DoProgress: boolean); override;`
| `function FlexibleUp: boolean; virtual;`
| `constructor Create(const AName: string); override;`
| `function Radius: Single;`
| `function CreateCreature(World: T3DWorld; const APosition, ADirection: TVector3Single; const MaxLife: Single): TCreature; virtual; overload;`
| `function CreateCreature(World: T3DWorld; const APosition, ADirection: TVector3Single): TCreature; overload;`
| `procedure InstantiatePlaceholder(World: T3DWorld; const APosition, ADirection: TVector3Single; const NumberPresent: boolean; const Number: Int64); override;`
| `function CreatureClass: TCreatureClass; virtual; abstract;`
| `procedure LoadFromFile(ResourceConfig: TCastleConfig); override;`
### Properties
| `property Flying: boolean read FFlying write FFlying default DefaultFlying;`
| `property SoundSuddenPain: TSoundType read FSoundSuddenPain write FSoundSuddenPain default stNone;`
| `property SoundDie: TSoundType read FSoundDie write FSoundDie default stNone;`
| `property SoundDieTiedToCreature: boolean read FSoundDieTiedToCreature write FSoundDieTiedToCreature default DefaultSoundDieTiedToCreature;`
| `property DefaultMaxLife: Single read FDefaultMaxLife write FDefaultMaxLife default DefaultDefaultMaxLife;`
| `property KnockBackDistance: Single read FKnockBackDistance write FKnockBackDistance default DefaultKnockBackDistance;`
| `property KnockBackSpeed: Single read FKnockBackSpeed write FKnockBackSpeed default T3DAlive.DefaultKnockBackSpeed;`
| `property AttackDamageConst: Single read FAttackDamageConst write FAttackDamageConst default DefaultAttackDamageConst;`
| `property AttackDamageRandom: Single read FAttackDamageRandom write FAttackDamageRandom default DefaultAttackDamageRandom;`
| `property AttackKnockbackDistance: Single read FAttackKnockbackDistance write FAttackKnockbackDistance default DefaultAttackKnockbackDistance;`
| `property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default T3DCustomTransform.DefaultMiddleHeight;`
| `property FallMinHeightToSound: Single read FFallMinHeightToSound write FFallMinHeightToSound default DefaultCreatureFallMinHeightToSound;`
| `property FallMinHeightToDamage: Single read FFallMinHeightToDamage write FFallMinHeightToDamage default DefaultFallMinHeightToDamage;`
| `property FallDamageScaleMin: Single read FFallDamageScaleMin write FFallDamageScaleMin default DefaultFallDamageScaleMin;`
| `property FallDamageScaleMax: Single read FFallDamageScaleMax write FFallDamageScaleMax default DefaultFallDamageScaleMax;`
| `property FallSound: TSoundType read FFallSound write FFallSound;`
## Description ### Fields
| `internal const DefaultDefaultMaxLife = 100.0;`
Default value for TCreatureResource.DefaultMaxLife. Yes, it's not a typo, this identifier starts with "DefaultDefault".
| `internal const DefaultFlying = false;`
| `internal const DefaultKnockBackDistance = 4.0;`
| `internal const DefaultSoundDieTiedToCreature = true;`
| `internal const DefaultAttackDamageConst = 0.0;`
| `internal const DefaultAttackDamageRandom = 0.0;`
| `internal const DefaultAttackKnockbackDistance = 0.0;`
### Methods
| `function RadiusCalculate(const GravityUp: TVector3Single): Single; virtual;`
| `procedure PrepareCore(const BaseLights: TAbstractLightInstancesList; const GravityUp: TVector3Single; const DoProgress: boolean); override;`
| `function FlexibleUp: boolean; virtual;`
Can the "up" vector be skewed, that is: not equal to gravity up vector. This is used when creating creature in CreateCreature. The default implementation here returns `True`, which allows creature model to point slightly upward/downward. Override this to return `False` if given creature kind for some reason cannot have up vector different. For example, TWalkAttackCreature AI assumes that the non-flying creature is always standing up. For now, non-flying TWalkAttackCreature cannot "stand up" before walking, in case it's up vector gets skewed.
| `constructor Create(const AName: string); override;`
| `function Radius: Single;`
Sphere radius for collision detection for alive creatures. Must be something <> 0 for collision detection. You can define it in the creature resource.xml file, by setting radius="xxx" attribute on the root <resource> element. If it's not defined (or zero) in resource.xml file, then we use automatically calculated radius using RadiusCalculate, that is adjusted to the bounding box of the animation. Note that this radius is not used at all when creature is dead, as dead creatures usually have wildly different boxes (tall humanoid creature probably has a flat bounding box when it's dead lying on the ground), so trying to use (the same) radius would only cause problems. Using sphere collision is also not necessary for dead creatures. See T3D.Sphere for more discussion about when the sphere is a useful bounding volume. The sphere center is the Middle point ("eye position") of the given creature. If the creature may be affected by gravity then make sure radius is < than PreferredHeight of the creature, see T3D.PreferredHeight, otherwise creature may get stuck into ground. In short, if you use the default implementations, PreferredHeight is by default MiddleHeight (default 0.5) * bounding box height. Your radius must be smaller for all possible bounding box heights when the creature is not dead.
| `function CreateCreature(World: T3DWorld; const APosition, ADirection: TVector3Single; const MaxLife: Single): TCreature; virtual; overload;`
Create the TCreature instance using this resource. Uses TCreature descendant that can best cooperate with this resource, e.g. if this resource has settings for short-range fight, then the TCreature instance will be able to short-range fight. The creature is added to the World, and it's owned by World. This is the only way to create TCreature instances. ADirection passed here is normalized, and then used as initial TCreature.Direction value.
| `function CreateCreature(World: T3DWorld; const APosition, ADirection: TVector3Single): TCreature; overload;`
| `procedure InstantiatePlaceholder(World: T3DWorld; const APosition, ADirection: TVector3Single; const NumberPresent: boolean; const Number: Int64); override;`
Instantiate creature placeholder, by calling CreateCreature.
| `function CreatureClass: TCreatureClass; virtual; abstract;`
| `procedure LoadFromFile(ResourceConfig: TCastleConfig); override;`
### Properties
| `property Flying: boolean read FFlying write FFlying default DefaultFlying;`
Flying creatures are not affected by gravity and (in case of TWalkAttackCreatureResource) their move direction is free. For all creatures, TCreature.Gravity (inherited from T3D.Gravity) is set to `"not Flying"` at creation. (Except TMissileCreatureResource, that has special approach to gravity, see TMissileCreatureResource.DirectionFallSpeed.) For TWalkAttackCreatureResource, additionally Flying allows to move freely, while non-flying creatures are constrained to move (and think about moving) only horizontally. You can always change the Gravity property of a particular creature during it's lifetime, so a creature may start/stop flying during game. For example, this is how you can let your creatures to use jetpack and such. Be careful about creature Radius and MiddleHeight properties in this case, make sure that the values (explicitly set or automatically calculated) are suitable for both flying and non-flying states.
| `property SoundSuddenPain: TSoundType read FSoundSuddenPain write FSoundSuddenPain default stNone;`
| `property SoundDie: TSoundType read FSoundDie write FSoundDie default stNone;`
| `property SoundDieTiedToCreature: boolean read FSoundDieTiedToCreature write FSoundDieTiedToCreature default DefaultSoundDieTiedToCreature;`
See TCreature.Sound3d TiedToCreature parameter docs. You can set this to false if you want SoundDie to last even after the creature object was destroyed.
| `property DefaultMaxLife: Single read FDefaultMaxLife write FDefaultMaxLife default DefaultDefaultMaxLife;`
The default MaxLife for creatures of this resource. Note that you can always override it for a particular creature instance. You can use a special creature placeholder with a specific starting life value (see TGameSceneManager.LoadLevel for placeholders docs, and see http://castle-engine.sourceforge.net/castle-development.php about the creature placeholders). Or you can use CreateCreature overloaded version that takes extra MaxLife parameter. So this is only a "suggested" default for MaxLife of this creature.
| `property KnockBackDistance: Single read FKnockBackDistance write FKnockBackDistance default DefaultKnockBackDistance;`
Distance this creature is knocked back when hurt (should reflect the creature weight, how easy it is to push this creature). Will always be multiplied by the knocking distance of the weapon that caused the push (which should reflect the force of the weapon blow), see TItemWeaponResource.AttackKnockbackDistance. Only for TWalkAttackCreature, the final distance the creature is knocked back is capped by the time of the HurtAnimation (HurtAnimation.Duration). When the hurt animation ends, the knockback effect always ends, even if the distance (creature * weapon) indicates it should be knocked further. Otherwise knockback would work on standing creature, which could look bad. This may be changed some day.
| `property KnockBackSpeed: Single read FKnockBackSpeed write FKnockBackSpeed default T3DAlive.DefaultKnockBackSpeed;`
See T3DAlive.KnockBackSpeed.
| `property AttackDamageConst: Single read FAttackDamageConst write FAttackDamageConst default DefaultAttackDamageConst;`
Default attack damage and knockback. Used only by the creatures that actually do some kind of direct attack. For example it is used for short-range attack by TWalkAttackCreatureResource (if TWalkAttackCreatureResource.AttackAnimation defined) and for hit of TMissileCreatureResource. All these values must be >= 0. AttackKnockbackDistance = 0 means no knockback.
| `property AttackDamageRandom: Single read FAttackDamageRandom write FAttackDamageRandom default DefaultAttackDamageRandom;`
| `property AttackKnockbackDistance: Single read FAttackKnockbackDistance write FAttackKnockbackDistance default DefaultAttackKnockbackDistance;`
| `property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default T3DCustomTransform.DefaultMiddleHeight;`
Height of the eyes of the creature, used for various collision detection routines. See T3DCustomTransform.MiddleHeight for a precise documentation. Game developers can use the RenderDebug3D variable to easily visualize the bounding sphere (and other things) around resources. The bounding sphere is centered around the point derived from `MiddleHeight` setting and with given (or automatically calculated) Radius.
| `property FallMinHeightToSound: Single read FFallMinHeightToSound write FFallMinHeightToSound default DefaultCreatureFallMinHeightToSound;`
| `property FallMinHeightToDamage: Single read FFallMinHeightToDamage write FFallMinHeightToDamage default DefaultFallMinHeightToDamage;`
| `property FallDamageScaleMin: Single read FFallDamageScaleMin write FFallDamageScaleMin default DefaultFallDamageScaleMin;`
| `property FallDamageScaleMax: Single read FFallDamageScaleMax write FFallDamageScaleMax default DefaultFallDamageScaleMax;`
| `property FallSound: TSoundType read FFallSound write FFallSound;`
Sound when falling. The default is the sound named 'creature_fall'.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:09