Пример #1
0
        public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            if (map == null)
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " in a null map.", false);
                return(null);
            }
            if (!loc.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to spawn ",
                    newThing.ToStringSafe <Thing>(),
                    " out of bounds at ",
                    loc,
                    "."
                }), false);
                return(null);
            }
            if (newThing.def.randomizeRotationOnSpawn)
            {
                rot = Rot4.Random;
            }
            CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size);

            if (!occupiedRect.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to spawn ",
                    newThing.ToStringSafe <Thing>(),
                    " out of bounds at ",
                    loc,
                    " (out of bounds because size is ",
                    newThing.def.Size,
                    ")."
                }), false);
                return(null);
            }
            if (newThing.Spawned)
            {
                Log.Error("Tried to spawn " + newThing + " but it's already spawned.", false);
                return(newThing);
            }
            if (wipeMode == WipeMode.Vanish)
            {
                GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
            }
            else if (wipeMode == WipeMode.FullRefund)
            {
                GenSpawn.WipeAndRefundExistingThings(loc, rot, newThing.def, map);
            }
            if (newThing.def.category == ThingCategory.Item)
            {
                foreach (IntVec3 intVec in occupiedRect)
                {
                    foreach (Thing thing in intVec.GetThingList(map).ToList <Thing>())
                    {
                        if (thing != newThing)
                        {
                            if (thing.def.category == ThingCategory.Item)
                            {
                                thing.DeSpawn(DestroyMode.Vanish);
                                if (!GenPlace.TryPlaceThing(thing, intVec, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x)))
                                {
                                    thing.Destroy(DestroyMode.Vanish);
                                }
                            }
                        }
                    }
                }
            }
            newThing.Rotation = rot;
            newThing.Position = loc;
            if (newThing.holdingOwner != null)
            {
                newThing.holdingOwner.Remove(newThing);
            }
            newThing.SpawnSetup(map, respawningAfterLoad);
            if (newThing.Spawned && newThing.stackCount == 0)
            {
                Log.Error("Spawned thing with 0 stackCount: " + newThing, false);
                newThing.Destroy(DestroyMode.Vanish);
                return(null);
            }
            if (newThing.def.passability == Traversability.Impassable)
            {
                foreach (IntVec3 c in occupiedRect)
                {
                    foreach (Thing thing2 in c.GetThingList(map).ToList <Thing>())
                    {
                        if (thing2 != newThing)
                        {
                            Pawn pawn = thing2 as Pawn;
                            if (pawn != null)
                            {
                                pawn.pather.TryRecoverFromUnwalkablePosition(false);
                            }
                        }
                    }
                }
            }
            return(newThing);
        }
Пример #2
0
        public override void Regenerate()
        {
            if (!MatBases.SunShadow.shader.isSupported)
            {
                return;
            }
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.IndoorMask);

            subMesh.Clear(MeshParts.All);
            Building[] innerArray = base.Map.edificeGrid.InnerArray;
            CellRect   cellRect   = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(base.Map);
            subMesh.verts.Capacity = cellRect.Area * 2;
            subMesh.tris.Capacity  = cellRect.Area * 4;
            float       y           = AltitudeLayer.MetaOverlays.AltitudeFor();
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                int j = cellRect.minZ;
                while (j <= cellRect.maxZ)
                {
                    IntVec3 intVec = new IntVec3(i, 0, j);
                    if (this.HideRainPrimary(intVec))
                    {
                        goto IL_16E;
                    }
                    bool flag  = intVec.Roofed(base.Map);
                    bool flag2 = false;
                    if (flag)
                    {
                        for (int k = 0; k < 8; k++)
                        {
                            IntVec3 c = intVec + GenAdj.AdjacentCells[k];
                            if (c.InBounds(base.Map))
                            {
                                if (this.HideRainPrimary(c))
                                {
                                    flag2 = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (flag && flag2)
                    {
                        goto IL_16E;
                    }
IL_29D:
                    j++;
                    continue;
IL_16E:
                    Thing thing = innerArray[cellIndices.CellToIndex(i, j)];
                    float num;
                    if (thing != null && (thing.def.passability == Traversability.Impassable || thing.def.IsDoor))
                    {
                        num = 0f;
                    }
                    else
                    {
                        num = 0.16f;
                    }
                    subMesh.verts.Add(new Vector3((float)i - num, y, (float)j - num));
                    subMesh.verts.Add(new Vector3((float)i - num, y, (float)(j + 1) + num));
                    subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)(j + 1) + num));
                    subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)j - num));
                    int count = subMesh.verts.Count;
                    subMesh.tris.Add(count - 4);
                    subMesh.tris.Add(count - 3);
                    subMesh.tris.Add(count - 2);
                    subMesh.tris.Add(count - 4);
                    subMesh.tris.Add(count - 2);
                    subMesh.tris.Add(count - 1);
                    goto IL_29D;
                }
            }
            if (subMesh.verts.Count > 0)
            {
                subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris);
            }
        }
Пример #3
0
        public override void Regenerate()
        {
            if (!MatBases.SunShadow.shader.isSupported)
            {
                return;
            }
            Building[] innerArray = base.Map.edificeGrid.InnerArray;
            float      y          = AltitudeLayer.Shadows.AltitudeFor();
            CellRect   cellRect   = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(base.Map);
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.SunShadow);

            subMesh.Clear(MeshParts.All);
            subMesh.verts.Capacity  = cellRect.Area * 2;
            subMesh.tris.Capacity   = cellRect.Area * 4;
            subMesh.colors.Capacity = cellRect.Area * 2;
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    Thing thing = innerArray[cellIndices.CellToIndex(i, j)];
                    if (thing != null && thing.def.staticSunShadowHeight > 0f)
                    {
                        float   staticSunShadowHeight = thing.def.staticSunShadowHeight;
                        Color32 item  = new Color32(0, 0, 0, (byte)(255f * staticSunShadowHeight));
                        int     count = subMesh.verts.Count;
                        subMesh.verts.Add(new Vector3((float)i, y, (float)j));
                        subMesh.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                        subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                        subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        int count2 = subMesh.verts.Count;
                        subMesh.tris.Add(count2 - 4);
                        subMesh.tris.Add(count2 - 3);
                        subMesh.tris.Add(count2 - 2);
                        subMesh.tris.Add(count2 - 4);
                        subMesh.tris.Add(count2 - 2);
                        subMesh.tris.Add(count2 - 1);
                        if (i > 0)
                        {
                            thing = innerArray[cellIndices.CellToIndex(i - 1, j)];
                            if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight)
                            {
                                int count3 = subMesh.verts.Count;
                                subMesh.verts.Add(new Vector3((float)i, y, (float)j));
                                subMesh.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                                subMesh.colors.Add(item);
                                subMesh.colors.Add(item);
                                subMesh.tris.Add(count + 1);
                                subMesh.tris.Add(count);
                                subMesh.tris.Add(count3);
                                subMesh.tris.Add(count3);
                                subMesh.tris.Add(count3 + 1);
                                subMesh.tris.Add(count + 1);
                            }
                        }
                        if (i < base.Map.Size.x - 1)
                        {
                            thing = innerArray[cellIndices.CellToIndex(i + 1, j)];
                            if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight)
                            {
                                int count4 = subMesh.verts.Count;
                                subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                                subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                subMesh.colors.Add(item);
                                subMesh.colors.Add(item);
                                subMesh.tris.Add(count + 2);
                                subMesh.tris.Add(count4);
                                subMesh.tris.Add(count4 + 1);
                                subMesh.tris.Add(count4 + 1);
                                subMesh.tris.Add(count + 3);
                                subMesh.tris.Add(count + 2);
                            }
                        }
                        if (j > 0)
                        {
                            thing = innerArray[cellIndices.CellToIndex(i, j - 1)];
                            if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight)
                            {
                                int count5 = subMesh.verts.Count;
                                subMesh.verts.Add(new Vector3((float)i, y, (float)j));
                                subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                subMesh.colors.Add(item);
                                subMesh.colors.Add(item);
                                subMesh.tris.Add(count);
                                subMesh.tris.Add(count + 3);
                                subMesh.tris.Add(count5);
                                subMesh.tris.Add(count + 3);
                                subMesh.tris.Add(count5 + 1);
                                subMesh.tris.Add(count5);
                            }
                        }
                    }
                }
            }
            if (subMesh.verts.Count > 0)
            {
                subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors);
                float   num  = Mathf.Max(15f, 15f);
                Vector3 size = subMesh.mesh.bounds.size;
                size.x += 2f * num + 2f;
                size.z += 2f * num + 2f;
                subMesh.mesh.bounds = new Bounds(subMesh.mesh.bounds.center, size);
            }
        }
