containerlocked.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. class ContainerLockedBase : BuildingSuper
  2. {
  3. protected int m_LockedMask = 0;
  4. protected int m_OpeningMask = 0;
  5. void ContainerLockedBase()
  6. {
  7. int count = GetDoorCount();
  8. for (int i = 0; i < count; i++)
  9. {
  10. LockDoor(i);
  11. }
  12. }
  13. override void OnStoreSave(ParamsWriteContext ctx)
  14. {
  15. super.OnStoreSave(ctx);
  16. ctx.Write(m_LockedMask);
  17. ctx.Write(m_OpeningMask);
  18. }
  19. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  20. {
  21. if (!super.OnStoreLoad(ctx, version))
  22. return false;
  23. ctx.Read(m_LockedMask);
  24. ctx.Read(m_OpeningMask);
  25. HandleDoorLoad();
  26. return true;
  27. }
  28. protected void HandleDoorLoad()
  29. {
  30. int count = GetDoorCount();
  31. int i;
  32. //locking
  33. for (i = 0; i < count; i++)
  34. {
  35. if (m_LockedMask & (1 << i))
  36. {
  37. LockDoor(i,true);
  38. }
  39. else
  40. {
  41. UnlockDoor(i);
  42. }
  43. }
  44. //then opening
  45. for (i = 0; i < count; i++)
  46. {
  47. if (m_OpeningMask & (1 << i) && !IsDoorLocked(i))
  48. {
  49. OpenDoor(i);
  50. }
  51. }
  52. }
  53. //////////////////////////////////////////
  54. //events
  55. override void OnDoorLocked(DoorLockParams params)
  56. {
  57. super.OnDoorLocked(params);
  58. m_LockedMask |= 1 << params.param1;
  59. string selectionName = string.Format("side%1_lock",(params.param1 + 1));
  60. SetAnimationPhase(selectionName,0);
  61. }
  62. override void OnDoorUnlocked(DoorLockParams params)
  63. {
  64. super.OnDoorUnlocked(params);
  65. int doorIdx = params.param1;
  66. m_LockedMask &= ~(1 << doorIdx);
  67. string selectionName = string.Format("side%1_lock",(doorIdx + 1));
  68. SetAnimationPhase(selectionName,1);
  69. if (!GetGame().IsDedicatedServer())
  70. SEffectManager.PlaySoundEnviroment("Land_ContainerLocked_lock_SoundSet",GetDoorSoundPos(doorIdx));
  71. }
  72. override void OnDoorCloseStart(DoorStartParams params)
  73. {
  74. super.OnDoorCloseStart(params);
  75. m_OpeningMask &= ~(1 << params.param1);
  76. }
  77. override void OnDoorOpenStart(DoorStartParams params)
  78. {
  79. super.OnDoorOpenStart(params);
  80. m_OpeningMask |= 1 << params.param1;
  81. }
  82. }
  83. class Land_ContainerLocked_Blue_DE : ContainerLockedBase
  84. {
  85. override int GetLockCompatibilityType(int doorIdx)
  86. {
  87. return 1 << EBuildingLockType.SHIP_CONTAINER_0;
  88. }
  89. }
  90. class Land_ContainerLocked_Yellow_DE : ContainerLockedBase
  91. {
  92. override int GetLockCompatibilityType(int doorIdx)
  93. {
  94. return 1 << EBuildingLockType.SHIP_CONTAINER_1;
  95. }
  96. }
  97. class Land_ContainerLocked_Orange_DE : ContainerLockedBase
  98. {
  99. override int GetLockCompatibilityType(int doorIdx)
  100. {
  101. return 1 << EBuildingLockType.SHIP_CONTAINER_2;
  102. }
  103. }
  104. class Land_ContainerLocked_Red_DE : ContainerLockedBase
  105. {
  106. override int GetLockCompatibilityType(int doorIdx)
  107. {
  108. return 1 << EBuildingLockType.SHIP_CONTAINER_3;
  109. }
  110. }