Skip to content

Commit

Permalink
Added map positioning, normal distribution, etc.
Browse files Browse the repository at this point in the history
Added minimap.getLocalPosition(). This method will return the position
of the player, a point, or a texture on the map.

Added normalRandom(), normalRandomE(). This, like gauss, will return a
random number biased toward the median, using the central limit theorem.

Fixed glMapCoords() to not cache results if all coordinates are equal,
or the map was not found, or the function timed out.
  • Loading branch information
ObscuritySRL committed Apr 10, 2015
1 parent db8c628 commit e0156fb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/glMapCoords.simba
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function glMapCoords(var funcX,funcY:array[0..3] of single):boolean;
begin
if (funcSystemTime:=getSystemTime())-oglMapCoordsTimeLast>oglCacheTime then
begin
if result:=glxMapCoords(funcX,funcY) then
if (result:=glxMapCoords(funcX,funcY)) and (funcX[0]-funcX[1]-funcX[2]-funcX[3]<>0) and (funcY[0]-funcY[1]-funcY[2]-funcY[3]<>0) then
begin
oglMapCoords:=result;
oglMapCoordsParameters[0]:=funcX;
Expand Down
10 changes: 10 additions & 0 deletions lib/core/math.simba
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ function shortestRadians(funcStart,funcEnd:double):double;
exit(result);
end;

//~ Normal distribution using the central limit theorem

function normalRandom(funcMin,funcMax:int32):int32;
begin result:=round((funcMin+funcMax)/2+((funcMax-funcMin)/2)*((randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()-6)/6));end;

function normalRandomE():double;overload;
begin result:=0.5+0.5*((randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()-6)/6);end;

function normalRandomE(funcMin,funcMax:double):double;overload;
begin result:=(funcMin+funcMax)/2+((funcMax-funcMin)/2)*((randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()+randomE()-6)/6);end;


//0.01745329251994 - 1deg
Expand Down
92 changes: 92 additions & 0 deletions lib/interfaces/minimap.simba
Original file line number Diff line number Diff line change
@@ -1,3 +1,95 @@
{
========================================
EXAMPLES:
----------------------------------------
if minimap.getLocalPosition().y>70 then
minimap.clickDirection('south');
========================================
}

function minimap.getLocalPosition():tPoint;
var
funcMap:array[0..1] of array[0..3] of single;
funcPointer:pointer;
funcPointerIndex,
funcPointerSize:uInt32=0;
funcPlayer,
funcPosition:array[0..1] of double;
begin
funcPointer:=glTextures(funcPointerSize);
if funcPointer<>nil then
begin
for funcPointerIndex to funcPointerSize-1 do
begin
if funcPointer^=237147 then
begin
funcPlayer:=[0+(funcPointer+20)^+(0+(funcPointer+136)^-(funcPointer+20)^)/2,0+(funcPointer+24)^+(0+(funcPointer+140)^-(funcPointer+24)^)/2];
break;
end;
funcPointer:=funcPointer+36;
end;
if glMapCoords(funcMap[0],funcMap[1]) then
begin
funcPosition[0]:=((funcPlayer[0]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcPlayer[1]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))*512.0/((funcMap[0][3]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcMap[1][3]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))/4;
funcPosition[1]:=((funcPlayer[1]-funcMap[1][0])*(funcMap[0][3]-funcMap[0][0])-(funcPlayer[0]-funcMap[0][0])*(funcMap[1][3]-funcMap[1][0]))*512.0/((funcMap[0][3]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcMap[1][3]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))/4;
result:=[round(funcPosition[0]+0.1) , round(funcPosition[1]+0.1)];
end;
end;
exit(result);
end;

{
========================================
EXAMPLES:
----------------------------------------
if minimap.getLocalPosition(minimap.getPlayer()).y>70 then
minimap.clickDirection('south');
========================================
}

function minimap.getLocalPosition(funcPoint:tPoint):tPoint;overload;
var
funcMap:array[0..1] of array[0..3] of single;
funcPlayer,
funcPosition:array[0..1] of double;
begin
if glMapCoords(funcMap[0],funcMap[1]) then
begin
funcPosition[0]:=((funcPoint.x-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcPlayer[1]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))*512.0/((funcMap[0][3]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcMap[1][3]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))/4;
funcPosition[1]:=((funcPoint.y-funcMap[1][0])*(funcMap[0][3]-funcMap[0][0])-(funcPlayer[0]-funcMap[0][0])*(funcMap[1][3]-funcMap[1][0]))*512.0/((funcMap[0][3]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcMap[1][3]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))/4;
result:=[round(funcPosition[0]+0.1) , round(funcPosition[1]+0.1)];
end;
exit(result);
end;

{
========================================
EXAMPLES:
----------------------------------------
(*
DESCRIPTION: The ID 3570 belongs to
player dots.
*)
if minimap.getLocalPosition().y>minimap.getLocalPosition(ogl.getTextures(3570)) then
minimap.clickDirection('north');
========================================
}

function minimap.getLocalPosition(funcTexture:glTexture):tPoint;overload;
var
funcMap:array[0..1] of array[0..3] of single;
funcPlayer,
funcPosition:array[0..1] of double;
begin
if glMapCoords(funcMap[0],funcMap[1]) then
begin
funcPosition[0]:=((funcTexture.x-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcPlayer[1]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))*512.0/((funcMap[0][3]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcMap[1][3]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))/4;
funcPosition[1]:=((funcTexture.y-funcMap[1][0])*(funcMap[0][3]-funcMap[0][0])-(funcPlayer[0]-funcMap[0][0])*(funcMap[1][3]-funcMap[1][0]))*512.0/((funcMap[0][3]-funcMap[0][0])*(funcMap[1][1]-funcMap[1][0])-(funcMap[1][3]-funcMap[1][0])*(funcMap[0][1]-funcMap[0][0]))/4;
result:=[round(funcPosition[0]+0.1) , round(funcPosition[1]+0.1)];
end;
exit(result);
end;

{
========================================
EXAMPLES:
Expand Down

0 comments on commit e0156fb

Please sign in to comment.