Beispiel #1
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 );
            }
        }
        // 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 );
            }
        }
        // do we need this???  handled by specific controllers???
        //IntArrayList commanders = new IntArrayList();
        //IntArrayList constructors = new IntArrayList();
        //IntArrayList metalcollectors = new IntArrayList();
        //IntArrayList energycollectors = new IntArrayList();
        //IntArrayList groundattack = new IntArrayList();
        
        UnitController()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            unitdefhelp = new UnitDefHelp( aicallback );
            
            csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler( this.NewUnitFinished );
            csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( this.UnitDestroyed );   

            csai.RegisterVoiceCommand( "killallfriendly", new CSAI.VoiceCommandHandler( this.VoiceCommandKillAllFriendly ) );
            csai.RegisterVoiceCommand( "countunits", new CSAI.VoiceCommandHandler( this.VoiceCommandCountUnits ) );
            
            logfile.WriteLine ("*UnitController initialized*");
        }
       // int terrainwidth;
       // int terrainheight;
        
        public ScoutControllerRaider()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            
            random = new Random();

            unitcontroller = UnitController.GetInstance();
           // buildtable = BuildTable.GetInstance();
            enemycontroller = EnemyController.GetInstance();
            
            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );
            
            logfile.WriteLine( "*ScoutControllerRaider initialized*" );
        }
        public ScoutControllerRandomSearch( IPlayStyle playstyle )
        {
            random = new Random();

            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );

            logfile.WriteLine( "*ScoutController initialized*" );
        }
Beispiel #6
0
        public ConstructorController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            ShowNextBuildSite = csai.DebugOn;

            unitcontroller = UnitController.GetInstance();
            // factorycontroller = FactoryController.GetInstance();
            buildtable = BuildTable.GetInstance();
            metal = Metal.GetInstance();

            ShowNextBuildSite = csai.DebugOn;
            logfile.WriteLine("ConstructorController::ConstructorController() finished" );
        }
 public void LoadExistingUnits()
 {
     int[] friendlyunits = aicallback.GetFriendlyUnits();
     foreach (int friendlyunit in friendlyunits)
     {
         IUnitDef unitdef = aicallback.GetUnitDef(friendlyunit);
         logfile.WriteLine("friendly unit existing: " + friendlyunit + " " + unitdef.name + " " + unitdef.humanName);
         AddUnit(friendlyunit);
         if (ExistingUnitEvent != null)
         {
             ExistingUnitEvent(friendlyunit, unitdef);
         }
     }
     if (AllUnitsLoaded != null)
     {
         AllUnitsLoaded();
     }
 }
Beispiel #8
0
        // int terrainwidth;
        // int terrainheight;

        public ScoutControllerRaider(IPlayStyle playstyle)
        {
            this.playstyle = playstyle;

            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            random = new Random();

            //terrainwidth = aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE;
            // terrainheight = aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE;

            //int[,] sectorlastcheckedtickcount = new int[ terrainwidth, terrainheight ];
            // bool[,] sectorispriority = new bool[ terrainwidth, terrainheight ];;

            unitcontroller  = UnitController.GetInstance();
            buildtable      = BuildTable.GetInstance();
            enemycontroller = EnemyController.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid(ScoutUnitDefsById);

            logfile.WriteLine("*ScoutControllerRaider initialized*");
        }
