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() ) ); }
public override Command ToSpringCommand() { if (pos == null) { return(new Command(-idtobuild, new double[] { })); } else { return(new Command(-idtobuild, pos.ToDoubleArray())); } }
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())); } } } }
void ExploreWith(int unitid) { bool destinationfound = false; Float3 currentpos = aicallback.GetUnitPos(unitid); MovementMaps movementmaps = MovementMaps.GetInstance(); IUnitDef unitdef = UnitDefListByDeployedId[unitid] as IUnitDef; int currentarea = movementmaps.GetArea(unitdef, currentpos); LosMap losmap = LosMap.GetInstance(); if (csai.DebugOn) { logfile.WriteLine("explorewith unit " + unitid + " " + unitdef.humanName + " area: " + currentarea); } /* * int numtriesleft = 30; // just try a few times then give up * // maybe there is a better way to do this? * while( !destinationfound ) * { * Float3 destination = GetRandomDestination(); * // logfile.WriteLine( "SpreadSearchWithSearchGrid attempt " + destination.ToString() ); * int mapx = (int)( destination.x / 16 ); * int mapy = (int)( destination.z / 16 ); * if( ( movementmaps.GetArea( unitdef, destination ) == currentarea && * losmap.LastSeenFrameCount[ mapx, mapy ] < recentmeansnumframes || numtriesleft <= 0 ) ) * { * logfile.WriteLine( "Looks good. Go. " + numtriesleft + " retriesleft" ); * if( csai.DebugOn ) * { * aicallback.CreateLineFigure( currentpos, destination,10,true,400,0); * aicallback.DrawUnit( "ARMFAV", destination, 0.0f, 400, aicallback.GetMyAllyTeam(), true, true); * } * aicallback.GiveOrder( unitid, new Command( Command.CMD_MOVE, destination.ToDoubleArray() ) ); * return; * } * numtriesleft--; * } */ // find nearest, area that hasnt had los recently //int maxradius = Math.Max( aicallback.GetMapWidth(), aicallback.GetMapHeight() ) / 2; //for( int radius = Float3 nextpoint = LosMap.GetInstance().GetNearestUnseen(currentpos, unitdef, 6000); if (nextpoint == null) { nextpoint = GetRandomDestination(); } aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, nextpoint.ToDoubleArray())); }
void ExploreWith(int unitid) { Float3 destination = new Float3(); if (PriorityTargets.Count > 0) { destination = PriorityTargets.Dequeue() as Float3; logfile.WriteLine("dequeued next destination: " + destination.ToString()); } else { destination.x = random.Next(0, aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE); destination.z = random.Next(0, aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE); destination.y = aicallback.GetElevation(destination.x, destination.y); logfile.WriteLine("mapwidth: " + aicallback.GetMapWidth() + " squaresize: " + MovementMaps.SQUARE_SIZE); logfile.WriteLine("ScoutController sending scout " + unitid + " to " + destination.ToString()); } aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, destination.ToDoubleArray())); }
void MoveTo(Float3 pos) { // check whether we really need to do anything or if order is roughly same as last one if (csai.DebugOn) { aicallback.DrawUnit("ARMSOLAR", pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); } if (restartedfrompause || Float3Helper.GetSquaredDistance(pos, lasttargetpos) > (movetothreshold * movetothreshold)) { foreach (DictionaryEntry de in UnitDefListByDeployedId) { int deployedid = (int)de.Key; IUnitDef unitdef = de.Value as IUnitDef; aicallback.GiveOrder(deployedid, new Command(Command.CMD_MOVE, pos.ToDoubleArray())); } restartedfrompause = false; lasttargetpos = pos; } }
void MoveTo( Float3 pos ) { // check whether we really need to do anything or if order is roughly same as last one aicallback.DrawUnit("ARMSOLAR", pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true); if( restartedfrompause || Float3Helper.GetSquaredDistance( pos, lasttargetpos ) > ( movetothreshold * movetothreshold ) ) { aicallback.GiveGroupOrder( groupid, new Command( Command.CMD_MOVE, pos.ToDoubleArray() ) ); /* foreach( DictionaryEntry de in UnitDefListByDeployedId ) { int deployedid = (int)de.Key; IUnitDef unitdef = de.Value as IUnitDef; aicallback.GiveOrder( deployedid, new Command( Command.CMD_MOVE, pos.ToDoubleArray() ) ); } */ restartedfrompause = false; lasttargetpos = pos; } }
void ExploreWith(int unitid) { Float3 destination = GetRandomDestination(); aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, destination.ToDoubleArray())); }
void ExploreWith( int unitid ) { Float3 destination = new Float3(); if( PriorityTargets.Count > 0 ) { destination = PriorityTargets.Dequeue() as Float3; logfile.WriteLine( "dequeued next destination: " + destination.ToString() ); } else { destination.x = random.Next(0, aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE ); destination.z = random.Next( 0, aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE ); destination.y = aicallback.GetElevation( destination.x, destination.y ); logfile.WriteLine( "mapwidth: " + aicallback.GetMapWidth() + " squaresize: " + MovementMaps.SQUARE_SIZE ); logfile.WriteLine( "ScoutController sending scout " + unitid + " to " + destination.ToString() ); } aicallback.GiveOrder( unitid, new Command( Command.CMD_MOVE, destination.ToDoubleArray() ) ); }
void CommanderBuildAt(IUnitDef unitdef, Float3 buildsite) { logfile.WriteLine("Commander building " + unitdef.name + " at " + buildsite.ToString()); aicallback.DrawUnit(unitdef.name, buildsite, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); aicallback.GiveOrder(commanderid, new Command(-unitdef.id, buildsite.ToDoubleArray())); }
void CommanderBuildAt( IUnitDef unitdef, Float3 buildsite ) { logfile.WriteLine( "Commander building " + unitdef.name + " at " + buildsite.ToString() ); aicallback.DrawUnit(unitdef.name, buildsite, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true); aicallback.GiveOrder( commanderid, new Command( - unitdef.id, buildsite.ToDoubleArray() ) ); }
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 == "ARMMEX" ) { placeholder = buildtable.UnitDefByName[ "ARMMOHO".ToLower() ] 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() ) ); }
public override double[] ToDoubleArray() { return(targetpos.ToDoubleArray()); }
public override Command ToSpringCommand() { return(new Command(Command.CMD_MOVE, targetpos.ToDoubleArray())); }
void Move(int unitid) { aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, targetpos.ToDoubleArray())); }