コード例 #1
0
        private static IEnumerable <Blueprint_Build> PlaceArtilleryBlueprints(LordToilData_SiegeCustom data, Map map)
        {
            IEnumerable <ThingDef> artyDefs = customParams.artilleryDefs;

            // No tag matches
            if (!artyDefs.Any())
            {
                Log.Error($"Could not find any artillery ThingDefs matching the following tags: {customParams.artilleryBuildingTags.ToStringSafeEnumerable()}");
                yield break;
            }

            float points = data.blueprintPoints;

            // Generate blueprints
            int numArtillery = Mathf.RoundToInt(points / customParams.lowestArtilleryBlueprintPoints);

            numArtillery = Mathf.Clamp(numArtillery, customParams.artilleryCountRange.min, customParams.artilleryCountRange.max);
            int i = 0;

            while (points > 0 && i < numArtillery)
            {
                artyDefs = artyDefs.Where(t => ThingDefExtension.Get(t).siegeBlueprintPoints <= points);
                if (!artyDefs.Any())
                {
                    yield break;
                }
                var rot      = Rot4.Random;
                var artyDef  = artyDefs.RandomElementByWeight(t => ThingDefExtension.Get(t).siegeBlueprintPoints);
                var artySpot = NonPublicMethods.SiegeBlueprintPlacer_FindArtySpot(artyDef, rot, map);
                if (!artySpot.IsValid)
                {
                    yield break;
                }
                yield return(GenConstruct.PlaceBlueprintForBuild(artyDef, artySpot, map, rot, (Faction)NonPublicFields.SiegeBlueprintPlacer_faction.GetValue(null), GenStuff.DefaultStuffFor(artyDef)));

                if (data.artilleryCounts.ContainsKey(artyDef))
                {
                    data.artilleryCounts[artyDef]++;
                }
                else
                {
                    data.artilleryCounts.Add(artyDef, 1);
                }
                points -= ThingDefExtension.Get(artyDef).siegeBlueprintPoints;
                i++;
            }
            yield break;
        }
コード例 #2
0
        private static IntVec3 FindCoverRoot(Map map, ThingDef coverDef, ThingDef coverStuff)
        {
            var      centre          = (IntVec3)NonPublicFields.SiegeBlueprintPlacer_center.GetValue(null);
            var      placedCoverLocs = (List <IntVec3>)NonPublicFields.SiegeBlueprintPlacer_placedCoverLocs.GetValue(null);
            CellRect cellRect        = CellRect.CenteredOn(centre, 13);

            cellRect.ClipInsideMap(map);
            CellRect cellRect2 = CellRect.CenteredOn(centre, 8);

            cellRect2.ClipInsideMap(map);
            int num = 0;

            for (; ;)
            {
                num++;
                if (num > 200)
                {
                    break;
                }
                IntVec3 randomCell = cellRect.RandomCell;
                if (!cellRect2.Contains(randomCell))
                {
                    if (map.reachability.CanReach(randomCell, centre, PathEndMode.OnCell, TraverseMode.NoPassClosedDoors, Danger.Deadly))
                    {
                        if (NonPublicMethods.SiegeBlueprintPlacer_CanPlaceBlueprintAt(randomCell, Rot4.North, coverDef, map, coverStuff))
                        {
                            bool flag = false;
                            for (int i = 0; i < placedCoverLocs.Count; i++)
                            {
                                float num2 = (float)(placedCoverLocs[i] - randomCell).LengthHorizontalSquared;
                                if (num2 < 36f)
                                {
                                    flag = true;
                                }
                            }
                            if (!flag)
                            {
                                return(randomCell);
                            }
                        }
                    }
                }
            }
            return(IntVec3.Invalid);
        }
コード例 #3
0
        private static IEnumerable <Blueprint_Build> MakeCoverLine(IntVec3 root, Map map, Rot4 growDir, int maxLength, ThingDef coverThing, ThingDef coverStuff)
        {
            var     placedSandbagLocs = (List <IntVec3>)NonPublicFields.SiegeBlueprintPlacer_placedCoverLocs.GetValue(null);
            IntVec3 cur = root;

            for (int i = 0; i < maxLength; i++)
            {
                if (!NonPublicMethods.SiegeBlueprintPlacer_CanPlaceBlueprintAt(cur, Rot4.North, coverThing, map, coverStuff))
                {
                    break;
                }
                yield return(GenConstruct.PlaceBlueprintForBuild(coverThing, cur, map, Rot4.North, (Faction)NonPublicFields.SiegeBlueprintPlacer_faction.GetValue(null), coverStuff));

                placedSandbagLocs.Add(cur);
                cur += growDir.FacingCell;
            }
            yield break;
        }