Пример #4
0
        public override void Regenerate()
        {
            ClearSubMeshes(MeshParts.All);
            TerrainGrid terrainGrid = base.Map.terrainGrid;
            CellRect    cellRect    = section.CellRect;

            TerrainDef[]         array   = new TerrainDef[8];
            HashSet <TerrainDef> hashSet = new HashSet <TerrainDef>();

            bool[] array2 = new bool[8];
            foreach (IntVec3 item in cellRect)
            {
                IntVec3 current = item;
                hashSet.Clear();
                TerrainDef   terrainDef = terrainGrid.TerrainAt(current);
                LayerSubMesh subMesh    = GetSubMesh(GetMaterialFor(terrainDef));
                if (subMesh != null && AllowRenderingFor(terrainDef))
                {
                    int count = subMesh.verts.Count;
                    subMesh.verts.Add(new Vector3((float)current.x, 0f, (float)current.z));
                    subMesh.verts.Add(new Vector3((float)current.x, 0f, (float)(current.z + 1)));
                    subMesh.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)(current.z + 1)));
                    subMesh.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)current.z));
                    subMesh.colors.Add(ColorWhite);
                    subMesh.colors.Add(ColorWhite);
                    subMesh.colors.Add(ColorWhite);
                    subMesh.colors.Add(ColorWhite);
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 1);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count + 3);
                }
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c = current + GenAdj.AdjacentCellsAroundBottom[i];
                    if (!c.InBounds(base.Map))
                    {
                        array[i] = terrainDef;
                    }
                    else
                    {
                        TerrainDef terrainDef2 = terrainGrid.TerrainAt(c);
                        Thing      edifice     = c.GetEdifice(base.Map);
                        if (edifice != null && edifice.def.coversFloor)
                        {
                            terrainDef2 = TerrainDefOf.Underwall;
                        }
                        array[i] = terrainDef2;
                        if (terrainDef2 != terrainDef && terrainDef2.edgeType != 0 && terrainDef2.renderPrecedence >= terrainDef.renderPrecedence && !hashSet.Contains(terrainDef2))
                        {
                            hashSet.Add(terrainDef2);
                        }
                    }
                }
                foreach (TerrainDef item2 in hashSet)
                {
                    LayerSubMesh subMesh2 = GetSubMesh(GetMaterialFor(item2));
                    if (subMesh2 != null && AllowRenderingFor(item2))
                    {
                        int count = subMesh2.verts.Count;
                        subMesh2.verts.Add(new Vector3((float)current.x + 0.5f, 0f, (float)current.z));
                        subMesh2.verts.Add(new Vector3((float)current.x, 0f, (float)current.z));
                        subMesh2.verts.Add(new Vector3((float)current.x, 0f, (float)current.z + 0.5f));
                        subMesh2.verts.Add(new Vector3((float)current.x, 0f, (float)(current.z + 1)));
                        subMesh2.verts.Add(new Vector3((float)current.x + 0.5f, 0f, (float)(current.z + 1)));
                        subMesh2.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)(current.z + 1)));
                        subMesh2.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)current.z + 0.5f));
                        subMesh2.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)current.z));
                        subMesh2.verts.Add(new Vector3((float)current.x + 0.5f, 0f, (float)current.z + 0.5f));
                        for (int j = 0; j < 8; j++)
                        {
                            array2[j] = false;
                        }
                        for (int k = 0; k < 8; k++)
                        {
                            if (k % 2 == 0)
                            {
                                if (array[k] == item2)
                                {
                                    array2[(k - 1 + 8) % 8] = true;
                                    array2[k]           = true;
                                    array2[(k + 1) % 8] = true;
                                }
                            }
                            else if (array[k] == item2)
                            {
                                array2[k] = true;
                            }
                        }
                        for (int l = 0; l < 8; l++)
                        {
                            if (array2[l])
                            {
                                subMesh2.colors.Add(ColorWhite);
                            }
                            else
                            {
                                subMesh2.colors.Add(ColorClear);
                            }
                        }
                        subMesh2.colors.Add(ColorClear);
                        for (int m = 0; m < 8; m++)
                        {
                            subMesh2.tris.Add(count + m);
                            subMesh2.tris.Add(count + (m + 1) % 8);
                            subMesh2.tris.Add(count + 8);
                        }
                    }
                }
            }
            FinalizeMesh(MeshParts.All);
        }
Пример #5
0
        public static bool CanReachImmediate(IntVec3 start, CellRect rect, Map map, PathEndMode peMode, Pawn pawn)
        {
            IntVec3 c = rect.ClosestCellTo(start);

            return(ReachabilityImmediate.CanReachImmediate(start, c, map, peMode, pawn));
        }
Пример #6
0
        public static bool LineOfSight(IntVec3 start, IntVec3 end, Map map, CellRect startRect, CellRect endRect, Func <IntVec3, bool> validator = null)
        {
            bool result;

            if (!start.InBounds(map) || !end.InBounds(map))
            {
                result = false;
            }
            else
            {
                bool flag;
                if (start.x == end.x)
                {
                    flag = (start.z < end.z);
                }
                else
                {
                    flag = (start.x < end.x);
                }
                int num  = Mathf.Abs(end.x - start.x);
                int num2 = Mathf.Abs(end.z - start.z);
                int num3 = start.x;
                int num4 = start.z;
                int i    = 1 + num + num2;
                int num5 = (end.x <= start.x) ? -1 : 1;
                int num6 = (end.z <= start.z) ? -1 : 1;
                int num7 = num - num2;
                num  *= 2;
                num2 *= 2;
                IntVec3 intVec = default(IntVec3);
                while (i > 1)
                {
                    intVec.x = num3;
                    intVec.z = num4;
                    if (endRect.Contains(intVec))
                    {
                        return(true);
                    }
                    if (!startRect.Contains(intVec))
                    {
                        if (!intVec.CanBeSeenOverFast(map))
                        {
                            return(false);
                        }
                        if (validator != null && !validator(intVec))
                        {
                            return(false);
                        }
                    }
                    if (num7 > 0 || (num7 == 0 && flag))
                    {
                        num3 += num5;
                        num7 -= num2;
                    }
                    else
                    {
                        num4 += num6;
                        num7 += num;
                    }
                    i--;
                }
                result = true;
            }
            return(result);
        }
Пример #7
0
        protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (this.def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.Cell.ToVector3Shifted();
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = (!A.HasThing) ? A.Cell.ToVector3Shifted() : A.Thing.DrawPos;
                Vector3 vector3 = (!B.HasThing) ? B.Cell.ToVector3Shifted() : B.Thing.DrawPos;
                if (A.HasThing && !A.Thing.Spawned)
                {
                    vector = vector3;
                }
                else if (B.HasThing && !B.Thing.Spawned)
                {
                    vector = vector2;
                }
                else
                {
                    vector = vector2 * this.def.positionLerpFactor + vector3 * (1f - this.def.positionLerpFactor);
                }
                break;
            }

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;

            case MoteSpawnLocType.RandomCellOnTarget:
            {
                CellRect cellRect;
                if (B.HasThing)
                {
                    cellRect = B.Thing.OccupiedRect();
                }
                else
                {
                    cellRect = CellRect.CenteredOn(B.Cell, 0);
                }
                vector = cellRect.RandomCell.ToVector3Shifted();
                break;
            }
            }
            Map map = A.Map ?? B.Map;

            if (map != null && vector.ShouldSpawnMotesAt(map))
            {
                int randomInRange = this.def.burstCount.RandomInRange;
                for (int i = 0; i < randomInRange; i++)
                {
                    Mote mote = (Mote)ThingMaker.MakeThing(this.def.moteDef, null);
                    GenSpawn.Spawn(mote, vector.ToIntVec3(), map);
                    mote.Scale         = this.def.scale.RandomInRange;
                    mote.exactPosition = vector + Gen.RandomHorizontalVector(this.def.positionRadius);
                    mote.rotationRate  = this.def.rotationRate.RandomInRange;
                    float num = (!this.def.absoluteAngle) ? (B.Cell - A.Cell).AngleFlat : 0f;
                    mote.exactRotation = this.def.rotation.RandomInRange + num;
                    MoteThrown moteThrown = mote as MoteThrown;
                    if (moteThrown != null)
                    {
                        moteThrown.airTimeLeft = this.def.airTime.RandomInRange;
                        moteThrown.SetVelocity(this.def.angle.RandomInRange + num, this.def.speed.RandomInRange);
                    }
                }
            }
        }
Пример #8
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            Map map = base.Map;

            base.DeSpawn(mode);
            if (def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
                if (def.Fillage == FillCategory.Full)
                {
                    map.terrainGrid.Drawer.SetDirty();
                }
                if (def.AffectsFertility)
                {
                    map.fertilityGrid.Drawer.SetDirty();
                }
            }
            if (mode != DestroyMode.WillReplace)
            {
                if (def.MakeFog)
                {
                    foreach (IntVec3 item in this.OccupiedRect())
                    {
                        map.fogGrid.Notify_FogBlockerRemoved(item);
                    }
                }
                if (def.holdsRoof)
                {
                    RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
                }
                if (def.IsSmoothable)
                {
                    SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map);
                }
            }
            if (sustainerAmbient != null)
            {
                sustainerAmbient.End();
            }
            CellRect cellRect = this.OccupiedRect();

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3     loc         = new IntVec3(j, 0, i);
                    MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings;
                    if (def.coversFloor)
                    {
                        mapMeshFlag |= MapMeshFlag.Terrain;
                    }
                    if (def.Fillage == FillCategory.Full)
                    {
                        mapMeshFlag |= MapMeshFlag.Roofs;
                        mapMeshFlag |= MapMeshFlag.Snow;
                    }
                    map.mapDrawer.MapMeshDirty(loc, mapMeshFlag);
                    map.glowGrid.MarkGlowGridDirty(loc);
                }
            }
            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);
            map.listerArtificialBuildingsForMeditation.Notify_BuildingDeSpawned(this);
            map.listerBuldingOfDefInProximity.Notify_BuildingDeSpawned(this);
            if (def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && canChangeTerrainOnDestroyed)
            {
                foreach (IntVec3 item2 in this.OccupiedRect())
                {
                    map.terrainGrid.SetTerrain(item2, def.building.leaveTerrain);
                }
            }
            map.designationManager.Notify_BuildingDespawned(this);
            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }
            if (def.building.hasFuelingPort)
            {
                FuelingPortUtility.LaunchableAt(FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation), map)?.Notify_FuelingPortSourceDeSpawned();
            }
            map.avoidGrid.Notify_BuildingDespawned(this);
        }
