Exemplo n.º 1
0
        public override void Resolve(ResolveParams rp)
        {
            Map map = BaseGen.globalSettings.map;
            RectActionTrigger rectActionTrigger;

            if (rp.TryGetCustom <RectActionTrigger>("trigger", out rectActionTrigger))
            {
                GenSpawn.Spawn(rectActionTrigger, rectActionTrigger.Rect.CenterCell, map);
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            Map map = BaseGen.globalSettings.map;
            ActivatedActionDef actionDef;

            if (rp.TryGetCustom <ActivatedActionDef>("mainAdventureAction", out actionDef))
            {
                ActionTrigger       actionTrigger = null;
                IEnumerable <Thing> source        = from t in map.listerThings.AllThings
                                                    where t is ActionTrigger
                                                    select t;
                if (source.Count <Thing>() == 0)
                {
                    List <Room> allRooms = map.regionGrid.allRooms;
                    if (allRooms.Count == 0)
                    {
                        Log.Error("Could not find contained room for adventure trigger!");
                    }
                    else
                    {
                        Room room = allRooms.RandomElementByWeight((Room r) => 1f / r.GetStat(RoomStatDefOf.Space));
                        actionTrigger = new ActionTrigger();
                        foreach (IntVec3 item in room.Cells)
                        {
                            actionTrigger.Cells.Add(item);
                        }
                        IntVec3 loc = actionTrigger.Cells.RandomElement <IntVec3>();
                        GenSpawn.Spawn(actionTrigger, loc, map);
                    }
                }
                else
                {
                    actionTrigger = (source.RandomElement <Thing>() as ActionTrigger);
                }
                if (actionTrigger != null)
                {
                    actionTrigger.actionDef = actionDef;
                }
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            char[] array;
            if (rp.TryGetCustom <char[]>("hasDoor", out array))
            {
                if (rp.rect.Width < 3 && rp.rect.Height < 3)
                {
                    return;
                }
                ResolveParams resolveParams = rp;
                char[]        array2        = array;
                int           i             = 0;
                while (i < array2.Length)
                {
                    char c = array2[i];
                    if (c == 'N')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.North);
                        resolveParams.rect     = new CellRect(rp.rect.minX + 1, rp.rect.maxZ, rp.rect.Width - 2, 1);
                        goto IL_1AA;
                    }
                    if (c == 'S')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.South);
                        resolveParams.rect     = new CellRect(rp.rect.minX + 1, rp.rect.minZ, rp.rect.Width - 2, 1);
                        goto IL_1AA;
                    }
                    if (c == 'E')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.East);
                        resolveParams.rect     = new CellRect(rp.rect.maxX, rp.rect.minZ + 1, 1, rp.rect.Height - 2);
                        goto IL_1AA;
                    }
                    if (c == 'W')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.West);
                        resolveParams.rect     = new CellRect(rp.rect.minX, rp.rect.minZ + 1, 1, rp.rect.Height - 2);
                        goto IL_1AA;
                    }
IL_1BB:
                    i++;
                    continue;
