private void Start() { foreach (GameObject agentOther in GameObject.FindGameObjectsWithTag("agent")) { _numberOfAgent += 1; } _listenAnOtherAgent = new bool[_numberOfAgent]; SilenceDialogue(); _agent = GetComponent(typeof(NavMeshAgent)) as NavMeshAgent; _code = PRE_CODE + 1; _currentState = AgentStates.Start; PRE_CODE = _code; _animator = GetComponent <Animator>(); _camera.enabled = false; _canvas.enabled = false; _boolStartTrust = true; _checkPile = false; _currentDialogue = Discussion.NothingToSay; _randomDirection = Random.Range(0, 4); _numberOfBatteryByPlace = new int[4]; _actualInteractionAgent = null; _doneHistoric = false; if (_fluctuationTrust > 10 && _fluctuationTrust < 0) { _fluctuationTrust = 5; } _countDown = _countDownUtilisateur; }
// Use this for initialization void Awake() { _states = GetComponent <AgentStates> (); _inventory = GetComponent <AgentInventory> (); _pheromonePlacement = GetComponent <AntPheromonePlacement> (); _navHelper = GetComponent <NavAgentHelper> (); }
private void ExecuteSaveAgentStateCommand(object obj) { AgentProgressInfo = string.Format("Saving Agent States..."); ShowAll = Visibility.Collapsed; ShowAgentProgress = Visibility.Visible; AgentVisibility = Visibility.Collapsed; System.Threading.Tasks.Task.Factory.StartNew(() => { Hide.Name = HideOrDisable.ToString(); Hide.Description = string.Empty; AgentStates.Add(Hide); ScreenPopConfigModel.Instance.SaveAgentStates(AgentStates.ToList()); ExecuteSaveScreentSettings(new object()); BindAgentStates(); }).ContinueWith((wait) => { ShowAgentProgress = Visibility.Collapsed; AgentVisibility = Visibility.Visible; ShowAll = Visibility.Visible; }); }
protected void SwitchState(AgentStates newState) { OnExitState(); previousState = this.state; state = newState; OnEnterState(); }
private void AssignTask(Vector3 position) { EAntTasks task; // Choose task to assing if (pheromoneType == EPheromoneTypes.Food) { task = EAntTasks.HarvestFood; } else if (pheromoneType == EPheromoneTypes.Attack) { task = EAntTasks.Attack; } else { return; } Collider[] targetedColliders = Physics.OverlapSphere(position, 0.5f, agentLayerMask); foreach (Collider collider in targetedColliders) { AgentStates antStates = collider.GetComponent <AgentStates>(); if (antStates) { antStates.SetTask(task); } } }
// Use this for initialization void Awake() { navHelper = GetComponent <NavAgentHelper> (); state = GetComponent <AgentStates> (); inventory = GetComponent <AgentInventory> (); agentBase = GameObject.FindWithTag("AntHill"); _resourceManager = FindObjectOfType(typeof(ResourceManager)) as ResourceManager; }
// Use this for initialization void Awake() { _attack = GetComponent <Attack> (); _states = GetComponent <AgentStates> (); _pheromonePlacement = GetComponent <AntPheromonePlacement> (); _navHelper = GetComponent <NavAgentHelper> (); _randomRadius = _attack.GetAttackRadius(); }
void Awake() { _navHelper = GetComponent <NavAgentHelper> (); _states = GetComponent <AgentStates> (); // Create dicts and sets for newarby pheromones. _nearbyPheromones = new Dictionary <EPheromoneTypes, HashSet <Pheromone> >(); _nearbyPheromones [EPheromoneTypes.Food] = new HashSet <Pheromone> (); _nearbyPheromones [EPheromoneTypes.Attack] = new HashSet <Pheromone> (); _nearbyPheromones [EPheromoneTypes.Repellant] = new HashSet <Pheromone> (); _agentConfiguration = FindObjectOfType(typeof(GlobalAgentConfiguration)) as GlobalAgentConfiguration; }
private void UpdateTabItem(int index) { if (index == 1) { AgentStates.Clear(); tempAgents.ToList().ForEach(x => { if (!x.DefaultName.Equals("Buttons")) { AgentStates.Add(x); } }); Hide = tempAgents.FirstOrDefault(p => p.DefaultName == "Buttons"); HideOrDisable = Hide.Name.Equals("true", StringComparison.OrdinalIgnoreCase) ? true : false; } }
public void IncrementState(AgentStates stateName, int increaseBy) { if (States.ContainsKey(stateName)) { States[stateName] += increaseBy; if (States[stateName] <= 0) { RemoveState(stateName); } } else { States.Add(stateName, increaseBy); } }
// Generate dialogue according of the need of the other agent public Discussion DialogueUpdtate(AgentStates stateAgent, int[] list) { int maxValue = Mathf.Max(list); Direction friendTarget = _fieldOfView._agentMemberTarget; Discussion friendDialogue = _fieldOfView._agentMemberDialogue; AgentStates friendState = _fieldOfView._agentMemberState; if (stateAgent == AgentStates.Start || stateAgent == AgentStates.PutObject) { return(Discussion.NothingToSay); } if ((friendState == AgentStates.FindingEnergy || friendDialogue == Discussion.NeedFindEnergy) || (_currentState == AgentStates.CarryingAcidToPile || _currentState == AgentStates.CarryingEnergyToPile) && maxValue >= 1) { if ((_previousTarget == friendTarget || _currentTarget == friendTarget) && (int)friendTarget < 4) { if (list[(int)friendTarget] >= 1) { return((Discussion)friendTarget); } else { return((Discussion)(friendTarget + 4)); // Correspond of the no presence of battery in this point } } else { if (maxValue >= 1) { return((Discussion)System.Array.IndexOf(list, maxValue)); } else { return((Discussion)_previousTarget + 4); // Correwpond of the no presence of battery in this point } } } if (_fieldOfView._currentObjet == null && maxValue == 0 && stateAgent == AgentStates.FindingEnergy) { return(Discussion.NeedFindEnergy); } else { return(Discussion.NothingToSay); // If the agent have no historic about the place } }
// Make a choice of Objectif (State) when he see the two pile public AgentStates MakeAChoiceState(float percentOfEnergy, float percentOfToxic) { float proba = Random.Range(0f, 1f); if (percentOfEnergy >= 0 && percentOfEnergy <= 99 && percentOfToxic <= 20) { AgentStates state = AgentStates.FindingEnergy; return(state); } if (percentOfEnergy <= 10) { AgentStates state = AgentStates.FindingEnergy; return(state); } if (percentOfEnergy >= 0 && percentOfEnergy <= 99 && percentOfToxic > 20 && percentOfToxic < 70) { if (proba >= 0.6f) { AgentStates state = AgentStates.FindingAcid; return(state); } if (proba < 0.6f) { AgentStates state = AgentStates.FindingEnergy; return(state); } } if (percentOfToxic >= 70) { AgentStates state = AgentStates.FindingAcid; return(state); } else { if (proba >= 0.5f) { AgentStates state = AgentStates.FindingAcid; return(state); } else { AgentStates state = AgentStates.FindingEnergy; return(state); } } }
// Agent animation manager public void AnimationMove(AgentStates agentStates) { if (_mouvement == AgentMovement.Standby && _currentState == AgentStates.FindingEnergy) { _animator.SetBool("walk", false); } else { if (agentStates == AgentStates.FindingEnergy || agentStates == AgentStates.FindingAcid || agentStates == AgentStates.Start || agentStates == AgentStates.CarryingEnergyToPile || agentStates == AgentStates.CarryingAcidToPile) { _animator.SetBool("walk", true); } if (agentStates == AgentStates.TakingEnergy || agentStates == AgentStates.TakingAcid) { _animator.SetTrigger("takeRessource"); } } }
void OnTriggerEnter(Collider col) { // Allow to check the number of battery in the zone if (col.gameObject.name == "EastInformationBox") { _numberOfbattery[(int)Direction.EastPoint] = col.GetComponent <SpawnListener>().numberOfPile; } if (col.gameObject.name == "NorthInformationBox") { _numberOfbattery[(int)Direction.NorthPoint] = col.GetComponent <SpawnListener>().numberOfPile; } if (col.gameObject.name == "SouthInformationBox") { _numberOfbattery[(int)Direction.SouthPoint] = col.GetComponent <SpawnListener>().numberOfPile; } if (col.gameObject.name == "WestInformationBox") { _numberOfbattery[(int)Direction.WestPoint] = col.GetComponent <SpawnListener>().numberOfPile; } if (col.gameObject.name == "EnergyCoil(Clone)" && _owner._currentState == AgentStates.FindingEnergy && _owner._canTakeEnergy == 0) { // Look roughly the number of pile there are in the area if there are many or not( A VOIR PLUS TARD!!!) _battery = col.GetComponent <PickableEnergy>(); // If the energy enter in the field of view if (_battery._hasPlayer == false) { _energyFront = true; _currentObjet = col.gameObject; _position = col.transform; _identifiant = _battery._idEnergy; } } // If the toxic enter in the field of view if (col.gameObject.name == "Toxic(Clone)" && _owner._currentState == AgentStates.FindingAcid && _owner._canTakeEnergy == 0) { _battery = col.GetComponent <PickableEnergy>(); if (_battery._hasPlayer == false) { _toxicFront = true; _currentObjet = col.gameObject; _position = col.transform; _identifiant = _battery._idEnergy; } } // If the box Energy enter in the field of view if (col.gameObject.name == "EnergyBoxEnterAgent") { if (_currentObjet != null && _currentObjet.name == "EnergyCoil(Clone)") { PutEnergy(); } } // If the box Waste enter in the field of view if (col.gameObject.name == "WasteBoxEnterAgent") { if (_currentObjet != null && _currentObjet.name == "Toxic(Clone)") { PutEnergy(); } } // If the box informationBox enter in the field of view if (col.gameObject.name == "PileInformationBox") { _percentOfEnergy = col.GetComponent <InformationPiles>()._energyRate; _percentOfWaste = col.GetComponent <InformationPiles>()._toxicRate; _pileFront = true; } // If an agent enter in the field of view if (col.gameObject.tag == "agent") { _agentFront = true; _agentMember = col.GetComponent <Agent>(); if (_agentMember._code != _owner._code && _agentFront == true) { _agentMemberDialogue = _agentMember._currentDialogue; _agentMemberState = _agentMember._currentState; _agentMemberTarget = _agentMember._currentTarget; } } // Check if the Agent Friend is near enough to consider if he is front of him or not if (_agentMember != null) { if (Vector2.Distance(new Vector2(_agentMember.transform.position.x, _agentMember.transform.position.z), new Vector2(transform.position.x, transform.position.z)) > 2.2) { _agentFront = false; } if (Vector2.Distance(new Vector2(_agentMember.transform.position.x, _agentMember.transform.position.z), new Vector2(transform.position.x, transform.position.z)) <= 2.2) { _agentFront = true; } } }
public SubGoal(AgentStates action, int importance, bool removeable) { sgoal = new Dictionary <AgentStates, int>(); sgoal.Add(action, importance); remove = removeable; }
// When the agent is near enough to take the objet public void TakeObject(AgentStates state) { AnimationMove(state); }
public void AddState(AgentStates stateName, int value) { States.Add(stateName, value); }
/* * globaalaas uzvediibas FSM (finite-state-machine) * @todo -- stack baased ? ---paartaisiishu, ja atradiishu vismaz 12 iemeslus * */ private void thinkAbout() { Room room = null; switch(CurrentState) { //--------------------------------------------------------------- case AgentStates.idling: isCraving = -1; //nemeklee nekaadu resursu workUnit = null; int numResourceShortages = Needs.Shortage.Count(c => c); // ezoteeriskaa veidaa izskaita cik ir TRUE shajaa masiivaa - tik mums ir resursu, kas iet uz galu un jaaiet tos papildinaat if(numResourceShortages > 0){ //meklees sev resursus CurrentState = AgentStates.choosingResourceDestination; } else if(idlingFor > 0){ //pagaidiis bezdarbiibaa idlingFor -= Time.deltaTime; //bodyAnimator.SetBool("waving", true); } else if(workManagerScript.IsThereWorkAvailable()) { //ir kaads darbinsh pieejams // print("ir kaads darbinsh"); CurrentState = AgentStates.choosingWorkDestination; } else { //ja nav jaameklee resursus, tad izveeleesies nejaushu galapunktu un tur pagaidiis CurrentState = AgentStates.choosingRandomDestination; idlingFor = Random.Range(1, 3); //bodyAnimator.SetBool("waving", false); // print("STATE:idling + choseRND"); } //print("STATE:idling"); break; //--------------------------------------------------------------- case AgentStates.choosingRandomDestination: room = levelscript.roomWhereIcanDoThis(-1); //dabuus nejaushu telpa if(room != null) { Vector2 rc = levelscript.randomCubeInThisRoom(room); //randomcube - nejaushss kubiks atrastajaa telpaa if(GoThere(rc.x, rc.y) == -1){ // kljuuda - agjents neatrodas uz grida CurrentState = AgentStates.offTheGrid; break; } // print("rooom " + Mathf.RoundToInt(room.transform.position.x) + ", " + Mathf.RoundToInt(room.transform.position.y) + "randCube " + Mathf.RoundToInt(rc.x) + ", " + Mathf.RoundToInt(rc.y)); // print("RANDrooom " + (room.transform.position.x) + ", " + (room.transform.position.y) + " RANDcube " + (rc.x) + ", " + (rc.y)); CurrentState = AgentStates.traveling; } else { CurrentState = AgentStates.idling; //nav pat 1 nejaushas telpas, nu tad neko - turpina gaidiit } //print("STATE:choosingRandomDestination"); break; //--------------------------------------------------------------- case AgentStates.choosingResourceDestination: //jaaatrod TUVAAKAA telpa, kas apmierina vajadziibu peec resursa for(int need = 0; need < AgentNeeds.numTypes; need++) { //iet cauri visaam agjentvajadziibaam if(Needs.Shortage[need]){ //shis resurss truukst, to ir jaaiet mekleet | pirmaas vajadziibas ir svariigaakas (jo taas apskata sekvencionaali, varbuut vajag randomizeet seciibu ikreizi ?) room = levelscript.roomWhereIcanDoThis(need); if(room != null){ //ir atrasta sho vajadziibu apmierinosha telpa isCraving = need; //pieseivos kuru vajadziibu ies apmierinaat - lai zinaatu, ka jaait prom, tikliidz TAA ir apmierinaata break; //neapskata paareejaas vajadziibas } } } if(room != null){ //jaaiet uz atrasto telpu Vector2 rc = levelscript.randomCubeInThisRoom(room); //randomcube - nejaushss kubiks atrastajaa telpaa if(GoThere(rc.x, rc.y) == -1){ // kljuuda - agjents neatrodas uz grida CurrentState = AgentStates.offTheGrid; break; } CurrentState = AgentStates.traveling; // print("atrada " + rc.x + "," + rc.y); } else { CurrentState = AgentStates.idling; //neko neatrada - jaaiet neko nedariit // print("neatrada"); } // print("STATE:choosingResourceDestination craving=" + isCraving); break; //--------------------------------------------------------------- case AgentStates.choosingWorkDestination: //print("STATE:choosingWorkDestination "); workUnit = null; try{ workUnit = workManagerScript.GetWork(this); if(workUnit != null){ if(GoThere(workUnit.BestPositionToStandWhileWorking.x, workUnit.BestPositionToStandWhileWorking.y) == -1){ // iet uz noraadiito darbavietu (ja -1 tad Agjents neatrodas uz grida, jaaiet sho glaabt) CurrentState = AgentStates.offTheGrid; break; } CurrentState = AgentStates.traveling; workUnit.ReserveWork(true,this); // print("ir straadaashana " + workUnit + " @" + workUnit.parentGameobject.transform + " bestPOS " + workUnit.BestPositionToStandWhileWorking); } else { //nav neviena briiva,pieejama darbinja CurrentState = AgentStates.idling; break; } } catch(System.Exception e) { // kjer pathfinding iznjeemumu, ka agjents nemaz neatrodas uz grida if(e.Message == "not-on-a-grid"){ CurrentState = AgentStates.offTheGrid; //agjents ies glaabties } } break; //--------------------------------------------------------------- case AgentStates.traveling: // print("STATE:traveling"); //kad agjents buus nonaacis galaa, tad vinja staavokli nomainiis moveAbout() metodee nevis sheit; nomainiis uz "arriving" break; //--------------------------------------------------------------- case AgentStates.offTheGrid: //neatrodas uz navgrida, jaaatrod tuvaakais navgridaa esoshais punts un jaaevakueejas taa virzienaa if(offTheGridFor > 0){ //pagaidiis kaadu laicinju, lai neceptu procesoru offTheGridFor -= Time.deltaTime; break; } if(levelscript.Navgrid.Count > 0){ //ja ir navgridaa punkti, kur mukt //print ("provees tikt uz celja"); Vector2 closestPoint = new Vector2(0,0); float closestDistance = -1; float x = transform.position.x; float y = transform.position.y; foreach(KeyValuePair<Vector4, float> p in levelscript.Navgrid) { if(p.Key.y == y){ //meklee tuvaakos punkts tikai shajaa staavaa float d = levelscript.MapDistanceBetweenPoints(p.Key.x,p.Key.y,x,y);//cik taalu shis navgrida punkts no agjenta if(closestDistance == -1 || d < closestDistance){ closestPoint = new Vector2(p.Key.x,p.Key.y); //shis ir tuvaakais navgrida punkts closestDistance = d; } } } if(closestDistance > -1){ // print("atradaam kaadu punktu, kur glaabties"); destinationNode = closestPoint; actualRoute.Add(closestPoint); //manuaali izveidoju celju (stur tikai 1 punktu - kur skrienu glaabties) CurrentState = AgentStates.traveling; //peec ieshanas automaatiski staavoklis buus IDLING avatarAnimator.SetBool("fast", true); //manuaalie iesaaku animaaciju //print(x + "," + y + " -> " + closestPoint); break; } else { // print("NEatradaam nevienu punktu, kur glaabties"); offTheGridFor = 3; //3 sekundes pagaidiis, liidz meegjinaas atkal, varbuut tad buuus kaut kas uzbuuveets } } break; //----------------------------------------------------------------- case AgentStates.arriving: if(workUnit != null){ //te ieradies darba dariishanaas // print("ieradies straaadaaat"); workingFor = Random.Range(2,5); //dazhas sekundes pastraadaas avatarAnimator.SetBool("working", true); CurrentState = AgentStates.working; break; //break case } else if(isCraving >= 0){//sheit ieradies apmierinaat kaadu vajadziibu room = levelscript.roomAtThisPosition(transform.position.x,transform.position.y); //null vai telpa if(room == null){ //atnaacis, bet neatrodas telpaa, hmmm CurrentState = AgentStates.idling; // print("iatnaacis, bet neatrodas telpaa, hmmm"); } else { //viss kaartiibaa ir telpaa bool roomIsProviding = false; for(int need = 0; need < AgentNeeds.numTypes; need++) { //iet cauri visaam agjentvajadziibaam if(Needs.Shortage[need]){ //shis resurss truukst if(room.AgentNeedsGeneration[need] > 0){ //telpa dod sho resursu roomIsProviding = true; break; } } } if(roomIsProviding){ //telpa deriiga, saakam eest // print("telpa deriiga, saakam eest"); currentRoom = room; //piekesho telpu, kur atnaacis CurrentState = AgentStates.consumingResource; } else { //telpa neko nedod //print("telpa neko nedod"); CurrentState = AgentStates.idling; } } } else if(isCraving == -1){ //ir bezmeerkjiigi ieradies CurrentState = AgentStates.idling; break; //break case } //print("STATE:arriving"); break; //--------------------------------------------------------------- case AgentStates.consumingResource: // currentRoom -- tikai sheit droshi varu lietot sho mainiigo, jo tas ir uzsists ieprieksheejaa kadraa vieniigajaa IFaa, kas ved uz shejieni for(int need = 0; need < AgentNeeds.numTypes; need++) { //iet cauri visaam agjentvajadziibaam avatarAnimator.SetBool("eating", true); //pagaidaam ir tikai 1 teereeshanas animaacija - eeshana, visus resursus pateeree eedot - arii miedzinju XD Needs.Reserve[need] += currentRoom.AgentNeedsGeneration[need] * Time.deltaTime; //eed visus resursus (kas ir 0 vai pozitiivs skaitlis) if(Needs.Reserve[need] > Needs.Max[need]){ //neljauj paareesties, ierobesho maximumu Needs.Reserve[need] = Needs.Max[need]; } if(Needs.Reserve[isCraving] == Needs.Max[isCraving]){ // vajadziiba, kuras deelj naaca uz sho telpu, ir apmierinaata CurrentState = AgentStates.idling; avatarAnimator.SetBool("eating", false); } } //print("STATE:consumingResource"); break; //--------------------------------------------------------------- case AgentStates.working: if(!workUnit.IsOn()){ //darbinsh tiek izsleegts CurrentState = AgentStates.idling; avatarAnimator.SetBool("working", false); workUnit.ReserveWork(false); //padara darbinju pieejamu citiem break; } workingFor -= Time.deltaTime; workUnit.DoSomeActualMotherFlippingJob(); if(workingFor < 0){ //buus gana straadaats CurrentState = AgentStates.idling; avatarAnimator.SetBool("working", false); workUnit.ReserveWork(false);//padara darbinju pieejamu citiem break; } //visa magjija un progress notiek workunit skriptaa break; } }
public string GetTaskString() { return(AgentStates.TaskToString(_task)); }
public double GetValue(AgentStates stateName) { return(States[stateName]); }
public bool HasState(AgentStates stateName) { return(States.ContainsKey(stateName)); }
private void Update() { // At the beginning the agent trust is the same for everyone if (_boolStartTrust) { InstanciateTrust(_percentTrustStart); _boolStartTrust = false; } //go out or no after x seconde of the currentTarget if there is no energy if (_mouvement == AgentMovement.Standby && _currentState == AgentStates.FindingEnergy && PlayerPrefs.GetInt("High") == 1) { _countDown -= Time.deltaTime; bool stayOrNo = MakeAChoiceTrust(50); if (_countDown <= 0.0f && stayOrNo == true) { _currentTarget = MakeAChoiceDirection(_numberOfBatteryByPlace, _previousTarget, _currentTarget); _countDown = _countDownUtilisateur; ListenDialogue(); } if (_countDown <= 0.0f && stayOrNo == false) { _countDown = _countDownUtilisateur; } } // Look if the percent of trust is >0 and <100 TrustManager(); // set the mouvement (walk or idle) of the agent SetAgentMovement(_currentTarget); // List of number of battery seen by the agent by place _numberOfBatteryByPlace = _fieldOfView._numberOfbattery; _actualInteractionAgent = _fieldOfView._agentMember; // Actual agent in the fieldOfview if (_actualInteractionAgent != null) { _currentDialogue = DialogueUpdtate(_currentState, _numberOfBatteryByPlace); } #region PICKABLE OBJECT // Detection of energy in the field of view of the agent if ((_fieldOfView._energyFront == true && _currentState == AgentStates.FindingEnergy)) { if (_fieldOfView._ownerCombustible == _code) { SilenceDialogue(); SeeObject(); // if the agent enough near of the energy if (_fieldOfView._energyPickable == true) { _doneHistoric = false; _currentState = AgentStates.TakingEnergy; TakeObject(_currentState); _currentState = AgentStates.CarryingEnergyToPile; if (_currentTarget != Direction.PileEnergyPoint && _currentTarget != Direction.PileWastePoint) { _previousTarget = _currentTarget; } _currentTarget = Direction.PileEnergyPoint; DestinationAgent(_currentTarget); } } else { _canTakeEnergy = 0; } } // Detection of toxic in the field of view of the agent if (_fieldOfView._toxicFront == true && _currentState == AgentStates.FindingAcid) { SilenceDialogue(); if (_fieldOfView._ownerCombustible == _code) { SeeObject(); // If the agent enough near of the energy if (_fieldOfView._energyPickable == true) { _doneHistoric = false; _currentState = AgentStates.TakingAcid; TakeObject(_currentState); _currentState = AgentStates.CarryingAcidToPile; if (_currentTarget != Direction.PileEnergyPoint && _currentTarget != Direction.PileWastePoint) { _previousTarget = _currentTarget; } _currentTarget = Direction.PileWastePoint; DestinationAgent(_currentTarget); } } else { _canTakeEnergy = 0; } } // If nothing in front look for energy or toxic battery if ((_fieldOfView._energyFront == false && _currentState == AgentStates.FindingEnergy) || (_fieldOfView._toxicFront == false && _currentState == AgentStates.FindingAcid)) { _canTakeEnergy = 0; } #endregion #region AGENT CHOICE // Destination of the agent if he carry nothing if (_fieldOfView._currentObjet == null) { // At the start of the simulation if (_currentState == AgentStates.Start) { _previousTarget = (Direction)_randomDirection; _currentTarget = Direction.PileEnergyPoint; DestinationAgent(_currentTarget); AnimationMove(_currentState); } // Choice in front of the pile : Go check the need of the different pile if (_fieldOfView._pileFront == true && _checkPile == false && (_currentState == AgentStates.PutObject || _currentState == AgentStates.Start)) { ListenDialogue(); _percentOfEnergyPile = _fieldOfView._percentOfEnergy; _percentOfWastePile = _fieldOfView._percentOfWaste; _currentState = MakeAChoiceState(_percentOfEnergyPile, _percentOfWastePile); _currentTarget = MakeAChoiceDirection(_numberOfBatteryByPlace, _previousTarget, _currentTarget); AnimationMove(_currentState); _randomDirection = Random.Range(0, 4); _checkPile = true; } if (_fieldOfView._pileFront == false) { _checkPile = false; } //if none agent front if (_fieldOfView._agentFront == false) { _actualInteractionAgent = null; } // Target if currentState = findingToxic if (_currentState == AgentStates.FindingAcid && _doneHistoric == false && _fieldOfView._energyPickable == false && _fieldOfView._currentObjet == null) { SilenceDialogue(); if (_currentTarget != Direction.PileEnergyPoint && _currentTarget != Direction.PileWastePoint) { _previousTarget = _currentTarget; } _currentTarget = Direction.AcidPoint; _doneHistoric = true; } // If the agent have an interaction with an other agent if (_actualInteractionAgent != null) { // Target if currentState = findingEnergy if (_currentState == AgentStates.FindingEnergy && _listenAnOtherAgent[_actualInteractionAgent._code - 1] == true && _doneHistoric == false && _fieldOfView._energyPickable == false) { Direction newTarget = MakeAChoiceDirection(_numberOfBatteryByPlace, _previousTarget, _currentTarget); if (_currentTarget != Direction.PileEnergyPoint && _currentTarget != Direction.PileWastePoint) { _previousTarget = _currentTarget; } _currentTarget = newTarget; _doneHistoric = true; } // If he meet an other agent if (_listenAnOtherAgent[_actualInteractionAgent._code - 1] == true && _fieldOfView._agentFront == true && _fieldOfView._agentMember == _actualInteractionAgent && _currentState != AgentStates.FindingAcid && _currentState != AgentStates.CarryingAcidToPile) { // Correspond to the Discussion (enumartion) about presence of battery : HaveManyAtNorth, HaveManyAtSouth, HaveManyAtEast, HaveManyAtWest if ((int)_fieldOfView._agentMemberDialogue >= 0 && (int)_fieldOfView._agentMemberDialogue < 4 && (_currentState == AgentStates.FindingEnergy || _currentDialogue == Discussion.NeedFindEnergy)) { Direction precedentchoiceTarget = _currentTarget; _actualInteractionAgent = _fieldOfView._agentMember; IndexOfAgentTrust(_actualInteractionAgent); // Attribute the value to actualAgentTrust if ((int)_fieldOfView._agentMemberDialogue != (int)_currentTarget) { Direction newTarget = MakeAChoice(precedentchoiceTarget, _fieldOfView._agentMemberDialogue, _agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust); if (newTarget != precedentchoiceTarget) { if (precedentchoiceTarget != Direction.PileEnergyPoint && precedentchoiceTarget != Direction.PileWastePoint) { _previousTarget = _currentTarget; } _currentTarget = newTarget; _agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust += _fluctuationTrust; } else { _agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust -= _fluctuationTrust; } } if ((int)_fieldOfView._agentMemberDialogue == (int)_currentTarget) { _agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust += _fluctuationTrust; } SilenceDialogue(_actualInteractionAgent._code); _actualInteractionAgent = null; } // Correspond to the Discussion (enumartion) about no presence of battery : DonthaveManyAtEast, DonthaveManyAtNorth, DonthaveManyAtWest, DonthaveManyAtSouth // Caution -4 it is in order to have the same correspondance according the AgentBhavior (North, south,...) if ((int)_fieldOfView._agentMemberDialogue >= 4 && (int)_fieldOfView._agentMemberDialogue <= 7 && _currentState == AgentStates.FindingEnergy) { Direction precedentchoiceTarget = _currentTarget; _actualInteractionAgent = _fieldOfView._agentMember; IndexOfAgentTrust(_actualInteractionAgent); // Attribute the value to actualAgentTrust if ((int)_fieldOfView._agentMemberDialogue - 4 == (int)_currentTarget && MakeAChoiceTrust(_agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust) == true) { _numberOfBatteryByPlace[(int)_currentTarget] = 0; Direction newTarget = MakeAChoiceDirection(_numberOfBatteryByPlace, _previousTarget, _currentTarget); if (precedentchoiceTarget != Direction.PileEnergyPoint && precedentchoiceTarget != Direction.PileWastePoint) { _previousTarget = _currentTarget; } _currentTarget = newTarget; _agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust += _fluctuationTrust; } if (MakeAChoiceTrust(_agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust) == false) { _currentTarget = precedentchoiceTarget; _agentsList[System.Array.IndexOf(_agentsList.ToArray(), _actualAgentTrust)]._trust -= _fluctuationTrust; } SilenceDialogue(_actualInteractionAgent._code); _actualInteractionAgent = null; } } } // Animation and destination if currentState != GoToPileEnergy and GoToPileToxic if (_currentState != AgentStates.CarryingEnergyToPile && _currentState != AgentStates.CarryingAcidToPile) { DestinationAgent(_currentTarget); AnimationMove(_currentState); } } // Destination of the agent if he carry something (Toxic/Energy) if (_fieldOfView._currentObjet != null && _currentState == AgentStates.FindingEnergy && _fieldOfView._energyPickable == true && _fieldOfView._ownerCombustible == _code) { SilenceDialogue(); _currentState = AgentStates.CarryingEnergyToPile; if ((_currentTarget != Direction.PileEnergyPoint && _currentTarget != Direction.PileWastePoint) && _doneHistoric == false) { _previousTarget = _currentTarget; _doneHistoric = true; } _currentTarget = Direction.PileEnergyPoint; DestinationAgent(_currentTarget); } if (_fieldOfView._currentObjet != null && _currentState == AgentStates.FindingAcid && _fieldOfView._energyPickable == true && _fieldOfView._ownerCombustible == _code && _currentTarget == Direction.AcidPoint) { SilenceDialogue(); _currentState = AgentStates.CarryingAcidToPile; if ((_currentTarget != Direction.PileEnergyPoint && _currentTarget != Direction.PileWastePoint) && _doneHistoric == false) { _previousTarget = _currentTarget; _doneHistoric = true; } _currentTarget = Direction.PileWastePoint; DestinationAgent(_currentTarget); } #endregion }
public void RemoveState(AgentStates stateName) { States.Remove(stateName); }
/** * zemaakaa FMS - ruupeeejaas par ieshanu, roteeshanu un kaapshanu uz naakamo punktu atrastajaa celjaa */ private void moveAbout() { if(!nextRouteNodeIsSet) { //nav dabuut naakamais solis // print ("njem naakamo virsotni lastRoute.Count = " + lastRoute.Count); if(actualRoute != null && actualRoute.Count > 0) { //bet ir veel celjsh priekhsaa nextRouteNodeIsSet = true; nextRouteNode = actualRoute[actualRoute.Count - 1]; //POP 2 soljos :/ actualRoute.RemoveAt(actualRoute.Count - 1); //print ("panjeema naakamo virsotni"); //lieku iet un griezties uz naakamo punktu if(Mathf.Round(nextRouteNode.y) != Mathf.Round(destinationNode.y)) { //buus jaakaapj pa kaapneem uz citu staavu isScaling = true; } else { // naakamais punkts atrodas tajaa pashaa staavaa isWalking = true; } isTurning = true; destinationNode = new Vector3(nextRouteNode.x, nextRouteNode.y, nextRouteNode.z); avatarAnimator.SetBool("fast", true); //aaaaaaaanimeeeeeet! } else { if(CurrentState == AgentStates.traveling) { //nomaina staavokli lielajaa FSM - ka esam sasniegushi galapunktu CurrentState = AgentStates.arriving; //print ("ieshana beigusies ? esam klaat ? "); } } } //print("destinationNode" + destinationNode + " turning: " + isTurning + " walking: " + isWalking + " isScaling: " + isScaling); //griezhas pret meerkji (kameer nav pagriezies) | griezhas tikai pa Y asi (personaazhs staav uz x z plaknes ) if(isTurning) { float y = transform.position.y; float z = transform.position.z; //joka peec nofiksees arii z parametru Vector3 a = new Vector3(destinationNode.x, y, z); Vector3 b = new Vector3(transform.position.x, y, z); if(Vector3.Distance(a, b) > 0.01) { // zhigli apaskatiishos vai a un b punkti nav viens un tas pats (ja ir, tad nav vajadziibas griezties un kvaternionu reekjinaataajs ir verni dusmiigs, ja prasu lenjkji starp 2 identiskiem vektoriem) Quaternion targetRotation = Quaternion.LookRotation(a - b, Vector3.up); if(Quaternion.Angle(targetRotation, transform.rotation) < 10f) { //gandriiz jau ir pagriezies transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 100); //atlikushos graadus norotee uzreiz //print ("vairs negriezhas"); isTurning = false; } else { //print ("griezhas"); transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * turningSpeed); } } else { isTurning = false; } } if(isWalking && !isTurning) { //ies tikai, ja buus pagriezies pareizajaa virzienaa (citaadi rodas bezgaliiga groziishanaas) //uzskatu, ka ir atnaacis mirklii, kad saak iet iet prom: punkts uz kuru jaapaariet sahajaa kadraa ir taalaak no meerkja, nekaa pashreizeejaa lokaacija | shii metode ir visizturigaakaa pret FPS piikjiem Vector3 newpos = transform.position + transform.TransformDirection(Vector3.forward) * speed * Time.deltaTime; //punkts uz kuru shajaa kadraa paarvietoties if(Vector3.Distance(transform.position, destinationNode) < Vector3.Distance(newpos, destinationNode)) {// grib attaalinaaties isWalking = false; nextRouteNodeIsSet = false; avatarAnimator.SetBool("fast", false); transform.position = destinationNode; //ir atnaacis } else { transform.position = newpos; //iet } } if(isScaling) { // print ("scaling distance " + Vector3.Distance(transform.position, destinationNode) + " = " + transform.position + " + " + destinationNode ); float a = Mathf.Abs(transform.position.y); float b = Mathf.Abs(destinationNode.y); if( Mathf.Max(a,b) - Mathf.Min(a,b) < 0.05f) { ///ja shvaks freimreits, tad var paskriet garaam, ja rodas shii probleema, vajag skatiities arii virzienu - ja attaalinaas no meerkja, tad automaatiski => atrodas uz meerkja isScaling = false; nextRouteNodeIsSet = false; transform.position = destinationNode; //ir atnaacis avatarAnimator.SetBool("fast", false); } else { Vector3 direction; //taa kaa varonis negriezhas un augshu/leju, tad man manuaali jaapadod virzien, kuraa gribu, lai vinsh kaapj if(destinationNode.y > transform.position.y) { direction = Vector3.up; } else { direction = Vector3.down; } transform.position = transform.position + transform.TransformDirection(direction) * speed * Time.deltaTime; } } }
public void UpdateState(AgentStates basicState, int i) { States[basicState] = i; }
public string GetStatusString() { return(AgentStates.StateToString(currentState)); }