Пример #9
0
        public static bool TryFindRandomEdgeCellWith(Predicate <IntVec3> validator, Map map, Rot4 dir, float roadChance, out IntVec3 result)
        {
            if (Rand.Value < roadChance)
            {
                bool flag = (from c in map.roadInfo.roadEdgeTiles
                             where validator(c) && c.OnEdge(map, dir)
                             select c).TryRandomElement(out result);
                if (flag)
                {
                    return(flag);
                }
            }
            for (int i = 0; i < 100; i++)
            {
                result = CellFinder.RandomEdgeCell(dir, map);
                if (validator(result))
                {
                    return(true);
                }
            }
            int asInt = dir.AsInt;

            if (CellFinder.mapSingleEdgeCells[asInt] == null || map.Size != CellFinder.mapSingleEdgeCellsSize)
            {
                CellFinder.mapSingleEdgeCellsSize    = map.Size;
                CellFinder.mapSingleEdgeCells[asInt] = new List <IntVec3>();
                foreach (IntVec3 current in CellRect.WholeMap(map).GetEdgeCells(dir))
                {
                    CellFinder.mapSingleEdgeCells[asInt].Add(current);
                }
            }
            List <IntVec3> list = CellFinder.mapSingleEdgeCells[asInt];

            list.Shuffle <IntVec3>();
            int j     = 0;
            int count = list.Count;

            while (j < count)
            {
                try
                {
                    if (validator(list[j]))
                    {
                        result = list[j];
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "TryFindRandomEdgeCellWith exception validating ",
                        list[j],
                        ": ",
                        ex.ToString()
                    }));
                }
                j++;
            }
            result = IntVec3.Invalid;
            return(false);
        }
        private void TryGenerateAreaNow(Room room)
        {
            if (room.Dereferenced || room.TouchesMapEdge || room.RegionCount > 26 || room.CellCount > 320 || room.RegionType == RegionType.Portal)
            {
                return;
            }
            bool flag = false;

            foreach (IntVec3 borderCell in room.BorderCells)
            {
                Thing roofHolderOrImpassable = borderCell.GetRoofHolderOrImpassable(map);
                if (roofHolderOrImpassable != null)
                {
                    if ((roofHolderOrImpassable.Faction != null && roofHolderOrImpassable.Faction != Faction.OfPlayer) || (roofHolderOrImpassable.def.building != null && !roofHolderOrImpassable.def.building.allowAutoroof))
                    {
                        return;
                    }
                    if (roofHolderOrImpassable.Faction == Faction.OfPlayer)
                    {
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                return;
            }
            innerCells.Clear();
            foreach (IntVec3 cell in room.Cells)
            {
                if (!innerCells.Contains(cell))
                {
                    innerCells.Add(cell);
                }
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c = cell + GenAdj.AdjacentCells[i];
                    if (!c.InBounds(map))
                    {
                        continue;
                    }
                    Thing roofHolderOrImpassable2 = c.GetRoofHolderOrImpassable(map);
                    if (roofHolderOrImpassable2 == null || (roofHolderOrImpassable2.def.size.x <= 1 && roofHolderOrImpassable2.def.size.z <= 1))
                    {
                        continue;
                    }
                    CellRect cellRect = roofHolderOrImpassable2.OccupiedRect();
                    cellRect.ClipInsideMap(map);
                    for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                    {
                        for (int k = cellRect.minX; k <= cellRect.maxX; k++)
                        {
                            IntVec3 item = new IntVec3(k, 0, j);
                            if (!innerCells.Contains(item))
                            {
                                innerCells.Add(item);
                            }
                        }
                    }
                }
            }
            cellsToRoof.Clear();
            foreach (IntVec3 innerCell in innerCells)
            {
                for (int l = 0; l < 9; l++)
                {
                    IntVec3 intVec = innerCell + GenAdj.AdjacentCellsAndInside[l];
                    if (intVec.InBounds(map) && (l == 8 || intVec.GetRoofHolderOrImpassable(map) != null) && !cellsToRoof.Contains(intVec))
                    {
                        cellsToRoof.Add(intVec);
                    }
                }
            }
            justRoofedCells.Clear();
            foreach (IntVec3 item2 in cellsToRoof)
            {
                if (map.roofGrid.RoofAt(item2) == null && !justRoofedCells.Contains(item2) && !map.areaManager.NoRoof[item2] && RoofCollapseUtility.WithinRangeOfRoofHolder(item2, map, assumeNonNoRoofCellsAreRoofed: true))
                {
                    map.areaManager.BuildRoof[item2] = true;
                    justRoofedCells.Add(item2);
                }
            }
        }
Пример #11
0
 public static bool LineOfSight(IntVec3 start, IntVec3 end, Map map, CellRect startRect, CellRect endRect, Func <IntVec3, bool> validator = null)
 {
     if (start.InBounds(map) && end.InBounds(map))
     {
         bool flag = (start.x != end.x) ? (start.x < end.x) : (start.z < end.z);
         int  num  = Mathf.Abs(end.x - start.x);
         int  num2 = Mathf.Abs(end.z - start.z);
         int  num3 = start.x;
         int  num4 = start.z;
         int  num5 = 1 + num + num2;
         int  num6 = (end.x > start.x) ? 1 : (-1);
         int  num7 = (end.z > start.z) ? 1 : (-1);
         int  num8 = num - num2;
         num  *= 2;
         num2 *= 2;
         IntVec3 intVec = default(IntVec3);
         while (num5 > 1)
         {
             intVec.x = num3;
             intVec.z = num4;
             if (endRect.Contains(intVec))
             {
                 return(true);
             }
             if (!startRect.Contains(intVec))
             {
                 if (!intVec.CanBeSeenOverFast(map))
                 {
                     return(false);
                 }
                 if (validator != null && !validator(intVec))
                 {
                     return(false);
                 }
             }
             if (num8 > 0 || (num8 == 0 && flag))
             {
                 num3 += num6;
                 num8 -= num2;
             }
             else
             {
                 num4 += num7;
                 num8 += num;
             }
             num5--;
         }
         return(true);
     }
     return(false);
 }
Пример #12
0
        public void RegenerateMesh()
        {
            for (int i = 0; i < meshes.Count; i++)
            {
                meshes[i].Clear();
            }
            int num  = 0;
            int num2 = 0;

            if (meshes.Count < num + 1)
            {
                Mesh mesh = new Mesh();
                mesh.name = "CellBoolDrawer";
                meshes.Add(mesh);
            }
            Mesh     mesh2    = meshes[num];
            CellRect cellRect = new CellRect(0, 0, mapSizeX, mapSizeZ);
            float    y        = AltitudeLayer.MapDataOverlay.AltitudeFor();
            bool     careAboutVertexColors = false;

            for (int j = cellRect.minX; j <= cellRect.maxX; j++)
            {
                for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                {
                    int arg = CellIndicesUtility.CellToIndex(j, k, mapSizeX);
                    if (!cellBoolGetter(arg))
                    {
                        continue;
                    }
                    verts.Add(new Vector3(j, y, k));
                    verts.Add(new Vector3(j, y, k + 1));
                    verts.Add(new Vector3(j + 1, y, k + 1));
                    verts.Add(new Vector3(j + 1, y, k));
                    Color color = extraColorGetter(arg);
                    colors.Add(color);
                    colors.Add(color);
                    colors.Add(color);
                    colors.Add(color);
                    if (color != Color.white)
                    {
                        careAboutVertexColors = true;
                    }

                    int count = verts.Count;
                    tris.Add(count - 4);
                    tris.Add(count - 3);
                    tris.Add(count - 2);
                    tris.Add(count - 4);
                    tris.Add(count - 2);
                    tris.Add(count - 1);

                    num2++;
                    if (num2 >= 16383)
                    {
                        FinalizeWorkingDataIntoMesh(mesh2);
                        num++;
                        if (meshes.Count < num + 1)
                        {
                            Mesh mesh3 = new Mesh();
                            mesh3.name = "CellBoolDrawer";
                            meshes.Add(mesh3);
                        }
                        mesh2 = meshes[num];
                        num2  = 0;
                    }
                }
            }
            FinalizeWorkingDataIntoMesh(mesh2);
            CreateMaterialIfNeeded(careAboutVertexColors);
            dirty = false;
        }
Пример #13
0
        public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            if (map == null)
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe() + " in a null map.");
                return(null);
            }
            if (!loc.InBounds(map))
            {
                Log.Error(string.Concat("Tried to spawn ", newThing.ToStringSafe(), " out of bounds at ", loc, "."));
                return(null);
            }
            if (newThing.def.randomizeRotationOnSpawn)
            {
                rot = Rot4.Random;
            }
            CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size);

            if (!occupiedRect.InBounds(map))
            {
                Log.Error(string.Concat("Tried to spawn ", newThing.ToStringSafe(), " out of bounds at ", loc, " (out of bounds because size is ", newThing.def.Size, ")."));
                return(null);
            }
            if (newThing.Spawned)
            {
                Log.Error(string.Concat("Tried to spawn ", newThing, " but it's already spawned."));
                return(newThing);
            }
            switch (wipeMode)
            {
            case WipeMode.Vanish:
                WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
                break;

            case WipeMode.FullRefund:
                WipeAndRefundExistingThings(loc, rot, newThing.def, map);
                break;

            case WipeMode.VanishOrMoveAside:
                CheckMoveItemsAside(loc, rot, newThing.def, map);
                WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
                break;
            }
            if (newThing.def.category == ThingCategory.Item)
            {
                foreach (IntVec3 item in occupiedRect)
                {
                    foreach (Thing item2 in item.GetThingList(map).ToList())
                    {
                        if (item2 != newThing && item2.def.category == ThingCategory.Item)
                        {
                            item2.DeSpawn();
                            if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x)))
                            {
                                item2.Destroy();
                            }
                        }
                    }
                }
            }
            newThing.Rotation = rot;
            newThing.Position = loc;
            if (newThing.holdingOwner != null)
            {
                newThing.holdingOwner.Remove(newThing);
            }
            newThing.SpawnSetup(map, respawningAfterLoad);
            if (newThing.Spawned && newThing.stackCount == 0)
            {
                Log.Error("Spawned thing with 0 stackCount: " + newThing);
                newThing.Destroy();
                return(null);
            }
            if (newThing.def.passability == Traversability.Impassable)
            {
                foreach (IntVec3 item3 in occupiedRect)
                {
                    foreach (Thing item4 in item3.GetThingList(map).ToList())
                    {
                        if (item4 != newThing)
                        {
                            (item4 as Pawn)?.pather.TryRecoverFromUnwalkablePosition(error: false);
                        }
                    }
                }
                return(newThing);
            }
            return(newThing);
        }
