sheltersite.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. class ShelterSite extends BaseBuildingBase
  2. {
  3. const float MAX_ACTION_DETECTION_ANGLE_RAD = 1.3; //1.3 RAD = ~75 DEG
  4. const float MAX_ACTION_DETECTION_DISTANCE = 2.0; //meters
  5. void ShelterSite()
  6. {
  7. }
  8. override string GetConstructionKitType()
  9. {
  10. return "ShelterKit";
  11. }
  12. override int GetMeleeTargetType()
  13. {
  14. return EMeleeTargetType.NONALIGNABLE;
  15. }
  16. //--- CONSTRUCTION KIT
  17. override vector GetKitSpawnPosition()
  18. {
  19. if ( MemoryPointExists( "kit_spawn_position" ) )
  20. {
  21. vector position;
  22. position = GetMemoryPointPos( "kit_spawn_position" );
  23. return ModelToWorld( position );
  24. }
  25. return GetPosition();
  26. }
  27. //--- BUILD EVENTS
  28. //CONSTRUCTION EVENTS
  29. override void OnPartBuiltServer( notnull Man player, string part_name, int action_id )
  30. {
  31. ConstructionPart constrution_part = GetConstruction().GetConstructionPart( part_name );
  32. string shelter_type = "";
  33. switch (part_name)
  34. {
  35. case "leather":
  36. shelter_type = "ShelterLeather";
  37. break;
  38. case "fabric":
  39. shelter_type = "ShelterFabric";
  40. break;
  41. case "stick":
  42. shelter_type = "ShelterStick";
  43. break;
  44. default: {};
  45. }
  46. if (shelter_type != "")
  47. {
  48. GetConstruction().DropNonUsableMaterialsServer( player, part_name );
  49. MiscGameplayFunctions.TurnItemIntoItem(this, shelter_type, PlayerBase.Cast(player));
  50. PluginAdminLog admin_log = PluginAdminLog.Cast( GetPlugin(PluginAdminLog) );
  51. if (admin_log)
  52. {
  53. string playerPrefix = admin_log.GetPlayerPrefix(PlayerBase.Cast(player), player.GetIdentity());
  54. admin_log.DirectAdminLogPrint(playerPrefix +" built " + shelter_type + " with Hands ");
  55. }
  56. }
  57. //super.OnPartBuiltServer( part_name, action_id );
  58. }
  59. override bool CanPutIntoHands( EntityAI parent )
  60. {
  61. return false;
  62. }
  63. override bool CanBeRepairedToPristine()
  64. {
  65. return true;
  66. }
  67. override bool CanUseHandConstruction()
  68. {
  69. return true;
  70. }
  71. override bool MustBeBuiltFromOutside()
  72. {
  73. return true;
  74. }
  75. override bool IsFacingCamera( string selection )
  76. {
  77. vector ref_dir = GetDirection();
  78. vector cam_dir = GetGame().GetCurrentCameraDirection();
  79. //ref_dir = GetGame().GetCurrentCameraPosition() - GetPosition();
  80. ref_dir.Normalize();
  81. ref_dir[1] = 0; //ignore height
  82. cam_dir.Normalize();
  83. cam_dir[1] = 0; //ignore height
  84. if ( ref_dir.Length() != 0 )
  85. {
  86. float angle = Math.Acos( cam_dir * ref_dir );
  87. if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
  88. {
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. override bool IsPlayerInside( PlayerBase player, string selection )
  95. {
  96. vector player_pos = player.GetPosition();
  97. vector object_pos = GetPosition();
  98. vector ref_dir = GetDirection();
  99. ref_dir[1] = 0;
  100. ref_dir.Normalize();
  101. vector min,max;
  102. min = -GetMemoryPointPos( "BoundingBox_min" );
  103. max = -GetMemoryPointPos( "BoundingBox_max" );
  104. vector dir_to_object = object_pos - player_pos;
  105. dir_to_object[1] = 0;
  106. float len = dir_to_object.Length();
  107. dir_to_object.Normalize();
  108. vector ref_dir_angle = ref_dir.VectorToAngles();
  109. vector dir_to_object_angle = dir_to_object.VectorToAngles();
  110. vector test_angles = dir_to_object_angle - ref_dir_angle;
  111. vector test_position = test_angles.AnglesToVector() * len;
  112. if(test_position[0] > max[0] || test_position[0] < min[0] || test_position[2] > max[2] || test_position[2] < min[2] )
  113. {
  114. return false;
  115. }
  116. return true;
  117. }
  118. override bool HasProperDistance( string selection, PlayerBase player )
  119. {
  120. if ( MemoryPointExists( selection ) )
  121. {
  122. vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
  123. float distance = vector.Distance( selection_pos, player.GetPosition() );
  124. if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
  125. {
  126. return false;
  127. }
  128. }
  129. return true;
  130. }
  131. override void SetActions()
  132. {
  133. super.SetActions();
  134. AddAction(ActionTogglePlaceObject);
  135. AddAction(ActionPlaceObject);
  136. AddAction(ActionFoldBaseBuildingObject);
  137. AddAction(ActionBuildShelter);
  138. }
  139. }