Beispiel #9
0
        void DoIncrementalRefreshes()
        {
            logfile.WriteLine("LosMap start incrementalrefreshes");
            int numupdates = 0;
            int thresholddistancesquared = distancethresholdforunitupdate * distancethresholdforunitupdate;

            foreach (object mobileidobject in friendlyunitpositionobserver.MobileUnitIds)
            {
                int    id              = (int)mobileidobject;
                Float3 currentpos      = friendlyunitpositionobserver.PosById[id] as Float3;
                Float3 lastpos         = PosAtLastRefreshByUnitId[id] as Float3;
                double distancesquared = Float3Helper.GetSquaredDistance(lastpos, currentpos);
                if (distancesquared > thresholddistancesquared)
                {
                    UpdateLosForUnit(id, unitcontroller.UnitDefByDeployedId[id] as IUnitDef);
                    numupdates++;
                }
            }
            logfile.WriteLine("LosMap end incrementalrefreshes, " + numupdates + " units refreshed");
        }
        public TankController( Dictionary< int,IUnitDef>UnitDefsById, IUnitDef typicalunitdef)
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            this.DefsById = UnitDefsById;
            this.typicalunitdef = typicalunitdef;
            
            unitcontroller = UnitController.GetInstance();
            enemycontroller = EnemyController.GetInstance();
            buildtable = BuildTable.GetInstance();

            enemyselector = new EnemySelector2( typicalunitdef.speed * 2, typicalunitdef );
            // speed here is experimental

            attackpackcoordinator = new AttackPackCoordinator(DefsById);
            spreadsearchpackcoordinator = new SpreadSearchPackCoordinator(DefsById);
            movetopackcoordinator = new MoveToPackCoordinator(DefsById);
            guardpackcoordinator = new GuardPackCoordinator(DefsById);
            
            packcoordinatorselector = new PackCoordinatorSelector();
            packcoordinatorselector.LoadCoordinator( attackpackcoordinator );
            packcoordinatorselector.LoadCoordinator( spreadsearchpackcoordinator );
            packcoordinatorselector.LoadCoordinator( movetopackcoordinator );
            packcoordinatorselector.LoadCoordinator( guardpackcoordinator );

            logfile.WriteLine( "*TankController Initialized*" );
        }
Beispiel #11
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());
            }
        }
Beispiel #12
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: " + TankDefsById.Count, 0);
            logfile.WriteLine("Number tanks: " + TankDefsById.Count);
        }
Beispiel #13
0
        // int terrainwidth;
        // int terrainheight;
        public ScoutControllerRaider( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            random = new Random();

            //terrainwidth = aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE;
               // terrainheight = aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE;

            //int[,] sectorlastcheckedtickcount = new int[ terrainwidth, terrainheight ];
               // bool[,] sectorispriority = new bool[ terrainwidth, terrainheight ];;

            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();
            enemycontroller = EnemyController.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );

            logfile.WriteLine( "*ScoutControllerRaider initialized*" );
        }
Beispiel #14
0
 public void Shutdown()
 {
     logfile.WriteLine("Shutting down.");
     logfile.Shutdown();
 }
