public void ScheduleReplacement(CompAutoReplaceable replaceableComp)
        {
            var building = replaceableComp.parent;

            if (building?.def == null)
            {
                return;
            }
            if ((building.Stuff == null && building.def.MadeFromStuff) || (building.Stuff != null && !building.def.MadeFromStuff))
            {
                RemoteTechController.Instance.Logger.Warning("Could not schedule {0} auto-replacement due to Stuff discrepancy.", building);
                return;
            }
            var report = GenConstruct.CanPlaceBlueprintAt(building.def, replaceableComp.ParentPosition, replaceableComp.ParentRotation, map);

            if (!report.Accepted)
            {
                RemoteTechController.Instance.Logger.Message($"Could not auto-replace {building.LabelCap}: {report.Reason}");
                return;
            }
            var blueprint = GenConstruct.PlaceBlueprintForBuild(building.def, replaceableComp.ParentPosition, map, replaceableComp.ParentRotation, Faction.OfPlayer, building.Stuff);
            var entry     = new ReplacementEntry {
                position     = replaceableComp.ParentPosition,
                unforbidTick = Find.TickManager.TicksGame + RemoteTechController.Instance.BlueprintForbidDuration * GenTicks.TicksPerRealSecond,
                savedVars    = new Dictionary <string, string>()
            };

            InvokeExposableCallbacks(building, entry.savedVars, LoadSaveMode.Saving);
            pendingSettings.Add(entry);
            if (RemoteTechController.Instance.BlueprintForbidDuration > 0)
            {
                blueprint.SetForbidden(true, false);
                pendingForbiddenBlueprints.Add(entry);
            }
        }
Пример #2
0
        public void ScheduleReplacement(CompAutoReplaceable replaceableComp)
        {
            var building  = replaceableComp.parent;
            var blueprint = GenConstruct.PlaceBlueprintForBuild(building.def, replaceableComp.ParentPosition, map, replaceableComp.ParentRotation, Faction.OfPlayer, null);
            var entry     = new ReplacementEntry {
                position     = replaceableComp.ParentPosition,
                unforbidTick = Find.TickManager.TicksGame + RemoteExplosivesController.Instance.BlueprintForbidDuration * GenTicks.TicksPerRealSecond
            };
            var explosive = building as Building_RemoteExplosive;

            if (explosive != null)
            {
                entry.armed   = explosive.IsArmed;
                entry.channel = explosive.CurrentChannel;
            }
            pendingSettings.Add(entry);
            if (RemoteExplosivesController.Instance.BlueprintForbidDuration > 0)
            {
                blueprint.SetForbidden(true, false);
                pendingForbiddenBlueprints.Add(entry);
            }
        }
