예제 #1
0
        void DoSomething()
        {
            if (TankDefsById.Count >= MinTanksForAttack)  // make sure at least have a few units before attacking
            {
                Float3 approximateattackpos = LastAttackPos;
                if (approximateattackpos == null)
                {
                    approximateattackpos = CommanderController.GetInstance().GetCommanderPos();
                }

                Float3 nearestenemypos = enemyselector.ChooseAttackPoint(approximateattackpos);
                if (nearestenemypos != null)
                {
                    attackpackcoordinator.SetTarget(nearestenemypos);
                    packcoordinatorselector.ActivatePackCoordinator(attackpackcoordinator);
                    LastAttackPos = nearestenemypos;
                }
                else
                {
                    if (TankDefsById.Count > MinTanksForSpreadSearch)
                    {
                        spreadsearchpackcoordinator.SetTarget(nearestenemypos);
                        packcoordinatorselector.ActivatePackCoordinator(spreadsearchpackcoordinator);
                    }
                    else
                    {
                        guardpackcoordinator.SetTarget(CommanderController.GetInstance().commanderid);
                        packcoordinatorselector.ActivatePackCoordinator(guardpackcoordinator);
                        // movetopackcoordinator.SetTarget( CommanderController.GetInstance().GetCommanderPos() );
                        //packcoordinatorselector.ActivatePackCoordinator( movetopackcoordinator );
                    }
                }
            }
            else
            {
                guardpackcoordinator.SetTarget(CommanderController.GetInstance().commanderid);
                packcoordinatorselector.ActivatePackCoordinator(guardpackcoordinator);
                //movetopackcoordinator.SetTarget( CommanderController.GetInstance().GetCommanderPos() );
                //packcoordinatorselector.ActivatePackCoordinator( movetopackcoordinator );
            }
        }
예제 #2
0
        //int numOfUnits = 0;
        //IUnitDef[] unitList;
        //IUnitDef solarcollectordef;

        public void InitAI(IAICallback aicallback, int team)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

            this.aicallback = aicallback;
            try{
                this.Team = team;
                logfile   = LogFile.GetInstance().Init(team);
                logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName());

                if (File.Exists("AI/CSAI/debug.flg"))    // if this file exists, activate debug mode; saves manually changing this for releases
                {
                    logfile.WriteLine("Toggling debug on");
                    DebugOn = true;
                }

                if (DebugOn)
                {
                    new Testing.RunTests().Go();
                }

                InitCache();

                PlayStyleManager.GetInstance();
                LoadPlayStyles.Go();

                metal = Metal.GetInstance();
                CommanderController.GetInstance();
                BuildTable.GetInstance();
                UnitController.GetInstance();
                EnemyController.GetInstance();

                EnergyController.GetInstance();

                MovementMaps.GetInstance();
                BuildMap.GetInstance();

                //FactoryController.GetInstance();
                //RadarController.GetInstance();
                //TankController.GetInstance();
                //ScoutController.GetInstance();
                //ConstructorController.GetInstance();

                metal.Init();
                BuildPlanner.GetInstance();

                UnitController.GetInstance().LoadExistingUnits();  // need this if we're being reloaded in middle of a game, to get already existing units
                EnemyController.GetInstance().LoadExistingUnits();

                StrategyController.GetInstance();
                LoadStrategies.Go();

                PlayStyleManager.GetInstance().ChoosePlayStyle("tankrush");

                if (aicallback.GetModName().ToLower().IndexOf("aass") == 0 || aicallback.GetModName().ToLower().IndexOf("xtape") == 0)
                {
                    aicallback.SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team, 0);
                    aicallback.SendTextMsg("Please say '.csai help' for available commands", 0);

                    PlayStyleManager.GetInstance().ListPlayStyles();

                    //CommanderController.GetInstance().CommanderBuildPower();
                }
                else
                {
                    aicallback.SendTextMsg("Warning: CSAI needs AA2.23  or XTA7 to run correctly at this time", 0);
                    logfile.WriteLine("*********************************************************");
                    logfile.WriteLine("*********************************************************");
                    logfile.WriteLine("****                                                                                           ****");
                    logfile.WriteLine("**** Warning: CSAI needs AA2.23 or XTA7 to run correctly at this time ****");
                    logfile.WriteLine("****                                                                                           ****");
                    logfile.WriteLine("*********************************************************");
                    logfile.WriteLine("*********************************************************");
                }
            }
            catch (Exception e)
            {
                logfile.WriteLine("Exception: " + e.ToString());
                aicallback.SendTextMsg("Exception: " + e.ToString(), 0);
            }
        }