bucketigc.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: bucketIGC.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the CbucketIGC class. This file was initially created by
  10. ** the ATL wizard for the core object.
  11. **
  12. ** History:
  13. */
  14. // bucketIGC.cpp : Implementation of CbucketIGC
  15. #include "pch.h"
  16. #include "bucketIGC.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CbucketIGC
  19. HRESULT CbucketIGC::Initialize(ImissionIGC* pMission,
  20. Time now,
  21. const void* data,
  22. int dataSize)
  23. {
  24. assert (pMission);
  25. m_pMission = pMission;
  26. ZRetailAssert (data && (dataSize == sizeof(DataBucketIGC)));
  27. m_data = *((DataBucketIGC*)data);
  28. assert (m_data.side);
  29. m_data.side->AddRef();
  30. m_price = m_data.buyable->GetPrice();
  31. m_timeToBuild = m_data.buyable->GetTimeToBuild();
  32. //See if there is a predecessor bucket
  33. if (m_data.buyable->GetObjectType() == OT_development)
  34. {
  35. IdevelopmentIGC* pdevelopment = (IdevelopmentIGC*)(m_data.buyable);
  36. if ((!pdevelopment->GetTechOnly()) && pdevelopment->GetEffectTechs().GetAllZero())
  37. {
  38. //A tech that affects only a side's global attributes.
  39. //Check for other buckets which do exactly the same thing
  40. Money price = pdevelopment->GetPrice();
  41. const GlobalAttributeSet& gas = pdevelopment->GetGlobalAttributeSet();
  42. //Go backwards to get the last possible development
  43. for (BucketLinkIGC* pbl = m_data.side->GetBuckets()->last(); (pbl != NULL); pbl = pbl->txen())
  44. {
  45. IbucketIGC* pbucket = pbl->data();
  46. IbuyableIGC* pbuyable = pbucket->GetBuyable();
  47. if (pbuyable->GetObjectType() == OT_development)
  48. {
  49. IdevelopmentIGC* pd = (IdevelopmentIGC*)pbuyable;
  50. if ((!pd->GetTechOnly()) && (pd->GetPrice() <= price) && pd->GetEffectTechs().GetAllZero())
  51. {
  52. //Look at that ... a equally or less expensive development that affects only global attributes
  53. //do they affect the same global attributes the same way?
  54. if (pd->GetGlobalAttributeSet() == gas)
  55. {
  56. pbucket->AddRef();
  57. m_pbucketPredecessor = pbucket;
  58. break;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. if (pdevelopment->GetObjectID() != c_didTeamMoney)
  65. {
  66. m_price = (Money)(m_price * m_data.side->GetGlobalAttributeSet().GetAttribute(c_gaDevelopmentCost));
  67. m_timeToBuild = (DWORD)(m_timeToBuild * m_data.side->GetGlobalAttributeSet().GetAttribute(c_gaDevelopmentTime));
  68. }
  69. }
  70. m_data.side->AddBucket(this);
  71. assert (m_data.buyable);
  72. m_data.buyable->AddRef();
  73. m_lastUpdate = now;
  74. return S_OK;
  75. }
  76. void CbucketIGC::Terminate(void)
  77. {
  78. AddRef();
  79. assert (m_data.side);
  80. if (m_pbucketPredecessor)
  81. {
  82. m_pbucketPredecessor->Release();
  83. m_pbucketPredecessor = NULL;
  84. }
  85. m_pMission->GetIgcSite()->BucketChangeEvent(c_bcTerminated, this);
  86. assert (m_data.side);
  87. m_data.side->DeleteBucket(this);
  88. m_data.side->Release();
  89. m_data.side = NULL;
  90. assert (m_data.buyable);
  91. m_data.buyable->Release();
  92. m_data.buyable = NULL;
  93. Release();
  94. }
  95. int CbucketIGC::Export(void* data) const
  96. {
  97. return NA;
  98. }