Exemplo n.º 1
0
        protected override Element CreateChildForParameter(Parameter parameter)
        {
            switch (parameter.Id)
            {
            case 1:
                Steps = new StepsElement(parameter, this);
                return(Steps);

            case 2:
                StepsGoal = new StepsGoalElement(parameter, this);
                return(StepsGoal);

            case 3:
                Calories = new CaloriesElement(parameter, this);
                return(Calories);

            case 4:
                Pulse = new PulseElement(parameter, this);
                return(Pulse);

            case 5:
                Distance = new DistanceElement(parameter, this);
                return(Distance);

            default:
                return(base.CreateChildForParameter(parameter));
            }
        }
Exemplo n.º 2
0
 private void ApplyDistanceField(DistanceElement[,] distance, Map map, TerrainDef rockDef, RoadDef roadDef, RoadPathingDef pathingDef)
 {
     for (int i = 0; i < map.Size.x; i++)
     {
         for (int j = 0; j < map.Size.z; j++)
         {
             DistanceElement distanceElement = distance[i, j];
             if (!distanceElement.touched)
             {
                 continue;
             }
             float b = Mathf.Abs(distanceElement.fromRoad + Rand.Value - 0.5f);
             for (int k = 0; k < roadDef.roadGenSteps.Count; k++)
             {
                 RoadDefGenStep roadDefGenStep = roadDef.roadGenSteps[k];
                 float          x   = Mathf.LerpUnclamped(distanceElement.fromRoad, b, roadDefGenStep.antialiasingMultiplier);
                 float          num = roadDefGenStep.chancePerPositionCurve.Evaluate(x);
                 if (!(num <= 0f) && (roadDefGenStep.periodicSpacing == 0 || !(distanceElement.alongPath / (float)roadDefGenStep.periodicSpacing % 1f * (float)roadDefGenStep.periodicSpacing >= 1f)))
                 {
                     IntVec3 position = new IntVec3(i, 0, j);
                     if (Rand.Value < num)
                     {
                         roadDefGenStep.Place(map, position, rockDef, distanceElement.origin, distance);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        private Action PrepDrawRoad(Map map, TerrainDef rockDef, IntVec3 start, IntVec3 end, RoadDef roadDef, RoadPathingDef pathingDef, out IntVec3 centerpoint)
        {
            centerpoint = IntVec3.Invalid;
            PawnPath pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoorsOrWater));

            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoors));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThingsNotWater));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThings));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                return(null);
            }
            List <IntVec3> list = RefinePath(pawnPath.NodesReversed, map);

            pawnPath.ReleaseToPool();
            IntVec3 size  = map.Size;
            int     x     = size.x;
            IntVec3 size2 = map.Size;

            DistanceElement[,] distance = new DistanceElement[x, size2.z];
            for (int i = 0; i < distance.GetLength(0); i++)
            {
                for (int j = 0; j < distance.GetLength(1); j++)
                {
                    distance[i, j].origin = IntVec3.Invalid;
                }
            }
            int count            = list.Count;
            int centerpointIndex = Mathf.RoundToInt(Rand.Range(0.3f, 0.7f) * (float)count);
            int num = Mathf.Max(1, GenMath.RoundRandom((float)count / (float)roadDef.tilesPerSegment));

            for (int k = 0; k < num; k++)
            {
                int pathStartIndex = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)k);
                int pathEndIndex   = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)(k + 1));
                DrawCurveSegment(distance, list, pathStartIndex, pathEndIndex, pathingDef, map, centerpointIndex, ref centerpoint);
            }
            return(delegate
            {
                ApplyDistanceField(distance, map, rockDef, roadDef, pathingDef);
            });
        }
Exemplo n.º 4
0
        private void ApplyDistanceField(DistanceElement[,] distance, Map map, TerrainDef rockDef, RoadDef roadDef, RoadPathingDef pathingDef)
        {
            int num = 0;

            while (true)
            {
                int     num2 = num;
                IntVec3 size = map.Size;
                if (num2 < size.x)
                {
                    int num3 = 0;
                    while (true)
                    {
                        int     num4  = num3;
                        IntVec3 size2 = map.Size;
                        if (num4 < size2.z)
                        {
                            DistanceElement distanceElement = distance[num, num3];
                            if (distanceElement.touched)
                            {
                                float b = Mathf.Abs((float)(distanceElement.fromRoad + Rand.Value - 0.5));
                                for (int i = 0; i < roadDef.roadGenSteps.Count; i++)
                                {
                                    RoadDefGenStep roadDefGenStep = roadDef.roadGenSteps[i];
                                    float          x    = Mathf.LerpUnclamped(distanceElement.fromRoad, b, roadDefGenStep.antialiasingMultiplier);
                                    float          num5 = roadDefGenStep.chancePerPositionCurve.Evaluate(x);
                                    if (!(num5 <= 0.0) && (roadDefGenStep.periodicSpacing == 0 || !(distanceElement.alongPath / (float)roadDefGenStep.periodicSpacing % 1.0 * (float)roadDefGenStep.periodicSpacing >= 1.0)))
                                    {
                                        IntVec3 position = new IntVec3(num, 0, num3);
                                        if (Rand.Value < num5)
                                        {
                                            roadDefGenStep.Place(map, position, rockDef);
                                        }
                                    }
                                }
                            }
                            num3++;
                            continue;
                        }
                        break;
                    }
                    num++;
                    continue;
                }
                break;
            }
        }
Exemplo n.º 5
0
        protected override Element CreateChildForParameter(Parameter parameter)
        {
            if (Header.HeaderSize == 60)
            {
                switch (parameter.Id)
                {
                case 4:
                    Distance = new DistanceElement(parameter, this);
                    return(Distance);

                case 5:
                    Steps = new StepsElementP(parameter, this);
                    return(Steps);

                case 3:
                    Pulse = new PulseElement(parameter, this);
                    return(Pulse);

                case 7:
                    StarImage = new ImageElement(parameter, this);
                    return(StarImage);

                case 9:
                    CircleRange = new ImageElement(parameter, this);
                    return(CircleRange);
                }
            }
            else
            {
                switch (parameter.Id)
                {
                case 1:
                    if (StatusElement.IsBip)
                    {
                        StepsBip = new StepsElement(parameter, this, nameof(Steps));
                        return(StepsBip);
                    }

                    Steps = new StepsElementP(parameter, this);
                    return(Steps);

                case 2:
                    StepsGoal = new StepsGoalElement(parameter, this);
                    return(StepsGoal);

                case 3:
                    Calories = new CaloriesElement(parameter, this);
                    return(Calories);

                case 4:
                    Pulse = new PulseElement(parameter, this);
                    return(Pulse);

                case 5:
                    Distance = new DistanceElement(parameter, this);
                    return(Distance);
                }
            }

            return(base.CreateChildForParameter(parameter));
        }