// Use this for initialization void Start() { states = new List <State>(); //Transitions for patroll state List <Transition> patrolltrans = new List <Transition>(); patrolltrans.Add(new GetSignalTrans(gameObject)); patrolltrans.Add(new SeeMonsterTrans(gameObject)); PatrollState patroll = new PatrollState(gameObject, patrolltrans); states.Add(patroll); //Transitions for pursue state List <Transition> pursuetrans = new List <Transition>(); pursuetrans.Add(new GetSignalTrans(gameObject)); pursuetrans.Add(new StopSeeMonsterTrans(gameObject)); PursueState pursue = new PursueState(gameObject, pursuetrans, 12f); states.Add(pursue); //Transitions for look for state List <Transition> looktrans = new List <Transition>(); looktrans.Add(new GetSignalTrans(gameObject)); looktrans.Add(new SeeMonsterTrans(gameObject)); looktrans.Add(new TimePassTrans(gameObject, 7f, "patroll")); LookForState look = new LookForState(gameObject, looktrans, 10f); states.Add(look); //Transitions for eat state List <Transition> eattrans = new List <Transition>(); eattrans.Add(new FoodDisappearsTrans(gameObject)); GoToSignalState eat = new GoToSignalState(gameObject, eattrans, 9f); states.Add(eat); initialState = patroll; currentState = patroll; triggeredTransition = null; gameObject.GetComponent <GraphPathFollowing>().astar_target = null; //Set to null just in case initialSpeed = gameObject.GetComponent <Agent>().maxSpeed; }
public BomberAgent(GameState gs, bool isBombPassable, int agentID) { this.gs = gs; this.isBombPassable = isBombPassable; this.agentId = agentID; this.chokepoints = new ChokePoints(this.gs, this.isBombPassable); this.suicideBomberFSM = new FSM<BomberAgent>(this, null, null); State<BomberAgent> state = new PursueState(this.gs, this.isBombPassable); this.suicideBomberFSM.changeState(state); this.safeBomberFSM = new FSM<BomberAgent>(this, null, null); state = new PursueState(this.gs, this.isBombPassable); this.safeBomberFSM.changeState(state); this.blockEscapeFSM = new FSM<BomberAgent>(this, null, null); state = new PursueState(this.gs, this.isBombPassable); this.blockEscapeFSM.changeState(state); this.surroundFSM = new FSM<BomberAgent>(this, null, null); //state = new PredictDestinationState(this.gs, this.isBombPassable); state = new SurroundState(this.gs, this.isBombPassable); this.surroundFSM.changeState(state); }
// Use this for initialization void Start() { states = new List <State>(); //Patroll state List <Transition> patrolltrans = new List <Transition>(); patrolltrans.Add(new SeeMonsterTrans(gameObject)); patrolltrans.Add(new GetSignalTrans(gameObject)); //patrolltrans.Add(new HearNoiseTrans(gameObject)); PatrollState patroll = new PatrollState(gameObject, patrolltrans); states.Add(patroll); //Search noise state (not active) //List<Transition> searchnoisetrans = new List<Transition>(); //searchnoisetrans.Add(new SeeMonsterTrans(gameObject)); //searchnoisetrans.Add(new GetSignalTrans(gameObject)); //searchnoisetrans.Add(new StopAndTimePassTrans(gameObject,3f,"patroll")); //SearchNoiseState search = new SearchNoiseState(gameObject, searchnoisetrans,9f); //states.Add(search); //Search Disgust (go to signal state) List <Transition> searchdisgusttrans = new List <Transition>(); searchdisgusttrans.Add(new SeeMonsterTrans(gameObject)); searchdisgusttrans.Add(new StopAndTimePassTrans(gameObject, 1f, "searchlocation")); GoToSignalState gotosignal = new GoToSignalState(gameObject, searchdisgusttrans, 10f); states.Add(gotosignal); //Search location state List <Transition> searchlocationtrans = new List <Transition>(); searchlocationtrans.Add(new SeeMonsterTrans(gameObject)); searchlocationtrans.Add(new GetSignalTrans(gameObject)); searchlocationtrans.Add(new StopAndTimePassTrans(gameObject, 2f, "patroll")); //No hay nadie en el punto SearchLocationState searchLocation = new SearchLocationState(gameObject, searchlocationtrans, 10f); states.Add(searchLocation); //Pursue state List <Transition> pursuetrans = new List <Transition>(); pursuetrans.Add(new StopSeeMonsterTrans(gameObject)); pursuetrans.Add(new ReachTrans(gameObject)); PursueState pursue = new PursueState(gameObject, pursuetrans, 11f); states.Add(pursue); //Look for state List <Transition> looktrans = new List <Transition>(); looktrans.Add(new SeeMonsterTrans(gameObject)); looktrans.Add(new TimePassTrans(gameObject, 7f, "pursuerwaypoint")); LookForState look = new LookForState(gameObject, looktrans, 11f); states.Add(look); //Push Fear state List <Transition> pushtrans = new List <Transition>(); pushtrans.Add(new StopSeeMonsterTrans(gameObject)); //pushtrans.Add(new TimePassTrans(gameObject,3f,"patroll")); PushState push = new PushState(gameObject, pushtrans); states.Add(push); //Nearest pursuer waypoint state List <Transition> waypointtrans = new List <Transition>(); waypointtrans.Add(new SeeMonsterTrans(gameObject)); waypointtrans.Add(new StopAndTimePassTrans(gameObject, 2f, "patroll")); PursuerWaypointState pursuerwaypoint = new PursuerWaypointState(gameObject, waypointtrans, 11f); states.Add(pursuerwaypoint); initialState = patroll; currentState = patroll; //TEST //currentState = push; // triggeredTransition = null; gameObject.GetComponent <GraphPathFollowing>().astar_target = null; //Set to null just in case initialSpeed = gameObject.GetComponent <Agent>().maxSpeed; }
private Action blockEscapeMove(FSM<BomberAgent> fsm) { State<BomberAgent> current = fsm.getCurrentState(); Action move = null; State<BomberAgent> nextState = null; if (current is PursueState) { if (current.fail(this)) { nextState = new BlastWallState(this.gs, false); } else { //check for four adjacent locations open near player Coords playerCoords = this.gs.GetAgentCoords(0); List<Coords> adj = this.gs.GetAdjacentAccessibleTiles(playerCoords.getTileNum(), this.isBombPassable, false); if (adj.Count == 4) { nextState = new SurroundState(this.gs, this.isBombPassable); } else { Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this); if (choke != null) { nextState = new CutOffChokePointState(this.gs, this.isBombPassable, choke); } } } } else if (current is BlastWallState) { if (current.fail(this) || current.complete(this)) { nextState = new EvadeExplosionState(this.gs); } } else if (current is CutOffChokePointState) { //Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this); //if ((choke == null) || current.fail(this)) { if (current.fail(this)) { nextState = new PursueState(this.gs, this.isBombPassable); } else if (current.complete(this)) { nextState = new BombState(this.gs); } } else if (current is BombState) { if (current.fail(this) || current.complete(this)) { nextState = new EvadeExplosionState(this.gs); } } else if (current is EvadeExplosionState) { if (current.fail(this) || current.complete(this)) { Coords choke = this.chokepoints.findChokePoint(this.isBombPassable, this); if (choke == null) { nextState = new PursueState(this.gs, this.isBombPassable); } else { nextState = new CutOffChokePointState(this.gs, this.isBombPassable, choke); } } } else if (current is SurroundState) { if (current.fail(this)) { nextState = new PursueState(this.gs, this.isBombPassable); //move to default state } else if (current.complete(this)) { nextState = new BombState(this.gs); } } if (nextState != null) { Console.WriteLine("Agent " + this.agentId + " switching to " + nextState.GetType().ToString()); fsm.changeState(nextState); } move = fsm.getCurrentState().getAction(this); Console.WriteLine("Agent " + this.agentId + ", state " + fsm.getCurrentState().GetType().ToString() + ", move " + move); return move; }