コード例 #1
0
ファイル: BaseMapGenerator.cs プロジェクト: TrutzX/9Nations
        protected virtual void CreateTile(GameMapDataLevel std, int x, int y, int layer, int[][] layerData, int height,
                                          DataTerrain invisible)
        {
            int oTerrain = std.At(new Vector3Int(x, y, layer));

            if (oTerrain == -1)
            {
                layerData[height - y - 1][x] = -1;
                return;
            }

            DataTerrain org = L.b.terrains[oTerrain];

            //has element?
            try
            {
                if (mapGeneration.terrains.ContainsKey(org.id))
                {
                    layerData[height - y - 1][x] = L.b.terrains[mapGeneration.terrains[org.id]].defaultTile;
                }
                else if (layer == 0)
                {
                    layerData[height - y - 1][x] = invisible.defaultTile;
                }
                else
                {
                    layerData[height - y - 1][x] = -1;
                }
            }
            catch (Exception e)
            {
                Debug.Log($"{y}/{height - y - 1}/{height},{x}/{GameMgmt.Get().data.map.width}");
                throw e;
            }
        }
コード例 #2
0
ファイル: LightElement.cs プロジェクト: TrutzX/9Nations
        protected virtual NVector CreateNewSpot()
        {
            GameMapData      gmap = GameMgmt.Get().data.map;
            GameMapDataLevel gmdl = GameMgmt.Get().data.map.levels[gmap.standard];

            int i = 0;

            while (i < 1000)
            {
                i++;
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = gmdl.Terrain(x, y);

                if (t.MoveCost("walk") == 0 || t.MoveCost("walk") > 10)
                {
                    continue;                                                     // can walk?
                }
                if (!gmdl.TerrainNear(x, y, "water", 2))
                {
                    continue;                                      //near water?
                }
                if (!S.Unit().Free(new NVector(x, y, gmap.standard)))
                {
                    continue;                                                 //near water?
                }
                return(new NVector(x, y, gmap.standard));
            }

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position using {pos}");
            return(pos);
        }
コード例 #3
0
ファイル: GameMapTools.cs プロジェクト: TrutzX/9Nations
        /// <summary>
        /// Get a start position or an exception
        /// </summary>
        /// <param name="nation"></param>
        /// <returns></returns>
        /// <exception cref="System.MissingMemberException"></exception>
        public NVector GetStartPos(string nation)
        {
            GameMapData gmap = GameMgmt.Get().data.map;

            Nation n = L.b.nations[nation];
            int    i = 0;

            while (i < 1000)
            {
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = _map.Terrain(new NVector(x, y, gmap.standard));

                //right terrain?
                //TODO  && t.visible > 0
                if (t.id == n.Terrain || (t.MoveCost("walk") > 0 && t.MoveCost("walk") <= 10))
                {
                    //has a unit?
                    if (S.Unit().Free(new NVector(x, y, gmap.standard)))
                    {
                        //TODO find right spot with level support
                        return(new NVector(x, y, gmap.standard));
                    }
                }

                i++;
            }

            Debug.Log($"{gmap.standard}/{gmap.levels.Count}");

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position for {nation} using {pos}");
            return(pos);
        }
コード例 #4
0
ファイル: GameMapLevel.cs プロジェクト: TrutzX/9Nations
        public void SetTile(Vector3Int pos, DataTerrain terrain)
        {
            //set or remove?
            if (terrain == null)
            {
                dataLevel.Set(pos, -1, false);
                dataLevel.Set(pos, -1, true);
            }
            else
            {
                dataLevel.Set(pos, terrain.defaultTile, false);

                DataTerrain winter = string.IsNullOrEmpty(terrain.winter) ? terrain : L.b.terrains[terrain.winter];
                dataLevel.Set(pos, winter.defaultTile, true);
            }

            //inform tiles
            UpdateTile(new Vector3Int(pos.x - 1, pos.y - 1, pos.z));
            UpdateTile(new Vector3Int(pos.x - 1, pos.y, pos.z));
            UpdateTile(new Vector3Int(pos.x - 1, pos.y + 1, pos.z));
            UpdateTile(new Vector3Int(pos.x, pos.y - 1, pos.z));
            UpdateTile(pos);
            UpdateTile(new Vector3Int(pos.x, pos.y + 1, pos.z));
            UpdateTile(new Vector3Int(pos.x + 1, pos.y - 1, pos.z));
            UpdateTile(new Vector3Int(pos.x + 1, pos.y, pos.z));
            UpdateTile(new Vector3Int(pos.x + 1, pos.y + 1, pos.z));

            //reset pathfinding
            ResetPathFinding();
        }
