Example #1
0
 private static void AddRadial(NVector pos, int radius, List <NVector> list)
 {
     Add(pos.DiffX(-radius), list);
     Add(pos.DiffX(radius), list);
     Add(pos.DiffY(-radius), list);
     Add(pos.DiffY(radius), list);
 }
Example #2
0
        public override bool Check(Player player, MapElementInfo onMap, string sett, NVector pos)
        {
            string[] terr = sett.Split(',');
            foreach (string terrain in terr)
            {
                if (GameMgmt.Get().newMap.Terrain(pos.DiffX(1)).category == terrain ||
                    GameMgmt.Get().newMap.Terrain(pos.DiffX(-1)).category == terrain ||
                    GameMgmt.Get().newMap.Terrain(pos.DiffY(1)).category == terrain ||
                    GameMgmt.Get().newMap.Terrain(pos.DiffY(-1)).category == terrain)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        public Sprite CalcSprite(NVector pos)
        {
            if (!combine)
            {
                return(Sprite());
            }

            string[,] i = GameMgmt.Get().data.map.levels[pos.level].improvement;
            bool north = !pos.DiffY(1).Valid() || i[pos.x, pos.y + 1] == id;
            bool east  = !pos.DiffX(1).Valid() || i[pos.x + 1, pos.y] == id;
            bool south = !pos.DiffY(-1).Valid() || i[pos.x, pos.y - 1] == id;
            bool west  = !pos.DiffX(-1).Valid() || i[pos.x - 1, pos.y] == id;

            //Debug.Log($"{pos} north:{north}, east:{east}, south:{south}, west:{west}");

            return(Sprite(ImprovementHelper.GetId(north, east, south, west)));
        }
Example #4
0
        public void Set(string id, NVector pos)
        {
            Debug.Log($"Set {pos} to {id}");

            //set data
            GameMgmt.Get().data.map.levels[pos.level].improvement[pos.x, pos.y] = id;

            //show it
            UpdateSprite(id, pos);

            //update neighbors?
            if (data[id].combine)
            {
                UpdateSprite(id, pos.DiffX(-1));
                UpdateSprite(id, pos.DiffX(1));
                UpdateSprite(id, pos.DiffY(-1));
                UpdateSprite(id, pos.DiffY(1));
            }
        }
Example #5
0
        public void Run()
        {
            L.b.gameOptions["chestGen"].SetValue("false");
            //L.b.gameOptions["fog"].SetValue("false");

            int pid = S.Players().CreatePlayer("userx", "forger");

            S.Player(pid).elements.elements.Add("shadow");
            S.Player(pid).elements.elements.Add("earth");
            S.Player(pid).quests.Add(QuestHelper.AddNoUnitTown(QuestHelper.Lose()));

            NVector pos = new NVector(8, 6, 1);

            S.Unit().Create(pid, "christkind", pos).FinishConstruct();
            var u = S.Unit().Create(pid, "emage", pos.DiffX(2));

            u.data.spells.Learn("createGolem");
            u.data.spells.Learn("vision");
            u.data.spells.Learn("heal");

            var tid = S.Towns().Create("ua", pid, pos.DiffY(-3));

            //S.Building().Create(tid, "tent", pos).FinishConstruct();

            S.Player(pid).research.Set("createGolem", true);

            int pid2 = S.Players().CreatePlayer("usery", "customn");

            S.Player(pid2).elements.elements.Add("light");
            S.Player(pid2).quests.Add(QuestHelper.AddNoUnitTown(QuestHelper.Lose()));

            NVector p2 = new NVector(9, 6, 1);

            u = S.Unit().Create(pid2, "lcurer", p2);
            u.FinishConstruct();

            tid = S.Towns().Create("ua", pid2, pos);
            S.Building().Create(tid, "logger", p2).FinishConstruct();
            S.Building().Create(tid, "temple", p2.DiffX(1)).FinishConstruct();

            //var at = L.b.animations.Hp(-12,u.Pos(), u);
            //Debug.Log("ds"+at.transform.position);

            /*S.Player(pid).elements.elements.Add("earth");
             * //GameMgmt.Get().NextPlayer();
             *
             * NVector pos = new NVector(6, 6, 0);
             * S.Unit().Create(pid, "shadow", pos);
             *
             * //if (1==1) return;
             * NVector p1 = new NVector(7, 7, 0);
             *
             * int tid = S.Towns().Create(LClass.s.NameGenerator("town"), pid, pos);
             * //S.Towns().Get(tid).level++;
             *
             * S.Town(tid).AddRes("wood",60, ResType.Gift);
             * S.Towns().Get(tid).AddRes("cobblestone",60, ResType.Gift);
             * S.Towns().Get(tid).AddRes("stone",60, ResType.Gift);
             * //S.Towns().Get(tid).AddRes("brick",50, ResType.Gift);
             * //S.Towns().Get(tid).AddRes("plank",50, ResType.Gift);
             * S.Towns().Get(tid).AddRes("gold",50, ResType.Gift);
             * S.Towns().Get(tid).AddRes("worker",50, ResType.Gift);
             * S.Towns().Get(tid).AddRes("sand",50, ResType.Gift);
             * S.Towns().Get(tid).AddRes("tool",50, ResType.Gift);
             * S.Towns().Get(tid).AddRes("telescope",2, ResType.Gift);
             * S.Towns().Get(tid).AddRes("swordc",2, ResType.Gift);
             * S.Towns().Get(tid).AddRes("shieldi",2, ResType.Gift);
             * S.Towns().Get(tid).AddRes("potionap",2, ResType.Gift);
             *
             * S.Building().Create(tid, "stair", pos.DiffX(1));
             *
             * //UnitMgmt.Get().Create(pid, "light", GameMgmt.Get().newMap.tools.GetStartPos("north"));
             * //S.Unit().Create(pid, "shadow", pos);
             * S.Unit().Create(pid, "sworker", p1.DiffX(1)).FinishConstruct();
             * GameMgmt.Get().data.map.ResGenAdd(p1, "copper", 1-GameMgmt.Get().data.map.ResGen(p1, "copper"));
             * var mage = S.Unit().Create(pid, "emage", pos.DiffY(1).DiffX(1));
             * mage.FinishConstruct();
             * mage.data.spells.Learn("addAP");
             * mage.data.spells.Learn("vision");
             *
             * S.Building().Create(tid, "emagicschool", pos.DiffY(1).DiffX(1)).FinishConstruct();
             *
             * S.Building().Create(tid, "tent", pos.DiffY(5).DiffX(1)).FinishConstruct();
             * S.Building().Create(tid, "sshrine", pos.DiffY(-1).DiffX(1)).FinishConstruct();
             *
             * S.Building().Create(tid, "shall2", pos.DiffY(-2).DiffX(1)).FinishConstruct();
             *
             * S.Building().Create(tid, "mint", pos.DiffY(-3).DiffX(1)).FinishConstruct();
             * S.Building().Create(tid, "mine", pos.DiffY(-3).DiffX(2)).FinishConstruct();
             * S.Building().Create(tid, "toolshop", pos.DiffY(-3).DiffX(3)).FinishConstruct();
             *
             * //GameMgmt.Get().newMap.levels[0].SetTile(new Vector3Int(7,7,0), L.b.terrains["grass"]);
             *
             * p1 = pos.Diff(3, 0);
             * S.Building().Create(tid, "earthWall", p1).FinishConstruct();
             * S.Building().Create(tid, "earthWall", p1.DiffY(1)).FinishConstruct();
             * S.Building().Create(tid, "earthWallGate", p1.DiffY(2));
             * S.Building().Create(tid, "earthWall", p1.DiffY(3)).FinishConstruct();
             * S.Building().Create(tid, "earthWall", p1.DiffX(-1));//.FinishConstruct();
             *
             * p1 = p1.Diff(0, 4);
             *
             * //pid = PlayerMgmt.Get().CreatePlayer("usery", "north");
             * //PlayerMgmt.Get(pid).elements.elements.Add("light");
             * //S.Unit().Create(pid, "lworker", pos.DiffX(3));
             * S.Unit().Create(pid, "sexplorer", p1).FinishConstruct();
             * S.Unit().Create(pid, "geologist", p1.DiffX(1)).FinishConstruct();
             * S.Building().Create(tid, "mine", p1).FinishConstruct();
             *
             *
             * pid = S.Players().CreatePlayer("usery", "north");
             *
             * /*UnitMgmt.Get().Create(pid,"nking", new NVector(13,10,GameMgmt.Get().data.map.standard));
             * UnitMgmt.Get().Create(pid,"nsoldier", GameMgmt.Get().newMap.tools.GetStartPos("north"));
             * UnitMgmt.Get().Create(pid,"nworker", GameMgmt.Get().newMap.tools.GetStartPos("north"));
             * int tid = S.Towns().Create(NGenTown.GetTownName("north"), pid, new NVector(6,6,GameMgmt.Get().data.map.standard));
             * TownMgmt.Get(tid).level = 4;
             *
             *
             * PlayerMgmt.Get(pid).elements.elements.Add("light");
             *
             * BuildingMgmt.Get().Create(tid, "nlibrary",new NVector(6,5,GameMgmt.Get().data.map.standard));
             *
             * //PlayerMgmt.Get(pid).quests.AddQuest(QuestHelper.Win().AddReq("season","summer"));
             * //PlayerMgmt.Get(pid).quests.AddQuest(QuestHelper.Lose().AddReq("daytime","afternoon"));
             *
             * L.b.improvements.Set("way",new NVector(7,4,0));
             * L.b.improvements.Set("way",new NVector(8,4,0));
             * L.b.improvements.Set("way",new NVector(9,4,0));
             * L.b.improvements.Set("way",new NVector(9,5,0));
             * L.b.improvements.Set("way",new NVector(9,3,0));
             *
             * /*
             * BuildingMgmt.Get().Create(tid, "nwall",8, 8);
             * BuildingMgmt.Get().Create(tid, "nwall",9, 9);
             * BuildingMgmt.Get().Create(tid, "nwall",9, 10);
             * BuildingMgmt.Get().Create(tid, "nwall",10, 10);
             * BuildingMgmt.Get().Create(tid, "nwall",11, 10);
             * BuildingMgmt.Get().Create(tid, "nwall",12, 10);
             */

            //L.b.improvements.Set("way",new NVector(6,5,0));
            //L.b.improvements.Set("way",new NVector(6,6,0));
        }
Example #6
0
        public void Run()
        {
            //L.b.gameOptions["fog"].SetValue("false");
            //add player
            int    pid = S.Players().CreatePlayer(System.Environment.UserName, "forger");
            Player p   = S.Player(pid);

            p.elements.elements.Add("shadow");
            //p.elements.elements.Add("earth"); //TODO REMOVE

            //create flower
            var flower = L.b.res.GetOrCreate("flower");

            flower.Icon = "!Icons/base:flower";
            Swamp(p, new NVector(17, 11, 1));
            Swamp(p, new NVector(17, 12, 1));
            Swamp(p, new NVector(16, 11, 1));

            //create greenhouse
            var nursery = L.b.buildings.GetOrCreate("nursery");

            nursery.Icon = "!Building/farm:nursery";
            nursery.req.Add("terrain", "swamp");
            nursery.action.Add("produce", "turn;flower:1");
            nursery.cost["construction"] = 5;
            nursery.cost["brick"]        = 2;
            nursery.buildTime            = 4;
            nursery.category             = "earth";

            //change evolve
            L.b.actions["evolve"].cost = 15;

            //create town
            var center = new NVector(20, 15, 0);
            int tid    = S.Towns().Create(LClass.s.NameGenerator("dwarf"), pid, center, false);
            var t      = S.Town(tid);

            //add buildings
            Build(tid, "shall2", center);
            Build(tid, "sshrine", center.DiffX(-2)).dataBuilding.action.Get("evolve").cost = 15;
            S.Building().Create(tid, "sfarm", center.DiffY(2)).FinishConstruct();
            S.Building().Create(tid, "quarry", center.DiffY(-2)).FinishConstruct();
            Build(tid, "sandG", center.DiffX(1).DiffY(1));
            Build(tid, "sdirt", center.DiffX(2).DiffY(1));
            Build(tid, "tent", center.DiffX(-2).DiffY(1));

            t.AddRes("worker", 7, ResType.Gift);
            t.AddRes("mushroom", 5, ResType.Gift);
            t.AddRes("tool", 20, ResType.Gift);

            //add units
            Unit(pid, "sexplorer", center);
            Unit(pid, "sworker", center.DiffX(-1));

            /*t.AddRes("copper",10,ResType.Gift); //TODO REMOVE
             * t.AddRes("pottery",10,ResType.Gift); //TODO REMOVE
             * Unit(pid, "geologist", center.DiffX(1)); //TODO REMOVE
             * Unit(pid, "settler", center.DiffY(-4)); //TODO REMOVE
             * Build(tid, "stair", center.DiffY(1).DiffX(-1)); //TODO REMOVE
             * Build(tid, "toolshop", center.DiffY(-1).DiffX(1)); //TODO REMOVE
             * Build(tid, "mine", center.DiffY(-1), false); //TODO REMOVE
             * Build(tid, "athenaeum", center.DiffX(-1)); //TODO REMOVE
             * p.research.Set("ehall",true); //TODO REMOVE
             * t.AddRes("stone",10,ResType.Gift); //TODO REMOVE
             * Build(tid, "equarters", center.DiffY(-3)); //TODO REMOVE
             *
             *
             * Unit(pid, "emage", center.DiffY(-2)); //TODO REMOVE*/

            //remove notifications
            p.info.infos.Clear();

            //add units

            //and unit
            //S.Unit().Create(pid, "shadow", new NVector(14,10, 0));

            //win
            Quest q = QuestHelper.Win();

            q.desc = TextHelper.RichText("To win this tutorial, you need to collect a rare flower for your scheduled wedding. The flower grow on the other side of the river", QuestHelper.Version("0.24"));
            q.AddReq("res", ">1:flower");
            q.main = true;
            p.quests.Add(q);

            //develop earth
            q      = new Quest("earth", "Evolve to a new element", "religion");
            q.desc = TextHelper.RichText(
                "Worship the gods in the shrine can and develop the element earth. It need maybe some attempts. (Evolve cost much less ap in this tutorial.)",
                TextHelper.Header("Tasks"), TextHelper.IconLabel("religion", "Evolve to a new element"));
            q.main = true;
            p.quests.Add(q);

            //research
            var athenaeum = L.b.buildings["athenaeum"];

            q      = QuestHelper.Build(athenaeum);
            q.desc = TextHelper.RichText("You have successfully developed. With the further development you also have new possibilities.", "Unlike the shadow element, you now need research.",
                                         TextHelper.Header("Tasks"), q.desc);
            q.AddReq("element", "earth");
            q.AddReq("questFinish", "earth");
            q.main = true;
            p.quests.Add(q);

            //geologe
            var geologe = L.b.units["geologist"];

            q      = QuestHelper.Unit(geologe);
            q.desc = TextHelper.RichText("Now it is time to produce the tools. The copper is mined in a mine and processed into tools in a factory. Train a geologist to search the mountains for copper.",
                                         TextHelper.Header("Tasks"), q.desc, TextHelper.IconLabel("examine", "Move to a stone and examine it"), TextHelper.IconLabel("overlay", "In the overlay you can see your results"));
            q.AddReq("questFinish", "athenaeum");
            q.main = true;
            p.quests.Add(q);

            //mine
            var toolshop = L.b.buildings["toolshop"];
            var mine     = L.b.buildings["mine"];

            q      = QuestHelper.Build(toolshop);
            q.desc = TextHelper.RichText("You found a perfect place for a mine. For this purpose a mine and a tool factory is needed.", "Copper mining in the mine also needs to be researched (shadow, shadow, shadow).", "The tool factory still needs to be researched (shadow, shadow).",
                                         TextHelper.Header("Tasks"), TextHelper.IconLabel(mine.Icon, "Build a " + mine.Name()), q.desc);
            q.AddReq("building", ">1:" + mine.id);
            q.AddReq("questFinish", "geologist");
            q.main = true;
            p.quests.Add(q);

            //produce copper
            var copper = L.b.res["copper"];

            q      = QuestHelper.Res(copper);
            q.desc = TextHelper.RichText(
                "Once the buildings are in function, they still need to know what they are to produce.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel("craft", "Open the craft menu in the mine and produce copper"), TextHelper.IconLabel("craft", "Open the craft menu in the tool factory and produce tools"), q.desc);
            q.AddReq("questFinish", "toolshop");
            q.main = true;
            p.quests.Add(q);

            //reach level 3
            var ehall = L.b.buildings["ehall"];

            q      = QuestHelper.Build(ehall);
            q.desc = TextHelper.RichText(
                "The basic production stands. We can now expand our settlement.", $"Research the {ehall.Name()} and upgrade your settlement.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel("research", $"Research the {ehall.Name()}"), q.desc);
            q.AddReq("questFinish", "copper");
            q.main = true;
            p.quests.Add(q);

            //pottery
            var pottery = L.b.res["pottery"];
            var pot     = L.b.buildings["pottery"];

            q      = QuestHelper.Res(pottery);
            q.desc = TextHelper.RichText(
                "Congratulations, your settlement has become a city. But now your residents have more demands, for example for pottery. You can see the demands in XX.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel(pot.Icon, $"Build the {pot.Name()}."), q.desc);
            q.AddReq("questFinish", "ehall");
            q.main = true;
            p.quests.Add(q);

            //settler
            var settler   = L.b.units["settler"];
            var equarters = L.b.buildings["equarters"];

            q      = QuestHelper.Unit(settler);
            q.desc = TextHelper.RichText(
                $"To pick the flower, we need a new city where we can build the nursery, so train a new settler in your {equarters.Name()}.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel(equarters.Icon, $"Build the {equarters.Name()} (Maybe you need to research it before)."), q.desc);
            q.AddReq("questFinish", "pottery");
            q.main = true;
            p.quests.Add(q);

            //town
            q      = new Quest("town", "Found a new town", "foundTown");
            q.desc = TextHelper.RichText(
                "The settler must walk near the swamp and found the city there. The swamp is already highlighted in the map. Via a staircase he gets to the surface. With R & F you can switch the view of the level.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel(q.Icon, q.name));
            q.AddReq("townCount", ">2");
            q.AddReq("questFinish", "settler");
            q.main = true;
            p.quests.Add(q);

            //town
            q      = QuestHelper.Build(nursery);
            q.desc = TextHelper.RichText(
                "The last task is to build a nursery. For this you have to send some resources to your new city or build the corresponding industries.",
                TextHelper.Header("Tasks"), q.desc);
            q.AddReq("questFinish", "town");
            q.main = true;
            p.quests.Add(q);
        }
Example #7
0
        public IEnumerator CreatingFog(int pid)
        {
            if (noFog)
            {
                yield break;
            }
            yield return(GameMgmt.Get().load.ShowMessage($"Create fog"));

            tileMap = new List <TileMapConfig16>();
            TileBase fTile = GameMgmt.Get().newMap.prototypeFog;

            int    width  = visible[0].GetLength(0);
            int    height = visible[0].GetLength(1);
            string max    = "/" + width + "/" + GameMgmt.Get().data.map.levels.Count;

            for (int level = 0; level < GameMgmt.Get().data.map.levels.Count; level++)
            {
                tileMap.Add(GameMgmt.Get().newMap[level].CreateNewLayer($"Fog of war {pid}", GameMgmt.Get().data.map.levels[0].LayerCount() + 2));
                bool[,] v = visible[level];
                //paint everything?
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        bool d = v[x, y];
                        //skip?
                        if (d)
                        {
                            continue;
                        }

                        NVector pos = new NVector(x, y, level);

                        //set it
                        SetTile(pos, fTile);

                        //set border
                        if (x == 0)
                        {
                            SetTile(pos.DiffX(-1), fTile);
                        }
                        if (x == width - 1)
                        {
                            SetTile(pos.DiffX(1), fTile);
                        }
                        if (y == 0)
                        {
                            SetTile(pos.DiffY(-1), fTile);
                        }
                        if (y == height - 1)
                        {
                            SetTile(pos.DiffY(1), fTile);
                        }
                    }
                    yield return(GameMgmt.Get().load.ShowSubMessage($"Create player fog {x}{max}"));
                }

                //add points
                SetTile(new NVector(-1, -1, level), fTile);
                SetTile(new NVector(-1, height, level), fTile);
                SetTile(new NVector(width, -1, level), fTile);
                SetTile(new NVector(width, height, level), fTile);
            }

            FinishRound();
        }
Example #8
0
        public void Run()
        {
            //L.b.gameOptions["fog"].SetValue("false");

            //1. player
            int pid = S.Players().CreatePlayer("forger", "forger");

            S.Player(pid).elements.elements.Add("shadow");
            S.Player(pid).elements.elements.Add("earth");

            //GameMgmt.Get().NextPlayer();

            NVector pos = new NVector(10, 8, 1);
            int     tid = S.Towns().Create(LClass.s.NameGenerator("town"), pid, pos);

            L.b.improvements.Set("way", pos);
            L.b.improvements.Set("way", pos.DiffX(1));
            L.b.improvements.Set("way", pos.DiffX(1).DiffY(1));
            S.Building().Create(tid, "sandG", pos.DiffX(1).DiffY(1)).FinishConstruct();
            L.b.improvements.Set("way", pos.DiffX(-1));
            L.b.improvements.Set("way", pos.DiffX(-2));
            S.Building().Create(tid, "stair", pos.DiffX(-2)).FinishConstruct();
            S.Building().Create(tid, "sfarm", pos.DiffX(1).DiffY(-1)).FinishConstruct();
            S.Building().Create(tid, "rootplantation", pos.DiffY(-1)).FinishConstruct();
            S.Building().Create(tid, "rootplantation", pos.DiffX(1)).FinishConstruct();
            S.Building().Create(tid, "tent", pos.DiffX(-1)).FinishConstruct();

            S.Building().Create(tid, "quarry", pos.DiffX(-1).DiffY(1)).FinishConstruct();
            S.Building().Create(tid, "sshrine", pos.DiffX(-1).DiffY(-1)).FinishConstruct();

            S.Unit().Create(pid, "sworker", pos.DiffX(1)).FinishConstruct();
            S.Unit().Create(pid, "sexplorer", pos.DiffX(-2)).FinishConstruct();
            S.Unit().Create(pid, "swarrior", pos.DiffY(-2)).FinishConstruct();

            S.Town(tid).AddRes("swordc", 3, ResType.Gift);
            S.Town(tid).AddRes("shieldc", 3, ResType.Gift);
            S.Town(tid).AddRes("shoec", 3, ResType.Gift);

            //2. player
            pos = new NVector(17, 9, 1);
            pid = S.Players().CreatePlayer("north", "north");
            S.Player(pid).elements.elements.Add("light");
            tid = S.Towns().Create(LClass.s.NameGenerator("town"), pid, pos);
            L.b.improvements.Set("way", pos.DiffX(-2));
            L.b.improvements.Set("way", pos.DiffX(-1));
            L.b.improvements.Set("way", pos);
            L.b.improvements.Set("way", pos.DiffX(1));
            L.b.improvements.Set("way", pos.DiffX(1).DiffY(-1));
            L.b.improvements.Set("way", pos.DiffX(1).DiffY(-2));
            L.b.improvements.Set("way", pos.DiffX(2).DiffY(-2));
            S.Building().Create(tid, "cobblestoneC", pos.DiffX(2).DiffY(-2)).FinishConstruct();
            L.b.improvements.Set("way", pos.DiffX(3).DiffY(-2));
            L.b.improvements.Set("way", pos.DiffX(4).DiffY(-2));
            L.b.improvements.Set("way", pos.DiffX(4).DiffY(-1));
            S.Building().Create(tid, "logger", pos.DiffX(4).DiffY(-1)).FinishConstruct();
            L.b.improvements.Set("way", pos.DiffX(5).DiffY(-2));
            S.Building().Create(tid, "hunter", pos.DiffX(5).DiffY(-2)).FinishConstruct();

            S.Building().Create(tid, "lshrine", pos.DiffY(1)).FinishConstruct();
            S.Building().Create(tid, "barrack", pos.DiffY(-1).DiffX(-1)).FinishConstruct();
            S.Building().Create(tid, "tent", pos.DiffX(2)).FinishConstruct();
            S.Building().Create(tid, "library", pos.DiffX(-1)).FinishConstruct();
            S.Building().Create(tid, "fisher", pos.DiffX(-2).DiffY(1)).FinishConstruct();
            S.Building().Create(tid, "samplingpoint", pos.DiffX(-2)).FinishConstruct();


            S.Unit().Create(pid, "lworker", pos.DiffX(1)).FinishConstruct();
            S.Unit().Create(pid, "lexplorer", pos.DiffX(4).DiffY(-2)).FinishConstruct();
            S.Unit().Create(pid, "lwarrior", pos.DiffY(-2)).FinishConstruct();



            //S.Unit().Create(pid, "light", pos);
        }
Example #9
0
        /// <summary>
        /// Get the next town
        /// </summary>
        /// <param name="player"></param>
        /// <param name="pos"></param>
        /// <param name="nextField"></param>
        /// <returns></returns>
        public Town NearestTown(Player player, NVector pos, bool nextField)
        {
            int x = pos.x;
            int y = pos.y;

            //is on this field from a own town`
            var town = S.Towns().OverlayHighestPlayer("boundary", pos, player);

            if (town != null)
            {
                return(town);
            }

            // on the next field and part of the player?
            foreach (BuildingInfo b in new [] { S.Building().At(pos),
                                                S.Building().At(pos.DiffX(-1)),
                                                S.Building().At(pos.DiffY(-1)),
                                                S.Building().At(pos.DiffX(1)),
                                                S.Building().At(pos.DiffY(1)) })
            {
                if (b != null && b.Town().playerId == player.id)
                {
                    return(b.Town());
                }
            }

            // look only for the field?
            if (nextField)
            {
                return(null);
            }

            // get towns
            List <Town> towns = GetByPlayer(player.id).ToList();

            // has a town?
            if (towns.Count == 0)
            {
                return(null);
            }

            if (towns.Count == 1)
            {
                return(towns[0]);
            }

            //TODO support for level

            Town t = null;
            // find nearst town
            int diff = 9999999;

            foreach (Town pT in towns)
            {
                int d = Math.Abs(pT.pos.x - x) + Math.Abs(pT.pos.y - y);
                // Town is near?
                if (d < diff)
                {
                    diff = d;
                    t    = pT;
                }
            }

            return(t);
        }