HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

AI coding library useful?

04-21-2009, 05:29 PM#1
Opossum
I've just started working on some sort of coding environment which is supposed to make scripting custom AIs a bit easier. It currently looks like this and works fine so far:
Expand JASS:

What this does is basically assigning an AI struct to a unit and creating event triggers for certain events that might be useful for custom AIs. These events are accessable through interface functions.
The code currently covers these four events:
1. A unit being engaged by another unit. Engaged and engaging unit will be passed through the interface.
2. A unit that already is engaged changing target. Engaged unit and new target will be passed.
3. A unit disengaging and retreating to its camp (= receiving order "move"). Disengaging unit and the camp's location will be passed.
4. A unit finishing disengaging and going into idle status again (= receiving order null). Only the idling unit will be passed.
The struct also saves information like the unit's target and the unit's current state (i.e., idling, being engaged, retreating etc).

Current problems are though that each AI struct will leak three (more to come) triggers that can't be destroyed. Using custom AIs for many units might cause serious lag or troubles with HSAS.
The other problem is that I'm not really sure if it's useful at all. Of course there will be more events added to the struct that define a unit's behaviour (like maybe starting to cast a spell, the targeted unit trying to flee or something like that etc.) but many possibilities this script offers can actually easily be achieved by setting up the triggers yourself.

Here is a sample script that demonstrates how to use the interface functions:
Expand JASS:
04-21-2009, 05:59 PM#2
tamisrah
Regarding your trigger problem:
As I imagine that all orders are given by the AI itself, it would probably
be better to use function wrappers to detect for example orders.
Besides if that isn't suitable, you could go for a single trigger approach and attach the structs to the units.
04-21-2009, 06:53 PM#3
Viikuna-
Looks neat.

I was going to create something like this for small groups of units, and this is pretty cool actually.

Quote:
Current problems are though that each AI struct will leak three (more to come) triggers that can't be destroyed. Using custom AIs for many units might cause serious lag or troubles with HSAS.

Good thing that I recycle my units. I sometimes forget how easy it makes these things. ^_^

You could also add some wrapper function, so we can use some struct array and UnitUserData instead of HSAS. It would be nice, but not neccesacy, because its easy enough to change it now too.

Anyways, I find this useful.
04-21-2009, 08:50 PM#4
Opossum
Ok I'm using global triggers now and I wrapped them a bit too.
Also I'm not passing anything through the events anymore as you can just use the usual event responses in the interfaced event functions (didn't know about that, sounds reasonable though). So that's basically just one function interface now.
Added spell and order support, too:
Expand JASS:
Gotta think about what else to add now. I'm always open to suggestions :D