コード例 #5
0
        protected override NVector CreateNewSpot()
        {
            int              level = Math.Max(GameMgmt.Get().data.map.standard - 1, 0); //underground
            GameMapData      gmap  = GameMgmt.Get().data.map;
            GameMapDataLevel gmdl  = GameMgmt.Get().data.map.levels[level];

            int i = 0;

            while (i < 1000)
            {
                i++;
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = gmdl.Terrain(x, y);


                if (t.MoveCost("float") == 0 || t.MoveCost("float") > 10)
                {
                    continue;                                                       // can walk?
                }
                if (!S.Unit().Free(new NVector(x, y, gmap.standard)))
                {
                    continue;                                                 //near water?
                }
                return(new NVector(x, y, level));
            }

            Debug.Log($"{level}/{gmap.levels.Count}");

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position using {pos}");
            return(pos);
        }
コード例 #6
0
ファイル: UnitInfo.cs プロジェクト: TrutzX/9Nations
        public string Passable(NVector pos)
        {
            DataTerrain land = GameMgmt.Get().newMap.Terrain(pos);

            //check terrain
            int cost = GameMgmt.Get().newMap.PathFinding(Pos().level).Cost(Player(), dataUnit.movement, Pos(), pos);

            if (cost == 0)
            {
                return(S.T("unitMoveErrorPassable", land.Name()));
            }

            //visible?
            if (!Player().fog.Visible(pos))
            {
                return(S.T("unitMoveErrorExplored", land.Name()));
            }

            //another unit?
            if (!S.Unit().Free(pos))
            {
                return(S.T("unitMoveErrorUnit", land.Name(), S.Unit().At(pos).name));
            }

            //can walk
            if (cost > data.ap)
            {
                return(S.T("unitMoveErrorAp", land.Name(), cost - data.ap));
            }

            return(null);
        }
コード例 #7
0
        public override bool Check(string data, Player player, NVector pos)
        {
            string[]    d    = data.Split(';');
            DataTerrain terr = GameMgmt.Get().newMap.Terrain(pos);

            return(terr.id == d[2]);
        }
コード例 #8
0
        public void SetTile(IDataLevel data, Vector3Int pos, DataTerrain terrain, bool winter, Color color)
        {
            //set it
            _data    = data;
            _winter  = winter;
            _tileMap = GetComponent <Tilemap>();
            _terrain = terrain;
            _color   = color;

            //remove it?
            if (terrain == null)
            {
                SetTile(pos.x, pos.y);
                return;
            }

            //top left
            _tileMap.SetTile(new Vector3Int(pos.x * 2, pos.y * 2 + 1, 0), _terrain.Tile(TopLeft(pos.z, pos.x, pos.y), _color));

            //top right
            _tileMap.SetTile(new Vector3Int(pos.x * 2 + 1, pos.y * 2 + 1, 0), _terrain.Tile(TopRight(pos.z, pos.x, pos.y), _color));

            //down left
            _tileMap.SetTile(new Vector3Int(pos.x * 2, pos.y * 2, 0), _terrain.Tile(DownLeft(pos.z, pos.x, pos.y), _color));

            //down right
            _tileMap.SetTile(new Vector3Int(pos.x * 2 + 1, pos.y * 2, 0), _terrain.Tile(DownRight(pos.z, pos.x, pos.y), _color));
        }
コード例 #9
0
    public void execIA(int myPlayer, WorldMap worldMap)
    {
        this.worldMap = worldMap;
        actualPlayer  = myPlayer;

        //START: get my Units
        DataTerrain dt = worldMap.dataTerrain;

        myUnits   = new List <Unit>();
        unitIndex = 0;

        for (int i = 0; i < dt.sizeMap; i++)
        {
            for (int j = 0; j < dt.sizeMap; j++)
            {
                Unit u = dt.units[j, i];
                if (u != null)
                {
                    if (u.owerPlayer == actualPlayer)
                    {
                        myUnits.Add(u);
                    }
                }
            }
        }

        GD.Print("-BASIC IA " + actualPlayer + " READY, UNITS: " + myUnits.Count);

        awaitExec(actualPlayer);
    }
