quantumstate Posted September 19, 2011 Report Share Posted September 19, 2011 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/265ucAb2The 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. Quote Link to comment Share on other sites More sharing options...
historic_bruno Posted September 21, 2011 Report Share Posted September 21, 2011 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/265ucAb2The 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.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). Quote Link to comment Share on other sites More sharing options...
quantumstate Posted September 21, 2011 Author Report Share Posted September 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
historic_bruno Posted September 21, 2011 Report Share Posted September 21, 2011 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 Quote Link to comment Share on other sites More sharing options...
quantumstate Posted September 21, 2011 Author Report Share Posted September 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.