Пример #14
0
        public static IntVec3 FindNoWipeSpawnLocNear(IntVec3 near, Map map, ThingDef thingToSpawn, Rot4 rot, int maxDist = 2, Predicate <IntVec3> extraValidator = null)
        {
            int     num    = GenRadial.NumCellsInRadius((float)maxDist);
            IntVec3 intVec = IntVec3.Invalid;
            float   num2   = 0f;

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec2 = near + GenRadial.RadialPattern[i];
                if (intVec2.InBounds(map))
                {
                    CellRect cellRect = GenAdj.OccupiedRect(intVec2, rot, thingToSpawn.size);
                    if (cellRect.InBounds(map))
                    {
                        if (GenSight.LineOfSight(near, intVec2, map, true, null, 0, 0))
                        {
                            if (extraValidator == null || extraValidator(intVec2))
                            {
                                if (thingToSpawn.category != ThingCategory.Building || GenConstruct.CanBuildOnTerrain(thingToSpawn, intVec2, map, rot, null))
                                {
                                    bool flag  = false;
                                    bool flag2 = false;
                                    CellFinder.tmpUniqueWipedThings.Clear();
                                    CellRect.CellRectIterator iterator = cellRect.GetIterator();
                                    while (!iterator.Done())
                                    {
                                        if (iterator.Current.Impassable(map))
                                        {
                                            flag2 = true;
                                        }
                                        List <Thing> thingList = iterator.Current.GetThingList(map);
                                        for (int j = 0; j < thingList.Count; j++)
                                        {
                                            if (thingList[j] is Pawn)
                                            {
                                                flag = true;
                                            }
                                            else if (GenSpawn.SpawningWipes(thingToSpawn, thingList[j].def) && !CellFinder.tmpUniqueWipedThings.Contains(thingList[j]))
                                            {
                                                CellFinder.tmpUniqueWipedThings.Add(thingList[j]);
                                            }
                                        }
                                        iterator.MoveNext();
                                    }
                                    if (flag && thingToSpawn.passability == Traversability.Impassable)
                                    {
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                    }
                                    else if (flag2 && thingToSpawn.category == ThingCategory.Item)
                                    {
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                    }
                                    else
                                    {
                                        float num3 = 0f;
                                        for (int k = 0; k < CellFinder.tmpUniqueWipedThings.Count; k++)
                                        {
                                            if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building && !CellFinder.tmpUniqueWipedThings[k].def.costList.NullOrEmpty <ThingDefCountClass>() && CellFinder.tmpUniqueWipedThings[k].def.costStuffCount == 0)
                                            {
                                                List <ThingDefCountClass> list = CellFinder.tmpUniqueWipedThings[k].CostListAdjusted();
                                                for (int l = 0; l < list.Count; l++)
                                                {
                                                    num3 += list[l].thingDef.GetStatValueAbstract(StatDefOf.MarketValue, null) * (float)list[l].count * (float)CellFinder.tmpUniqueWipedThings[k].stackCount;
                                                }
                                            }
                                            else
                                            {
                                                num3 += CellFinder.tmpUniqueWipedThings[k].MarketValue * (float)CellFinder.tmpUniqueWipedThings[k].stackCount;
                                            }
                                            if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building || CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Item)
                                            {
                                                num3 = Mathf.Max(num3, 0.001f);
                                            }
                                        }
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                        if (!intVec.IsValid || num3 < num2)
                                        {
                                            if (num3 == 0f)
                                            {
                                                return(intVec2);
                                            }
                                            intVec = intVec2;
                                            num2   = num3;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return((!intVec.IsValid) ? near : intVec);
        }
Пример #15
0
        public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine)
        {
            if (targ.HasThing && targ.Thing.Map != this.caster.Map)
            {
                resultingLine = default(ShootLine);
                return(false);
            }
            if (this.verbProps.MeleeRange)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(ReachabilityImmediate.CanReachImmediate(root, targ, this.caster.Map, PathEndMode.Touch, null));
            }
            CellRect cellRect = (!targ.HasThing) ? CellRect.SingleCell(targ.Cell) : targ.Thing.OccupiedRect();
            float    num      = cellRect.ClosestDistSquaredTo(root);

            if (!(num > this.verbProps.range * this.verbProps.range) && !(num < this.verbProps.minRange * this.verbProps.minRange))
            {
                if (!this.verbProps.requireLineOfSight)
                {
                    resultingLine = new ShootLine(root, targ.Cell);
                    return(true);
                }
                IntVec3 dest = default(IntVec3);
                if (this.CasterIsPawn)
                {
                    if (this.CanHitFromCellIgnoringRange(root, targ, out dest))
                    {
                        resultingLine = new ShootLine(root, dest);
                        return(true);
                    }
                    ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), this.caster.Map, Verb.tempLeanShootSources);
                    for (int i = 0; i < Verb.tempLeanShootSources.Count; i++)
                    {
                        IntVec3 intVec = Verb.tempLeanShootSources[i];
                        if (this.CanHitFromCellIgnoringRange(intVec, targ, out dest))
                        {
                            resultingLine = new ShootLine(intVec, dest);
                            return(true);
                        }
                    }
                }
                else
                {
                    CellRect.CellRectIterator iterator = this.caster.OccupiedRect().GetIterator();
                    while (!iterator.Done())
                    {
                        IntVec3 current = iterator.Current;
                        if (this.CanHitFromCellIgnoringRange(current, targ, out dest))
                        {
                            resultingLine = new ShootLine(current, dest);
                            return(true);
                        }
                        iterator.MoveNext();
                    }
                }
                resultingLine = new ShootLine(root, targ.Cell);
                return(false);
            }
            resultingLine = new ShootLine(root, targ.Cell);
            return(false);
        }
Пример #16
0
        public static FloodUnfogResult FloodUnfog(IntVec3 root, Map map)
        {
            FloodFillerFog.cellsToUnfog.Clear();
            FloodUnfogResult result = default(FloodUnfogResult);

            bool[]         fogGridDirect      = map.fogGrid.fogGrid;
            FogGrid        fogGrid            = map.fogGrid;
            List <IntVec3> newlyUnfoggedCells = new List <IntVec3>();
            int            numUnfogged        = 0;
            bool           expanding          = false;
            CellRect       viewRect           = CellRect.ViewRect(map);

            result.allOnScreen = true;
            Predicate <IntVec3> predicate = delegate(IntVec3 c)
            {
                if (!fogGridDirect[map.cellIndices.CellToIndex(c)])
                {
                    return(false);
                }
                Thing edifice = c.GetEdifice(map);
                return((edifice == null || !edifice.def.MakeFog) && (!FloodFillerFog.testMode || expanding || numUnfogged <= 500));
            };
            Action <IntVec3> processor = delegate(IntVec3 c)
            {
                fogGrid.Unfog(c);
                newlyUnfoggedCells.Add(c);
                List <Thing> thingList = c.GetThingList(map);
                for (int l = 0; l < thingList.Count; l++)
                {
                    Pawn pawn = thingList[l] as Pawn;
                    if (pawn != null)
                    {
                        pawn.mindState.Active = true;
                        if (pawn.def.race.IsMechanoid)
                        {
                            result.mechanoidFound = true;
                        }
                    }
                }
                if (!viewRect.Contains(c))
                {
                    result.allOnScreen = false;
                }
                result.cellsUnfogged++;
                if (FloodFillerFog.testMode)
                {
                    numUnfogged++;
                    map.debugDrawer.FlashCell(c, (float)numUnfogged / 200f, numUnfogged.ToStringCached(), 50);
                }
            };

            map.floodFiller.FloodFill(root, predicate, processor, int.MaxValue, false, null);
            expanding = true;
            for (int i = 0; i < newlyUnfoggedCells.Count; i++)
            {
                IntVec3 a = newlyUnfoggedCells[i];
                for (int j = 0; j < 8; j++)
                {
                    IntVec3 intVec = a + GenAdj.AdjacentCells[j];
                    if (intVec.InBounds(map) && fogGrid.IsFogged(intVec))
                    {
                        if (!predicate(intVec))
                        {
                            FloodFillerFog.cellsToUnfog.Add(intVec);
                        }
                    }
                }
            }
            for (int k = 0; k < FloodFillerFog.cellsToUnfog.Count; k++)
            {
                fogGrid.Unfog(FloodFillerFog.cellsToUnfog[k]);
                if (FloodFillerFog.testMode)
                {
                    map.debugDrawer.FlashCell(FloodFillerFog.cellsToUnfog[k], 0.3f, "x", 50);
                }
            }
            FloodFillerFog.cellsToUnfog.Clear();
            return(result);
        }
Пример #17
0
 public static object FromString(string str, Type itemType)
 {
     try
     {
         itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
         if (itemType == typeof(string))
         {
             str = str.Replace("\\n", "\n");
             return(str);
         }
         if (itemType == typeof(int))
         {
             return(int.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(float))
         {
             return(float.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(bool))
         {
             return(bool.Parse(str));
         }
         if (itemType == typeof(long))
         {
             return(long.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(double))
         {
             return(double.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(sbyte))
         {
             return(sbyte.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType.IsEnum)
         {
             try
             {
                 return(Enum.Parse(itemType, str));
             }
             catch (ArgumentException innerException)
             {
                 string str2 = "'" + str + "' is not a valid value for " + itemType + ". Valid values are: \n";
                 str2 += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                 ArgumentException ex = new ArgumentException(str2, innerException);
                 throw ex;
             }
         }
         if (itemType == typeof(Type))
         {
             if (!(str == "null") && !(str == "Null"))
             {
                 Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
                 if (typeInAnyAssembly == null)
                 {
                     Log.Error("Could not find a type named " + str);
                 }
                 return(typeInAnyAssembly);
             }
             return(null);
         }
         if (itemType == typeof(Action))
         {
             string[] array      = str.Split('.');
             string   methodName = array[array.Length - 1];
             string   empty      = string.Empty;
             empty = ((array.Length != 3) ? array[0] : (array[0] + "." + array[1]));
             Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(empty);
             MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
             return((Action)Delegate.CreateDelegate(typeof(Action), method));
         }
         if (itemType == typeof(Vector3))
         {
             return(ParseHelper.FromStringVector3(str));
         }
         if (itemType == typeof(Vector2))
         {
             return(ParseHelper.FromStringVector2(str));
         }
         if (itemType == typeof(Rect))
         {
             return(ParseHelper.FromStringRect(str));
         }
         if (itemType == typeof(Color))
         {
             str = str.TrimStart('(', 'R', 'G', 'B', 'A');
             str = str.TrimEnd(')');
             string[] array2 = str.Split(',');
             float    num    = (float)ParseHelper.FromString(array2[0], typeof(float));
             float    num2   = (float)ParseHelper.FromString(array2[1], typeof(float));
             float    num3   = (float)ParseHelper.FromString(array2[2], typeof(float));
             bool     flag   = num > 1.0 || num3 > 1.0 || num2 > 1.0;
             float    num4   = (float)((!flag) ? 1 : 255);
             if (array2.Length == 4)
             {
                 num4 = (float)ParseHelper.FromString(array2[3], typeof(float));
             }
             Color color = default(Color);
             if (!flag)
             {
                 color.r = num;
                 color.g = num2;
                 color.b = num3;
                 color.a = num4;
             }
             else
             {
                 color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
             }
             return(color);
         }
         if (itemType == typeof(PublishedFileId_t))
         {
             return(new PublishedFileId_t(ulong.Parse(str)));
         }
         if (itemType == typeof(IntVec2))
         {
             return(IntVec2.FromString(str));
         }
         if (itemType == typeof(IntVec3))
         {
             return(IntVec3.FromString(str));
         }
         if (itemType == typeof(Rot4))
         {
             return(Rot4.FromString(str));
         }
         if (itemType == typeof(CellRect))
         {
             return(CellRect.FromString(str));
         }
         if (itemType == typeof(CurvePoint))
         {
             return(CurvePoint.FromString(str));
         }
         if (itemType == typeof(NameTriple))
         {
             NameTriple nameTriple = NameTriple.FromString(str);
             nameTriple.ResolveMissingPieces(null);
         }
         else
         {
             if (itemType == typeof(FloatRange))
             {
                 return(FloatRange.FromString(str));
             }
             if (itemType == typeof(IntRange))
             {
                 return(IntRange.FromString(str));
             }
             if (itemType == typeof(QualityRange))
             {
                 return(QualityRange.FromString(str));
             }
             if (itemType == typeof(ColorInt))
             {
                 str = str.TrimStart('(', 'R', 'G', 'B', 'A');
                 str = str.TrimEnd(')');
                 string[] array3   = str.Split(',');
                 ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                 colorInt.r = (int)ParseHelper.FromString(array3[0], typeof(int));
                 colorInt.g = (int)ParseHelper.FromString(array3[1], typeof(int));
                 colorInt.b = (int)ParseHelper.FromString(array3[2], typeof(int));
                 if (array3.Length == 4)
                 {
                     colorInt.a = (int)ParseHelper.FromString(array3[3], typeof(int));
                 }
                 else
                 {
                     colorInt.a = 255;
                 }
                 return(colorInt);
             }
         }
         throw new ArgumentException("Trying to parse to unknown data type " + itemType.Name + ". Content is '" + str + "'.");
     }
     catch (Exception innerException2)
     {
         ArgumentException ex2 = new ArgumentException("Exception parsing " + itemType + " from \"" + str + "\"", innerException2);
         throw ex2;
     }
 }
Пример #18
0
 public void UpdateRotation()
 {
     if (this.pawn.Destroyed)
     {
         return;
     }
     if (this.pawn.jobs.HandlingFacing)
     {
         return;
     }
     if (this.pawn.pather.Moving)
     {
         if (this.pawn.pather.curPath == null || this.pawn.pather.curPath.NodesLeftCount < 1)
         {
             return;
         }
         this.FaceAdjacentCell(this.pawn.pather.nextCell);
         return;
     }
     else
     {
         Stance_Busy stance_Busy = this.pawn.stances.curStance as Stance_Busy;
         if (stance_Busy != null && stance_Busy.focusTarg.IsValid)
         {
             if (stance_Busy.focusTarg.HasThing)
             {
                 this.Face(stance_Busy.focusTarg.Thing.DrawPos);
             }
             else
             {
                 this.FaceCell(stance_Busy.focusTarg.Cell);
             }
             return;
         }
         if (this.pawn.jobs.curJob != null)
         {
             LocalTargetInfo target = this.pawn.CurJob.GetTarget(this.pawn.jobs.curDriver.rotateToFace);
             if (target.HasThing)
             {
                 bool     flag     = false;
                 IntVec3  c        = default(IntVec3);
                 CellRect cellRect = target.Thing.OccupiedRect();
                 for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
                 {
                     for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                     {
                         if (this.pawn.Position == new IntVec3(j, 0, i))
                         {
                             this.Face(target.Thing.DrawPos);
                             return;
                         }
                     }
                 }
                 for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                 {
                     for (int l = cellRect.minX; l <= cellRect.maxX; l++)
                     {
                         IntVec3 intVec = new IntVec3(l, 0, k);
                         if (intVec.AdjacentToCardinal(this.pawn.Position))
                         {
                             this.FaceAdjacentCell(intVec);
                             return;
                         }
                         if (intVec.AdjacentTo8Way(this.pawn.Position))
                         {
                             flag = true;
                             c    = intVec;
                         }
                     }
                 }
                 if (flag)
                 {
                     if (DebugViewSettings.drawPawnRotatorTarget)
                     {
                         this.pawn.Map.debugDrawer.FlashCell(this.pawn.Position, 0.6f, "jbthing", 50);
                         GenDraw.DrawLineBetween(this.pawn.Position.ToVector3Shifted(), c.ToVector3Shifted());
                     }
                     this.FaceAdjacentCell(c);
                     return;
                 }
                 this.Face(target.Thing.DrawPos);
                 return;
             }
             else
             {
                 if (this.pawn.Position.AdjacentTo8Way(target.Cell))
                 {
                     if (DebugViewSettings.drawPawnRotatorTarget)
                     {
                         this.pawn.Map.debugDrawer.FlashCell(this.pawn.Position, 0.2f, "jbloc", 50);
                         GenDraw.DrawLineBetween(this.pawn.Position.ToVector3Shifted(), target.Cell.ToVector3Shifted());
                     }
                     this.FaceAdjacentCell(target.Cell);
                     return;
                 }
                 if (target.Cell.IsValid && target.Cell != this.pawn.Position)
                 {
                     this.Face(target.Cell.ToVector3());
                     return;
                 }
             }
         }
         if (this.pawn.Drafted)
         {
             this.pawn.Rotation = Rot4.South;
         }
         return;
     }
 }
Пример #19
0
        public override void Regenerate()
        {
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.Snow);

            if (subMesh.mesh.vertexCount == 0)
            {
                SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.Terrain);
            }
            subMesh.Clear(MeshParts.Colors);
            float[]     depthGridDirect_Unsafe = base.Map.snowGrid.DepthGridDirect_Unsafe;
            CellRect    cellRect    = this.section.CellRect;
            int         num         = base.Map.Size.z - 1;
            int         num2        = base.Map.Size.x - 1;
            bool        flag        = false;
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    float num3 = depthGridDirect_Unsafe[cellIndices.CellToIndex(i, j)];
                    int   num4 = cellIndices.CellToIndex(i, j - 1);
                    float num5 = (j <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j - 1);
                    float num6 = (j <= 0 || i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j);
                    float num7 = (i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i - 1, j + 1);
                    float num8 = (j >= num || i <= 0) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i, j + 1);
                    float num9 = (j >= num) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j + 1);
                    float num10 = (j >= num || i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j);
                    float num11 = (i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    num4 = cellIndices.CellToIndex(i + 1, j - 1);
                    float num12 = (j <= 0 || i >= num2) ? num3 : depthGridDirect_Unsafe[num4];
                    this.vertDepth[0] = (num5 + num6 + num7 + num3) / 4f;
                    this.vertDepth[1] = (num7 + num3) / 2f;
                    this.vertDepth[2] = (num7 + num8 + num9 + num3) / 4f;
                    this.vertDepth[3] = (num9 + num3) / 2f;
                    this.vertDepth[4] = (num9 + num10 + num11 + num3) / 4f;
                    this.vertDepth[5] = (num11 + num3) / 2f;
                    this.vertDepth[6] = (num11 + num12 + num5 + num3) / 4f;
                    this.vertDepth[7] = (num5 + num3) / 2f;
                    this.vertDepth[8] = num3;
                    for (int k = 0; k < 9; k++)
                    {
                        if (this.vertDepth[k] > 0.01f)
                        {
                            flag = true;
                        }
                        subMesh.colors.Add(SectionLayer_Snow.SnowDepthColor(this.vertDepth[k]));
                    }
                }
            }
            if (flag)
            {
                subMesh.disabled = false;
                subMesh.FinalizeMesh(MeshParts.Colors);
            }
            else
            {
                subMesh.disabled = true;
            }
        }
Пример #20
0
        public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine)
        {
            if (targ.HasThing && targ.Thing.Map != caster.Map)
            {
                resultingLine = default(ShootLine);
                return(false);
            }
            if (verbProps.IsMeleeAttack || verbProps.range <= 1.42f)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(ReachabilityImmediate.CanReachImmediate(root, targ, caster.Map, PathEndMode.Touch, null));
            }
            CellRect cellRect = (!targ.HasThing) ? CellRect.SingleCell(targ.Cell) : targ.Thing.OccupiedRect();
            float    num      = verbProps.EffectiveMinRange(targ, caster);
            float    num2     = cellRect.ClosestDistSquaredTo(root);

            if (num2 > verbProps.range * verbProps.range || num2 < num * num)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(false);
            }
            if (!verbProps.requireLineOfSight)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(true);
            }
            IntVec3 goodDest;

            if (CasterIsPawn)
            {
                if (CanHitFromCellIgnoringRange(root, targ, out goodDest))
                {
                    resultingLine = new ShootLine(root, goodDest);
                    return(true);
                }
                ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), caster.Map, tempLeanShootSources);
                for (int i = 0; i < tempLeanShootSources.Count; i++)
                {
                    IntVec3 intVec = tempLeanShootSources[i];
                    if (CanHitFromCellIgnoringRange(intVec, targ, out goodDest))
                    {
                        resultingLine = new ShootLine(intVec, goodDest);
                        return(true);
                    }
                }
            }
            else
            {
                CellRect.CellRectIterator iterator = caster.OccupiedRect().GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 current = iterator.Current;
                    if (CanHitFromCellIgnoringRange(current, targ, out goodDest))
                    {
                        resultingLine = new ShootLine(current, goodDest);
                        return(true);
                    }
                    iterator.MoveNext();
                }
            }
            resultingLine = new ShootLine(root, targ.Cell);
            return(false);
        }
