Exemplo n.º 1
0
 public Link(PortalInfo p1, PortalInfo p2)
 {
     this.P1 = p1;
     this.P2 = p2;
 }
Exemplo n.º 2
0
        public bool addLink(int p1id, int p2id)
        {
            if (!checkLink(p1id, p2id))
            {
                return(false);
            }

            _cachedHashcode = 0;

            Portal p1 = this.pData[p1id];
            Portal p2 = this.pData[p2id];

            p1.addLink(p2id, true);  // outgoing
            p2.addLink(p1id, false); // incoming

            p2.KeysLeft--;

            if (this.Parent != null && this.Parent.LastLinks != null && this.Parent.LastLinks.Count > 0)
            {
                PortalInfo lastPortal = this.Parent.LastLinks[this.Parent.LastLinks.Count - 1].P1;
                p1.KeysLeft += 4;
            }
            if (this.LastLinks == null)
            {
                this.LastLinks = new List <Link>();
            }
            this.LastLinks.Add(new Link(this.glob.pInfos[p1id], this.glob.pInfos[p2id]));

            Field rightf    = null;
            Field leftf     = null;
            float rightsize = float.MaxValue;
            float leftsize  = float.MaxValue;

            foreach (int oid in p1.SideLinks.Keys)
            {
                if (this.pData[oid].SideLinks.ContainsKey(p2id))
                {
                    Field f = new Field(p1id, p2id, oid);

                    int   side = geohelper.findSide(this.glob.pInfos[p1id], this.glob.pInfos[p2id], this.glob.pInfos[oid]);
                    float size = (float)geohelper.calculateArea(this, f);
                    if (side == 1)
                    {
                        if (rightf == null || size < rightsize)
                        {
                            rightsize = size;
                            rightf    = f;
                        }
                    }
                    else if (side == -1)
                    {
                        if (leftf == null || size < leftsize)
                        {
                            leftsize = size;
                            leftf    = f;
                        }
                    }
                }
            }
            foreach (Field f in new Field[] { rightf, leftf })
            {
                if (f == null)
                {
                    continue;
                }
                List <int> intr = geohelper.getPointsInArea(this, f);
                foreach (int item in intr)
                {
                    this.PortalData[item].InTriangle = true;
                }
                this.fields.Add(f);
                f.Size = geohelper.calculateArea(this, f);
            }
            _changed = true;

            /*
             *
             * }*/

            return(true);
        }
Exemplo n.º 3
0
 public Vector(PortalInfo ni)
 {
     this.X = ni.Pos.X;
     this.Y = ni.Pos.Y;
 }
Exemplo n.º 4
0
 public void updatePortals(PortalInfo pi)
 {
     AllPortals.Update(pi);
 }
Exemplo n.º 5
0
 public static double calculateDistance(PortalInfo n1, PortalInfo n2)
 {
     return(CalcDistance(n1.Pos.X, n1.Pos.Y, n2.Pos.X, n2.Pos.Y));
 }
Exemplo n.º 6
0
        public static bool FindIntersection(PortalInfo s1, PortalInfo e1, PortalInfo s2, PortalInfo e2)
        {
            Border b1 = new Border();

            b1.addValue(s1.Pos);
            b1.addValue(e1.Pos);

            Border b2 = new Border();

            b2.addValue(s2.Pos);
            b2.addValue(e2.Pos);

            //if (!b1.overlaps(b2)) return false; // not even overlaps -> no collision possible!

            return(Intersect(new Vector(s1), new Vector(e1), new Vector(s2), new Vector(e2)));
        }
Exemplo n.º 7
0
 public static int findSide(PortalInfo n1, PortalInfo n2, PortalInfo n3)
 {
     return(findSide(n1.Pos.X, n1.Pos.Y, n2.Pos.X, n2.Pos.Y, n3.Pos.X, n3.Pos.Y));
 }
Exemplo n.º 8
0
 public static bool PointInPolygon(PointD[] Points, PortalInfo ni)
 {
     return(PointInPolygon(Points, ni.Pos.X, ni.Pos.Y));
 }
