FURTHER DEVELOPMENT
There's still not much flexibility about it, but you can play with LUA scripts.
Here is how scripting works:
Engine imports sets of functions and constants into each LUA script loaded (these sets differ from script to script), as well as common LUA script Common.lua, which contains math functions and proxy functions definitions (for debugging).
Each script recieves COMBINE_ closure so LUA can understand whether engine is executing script or you are testing it on your own.
So when you want to execute script apart from engine, you place Common.lua to folder with your script, and thats pretty much it.
One important C++ function accesible in LUA is trace, which recieves text string and prints in to file lua_debug.txt.
When you execute script on your own, trace merely transforms into print (standard LUA output function)
Important: you need a basic understanding of 3D space to write scripts in 2D. DirectX uses left-handed coordinate system (compared to OpenGL's right handed), which means that X axis points to your right, Y axis points up (to the sky), Z axis points away from you.
In 2D, X axis points right, Y axis points up. When 3D and 2D communicate, X(3D) axis is assumed to point the same way as X(2D), Z(3D) is the same as Y(2D), and Y(3D) is omitted (creatures cant currently move up and down in the dungeon).
1. Media/Common.lua
Check it out yourself, I dont think there is something complicated in it.
Outline: it defines functions to work with tables (structures form C++ are called tables in LUA) of specific type, which I call V2Vec and V3Vec.
2. Dungeon script
Media\Dungeon\dungeon_script.lua
Imported constants:
DUNGEON_BLOCK_WIDTH
DUNGEON_BLOCK_HEIGHT
BLOCK_EMPTY
BLOCK_WALL
BLOCK_DIRT
C++ imported functions:
CreateDungeon
parameters:
int - number of dungeon tiles along x asix (1..128)
int - number of dungeon tiles along z asix (1..128)
Note that since most dungeons algorithms are 2D, I use 2D vectors for it, But DirectX uses Y asix to point upwards, so 3D Z axis is 2D Y axis. (X remains the same)
SetBlockType
parameters:
int - block x position
int - block z position
int - block type
Possible block types are:
BLOCK_DIRT = 0;
BLOCK_EMPTY = 1;
BLOCK_WALL = 2;
, these are defined in LUA (as already stated)
GetBlockType
parameters:
int - block x position
int - block z position
return values:
int - block type
CreateStaticEntity
parameters:
V3Vec - entity position
V3Vec - entity up direction (normalized vector)
V3Vec - entity forward direction (normalized vector)
String - entity mesh file
CreateCreature
[to be continued]
CreateTorch
[to be continued]
RemoveEntities
[to be continued]
GetEntityClass
[to be continued]
GetEntityPosition
[to be continued]
LUA functions called from C++:
OnCreateEntities
No input or output. Called once, right after dungeon is created. Can be used to define custom level appearance.
OnBlockChange
No input or output. Most important function called for each block which type has changed.
3. Creature AI script
[you can add new ones]
Media\Creatures\Orc\orc_script.lua
Each creature recieves its own instance of LUA script context, so you dont need to mess around with 'this' pointer.
C++ imported functions:
SetPosition
parameters:
V2Vec - 2D position you want place creature to. X and Y axis are mapped to X and Z axes, respectively.
return:
bool - false if cant move creature to that position.
GetPosition
return:
V2Vec - Current 2D position of creature. X and Y axis are mapped to X and Z axes, respectively.
SetOrientation
parameters:
V2Vec - Normalized 2D orientation. X and Y axis are mapped to X and Z axes, respectively.
return:
bool - false if cant orient creature that way.
GetOrientation
return:
V2Vec - Normalized 2D orientation. X and Y axis are mapped to X and Z axes, respectively.
SetAnimation
parameters:
string - Name of the animation. Use your own .X files with arbitrary animations.
FindPath
parameters:
V2Vec - where you want the path to start from
V2Vec - where you want the path to end
return:
list of V2Vec - path nodes, each segment of this path is a line .
note:
This function is supposed to be implemented in C++. It currently uses proxy LUA implementation. Feel free to extend it.
LUA functions called from C++:
OnProcess
input:
float - elapsed time since last call
The only function, which is responsible for all AI logic.
IMPORTANT NOTE
This is draft. I'm new to LUA.




Reply With Quote


