treasuresetigc.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: treasureSetIGC.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the CtreasureSetIGC class. This file was initially created by
  10. ** the ATL wizard for the core object.
  11. **
  12. ** History:
  13. */
  14. // treasureSetIGC.cpp : Implementation of CtreasureSetIGC
  15. #include "pch.h"
  16. #include "treasureSetIGC.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CtreasureSetIGC
  19. HRESULT CtreasureSetIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
  20. {
  21. assert (pMission);
  22. m_pMission = pMission;
  23. ZRetailAssert (data && (dataSize >= sizeof(DataTreasureSetIGC)));
  24. int size;
  25. if (((DataTreasureSetIGC*)data)->nTreasureData == 0)
  26. {
  27. assert (dataSize == sizeof(DataTreasureSetIGC));
  28. const short c_maxDefault = 10;
  29. m_maxTreasureData = c_maxDefault;
  30. size = sizeof(DataTreasureSetIGC) +
  31. c_maxDefault * sizeof(TreasureData);
  32. }
  33. else
  34. {
  35. m_maxTreasureData = ((DataTreasureSetIGC*)data)->nTreasureData;
  36. assert (dataSize == int(sizeof(DataTreasureSetIGC) +
  37. m_maxTreasureData *
  38. sizeof(TreasureData)));
  39. size = dataSize;
  40. }
  41. assert (size >= dataSize);
  42. m_data = (DataTreasureSetIGC*)(new char [size]);
  43. memcpy(m_data, data, dataSize);
  44. m_totalTreasureChance = 0;
  45. {
  46. TreasureData* ptd = m_data->treasureData0();
  47. for (short i = 0; (i < m_data->nTreasureData); i++)
  48. m_totalTreasureChance += (ptd + i)->chance;
  49. }
  50. pMission->AddTreasureSet(this);
  51. return S_OK;
  52. }
  53. int CtreasureSetIGC::Export(void* data) const
  54. {
  55. int size = sizeof(DataTreasureSetIGC) + sizeof(TreasureData) *
  56. m_data->nTreasureData;
  57. if (data)
  58. memcpy(data, m_data, size);
  59. return size;
  60. }