FSM_LUA = true
-------------------------------------------------------------------
-- fsm.lua:
-- defines FSM object and other helper objects.
-------------------------------------------------------------------

-- semi dependencies
DEBUG_MODE = DEBUG_MODE or true

-- constants
STATE_NONE = "STATE_NONE"

-------------------------------------------------------------------
-- FSM table: defines behavior of finite state machine objects
-------------------------------------------------------------------

FSM = {}

-- FSM.__index:
--  since FSM will be an "instatiable" table, it will also
--  be the metatable for new fsm objects. Therefore we must
--  set the metatable entry FSM.__index to refer back to 
--  the FSM table.
FSM.__index = FSM 

-- default values
FSM.state      = STATE_NONE
FSM.state_time = 0
FSM.to_str     = "FSM"

-- FSM.new:
--  creates a new fsm object and returns it.
function FSM:instantiate ( new_o )
    new_o = new_o or {}
    setmetatable(new_o, self)
    self.__index = self
    return new_o
end

-- FSM:set_state( newstate ):
--  sets the state, resets state time, and calls the
--  FSM:do_change_state() function.
--  inputs:
--     newstate - the new state
--  outputs:
--     none
function FSM:set_state ( new_state ) 
    self:do_change_state(self.state, new_state)
    self.state      = new_state
    self.state_time = 0
end

-- "virtual" functions, expect overload

function FSM:do_change_state ( prev_state, new_state ) end

function FSM:do_idle ( dt ) end

