cargo.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**@class CargoBase
  2. * @brief represents base for cargo storage for entities
  3. *
  4. * @NOTE: rows == y axis
  5. **/
  6. class CargoBase : Managed
  7. {
  8. /**@fn GetCargoOwner
  9. * @brief get the entity that owns the cargo
  10. * @return cargo owner
  11. **/
  12. proto native EntityAI GetCargoOwner ();
  13. /**@fn GetCargoOwnerIndex
  14. * @brief get index of this cargo in the entity that owns the cargo
  15. * @return owner's index of this cargo
  16. **/
  17. proto native int GetOwnerCargoIndex ();
  18. /**@fn IsProxyCargo
  19. * @return true if cargo is in proxy object
  20. **/
  21. proto native bool IsProxyCargo ();
  22. /**@fn GetItemCount
  23. * @return number of items in cargo
  24. **/
  25. proto native int GetItemCount ();
  26. /**@fn GetItem
  27. * @return get item at specific index
  28. **/
  29. proto native EntityAI GetItem (int index);
  30. /**@fn GetWidth
  31. * @return width of the cargo
  32. **/
  33. proto native int GetWidth ();
  34. /**@fn GetHeight
  35. * @return height of the cargo
  36. **/
  37. proto native int GetHeight ();
  38. /**@fn GetItemRowCol
  39. * @param[out] row returned row of the item at internal index
  40. * @param[out] col returned col. 0 on xbox
  41. **/
  42. proto bool GetItemRowCol (int index, out int row, out int col);
  43. /**@fn GetItemSize
  44. * @param[out] w returned width of the item at internal index
  45. * @param[out] h returned height of the item at internal index
  46. **/
  47. proto bool GetItemSize (int index, out int w, out int h);
  48. /**@fn FindEntityInCargo
  49. * @return find internal index of the entity in cargo or -1 if not found
  50. **/
  51. proto native int FindEntityInCargo (notnull EntityAI e);
  52. private void CargoBase ();
  53. private void ~CargoBase ();
  54. /**@fn CanReceiveItemIntoCargo
  55. * @brief condition EntityAI::CanReceiveItemIntoCargo for Cargo.
  56. * @return true if cargo can be added, false otherwise
  57. **/
  58. bool CanReceiveItemIntoCargo (EntityAI item) { return true; }
  59. /**@fn CanSwapItemInCargo
  60. * @brief condition EntityAI::CanSwapItemInCargo for Cargo.
  61. * @return true if cargo can be added, false otherwise
  62. **/
  63. bool CanSwapItemInCargo (EntityAI child_entity, EntityAI new_entity) { return true; }
  64. proto native int GetUserReservedLocationCount ();
  65. /**@fn GetUserReservedLocation
  66. * @param[in] idx index of the user reserved location
  67. * @param[out] eai returned entity of the user reservation at internal index
  68. * @param[out] row returned row of the user reservation at internal index
  69. * @param[out] col returned col
  70. * @param[out] w returned width of the user reservation at internal index
  71. * @param[out] h returned height of the user reservation at internal index
  72. * @param[out] flp returned flip
  73. * @return true if record found, false otherwise
  74. **/
  75. proto bool GetUserReservedLocation (int index, out EntityAI eai, out int row, out int col, out int w, out int h, out int flp);
  76. proto native void SetUserReservedLocation (notnull EntityAI eai);
  77. proto native void ClearUserReservedLocation (notnull EntityAI eai);
  78. };
  79. #ifdef PLATFORM_CONSOLE
  80. class CargoList : CargoBase
  81. {
  82. /**@fn GetMaxWeight
  83. * @return maximum weight that the cargo can hold
  84. **/
  85. proto native int GetMaxWeight ();
  86. /**@fn GetTotalWeight
  87. * @brief sums weight of all items in cargo and adds weight of item if item != null
  88. * @return sum of weights plus weight of item (if !null)
  89. **/
  90. proto native int GetTotalWeight (EntityAI item);
  91. /**@fn CanFitItemIntoCargo
  92. * @return true if adding item does not exceed GetMaxWeight, false otherwise
  93. **/
  94. proto native bool CanFitItemIntoCargo (EntityAI cargo);
  95. /**@fn CanReceiveItemIntoCargo
  96. * @return true if adding item does not exceed GetMaxWeight, false otherwise
  97. **/
  98. override bool CanReceiveItemIntoCargo (EntityAI item)
  99. {
  100. return true;
  101. //return CanFitItemIntoCargo(item);
  102. }
  103. /**@fn CanFitSwappedItemInCargo
  104. * @return true if swapping item does not exceed GetMaxWeight, false otherwise
  105. **/
  106. proto native bool CanFitSwappedItemInCargo (EntityAI child_entity, EntityAI new_entity);
  107. override bool CanSwapItemInCargo (EntityAI child_entity, EntityAI new_entity)
  108. {
  109. return CanFitSwappedItemInCargo(child_entity, new_entity);
  110. }
  111. };
  112. #else
  113. #ifdef SERVER_FOR_CONSOLE
  114. class CargoList : CargoBase
  115. {
  116. /**@fn GetMaxWeight
  117. * @return maximum weight that the cargo can hold
  118. **/
  119. proto native int GetMaxWeight ();
  120. /**@fn GetTotalWeight
  121. * @brief sums weight of all items in cargo and adds weight of item if item != null
  122. * @return sum of weights plus weight of item (if !null)
  123. **/
  124. proto native int GetTotalWeight (EntityAI item);
  125. /**@fn CanFitItemIntoCargo
  126. * @return true if adding item does not exceed GetMaxWeight, false otherwise
  127. **/
  128. proto native bool CanFitItemIntoCargo (EntityAI cargo);
  129. /**@fn CanReceiveItemIntoCargo
  130. * @return true if adding item does not exceed GetMaxWeight, false otherwise
  131. **/
  132. override bool CanReceiveItemIntoCargo (EntityAI item)
  133. {
  134. return true;
  135. //return CanFitItemIntoCargo(item);
  136. }
  137. /**@fn CanFitSwappedItemInCargo
  138. * @return true if swapping item does not exceed GetMaxWeight, false otherwise
  139. **/
  140. proto native bool CanFitSwappedItemInCargo (EntityAI child_entity, EntityAI new_entity);
  141. override bool CanSwapItemInCargo (EntityAI child_entity, EntityAI new_entity)
  142. {
  143. return CanFitSwappedItemInCargo(child_entity, new_entity);
  144. }
  145. };
  146. #else
  147. class CargoGrid : CargoBase
  148. {
  149. /**@fn FindEntityInCargoOn
  150. * @return get item at coordinates (row, col). col is 0 on xbox.
  151. **/
  152. proto native EntityAI FindEntityInCargoOn (int row, int col);
  153. };
  154. #endif
  155. #endif