treasureIGC.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: treasureIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CtreasureIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // treasureIGC.h : Declaration of the CtreasureIGC
  15. #ifndef __TRESUREIGC_H_
  16. #define __TRESUREIGC_H_
  17. #include "modelIGC.h"
  18. class CtreasureIGC : public TmodelIGC<ItreasureIGC>
  19. {
  20. public:
  21. // IbaseIGC
  22. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int length);
  23. virtual void Terminate(void)
  24. {
  25. AddRef();
  26. GetMyMission()->DeleteTreasure(this);
  27. TmodelIGC<ItreasureIGC>::Terminate();
  28. if (m_buyable)
  29. {
  30. m_buyable->Release();
  31. m_buyable = NULL;
  32. }
  33. Release();
  34. }
  35. virtual void Update(Time now);
  36. virtual int Export(void* data) const;
  37. virtual ObjectType GetObjectType(void) const
  38. {
  39. return OT_treasure;
  40. }
  41. virtual ObjectID GetObjectID(void) const
  42. {
  43. return m_data.objectID;
  44. }
  45. // ImodelIGC
  46. virtual void SetCluster(IclusterIGC* cluster)
  47. {
  48. AddRef();
  49. //Overrride the model's cluster method so that we can maintain the cluster's treasure list
  50. //(as well as letting the model maintain its model list)
  51. {
  52. IclusterIGC* c = GetCluster();
  53. if (c)
  54. c->DeleteTreasure(this);
  55. }
  56. TmodelIGC<ItreasureIGC>::SetCluster(cluster);
  57. if (cluster)
  58. cluster->AddTreasure(this);
  59. Release();
  60. }
  61. virtual void HandleCollision(Time timeCollision,
  62. float tCollision,
  63. const CollisionEntry& entry,
  64. ImodelIGC* pModel)
  65. {
  66. if (pModel->GetObjectType() == OT_ship)
  67. {
  68. //A treasure hitting a ship ... can the ship pick treasures up?
  69. if ((((IshipIGC*)pModel)->GetPilotType() >= c_ptPlayer) &&
  70. ((IshipIGC*)pModel)->GetBaseHullType()->HasCapability(c_habmRescue))
  71. {
  72. //yes ...let the gamesite deal with it.
  73. IIgcSite* igc = GetMyMission()->GetIgcSite();
  74. if (igc->HitTreasureEvent(timeCollision,
  75. (IshipIGC*)pModel,
  76. this))
  77. {
  78. igc->KillTreasureEvent(this);
  79. }
  80. }
  81. }
  82. else if (pModel->GetAttributes() & c_mtStatic)
  83. {
  84. GetMyMission()->GetIgcSite()->KillTreasureEvent(this);
  85. }
  86. }
  87. // ItreasureIGC
  88. virtual TreasureCode GetTreasureCode(void) const
  89. {
  90. return m_data.treasureCode;
  91. }
  92. virtual IbuyableIGC* GetBuyable(void) const
  93. {
  94. return m_buyable;
  95. }
  96. virtual ObjectID GetTreasureID(void) const
  97. {
  98. return m_data.treasureID;
  99. }
  100. virtual void SetTreasureID(ObjectID newVal)
  101. {
  102. m_data.treasureID = newVal;
  103. }
  104. virtual short GetAmount(void) const
  105. {
  106. return m_data.amount;
  107. }
  108. virtual void SetAmount(short a)
  109. {
  110. m_data.amount = a;
  111. }
  112. virtual void ResetExpiration(Time now)
  113. {
  114. m_expire = now + m_data.lifespan;
  115. }
  116. virtual void SetCreateNow (void)
  117. {
  118. m_data.createNow = true;
  119. }
  120. private:
  121. DataTreasureIGC m_data;
  122. IbuyableIGC* m_buyable;
  123. Time m_expire;
  124. float m_speed0;
  125. bool m_stationaryF;
  126. };
  127. #endif //__TRESUREIGC_H_