public void ExploreWith( int unitid ) { if (lastexploretime.ContainsKey(unitid) && aicallback.GetCurrentFrame() - lastexploretime[unitid] < 30) { return; } 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("SpreadSearchWithSearchGrid 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 = new LosHelper().GetNearestUnseen(currentpos, unitdef, 12000 ); if (nextpoint == null) { nextpoint = GetRandomDestination(); } if (!lastexploretime.ContainsKey(unitid)) { lastexploretime.Add(unitid, aicallback.GetCurrentFrame()); } else { lastexploretime[unitid] = aicallback.GetCurrentFrame(); } GiveOrderWrapper.GetInstance().MoveTo(unitid, nextpoint); }
public void ExploreWith(int unitid) { if (lastexploretime.ContainsKey(unitid) && aicallback.GetCurrentFrame() - lastexploretime[unitid] < 30) { return; } 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("SpreadSearchWithSearchGrid 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 = new LosHelper().GetNearestUnseen(currentpos, unitdef, 12000); if (nextpoint == null) { nextpoint = GetRandomDestination(); } if (!lastexploretime.ContainsKey(unitid)) { lastexploretime.Add(unitid, aicallback.GetCurrentFrame()); } else { lastexploretime[unitid] = aicallback.GetCurrentFrame(); } GiveOrderWrapper.GetInstance().MoveTo(unitid, nextpoint); }