Exemplo n.º 1
0
        internal void ClearSigns()
        {
            foreach (var(signId, _) in this.signs)
            {
                AISign.RemoveSign(signId);
            }

            this.signs.Clear();
            this.signDictionary.Clear();
        }
Exemplo n.º 2
0
        internal void BuildSign(TileIndex tile, string text)
        {
            if (signDictionary.ContainsKey(tile))
            {
                AISign.RemoveSign(signDictionary[tile]);
            }

            if (!string.IsNullOrEmpty(text))
            {
                var signId = AISign.BuildSign(tile, "" + text);
                this.signs.AddItem(signId, 0);
                signDictionary[tile] = signId;
            }
        }
Exemplo n.º 3
0
        protected /*override*/ void Start2()
        {
            SignManager signManager = new SignManager();

            this.signs = new AISignList();
            var list = new AIRailTypeList();

            AIRail.SetCurrentRailType(list.Begin());

            AICompany.SetLoanAmount(AICompany.GetMaxLoanAmount());

            ////*
            //RailBuilder.BuildRail(
            //    AIMap.GetTileIndex(42, 121),
            //    AIMap.GetTileIndex(41, 121),
            //    AIMap.GetTileIndex(31, 121),
            //    AIMap.GetTileIndex(30, 121),
            //    new HashSet<TileIndex>(),
            //    1,
            //    this.BuildSign);
            ///*/

            //var i = 39;
            //var ns = RailBuilder.GetNeighbors(
            //    AIMap.GetTileIndex(i, 121),
            //    new RailBuilder.PathInfo(
            //        AIMap.GetTileIndex(i + 1, 121),
            //        1,
            //        1,
            //        RailBuilder.BuildType.Rail,
            //        new RailBuilder.PathInfo(
            //            AIMap.GetTileIndex(i + 2, 121),
            //            1,
            //            1,
            //            RailBuilder.BuildType.Rail,
            //            null)),
            //    this.BuildSign);

            //foreach (var n in ns)
            //{
            //    this.BuildSign(n.Tile, n.Cost.ToString());
            //}
            ///* */

            ///*
            try
            {
                if (this.workStatus == 0)
                {
                    var towns = new AITownList();
                    towns.Valuate(AITown.GetPopulation);
                    RailStationBuildResult s1 = null;
                    foreach (var(town, _) in towns)
                    {
                        if (s1 == null)
                        {
                            s1 = RailStationBuilder.BuildStationNear(AITown.GetLocation(town), this.platformSize, 2);
                        }
                        else
                        {
                            RailStationBuildResult s2        = RailStationBuilder.BuildStationNear(AITown.GetLocation(town), this.platformSize, 2);
                            HashSet <TileIndex>    forbidden = new HashSet <TileIndex>();
                            forbidden.Add(s1.ExitFarther);
                            forbidden.Add(s2.EntryFarther);
                            var good = RailBuilder.BuildRail(s1.EntryCloser, s1.EntryFarther, s2.ExitFarther, s2.ExitCloser, forbidden);
                            signManager.ClearSigns();
                            if (good)
                            {
                                forbidden = new HashSet <TileIndex>();
                                good      = RailBuilder.BuildRail(s1.ExitCloser, s1.ExitFarther, s2.EntryFarther, s2.EntryCloser, forbidden, 1);
                            }

                            if (good)
                            {
                                if (s1.DepotTile != AIMap.TILE_INVALID)
                                {
                                    TrainManager.BuildTrain(s1.DepotTile, new StationID[] { s1.StationID, s2.StationID }, this.BuildSign);
                                }
                                else
                                {
                                    TrainManager.BuildTrain(s2.DepotTile, new StationID[] { s2.StationID, s1.StationID }, this.BuildSign);
                                }
                            }
                            else
                            {
                                AILog.Info("No route found.");
                            }

                            s1 = null;

                            //if (AICompany.GetBankBalance(AICompany.COMPANY_SELF) < 50000)
                            {
                                // Better to stop before bankrupcy.
                                AILog.Info("Better to stop before bankrupcy.");
                                break;
                            }
                        }
                    }
                }

                this.workStatus = 1;
            }
            catch
            {
                AILog.Error("An error happened");
            }
            /* */

            signManager.ClearSigns();
            AILog.Info("Sign count: " + this.signs.Count());
            AIController.Sleep(150);

            AILog.Info("Remove all signs");
            foreach (var(signId, _) in this.signs)
            {
                AISign.RemoveSign(signId);
            }

            while (true)
            {
                // Main loop
                //this.setMinLoan();
                CsTestAi.SetMinimumLoanAmount();
                Sleep(100);
            }
        }