private void InsertWallIntoBlueprint(LevelBlueprint bp) { var center = FPoint.MiddlePoint(Wall_Point1, Wall_Point2); var length = (Wall_Point2 - Wall_Point1).Length(); var degrot = (Wall_Point2 - Wall_Point1).ToDegAngle(); switch (Wall_WallType) { case WallStub.WallStubType.Void: bp.BlueprintVoidWalls.Add(new VoidWallBlueprint(center.X, center.Y, length, degrot)); break; case WallStub.WallStubType.Glass: bp.BlueprintGlassBlocks.Add(new GlassBlockBlueprint(center.X, center.Y, length, GlassBlockBlueprint.DEFAULT_WIDTH, degrot)); break; case WallStub.WallStubType.Mirror: bp.BlueprintMirrorBlocks.Add(new MirrorBlockBlueprint(center.X, center.Y, length, GlassBlockBlueprint.DEFAULT_WIDTH, degrot)); break; default: SAMLog.Error("ABTA::IWIBP", "Wall_WallType: " + Wall_WallType); return; } }
protected override void OnDraw(IBatchRenderer sbatch) { if (GDOwner.Selection == this) { sbatch.FillShape(GetArea().AsInflated(GDConstants.TILE_WIDTH / 2, GDConstants.TILE_WIDTH / 2), Color.Black * 0.333f); } switch (WallType) { case WallStubType.Void: if (_vvCacheKey != EquatableTuple.Create(Point1, Point2)) { _vvCacheKey = EquatableTuple.Create(Point1, Point2); _vvCacheRects = CommonWallRenderer.CreateVoidWallRenderRects(FPoint.MiddlePoint(Point1, Point2), (Point1 - Point2).Length(), (Point1 - Point2).ToAngle()); } CommonWallRenderer.DrawVoidWall_BG(sbatch, (Point1 - Point2).Length(), (Point1 - Point2).ToAngle(), _vvCacheRects); break; case WallStubType.Glass: CommonWallRenderer.DrawGlassWall(sbatch, GetArea()); break; case WallStubType.Mirror: CommonWallRenderer.DrawMirrorWall(sbatch, GetArea()); break; default: SAMLog.Error("LEWS::EnumSwitch_CS_OD", "WallType = " + WallType); break; } }
protected override void OnDrawOrderedForegroundLayer(IBatchRenderer sbatch) { switch (WallType) { case WallStubType.Void: if (_vvCacheKey != EquatableTuple.Create(Point1, Point2)) { _vvCacheKey = EquatableTuple.Create(Point1, Point2); _vvCacheRects = CommonWallRenderer.CreateVoidWallRenderRects(FPoint.MiddlePoint(Point1, Point2), (Point1 - Point2).Length(), (Point1 - Point2).ToAngle()); } CommonWallRenderer.DrawVoidWall_FG(sbatch, (Point1 - Point2).Length(), (Point1 - Point2).ToAngle(), _vvCacheRects); break; case WallStubType.Glass: // NOP break; case WallStubType.Mirror: // NOP break; default: SAMLog.Error("LEWS::EnumSwitch_CS_ODOFL", "WallType = " + WallType); break; } }
public LevelNodePipe(GameScreen scrn, IWorldNode start, IWorldNode end, PipeBlueprint.Orientation orientation) : base(scrn, GDConstants.ORDER_MAP_PIPE_ON) { NodeSource = start; NodeSink = end; Position = FPoint.MiddlePoint(start.Position, end.Position); DrawingBoundingBox = FSize.Diff(start.Position, end.Position) + new FSize(THICKNESS, THICKNESS); curvature = GetCurve(start, end, orientation); InitCurvature(); }
public FRotatedRectangle GetArea() { switch (WallType) { case WallStubType.Void: return(FRotatedRectangle.CreateByCenter(FPoint.MiddlePoint(Point1, Point2), (Point2 - Point1).Length(), VoidWallBlueprint.DEFAULT_WIDTH, (Point2 - Point1).ToAngle())); case WallStubType.Glass: return(FRotatedRectangle.CreateByCenter(FPoint.MiddlePoint(Point1, Point2), (Point2 - Point1).Length(), GlassBlockBlueprint.DEFAULT_WIDTH, (Point2 - Point1).ToAngle())); case WallStubType.Mirror: return(FRotatedRectangle.CreateByCenter(FPoint.MiddlePoint(Point1, Point2), (Point2 - Point1).Length(), MirrorBlockBlueprint.DEFAULT_WIDTH, (Point2 - Point1).ToAngle())); default: SAMLog.Error("LEWS::EnumSwitch_GA", "WallType = " + WallType); return(default(FRotatedRectangle)); } }
private void DrawNetwork(IBatchRenderer sbatch) { foreach (var src in _network.Sources) { foreach (var ray in src.Lasers) { if (src.LaserPowered) { sbatch.DrawCentered( (src.Type == RayType.Laser) ? Textures.TexLaserBase : Textures.TexShieldLaserBase, FPoint.MiddlePoint(ray.Start, ray.End), ray.Length + RAY_WIDTH / 4f, RAY_WIDTH, Color.White, ray.Angle); } else { sbatch.DrawCentered( (src.Type == RayType.Laser) ? Textures.TexLaserPointer : Textures.TexShieldLaserPointer, FPoint.MiddlePoint(ray.Start, ray.End), ray.Length, RAY_WIDTH, Color.White, ray.Angle); } } } foreach (var src in _network.Sources) { if (src.LaserPowered) { var pwr = FloatMath.AbsSin(src.UserData.LaserPulseTime * FloatMath.TAU * Cannon.LASER_GLOW_FREQ); foreach (var ray in src.Lasers) { sbatch.DrawCentered( (src.Type == RayType.Laser) ? Textures.TexLaserGlow : Textures.TexShieldLaserGlow, FPoint.MiddlePoint(ray.Start, ray.End), ray.Length + RAY_WIDTH / 4f, 2 * RAY_WIDTH, src.LaserFraction.Color * pwr, ray.Angle); } } } foreach (var src in _network.Sources) { foreach (var ray in src.Lasers) { var size = FLARE_SIZE_SMALL; if (src.LaserPowered) { size = FLARE_SIZE_BIG; } size += FloatMath.Sin(_flareScale) * FLARE_PULSE_SCALE; switch (ray.Terminator) { case LaserRayTerminator.VoidObject: sbatch.DrawCentered(ray.RayType == RayType.Laser ? Textures.TexLaserFlare : Textures.TexShieldLaserFlare, ray.End, size, size, Color.White, _flareRotation); break; case LaserRayTerminator.Target: if (ray.RayType == RayType.Laser) { sbatch.DrawCentered(Textures.TexLaserFlare, ray.End, size, size, Color.White, _flareRotation); } break; case LaserRayTerminator.LaserMultiTerm: var lsr = ray.RayType == RayType.Laser || ray.TerminatorRays.Any(r => r.Item1.RayType == RayType.Laser); sbatch.DrawCentered(lsr ? Textures.TexLaserFlareHalf : Textures.TexShieldLaserFlareHalf, ray.End, size, size, Color.White, _flareRotation); break; case LaserRayTerminator.LaserSelfTerm: case LaserRayTerminator.LaserFaultTerm: sbatch.DrawCentered(ray.RayType == RayType.Laser ? Textures.TexLaserFlare : Textures.TexShieldLaserFlare, ray.End, size, size, Color.White, _flareRotation); break; case LaserRayTerminator.BulletTerm: sbatch.DrawCentered(ray.RayType == RayType.Laser ? Textures.TexLaserFlare : Textures.TexShieldLaserFlare, ray.End, size, size, Color.White, _flareRotation); break; case LaserRayTerminator.OOB: case LaserRayTerminator.Portal: case LaserRayTerminator.Glass: case LaserRayTerminator.Mirror: //no draw break; default: SAMLog.Error("LASER::EnumSwitch_DN", "value: " + ray.Terminator); break; } } } }
// test of rays hit each other private bool RayParallality(FPoint v1s, FPoint v1e, float v1d, FPoint v2s, FPoint v2e, float v2d, bool reflTolerant, out FPoint intersect, out float u) { var a1 = (v1e - v1s).ToAngle(); var a2 = (v2e - v2s).ToAngle(); var maxAngle = reflTolerant ? FloatMath.RAD_POS_004 : FloatMath.RAD_POS_090; if (FloatMath.DiffRadiansAbs(a1, a2) < maxAngle) { // same direction var u1 = v2s.ProjectOntoLine(v1s, v1e); var u2 = v1s.ProjectOntoLine(v2s, v2e); if (u1 > 0 && u1 < 1) { intersect = Math2D.PointOnLine(u1, v1s, v1e); u = u1; return(true); } if (u2 > 0 && u2 < 1) { intersect = v1s; u = 0; return(true); } } else if (FloatMath.DiffRadiansAbs(a1 + FloatMath.RAD_POS_180, a2) < maxAngle) { var u1s = FloatMath.Clamp(v2e.ProjectOntoLine(v1s, v1e), 0f, 1f); var u1e = FloatMath.Clamp(v2s.ProjectOntoLine(v1s, v1e), 0f, 1f); var u2s = FloatMath.Clamp(v1e.ProjectOntoLine(v2s, v2e), 0f, 1f); var u2e = FloatMath.Clamp(v1s.ProjectOntoLine(v2s, v2e), 0f, 1f); var v1rs = (u1s == 0) ? v1s : Math2D.PointOnLine(u1s, v1s, v1e); var v1re = (u1e == 1) ? v1e : Math2D.PointOnLine(u1e, v1s, v1e); var v2rs = (u2s == 0) ? v2s : Math2D.PointOnLine(u2s, v2s, v2e); var v2re = (u1e == 1) ? v2e : Math2D.PointOnLine(u2e, v2s, v2e); var distStart = (v1rs - v2re).LengthSquared(); var distEnd = (v1re - v2rs).LengthSquared(); if (distStart < RAY_WIDTH * RAY_WIDTH && distEnd < RAY_WIDTH * RAY_WIDTH) { var pc = FPoint.MiddlePoint(v1s, v2s); pc = pc + (v1s - v2s).WithLength((v1d - v2d) / 2f); var pcu1 = pc.ProjectOntoLine(v1s, v1e); if (pcu1 < 0) { pc = v1s; } if (pcu1 > 1) { pc = v1e; } var pcu2 = pc.ProjectOntoLine(v2s, v2e); if (pcu2 < 0) { pc = v2s; } if (pcu2 > 1) { pc = v2e; } intersect = pc; u = pc.ProjectOntoLine(v1s, v1e); return(true); } else if (distStart < RAY_WIDTH * RAY_WIDTH) { var drStart = FloatMath.Sqrt(distStart); var drEnd = FloatMath.Sqrt(distEnd); var perc = (RAY_WIDTH - drStart) / (drEnd - drStart); u1e = u1s + (u1e - u1s) * perc; u2s = u2e + (u2s - u2e) * perc; v1re = Math2D.PointOnLine(u1e, v1s, v1e); v2rs = Math2D.PointOnLine(u2s, v2s, v2e); var v1rd = v1d + u1s * (v1e - v1s).Length(); var v2rd = v2d + u2s * (v2e - v2s).Length(); var pc = FPoint.MiddlePoint(v1rs, v2rs); pc = pc + (v1rs - v2rs).WithLength((v1rd - v2rd) / 2f); var pcu1 = pc.ProjectOntoLine(v1rs, v1re); if (pcu1 < u1s) { pc = v1rs; } if (pcu1 > u1e) { pc = v1re; } var pcu2 = pc.ProjectOntoLine(v2rs, v2re); if (pcu2 < u2s) { pc = v2rs; } if (pcu2 > u2e) { pc = v2re; } intersect = pc; u = pc.ProjectOntoLine(v1s, v1e); return(true); } else if (distEnd < RAY_WIDTH * RAY_WIDTH) { var drStart = FloatMath.Sqrt(distStart); var drEnd = FloatMath.Sqrt(distEnd); var perc = (RAY_WIDTH - drEnd) / (drStart - drEnd); u1s = u1e + (u1s - u1e) * perc; u2e = u2s + (u2e - u2s) * perc; v1rs = Math2D.PointOnLine(u1s, v1s, v1e); v2re = Math2D.PointOnLine(u2e, v2s, v2e); var v1rd = v1d + u1s * (v1e - v1s).Length(); var v2rd = v2d + u2s * (v2e - v2s).Length(); var pc = FPoint.MiddlePoint(v1rs, v2rs); pc = pc + (v1rs - v2rs).WithLength((v1rd - v2rd) / 2f); var pcu1 = pc.ProjectOntoLine(v1rs, v1re); if (pcu1 < u1s) { pc = v1rs; } if (pcu1 > u1e) { pc = v1re; } var pcu2 = pc.ProjectOntoLine(v2rs, v2re); if (pcu2 < u2s) { pc = v2rs; } if (pcu2 > u2e) { pc = v2re; } intersect = pc; u = pc.ProjectOntoLine(v1s, v1e); return(true); } } intersect = FPoint.Zero; u = float.NaN; return(false); }
public bool Run(KIController ki) { if (_runDirect != null) { var target = _runDirect(); if (target != null) { var rot = FloatMath.PositiveAtan2(target.Position.Y - ki.Cannon.Position.Y, target.Position.X - ki.Cannon.Position.X); ki.Cannon.KITarget = target; if (ki.MinimumRotationalDelta > 0 && FloatMath.DiffRadiansAbs(rot, ki.Cannon.Rotation.TargetValue) < ki.MinimumRotationalDelta) { ki.LastKIFunction = "Ign[" + Name + "]"; return(true); } ki.Cannon.Rotation.Set(rot); ki.LastKIFunction = Name; return(true); } } else if (_runPrecalc != null) { var target = _runPrecalc(); if (target != null) { ki.Cannon.KITarget = target.TargetCannon; if (ki.MinimumRotationalDelta > 0 && FloatMath.DiffRadiansAbs(target.CannonRotation, ki.Cannon.Rotation.TargetValue) < ki.MinimumRotationalDelta) { ki.LastKIFunction = "Ign[" + Name + "]"; return(true); } ki.Cannon.Rotation.Set(target.CannonRotation); ki.LastKIFunction = Name; return(true); } } else if (_runAntiLaser != null) { var ray = _runAntiLaser(); if (ray != null) { var target = ki.Cannon.Position.MirrorAt(FPoint.MiddlePoint(ray.Start, ray.End)); var rot = target.ToAngle(ki.Cannon.Position); ki.Cannon.KITarget = null; if (ki.MinimumRotationalDelta > 0 && FloatMath.DiffRadiansAbs(rot, ki.Cannon.Rotation.TargetValue) < ki.MinimumRotationalDelta / 4f) { ki.LastKIFunction = "Ign[" + Name + "]"; return(true); } ki.Cannon.Rotation.Set(rot); ki.LastKIFunction = Name; return(true); } return(false); } else if (_runGeneric != null) { _runGeneric(); return(true); } else if (_runCustom != null) { var f = _runCustom(); if (f != null) { var rot = f.Value; if (ki.MinimumRotationalDelta > 0 && FloatMath.DiffRadiansAbs(rot, ki.Cannon.Rotation.TargetValue) < ki.MinimumRotationalDelta / 4f) { ki.LastKIFunction = "Ign[" + Name + "]"; return(true); } ki.Cannon.Rotation.Set(rot); ki.LastKIFunction = Name; return(true); } return(false); } ki.Cannon.KITarget = null; return(false); }