Exemplo n.º 1
0
 public void UnitAdded(int deployedunitid, IUnitDef unitdef)
 {
     if (unitdef.name.ToLower() == BuildTable.ArmConstructionVehicle ||
         unitdef.name.ToLower() == "armck" || unitdef.name.ToLower() == "armca" ||
         unitdef.isCommander)
     {
         if (!UnitDefByUnitId.Contains(deployedunitid))
         {
             UnitDefByUnitId.Add(deployedunitid, unitdef);
             logfile.WriteLine("Constructor controller; new constructor: " + unitdef.humanName);
             DoSomething(deployedunitid);
         }
     }
     if (unitdef.isCommander && unitdef.name.ToLower() != BuildTable.ArmCommander)
     {
         aicallback.SendTextMsg("Warning: please make sure the AI is running as ARM", 0);
         aicallback.SendTextMsg("CSAI will not function correctly if not running as ARM", 0);
         logfile.WriteLine("************************************************");
         logfile.WriteLine("************************************************");
         logfile.WriteLine("**** Warning: please make sure the AI is running as ARM ****");
         logfile.WriteLine("**** CSAI will not function correctly if not running as ARM ****");
         logfile.WriteLine("************************************************");
         logfile.WriteLine("************************************************");
     }
 }
Exemplo n.º 2
0
        public void DumpLos(string cmd, string[] cmdsplit, int player)
        {
            logfile.WriteLine("calling getlosmap...");
            bool[] LosMap = aicallback.GetLosMap();
            logfile.WriteLine("...done");
            int loswidth  = aicallback.GetMapWidth() / 2;
            int losheight = aicallback.GetMapHeight() / 2;

            logfile.WriteLine("losmap width: " + loswidth + " losheight: " + losheight);
            ArrayIndexer arrayindexer = new ArrayIndexer(loswidth, losheight);

            for (int y = 0; y < losheight; y++)
            {
                string line = "";
                for (int x = 0; x < loswidth; x++)
                {
                    if (LosMap[arrayindexer.GetIndex(x, y)])
                    {
                        line += "*";
                        //  aicallback.DrawUnit( "ARMCOM", new Float3( x * 16, 0, y * 16 ), 0.0f, 100, aicallback.GetMyAllyTeam(), true, true);
                    }
                    else
                    {
                        line += "-";
                    }
                }
                logfile.WriteLine(line);
            }
            aicallback.SendTextMsg("los dumped to logfile", 0);
        }
Exemplo n.º 3
0
        // int commander = 0;

        public void DebugSay(string message)
        {
            if (DebugOn)
            {
                aicallback.SendTextMsg(message, 0);
                logfile.WriteLine(message);
            }
        }
        public void ListPlayStyles()
        {
            string reply = "Play styles available: ";

            foreach (object playstyleobject in playstyles)
            {
                IPlayStyle playstyle = playstyleobject as IPlayStyle;
                reply += playstyle.GetName() + ", ";
            }
            aicallback.SendTextMsg(reply, 0);
            aicallback.SendTextMsg(".csai chooseplaystyle <name> to choose", 0);
        }
Exemplo n.º 5
0
 public void Init()
 {
     if (!LoadCache())
     {
         aicallback.SendTextMsg("Metal analyzer rebuilding cachefile", 0);
         SearchMetalSpots();
     }
     if (!isMetalMap)
     {
         ReserveMetalExtractorSpaces();
     }
 }
