| 12-31-2008, 02:06 AM | #1 |
I've been experimenting with the game's AI recently, and I wonder if it is already common knowledge that AIs can store data in a gamecache that can be retrieved by your triggers and functions and such. Apparently triggers can also be created in AIs, but I haven't found an in-game event to which they respond. |
| 12-31-2008, 03:01 AM | #2 |
JASS:native CommandAI takes player num, integer command, integer data returns nothing I've never messed with AI, but I think there are Start and Pause functions as well. EDIT: It occurs to me that you were actually asking for something entirely different, and that you actually meant the handle. In that case, I actually don't know enough about AI coding to help. If you can use global variables in AI, then that helps. If you can use custom functions in AI, that SUPER helps. |
| 12-31-2008, 03:57 AM | #3 | |
Quote:
remember that the scope of AI is limited, the data stored in global vars is local to each player (in other words we ensure MPI). The only possible usage of gamecache in AI could be to share data between player AIs.... is what you're planning? |
| 12-31-2008, 06:02 AM | #4 | |
I'm asking if I've discovered something new or rediscovered something. You can use custom functions in AI. And the natives in common.j appear to work quite well. I've spawned destructables and units. I've created units with AI, stored them in gamecache, removed them, then restored them with triggers from "in-game" (I don't know how else to refer to the map's script to differentiate it from AI). This only seems significant to me because I thought I had read somewhere that information can be sent to an AI with CommandAI, but information cannot be retrieved from an AI. But it certainly can through gamecache. Oh, and regarding triggers... I got an AI to run a trigger with TriggerExecute after I had passed it through gamecache into an AI global. Ingame Script JASS:globals gamecache AIcache = InitGameCache("AIcache") trigger testTrig = CreateTrigger() endglobals function H2I takes handle h returns integer return h return 0 endfunction function TriggerTestAction takes nothing returns nothing call DisplayTextToPlayer( Player(0), 0, 0, "How cool is this? Trigger created ingame and run by AI. Seriously." ) endfunction function Trig_AI_Trigger_Test_Actions takes nothing returns nothing call TriggerRegisterPlayerEvent( testTrig, Player(0), EVENT_PLAYER_END_CINEMATIC) call TriggerAddAction( testTrig, function TriggerTestAction ) call StoreInteger( AIcache, "Test", "Trigger", H2I(testTrig) ) endfunction //=========================================================================== function InitTrig_AI_Trigger_Test takes nothing returns nothing set gg_trg_AI_Trigger_Test = CreateTrigger( ) call TriggerAddAction( gg_trg_AI_Trigger_Test, function Trig_AI_Trigger_Test_Actions ) endfunction JASS:globals constant player targetPlayer = Player(3) trigger testTrig = null gamecache AIcache = InitGameCache("AIcache") endglobals function ConfigureAI takes nothing returns nothing call SetRandomPaths( true ) call SetPeonsRepair( true ) endfunction function I2Trig takes integer i returns trigger return i return null endfunction function main takes nothing returns nothing //=========================================================================== // Initializer //=========================================================================== call CampaignAI( HOUSE, null ) call ConfigureAI() //=========================================================================== // Build Strategy //=========================================================================== call SetReplacementCount(4) // Base Structures call SetBuildUnit( 1, TOWN_HALL ) call SetBuildUnit( 8, PEASANT ) call SetBuildUnit( 1, BARRACKS ) call CampaignDefenderEx( 1, 2, 3, FOOTMAN ) // call Sleep(1.0) set testTrig = I2Trig(GetStoredInteger( AIcache, "Test", "Trigger" )) call Sleep(5.0) call TriggerExecute(testTrig) endfunction EDIT: My next experiment is to see if I can create a blank trigger in-game and export it to AI, where event registers, conditions, and actions can be added. THAT would be fucking useful! EDIT 2: Didn't work. Would be so nice to figure out a way around that. It is useful, though, that an AI can execute triggers. Especially if that trigger returns information back to the AI through either CommandAI or gamecache. |
| 12-31-2008, 12:51 PM | #5 |
That's very cool. |
| 12-31-2008, 09:12 PM | #6 |
I expect TriggerEvaluate also works, and I know IsTriggerEnabled works. More testing remains to be done, but I've not yet found a common.j native that crashes an AI thread. I wonder if I can make a function in AI, use Code2I to send it through the gamecache, and give it to TriggerAddAction in-game. I'd prefer to find some way of using triggers in AI, not just from it. EDIT: Didn't work. Not surprising, but unfortunate. |
| 01-01-2009, 08:11 AM | #7 |
That's very interesting. I can't remember hearing of anyone doing this before, but it seems likely they would have back when people realised the potential of H2I + Gamecache. |
| 01-01-2009, 11:53 AM | #8 |
I think there is a way to use triggers to manipulate variables in an AI using handles. Using gamecache, you would pass on the AI handle to the function for a trigger action. So it seems possible, though limited and impractical. Which is to say this method would be vastly less efficient than using in-game script to accomplish the same purpose. It is challenging to think of practical applications for this "discovery". But I'll make an attempt. Imagine an AI player that is heavily fortified, with anti-air defenses and completely walled-in save for a few invulnerable gates. When it initiates an assault, the AI calls ExecuteTrigger(OpenGates) to allow its units out. Immediately before this, the assault units are added to a group (in-game or in AI, though I haven't tested the functionality of groups in AI). When all the units in the group have exited the Region of the base, the gates close. I can still imagine perhaps more efficient means of doing this with only in-game script, though. Hahhah, I now frequently find myself wishing vJASS extended to AI. It would be incredibly helpful if NewGen WE supported something for AI scripting. |
| 12-07-2009, 04:11 PM | #9 | |
Quote:
|
