Author Topic: Post Galaxy gernation code to add a golem?  (Read 5793 times)

Offline rogerbacon

  • Newbie Mark II
  • *
  • Posts: 11
Post Galaxy gernation code to add a golem?
« on: May 01, 2020, 10:59:06 am »
I really like the Hive golem and I'd like to ensure its somewhere in the galaxy. Is there some post-galaxy generation code where I can insert it? Also, an example of creating a specific unit would be appreciated.

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Post Galaxy gernation code to add a golem?
« Reply #1 on: May 01, 2020, 11:10:32 am »
There are two major places where unit seeding can be done. First, look in MagGeneration.cs, in the SeedSpecialEntities_LateAfterAllFactionSeeding() function. This is where most of the work is done.

However, each Faction also has a hook into similar behaviour, in its override SeedStartingEntities_LaterEverythingElse(). This is generally where more fine-grained stuff is done.

Unfortunately there's not an obvious way to seed a unit by name and not by tag; tags are just strings attached to units in the XML used generally for us to make unit seeding easy. So the easiest thing is probably to add a new Tag to the HiveGolem xml, then update SeedSpecialEntities_LateAfterAllFactionSeeding() to do that. There are a number of examples in that function, but for you you'll want to use Mapgen_SeedSpecialEntities with suitable arguments.


Offline rogerbacon

  • Newbie Mark II
  • *
  • Posts: 11
Re: Post Galaxy gernation code to add a golem?
« Reply #2 on: May 02, 2020, 04:00:39 pm »
Thanks BadgerBadger. I finally got it working. The code is below for anyone else who is interested.
One side effect is that if I use the Debug menu option "Explore All" everything disappears from the map view except for fleets. Its no big deal since I don't use that option but it is strange.

Code: [Select]
try
                {
                    planetsSeeded.Clear();
                    planetsSeeded = Mapgen_SeedSpecialEntities(Context, galaxy, null, FactionType.NaturalObject, SpecialEntityType.None, "TheHive", SeedingType.CapturableWeightsAndMax,
                    1, MapGenCountPerPlanet.One, MapGenSeedStyle.BigBad, 1, 2, minHopsToAIHomeworld, maxHopsToAIHomeworld,
                    PlanetSeedingZone.MostAnywhere, SeedingExpansionType.ComplicatedOriginal);
                    Helper_MapgenLogger_PlanetsSeeder(planetsSeeded, "TheHive - wherever", 1);
                    if (planetsSeeded.Count > 0)
                    {
                        planetsSeeded[0].IntelLevel = PlanetIntelLevel.PermanentlyWatched;
                        UnityEngine.Debug.Log("I seeded the Hive on planet " + planetsSeeded[0].Name);
                    }
                }
                catch (Exception ex)
                {

                    UnityEngine.Debug.Log("Exception in Bacon code: " + ex.Message);
                }