Scripting:TWTrapAIEcology

Building pieces of another world.
Revision as of 21:49, 21 June 2020 by gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
Jump to navigation Jump to search

TWTrapAIEcology is a script that allows a controlled population of AIs to be spawned dynamically during play.

Periodically this script will check whether the number of currently spawned AIs has reached a configurable population limit. If the count is less than the limit, the script will select an AI archetype to spawn, and then choose a spawn point at which the AI should be created. If AIs are killed and despawn, the population drops, and new AIs will be spawned to replace them. Note that this only works if the AI despawns - use the TWTrapAIEcologyDespawn script to make that happen.

At most one AI is spawned each time the script checks the current population. This is a deliberate restriction imposed to prevent AIs being spawned on top of each other.

The AI archetype is chosen based on links from the TWTrapAIEcology host object to archetypes. By default the script will use weighted random selection if multiple AI archetypes are linked, and if only a single AI archetype is linked that is always used.

Example from demo.osm

The spawn point is chosen based on links from the TWTrapAIEcology to concrete objects in the world. If multiple spawn points are linked, one is chosen at random, whereas if only one spawn point is linked that one is always used. The default behaviour is to try and find the first randomly selected spawn point that is not visible on screen. If all spawn points are on screen, spawning is aborted. This behaviour can be disabled if desired - the spawn point is sent a TurnOn message when an AI spawns there, so particle effects can be tiggered.

It is important to note that, while a fnord (a Marker or similar) could be used to mark the location of a spawn point, using a standard fnord is NOT recommended if you want to spawn AIs off screen. fnord objects are not rendered, and this means that the engine can not determine whether the object is on screen: it will always say it is not because, well, you can't see it; it's not rendered! While this is a fine and useful attribute for a normal fnord to have, if you want to make sure that AIs are always spawned off screen, you can't use a fnord unless you give it a transparent, physicsless object and change its Render Type to 'Normal'. An example using this setup can be found in the TWScript Demo mission.

Design Note Parameters

This script supports all the following arguments in the Editor -> Design Note in addition to the arguments given in the TWBaseScript and TWBaseTrap documentation.

TWTrapAIEcologyRate
Type: time
Default: 30s
The frequency at which the AIEcology checks the current population and attempts to spawn new AIs if the number of spawned AIs is less than the target population. You probably don't want to set this to anything less than the default - and even that is probably too fast - unless there's some obvious reason why AIs are spawning so quickly (for example, you have Fire Elementals spawning near lava)
TWTrapAIEcologyPopulation
Type: integer
Default: 1
The target number of AIs to have spawned at the same time. If less than this number of AIs have been spawned, the script will try to spawn a new one at the specified rate.
TWTrapAIEcologyLives
Type: integer
Default: 0 (unlimited)
Limit the overall number of times that AIs can be spawned. If this has been set, every time an AI is spawned the number of 'lives' the AIEcology has is decreased by 1. When the lives have all been used up, the AIEcology stops spawning new AIs until it receives a ResetSpawned message.
TWTrapAIEcologyStartOn
Type: boolean
Default: false
TWTrapAIEcologyVisibleSpawn
Type: boolean
Default: false
TWTrapAIEcologySpawnQVar
Type: string
Default: false


TWTrapAIEcologyAILink
Type: target
Default: &%Weighted


TWTrapAIEcologySpawnLink
Type: target
Default: &#Weighted


Authors

  • gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+]