Dayz Explorer 1.29.162510
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
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 = g_Game.GetCurrentCameraDirection();
97
98 //ref_dir = g_Game.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
169 AddAction(ActionTogglePlaceObject);
172 AddAction(ActionBuildShelter);
173 }
174}
class LogManager EntityAI
ActionFoldBaseBuildingObjectCB ActionContinuousBaseCB ActionFoldBaseBuildingObject()
ActionPlaceObjectCB ActiondeployObjectCB ActionPlaceObject()
void AddAction(typename actionName)
Construction GetConstruction()
bool MustBeBuiltFromOutside()
Some buildings can only be built from outside.
override bool IsPlayerInside(PlayerBase player, string selection)
Definition fence.c:615
override string GetConstructionKitType()
Definition fence.c:45
override bool CanPutIntoHands(EntityAI parent)
Definition fence.c:406
override void OnPartBuiltServer(notnull Man player, string part_name, int action_id)
Definition fence.c:297
override void SetActions()
Definition fence.c:825
override bool IsFacingCamera(string selection)
Definition fence.c:678
override int GetMeleeTargetType()
Definition fence.c:50
override bool HasProperDistance(string selection, PlayerBase player)
Definition fence.c:703
override vector GetKitSpawnPosition()
Definition fence.c:162
override bool CanBeRepairedToPristine()
Definition fence.c:421
DayZGame g_Game
Definition dayzgame.c:3942
EMeleeTargetType
vector GetPosition()
Get the world position of the Effect.
Definition effect.c:473
PluginBase GetPlugin(typename plugin_type)