Пример #21
0
        public static object FromString(string str, Type itemType)
        {
            object result;

            try
            {
                itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
                if (itemType == typeof(string))
                {
                    str    = str.Replace("\\n", "\n");
                    result = str;
                }
                else if (itemType == typeof(int))
                {
                    result = ParseHelper.ParseIntPermissive(str);
                }
                else if (itemType == typeof(float))
                {
                    result = float.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(bool))
                {
                    result = bool.Parse(str);
                }
                else if (itemType == typeof(long))
                {
                    result = long.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(double))
                {
                    result = double.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(sbyte))
                {
                    result = sbyte.Parse(str, CultureInfo.InvariantCulture);
                }
                else
                {
                    if (itemType.IsEnum)
                    {
                        try
                        {
                            object obj = BackCompatibility.BackCompatibleEnum(itemType, str);
                            if (obj != null)
                            {
                                result = obj;
                                return(result);
                            }
                            result = Enum.Parse(itemType, str);
                            return(result);
                        }
                        catch (ArgumentException innerException)
                        {
                            string text = string.Concat(new object[]
                            {
                                "'",
                                str,
                                "' is not a valid value for ",
                                itemType,
                                ". Valid values are: \n"
                            });
                            text += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                            ArgumentException ex = new ArgumentException(text, innerException);
                            throw ex;
                        }
                    }
                    if (itemType == typeof(Type))
                    {
                        if (str == "null" || str == "Null")
                        {
                            result = null;
                        }
                        else
                        {
                            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
                            if (typeInAnyAssembly == null)
                            {
                                Log.Error("Could not find a type named " + str, false);
                            }
                            result = typeInAnyAssembly;
                        }
                    }
                    else if (itemType == typeof(Action))
                    {
                        string[] array = str.Split(new char[]
                        {
                            '.'
                        });
                        string methodName = array[array.Length - 1];
                        string typeName   = string.Empty;
                        if (array.Length == 3)
                        {
                            typeName = array[0] + "." + array[1];
                        }
                        else
                        {
                            typeName = array[0];
                        }
                        Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(typeName);
                        MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
                        result = (Action)Delegate.CreateDelegate(typeof(Action), method);
                    }
                    else if (itemType == typeof(Vector3))
                    {
                        result = ParseHelper.FromStringVector3(str);
                    }
                    else if (itemType == typeof(Vector2))
                    {
                        result = ParseHelper.FromStringVector2(str);
                    }
                    else if (itemType == typeof(Rect))
                    {
                        result = ParseHelper.FromStringRect(str);
                    }
                    else if (itemType == typeof(Color))
                    {
                        str = str.TrimStart(new char[]
                        {
                            '(',
                            'R',
                            'G',
                            'B',
                            'A'
                        });
                        str = str.TrimEnd(new char[]
                        {
                            ')'
                        });
                        string[] array2 = str.Split(new char[]
                        {
                            ','
                        });
                        float num  = (float)ParseHelper.FromString(array2[0], typeof(float));
                        float num2 = (float)ParseHelper.FromString(array2[1], typeof(float));
                        float num3 = (float)ParseHelper.FromString(array2[2], typeof(float));
                        bool  flag = num > 1f || num3 > 1f || num2 > 1f;
                        float num4 = (float)((!flag) ? 1 : 255);
                        if (array2.Length == 4)
                        {
                            num4 = (float)ParseHelper.FromString(array2[3], typeof(float));
                        }
                        Color color;
                        if (!flag)
                        {
                            color.r = num;
                            color.g = num2;
                            color.b = num3;
                            color.a = num4;
                        }
                        else
                        {
                            color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
                        }
                        result = color;
                    }
                    else if (itemType == typeof(PublishedFileId_t))
                    {
                        result = new PublishedFileId_t(ulong.Parse(str));
                    }
                    else if (itemType == typeof(IntVec2))
                    {
                        result = IntVec2.FromString(str);
                    }
                    else if (itemType == typeof(IntVec3))
                    {
                        result = IntVec3.FromString(str);
                    }
                    else if (itemType == typeof(Rot4))
                    {
                        result = Rot4.FromString(str);
                    }
                    else if (itemType == typeof(CellRect))
                    {
                        result = CellRect.FromString(str);
                    }
                    else
                    {
                        if (itemType != typeof(CurvePoint))
                        {
                            if (itemType == typeof(NameTriple))
                            {
                                NameTriple nameTriple = NameTriple.FromString(str);
                                nameTriple.ResolveMissingPieces(null);
                            }
                            else
                            {
                                if (itemType == typeof(FloatRange))
                                {
                                    result = FloatRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(IntRange))
                                {
                                    result = IntRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(QualityRange))
                                {
                                    result = QualityRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(ColorInt))
                                {
                                    str = str.TrimStart(new char[]
                                    {
                                        '(',
                                        'R',
                                        'G',
                                        'B',
                                        'A'
                                    });
                                    str = str.TrimEnd(new char[]
                                    {
                                        ')'
                                    });
                                    string[] array3 = str.Split(new char[]
                                    {
                                        ','
                                    });
                                    ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                                    colorInt.r = (int)ParseHelper.FromString(array3[0], typeof(int));
                                    colorInt.g = (int)ParseHelper.FromString(array3[1], typeof(int));
                                    colorInt.b = (int)ParseHelper.FromString(array3[2], typeof(int));
                                    if (array3.Length == 4)
                                    {
                                        colorInt.a = (int)ParseHelper.FromString(array3[3], typeof(int));
                                    }
                                    else
                                    {
                                        colorInt.a = 255;
                                    }
                                    result = colorInt;
                                    return(result);
                                }
                            }
                            throw new ArgumentException(string.Concat(new string[]
                            {
                                "Trying to parse to unknown data type ",
                                itemType.Name,
                                ". Content is '",
                                str,
                                "'."
                            }));
                        }
                        result = CurvePoint.FromString(str);
                    }
                }
            }
            catch (Exception innerException2)
            {
                ArgumentException ex2 = new ArgumentException(string.Concat(new object[]
                {
                    "Exception parsing ",
                    itemType,
                    " from \"",
                    str,
                    "\""
                }), innerException2);
                throw ex2;
            }
            return(result);
        }
