/* ---------------------------------------------------------------------------- * Creates the finite state machine for the decoration's logic. */ void decoration_fsm::create_fsm(mob_type* typ) { easy_fsm_creator efc; efc.new_state("idling", DECORATION_STATE_IDLING); { efc.new_event(MOB_EVENT_ON_ENTER); { efc.run(decoration_fsm::become_idle); } efc.new_event(MOB_EVENT_TOUCHED_OBJECT); { efc.run(decoration_fsm::check_bump); } } efc.new_state("bumped", DECORATION_STATE_BUMPED); { efc.new_event(MOB_EVENT_ON_ENTER); { efc.run(decoration_fsm::be_bumped); } efc.new_event(MOB_EVENT_ANIMATION_END); { efc.change_state("idling"); } } typ->states = efc.finish(); typ->first_state_nr = fix_states(typ->states, "idling"); //Check if the number in the enum and the total match up. engine_assert( typ->states.size() == N_DECORATION_STATES, i2s(typ->states.size()) + " registered, " + i2s(N_DECORATION_STATES) + " in enum." ); }
void gate_fsm::create_fsm(mob_type* typ) { easy_fsm_creator efc; efc.new_state("idle", GATE_STATE_IDLE); { efc.new_event(MOB_EVENT_ON_ENTER); { efc.run_function(gate_fsm::set_anim); } efc.new_event(MOB_EVENT_HITBOX_TOUCH_N_A); { efc.run_function(gate_fsm::take_damage); } efc.new_event(MOB_EVENT_DEATH); { efc.run_function(gate_fsm::open); efc.change_state("dead"); } } efc.new_state("dead", GATE_STATE_DEAD); { } typ->states = efc.finish(); typ->first_state_nr = fix_states(typ->states, "idle"); if(typ->states.size() != N_GATE_STATES) { error_log( "ENGINE WARNING: Number of gate states on the FSM (" + i2s(typ->states.size()) + ") and the enum (" + i2s(N_GATE_STATES) + ") do not match." ); } }
/* ---------------------------------------------------------------------------- * Creates the finite state machine for the Onion's logic. */ void onion_fsm::create_fsm(mob_type* typ) { easy_fsm_creator efc; efc.new_state("idling", ONION_STATE_IDLING); { efc.new_event(MOB_EVENT_RECEIVE_DELIVERY); { efc.run(onion_fsm::receive_mob); } } typ->states = efc.finish(); typ->first_state_nr = fix_states(typ->states, "idling"); //Check if the number in the enum and the total match up. engine_assert( typ->states.size() == N_ONION_STATES, i2s(typ->states.size()) + " registered, " + i2s(N_ONION_STATES) + " in enum." ); }
/* ---------------------------------------------------------------------------- * Creates the finite state machine for the Onion's logic. */ void onion_fsm::create_fsm(mob_type* typ) { easy_fsm_creator efc; efc.new_state("idling", ONION_STATE_IDLING); { efc.new_event(MOB_EVENT_RECEIVE_DELIVERY); { efc.run_function(onion_fsm::receive_mob); } } typ->states = efc.finish(); typ->first_state_nr = fix_states(typ->states, "idling"); if(typ->states.size() != N_ONION_STATES) { log_error( "ENGINE WARNING: Number of Onion states on the FSM (" + i2s(typ->states.size()) + ") and the enum (" + i2s(N_ONION_STATES) + ") do not match." ); } }
void treasure_fsm::create_fsm(mob_type* typ) { easy_fsm_creator efc; efc.new_state("idle_waiting", TREASURE_STATE_IDLE_WAITING); { efc.new_event(MOB_EVENT_ON_ENTER); { efc.run_function(gen_mob_fsm::carry_stop_move); } efc.new_event(MOB_EVENT_CARRY_KEEP_GOING); { efc.run_function(gen_mob_fsm::check_carry_begin); } efc.new_event(MOB_EVENT_CARRIER_ADDED); { efc.run_function(gen_mob_fsm::handle_carrier_added); efc.run_function(gen_mob_fsm::check_carry_begin); } efc.new_event(MOB_EVENT_CARRIER_REMOVED); { efc.run_function(gen_mob_fsm::handle_carrier_removed); } efc.new_event(MOB_EVENT_CARRY_BEGIN_MOVE); { efc.change_state("idle_moving"); } } efc.new_state("idle_moving", TREASURE_STATE_IDLE_MOVING); { efc.new_event(MOB_EVENT_ON_ENTER); { efc.run_function(gen_mob_fsm::carry_begin_move); efc.run_function(gen_mob_fsm::set_next_target); } efc.new_event(MOB_EVENT_CARRIER_REMOVED); { efc.run_function(gen_mob_fsm::handle_carrier_removed); efc.run_function(gen_mob_fsm::check_carry_stop); } efc.new_event(MOB_EVENT_CARRY_WAIT_UP); { efc.change_state("idle_waiting"); } efc.new_event(MOB_EVENT_CARRY_STOP_MOVE); { efc.change_state("idle_waiting"); } efc.new_event(MOB_EVENT_CARRY_BEGIN_MOVE); { efc.run_function(gen_mob_fsm::carry_begin_move); efc.run_function(gen_mob_fsm::set_next_target); } efc.new_event(MOB_EVENT_REACHED_DESTINATION); { efc.run_function(gen_mob_fsm::set_next_target); } efc.new_event(MOB_EVENT_CARRY_DELIVERED); { efc.change_state("being_delivered"); } } efc.new_state("being_delivered", TREASURE_STATE_BEING_DELIVERED); { efc.new_event(MOB_EVENT_ON_ENTER); { efc.run_function(gen_mob_fsm::start_being_delivered); } efc.new_event(MOB_EVENT_TIMER); { efc.run_function(treasure_fsm::handle_delivery); } } typ->states = efc.finish(); typ->first_state_nr = fix_states(typ->states, "idle_waiting"); if(typ->states.size() != N_TREASURE_STATES) { error_log( "ENGINE WARNING: Number of treasure states on the FSM (" + i2s(typ->states.size()) + ") and the enum (" + i2s(N_TREASURE_STATES) + ") do not match." ); } }