コード例 #1
0
ファイル: GameObject.cs プロジェクト: ohadmanor/TDS
        private clsGroundAtom[] RandomizeAtomsInArea(clsPolygon Structure, ref QuadTree<clsGroundAtom> quadTree, int Qty)
        {
            double minX = double.MaxValue;
            double maxX = 0;
            double minY = double.MaxValue;
            double maxY = 0;
            IEnumerable<TerrainService.shPoint> PolPnts = Structure.Points;
            clsGroundAtom[] Atoms = new clsGroundAtom[Qty];


            System.Random Rnd = new Random();
       
            foreach(var pnt in PolPnts)
            {
                if (pnt.x > maxX) maxX = pnt.x;
                if (pnt.x < minX) minX = pnt.x;
                if (pnt.y > maxY) maxY = pnt.y;
                if (pnt.y < minY) minY = pnt.y;
            }


            DAreaRect rect = new DAreaRect(minX, minY, maxX, maxY);
            quadTree = new QuadTree<clsGroundAtom>(rect, 0, null);


            for (int i = 0; i < Qty; i++)
            {
                double vRnd = Rnd.NextDouble();
                double randX = minX + (maxX - minX) * vRnd;
                vRnd = Rnd.NextDouble();
                double randY = minY + (maxY - minY) * vRnd;

                // choose a random waypoint between rooms and corridors
                List<PolygonWaypoint> roomsAndCorridors = new List<PolygonWaypoint>();
                roomsAndCorridors.AddRange(Structure.waypointGraph.rooms);
                roomsAndCorridors.AddRange(Structure.waypointGraph.corridors);

                int randomWaypointIndex = Rnd.Next(roomsAndCorridors.Count());
                PolygonWaypoint waypoint = roomsAndCorridors[randomWaypointIndex];

                TerrainService.shPoint[] Pnts=PolPnts.ToArray();

                while (true)
                {
                    bool inPolygon =TerrainService.GeometryHelper.GeometryMath.isPointInPolygon(randX, randY,ref  Pnts);
                    if (inPolygon == true)
                    {
                        clsGroundAtom GroundAtom = new clsGroundAtom(this);
                        GroundAtom = new clsGroundAtom(this);
                        GroundAtom.GUID = Util.CretaeGuid();
                        GroundAtom.MyName = GroundAtom.GUID;
						// YD: generate position by waypoints and not randomly
                        //GroundAtom.curr_X = randX;
                        //GroundAtom.curr_Y = randY;
                        //GroundAtom.currPosition = new TerrainService.Vector(randX, randY, 0);
                        GroundAtom.curr_X = waypoint.x;
                        GroundAtom.curr_Y = waypoint.y;
                        GroundAtom.currPosition = new TerrainService.Vector(waypoint.x, waypoint.y, 0);
                        GroundAtom.currentStructureWaypoint = waypoint;
                        GroundAtom.currentAzimuth = Util.Azimuth2Points(GroundAtom.curr_X, GroundAtom.curr_Y,
                                            GroundAtom.currentStructureWaypoint.x, GroundAtom.currentStructureWaypoint.y);
						
						// set speed randomly and not fixed
                        GroundAtom.currentSpeed = Rnd.Next(3, 8);

                        Atoms[i] = GroundAtom;

                        GroundAtomObjectCollection.TryAdd(GroundAtom.GUID, GroundAtom);

                        GroundAtom.ChangeState(new REGULAR_MOVEMENT_IN_STRUCTURE_STATE(Structure, GroundAtom.currentStructureWaypoint));
                        m_GameManager.QuadTreeStructure1GroundAtom.PositionUpdate(GroundAtom);

                        break;
                    }
                    else
                    {
                        vRnd = Rnd.NextDouble();
                        randX = minX + (maxX - minX) * vRnd;
                        vRnd = Rnd.NextDouble();
                        randY = minY + (maxY - minY) * vRnd;
                    }
                }
            }


            return Atoms;
        }
