Advertisement
Guest User

0AD AI territories

a guest
Sep 19th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.12 KB | None | 0 0
  1. Index: CCmpAIManager.cpp
  2. ===================================================================
  3. --- CCmpAIManager.cpp   (revision 10297)
  4. +++ CCmpAIManager.cpp   (working copy)
  5. @@ -34,6 +34,7 @@
  6.  #include "simulation2/components/ICmpObstructionManager.h"
  7.  #include "simulation2/components/ICmpRangeManager.h"
  8.  #include "simulation2/components/ICmpTemplateManager.h"
  9. +#include "simulation2/components/ICmpTerritoryManager.h"
  10.  #include "simulation2/helpers/Grid.h"
  11.  #include "simulation2/serialization/DebugSerializer.h"
  12.  #include "simulation2/serialization/StdDeserializer.h"
  13. @@ -286,7 +287,7 @@
  14.         return true;
  15.     }
  16.  
  17. -   void StartComputation(const shared_ptr<ScriptInterface::StructuredClone>& gameState, const Grid<u16>& map)
  18. +   void StartComputation(const shared_ptr<ScriptInterface::StructuredClone>& gameState, const Grid<u16>& map, const Grid<u8>& territoryMap)
  19.     {
  20.         ENSURE(m_CommandsComputed);
  21.  
  22. @@ -300,6 +301,25 @@
  23.             m_GameStateMapVal = CScriptValRooted(cx, ScriptInterface::ToJSVal(cx, m_GameStateMap));
  24.         }
  25.  
  26. +       if (true) //territoryMap.m_DirtyID != m_TerritoryMap.m_DirtyID) couldn't manage to get this working the ID's always matched
  27. +       {
  28. +           PROFILE("territoryMap");
  29. +           m_TerritoryMap = territoryMap;
  30. +
  31. +           // The ToJSVal function can't take Grid<u8> so convert.
  32. +           Grid<u16>* tmp = new Grid<u16>(territoryMap.m_W, territoryMap.m_H);
  33. +
  34. +           for (u16 i = 0; i < tmp->m_W; i++){
  35. +               for (u16 j = 0; j < tmp->m_W; j++){
  36. +                   tmp->set(i,j, u16(territoryMap.get(i,j)));
  37. +               }
  38. +           }
  39. +
  40. +           JSContext* cx = m_ScriptInterface.GetContext();
  41. +           m_TerritoryMapVal = CScriptValRooted(cx, ScriptInterface::ToJSVal(cx, *tmp));
  42. +       }
  43. +
  44. +
  45.         m_CommandsComputed = false;
  46.     }
  47.  
  48. @@ -427,12 +447,14 @@
  49.  
  50.     void PerformComputation()
  51.     {
  52. +
  53.         // Deserialize the game state, to pass to the AI's HandleMessage
  54.         CScriptVal state;
  55.         {
  56.             PROFILE("AI compute read state");
  57.             state = m_ScriptInterface.ReadStructuredClone(m_GameState);
  58.             m_ScriptInterface.SetProperty(state.get(), "map", m_GameStateMapVal, true);
  59. +           m_ScriptInterface.SetProperty(state.get(), "territoryMap", m_TerritoryMapVal, true);
  60.         }
  61.  
  62.         // It would be nice to do
  63. @@ -469,6 +491,8 @@
  64.     shared_ptr<ScriptInterface::StructuredClone> m_GameState;
  65.     Grid<u16> m_GameStateMap;
  66.     CScriptValRooted m_GameStateMapVal;
  67. +   Grid<u8> m_TerritoryMap;
  68. +   CScriptValRooted m_TerritoryMapVal;
  69.  
  70.     bool m_CommandsComputed;
  71.  };
  72. @@ -575,9 +599,15 @@
  73.         if (!cmpPathfinder.null())
  74.             map = &cmpPathfinder->GetPassabilityGrid();
  75.  
  76. +       Grid<u8> dummyGrid2;
  77. +       const Grid<u8>* territoryMap = &dummyGrid2;
  78. +       CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY);
  79. +       if (!cmpTerritoryManager.null())// || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID)) - Don't think this is appropriate here so have ignored it
  80. +           territoryMap = &cmpTerritoryManager->GetTerritoryGrid();
  81. +
  82.         LoadPathfinderClasses(state);
  83.  
  84. -       m_Worker.StartComputation(scriptInterface.WriteStructuredClone(state.get()), *map);
  85. +       m_Worker.StartComputation(scriptInterface.WriteStructuredClone(state.get()), *map, *territoryMap);
  86.     }
  87.  
  88.     virtual void PushCommands()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement