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 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);
     }
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public Float3 ClosestBuildSite(IUnitDef unitdef, Float3 approximatepos, int maxposradius, int mindistancemapunits)
        {
            // ok, so plan is we work our way out in a kindof spiral
            // we start in centre, and increase radius, and work around in a square at each radius, until we find something
            int centrex = (int)(approximatepos.x / 8);
            int centrey = (int)(approximatepos.z / 8);
            //int radius = 0;
            int radius = mindistancemapunits;
            int unitsizexwithmargin = unitdef.xsize + 2 * BuildMargin;
            int unitsizeywithmargin = unitdef.ysize + 2 * BuildMargin;

            if (unitdefhelp.IsFactory(unitdef))
            {
                unitsizeywithmargin += 8;
                centrey             += 4;
            }
            BuildMap     buildmap     = BuildMap.GetInstance();
            MovementMaps movementmaps = MovementMaps.GetInstance();

            // while( radius < mapwidth || radius < mapheight ) // hopefully we never get quite this far...
            while (radius < (maxposradius / 8))
            {
                //  logfile.WriteLine( "ClosestBuildSite radius " + radius );
                for (int deltax = -radius; deltax <= radius; deltax++)
                {
                    for (int deltay = -radius; deltay <= radius; deltay++)
                    {
                        if (deltax == radius || deltax == -radius || deltay == radius || deltay == -radius)  // ignore the hollow centre of square
                        {
                            // logfile.WriteLine( "delta " + deltax + " " + deltay );
                            bool positionok = true;
                            // go through each square in proposed site, check not build on
                            for (int buildmapy = centrey - unitsizeywithmargin / 2; positionok && buildmapy < centrey + unitsizeywithmargin / 2; buildmapy++)
                            {
                                //string logline = "";
                                for (int buildmapx = centrex - unitsizexwithmargin / 2; positionok && buildmapx < centrex + unitsizexwithmargin / 2; buildmapx++)
                                {
                                    int thisx = buildmapx + deltax;
                                    int thisy = buildmapy + deltay;
                                    if (thisx < 0 || thisy < 0 || thisx >= mapwidth || thisy >= mapwidth ||
                                        !buildmap.SquareAvailable[thisx, thisy] ||
                                        !movementmaps.vehiclemap[thisx / 2, thisy / 2])
                                    {
                                        //logfile.WriteLine( "check square " + buildmapx + " " + buildmapy + " NOK" );
                                        positionok = false;
                                        //   logline += "*";
                                    }
                                    else
                                    {
                                        //   logline += "-";
                                    }
                                    //logfile.WriteLine( "check square " + buildmapx + " " + buildmapy + "Ok" );
                                }
                                //    logfile.WriteLine( logline );
                            }
                            // logfile.WriteLine("");
                            if (positionok)
                            {
                                return(new Float3((centrex + deltax) * 8, 0, (centrey + deltay) * 8));
                            }
                        }
                    }
                }
                radius++;
            }
            return(null);
        }