Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public void LoadExistingUnits()
 {
     int[] enemyunits = aicallback.GetEnemyUnitsInRadarAndLos();
     foreach (int enemyid in enemyunits)
     {
         IUnitDef unitdef = aicallback.GetUnitDef(enemyid);
         logfile.WriteLine("enemy unit existing: " + enemyid);
         AddEnemy(enemyid);
     }
 }
Exemplo n.º 3
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);
     }
 }
 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();
     }
 }
Exemplo n.º 5
0
        public void UnitCreated(int deployedunitid)                                                                     //called when a new unit is created on ai team
        {
            DateTime start = DateTime.Now;

            try
            {
                IUnitDef unitdef = aicallback.GetUnitDef(deployedunitid);
                if (UnitCreatedEvent != null)
                {
                    UnitCreatedEvent(deployedunitid, unitdef);
                }
            }
            catch (Exception e)
            {
                logfile.WriteLine("Exception: " + e.ToString());
                SendTextMsg("Exception: " + e.ToString());
            }
            unitcreatedtime += DateTime.Now.Subtract(start).TotalMilliseconds;
        }
Exemplo n.º 6
0
 /*
  * bool WeLikeUnit( string name )
  * {
  *  foreach( string unitwelike in UnitsWeLike )
  *  {
  *      if( unitwelike == name )
  *      {
  *          return true;
  *      }
  *  }
  *  return false;
  * }
  */
 // shifted this to unitidle to give unit time to leave factory
 public void UnitIdle(int id)
 {
     // make this more elegant later, with concept of ownership etc
     if (!TankDefsById.Contains(id))
     {
         IUnitDef unitdef = aicallback.GetUnitDef(id);
         if (WeLikeUnit(unitdef.name.ToLower()))
         {
             logfile.WriteLine("TankController new tank " + " id " + id + " " + unitdef.humanName + " speed " + unitdef.speed);
             TankDefsById.Add(id, unitdef);
             //   DoSomething();
         }
     }
 }
Exemplo n.º 7
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()));
                    }
                }
            }
        }