IL_1AA:
                    BaseGen.symbolStack.Push("wallDoor", resolveParams);
                    goto IL_1BB;
                }
            }
            //float num;
            //rp.TryGetCustom<float>("madAnimalChance", ref num);
            //float num2;
            //rp.TryGetCustom<float>("luciferiumGasChance", ref num2);
            //float num3;
            //rp.TryGetCustom<float>("psionicLandmineChance", ref num3);
            //float num4;
            //rp.TryGetCustom<float>("smallGoldChance", ref num4);
            //float num5;
            //rp.TryGetCustom<float>("smallSilverChance", ref num5);
            //RectActionTrigger rectActionTrigger = ThingMaker.MakeThing(ThingDefOfReconAndDiscovery.RectActionTrigger, null) as RectActionTrigger;
            //rectActionTrigger.Rect = rp.rect;
            //if (Rand.Chance(num))
            //{
            //    rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.MadAnimal;
            //}
            //else if (Rand.Chance(num2))
            //{
            //    rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.LuciferiumGas;
            //}
            //else if (Rand.Chance(num3))
            //{
            //    rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.PsionicLandmine;
            //}
            //else if (Rand.Chance(num4))
            //{
            //    rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.SmallGold;
            //}
            //else if (Rand.Chance(num5))
            //{
            //    rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.SmallSilver;
            //}
            //else
            //{
            //    rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.BaseActivatedAction;
            //}
            //if (rectActionTrigger.actionDef != null)
            //{
            //    ResolveParams resolveParams2 = rp;
            //    resolveParams2.SetCustom<RectActionTrigger>("trigger", rectActionTrigger, false);
            //    BaseGen.symbolStack.Push("placeTrigger", resolveParams2);
            //}
            BaseGen.symbolStack.Push("emptyRoom", rp);
        }
        public void Transfer()
        {
            //Planting blueprint
            float totalCost           = 0;
            int   transferredTerrains = 0;
            int   transferredTiles    = 0;
            int   totalTerrains       = 0;
            int   totalItems          = 0;

            //update rect to actual placement rect using width and height
            rp.rect = new CellRect(mapOriginX, mapOriginZ, blueprint.width, blueprint.height);
            CoverageMap coverageMap = null;

            rp.TryGetCustom <CoverageMap>(Constants.CoverageMap, out coverageMap);

            for (int z = 0; z < blueprint.height; z++)
            {
                for (int x = 0; x < blueprint.width; x++)
                {
                    IntVec3 mapLocation = new IntVec3(x + mapOriginX, 0, z + mapOriginZ);
                    //Check if thepoint is in allowed bounds of the map
                    if (!mapLocation.InBounds(map) || mapLocation.InNoBuildEdgeArea(map))
                    {
                        continue; //ignore invalid cells
                    }

                    if (options.overwritesEverything || Rand.Chance(0.6f))
                    {
                        if (blueprint.terrainMap[x, z] != null ||
                            blueprint.itemsMap[x, z].Count > 0 ||
                            blueprint.wallMap[x, z] > 1)
                        {
                            ClearCell(mapLocation, map, true);
                        }
                    }
                }
            }


            for (int z = 0; z < blueprint.height; z++)
            {
                for (int x = 0; x < blueprint.width; x++)
                {
                    IntVec3 mapLocation = new IntVec3(x + mapOriginX, 0, z + mapOriginZ);
                    if (coverageMap != null)
                    {
                        if (coverageMap.isMarked(mapLocation.x, mapLocation.z) == true) //cell was used earlier
                        {
                            continue;                                                   //skip already covered tiles
                        }
                        else
                        {
                            if (blueprint.wallMap[x, z] > 1 || blueprint.wallMap[x, z] == -1)
                            {
                                coverageMap.Mark(mapLocation.x, mapLocation.z);                                                               //mark cell as used
                            }
                        }
                    }

                    //Check if thepoint is in allowed bounds of the map
                    if (!mapLocation.InBounds(map) || mapLocation.InNoBuildEdgeArea(map))
                    {
                        continue; //ignore invalid cells
                    }

                    //Construct terrain if some specific terrain stored in the blueprint
                    if (blueprint.terrainMap[x, z] != null)
                    {
                        totalTerrains++;
                        TerrainDef blueprintTerrain = TerrainDef.Named(blueprint.terrainMap[x, z].defName);
                        if (!map.terrainGrid.TerrainAt(mapLocation).IsWater)
                        {
                            map.terrainGrid.SetTerrain(mapLocation, blueprintTerrain);
                            totalCost += blueprint.terrainMap[x, z].cost;
                            transferredTerrains++;
                        }
                    }

                    //construct roof evetywhere if we doing complete transfer (ignoring outside: room with index 1).
                    if (blueprint.roofMap[x, z] == true && options.overwritesEverything && blueprint.wallMap[x, z] != 1)
                    {
                        map.roofGrid.SetRoof(mapLocation, RoofDefOf.RoofConstructed);
                    }


                    //Add items
                    if (blueprint.itemsMap[x, z] != null && blueprint.itemsMap[x, z].Count > 0 /* && cellUsed[mapLocation.x, mapLocation.z] == false*/)
                    {
                        totalItems += blueprint.itemsMap[x, z].Count;

                        bool cellIsAlreadyCleared = false;
                        foreach (ItemTile itemTile in blueprint.itemsMap[x, z])
                        {
                            if (!cellIsAlreadyCleared)   //first item to be spawned should also clear place for itself. we can't do it beforehand because we don't know if it will be able and get a chance to be spawned.
                            {
                                bool forceCleaning = (blueprint.wallMap[x, z] > 1) && Rand.Chance(0.9f);

                                if (!ClearCell(mapLocation, map, forceCleaning))
                                {
                                    break; //if cell was not cleared successfully -> break things placement cycle and move on to the next item
                                }
                                else
                                {
                                    cellIsAlreadyCleared = true;
                                }
                            }

                            Thing thing = MakeThingFromItemTile(itemTile);
                            if (thing != null)
                            {
                                try {
                                    GenSpawn.Spawn(thing, mapLocation, map, new Rot4(itemTile.rot));
                                    try {
                                        switch (thing.def.tickerType)
                                        {
                                        case TickerType.Never:
                                            break;

                                        case TickerType.Normal:
                                            thing.Tick();
                                            break;

                                        case TickerType.Long:
                                            thing.TickLong();
                                            break;

                                        case TickerType.Rare:
                                            thing.TickRare();
                                            break;
                                        }
                                        //Debug.Message("Ticked");
                                    } catch (Exception e) {
                                        //Debug.Message("Exception while tried to perform tick for {0} of cost {1}", thing.def.defName, itemTile.cost);
                                        thing.Destroy();
                                        throw e;
                                    }

                                    //Debug.Message("Setting up props");
                                    //Breakdown breakdownables: it't yet impossible to silently breakdown an item which is not spawned.
                                    CompBreakdownable b = thing.TryGetComp <CompBreakdownable>();
                                    if (b != null && options.enableDeterioration)
                                    {
                                        if (Rand.Chance(0.8f))
                                        {
                                            b.DoBreakdown();
                                        }
                                    }

                                    //reduce HP for haulable things in water
                                    if (thing.def.EverHaulable)
                                    {
                                        TerrainDef t = map.terrainGrid.TerrainAt(mapLocation);
                                        if (t != null && t.IsWater)
                                        {
                                            thing.HitPoints = (thing.HitPoints - 10) / Rand.Range(5, 20) + Rand.Range(1, 10); //things in marsh or river are really in bad condition
                                        }
                                    }
                                    transferredTiles++;
                                    totalCost += itemTile.cost;
                                } catch (Exception e) {
                                    //Debug.Message("Failed to spawn item {0} of cost {1} because of exception", thing, itemTile.cost);
                                    //ignore
                                }
                            }
                        }
                    }
                }

                if (options.shouldKeepDefencesAndPower)
                {
                    RestoreDefencesAndPower();
                }
                options.uncoveredCost = totalCost;
            }
            Debug.Log(Debug.BlueprintTransfer, "Transferred blueprint of size {0}x{1}, age {2}, total cost of approximately {3}. Items: {4}/{5}, terrains: {6}/{7}", blueprint.width, blueprint.height, -blueprint.dateShift, totalCost, transferredTiles, totalItems, transferredTerrains, totalTerrains);
        }
