Beispiel #1
0
        public void Init(IExampleContextManager contextManager, BuildingIngredientConfig config, WorldGeneratorConfig worldGeneratorConfig, IRandomNumberGenerator rng,
                         ValueMap civilizationMap, ValueMap soilMap, ValueMap vegetationMapValues, ValueMap debugMapValues)
        {
            _rng           = rng;
            _config        = config;
            _soilMap       = soilMap;
            _walkability   = contextManager.Current.Walkability;
            _vegetationMap = vegetationMapValues;
            base.Init(contextManager.Current, config, worldGeneratorConfig);

            Values            = new ValueMap(1, worldGeneratorConfig.XSize, worldGeneratorConfig.YSize);
            _tileMatricesByte = GameContext.TileMatricesByLayer;
            _tileset          = worldGeneratorConfig.Tileset;
            _gameConfig       = worldGeneratorConfig.GameConfig;

            _grid       = new Grid(contextManager, true);
            _pathfinder = Pathfinder.Create(contextManager);
        }
    public void StartGame()
    {
        RandomUtility.Initialize(Random.rotation);

        StartCoordinates startCoords = level.Generate();

        PortalPosition = startCoords.playerPosition;
        player         = Instantiate <Player> (_playerPrefab, PortalPosition, Quaternion.identity);
        Portal         = Instantiate(_portalPrefab, PortalPosition, Quaternion.identity);

        rescuee = Instantiate(rescueePrefab, startCoords.rescueePosition, Quaternion.identity);
        enemyController.Initialize(startCoords.enemyPositions, player.transform);

        walkableMap = startCoords.walkableMap;
        Pathfinder.Create(walkableMap, (Vector2)level.grid.cellSize);

        _playerUI.gameObject.SetActive(true);
        _startMenu.SetActive(false);
    }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // --- Input

            var path          = default(Path);
            var surface       = default(Surface);
            var startingPoint = default(Vector3d);
            var stepSize      = default(double);

            if (!DA.GetData(0, ref path))
            {
                return;
            }
            if (!DA.GetData(1, ref surface))
            {
                return;
            }
            if (!DA.GetData(2, ref startingPoint))
            {
                return;
            }
            if (!DA.GetData(3, ref stepSize))
            {
                return;
            }

            // --- Execute

            if (StartPointType == StartPointTypes.UV)
            {
                var u = surface.Domain(0).NormalizedParameterAt(startingPoint.X);
                var v = surface.Domain(1).NormalizedParameterAt(startingPoint.Y);
                startingPoint = new Vector3d(u, v, 0);
            }

            surface = (Surface)surface.Duplicate();
            surface.SetDomain(0, new Interval(0, 1));
            surface.SetDomain(1, new Interval(0, 1));

            if (StartPointType == StartPointTypes.XYZ)
            {
                surface.ClosestPoint((Point3d)startingPoint, out double u, out double v);
                startingPoint = new Vector3d(u, v, 0);
            }

            var paths = new List <Polyline>();

            var type = (path as NormalCurvaturePath)?.Type ?? (path as GeodesicTorsionPath)?.Type ?? (path as DGridPath)?.Type ?? (path as PSPath).Type;

            if (type.HasFlag(Path.Types.First))
            {
                var pathfinder = Pathfinder.Create(path, surface, startingPoint, false, stepSize);
                var polyline   = new Polyline(pathfinder.Points);
                paths.Add(polyline);
            }

            if (type.HasFlag(Path.Types.Second))
            {
                var pathfinder = Pathfinder.Create(path, surface, startingPoint, true, stepSize);
                var polyline   = new Polyline(pathfinder.Points);
                paths.Add(polyline);
            }

            // --- Output

            var curves = new List <CurveOnSurface>();

            foreach (var p in paths)
            {
                var curve = new PolylineCurve(p.Select(o => { surface.ClosestPoint(o, out var u, out var v); return(new Point3d(u, v, 0)); }));
                curves.Add(CurveOnSurface.Create(surface, curve));
            }

            DA.SetDataList(0, curves);
        }