Beispiel #15
0
        void GenerateBuildTable(string modname)
        {
            logfile.WriteLine("Generating indexes mod " + modname);

            foreach (IUnitDef unitdef in availableunittypes)
            {
                if (unitdef != null)
                {
                    string    logline  = unitdef.id + " " + unitdef.name + " " + unitdef.humanName + " size: " + unitdef.xsize + "," + unitdef.ysize;
                    IMoveData movedata = unitdef.movedata;
                    if (movedata != null)
                    {
                        logline += " maxSlope: " + movedata.maxSlope + " depth " + movedata.depth + " slopeMod " + movedata.slopeMod +
                                   " depthMod: " + movedata.depthMod + " movefamily: " + movedata.moveFamily;
                    }
                    logfile.WriteLine(logline);

                    if (unitdef.extractsMetal > 0)
                    {
                        MetalExtractors.Add(unitdef);
                    }
                    if (unitdef.energyMake > 0 || unitdef.windGenerator > 0 || unitdef.tidalGenerator > 0)
                    {
                        EnergyProducers.Add(unitdef);
                    }
                    if (unitdef.builder && unitdef.speed >= 1)
                    {
                        Constructors.Add(unitdef);
                    }
                    if (unitdef.builder && unitdef.speed < 1)
                    {
                        Factories.Add(unitdef);
                    }
                    if (unitdef.canAttack && unitdef.canmove && unitdef.minWaterDepth < 0)
                    {
                        GroundAttack.Add(unitdef);
                    }
                    if (unitdef.canAttack && unitdef.canmove && unitdef.canfly)
                    {
                        AirAttack.Add(unitdef);
                    }
                    if (!UnitDefByName.ContainsKey(unitdef.name.ToLower()))
                    {
                        UnitDefByName.Add(unitdef.name.ToLower(), unitdef);
                    }
                    else
                    {
                        logfile.WriteLine("Warning: duplicate name: " + unitdef.name.ToLower());
                    }
                }
            }
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("Metal Extractors");
            logfile.WriteLine(MetalExtractors.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("EnergyProducers");
            logfile.WriteLine(EnergyProducers.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("Constructors");
            logfile.WriteLine(Constructors.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("GroundAttack");
            logfile.WriteLine(GroundAttack.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("Factories");
            logfile.WriteLine(Factories.ToString());

            IUnitDef constuctionvehicle = UnitDefByName[BuildTable.ArmConstructionVehicle] as IUnitDef;
            //int
            //BuildOption[] buildoptions = constuctionvehicle.GetNumBuildOptions;
            //string buildoptionsstring = "Constructionvehicle build options: ";
            //foreach( BuildOption buildoption in buildoptions )
            //{
            //buildoptionsstring += "( " + buildoption.TablePosition.ToString() + ", " + buildoption.UnitTypeName + " ) ";
            //}
            //logfile.WriteLine( buildoptionsstring );
        }
Beispiel #16
0
 public void VoiceCommandCountEnemies(string voicestring, string[] splitchatstring, int player)
 {
     aicallback.SendTextMsg("Number enemies: " + EnemyUnitDefByDeployedId.Count, 0);
     aicallback.SendTextMsg("Static enemies: " + EnemyStaticPosByDeployedId.Count, 0);
     logfile.WriteLine("Number enemies: " + EnemyUnitDefByDeployedId.Count);
 }
        LosMap()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitcontroller = UnitController.GetInstance();
            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitAdded );
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );

            friendlyunitpositionobserver = FriendlyUnitPositionObserver.GetInstance();

            csai.TickEvent += new CSAI.TickHandler( Tick );

            mapwidth = aicallback.GetMapWidth();
            mapheight = aicallback.GetMapHeight();

            logfile.WriteLine( "LosMap, create losarray" );
            LastSeenFrameCount = new int[ mapwidth / 2, mapheight / 2 ];
            logfile.WriteLine( "losarray created, initializing..." );
            for( int y = 0; y < mapheight / 2; y++ )
            {
                for( int x = 0; x < mapwidth / 2; x++ )
                {
                    LastSeenFrameCount[ x, y ] = -1000000;
                }
            }
            logfile.WriteLine( "losarray initialized" );

            if (csai.DebugOn)
            {
                csai.RegisterVoiceCommand("dumplosmap", new CSAI.VoiceCommandHandler(DumpLosMap));
            }
        }
Beispiel #18
0
        // int commander = 0;

        public void DebugSay(string message)
        {
            if (DebugOn)
            {
                aicallback.SendTextMsg(message, 0);
                logfile.WriteLine(message);
            }
        }
        public TankController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitdefhelp = new UnitDefHelp( aicallback );
            unitcontroller = UnitController.GetInstance();
            enemycontroller = EnemyController.GetInstance();
            buildtable = BuildTable.GetInstance();

            enemyselector = new EnemySelector( 110, false, false );

            attackpackcoordinator = new AttackPackCoordinator( TankDefsById );
            spreadsearchpackcoordinator = new SpreadSearchPackCoordinator( TankDefsById );
            movetopackcoordinator = new MoveToPackCoordinator( TankDefsById );
            guardpackcoordinator = new GuardPackCoordinator( TankDefsById );

            packcoordinatorselector = new PackCoordinatorSelector();
            packcoordinatorselector.LoadCoordinator( attackpackcoordinator );
            packcoordinatorselector.LoadCoordinator( spreadsearchpackcoordinator );
            packcoordinatorselector.LoadCoordinator( movetopackcoordinator );
            packcoordinatorselector.LoadCoordinator( guardpackcoordinator );

            logfile.WriteLine( "*TankController Initialized*" );
        }
Beispiel #20
0
 void ReserveMetalExtractorSpaces()
 {
     foreach (object metalspotobject in MetalSpots)
     {
         MetalSpot metalspot = metalspotobject as MetalSpot;
         logfile.WriteLine("reserving space for " + metalspot.Pos.ToString());
         BuildMap.GetInstance().ReserveSpace(this, (int)(metalspot.Pos.x / 8), (int)(metalspot.Pos.z / 8), 6, 6);
     }
 }