コード例 #2
0
ファイル: GameObject.cs プロジェクト: ohadmanor/TDS
        //VH
        internal void PolygonsInit()
        {
            try
            {
                List<clsPolygon> structures = new List<clsPolygon>();

                Structure1 = TDS.DAL.PolygonsDB.GetPolygonByName("Polygon1");
                Structure2 = TDS.DAL.PolygonsDB.GetPolygonByName("Malam");

                // initialize waypoint graphs. TODO - move to non volatile afterwards
                Structure1.waypointGraph = new PolygonWaypointGraph();
                PolygonWaypoint waypoint1 = new PolygonWaypoint(1, 34.849099516868591, 32.098940297448664, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint waypoint2 = new PolygonWaypoint(2, 34.849078059196472, 32.098663090529335, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint waypoint3 = new PolygonWaypoint(3, 34.849582314491272, 32.098685812439619, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint waypoint7 = new PolygonWaypoint(7, 34.85012412071228, 32.098722167484318, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint waypoint8 = new PolygonWaypoint(8, 34.850113391876221, 32.098940297448664, PolygonWaypoint.WaypointType.ROOM);
                PolygonWaypoint waypoint9 = new PolygonWaypoint(9, 34.85012412071228, 32.098444959902984, PolygonWaypoint.WaypointType.ROOM);
                PolygonWaypoint waypoint10 = new PolygonWaypoint(10, 34.849571585655212, 32.0989584749222, PolygonWaypoint.WaypointType.ROOM);
                PolygonWaypoint opening0 = new PolygonWaypoint(4, 34.8490619659424, 32.0996174058948, PolygonWaypoint.WaypointType.OPENING);
                PolygonWaypoint opening4 = new PolygonWaypoint(5, 34.8496359586716, 32.0980768632898, PolygonWaypoint.WaypointType.OPENING);
                PolygonWaypoint opening5 = new PolygonWaypoint(6, 34.848627448082, 32.0989584749222, PolygonWaypoint.WaypointType.OPENING);
                opening0.edgeNum = 0;
                opening4.edgeNum = 4;
                opening5.edgeNum = 5;
                Structure1.waypointGraph.addWaypoint(waypoint1, waypoint2, opening0, opening5, waypoint10);
                Structure1.waypointGraph.addWaypoint(waypoint2, waypoint1, waypoint3);
                Structure1.waypointGraph.addWaypoint(waypoint3, waypoint2, opening4);
                Structure1.waypointGraph.addWaypoint(waypoint7, waypoint3);
                Structure1.waypointGraph.addWaypoint(waypoint8, waypoint7);
                Structure1.waypointGraph.addWaypoint(waypoint9, waypoint7);
                Structure1.waypointGraph.addWaypoint(waypoint10, waypoint3, waypoint1);
                Structure1.waypointGraph.addWaypoint(opening0, waypoint1);
                Structure1.waypointGraph.addWaypoint(opening4, waypoint3);
                Structure1.waypointGraph.addWaypoint(opening5, waypoint1);

                Structure2.waypointGraph = new PolygonWaypointGraph();
                PolygonWaypoint malamOpening1 = new PolygonWaypoint(1, 34.8513351380825, 32.098514261381, PolygonWaypoint.WaypointType.OPENING);
                malamOpening1.edgeNum = 1;
                PolygonWaypoint malamWaypoint2 = new PolygonWaypoint(2, 34.851239919662476, 32.098531303338191, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint malamWaypoint3 = new PolygonWaypoint(3, 34.851202368736267, 32.098304083596624, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint malamWaypoint4 = new PolygonWaypoint(4, 34.850950241088867, 32.098322261196749, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint malamWaypoint5 = new PolygonWaypoint(5, 34.851266741752625, 32.098753978136557, PolygonWaypoint.WaypointType.CORRIDOR);
                PolygonWaypoint malamWaypoint6 = new PolygonWaypoint(6, 34.850998520851135, 32.098772155647154, PolygonWaypoint.WaypointType.CORRIDOR);
                Structure2.waypointGraph.addWaypoint(malamOpening1, malamWaypoint2);
                Structure2.waypointGraph.addWaypoint(malamWaypoint2, malamOpening1, malamWaypoint3, malamWaypoint5);
                Structure2.waypointGraph.addWaypoint(malamWaypoint3, malamWaypoint2, malamWaypoint4);
                Structure2.waypointGraph.addWaypoint(malamWaypoint4, malamWaypoint3);
                Structure2.waypointGraph.addWaypoint(malamWaypoint5, malamWaypoint2, malamWaypoint6);
                Structure2.waypointGraph.addWaypoint(malamWaypoint6, malamWaypoint5);

                structures.Add(Structure1);
                structures.Add(Structure2);

                foreach (clsPolygon structure in structures)
                {
                    foreach (var pnt in structure.Points)
                    {
                        if (pnt.x > structure.maxX) structure.maxX = pnt.x;
                        if (pnt.x < structure.minX) structure.minX = pnt.x;
                        if (pnt.y > structure.maxY) structure.maxY = pnt.y;
                        if (pnt.y < structure.minY) structure.minY = pnt.y;
                    }
                }
            }
            catch (Exception ex)
            {

            }
         
          
        }
コード例 #3
0
ファイル: GameObject.cs プロジェクト: ohadmanor/TDS
 public QuadTree<clsGroundAtom> getQuadTreeByStructure(clsPolygon structure)
 {
     if (structure == Structure1) return m_GameManager.QuadTreeStructure1GroundAtom;
     else if (structure == Structure2) return m_GameManager.QuadTreeStructure2GroundAtom;
     else return null;
 }