Ejemplo n.º 1
0
        public static Point DrawInside(Level level, Room room, Point from, int n, int value)
        {
            var step = new Point();

            if (from.X == room.Left)
            {
                step.Set(+1, 0);
            }
            else if (from.X == room.Right)
            {
                step.Set(-1, 0);
            }
            else if (from.Y == room.Top)
            {
                step.Set(0, +1);
            }
            else if (from.Y == room.Bottom)
            {
                step.Set(0, -1);
            }

            var p = new Point(from).Offset(step);

            for (var i = 0; i < n; i++)
            {
                if (value != -1)
                {
                    Set(level, p, value);
                }
                p.Offset(step);
            }

            return(p);
        }
 public override void DrawLine(int x1, int y1, int x2, int y2, System.Drawing.Color lineColor, int lineWidth)
 {
     P1.Set(x1, y1);
     P2.Set(x2, y2);
     TransformPoint(P1);
     TransformPoint(P2);
     SourceDrawOperations.DrawLine(P1.X, P1.Y, P2.X, P2.Y, lineColor, lineWidth);
 }
Ejemplo n.º 3
0
        public static bool ClipLine(Point a, Point b, int left, int right, int top, int bottom)
        {
            Point      clippedPoint = new Point();
            ClipResult res;

            res = clipLeftLine(a, b, clippedPoint, left);
            switch (res)
            {
            case ClipResult.A_IN: b.Set(clippedPoint); break;

            case ClipResult.B_IN: a.Set(clippedPoint); break;

            case ClipResult.BOTH_OUT: return(false);

            case ClipResult.BOTH_IN: break;
            }
            res = clipRightLine(a, b, clippedPoint, right);
            switch (res)
            {
            case ClipResult.A_IN: b.Set(clippedPoint); break;

            case ClipResult.B_IN: a.Set(clippedPoint); break;

            case ClipResult.BOTH_OUT: return(false);

            case ClipResult.BOTH_IN: break;
            }

            res = clipTopLine(a, b, clippedPoint, top);
            switch (res)
            {
            case ClipResult.A_IN: b.Set(clippedPoint); break;

            case ClipResult.B_IN: a.Set(clippedPoint); break;

            case ClipResult.BOTH_OUT: return(false);

            case ClipResult.BOTH_IN: break;
            }

            res = clipBottomLine(a, b, clippedPoint, bottom);
            switch (res)
            {
            case ClipResult.A_IN: b.Set(clippedPoint); break;

            case ClipResult.B_IN: a.Set(clippedPoint); break;

            case ClipResult.BOTH_OUT: return(false);

            case ClipResult.BOTH_IN: break;
            }

            return(true);
        }
Ejemplo n.º 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.content_image);
            size.Set(1100, 1100);
            start.Set(0, 0);
            DrawImage();

            ZoomControls ZC = FindViewById <ZoomControls>(Resource.Id.zoom);

            ZC.ZoomInClick  += ZC_ZoomInClick;
            ZC.ZoomOutClick += ZC_ZoomOutClick;
        }
        protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            base.OnSizeChanged(w, h, oldw, oldh);

            mNavigationHeight = Height;
            mNavigationWidth  = Width;

            mFirstCurveStartPoint.Set(mNavigationWidth / 2
                                      - CURVE_CIRCLE_RADIUS * 2
                                      - CURVE_CIRCLE_RADIUS / 3,
                                      0);

            mFirstCurveEndPoint.Set(mNavigationWidth / 2, CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4));

            mSecondCurveStartPoint = mFirstCurveEndPoint;

            mSecondCurveEndPoint.Set(mNavigationWidth / 2 + CURVE_CIRCLE_RADIUS * 2 + CURVE_CIRCLE_RADIUS / 3,
                                     0);

            //
            mFirstCurveControlPoint1.Set(mFirstCurveStartPoint.X + CURVE_CIRCLE_RADIUS + CURVE_CIRCLE_RADIUS / 4,
                                         mFirstCurveStartPoint.Y);

            mFirstCurveControlPoint2.Set(mFirstCurveEndPoint.X - CURVE_CIRCLE_RADIUS * 2 + CURVE_CIRCLE_RADIUS,
                                         mFirstCurveEndPoint.Y);

            //
            mSecondCurveControlPoint1.Set(mSecondCurveStartPoint.X + CURVE_CIRCLE_RADIUS * 2 - CURVE_CIRCLE_RADIUS,
                                          mSecondCurveStartPoint.Y);

            mSecondCurveControlPoint2.Set(mSecondCurveEndPoint.X - CURVE_CIRCLE_RADIUS + CURVE_CIRCLE_RADIUS / 4,
                                          mSecondCurveEndPoint.Y);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 1. Content size changed
 /// </summary>
 /// <param name="ResizedShape">IShape of Content</param>
 /// <param name="OldSize">Old content size</param>
 protected void Content_SizeChanged(IShape ResizedShape, Point OldSize)
 {
     UpdateVRange();
     UpdateHRange();
     OldContentSize.Set(this.Bounds.Size);
     RaiseContentSizeChanged(ResizedShape, OldContentSize);
 }
        public Point BiggestMinimumChildSize()
        {
            int maxX = 0;
            int maxY = 0;

            Point childSize = new Point();

            foreach (Control child in this.Children)
            {
                if (child.Visible)
                {
                    child.CalcSizeWithMargins(child.MinimumRequiredSize, childSize);

                    if (childSize.X > maxX)
                    {
                        maxX = childSize.X;
                    }
                    if (childSize.Y > maxY)
                    {
                        maxY = childSize.Y;
                    }
                }
            }

            mBiggestMinimumChildSize.Set(maxX, maxY);

            return(mBiggestMinimumChildSize);
        }
 public void DrawTriangle(
     int x1,
     int y1,
     int x2,
     int y2,
     int x3,
     int y3,
     System.Drawing.Color borderColor,
     System.Drawing.Color fillColor)
 {
     P1.Set(x1, y1);
     P2.Set(x2, y2);
     P3.Set(x3, y3);
     TransformPoint(P1, P1);
     TransformPoint(P2, P2);
     TransformPoint(P3, P3);
     SourceDrawOperations.DrawTriangle(
         P1.X,
         P1.Y,
         P2.X,
         P2.Y,
         P3.X,
         P3.Y,
         borderColor,
         fillColor);
 }
        private Point GetNaiveTargetVelocity(Point collisionPoint, Point targetPoint, double velocity)
        {
            Point velocityVector = (collisionPoint - targetPoint).Normalize();

            velocityVector.Set(velocityVector.X * velocity, velocityVector.Y * velocity);
            return(velocityVector);
        }
