MoBot
"mO-bot" - noun; A weak and quite stupid bot. It is known to take a specific path upon spawning and holds still whenever shooting. It never uses any modules.
This bot, in its current version, is only compatible with one level. I made a MOBA style level, and this bot is made to act as the weakling minions that show up in waves. The level is "BOTA"
What is a MOBA? Well, it stands for Multiplayer Online Battle Arena. Think "League of Legends" or "DOTA 2".
Get the level:
http://bitfighter.org/pleiades/levels/view/353
Get the bot:
Download the attached file.
If it isn't working, you can copy the code into a file manually. The file should be named "MoBot.bot" and be put inside your "robots" folder.
- Code:
-------------------------------------------------------------------------------
-- This bot is adapted from the code for S_bot.
-- S_bots' authors deserve their due credit.
--
-- Author:
-- thread
-------------------------------------------------------------------------------
goalPt = point.new(0,0);
prevtarget = nil;
gotoPositionWasNil = true;
o = point.new(0,0);
botPos = nil;
items = { };
--BOTA specific variables
--First, the different paths the bot can take.
top1 = {point.new(1402.5,-382.5), point.new(1020,-382.5), point.new(765,-892.5), point.new(0,-892.5), point.new(-765,-892.5), point.new(-1020,-382.5), point.new(-1402.5,-382.5), point.new(-1912.5,0)};
bot1 = {point.new(1402.5,382.5), point.new(1020,382.5), point.new(765,892.5), point.new(0,892.5), point.new(-765,892.5), point.new(-1020,382.5), point.new(-1402.5,382.5), point.new(-1912.5,0)};
top2 = {point.new(-1402.5,-382.5), point.new(-1020,-382.5), point.new(-765,-892.5), point.new(0,-892.5), point.new(765,-892.5), point.new(1020,-382.5), point.new(1402.5,-382.5), point.new(1912.5,0)};
bot2 = {point.new(-1402.5,382.5), point.new(-1020,382.5), point.new(-765,892.5), point.new(0,892.5), point.new(765,892.5), point.new(1020,382.5), point.new(1402.5,382.5), point.new(1912.5,0)};
myPath = {};
soFar = 0;
pathSize = 8;
-- This function gets run once during setup. It is the only time we can declare variables
-- and have them be defined as globals.
function main()
botRadius = bot:getRad();
dirToGo = 0;
game = bf:getGameInfo();
difficulty = tonumber(arg[1]) or .5;
agression = tonumber(arg[2]) or 0.5;
defense = tonumber(arg[3]) or 0;
speed = tonumber(arg[4]) or .75;
directionThreshold = tonumber(arg[5]) or .25;
gameType = game:getGameType();
averageIndex = 1;
averageMax = 20;
averageArray = { };
for i = 1, averageMax do
averageArray[i] = false;
end
myOrbitalDirection = 1;
end
-- bot:fireModule(Module.Shield);
function angleDifference(angleA, angleB)
return (math.mod(math.mod(angleA - angleB, math.pi * 2) + math.pi * 3, math.pi * 2) - math.pi)
end
function fireAtObjects()
result = false;
table.clear(items);
bot:findVisibleObjects(items, ObjType.Robot, ObjType.Turret, ObjType.Ship, ObjType.Core);
-- Cycle through list of potential items until we find one that we can attack
for index, enemy in ipairs(items) do
if(fireAtObject(enemy, Weapon.Phaser)) then
result = true;
break;
end
end
return result;
end
-- Fires at the specified object with the specified weapon if the obj is a good target. Returns whether it fired or not.
-- This is more than I need for my purposes, but it covers all the cases I need, so I will leave it as is.
function fireAtObject(obj, weapon)
local classId = obj:getObjType()
if(classId == ObjType.Turret or classId == ObjType.ForceFieldProjector) then
--Ignore all same-team engineered objects and essentially dead objects
if (obj:getTeamIndex() == bot:getTeamIndex() or obj:getHealth() < .1) then
return false;
end
end
--No shooting various team related objects
if (obj:getTeamIndex() == bot:getTeamIndex() and game:isTeamGame()) or
obj:getTeamIndex() == Team.Neutral then
if (classId == ObjType.Ship or classId == ObjType.Robot or
classId == ObjType.Core or classId == ObjType.SpyBug) then
return false;
end
end
--No shooting non-flag carriers in single player rabbit
if gameType == GameType.Rabbit and not game:isTeamGame() and
(classId == ObjType.Ship or classId == ObjType.Robot) and
not bot:hasFlag() and not obj:hasFlag() then
return false;
end
--We made it here! We have a valid target..
local angle = getFiringSolution(obj);
if angle ~= nil and bot:hasWeapon(weapon) then
bot:setAngle(angle + math.rad((math.random()-0.5)*20*(1-difficulty)));
bot:fireWeapon(weapon);
return(true);
end
return(false)
end
function getName()
return("MOBOT");
end
function gotoPosition(pt)
if pt ~= nil then
gotoPositionWasNil = false;
goalPt = bot:getWaypoint(pt);
if(goalPt ~= nil) then
dirToGo = point.angleTo(botPos, goalPt);
end
end
end
-- Returns the objective for the bot, in the form of a point the bot can navigate towards.
function getObjective()
local result = nil;
local dest = myPath[soFar];
gotoPosition(dest);
--Move to next waypoint?
if (point.distSquared(bot:getPos(), dest) <= 250 and soFar < pathSize) then
soFar = soFar + 1;
end
return result;
end
function doObjective()
--get destination object
if (soFar ~= 0) then
local obj = getObjective();
if obj ~= nil then
gotoPosition(obj:getPos());
end
end
end
function goInDirection()
bot:setThrust(speed, dirToGo);
end
function onTick(deltaTime)
-- Since team hasn't been assigned when main runs, I have to do my checking in onTick
-- Set path if soFor is still 0
if (soFar == 0) then
if (bot:getTeamIndex() > 0) then
if (bot:getPos().y < 0) then
if (bot:getTeamIndex() == 1) then
myPath = top1;
else
myPath = top2;
end
else
if (bot:getTeamIndex() == 1) then
myPath = bot1;
else
myPath = bot2;
end
end
soFar = 1;
end
end
botPos = bot:getPos();
assert(bot:getPos() ~= nil);
if (not fireAtObjects()) then
doObjective();
goInDirection();
end
end
You do not have the required permissions to view the files attached to this post.
_
\/
*
*
*
\/
*
*
*