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*" );
        }
        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*" );
        }
        public EnemySelector( double maxenemyspeed, bool WaterOk, bool BadTerrainOk )
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

               // csai.EnemyEntersLOSEvent += new CSAI.EnemyEntersLOSHandler( EnemyEntersLOS );

            enemycontroller = EnemyController.GetInstance();
            unitdefhelp = new UnitDefHelp( aicallback );

            this.maxenemyspeed = maxenemyspeed;
            this.WaterOk = WaterOk;
            this.BadTerrainOk = BadTerrainOk;
        }
       // 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 EnemySelector2(double maxenemyspeed, IUnitDef typicalunitdef)
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            // csai.EnemyEntersLOSEvent += new CSAI.EnemyEntersLOSHandler( EnemyEntersLOS );

            enemycontroller = EnemyController.GetInstance();
            unitdefhelp = new UnitDefHelp(aicallback);

            this.maxenemyspeed = maxenemyspeed;
            this.WaterOk = WaterOk;
            this.BadTerrainOk = BadTerrainOk;

            this.typicalunitdef = typicalunitdef;
            //    startarea = MovementMaps.GetInstance().GetArea(typicalunitdef, startpos);
        }
示例#6
0
文件: EnemyMap.cs 项目: achoum/spring
        EnemyMap()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            enemymap = new int[ mapwidth / 2, mapheight / 2 ];

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

            //csai.UnitCreatedEvent += new CSAI.UnitCreatedHandler( UnitCreated );
            //csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( UnitDestroyed );

            enemycontroller.NewStaticEnemyAddedEvent += new EnemyController.NewStaticEnemyAddedHandler( StaticEnemyAdded );
            enemycontroller.EnemyRemovedEvent += new EnemyController.EnemyRemovedHandler( EnemyRemoved );

            Init();
        }
示例#7
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*" );
        }
示例#8
0
        void Reappraise()
        {
            //  logfile.WriteLine("reappraise>>>");
            foreach (KeyValuePair <int, IUnitDef> scoutkvp in ScoutUnitDefsById)
            {
                int    scoutdeployedid = scoutkvp.Key;
                Float3 scoutpos        = aicallback.GetUnitPos(scoutdeployedid);

                Float3 nearestpos          = null;
                double bestsquareddistance = 100000000;
                int    targetid            = 0;
                // need to add index by position for this, to speed things up
                foreach (KeyValuePair <int, IUnitDef> enemykvp in EnemyController.GetInstance().EnemyUnitDefByDeployedId)
                {
                    int      deployedid = enemykvp.Key;
                    IUnitDef unitdef    = enemykvp.Value;
                    if (unitdef != null)
                    {
                        if (IsPriorityTarget(unitdef))
                        {
                            logfile.WriteLine("considering unit " + deployedid + " " + unitdef.name);
                            Float3 thispos             = aicallback.GetUnitPos(deployedid);
                            double thissquareddistance = Float3Helper.GetSquaredDistance(scoutpos, thispos);
                            if (thissquareddistance < bestsquareddistance)
                            {
                                bool nolasertowersnear = true;
                                foreach (KeyValuePair <int, IUnitDef> attackerkvp in EnemyController.GetInstance().EnemyUnitDefByDeployedId)
                                {
                                    int      attackerid      = attackerkvp.Key;
                                    IUnitDef attackerunitdef = attackerkvp.Value;
                                    if (attackerunitdef != null)
                                    {
                                        if (IsLaserTower(attackerunitdef))
                                        {
                                            Float3 attackerpos = aicallback.GetUnitPos(attackerid);
                                            if (Float3Helper.GetSquaredDistance(attackerpos, thispos) < nearbyforenemiesmeans * nearbyforenemiesmeans)
                                            {
                                                nolasertowersnear = false;
                                            }
                                        }
                                    }
                                }
                                if (nolasertowersnear)
                                {
                                    nearestpos          = thispos;
                                    bestsquareddistance = thissquareddistance;
                                    targetid            = deployedid;
                                }
                            }
                        }
                    }
                }
                if (nearestpos != null)
                {
                    GiveOrderWrapper.GetInstance().Attack(scoutdeployedid, targetid);
                    if (!attackingscouts.Contains(scoutdeployedid))
                    {
                        attackingscouts.Add(scoutdeployedid);
                    }
                }
                else
                {
                    if (attackingscouts.Contains(scoutdeployedid))
                    {
                        ExploreWith(scoutdeployedid);
                        attackingscouts.Remove(scoutdeployedid);
                    }
                }
            }
            //     logfile.WriteLine("reappraise<<<");
        }
示例#9
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());
            }
        }
示例#10
0
        void Reappraise()
        {
            foreach (DictionaryEntry scoutde in ScoutUnitDefsById)
            {
                int    scoutdeployedid = (int)scoutde.Key;
                Float3 scoutpos        = aicallback.GetUnitPos(scoutdeployedid);

                Float3 nearestpos          = null;
                double bestsquareddistance = 100000000;
                int    targetid            = 0;
                // need to add index by position for this, to speed things up
                foreach (DictionaryEntry de in EnemyController.GetInstance().EnemyUnitDefByDeployedId)
                {
                    int      deployedid = (int)de.Key;
                    IUnitDef unitdef    = de.Value as IUnitDef;
                    if (unitdef != null)
                    {
                        Float3 thispos = aicallback.GetUnitPos(deployedid);
                        if (IsPriorityTarget(unitdef))
                        {
                            double thissquareddistance = Float3Helper.GetSquaredDistance(scoutpos, thispos);
                            if (thissquareddistance < bestsquareddistance)
                            {
                                bool nolasertowersnear = true;
                                foreach (DictionaryEntry attackerde in EnemyController.GetInstance().EnemyUnitDefByDeployedId)
                                {
                                    int      attackerid      = (int)attackerde.Key;
                                    IUnitDef attackerunitdef = attackerde.Value as IUnitDef;
                                    if (attackerunitdef != null)
                                    {
                                        if (IsLaserTower(attackerunitdef))
                                        {
                                            Float3 attackerpos = aicallback.GetUnitPos(attackerid);
                                            if (Float3Helper.GetSquaredDistance(attackerpos, thispos) < nearbyforenemiesmeans * nearbyforenemiesmeans)
                                            {
                                                nolasertowersnear = false;
                                            }
                                        }
                                    }
                                }
                                if (nolasertowersnear)
                                {
                                    nearestpos          = thispos;
                                    bestsquareddistance = thissquareddistance;
                                    targetid            = deployedid;
                                }
                            }
                        }
                    }
                }
                if (nearestpos != null)
                {
                    aicallback.GiveOrder(scoutdeployedid, new Command(Command.CMD_ATTACK, new double[] { targetid }));
                    if (!attackingscouts.Contains(scoutdeployedid))
                    {
                        attackingscouts.Add(scoutdeployedid);
                    }
                }
                else
                {
                    if (attackingscouts.Contains(scoutdeployedid))
                    {
                        ExploreWith(scoutdeployedid);
                        attackingscouts.Remove(scoutdeployedid);
                    }
                }
            }
        }