Click or drag to resize
Animal Class
This is the class that you derive from when you create an animal.
Inheritance Hierarchy

Namespace: Terrarium.Sdk.Classes.Creature
Assembly: Terrarium.Sdk (in Terrarium.Sdk.dll) Version: 1.1.0.0 (1.1.0.0)
Syntax
public abstract class Animal : Organism

The Animal type exposes the following members.

Constructors
  NameDescription
Protected methodAnimal
Initializes a new instance of the Animal class
Top
Methods
  NameDescription
Public methodBeginAttacking

Method used to command your creature to start attacking another creature. You can only attack one creature per round, and a single call to BeginAttacking will only attack a target creature in the upcoming tick. Calling BeginAttacking multiple times in the same turn will only result in your creature attacking the target specified in the last call to BeginAttacking.

Attacking is asynchronous so you'll need to handle the AttackCompleted event in order to get the status of your attack. A single attack might not kill a target enemy so you should detect if the enemy is still alive and call BeginAttacking once per round until the target creature is either dead or has escaped.

Public methodBeginDefending

Method used to command a creature to begin defending against a specific target creature. You can only defend against one creature at a time, so only the final call to BeginDefending will actually be used in the upcoming turn.

Once your creature has finished defending, the DefendCompleted event will be fired and your event handler will be called if you provided one. You can use this event to determine the results of your defense.

Public methodBeginEating

Method used to command your creature to start eating another creature. You can only eat one target creature per round, and a single call to BeginEating will only attack a target creature in the upcoming tick. Calling BeginEating multiple times in the same turn will only result in your creature eating the target specified in the last call to BeginEating.

Eating is asynchronous so you'll need to handle the EatCompleted event in order to get the status of the bite. A single bite might not produce enough energy for your creature so you'll have to make multiple bites against the same target until it is completed eaten.

Public methodBeginMoving

Method used to command a creature to begin moving towards a specific location at a specific speed. The actual movement operation may take several turns, but is always initiated using this method. Your movement location should be within the world boundary and your movement speed should be less than or equal to your creature's Species.MaximumSpeed.

Once called the creature will begin moving towards the specified point. This movement will continue until you issue a different BeginMoving command to your creature, it reaches its destination, or becomes blocked by something. Any calls to BeginMoving will clear out any previous calls, so care should be taken when issuing multi-part path movements.

Once the movement is completed the MoveCompleted event will be fired and your event handler for this function will be called if you've provided one. The event handler will provide full information about the results of an attempted movement operation.

Public methodBeginReproduction

Use this function to command your creature to reproduce. There are many conditions on whether your creature can reproduce. If these conditions are not met, an exception will be thrown. The easiest way to make sure all pre-existing conditions have been met is to check the CanReproduce property.

If you call this method multiple times in the same turn, then the last call will be used, and all previous calls will be ignored. This method is also asynchronous, and a ReproduceCompletedEvent will be fired when your creature has actually given birth. The time between start and completion is 10 ticks.

(Inherited from Organism.)
Public methodCanAttack

Used to determine if your creature can attack another creature. This will return true all the time for a Carnivore since they can always attack.

For Herbivores this will return true if they are hungry enough to be aggressive. Herbivores may also attack a creature in the upcoming round if that creature attacked them in the previous round. The best place to attack a creature that is attacking you is to handle the Attacked event.

Public methodDeserializeAnimal

This method should be overridden by any class inheriting from Animal. This method is called with a MemoryStream that the user can read any data from that was written during the call to SerializeAnimal.

Care should be taken when reading from a MemoryStream since the values may have been truncated at 8000bytes if more than 8000bytes were originally written.

Public methodDistanceTo

Calculates the linear distance between your creature and another using various API's defined by the Vector class.

