Example #1
0
        public HashSet <IntVec3> MakeProjectileLine(Vector3 start, Vector3 end, Map map)
        {
            var resultingLine           = new ShootLine(start.ToIntVec3(), end.ToIntVec3());
            var points                  = resultingLine.Points();
            HashSet <IntVec3> positions = new HashSet <IntVec3>();

            var currentPos = CurPosition;

            currentPos.y = 0;
            var startingPosition = StartingPosition;

            startingPosition.y = 0;
            var destination = new Vector3(currentPos.x, currentPos.y, currentPos.z);

            Vector3 pos = (startingPosition + currentPos) / 2f;

            pos.y = 10;
            pos  += Quaternion.Euler(0, (startingPosition - currentPos).AngleFlat(), 0) * this.def.startingPositionOffset;

            var distance         = Vector3.Distance(startingPosition, currentPos) * this.def.totalSizeScale;
            var distanceToTarget = Vector3.Distance(startingPosition, currentPos);
            var widthFactor      = distance / distanceToTarget;

            var width         = distance * this.def.widthScaleFactor * widthFactor;
            var height        = distance * this.def.heightScaleFactor;
            var centerOfLine  = pos.ToIntVec3();
            var startPosition = StartingPosition.ToIntVec3();
            var endPosition   = this.CurPosition.ToIntVec3();

            if (points.Any())
            {
                foreach (var cell in GenRadial.RadialCellsAround(start.ToIntVec3(), height, true))
                {
                    if (centerOfLine.DistanceToSquared(endPosition) >= cell.DistanceToSquared(endPosition) && startPosition.DistanceTo(cell) > def.minDistanceToAffect)
                    {
                        var nearestCell = points.MinBy(x => x.DistanceToSquared(cell));
                        if ((width / height) * 2.5f > nearestCell.DistanceToSquared(cell))
                        {
                            positions.Add(cell);
                        }
                    }
                }
                foreach (var cell in points)
                {
                    var startCellDistance = startPosition.DistanceTo(cell);
                    if (startCellDistance > def.minDistanceToAffect && startCellDistance <= startPosition.DistanceTo(endPosition))
                    {
                        positions.Add(cell);
                    }
                }
            }
            return(positions);
        }