Ejemplo n.º 1
0
        public void Activate()
        {
            UnitController.GetInstance();
            EnemyController.GetInstance();
            FriendlyUnitPositionObserver.GetInstance();

            MovementMaps.GetInstance();
            BuildMap.GetInstance();
            Metal.GetInstance().Init();
            LosMap.GetInstance();
            BuildPlanner.GetInstance();

            BuildTable.GetInstance();

            CommanderList.GetInstance();
            Level1ConstructorList.GetInstance();
            Level1FactoryList.GetInstance();

            tankcontroller = new TankController(TankList.GetInstance().defbyid, BuildTable.GetInstance().UnitDefByName["armstump"]);
            tankcontroller.Activate();
            helicoptercontroller = new TankController(HelicopterList.GetInstance().defbyid, BuildTable.GetInstance().UnitDefByName["armbrawl"]);
            helicoptercontroller.Activate();
            new ScoutControllerRaider().Activate();

            UnitController.GetInstance().LoadExistingUnits();
            EnemyController.GetInstance().LoadExistingUnits();

            CheckIdleUnits();

            //BuildSolarCell(CommanderList.GetInstance().defbyid.Keys.GetEnumerator().Current);

            csai.UnitIdleEvent += new CSAI.UnitIdleHandler(csai_UnitIdleEvent);
            csai.TickEvent     += new CSAI.TickHandler(csai_TickEvent);
        }
Ejemplo n.º 2
0
 void BuildAt( int constructorid, IUnitDef unitdef, Float3 buildsite )
 {
     IUnitDef placeholder;
     /*
     if( unitdef.name.ToLower() == "armmex" ) // use smaller placeholder for mexes so fit closer to intended metalspot
     {
         placeholder = buildtable.UnitDefByName[ "ARMMOHO".ToLower() ] as IUnitDef;
     }
     else
     {
         placeholder = buildtable.UnitDefByName[ "CORGANT".ToLower() ] as IUnitDef;
     }
     buildsite = aicallback.ClosestBuildSite( placeholder, buildsite, 1400.0, 2 );            
     buildsite = aicallback.ClosestBuildSite( unitdef, buildsite, 1400.0, 2 );            
     */
     if( unitdef.name == BuildTable.ArmMex )
     {
         placeholder = buildtable.UnitDefByName[ BuildTable.ArmMoho ] as IUnitDef;
         buildsite = aicallback.ClosestBuildSite( placeholder, buildsite, 1400.0, 2 );            
         buildsite = aicallback.ClosestBuildSite( unitdef, buildsite, 1400.0, 2 );            
     }
     else
     {
         buildsite = BuildPlanner.GetInstance().ClosestBuildSite( unitdef, buildsite, 3000 );
         buildsite.y = aicallback.GetElevation( buildsite.x, buildsite.z );
         buildsite = aicallback.ClosestBuildSite( unitdef, buildsite, 1400, 2 );            
     }
     
     logfile.WriteLine( "building " + unitdef.name + " at " + buildsite.ToString() );
     if( ShowNextBuildSite )
     {
         aicallback.DrawUnit(unitdef.name, buildsite, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true);
     }
     aicallback.GiveOrder( constructorid, new Command( - unitdef.id, buildsite.ToDoubleArray() ) );
 }
Ejemplo n.º 3
0
        bool BuildSolarCell(int constructorid)
        {
            if (!BuildTree.GetInstance().CanBuild(UnitController.GetInstance().UnitDefByDeployedId[constructorid].name.ToLower(),
                                                  "armsolar"))
            {
                return(false);
            }
            IUnitDef unitdef   = BuildTable.GetInstance().UnitDefByName["armsolar"];
            Float3   buildsite = BuildPlanner.GetInstance().ClosestBuildSite(unitdef,
                                                                             aicallback.GetUnitPos(constructorid),
                                                                             3000, 2);

            buildsite = aicallback.ClosestBuildSite(unitdef, buildsite, 100, 0);
            if (!ActiveConstructors.Contains(constructorid))
            {
                ActiveConstructors.Add(constructorid);
            }
            //aicallback.GiveOrder(constructorid, new Command(-unitdef.id, buildsite.ToDoubleArray()));
            GiveOrderWrapper.GetInstance().BuildUnit(constructorid, unitdef.name, buildsite);
            return(true);
        }
Ejemplo n.º 4
0
        Float3 BuildUnit(int constructorid, string targetunitname)
        {
            csai.DebugSay("workflow, building " + targetunitname);
            IUnitDef targetunitdef  = BuildTable.GetInstance().UnitDefByName[targetunitname];
            IUnitDef constructordef = UnitController.GetInstance().UnitDefByDeployedId[constructorid];

            if (new UnitDefHelp(aicallback).IsMobile(constructordef))
            {
                logfile.WriteLine("constructor is mobile");
                Float3 constructorpos = aicallback.GetUnitPos(constructorid);
                Float3 buildsite      = BuildPlanner.GetInstance().ClosestBuildSite(targetunitdef,
                                                                                    constructorpos,
                                                                                    3000, 2);
                buildsite = aicallback.ClosestBuildSite(targetunitdef, buildsite, 1400, 0);
                logfile.WriteLine("constructor location: " + constructorpos.ToString() + " Buildsite: " + buildsite.ToString() + " target item: " + targetunitdef.humanName);
                if (!ActiveConstructors.Contains(constructorid))
                {
                    ActiveConstructors.Add(constructorid);
                }
                aicallback.DrawUnit(targetunitname.ToUpper(), buildsite, 0.0, 200, aicallback.GetMyAllyTeam(), true, true);
                GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname, buildsite);
                return(buildsite);
            }
            else
            {
                Float3 factorypos = aicallback.GetUnitPos(constructorid);
                logfile.WriteLine("factory location: " + factorypos.ToString() + " target item: " + targetunitdef.humanName);
                if (!ActiveConstructors.Contains(constructorid))
                {
                    ActiveConstructors.Add(constructorid);
                }
                aicallback.DrawUnit(targetunitdef.name.ToUpper(), factorypos, 0.0, 200, aicallback.GetMyAllyTeam(), true, true);
                GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname);
                return(factorypos);
            }
        }
Ejemplo n.º 5
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);
            }
        }