Пример #22
0
 public Enumerator(CellRect ir)
 {
     this.ir = ir;
     this.x  = ir.minX - 1;
     this.z  = ir.minZ;
 }
        public override void Regenerate()
        {
            Building[] innerArray = base.Map.edificeGrid.InnerArray;
            float      y          = AltitudeLayer.Shadows.AltitudeFor();
            CellRect   cellRect   = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(base.Map);
            LayerSubMesh sm = base.GetSubMesh(MatBases.EdgeShadow);

            sm.Clear(MeshParts.All);
            sm.verts.Capacity  = cellRect.Area * 4;
            sm.colors.Capacity = cellRect.Area * 4;
            sm.tris.Capacity   = cellRect.Area * 8;
            bool[]      array       = new bool[4];
            bool[]      array2      = new bool[4];
            bool[]      array3      = new bool[4];
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    Thing thing = innerArray[cellIndices.CellToIndex(i, j)];
                    if (thing != null && thing.def.castEdgeShadows)
                    {
                        sm.verts.Add(new Vector3((float)i, y, (float)j));
                        sm.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                        sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                        sm.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        int count = sm.verts.Count;
                        sm.tris.Add(count - 4);
                        sm.tris.Add(count - 3);
                        sm.tris.Add(count - 2);
                        sm.tris.Add(count - 4);
                        sm.tris.Add(count - 2);
                        sm.tris.Add(count - 1);
                    }
                    else
                    {
                        array[0]  = false;
                        array[1]  = false;
                        array[2]  = false;
                        array[3]  = false;
                        array2[0] = false;
                        array2[1] = false;
                        array2[2] = false;
                        array2[3] = false;
                        array3[0] = false;
                        array3[1] = false;
                        array3[2] = false;
                        array3[3] = false;
                        IntVec3   a = new IntVec3(i, 0, j);
                        IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround;
                        for (int k = 0; k < 4; k++)
                        {
                            IntVec3 c = a + cardinalDirectionsAround[k];
                            if (c.InBounds(base.Map))
                            {
                                thing = innerArray[cellIndices.CellToIndex(c)];
                                if (thing != null && thing.def.castEdgeShadows)
                                {
                                    array2[k]          = true;
                                    array[(k + 3) % 4] = true;
                                    array[k]           = true;
                                }
                            }
                        }
                        IntVec3[] diagonalDirectionsAround = GenAdj.DiagonalDirectionsAround;
                        for (int l = 0; l < 4; l++)
                        {
                            if (!array[l])
                            {
                                IntVec3 c = a + diagonalDirectionsAround[l];
                                if (c.InBounds(base.Map))
                                {
                                    thing = innerArray[cellIndices.CellToIndex(c)];
                                    if (thing != null && thing.def.castEdgeShadows)
                                    {
                                        array[l]  = true;
                                        array3[l] = true;
                                    }
                                }
                            }
                        }
                        Action <int> action = delegate(int idx)
                        {
                            sm.tris.Add(sm.verts.Count - 2);
                            sm.tris.Add(idx);
                            sm.tris.Add(sm.verts.Count - 1);
                            sm.tris.Add(sm.verts.Count - 1);
                            sm.tris.Add(idx);
                            sm.tris.Add(idx + 1);
                        };
                        Action action2 = delegate()
                        {
                            sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                            sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                            sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                            sm.tris.Add(sm.verts.Count - 3);
                            sm.tris.Add(sm.verts.Count - 2);
                            sm.tris.Add(sm.verts.Count - 1);
                        };
                        int count2 = sm.verts.Count;
                        if (array[0])
                        {
                            if (array2[0] || array2[1])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[0])
                                {
                                    num = 0.45f;
                                }
                                if (array2[1])
                                {
                                    num2 = 0.45f;
                                }
                                sm.verts.Add(new Vector3((float)i, y, (float)j));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)i + num2, y, (float)j + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[1] && !array3[1])
                                {
                                    action(sm.verts.Count);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)i, y, (float)j));
                                sm.verts.Add(new Vector3((float)i, y, (float)j + 0.45f));
                                sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)j));
                                action2();
                            }
                        }
                        if (array[1])
                        {
                            if (array2[1] || array2[2])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[1])
                                {
                                    num2 = 0.45f;
                                }
                                if (array2[2])
                                {
                                    num = -0.45f;
                                }
                                sm.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)i + num2, y, (float)(j + 1) + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[2] && !array3[2])
                                {
                                    action(sm.verts.Count);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                                sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)(j + 1)));
                                sm.verts.Add(new Vector3((float)i, y, (float)(j + 1) - 0.45f));
                                action2();
                            }
                        }
                        if (array[2])
                        {
                            if (array2[2] || array2[3])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[2])
                                {
                                    num = -0.45f;
                                }
                                if (array2[3])
                                {
                                    num2 = -0.45f;
                                }
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)(j + 1) + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[3] && !array3[3])
                                {
                                    action(sm.verts.Count);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1) - 0.45f));
                                sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)(j + 1)));
                                action2();
                            }
                        }
                        if (array[3])
                        {
                            if (array2[3] || array2[0])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[3])
                                {
                                    num2 = -0.45f;
                                }
                                if (array2[0])
                                {
                                    num = 0.45f;
                                }
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)j + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[0] && !array3[0])
                                {
                                    action(count2);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)j));
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)j + 0.45f));
                                action2();
                            }
                        }
                    }
                }
            }
            if (sm.verts.Count > 0)
            {
                sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors);
            }
        }
