IAGCSectorImpl.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef __IAGCSectorImpl_h__
  2. #define __IAGCSectorImpl_h__
  3. /////////////////////////////////////////////////////////////////////////////
  4. // IAGCSectorImpl.h : Declaration of the IAGCSectorImpl class template.
  5. #include "IAGCBaseImpl.h"
  6. #include "AGCChat.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // Interface Map Macro
  9. //
  10. // Classes derived from IAGCSectorImpl should include this macro in their
  11. // interface maps.
  12. //
  13. #define COM_INTERFACE_ENTRIES_IAGCSectorImpl() \
  14. COM_INTERFACE_ENTRY(IAGCSector) \
  15. COM_INTERFACE_ENTRY(IDispatch) \
  16. COM_INTERFACE_ENTRIES_IAGCBaseImpl()
  17. /////////////////////////////////////////////////////////////////////////////
  18. // IAGCSectorImpl
  19. //
  20. template <class T, class IGC, class ITF, const GUID* plibid>
  21. class ATL_NO_VTABLE IAGCSectorImpl :
  22. public IAGCBaseImpl<T, IGC, ITF, plibid, IclusterIGC, IAGCSector>
  23. {
  24. // Types
  25. public:
  26. typedef IAGCSectorImpl<T, IGC, ITF, plibid> IAGCSectorImplBase;
  27. // IAGCSector Interface Methods
  28. public:
  29. STDMETHODIMP get_Name(BSTR* pbstr)
  30. {
  31. if (!GetIGC())
  32. return T::Error("Sector not initialized");
  33. assert(GetIGC());
  34. CComBSTR bstrTemp(GetIGC()->GetName());
  35. CLEAROUT(pbstr, (BSTR)bstrTemp);
  36. bstrTemp.Detach();
  37. return S_OK;
  38. }
  39. STDMETHODIMP get_Stations(IAGCStations** ppStations)
  40. {
  41. assert(GetIGC());
  42. assert(GetIGC()->GetStations());
  43. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetStations(),
  44. IID_IAGCStations, (void**)ppStations);
  45. }
  46. STDMETHODIMP get_Ships(IAGCShips** ppShips)
  47. {
  48. assert(GetIGC());
  49. assert(GetIGC()->GetShips());
  50. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetShips(), IID_IAGCShips,
  51. (void**)ppShips);
  52. }
  53. STDMETHODIMP get_Alephs(IAGCAlephs** ppAlephs)
  54. {
  55. assert(GetIGC());
  56. assert(GetIGC()->GetWarps());
  57. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetWarps(), IID_IAGCAlephs,
  58. (void**)ppAlephs);
  59. }
  60. STDMETHODIMP get_Asteroids(IAGCAsteroids** ppAsteroids)
  61. {
  62. assert(GetIGC());
  63. assert(GetIGC()->GetAsteroids());
  64. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetAsteroids(),
  65. IID_IAGCAsteroids, (void**)ppAsteroids);
  66. }
  67. STDMETHODIMP get_ScreenX(float * pVal)
  68. {
  69. assert(GetIGC());
  70. CLEAROUT(pVal, GetIGC()->GetScreenX());
  71. return S_OK;
  72. }
  73. STDMETHODIMP get_ScreenY(float * pVal)
  74. {
  75. assert(GetIGC());
  76. CLEAROUT(pVal, GetIGC()->GetScreenY());
  77. return S_OK;
  78. }
  79. ///////////////////////////////////////////////////////////////////////////
  80. STDMETHODIMP SendChat(BSTR bstrText, VARIANT_BOOL bIncludeEnemies,
  81. AGCSoundID idSound)
  82. {
  83. assert(GetIGC());
  84. assert(GetIGC()->GetMission()->GetIgcSite());
  85. // Do nothing if string is empty
  86. if (!BSTRLen(bstrText))
  87. return S_FALSE;
  88. // Determine the specified chat recipient
  89. ChatTarget eRecipient = bIncludeEnemies ?
  90. CHAT_ALL_SECTOR : CHAT_FRIENDLY_SECTOR;
  91. // Send the chat
  92. USES_CONVERSION;
  93. GetIGC()->GetMission()->GetIgcSite()->SendChat(NULL, eRecipient,
  94. GetIGC()->GetObjectID(), idSound, OLE2CA(bstrText), c_cidNone, NA, NA, NULL, true);
  95. // Indicate success
  96. return S_OK;
  97. }
  98. ///////////////////////////////////////////////////////////////////////////
  99. STDMETHODIMP SendCommand(BSTR bstrCommand, IAGCModel* pModelTarget,
  100. VARIANT_BOOL bIncludeEnemies, AGCSoundID idSound)
  101. {
  102. assert(GetIGC());
  103. assert(GetIGC()->GetMission()->GetIgcSite());
  104. // Convert the command string to a command ID
  105. CommandID idCmd;
  106. RETURN_FAILED(FindCommandName(bstrCommand, &idCmd, T::GetObjectCLSID(),
  107. IID_IAGCSector));
  108. // Verify that the specified model supports IAGCPrivate
  109. IAGCPrivatePtr spPrivate(pModelTarget);
  110. if (NULL == spPrivate)
  111. return E_INVALIDARG;
  112. // Get the target's IGC pointer
  113. ImodelIGC* pModel = reinterpret_cast<ImodelIGC*>(spPrivate->GetIGCVoid());
  114. // Determine the specified chat recipient
  115. ChatTarget eRecipient = bIncludeEnemies ?
  116. CHAT_ALL_SECTOR : CHAT_FRIENDLY_SECTOR;
  117. // Send the chat
  118. GetIGC()->GetMission()->GetIgcSite()->SendChat(NULL, eRecipient,
  119. GetIGC()->GetObjectID(), idSound, "", idCmd, pModel->GetObjectType(),
  120. pModel->GetObjectID(), pModel, true);
  121. // Indicate success
  122. return S_OK;
  123. }
  124. STDMETHODIMP get_Mines(IAGCModels** ppMines)
  125. {
  126. assert(GetIGC());
  127. assert(GetIGC()->GetMines());
  128. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetMines(),
  129. IID_IAGCModels, (void**)ppMines);
  130. }
  131. STDMETHODIMP get_Missiles(IAGCModels** ppMissiles)
  132. {
  133. assert(GetIGC());
  134. assert(GetIGC()->GetMissiles());
  135. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetMissiles(),
  136. IID_IAGCModels, (void**)ppMissiles);
  137. }
  138. STDMETHODIMP get_Probes(IAGCProbes** ppProbes)
  139. {
  140. assert(GetIGC());
  141. assert(GetIGC()->GetProbes());
  142. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetProbes(),
  143. IID_IAGCProbes, (void**)ppProbes);
  144. }
  145. STDMETHODIMP get_Models(IAGCModels** ppModels)
  146. {
  147. assert(GetIGC());
  148. assert(GetIGC()->GetModels());
  149. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetModels(),
  150. IID_IAGCModels, (void**)ppModels);
  151. }
  152. STDMETHODIMP get_SelectableModels(IAGCModels** ppModels)
  153. {
  154. assert(GetIGC());
  155. assert(GetIGC()->GetPickableModels());
  156. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetPickableModels(),
  157. IID_IAGCModels, (void**)ppModels);
  158. }
  159. STDMETHODIMP get_Treasures(IAGCModels** ppTreasures)
  160. {
  161. assert(GetIGC());
  162. assert(GetIGC()->GetTreasures());
  163. return GetAGCGlobal()->GetAGCObject(GetIGC()->GetTreasures(),
  164. IID_IAGCModels, (void**)ppTreasures);
  165. }
  166. };
  167. /////////////////////////////////////////////////////////////////////////////
  168. #endif //__IAGCSectorImpl_h__