My game uses an entity component framework and uses scripts to define entities (this doesn't directly define behavior, I'll talk more about that at the end). The scripts define the actual components to be used for creating each entity. It uses a simple scripting language I created. Here is a simplified version of one of my scripts:
ENTITY:"Goblin"
{
description="It's currently their age."
commonname="goblin"
pluralCommonName="goblins"
childname="gob'in"
pluralChildName="gob'ins"
active=Nocturnal
tags=Mobile
baseAttributes="OrganicMobileCreature"
[Model]{
meshname="Goblin"
texturename="GoblinTexture"
}
[Motion]{
maxvelocity=0.01:0.015
locomotion=Walk,Swim
}
[Skills]{
ALL=0.01:0.05,Mine=8.3:8.8,PlaceCube=8.3:8.8
}
[Inventory]{
maxItems=2
Allow=ALL
Disallow=NONE
}
}
Much of that is self describing, but here are some highlights:
- The first section describes the common information for the entity. That includes a description and display names for various aspects of the entity.
- The
baseAttributes
tag references another script file that defines common components that I don't want to have to redefine multiple times. It contains components like position
, liferequirements
and so on. If any component is defined here again, this component will overwrite the common one.
- Each
[NAME] { }
set defines a new component that will be added to these entities.
- This description is not just for a single entity, it's for all goblins created. You'll see that some of the values have ranges (i.e.
0.01:0.015
), when a new goblin is created it gets created with a component that has a random value in that range. So each goblin will have slightly different skills and slightly different speeds. This setup defines that all goblins will start with really good skills in placing cubes and mining, which is really just for my own testing purposes. But as I'm sure you can guess, it's very easy to change the values to whatever I want.
This whole thing involves creating a custom parser, some kind of structure to hold the entity definitions (I call mine the Lexicon!) and a factory for taking those entity definitions and generating new entities. For me this system is still in its early stages, but it's turning out really, really well. It's a pretty powerful system for quickly defining entities and allows you to make any entity you want using the components you've created. If you're not comfortable creating your own parser, I think XML will work just fine. I converted mine from a pushback recursive parser I wrote for a little made up programming language.
As you can see this defines the entity. I mentioned that it doesn't directly define behavior. It can, however, easily define such things as hated enemies and how aggressively to react to said enemies. This would be as simple as defining whatever component you use to control such behavior. My entities also have a intelligence component (not shown) that defines things like:
- How they path find (simple line-of-sight movement, simple A*, predictive A*, etc.)
- How aggressive/defensive they are. Entities can have home zones that will be defended, but maybe not aggressive outside those zones.
- Technology awareness (open doors, use gadgets, avoid traps, etc)
- And more...
However yours is defined, it's your system that will drive the data in that component, which in turn affects the behavior of your entites.