Engineer Robot.
Posted: Sat Feb 05, 2011 5:18 pm
This is a robot I made that only use Engineer. Requires level with loadout zone, resource item, and engineer enabled.
Update by raptor: updated for 018a
- Code:
- function getName()
return("engineer_bot")
end
function hasOurLoadout()
-- Test for triple weapon to see if we have changed loadout
-- This is to avoid the memory leak with getCurrLoadout()
return bot:hasWeapon(Weapon.Triple)
end
function gotoClosestLoadoutZone()
local zone = findClosestLoadoutZone()
-- Go to nearest loadout zone to change
if zone ~= nil then
-- If we're close enough, just sit instead of fighting other bots for
-- the zone center point
if point.distSquared(zone:getLoc(), bot:getLoc()) > 1225 then -- (35^2)
bot:setThrustToPt(zone:getLoc())
end
end
end
function onTick()
local target = nil
if hasOurLoadout() then
if bot:getMountedItems(ObjType.ResourceItem)[1] == nil then
table.clear(items)
bot:findGlobalObjects(items, ObjType.ResourceItem)
for index, item in ipairs(items) do
if not item:isOnShip() then
target = item:getLoc()
end
end
elseif bot:getEnergy() > 0.8 then
bot:setThrust(1,angleTo)
bot:setAngle(angleTo)
angleTo = angleTo + bot:getTime() * 0.002
if math.random(10) < 5 then
bot:engineerDeployObject(EngineerBuildObject.ForceFieldProjector)
else
bot:engineerDeployObject(EngineerBuildObject.Turret)
end
end
else
bot:setReqLoadout(loadout);
table.clear(items)
bot:findGlobalObjects(items, ObjType.LoadoutZone)
for index, item in ipairs(items) do
if item:getTeamIndx() == 0 or item:getTeamIndx() == bot:getTeamIndx() then
target = item:getLoc()
end
end
end
if target ~= nil then
target = bot:getWaypoint(target)
end
if target ~= nil then
angleTo = point.angleTo(bot:getLoc(),target)
bot:setThrust(1,angleTo)
bot:setAngle(angleTo)
end
end
function main()
angleTo = 0
items = {} -- Our search table
-- Set up the loadout we want
loadout = Loadout.new()
loadout:setModule(1, Module.Engineer) -- We only care about this
loadout:setModule(2, Module.Shield)
loadout:setWeapon(1, Weapon.Phaser)
loadout:setWeapon(2, Weapon.Bounce)
loadout:setWeapon(3, Weapon.Triple) -- And this - to get around the memory leak
-- Set the loadout, will become active when bot hits loadout zone
-- or spawns, depending on game
bot:setReqLoadout(loadout)
end
Update by raptor: updated for 018a