コード例 #10
0
        protected override void CreateTile(GameMapDataLevel std, int x, int y, int layer, int[][] layerData, int height,
                                           DataTerrain invisible)
        {
            int oTerrain = std.At(new Vector3Int(x, y, layer));

            if (oTerrain == -1 && Random.Range(0, 10) <= 7) // 70%
            {
                layerData[height - y - 1][x] = L.b.terrains["deepWall"].defaultTile;
                return;
            }

            base.CreateTile(std, x, y, layer, layerData, height, invisible);
        }
コード例 #11
0
ファイル: ReqFogField.cs プロジェクト: TrutzX/9Nations
        public override string Desc(Player player, string sett)
        {
            string e = "Explore a field";

            if (player == null)
            {
                return(e);
            }

            DataTerrain n = GameMgmt.Get().newMap.Terrain(new NVector(sett));

            return($"You need to explore a {n.Name()}. Status: " + (Check(player, sett) ? "Not found" : "Found"));
        }
コード例 #12
0
ファイル: ActionTerraform.cs プロジェクト: TrutzX/9Nations
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            DataTerrain terrain = GameMgmt.Get().newMap.Terrain(pos);

            //which is possible?
            List <(string key, string value)> opts = new List <(string key, string value)>();
            int i = 0;

            while (holder.data.ContainsKey(i.ToString()))
            {
                var d = SplitHelper.Split(holder.data[i.ToString()]);
                if (terrain.id == d.key)
                {
                    opts.Add(d);
                }
                i++;
            }

            //found it?
            if (opts.Count == 0)
            {
                OnMapUI.Get().unitUI.ShowPanelMessageError($"No terraform possible for {terrain.Name()}");
                return;
            }

            Vector3Int v3 = new Vector3Int(pos.x, pos.y, 1); //TODO find right pos

            if (opts.Count == 1)
            {
                GameMgmt.Get().newMap.levels[pos.level]
                .SetTile(v3, opts[0].value == "remove" ? null : L.b.terrains[opts[0].value]);
                return;
            }

            //multiple?
            WindowPanelBuilder wpb = WindowPanelBuilder.Create($"Terraform {terrain.Name()}");

            foreach (var opt in opts)
            {
                wpb.panel.AddImageTextButton(CreateTitle(opt), terrain.Sprite(), () =>
                {
                    GameMgmt.Get().newMap.levels[pos.level]
                    .SetTile(v3, opt.value == "remove" ? null : L.b.terrains[opt.value]);
                    wpb.Close();
                });
            }

            wpb.AddClose();
            wpb.Finish();
        }
コード例 #13
0
ファイル: ActionTerraform.cs プロジェクト: TrutzX/9Nations
        public override void BuildPanel(ActionDisplaySettings sett)
        {
            base.BuildPanel(sett);

            //list it
            int i = 0;

            while (sett.holder.data.ContainsKey(i.ToString()))
            {
                var         d    = SplitHelper.Split(sett.holder.data[i.ToString()]);
                DataTerrain terr = L.b.terrains[d.key];
                sett.panel.AddImageLabel(CreateTitle(d), terr.Icon);
                i++;
            }
        }
コード例 #14
0
        public override void ShowLexicon(PanelBuilder panel)
        {
            DataTerrain terr = L.b.terrains[Terrain];

            base.ShowLexicon(panel);
            panel.AddHeaderLabelT("general");
            panel.AddImageLabel($"Home terrain: {terr.Name()}", terr.Sprite());
            panel.AddModi(Modi);
            if (elements.Count > 0)
            {
                panel.AddHeaderLabel(S.T(L.b.elements.Id(), elements.Count));
                foreach (var element in elements)
                {
                    L.b.elements[element].AddImageLabel(panel);
                }
            }
        }
コード例 #15
0
ファイル: ActionInteract.cs プロジェクト: TrutzX/9Nations
        protected override void ClickFirst()
        {
            //special field?
            if (!S.Unit().Free(LastClickPos))
            {
                UnitInfo unit = S.Unit().At(LastClickPos);
                if (unit.Owner(S.ActPlayerID()))
                {
                    mapElementInfo.UI().ShowPanelMessage($"You want to interact with {unit.name}? Click again!");
                }
                else
                {
                    mapElementInfo.UI().ShowPanelMessage($"You want to fight with {unit.name} from {unit.Player().name}? Click again!");
                }
                return;
            }

            DataTerrain terr = GameMgmt.Get().newMap.Terrain(LastClickPos);
            mapElementInfo.UI().ShowPanelMessage($"You want to interact with {terr.Name()}? Click again!");
        }
