/********** * UTILITIES **********/ // Save resources for the passed unit type. private void SaveResourcesFor(uint unitType) { var rollToSaveFor = random.Next(100); var showNotFoundMessage = false; // If there is no structure save to make one. if (Units.Structures.Contains(unitType) && controller.GetTotalCount(unitType, inConstruction: true) == 0 && controller.GetTotalCount(Units.DRONE) > DRONE_MIN_TO_AUTO_SAVE_RESOUCES) { rollToSaveFor = 0; showNotFoundMessage = true; } if (rollToSaveFor <= CHANCE_TO_SAVE_RESOURCES && controller.CanConstruct(unitType, ignoreResourceSupply: true)) { if (showNotFoundMessage) { Logger.Info("Could not find a {0}, save resouces for it.", ControllerDefault.GetUnitName(unitType)); } var mineralCost = 0; var vespeneCost = 0; controller.CanAfford(unitType, ref mineralCost, ref vespeneCost); SetSaveResouces(unitType, mineralCost, vespeneCost); } }
// Call the units smart ability. // I belive this is smart casting so units will check if other units are already doing the ability, but i am not sure. public void Smart(Unit unit) { var action = ControllerDefault.CreateRawUnitCommand(Abilities.SMART); action.ActionRaw.UnitCommand.TargetUnitTag = unit.tag; action.ActionRaw.UnitCommand.UnitTags.Add(tag); ControllerDefault.AddAction(action); }
// Move a unit to a location. public void Move(Vector3 target) { var action = ControllerDefault.CreateRawUnitCommand(Abilities.MOVE); action.ActionRaw.UnitCommand.TargetWorldSpacePos = new Point2D(); action.ActionRaw.UnitCommand.TargetWorldSpacePos.X = target.X; action.ActionRaw.UnitCommand.TargetWorldSpacePos.Y = target.Y; action.ActionRaw.UnitCommand.UnitTags.Add(tag); ControllerDefault.AddAction(action); }
// Set the camera on a unit. private void FocusCamera() { var action = new Action(); action.ActionRaw = new ActionRaw(); action.ActionRaw.CameraMove = new ActionRawCameraMove(); action.ActionRaw.CameraMove.CenterWorldSpace = new Point(); action.ActionRaw.CameraMove.CenterWorldSpace.X = position.X; action.ActionRaw.CameraMove.CenterWorldSpace.Y = position.Y; action.ActionRaw.CameraMove.CenterWorldSpace.Z = position.Z; ControllerDefault.AddAction(action); }
// Train a unit. public void Train(uint unitType, bool queue = false) { if (!queue && orders.Count > 0) { return; } var abilityID = Abilities.GetID(unitType); var action = ControllerDefault.CreateRawUnitCommand(abilityID); action.ActionRaw.UnitCommand.UnitTags.Add(tag); ControllerDefault.AddAction(action); var targetName = ControllerDefault.GetUnitName(unitType); Logger.Info("Started training: {0}", targetName); }
// Set the resouces that need to be saved to for a unit type. // Not sending in any data to the method will reset it to not saving for a unit. private void SetSaveResouces(uint unitType = 0, int minerals = 0, int vespene = 0) { if (unitType != 0) { Logger.Info("Save resources for {0}: minerals = {1} vespene = {2}", ControllerDefault.GetUnitName(unitType), minerals, vespene); } saveForUnitType = unitType; saveForMinerals = minerals; saveForVespene = vespene; }
public IEnumerable <Action> OnFrame() { controller.OpenFrame(); if (controller.frame == 0) { Logger.Info("JCZergBot"); Logger.Info("--------------------------------------"); Logger.Info("Map: {0}", ZergController.gameInfo.MapName); Logger.Info("--------------------------------------"); } /* * if (controller.frame == 1) * { * foreach (var unit in Units.Zerg) * { * controller.CanAfford(unit); * } * } */ // Distribute workers optimally every 10 frames. if (controller.frame % 10 == 0) { controller.DistributeWorkers(); } // Setup the game minute. if (controller.frame % (22 * 60) == 0) { gameMin++; } if (controller.minerals >= saveForMinerals && controller.vespene >= saveForVespene) { // Construct / Train saved for unit. if (saveForUnitType != 0) { CreateSavedForUnit(); } } else { // There are no workers to gather. var workers = controller.GetUnits(Units.Workers); if (workers.Count == 0) { Logger.Info("No workers to gather resources to save for {0}.", ControllerDefault.GetUnitName(saveForUnitType)); SetSaveResouces(); } // Make sure there is enough minerals to gather. if (saveForMinerals > 0) { var mineralFields = controller.GetUnits(Units.MineralFields, alliance: Alliance.Neutral, onlyVisible: true); var totalMineralsLeft = 0; //Logger.Info("Visible mineral fields = {0}", mineralFields.Count); foreach (var mineralField in mineralFields) { totalMineralsLeft = totalMineralsLeft + mineralField.minerals; } if (totalMineralsLeft < saveForMinerals) { Logger.Info("Not enough minerals left: {0} left but need {1}", totalMineralsLeft, saveForMinerals); SetSaveResouces(); } } // Make sure there is enough vespene to gather. // Note: Need to add code to make sure vespene is being gathered. if (saveForVespene > 0) { var gasBuildings = controller.GetUnits(Units.GasGeysersStructures); var totalVespeneLeft = 0; foreach (var gasBuilding in gasBuildings) { totalVespeneLeft = totalVespeneLeft + gasBuilding.vespene; } if (totalVespeneLeft < saveForVespene) { Logger.Info("Not enough vespene left: {0} left but need {1}", totalVespeneLeft, saveForVespene); SetSaveResouces(); } } } if (controller.frame > nextWaitFrame) { // This is for a bot that randomly dose all its actions. if (totalRandom) { var randAction = random.Next(4); switch (randAction) { case 0: nextWaitFrame = nextWaitFrame + controller.SecsToFrames(WAIT_IN_SECONDS); break; case 1: BuildBuildingsRandom(); break; case 2: BuildUnitsRandom(); break; case 3: UnitActionsRandom(); break; } } else { // Bot will try and do actions more intelligently. var randAction = random.Next(100); //Logger.Info("Random = {0}", randAction); if (randAction < 10) { nextWaitFrame = nextWaitFrame + controller.SecsToFrames(WAIT_IN_SECONDS * random.Next(1, 10)); } else if (randAction < 70) { BuildBuildings(); } else if (randAction < 90) { BuildUnits(); } else { UnitActions(); } } } return(controller.CloseFrame()); }