Beispiel #21
0
 public void UnitFinished(int id, IUnitDef def)
 {
     logfile.WriteLine("RadarController UnitAdded: " + def.humanName + " id: " + id);
     Radars.Add(id, new Radar(aicallback.GetUnitPos(id), def.radarRadius, def));
 }
Beispiel #22
0
        public static Float3 GetNearestReclaim(Float3 mypos, int constructorid)
        {
            if (CSAI.GetInstance().aicallback.GetCurrentFrame() == 0) // check ticks first, beacuse metal shows as zero at start
            {
                return(null);
            }
            LogFile     logfile    = LogFile.GetInstance();
            IAICallback aicallback = CSAI.GetInstance().aicallback;
            IUnitDef    unitdef    = UnitController.GetInstance().UnitDefByDeployedId[constructorid];

            if (!new UnitDefHelp(aicallback).IsMobile(unitdef))
            {
                return(null);
            }
            //Float3 mypos = aicallback.GetUnitPos( constructorid );
            MovementMaps movementmaps = MovementMaps.GetInstance();
            int          currentarea  = movementmaps.GetArea(unitdef, mypos);
            //double nearestreclaimdistancesquared = 1000000;
            //Float3 nearestreclaimpos = null;
            double bestmetaldistanceratio = 0;
            int    bestreclaimid          = 0;
            int    metalspace             = (int)(aicallback.GetMetalStorage() - aicallback.GetMetal());

            logfile.WriteLine("available space in metal storage: " + metalspace);
            int[] nearbyfeatures = aicallback.GetFeatures(mypos, maxreclaimradius);
            bool  reclaimfound   = false;

            foreach (int feature in nearbyfeatures)
            {
                IFeatureDef featuredef = aicallback.GetFeatureDef(feature);
                if (featuredef.metal > 0 && featuredef.metal <= metalspace)
                {
                    Float3 thisfeaturepos         = aicallback.GetFeaturePos(feature);
                    double thisdistance           = Math.Sqrt(Float3Helper.GetSquaredDistance(thisfeaturepos, mypos));
                    double thismetaldistanceratio = featuredef.metal / thisdistance;
                    if (thismetaldistanceratio > bestmetaldistanceratio && movementmaps.GetArea(unitdef, thisfeaturepos) == currentarea)
                    {
                        logfile.WriteLine("Potential reclaim, distance = " + thisdistance + " metal = " + featuredef.metal + " ratio = " + thismetaldistanceratio);
                        bestmetaldistanceratio = thismetaldistanceratio;
                        bestreclaimid          = feature;
                        //         nearestreclaimpo
                        reclaimfound = true;
                    }
                }
            }
            if (reclaimfound && (bestmetaldistanceratio > (1.0 / (100 * reclaimradiusperonehundredmetal))))
            {
                Float3 reclaimpos = aicallback.GetFeaturePos(bestreclaimid);
                logfile.WriteLine("Reclaim found, pos " + reclaimpos.ToString());
                if (CSAI.GetInstance().DebugOn)
                {
                    aicallback.DrawUnit("ARMMEX", reclaimpos, 0.0f, 200, aicallback.GetMyAllyTeam(), true, true);
                }
                return(reclaimpos);
                //aicallback.GiveOrder( constructorid, new Command( Command.CMD_RECLAIM,
                //    new double[]{ reclaimpos.x, reclaimpos.y, reclaimpos.z, 10 } ) );
            }
            else
            {
                //logfile.WriteLine( "No reclaim within parameters" );
                return(null);
            }
        }
Beispiel #23
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() );
           }
        }
Beispiel #24
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);
            }
        }
Beispiel #25
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 );
            }
        }
Beispiel #26
0
 public void RegisterRequester(IUnitRequester requester)
 {
     if (!Requesters.Contains(requester))
     {
         logfile.WriteLine("FactoryController: adding requester: " + requester.ToString());
         Requesters.Add(requester);
     }
 }
Beispiel #27
0
 public void DumpWorkFlow(string cmd, string[] split, int playe)
 {
     logfile.WriteLine("Workflow:");
     foreach (Order order in orders)
     {
         logfile.WriteLine(order.ToString());
     }
 }
Beispiel #28
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() );
               }
        }
Beispiel #29
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() );
               }
        }
Beispiel #30
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());
         SendTextMsg("Exception: " + e.ToString());
     }
 }