Class TCreatureResource

Unit

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

Overview

Fields

Public nested const DefaultDefaultMaxLife = 100.0;
Public nested const DefaultFlying = false;
Public nested const DefaultKnockBackDistance = 4.0;
Public nested const DefaultSoundDieTiedToCreature = true;
Public nested const DefaultAttackDamageConst = 0.0;
Public nested const DefaultAttackDamageRandom = 0.0;
Public nested const DefaultAttackKnockbackDistance = 0.0;

Methods

Protected function RadiusCalculate(const GravityUp: TVector3): Single; virtual;
Protected function FlexibleUp: boolean; virtual;
Public constructor Create(const AName: string); override;
Public function CreateCreature( const ALevelProperties: TLevelProperties; const APosition, ADirection: TVector3; const MaxLife: Single): TCreature; virtual; overload;
Public function CreateCreature( const ALevelProperties: TLevelProperties; const APosition, ADirection: TVector3): TCreature; overload;
Public procedure InstantiatePlaceholder( const ALevelProperties: TLevelProperties; const APosition, ADirection: TVector3; const NumberPresent: boolean; const Number: Int64); override;
Public function CreatureClass: TCreatureClass; virtual; abstract;
Public procedure LoadFromFile(ResourceConfig: TCastleConfig); override;
Public function Radius(const GravityUp: TVector3): Single;

Properties

Public property Flying: boolean read FFlying write FFlying default DefaultFlying;
Public property SoundSuddenPain: TSoundType read FSoundSuddenPain write FSoundSuddenPain;
Public property SoundDie: TSoundType read FSoundDie write FSoundDie;
Public property SoundDieTiedToCreature: boolean read FSoundDieTiedToCreature write FSoundDieTiedToCreature default DefaultSoundDieTiedToCreature;
Public property DefaultMaxLife: Single read FDefaultMaxLife write FDefaultMaxLife default DefaultDefaultMaxLife;
Public property KnockBackDistance: Single read FKnockBackDistance write FKnockBackDistance default DefaultKnockBackDistance;
Public property KnockBackSpeed: Single read FKnockBackSpeed write FKnockBackSpeed default TAlive.DefaultKnockBackSpeed;
Public property CollidesWhenDead: boolean read FCollidesWhenDead write FCollidesWhenDead default false;
Public property ScaleMin: Single read FScaleMin write FScaleMin default 1;
Public property ScaleMax: Single read FScaleMax write FScaleMax default 1;
Public property AttackDamageConst: Single read FAttackDamageConst write FAttackDamageConst default DefaultAttackDamageConst;
Public property AttackDamageRandom: Single read FAttackDamageRandom write FAttackDamageRandom default DefaultAttackDamageRandom;
Public property AttackKnockbackDistance: Single read FAttackKnockbackDistance write FAttackKnockbackDistance default DefaultAttackKnockbackDistance;
Public property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default TCastleTransform.DefaultMiddleHeight;
Public property FallMinHeightToSound: Single read FFallMinHeightToSound write FFallMinHeightToSound default DefaultCreatureFallMinHeightToSound;
Public property FallMinHeightToDamage: Single read FFallMinHeightToDamage write FFallMinHeightToDamage default DefaultFallMinHeightToDamage;
Public property FallDamageScaleMin: Single read FFallDamageScaleMin write FFallDamageScaleMin default DefaultFallDamageScaleMin;
Public property FallDamageScaleMax: Single read FFallDamageScaleMax write FFallDamageScaleMax default DefaultFallDamageScaleMax;
Public property FallSound: TSoundType read FFallSound write FFallSound;
Public property RadiusOverride: Single read FRadiusOverride write FRadiusOverride;

Description

Fields

Public nested const DefaultDefaultMaxLife = 100.0;

Default value for TCreatureResource.DefaultMaxLife. Yes, it's not a typo, this identifier starts with "DefaultDefault".

Public nested const DefaultFlying = false;
 
Public nested const DefaultKnockBackDistance = 4.0;
 
Public nested const DefaultSoundDieTiedToCreature = true;
 
Public nested const DefaultAttackDamageConst = 0.0;
 
Public nested const DefaultAttackDamageRandom = 0.0;
 
Public nested const DefaultAttackKnockbackDistance = 0.0;
 

Methods

Protected function RadiusCalculate(const GravityUp: TVector3): Single; virtual;

Sphere radius for collision detection for alive creatures. Must be something <> 0 for collision detection to work. Defining it in the creature resource.xml file (as radius="xxx" attribute on the root <resource> element) overrides the results of this function.

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