(Inherited from Organism.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetThenErasePendingActions (Inherited from Organism.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodInitialize
The Initialize method is called immediately after instantiating a new creature. The developer should override this method to set up event handlers for the creature and do any first time initialization that needs to be done to set up member variables.
(Inherited from Organism.)
Public methodInternalAnimalDeserialize
Implemented by the Animal class in order to allow deserialization of any private members required for the class to operate properly after deserialization.
Public methodInternalAnimalSerialize
Implemented by the Animal class in order to allow serialization of any private members required for the class to operate properly after deserialization.
Public methodInternalMain
Provides all of the per tick processing for an Animal. This method fires all of the events that make a creature tick. Some events are fired every tick, while other events are only fired whenever certain actions complete. This method can be called in order to process Animal code without processing the developer code in the instance they are being skipped for using too much time.
(Overrides OrganismInternalMain(Boolean).)
Public methodInternalOrganismDeserialize (Inherited from Organism.)
Public methodInternalOrganismSerialize (Inherited from Organism.)
Public methodIsMySpecies

Allows a creature to determine if the OrganismState of another creature represents the same species. This can be used to determine whether you should attack/defend against another creature.

Creatures of the same species often don't fight one another, defend against one another, and kill one another. They often help their own species in fights against other species. Carnivores of the same species may sacrifice themselves as food once they become too old to members of their species.

Public methodLookFor

Tries to return an updated OrganismState given a creature's state OrganismState. This function may return null if the creature can't be found or was hidden by camouflage. You may call this method multiple times and get different results.

Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRefreshState

Tries to return an updated OrganismState given a creature's ID. This function may return null if the creature can't be found or was hidden by camouflage. You may call this method multiple times just like the LookFor method and get different results.

Public methodScan

Scans the world around your creature's current location in a circular area and returns an ArrayList of OrganismState objects representing what was seen.

The radius scanned by your creature is dependent upon the number of points placed into the EyesightPoints attribute. Animals may also hide within your radius by using camouflage. This means that more points placed into the EyesightPoints attribute will yield a better vision of hidden creatures.

Because of camouflage and the random aspect of hiding vs. being seen by another creature, multiple calls to Scan might returns different results. However, each call to Scan also takes additional time from your creature's total timeslice.

It is recommended that you hold onto the OrganismState objects, determine your target creature, and then use the LookFor method to update the state rather than calling the Scan method again. The LookFor method also takes into account camouflage and may not work the first time, but is much less expensive timewise than Scan.

Public methodSerializeAnimal

This method should be overridden by any class inheriting from Animal. This method is called with a MemoryStream that the user can place any data on they wish to Serialize during save games or while being teleported.

The complement of this method is the DeserializeAnimal method which is called to deserialize the data when the creature is restored. Authors should be careful when writing to a MemoryStream since it will be truncated at 8000bytes.

Public methodSetWorldBoundary (Inherited from Organism.)
Public methodStopMoving

Clears any pending movement operations your creature might be performing.

Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWithinAttackingRange

Used to determine if your creature is within range to attack another target creature.

This method does not attempt to validate the position of the organismState with respect to the current world state. If you pass a stale object in then you may get stale results. Make sure you use the LookFor method to get the most up-to-date results.

Public methodWithinEatingRange

Used to determine if your creature is within range to eat another target creature.

This method does not attempt to validate the position of the organismState with respect to the current world state. If you pass a stale object in then you may get stale results. Make sure you use the LookFor method to get the most up-to-date results.

Public methodWriteTrace(Object)

Writes a trace to the Terrarium trace window for debugging. The Tracing routines take a *very* small amount of time if you're not monitoring them. They are on the order of 12 nSec per call. To meet this performance requirement there are several overloads taking a varying number of parameters rather than a single variable argument parameter.

(Inherited from Organism.)
Public methodWriteTrace(Object, Object)

Writes a trace to the Terrarium trace window for debugging. The Tracing routines take a *very* small amount of time if you're not monitoring them. They are on the order of 12 nSec per call. To meet this performance requirement there are several overloads taking a varying number of parameters rather than a single variable argument parameter.

(Inherited from Organism.)
Public methodWriteTrace(Object, Object, Object)

Writes a trace to the Terrarium trace window for debugging. The Tracing routines take a *very* small amount of time if you're not monitoring them. They are on the order of 12 nSec per call. To meet this performance requirement there are several overloads taking a varying number of parameters rather than a single variable argument parameter.

(Inherited from Organism.)
Public methodWriteTrace(Object, Object, Object, Object)

Writes a trace to the Terrarium trace window for debugging. The Tracing routines take a *very* small amount of time if you're not monitoring them. They are on the order of 12 nSec per call. To meet this performance requirement there are several overloads taking a varying number of parameters rather than a single variable argument parameter.

(Inherited from Organism.)
Top
Properties
  NameDescription
Public propertyAntennas

Provides access to the creature's Antenna. Each Antenna has a specific set of positions that it may be in. Setting states with this information is possible as is passing numeric data.

Public propertyCanEat

Used to determine if your creature is capable of eating depending on the creature's current energy state. You can also trap the AlreadyFullException from BeginEating.

Public propertyCanReproduce

Determines whether all conditions are met for your organism to be able to reproduce. These conditions include various state information like whether your creature is mature, has enough energy, and is not already reproducing.

(Inherited from Organism.)
Public propertyCurrentAttackAction

After your creature has begun attacking you can get the AttackAction object that represents your creature's current attack action. You can use this to examine the target creature you're attacking and determine if there might be a more appropriate enemy.

Public propertyCurrentDefendAction

After your creature has begun defending you can get the DefendAction object that represents you're creatures current defend action. You can use this to examine the target creature you're defending against and determine if there might be a more appropriate enemy.

Public propertyCurrentEatAction

After your creature has begun eating you can get the EatAction object that represents you're creatures current eat action. You can use this to examine the target creature your eating and determine if their might be a better target to eat.

Public propertyCurrentMoveToAction

After your creature has begun moving you can get the MoveToAction object that represents your creature's current movement action. You can use this to examine the movement location and speed that your creature moving to see if you'll need to alter your course.

Public propertyCurrentReproduceAction

After your creature has begun reproduction you can get the ReproduceAction object that represents your creature's current reproduction. You can use this to examine the dna byte array that will be passed to the child.

(Inherited from Organism.)
Public propertyID

The unique GUID for an organism. This is used to store plant/animal state when being saved to disk, or when passing plant/animal information to children during reproduction.

(Inherited from Organism.)
Public propertyIsAttacking

Used to determine if your creature has been commanded to attack. You can also check the CurrentAttackAction property to get the actual target creature you're attacking. Because attacking is asynchronous your creature won't attack until the upcoming tick.

Public propertyIsDefending

Used to determine if your creature has been commanded to defend. You can also check the CurrentDefendAction property to get the actual target creature you're defending against. Because defending is asynchronous your creature won't defend until the upcoming tick.

Public propertyIsEating

Used to determine if your creature has been commanded to eat. You can also check the CurrentEatAction property to get the actual target creature you're eating. Because eating is asynchronous your creature won't actually eat until the upcoming tick.

Public propertyIsMoving

Used to determine if your creature has been commanded to move. You can also check the CurrentMoveToAction property to get the actual movement vector for your creature. Because moving is asynchronous your creature might not have started moving yet.

Public propertyIsReproducing

Determines if your organism is currently in the process of reproducing. Because reproducing is an asynchronous action, the organism may not actually be giving birth yet.

(Inherited from Organism.)
Public propertyOrganismRandom

To make random actions deterministic the creature should use this Random object when in need of a random number or variable in the creature's code. This can help aid in debugging so that strange behavior can be reproduced.

(Inherited from Organism.)
Public propertyPosition

Each creature is centered in the game world to a specific point. The Position property can be used to query for this location.

(Inherited from Organism.)
Public propertySerializedStream (Inherited from Organism.)
Public propertySpecies
Returns the immutable species object containing information about your creature's species related information. This includes how many points were placed into creature attributes and other values calculated from those points allocations.
Public propertyState
The current state of your own creature. This is used to get the latest information about your creature's health, damage, and other stats available on the AnimalState object.
Public propertyTrace (Inherited from Organism.)
Public propertyTurnsSkipped

A creature can get skipped for a number of turns if it takes too long to execute. There is a limit to the time an animal can use for processing every turn which is calculated dynamically by the Terrarium each time it starts based on your computer's processing power.

To see how long your creature takes to process, you can open the Trace window, unselect "Show Organism Traces", and then select your creature. Note that this time will be different depending on the machine.

If you do break the limit Terrarium determines how many ticks worth of time you've gone over the limit and sets this property. You can examine this property to recover from conditions where your creature is skipped for a given number of turns. This is useful since you may not receive events that fire while during the time your creature's turn is being skipped.

(Inherited from Organism.)
Public propertyWorldHeight

The height of the world in single points/pixels. Use this to make sure you don't try to move outside of the bounds of the Terrarium and to help manage your creature's population size/density.

Public propertyWorldWidth

The width of the world in single points/pixels. Use this to make sure you don't try to move outside of the bounds of the Terrarium and to help manage your creature's population size/density.

Top
Events
  NameDescription
Public eventAttackCompleted

The AttackCompleted event is fired whenever your creature has completed an attack operation. Your creature should hook this event to learn the results of the battle such as how much damage was inflicted and whether the target creature was killed.

Public eventAttacked
Fired when an organism is being attacked by another organism.
Public eventBorn
Fired on an organism when it is first born.
Public eventDefendCompleted
Fired when a DefendAction is completed.
Public eventEatCompleted
Fired when an EatAction is completed.
Public eventIdle
Fired after all other events have been fired.
Public eventLoad
Fired before all other events have been fired.
Public eventMoveCompleted

The MoveCompleted event is fired whenever your creature has completed a movement operation. This can either mean the creature reached the destination or that the creature was blocked and can't move anymore.

Public eventReproduceCompleted
Fired on the parent when a ReproduceAction is completed.
Public eventTeleported
Fired after an organism has been teleported.
Top
See Also