Exemplo n.º 5
0
        public override void Resolve(ResolveParams rp)
        {
            char[] array;
            if (rp.TryGetCustom <char[]>("hasDoor", out array))
            {
                if (rp.rect.Width < 3 && rp.rect.Height < 3)
                {
                    return;
                }
                ResolveParams resolveParams = rp;
                char[]        array2        = array;
                int           i             = 0;
                while (i < array2.Length)
                {
                    char c = array2[i];
                    if (c == 'N')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.North);
                        resolveParams.rect     = new CellRect(rp.rect.minX + 1, rp.rect.maxZ, rp.rect.Width - 2, 1);
                        goto IL_1AA;
                    }
                    if (c == 'S')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.South);
                        resolveParams.rect     = new CellRect(rp.rect.minX + 1, rp.rect.minZ, rp.rect.Width - 2, 1);
                        goto IL_1AA;
                    }
                    if (c == 'E')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.East);
                        resolveParams.rect     = new CellRect(rp.rect.maxX, rp.rect.minZ + 1, 1, rp.rect.Height - 2);
                        goto IL_1AA;
                    }
                    if (c == 'W')
                    {
                        resolveParams.thingRot = new Rot4?(Rot4.West);
                        resolveParams.rect     = new CellRect(rp.rect.minX, rp.rect.minZ + 1, 1, rp.rect.Height - 2);
                        goto IL_1AA;
                    }
IL_1BB:
                    i++;
                    continue;
