public static List <Mission> DefendAllyFactories() { List <Mission> possibleMissions = new List <Mission>(); var factoryPrority = Factory.factories.Values .OrderBy(f => f.team) .ThenByDescending(f => f.oldProduction); //Defend all ally, and ally to be factories foreach (var factory in factoryPrority) { if (factory.oldProduction == 0) { continue; } if (FactoryState.WillFactoryBeAlly(factory.states)) //nothing to do here { continue; } possibleMissions.Add(new Mission(MissionType.Capture, factory, 1)); } return(possibleMissions); }
public static void SolveIncreaseMission(Mission mission) { Factory ally = mission.factory; List <Troop> mockTroops = new List <Troop>(); mockTroops.Add(new Troop { start = ally, end = ally, count = 10, team = Team.Enemy, isAlly = false, isEnemy = true, turns = 1, endTime = Game.gameTime + 1, }); mockTroops.AddRange(ally.incoming.Values.ToList()); var mockStates = FactoryState.CalculateFactoryState(ally, mockTroops); //FactoryState lastState = mockStates.Last(); if (FactoryState.IsFactoryCaptured(mockStates) == false) { Action newAction = new Action(MoveType.Inc, mission.factory); AddAction(newAction); } }
public static void CalculateAllArmyScore() { return; //do nothing for now foreach (var factory in factories) { FactoryState lastState = factory.states.Last(); //assume the lastState for now double allyCount = 0; double enemyCount = 0; if (lastState.isAlly) { allyCount += lastState.count; } else if (lastState.team == Team.Enemy) { enemyCount += lastState.count; } HashSet <Factory> visited = new HashSet <Factory>(); // factory.AddArmyScore(allyCount, enemyCount); factory.CalculateArmyScore(visited, allyCount, enemyCount); } }
public void UpdateFactoryState() { if ((DateTime.Now - LastStateChange).TotalMinutes < 2) { return; } LastStateChange = DateTime.Now; switch (currentState) { case FactoryState.Unknown: FindCurrentState(); break; case FactoryState.ReadyToBuild: Build(); currentState = FactoryState.Building; break; case FactoryState.Building: break; case FactoryState.Releasing: Release(); currentState = FactoryState.Reseting; break; case FactoryState.Reseting: Reset(); currentState = FactoryState.ReadyToBuild; break; } }
public static void AddAction(Action action, Troop troop = null) { if (action.move == MoveType.Move) { action.start.count -= action.numRobots; action.start.armyAvailable -= action.numRobots; action.end.incoming.Add(troop); action.end.states = FactoryState.CalculateFactoryState(action.end, action.end.incoming); //Console.Error.WriteLine(action.start.id + "-" + action.end.id + ": " + troop.count); } else if (action.move == MoveType.Inc) { action.start.count -= 10; action.start.armyAvailable -= 10; } else if (action.move == MoveType.Bomb) { action.end.incoming.Add(troop); Game.bomb--; } Action.actions.Add(action); }
public FactoryState(FactoryState factory, Troop troop) { this.id = factory.id; this.count = factory.count; this.production = factory.production; this.gameTime = troop.endTime; if (factory.team != Team.Neutral) { int timeDiff = troop.endTime - factory.gameTime; this.count += timeDiff * production; } this.count += (troop.team == factory.team) ? troop.count : -troop.count; if (this.count <= 0) //if the troop captured the factory { this.count *= -1; SetTeam(troop.team); //team become the troops team } else { SetTeam(factory.team); //team stays the same } }
public void Solve() { Factory ally = mission.factory; SortedSet <Troop> mockTroops = new SortedSet <Troop>(ally.incoming); Troop testTroop = new Troop { start = ally, end = ally, count = 10, team = Team.Enemy, isAlly = false, isEnemy = true, turns = 1, endTime = Game.gameTime + 1, }; mockTroops.Add(testTroop); var mockStates = FactoryState.CalculateFactoryState(ally, mockTroops); //FactoryState lastState = mockStates.Last(); if (FactoryState.IsFactoryCaptured(mockStates) == false) { mission.successRating = MissionSuccessRating.Guaranteed; mission.acceptedMission.Add(testTroop); mission.missionEndTime = Game.gameTime + 1; } }
public static List <FactoryState> CalculateFactoryState(Factory factory, List <Troop> troops, bool mockState = true) { List <FactoryState> states = new List <FactoryState>(); FactoryState lastState = new FactoryState(factory, Game.gameTime); states.Add(lastState); //add atleast 1 state to the list var ordered = troops.OrderBy(troop => troop.endTime); foreach (var troop in ordered) { FactoryState newState = new FactoryState(lastState, troop); states.Add(newState); if (mockState == false) { if (newState.isAlly) { factory.armyAvailable = Math.Min(factory.armyAvailable, newState.count); } else { factory.armyAvailable = Math.Min(factory.armyAvailable, -newState.count); } } lastState = newState; } return(states); }
public static bool WillFactoryBeAlly(List <FactoryState> states) { FactoryState firstState = states.First(); bool allyLock = firstState.isAlly; for (int i = 0; i < states.Count; i++) { FactoryState state = states[i]; if (i + 1 < states.Count && state.gameTime == states[i + 1].gameTime) //if states occur at same time { continue; } if (allyLock && state.isEnemy) { return(false); } if (allyLock == false && state.isAlly) { allyLock = true; } } return(allyLock); }
// triggers starting public void Start(String bpName) { bPName = bpName; currentState = FactoryState.Starting; L.Debug("Extending pistons"); Extend(); }
public static void AddMission() { var orderedFactories = Factory.factories .OrderByDescending(factory => factory.stats.allyScore * factory.oldProduction); foreach (var factory in orderedFactories) { if (FactoryState.WillFactoryBeAlly(factory.states)) //if the factory will always be ally's { if (factory.production < 3 && factory.armyAvailable > 10) { Mission newMission = new Mission(MissionType.Inc, factory); newMission.EnlistTroops(); missions.Add(newMission); newMission.solver.Solve(); } } else { Mission newMission = new Mission(MissionType.Capture, factory); newMission.EnlistTroops(); missions.Add(newMission); newMission.solver.Solve(); //double missionScore = factory.stats.allyScore * factory.oldProduction; //Console.Error.WriteLine(factory.id + ": " + missionScore); //return; } } }
public static void ProcessFactoryStates() { foreach (var factory in factories) { factory.states = FactoryState.CalculateFactoryState(factory, factory.incoming.Values.ToList(), false); } }
public static List <Mission> CaptureFactories() { List <Mission> possibleMissions = new List <Mission>(); var factoryPrority = Factory.factories.Values .OrderByDescending(f => f.missionPrority * (f.oldProduction + 1)); bool setCaptureMission = false; //Defend all ally, and ally to be factories foreach (var factory in factoryPrority) { if (factory.oldProduction == 0 && factory.isAlly == false && factory.count + 1 > .025 * Factory.totalAllyCount) { continue; } //Console.Error.WriteLine(factory.id + ": " + factory.states.Last().count); if (FactoryState.WillFactoryBeAlly(factory.states)) //nothing to do here { if (factory.isAlly && factory.count > 10 && factory.oldProduction < 3) { if (factory.averageEnemyDistance > 7.5 && Factory.neutralTotalProduction == 0) { possibleMissions.Add(new Mission(MissionType.Inc, factory, 0)); } } else { double enemyCountPercent = factory.enemyCountWeighted / Factory.totalEnemyCountWeighted; int numRobots = (int)(Factory.totalAllyCount * enemyCountPercent); int diff = numRobots - factory.armyAvailable;//ally.count; if (factory.production < 3) { diff += 11; //account for increase production } if (diff > 0) { possibleMissions.Add(new Mission(MissionType.Reinforce, factory, diff)); } } } else { if (setCaptureMission == false || factory.team == Team.Neutral) { possibleMissions.Add(new Mission(MissionType.Capture, factory, 1)); setCaptureMission = true; } } } return(possibleMissions); }
public void UpdateFactoryState() { var pistonSpeed = pistons.Average(x => x.Velocity); var pistonExtended = pistons.Any(x => x.CurrentPosition == x.MaxLimit); var pistonRetracted = pistons.All(x => x.CurrentPosition == 0); var constructionPartial = merges.Any(x => x.IsConnected); var weldersOnline = welders.Any(x => x.Enabled); var sevenSecondsPassed = (DateTime.Now - LaunchStartTime).TotalSeconds > 7; switch (currentState) { case FactoryState.Unknown: FindCurrentState(); break; //triggers ready to build case FactoryState.Starting: L.Debug(pistonExtended + " Extended"); if (pistonExtended) { currentState = FactoryState.ReadyToBuild; } break; //triggers building case FactoryState.ReadyToBuild: Build(); currentState = FactoryState.Building; break; //triggers readyToLaunch case FactoryState.Building: if (pistonRetracted && constructionPartial) { currentState = FactoryState.ReadyToLaunch; } break; //calls launching case FactoryState.ReadyToLaunch: //Launch Called Remotly break; //triggers complete case FactoryState.Launching: if (sevenSecondsPassed) { currentState = FactoryState.Complete; } break; case FactoryState.Complete: //Start called remotly break; } }
private T FetchDatumIfNeeded(IBindingRequest localRequest) { if (state != FactoryState.NotCreatedYet) { return(datum !); } state = FactoryState.StaticCreationDone; return((T)(localRequest.IocService.Get(localRequest) ?? new InvalidOperationException("Failed to fetch datum"))); }
public static List <Mission> CaptureFactories() { List <Mission> possibleMissions = new List <Mission>(); var factoryPrority = Factory.factories.Values .OrderByDescending(f => f.missionPrority * (f.oldProduction + 1)); bool setCaptureMission = false; //Defend all ally, and ally to be factories foreach (var factory in factoryPrority) { if (factory.oldProduction == 0 && factory.isAlly == false && factory.count + 1 > .025 * Factory.totalAllyCount) { continue; } //Console.Error.WriteLine(factory.id + ": " + factory.states.Last().count); if (FactoryState.WillFactoryBeAlly(factory.states)) //nothing to do here { if (factory.isAlly && factory.count > 10 && factory.oldProduction < 3) { if (Factory.neutralTotalProduction == 0) { possibleMissions.Add(new Mission(MissionType.Inc, factory, 0)); } } else { int armyNeededForInc = 10 - factory.armyAvailable; if (factory.oldProduction < 3 && armyNeededForInc > 0) { possibleMissions.Add(new Mission(MissionType.Reinforce, factory, armyNeededForInc)); } } } else { if (setCaptureMission == false || factory.team == Team.Neutral) { possibleMissions.Add(new Mission(MissionType.Capture, factory, 1)); setCaptureMission = true; } } } return(possibleMissions); }
public static List <Mission> SendBomb() { List <Mission> possibleMissions = new List <Mission>(); if (Factory.totalEnemyCount == 0 || Game.bomb <= 0) { return(possibleMissions); } List <Factory> combinedList = Factory.enemy.Values.ToList(); combinedList.AddRange(Factory.neutral.Values); foreach (var factory in combinedList.OrderByDescending(f => f.production)) { if (factory.production == 0) { continue; } FactoryState lastState = factory.states.Last(); if (lastState.team == Team.Enemy) { //might send too early if (lastState.production >= Factory.enemyTotalProduction / 2) { bool alreadySent = false; foreach (var bomb in Bomb.bombs.Values) { if (bomb.team == Team.Ally) { if (bomb.end == factory) { alreadySent = true; break; } } } if (alreadySent == false) { possibleMissions.Add(new Mission(MissionType.Bomb, factory, lastState.gameTime)); } } } } return(possibleMissions); }
public static List <Mission> IncreaseAllyFactories() { List <Mission> possibleMissions = new List <Mission>(); foreach (var ally in Factory.ally.Values.OrderBy(f => f.production)) { FactoryState lastState = ally.states.Last(); if (lastState.team == ally.team && lastState.count > 10) { possibleMissions.Add(new Mission(MissionType.Inc, ally, 0)); } } return(possibleMissions); }
void FixedUpdate() { switch (_state) { case FactoryState.GENERATE: GenerateBehaviour(); _state = FactoryState.IDLE; break; case FactoryState.CLEAR: ClearBehaviour(); ResetBehaviour(); _state = FactoryState.IDLE; break; } }
public static FactoryState GetFactoryState(Factory factory, int gameTime) { List <FactoryState> states = factory.states; for (int i = states.Count - 1; i >= 0; i--) //count backwards to in case of states of same time { FactoryState state = states[i]; if (state.gameTime < gameTime) { return(state); } } return(states.Last()); }
public static void ProcessFactoryStates() { foreach (var factory in factories.Values) { FactoryState lastState = new FactoryState(factory.id, factory.team, factory.count, factory.production, Game.gameTime); factory.states.Add(lastState); //add atleast 1 state to the list var ordered = factory.incoming.Values.OrderBy(troop => troop.endTime); foreach (var troop in ordered) { FactoryState newState = new FactoryState(lastState, troop); factory.states.Add(newState); lastState = newState; } } }
private void FindCurrentState() { var rotorsnotreset = rotors.Where(x => (x.Angle / (float)Math.PI * 180f) != 0).Count(); var pistonsnotReset = pistons.Where(x => x.CurrentPosition != 0).Count(); if (rotorsnotreset > 0 && pistonsnotReset > 0) { currentState = FactoryState.Releasing; } if (rotorsnotreset == 0 && pistonsnotReset > 0) { currentState = FactoryState.Building; } if (rotorsnotreset == 0 && pistonsnotReset == 0) { currentState = FactoryState.ReadyToBuild; } }
public static List <Mission> DefendAllyFactories() { List <Mission> possibleMissions = new List <Mission>(); foreach (var ally in Factory.ally.Values) { if (ally.production == 0) { continue; } FactoryState lastState = ally.states.Last(); if (lastState.team != ally.team) { possibleMissions.Add(new Mission(MissionType.Defend, ally, lastState.count)); } } return(possibleMissions); }
//Member creation pattern private async Task FetchAndInitializeDatum(object[] parameters) { // make sure we do not get a torn request because SetRequest gets called on another thread. var localRequest = request; if (localRequest == null) { throw new InvalidOperationException("Binding Request has not been set."); } datum = FetchDatumIfNeeded(localRequest); if (datum == null) { throw new InvalidOperationException("Failed to fetch datum"); } if (localRequest.Run(datum, "Create", parameters) is Task task) { await task; } state = FactoryState.AsyncInitializationDone; }
public static List <Mission> CaptureEnemyFactories() { List <Mission> possibleMissions = new List <Mission>(); foreach (var factory in Factory.enemy.Values.OrderByDescending(f => f.production)) { if (factory.production == 0 && Factory.enemyTotalProduction != 0) { continue; } FactoryState lastState = factory.states.Last(); if (lastState.team != Team.Ally) //if enemy factory doesn't belong to ally in the last state { possibleMissions.Add(new Mission(MissionType.Capture, factory, lastState.count + 1)); } } return(possibleMissions); }
public static List <Mission> DefendAllyFactories() { List <Mission> possibleMissions = new List <Mission>(); foreach (var ally in Factory.ally.Values.OrderByDescending(f => f.production)) { if (ally.production == 0 && Factory.enemyTotalProduction != 0) { continue; } FactoryState lastState = ally.states.Last(); if (lastState.team != ally.team) { possibleMissions.Add(new Mission(MissionType.Defend, ally, lastState.count + 1)); } } return(possibleMissions); }
public static List <Mission> CaptureEnemyFactories() { List <Mission> possibleMissions = new List <Mission>(); foreach (var factory in Factory.enemy.Values) { if (factory.production == 0) { continue; } FactoryState lastState = factory.states.Last(); if (lastState.team != Team.Ally) //if neutral factory doesn't belong to ally in the last state { possibleMissions.Add(new Mission(MissionType.Capture, factory, lastState.count)); } } return(possibleMissions); }
public static bool WillFactoryBeAlly(List <FactoryState> states) { FactoryState firstState = states.First(); bool allyLock = firstState.isAlly; foreach (var state in states) { if (allyLock && state.isEnemy) { return(false); } if (allyLock == false && state.isAlly) { allyLock = true; } } return(allyLock); }
public Factory(string name, FactoryType factoryType, CelestialBody body, InventoryType inventoryType) { var inventory = new Inventory(inventoryType); _factoryState = new FactoryState(body, name, factoryType, inventory, 0); Receive <QueryState>(msg => { Sender.Tell(_factoryState); }); Receive <HeartBeatActor.FactoryTick>(msg => { Context.LogMessageDebug("Tick received"); var areInputRequirementsMet = AreInputRequirementsMet(); if (areInputRequirementsMet) { PerformTick(); } }); Receive <DepositResources>(msg => { var stateInventory = _factoryState.Inventory.Resources; var newItems = new Dictionary <IResource, int>(); foreach (var resource in msg.Resources.Keys) { if (stateInventory.ContainsKey(resource)) { newItems.Add(resource, stateInventory[resource] + msg.Resources[resource]); } else { newItems.Add(resource, msg.Resources[resource]); } } var newInventory = stateInventory.AddRange(newItems); _factoryState = new FactoryState(_factoryState.Body, _factoryState.Name, _factoryState.FactoryType, new Inventory(_factoryState.Inventory.InventoryType, newInventory), _factoryState.TicksSinceLastUpdate); }); }
public static bool IsFactoryCaptured(List <FactoryState> states) { Team originalTeam = states.First().team; for (int i = 0; i < states.Count; i++) { FactoryState state = states[i]; if (i + 1 < states.Count && state.gameTime == states[i + 1].gameTime) //if states occur at same time { continue; } if (originalTeam != state.team) { return(true); } } return(false); }
// Use this for initialization void Start() { print("PoFactory starting..."); _factoryState = FactoryState.Idle; GameManager.Instance.OnSinglePODataWithItemsChanged += OnSinglePODataWithItemsChanged; GameManager.Instance.OnMassListPOChanged += OnMassListPOChanged; // Store any generator locations defined as child objects of the factory _generatorLocations = new List<GameObject>(2); foreach (Transform child in transform) { if (child.gameObject.name.StartsWith("Generator_")) { _generatorLocations.Add(child.gameObject); } } // Game Gui, to tell it when we create, andto listen to when a new wave asked for GameObject go = GameObject.Find("GameGui"); if (go != null) { _gameGui = go.GetComponent<GameGui>(); _gameGui.OnNewWaveRequested += OnNewWaveRequested; } // and we're off! DoProductionRun(); }
private void CreatePoWithItems() { //------------------------------------------------------------------------- // Instatiate PO gameobject //------------------------------------------------------------------------- GameObject gParent = GameObject.FindWithTag("PoBucket"); Vector3 spawnPosition = _posToCreate[_posCreatedSoFar].Pos; Quaternion spawnRotation = _posToCreate[_posCreatedSoFar].Rot; spawnRotation.SetLookRotation(new Vector3(0, 270, 0)); GameObject g = (GameObject)Instantiate(PoTemplate, spawnPosition, spawnRotation); if (gParent != null) { g.transform.parent = gParent.transform; } // Scale float f = UnityEngine.Random.Range(0.85f, 1.15f); Vector3 adjustedScale = new Vector3(f, f, f); g.transform.localScale = adjustedScale; //------------------------------------------------------------------------- // Fill PO with its PO business data //------------------------------------------------------------------------- EpmPoDataWithItems powi = GameManager.Instance.GetEpmResponse_SinglePOWithItems(); //powi.PrintToConsole(); PoManager pom = g.GetComponent<PoManager>(); pom.PoBusinessDataWithItems = powi; //------------------------------------------------------------------------- // Change its texture //------------------------------------------------------------------------- Texture2D tex = PoTexturesMaster.GetPoTextureForProductId(powi.PoItems[0].ProductId); if (tex == null) { print("WARNING could not find PO texture called " + powi.PoItems[0].ProductId); tex = PoTexturesMaster.HT_1000; // just default to something } g.GetComponent<Renderer>().material.mainTexture = tex; // Set the tint Color tint = PoProdCategoriesMaster.GetTintForProductCategory(powi.PoItems[0].ProductCategory); g.GetComponent<Renderer>().material.color = tint; //------------------------------------------------------------------------- // PO behaviour //------------------------------------------------------------------------- EpmPoBehaviour pob = new EpmPoBehaviour() { movementType = _posToCreate[_posCreatedSoFar].MoveType, PreRocketWarmUpTime = 2f }; pom.PoBehaviour = pob; // Tell Gui if (_gameGui != null) { _gameGui.PoCreated(); } // Have we created all the POs? _posCreatedSoFar++; if (_posCreatedSoFar < _actualPoHeaderCount) { Invoke("AskForPoData", PoCreateDelayInSeconds); } else { // factory is idle _factoryState = FactoryState.Idle; } }
/// <summary> /// Do a production run of POs. /// </summary> private void DoProductionRun() { // init the factory and spawn POs _factoryState = FactoryState.Working; _posCreatedSoFar = 0; print("Po Factory is starting a production run"); GameManager.Instance.GetEpmData_MassListPO(DesiredPoItemCount); }