コード例 #16
0
ファイル: GameMapDataLevel.cs プロジェクト: TrutzX/9Nations
        public void FinishBuild()
        {
            //check generate
            if (terrains.Count == 0)
            {
                Assert.IsNotNull(generate, $"Data and generate for level {name} is missing.");
                LSys.tem.mapGeneration[generate].Generator().Generate(this);
            }

            //set res
            resGenerate = new Dictionary <string, int> [Width(), Height()];
            for (int x = 0; x < Width(); x++)
            {
                for (int y = 0; y < Height(); y++)
                {
                    DataTerrain bt = Terrain(x, y);
                    //has res?
                    if (bt.res.Count == 0)
                    {
                        continue;
                    }

                    //add it
                    resGenerate[x, y] = new Dictionary <string, int>();
                    foreach (KeyValuePair <string, string> r in bt.res)
                    {
                        string[] s = SplitHelper.Separator(r.Value);

                        //has chance?
                        if (s.Length >= 2 && Random.Range(0, 100) < ConvertHelper.Proc(s[1]))
                        {
                            continue;
                        }

                        var c = bt.ResRange(r.Key);
                        resGenerate[x, y].Add(r.Key, Random.Range(c.min, c.max));
                    }
                }
            }
        }
コード例 #17
0
ファイル: BaseMapGenerator.cs プロジェクト: TrutzX/9Nations
        public void Generate(GameMapDataLevel gmdl)
        {
            int              height    = GameMgmt.Get().data.map.height;
            DataTerrain      invisible = L.b.terrains["invisible"];
            GameMapDataLevel std       = GameMgmt.Get().data.map.levels[GameMgmt.Get().data.map.standard];

            Debug.Log($"Generate layer {mapGeneration.Name()}:{GameMgmt.Get().data.map.width}/{height}");

            for (int layer = 0; layer < std.LayerCount(); layer++)
            {
                int[][] layerData = new int[height][];
                for (int y = 0; y < height; y++)
                {
                    layerData[height - y - 1] = new int[GameMgmt.Get().data.map.width];
                    for (int x = 0; x < GameMgmt.Get().data.map.width; x++)
                    {
                        CreateTile(std, x, y, layer, layerData, height, invisible);
                    }
                }
                gmdl.AddLayer(layerData);
            }
        }
