public float radiusRun = 15f; //radio para huir void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kinGlameow = glameow.kineticsAgent; steeringGlameow = glameow.steeringAgent; kineticsTarget = target.kineticsAgent; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; Vector3 center = (kinGlameow.transform.position + kineticsTarget.transform.position) / 2; //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: //este es seek pero en verdad como meowth le hace seek tambien pareciera que huye FollowTarget seekTarget = new FollowTarget(steeringGlameow, kinGlameow, kineticsTarget, maxSeekAccel); //el target es null porque todavia no sabemos cual trainer se acercara ArriveToTarget arriveTrainer = new ArriveToTarget(steeringGlameow, kinGlameow, null, MaxAccelerationArrive, glameow.maxspeed, targetRadiusArrive, slowRadiusArrive); Kinetics[] targets = new Kinetics[2]; targets[0] = kineticsTrainer; targets[1] = kineticsRival; SetArriveTarget setTrainer = new SetArriveTarget(targets, arriveTrainer); //seek closes StopMoving stop = new StopMoving(kinGlameow, steeringGlameow); ShowIcon showHeart = new ShowIcon(this.gameObject, "Heart"); DisableIcon disableHeart = new DisableIcon(this.gameObject, "Heart"); ShowIcon showSweat = new ShowIcon(this.gameObject, "Sweat"); DisableIcon disableSweat = new DisableIcon(this.gameObject, "Sweat"); ShowIcon showExclamation = new ShowIcon(this.gameObject, "Exclamation"); DisableIcon disableExclamation = new DisableIcon(this.gameObject, "Exclamation"); //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para huir de anamorado (meowth) entryActions = new List <Action>() { showSweat }; //al entrar al estado ponemos un corazon actions = new List <Action>() { seekTarget }; //durante el estado perseguimos al enamorado exitActions = new List <Action>() { disableSweat }; //al salir quitamos el corazon State stalked = new State(actions, entryActions, exitActions); //2.b estado para alertarse de entrenador cercano entryActions = new List <Action>() { showExclamation, stop }; //al entrar al estado debemos mostrar un signo de exclamacion actions = new List <Action>(); exitActions = new List <Action>() { disableExclamation }; //al salir quitamos el signo State alert = new State(actions, entryActions, exitActions); //2.c estado para perseguir enamorado al entrenador entryActions = new List <Action> { setTrainer, showHeart }; actions = new List <Action>() { arriveTrainer }; exitActions = new List <Action> { disableHeart }; State stalkTrainer = new State(actions, entryActions, exitActions); //3. CONDICIONES: TooCloseToPoint closeCenterTrainer = new TooCloseToPoint(center, kineticsTrainer, radiusAlert); TooClose closeTrainer = new TooClose(kinGlameow, kineticsTrainer, radiusAlert); TooClose veryCloseTrainer = new TooClose(kinGlameow, kineticsTrainer, radiusRun); TooCloseToPoint closeCenterRival = new TooCloseToPoint(center, kineticsRival, radiusAlert); TooClose closeRival = new TooClose(kinGlameow, kineticsRival, radiusAlert); TooClose veryCloseRival = new TooClose(kinGlameow, kineticsRival, radiusRun); //Estas son las que de verdad necesitamos OrCondition anyTargetCloseCenter = new OrCondition(closeCenterRival, closeCenterTrainer); OrCondition anyTargetClose = new OrCondition(closeTrainer, closeRival); OrCondition anyTargetVeryClose = new OrCondition(veryCloseRival, veryCloseTrainer); NotCondition noOneClose = new NotCondition(anyTargetClose); List <Action> noActions = new List <Action>(); //4. TRANSICIONES: Transition anyHumanClose = new Transition(anyTargetCloseCenter, noActions, alert); Transition noHumanClose = new Transition(noOneClose, noActions, stalkTrainer); Transition anyHumanVeryClose = new Transition(anyTargetVeryClose, noActions, stalkTrainer); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions = new List <Transition>() { anyHumanClose }; stalked.transitions = transitions; transitions = new List <Transition>() { noHumanClose, anyHumanVeryClose }; alert.transitions = transitions; transitions = new List <Transition>(); stalkTrainer.transitions = transitions; //5 MAQUINA DE ESTADOS State[] states = new State[] { stalked, alert, stalkTrainer }; glameowMachine = new StateMachine(states, stalked); }
// public float radiusAlert = 40f;//radio para alertarse // public float radiusRun = 35f;//radio para huir void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; sightSensor = sightComponent.sensor; sightSensorPokemon = sightComponentPokemon.sensor; soundSensor = soundComponent.sensor; //Piedras stones = GameObject.FindGameObjectsWithTag("Stone"); List <GameObject> stonesList = new List <GameObject>(stones); //Inicializamos grafo y A* graph = graphComponent.graph; aStar = new PathFindAStar(graph, null, null, null, walkable); //Inicializamos seek seek = new Seek(kineticsAgent, kineticsAgent, maxAccel); //Inicializamos lookwehereyougoing look = new LookWhereYouAreGoing(kineticsAgent); //Obstaculos GameObject[] obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); obstacle_data[] obstaclesData = new obstacle_data[obstacles.Length]; for (int k = 0; k < obstacles.Length; k++) { obstaclesData[k] = obstacles[k].GetComponent <obstacle_data>(); } //Puntos estrategicos strategicPoints = pointsComponent.coverNodes; //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: //acciones relacionadas a astar FollowPathOfPoints followPath = new FollowPathOfPoints(steeringAgent, seek, null, false); UpdateFollowPathWithAstar updateFollow = new UpdateFollowPathWithAstar(followPath, aStar, obstaclesData); UpdateAstarBestCoverPoint updateAstarCover = new UpdateAstarBestCoverPoint(strategicPoints, transform, new Transform[] { kineticsRival.transform, kineticsTrainer.transform }, obstaclesData, graph, aStar, walkable); UpdateAStarSeenStone updateAstarStone = new UpdateAStarSeenStone(sightSensor, aStar, graph, transform, walkable); //acciones de manejo de giros SetAngularSpeed setDefaultRotation = new SetAngularSpeed(kineticsAgent, 10f); SetAngularSpeed setZeroRotation = new SetAngularSpeed(kineticsAgent, 0f); StopMoving stop = new StopMoving(kineticsAgent, steeringAgent); LookWhereGoing lookAction = new LookWhereGoing(look, steeringAgent); //acciones de manejo de srpites ShowDefaultSprite defaultSprite = new ShowDefaultSprite(pokemonData); RunSprite showRunSprite = new RunSprite(pokemonData); Evolve2 evolve; ShowIcon showExclamation = new ShowIcon(this.gameObject, "Exclamation"); DisableIcon disableExclamation = new DisableIcon(this.gameObject, "Exclamation"); ShowIcon showSweat = new ShowIcon(this.gameObject, "Sweat"); DisableIcon disableSweat = new DisableIcon(this.gameObject, "Sweat"); //acciones de asistencia ResetSensor resetSight = new ResetSensor(sightSensor); ResetSensor resetSightPokemon = new ResetSensor(sightSensorPokemon); ResetSensor resetSound = new ResetSensor(soundSensor); ResetSensorList resetSensors = new ResetSensorList(new List <ResetSensor>() { resetSight, resetSound, resetSightPokemon }); //acciones de tiempo SetTimer setAlertTime; //acciones que modifican la maquina de estados misma RemoveStateTransition removeTouchStone; RemoveStateTransition removeSawStone; RemoveStateTransition removeSawStone2; RemoveAction removeDefaultSpriteAction; RemoveAction removeRunSpriteAction; RemoveAction removeRunSpriteAction2; //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para esperar sin hacer nada //durante este estado eevee estara quieto hasta que algun humano lo haga reaccionar entryActions = new List <Action>() { stop, defaultSprite, setZeroRotation, resetSensors }; //al entrar al estado debemos parar y sentarnos removeDefaultSpriteAction = new RemoveAction(defaultSprite, entryActions); actions = new List <Action>() { }; //hacer guardia girando exitActions = new List <Action>() { }; State wait = new State(actions, entryActions, exitActions); //2.b estado para sorprenderse //durante este estado eevee dara vueltas en alterta angustiado porque escucho algo, este estado durara solo cierto tiempo entryActions = new List <Action>() { showExclamation, setDefaultRotation }; //al entrar al estado debemos sorprendernos actions = new List <Action>() { }; exitActions = new List <Action>() { disableExclamation, setZeroRotation }; //al salir dejamos de sorprendernos State alert = new State(actions, entryActions, exitActions); //2.c estado para perseguir piedra //durante este estado eevee se concentrara unicamente en buscar las piedra que vio entryActions = new List <Action>() { updateAstarStone, updateFollow, showExclamation, showRunSprite }; //al entrar al estado debemos actualizar el a* y luego el camino removeRunSpriteAction2 = new RemoveAction(showRunSprite, entryActions); actions = new List <Action>() { followPath, lookAction }; //durante la accion seguimos el camino exitActions = new List <Action>() { disableExclamation }; //al salir no hacemos nada State followStone = new State(actions, entryActions, exitActions); //2.d estado para perseguir punto de encuentro //durante este estado eevee buscara donde esconderse, puede verse interrumpido si accidentalmente toca una piedra o se comprometio su escondite entryActions = new List <Action>() { updateAstarCover, updateFollow, showSweat, showRunSprite, resetSensors }; //al entrar al estado debemos actualizar el a* y luego el camino removeRunSpriteAction = new RemoveAction(showRunSprite, entryActions); actions = new List <Action>() { followPath, lookAction }; //durante la accion seguimos el camino exitActions = new List <Action>() { disableSweat }; //al salir no hacemos nada State followCoverPoint = new State(actions, entryActions, exitActions); //2.extra dummy states //estos estados son de relleno para facilitar la activacion de ciertas acciones en le orden adecuado entryActions = new List <Action>(); //al entrar al estado debemos parar y sentarnos actions = new List <Action>(); //hacer guardia girando exitActions = new List <Action>(); //al salir no hacemos nada State evolveState1 = new State(actions, entryActions, exitActions); State evolveState2 = new State(actions, entryActions, exitActions); //3. CONDICIONES: SawSomething sawStone = new SawSomething(sightSensor, "Stone"); //si vemos una piedra evolutiva SawSomething sawHuman = new SawSomething(sightSensor, "Human"); //si vemos una persona HeardSomething heardHumanClose = new HeardSomething(soundSensor, "Human", 0f); //si escuchamos a un humano cerca HeardSomething heardHumanVeryClose = new HeardSomething(soundSensor, "Human", 5f); //si escuchamos a un humanos muy cerca TouchedGameObjects touchedStone = new TouchedGameObjects(stonesList, transform, "Sun"); //si tocamos una piedra evolutiva evolve = new Evolve2(pokemonData, touchedStone, updateAstarCover, aStar); FollowArrived arrived = new FollowArrived(followPath, transform); //si llegamos al objetivo de follow PokemonInCoverPoint otherInMyCover = new PokemonInCoverPoint(aStar, sightSensorPokemon, transform); //si vemos que un pokemon se metio en nuestro escondite TimeOut alertTimeOut = new TimeOut(5f); setAlertTime = new SetTimer(alertTimeOut); TrueCondition alwaysTrue = new TrueCondition(); //4. TRANSICIONES: List <Action> transitionsActions; List <Action> noActions = new List <Action>(); transitionsActions = new List <Action>() { setAlertTime }; Transition heardCloseHuman = new Transition(heardHumanClose, transitionsActions, alert); Transition seemsSafe = new Transition(alertTimeOut, noActions, wait); Transition heardVeryCloseHuman = new Transition(heardHumanVeryClose, noActions, followCoverPoint); transitionsActions = new List <Action>() { }; Transition sawAhuman = new Transition(sawHuman, transitionsActions, followCoverPoint); Transition sawAstone = new Transition(sawStone, transitionsActions, followStone); Transition pokemonInMyCover = new Transition(otherInMyCover, transitionsActions, followCoverPoint); //transiciones dummy transitionsActions = new List <Action>() { evolve }; Transition evolving1 = new Transition(alwaysTrue, transitionsActions, followCoverPoint); Transition evolving2 = new Transition(alwaysTrue, transitionsActions, wait); transitionsActions = new List <Action>() { evolve, removeDefaultSpriteAction, removeRunSpriteAction, removeRunSpriteAction2 }; Transition touchStone1 = new Transition(touchedStone, transitionsActions, evolveState1); Transition touchStone2 = new Transition(touchedStone, transitionsActions, evolveState2); //si evolucionamos debemos quitar las transiciones relacionadas a las stones removeSawStone = new RemoveStateTransition(sawAstone, followCoverPoint); removeSawStone2 = new RemoveStateTransition(sawAstone, alert); removeTouchStone = new RemoveStateTransition(touchStone1, followCoverPoint); transitionsActions.Add(removeSawStone); transitionsActions.Add(removeSawStone2); transitionsActions.Add(removeTouchStone); Transition arrivedFollowEnd = new Transition(arrived, noActions, wait); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions; transitions = new List <Transition>() { sawAhuman, heardCloseHuman }; wait.transitions = transitions; transitions = new List <Transition>() { sawAhuman, sawAstone, heardVeryCloseHuman, seemsSafe }; alert.transitions = transitions; transitions = new List <Transition>() { evolving1 }; evolveState1.transitions = transitions; transitions = new List <Transition>() { evolving2 }; evolveState2.transitions = transitions; transitions = new List <Transition>() { touchStone1, sawAstone, pokemonInMyCover, arrivedFollowEnd, sawAhuman }; followCoverPoint.transitions = transitions; transitions = new List <Transition>() { touchStone2, arrivedFollowEnd, pokemonInMyCover }; followStone.transitions = transitions; //5 MAQUINA DE ESTADOS State[] states = new State[] { wait, alert, followCoverPoint, followStone, evolveState1, evolveState2 }; eeveeMachine = new StateMachine(states, wait); }
public float radiusChange = 5f;//radio para asustarse y cambiar gas venenoso void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kinRoselia = roselia.kineticsAgent; steeringRoselia = roselia.steeringAgent; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; Kinetics[] targets = new Kinetics[2]; targets[0] = kineticsTrainer; targets[1] = kineticsRival; //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: ShowIcon showSweet = new ShowIcon(this.gameObject, "SweetGas"); DisableIcon disableSweet = new DisableIcon(this.gameObject, "SweetGas"); ShowIcon showPoison = new ShowIcon(this.gameObject, "PoisonGas"); DisableIcon disablePoison = new DisableIcon(this.gameObject, "PoisonGas"); ChangeSmellSent changeSmellPoison = new ChangeSmellSent(sendSmell, "Poison"); ChangeSmellSent changeSmellSweet = new ChangeSmellSent(sendSmell, "Sweet"); SetTimer setPoisonTimer; //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para seguir camino entryActions = new List <Action>() { showSweet, changeSmellSweet }; actions = new List <Action>(); exitActions = new List <Action>() { disableSweet }; State sweetGasState = new State(actions, entryActions, exitActions); entryActions = new List <Action>() { showPoison, changeSmellPoison }; actions = new List <Action>(); exitActions = new List <Action>() { disablePoison }; State poisonGasState = new State(actions, entryActions, exitActions); //3. CONDICIONES: // roselia solo usara veneno durante 30 segs TimeOut poisonTimer = new TimeOut(30f); setPoisonTimer = new SetTimer(poisonTimer); TooClose closeTrainer = new TooClose(kinRoselia, kineticsTrainer, radiusChange); TooClose closeRival = new TooClose(kinRoselia, kineticsRival, radiusChange); OrCondition anyTargetClose = new OrCondition(closeTrainer, closeRival); NotCondition noOneClose = new NotCondition(anyTargetClose); //4. TRANSICIONES: List <Action> noActions = new List <Action>(); List <Action> transitionActions; transitionActions = new List <Action>() { setPoisonTimer }; Transition anyHumanClose = new Transition(anyTargetClose, transitionActions, poisonGasState); transitionActions = new List <Action>(); Transition poisonTimeOut = new Transition(poisonTimer, transitionActions, sweetGasState); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions = new List <Transition>() { anyHumanClose }; sweetGasState.transitions = transitions; transitions = new List <Transition>() { poisonTimeOut }; poisonGasState.transitions = transitions; //5 MAQUINA DE ESTADOS State[] states = new State[] { sweetGasState, poisonGasState }; roseliaMachine = new StateMachine(states, sweetGasState); }
public float radiusRun = 15f; //radio para huir void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kinMeowth = meowth.kineticsAgent; steeringMeowth = meowth.steeringAgent; kineticsTarget = target.kineticsAgent; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; // Centro de masa de glameow y meowth sera util pra cierta condicion Vector3 center = (kinMeowth.transform.position + kineticsTarget.transform.position) / 2; //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: FollowTarget seekTarget = new FollowTarget(steeringMeowth, kinMeowth, kineticsTarget, maxSeekAccel); FollowTarget seekWorried = new FollowTarget(steeringMeowth, kinMeowth, kineticsTarget, 100f); Kinetics[] targets = new Kinetics[2]; targets[0] = kineticsTrainer; targets[1] = kineticsRival; RunFromTargets runFromTargets = new RunFromTargets(steeringMeowth, kinMeowth, targets, maxSeekAccel * 5); StopMoving stop = new StopMoving(kinMeowth, steeringMeowth); UpdateMaxSpeed moreMaxSpeed = new UpdateMaxSpeed(meowth, meowth.maxspeed * 5); // esto ayudara a aumentar la maxspeed UpdateMaxSpeed speedBackToNormal = new UpdateMaxSpeed(meowth, meowth.maxspeed); // esto guarda la maxspeed original para volverla a poner asi ShowIcon showHeart = new ShowIcon(this.gameObject, "Heart"); DisableIcon disableHeart = new DisableIcon(this.gameObject, "Heart"); ShowIcon showSweat = new ShowIcon(this.gameObject, "Sweat"); DisableIcon disableSweat = new DisableIcon(this.gameObject, "Sweat"); ShowIcon showExclamation = new ShowIcon(this.gameObject, "Exclamation"); DisableIcon disableExclamation = new DisableIcon(this.gameObject, "Exclamation"); //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para perseguir enamorado (glameow) entryActions = new List <Action>() { showHeart }; //al entrar al estado ponemos un corazon actions = new List <Action>() { seekTarget }; //durante el estado perseguimos al enamorado exitActions = new List <Action>() { disableHeart }; //al salir quitamos el corazon State stalkTarget = new State(actions, entryActions, exitActions); //2.b estado para alertarse de entrenador cercano entryActions = new List <Action>() { showExclamation, stop }; //al entrar al estado debemos mostrar un signo de exclamacion actions = new List <Action>(); exitActions = new List <Action>() { disableExclamation }; //al salir quitamos el signo State alert = new State(actions, entryActions, exitActions); //2,c estado para perseguir sin corazon entryActions = new List <Action>();//al entrar al estado ponemos un corazon actions = new List <Action>() { seekTarget }; //durante el estado perseguimos al enamorado exitActions = new List <Action>(); //al salir quitamos el corazon State stalk = new State(actions, entryActions, exitActions); //2.d estado para huir del entrenador entryActions = new List <Action>() { moreMaxSpeed }; actions = new List <Action>() { runFromTargets }; exitActions = new List <Action>() { speedBackToNormal }; State runAway = new State(actions, entryActions, exitActions); //2.e estado para preocuparse por alguien y seguirlo preocupado entryActions = new List <Action>() { showSweat, disableHeart, disableExclamation }; actions = new List <Action>() { seekWorried }; exitActions = new List <Action>() { disableSweat }; State worry = new State(actions, entryActions, exitActions); //3. CONDICIONES: TooCloseToPoint closeCenterTrainer = new TooCloseToPoint(center, kineticsTrainer, radiusAlert); TooClose closeTrainer = new TooClose(kinMeowth, kineticsTrainer, radiusAlert); TooClose veryCloseTrainer = new TooClose(kinMeowth, kineticsTrainer, radiusRun); TooCloseToPoint closeCenterRival = new TooCloseToPoint(center, kineticsRival, radiusAlert); TooClose closeRival = new TooClose(kinMeowth, kineticsRival, radiusAlert); TooClose veryCloseRival = new TooClose(kinMeowth, kineticsRival, radiusRun); //Estas son las que de verdad necesitamos OrCondition anyTargetCloseCenter = new OrCondition(closeCenterRival, closeCenterTrainer); OrCondition anyTargetClose = new OrCondition(closeTrainer, closeRival); OrCondition anyTargetVeryClose = new OrCondition(veryCloseRival, veryCloseTrainer); NotCondition noOneClose = new NotCondition(anyTargetClose); NotCondition noOneVeryClose = new NotCondition(anyTargetVeryClose); WasCaught targetCaught = new WasCaught(kineticsTarget); List <Action> noActions = new List <Action>(); //4. TRANSICIONES: Transition anyHumanCloseCenter = new Transition(anyTargetCloseCenter, noActions, alert); Transition anyHumanClose = new Transition(anyTargetClose, noActions, alert); Transition noHumanClose = new Transition(noOneClose, noActions, stalk); Transition anyHumanVeryClose = new Transition(anyTargetVeryClose, noActions, runAway); Transition noHumanVeryClose = new Transition(noOneVeryClose, noActions, alert); Transition targetWasCaught = new Transition(targetCaught, noActions, worry); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions = new List <Transition>() { anyHumanCloseCenter, targetWasCaught }; stalkTarget.transitions = transitions; transitions = new List <Transition>() { noHumanClose, anyHumanVeryClose, targetWasCaught }; alert.transitions = transitions; transitions = new List <Transition>() { anyHumanClose, targetWasCaught }; stalk.transitions = transitions; transitions = new List <Transition>() { noHumanVeryClose, targetWasCaught }; runAway.transitions = transitions; worry.transitions = new List <Transition>();//es un sumidero //5 MAQUINA DE ESTADOS State[] states = new State[] { stalkTarget, alert, stalk, runAway, worry }; meowthMachine = new StateMachine(states, stalkTarget); }
// Start is called before the first frame update void Start() { //DATOS EXTERNOS smellSensor = smellSensorScript.sensor; soundSensor = soundSensorScript.sensor; kinTrainer = trainerStaticData.kineticsAgent; steeringTrainer = trainerStaticData.steeringAgent; //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: ShowIcon showPoisoned = new ShowIcon(this.gameObject, "Poisoned"); DisableIcon disablePoisoned = new DisableIcon(this.gameObject, "Poisoned"); ShowIcon showSleep = new ShowIcon(this.gameObject, "Sleeping"); DisableIcon disableSleep = new DisableIcon(this.gameObject, "Sleeping"); SetTimer setPoisonClock; SetTimer setSleepClock; ResetSensor resetSmellSensor = new ResetSensor(smellSensor); ResetSensor resetSoundSensor = new ResetSensor(soundSensor); List <ResetSensor> resets = new List <ResetSensor>() { resetSmellSensor, resetSoundSensor }; ResetSensorList resetAllSensor = new ResetSensorList(resets); UpdateMaxSpeed setOriginalSpeed = new UpdateMaxSpeed(trainerStaticData, trainerStaticData.maxspeed); UpdateMaxSpeed setSlowSpeed = new UpdateMaxSpeed(trainerStaticData, poisonedSpeed); UpdateMaxSpeed setZeroSpeed = new UpdateMaxSpeed(trainerStaticData, 0f); SetAngularSpeed setAngularToZero = new SetAngularSpeed(kinTrainer, 0f); SetAngularAccel setAngularAccelToZero = new SetAngularAccel(steeringTrainer, 0f); //accion para deshabilitar todos scripts de interes mientras dormimos List <DisableScript> disables = new List <DisableScript>(); foreach (var script in scriptsToDisable) { disables.Add(new DisableScript(script)); } DisableScriptList disableScripts = new DisableScriptList(disables); //accion para habilitar todos los script de interes si despertamos List <EnableScript> enables = new List <EnableScript>(); foreach (var script in scriptsToDisable) { enables.Add(new EnableScript(script)); } EnableScriptList enableScripts = new EnableScriptList(enables); //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado donde estamos sanos entryActions = new List <Action>(); //al entrar al estado ponemos un corazon actions = new List <Action>(); //durante el estado perseguimos al enamorado exitActions = new List <Action>(); //al salir quitamos el corazon State healthyState = new State(actions, entryActions, exitActions); //2.b estado donde estamos envenenados entryActions = new List <Action>() { showPoisoned, setSlowSpeed }; //al entrar al estado ponemos un corazon actions = new List <Action>(); //durante el estado perseguimos al enamorado exitActions = new List <Action>() { disablePoisoned, resetAllSensor, setOriginalSpeed }; //al salir quitamos el corazon State poisonedState = new State(actions, entryActions, exitActions); //2.c estado donde estamos dormidos entryActions = new List <Action>() { showSleep, setZeroSpeed, disableScripts, setAngularAccelToZero, setAngularToZero }; //al entrar al estado ponemos un corazon actions = new List <Action>(); //durante el estado perseguimos al enamorado //al salir debemos: // quitar el icono de dormir, resetear el sensor de sonido, reset el sensor de aroma porque puede haber un sweet // volver a habilitar lo que se deba exitActions = new List <Action>() { disableSleep, resetAllSensor, setOriginalSpeed, enableScripts }; //al salir quitamos el corazon State sleepState = new State(actions, entryActions, exitActions); //3. CONDICIONES: SmelledSomething smelledPoison = new SmelledSomething(smellSensor, "Poison"); SmelledSomething smelledSweet = new SmelledSomething(smellSensor, "Sweet"); HeardSleepSong heardSong = new HeardSleepSong(soundSensor); TimeOut poisonClock = new TimeOut(poisonTimer); setPoisonClock = new SetTimer(poisonClock); TimeOut sleepClock = new TimeOut(sleepTimer); setSleepClock = new SetTimer(sleepClock); //4. TRANSICIONES: List <Action> noActions = new List <Action>(); List <Action> transitionActions; transitionActions = new List <Action>() { setPoisonClock }; Transition gotPoisoned = new Transition(smelledPoison, transitionActions, poisonedState); Transition poisonTimeOut = new Transition(poisonClock, noActions, healthyState); Transition sweetScent = new Transition(smelledSweet, noActions, healthyState); transitionActions = new List <Action>() { setSleepClock }; Transition gotSlept = new Transition(heardSong, transitionActions, sleepState); Transition sleepTimeOut = new Transition(sleepClock, noActions, healthyState); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions; transitions = new List <Transition>() { gotPoisoned, gotSlept };; healthyState.transitions = transitions; poisonedState.transitions = new List <Transition>() { poisonTimeOut, sweetScent }; sleepState.transitions = new List <Transition>() { sleepTimeOut, sweetScent }; //5 MAQUINA DE ESTADOS State[] states = new State[] { healthyState, poisonedState, sleepState }; trainerStatusMachine = new StateMachine(states, healthyState); }
void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kinDugtrio = dugtrio.kineticsAgent; steeringDugtrio = dugtrio.steeringAgent; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; graph = graphComponent.graph; aStar = new PathFindAStar(graph, null, null, null, walkable); seek = new Seek(kinDugtrio, kinDugtrio, dugtrio.maxspeed); Kinetics[] targets = new Kinetics[2]; targets[0] = kineticsTrainer; targets[1] = kineticsRival; //obstaculos GameObject[] obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); obstacle_data[] obstaclesData = new obstacle_data[obstacles.Length]; for (int k = 0; k < obstacles.Length; k++) { obstaclesData[k] = obstacles[k].GetComponent <obstacle_data>(); } //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: UpdateAStarRandom updateAStar = new UpdateAStarRandom(aStar, graph, kinDugtrio, null, walkable); ShowIcon showHole = new ShowIcon(this.gameObject, "Digging"); DisableIcon disableHole = new DisableIcon(this.gameObject, "Digging"); FollowPathOfPoints followPath = new FollowPathOfPoints(steeringDugtrio, seek, null, true); UpdateFollowPathWithAstar updateFollow = new UpdateFollowPathWithAstar(followPath, aStar, obstaclesData); MoveOnZ underground = new MoveOnZ(transform, undergroundCoord); MoveOnZ getOutOfGround = new MoveOnZ(transform, 0f); //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para seguir camino entryActions = new List <Action>() { }; actions = new List <Action>() { followPath }; //durante el estado seguimos el camino exitActions = new List <Action>() { }; State followPathState = new State(actions, entryActions, exitActions); //3. CONDICIONES: TooClose closeTrainer = new TooClose(kinDugtrio, kineticsTrainer, radiusHide); TooClose closeRival = new TooClose(kinDugtrio, kineticsRival, radiusHide); ArrivedToPosition arrived = new ArrivedToPosition(new Vector3(), transform, 10f); AmIUnderground amIunderground = new AmIUnderground(transform); updateAStar.arrived = arrived; OrCondition anyTargetClose = new OrCondition(closeTrainer, closeRival); NotCondition noOneClose = new NotCondition(anyTargetClose); NotCondition notUnderground = new NotCondition(amIunderground); AndCondition closeAndNotUndeground = new AndCondition(anyTargetClose, notUnderground); AndCondition notCloseAndUndeground = new AndCondition(noOneClose, amIunderground); List <Action> noActions = new List <Action>(); List <Action> transitionActions; //4. TRANSICIONES: transitionActions = new List <Action>() { showHole, underground }; Transition anyHumanClose = new Transition(closeAndNotUndeground, transitionActions, followPathState); transitionActions = new List <Action>() { disableHole, getOutOfGround }; Transition noHumanClose = new Transition(notCloseAndUndeground, transitionActions, followPathState); transitionActions = new List <Action>() { updateAStar, updateFollow }; Transition pathEnd = new Transition(arrived, transitionActions, followPathState); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions = new List <Transition>() { anyHumanClose, noHumanClose, pathEnd }; followPathState.transitions = transitions; //5 MAQUINA DE ESTADOS State[] states = new State[] { followPathState }; dugtrioMachine = new StateMachine(states, followPathState); updateAStar.DoAction();//esto es para inicializar el primer camino updateFollow.DoAction(); }
void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kinOctillery = octillery.kineticsAgent; steeringOctillery = octillery.steeringAgent; defaulAngularSpeed = kinOctillery.rotation; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; sightSensor = sightSensorScript.sensor; Kinetics[] targets = new Kinetics[2]; targets[0] = kineticsTrainer; targets[1] = kineticsRival; //obstacles List <Transform> obstacles_list = new List <Transform>(); GameObject[] obstaclesGo = GameObject.FindGameObjectsWithTag("Obstacle"); for (int i = 0; i < obstaclesGo.Length; i++) { obstacles_list.Add(obstaclesGo[i].GetComponent <Transform>()); } obstacles = obstacles_list.ToArray(); //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: ShowIcon showExclamation = new ShowIcon(this.gameObject, "Exclamation"); DisableIcon disableExclamation = new DisableIcon(this.gameObject, "Exclamation"); SetAngularSpeed setAngularToZero = new SetAngularSpeed(kinOctillery, 0f); SetAngularSpeed setAngularToDefault = new SetAngularSpeed(kinOctillery, defaulAngularSpeed); SetAngularAccel setAngularAccelToZero = new SetAngularAccel(steeringOctillery, 0f); ResetSensor resetSightSensor = new ResetSensor(sightSensor); FaceToSeenTarget faceTarget = new FaceToSeenTarget(sightSensor, kinOctillery, steeringOctillery); ShootInk shootInkToTarget = new ShootInk(transform, inkBallPrefab, inkSpeed, inkScreen, sightSensor, targets, obstacles); //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para seguir camino entryActions = new List <Action>() { setAngularToDefault, setAngularAccelToZero }; actions = new List <Action>(); exitActions = new List <Action>(); State guardState = new State(actions, entryActions, exitActions); entryActions = new List <Action>() { showExclamation, setAngularToZero }; actions = new List <Action>() { faceTarget, shootInkToTarget }; exitActions = new List <Action>() { disableExclamation }; State shootState = new State(actions, entryActions, exitActions); //3. CONDICIONES: // octillery solo disparara si ve un humano SawSomething sawHuman = new SawSomething(sightSensor, "Human"); // octillery solo entrara en guardia de nuevo si no hay humanos en su cono de vision NoInSightCone noHumanInCone = new NoInSightCone(sightSensor); //4. TRANSICIONES: List <Action> noActions = new List <Action>(); List <Action> transitionsActions; transitionsActions = new List <Action>() { resetSightSensor }; Transition noHumanInConeSight = new Transition(noHumanInCone, transitionsActions, guardState); Transition humanSeen = new Transition(sawHuman, noActions, shootState); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions = new List <Transition>() { humanSeen }; guardState.transitions = transitions; transitions = new List <Transition>() { noHumanInConeSight }; shootState.transitions = transitions; //5 MAQUINA DE ESTADOS State[] states = new State[] { guardState, shootState }; octilleryMachine = new StateMachine(states, guardState); }
public Transform[] allEevees; //necesitamos saber donde estan todos los eevee void Start() { //INICIALIZAMOS LA DATA DEL EXTERIOR kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; kineticsTrainer = trainer.kineticsAgent; kineticsRival = rival.kineticsAgent; Vector3 center = Vector3.zero;// Necesitamos el centro de masa de los eevee for (int k = 0; k < allEevees.Length; k++) { center += allEevees[k].transform.position; } center = center / allEevees.Length; // Centro de masas //piedras stones = GameObject.FindGameObjectsWithTag("Stone"); Stack <GameObject> stonesStack = new Stack <GameObject>(stones); //Inicializamos grafo y A* graph = graphComponent.graph; aStar = new PathFindAStar(graph, null, null, null, walkable); //Inicializamos seek seek = new Seek(kineticsAgent, kineticsAgent, maxAccel); //obstaculos GameObject[] obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); obstacle_data[] obstaclesData = new obstacle_data[obstacles.Length]; for (int k = 0; k < obstacles.Length; k++) { obstaclesData[k] = obstacles[k].GetComponent <obstacle_data>(); } //COMENZAMOS A CONSTRUIR LA MAQUINA DE ESTADOS //1. ACCIONES: UpdateAStarGameObject updateAStar = new UpdateAStarGameObject(stonesStack, aStar, graph, kineticsAgent, walkable); FollowPathOfPoints followPath = new FollowPathOfPoints(steeringAgent, seek, null, false); PopGameObject popStone = new PopGameObject(stonesStack); DestroyGameObject destroyStone = new DestroyGameObject(stonesStack); UpdateFollowPathWithAstar updateFollow = new UpdateFollowPathWithAstar(followPath, aStar, obstaclesData); UpdateAStarTarget updateAStar2 = new UpdateAStarTarget(aStar, graph, kineticsAgent, graph.GetNode(550), walkable); StopMoving stop = new StopMoving(kineticsAgent, steeringAgent); RunSprite showRunSprite = new RunSprite(pokemonData); Evolve evolve = new Evolve(pokemonData, "Sun", updateAStar, updateAStar2, aStar); updateEvolveMethod updateEvolve = new updateEvolveMethod(evolve, stonesStack); ShowIcon showExclamation = new ShowIcon(this.gameObject, "Exclamation"); DisableIcon disableExclamation = new DisableIcon(this.gameObject, "Exclamation"); ShowIcon showSweat = new ShowIcon(this.gameObject, "Sweat"); DisableIcon disableSweat = new DisableIcon(this.gameObject, "Sweat"); //2. ESTADOS: List <Action> entryActions; //aqui iremos guardanndo todas las acciondes de entrada List <Action> exitActions; //aqui iremos guardanndo todas las acciones de salida List <Action> actions; //aqui guardaremos todas las acciones intermedias //2.a estado para esperar sin hacer nada entryActions = new List <Action>() { stop }; //al entrar al estado debemos parar actions = new List <Action>(); exitActions = new List <Action>(); State wait = new State(actions, entryActions, exitActions); //2.b estado para sorprenderse entryActions = new List <Action>() { showExclamation }; //al entrar al estado debemos sorprendernos actions = new List <Action>(); exitActions = new List <Action>() { disableExclamation }; //al salir dejamos de sorprendernos State alert = new State(actions, entryActions, exitActions); //2.c estado para perseguir piedra entryActions = new List <Action>() { updateAStar, updateFollow, showSweat }; //al entrar al estado debemos actualizar el a* y luego el camino actions = new List <Action>() { followPath }; //durante la accion seguimos el camino exitActions = new List <Action>(); //al salir no hacemos nada State followStone = new State(actions, entryActions, exitActions); //2.d estado para perseguir punto de encuentro entryActions = new List <Action>() { updateAStar2, updateFollow }; //al entrar al estado debemos actualizar el a* y luego el camino actions = new List <Action>() { followPath }; //durante la accion seguimos el camino exitActions = new List <Action>(); //al salir no hacemos nada State followReunionPoint = new State(actions, entryActions, exitActions); //3. CONDICIONES: TooCloseToPoint closeTrainer = new TooCloseToPoint(center, kineticsTrainer, radiusAlert); TooCloseToPoint veryCloseTrainer = new TooCloseToPoint(center, kineticsTrainer, radiusRun); TooCloseToPoint closeRival = new TooCloseToPoint(center, kineticsRival, radiusAlert); TooCloseToPoint veryCloseRival = new TooCloseToPoint(center, kineticsRival, radiusRun); //Estas son las que de verdad necesitamos OrCondition anyTargetClose = new OrCondition(closeTrainer, closeRival); OrCondition anyTargetVeryClose = new OrCondition(veryCloseRival, veryCloseTrainer); NotCondition noOneClose = new NotCondition(anyTargetClose); NotCondition noOneVeryClose = new NotCondition(anyTargetVeryClose); GameObjectGone stoneGone = new GameObjectGone(stonesStack); //si una piedra es obtenida por alguien mas AllGameObjectGone allStoneGone = new AllGameObjectGone(stonesStack); //si se acaban las piedras ArrivedToStone arrivedToStone = new ArrivedToStone(stonesStack, transform, 2f); //si alcanzamos una piedra //4. TRANSICIONES: Transition closeHuman = new Transition(anyTargetClose, new List <Action>(), alert); Transition noHumanClose = new Transition(noOneClose, new List <Action>(), wait); Transition veryCloseHuman = new Transition(anyTargetVeryClose, new List <Action>() { showRunSprite }, followStone); Transition stoneLost = new Transition(stoneGone, new List <Action> { popStone }, followStone); Transition allStonesLost = new Transition(allStoneGone, new List <Action> { evolve, disableSweat }, followReunionPoint); Transition reachStone = new Transition(arrivedToStone, new List <Action> { updateEvolve, evolve, destroyStone, popStone, disableSweat }, followReunionPoint); //4.1 AGREGAMOS TRANSICIONES A ESTADOS List <Transition> transitions; transitions = new List <Transition>() { closeHuman }; wait.transitions = transitions; transitions = new List <Transition>() { veryCloseHuman, noHumanClose }; alert.transitions = transitions; transitions = new List <Transition>() { allStonesLost, stoneLost, reachStone }; followStone.transitions = transitions; followReunionPoint.transitions = new List <Transition>(); //5 MAQUINA DE ESTADOS State[] states = new State[] { wait, alert, followStone, followReunionPoint }; eeveeMachine = new StateMachine(states, wait); }