Пример #24
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            var map = Map;     // before DeSpawn!

            base.DeSpawn(mode);

            if (def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
            }

            if (mode != DestroyMode.WillReplace)
            {
                if (def.MakeFog)
                {
                    map.fogGrid.Notify_FogBlockerRemoved(Position);
                }

                if (def.holdsRoof)
                {
                    RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
                }

                if (def.IsSmoothable)
                {
                    SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map);
                }
            }

            if (sustainerAmbient != null)
            {
                sustainerAmbient.End();
            }

            CellRect occRect = GenAdj.OccupiedRect(this);

            for (int z = occRect.minZ; z <= occRect.maxZ; z++)
            {
                for (int x = occRect.minX; x <= occRect.maxX; x++)
                {
                    IntVec3 c = new IntVec3(x, 0, z);

                    MapMeshFlag changeType = MapMeshFlag.Buildings;

                    if (def.coversFloor)
                    {
                        changeType |= MapMeshFlag.Terrain;
                    }

                    if (def.Fillage == FillCategory.Full)
                    {
                        changeType |= MapMeshFlag.Roofs;
                        changeType |= MapMeshFlag.Snow;
                    }

                    map.mapDrawer.MapMeshDirty(c, changeType);

                    map.glowGrid.MarkGlowGridDirty(c);
                }
            }

            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);

            if (def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && canChangeTerrainOnDestroyed)
            {
                for (var cri = GenAdj.OccupiedRect(this).GetIterator(); !cri.Done(); cri.MoveNext())
                {
                    map.terrainGrid.SetTerrain(cri.Current, def.building.leaveTerrain);
                }
            }

            //Mining, planning, etc
            map.designationManager.Notify_BuildingDespawned(this);

            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }

            if (def.building.hasFuelingPort)
            {
                var fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(Position, Rotation);
                var launchable      = FuelingPortUtility.LaunchableAt(fuelingPortCell, map);

                if (launchable != null)
                {
                    launchable.Notify_FuelingPortSourceDeSpawned();
                }
            }

            //Must go after removing from buildings list
            map.avoidGrid.Notify_BuildingDespawned(this);
        }
Пример #25
0
 public IntVec3 ClampInsideMap(Map map)
 {
     return(this.ClampInsideRect(CellRect.WholeMap(map)));
 }
Пример #26
0
 public void FaceTarget(LocalTargetInfo target)
 {
     if (!target.IsValid)
     {
         return;
     }
     if (target.HasThing)
     {
         Thing thing = target.Thing.Spawned ? target.Thing : ThingOwnerUtility.GetFirstSpawnedParentThing(target.Thing);
         if (thing == null || !thing.Spawned)
         {
             return;
         }
         bool     flag     = false;
         IntVec3  c        = default(IntVec3);
         CellRect cellRect = thing.OccupiedRect();
         for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
         {
             for (int j = cellRect.minX; j <= cellRect.maxX; j++)
             {
                 if (pawn.Position == new IntVec3(j, 0, i))
                 {
                     Face(thing.DrawPos);
                     return;
                 }
             }
         }
         for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
         {
             for (int l = cellRect.minX; l <= cellRect.maxX; l++)
             {
                 IntVec3 intVec = new IntVec3(l, 0, k);
                 if (intVec.AdjacentToCardinal(pawn.Position))
                 {
                     FaceAdjacentCell(intVec);
                     return;
                 }
                 if (intVec.AdjacentTo8Way(pawn.Position))
                 {
                     flag = true;
                     c    = intVec;
                 }
             }
         }
         if (flag)
         {
             if (DebugViewSettings.drawPawnRotatorTarget)
             {
                 pawn.Map.debugDrawer.FlashCell(pawn.Position, 0.6f, "jbthing");
                 GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), c.ToVector3Shifted());
             }
             FaceAdjacentCell(c);
         }
         else
         {
             Face(thing.DrawPos);
         }
     }
     else if (pawn.Position.AdjacentTo8Way(target.Cell))
     {
         if (DebugViewSettings.drawPawnRotatorTarget)
         {
             pawn.Map.debugDrawer.FlashCell(pawn.Position, 0.2f, "jbloc");
             GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), target.Cell.ToVector3Shifted());
         }
         FaceAdjacentCell(target.Cell);
     }
     else if (target.Cell.IsValid && target.Cell != pawn.Position)
     {
         Face(target.Cell.ToVector3());
     }
 }