Exemplo n.º 6
0
 public void InitAI( IAICallback aicallback, int team )
 {
     this.aicallback = aicallback;
     this.team = team;
     aicallback.SendTextMsg( "Hello from Mono AbicWrappers", 0 );
     aicallback.SendTextMsg( "The map name is: " + aicallback.GetMapName(), 0 );
     aicallback.SendTextMsg( "Our ally team is: " + aicallback.GetMyTeam(), 0 );
     
     //int features[10000 + 1];
     //int numfeatures = IAICallback_GetFeatures( aicallback, features, 10000 );
     //sprintf( buffer, "Num features is: %i", numfeatures );
     //IAICallback_SendTextMsg( aicallback, buffer, 0 );
     
     //const FeatureDef *featuredef = IAICallback_GetFeatureDef( aicallback, features[0] );
     //sprintf( buffer, "First feature: %s", FeatureDef_get_myName( featuredef ) );
     //IAICallback_SendTextMsg( aicallback, buffer, 0 );    
     
     IUnitDef unitdef = aicallback.GetUnitDefByTypeId( 34 );
     aicallback.SendTextMsg( "gotunitdef", 0 );
     aicallback.SendTextMsg( "type id 34 is " + unitdef.name, 0 );
     aicallback.SendTextMsg( "human name: " + unitdef.humanName, 0 );
     aicallback.SendTextMsg( "id: " + unitdef.id, 0 );
     
     IMoveData movedata = unitdef.movedata;
     //IAICallback_SendTextMsg( aicallback, "movedata is null? " + ( movedata == 0 );
     //IAICallback_SendTextMsg( aicallback, buffer, 0 );    
     
     //IAICallback_SendTextMsg( aicallback, "movetype: %i" + MoveData_get_movetype( movedata ) );        
     //IAICallback_SendTextMsg( aicallback, buffer, 0 );    
     
     aicallback.SendTextMsg( "maxslope: " + movedata.maxSlope, 0 );
 }
Exemplo n.º 7
0
        public void InitAI(IAICallback aicallback, int team)
        {
            this.aicallback = aicallback;
            this.team       = team;
            aicallback.SendTextMsg("Hello from Mono AbicWrappers", 0);
            aicallback.SendTextMsg("The map name is: " + aicallback.GetMapName(), 0);
            aicallback.SendTextMsg("Our ally team is: " + aicallback.GetMyTeam(), 0);

            //int features[10000 + 1];
            //int numfeatures = IAICallback_GetFeatures( aicallback, features, 10000 );
            //sprintf( buffer, "Num features is: %i", numfeatures );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            //const FeatureDef *featuredef = IAICallback_GetFeatureDef( aicallback, features[0] );
            //sprintf( buffer, "First feature: %s", FeatureDef_get_myName( featuredef ) );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34);

            aicallback.SendTextMsg("gotunitdef", 0);
            aicallback.SendTextMsg("type id 34 is " + unitdef.name, 0);
            aicallback.SendTextMsg("human name: " + unitdef.humanName, 0);
            aicallback.SendTextMsg("id: " + unitdef.id, 0);

            IMoveData movedata = unitdef.movedata;

            //IAICallback_SendTextMsg( aicallback, "movedata is null? " + ( movedata == 0 );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            //IAICallback_SendTextMsg( aicallback, "movetype: %i" + MoveData_get_movetype( movedata ) );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            aicallback.SendTextMsg("maxslope: " + movedata.maxSlope, 0);
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        // 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 );
            }
        }
Exemplo n.º 11
0
 public void EnemyEnterRadar(int enemy)
 {
     try
     {
         if (EnemyEnterRadarEvent != null)
         {
             aicallback.SendTextMsg("enemy entered radar: " + enemy, 0);
             logfile.WriteLine("enemy entered radar: " + enemy);
             EnemyEnterRadarEvent(enemy);
         }
     }
     catch (Exception e)
     {
         logfile.WriteLine("Exception: " + e.ToString());
         SendTextMsg("Exception: " + e.ToString());
     }
 }
