Esempio n. 1
0
    private static bool CanScatterAt(IntVec3 pos, Map map)
    {
        var terrainDef = map.terrainGrid.TerrainAt(CellIndicesUtility.CellToIndex(pos, map.Size.x));

        return((terrainDef == null || !terrainDef.IsWater || terrainDef.passability != Traversability.Impassable) &&
               !map.deepResourceGrid.GetCellBool(CellIndicesUtility.CellToIndex(pos, map.Size.x)));
    }
Esempio n. 2
0
        //used as helper to verify, debugsettings => draw avoid grid is better once the grid sticks.
        private string GridToString(ByteGrid grid, Map map)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < map.Size.x; i++)
            {
                stringBuilder.AppendLine();
                for (int j = 0; j < map.Size.z; j++)
                {
                    stringBuilder.Append(grid[CellIndicesUtility.CellToIndex(i, j, map.Size.x)]);
                }
            }
            return(stringBuilder.ToString());
        }
Esempio n. 3
0
        static void Prefix(Projectile __instance, Thing hitThing, Vector3 ___origin)
        {
            Map map = __instance.Map;

            if (map == null)
            {
                return;
            }

            GunPropDef prop = GunplaySetup.GunProp(__instance.EquipmentDef);

            if (prop == null)
            {
                return;
            }

            MaterialKind kind = MaterialKind.None;

            if (hitThing != null)
            {
                kind = MaterialKindGetter.Get(hitThing);
            }

            if (kind == MaterialKind.None)
            {
                TerrainDef terrainDef = map.terrainGrid.TerrainAt(CellIndicesUtility.CellToIndex(__instance.Position, map.Size.x));
                kind = MaterialKindGetter.Get(terrainDef);
            }

            if (Gunplay.settings.enableSounds)
            {
                SoundDef sound = prop.projectileImpactSound == null ? null : prop.projectileImpactSound.Effect(kind);
                if (sound != null)
                {
                    sound.PlayOneShot(new TargetInfo(__instance.Position, map, false));
                }
            }

            if (Gunplay.settings.enableEffects)
            {
                EffecterDef effecterDef = prop.projectileImpactEffect == null ? null : prop.projectileImpactEffect.Effect(kind);
                if (effecterDef != null)
                {
                    Effecter effecter = new Effecter(effecterDef);
                    effecter.Trigger(__instance, new TargetInfo(___origin.ToIntVec3(), __instance.Map));
                    effecter.Cleanup();
                }
            }
        }
        public static void AddAvoidanceSource(Thing source, int pathCost)
        {
            AssertMap(source);
            pathCost = Mathf.Max(0, pathCost);
            if (!TryGetGridForMap(source.Map.uniqueID, out PlayerAvoidanceGrid grid))
            {
                grid = new PlayerAvoidanceGrid(source.Map);
                grids.Add(grid);
            }
            var cellIndex    = CellIndicesUtility.CellToIndex(source.Position, source.Map.Size.x);
            var previousCost = CalculatePathCostInCell(grid, cellIndex);
            var currentCost  = Mathf.Min(byte.MaxValue, previousCost + pathCost);

            grid.byteGrid[cellIndex] = (byte)currentCost;
            grid.sources.Add(new AvoidanceSource(source.thingIDNumber, cellIndex, currentCost - previousCost));
        }