Public constructor Create(const AName: string); override;
 
Public function CreateCreature( const ALevelProperties: TLevelProperties; const APosition, ADirection: TVector3; 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 is 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.

Public function CreateCreature( const ALevelProperties: TLevelProperties; const APosition, ADirection: TVector3): TCreature; overload;
 
Public procedure InstantiatePlaceholder( const ALevelProperties: TLevelProperties; const APosition, ADirection: TVector3; const NumberPresent: boolean; const Number: Int64); override;

Instantiate creature placeholder, by calling CreateCreature.

Public function CreatureClass: TCreatureClass; virtual; abstract;
 
Public procedure LoadFromFile(ResourceConfig: TCastleConfig); override;
 
Public function Radius(const GravityUp: TVector3): Single;

Sphere radius for collision detection for alive creatures. Must be something <> 0 for collision detection to work.

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.

This radius is used only for alive creatures, because:

  • It would cause incorrect results on many dead creatures. Dead creatures usually have very different boxes than alive (tall alive humanoid creature probably has a small flat bounding box when it's lying dead on the ground). So the same radius would not work nicely.

  • It is not necessary to use sphere bounding volumes for dead creatures. The main advantage of sphere bounding volumes (over box bounding volumes) is for moving (alive) creatures: sphere better avoids getting stuck into obstacles (because an animation can change the bounding box at any moment).

  • Actually, the results look best when dead creatures don't collide at all.

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

Properties

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

Public property SoundSuddenPain: TSoundType read FSoundSuddenPain write FSoundSuddenPain;
 
Public property SoundDie: TSoundType read FSoundDie write FSoundDie;
 
Public 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.

Public 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 https://castle-engine.io/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.

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

Public property KnockBackSpeed: Single read FKnockBackSpeed write FKnockBackSpeed default TAlive.DefaultKnockBackSpeed;

See TAlive.KnockBackSpeed.

Public property CollidesWhenDead: boolean read FCollidesWhenDead write FCollidesWhenDead default false;

By default dead creatures (corpses) don't collide, this usually looks better.

Public property ScaleMin: Single read FScaleMin write FScaleMin default 1;

Minimum scale when spawning, must be <= ScaleMax. When we spawn a creature, we set it's scale to random number in [ScaleMin, ScaleMax] range. By default both ScaleMin and ScaleMax are 1, resulting in no scaling.

Public property ScaleMax: Single read FScaleMax write FScaleMax default 1;

Maximum scale when spawning, must be >= ScaleMin. When we spawn a creature, we set it's scale to random number in [ScaleMin, ScaleMax] range. By default both ScaleMin and ScaleMax are 1, resulting in no scaling.

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

Public property AttackDamageRandom: Single read FAttackDamageRandom write FAttackDamageRandom default DefaultAttackDamageRandom;
 
Public property AttackKnockbackDistance: Single read FAttackKnockbackDistance write FAttackKnockbackDistance default DefaultAttackKnockbackDistance;
 
Public property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default TCastleTransform.DefaultMiddleHeight;

Height of the eyes of the creature, used for various collision detection routines. See TCastleTransform.MiddleHeight for a precise documentation.

Game developers can use the RenderDebug 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 creature radius (given in resource.xml, or automatically calculated by TCreatureResource.RadiusCalculate).

Public property FallMinHeightToSound: Single read FFallMinHeightToSound write FFallMinHeightToSound default DefaultCreatureFallMinHeightToSound;
 
Public property FallMinHeightToDamage: Single read FFallMinHeightToDamage write FFallMinHeightToDamage default DefaultFallMinHeightToDamage;
 
Public property FallDamageScaleMin: Single read FFallDamageScaleMin write FFallDamageScaleMin default DefaultFallDamageScaleMin;
 
Public property FallDamageScaleMax: Single read FFallDamageScaleMax write FFallDamageScaleMax default DefaultFallDamageScaleMax;
 
Public property FallSound: TSoundType read FFallSound write FFallSound;

Sound when falling. The default is the sound named 'creature_fall'.

Public property RadiusOverride: Single read FRadiusOverride write FRadiusOverride;

Radius used for resolving (some) collisions with the alive creature. This can be read from the resource.xml file. When zero, the radius is automatically calculated looking at the 3D model bounding box, and taking into account gravity direction, see TCreatureResource.RadiusCalculate.


Generated by PasDoc 0.15.0.