DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Totem.c
См. документацию.
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
11
12 protected int m_FlagRefresherFrequency = GameConstants.REFRESHER_FREQUENCY_DEFAULT; //how often does the flag increase lifetimes
13 protected int m_FlagRefresherMaxDuration = GameConstants.REFRESHER_MAX_DURATION_DEFAULT; //how long will the refresher run; multiple of m_FlagRefresherFrequency by default
14
16 {
17 m_RefresherActive = false;
21
22 if ( GetCEApi() )
23 {
25 }
26 RegisterNetSyncVariableBool("m_RefresherActive");
27 }
28
33
35 {
36 int frequency = GetCEApi().GetCEGlobalInt("FlagRefreshFrequency");
37 int max_duration = GetCEApi().GetCEGlobalInt("FlagRefreshMaxDuration");
38
39 if ( frequency > 0)
40 {
41 m_FlagRefresherFrequency = frequency;
42 }
43 if ( max_duration > 0 )
44 {
45 m_FlagRefresherMaxDuration = max_duration;
46 }
48 }
49
50 override string GetConstructionKitType()
51 {
52 return "TerritoryFlagKit";
53 }
54
55 override int GetMeleeTargetType()
56 {
57 return EMeleeTargetType.NONALIGNABLE;
58 }
59
60 /*override bool NameOverride(out string output)
61 {
62 if ( m_GateState != GATE_STATE_NONE )
63 {
64 output = "#str_cfgvehicles_construction_part_gate"; //changes object displayed name if in 'gate' state
65 output.ToUpper();
66 return true;
67 }
68 return false;
69 }*/
70
71 //--- CONSTRUCTION KIT
73 {
74 if ( MemoryPointExists( "kit_spawn_position" ) )
75 {
76 vector position;
77 position = GetMemoryPointPos( "kit_spawn_position" );
78
79 return ModelToWorld( position );
80 }
81
82 return GetPosition();
83 }
84
85 override bool CanDisplayAttachmentCategory( string category_name )
86 {
87 if ( category_name == "Base" && !HasBase() )
88 return true;
89 else if ( category_name == "Support" && HasBase() && !GetConstruction().IsPartConstructed("support") )
90 return true;
91 else if ( category_name == "Pole" && GetConstruction().IsPartConstructed("support") && !GetConstruction().IsPartConstructed("pole") )
92 return true;
93 else if ( category_name == "Flag" && GetConstruction().IsPartConstructed("pole") )
94 return true;
95 else
96 return false;
97 }
98 // ---
99
100 // --- EVENTS
101 override void OnStoreSave( ParamsWriteContext ctx )
102 {
103 super.OnStoreSave( ctx );
104
109 }
110
111 override bool OnStoreLoad( ParamsReadContext ctx, int version )
112 {
113 if ( !super.OnStoreLoad( ctx, version ) )
114 return false;
115
116 //int loaded_frequency;
117 int loaded_max_duration;
118
119 if ( !ctx.Read( m_RefresherTimeRemaining ) )
120 {
121 return false;
122 }
123
124 if ( !ctx.Read( m_RefreshTimeCounter ) )
125 {
126 return false;
127 }
128
129 if ( !ctx.Read( loaded_max_duration ) )
130 {
131 return false;
132 }
133
134 if ( version >= 118 && !ctx.Read( m_RefresherActive ) )
135 {
136 return false;
137 }
138
139 CheckLoadedVariables(loaded_max_duration);
141
142 return true;
143 }
144
145 override void AfterStoreLoad()
146 {
147 super.AfterStoreLoad();
148
150 {
152 }
153 SetSynchDirty();
155 }
156
157 override void OnCEUpdate()
158 {
159 super.OnCEUpdate();
160
161 int time_elapsed_rounded = Math.Round(m_ElapsedSinceLastUpdate);
162
163 if ( m_RefresherTimeRemaining > 0 )
164 {
165 m_RefreshTimeCounter += time_elapsed_rounded;
167 {
168 GetCEApi().RadiusLifetimeReset(GetPosition(),GameConstants.REFRESHER_RADIUS);
170 m_RefreshTimeCounter = 0; //possibly carry over the rest?
172 }
173 }
174
176 }
177
180 {
182 if (!mission.m_ActiveRefresherLocations)
183 return;
184
185 int idx = mission.m_ActiveRefresherLocations.Find(GetPosition());
186 if ( m_RefresherActive && idx == -1 )
187 {
189 }
190 else if ( !m_RefresherActive && idx > -1 )
191 {
193 }
194 }
195
196 void SetRefresherActive(bool state)
197 {
198 if ( m_RefresherActive != state )
199 {
200 m_RefresherActive = state;
201 SetSynchDirty();
202
204
205 //update on refresher activation / last update on refresher deactivation
206 if (GetCEApi())
207 GetCEApi().RadiusLifetimeReset(GetPosition(),GameConstants.REFRESHER_RADIUS);
208 }
209 }
210
212 {
214 mission.m_ActiveRefresherLocations.Insert(GetPosition());
215 }
216
217 void RemoveRefresherPosition(int idx = -2)
218 {
219 if (!GetGame())
220 return;
221
223 if (!mission || !mission.m_ActiveRefresherLocations)
224 return;
225
226 if (idx == -2)
227 {
228 idx = mission.m_ActiveRefresherLocations.Find(GetPosition());
229 }
230
231 if (idx > -1)
232 {
233 mission.m_ActiveRefresherLocations.Remove(idx);
234 }
235 }
236
238 {
239 super.OnVariablesSynchronized();
240
242 {
245 }
246 }
247
248 //--- BUILD EVENTS
249 //CONSTRUCTION EVENTS
250 override void OnPartBuiltServer( notnull Man player, string part_name, int action_id )
251 {
252 //ConstructionPart constrution_part = GetConstruction().GetConstructionPart( part_name );
253
254 super.OnPartBuiltServer( player, part_name, action_id );
255
256 //update visuals (server)
258 }
259
260 override void OnPartDismantledServer( notnull Man player, string part_name, int action_id )
261 {
262 ConstructionPart constrution_part = GetConstruction().GetConstructionPart( part_name );
263
264 super.OnPartDismantledServer( player, part_name, action_id );
265
266 //update visuals (server)
268 }
269
270 override void OnPartDestroyedServer( Man player, string part_name, int action_id, bool destroyed_by_connected_part = false )
271 {
272 super.OnPartDestroyedServer( player, part_name, action_id );
273
274 //update visuals (server)
276 }
277
278 //--- ATTACHMENT & CONDITIONS
279 override void EEItemDetached( EntityAI item, string slot_name )
280 {
281 super.EEItemDetached( item, slot_name );
282
283 if (GetGame().IsServer()) // reset totem state is flag is decrafted while raised
284 {
285 float state = GetAnimationPhase("flag_mast");
286 if (state < 1)
287 {
288 AnimateFlag(1);
290 }
291 }
292 }
293
294 override bool CanReceiveAttachment( EntityAI attachment, int slotId ) //TODO
295 {
296 if ( !super.CanReceiveAttachment(attachment, slotId) )
297 return false;
298
299 //manage action initiator (AT_ATTACH_TO_CONSTRUCTION)
300 if ( !GetGame().IsDedicatedServer() )
301 {
302 PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
303 if ( player )
304 {
305 ConstructionActionData construction_action_data = player.GetConstructionActionData();
306
307 //reset action initiator
308 construction_action_data.SetActionInitiator( NULL );
309 }
310 }
311
312 //conditions
313 string slot_name = InventorySlots.GetSlotName(slotId);
314 //flag item attachment
315 if ( slot_name == "Material_FPole_Flag" )
316 {
317 if ( GetConstruction().IsPartConstructed("pole") )
318 return true;
319 else
320 return false;
321 }
322 //materials
323 ConstructionPart part;
324 ConstructionPart part_lowest;
325 int part_id = -1;
326 for (int i = 0; i < GetConstruction().GetConstructionParts().Count(); i++)
327 {
328 part = GetConstruction().GetConstructionParts().GetElement(i);
329 if (!part.IsBuilt())
330 {
331 if (part_id == -1 || part_id > part.GetId())
332 {
333 part_lowest = part;
334 part_id = part.GetId();
335 }
336 }
337 }
338
339 if (part_lowest /*&& !part_lowest.IsBuilt()*/)
340 {
341 string cfg_path = "cfgVehicles " + GetType() + " Construction " + part_lowest.GetMainPartName() + " " + part_lowest.GetPartName() + " Materials";
342 string material_path;
343 if ( GetGame().ConfigIsExisting(cfg_path) )
344 {
345 string child_name;
346 string child_slot_name;
347 for ( i = 0; i < GetGame().ConfigGetChildrenCount( cfg_path ); i++ )
348 {
349 GetGame().ConfigGetChildName( cfg_path, i, child_name );
350 material_path = "" + cfg_path + " " + child_name + " slot_name";
351 if ( GetGame().ConfigGetText(material_path,child_slot_name) && child_slot_name == slot_name )
352 {
353 return true;
354 }
355 }
356 }
357 }
358
359 return false;
360 }
361
362 //hands
363 override bool CanPutIntoHands( EntityAI parent )
364 {
365 return false;
366 }
367
369 {
370 return true;
371 }
372
373 //--- ACTION CONDITIONS
374 override bool IsPlayerInside( PlayerBase player, string selection )
375 {
376 return true; //TODO
377
378 vector player_pos = player.GetPosition();
379 vector fence_pos = GetPosition();
380 vector ref_dir = GetDirection();
381 ref_dir[1] = 0;
382 ref_dir.Normalize();
383
384 vector x[2];
385 vector b1,b2;
386 GetCollisionBox(x);
387 b1 = x[0];
388 b2 = x[1];
389
390 vector dir_to_fence = fence_pos - player_pos;
391 dir_to_fence[1] = 0;
392 float len = dir_to_fence.Length();
393
394 dir_to_fence.Normalize();
395
396 vector ref_dir_angle = ref_dir.VectorToAngles();
397 vector dir_to_fence_angle = dir_to_fence.VectorToAngles();
398 vector test_angles = dir_to_fence_angle - ref_dir_angle;
399
400 vector test_position = test_angles.AnglesToVector() * len;
401
402 if(test_position[0] < b1[0] || test_position[0] > b2[0] || test_position[2] < 0.2 || test_position[2] > 2.2 )
403 {
404 return false;
405 }
406 else
407 {
408 return true;
409 }
410 }
411
412 override bool IsFacingPlayer( PlayerBase player, string selection )
413 {
414 return true; //TODO
415
416 vector fence_pos = GetPosition();
417 vector player_pos = player.GetPosition();
418 vector ref_dir = GetDirection();
419
420 //vector fence_player_dir = player_pos - fence_pos;
421 vector fence_player_dir = player.GetDirection();
422 fence_player_dir.Normalize();
423 fence_player_dir[1] = 0; //ignore height
424
425 ref_dir.Normalize();
426 ref_dir[1] = 0; //ignore height
427
428 if ( ref_dir.Length() != 0 )
429 {
430 float angle = Math.Acos( fence_player_dir * ref_dir );
431
432 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
433 {
434 return true;
435 }
436 }
437
438 return false;
439 }
440
441 override bool IsFacingCamera( string selection )
442 {
443 return false; //TODO
444
445 vector ref_dir = GetDirection();
447
448 //ref_dir = GetGame().GetCurrentCameraPosition() - GetPosition();
449 ref_dir.Normalize();
450 ref_dir[1] = 0; //ignore height
451
452 cam_dir.Normalize();
453 cam_dir[1] = 0; //ignore height
454
455 if ( ref_dir.Length() != 0 )
456 {
457 float angle = Math.Acos( cam_dir * ref_dir );
458
459 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
460 {
461 return true;
462 }
463 }
464
465 return false;
466 }
467
468 override bool HasProperDistance( string selection, PlayerBase player )
469 {
470 //TODO
471 if ( MemoryPointExists( selection ) )
472 {
473 vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
474 float distance = vector.Distance( selection_pos, player.GetPosition() );
475 if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
476 {
477 return false;
478 }
479 }
480
481 return true;
482 }
483
484 //================================================================
485 // SOUNDS
486 //================================================================
487 //TODO
488
489 override void SetActions()
490 {
491 super.SetActions();
492
496 }
497
498 /*override void UpdateVisuals()
499 {
500 super.UpdateVisuals();
501 }*/
502
503 //================================================================
504 // FLAG MANIPULATION + REFRESHER
505 //================================================================
506 void AnimateFlagEx(float delta, PlayerBase player = null)
507 {
508 float temp = Math.Clamp( delta,0,1 );
509 float phase_new;
510 if (temp < 0.01 || temp > 0.99)
511 {
512 phase_new = Math.Round(temp);
513 }
514 else
515 phase_new = temp;
516
517 SetAnimationPhase("flag_mast",phase_new);
518
519 if (player)
520 LogAnimateFlag(phase_new, player);
521
522 GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString("Material_FPole_Flag"),phase_new != 1);
523
524 }
525
526 void AnimateFlag(float delta)
527 {
528 AnimateFlagEx(delta);
529 }
530
531 protected void LogAnimateFlag(float newPhase, notnull PlayerBase player)
532 {
533 PluginAdminLog logs = PluginAdminLog.Cast(GetPlugin(PluginAdminLog));
534 if (newPhase == 0)
535 {
536 // at the top(it's inverted)
537 logs.TotemFlagChange(true, player, this);
538 }
539 else if (newPhase == 1)
540 {
541 // at the bottom(it's inverted)
542 logs.TotemFlagChange(false, player, this);
543 }
544
545 }
546
547 void SetRefreshTimer01(float fraction)
548 {
551 }
552
553 /*void AddRefresherTimeFlat(float seconds) //seconds?
554 {
555 float temp = Math.Clamp(m_RefresherTimeRemaining + seconds, 0, m_FlagRefresherMaxDuration);
556 m_RefresherTimeRemaining = Math.Round(temp);
557 SetRefresherActive(m_RefresherTimeRemaining > 0);
558 }*/
559
560 void AddRefresherTime01(float fraction)
561 {
565 //Print(m_RefresherTimeRemaining);
566 }
567
572
573 void CheckLoadedVariables(int max_duration)
574 {
575 if (max_duration != m_FlagRefresherMaxDuration)
576 {
578 }
579 }
580
581 //================================================================
582 // DEBUG
583 //================================================================
584 /*
585 override void DebugCustomState()
586 {
587 //debug
588 m_SyncParts01 = 881; //full fence with gate
589 m_HasHinges = true;
590 m_HasBase = true;
591
592 OnVariablesSynchronized();
593 }
594 */
595
596 //Debug menu Spawn Ground Special
597 override void OnDebugSpawn()
598 {
599 super.OnDebugSpawn();
600
601 GetInventory().CreateInInventory("Flag_DayZ");
602 AnimateFlag(0);
604 }
605}
eBleedingSourceType GetType()
Определения BleedingSource.c:63
ActionFoldBaseBuildingObjectCB ActionContinuousBaseCB ActionFoldBaseBuildingObject()
Определения ActionFoldBaseBuildingObject.c:11
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
Construction GetConstruction()
Определения BaseBuildingBase.c:2244
bool HasBase()
Определения BaseBuildingBase.c:1620
proto native CEApi GetCEApi()
Get the CE API.
void UpdateVisuals()
Определения Construction.c:188
bool IsPartConstructed(string part_name)
Определения Construction.c:602
Mission mission
Определения DisplayStatus.c:28
EMeleeTargetType
Определения EMeleeTargetType.c:2
Icon x
PlayerBase GetPlayer()
Определения ModifierBase.c:51
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:316
Определения ActionLowerFlag.c:3
override bool CanDisplayAttachmentCategory(string category_name)
Определения Totem.c:85
void TerritoryFlag()
Определения Totem.c:15
override void OnDebugSpawn()
Определения Totem.c:597
override bool IsPlayerInside(PlayerBase player, string selection)
Определения Totem.c:374
bool m_RefresherInitialized
Определения Totem.c:8
override void OnVariablesSynchronized()
Определения Totem.c:237
void ~TerritoryFlag()
Определения Totem.c:29
void SetRefreshTimer01(float fraction)
Определения Totem.c:547
void RemoveRefresherPosition(int idx=-2)
Определения Totem.c:217
override string GetConstructionKitType()
Определения Totem.c:50
float GetRefresherTime01()
Определения Totem.c:568
int m_FlagRefresherFrequency
Определения Totem.c:12
int m_RefreshTimeCounter
Определения Totem.c:10
override void EEItemDetached(EntityAI item, string slot_name)
Определения Totem.c:279
override bool CanPutIntoHands(EntityAI parent)
Определения Totem.c:363
int m_RefresherTimeRemaining
Определения Totem.c:9
override void OnPartBuiltServer(notnull Man player, string part_name, int action_id)
Определения Totem.c:250
override void SetActions()
Определения Totem.c:489
void AddRefresherTime01(float fraction)
Определения Totem.c:560
void SetRefresherActive(bool state)
Определения Totem.c:196
int m_FlagRefresherMaxDuration
Определения Totem.c:13
const float MAX_ACTION_DETECTION_ANGLE_RAD
Определения Fence.c:16
override bool IsFacingCamera(string selection)
Определения Totem.c:441
override bool IsFacingPlayer(PlayerBase player, string selection)
Определения Totem.c:412
const float MAX_ACTION_DETECTION_DISTANCE
Определения Fence.c:17
override void OnCEUpdate()
Определения Totem.c:157
override void AfterStoreLoad()
Определения Totem.c:145
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения Totem.c:111
void LogAnimateFlag(float newPhase, notnull PlayerBase player)
Определения Totem.c:531
override int GetMeleeTargetType()
Определения Totem.c:55
override bool HasProperDistance(string selection, PlayerBase player)
Определения Totem.c:468
bool m_RefresherActive
Определения Totem.c:6
void HandleRefreshers()
Saves positions of active lifetime refreshers to MissionGameplay / MissionServer.
Определения Totem.c:179
void InitRefresherData()
Определения Totem.c:34
override void OnPartDestroyedServer(Man player, string part_name, int action_id, bool destroyed_by_connected_part=false)
Определения Totem.c:270
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Определения Totem.c:294
void CheckLoadedVariables(int max_duration)
Определения Totem.c:573
override void OnStoreSave(ParamsWriteContext ctx)
Определения Totem.c:101
void InsertRefresherPosition()
Определения Totem.c:211
override vector GetKitSpawnPosition()
Определения Totem.c:72
override bool CanBeRepairedToPristine()
Определения Totem.c:368
void AnimateFlagEx(float delta, PlayerBase player=null)
Определения Totem.c:506
void AnimateFlag(float delta)
Определения Totem.c:526
bool m_RefresherActiveLocal
Определения Totem.c:7
override void OnPartDismantledServer(notnull Man player, string part_name, int action_id)
Определения Totem.c:260
Определения Fence.c:2
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass in config class on path.
proto native int ConfigGetChildrenCount(string path)
Get count of subclasses in config class on path.
proto native vector GetCurrentCameraDirection()
proto native Mission GetMission()
void SetActionInitiator(PlayerBase action_initiator)
Определения ConstructionActionData.c:108
int GetId()
Определения ConstructionPart.c:40
string GetPartName()
Определения ConstructionPart.c:30
bool IsBuilt()
Определения ConstructionPart.c:45
string GetMainPartName()
Определения ConstructionPart.c:35
Определения Building.c:6
Определения constants.c:659
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static proto native owned string GetSlotName(int id)
converts slot_id to string
provides access to slot configuration
Определения InventorySlots.c:6
Определения EnMath.c:7
Mission class.
Определения gameplay.c:687
Определения PlayerBaseClient.c:2
proto bool Write(void value_out)
proto bool Read(void value_in)
Определения StaticFlagPole.c:28
proto native float Length()
Returns length of vector (magnitude)
proto float Normalize()
Normalizes vector. Returns length.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
proto vector AnglesToVector()
Converts spherical coordinates (yaw, pitch, roll in degrees) to unit length vector.
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
Serializer ParamsWriteContext
Определения gameplay.c:16
const float REFRESHER_RADIUS
Определения constants.c:1023
const int REFRESHER_MAX_DURATION_DEFAULT
Определения constants.c:1021
const int REFRESHER_FREQUENCY_DEFAULT
Определения constants.c:1022
static proto float Acos(float c)
Returns angle in radians from cosinus.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9