rendered paste bodybool RunToLocation_(int X_,int Y_,int Step_,int Timeout_,int BetweenPacketSleep_,int MaxOffDistance_)
{
int INIT_Time = clock();
bool RetVal = false;
while ((INIT_Time+Timeout_)>clock())
{
int Last_X = My_Character.X_pos;
int Last_Y = My_Character.Y_pos;
int X__;
int Y__;
if (Last_X<X_)
{
if ((Last_X+Step_)>X_)
{
X__ = X_;
Last_X = X__;
}
else
{
X__ = Last_X+Step_;
Last_X = X__;
}
}
else
{
if ((Last_X-Step_)<X_)
{
X__ = X_;
Last_X = X__;
}
else
{
X__ = Last_X-Step_;
Last_X = X__;
}
}
if (Last_Y<Y_)
{
if ((Last_Y+Step_)>Y_)
{
Y__ = Y_;
Last_Y = Y__;
}
else
{
Y__ = Last_Y+Step_;
Last_Y = Y__;
}
}
else
{
if ((Last_Y-Step_)<Y_)
{
Y__ = Y_;
Last_Y = Y__;
}
else
{
Y__ = Last_Y-Step_;
Last_Y = Y__;
}
}
//LogWrite_("WillRun_.log",true,"Will run to: %d,%d , Should reach %d,%d\n",X__,Y__,X_,Y_);
mutex_lock();
RunToLocation(X__,Y__);
mutex_unlock();
Sleep(BetweenPacketSleep_);
if (((Last_X < (X_ + MaxOffDistance_)) && (Last_X > (X_ - MaxOffDistance_))) && ((Last_Y < (Y_ + MaxOffDistance_)) && (Last_Y > (Y_ - MaxOffDistance_))))
{
My_Character.WaitingReassign = 0;
mutex_lock();
RequestReassign(My_Character.UID,0x00);
mutex_unlock();
for (short nn=0; nn < 300 ; nn++)
{
if (My_Character.WaitingReassign == 1){break;}
if (!((INIT_Time+Timeout_)>clock())){RetVal = false;}
Sleep(1);
}
if (((My_Character.LAX_pos < (X_ + MaxOffDistance_)) && (My_Character.LAX_pos > (X_ - MaxOffDistance_))) && ((My_Character.LAY_pos < (Y_ + MaxOffDistance_)) && (My_Character.LAY_pos > (Y_ - MaxOffDistance_)))){RetVal = true;break;}
}
}
return RetVal;
}