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);
    }
        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;
        }
Example #3
0
 public void CalcSizeWithMargins(Point originalSize, Point result)
 {
     result.Set(
         originalSize.X + Box.Margins.LeftAndRight,
         originalSize.Y + Box.Margins.TopAndBottom);
 }
 public virtual void DeTransformPoint(Point src, Point dst)
 {
     dst.Set(src);
 }
 protected virtual void TransformPoint(Point src, Point dst)
 {
     dst.Set(src);
 }
Example #6
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);
        }
Example #7
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);
				}
			}
		}
	}
Example #8
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());
	}