3 const int GATE_STATE_NONE = 0;
4 const int GATE_STATE_PARTIAL = 1;
5 const int GATE_STATE_FULL = 2;
7 const string ATTACHMENT_SLOT_COMBINATION_LOCK =
"Att_CombinationLock";
8 const string SOUND_GATE_OPEN_START =
"DoorWoodTowerOpen_SoundSet";
9 const string SOUND_GATE_CLOSE_START =
"DoorWoodTowerClose_start_SoundSet";
10 const string SOUND_GATE_CLOSE_END =
"DoorWoodTowerClose_end_SoundSet";
13 const float GATE_ROTATION_ANGLE_DEG = 100;
14 const float GATE_ROTATION_TIME_APPROX = 2000;
16 const float MAX_ACTION_DETECTION_ANGLE_RAD = 1.3;
17 const float MAX_ACTION_DETECTION_DISTANCE = 2.0;
19 typename ATTACHMENT_WOODEN_LOG = WoodenLog;
22 string ATTSLOT_CAMONET =
"Wall_Camonet";
23 string ATTSLOT_BARBEDWIRE_DOWN =
"Wall_Barbedwire_1";
24 string ATTSLOT_BARBEDWIRE_UP =
"Wall_Barbedwire_2";
28 protected bool m_ToDiscard =
false;
30 protected bool m_IsOpenedClient =
false;
31 protected int m_GateState = 0;
41 RegisterNetSyncVariableBool(
"m_IsOpened" );
42 RegisterNetSyncVariableInt(
"m_GateState" );
50 override int GetMeleeTargetType()
58 return m_GateState > GATE_STATE_NONE;
61 bool HasFullyConstructedGate()
63 return m_GateState == GATE_STATE_FULL;
66 void SetGateState(
int state )
80 int state = GATE_STATE_NONE;
81 if( gate_part.IsBuilt() )
85 for (
int i = 0; i < req_parts.Count(); i++)
88 if(!req_part.IsBuilt())
92 if( i != req_parts.Count() )
94 state = GATE_STATE_PARTIAL;
98 state = GATE_STATE_FULL;
105 void SetOpenedState(
bool state )
118 if ( combination_lock && combination_lock.IsLocked() )
126 override bool NameOverride(out
string output)
128 if ( m_GateState != GATE_STATE_NONE )
130 output =
"#str_cfgvehicles_construction_part_gate";
140 return combination_lock;
145 CamoNet camonet = CamoNet.Cast( FindAttachmentBySlotName(
"Wall_Camonet" ) );
149 BarbedWire GetBarbedWire1()
151 BarbedWire barbedwire = BarbedWire.Cast( FindAttachmentBySlotName(
"Wall_Barbedwire_1" ) );
155 BarbedWire GetBarbedWire2()
157 BarbedWire barbedwire = BarbedWire.Cast( FindAttachmentBySlotName(
"Wall_Barbedwire_2" ) );
164 if ( MemoryPointExists(
"kit_spawn_position" ) )
167 position = GetMemoryPointPos(
"kit_spawn_position" );
169 return ModelToWorld( position );
178 if (!super.CanDisplayAttachmentSlot(slot_id))
183 if ( slot_name ==
"Att_CombinationLock" )
185 if ( !HasFullyConstructedGate() )
191 if ( !GateAttachmentConditions(
InventorySlots.GetSlotIdFromString(slot_name)) )
199 if ( category_name ==
"Attachments" || category_name ==
"Material" )
214 super.OnStoreSave( ctx );
217 ctx.Write( m_GateState );
224 if ( !super.OnStoreLoad( ctx, version ) )
231 if ( !ctx.Read( m_ToDiscard ) )
236 m_GateState = GATE_STATE_NONE;
238 else if ( !ctx.Read( m_GateState ) )
240 m_GateState = GATE_STATE_NONE;
259 super.AfterStoreLoad();
263 SetGateState( CheckGateState() );
278 super.OnVariablesSynchronized();
284 if ( m_IsOpenedClient )
297 override void OnPartBuiltServer( notnull Man player,
string part_name,
int action_id )
301 super.OnPartBuiltServer( player, part_name, action_id );
303 SetGateState(CheckGateState());
314 if ( constrution_part.IsGate() )
319 combination_lock.UnlockServer( player ,
this );
323 super.OnPartDismantledServer( player, part_name, action_id );
325 SetGateState( CheckGateState() );
331 override void OnPartDestroyedServer( Man player,
string part_name,
int action_id,
bool destroyed_by_connected_part =
false )
333 super.OnPartDestroyedServer( player, part_name, action_id );
337 if ( constrution_part.IsGate() && destroyed_by_connected_part )
340 HandleDropAttachment(GetBarbedWire1());
341 HandleDropAttachment(GetBarbedWire2());
342 HandleDropAttachment(GetCamoNet());
343 HandleDropAttachment(GetCombinationLock());
349 if ( part_name ==
"wall_base_down" )
351 HandleDropAttachment(GetBarbedWire1());
352 HandleDropAttachment(GetCombinationLock());
354 if ( part_name ==
"wall_base_up" )
356 HandleDropAttachment(GetBarbedWire2());
357 HandleDropAttachment(GetCamoNet());
358 HandleDropAttachment(GetCombinationLock());
361 SetGateState( CheckGateState() );
369 if ( !super.CanReceiveAttachment(attachment, slotId) )
373 if ( !
GetGame().IsDedicatedServer() )
381 construction_action_data.SetActionInitiator( NULL );
386 if ( attachment.Type() != ATTACHMENT_WOODEN_LOG )
394 if ( attachment.IsInherited( ATTACHMENT_COMBINATION_LOCK ) )
396 return ( HasFullyConstructedGate() && !
IsOpened() );
399 if ( !GateAttachmentConditions(slotId) )
408 if( !super.CanPutIntoHands( parent ) )
421 override bool CanBeRepairedToPristine()
452 float value = GATE_ROTATION_ANGLE_DEG;
453 SetAnimationPhase(
"Wall_Interact_Rotate", value );
454 SetAnimationPhase(
"Wall_Barbedwire_1_Mounted_Rotate", value );
455 SetAnimationPhase(
"Wall_Barbedwire_2_Mounted_Rotate", value );
456 SetAnimationPhase(
"Wall_Camonet_Rotate", value );
457 SetAnimationPhase(
"Wall_Gate_Rotate", value );
458 SetAnimationPhase(
"Wall_Base_Down_Rotate", value );
459 SetAnimationPhase(
"Wall_Base_Up_Rotate", value );
460 SetAnimationPhase(
"Wall_Wood_Down_Rotate", value );
461 SetAnimationPhase(
"Wall_Wood_Up_Rotate", value );
462 SetAnimationPhase(
"Wall_Metal_Down_Rotate", value );
463 SetAnimationPhase(
"Wall_Metal_Up_Rotate", value );
465 SetOpenedState(
true );
475 if ( !
GetGame().IsDedicatedServer() )
478 SoundGateOpenStart();
482 UpdateBarbedWireAreaDamagePos(0,
true);
495 SetAnimationPhase(
"Wall_Interact_Rotate", value );
496 SetAnimationPhase(
"Wall_Barbedwire_1_Mounted_Rotate", value );
497 SetAnimationPhase(
"Wall_Barbedwire_2_Mounted_Rotate", value );
498 SetAnimationPhase(
"Wall_Camonet_Rotate", value );
499 SetAnimationPhase(
"Wall_Gate_Rotate", value );
500 SetAnimationPhase(
"Wall_Base_Down_Rotate", value );
501 SetAnimationPhase(
"Wall_Base_Up_Rotate", value );
502 SetAnimationPhase(
"Wall_Wood_Down_Rotate", value );
503 SetAnimationPhase(
"Wall_Wood_Up_Rotate", value );
504 SetAnimationPhase(
"Wall_Metal_Down_Rotate", value );
505 SetAnimationPhase(
"Wall_Metal_Up_Rotate", value );
507 SetOpenedState(
false );
517 if ( !
GetGame().IsDedicatedServer() )
520 SoundGateCloseStart();
524 UpdateBarbedWireAreaDamagePos(0,
true);
531 protected void CheckFenceOpened()
533 if ( GetAnimationPhase(
"Wall_Gate_Rotate" ) == GATE_ROTATION_ANGLE_DEG )
535 UpdateBarbedWireAreaDamagePos(GetAnimationPhase(
"Wall_Gate_Rotate" ));
541 protected void CheckFenceClosed()
543 if ( GetAnimationPhase(
"Wall_Gate_Rotate" ) == 0 )
546 if ( !
GetGame().IsDedicatedServer() )
549 if (
this ) SoundGateCloseEnd();
551 UpdateBarbedWireAreaDamagePos(GetAnimationPhase(
"Wall_Gate_Rotate" ));
558 override void CreateAreaDamage(
string slot_name,
float rotation_angle = 0 )
562 rotation_angle = 100;
565 super.CreateAreaDamage( slot_name, rotation_angle );
569 void UpdateBarbedWireAreaDamagePos(
float rotation_angle = 0,
bool to_delete =
false )
573 string slot_name_mounted;
574 if ( GetBarbedWire1() && GetBarbedWire1().IsMounted() )
576 GetBarbedWire1().GetInventory().GetCurrentAttachmentSlotInfo(slot_id,slot_name);
577 slot_name_mounted = slot_name +
"_Mounted";
584 super.CreateAreaDamage( slot_name_mounted, rotation_angle );
587 if ( GetBarbedWire2() && GetBarbedWire2().IsMounted() )
589 GetBarbedWire2().GetInventory().GetCurrentAttachmentSlotInfo(slot_id,slot_name);
590 slot_name_mounted = slot_name +
"_Mounted";
597 super.CreateAreaDamage( slot_name_mounted, rotation_angle );
603 override void PostAreaDamageActions()
617 vector player_pos = player.GetPosition();
619 vector ref_dir = GetDirection();
629 vector dir_to_fence = fence_pos - player_pos;
631 float len = dir_to_fence.Length();
633 dir_to_fence.Normalize();
635 vector ref_dir_angle = ref_dir.VectorToAngles();
636 vector dir_to_fence_angle = dir_to_fence.VectorToAngles();
637 vector test_angles = dir_to_fence_angle - ref_dir_angle;
639 vector test_position = test_angles.AnglesToVector() * len;
641 if(test_position[0] < b1[0] || test_position[0] > b2[0] || test_position[2] < 0.2 || test_position[2] > 2.2 )
654 vector player_pos = player.GetPosition();
655 vector ref_dir = GetDirection();
658 vector fence_player_dir = player.GetDirection();
659 fence_player_dir.Normalize();
660 fence_player_dir[1] = 0;
665 if ( ref_dir.Length() != 0 )
667 float angle =
Math.Acos( fence_player_dir * ref_dir );
669 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
680 vector ref_dir = GetDirection();
690 if ( ref_dir.Length() != 0 )
692 float angle =
Math.Acos( cam_dir * ref_dir );
694 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
705 if ( MemoryPointExists( selection ) )
707 vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
708 float distance =
vector.Distance( selection_pos, player.GetPosition() );
709 if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
726 protected void SoundGateOpenStart()
729 if ( !
GetGame().IsDedicatedServer() )
731 PlaySoundSet( m_SoundGate_Start, SOUND_GATE_OPEN_START, 0.1, 0.1 );
735 protected void SoundGateCloseStart()
738 if ( !
GetGame().IsDedicatedServer() )
740 PlaySoundSet( m_SoundGate_Start, SOUND_GATE_CLOSE_START, 0.1, 0.1 );
744 protected void SoundGateCloseEnd()
747 if ( !
GetGame().IsDedicatedServer() )
749 PlaySoundSet( m_SoundGate_End, SOUND_GATE_CLOSE_END, 0.1, 0.1 );
753 void GateAttachmentsSanityCheck()
757 if(GetBarbedWire1() && !wall_base_down.IsBuilt())
759 HandleDropAttachment(GetBarbedWire1());
760 HandleDropAttachment(GetCombinationLock());
762 if( ( GetCamoNet() || GetBarbedWire2() ) && !wall_base_up.IsBuilt() )
764 HandleDropAttachment(GetBarbedWire2());
765 HandleDropAttachment(GetCamoNet());
766 HandleDropAttachment(GetCombinationLock());
770 void HandleDropAttachment(
ItemBase item)
774 if (
Class.CastTo(wire,item))
776 wire.SetMountedState(
false );
779 else if (
Class.CastTo(lock,item))
781 lock.UnlockServer(
null,
this);
789 bool GateAttachmentConditions(
int slotId)
791 if ( GetGateState() == GATE_STATE_PARTIAL )
796 if ( !wall_base_up.IsBuilt() )
798 if ( slot_name == ATTSLOT_CAMONET || slot_name == ATTSLOT_BARBEDWIRE_UP )
803 if ( !wall_base_down.IsBuilt() )
805 if ( slot_name == ATTSLOT_BARBEDWIRE_DOWN )
815 override bool TranslateSlotFromSelection(
string selection_name, out
int slot_id)
817 if ( selection_name ==
"wall_camonet_attach" )
858 #ifdef DIAG_DEVELOPER
866 excludes.Insert(
"_metal_");
870 excludes.Insert(
"_wood_");
873 #ifdef DIAG_DEVELOPER
881 excludes.Insert(
"platform");
885 excludes.Insert(
"gate");
894 super.OnDebugSpawn();
896 GetInventory().CreateInInventory(
"CamoNet");
898 for (
int i = 0; i < 2; ++i)
900 BarbedWire wire = BarbedWire.Cast(GetInventory().CreateInInventory(
"BarbedWire"));
901 wire.SetMountedState(
true);