private bool TryNewGoalAttack() { if (monster.baseMoves.Count == 0) { return(false); } goalState = GoalState.BasicAttack; float minDist = 1000f; foreach (Unit unit in board.units) { float dist = currentTile.DistanceTo(unit.currentTile); if (unit.team != team && unit.IsAlive() && dist <= minDist) { attackTarget = unit; minDist = dist; } } if (attackTarget == null) { return(false); } return(true); }
void Start() { //HostOptions host; //foreach (HostOptions hostOptions in FindObjectsOfType<HostOptions>()) //{ // if (hostOptions.isHost) // { // host = hostOptions; // repairTimerMax = host.repairTime; // repairValue = host.repairValue; // sabotageTime = host.taskSpeed + host.taskSpeed / 4; // } //} myTask = GetComponent <Task>(); myTask.spyMinimapObj.SetActive(false); myTask.myTaskType = Task.TaskType.pile; //testTimer = testTimerSet; repairTimer = 0; objectsPlaced = 0; myState = GoalState.inProgress; myTask.done = false; myTask.percentage = 0; myTask.sabotaged = sabotaged; if (serverOnly == null && FindObjectOfType <ServerOnlyScript>()) { serverOnly = FindObjectOfType <ServerOnlyScript>(); } }
private bool TryNewGoalSpecial() { int newCount = (specialMoveCount + 1) % monster.specMoves.Count; if (monster.specMoves.Count == 0 || currentEnergy < monster.specMoves[newCount].EnergyCost()) { return(false); } specialMoveCount = newCount; goalState = GoalState.SpecialAttack; float minHp = 1000f; foreach (Unit unit in board.units) { float hp = unit.currentHealth / (float)unit.monster.MaxHealth(); if (unit.team != team && unit.IsAlive() && hp <= minHp) { attackTarget = unit; minHp = hp; } } if (attackTarget == null) { return(false); } return(true); }
/// <summary> /// Executes counterfactual thinking about most important agent goal for specific site /// </summary> /// <param name="agent"></param> /// <param name="lastIteration"></param> /// <param name="goal"></param> /// <param name="matched"></param> /// <param name="layer"></param> /// <param name="site"></param> /// <returns></returns> public bool Execute(IAgent agent, LinkedListNode <Dictionary <IAgent, AgentState> > lastIteration, Goal goal, Rule[] matched, RuleLayer layer, ActiveSite site) { confidence = false; //Period currentPeriod = periodModel.Value; AgentState priorIterationAgentState = lastIteration.Previous.Value[agent]; selectedGoal = goal; selectedGoalState = lastIteration.Value[agent].GoalsState[selectedGoal]; RuleHistory history = priorIterationAgentState.RuleHistories[site]; activatedRule = history.Activated.First(r => r.Layer == layer); anticipatedInfluences = agent.AnticipationInfluence; matchedRules = matched; SpecificLogic(selectedGoal.Tendency); return(confidence); }
// use this to initialize any game specific logic public void StartChallenge() { IsStarted = true; goalState = Instantiate(goalState); failState = Instantiate(failState); Debug.Log("chellege staert"); }
public static void TryCompleteGoal(AIContext context, GoalState endOfGoal, EffectType type) { if (context.HasGoal(endOfGoal)) { context.SetGoal(GoalState.None, true, type); } }
GameStateBase getState(GameState state) { GameStateBase gameState; if (states.TryGetValue(state, out gameState)) { return(gameState); } switch (state) { case GameState.Enter: gameState = new GameEnterState(this); break; case GameState.Ready: gameState = new GameReadyState(this); break; case GameState.Gaming: gameState = new GamingState(this); break; case GameState.Goal: gameState = new GoalState(this); break; case GameState.Replay: gameState = new ReplayState(this); break; case GameState.Over: gameState = new GameOverState(this); break; } states.Add(state, gameState); return(gameState); }
void Start() { repairTimer = 0; objectsPlaced = 0; myState = GoalState.inProgress; done = false; }
public void PlanAndExecute(Bot bot, InternalState internalState) { bot.GetCurrentGoal().FlushCurrentActions(); GoalState goalWithInternalState = bot.GetGoals().Find(goal => goal.internalState == internalState); PlanAndExecute(bot, goalWithInternalState); }
/// <summary> /// Executes counterfactual thinking about most important agent goal for specific site /// </summary> /// <param name="agent"></param> /// <param name="lastIteration"></param> /// <param name="goal"></param> /// <param name="matched"></param> /// <param name="layer"></param> /// <param name="site"></param> /// <returns></returns> public bool Execute(IAgent agent, LinkedListNode <Dictionary <IAgent, AgentState <TSite> > > lastIteration, Goal goal, DecisionOption[] matched, DecisionOptionLayer layer, TSite site) { //Period currentPeriod = periodModel.Value; AgentState <TSite> priorIterationAgentState = lastIteration.Previous.Value[agent]; selectedGoal = goal; selectedGoalState = lastIteration.Value[agent].GoalsState[selectedGoal]; selectedGoalState.Confidence = false; DecisionOptionsHistory history = priorIterationAgentState.DecisionOptionsHistories[site]; activatedDecisionOption = history.Activated.FirstOrDefault(r => r.Layer == layer); anticipatedInfluences = agent.AnticipationInfluence; matchedDecisionOptions = matched; SpecificLogic(selectedGoal.Tendency); return(selectedGoalState.Confidence); }
public async Task UpdateTitleTest(string title, string description, int goalNumber, int projectId, GoalState state, GoalPriority priority) { //Arrange int goalId = 1; var vmGoal = new VmGoal { Id = goalId, Title = title, Description = description, ProjectId = projectId, State = state, Priority = priority, GoalNumber = goalNumber, IsRemoved = true }; //Act await _service.Update(_currentUser, vmGoal); var goal = _dataContext.Goals.First(g => g.Id == goalId); //Assert Assert.AreEqual(title, goal.Title); Assert.AreEqual(description, goal.Description); Assert.AreEqual(projectId, goal.ProjectId); Assert.AreEqual(priority, goal.Priority); Assert.AreEqual(state, goal.State); Assert.AreEqual(0, (goal.CreationDate - DateTime.Now).TotalMinutes, 1); Assert.IsFalse(goal.IsRemoved); }
/// <summary> /// Calculates normalized value for goal prioritizing. /// </summary> /// <param name="goalIndex"></param> /// <param name="goal"></param> /// <param name="goalState"></param> /// <returns>Reative importance level adjustement value.</returns> private double CalculateRelativeImportanceLevelAdjustment(Goal goal, GoalState goalState) { var value = goalState.Value; var focalValue = goalState.FocalValue; var priorValue = goalState.PriorValue; var gainLossMapping = _config.GainAndLossToValue[goal.Name]; switch (goal.Tendency) { case GoalTendency.Maximize: { if (priorValue == 0.0) { return(1.0); } var loss = Math.Min(0.0, value / priorValue - 1.0); return(1.0 - FindNearestValue(gainLossMapping.LossToValue, loss)); } case GoalTendency.EqualToOrAboveFocalValue: { if (focalValue == 0.0) { return(1.0); } var loss = Math.Min(0.0, value / focalValue - 1.0); return(1.0 - FindNearestValue(gainLossMapping.LossToValue, loss)); } case GoalTendency.MaintainAtValue: { if (focalValue == 0.0) { return(1.0); } var k = value / focalValue; return((k >= 1.0) ? 1.0 + FindNearestValue(gainLossMapping.GainToValue, k - 1.0) : 1.0 - FindNearestValue(gainLossMapping.LossToValue, k - 1.0)); } case GoalTendency.Minimize: { if (priorValue == 0.0) { return(1.0); } var loss = Math.Max(0.0, value / priorValue - 1.0); return(1.0 - FindNearestValue(gainLossMapping.LossToValue, loss)); } default: { throw new SosielAlgorithmException( "Cannot calculate relative difference between goal value and focal" + $" goal value for goal tendency {goal.Tendency}"); } } }
public Goal(Vector2 pos, Sound sound) : base("goal", pos, Vector2.Zero, true, "Goal") { this.sound = sound; //by柏 2016.12.14 SE実装 state = GoalState.NONE; alpha = 0; animePlayer = new AnimationPlayer(); goalAnime = new Animation(Renderer.GetTexture("goalAnime"), 0.6f, true); }
public override void Load(LoadObjectStore ObjectStore) { base.Load(ObjectStore); _State = ObjectStore.LoadGoalState("state"); foreach (var Goal in ObjectStore.LoadGoals("sub-goals")) { _SubGoals.Add(Goal); } }
public void TryCreateTest() { GoalState result; Assert.IsTrue(GoalState.TryCreate(new Uri(GoalStateTest.DefaultGoalStateFileUrl, UriKind.Absolute), new TraceLogger(new MockUpTraceEventProvider()), out result)); Assert.IsTrue(result.Packages.Any()); Assert.IsFalse(GoalState.TryCreate(new Uri("http://6532A867-8DC0-4A2F-8870-95FB567664A9.com", UriKind.Absolute), new TraceLogger(new MockUpTraceEventProvider()), out result)); }
void InProgressState() { whatDoINeed = "Leaf"; UpdatePile(); if (objectsPlaced >= objectsNeeded) { myState = GoalState.done; } }
public void ResetUnit() { currentHealth = monster.MaxHealth(); currentEnergy = 0; specialMoveCount = -1; goalState = GoalState.None; actionState = ActionState.Wait; MoveToTile(startingTile); }
public List <Action> FindActionsForGoal(Bot bot, GoalState goalState) { List <Action> actionSequence = FindActionsForWorldState(bot, goalState.internalState); actionSequence.Reverse(); Debug.Log("[Planner] Found sequence with " + actionSequence.Count + " actions"); return(actionSequence); }
// use this to initialize any game specific logic public void StartChallenge() { //goalState.enabled = true; //failState.enabled = true; IsStarted = true; this.gameObject.SetActive(true); goalState = GetComponent<GoalState>(); failState = GetComponent<FailState>(); Debug.Log("chellege staert"); }
/// <summary> /// Creates agent instance based on agent archetype and agent configuration. /// </summary> /// <param name="agentConfiguration"></param> /// <param name="archetype"></param> /// <returns></returns> public static SosielHarvestAgent Create( AgentStateConfiguration agentConfiguration, AgentArchetype archetype, string name) { var agent = new SosielHarvestAgent(); agent.Id = name; agent.Archetype = archetype; agent.privateVariables = new Dictionary <string, dynamic>(agentConfiguration.PrivateVariables); agent.AssignedDecisionOptions = archetype.DecisionOptions.Where( r => agentConfiguration.AssignedDecisionOptions.Contains(r.Name)).ToList(); agent.AssignedGoals = archetype.Goals.Where( g => agentConfiguration.AssignedGoals.Contains(g.Name)).ToList(); agent.AssignedDecisionOptions.ForEach( decisionOption => agent.DecisionOptionActivationFreshness.Add(decisionOption, 1)); // Generates goal importance. agentConfiguration.GoalStates.ForEach(kvp => { var goalName = kvp.Key; var config = kvp.Value; var goal = agent.AssignedGoals.FirstOrDefault(g => g.Name == goalName); if (goal != null) { var goalState = new GoalState(goal, agent, config.Value, config.FocalValue, config.Importance, config.MinValue, config.MaxValue, config.MinValueReference, config.MaxValueReference); agent.InitialGoalStates.Add(goal, goalState); } }); // Initializes initial anticipated influence for each kh and goal assigned to the agent agent.AssignedDecisionOptions.ForEach(decisionOption => { Dictionary <string, double> source; if (decisionOption.AutoGenerated && agent.Archetype.DoNothingAnticipatedInfluence != null) { source = agent.Archetype.DoNothingAnticipatedInfluence; } else { agentConfiguration.AnticipatedInfluenceState.TryGetValue(decisionOption.Name, out source); } var inner = new Dictionary <Goal, double>(); agent.AssignedGoals.ForEach(g => { inner.Add(g, source != null && source.ContainsKey(g.Name) ? source[g.Name] : 0); }); agent.AnticipationInfluence.Add(decisionOption, inner); }); InitializeDynamicVariables(agent); agent.AgentStateConfiguration = agentConfiguration; return(agent); }
public ActionResult <GoalState> Post([FromBody] GoalState model) { var serviceResult = _goalStateService.Create(model); if (serviceResult.Status == BrashActionStatus.ERROR) { return(BadRequest(serviceResult.Message)); } return(serviceResult.Model); }
public void SwitchPlan() { if (mGoalState == m_CalmState) { mGoalState = m_AggressiveState; } else { mGoalState = m_CalmState; } }
public Goal(string id, string title, string description, GoalState state, Assignee assignee = null) { Id = id; Title = title; Description = description; State = state; Assignee = assignee; }
void RepairMe() { if (repairTimer >= repairTimerMax) { sabotaged = false; myState = GoalState.inProgress; repairTimer = 0; } else { repairTimer += Time.deltaTime; } }
public override void Initialize() { base.Initialize(); state = GoalState.NONE; alpha = 0; isComplete = false; isOnFire = false; //葉梨竜太 signpos = position - new Vector2(0, 64); startpos = signpos; endpos = startpos - new Vector2(0, 32); signvelo = new Vector2(0, 1); }
public void PlanAndExecute(Bot bot, GoalState goalState) { Debug.Log("[Planner] Planning for : " + bot + " with goalstate : " + goalState.internalState); if (!goalState) { Debug.Log("ERROR : CANNOT FIND A GOAL FOR THAT INTERNAL STATE!"); } goalState.SetActionSequence(FindActionsForGoal(bot, goalState)); goalState.Initialize(bot, this); bot.SetGoalStateAndExecute(goalState); }
public void IntegrationTest() { TraceLogger traceLogger = new TraceLogger(new MockUpTraceEventProvider()); Uri goalStateFileUri = this.PrepareTargetGoalStateFile(); ProgramConfig config = new ProgramConfig( ProgramParameterDefinitions.ExecutionModes.Service, new AppConfig( new Uri("http://localhost", UriKind.Absolute), null, TestUtility.TestDirectory + "\\Data", goalStateFileUri, TimeSpan.FromSeconds(3000), TimeSpan.FromSeconds(3000))); UpdateServicelet server = new UpdateServicelet(config, traceLogger); server.Start(); // ensure that the packages have been downloaded Thread.Sleep(10000); GoalState goalState; Assert.IsTrue(GoalState.TryCreate(new Uri("http://localhost/api/files/goalstate", UriKind.Absolute), server.Logger, out goalState)); string packageDownloadDstDirectory = TestUtility.TestDirectory + "\\DownloadDstDir"; if (!Directory.Exists(packageDownloadDstDirectory)) { Directory.CreateDirectory(packageDownloadDstDirectory); } TaskManager tskMgr = new TaskManager(traceLogger); foreach (PackageDetails package in goalState.Packages) { string fileName = new Uri(package.TargetPackageLocation).Segments.Last(); tskMgr.AddTask(Utility.DownloadFileAsync(package.TargetPackageLocation, packageDownloadDstDirectory + "\\" + fileName)); } Assert.IsTrue(tskMgr.WaitForAllTasks()); Assert.AreEqual(5, Directory.GetFiles(TestUtility.TestDirectory + "\\Data\\UpdateService\\Packages", "*.cab", SearchOption.TopDirectoryOnly).Length); server.Stop(); Assert.IsFalse(GoalState.TryCreate(new Uri("http://localhost/api/files/goalstat", UriKind.Absolute), server.Logger, out goalState)); Directory.Delete(TestUtility.TestDirectory + "\\Data", recursive: true); File.Delete(TestUtility.TestDirectory + "\\WsusIntegration.json"); Directory.Delete(packageDownloadDstDirectory, recursive: true); }
/// <summary> /// Calculates normalized value for goal prioritizing. /// </summary> /// <param name="agent"></param> /// <param name="goal"></param> /// <param name="goalState"></param> /// <returns></returns> double CalculateRelativeDifference(IAgent agent, Goal goal, GoalState goalState) { double goalValue = goalState.Value; double focalValue = goalState.FocalValue; double priorValue = goalState.PriorValue; double priorFocalValue = goalState.PriorFocalValue; if (goal.Tendency == GoalTendency.Maximize) { if (priorFocalValue - priorValue == 0) { return(1); } return(Math.Max(1, (focalValue - goalValue) / (priorFocalValue - priorValue))); } if (goal.Tendency == GoalTendency.EqualToOrAboveFocalValue) { if (priorFocalValue - priorValue == 0) { return(1); } return(Math.Max(1, (focalValue - goalValue) / (priorFocalValue - priorValue))); } if (goal.Tendency == GoalTendency.MaintainAtValue) { if (priorFocalValue - priorValue == 0) { return(1); } return(Math.Max(1, Math.Abs(focalValue - goalValue) / Math.Abs(priorFocalValue - priorValue))); } if (goal.Tendency == GoalTendency.Minimize) { if (priorValue - priorFocalValue == 0) { return(1); } return(Math.Max(1, (goalValue - focalValue) / (priorValue - priorFocalValue))); } throw new SosielAlgorithmException( "Cannot calculate relative difference between goal value and focal goal value for tendency" + goal.Tendency); }
public void SerializeTest() { GoalState result; Assert.IsTrue(GoalState.TryCreate(new Uri(TestUtility.TestDirectory + "\\goalstate.json", UriKind.Absolute), new TraceLogger(new MockUpTraceEventProvider()), out result)); Assert.IsTrue(result.Packages.Any()); string newJsonPath = TestUtility.TestDirectory + "\\goalstate222.json"; string content = result.Serialize(); File.WriteAllText(newJsonPath, content); Assert.IsTrue(GoalState.TryCreate(new Uri(newJsonPath, UriKind.Absolute), new TraceLogger(new MockUpTraceEventProvider()), out result)); Assert.IsTrue(result.Packages.Any()); }
protected override void Awake() { base.Awake(); _targetState = TargetState.ALIVE; _goalState = GoalState.NEUTRAL; _pointState = PointState.NEUTRAL; ZMSoul.SoulDestroyedEvent += HandleSoulDestroyedEvent; ZMPedestalController.OnDeactivateEvent += HandlePedestalDeactivation; MatchStateManager.OnMatchEnd += HandleGameEndEvent; }
public void Sabotager(float i) { if (myState == GoalState.inProgress) { Debug.Log(i / 5); spyCanvas.GetComponentInChildren <Image>().fillAmount = i / 5; if (i / 5 >= 1) { sabotaged = true; spyCanvas.GetComponentInChildren <Image>().fillAmount = 0; myState = GoalState.sabotaged; } } }
public ActionResult <GoalState> Delete(int id) { var model = new GoalState() { GoalStateId = id }; var serviceResult = _goalStateService.Delete(model); if (serviceResult.Status == BrashActionStatus.ERROR) { return(BadRequest(serviceResult.Message)); } return(serviceResult.Model); }
protected void Log(GoalState state) { string logMsg = ""; logMsg += "@ " + name + " > "; switch (state) { case GoalState.Active: logMsg += "active"; break; case GoalState.Failed: logMsg += "fail - " + map.GetLastError(); break; case GoalState.Completed: logMsg += "completed"; break; } for (int loop1 = 0; loop1 < depth; loop1++) { logMsg = " " + logMsg; } Log(logMsg); }
/// <summary>Gets or sets the Trigger Status strings</summary> /// <remarks><i>value</i> is limited to 63 characters</remarks> /// <param name="trigger">The Trigger index, 0-3</param> /// <param name="state"><see cref="GoalState"/> value</param> /// <exception cref="IndexOutOfRangeException">Invalid <i>trigger</i> value</exception> public string this[int trigger, GoalState state] { get { return _owner._strings[trigger, (int)state]; } set { _owner._strings[trigger, (int)state] = Idmr.Common.StringFunctions.GetTrimmed(value, 63); } }
/// <summary>Gets or sets the Trigger Status strings</summary> /// <remarks>Limited to 63 characters</remarks> /// <param name="state">GoalState value, 0-2</param> /// <exception cref="IndexOutOfRangeException">Invalid <i>state</i> value</exception> public string this[GoalState state] { get { return _strings[(int)state]; } set { _strings[(int)state] = StringFunctions.GetTrimmed(value, 63); } }
/// <summary> /// Starts a countdown to register the goal as tripped. /// </summary> IEnumerator BeginTrippedTimer(float delay) { yield return new WaitForSeconds(delay); currentState = GoalState.Tripped; yield break; }
void GenerateNewTask() { int Pop = 0, ARes = 0, Scout = 0, Hous = 0, Edu = 0,Spec = 0 , Money = 0, Trade = 0, War = 0; // first we count the number of objectives already set with specific types, so we dont focus only on one type all the time int ObjCap = Mathf.CeilToInt(MaxTasks *0.4f); // maximum of 40% of tasks dedicated to one objective type foreach(var obj in CurrentObj) { if (obj.Type == ObjectiveTypes.GoToWar) War++; else if (obj.Type == ObjectiveTypes.IncreaseAdvResources) ARes++; else if (obj.Type == ObjectiveTypes.IncreaseEducation) Edu++; else if (obj.Type == ObjectiveTypes.IncreaseHousing) Hous++; else if (obj.Type == ObjectiveTypes.IncreaseMoney) Money++; else if (obj.Type == ObjectiveTypes.IncreasePopulation) Pop++; else if (obj.Type == ObjectiveTypes.IncreaseSpecialistBuilding) Spec++; else if (obj.Type == ObjectiveTypes.ScoutArea) Scout++; else if (obj.Type == ObjectiveTypes.TradeResources) Trade++; } // now we take stock of what we have, to deciede what we need int TotPop = 0, Labs = 0, Rifle = 0, Trader = 0, BlacksP = 0, Mine = 0, Lumber = 0, Carp = 0, Turf = 0, House = 0, Scho = 0, Barr = 0, Stora = 0, MineB = 0, Smelt = 0, Quar = 0, Saw = 0, BlacksB = 0, Mark = 0, TotBuild = 0; foreach(var villager in Villagers) { TotPop++; // total population if (villager.Skill == Villager.Skills.Labourer) Labs++; else if (villager.Skill == Villager.Skills.Blacksmith) BlacksP++; else if (villager.Skill == Villager.Skills.Carpenter) Carp++; else if (villager.Skill == Villager.Skills.Lumberjack) Lumber++; else if (villager.Skill == Villager.Skills.Miner) Mine++; else if (villager.Skill == Villager.Skills.Rifleman) Rifle++; else if (villager.Skill == Villager.Skills.Trader) Trader++; } foreach(var building in Buildings) { if (building.Type == Building.BuildingType.Barracks) Barr++; else if (building.Type == Building.BuildingType.Blacksmith) BlacksB++; else if (building.Type == Building.BuildingType.House) House++; else if (building.Type == Building.BuildingType.Market) Mark++; else if (building.Type == Building.BuildingType.Mine) MineB++; else if (building.Type == Building.BuildingType.Quarry) Quar++; else if (building.Type == Building.BuildingType.Sawmill) Saw++; else if (building.Type == Building.BuildingType.School) Scho++; else if (building.Type == Building.BuildingType.Smelter) Smelt++; else if (building.Type == Building.BuildingType.Storage) Stora++; else if (building.Type == Building.BuildingType.Turf) Turf++; } TotBuild = Barr + BlacksB + House + Mark + MineB + Quar + Saw + Scho + Smelt + Stora + Turf; // and finally we take stock of the items int stone = 0 , wood = 0 , iron = 0 , timber = 0, ore = 0, coal = 0, axe = 0, cart = 0, RifleI = 0, MoneyI = 0, goods = 0; foreach (var villager in Villagers) { if (villager.Inventory == Villager.Items.Axe) axe++; else if (villager.Inventory == Villager.Items.Cart) cart++; else if (villager.Inventory == Villager.Items.Coal) coal++; else if (villager.Inventory == Villager.Items.Goods) goods++; else if (villager.Inventory == Villager.Items.Iron) iron++; else if (villager.Inventory == Villager.Items.Money) MoneyI++; else if (villager.Inventory == Villager.Items.Ore) ore++; else if (villager.Inventory == Villager.Items.Rifle) RifleI++; else if (villager.Inventory == Villager.Items.Stone) stone++; else if (villager.Inventory == Villager.Items.Timber) timber++; else if (villager.Inventory == Villager.Items.Wood) wood++; } foreach(var building in Buildings) { foreach(var item in building.Items) { if (item == Villager.Items.Axe) axe++; else if (item == Villager.Items.Cart) cart++; else if (item == Villager.Items.Coal) coal++; else if (item == Villager.Items.Goods) goods++; else if (item == Villager.Items.Iron) iron++; else if (item == Villager.Items.Money) MoneyI++; else if (item == Villager.Items.Ore) ore++; else if (item == Villager.Items.Rifle) RifleI++; else if (item == Villager.Items.Stone) stone++; else if (item == Villager.Items.Timber) timber++; else if (item == Villager.Items.Wood) wood++; } } //IncreasePopulation, // Chosen when the number of labourers in less than 10 % pop increased untill labourers more than 25% //IncreaseAdvResources, // chosen when rifles less than 2 x riflemen //ScoutArea, // only active after pop is more than 10 , then activated when ???????? probs not gonna add it //IncreaseHousing, // when villagers / 2 less than current number of houses //IncreaseEducation, // when specialists are less than specialist building i.e 0 blacksmith pop but 1 blacksmith //IncreaseSpecialistBuilding, // will build specialist buildings, such as blacksmith sawmill //IncreaseMoney, // when No of resources is more than 20 x no of villagers //TradeResources, // kinda same as above might need rework ... will need rework //GoToWar, // not implementing yet // now we are ready to gen the task // order task are in order of which i believe are important // continue to add tasks until the cap is reached int noneselected = 1; // this var is added to combat infinite loops, will reduce the requirements to activate a task until a task is met bool NeedTree = false; while (CurrentObj.Count < MaxTasks && noneselected < 20 && AvailableVillagers.Count > 0) { List<Villager.Skills> NeededSkills = new List<Villager.Skills>(); ObjectiveTypes newObj = new ObjectiveTypes(); GoalState newGoal = new GoalState(); newGoal.NewBuildings = Building.BuildingType.None; newGoal.NewSkills = new List<Villager.Skills>(); // Need to add a case for FORCED waiting to breed if( TotPop <= Mathf.FloorToInt(TotBuild * 0.75f)&& (House > 0 || Turf > 0)) // Increase Pop { // we need to gen a current state / decide what is going to be used here. newObj = ObjectiveTypes.IncreasePopulation; newGoal.AddNewSkills(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Any); NeededSkills.Add(Villager.Skills.Any); Pop++;// this SHOULD continually fail the second check until 2 vills are avaliable } else if (ARes < ObjCap && BlacksB > 0 && BlacksP > 0) // IncreaseAdvResources -rifles /carts axes { newObj = ObjectiveTypes.IncreaseAdvResources; if(RifleI < Rifle ) { newGoal.NewItems.Add( Villager.Items.Rifle); ARes++; NeededSkills.Add(Villager.Skills.Blacksmith); } } else if (Turf+House < TotPop/2 && Hous < ObjCap) // IncreaseHousing { newObj = ObjectiveTypes.IncreaseHousing; if(Quar>0) // build house { newGoal.NewBuildings = Building.BuildingType.House; var building = GenerateBuildingSite(Building.BuildingType.House); newGoal.Site = building; NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Lumberjack); NeededSkills.Add(Villager.Skills.Carpenter); Buildings.Add(building); Hous++; } else // build turf { newGoal.NewBuildings = Building.BuildingType.Turf; var building = GenerateBuildingSite(Building.BuildingType.Turf); newGoal.Site = building; NeededSkills.Add(Villager.Skills.Labourer); Buildings.Add(building); Hous++; } } else if (Edu < ObjCap) // IncreaseEducation { newObj = ObjectiveTypes.IncreaseEducation; // we want ratios of people // 25 % labour // 20% lumber // 20% miner // 20% blacksmith // 15% rifle if(Lumber < Mathf.CeilToInt(0.2f * TotPop)) { newGoal.NewSkills.Add(Villager.Skills.Lumberjack); NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Any); Edu++; } else if (Mine < Mathf.CeilToInt(0.2f * TotPop)) { newGoal.NewSkills.Add(Villager.Skills.Miner); NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Any); Edu++; } else if (BlacksP < Mathf.CeilToInt(0.2f * TotPop)) { newGoal.NewSkills.Add(Villager.Skills.Blacksmith); NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Any); Edu++; } else if (Rifle < Mathf.CeilToInt(0.15f * TotPop)) { newGoal.NewSkills.Add(Villager.Skills.Rifleman); NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Any); Edu++; } } else if (Spec < ObjCap) // IncreaseSpecialistBuilding { newObj = ObjectiveTypes.IncreaseSpecialistBuilding; if (Smelt > 0 && Quar > 0) { if(Scho == 0) // build school { newGoal.NewBuildings = Building.BuildingType.School; var building = GenerateBuildingSite(Building.BuildingType.School); newGoal.Site = building; NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Lumberjack); NeededSkills.Add(Villager.Skills.Carpenter); Buildings.Add(building); Spec++; } else if (BlacksB <(BlacksP*2)) // build blacksmith { newGoal.NewBuildings = Building.BuildingType.Blacksmith; var building = GenerateBuildingSite(Building.BuildingType.Blacksmith); newGoal.Site = building; NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Miner); Buildings.Add(building); Spec++; } else if(Saw < Mathf.CeilToInt(0.05f*TotPop)) // build sawmill { newGoal.NewBuildings = Building.BuildingType.Sawmill; var building = GenerateBuildingSite(Building.BuildingType.Sawmill); newGoal.Site = building; NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Miner); Buildings.Add(building); Spec++; } else if (Barr < Mathf.CeilToInt(0.05f * TotPop)) { newGoal.NewBuildings = Building.BuildingType.Barracks; var building = GenerateBuildingSite(Building.BuildingType.Barracks); newGoal.Site = building; NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Carpenter); NeededSkills.Add(Villager.Skills.Lumberjack); Buildings.Add(building); Spec++; } else if (Stora < Mathf.CeilToInt(0.05f * TotPop)) { newGoal.NewBuildings = Building.BuildingType.Storage; var building = GenerateBuildingSite(Building.BuildingType.Storage); NeededSkills.Add(Villager.Skills.Labourer); NeededSkills.Add(Villager.Skills.Carpenter); NeededSkills.Add(Villager.Skills.Lumberjack); newGoal.Site = building; Buildings.Add(building); Spec++; } else if (Mark < Mathf.CeilToInt(0.05f * TotPop)) { newGoal.NewBuildings = Building.BuildingType.Market; NeededSkills.Add(Villager.Skills.Carpenter); NeededSkills.Add(Villager.Skills.Lumberjack); var building = GenerateBuildingSite(Building.BuildingType.Market); newGoal.Site = building; Buildings.Add(building); Spec++; } } else if (Quar > 0) // build smelter { newGoal.NewBuildings = Building.BuildingType.Smelter; NeededSkills.Add(Villager.Skills.Labourer); var building = GenerateBuildingSite(Building.BuildingType.Smelter); newGoal.Site = building; Buildings.Add(building); Spec++; } else // build quarry { newGoal.NewBuildings = Building.BuildingType.Quarry; NeededSkills.Add(Villager.Skills.Labourer); var building = GenerateBuildingSite(Building.BuildingType.Quarry); newGoal.Site = building; Buildings.Add(building); Spec++; } } else noneselected++; if (NeededSkills.Count != 0) if (GenerateGameState(NeededSkills, ref newGoal.GameState, NeedTree)) PassGoal(newGoal, newObj); else noneselected++; if (noneselected >= 20) return; // no objective set } }
/// <summary> /// Launched once the ball has fixed into position in the center of the goal. /// </summary> void EnterLockedObjectState() { currentState = GoalState.LockedObject; // Change State BeginColorFade(fadeToColTime); // Fade Color BeginAngularRotationStopper(angularSlowdownTime); // Stop Angular Momentum StartCoroutine(BeginTrippedTimer(tripDelay)); // Start timer to register tripped }
/// <summary> /// Triggered when an object collides with the goal. /// </summary> /// <param name="coll"></param> void OnTriggerEnter2D(Collider2D coll) { if(selectedObjectRb != null) { return; // Goal is already filled. } ObjectColor otherColor = coll.gameObject.GetComponent<ObjectColor>(); if (otherColor != null && objColor.CheckSameColor(otherColor)) { currentState = GoalState.PullingObject; selectedObject = coll.gameObject; if (selectedObject != null) { selectedObjectRb = selectedObject.GetComponent<Rigidbody2D>(); } } }
void PassGoal(GoalState goal, ObjectiveTypes Type) { ObjectiveTasks newTask = new ObjectiveTasks(); newTask.Type = Type; newTask.PathID = -1; newTask.TaskID = TaskPlanner.RequestTask(goal); newTask.BuildingSite = goal.Site; newTask.Stepsneeded = new List<TaskPlanning.Task>(); Debug.Log("new task created Type : " + Type.ToString()); CurrentObj.Add(newTask); }