Ejemplo n.º 10
0
 /**
  * SetIsectPt
  *
  * @param isectpt
  */
 protected void SetIsectPt(IntersectPt isectpt)
 {
     t             = isectpt.GetT();
     Enter         = isectpt.GetEnter();
     IntersectObj  = isectpt.GetIntersectObj();
     OriginalObjID = isectpt.GetOriginal();
     Intersection.Set(isectpt.GetIntersection().GetX(), isectpt.GetIntersection().GetY(), isectpt.GetIntersection().GetZ());
 }
Ejemplo n.º 11
0
        public void Layout()
        {
            oldSize.Set(this.Bounds.Size);

            LayoutCore();

            RaiseSizeChanged(this, oldSize);
        }
Ejemplo n.º 12
0
        public void SetTest()
        {
            Point point = new Point(10, 20);

            point.Set(15, 25);
            Assert.AreEqual(15, point.X);
            Assert.AreEqual(25, point.Y);
        }
 public override void DrawLine(int x1, int y1, int x2, int y2, ILineStyleInfo theStyle)
 {
     P1.Set(x1, y1);
     P2.Set(x2, y2);
     TransformPoint(P1, P1);
     TransformPoint(P2, P2);
     SourceDrawOperations.DrawLine(P1.X, P1.Y, P2.X, P2.Y, theStyle);
 }
Ejemplo n.º 14
0
            public override void OnProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint)
            {
                width  = View.Width;
                height = View.Height;

                shadowSize.Set(width * 2, height * 2);
                // touch point is in the middle of the (height, width) top-right rect
                shadowTouchPoint.Set(width + width / 2 - centerOffset, height / 2 + centerOffset);
            }
Ejemplo n.º 15
0
            public override void OnSurfaceChanged(ISurfaceHolder holder, Format format, int width, int height)
            {
                base.OnSurfaceChanged(holder, format, width, height);

                //store the size of the frame
                size.Set(width, height);

                DrawFrame();
            }
        private Point GetNaiveTargetPoint(Point puckPline, Point collisionPoint, double malletRadius)
        {
            Point targetPoint  = null;
            Point attackVector = (puckPline - collisionPoint).Normalize();

            attackVector.Set(attackVector.X * rm, attackVector.Y * rm);
            targetPoint = collisionPoint - attackVector;
            return(targetPoint);
        }
        public override void OnProvideShadowMetrics(Point size, Point touch)
        {
            int width  = View.Width;
            int height = View.Height;

            shadow.SetBounds(0, 0, width, height);
            size.Set(width, height);
            touch.Set(width / 2, height / 2);
        }
Ejemplo n.º 18
0
    public Point WorldCoordToNode(Vector3 worldCoord)
    {
        Point node = Pools.Point;

        node.Set(
            (int)(worldCoord.x / nodeSize - bottomLeftCorner.x),
            (int)(worldCoord.z / nodeSize - bottomLeftCorner.y)
            );
        return(node);
    }
