예제 #1
0
파일: BuildTable.cs 프로젝트: achoum/spring
        // protected constructor to force Singleton instantiation
        BuildTable()
        {
            CSAI = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile = LogFile.GetInstance();

            modname = aicallback.GetModName();

            int numunitdefs = aicallback.GetNumUnitDefs();
            logfile.WriteLine( "calling GetUnitDefList, for " + numunitdefs + " units ... " );
            //availableunittypes = aicallback.GetUnitDefList();
            availableunittypes = new IUnitDef[numunitdefs + 1];
            for (int i = 1; i <= numunitdefs; i++)
            {
                availableunittypes[i] = aicallback.GetUnitDefByTypeId(i);
                logfile.WriteLine( i + " " + availableunittypes[i].name + " " + availableunittypes[i].humanName );
            }
            logfile.WriteLine( "... done" );

            if( !LoadCache( modname ) )
            {
                aicallback.SendTextMsg( "Creating new cachefile for mod " + modname, 0 );
                GenerateBuildTable( modname );
                SaveCache( modname );
            }
        }
예제 #2
0
        // Ask what unit they need building
        public IUnitDef WhatUnitDoYouNeed(IFactory factory)
        {
            IUnitDef unitdef = null;

            if (factory.Name == "armvp")
            {
                unitdef = buildtable.UnitDefByName["armfav"] as IUnitDef;
            }
            else if (factory.Name == "armlab")
            {
                if (aicallback.GetModName().ToLower().IndexOf("xta") == 0)
                {
                    unitdef = buildtable.UnitDefByName["armpw"] as IUnitDef;
                }
                else
                {
                    unitdef = buildtable.UnitDefByName["armflea"] as IUnitDef;
                }
            }
            else if (factory.Name == "armap")
            {
                unitdef = buildtable.UnitDefByName["armpeep"] as IUnitDef;
            }
            logfile.WriteLine("ScoutController: requesting " + unitdef.humanName);
            return(unitdef);
        }
예제 #3
0
        BuildTable() // protected constructor to force Singleton instantiation
        {
            CSAI       = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile    = LogFile.GetInstance();

            modname = aicallback.GetModName();

            logfile.WriteLine("calling GetUnitDefList... ");
            List <IUnitDef> unittypeslist = new List <IUnitDef>();
            int             numunittypes  = aicallback.GetNumUnitDefs();

            for (int i = 1; i <= numunittypes; i++)
            {
                unittypeslist.Add(aicallback.GetUnitDefByTypeId(i));
            }
            availableunittypes = unittypeslist.ToArray();
            logfile.WriteLine("... done");

            if (!LoadCache(modname))
            {
                aicallback.SendTextMsg("Creating new cachefile for mod " + modname, 0);
                GenerateBuildTable(modname);
                SaveCache(modname);
            }
        }
예제 #4
0
        BuildTable() // protected constructor to force Singleton instantiation
        {
            CSAI       = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile    = LogFile.GetInstance();

            modname = aicallback.GetModName();

            int numunitdefs = aicallback.GetNumUnitDefs();

            logfile.WriteLine("calling GetUnitDefList, for " + numunitdefs + " units ... ");
            //availableunittypes = aicallback.GetUnitDefList();
            availableunittypes = new IUnitDef[numunitdefs + 1];
            for (int i = 1; i <= numunitdefs; i++)
            {
                availableunittypes[i] = aicallback.GetUnitDefByTypeId(i);
                logfile.WriteLine(i + " " + availableunittypes[i].name + " " + availableunittypes[i].humanName);
            }
            logfile.WriteLine("... done");

            if (!LoadCache(modname))
            {
                aicallback.SendTextMsg("Creating new cachefile for mod " + modname, 0);
                GenerateBuildTable(modname);
                SaveCache(modname);
            }
        }
예제 #5
0
파일: BuildTable.cs 프로젝트: achoum/spring
        // protected constructor to force Singleton instantiation
        BuildTable()
        {
            CSAI = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile = LogFile.GetInstance();

            modname = aicallback.GetModName();

            logfile.WriteLine( "calling GetUnitDefList... " );
            List<IUnitDef> unittypeslist = new List<IUnitDef>();
            int numunittypes = aicallback.GetNumUnitDefs();
            for (int i = 1; i <= numunittypes; i++)
            {
                unittypeslist.Add( aicallback.GetUnitDefByTypeId( i ) );
            }
            availableunittypes = unittypeslist.ToArray();
            logfile.WriteLine( "... done" );

            if( !LoadCache( modname ) )
            {
                aicallback.SendTextMsg( "Creating new cachefile for mod " + modname, 0 );
                GenerateBuildTable( modname );
                SaveCache( modname );
            }
        }
예제 #6
0
        BuildTable() // protected constructor to force Singleton instantiation
        {
            CSAI       = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile    = LogFile.GetInstance();

            modname = aicallback.GetModName();

            logfile.WriteLine("calling GetUnitDefList... ");
            availableunittypes = aicallback.GetUnitDefList();
            logfile.WriteLine("... done");

            if (!LoadCache(modname))
            {
                aicallback.SendTextMsg("Creating new cachefile for mod " + modname, 0);
                GenerateBuildTable(modname);
                SaveCache(modname);
            }
        }
예제 #7
0
        // protected constructor to force Singleton instantiation
        BuildTable()
        {
            CSAI = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile = LogFile.GetInstance();

            modname = aicallback.GetModName();

            logfile.WriteLine( "calling GetUnitDefList... " );
            availableunittypes = aicallback.GetUnitDefList();
            logfile.WriteLine( "... done" );

            if( !LoadCache( modname ) )
            {
                aicallback.SendTextMsg( "Creating new cachefile for mod " + modname, 0 );
                GenerateBuildTable( modname );
                SaveCache( modname );
            }
        }
