// When useAltitude = true, the bounding box is extended // vertically to altitude = 0 to support FindUnitsInCircle queries // When false, the bounding box is given for the actor // at its current altitude Rectangle CalculateBounds(bool useAltitude) { var sizeVector = (PVecInt)size.Value; var loc = CenterLocation - sizeVector / 2; var si = Info.Traits.GetOrDefault <SelectableInfo>(); if (si != null && si.Bounds != null && si.Bounds.Length > 2) { loc += new PVecInt(si.Bounds[2], si.Bounds[3]); } var ios = occupySpace.Value; if (ios != null) { var altitude = ios.CenterPosition.Z * Game.CellSize / 1024; loc -= new PVecInt(0, altitude); if (useAltitude) { sizeVector = new PVecInt(sizeVector.X, sizeVector.Y + altitude); } } return(new Rectangle(loc.X, loc.Y, sizeVector.X, sizeVector.Y)); }
// When useAltitude = true, the bounding box is extended // vertically to altitude = 0 to support FindUnitsInCircle queries // When false, the bounding box is given for the actor // at its current altitude Rectangle CalculateBounds(bool useAltitude) { var size = (PVecInt)(Size.Value); var loc = CenterLocation - size / 2; var si = Info.Traits.GetOrDefault <SelectableInfo>(); if (si != null && si.Bounds != null && si.Bounds.Length > 2) { loc += new PVecInt(si.Bounds[2], si.Bounds[3]); } var move = Move.Value; if (move != null) { loc -= new PVecInt(0, move.Altitude); if (useAltitude) { size = new PVecInt(size.X, size.Y + move.Altitude); } } return(new Rectangle(loc.X, loc.Y, size.X, size.Y)); }
public override bool Equals(object obj) { if (obj == null) { return(false); } PVecInt o = (PVecInt)obj; return(o == this); }
public static IEnumerable <Actor> FindUnitsInCircle(this World world, PPos a, int r) { using (new PerfSample("FindUnitsInCircle")) { var min = a - PVecInt.FromRadius(r); var max = a + PVecInt.FromRadius(r); var actors = world.FindUnits(min, max); var rect = new Rectangle(min.X, min.Y, max.X - min.X, max.Y - min.Y); var inBox = actors.Where(x => x.ExtendedBounds.Value.IntersectsWith(rect)); return(inBox.Where(x => (x.CenterLocation - a).LengthSquared < r * r)); } }
public static int hash_PVecInt(PVecInt i2) { return(((i2.X * 5) ^ (i2.Y * 3)) / 4); }
public static PVecInt Min(PVecInt a, PVecInt b) { return new PVecInt(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public static int Dot(PVecInt a, PVecInt b) { return a.X * b.X + a.Y * b.Y; }
public static int Dot(PVecInt a, PVecInt b) { return(a.X * b.X + a.Y * b.Y); }
public static PVecInt Min(PVecInt a, PVecInt b) { return(new PVecInt(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y))); }
public static PSubVec ToPSubVec(this PVecInt vec) { return(new PSubVec((vec.X * PSubPos.PerPx), (vec.Y * PSubPos.PerPx))); }