public void CalculateRestrictedShapes(MyStringHash subtype, MyOrientedBoundingBoxD cubeBoundingBox, out MyOrientedBoundingBoxD restrictedBox, out BoundingSphereD restrictedSphere) { restrictedSphere = new BoundingSphereD(); restrictedBox = new MyOrientedBoundingBoxD(); if (!WeaponAreaRestrictions.ContainsKey(subtype)) { return; } WeaponAreaRestriction restriction = WeaponAreaRestrictions[subtype]; if (restriction.RestrictionBoxInflation < 0.1 && restriction.RestrictionRadius < 0.1) { return; } bool checkBox = restriction.RestrictionBoxInflation > 0; bool checkSphere = restriction.RestrictionRadius > 0; if (checkBox) { restrictedBox = new MyOrientedBoundingBoxD(cubeBoundingBox.Center, cubeBoundingBox.HalfExtent, cubeBoundingBox.Orientation); restrictedBox.HalfExtent = restrictedBox.HalfExtent + new Vector3D(Math.Sign(restrictedBox.HalfExtent.X) * restriction.RestrictionBoxInflation, Math.Sign(restrictedBox.HalfExtent.Y) * restriction.RestrictionBoxInflation, Math.Sign(restrictedBox.HalfExtent.Z) * restriction.RestrictionBoxInflation); } if (checkSphere) { restrictedSphere = new BoundingSphereD(cubeBoundingBox.Center, restriction.RestrictionRadius); } }
private void UpdatePlacer() { if (!Placer.Visible) { Placer = null; } if (!MyCubeBuilder.Static.DynamicMode && MyCubeBuilder.Static.HitInfo.HasValue) { var hit = MyCubeBuilder.Static.HitInfo.Value as IHitInfo; var grid = hit.HitEntity as MyCubeGrid; GridAi gridAi; if (grid != null && GridToMasterAi.TryGetValue(grid, out gridAi)) { if (MyCubeBuilder.Static.CurrentBlockDefinition != null) { var subtypeIdHash = MyCubeBuilder.Static.CurrentBlockDefinition.Id.SubtypeId; WeaponCount weaponCount; if (gridAi.WeaponCounter.TryGetValue(subtypeIdHash, out weaponCount)) { if (weaponCount.Max > 0 && gridAi.Construct.GetWeaponCount(subtypeIdHash) >= weaponCount.Max) { MyCubeBuilder.Static.NotifyPlacementUnable(); MyCubeBuilder.Static.Deactivate(); return; } } if (WeaponAreaRestrictions.ContainsKey(subtypeIdHash)) { MyOrientedBoundingBoxD restrictedBox; MyOrientedBoundingBoxD buildBox = MyCubeBuilder.Static.GetBuildBoundingBox(); BoundingSphereD restrictedSphere; if (IsWeaponAreaRestricted(subtypeIdHash, buildBox, grid, 0, null, out restrictedBox, out restrictedSphere)) { DsDebugDraw.DrawBox(buildBox, _uninitializedColor); } if (MyAPIGateway.Session.Config.HudState == 1) { if (restrictedBox.HalfExtent.AbsMax() > 0) { DsDebugDraw.DrawBox(restrictedBox, _restrictionAreaColor); } if (restrictedSphere.Radius > 0) { DsDebugDraw.DrawSphere(restrictedSphere, _restrictionAreaColor); } for (int i = 0; i < gridAi.Weapons.Count; i++) { MyOrientedBoundingBoxD b; BoundingSphereD s; CoreComponent Comp = gridAi.Weapons[i]; MyOrientedBoundingBoxD blockBox; SUtils.GetBlockOrientedBoundingBox(Comp.MyCube, out blockBox); CalculateRestrictedShapes(Comp.MyCube.BlockDefinition.Id.SubtypeId, blockBox, out b, out s); if (s.Radius > 0) { DsDebugDraw.DrawSphere(s, _restrictionAreaColor); } if (b.HalfExtent.AbsMax() > 0) { DsDebugDraw.DrawBox(b, _restrictionAreaColor); } } } } } } } }