コード例 #18
0
        public void Run()
        {
            L.b.gameOptions["usageTown"].SetValue("false");
            L.b.gameOptions["inhabitantGrow"].SetValue("false");

            DataTerrain water  = L.b.terrains["water"];
            DataTerrain forest = L.b.terrains["forest"];
            DataTerrain hill   = L.b.terrains["hill"];

            //rebuild map
            //TODO GameMgmt.Get().map.SetTile(0,15,9,Data.nTerrain.hill.id);
            //GameMgmt.Get().newMap.levels[1].SetTile(new Vector3Int(15,9,1), grass);
            GameMgmt.Get().newMap.levels[1].SetTile(new Vector3Int(17, 9, 1), forest);
            GameMgmt.Get().newMap.levels[1].SetTile(new Vector3Int(17, 10, 1), forest);

            //add player
            int    pid = S.Players().CreatePlayer(System.Environment.UserName, "north");
            Player p   = S.Player(pid);

            p.elements.elements.Add("light");

            //and unit
            S.Unit().Create(pid, "light", new NVector(16, 10, 1));

            string round = TextHelper.IconLabel("round", "End the round (space)");

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

            q.desc = TextHelper.RichText("To win this tutorial, you need to follow the other quests.", QuestHelper.Version("0.24"), "You can find more tutorials from the main game.");
            q.AddReq("building", ">1:lhall2");
            p.quests.Add(q);

            //show quest menu
            q      = new Quest("menu", "Show the quest menu", "quest");
            q.desc = TextHelper.RichText(
                "Welcome to 9 Nations, 9 Nations is a turn-based strategy game. In this tutorial you will learn the basics.", "All tasks are displayed in the quest menu. Go to the quest menu (F3), which you see in the upper right corner, and see your first quest.",
                TextHelper.Header("Task"), TextHelper.IconLabel("quest", "Open the quest menu and find your first task"));
            q.main = true;
            p.quests.Add(q);

            //move map
            q      = new Quest("moveCamera", "Move the camera", "map");
            q.desc = TextHelper.RichText(LSys.tem.helps["moveCamera"].Desc(),
                                         TextHelper.Header("Task"), TextHelper.IconLabel("quest", "Move the map"));
            p.quests.Add(q);

            //move
            DataUnit light = L.b.units["light"];

            q      = new Quest("moveLight", $"Move the {light.Name()}", "move");
            q.desc = TextHelper.RichText(
                $"You see your first unit: the element {light.Name()}. Click on it. Then you see on the bottom left the actions, click on the walk icon and move 2 fields down or press two times arrow down. ",
                "After that you consume all your action points (AP) for this turn. Finish your round. Press the hourglass icon in the bottom middle or press space. ",
                TextHelper.Header("Tasks"), TextHelper.IconLabel(light.Icon, $"Select your {light.Name()}."), TextHelper.IconLabel("move", "Move the light 2 field down (Arrow down) or with move action."), round);
            q.AddReq("fogField", "1;16;7");
            p.quests.Add(q);

            //found town
            q      = new Quest("found", "Found your first town", "foundTown");
            q.desc = TextHelper.RichText(
                "Your Kingdom is based on different towns. Every town has his own building and resources.", "This is a perfect spot for a new town. Click on the icon and found it. Finish then your round.", "The goal of this scenario will be to build the temple in your city.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel("foundTown", "Found your town."), round);
            q.AddReq("townCount", ">1");
            q.AddReq("questFinish", "moveLight");
            q.main = true;
            p.quests.Add(q);

            //first unit
            DataBuilding lhall   = L.b.buildings["lhall1"];
            DataUnit     lworker = L.b.units["lworker"];

            q      = new Quest(lworker.id, "Train your first unit", lworker.Icon);
            q.desc = TextHelper.RichText(
                "At the same time the town hall was built, which manages all resources of your settlement.", $"The life task of the element {light.Name()} has been fulfilled and it will die in 5 rounds.",
                "To build your empire you need units to perform the basic actions. The main task of workers is to construct buildings and collect resources.",
                $"Move the {light.Name()} away from the town hall and train a {lworker.Name()}.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel(light.Icon, $"Move the {light.Name()} away"), TextHelper.IconLabel("train", $"Call in the {lhall.Name()} lower right the train action"), TextHelper.IconLabel(lworker.Icon, $"Train a {lworker.Name()}"));
            q.AddReq("unit", $">1:{lworker.id}");
            q.AddReq("questFinish", "found");
            q.main = true;
            p.quests.Add(q);

            //build food
            var samp = L.b.buildings["samplingpoint"];

            q      = QuestHelper.Build(samp);
            q.desc = TextHelper.RichText($"You can only grow with enough resources. The basics are water, food (meat, fish) and construction material (wood, cobble stones). Move your {light.Name()} or your {lworker.Name()} near the water, finish the round and then click the build action and build the {samp.Name()}. It will produce water and a litte fish (food).",
                                         TextHelper.Header("Tasks"), TextHelper.IconLabel(water.Icon, $"Move near the {water.Name()}"), q.desc);
            q.AddReq("questFinish", lworker.id);
            p.quests.Add(q);

            //build wood
            q      = QuestHelper.Build(L.b.buildings["logger"]);
            q.desc = TextHelper.RichText("Great, you start produce food, now you need construction material, e.g. wood. Move your unit in the forest and build the logger.",
                                         TextHelper.Header("Tasks"), TextHelper.IconLabel(forest.Icon, $"Move to the {forest.Name()}"), q.desc);
            q.AddReq("questFinish", samp.id);
            p.quests.Add(q);

            //build stone
            var cob = L.b.buildings["cobblestoneC"];

            q      = QuestHelper.Build(cob);
            q.desc = TextHelper.RichText($"After that you need some cobblestone for some buildings. Move your unit on the hill and build the ${cob.Name()}.",
                                         TextHelper.Header("Tasks"), TextHelper.IconLabel(hill.Icon, $"Move in the {hill.Name()}"), q.desc);
            q.AddReq("questFinish", "logger");
            p.quests.Add(q);

            var tent = L.b.buildings["tent"];

            q      = QuestHelper.Build(tent);
            q.desc = TextHelper.RichText($"We also need some place for the inhabitants of this town. Move your unit on a free field and build the ${tent.Name()}.",
                                         TextHelper.Header("Tasks"), q.desc);
            q.AddReq("questFinish", "cobblestoneC");
            p.quests.Add(q);

            //build research
            DataBuilding library = L.b.buildings["library"];

            q      = QuestHelper.Build(library);
            q.desc = TextHelper.RichText($"So the basics are set. To build a temple, we need to evolve the town.", $"But we need to research it before in the {library.Name()}. Move near your village hall and build the {library.Name()}.",
                                         "You have now 2 construction material: wood and cobblestone. You can choose which one to use or a mix of them. If you build with wood, the building is finished faster, but has less HP. Stone is very robust, but takes a long time to build.",
                                         TextHelper.Header("Tasks"), q.desc);
            q.AddReq("questFinish", "tent");
            p.quests.Add(q);

            //research something
            DataBuilding lhall2 = L.b.buildings["lhall2"];

            q      = new Quest("lhall2", "Research the " + lhall2.Name(), "research");
            q.desc = TextHelper.RichText(
                "In 9 nations, research is carried out in elements in which we want to develop further. The bigger village hall is in the area of 2x the light element. Then upgrade the village hall and win the game.",
                TextHelper.Header("Tasks"), TextHelper.IconLabel(library.Icon, $"Wait until the {library.Name()} is finish build"), TextHelper.IconLabel("research", "Open research menu"), TextHelper.IconLabel(L.b.elements["light"].Icon, "Select 2x light as area"),
                TextHelper.IconLabel("research", "Finish the research"), TextHelper.IconLabel(lhall2.Icon, "Upgrade the townhall to " + lhall2.Name()));
            q.AddReq("questFinish", "library");
            q.AddReq("building", ">1:" + lhall2.id);
            q.main = true;
            p.quests.Add(q);
        }
コード例 #19
0
ファイル: FrontierOverlay.cs プロジェクト: TrutzX/9Nations
 public override void Run(Player player, TileMapConfig16 tile)
 {
     _frontier = L.b.terrains["frontier"];
     base.Run(player, tile);
 }
コード例 #20
0
    //exec in a thread
    public void exec()
    {
        //end control
        if (unitIndex >= myUnits.Count)
        {
            GD.Print("BASIC IA: NO MORE UNITS. END TURN");
            EmitSignal("endTurn", actualPlayer);
            return;
        }

        //GO
        Unit        myUnit = myUnits[unitIndex];
        DataTerrain dt     = worldMap.dataTerrain;

        //get enemies
        List <Unit> othersUnits = new List <Unit>();

        for (int i = 0; i < dt.sizeMap; i++)
        {
            for (int j = 0; j < dt.sizeMap; j++)
            {
                Unit u = dt.units[j, i];
                if (u != null)
                {
                    if (u.owerPlayer != actualPlayer)
                    {
                        othersUnits.Add(u);
                    }
                }
            }
        }

        GD.Print("UNIT. ENEMIES: " + othersUnits.Count);

        //no Enemies
        if (othersUnits.Count < 1)
        {
            GD.Print("BASIC IA: NO ENEMIES. END TURN");
            EmitSignal("endTurn", actualPlayer);
            return;
        }

        //update unit subNavigation system
        worldMap.updateUnit(myUnit.wpX, myUnit.wpY);

        //1)get closed enemy, if can atack-> atack, else move close position.
        Unit  closedU = getCloseUnit(myUnit.wpX, myUnit.wpY, othersUnits);
        float dist2   = getDist2(closedU.wpX, closedU.wpY, myUnit.wpX, myUnit.wpY);

        if (closedU == null)
        {
            exec();//unit not valid. try again
            return;
        }

        //2) atack or approach
        GD.Print("UNIT. closed enemy at: " + closedU.wpX + " " + closedU.wpY + " dist2: " + dist2);

        if (myUnit.isValidAttack(myUnit.wpX, myUnit.wpY, closedU.wpX, closedU.wpY))
        {
            GD.Print("UNIT: atacking closed unit!");
            worldMap.execOrder(myUnit.wpX, myUnit.wpY, closedU.wpX, closedU.wpY, 1); //move order
            return;                                                                  //wait animation
        }
        else
        {
            //expensive call
            Vector2 closed = myUnit.atackMove(closedU.wpX, closedU.wpY);

            if (closed != new Vector2(-100, -100))
            {
                if (myUnit.isValidMove((int)closed.x, (int)closed.y))
                {
                    GD.Print("UNIT: moving to closed unit to atack!");
                    worldMap.execOrder(myUnit.wpX, myUnit.wpY, (int)closed.x, (int)closed.y, 0); //move order
                    return;                                                                      //wait animation
                }
            }
        }

        GD.Print("UNIT.END, next unit.");
        unitIndex++;
        exec();
    }
コード例 #21
0
        protected override int ValueMax(Player player, MapElementInfo onMap, string element, string sett, NVector pos)
        {
            DataTerrain dataTerrain = S.Map().Terrain(pos);

            return(dataTerrain.ResChance(element));
        }