Index: LuaAI.lua =================================================================== --- LuaAI.lua (revision 0) +++ LuaAI.lua (revision 0) @@ -0,0 +1,7 @@ +local foo = { + { + name="Spring 1944 German AI", + desc="Very, very basic and extraodinarily dumb. Only one at a time will work currently. Can only play Germans for now!", + }, +} +return foo Index: LuaRules/Gadgets/Spring44dumbGermanAI.lua =================================================================== --- LuaRules/Gadgets/Spring44dumbGermanAI.lua (revision 0) +++ LuaRules/Gadgets/Spring44dumbGermanAI.lua (revision 0) @@ -0,0 +1,116 @@ +function gadget:GetInfo() + return { + name = "Spring 1944 German AI", + desc = "rudimentary German AI", + author = "Sean Heron, lots of copy and paste from KDR's stuff though", + date = "2009-03-02", + license = "GNU GPL version 2 or later", + layer = 82, + enabled = true + --credits to KDR for the structure of the files and the commands I copied (from Fibre and the Kernel Panic AI) + -- and to SpliFF for the excellent SpringLua documentation without which I couldn't have made this + } +end + + + + + +--local myteam = -1 -- set as a non player ID value so that checking against it to find a player for attacking works for sure - + +--local enemybaseposx = 100 -- todo: insert enemy base position code here later - doing now :P +--local enemybaseposz = 100 +enemypositionset = false -- for my finding an opponent hack + +if (gadgetHandler:IsSyncedCode()) then + +--SYNCED + +function gadget:GameStart() + + -- set the AI team (not teams yet... :P) + for _,t in ipairs(Spring.GetTeamList()) do + local _,_,_,ai,side = Spring.GetTeamInfo(t) + local thisteamisAI = false + if Spring.GetTeamLuaAI(t)==gadget:GetInfo().name then + myteam = t -- only works for one AI team - need to fix + -- Spring.Echo("The AI should be team "..myteam.." ,has it bleeding worked?") -- seems like it :P + thisteamisAI = true + end + if thisteamisAI == false then -- big hack of course, but whatever works for now... + if enemypositionset == false then + -- Spring.Echo("hope this works!???") + enemybaseposx,_,enemybaseposz = Spring.GetTeamStartPosition(t) + enemypositionset = true + end + end + end + + --HQ orders to get started with + for _,unitID in ipairs(Spring.GetTeamUnits(myteam)) do + -- Spring.Echo("Team "..myteam.." has unit "..unitID.." and") + local posx,_,posz = Spring.GetUnitPosition(unitID) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.gerhqengineer.id, {}, {}) -- seems like it needs to be lowercase for these calls... don't ask + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.gerhqengineer.id, {}, {}) -- the second one used to assist, but stopped after I changed some stuff :/ + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_hq.id, {}, {}) + Spring.GiveOrderToUnit(unitID, CMD.REPEAT, { 1 }, {}) + Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {posx,0,posz + 100}, {}) + Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {enemybaseposx,0,enemybaseposz}, {"shift"}) + + home_x,home_y,home_z = Spring.GetTeamStartPosition(myteam) -- for the barracks placing + end + +end + + +function gadget:UnitFromFactory(unitID, unitDefID, unitTeam) + + -- make Engineer build 'racks + if unitTeam == myteam then + if unitDefID == UnitDefNames.gerhqengineer.id then + -- Spring.Echo("Engineer appeared!") + local posx,_,posz = Spring.GetUnitPosition(unitID) + Spring.GiveOrderToUnit(unitID, CMD.STOP, {}, {}) -- need this, or the engineers start building inside, if the construction site is very close :/ + Spring.GiveOrderToUnit(unitID, CMD.MOVE, {posx,0,posz + 100}, {}) + Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {posx - 50,0,posz + 100}, {"shift"}) --will this get them to assist build ? something does again, anyway :P + -- Spring.Echo("Engineer is building! woot!") + Spring.GiveOrderToUnit(unitID, -UnitDefNames.gerbarracks.id, {home_x - 120,0,home_z}, {"shift"}) + end + end + +end + +function gadget:UnitFinished(unitID, unitDefID, unitTeam) + + -- make 'racks build troops ! + if unitTeam == myteam then + -- Spring.Echo("Stuff finished building") + if unitDefID == UnitDefNames.gerbarracks.id then + -- Spring.Echo("Barracks finished!") + -- Spring.Echo("Pumping out troops :) ") + local posx,_,posz = Spring.GetUnitPosition(unitID) -- get position of 'racks + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_rifle.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_scout.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_assault.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_mg.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_mortar.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_rifle.id, {}, {}) + Spring.GiveOrderToUnit(unitID, -UnitDefNames.ger_platoon_at.id, {}, {}) + Spring.GiveOrderToUnit(unitID, CMD.REPEAT, { 1 }, {}) + Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {posx,0,posz + 100}, {}) + Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {enemybaseposx,0,enemybaseposz}, {"shift"}) + end + end +end + + +--function gadget:GameFrame(f) -- not using this at the moment +--end + +end -- the end of the synced code