Re: Проверка на проходимость
Posted: 2011-07-07 12:34:36
Ну я бы вообще не стал браться. Но у тебя уже существенные продвижения по теме. Глядишь родится интелектуальный бот на инжекте. 

Code: Select all
sub test()
var String = VectorPoints(UO.GetX('self'), UO.GetY('self'), UO.GetX('self') - 3, UO.GetY('self') - 4), i
var Count = val(GetWord(String, 1))
UO.Print(String)
UO.Print(str(uo.getz()))
For i = 2 to Count * 2 + 1 step 2
UO.MFGI('add', '1339', GetWord(String, i), GetWord(String, i + 1), UO.GetZ(), '0x0025', 'cave floor')
Next
Endsub
sub deltile()
var MaxRange = 18
var X, Y, Z, Tiles
var mX, mY, mZ
mX = UO.GetX('self')
mY = UO.GetY('self')
mZ = UO.GetZ('self')
for Y = MaxRange - ( MaxRange * 2 ) to MaxRange
for X = MaxRange - ( MaxRange * 2 ) to MaxRange
UO.MFGI('clear', '1339', mX+X, mY+Y, UO.GetZ('self'))
next
next
end sub
Sub VectorPoints(startx, starty, endx, endy)
var x = startx, y = starty, Coordinates = ' ' + str(x) + ' ' + str(y) + ' ', Amount = 1
While x <> endx and y <> endy
If x == endx and y < endy then
y = y + 1
Endif
If x > endx and y < endy then
x = x - 1
y = y + 1
Endif
If x > endx and y == endy then
x = x - 1
Endif
If x > endx and y > endy then
x = x - 1
y = y - 1
Endif
If x == endx and y > endy then
y = y - 1
Endif
If x < endx and y > endy then
x = x + 1
y = y - 1
Endif
If x < endx and y == endy then
x = x + 1
Endif
If x < endx and y < endy then
x = x + 1
y = y + 1
Endif
Coordinates = (Coordinates + str(x) + ' ' + str(y) + ' ')
Amount = Amount + 1
Wend
Return str(Amount) + Coordinates
Endsub
Sub GetWord(st, nom)
var tmpst, i, dlin, kol = 0, start = 0
dlin = len(st)
For i = 0 to dlin - 1
If mid(st, i, 1) == ' ' or i == dlin - 1 then
kol = kol + 1
If kol == nom then
tmpst = mid(st, start, i - start)
Return tmpst
else
While mid(st, i, 1) == ' '
i = i + 1
Wend
If kol == nom - 1 then
start = i
Endif
Endif
Endif
Next
tmpst = ''
Return tmpst
Endsub
Code: Select all
Sub GetAngle(startx, starty, endx, endy)
var a, c = GetVectorLenght(startx, starty, endx, endy), i
If Absolute(endx - startx) < Absolute(endy - starty) then
a = Absolute(endx - startx)
else
a = Absolute(endy - starty)
Endif
For i = 0 to 90
If IsInRange(Sin(i), a / c - 0.005, a / c + 0.005) then
Return i
Endif
Next
Endsub
Sub GetVectorLenght(startx, starty, endx, endy)
Return SQRT(Exponent(endx - startx, 2) + Exponent(endy - starty, 2))
Endsub
Code: Select all
а = с * sin A
Grin wrote:С каждым шагом заново вычисляется направление, и делается 1 шаг в этом направлении. вот и все:)
Code: Select all
Sub VectorPoints(startx, starty, endx, endy)
var x = startx, y = starty, Coordinates = ' ' + str(x) + ' ' + str(y) + ' ', Amount = 1
While x <> endx and y <> endy
If x < endx then
x = x + 1
Endif
If x > endx then
x = x - 1
Endif
If y < endy then
y = y + 1
Endif
If y > endy then
y = y - 1
Endif
Coordinates = (Coordinates + str(x) + ' ' + str(y) + ' ')
Amount = Amount + 1
Wend
Return str(Amount) + Coordinates
Endsub
Code: Select all
bool CChar::CanSeeLOS( const CPointMap & ptDst, CPointMap * pptBlock, int iMaxDist ) const
{
// Max distance of iMaxDist
// Line of sight check
// NOTE: if not blocked. pptBlock is undefined.
if ( IsPriv( PRIV_GM ))
return( true );
CPointMap ptSrc = GetTopPoint();
ptSrc.m_z += PLAYER_HEIGHT/2;
int iDist = ptSrc.GetDist( ptDst );
// Walk towards the object. If any spot is too far above our heads
// then we can not see what's behind it.
int iDistTry = 0;
while ( --iDist > 0 )
{
DIR_TYPE dir = ptSrc.GetDir( ptDst );
ptSrc.Move( dir ); // NOTE: The dir is very coarse and can change slightly.
WORD wBlockFlags = CAN_C_SWIM | CAN_C_WALK | CAN_C_FLY;
signed char z = g_World.GetHeightPoint( ptSrc, wBlockFlags, ptSrc.GetRegion( REGION_TYPE_MULTI ));
if ( wBlockFlags & ( CAN_I_BLOCK | CAN_I_DOOR ))
{
blocked:
if ( pptBlock != NULL )
* pptBlock = ptSrc;
return false; // blocked
}
if ( iDistTry > iMaxDist )
{
// just went too far.
goto blocked;
}
iDistTry ++;
}
return true; // made it all the way to the object with no obstructions.
}
DIR_TYPE CPointBase::GetDir( const CPointBase & pt, DIR_TYPE DirDefault ) const // Direction to point pt
{
// Get the 2D direction between points.
int dx = (m_x-pt.m_x);
int dy = (m_y-pt.m_y);
int ax = abs(dx);
int ay = abs(dy);
if ( ay > ax )
{
if ( ! ax )
{
return(( dy > 0 ) ? DIR_N : DIR_S );
}
int slope = ay / ax;
if ( slope > 2 )
return(( dy > 0 ) ? DIR_N : DIR_S );
if ( dx > 0 ) // westish
{
return(( dy > 0 ) ? DIR_NW : DIR_SW );
}
return(( dy > 0 ) ? DIR_NE : DIR_SE );
}
else
{
if ( ! ay )
{
if ( ! dx )
return( DirDefault ); // here ?
return(( dx > 0 ) ? DIR_W : DIR_E );
}
int slope = ax / ay;
if ( slope > 2 )
return(( dx > 0 ) ? DIR_W : DIR_E );
if ( dy > 0 )
{
return(( dx > 0 ) ? DIR_NW : DIR_NE );
}
return(( dx > 0 ) ? DIR_SW : DIR_SE );
}
}
Code: Select all
sub test()
var String = VectorPoints(UO.GetX('self'), UO.GetY('self'), UO.GetX('self') + 2, UO.GetY('self') + 7), i
var Count = val(GetWord(String, 1))
UO.Print(String)
For i = 2 to Count * 2 step 2
UO.MFGI('add', '1339', GetWord(String, i), GetWord(String, i + 1), 20, '0x0025', 'cave floor')
Next
Endsub
sub deltile()
var MaxRange = 18
var X, Y, Z, Tiles
var mX, mY, mZ
mX = UO.GetX('self')
mY = UO.GetY('self')
mZ = UO.GetZ('self')
for Y = MaxRange - ( MaxRange * 2 ) to MaxRange
for X = MaxRange - ( MaxRange * 2 ) to MaxRange
UO.MFGI('clear', '1339', mX+X, mY+Y, UO.GetZ('self'))
next
next
end sub
Sub VectorPoints(startx, starty, endx, endy)
var Coordinates = ' ' + str(startx) + ' ' + str(starty) + ' ', Amount = 1, dx, dy, ax, ay
While startx <> endx or starty <> endy
dx = startx - endx
dy = starty - endy
ax = Absolute(dx)
ay = Absolute(dy)
If ax > ay then
If ay == 0 then
If dx > 0 then
startx = startx - 1
else
startx = startx + 1
Endif
else
If ax / ay > 2 then
If dx > 0 then
startx = startx - 1
else
startx = startx + 1
Endif
else
If dy > 0 then
If dx > 0 then
startx = startx - 1
starty = starty - 1
else
startx = startx + 1
starty = starty - 1
Endif
else
If dx > 0 then
startx = startx - 1
starty = starty + 1
else
startx = startx + 1
starty = starty + 1
Endif
Endif
Endif
Endif
Endif
If ax < ay then
If ax == 0 then
If dy > 0 then
starty = starty - 1
else
starty = starty + 1
Endif
else
If ay / ax > 2 then
If dy > 0 then
starty = starty - 1
else
starty = starty + 1
Endif
else
If dx > 0 then
If dy > 0 then
starty = starty - 1
startx = startx - 1
else
starty = starty + 1
startx = startx - 1
Endif
else
If dy > 0 then
starty = starty - 1
startx = startx + 1
else
starty = starty + 1
startx = startx + 1
Endif
Endif
Endif
Endif
Endif
If ax == ay then
If dx > 0 then
If dy > 0 then
startx = startx - 1
starty = starty - 1
else
startx = startx - 1
starty = starty + 1
Endif
else
If dy > 0 then
startx = startx + 1
starty = starty - 1
else
startx = startx + 1
starty = starty + 1
Endif
Endif
Endif
Coordinates = Coordinates + str(startx) + ' ' + str(starty) + ' '
Amount = Amount + 1
Wend
Return str(Amount) + Coordinates
Endsub
Sub GetWord(st, nom)
var tmpst, i, dlin, kol = 0, start = 0
dlin = len(st)
For i = 0 to dlin - 1
If mid(st, i, 1) == ' ' or i == dlin - 1 then
kol = kol + 1
If kol == nom then
tmpst = mid(st, start, i - start)
Return tmpst
else
While mid(st, i, 1) == ' '
i = i + 1
Wend
If kol == nom - 1 then
start = i
Endif
Endif
Endif
Next
tmpst = ''
Return tmpst
Endsub
Sub Absolute(val)
If val < 0 then
Return -val
else
Return val
Endif
Endsub