Example #1
0
        private double RiskPerEnemyProximity(List <ABasicPawn> enemies, CulturalCenter center)
        {
            NearEnemies.Clear();
            double result = 0;

            if (enemies != null && center != null)
            {
                if (enemies.Count > 0)
                {
                    foreach (ABasicPawn enemy in enemies)
                    {
                        double dist = Math.Exp(1.0 / Coord.Distance(enemy.Position, center.Position));
                        result += dist;
                        if (dist <= CRITICAL_DIST)
                        {
                            NearEnemies.Add(enemy);
                        }
                    }
                    result = result / enemies.Count;
                }
                else
                {
                    result = 0;
                }
            }
            return(result);
        }
Example #2
0
 private void CalculateMeanEnemyDistance(List <Unit> allies, List <Unit> enemies)
 {
     if (allies != null && enemies != null)
     {
         if (allies.Count > 0 && enemies.Count > 0)
         {
             double totalDist = 0;
             for (int i = 0; i < allies.Count; i++)
             {
                 int min = Coord.Distance(allies[i].Position, enemies[0].Position);
                 for (int j = 1; j < enemies.Count; j++)
                 {
                     int currDist = Coord.Distance(allies[i].Position, enemies[j].Position);
                     if (currDist < min)
                     {
                         min = currDist;
                     }
                 }
                 totalDist += min;
             }
             if (totalDist > 0)
             {
                 SetMeanEnemyDist(allies[0].Culture, totalDist / allies.Count);
             }
         }
     }
 }
        public override double Value()
        {
            double total = 1;

            if (Coord.Distance(Target, Oponent.GetCultCenter().Position) <
                Coord.Distance(AllyPos, Oponent.GetCultCenter().Position))
            {
                total += 2 * (1 + 1.0 / Coord.Distance(AllyPos, Oponent.GetCultCenter().Position));
            }

            ETerrain terrainAtTarget = Boards.TerrainAt(Target);

            foreach (ETerrain terrain in CurPlayer.GetPawnAt(AllyPos).PositiveTerrains)
            {
                if (terrainAtTarget == terrain)
                {
                    total += 1;
                    break;
                }
            }

            foreach (ABasicPawn enemy in Oponent.GetAttackers())
            {
                if (Coord.Distance(enemy.Position, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2 &&
                    Coord.Distance(Target, enemy.Position) < Coord.Distance(AllyPos, enemy.Position))
                {
                    total += 3.0 * (1 + 1.0 / Coord.Distance(AllyPos, enemy.Position));
                }
            }

            return(total);
        }
        public static ConnectionInfo FindConnection(TileRegion regionA, TileRegion regionB, int roomIndexA, int roomIndexB)
        {
            Coord bestTileA    = new Coord();
            Coord bestTileB    = new Coord();
            float bestDistance = float.MaxValue;

            int indexA = 0;

            while (indexA < regionA.Count)
            {
                int   indexB               = 0;
                Coord tileA                = regionA[indexA];
                Coord bestTileBThisLoop    = new Coord();
                float bestDistanceThisLoop = float.MaxValue;
                while (indexB < regionB.Count)
                {
                    Coord tileB    = regionB[indexB];
                    float distance = tileA.Distance(tileB);
                    if (distance < bestDistanceThisLoop)
                    {
                        bestDistanceThisLoop = distance;
                        bestTileBThisLoop    = tileB;
                    }
                    indexB += (int)distance;
                }
                if (bestDistanceThisLoop < bestDistance)
                {
                    bestTileA    = tileA;
                    bestTileB    = bestTileBThisLoop;
                    bestDistance = bestDistanceThisLoop;
                }
                indexA += (int)bestDistanceThisLoop;
            }
            return(new ConnectionInfo(bestTileA, bestTileB, roomIndexA, roomIndexB, bestDistance));
        }
Example #5
0
    public List <BoardEntity> FindEntitiesInArea(Coord center, int radius)
    {
        List <BoardEntity> ret = new List <BoardEntity>();

        for (int i = center.y - radius; i <= center.y + radius; i++)
        {
            for (int j = center.x - radius; j <= center.x + radius; j++)
            {
                Coord c = new Coord(j, i);

                if (center.Distance(c) <= radius)
                {
                    Tile t = GetTile(c);
                    if (t != null)
                    {
                        BoardEntity e = t.entity;
                        if (e != null)
                        {
                            ret.Add(e);
                        }
                    }
                }
            }
        }

        return(ret);
    }
Example #6
0
    private bool TooCloseToOtherPoints(Coord coord, Coord[,] grid, float cellSize)
    {
        // get the position on the grid
        Coord gridCoord = SpaceToPoissonGrid(coord, cellSize);

        // check adjacent squares
        for (int x = gridCoord.x - 1; x < gridCoord.x + 1; x++)
        {
            for (int y = gridCoord.y - 1; y < gridCoord.y + 1; y++)
            {
                if (x < 0 || x >= grid.GetLength(0) || y < 0 || y >= grid.GetLength(1))
                {
                    continue;
                }
                Coord cell = grid [x, y];
                if (cell != null)
                {
                    if (coord.Distance(cell) < minDistBetweenPoints)
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Example #7
0
 private void CalculateMeanAllyDistance(List <Unit> allies)
 {
     if (allies != null)
     {
         double totalDist = 0;
         if (allies.Count > 2)
         {
             for (int i = 0; i < allies.Count; i++)
             {
                 List <int> distances = new List <int>();
                 for (int j = 1; j < allies.Count; j++)
                 {
                     if (i != j)
                     {
                         distances.Add(Coord.Distance(allies[i].Position, allies[j].Position));
                     }
                 }
                 totalDist += distances.Min();
             }
             if (totalDist > 0)
             {
                 SetMeanAllyDistance(allies[0].Culture, totalDist / allies.Count);
             }
         }
         else
         {
             SetMeanAllyDistance(allies[0].Culture, 0);
         }
     }
 }
Example #8
0
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader("P5-snaps.txt");

            List <Snapshot> snapshots = new List <Snapshot>();

            DateTime start           = DateTime.Now;
            Snapshot currentSnapshot = null;
            String   line;

            while ((line = sr.ReadLine()) != null)
            {
                if (line.StartsWith("snapshot"))
                {
                    if (currentSnapshot != null)
                    {
                        snapshots.Add(currentSnapshot);
                    }
                    currentSnapshot = new Snapshot(line);
                }
                else
                {
                    currentSnapshot.Records.Add(new Record(line));
                }
            }
            snapshots.Add(currentSnapshot);

            TimeSpan duration = DateTime.Now - start;

            Console.WriteLine("{0} snapshots; dur: {1}", snapshots.Count, duration.ToString());
            var allnums        = snapshots.SelectMany(x => x.Records.Select(y => y.Number)).Distinct().ToList();
            var snapshotsByNum = snapshots
                                 .SelectMany(x => x.Records.Select(y => new { y.Number, y.Coordinates, x.Timestamp }))
                                 .GroupBy(x => x.Number)
                                 .ToDictionary(x => x.Key, x => x.ToList());

            Dictionary <DateTime, Coord> s = new Dictionary <DateTime, Coord>();

            foreach (var item in snapshotsByNum[736637736])
            {
                if (!s.Any() || Coord.Distance(item.Coordinates, s.Last().Value) > 0.0001)
                {
                    if (s.Any() && (item.Timestamp - s.Last().Key).TotalMinutes > 30)
                    {
                        Console.WriteLine("hospoda? [{0}]: {1}", item.Timestamp, item.Coordinates.ToString());
                    }

                    s[item.Timestamp] = item.Coordinates;
                }
            }

            /*  foreach (var item in s)
             * {
             *    Console.WriteLine("[{0}]: {1}", item.Key, item.Value.ToString());
             * }*/

            Console.ReadKey();
        }
Example #9
0
            public IEnumerable <Coord> GetPath(Coord start, Coord end)
            {
                Coord current = start;
                var   path    = Enumerable.Empty <Coord>();

                while (current.Distance(end) > JUMP_SIZE)
                {
                    Coord next;
                    do
                    {
                        next = GetRandomPointOnBox(current, JUMP_SIZE);
                    } while (!boundary.IsInBounds(next) || next.Distance(end) >= current.Distance(end));
                    path    = path.Concat(tunneler.GetPath(current, next));
                    current = next;
                }
                path = path.Concat(tunneler.GetPath(current, end));
                return(path);
            }
Example #10
0
        public void Distance_SoloDiferenteLongitud(Coord c1, double delta)
        {
            var c2 = c1.Offset(dLongitud: delta);

            var result = c2.Distance(c1);

            Assert.That(result, Is.EqualTo(delta), "Magnitud");
            Assert.That(result, Is.EqualTo(c1.Distance(c2)), "debe ser conmutativa");
        }
Example #11
0
        public void Distance_Ambos(Coord c1, double dLatitud, double dLongitud)
        {
            var c2 = c1.Offset(dLatitud, dLongitud);

            var result = c2.Distance(c1);

            Assert.That(result, Is.GreaterThan(Abs(dLatitud)), "Debe ser mayor a la magnitud del delta de latitud");
            Assert.That(result, Is.GreaterThan(Abs(dLongitud)), "Debe ser mayor a la magnitud del delta de longitud");
            Assert.That(result, Is.LessThan(Abs(dLatitud) + Abs(dLongitud)), "Debe ser menor a la suma de magnitudes");
            Assert.That(result, Is.EqualTo(c1.Distance(c2)), "debe ser conmutativa");
        }
Example #12
0
 public override int GetCost()
 {
     if (isReady())
     {
         Debug.Log(Coord.Distance(actor.position, this.position));
         return((int)(Coord.Distance(actor.position, this.position) * COOLDOWN_PER_UNIT));
     }
     else
     {
         throw new System.Exception();
     }
 }
        private Coord PlacementPosition(Board boards)
        {
            Coord spawnPoint = null;

            for (int i = 0; i < BoardConsts.MAX_LIN; i++)
            {
                for (int j = 0; j < BoardConsts.MAX_COL; j++)
                {
                    if ((boards.CellAt(i, j) == BoardConsts.EMPTY) && (Coord.Distance(SpawnPoint, new Coord(i, j)) <= SpawnRange))
                    {
                        spawnPoint = new Coord(i, j);
                        break;
                    }
                }
            }
            return(spawnPoint);
        }
Example #14
0
        public override double Value()
        {
            double total = 10;

            if (Oponent.GetUnitAt(Target) is CulturalCenter)
            {
                total += 1.0;
            }
            double remainingHealth = Oponent.GetUnitAt(Target).CurrLife / Oponent.GetUnitAt(Target).TotalLife;

            if (remainingHealth < 0.5)
            {
                total += 3.0;
            }
            if (Coord.Distance(Target, CurPlayer.GetCultCenter().Position) < BoardConsts.MAX_COL / 2)
            {
                total += 1 + 100 / Coord.Distance(Target, CurPlayer.GetCultCenter().Position);
            }
            return(total);
        }
Example #15
0
        private double RiskPerAllyCloseToEnemy(List <ABasicPawn> allies)
        {
            double result     = 0;
            int    nearAllies = 0;

            foreach (ABasicPawn ally in allies)
            {
                foreach (ABasicPawn enemy in NearEnemies)
                {
                    double dist = Coord.Distance(ally.Position, enemy.Position);
                    if (dist <= ally.MovePoints)
                    {
                        nearAllies++;
                    }
                }
            }
            if (nearAllies > 0)
            {
                result = Math.Exp(1.0 / nearAllies);
            }
            return(result);
        }
Example #16
0
    // Click target tile
    //
    public bool DoClickTarget(Coord coord)
    {
//		Debug.Log("Casting " + abilityInfo.name + " at " + coord.ToString() + "!");

        Utils.Assert(coord.Distance(owner.pos) <= abilityInfo.range, "Target was not in range of ability!");

        bool casted = false;
        Unit unit   = Game.Instance().board.FindUnit(coord);

        // Do some basic checks to save work in child classes.
        //
        bool canCast = false;

        if (abilityInfo.targetsGround)
        {
            canCast = true;
        }
        else
        {
            // Requires target unit
            //
            if (unit == null)
            {
                canCast = false;
            }
            else
            {
                canCast = true;
            }
        }

        if (canCast)
        {
            casted = Cast(coord, unit);
        }

        return(casted);
    }
Example #17
0
        private List <ACommand> GetValidAttacks()
        {
            List <ACommand> validAtks = new List <ACommand>();

            foreach (ABasicPawn pawn in CurPlayer.GetPawns())
            {
                foreach (ABasicPawn enemy in GetOponent().GetPawns())
                {
                    if (Coord.Distance(pawn.Position, enemy.Position) < pawn.MovePoints)
                    {
                        AttackCommand atk = new AttackCommand();
                        atk.SetUp(Boards, CurPlayer, GetOponent());
                        atk.SetUp(pawn.Position, enemy.Position, CurPlayer, GetOponent(), Boards);
                        if (atk.IsValid())
                        {
                            validAtks.Add(atk);
                        }
                    }
                }
            }

            return(validAtks);
        }
Example #18
0
    List <Coord> GetPointsNearBorder(Pixel[,] pixels, Coord nearCoord, int pointCount)
    {
        List <Coord> points    = new List <Coord>();
        List <int>   distances = new List <int>();

        for (int i = 0; i < pixels.GetLength(0); i++)
        {
            for (int j = 0; j < pixels.GetLength(1); j++)
            {
                Coord currentCoord = new Coord(i, j);
                if (pixels[i, j].type == PixelType.Solid && hasNeighbourOfType(pixels, currentCoord, PixelType.Border))
                {
                    int currentDist = nearCoord.Distance(currentCoord);

                    if (points.Count < pointCount)
                    {
                        points.Add(currentCoord);
                        distances.Add(currentDist);
                    }
                    else
                    {
                        for (int k = 0; k < points.Count; k++)
                        {
                            if (currentDist < distances[k])
                            {
                                points[k]    = currentCoord;
                                distances[k] = currentDist;
                                break;
                            }
                        }
                    }
                }
            }
        }
        return(points);
    }
Example #19
0
 public static int Distance(Coord a, Coord b)
 {
     return(a.Distance(b));
 }
    private void AddPlayerAndCreatures()
    {
        Room mainRoom = rooms[rooms.Count - 1];
        playerLoc = mainRoom.tiles[rand.Next(0, mainRoom.tiles.Count)];
        map[playerLoc.tileX, playerLoc.tileY] = 2;
        manager.movingObjects[playerLoc.tileX, playerLoc.tileY] = true;
        player.transform.position = new Vector3(playerLoc.tileX, playerLoc.tileY, 0f);

        GameObject instance;

        for(int i = 0; i < rooms.Count - 1; i++)
        {
            for(int j = 0; j < (rooms[i].roomSize / rand.Next(15, 25)); j++ )
            {
                Coord tilePlacement = rooms[i].tiles[rand.Next(0, rooms[i].tiles.Count)];
                if (map[tilePlacement.tileX, tilePlacement.tileY] > 1 || playerLoc.Distance(tilePlacement) < 10)
                    continue;
                instance = EnemyFactory.GetRandomObject(new Vector3(tilePlacement.tileX, tilePlacement.tileY, 0f), Quaternion.identity);
                instance.transform.SetParent(levelHolder);
                map[tilePlacement.tileX, tilePlacement.tileY] = 3;
                manager.movingObjects[tilePlacement.tileX, tilePlacement.tileY] = true;
            }

        }
    }
Example #21
0
    private void MakeCity(ref int XzSpread, string HomeTownName, ref int timesThru, int timeThru)
    {
        // The new Town
        Coord newlocality = new Coord();

        // New random choices for the towns coords
        int newXmaybe = 0;
        int newZmaybe = 0;


        int NextValidRandomPatchAmountFromTGOSRange =
            RandomGen.Next(TownGlobalObjectService.PatchCap, TownGlobalObjectService.PatchFloor);


        // Get A valid amount for the patch choice
        int randomPatches = NextValidRandomPatchAmountFromTGOSRange;

        // For "Distance" comparison
        float closest = 0;

        if (timeThru >= TownGlobalObjectService.TownRequests.Count)
        {
            newXmaybe = (int)(GetRandomXZrangedInt() * 1) + (RandomGen.FlipACoin() ? (int)MinimumDistance : -(int)MinimumDistance);
            newZmaybe = (int)(GetRandomXZrangedInt() * 1) + (RandomGen.FlipACoin() ? (int)MinimumDistance : -(int)MinimumDistance);


            // Test if the hit is closer than we would like, if it is then we need to try again

            timesThru = 0;

            while (closest < MinimumDistance + ((RandomGen.FlipACoin()) ? 0 : 1))
            {
                if (timesThru >= ExpandXZsAfterTries)
                {
                    timesThru = 0;
                    Debug.Log("**********BAILED ON COUNT OUT**************");
                    XzSpread++;
                    // closest = MinimumDistance +1;
                    // continue;
                }



                // ADDED +1!
                newXmaybe += (RandomGen.FlipACoin() ? (int)MinimumDistance : -(int)MinimumDistance);
                newZmaybe += (RandomGen.FlipACoin() ? (int)MinimumDistance : -(int)MinimumDistance);


                // wraps the modulo regardless of sign
                //newXmaybe = (newXmaybe < 0) ? newXmaybe = -(Mathf.Abs(newXmaybe) % XzSpread) : newXmaybe % XzSpread;
                //newZmaybe = (newZmaybe < 0) ? newZmaybe = -(Mathf.Abs(newZmaybe) % XzSpread) : newZmaybe % XzSpread;


                // find a random coord with a magnitude high enough
                newlocality = new Coord(newXmaybe, newZmaybe);

                // convert it to 1000* size and 500 Y
                Vector3 p1 = newlocality.ToTileSizeCeilVector3();
                //   Debug.LogFormat("{0}", p1);

                // get hits
                //   Collider[] hitColliders = Physics.OverlapSphere(p1, (MinimumDistance * ratio) * 1000f, layerMask);//, LayerMask.NameToLayer("MAPGEN"));

                ///  Collider[] hitColliders = Physics.OverlapSphere(p1, (MinimumDistance) * 500f, layerMask);//, LayerMask.NameToLayer("MAPGEN"));


                Coord closetTownFound = TownGlobalObject.GetClosest(newlocality, TownGlobalObject.townsData.Keys.ToList());


                //Scale the result based on city size.  allow for 1.41  within reason

                var tinyCityApproxPatchCount = 100;

                var scalar = (0.002f * CityRatioGrowthApproximationmultiplier * Mathf.Min(TownGlobalObject.townsData[closetTownFound].Patches.Count - tinyCityApproxPatchCount, 10));


                closest = Coord.Distance(
                    newlocality,
                    TownGlobalObject.GetClosest(
                        newlocality,
                        TownGlobalObject.townsData.Keys.ToList()
                        )
                    )
                          - scalar;           //// if we didn't hit at all just place it otherwise check the lengths

                //if (hitColliders.Length == 0)
                //{
                //    // Just skip the next bit and place this directly.
                //    closest = MinimumDistance + 1;
                //    //     Debug.LogFormat("{0} is okay as a placement", newlocality);
                //    break;
                //}

                //foreach (var hitCollider in hitColliders)
                //{

                //    var distance = (p1 - hitCollider.gameObject.transform.position).sqrMagnitude * 0.001f;

                //    if (distance < MinimumDistance)
                //    {
                //        closest = distance;
                //        //   Debug.LogFormat(hitCollider.gameObject, "{0} for {1} from {2} at {3}", closest, hitCollider.gameObject.name, "newlocality", p1);
                //    }
                //    //  closest = (distance < MinimumDistance) ? distance : closest;
                //}
                ////   closest = TownGlobalObject.GetClosestMagnitude (newlocality , placesWePlaced);

                timesThru++;
            }
        }
        else  // i < TownGlobalObjectService.TownRequests.Count
        {
            //home North etc...

            newlocality = new Coord(
                (int)TownGlobalObjectService.TownRequests[timeThru].Coord.x,
                (int)TownGlobalObjectService.TownRequests[timeThru].Coord.y);                      // Hometon
        }


        TownTileRenderer mrnewlocalityMaker = new TownTileRenderer();


        // 0 triggers a random
        int amount = 0;


        if (timeThru < TownGlobalObjectService.TownRequests.Count)
        {
            if (timeThru == 0)
            {
                amount += TownHolder.Instance.MinCitySpreadreq;
            }
            else
            {
                amount += TownGlobalObjectService.TownRequests[timeThru].PatchesInSize;
            }
        }
        // Fill it with Joy
        AOTABundle newlocalityBundle = mrnewlocalityMaker.MakeATileBundle(newlocality, true, false, amount);



        //  Debug.Log(TownGlobalObjectService.WorldMultiplier);


        //Town.Town newlocalitylazyTown;

        ////Handle the homes case
        //if (i ==0 )
        //{
        //   newlocalitylazyTown = TownGlobalObject.towns.GetOrAdd(newlocality, k => TownGlobalObject.MakeTown(k, k.x, k.z, 0, 60));

        //}
        //else
        //{
        //  newlocalitylazyTown = TownGlobalObject.towns.GetOrAdd(newlocality, k => TownGlobalObject.MakeTown(k, k.x, k.z, 0, randomPatches));

        //}

        //    TownGlobalObject.townsData[locality] = TownGlobalObject.MakeTown(locality, locality.x, locality.z);

        // THIS CONTAINS THE TOWN DATA
        TownGlobalObject.townsData[newlocality] = newlocalityBundle.town;



        if (timeThru < TownGlobalObjectService.TownRequests.Count)
        {
            TownGlobalObject.townsData[newlocality].name = TownGlobalObjectService.TownRequests[timeThru].Name;
            newlocalityBundle.town.coord = new Coord(
                (int)TownGlobalObjectService.TownRequests[timeThru].Coord.x,
                (int)TownGlobalObjectService.TownRequests[timeThru].Coord.y);
        }

        //handle the home case.
        if (timeThru == 0 && newlocality == new Coord(0))
        {
            TownGlobalObject.townsData[newlocality].name = HomeTownName;
            TownGlobalObject.homeTown = TownGlobalObject.townsData[newlocality];
        }



        //  Debug.Log(TownGlobalObject.townsData[newlocality].name);

        // Bless it.

        // TODO: ADD  METHOD WERE WE CAN PASS A TOWN



        newlocalityBundle.MarkisBundledTrue();

        newlocalityBundle.MarkIsTileDataInBundleTrue();

        TownGlobalObject.bundles[newlocality] = newlocalityBundle;



        AOTABundle reffedBundle = TownGlobalObject.bundles[newlocality];

        //Debug.LogFormat(
        //            "INIT TEST: bundle found for tile {5} town {0}: {7} : {3} with {1} SplineSysBundles and {2} TransitionsListBundles and {4} and {6}",
        //           string.Format("{0}:{1}", newlocality.x, newlocality.z),
        //            reffedBundle.SplineSysBundle.Count(),
        //            reffedBundle.TransitionsListBundle.Count(),
        //            reffedBundle.name,
        //            (reffedBundle.isBundled) ? " is bundled :)" : "is not bundled :(",
        //           newlocality,
        //             (reffedBundle.isTileDataInBundle) ? " Tile Data IS In Bundle :)" : "TILE DATA MISSING!!!!!!!!!!",
        //             reffedBundle.town.name
        //            );

        //  in here we could then span every X|Z and prerender every likely tile to have it's data


        float size = CityRatioGrowthApproximationmultiplier * reffedBundle.town.Patches.Count;


        // rendering 36 tiles by default at max per city
        int roughTileGuess = (int)Mathf.Max(MinTileRender, Mathf.Min(MaxTileRender, Mathf.Ceil(size * 0.004f)));



        //return the even above, we will split this in half and use that as out "theoretical middle";
        roughTileGuess = (roughTileGuess % 2 == 1) ? roughTileGuess + 1 : roughTileGuess;


        //    Debug.LogFormat("approximate city size is {0} for {2} so roughly a {1} tile square", size , roughTileGuess, reffedBundle.name);


        // back assign the bundle names from the town for consistency in the editor (manually named and generated cities)

        reffedBundle.name = reffedBundle.town.name;

        // assign the non manually assigned cases
        if (timeThru >= TownGlobalObjectService.TownRequests.Count)
        {
            reffedBundle.town.coord = reffedBundle.coord;
        }


        if (TownGlobalObject.townsData[reffedBundle.town.coord].TownGameObject == null)
        {
            TownGlobalObject.townsData[reffedBundle.town.coord].TownGameObject = new GameObject(reffedBundle.town.name);
        }

        //create or use the holder now it has the right name.
        var go = TownGlobalObject.townsData[reffedBundle.town.coord].TownGameObject;

        GameObject CityHolder = new GameObject("MAP GEN COLLION HOLDER");

        CityHolder.transform.parent        = go.transform;
        CityHolder.transform.localPosition = Vector3.zero;

        CityHolder.transform.position = new Vector3(newlocality.x * 1000, 400, newlocality.z * 1000);


        //GameObject CityHolder = Instantiate<GameObject>(Temp, Temp.transform.position, Quaternion.identity);

        //Debug.LogFormat(CityHolder, "newlocalityBundle is {0} with {1} cells at {2} closest is {3}",
        //      TownGlobalObject.bundles[newlocality].name,
        //      TownGlobalObject.bundles[newlocality].town.Patches.Count,
        //      newlocality,
        //      closest);


        // add something for every city.


        float halfsize = size * 0.01f;

        // Add an item for the HUD
        //  var HUD = Instantiate(TownHolder.Instance.HUDPrefab,CityHolder.transform);
        //  HUD.transform.localPosition = Vector3.zero;


        var collisionCube = new Cube(reffedBundle.name,
                                     TownMeshRendererUtils.GetVertices((int)size, (int)size, -halfsize, -halfsize), halfsize,
                                     null,
                                     CityHolder.transform, false, false);



        collisionCube.Transform.localPosition = Vector3.zero;
        //  collisionCube.GameObject.layer = LayerMask.NameToLayer("MAPGEN");

        BoxCollider col = collisionCube.GameObject.AddComponent <BoxCollider>();

        col.size = new Vector3(size, halfsize, size);

        // Register our BoxCollider for Disabling later.

        TownGlobalObject.renderedBoxColliders.Add(col);

        TownMeshRendererOptions rendererOptions = TownGlobalObjectService.rendererOptions;

        TownOptions skeletonOptions = TownGlobalObject.bundles[newlocality].town.Options;

        skeletonOptions.IOC        = false;
        skeletonOptions.Farm       = false;
        skeletonOptions.Roads      = false;
        skeletonOptions.Walls      = false;
        skeletonOptions.CityDetail = false;



        //TownGlobalObject.MeshRenderer = new TownMeshRenderer (
        //        reffedBundle.town,
        //        skeletonOptions,
        //        rendererOptions);

        //// This does the fancy  world map colored sections
        TownGlobalObject.MeshRenderer.GenerateOverlay();


        //  Debug.LogFormat("{0} {1} ", reffedBundle.name, reffedBundle.town.name);



        // This does the fancy city overlay over the world map colored sections
        RenderTownMeshes(ref reffedBundle);



        //   TownGlobalObject.bundles[newlocality].isTileDataInBundle = true;

        //  Destroy(CityHolder);


        // Assign it back?
        TownGlobalObject.SetBundle(newlocality, reffedBundle);

        //   TownGlobalObject.bundles[newlocality] = reffedBundle;


        //   UnityEngine.Assertions.Assert.IsTrue( TownGlobalObject.bundles.ContainsKey(newlocality));



        // COULD HAVE LOOPED HERE
    }