// This runs the check public override void Run() { BlockMap <BlockEntry> blockmap = BuilderPlug.Me.ErrorCheckForm.BlockMap; int progress = 0; int stepprogress = 0; float maxradius = 0; foreach (ThingTypeInfo tti in General.Map.Data.ThingTypes) { if (tti.Radius > maxradius) { maxradius = tti.Radius; } } // Go for all the things foreach (Thing t in General.Map.Map.Things) { ThingTypeInfo info = General.Map.Data.GetThingInfo(t.Type); bool stuck = false; StuckType stucktype = StuckType.None; // Check this thing for getting stuck? if ((info.ErrorCheck == ThingTypeInfo.THING_ERROR_INSIDE_STUCK) && (info.Blocking > ThingTypeInfo.THING_BLOCKING_NONE)) { // Make square coordinates from thing float blockingsize = t.Size - ALLOWED_STUCK_DISTANCE; Vector2D lt = new Vector2D(t.Position.x - blockingsize, t.Position.y - blockingsize); Vector2D rb = new Vector2D(t.Position.x + blockingsize, t.Position.y + blockingsize); Vector2D bmlt = new Vector2D(t.Position.x - maxradius, t.Position.y - maxradius); Vector2D bmrb = new Vector2D(t.Position.x + maxradius, t.Position.y + maxradius); // Go for all the lines to see if this thing is stuck List <BlockEntry> blocks = blockmap.GetSquareRange(new RectangleF(bmlt.x, bmlt.y, (bmrb.x - bmlt.x), (bmrb.y - bmlt.y))); Dictionary <Linedef, Linedef> doneblocklines = new Dictionary <Linedef, Linedef>(blocks.Count * 3); foreach (BlockEntry b in blocks) { foreach (Linedef l in b.Lines) { // Only test when sinlge-sided, two-sided + impassable and not already checked if (((l.Back == null) || l.IsFlagSet(General.Map.Config.ImpassableFlag)) && !doneblocklines.ContainsKey(l)) { // Test if line ends are inside the thing if (PointInRect(lt, rb, l.Start.Position) || PointInRect(lt, rb, l.End.Position)) { // Thing stuck in line! stuck = true; } // Test if the line intersects the square else if (Line2D.GetIntersection(l.Start.Position, l.End.Position, lt.x, lt.y, rb.x, lt.y) || Line2D.GetIntersection(l.Start.Position, l.End.Position, rb.x, lt.y, rb.x, rb.y) || Line2D.GetIntersection(l.Start.Position, l.End.Position, rb.x, rb.y, lt.x, rb.y) || Line2D.GetIntersection(l.Start.Position, l.End.Position, lt.x, rb.y, lt.x, lt.y)) { // Thing stuck in line! stuck = true; stucktype = StuckType.Line; } // Checked doneblocklines.Add(l, l); } } // Check if thing is stuck in other things if (info.Blocking != ThingTypeInfo.THING_BLOCKING_NONE) { foreach (Thing ot in b.Things) { // Don't compare the thing with itself if (t.Index == ot.Index) { continue; } // Only check of items that can block if (General.Map.Data.GetThingInfo(ot.Type).Blocking == ThingTypeInfo.THING_BLOCKING_NONE) { continue; } // need to compare the flags /* TODO: skill settings * Dictionary<string, bool> flags1 = t.GetFlags(); * Dictionary<string, bool> flags2 = ot.GetFlags(); */ if (FlagsOverlap(t, ot) && ThingsOverlap(t, ot)) { stuck = true; stucktype = StuckType.Thing; } } } } } // Stuck? if (stuck) { // Make result switch (stucktype) { case StuckType.Line: SubmitResult(new ResultStuckThingInLine(t)); break; case StuckType.Thing: SubmitResult(new ResultStuckThingInThing(t)); break; } } else { // Check this thing for being outside the map? if (info.ErrorCheck >= ThingTypeInfo.THING_ERROR_INSIDE) { // Get the nearest line to see if the thing is outside the map bool outside = false; Linedef l = General.Map.Map.NearestLinedef(t.Position); if (l.SideOfLine(t.Position) <= 0) { outside = (l.Front == null); } else { outside = (l.Back == null); } // Outside the map? if (outside) { // Make result SubmitResult(new ResultThingOutside(t)); } } } // Handle thread interruption try { Thread.Sleep(0); } catch (ThreadInterruptedException) { return; } // We are making progress! if ((++progress / PROGRESS_STEP) > stepprogress) { stepprogress = (progress / PROGRESS_STEP); AddProgress(1); } } }
private void Update() { //sprite moving animation if (isSpriteSet) { Vector2 fixedOffset = new Vector2(0.5f, -0.5f); bool stuck = false; float distance = Vector2.Distance(_location.ToVector2(), _currStateInfo.lastLoc); if (_character != null) { stuck = _character.isStuck; } //stuck animation if (stuck) { inStuckAnimation = true; Vector2 v = Vector2.zero; float x = 0f; float y = 0f; switch (_character.Direction) { case Direction.North: x = 0f; y = 1f; break; case Direction.South: x = 0f; y = -1f; break; case Direction.West: x = -1f; y = 0f; break; case Direction.East: x = 1f; y = 0f; break; } Vector2 visualOffset = new Vector2(x, y); visualOffset *= (_currStateInfo.fractionComplete); v = _currStateInfo.lastLoc + visualOffset + fixedOffset; _visuals.position = v * WorldManager.g.TileSize; var stuckCurve = visStuckCurve; switch (stuckType) { case StuckType.MoveStuck: stuckCurve = visStuckCurve; break; case StuckType.PushStuck: stuckCurve = visPushStuckCurve; break; case StuckType.PushedStuck: stuckCurve = visPushedStuckCurve; break; } if (timer < stuckDuration) { timer += Time.deltaTime; _currStateInfo.fractionComplete = stuckCurve.Evaluate(timer / stuckDuration); } if (timer >= stuckDuration) { AnimationStop(); _currStateInfo.lastLoc = _location.ToVector2(); _currStateInfo.fractionComplete = 0f; timer = 0f; _character.isStuck = false; stuckType = StuckType.Null; inStuckAnimation = false; } //non stuck } else { if (!instantMove && distance > 0f) { // if(inStuckAnimation) // { // AnimationStop(); // _currStateInfo.lastLoc = _location.ToVector2(); // _currStateInfo.fractionComplete = 0f; // timer = 0f; // _character.isStuck = false; // stuckType = StuckType.Null; // inStuckAnimation=false; // } Vector2 v = Vector2.zero; Vector2 visualOffset = (_location.ToVector2() - _currStateInfo.lastLoc) * (_currStateInfo.fractionComplete); v = _currStateInfo.lastLoc + visualOffset + fixedOffset; _visuals.position = v * WorldManager.g.TileSize; if (_character != null) { if (!_character.onMergingStar) { _collidingType = EntityCollidingType.Colliding; } _currStateInfo.characterInMoving = true; } if (timer < movingDuration) { timer += Time.deltaTime; if (_character != null) { if (_character.isPushedUp) { _currStateInfo.fractionComplete = visPushedUpCurve.Evaluate(timer / movingDuration); } else if (_character.isPushedDown) { _currStateInfo.fractionComplete = visPushedDownCurve.Evaluate(timer / movingDuration); } else { _currStateInfo.fractionComplete = visMovingCurve.Evaluate(timer / movingDuration); } } else { _currStateInfo.fractionComplete = visMovingCurve.Evaluate(timer / movingDuration); } } if (timer >= movingDuration) // why can't else work??? { AnimationStop(); _currStateInfo.lastLoc = _location.ToVector2(); _currStateInfo.fractionComplete = 0f; timer = 0f; _collidingType = _tempCollisionType; if (_character != null) { _currStateInfo.characterInMoving = false; _character.isPushedUp = false; _character.isPushedDown = false; _character.characterInMoving = false; } isPushed = false; } } else { Vector2 v = _currStateInfo.lastLoc + fixedOffset; _visuals.position = v * WorldManager.g.TileSize; _currStateInfo.lastLoc = _location.ToVector2(); instantMove = false; _collidingType = _tempCollisionType; } } } }