Exemplo n.º 9
0
        public Bitmap printGameState(int height, int width)
        {
            Bitmap   ret = new Bitmap(width, height);
            Graphics g   = Graphics.FromImage(ret);

            extBorder = new Border();

            for (int i = 0; i < gs.PortalInfos.Count; i++)
            {
                PortalInfo p = gs.PortalInfos[i];
                extBorder.addValue(p.Pos);
            }
            // Extend border
            extBorder.addValue(extBorder.LonXMin - extBorder.LonXDiff * borderPerc, extBorder.LatYMin - extBorder.LatYDiff * borderPerc);
            extBorder.addValue(extBorder.LonXMax + extBorder.LonXDiff * borderPerc, extBorder.LatYMax + extBorder.LatYDiff * borderPerc);

            foreach (Field f in gs.Fields)
            {
                List <System.Drawing.Point> points = new List <System.Drawing.Point>();
                foreach (int pid in f.NodesIds)
                {
                    float x1 = getXPer(gs.PortalInfos[pid]) * width;
                    float y1 = getYPer(gs.PortalInfos[pid]) * height;
                    points.Add(new System.Drawing.Point((int)x1, (int)y1));
                }
                g.FillPolygon(new SolidBrush(Color.FromArgb(30, Color.Blue)), points.ToArray());
            }

            Pen linkPen = new Pen(new SolidBrush(Color.Blue), 3);

            for (int i = 0; i < gs.PortalInfos.Count; i++)
            {
                Portal p = gs.PortalData[i];
                foreach (KeyValuePair <int, bool> target in p.SideLinks)
                {
                    if (!target.Value)
                    {
                        continue;                // insideLink, draw only outside.
                    }
                    float x1 = getXPer(gs.PortalInfos[i]) * width;
                    float y1 = getYPer(gs.PortalInfos[i]) * height;
                    float x2 = getXPer(gs.PortalInfos[target.Key]) * width;
                    float y2 = getYPer(gs.PortalInfos[target.Key]) * height;

                    float xm = (x1 + x2 * 9) / 10;
                    float ym = (y1 + y2 * 9) / 10;
                    linkPen.Color = Color.Blue;
                    g.DrawLine(linkPen, x1, y1, xm, ym);
                    linkPen.Color = Color.DarkBlue;
                    g.DrawLine(linkPen, xm, ym, x2, y2);
                }
            }


            for (int i = 0; i < gs.PortalData.Count; i++)
            {
                PortalInfo ni = gs.PortalInfos[i];
                Portal     n  = gs.PortalData[i];
                float      x1 = getXPer(ni) * width - (PortalWidth / 2);
                float      y1 = getYPer(ni) * height - (PortalWidth / 2);
                //g.FillEllipse(new SolidBrush(n.InTriangle ? Color.LightGray : Color.Black), x1, y1, PortalWidth, PortalWidth);
                g.DrawLine(new Pen(n.InTriangle ? Color.LightGray : Color.Black, 3), x1 - (PortalWidth / 2), y1, x1 + (PortalWidth / 2), y1);
                g.DrawLine(new Pen(n.InTriangle ? Color.LightGray : Color.Black, 3), x1, y1 - (PortalWidth / 2), x1, y1 + (PortalWidth / 2));

                if (gs.PortalInfos[i].ShowLabel)
                {
                    g.DrawString(ni.Name + " / " + ni.Pos.X + " / " + ni.Pos.Y, new Font("Tahoma", 12), Brushes.Black, x1, y1 + PortalWidth);
                }
            }

            PortalInfo fromPortal = null;

            foreach (Link link in gs.getTotalLinkList())
            {
                if (fromPortal != null)
                {
                    PortalInfo newPortal = link.P1;

                    float x1 = getXPer(fromPortal) * width;
                    float y1 = getYPer(fromPortal) * height;
                    float x2 = getXPer(newPortal) * width;
                    float y2 = getYPer(newPortal) * height;

                    g.DrawLine(new Pen(new SolidBrush(Color.Yellow), 1), x1, y1, x2, y2);
                }
                fromPortal = link.P1;
            }

            /*
             * if(MousePosition != null) {
             *  float x1 = getXPer(MousePosition) * width - (PortalWidth / 2);
             *  float y1 = getYPer(ni) * height - (PortalWidth / 2);
             *  g.FillEllipse(Color.Green), x1, y1, PortalWidth, PortalWidth);
             * }*/

            g.Dispose();

            return(ret);
        }
Exemplo n.º 10
0
 private float getXPer(PortalInfo ni)
 {
     return((float)((ni.Pos.X - extBorder.LonXMin) / extBorder.LonXDiff));
 }
Exemplo n.º 11
0
 private float getYPer(PortalInfo ni)
 {
     return((float)(1 - ((ni.Pos.Y - extBorder.LatYMin) / extBorder.LatYDiff)));
 }