Exemplo n.º 12
0
        public void UnitCreated(int unit)
        {
            aicallback.SendTextMsg("Unit created: " + unit, 0);

            IUnitDef unitdef = aicallback.GetUnitDef(unit);

            aicallback.SendTextMsg("Unit created: " + unitdef.name, 0);

            IMoveData movedata = unitdef.movedata;

            if (movedata != null)
            {
                aicallback.SendTextMsg("Max Slope: " + movedata.maxSlope, 0);
            }

            if (unitdef.isCommander)
            {
                int    numbuildoptions    = unitdef.GetNumBuildOptions();
                string buildoptionsstring = "Build options: ";
                for (int i = 0; i < numbuildoptions; i++)
                {
                    buildoptionsstring += unitdef.GetBuildOption(i);
                }
                aicallback.SendTextMsg(buildoptionsstring, 0);

                Float3 commanderpos = aicallback.GetUnitPos(unit);
                aicallback.SendTextMsg("Commanderpos: " + commanderpos.ToString(), 0);

                int numunitdefs = aicallback.GetNumUnitDefs();
                aicallback.SendTextMsg("Num unit defs: " + numunitdefs, 0);

                for (int i = 1; i <= numunitdefs; i++)
                {
                    IUnitDef thisunitdef = aicallback.GetUnitDefByTypeId(i);
                    if (thisunitdef.name == "ARMSOLAR")
                    {
                        aicallback.SendTextMsg("Found solar collector def: " + thisunitdef.id, 0);

                        Float3 nearestbuildpos = aicallback.ClosestBuildSite(thisunitdef, commanderpos, 1400, 2);
                        aicallback.SendTextMsg("Closest build site: " + nearestbuildpos.ToString(), 0);

                        aicallback.DrawUnit("ARMSOLAR", nearestbuildpos, 0,
                                            200, aicallback.GetMyAllyTeam(), true, true);

                        aicallback.GiveOrder(unit, new Command(-thisunitdef.id, nearestbuildpos.ToDoubleArray()));
                    }
                }
            }
        }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
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 );
            }
        }
Exemplo n.º 15
0
        }                                                     // assign continuous metal flow to this controller; negative for reverse flow

        public void VoiceCommandCountTanks(string voicestring, string[] splitchatstring, int player)
        {
            aicallback.SendTextMsg("Number tanks: " + DefsById.Count, 0);
            logfile.WriteLine("Number tanks: " + DefsById.Count);
        }
Exemplo n.º 16
0
        }                                                     // assign continuous metal flow to this controller; negative for reverse flow

        public void VoiceCommandCountScouts(string cmdline, string[] splitstring, int player)
        {
            aicallback.SendTextMsg("scouts: " + ScoutUnitDefsById.Count, 0);
        }
Exemplo n.º 17
0
        // 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 );
            }
        }
Exemplo n.º 18
0
 public void VoiceCommandShowEnemies(string voicestring, string[] splitchatstring, int player)
 {
     aicallback.SendTextMsg("Number enemies: " + EnemyUnitDefByDeployedId.Count, 0);
     aicallback.SendTextMsg("Static enemies: " + EnemyStaticPosByDeployedId.Count, 0);
     ShowEnemies();
 }
Exemplo n.º 19
0
 public void UnitCreated(int deployedunitid)                                                                     //called when a new unit is created on ai team
 {
     try
     {
         IUnitDef unitdef = aicallback.GetUnitDef(deployedunitid);
         if (UnitCreatedEvent != null)
         {
             UnitCreatedEvent(deployedunitid, unitdef);
         }
     }
     catch (Exception e)
     {
         logfile.WriteLine("Exception: " + e.ToString());
         aicallback.SendTextMsg("Exception: " + e.ToString(), 0);
     }
 }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
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 );
               }
        }
Exemplo n.º 22
0
 public void VoiceCommandCountUnits(string cmd, string[] splitcmd, int player)
 {
     aicallback.SendTextMsg("friendly unit count: " + UnitDefByDeployedId.Count, 0);
 }
 public void  VoiceCommandCommanderIsActive(string chatstring, string[] splitchatstring, int player)
 {
     aicallback.SendTextMsg("Commander UnitIsBusy: " + aicallback.UnitIsBusy(commanderid).ToString(), 0);
 }