Ejemplo n.º 19
0
    private static Point ToGridCoord(this Vector2 v, float tileSize)
    {
        Point p = Pools.Point;

        p.Set(
            (int)(v.x / tileSize),
            (int)(v.y / tileSize)
            );
        return(p);
    }
Ejemplo n.º 20
0
    public override void OnProvideShadowMetrics(Point size, Point touch)
    {
        // Nous prenons les dimensions de notre image
        int width = View.Width;
        int height = View.Height;
        // Nous créons les dimensions de l'ombre
        _shadow.SetBounds(0, 0, width, height);
        size.Set(width, height);

        touch.Set(width / 2, height / 2);
    }
Ejemplo n.º 21
0
        public static bool ClipLine(Point a, Point b, int left, int right, int top, int bottom)
        {
            Point clippedPoint = new Point();
            ClipResult res;
            res = clipLeftLine(a, b, clippedPoint, left);
            switch (res)
            {
                case ClipResult.A_IN: b.Set(clippedPoint); break;
                case ClipResult.B_IN: a.Set(clippedPoint); break;
                case ClipResult.BOTH_OUT: return false;
                case ClipResult.BOTH_IN: break;
            }
            res = clipRightLine(a, b, clippedPoint, right);
            switch (res)
            {
                case ClipResult.A_IN: b.Set(clippedPoint); break;
                case ClipResult.B_IN: a.Set(clippedPoint); break;
                case ClipResult.BOTH_OUT: return false;
                case ClipResult.BOTH_IN: break;
            }

            res = clipTopLine(a, b, clippedPoint, top);
            switch (res)
            {
                case ClipResult.A_IN: b.Set(clippedPoint); break;
                case ClipResult.B_IN: a.Set(clippedPoint); break;
                case ClipResult.BOTH_OUT: return false;
                case ClipResult.BOTH_IN: break;
            }

            res = clipBottomLine(a, b, clippedPoint, bottom);
            switch (res)
            {
                case ClipResult.A_IN: b.Set(clippedPoint); break;
                case ClipResult.B_IN: a.Set(clippedPoint); break;
                case ClipResult.BOTH_OUT: return false;
                case ClipResult.BOTH_IN: break;
            }

            return true;
        }
