LUA Scripts, loading and communication
Posted: 27 Apr 2007, 02:07
Now, before I got a-ranting any more about how I think that LUA could be used to build whole new economic gameplay (and, not coincidentally, get rid of large chunks of code within Spring's main loop, by putting them on outside, customized sync timing tracks where they belong anyhow)....
There are two big issues that have come up, as I thought about these things:
1. LUA scripts must (not kind've, nor sort've, MUST) have ways to be invoked that cannot be shut off, and must be able to be loaded by a game. A game should be able to start LUA scripts when it loads. There simply isn't any other way to go about this.
2. LUA scripts must have a common communication system that can be accessed by "sharing" code, as well as by AIs and other agents. A player should be able to share resources in a LUA-engineered game with other players, through simple means codewise, or we'll lose a major element of team-based strategy, which would be bad. However, we need this to be very flexible in its concept of "sharing"... for example:
A. I have a game where I have built a Ba'alrog. It has a magic (LUA-powered) ability to "strengthen the courage of nearby troops". If I move this mighty beast near a pack of my buddy's Orcs, then I darn well want to "pass" this benefit on to those troops, too!
Here, I want to be able to pass along a shareable "container" that goes to a script that looks for a Ba'alrog near troops, and has logic that says, "if friendly, then your troops nearby get a bonus".
B. In my game, I have not TWO resources, but FOUR. And none of them follow the usual rules for Metal and Energy. I have to make Food with laborers, which I feed to Miners, which produce Coal and Ore, and finally I combine the Coal and Ore to make Metal for my armored hordes... who also occasionally need the other two elements. I want to pass my buddy Food... the system of communication to set that up should be fairly trivial:
Player opens Sharing Menu
Player selects "food" resource
Player selects his buddy
Player selects amount / percentage to give, either immediately or every game "long period" (however that is defined).
So, as a coder, I'd need to build the Sharing Menu (not too painful), then define "food" as a game variable that is tracked through (insert some fairly complicated logic here) every (however many ticks we want between "long periods") and which is "shareable". Every "long period", the logic runs, and all of the resource that I have left up to the amount I've designated should then go to the person I've shared with.
Etc., etc.
This means of communication should also provide a portal whereby AIs can "see" new resources, be "told" some things how they work (ok, we're getting into devilishly nasty stuff here, but meh, I'm an idealist) and then actually make use of these things. So AIs can "see" these things because they are a "shareable" item that's defined in a way that AIs can "see", and while they may not handle what to do with this properly, they aren't blind.
The same goes for commands using LUA exclusively, which I predict are going to become more and more popular as people finally get into things. If I have an Engineer unit that can build a Forge, and that Forge can be "upgraded" into an Uber-Forge, and that Uber-Forge then makes, oh, I dunno, "Widgets +3" that are really useful... AIs need a way to be told, "hey, stupid AI! If you can, you should try activating this command under certain circumstances!". And, frankly, this should probably be a common system that all AIs use, instead of the collection of custom hacks that we now have, or it will just be a huge mess and every large game team will need an AI programmer or they'll never have any single-player at all
So... back on point... what I see coming, once we all get our heads wrapped around this LUA thing, is pretty neato, because we can just about totally abandon OTA if we feel like it... but to get that last inch, frankly, is probably going to be as much work as the first 9.999 miles. But it will be worth it, if we can get this to work, because then, among other things, AI developers will finally have the makings of a core meta-language that goes beyond hard-coded commands.
Why am I bothering with this? Do I write AIs? No. Heck, other than minor goofing around, I hardly know what to do with the LUA thingy yet. But I can already see that there are many, many, many contingencies that AI developers simply cannot handle very well without a better way to see what they need their AIs to do. For example... I used a few tricks in my current project where there are transports that cannot use their weapons unless they are "manned". No AI I've looked at knows how handle this little wrinkle, and since the said transports are, if you just look at stats, not-too-shabby as vehicles, AIs build them and send them at me... empty
I'd like to see a future where AIs could be "told" by a game designer, "hey, don't build this unit unless you are using it as a transport", etc., or at the very least, some way to lock AIs OUT of using the unit until they are finally "smart" enough to make use of it properly. The examples of this are just going to keep coming, so it's best to see that future and plan for it, imo.
There are two big issues that have come up, as I thought about these things:
1. LUA scripts must (not kind've, nor sort've, MUST) have ways to be invoked that cannot be shut off, and must be able to be loaded by a game. A game should be able to start LUA scripts when it loads. There simply isn't any other way to go about this.
2. LUA scripts must have a common communication system that can be accessed by "sharing" code, as well as by AIs and other agents. A player should be able to share resources in a LUA-engineered game with other players, through simple means codewise, or we'll lose a major element of team-based strategy, which would be bad. However, we need this to be very flexible in its concept of "sharing"... for example:
A. I have a game where I have built a Ba'alrog. It has a magic (LUA-powered) ability to "strengthen the courage of nearby troops". If I move this mighty beast near a pack of my buddy's Orcs, then I darn well want to "pass" this benefit on to those troops, too!
Here, I want to be able to pass along a shareable "container" that goes to a script that looks for a Ba'alrog near troops, and has logic that says, "if friendly, then your troops nearby get a bonus".
B. In my game, I have not TWO resources, but FOUR. And none of them follow the usual rules for Metal and Energy. I have to make Food with laborers, which I feed to Miners, which produce Coal and Ore, and finally I combine the Coal and Ore to make Metal for my armored hordes... who also occasionally need the other two elements. I want to pass my buddy Food... the system of communication to set that up should be fairly trivial:
Player opens Sharing Menu
Player selects "food" resource
Player selects his buddy
Player selects amount / percentage to give, either immediately or every game "long period" (however that is defined).
So, as a coder, I'd need to build the Sharing Menu (not too painful), then define "food" as a game variable that is tracked through (insert some fairly complicated logic here) every (however many ticks we want between "long periods") and which is "shareable". Every "long period", the logic runs, and all of the resource that I have left up to the amount I've designated should then go to the person I've shared with.
Etc., etc.
This means of communication should also provide a portal whereby AIs can "see" new resources, be "told" some things how they work (ok, we're getting into devilishly nasty stuff here, but meh, I'm an idealist) and then actually make use of these things. So AIs can "see" these things because they are a "shareable" item that's defined in a way that AIs can "see", and while they may not handle what to do with this properly, they aren't blind.
The same goes for commands using LUA exclusively, which I predict are going to become more and more popular as people finally get into things. If I have an Engineer unit that can build a Forge, and that Forge can be "upgraded" into an Uber-Forge, and that Uber-Forge then makes, oh, I dunno, "Widgets +3" that are really useful... AIs need a way to be told, "hey, stupid AI! If you can, you should try activating this command under certain circumstances!". And, frankly, this should probably be a common system that all AIs use, instead of the collection of custom hacks that we now have, or it will just be a huge mess and every large game team will need an AI programmer or they'll never have any single-player at all

So... back on point... what I see coming, once we all get our heads wrapped around this LUA thing, is pretty neato, because we can just about totally abandon OTA if we feel like it... but to get that last inch, frankly, is probably going to be as much work as the first 9.999 miles. But it will be worth it, if we can get this to work, because then, among other things, AI developers will finally have the makings of a core meta-language that goes beyond hard-coded commands.
Why am I bothering with this? Do I write AIs? No. Heck, other than minor goofing around, I hardly know what to do with the LUA thingy yet. But I can already see that there are many, many, many contingencies that AI developers simply cannot handle very well without a better way to see what they need their AIs to do. For example... I used a few tricks in my current project where there are transports that cannot use their weapons unless they are "manned". No AI I've looked at knows how handle this little wrinkle, and since the said transports are, if you just look at stats, not-too-shabby as vehicles, AIs build them and send them at me... empty
