Been working on an AI bot by having a bot send in keystrokes to a continuum client. Problem 1: Getting it to turn correctly to an angle. Here's the code I'm currently using: #include "ExternalPrgController.h"
StartPriority(); // sets thread to high priority
for (count=0; count < turnangle; count++)
{
keybd_event (VK_RIGHT,0,0,0);
Sleep (29);
keybd_event (VK_RIGHT,0,KEYEVENTF_KEYUP,0);
EndPriority(); // ends high priority
} The problem is it turns inconsistently, sometimes several angles off. Without high priority its even worse, real time priority isn't noticably different. Need a way to match something to the time it takes to turn 1 angle in SS. Sleep(29) is the closest thing I've found, large for() loops, using windows time ticker, etc are all more inaccurate. Anyone know a better way than Sleep(29)? Problem 2: Getting the angle to turn to fire at an enemy. Current code: BYTE fireangle = TriangulateFireAngle(bot->work - p->work, p->vel - bot->vel, settings->ships[bot->ship].BombSpeed / 1000); // bot = me, p = enemy
BYTE TriangulateFireAngle2(Vector &rel)
{
double dx = -rel.x,
dy = rel.y;
if (dy == 0)
if (dx > 0)
return 10;
else
return 30;
double angle = atan(dx / dy) + PI;
if (dy >= 0)
{
if (dx >= 0)
angle -= PI;
else
angle += PI;
}
return BYTE(angle * 40.0 / TwoPI);
}
BYTE TriangulateFireAngle(Vector &pos, Vector &vel, Sint32 scalar)
{
// pos = relative positions
// vel = relative velocities
// scalar = velocity of bullets
double a = vel.x * vel.x + vel.y * vel.y - scalar;
double b = 2 * (pos.x * vel.x + pos.y * vel.y);
double c = pos.x * pos.x + pos.y * pos.y;
double time = (-b - sqrt((b * b) - (a * c * 2))) / (2.0 * a);
if (time <= 0.0)
time = (-b + sqrt((b * b) - (a * c * 2))) / (2.0 * a);
return TriangulateFireAngle2(Vector(pos.x + Sint32(double(vel.y) * time), pos.y + Sint32(double(vel.y) * time)));
} Thats mostly copy/paste of the built in merv code used to autofire when put in a ship. Can anyone explain it in physics/trig? Does it work when both ships are in motion? If not thats what I need. Problem 3: Need more physics formulas to calculate non-linear flight paths. Example: ship is flying along and wants to fly to some point. How to map that path without making the bot stop and then fly in a line to that point. Problem 4: During movements mervbot doesn't get any incoming information, which is usually .5 - 1.5 seconds. There an easy way to fix that? Add another thread? Pipe information to another bot? Problem 5: Takes too long to calculate fire angles, etc.. by the time its calculated and the ship has moved inches and the angle is off. Need a faster way to calculate angles or someway to compensate. source code: http://www.hardwerk.net/dueling/bots/ai2 (use !fly x (secs) or uncomment sections out of spawn.cpp (player move, weaponfire, ball move) etc.. still heavily in testing, bot needs sysop or lags out, settings.ini = first line = continuum window name, second line = player name to control)