Ejemplo n.º 22
0
 protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
 {
     _size.Set(MeasureSpec.GetSize(widthMeasureSpec), MeasureSpec.GetSize(heightMeasureSpec));
     if (_maxWidth >= 0 || _maxHeight >= 0)
     {
         _maxSize.Set(_maxWidth, _maxHeight);
         ConstrainTo(_size, _maxSize);
         widthMeasureSpec  = MeasureSpec.MakeMeasureSpec(_size.X, MeasureSpecMode.Exactly);
         heightMeasureSpec = MeasureSpec.MakeMeasureSpec(_size.Y, MeasureSpecMode.Exactly);
     }
     base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
 }
        private Point GetNaiveCollisionPoint(AHEntities.Action direction, Point puckPline, double puckRadius, int tableW, int tableH)
        {
            Point  attackVector   = new Point();
            Point  collisionPoint = null;
            Point  wallCollision  = null;
            double ratio          = 0;

            switch (direction)
            {
            case AHEntities.Action.ATTACK_RIGHT:
                ratio         = Math.Abs(puckPline.Y - (-tableH / 2)) / (tableH / 2);
                wallCollision = new Point(Math.Abs(tableW / 2 - puckPline.X) / (1 + ratio) + puckPline.X, -tableH / 2);
                attackVector  = (wallCollision - puckPline).Normalize();
                attackVector.Set(attackVector.X * puckRadius, attackVector.Y * puckRadius);
                collisionPoint = puckPline - attackVector;
                break;

            case AHEntities.Action.ATTACK_MIDDLE:
                attackVector.X = tableW / 2 - puckPline.X;
                attackVector.Y = -puckPline.Y;
                attackVector   = attackVector.Normalize();
                attackVector.Set(attackVector.X * puckRadius, attackVector.Y * puckRadius);
                collisionPoint = puckPline - attackVector;
                break;

            case AHEntities.Action.ATTACK_LEFT:
                ratio         = Math.Abs(puckPline.Y - tableH / 2) / (tableH / 2);
                wallCollision = new Point(Math.Abs(tableW / 2 - puckPline.X) / (1 + ratio) + puckPline.X, tableH / 2);
                attackVector  = (wallCollision - puckPline).Normalize();
                attackVector.Set(attackVector.X * puckRadius, attackVector.Y * puckRadius);
                collisionPoint = puckPline - attackVector;
                break;

            default:
                collisionPoint = null;
                break;
            }

            return(collisionPoint);
        }
        public override void OnProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint)
        {
            width  = View.Width;
            height = View.Height;

            // This is the overall dimension of your drag shadow
            shadowSize.Set(width * 2, height * 2);
            // This one tells the system how to translate your shadow on the screen so
            // that the user fingertip is situated on that point of your canvas.
            // In my case, the touch point is in the middle of the (height, width) top-right rect
            //shadowTouchPoint.Set(width + width / 2 - centerOffset, height / 2 + centerOffset);
            shadowTouchPoint.Set(width, height);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Tells the shape to calculate its size itself.
        /// May be based on sizes of child shapes.
        /// </summary>
        /// <remarks>
        /// Layout doesn't set the Position of the shape,
        /// it only changes the shape's Size.
        /// Position of a shape is always changed by its parent,
        /// in parent's Layout.
        /// Layout is a template method and cannot be overriden as a whole.
        /// Inheritors can only override LayoutCore().
        /// </remarks>
        public virtual void Layout()
        {
            oldSize.Set(this.Bounds.Size);

            LayoutCore();

            // CalcMinimumRequiredSize();
            MinimumRequiredSize.Set(this.Bounds.Size);

            //LayoutDock();

            RaiseSizeChanged(oldSize);
        }
Ejemplo n.º 26
0
        public void TestIfFieldsAreInitializedCorrectlyWithSetMethod()
        {
            var point = new Point(8, 3);

            point.Set(1, 10);
            var expectedX = 1;
            var expectedY = 10;
            var actualX   = point.Get()[0];
            var actualY   = point.Get()[1];

            Assert.AreEqual(expectedX, actualX);
            Assert.AreEqual(expectedY, actualY);
        }
Ejemplo n.º 27
0
        static void Main()
        {
            var p = new Point(1, 2);

            p.Set(3, 4);                   // readonly フィールドの書き換えが出来ちゃう

            System.Console.WriteLine(p.X); // 3
            System.Console.WriteLine(p.Y); // 4

            var r = new ReadOnlyPoint(1, 2);

            System.Console.WriteLine(r.X); // こっちなら、絶対に 1 な保証あり
            System.Console.WriteLine(r.Y); // 同、2
        }
Ejemplo n.º 28
0
            public override void OnProvideShadowMetrics(Point size, Point touch)
            {
                //Obtenemos las dimenciones de nuestro vista(view) que estamos arrastrando
                int width  = View.Width;
                int height = View.Height;

                //Le asignamos esas dimenciones a nuestro Drawable
                shadow.SetBounds(0, 0, width, height);
                //De igual forma establecemos las dimenciones de nuestro ShadownBuilder
                size.Set(width, height);

                //Definimos la posicion que se colocara nuestro ShadownBuilder cuando lo estemos arrastrando
                touch.Set(width / 2, height / 2);
            }
Ejemplo n.º 29
0
        /// ------------------------------------------------------------------------------------------------

        /// ------------------------------------------------------------------------------------------------
        #region Public Function
        public override void OnProvideShadowMetrics(Point size, Point touch)
        {
            try
            {
                int width  = View.Width;
                int height = View.Height;
                _shadow.SetBounds(0, 0, width, height);
                size.Set(width, height);
                touch.Set(width / 2, height / 2);
            }
            catch (Exception ex)
            {
                LogTracking.LogTrace(ex.ToString());
            }
        }
Ejemplo n.º 30
0
        private void Move(int x, int y)
        {
            if (!CheckMove(x, y))
            {
                return;
            }

            posChanged = !(playerPos.X + x == playerPos.X && playerPos.Y + y == playerPos.Y);

            if (posChanged)
            {
                field[playerPos.X, playerPos.Y] = objectUnder;
                objectUnder = field[playerPos.X + x, playerPos.Y + y];
                field[playerPos.X + x, playerPos.Y + y] = Objects.PLAYER;
            }

            playerPos.Set(playerPos.X + x, playerPos.Y + y);
        }
Ejemplo n.º 31
0
 private void AxMap1_MeasuringChanged(object sender, _DMapEvents_MeasuringChangedEvent e)
 {
     if (e.action == tkMeasuringAction.PointAdded)
     {
     }
     if (e.action == tkMeasuringAction.MesuringStopped)
     {
         if (btnAnotation.Checked)
         {
             Shape shp = new Shape();
             shp.Create(ShpfileType.SHP_POLYGON);
             //shp_tmp.EditAddShape()
             double x, y;
             //Debug.WriteLine("Measured points (in map units.): " + axMap1.Measuring.PointCount);
             for (int i = 0; i < axMap1.Measuring.PointCount; i++)
             {
                 if (axMap1.Measuring.get_PointXY(i, out x, out y))
                 {
                     //var c = 0;
                     MapWinGIS.Point ptn = new MapWinGIS.Point();
                     ptn.Set(x, y);
                     shp.InsertPoint(ptn, ref i);
                     //Debug.WriteLine("x={0}; y={1}", x, y);
                 }
             }
             tmpLayer.EditAddShape(shp);
             axMap1.Redraw();
         }
         if (btnVP.Checked)
         {
             double x, y;
             axMap1.Measuring.get_PointXY(0, out x, out y);
             MapWinGIS.Point pt1 = new Point();
             pt1.Set(x, y);
             axMap1.Measuring.get_PointXY(1, out x, out y);
             MapWinGIS.Point pt2 = new Point();
             pt2.Set(x, y);
             MapWinGIS.Image         DEMImg = axMap1.get_Image(idxLayerRaster);
             Vertical_Profiling_Form vpf    = new Vertical_Profiling_Form(DEMImg, pt1, pt2);
             vpf.Show(this);
             axMap1.Redraw();
         }
     }
 }
Ejemplo n.º 32
0
        protected void DrawLines(IRenderer Renderer)
        {
            if (this.VMembers == null ||
                this.VMembers.Children.Count == 0 ||
                this.Collapsed)
            {
                return;
            }

            const int nonExistent = int.MinValue;

            topPoint.Set(
                nonExistent,
                this.HMembers.Bounds.Bottom);

            foreach (Control child in this.VMembers.Children)
            {
                TreeViewNodeControl node = child as TreeViewNodeControl;
                if (node != null)
                {
                    if (topPoint.X == nonExistent)
                    {
                        topPoint.X = node.CollapseButton.Bounds.CenterX;
                    }

                    bottomPoint.Set(
                        topPoint.X,
                        node.CollapseButton.Bounds.CenterY);

                    rightPoint.Set(
                        node.HMembers.Bounds.Location.X - 3,
                        bottomPoint.Y);

                    Renderer.DrawOperations.DrawLine(
                        topPoint, bottomPoint, this.TreeLineStyle);

                    Renderer.DrawOperations.DrawLine(
                        bottomPoint, rightPoint, this.TreeLineStyle);
                }
            }
        }
Ejemplo n.º 33
0
        public void Move(Trooper self, World world, Game game, Move move)
        {
            if (form == null)
            {
                thread = new Thread(showWindow);
                thread.Start();
                Thread.Sleep(1000);
            }
            var panel = form.panel;
            var drawArea = new Bitmap(panel.Size.Width, panel.Size.Height);
            panel.Image = drawArea;
            Graphics g = Graphics.FromImage(drawArea);
            Pen pen = new Pen(Brushes.Black);
            g.DrawLine(pen, 1, 1, 40, 40);

            this.self = self;
            this.world = world;
            this.game = game;
            this.move = move;
            InitializeVariables();
            ProcessApproximation();
            if (world.MoveIndex == 37 && self.Type == TrooperType.Commander)
                world = world;
            var allowHill = !CheckShootMe();
            if (BonusGoal != null && GetTrooper(MyStrategy.WhoseBonus) == null)
                BonusGoal = null;
            if (BonusGoal != null && IsHaveBonus(GetTrooper(MyStrategy.WhoseBonus), GetBonusAt(BonusGoal)))
                BonusGoal = null;

            // Карта где медик и снайпер отдельно (map03)
            // Координаты где собираться:
            // 18 13
            // 11 6
            if (MapHash == Lab2Map
                && world.MoveIndex <= 2
                && (self.Type == TrooperType.FieldMedic || self.Type == TrooperType.Sniper)
                && Opponents.Count() == 0
               )
            {
                var rightLower = new Point(18, 14);
                var leftUpper = new Point(11, 5);
                var goal = rightLower.GetDistanceTo(self) < leftUpper.GetDistanceTo(self) ? rightLower : leftUpper;
                var to = GoScouting(goal, goal);
                if (to != null)
                {
                    Go(ActionType.Move, to);
                    return;
                }

            }

            if (IfFieldRationNeed())
            {
                Go(ActionType.EatFieldRation);
                return;
            }
            Reached(new Point(self));

            if (Opponents.Count() != 0)
            {
                AllowTakeBonus = false;
                // Чтобы знали куда бежать если противник отступит
                PointGoal = new Point(Opponents[0]);
                PointGoal.profit = world.MoveIndex;

                var action = BruteForceDo();
                if (action != null)
                {
                    if (Equal(self, action) && action.Action == ActionType.Move && self.ActionPoints < GetMoveCost())
                    {
                        Go(ActionType.EndTurn);
                    }
                    else
                    {
                        Go(action.Action, new Point(action.X, action.Y));
                    }
                    return;
                }
            }

            if (self.Type == TrooperType.FieldMedic)
            {
                var ifHelp = IfHelpTeammate();
                if (ifHelp != null)
                {
                    var goal = GetTrooperAt(ifHelp.X, ifHelp.Y);
                    if (goal != null && goal.Hitpoints < goal.MaximalHitpoints && ifHelp.Nearest(self) && game.FieldMedicHealCost <= self.ActionPoints)
                    {
                        Go(ActionType.Heal, ifHelp);
                        return;
                    }
                    if (IsCanMove())
                    {
                        var to = GoToUnit(self, ifHelp, map, beginFree: true, endFree: true);
                        if (to != null)
                        {
                            Go(ActionType.Move, to);
                            return;
                        }
                    }
                }
            }

            var ifUseMedikit = IfUseMedikit();
            if (ifUseMedikit != null)
            {
                Go(ActionType.UseMedikit, ifUseMedikit);
                return;
            }

            if (allowHill && IfRequestEnemyDisposition())
            {
                Go(ActionType.RequestEnemyDisposition);
                return;
            }

            // Группировка
            if ((GetTeamRadius() > MaxTeamRadius && self.Id == commander.Id ||
                GetTeamRadius() > MaxTeamRadius/2 && self.Id != commander.Id)
                && self.ActionPoints >= GetMoveCost())
            {
                var bestTurn = new Point(0, 0, Inf);
                for (var i = 0; i < Width; i++)
                {
                    for (var j = 0; j < Height; j++)
                    {
                        var r = Math.Max(MaxTeamRadius, GetTeamRadius(self.Id, new Point(i, j)));
                        if (r < bestTurn.profit && r < GetTeamRadius())
                        {
                            bestTurn.Set(i, j, r);
                        }
                    }
                }
                if (bestTurn.profit < Inf)
                {
                    var to = GoScouting(bestTurn, PointGoal ?? (BonusGoal ?? bestTurn));
                    if (to != null)
                    {
                        Go(ActionType.Move, to);
                        return;
                    }
                }
            }

            Trooper whoseBonus = null;
            var ifTeamBonus = IfTeamBonus(ref whoseBonus, AllowTakeBonus);
            if (ifTeamBonus != null && BonusGoal == null && map[ifTeamBonus.X, ifTeamBonus.Y] == 0 && !Equal(ifTeamBonus, self))
            {
                BonusGoal = ifTeamBonus;
                MyStrategy.WhoseBonus = whoseBonus.Id;
            }

            var waitingHelp = false; //allowHill && IfNeedHelp() && self.Type != TrooperType.FieldMedic && GetBestHelper() != null;
            var allowNothing = true;

            if (!waitingHelp && IsCanMove() && BonusGoal != null && MyStrategy.WhoseBonus == self.Id)
            {
                if (IsCanUpper())
                {
                    Go(ActionType.RaiseStance);
                    return;
                }
                allowNothing = false;
                var to = GoScouting(BonusGoal, PointGoal ?? BonusGoal); //GoToUnit(self, BonusGoal, map, beginFree: true, endFree: false);
                // Если путь до бонуса пока что занят, то все равно идти к нему
                if (to == null)
                {
                    to = GoToUnit(self, BonusGoal, notFilledMap, beginFree: true, endFree: true);
                    if (to != null && map[to.X, to.Y] == 0 && self.ActionPoints >= 2 * GetMoveCost(self)) // TODO: ???
                    {
                        Go(ActionType.Move, to);
                        return;
                    }
                }
                else
                {
                    if (GetTeamRadius(self.Id, to) > MaxTeamRadius && GetTeamRadius() > GetTeamRadius(self.Id, to))
                        to = GoScouting(new Point(self), PointGoal ?? BonusGoal);
                    Go(ActionType.Move, to);
                    return;
                }
            }

            // Пытаюсь освободить дорогу до бонуса
            if (IsCanMove() && BonusGoal != null && MyStrategy.WhoseBonus != self.Id)
            {
                if (IsCanUpper())
                {
                    Go(ActionType.RaiseStance);
                    return;
                }
                var bestTurn = SkipPath(GetTrooper(MyStrategy.WhoseBonus), PointGoal ?? BonusGoal);
                var to = bestTurn == null ? null : GoScouting(bestTurn, PointGoal ?? (BonusGoal ?? new Point(commander)));//GoToUnit(self, bestTurn, map, beginFree: true, endFree: false);
                if (to == null || Equal(to, self) && self.ActionPoints < GetMoveCost()) // если Equal(to, self)) тоже делаем move, иначе он не дойдет обратно
                    Go(ActionType.EndTurn);
                else
                    Go(ActionType.Move, to);
                return;
            }

            var ifNothing = IfNothing();
            if (allowNothing && ifNothing != null && IsCanMove())
            {
                if (IsCanUpper())
                {
                    Go(ActionType.RaiseStance);
                    return;
                }

                Point to;
                if (self.Id == commander.Id)
                {
                    to = GoToUnit(self, ifNothing, map, beginFree: true, endFree: false);
                    if (GetTeamRadius(self.Id, to) > MaxTeamRadius)
                        to = GoScouting(new Point(self), ifNothing);
                }
                else
                {
                    to = GoScouting(ifNothing, ifNothing);
                }
                if (to == null || Equal(self, to) && self.ActionPoints < GetMoveCost())
                {
                    if (to == null && changedCommander == -1)
                    {
                        // значит мы застряли
                        // передать коммандование
                        ChangeCommander();
                    }
                    else
                    {
                        Go(ActionType.EndTurn);
                        return;
                    }
                }
                else if (!waitingHelp)
                {
                    Go(ActionType.Move, to);
                    return;
                }
            }

            Point go = GoScouting(new Point(self), IfNothingCommander() ?? new Point(self)); // подумать что делать
            if (Equal(self, go) && self.ActionPoints < GetMoveCost())
                Go(ActionType.EndTurn);
            else
                Go(ActionType.Move, go);
        }
Ejemplo n.º 34
0
 public void CalcSizeWithMargins(Point originalSize, Point result)
 {
     result.Set(
         originalSize.X + Box.Margins.LeftAndRight,
         originalSize.Y + Box.Margins.TopAndBottom);
 }
Ejemplo n.º 35
0
 public virtual void DeTransformPoint(Point src, Point dst)
 {
     dst.Set(src);
 }
Ejemplo n.º 36
0
	/**
	 * RenderScene
	 */
	public void RenderScene(Canvas canvas, int width, int section, int nsections)
	{
		Vector view = camera.GetViewDir();
		Vector up = camera.GetOrthoUp();
		Vector plane = new Vector();
		Vector horIncr = new Vector();
		Vector vertIncr = new Vector();
		double ylen = camera.GetFocalDist() * (double)Math.Tan(0.5f * camera.GetFOV());
		double xlen = ylen * canvas.GetWidth() / canvas.GetHeight();
		Point upleft = new Point();
		Point upright = new Point();
		Point lowleft = new Point();
		Point basepoint = new Point();
		Point current;
		Ray eyeRay = new Ray();
		int ypixel, xpixel;

		RayID = 1;
		plane.Cross(view, up);
		view.Scale(camera.GetFocalDist());
		up.Scale(ylen);
		plane.Scale(-xlen);
		upleft.FindCorner(view, up, plane, camera.GetPosition());
		plane.Negate();
		upright.FindCorner(view, up, plane, camera.GetPosition());
		up.Negate();
		plane.Negate();
		lowleft.FindCorner(view, up, plane, camera.GetPosition());
		horIncr.Sub(upright, upleft);
		horIncr.Scale(horIncr.Length() / ((double)canvas.GetWidth()));
		vertIncr.Sub(lowleft, upleft);
		vertIncr.Scale(vertIncr.Length() / ((double)canvas.GetHeight()));
		basepoint.Set(upleft.GetX() + 0.5f * (horIncr.GetX() + vertIncr.GetX()), upleft.GetY() + 0.5f * (horIncr.GetY() + vertIncr.GetY()),
			upleft.GetZ() + 0.5f * (horIncr.GetZ() + vertIncr.GetZ()));
		eyeRay.SetOrigin(camera.GetPosition());

		int xstart = section * width / nsections;
		int xend = xstart + width / nsections;

		Console.WriteLine("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight());

		for(ypixel = 0; ypixel < canvas.GetHeight(); ypixel++)
		{
			current = new Point(basepoint);
			for(xpixel = 0; xpixel < canvas.GetWidth(); xpixel++)
			{
				if(xpixel >= xstart && xpixel < xend)
				{
					Color color = new Color(0.0f, 0.0f, 0.0f);
					eyeRay.GetDirection().Sub(current, eyeRay.GetOrigin());
					eyeRay.GetDirection().Normalize();
					eyeRay.SetID(RayID);
					this.RayID = this.RayID + 1;
					Shade(octree, eyeRay, color, 1.0f, 0, 0);
					canvas.Write(Brightness, xpixel, ypixel, color);
				}
				current.Add(horIncr);
			}
			basepoint.Add(vertIncr);
		}
		Console.WriteLine("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight());
	}
Ejemplo n.º 37
0
	/**
	 * CreateChildren
	 *
	 * @param objects
	 * @param depth
	 */
	private void CreateChildren(ObjNode objects, int depth)
	{

		double maxX = OctFaces[MAXX].GetVert(0).GetX();
		double minX = OctFaces[MINX].GetVert(0).GetX();
		double maxY = OctFaces[MAXY].GetVert(0).GetY();
		double minY = OctFaces[MINY].GetVert(0).GetY();
		double maxZ = OctFaces[MAXZ].GetVert(0).GetZ();
		double minZ = OctFaces[MINZ].GetVert(0).GetZ();
		Point midpt = new Point((maxX + minX) / 2.0f, (maxY + minY) / 2.0f, (maxZ + minZ) / 2.0f);
		Point max = new Point();
		Point min = new Point();
		ObjNode currentnode;
		int i;

		max.Set(maxX, maxY, maxZ);
		min.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ());
		Child[0] = new OctNode(max, min);
		max.Set(maxX, midpt.GetY(), maxZ);
		min.Set(midpt.GetX(), minY, midpt.GetZ());
		Child[1] = new OctNode(max, min);
		max.Set(maxX, midpt.GetY(), midpt.GetZ());
		min.Set(midpt.GetX(), minY, minZ);
		Child[2] = new OctNode(max, min);
		max.Set(maxX, maxY, midpt.GetZ());
		min.Set(midpt.GetX(), midpt.GetY(), minZ);
		Child[3] = new OctNode(max, min);
		max.Set(midpt.GetX(), maxY, maxZ);
		min.Set(minX, midpt.GetY(), midpt.GetZ());
		Child[4] = new OctNode(max, min);
		max.Set(midpt.GetX(), midpt.GetY(), maxZ);
		min.Set(minX, minY, midpt.GetZ());
		Child[5] = new OctNode(max, min);
		max.Set(midpt.GetX(), midpt.GetY(), midpt.GetZ());
		min.Set(minX, minY, minZ);
		Child[6] = new OctNode(max, min);
		max.Set(midpt.GetX(), maxY, midpt.GetZ());
		min.Set(minX, midpt.GetY(), minZ);
		Child[7] = new OctNode(max, min);

		OctNode[] adj = this.Adjacent;
		OctNode[] chld = this.Child;

		OctNode adj0 = adj[0];
		OctNode adj1 = adj[1];
		OctNode adj2 = adj[2];
		OctNode adj3 = adj[3];
		OctNode adj4 = adj[4];
		OctNode adj5 = adj[5];

		OctNode chld0 = chld[0];
		OctNode chld1 = chld[1];
		OctNode chld2 = chld[2];
		OctNode chld3 = chld[3];
		OctNode chld4 = chld[4];
		OctNode chld5 = chld[5];
		OctNode chld6 = chld[6];
		OctNode chld7 = chld[7];

		Child[0].FormAdjacent(adj0, adj1, adj2, chld4, chld1, chld3);
		Child[1].FormAdjacent(adj0, chld0, adj2, chld5, adj4, chld2);
		Child[2].FormAdjacent(adj0, chld3, chld1, chld6, adj4, adj5);
		Child[3].FormAdjacent(adj0, adj1, chld0, chld7, chld2, adj5);
		Child[4].FormAdjacent(chld0, adj1, adj2, adj3, chld5, chld7);
		Child[5].FormAdjacent(chld1, chld4, adj2, adj3, adj4, chld6);
		Child[6].FormAdjacent(chld2, chld7, chld5, adj3, adj4, adj5);
		Child[7].FormAdjacent(chld3, adj1, chld4, adj3, chld6, adj5);
		if(objects != null)
		{
			currentnode = objects;
		}
		else
		{
			currentnode = ObjList;
		}
		while(currentnode != null)
		{
			ObjectType currentobj = currentnode.GetObj();
			for(i = 0; i < 8; i++)
			{
				OctNode cc = chld[i];
				max = cc.GetFace(0).GetVert(0);
				min = cc.GetFace(5).GetVert(3);
				if(!((currentobj.GetMin().GetX() > max.GetX()) ||
					(currentobj.GetMax().GetX() < min.GetX())))
				{
					if(!((currentobj.GetMin().GetY() > max.GetY()) ||
						(currentobj.GetMax().GetY() < min.GetY())))
					{
						if(!((currentobj.GetMin().GetZ() > max.GetZ()) ||
							(currentobj.GetMax().GetZ() < min.GetZ())))
						{
							ObjNode newnode = new ObjNode(currentobj, Child[i].GetList());
							cc.SetList(newnode);
							cc.IncNumObj();
						}
					}
				}
			}
			currentnode = currentnode.Next();
		}
		if(objects == null)
		{
			NumObj = 0;
			ObjList = null;
		}
		if(depth < MaxDepth)
		{
			for(i = 0; i < 8; i++)
			{
				if(Child[i].GetNumObj() > MaxObj)
				{
					Child[i].CreateChildren(null, depth + 1);
				}
			}
		}
	}
Ejemplo n.º 38
0
 protected virtual void TransformPoint(Point src, Point dst)
 {
     dst.Set(src);
 }