pileofwoodenplanks.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. class PileOfWoodenPlanks extends ItemBase
  2. {
  3. void PileOfWoodenPlanks()
  4. {
  5. if ( GetGame().IsServer() )
  6. {
  7. SetAllowDamage(false);
  8. }
  9. }
  10. // Shows/Hides selections. Call this in init or after every quantity change.
  11. void UpdateSelections()
  12. {
  13. RemoveProxyPhysics( "stage_1" );
  14. RemoveProxyPhysics( "stage_2" );
  15. RemoveProxyPhysics( "stage_3" );
  16. // Show/Hide selections according to the current quantity
  17. if ( this )
  18. {
  19. float quantity = GetQuantity();
  20. float quantity_max = GetQuantityMax();
  21. if ( quantity > GetQuantityMax() *0.66 )
  22. {
  23. // Show 3/3 amount of planks
  24. ShowSelection ( "stage_3" );
  25. HideSelection ( "stage_2" );
  26. HideSelection ( "stage_1" );
  27. AddProxyPhysics( "stage_3" );
  28. }
  29. if ( quantity > quantity_max *0.33 && quantity <= quantity_max *0.66 )
  30. {
  31. // Show 2/3 amount of planks
  32. HideSelection ( "stage_3" );
  33. ShowSelection ( "stage_2" );
  34. HideSelection ( "stage_1" );
  35. AddProxyPhysics( "stage_2" );
  36. }
  37. if ( quantity > 0 && quantity <= quantity_max *0.33 )
  38. {
  39. // Show 1/3 amount of planks
  40. HideSelection ( "stage_3" );
  41. HideSelection ( "stage_2" );
  42. ShowSelection ( "stage_1" );
  43. AddProxyPhysics( "stage_1" );
  44. }
  45. if ( quantity == 0 )
  46. {
  47. // Show 0 planks. Object should be deleted now.
  48. HideSelection ( "stage_3" );
  49. HideSelection ( "stage_2" );
  50. HideSelection ( "stage_1" );
  51. }
  52. }
  53. }
  54. override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
  55. {
  56. super.EEItemLocationChanged(oldLoc, newLoc);
  57. UpdateSelections();
  58. }
  59. // Removes a number of long planks. Note that one (4m) long plank has the length of 3x normal planks!
  60. // Returns the number of removed long planks
  61. int RemovePlanks( int needed_planks )
  62. {
  63. // Make sure to not give more long planks than we have available
  64. int available_planks = needed_planks;
  65. if ( available_planks > GetQuantity() )
  66. {
  67. available_planks = GetQuantity();
  68. }
  69. // Remove long planks from this object
  70. AddQuantity( -available_planks, true ); // Autodelete enabled
  71. // Return the number of removed long planks
  72. return available_planks;
  73. }
  74. override bool SetQuantity(float value, bool destroy_config = true, bool destroy_forced = false, bool allow_client = false, bool clamp_to_stack_max = true)
  75. {
  76. bool result = super.SetQuantity(value, destroy_config, destroy_forced, allow_client, clamp_to_stack_max);
  77. UpdateSelections();
  78. return result;
  79. }
  80. override bool CanPutIntoHands( EntityAI parent )
  81. {
  82. return false;
  83. }
  84. override bool CanPutInCargo (EntityAI parent)
  85. {
  86. return false;
  87. }
  88. }