예제 #1
0
        public void MergeAt(Sketch other, IntVec3 pos, SpawnPosType posType = SpawnPosType.Unchanged, bool wipeIfCollides = true)
        {
            Sketch sketch = other.DeepCopy();

            sketch.MoveBy(sketch.GetOffset(pos, posType));
            Merge(sketch, wipeIfCollides);
        }
예제 #2
0
    protected Vector3 M_GetSpawnPosition(SpawnPosType type)
    {
        Vector3 returnPos = Vector3.zero;

        switch (type)
        {
        case SpawnPosType.Iterating:
            returnPos = m_spawnPositions[m_currSpawnIndex].position;
            m_currSpawnIndex++;
            if (m_currSpawnIndex >= m_spawnPositions.Length)
            {
                m_currSpawnIndex = 0;
            }
            break;

        case SpawnPosType.Random:
            returnPos = m_spawnPositions[Random.Range(0, m_spawnPositions.Length)].position;
            break;

        default:
            break;
        }

        return(returnPos);
    }
예제 #3
0
        public bool AnyThingOutOfBounds(Map map, IntVec3 pos, SpawnPosType posType = SpawnPosType.Unchanged)
        {
            IntVec3 offset = GetOffset(pos, posType);

            for (int i = 0; i < entities.Count; i++)
            {
                SketchThing sketchThing = entities[i] as SketchThing;
                if (sketchThing == null)
                {
                    continue;
                }
                if (sketchThing.def.size == IntVec2.One)
                {
                    if (!(entities[i].pos + offset).InBounds(map))
                    {
                        return(true);
                    }
                }
                else
                {
                    foreach (IntVec3 item in sketchThing.OccupiedRect)
                    {
                        if (!(item + offset).InBounds(map))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #4
0
 private IntVec3 GetOffset(IntVec3 pos, SpawnPosType posType)
 {
     return(posType switch
     {
         SpawnPosType.Unchanged => IntVec3.Zero,
         SpawnPosType.OccupiedCenter => new IntVec3(-OccupiedCenter.x, 0, -OccupiedCenter.z),
         SpawnPosType.OccupiedBotLeft => new IntVec3(-OccupiedRect.minX, 0, -OccupiedRect.minZ),
         _ => default(IntVec3),
     } +pos);
 }
예제 #5
0
        public bool IsSpawningBlocked(Map map, IntVec3 pos, Faction faction, SpawnPosType posType = SpawnPosType.Unchanged)
        {
            IntVec3 offset = GetOffset(pos, posType);

            for (int i = 0; i < entities.Count; i++)
            {
                if (entities[i].IsSpawningBlocked(entities[i].pos + offset, map))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #6
0
        public void DrawGhost_NewTmp(IntVec3 pos, SpawnPosType posType = SpawnPosType.Unchanged, bool placingMode = false, Thing thingToIgnore = null, Func <SketchEntity, IntVec3, List <Thing>, Map, bool> validator = null)
        {
            IntVec3 offset     = GetOffset(pos, posType);
            Map     currentMap = Find.CurrentMap;
            bool    flag       = false;

            foreach (SketchEntity entity in Entities)
            {
                if (!entity.OccupiedRect.MovedBy(offset).InBounds(currentMap))
                {
                    flag = true;
                    break;
                }
            }
            foreach (SketchBuildable buildable in Buildables)
            {
                Thing       spawnedBlueprintOrFrame = buildable.GetSpawnedBlueprintOrFrame(buildable.pos + offset, currentMap);
                SketchThing sketchThing;
                if (spawnedBlueprintOrFrame != null)
                {
                    tmpSketchThings.Add(spawnedBlueprintOrFrame);
                }
                else if ((sketchThing = buildable as SketchThing) != null)
                {
                    Thing sameSpawned = sketchThing.GetSameSpawned(sketchThing.pos + offset, currentMap);
                    if (sameSpawned != null)
                    {
                        tmpSketchThings.Add(sameSpawned);
                    }
                }
            }
            CellRect cellRect = Find.CameraDriver.CurrentViewRect.ExpandedBy(1).ClipInsideMap(Find.CurrentMap);

            foreach (SketchEntity entity2 in Entities)
            {
                if ((placingMode || !entity2.IsSameSpawnedOrBlueprintOrFrame(entity2.pos + offset, currentMap)) && entity2.OccupiedRect.MovedBy(offset).InBounds(currentMap))
                {
                    Color color = ((flag || (entity2.IsSpawningBlocked(entity2.pos + offset, currentMap, thingToIgnore) && !entity2.IsSameSpawnedOrBlueprintOrFrame(entity2.pos + offset, currentMap)) || (validator != null && !validator(entity2, offset, tmpSketchThings, Find.CurrentMap))) ? BlockedColor : GhostColor);
                    if (cellRect.Contains(entity2.pos + offset))
                    {
                        entity2.DrawGhost(entity2.pos + offset, color);
                    }
                }
            }
            tmpSketchThings.Clear();
        }
예제 #7
0
        public void DrawGhost(IntVec3 pos, SpawnPosType posType = SpawnPosType.Unchanged, bool placingMode = false, Thing thingToIgnore = null)
        {
            IntVec3 offset     = GetOffset(pos, posType);
            Map     currentMap = Find.CurrentMap;
            bool    flag       = false;

            foreach (SketchEntity entity in Entities)
            {
                if (!entity.OccupiedRect.MovedBy(offset).InBounds(currentMap))
                {
                    flag = true;
                    break;
                }
            }
            foreach (SketchEntity entity2 in Entities)
            {
                if ((placingMode || !entity2.IsSameSpawnedOrBlueprintOrFrame(entity2.pos + offset, currentMap)) && entity2.OccupiedRect.MovedBy(offset).InBounds(currentMap))
                {
                    Color color = (flag || (entity2.IsSpawningBlocked(entity2.pos + offset, currentMap, thingToIgnore) && !entity2.IsSameSpawnedOrBlueprintOrFrame(entity2.pos + offset, currentMap))) ? BlockedColor : GhostColor;
                    entity2.DrawGhost(entity2.pos + offset, color);
                }
            }
        }
예제 #8
0
        private IntVec3 GetOffset(IntVec3 pos, SpawnPosType posType)
        {
            IntVec3 a;

            switch (posType)
            {
            case SpawnPosType.Unchanged:
                a = IntVec3.Zero;
                break;

            case SpawnPosType.OccupiedCenter:
                a = new IntVec3(-OccupiedCenter.x, 0, -OccupiedCenter.z);
                break;

            case SpawnPosType.OccupiedBotLeft:
                a = new IntVec3(-OccupiedRect.minX, 0, -OccupiedRect.minZ);
                break;

            default:
                a = default(IntVec3);
                break;
            }
            return(a + pos);
        }
예제 #9
0
        public void Spawn(Map map, IntVec3 pos, Faction faction, SpawnPosType posType = SpawnPosType.Unchanged, SpawnMode spawnMode = SpawnMode.Normal, bool wipeIfCollides = false, bool clearEdificeWhereFloor = false, List <Thing> spawnedThings = null, bool dormant = false, bool buildRoofsInstantly = false, Func <SketchEntity, IntVec3, bool> canSpawnThing = null, Action <IntVec3, SketchEntity> onFailedToSpawnThing = null)
        {
            IntVec3 offset = GetOffset(pos, posType);

            if (clearEdificeWhereFloor)
            {
                for (int i = 0; i < cachedTerrain.Count; i++)
                {
                    if (cachedTerrain[i].def.layerable)
                    {
                        (cachedTerrain[i].pos + offset).GetEdifice(map)?.Destroy();
                    }
                }
            }
            foreach (SketchEntity item in entities.OrderBy((SketchEntity x) => x.SpawnOrder))
            {
                IntVec3 intVec = item.pos + offset;
                if ((canSpawnThing == null || canSpawnThing(item, intVec)) && !item.Spawn(intVec, map, faction, spawnMode, wipeIfCollides, spawnedThings, dormant))
                {
                    onFailedToSpawnThing?.Invoke(intVec, item);
                }
            }
            if (spawnedThings != null && spawnMode == SpawnMode.TransportPod && !wipeIfCollides)
            {
                bool flag = false;
                for (int j = 0; j < spawnedThings.Count; j++)
                {
                    for (int k = j + 1; k < spawnedThings.Count; k++)
                    {
                        CellRect cellRect = GenAdj.OccupiedRect(spawnedThings[j].Position, spawnedThings[j].Rotation, spawnedThings[j].def.size);
                        CellRect other    = GenAdj.OccupiedRect(spawnedThings[k].Position, spawnedThings[k].Rotation, spawnedThings[k].def.size);
                        if (cellRect.Overlaps(other) && (GenSpawn.SpawningWipes(spawnedThings[j].def, spawnedThings[k].def) || GenSpawn.SpawningWipes(spawnedThings[k].def, spawnedThings[j].def)))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    for (int l = 0; l < spawnedThings.Count; l++)
                    {
                        ActiveDropPodInfo activeDropPodInfo;
                        if ((activeDropPodInfo = (spawnedThings[l].ParentHolder as ActiveDropPodInfo)) != null)
                        {
                            activeDropPodInfo.spawnWipeMode = null;
                        }
                    }
                }
            }
            if (buildRoofsInstantly && spawnMode == SpawnMode.Normal)
            {
                foreach (IntVec3 suggestedRoofCell in GetSuggestedRoofCells())
                {
                    IntVec3 c = suggestedRoofCell + offset;
                    if (c.InBounds(map) && !c.Roofed(map))
                    {
                        map.roofGrid.SetRoof(c, RoofDefOf.RoofConstructed);
                    }
                }
            }
        }
예제 #10
0
        public BackgroundSpritePrefab(XElement element)
        {
            string alignmentStr = element.GetAttributeString("alignment", "");

            if (string.IsNullOrEmpty(alignmentStr) || !Enum.TryParse(alignmentStr, out Alignment))
            {
                Alignment = Alignment.Top | Alignment.Bottom | Alignment.Left | Alignment.Right;
            }

            Commonness = element.GetAttributeInt("commonness", 1);

            string[] spawnPosStrs = element.GetAttributeString("spawnpos", "Wall").Split(',');
            foreach (string spawnPosStr in spawnPosStrs)
            {
                SpawnPosType parsedSpawnPos;
                if (Enum.TryParse(spawnPosStr.Trim(), out parsedSpawnPos))
                {
                    SpawnPos |= parsedSpawnPos;
                }
            }

            Scale.X = element.GetAttributeFloat("minsize", 1.0f);
            Scale.Y = element.GetAttributeFloat("maxsize", 1.0f);

            DepthRange = element.GetAttributeVector2("depthrange", new Vector2(0.0f, 1.0f));

            AlignWithSurface = element.GetAttributeBool("alignwithsurface", false);

            RandomRotation   = element.GetAttributeVector2("randomrotation", Vector2.Zero);
            RandomRotation.X = MathHelper.ToRadians(RandomRotation.X);
            RandomRotation.Y = MathHelper.ToRadians(RandomRotation.Y);

            SwingAmount = MathHelper.ToRadians(element.GetAttributeFloat("swingamount", 0.0f));

            OverrideCommonness = new Dictionary <string, int>();

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    Sprite = new Sprite(subElement);
                    break;

                case "overridecommonness":
                    string levelType = subElement.GetAttributeString("leveltype", "");
                    if (!OverrideCommonness.ContainsKey(levelType))
                    {
                        OverrideCommonness.Add(levelType, subElement.GetAttributeInt("commonness", 1));
                    }
                    break;

                case "leveltrigger":
                case "trigger":
                    LevelTriggerElement = subElement;
                    break;

#if CLIENT
                case "particleemitter":
                    if (ParticleEmitterPrefabs == null)
                    {
                        ParticleEmitterPrefabs = new List <Particles.ParticleEmitterPrefab>();
                        EmitterPositions       = new List <Vector2>();
                    }

                    ParticleEmitterPrefabs.Add(new Particles.ParticleEmitterPrefab(subElement));
                    EmitterPositions.Add(subElement.GetAttributeVector2("position", Vector2.Zero));
                    break;

                case "sound":
                    SoundElement  = subElement;
                    SoundPosition = subElement.GetAttributeVector2("position", Vector2.Zero);
                    break;
#endif
                }
            }
        }
예제 #11
0
 public void DrawGhost(IntVec3 pos, SpawnPosType posType = SpawnPosType.Unchanged, bool placingMode = false, Thing thingToIgnore = null)
 {
     DrawGhost_NewTmp(pos, posType, placingMode, thingToIgnore);
 }