Page 1 of 1

Engineer Robot.

PostPosted: Sat Feb 05, 2011 5:18 pm
by sam686
This is a robot I made that only use Engineer. Requires level with loadout zone, resource item, and engineer enabled.
  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

Re: Engineer Robot.

PostPosted: Thu Feb 02, 2012 4:40 pm
by Santiago ZAP
i love it 5/5

Re: Engineer Robot.

PostPosted: Thu Feb 02, 2012 8:01 pm
by CleverBot
Imagine a bot army filled with defensive bots and offensive bots (_k's bots) and engineering bots...that's annoying. Yeah I rather have bots build us stuff than me doing it.

Re: Engineer Robot.

PostPosted: Sat Feb 04, 2012 4:17 pm
by Santiago ZAP
CleverBot wrote:I rather have bots build us stuff than me doing it.

Same here :P

Re: Engineer Robot.

PostPosted: Sat Feb 04, 2012 8:10 pm
by CleverBot
We shall call them Servant Bots!....or just S_bots.... :?
Anyway I think the bitfighter community needs more engineers to fix the space ports and stuff.

Re: Engineer Robot.

PostPosted: Mon Jul 01, 2013 2:47 pm
by raptor
Updated for 018a