Пример #27
0
        public override void Regenerate()
        {
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.FogOfWar);

            if (subMesh.mesh.vertexCount == 0)
            {
                SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.FogOfWar);
            }
            subMesh.Clear(MeshParts.Colors);
            bool[]      fogGrid     = base.Map.fogGrid.fogGrid;
            CellRect    cellRect    = this.section.CellRect;
            int         num         = base.Map.Size.z - 1;
            int         num2        = base.Map.Size.x - 1;
            bool        flag        = false;
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    if (fogGrid[cellIndices.CellToIndex(i, j)])
                    {
                        for (int k = 0; k < 9; k++)
                        {
                            this.vertsCovered[k] = true;
                        }
                    }
                    else
                    {
                        for (int l = 0; l < 9; l++)
                        {
                            this.vertsCovered[l] = false;
                        }
                        if (j < num && fogGrid[cellIndices.CellToIndex(i, j + 1)])
                        {
                            this.vertsCovered[2] = true;
                            this.vertsCovered[3] = true;
                            this.vertsCovered[4] = true;
                        }
                        if (j > 0 && fogGrid[cellIndices.CellToIndex(i, j - 1)])
                        {
                            this.vertsCovered[6] = true;
                            this.vertsCovered[7] = true;
                            this.vertsCovered[0] = true;
                        }
                        if (i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j)])
                        {
                            this.vertsCovered[4] = true;
                            this.vertsCovered[5] = true;
                            this.vertsCovered[6] = true;
                        }
                        if (i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j)])
                        {
                            this.vertsCovered[0] = true;
                            this.vertsCovered[1] = true;
                            this.vertsCovered[2] = true;
                        }
                        if (j > 0 && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j - 1)])
                        {
                            this.vertsCovered[0] = true;
                        }
                        if (j < num && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j + 1)])
                        {
                            this.vertsCovered[2] = true;
                        }
                        if (j < num && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j + 1)])
                        {
                            this.vertsCovered[4] = true;
                        }
                        if (j > 0 && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j - 1)])
                        {
                            this.vertsCovered[6] = true;
                        }
                    }
                    for (int m = 0; m < 9; m++)
                    {
                        byte a;
                        if (this.vertsCovered[m])
                        {
                            a    = byte.MaxValue;
                            flag = true;
                        }
                        else
                        {
                            a = 0;
                        }
                        subMesh.colors.Add(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, a));
                    }
                }
            }
            if (flag)
            {
                subMesh.disabled = false;
                subMesh.FinalizeMesh(MeshParts.Colors);
            }
            else
            {
                subMesh.disabled = true;
            }
        }
Пример #28
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            Map map = base.Map;

            base.DeSpawn(mode);
            if (this.def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
            }
            if (mode != DestroyMode.WillReplace)
            {
                if (this.def.MakeFog)
                {
                    map.fogGrid.Notify_FogBlockerRemoved(base.Position);
                }
                if (this.def.holdsRoof)
                {
                    RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
                }
                if (this.def.IsSmoothable)
                {
                    SmoothSurfaceDesignatorUtility.Notify_BuildingDespawned(this, map);
                }
            }
            if (this.sustainerAmbient != null)
            {
                this.sustainerAmbient.End();
            }
            CellRect cellRect = this.OccupiedRect();

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3     loc         = new IntVec3(j, 0, i);
                    MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings;
                    if (this.def.coversFloor)
                    {
                        mapMeshFlag |= MapMeshFlag.Terrain;
                    }
                    if (this.def.Fillage == FillCategory.Full)
                    {
                        mapMeshFlag |= MapMeshFlag.Roofs;
                        mapMeshFlag |= MapMeshFlag.Snow;
                    }
                    map.mapDrawer.MapMeshDirty(loc, mapMeshFlag);
                    map.glowGrid.MarkGlowGridDirty(loc);
                }
            }
            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);
            if (this.def.building.leaveTerrain != null && Current.ProgramState == ProgramState.Playing && this.canChangeTerrainOnDestroyed)
            {
                CellRect.CellRectIterator iterator = this.OccupiedRect().GetIterator();
                while (!iterator.Done())
                {
                    map.terrainGrid.SetTerrain(iterator.Current, this.def.building.leaveTerrain);
                    iterator.MoveNext();
                }
            }
            map.designationManager.Notify_BuildingDespawned(this);
            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }
            if (this.def.building.hasFuelingPort)
            {
                IntVec3        fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation);
                CompLaunchable compLaunchable  = FuelingPortUtility.LaunchableAt(fuelingPortCell, map);
                if (compLaunchable != null)
                {
                    compLaunchable.Notify_FuelingPortSourceDeSpawned();
                }
            }
            if (this.def.building.ai_combatDangerous)
            {
                AvoidGridMaker.Notify_CombatDangerousBuildingDespawned(this, map);
            }
        }
Пример #29
0
        public static IntVec3 InteractionCellWhenAt(ThingDef def, IntVec3 center, Rot4 rot, Map map)
        {
            if (def.hasInteractionCell)
            {
                IntVec3 b = def.interactionCellOffset.RotatedBy(rot);
                return(center + b);
            }
            if (def.Size.x == 1 && def.Size.z == 1)
            {
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 intVec = center + GenAdj.AdjacentCells[i];
                    if (intVec.Standable(map) && intVec.GetDoor(map) == null && ReachabilityImmediate.CanReachImmediate(intVec, center, map, PathEndMode.Touch, null))
                    {
                        return(intVec);
                    }
                }
                for (int j = 0; j < 8; j++)
                {
                    IntVec3 intVec2 = center + GenAdj.AdjacentCells[j];
                    if (intVec2.Standable(map) && ReachabilityImmediate.CanReachImmediate(intVec2, center, map, PathEndMode.Touch, null))
                    {
                        return(intVec2);
                    }
                }
                for (int k = 0; k < 8; k++)
                {
                    IntVec3 intVec3 = center + GenAdj.AdjacentCells[k];
                    if (intVec3.Walkable(map) && ReachabilityImmediate.CanReachImmediate(intVec3, center, map, PathEndMode.Touch, null))
                    {
                        return(intVec3);
                    }
                }
                return(center);
            }
            List <IntVec3> list = GenAdjFast.AdjacentCells8Way(center, rot, def.size);
            CellRect       rect = GenAdj.OccupiedRect(center, rot, def.size);

            for (int l = 0; l < list.Count; l++)
            {
                if (list[l].Standable(map) && list[l].GetDoor(map) == null && ReachabilityImmediate.CanReachImmediate(list[l], rect, map, PathEndMode.Touch, null))
                {
                    return(list[l]);
                }
            }
            for (int m = 0; m < list.Count; m++)
            {
                if (list[m].Standable(map) && ReachabilityImmediate.CanReachImmediate(list[m], rect, map, PathEndMode.Touch, null))
                {
                    return(list[m]);
                }
            }
            for (int n = 0; n < list.Count; n++)
            {
                if (list[n].Walkable(map) && ReachabilityImmediate.CanReachImmediate(list[n], rect, map, PathEndMode.Touch, null))
                {
                    return(list[n]);
                }
            }
            return(center);
        }
Пример #30
0
        public void RegenerateMesh()
        {
            for (int i = 0; i < this.meshes.Count; i++)
            {
                this.meshes[i].Clear();
            }
            int num  = 0;
            int num2 = 0;

            if (this.meshes.Count < num + 1)
            {
                Mesh mesh = new Mesh();
                mesh.name = "CellBoolDrawer";
                this.meshes.Add(mesh);
            }
            Mesh     mesh2    = this.meshes[num];
            CellRect cellRect = new CellRect(0, 0, this.mapSizeX, this.mapSizeZ);
            float    y        = AltitudeLayer.MapDataOverlay.AltitudeFor();
            bool     careAboutVertexColors = false;

            for (int j = cellRect.minX; j <= cellRect.maxX; j++)
            {
                for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                {
                    int index = CellIndicesUtility.CellToIndex(j, k, this.mapSizeX);
                    if (this.giver.GetCellBool(index))
                    {
                        CellBoolDrawer.verts.Add(new Vector3((float)j, y, (float)k));
                        CellBoolDrawer.verts.Add(new Vector3((float)j, y, (float)(k + 1)));
                        CellBoolDrawer.verts.Add(new Vector3((float)(j + 1), y, (float)(k + 1)));
                        CellBoolDrawer.verts.Add(new Vector3((float)(j + 1), y, (float)k));
                        Color cellExtraColor = this.giver.GetCellExtraColor(index);
                        CellBoolDrawer.colors.Add(cellExtraColor);
                        CellBoolDrawer.colors.Add(cellExtraColor);
                        CellBoolDrawer.colors.Add(cellExtraColor);
                        CellBoolDrawer.colors.Add(cellExtraColor);
                        if (cellExtraColor != Color.white)
                        {
                            careAboutVertexColors = true;
                        }
                        int count = CellBoolDrawer.verts.Count;
                        CellBoolDrawer.tris.Add(count - 4);
                        CellBoolDrawer.tris.Add(count - 3);
                        CellBoolDrawer.tris.Add(count - 2);
                        CellBoolDrawer.tris.Add(count - 4);
                        CellBoolDrawer.tris.Add(count - 2);
                        CellBoolDrawer.tris.Add(count - 1);
                        num2++;
                        if (num2 >= 16383)
                        {
                            this.FinalizeWorkingDataIntoMesh(mesh2);
                            num++;
                            if (this.meshes.Count < num + 1)
                            {
                                Mesh mesh3 = new Mesh();
                                mesh3.name = "CellBoolDrawer";
                                this.meshes.Add(mesh3);
                            }
                            mesh2 = this.meshes[num];
                            num2  = 0;
                        }
                    }
                }
            }
            this.FinalizeWorkingDataIntoMesh(mesh2);
            this.CreateMaterialIfNeeded(careAboutVertexColors);
            this.dirty = false;
        }