Пример #3
0
        public XmlSpawnerGump(XmlSpawner spawner, int X, int Y, int extension, int textextension, int newpage, ReplacementEntry rentry)
            : base(X, Y)
        {
            if (spawner == null || spawner.Deleted)
                return;

            m_Spawner = spawner;
            spawner.SpawnerGump = this;
            xoffset = textextension;
            initial_maxcount = spawner.MaxCount;
            page = newpage;
            Rentry = rentry;

            AddPage(0);

            // automatically change the gump depending on whether sequential spawning and/or subgroups are activated

            if (spawner.SequentialSpawn >= 0 || spawner.HasSubGroups() || spawner.HasIndividualSpawnTimes())
            {
                // show the fully extended gump with subgroups and reset timer info
                m_ShowGump = 2;
            }
            /*
        else
            if(spawner.HasSubGroups() || spawner.SequentialSpawn >= 0)
        {
            // show partially extended gump with subgroups
            m_ShowGump = 1;
        }
        */

            if (extension > 0)
            {
                m_ShowGump = extension;
            }
            if (extension < 0)
            {
                m_ShowGump = 0;
            }

            // if the expanded gump toggle has been activated then override the auto settings.


            if (m_ShowGump > 1)
            {
                AddBackground(0, 0, 670 + xoffset + 30, 474, 5054);
                AddAlphaRegion(0, 0, 670 + xoffset + 30, 474);
            }
            else
                if (m_ShowGump > 0)
                {
                    AddBackground(0, 0, 335 + xoffset, 474, 5054);
                    AddAlphaRegion(0, 0, 335 + xoffset, 474);
                }
                else
                {
                    AddBackground(0, 0, 305 + xoffset, 474, 5054);
                    AddAlphaRegion(0, 0, 305 + xoffset, 474);
                }

            // spawner name area
            AddImageTiled(3, 5, 227, 23, 0x52);
            AddImageTiled(4, 6, 225, 21, 0xBBC);
            AddTextEntry(6, 5, 222, 21, 0, 999, spawner.Name); // changed from color 50

            AddButton(5, 450, 0xFAE, 0xFAF, 4, GumpButtonType.Reply, 0);
            AddLabel(38, 450, 0x384, "Goto");

            //AddButton( 5, 428, 0xFB7, 0xFB9, 1, GumpButtonType.Reply, 0 );
            AddButton(5, 428, 0xFAE, 0xFAF, 1, GumpButtonType.Reply, 0);
            AddLabel(38, 428, 0x384, "Help");

            AddButton(80, 428, 0xFB4, 0xFB6, 2, GumpButtonType.Reply, 0);
            AddLabel(113, 428, 0x384, "Bring Home");

            AddButton(80, 450, 0xFA8, 0xFAA, 3, GumpButtonType.Reply, 0);
            AddLabel(113, 450, 0x384, "Respawn");

            // Props button
            AddButton(200, 428, 0xFAB, 0xFAD, 9999, GumpButtonType.Reply, 0);
            AddLabel(233, 428, 0x384, "Props");

            // Sort button
            AddButton(200, 450, 0xFAB, 0xFAD, 702, GumpButtonType.Reply, 0);
            AddLabel(233, 450, 0x384, "Sort");

            // Reset button
            AddButton(80, 406, 0xFA2, 0xFA3, 701, GumpButtonType.Reply, 0);
            AddLabel(113, 406, 0x384, "Reset");

            // Refresh button
            AddButton(200, 406, 0xFBD, 0xFBE, 9998, GumpButtonType.Reply, 0);
            AddLabel(233, 406, 0x384, "Refresh");

            // add run status display
            if (m_Spawner.Running)
            {
                AddButton(5, 399, 0x2A4E, 0x2A3A, 700, GumpButtonType.Reply, 0);
                AddLabel(38, 406, 0x384, "On");
            }
            else
            {
                AddButton(5, 399, 0x2A62, 0x2A3A, 700, GumpButtonType.Reply, 0);
                AddLabel(38, 406, 0x384, "Off");
            }

            // Add sequential spawn state
            if (m_Spawner.SequentialSpawn >= 0)
            {
                AddLabel(15, 365, 33, String.Format("{0}", m_Spawner.SequentialSpawn));
            }

            // Add Current / Max count labels
            AddLabel(231 + xoffset, 9, 68, "Count");
            AddLabel(270 + xoffset, 9, 33, "Max");

            if (m_ShowGump > 0)
            {
                // Add subgroup label
                AddLabel(334 + xoffset, 9, 68, "Sub");
            }
            if (m_ShowGump > 1)
            {
                // Add entry field labels
                AddLabel(303 + xoffset, 9, 68, "Per");
                AddLabel(329 + xoffset + 30, 9, 68, "Reset");
                AddLabel(368 + xoffset + 30, 9, 68, "To");
                AddLabel(392 + xoffset + 30, 9, 68, "Kills");
                AddLabel(432 + xoffset + 30, 9, 68, "MinD");
                AddLabel(472 + xoffset + 30, 9, 68, "MaxD");
                AddLabel(515 + xoffset + 30, 9, 68, "Rng");
                AddLabel(545 + xoffset + 30, 9, 68, "RK");
                AddLabel(565 + xoffset + 30, 9, 68, "Clr");
                AddLabel(590 + xoffset + 30, 9, 68, "NextSpawn");
            }

            // add area for spawner max
            AddLabel(180 + xoffset, 365, 50, "Spawner");
            AddImageTiled(267 + xoffset, 365, 35, 23, 0x52);
            AddImageTiled(268 + xoffset, 365, 32, 21, 0xBBC);
            AddTextEntry(273 + xoffset, 365, 33, 33, 33, 300, m_Spawner.MaxCount.ToString());

            // add area for spawner count
            AddImageTiled(231 + xoffset, 365, 35, 23, 0x52);
            AddImageTiled(232 + xoffset, 365, 32, 21, 0xBBC);
            AddLabel(233 + xoffset, 365, 68, m_Spawner.CurrentCount.ToString());

            // add the status string
            AddTextEntry(38, 384, 235, 33, 33, 900, m_Spawner.status_str);
            // add the page buttons
            for (int i = 0; i < (int)(MaxSpawnEntries / MaxEntriesPerPage); i++)
            {
                //AddButton( 38+i*30, 365, 2206, 2206, 0, GumpButtonType.Page, 1+i );
                AddButton(38 + i * 25, 365, 0x8B1 + i, 0x8B1 + i, 4000 + i, GumpButtonType.Reply, 0);
            }

            // add gump extension button
            if (m_ShowGump > 1)
                AddButton(645 + xoffset + 30, 450, 0x15E3, 0x15E7, 200, GumpButtonType.Reply, 0);
            else
                if (m_ShowGump > 0)
                    AddButton(315 + xoffset, 450, 0x15E1, 0x15E5, 200, GumpButtonType.Reply, 0);
                else
                    AddButton(285 + xoffset, 450, 0x15E1, 0x15E5, 200, GumpButtonType.Reply, 0);

            // add the textentry extender button
            if (xoffset > 0)
            {
                AddButton(160, 365, 0x15E3, 0x15E7, 201, GumpButtonType.Reply, 0);
            }
            else
            {
                AddButton(160, 365, 0x15E1, 0x15E5, 201, GumpButtonType.Reply, 0);
            }


            for (int i = 0; i < MaxSpawnEntries; i++)
            {
                if (page != (int)(i / MaxEntriesPerPage)) continue;

                string str = String.Empty;
                int texthue = 0;
                int background = 0xBBC;

                if (i % MaxEntriesPerPage == 0)
                {
                    //AddPage(page+1);
                    // add highlighted page button
                    AddImageTiled(35 + page * 25, 363, 25, 25, 0xBBC);
                    AddImage(38 + page * 25, 365, 0x8B1 + page);
                }

                if (i < m_Spawner.SpawnObjects.Length)
                {
                    // disable button

                    if (m_Spawner.SpawnObjects[i].Disabled)
                    {
                        // change the background for the spawn text entry if disabled
                        background = 0x23F4;
                        AddButton(2, 22 * (i % MaxEntriesPerPage) + 34, 0x82C, 0x82C, 6000 + i, GumpButtonType.Reply, 0);
                    }
                    else
                    {
                        AddButton(2, 22 * (i % MaxEntriesPerPage) + 36, 0x837, 0x837, 6000 + i, GumpButtonType.Reply, 0);
                    }


                }

                bool hasreplacement = false;

                // check for replacement entries
                if (Rentry != null && Rentry.Index == i)
                {
                    hasreplacement = true;
                    str = Rentry.Typename;
                    background = Rentry.Color;
                    // replacement is one time only.
                    Rentry = null;

                }


                // increment/decrement buttons
                AddButton(15, 22 * (i % MaxEntriesPerPage) + 34, 0x15E0, 0x15E4, 6 + (i * 2), GumpButtonType.Reply, 0);
                AddButton(30, 22 * (i % MaxEntriesPerPage) + 34, 0x15E2, 0x15E6, 7 + (i * 2), GumpButtonType.Reply, 0);

                // categorization gump button
                AddButton(171 + xoffset - 18, 22 * (i % MaxEntriesPerPage) + 34, 0x15E1, 0x15E5, 5000 + i, GumpButtonType.Reply, 0);

                // goto spawn button
                AddButton(171 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 0xFAE, 0xFAF, 1300 + i, GumpButtonType.Reply, 0);

                // text entry gump button
                AddButton(200 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 0xFAB, 0xFAD, 800 + i, GumpButtonType.Reply, 0);

                // background for text entry area
                AddImageTiled(48, 22 * (i % MaxEntriesPerPage) + 30, 133 + xoffset - 25, 23, 0x52);
                AddImageTiled(49, 22 * (i % MaxEntriesPerPage) + 31, 131 + xoffset - 25, 21, background);

                // Add page number
                //AddLabel( 15, 365, 33, String.Format("{0}",(int)(i/MaxEntriesPerPage + 1)) );
                //AddButton( 38+page*25, 365, 0x8B1+i, 0x8B1+i, 0, GumpButtonType.Page, 1+i );



                if (i < m_Spawner.SpawnObjects.Length)
                {
                    if (!hasreplacement)
                    {
                        str = (string)m_Spawner.SpawnObjects[i].TypeName;
                    }

                    int count = m_Spawner.SpawnObjects[i].SpawnedObjects.Count;
                    int max = m_Spawner.SpawnObjects[i].ActualMaxCount;
                    int subgrp = m_Spawner.SpawnObjects[i].SubGroup;
                    int spawnsper = m_Spawner.SpawnObjects[i].SpawnsPerTick;

                    texthue = subgrp * 11;
                    if (texthue < 0) texthue = 0;

                    // Add current count
                    AddImageTiled(231 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 35, 23, 0x52);
                    AddImageTiled(232 + xoffset, 22 * (i % MaxEntriesPerPage) + 31, 32, 21, 0xBBC);
                    AddLabel(233 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 68, count.ToString());

                    // Add maximum count
                    AddImageTiled(267 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 35, 23, 0x52);
                    AddImageTiled(268 + xoffset, 22 * (i % MaxEntriesPerPage) + 31, 32, 21, 0xBBC);
                    // AddTextEntry(x,y,w,ht,color,id,str)
                    AddTextEntry(270 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 30, 30, 33, 500 + i, max.ToString());


                    if (m_ShowGump > 0)
                    {
                        // Add subgroup
                        AddImageTiled(334 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 25, 23, 0x52);
                        AddImageTiled(335 + xoffset, 22 * (i % MaxEntriesPerPage) + 31, 22, 21, 0xBBC);
                        AddTextEntry(338 + xoffset, 22 * (i % MaxEntriesPerPage) + 30, 17, 33, texthue, 600 + i, subgrp.ToString());
                    }
                    if (m_ShowGump > 1)
                    {
                        // Add subgroup timer fields

                        string strrst = null;
                        string strto = null;
                        string strkill = null;
                        string strmind = null;
                        string strmaxd = null;
                        string strnext = null;
                        string strpackrange = null;
                        string strspawnsper = spawnsper.ToString();

                        if (m_Spawner.SpawnObjects[i].SequentialResetTime > 0 && m_Spawner.SpawnObjects[i].SubGroup > 0)
                        {
                            strrst = m_Spawner.SpawnObjects[i].SequentialResetTime.ToString();
                            strto = m_Spawner.SpawnObjects[i].SequentialResetTo.ToString();
                        }
                        if (m_Spawner.SpawnObjects[i].KillsNeeded > 0)
                        {
                            strkill = m_Spawner.SpawnObjects[i].KillsNeeded.ToString();
                        }

                        if (m_Spawner.SpawnObjects[i].MinDelay >= 0)
                        {
                            strmind = m_Spawner.SpawnObjects[i].MinDelay.ToString();
                        }

                        if (m_Spawner.SpawnObjects[i].MaxDelay >= 0)
                        {
                            strmaxd = m_Spawner.SpawnObjects[i].MaxDelay.ToString();
                        }

                        if (m_Spawner.SpawnObjects[i].PackRange >= 0)
                        {
                            strpackrange = m_Spawner.SpawnObjects[i].PackRange.ToString();
                        }

						if (m_Spawner.SpawnObjects[i].NextSpawn > DateTime.UtcNow)
                        {
                            // if the next spawn tick of the spawner will occur after the subgroup is available for spawning
                            // then report the next spawn tick since that is the earliest that the subgroup can actually be spawned
							if ((DateTime.UtcNow + m_Spawner.NextSpawn) > m_Spawner.SpawnObjects[i].NextSpawn)
                            {
                                strnext = m_Spawner.NextSpawn.ToString();
                            }
                            else
                            {
                                // estimate the earliest the next spawn could occur as the first spawn tick after reaching the subgroup nextspawn 
								strnext = (m_Spawner.SpawnObjects[i].NextSpawn - DateTime.UtcNow + m_Spawner.NextSpawn).ToString();
                            }
                        }
                        else
                        {
                            strnext = m_Spawner.NextSpawn.ToString();
                        }

                        int yoff = 22 * (i % MaxEntriesPerPage) + 30;

                        // spawns per tick
                        AddImageTiled(303 + xoffset, yoff, 30, 23, 0x52);
                        AddImageTiled(304 + xoffset, yoff + 1, 27, 21, 0xBBC);
                        AddTextEntry(307 + xoffset, yoff, 22, 33, texthue, 1500 + i, strspawnsper);
                        // reset time
                        AddImageTiled(329 + xoffset + 30, yoff, 35, 23, 0x52);
                        AddImageTiled(330 + xoffset + 30, yoff + 1, 32, 21, 0xBBC);
                        AddTextEntry(333 + xoffset + 30, yoff, 27, 33, texthue, 1000 + i, strrst);
                        // reset to
                        AddImageTiled(365 + xoffset + 30, yoff, 26, 23, 0x52);
                        AddImageTiled(366 + xoffset + 30, yoff + 1, 23, 21, 0xBBC);
                        AddTextEntry(369 + xoffset + 30, yoff, 18, 33, texthue, 1100 + i, strto);
                        // kills needed
                        AddImageTiled(392 + xoffset + 30, yoff, 35, 23, 0x52);
                        AddImageTiled(393 + xoffset + 30, yoff + 1, 32, 21, 0xBBC);
                        AddTextEntry(396 + xoffset + 30, yoff, 27, 33, texthue, 1200 + i, strkill);

                        // mindelay
                        AddImageTiled(428 + xoffset + 30, yoff, 41, 23, 0x52);
                        AddImageTiled(429 + xoffset + 30, yoff + 1, 38, 21, 0xBBC);
                        AddTextEntry(432 + xoffset + 30, yoff, 33, 33, texthue, 1300 + i, strmind);

                        // maxdelay
                        AddImageTiled(470 + xoffset + 30, yoff, 41, 23, 0x52);
                        AddImageTiled(471 + xoffset + 30, yoff + 1, 38, 21, 0xBBC);
                        AddTextEntry(474 + xoffset + 30, yoff, 33, 33, texthue, 1400 + i, strmaxd);

                        // packrange
                        AddImageTiled(512 + xoffset + 30, yoff, 33, 23, 0x52);
                        AddImageTiled(513 + xoffset + 30, yoff + 1, 30, 21, 0xBBC);
                        AddTextEntry(516 + xoffset + 30, yoff, 25, 33, texthue, 1600 + i, strpackrange);

                        if (m_Spawner.SequentialSpawn >= 0)
                        {
                            // restrict kills button
                            AddButton(545 + xoffset + 30, yoff, m_Spawner.SpawnObjects[i].RestrictKillsToSubgroup ? 0xD3 : 0xD2,
                                m_Spawner.SpawnObjects[i].RestrictKillsToSubgroup ? 0xD2 : 0xD3, 300 + i, GumpButtonType.Reply, 0);

                            //clear on advance button for spawn entries in subgroups that require kills
                            AddButton(565 + xoffset + 30, yoff, m_Spawner.SpawnObjects[i].ClearOnAdvance ? 0xD3 : 0xD2,
                                m_Spawner.SpawnObjects[i].ClearOnAdvance ? 0xD2 : 0xD3, 400 + i, GumpButtonType.Reply, 0);
                        }

                        // add the next spawn time
                        AddLabelCropped(590 + xoffset + 30, yoff, 70, 20, 55, strnext);

                    }

                    //AddButton( 20, 22 * (i%MaxEntriesPerPage) + 34, 0x15E3, 0x15E7, 5 + (i * 2), GumpButtonType.Reply, 0 );
                }
                // the spawn specification text
                //if(str != null)
                AddTextEntry(52, 22 * (i % MaxEntriesPerPage) + 31, 119 + xoffset - 25, 21, texthue, i, str);
            }
        }