3 typename ATTACHMENT_BARBED_WIRE = BarbedWire;
4 typename ATTACHMENT_CAMONET = CamoNet;
6 const float MAX_FLOOR_VERTICAL_DISTANCE = 0.5;
8 const float MIN_ACTION_DETECTION_ANGLE_RAD = 0.35;
9 const float MAX_ACTION_DETECTION_DISTANCE = 2.0;
11 static const string BASE_VIEW_NAME =
"level_";
12 static const string BASE_WALL_NAME =
"_wall_";
13 static const string BASE_ROOF_NAME =
"_roof";
14 static const int MAX_WATCHTOWER_FLOORS = 3;
15 static const int MAX_WATCHTOWER_WALLS = 3;
23 return "WatchtowerKit";
26 override int GetMeleeTargetType()
46 super.UpdateVisuals();
48 SetAnimationPhase(
"level_1", 0);
49 SetAnimationPhase(
"level_1_wall_1", 0);
50 SetAnimationPhase(
"level_1_wall_2", 0);
51 SetAnimationPhase(
"level_1_wall_3", 0);
53 string part_name =
"";
56 for (
int i = 1; i < MAX_WATCHTOWER_FLOORS; ++i )
59 part_name =
"" + BASE_VIEW_NAME + i + BASE_ROOF_NAME;
68 SetAnimationPhase( BASE_VIEW_NAME + (i + 1), 0);
69 for (
int j = 1; j < MAX_WATCHTOWER_WALLS + 1; ++j )
73 SetAnimationPhase( BASE_VIEW_NAME + (i + 1) + BASE_WALL_NAME + j, 0);
78 SetAnimationPhase( BASE_VIEW_NAME + (i + 1), 1 );
79 for ( j = 1; j < MAX_WATCHTOWER_WALLS + 1; ++j )
83 SetAnimationPhase( BASE_VIEW_NAME + (i + 1) + BASE_WALL_NAME + j, 1);
92 if ( !super.CanReceiveAttachment( attachment, slotId ) )
98 if ( !
GetGame().IsDedicatedServer() )
105 PlayerBase action_initiator = construction_action_data.GetActionInitiator();
107 if ( action_initiator == player )
109 construction_action_data.SetActionInitiator( NULL );
128 override bool CanBeRepairedToPristine()
138 if (partName !=
"level_1_base" && partName !=
"level_2_base" && partName !=
"level_3_base" && partName !=
"level_3_roof")
150 excluded_objects.Insert(
this );
151 excluded_objects.Insert( player );
153 if ( partName ==
"level_2_base" )
155 min_max[0] = GetMemoryPointPos(
"level_2_wall_1_down_min" );
156 min_max[1] = GetMemoryPointPos(
"level_2_roof_max" );
158 else if ( partName ==
"level_3_base" )
160 min_max[0] = GetMemoryPointPos(
"level_3_wall_1_down_min" );
161 min_max[1] = GetMemoryPointPos(
"level_3_wall_2_up_max" );
163 else if ( partName ==
"level_3_roof" )
165 min_max[0] = GetMemoryPointPos(
"level_3_roof_min" );
166 min_max[1] = GetMemoryPointPos(
"level_3_roof_max" );
172 min_max[0] = GetMemoryPointPos(
"level_1_collisioncheck_min" );
173 min_max[1] = GetMemoryPointPos(
"level_1_roof_max" );
176 center[1] = center[1] + ( min_max[1][1] + min_max[0][1] ) / 2;
178 edge_length[0] = min_max[1][0] - min_max[0][0];
179 edge_length[2] = min_max[1][2] - min_max[0][2];
180 edge_length[1] = min_max[1][1] - min_max[0][1];
183 GetGame().IsBoxCollidingGeometry( center, orientation, edge_length, ObjIntersectView, ObjIntersectGeom, excluded_objects, collided_objects );
184 if ( collided_objects.Count() > 0 )
186 foreach (
Object o : collided_objects )
188 if (Building.Cast(o))
201 if ( !super.CanDisplayAttachmentSlot( slot_id ) )
208 if ( slot_name.Contains(
"material_l1" ) || slot_name.Contains(
"level_1_" ) )
210 if ( slot_name.Contains(
"woodenlogs" ) )
219 else if ( slot_name.Contains(
"material_l2" ) || slot_name.Contains(
"level_2_" ) )
221 if ( slot_name.Contains(
"woodenlogs" ) )
230 else if ( slot_name.Contains(
"material_l3" ) || slot_name.Contains(
"level_3_" ) )
232 if ( slot_name.Contains(
"woodenlogs" ) )
248 if ( !super.CanDisplayAttachmentCategory( category_name ) )
252 category_name.ToLower();
255 if ( category_name.Contains(
"level_1" ) )
257 if ( category_name.Contains(
"level_1_" ) )
267 if ( category_name.Contains(
"level_2" ) )
269 if ( category_name.Contains(
"level_2_" ) )
279 if ( category_name.Contains(
"level_3" ) )
281 if ( category_name.Contains(
"level_3_" ) )
303 if ( slot_name.Contains(
"material_l1" ) || slot_name.Contains(
"level_1_" ) )
305 if ( slot_name.Contains(
"woodenlogs" ) )
315 if ( slot_name.Contains(
"material_l2" ) || slot_name.Contains(
"level_2_" ) )
317 if ( slot_name.Contains(
"material_l2w" ) || slot_name.Contains(
"level_2_wall" ) )
323 if ( slot_name.Contains(
"woodenlogs" ) )
334 if ( slot_name.Contains(
"material_l3" ) || slot_name.Contains(
"level_3_" ) )
336 if ( slot_name.Contains(
"material_l3w" ) || slot_name.Contains(
"level_3_wall" ) )
342 if ( slot_name.Contains(
"woodenlogs" ) )
362 vector player_pos = player.GetPosition();
365 if ( MemoryPointExists( selection ) )
367 pos = ModelToWorld( GetMemoryPointPos( selection ) );
370 if (
Math.AbsFloat( player_pos[1] - pos[1] ) <= max_dist )
387 if ( selection.Contains(
"level_1_" ) )
390 if ( selection.Contains(
"level_2_" ) )
393 if ( selection.Contains(
"level_3_" ) )
401 super.AfterStoreLoad();
406 override void OnPartBuiltServer( notnull Man player,
string part_name,
int action_id )
408 super.OnPartBuiltServer( player, part_name, action_id );
415 super.OnPartDismantledServer( player, part_name, action_id );
420 override void OnPartDestroyedServer( Man player,
string part_name,
int action_id,
bool destroyed_by_connected_part =
false )
422 super.OnPartDestroyedServer( player, part_name, action_id );
435 bool has_memory_point = MemoryPointExists( selection );
437 if ( has_memory_point )
439 ref_pos = ModelToWorld( GetMemoryPointPos( selection ) );
445 ref_dir = ref_pos - player.GetPosition();
451 player_dir = player.GetDirection();
452 player_dir.Normalize();
455 if ( ref_dir.Length() != 0 )
457 dot =
vector.Dot( player_dir, ref_dir );
460 if ( has_memory_point )
462 if ( dot < 0 &&
Math.AbsFloat( dot ) > MIN_ACTION_DETECTION_ANGLE_RAD )
469 if ( dot > 0 &&
Math.AbsFloat( dot ) > MIN_ACTION_DETECTION_ANGLE_RAD )
484 if ( MemoryPointExists( selection ) )
486 ref_pos = ModelToWorld( GetMemoryPointPos( selection ) );
494 if ( ref_dir.Length() > 0.5 )
496 float dot =
vector.Dot( cam_dir, ref_dir );
510 if ( selection !=
"")
514 vector player_pos = player.GetPosition();
516 vector ref_dir = GetDirection();
522 min = -GetMemoryPointPos(
"interact_min" );
523 max = -GetMemoryPointPos(
"interact_max" );
525 vector dir_to_tower = tower_pos - player_pos;
527 float len = dir_to_tower.Length();
530 dir_to_tower.Normalize();
532 vector ref_dir_angle = ref_dir.VectorToAngles();
533 vector dir_to_tower_angle = dir_to_tower.VectorToAngles();
534 vector test_angles = dir_to_tower_angle - ref_dir_angle;
536 vector test_position = test_angles.AnglesToVector() * len;
538 if (test_position[0] > max[0] || test_position[0] < min[0] || test_position[2] > max[2] || test_position[2] < min[2] )
548 if ( MemoryPointExists( selection ) )
550 vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
551 float distance =
vector.Distance( selection_pos, player.GetPosition() );
552 if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
580 #ifdef DIAG_DEVELOPER
588 excludes = {
"_metal_"};
592 excludes = {
"_wood_"};
601 super.OnDebugSpawn();
605 for (i = 0; i < MAX_WATCHTOWER_FLOORS * MAX_WATCHTOWER_WALLS; ++i)
607 GetInventory().CreateInInventory(
"CamoNet");
610 for (i = 0; i < 2 * MAX_WATCHTOWER_WALLS; ++i)
612 BarbedWire wire = BarbedWire.Cast(GetInventory().CreateInInventory(
"BarbedWire"));
613 wire.SetMountedState(
true);