//RFAfim //RFA-delegate- Inicio (ver la em baixo - passa o: owner, partner) // private void PublishStopInteraction(Gajo g1, Gajo g2) private void PublishStopInteractionOfPartner(GajoCitizen g1) { if (requestStopInteraction != null) { requestStopInteraction(); } }
//------------------------------------------------------------------------------------------------------- void Update() { if (Global.gameState > 0) { text = ""; GajoCitizen g = CitizenFactory.listaGajos[Global.whoIsBeingTracked]; if (g != null) { text += "\n"; if (g.blueprint != null) { text += "\n Id:" + g.getId() + " Blueprint " + g.blueprint.dna; text += "\n"; } if (g.metabolism != null) { text += "\nEnergy " + g.metabolism.energy; } text += "\nProxemia " + g.proxemia; text += "\nDipatcherSpeed " + g.behavior.dispatcherSpeed; if (g.metabolism != null) { text += "\nChemicals " + g.metabolism.chemicals[0] + " - " + g.metabolism.chemicals[1] + " - " + g.metabolism.chemicals[2] + "\n"; /* text += "\nTestosterona " + g.metabolism.ht_testosterone; * text += "\nAdrenaline " + g.metabolism.ha_adrenaline; * text += "\nLeptine " + g.metabolism.hl_leptin; * text += "\nMelatonin " + g.metabolism.hm_melatonin; * text += "\nSerotonin " + g.metabolism.hs_serotonin; */} text += " "; if (g.walker != null) { text += "Walk Speed:" + g.walker.Animacao.GetFloat("WalkingSpeed"); //change to Movement text += "velocity anim " + g.walker.Animacao.velocity; // text += " ActionAnimation:" + g.walker.animator.GetFloat ("ActionAnimation");//change t } text += "\n Message was dispatched:" + Global.whatAmIDoing; text += "\n"; text += "\n"; if (g.behavior.dispatcher != null) { if (g.behavior.dispatcher != null) { text += g.behavior.getDebugString(); } } //deprecated if (g.walker!=null) //deprecated text += g.walker.Navigation.getDebugString(); } Repaint(); } }
//----------------------------------------------------------------------------------- //MOVE TO MATE----------------------------------------------------------------------- //----------------------------------------------------------------------------------- public static float moveToMate(GajoCitizen owner, Transform objecto) { float reward = 0; owner.walker.target = objecto.position; owner.metabolism.energy -= owner.priceMovement; reward += 0.01f; return(reward); }
//--------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- public InteractionHandler(GajoCitizen parent) { _parent = parent; Memoria = new MemoryOfRelationships(); interactingDistance_min = _parent.walker.Navigation.RAIO * 1.50f; interactingDistance_max = _parent.walker.Navigation.RAIO * 3f; isInteracting = false; }
//-------------------------------------------------------------------------------- public void die() { _navigation.die(); Destroy(_navigation); _gait.die(); Destroy(_gait); _animator = null; _owner = null; }
//--------------------------------------------------------------------------------------------- public void die() { _parent = null; for (int i = 0; i < Memoria.listOfInteractionPartners.Count; i++) { Memoria.listOfInteractionPartners[i] = null; } Memoria.listOfInteractionPartners.Clear(); Memoria.listOfInteractionPartners = null; }
//------------------------------------ public static void criaGajo_Producao(int i, float radius) { if(anchors_Production.Count>0) { int aux = Random.Range(0, anchors_Production.Count); Vector3 position = v3GetValidCoordinate(anchors_Production[aux].transform.position, radius); //CRIA CITIZEN aux = Random.Range(0, listaTemplates_Adults_Production.Count); GameObject template = listaTemplates_Adults_Production[aux]; GameObject go = (GameObject)Instantiate(template, position, Quaternion.identity); go.transform.gameObject.name += i; GajoCitizen g = go.AddComponent<GajoCitizen>(); g.init(qtGajosSinceBeginning++, null); listaGajos.Add(g); //CRIA FOLLOWER if (Random.Range(0, 100.0f) > 97.5f)//02.5% chances { aux = Random.Range(0, listaTemplates_Adults_Production.Count); template = listaTemplates_Adults_Production[aux]; if (template != null) { GameObject go2 = (GameObject)Instantiate(template, position + Vector3.right, Quaternion.identity); GajoFollower gaf = go2.AddComponent<GajoFollower>(); gaf.init(g, GajoFollower.WalkingMode.ADULT); go2.SetActive(true); i++; } else Debug.LogError("Follower:Citizen template is null!"); } else //CRIA CRIANCA if (listaTemplates_Children_Production.Count > 0) { aux = Random.Range(0, listaTemplates_Children_Production.Count); template = listaTemplates_Children_Production[aux]; if (template != null) { if (Random.Range(0, 100.0f) > 95)// 5 % chances { GameObject go1 = (GameObject)Instantiate(template, position + Vector3.right, Quaternion.identity); GajoFollower g1 = go1.AddComponent<GajoFollower>(); g1.init(g, GajoFollower.WalkingMode.CHILD); i++; } } else Debug.LogError("Children template is null!"); } }else { Debug.LogError("Please add at least one anchor to the scene, to define where characters should appear"); } }
//---------------------------------------------------------------------------------------- //ATACA-GAJO----------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- public float ataca(GajoCitizen prey) { float reward = 0; if (_owner.getId() == Global.whoIsBeingTracked) { Global.whatAmIDoing = TypeOfActionBeingPerformed.ATACA; } _owner.whatAmIDoing = TypeOfActionBeingPerformed.ATACA; _owner.walker.target = prey.transform.position; if (prey.iEstado == GajoCitizen.GajoState.VIVO && _owner.iEstado == GajoCitizen.GajoState.VIVO) { if (prey.walker.Animacao != null) { _owner.behavior.Interacao.isInteracting = true; prey.behavior.Interacao.isInteracting = true; prey.whatAmIDoing = TypeOfActionBeingPerformed.ATACA_COOPERA; //**// reward = negoceia(prey, true); //**// if (reward > 0) { myanimations.interactionState = InteractionAnimations.MyState.ATACK_YESinitiative_WIN; prey.behavior.actions.myanimations.interactionState = InteractionAnimations.MyState.ATACK_NOinitiative_WIN; _owner.whatAmIDoing = TypeOfActionBeingPerformed.ATACA_COOPERA; _owner.walker.Animacao.enabled = true; _owner.walker.target = _owner.transform.position; _owner.behavior.Interacao.Memoria.isCooperativeInteractionC = true; prey.behavior.Interacao.Memoria.isCooperativeInteractionC = true; } else { myanimations.interactionState = InteractionAnimations.MyState.ATACK_YESinitiative_LOSE; prey.behavior.actions.myanimations.interactionState = InteractionAnimations.MyState.ATACK_NOinitiative_LOSE; _owner.whatAmIDoing = TypeOfActionBeingPerformed.ATACA_NAOCOOPERA; _owner.behavior.Interacao.Memoria.isCooperativeInteractionC = false; prey.behavior.Interacao.Memoria.isCooperativeInteractionC = false; } float durationInteraction = 10f - (_owner.behavior.relaxation * 10f * 0.25f); _owner.startInteraction(prey, durationInteraction); } myanimations.anima(); prey.behavior.actions.myanimations.anima(); } else { reward = 0; } _owner.metabolism.energy -= _owner.priceAttack; return(reward); }
public float move(GajoCitizen posicaoObjecto) { if (posicaoObjecto != null)//Exception se morreu entretanto { return(makeMovement(posicaoObjecto.transform.position)); } else { return(0); } }
//--------------------------------------------------------------------------------------------- //NORMAL INTERACTION--------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- public void start(GajoCitizen outro, float duracao) { _partner = outro; _partner.behavior.Interacao.interactingPartner = _parent; //ANIMACAO stepAwayYourBreathIsTooStinky(); //ESTATISTICA //Regista interacao Memoria.numeroInteracoes++; _partner.behavior.Interacao.Memoria.numeroInteracoes++; Memoria.duracaoMediaInteracoes += duracao / Memoria.numeroInteracoes; _partner.behavior.Interacao.Memoria.duracaoMediaInteracoes += duracao / _partner.behavior.Interacao.Memoria.numeroInteracoes; //BEHAVIOR //Increase Connectedness _parent.metabolism.connectedness += _parent.metabolism.boostConnectednessWithEncounters; //Ver tambem o adicional de Actions.attemptMate() _partner.metabolism.connectedness += _partner.metabolism.boostConnectednessWithEncounters; //-------------------------------------------- //-------------------------------------------- //-------------------------------------------- if (duracao < 2f) { duracao = 2; } //-------------------------------------------- //-------------------------------------------- //-------------------------------------------- //Parametros interacao _parent.behavior.dispatcherSpeed = duracao; _partner.behavior.dispatcherSpeed = duracao; interactionState = InteractionState.WANTS_TO_GET_LINK; _partner.behavior.Interacao.interactionState = InteractionState.WANTS_TO_GET_LINK; isInteracting = true; _partner.behavior.Interacao.isInteracting = true; _parent.walker.Animacao.SetBool("interact", true); _partner.walker.Animacao.SetBool("interact", true); // _parent.walker.Animacao.SetBool("waving", false); //---------------------------- #if hasGigantonesInteraction _parent.transform.localScale = new Vector3(1, 8, 1); _partner.transform.localScale = new Vector3(1, 8, 1); #endif //Agora ponho o segundo interacto no estado do primeiro menos 1, //para evitarestarem os dois a fazer a mesma animacao _partner.behavior.myMarkov.currentState = _parent.behavior.myMarkov.currentState - 1; //Ficam no mesmo sitio _partner.walker.Navigation.stopMoving(); _parent.walker.Navigation.stopMoving(); _parent.walker.Navigation.locomotionMode = Navigation.LocomotionMode.MODE_STOPPED; _partner.walker.Navigation.locomotionMode = Navigation.LocomotionMode.MODE_STOPPED; }
public static void createGajo(int[] dna) { //Boneco// int aux = Random.Range(0, listaTemplates_Adults_Production.Count); GameObject prefab = listaTemplates_Adults_Production[aux]; aux = Random.Range(0, anchors_Production.Count); Vector3 position = v3GetValidCoordinate(anchors_Production[aux].transform.position, 30); GameObject go = (GameObject)Instantiate(prefab, position, Quaternion.identity); go.transform.gameObject.name += listaGajos.Count - 1; GajoCitizen g = go.AddComponent<GajoCitizen>(); g.init(qtGajosSinceBeginning++, dna); listaGajos.Add(g); }
//--------------------------------------------------------------------------------------------- //STOP INTERACTION //--------------------------------------------------------------------------------------------- public void stop() { #if hasGigantonesInteraction _parent.transform.localScale = new Vector3(1, 1f, 1); #endif interactionState = InteractionState.NEPIA; _parent.walker.Animacao.SetBool("interact", false); _parent.walker.Animacao.SetBool("frente_a_frente", false); // _parent.walker.Animacao.SetTrigger("waving"); _parent.behavior.Interacao.Memoria.typeOfInteraction = MemoryOfRelationships.TypeRelationship.VOID; _parent.behavior.Interacao.Memoria.isCooperativeInteractionC = false; //**************** isInteracting = false; if (_parent != null) { if (_parent.iEstado == GajoCitizen.GajoState.VIVO) { _parent.behavior.dispatcherSpeed = Global.normalDispatcherInterval; } } if (_partner != null) { if (_partner.iEstado == GajoCitizen.GajoState.VIVO) { if (_partner.behavior != null) { _partner.behavior.Interacao.interactionState = InteractionState.NEPIA; _partner.behavior.Interacao.isInteracting = false; _partner.behavior.dispatcherSpeed = Global.normalDispatcherInterval; //***************** _partner.behavior.Interacao.Memoria.typeOfInteraction = MemoryOfRelationships.TypeRelationship.VOID; _partner.behavior.Interacao.Memoria.isCooperativeInteractionC = false; //***************** } if (_partner.walker != null) { _partner.walker.Animacao.SetBool("interact", false); _partner.walker.Animacao.SetBool("frente_a_frente", false); } } } _partner = null; _parent.walker.Navigation.agent.SetDestination(_parent.walker.preferedPosition); _parent.walker.Navigation.startWalking(); }
//int rotateLeftAnimation; //int rotateRightAnimation; /*--------------------------------------------------*/ void Start() { GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY; gajo = GetComponent <GajoCitizen>(); anim = GetComponent <Animator>(); //layerIndex = anim.GetLayerIndex("Base Layer"); //rotateLeftAnimation = Animator.StringToHash("Base Layer.turning-left"); //rotateRightAnimation = Animator.StringToHash("Base Layer.turning-right"); /* ANIMACAO DA CABECA * if (!head) * head = findBone(anim.transform, "mixamorig:Head"); * if (!head) * head = findBone(anim.transform, "Head"); * if (!head) * head = findBone(anim.transform, "head"); * if (!head) * head = findBone(anim.transform, "Neck"); * if (!head) * head = findBone(anim.transform, "neck"); * if (!head) * head = anim.transform.Find("mixamorig:Hips/mixamorig:Spine/mixamorig:Spine1/mixamorig:Spine2/mixamorig:Neck/mixamorig:Head"); * * if (!head) * { * Debug.LogWarning(gameObject.name + " No head transform - LookAt disabled"); * enabled = false; * return; * } * else * { * lookAtTargetPosition = head.position + transform.forward; * lookAtPosition = lookAtTargetPosition; * } */ }
//--------------------------------------------------------------------------------------------- //OUTCOMEOFINTERACTION------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- //----0<x<1 No //----x>1 Yes public float engageInDialog(GajoCitizen interactionPartner) { if (interactionPartner.metabolism == null) { return(0); } if (_parent.metabolism == null) { return(0); } //calcula utility float[] my_chemicals = new float[3]; my_chemicals = _parent.metabolism.chemicals; float[] other_chemicals = new float[3]; other_chemicals = interactionPartner.metabolism.chemicals; float relationRP = 0; for (int i = 0; i < my_chemicals.Length; i++) { relationRP += my_chemicals[i] * other_chemicals[i]; } float utility = 1 - 1 / (1 + relationRP); //calcula psychology float psychol = psychologyAccessment(_parent.behavior.psy.mood, interactionPartner.behavior.psy.mood); //soma e determina float outcome = 0; outcome = utility + psychol; return(outcome); }
public float negoceia(GajoCitizen prey, bool isTradingForReal) { float reward = 0; float overplusThreshold_I = _owner.metabolism.gajoFomeEnergyThereshold * 0.25f; float needThreshold_I = 1000; // _owner.metabolism.gajoFomeEnergyThereshold * 2.00f; float overplusThreshold_J = prey.metabolism.gajoFomeEnergyThereshold * 0.25f; float needThreshold_J = 1000; // prey.metabolism.gajoFomeEnergyThereshold * 2.00f; PotencialNegocio[] listaDePotenciais = new PotencialNegocio[3]; int indiceNaLista = 0; int totalOfTradedResources = 0; if (prey != null) { indiceNaLista = 0; //MARCA OS SURPLUS DO I, em que o J tem falta for (int idx = 0; idx < 3; idx++) { PotencialNegocio negocio = new PotencialNegocio(); negocio.index_I = -1; negocio.index_J = -1; negocio.quantidade_I = 0; negocio.quantidade_J = 0; //Marca Surplus de I com correspondencia na necessidade de J if (_owner.metabolism.chemicals[idx] != -1 && prey.metabolism.chemicals[idx] != -1) { if (_owner.metabolism.chemicals[idx] > overplusThreshold_I) //Se i tem surplus { if (prey.metabolism.chemicals[idx] < needThreshold_J) //Se j tem necessidade { negocio.index_I = idx; negocio.quantidade_I = _owner.metabolism.chemicals[idx] - (overplusThreshold_I); listaDePotenciais[indiceNaLista++] = negocio; } } } } //MARCA OS surplus Do J na lista if (listaDePotenciais.Length > 0) { for (int idx = 0; idx < 3; idx++) { if (_owner.metabolism.chemicals[idx] != -1 && prey.metabolism.chemicals[idx] != -1) { if (prey.metabolism.chemicals[idx] > overplusThreshold_J) //Se j tem surplus { if (_owner.metabolism.chemicals[idx] < needThreshold_I) //Se i tem necessidade //vamos ver se encontramos um registo vazio para preencher { for (int i_index = 0; i_index < listaDePotenciais.Length; i_index++) { if (listaDePotenciais[i_index].index_J == -1)//se ainda esta em branco { listaDePotenciais[i_index].index_J = idx; listaDePotenciais[i_index].quantidade_J = prey.metabolism.chemicals[idx] - (overplusThreshold_J); } } } } } } } //FAZ TRANSACOES for (int i = 0; i < listaDePotenciais.Length; i++) { PotencialNegocio pn = listaDePotenciais[i]; if (listaDePotenciais[i].index_I == -1 || listaDePotenciais[i].index_J == -1) { break; } int amount = 0; if (pn.quantidade_I > pn.quantidade_J) { amount = (int)pn.quantidade_J; } else { amount = (int)pn.quantidade_I; } totalOfTradedResources += amount; if (isTradingForReal) { //Carrega traded resources que sao oferecidas pelo partner _owner.metabolism.chemicals[(int)pn.index_J] += amount; prey.metabolism.chemicals[(int)pn.index_I] += amount; //Remove traded resources from repositories _owner.metabolism.chemicals[(int)pn.index_I] -= amount; prey.metabolism.chemicals[(int)pn.index_J] -= amount; } } //CARREGAR MOTIVACAO _owner.behavior.Interacao.Memoria.ganhoTradingOrSocializing = totalOfTradedResources; prey.behavior.Interacao.Memoria.ganhoTradingOrSocializing = totalOfTradedResources; } if (totalOfTradedResources > 0) { reward = 1 - 1 / (float)totalOfTradedResources; } return(reward); }
public Trade(GajoCitizen g1, GajoCitizen g2) { _g1 = g1; _g2 = g2; }
//--------------------------------------------------------------------------- public void die() { _owner = null; myanimations = null; }
//-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //ATTEMPT TO MATE----------------------------------------------------------------------- //-------------------------------------------------------------------------------------- public float attemptMate(GajoCitizen closestMate, bool isSocializingForReal) { _owner.whatAmIDoing = TypeOfActionBeingPerformed.ATTEMPT_MATE; float reward = 0; if (closestMate != null) { if (closestMate.iEstado == GajoCitizen.GajoState.VIVO && _owner.iEstado == GajoCitizen.GajoState.VIVO) {//Exception se entretanto o outro morreu_owner.walker.target = closestMate.transform.position; closestMate.whatAmIDoing = TypeOfActionBeingPerformed.ATTEMPT_MATE; float other_excessiveBonding = closestMate.metabolism.connectednessLevelForSuccessThreshold * 2f; if (closestMate.metabolism.connectedness < other_excessiveBonding) {//DIALOGAM //-------------// //Mensagens _owner.behavior.actions.myanimations.interactionState = InteractionAnimations.MyState.MATE_YESinitiative_WIN; if (closestMate.walker.Animacao != null) { closestMate.behavior.actions.myanimations.interactionState = InteractionAnimations.MyState.MATE_NOinitiative_WIN; } _owner.whatAmIDoing = TypeOfActionBeingPerformed.ATTEMPT_MATE_COOPERA; closestMate.whatAmIDoing = TypeOfActionBeingPerformed.ATTEMPT_MATE_COOPERA; _owner.behavior.Interacao.Memoria.isCooperativeInteractionC = true; closestMate.behavior.Interacao.Memoria.isCooperativeInteractionC = true; //-------------// float durationInteraction1 = 5f - (_owner.behavior.relaxation * 10f * 0.25f); _owner.startInteraction(closestMate, durationInteraction1); _owner.behavior.Interacao.isInteracting = true; closestMate.behavior.Interacao.isInteracting = true; _owner.behavior.dispatcherSpeed = 2.5f; reward = 1; // _owner.behavior.Interacao.Memoria.ganhoTradingOrSocializing = 1; // closestMate.behavior.Interacao.Memoria.ganhoTradingOrSocializing = 1; //-------------// if (isSocializingForReal) { reproduz(); _owner.metabolism.connectedness += _owner.metabolism.boostConnectednessWithEncounters; closestMate.metabolism.connectedness += closestMate.metabolism.boostConnectednessWithEncounters; } } else {//NAO DIALOGAM //Mensagens _owner.behavior.actions.myanimations.interactionState = InteractionAnimations.MyState.MATE_YESinitiative_LOSE; if (closestMate.walker.Animacao != null) { closestMate.behavior.actions.myanimations.interactionState = InteractionAnimations.MyState.MATE_NOinitiative_LOSE; } _owner.whatAmIDoing = TypeOfActionBeingPerformed.ATTEMPT_MATE_NAOCOOPERA; closestMate.whatAmIDoing = TypeOfActionBeingPerformed.ATTEMPT_MATE_NAOCOOPERA; _owner.behavior.Interacao.Memoria.isCooperativeInteractionC = false; closestMate.behavior.Interacao.Memoria.isCooperativeInteractionC = false; _owner.behavior.Interacao.isInteracting = false; closestMate.behavior.Interacao.isInteracting = false; reward = 0; // _owner.behavior.Interacao.Memoria.ganhoTradingOrSocializing = 0; // closestMate.behavior.Interacao.Memoria.ganhoTradingOrSocializing = 0; } //reset walking target _owner.walker.target = _owner.transform.position; _owner.walker.Animacao.enabled = true; } //closestMate!=null } //-------------------------------------------------- //temos que forçar aqui porque closestMate é passivo closestMate.behavior.registaMemoria(); //------------------------------------------------- return(reward); }
//-------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- public void startInteraction(GajoCitizen g, float duracao) { behavior.Interacao.start(g, duracao); }
//RFAfim //------------------------------------ //------------------------------------ public void setOwner(GajoCitizen owner) { _owner = owner; }
//------------------------------------ public int getIndexGajo(GajoCitizen g1) { for (int i = 0; i < listaGajos.Count; i++) if (g1.getId() == listaGajos[i].getId()) return i; return -1; }
//------------------------------------ public void die() { isDispatcherActive = false; _owner = null; }
//-------------------------------------------------------------------------------- public void init(GajoCitizen g) { _owner = g; InvokeRepeating("checkIfIsInSamePlaceForTooLong", 1f, 4f); }
public InteractionAnimations(GajoCitizen owner) { _owner = owner; }
public Socialize(GajoCitizen g1, GajoCitizen g2) { _g1 = g1; _g2 = g2; }
public Actions(GajoCitizen owner) { _owner = owner; myanimations = new InteractionAnimations(_owner); }