Including the correct speed modifier for a new lvl 1 wizard , not including the tile speed modifier yet
There are functions for getting the correct rotmg angle from location 1 to location 2 variables and
all the necessary trigonometry is included
Code:
global constant PI = 3.141592653589793238
constant PI_HALF = PI / 2.0 -- this is pi/2
constant HALFPI = PI/2.0
constant SPEED_MULTIPLIER = 7.462686567164179E-5
constant SPEED_BASE=0.0034999999999999996
global function point_distance(atom x1,atom y1 , atom x2, atom y2)
atom x, y
x = power(floor(x1) - floor(x2), 2)
y = power(floor(y1) - floor(y2), 2)
return sqrt(x + y)
end function
global function atan2(atom y, atom x)
if x > 0 then
return arctan(y/x)
elsif x < 0 then
if y < 0 then
return arctan(y/x) - PI
else
return arctan(y/x) + PI
end if
elsif y > 0 then
return HALFPI
elsif y < 0 then
return -(HALFPI)
else
return 0
end if
end function
global function get_angle_to(atom x, atom y, atom x2, atom y2)
return (180- atan2(x2 - x ,y2 - y) *180/PI)
end function
global function degtorad(atom angle)
return (angle * (PI/180))
end function
global function get_tick_count()
return w32Func(xGetTickCount,{})
end function
global atom start_time
start_time=get_tick_count()
global function current_time()
return w32Func(xGetTickCount,{})-start_time
end function
The movement coded
Code:
angle=get_angle_to(mx,my,tx,ty)
speed=SPEED_BASE + (SPEED_MULTIPLIER)
stime=current_time()-client_list[client][client_last_move_time]
if stime>600 then
stime=600
end if
autolootbots_list[autoloot_handle][autoloot_mx]+=(stime * speed)*sin(degtorad(angle))
autolootbots_list[autoloot_handle][autoloot_my]-=(stime * speed)*cos(degtorad(angle))
there really should be a module/library for every programming language to do Polar/Cartesian and vector stuff ... also it seems that you are missing an early out which returns target->Pos as the new position if distance(myself->Pos,target->Pos)>expetectMovementDistance ...
---------- Post added at 03:10 PM ---------- Previous post was at 03:08 PM ----------
my $speed=$myself->stats(22) + $myself->stats(50);
my $tilesPerSecond=4+5.6*($speed/75);
my $deltaTime=defined $rotmg->{'prevTickTime'} ? $rotmg->gameTime - $rotmg->{'prevTickTime'} : 0;
$rotmg->{'prevTickTime'}=$rotmg->gameTime;
my $tilesPerTick=$tilesPerSecond*($deltaTime/1000);
$tilesPerTick*=0.65; # 'pool' compensation for Nexus
my $pos=$rotmg->movetowards($myself->pos,$goto,$tilesPerTick);
my $move=Rotmg::Packet->new('MOVE');
$move->tickId($packet->tickId);
$move->time($rotmg->gameTime);
if(defined $pos){
$move->pos($pos);
}else{
$move->pos($myself->pos);
}
Code:
sub moveTowards {
my $self=shift;
my($pos1,$pos2,$speed)=@_;
if($pos1->x==$pos2->x && $pos1->y==$pos2->y){ # distance==0
return $pos2;
}
my $distance=sqrt( ($pos1->x-$pos2->x)**2 + ($pos1->y-$pos2->y)**2 );
if($distance<$speed){
return $pos2;
}
my $vec_x=($pos2->x-$pos1->x)/$distance;
my $vec_y=($pos2->y-$pos1->y)/$distance;
$vec_x*=$speed;
$vec_y*=$speed;
my $pos=Rotmg::Pos->new($pos1->x+$vec_x,$pos1->y+$vec_y);
return $pos;
}
---------- Post added at 03:13 PM ---------- Previous post was at 03:10 PM ----------
also I don't know what you would need the radians for ... you need them for shooting and stuff but clearly not for movement? just multiply the unit vector of currentPos and targetPos with whatever speed you want ...
---------- Post added at 03:16 PM ---------- Previous post was at 03:13 PM ----------
again nothing personal but it is things like this that make it obvious that your bots can not compete with others ... you got millions of useless cpu cycles in your code. your never care about early outs. you do many things in weird and inefficient ways. once you realize that others write better code (especially DatCoder) you will understand why releasing your auto loot bots is a bad idea.
As I understand it, sin requires a radian for sin to return the correct value.
I could compute the sin, cos, values and put them into array beforehand to save on calls and speed up the code.
The slowest thing is the time it takes for the packets to travel to and from the server.
Once a packet is received, it takes 2 milliseconds to process a packet and send one back, I only need a fast looting method.
How about you read what is being posted? I don't see any sin/cos in my code?
Originally Posted by eth0nic
just multiply the unit vector of currentPos and targetPos with whatever speed you want ...
are you going to tell us how to actually use this bot because its damn hard to figure out
@t1000rod have you realized this thread is more than 1 year old?