View previous topic :: View next topic |
Author |
Message |
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Tue Jun 03, 2008 10:39 am Post subject: WarCoders Resurrection - Hooking up to MiniD |
|
|
Hi Jarrett! I'm finally going to be developing my game, now. I was wondering if you could help me figure out a technical problem.
My game will be an RTS except I with user-programmable robots. I want the language of the robot AI code to be in minid scripts.
Ok, so here's my technical problem. First, I want each robot to be in it's own script such as 'miner.md' and 'tankbot.md'
Second, I want each robot to be able to access a list of variables given to them from the game engine, such as
- position of base
- position on map
- targets in view (friendly or not, type of target, and position)
- base transmission message
Then, I want each of these scripts to be able to call functions from the game engine in an ai_routine() minid function. Then I want my game engine to call the ai_routine() minid function for each robot.
Exmp:
miner.md
// called by game engine
void ai_routine()
{
// fire... call miner.fire(x,y) function located in miner class of game engine
fire(x,y);
// move... call miner.move(x,y) function located in miner class of game engine
move(x,y);
// stop... call pre-defined stop() function located in miner class of game engine
stop();
}
I know this is a difficult technical problem, but I just wanted to ask you for some starter tips to get me going.
Should I use minid 1.0 or 2.0 as well?
Any advice / starter tips appreciated. Thanks. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Jun 03, 2008 12:29 pm Post subject: |
|
|
You mention in the comments that those functions call methods of a class in the game engine. Is this class generated by the engine? Is ai_routine treated as a method that is added to the class? So ai_routine's 'this' parameter will be an instance of the miner class, and when you call those functions, you're really calling methods of 'this'?
Re MD1 vs. MD2: MD2 is, IMO, a better language, but the implementation is considerably less mature in some spots (though more mature than the MD1 in others..). Notably it doesn't have the binding library which may or may not be a problem for you. Furthermore I'm rewriting the MD2 implementation which will radically change the native API (probably), so if you're looking for something that's stable, MD2 might not be it. But once it's done, the new implementation should be much better than the current MD1 and MD2 implementations. |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Tue Jun 03, 2008 4:38 pm Post subject: |
|
|
Sounds like I should stick with MD1 then. Where do you keep your minid 1.0 branch?
Sorry about the confusion, let me try and re-state what I want to do.
Alright, so first I want the AI of my robots to be defined in a .md script file, which I imagine might look something like this...
Code: |
---- miner.md -----
attack_rountine()
{
}
defend_routine()
{
}
// this will be called by the engine
ai_routine()
{
// get list of targets from engine
targets = getTargets();
// cycle through targets
foreach(target...)
{
if (target.type == 'miner' and target.friendly == false)
// call fire function from engine
fire(target.pos.x, target.pos.y);
}
// get state of main base from engine
baseState = getBaseState();
switch(baseState)
{
case "attack":
attackRoutine();
break;
case "defend":
defendRountine();
break;
}
}
|
Now, here is how I imagine I might want to go about hooking up minid to D code and vise-versa
Code: |
class Miner
{
this()
{
mdState = loadMD("miner.md");
// make functions from class callable from given minid script
mdState.addGlobalFunction(&getTargets);
mdState.addGlobalFunction(&fire);
mdState.addGlobalFunction(&getBaseState);
}
process()
{
// run function 'ai_routine' located in the minid script
mdState.runFunction("ai_routine");
}
getTargets()
{
return targetList;
}
fire(x,y)
{
// game code here necessary for bot to fire
}
getBaseState()
{
return base_state;
}
String base_state;
Target[] targetList;
}
|
This is the basis of what I want to do, call functions in the minid script from the game engine (D code), and to be able to call functions in the engine from the minid script.
I just wanted to get off on the right track by asking here first. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Jun 03, 2008 10:15 pm Post subject: |
|
|
MiniD 1 is in /trunk. (MD2 is in /branches/v2)
That stuff looks legit and should be relatively simple to do with minid.bind. Instead of putting those functions in the global namespace, you should probably put them in the module's namespace. So when you load "miner.md", you can get the namespace of that module and add those functions to it.
One thing to keep in mind - the binding lib doesn't support packing or unpacking arrays of wrapped class types, meaning that targetList will have to be manually converted to a MiniD array (or just kept as a MiniD array in the first place).
If you need any example code, don't hesitate to ask |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|