DayZ 1.24
Loading...
Searching...
No Matches
ShelterSite.c
Go to the documentation of this file.
1class 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
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
22 {
23 if (MemoryPointExists("kit_spawn_position"))
24 {
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 {
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
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 return true;
111 }
112
113 return false;
114 }
115
116 override bool IsPlayerInside(PlayerBase player, string selection)
117 {
118 vector player_pos = player.GetPosition();
120 vector ref_dir = GetDirection();
121 ref_dir[1] = 0;
122 ref_dir.Normalize();
123
124 vector min, max;
125 min = -GetMemoryPointPos("BoundingBox_min");
126 max = -GetMemoryPointPos("BoundingBox_max");
127
129 dir_to_object[1] = 0;
130 float len = dir_to_object.Length();
131
132 dir_to_object.Normalize();
133
134 vector ref_dir_angle = ref_dir.VectorToAngles();
135 vector dir_to_object_angle = dir_to_object.VectorToAngles();
137
138 vector test_position = test_angles.AnglesToVector() * len;
139
140 if (test_position[0] > max[0] || test_position[0] < min[0] || test_position[2] > max[2] || test_position[2] < min[2])
141 return false;
142
143 return true;
144 }
145
146 override bool HasProperDistance(string selection, PlayerBase player)
147 {
148 if (MemoryPointExists(selection))
149 {
150 vector selection_pos = ModelToWorld(GetMemoryPointPos(selection));
151 float distance = vector.Distance(selection_pos, player.GetPosition());
152 if (distance >= MAX_ACTION_DETECTION_DISTANCE)
153 return false;
154 }
155
156 return true;
157 }
158
168}
ActionFoldBaseBuildingObjectCB ActionContinuousBaseCB ActionFoldBaseBuildingObject()
void AddAction(typename actionName)
Construction GetConstruction()
EMeleeTargetType
PluginBase GetPlugin(typename plugin_type)
class JsonUndergroundAreaTriggerData GetPosition
override bool IsPlayerInside(PlayerBase player, string selection)
override string GetConstructionKitType()
Definition ShelterSite.c:10
override bool CanPutIntoHands(EntityAI parent)
Definition ShelterSite.c:73
override void OnPartBuiltServer(notnull Man player, string part_name, int action_id)
Definition ShelterSite.c:36
override bool CanUseHandConstruction()
Definition ShelterSite.c:83
override void SetActions()
override bool MustBeBuiltFromOutside()
Definition ShelterSite.c:88
override bool IsFacingCamera(string selection)
Definition ShelterSite.c:93
override int GetMeleeTargetType()
Definition ShelterSite.c:15
override bool HasProperDistance(string selection, PlayerBase player)
override vector GetKitSpawnPosition()
Definition ShelterSite.c:21
override bool CanBeRepairedToPristine()
Definition ShelterSite.c:78
Definition EnMath.c:7
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
static proto float Acos(float c)
Returns angle in radians from cosinus.