Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// AI module for managing your economy. Building drones, vespen geysers, etc.
- let private getEconomyAI (mediator : GameMediator) =
- async {
- while true do
- let currentState = mediator.CurrentGameState
- // Build workers with all available cash
- if currentState.SupplyUsed < currentState.SupplyTotal &&
- currentState.Minerals >= 50 &&
- currentState.CanProduce.[ int (getWorkerType(g_GameMetadata.PlayerRace)) ] then
- // BUG: Builds a worker at the first command center we find, this might not be the best one.
- // Ideally we'd have some higher level notion of a 'base' with a 'status' such as 'active' or 'out of resources'.
- let cmdCenter =
- currentState.Units
- |> Seq.filter (fun unit -> unit.Player = g_GameMetadata.PlayerID)
- |> Seq.tryFind (fun unit -> isCommandCenter (enum<UnitID> unit.TypeID))
- if Option.isSome cmdCenter then
- let cmdCenterID = cmdCenter |> Option.get |> (fun unit -> unit.ID)
- let cmd = TrainUnit(cmdCenterID, int (getWorkerType(g_GameMetadata.PlayerRace)))
- mediator.SendCommand(cmd)
- // Send idle workers to closest mineral patch
- for scunit in currentState.Units do
- // If you own the unit, it's a worker, and it's sitting there then
- // send it to the closest mineral patch.
- if scunit.Player = mediator.GameMetadata.PlayerID &&
- isWorker scunit &&
- scunit.OrderID = int (UnitOrder.PlayerGuard) then
- let orderID = scunit.OrderID
- let scunitLoc = { X = scunit.XPos; Y = scunit.YPos }
- let mineralPatches =
- currentState.Units
- |> Seq.filter(fun unit -> unit.TypeID = int UnitID.MineralField)
- |> Seq.map(fun minPatch -> let patchLoc = { X = minPatch.XPos; Y = minPatch.YPos }
- scunitLoc.FlyingDistanceTo(patchLoc), minPatch)
- |> Seq.sortBy(fun (dist, minPatch) -> dist)
- if mineralPatches <> Seq.empty then
- let targetMinPatch = mineralPatches |> Seq.head |> snd
- let cmd = RightClickUnit(scunit.ID, targetMinPatch.ID)
- mediator.SendCommand(cmd)
- // Sleep and check again later. If this agent gets canceled it will be right here.
- do! Async.Sleep(100)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement