Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
sheltersite.c
Go to the documentation of this file.
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 
6  void ShelterSite()
7  {
8  }
9 
10  override string GetConstructionKitType()
11  {
12  return "ShelterKit";
13  }
14 
15  override int GetMeleeTargetType()
16  {
17  return EMeleeTargetType.NONALIGNABLE;
18  }
19 
20  //--- CONSTRUCTION KIT
21  override vector GetKitSpawnPosition()
22  {
23  if ( MemoryPointExists( "kit_spawn_position" ) )
24  {
25  vector position;
26  position = GetMemoryPointPos( "kit_spawn_position" );
27 
28  return ModelToWorld( position );
29  }
30 
31  return GetPosition();
32  }
33 
34  //--- BUILD EVENTS
35  //CONSTRUCTION EVENTS
36  override void OnPartBuiltServer( notnull Man player, string part_name, int action_id )
37  {
38  ConstructionPart constrution_part = GetConstruction().GetConstructionPart( part_name );
39 
40  string shelter_type = "";
41  switch (part_name)
42  {
43  case "leather":
44  shelter_type = "ShelterLeather";
45  break;
46 
47  case "fabric":
48  shelter_type = "ShelterFabric";
49  break;
50 
51  case "stick":
52  shelter_type = "ShelterStick";
53  break;
54 
55  default: {};
56  }
57 
58  if (shelter_type != "")
59  {
60  GetConstruction().DropNonUsableMaterialsServer( player, part_name );
61  MiscGameplayFunctions.TurnItemIntoItem(this, shelter_type, PlayerBase.Cast(player));
62 
63  PluginAdminLog admin_log = PluginAdminLog.Cast( GetPlugin(PluginAdminLog) );
64  if (admin_log)
65  {
66  string playerPrefix = admin_log.GetPlayerPrefix(PlayerBase.Cast(player), player.GetIdentity());
67  admin_log.DirectAdminLogPrint(playerPrefix +" built " + shelter_type + " with Hands ");
68  }
69  }
70  //super.OnPartBuiltServer( part_name, action_id );
71  }
72 
73  override bool CanPutIntoHands( EntityAI parent )
74  {
75  return false;
76  }
77 
78  override bool CanBeRepairedToPristine()
79  {
80  return true;
81  }
82 
83  override bool CanUseHandConstruction()
84  {
85  return true;
86  }
87 
88  override bool MustBeBuiltFromOutside()
89  {
90  return true;
91  }
92 
93  override bool IsFacingCamera( string selection )
94  {
95  vector ref_dir = GetDirection();
96  vector cam_dir = GetGame().GetCurrentCameraDirection();
97 
98  //ref_dir = GetGame().GetCurrentCameraPosition() - GetPosition();
99  ref_dir.Normalize();
100  ref_dir[1] = 0; //ignore height
101 
102  cam_dir.Normalize();
103  cam_dir[1] = 0; //ignore height
104 
105  if ( ref_dir.Length() != 0 )
106  {
107  float angle = Math.Acos( cam_dir * ref_dir );
108 
109  if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
110  {
111  return true;
112  }
113  }
114 
115  return false;
116  }
117 
118  override bool IsPlayerInside( PlayerBase player, string selection )
119  {
120  vector player_pos = player.GetPosition();
121  vector object_pos = GetPosition();
122  vector ref_dir = GetDirection();
123  ref_dir[1] = 0;
124  ref_dir.Normalize();
125 
126  vector min,max;
127  min = -GetMemoryPointPos( "BoundingBox_min" );
128  max = -GetMemoryPointPos( "BoundingBox_max" );
129 
130  vector dir_to_object = object_pos - player_pos;
131  dir_to_object[1] = 0;
132  float len = dir_to_object.Length();
133 
134  dir_to_object.Normalize();
135 
136  vector ref_dir_angle = ref_dir.VectorToAngles();
137  vector dir_to_object_angle = dir_to_object.VectorToAngles();
138  vector test_angles = dir_to_object_angle - ref_dir_angle;
139 
140  vector test_position = test_angles.AnglesToVector() * len;
141 
142  if(test_position[0] > max[0] || test_position[0] < min[0] || test_position[2] > max[2] || test_position[2] < min[2] )
143  {
144  return false;
145  }
146 
147  return true;
148  }
149 
150  override bool HasProperDistance( string selection, PlayerBase player )
151  {
152  if ( MemoryPointExists( selection ) )
153  {
154  vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
155  float distance = vector.Distance( selection_pos, player.GetPosition() );
156  if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
157  {
158  return false;
159  }
160  }
161 
162  return true;
163  }
164 
165  override void SetActions()
166  {
167  super.SetActions();
168 
173  }
174 }
GetGame
proto native CGame GetGame()
OnPartBuiltServer
void OnPartBuiltServer(notnull Man player, string part_name, int action_id)
Definition: basebuildingbase.c:554
ActionBuildShelter
Definition: actionbuildshelter.c:1
ActionPlaceObject
Definition: actionplaceobject.c:9
ActionFoldBaseBuildingObject
ActionFoldBaseBuildingObjectCB ActionContinuousBaseCB ActionFoldBaseBuildingObject()
Definition: actionfoldbasebuildingobject.c:11
GetConstructionKitType
protected string GetConstructionKitType()
Definition: basebuildingbase.c:375
HasProperDistance
bool HasProperDistance(string selection, PlayerBase player)
Definition: basebuildingbase.c:969
IsFacingCamera
bool IsFacingCamera(string selection)
Definition: basebuildingbase.c:957
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
MustBeBuiltFromOutside
bool MustBeBuiltFromOutside()
Some buildings can only be built from outside.
Definition: basebuildingbase.c:951
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
GetKitSpawnPosition
protected vector GetKitSpawnPosition()
Definition: basebuildingbase.c:370
PlayerBase
Definition: playerbaseclient.c:1
CanPutIntoHands
override bool CanPutIntoHands(EntityAI parent)
Definition: explosivesbase.c:257
vector
Definition: enconvert.c:105
BaseBuildingBase
Definition: fence.c:1
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetActions
void SetActions()
Definition: advancedcommunication.c:79
GetConstruction
Construction GetConstruction()
Definition: basebuildingbase.c:888
ConstructionPart
Definition: constructionpart.c:1
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5
IsPlayerInside
override bool IsPlayerInside(PlayerBase player, string selection)
Definition: basebuildingbase.c:945
EMeleeTargetType
EMeleeTargetType
Definition: emeleetargettype.c:1