IL_1AA:
                    BaseGen.symbolStack.Push("wallDoor", resolveParams, null);
                    goto IL_1BB;
                }
            }
            float chance;

            rp.TryGetCustom <float>("madAnimalChance", out chance);
            float chance2;

            rp.TryGetCustom <float>("luciferiumGasChance", out chance2);
            float chance3;

            rp.TryGetCustom <float>("psionicLandmineChance", out chance3);
            float chance4;

            rp.TryGetCustom <float>("smallGoldChance", out chance4);
            float chance5;

            rp.TryGetCustom <float>("smallSilverChance", out chance5);
            RectActionTrigger rectActionTrigger = ThingMaker.MakeThing(ThingDefOfReconAndDiscovery.RD_RectActionTrigger, null) as RectActionTrigger;

            rectActionTrigger.Rect = rp.rect;
            if (Rand.Chance(chance))
            {
                rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.RD_MadAnimal;
            }
            else if (Rand.Chance(chance2))
            {
                rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.RD_LuciferiumGas;
            }
            else if (Rand.Chance(chance3))
            {
                rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.RD_PsionicLandmine;
            }
            else if (Rand.Chance(chance4))
            {
                rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.RD_SmallGold;
            }
            else if (Rand.Chance(chance5))
            {
                rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.RD_SmallSilver;
            }
            else
            {
                rectActionTrigger.actionDef = ActionDefOfReconAndDiscovery.RD_BaseActivatedAction;
            }
            if (rectActionTrigger.actionDef != null)
            {
                ResolveParams resolveParams2 = rp;
                resolveParams2.SetCustom <RectActionTrigger>("trigger", rectActionTrigger, false);
                BaseGen.symbolStack.Push("placeTrigger", resolveParams2, null);
            }
            BaseGen.symbolStack.Push("emptyRoom", rp, null);
        }
Exemplo n.º 6
0
        public override void Resolve(ResolveParams rp)
        {
            int num;

            if (!rp.TryGetCustom <int>("minRoomDimension", out num))
            {
                Log.Error("Could not find a field minRoomDimension");
            }
            else
            {
                int width  = rp.rect.Width;
                int height = rp.rect.Height;
                Log.Message(string.Format("Current nested room dimensions -> ({0}:{1})", width, height));
                if (width < 2 * num && height < 2 * num)
                {
                    this.MakeRoom(rp);
                }
                else if ((width < 4 * num || height < 4 * num) && Rand.Value < 0.2f)
                {
                    ResolveParams rp2 = rp;
                    ResolveParams rp3 = rp;
                    rp2.rect.Width = rp.rect.Width / 2;
                    rp3.rect.minX  = rp2.rect.maxX;
                    rp3.rect.Width = rp.rect.Width / 2;
                    this.MakeRoom(rp2);
                    this.MakeRoom(rp3);
                }
                else if (width < 4 * num && height < 4 * num && Rand.Value < 0.1f)
                {
                    this.MakeRoom(rp);
                }
                else
                {
                    List <CellRect> list  = new List <CellRect>();
                    List <CellRect> list2 = new List <CellRect>();
                    if (width > 2 * num)
                    {
                        list.Add(new CellRect(rp.rect.minX, rp.rect.minZ, rp.rect.Width / 2, rp.rect.Height));
                        list.Add(new CellRect(rp.rect.minX + rp.rect.Width / 2 - 1, rp.rect.minZ, rp.rect.Width / 2, rp.rect.Height));
                    }
                    else
                    {
                        list.Add(new CellRect(rp.rect.minX, rp.rect.minZ, rp.rect.Width, rp.rect.Height));
                    }
                    foreach (CellRect item in list)
                    {
                        if (height > 2 * num)
                        {
                            list2.Add(new CellRect(item.minX, item.minZ, item.Width, item.Height / 2));
                            list2.Add(new CellRect(item.minX, item.minZ + item.Height / 2 - 1, item.Width, item.Height / 2));
                        }
                        else
                        {
                            list2.Add(item);
                        }
                    }
                    foreach (CellRect rect in list2)
                    {
                        ResolveParams resolveParams = rp;
                        resolveParams.rect = rect;
                        resolveParams.SetCustom <int>("minRoomDimension", num, false);
                        BaseGen.symbolStack.Push("nestedRoomMaze", resolveParams, null);
                    }
                }
            }
        }