private static TownPatrolData SpawnTownPatrol(string name, string size, PatrolData dat, bool isPlayerSpawn, Settlement spawnSettlement = null)
        {
            MBObjectManager objManager = Game.Current.ObjectManager;
            TextObject      pName      = new TextObject(name);

            PartyTemplateObject templateObject = (PartyTemplateObject)objManager.GetObject <PartyTemplateObject>(dat.templateName + "_" + size);

            spawnSettlement = isPlayerSpawn ? Settlement.CurrentSettlement : spawnSettlement;

            MobileParty patrol = objManager.CreateObject <MobileParty>(dat.templateName + "_" + size + "_" + 1);

            patrol.InitializeMobileParty(MenuUtils.ConstructTroopRoster(templateObject, patrol.Party), new TroopRoster(patrol.Party), isPlayerSpawn ? Settlement.CurrentSettlement.GatePosition : spawnSettlement.GatePosition, 0);

            patrol.SetCustomName(pName);
            patrol.Party.Owner = spawnSettlement.MapFaction.Leader == null?spawnSettlement.OwnerClan.Heroes.ToList().First() : spawnSettlement.OwnerClan.Leader;

            patrol.Party.Visuals.SetMapIconAsDirty();
            patrol.ActualClan     = spawnSettlement.OwnerClan;
            patrol.HomeSettlement = spawnSettlement;
            MenuUtils.CreatePartyTrade(patrol);

            foreach (ItemObject obj in ItemObject.All)
            {
                if (obj.IsFood)
                {
                    int num = MBRandom.RandomInt(patrol.MemberRoster.TotalManCount / 3, patrol.MemberRoster.TotalManCount);
                    if (num > 0)
                    {
                        patrol.ItemRoster.AddToCounts(obj, num);
                    }
                }
            }

            patrol.SetMovePatrolAroundSettlement(spawnSettlement);

            return(new TownPatrolData(pName.ToString(), size, patrol));
        }