예제 #8
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() );

                csaiuserinteraction = CSAIUserInteraction.GetInstance();

                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();
                FriendlyUnitPositionObserver.GetInstance();

                EnergyController.GetInstance();

                MovementMaps.GetInstance();
                BuildMap.GetInstance();
                LosMap.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 )
                {
                    SendTextMsg( "C# AI initialized v" + AIVersion + ", team " + team );
                    SendTextMsg( "Please say '.csai help' for available commands" );

                    PlayStyleManager.GetInstance().ListPlayStyles();

                    //CommanderController.GetInstance().CommanderBuildPower();
                }
                else
                {
                    SendTextMsg( "Warning: CSAI needs AA2.23  or XTA7 to run correctly at this time" );
                    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() );
               SendTextMsg( "Exception: " + e.ToString() );
               }
        }
예제 #9
0
        public void InitAI( IAICallback aicallback, int team)
        {

            this.aicallback = aicallback;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            
            try{
                Directory.CreateDirectory(AIDirectoryPath);
                this.Team = team;
                logfile = LogFile.GetInstance().Init( Path.Combine( AIDirectoryPath, "csharpai_team" + team + ".log" ) );
                logfile.WriteLine( "C# AI started v" + AIVersion+ ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName() );
                logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString());

                if( File.Exists( AIDirectoryPath + "/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();
                /*
                IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34);
                aicallback.SendTextMsg(unitdef.name,0);
                aicallback.SendTextMsg(unitdef.id.ToString(), 0);
                aicallback.SendTextMsg(unitdef.humanName, 0);
                aicallback.SendTextMsg(unitdef.movedata.moveType.ToString(), 0);
                aicallback.SendTextMsg(unitdef.movedata.maxSlope.ToString(), 0);
                aicallback.GetMetalMap();
                aicallback.GetLosMap();
                aicallback.GetRadarMap();
                aicallback.GetFriendlyUnits();
                aicallback.GetFeatures();
                aicallback.GetEnemyUnitsInRadarAndLos();

                Metal.GetInstance();
                */
                //aicallback.GetElevation(300,300);
                //new SlopeMap().GetSlopeMap();
                //double[,] _SlopeMap = new double[256, 256];
                //LosMap.GetInstance();
                //MovementMaps.GetInstance();
                //BuildMap.GetInstance().Init();

                //return;
                // -- test stuff here --
                logfile.WriteLine("Is game paused? : " + aicallback.IsGamePaused());
                // -- end test stuff --

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

                SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team);
           }
           catch( Exception e )
           {
               logfile.WriteLine( "Exception: " + e.ToString() );
               SendTextMsg( "Exception: " + e.ToString() );
           }
        }
예제 #10
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);
            }
        }
예제 #11
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( Path.Combine( AIDirectoryPath, "csharpai_team" + team + ".log" ) );
                logfile.WriteLine( "C# AI started v" + AIVersion+ ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName() );
                logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString());

                if( File.Exists( AIDirectoryPath + "/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();

                BuildEconomy buildeconomy = new BuildEconomy();

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

                SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team);
               }
               catch( Exception e )
               {
               logfile.WriteLine( "Exception: " + e.ToString() );
               SendTextMsg( "Exception: " + e.ToString() );
               }
        }
예제 #12
0
        public void InitAI(IAICallback aicallback, int team)
        {
            this.aicallback = aicallback;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

            try{
                Directory.CreateDirectory(AIDirectoryPath);
                this.Team = team;
                logfile   = LogFile.GetInstance().Init(Path.Combine(AIDirectoryPath, "csharpai_team" + team + ".log"));
                logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName());
                logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString());

                if (File.Exists(AIDirectoryPath + "/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();

                /*
                 * IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34);
                 * aicallback.SendTextMsg(unitdef.name,0);
                 * aicallback.SendTextMsg(unitdef.id.ToString(), 0);
                 * aicallback.SendTextMsg(unitdef.humanName, 0);
                 * aicallback.SendTextMsg(unitdef.movedata.moveType.ToString(), 0);
                 * aicallback.SendTextMsg(unitdef.movedata.maxSlope.ToString(), 0);
                 * aicallback.GetMetalMap();
                 * aicallback.GetLosMap();
                 * aicallback.GetRadarMap();
                 * aicallback.GetFriendlyUnits();
                 * aicallback.GetFeatures();
                 * aicallback.GetEnemyUnitsInRadarAndLos();
                 *
                 * Metal.GetInstance();
                 */
                //aicallback.GetElevation(300,300);
                //new SlopeMap().GetSlopeMap();
                //double[,] _SlopeMap = new double[256, 256];
                //LosMap.GetInstance();
                //MovementMaps.GetInstance();
                //BuildMap.GetInstance().Init();

                //return;
                // -- test stuff here --
                logfile.WriteLine("Is game paused? : " + aicallback.IsGamePaused());
                // -- end test stuff --

                BuildEconomy buildeconomy = new BuildEconomy();

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

                SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team);
            }
            catch (Exception e)
            {
                logfile.WriteLine("Exception: " + e.ToString());
                SendTextMsg("Exception: " + e.ToString());
            }
        }
예제 #13
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(Path.Combine(AIDirectoryPath, "csharpai_team" + team + ".log"));
                logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName());
                logfile.WriteLine("RL Date/time: " + DateTime.Now.ToString());

                if (File.Exists(AIDirectoryPath + "/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();

                BuildEconomy buildeconomy = new BuildEconomy();

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

                SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team);
            }
            catch (Exception e)
            {
                logfile.WriteLine("Exception: " + e.ToString());
                SendTextMsg("Exception: " + e.ToString());
            }
        }