Jump to content

Territory support for the AI


Recommended Posts

I've written a patch which would let AI's have a map of their territories, but my C++ knowledge is not very good and I am unfamiliar with the 0AD code base so would someone be willing to look over it?

I have put the diff at http://pastebin.com/265ucAb2

The main thing I am still having trouble with is using the DirtyID so it doesn't have to do the work every time it runs. I haven't managed to get this working at all.

Apart from this a line needs to be added to base.js (in baseAI) to pass it through to AI script but that is trivial.

The AI script gets fed something like this picture but in array form. It is similar to how the AI reads building restrictions already.

kcbdf.png

Link to comment
Share on other sites

I've written a patch which would let AI's have a map of their territories, but my C++ knowledge is not very good and I am unfamiliar with the 0AD code base so would someone be willing to look over it?

I have put the diff at http://pastebin.com/265ucAb2

The main thing I am still having trouble with is using the DirtyID so it doesn't have to do the work every time it runs. I haven't managed to get this working at all.

Apart from this a line needs to be added to base.js (in baseAI) to pass it through to AI script but that is trivial.

The AI script gets fed something like this picture but in array form. It is similar to how the AI reads building restrictions already.

kcbdf.png

Why not make a Trac ticket and add your patch? :) Looks good at a glance, I didn't test it yet. One suggestion, instead of copying the territory Grid<u8> to Grid<u16> we could just add the necessary JS conversions (source\simulation2\scripting\EngineScriptConversions.cpp) - the most flexible solution would be to use templates, as we do for arrays. No idea what's going wrong with the dirtyID.

The missing bits are (as you said) to expose the territory map to AI scripts and also to add BuildRestrictions data to the simulation state (GuiInterface.js), that way the AI can determine if a building is allowed in own, neutral, or enemy territory (for that matter diplomacy is not implemented either for the AIs, but this is a lesser point).

Link to comment
Share on other sites

Why not make a Trac ticket and add your patch? :) Looks good at a glance, I didn't test it yet. One suggestion, instead of copying the territory Grid<u8> to Grid<u16> we could just add the necessary JS conversions (source\simulation2\scripting\EngineScriptConversions.cpp) - the most flexible solution would be to use templates, as we do for arrays. No idea what's going wrong with the dirtyID.

Thanks for your feedback, I have made a ticket #969. I added some code to the JS conversions, it doesn't use templates though since that is too advanced for me.

The missing bits are (as you said) to expose the territory map to AI scripts and also to add BuildRestrictions data to the simulation state (GuiInterface.js), that way the AI can determine if a building is allowed in own, neutral, or enemy territory (for that matter diplomacy is not implemented either for the AIs, but this is a lesser point).

The AI's are given a list of allies and enemies currently.

Link to comment
Share on other sites

The AI's are given a list of allies and enemies currently.

I was looking at how to properly implement the AI's Entity.isEnemy() and Entity.isFriendly(), but I couldn't figure out how to hook up the arrays you mention. Maybe instead of being part of the the Entity class they should be somewhere else that has access to the game state. It would be nice to have that, so the AI could attack real enemies instead of massing at allies' civ centres :)

Link to comment
Share on other sites

I was looking at how to properly implement the AI's Entity.isEnemy() and Entity.isFriendly(), but I couldn't figure out how to hook up the arrays you mention. Maybe instead of being part of the the Entity class they should be somewhere else that has access to the game state. It would be nice to have that, so the AI could attack real enemies instead of massing at allies' civ centres :)

It would be easiest to just drop those functions entirely. gameState.isEntityEnemy(ent) would be pretty easy to implement using the propoer array in gameState.playerData, it would be good enough for me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...