Animal Class |
Namespace: Terrarium.Sdk.Classes.Creature
The Animal type exposes the following members.
Name | Description | |
---|---|---|
![]() | BeginAttacking | 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. |
![]() | BeginDefending | 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. |
![]() | BeginEating | 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. |
![]() | BeginMoving | 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. |
![]() | BeginReproduction | 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. |
![]() | CanAttack | 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. |
![]() | DeserializeAnimal | 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. |
![]() | DistanceTo | Calculates the linear distance between your creature and another using various API's defined by the Vector class. |
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetThenErasePendingActions | (Inherited from Organism.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | Initialize |
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.) |
![]() | InternalAnimalDeserialize |
Implemented by the Animal class in order to allow
deserialization of any private members required for the
class to operate properly after deserialization.
|
![]() | InternalAnimalSerialize |
Implemented by the Animal class in order to allow
serialization of any private members required for the
class to operate properly after deserialization.
|
![]() | InternalMain |
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).) |
![]() | InternalOrganismDeserialize | (Inherited from Organism.) |
![]() | InternalOrganismSerialize | (Inherited from Organism.) |
![]() | IsMySpecies | 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. |
![]() | LookFor | 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. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | RefreshState | 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. |
![]() | Scan | 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. |
![]() | SerializeAnimal | 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. |
![]() | SetWorldBoundary | (Inherited from Organism.) |
![]() | StopMoving | Clears any pending movement operations your creature might be performing. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | WithinAttackingRange | 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. |
![]() | WithinEatingRange | 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. |
![]() | WriteTrace(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. |
![]() | WriteTrace(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. |
![]() | WriteTrace(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. |
![]() | WriteTrace(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. |
Name | Description | |
---|---|---|
![]() | Antennas | 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. |
![]() | CanEat | 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. |
![]() | CanReproduce | 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. |
![]() | CurrentAttackAction | 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. |
![]() | CurrentDefendAction | 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. |
![]() | CurrentEatAction | 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. |
![]() | CurrentMoveToAction | 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. |
![]() | CurrentReproduceAction | 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. |
![]() | ID | 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. |
![]() | IsAttacking | 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. |
![]() | IsDefending | 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. |
![]() | IsEating | 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. |
![]() | IsMoving | 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. |
![]() | IsReproducing | 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. |
![]() | OrganismRandom | 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. |
![]() | Position | Each creature is centered in the game world to a specific point. The Position property can be used to query for this location. |
![]() | SerializedStream | (Inherited from Organism.) |
![]() | Species |
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.
|
![]() | State |
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.
|
![]() | Trace | (Inherited from Organism.) |
![]() | TurnsSkipped | 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. |
![]() | WorldHeight | 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. |
![]() | WorldWidth | 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. |
Name | Description | |
---|---|---|
![]() | AttackCompleted | 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. |
![]() | Attacked | Fired when an organism is being attacked by another organism. |
![]() | Born | Fired on an organism when it is first born. |
![]() | DefendCompleted | Fired when a DefendAction is completed. |
![]() | EatCompleted | Fired when an EatAction is completed. |
![]() | Idle | Fired after all other events have been fired. |
![]() | Load | Fired before all other events have been fired. |
![]() | MoveCompleted | 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. |
![]() | ReproduceCompleted | Fired on the parent when a ReproduceAction is completed. |
![]() | Teleported | Fired after an organism has been teleported. |