[MUD-Dev] Material state transformations

Daniel.Harman at barclayscapital.com Daniel.Harman at barclayscapital.com
Wed Jul 2 17:50:46 CEST 2003


On 1 July 2003, Yuri Bazhukov wrote:

> I am very interested, in material transformations from solid to
> liquid, from liquid to gaseous form.  Is anybody have ideas how to
> solve these problems, or already implemented this in their own
> MUDs?

I would give all materials a temperature variable, and a finite
state machine(FSM) with the following states {solid, liquid,
gas}. The FSM isn't strictly necessary, but presuming you are using
them already in your engine have nicely abstracted support for any
state changes you need to apply to your object as it transitions.

This is slightly different to Richard's approach in that he appears
to have different objects {ice, water, steam}. My proposal is to
model it as {water} with a temperature affecting its state.

E.g. in C++

  Class CMaterial {
    unsigned long    m_lTemperature;    // using kelvin so can be unsigned.
    unsigned long    m_lFreezingPoint;
    unsigned long    m_lBoilingPoint;

  public:
    enum eTempState {
      SOLID,
      LIQUID,
      GAS
    }

    // Construction/Destruction.
    CMaterial (unsigned long freezingPoint, unsigned long boilingPoint)
      : m_lFreezingPoint (freezingPoint), m_lBoilingPoint (boilingPoint) {}

    virtual ~CMaterial () {}

    CFSM<CMaterialState> m_State;   // Not giving an implementation
                                    // for the FSM, but it just
                                    // records whether object is
                                    // {solid,liquid,gas} and
                                    // handles changes when the
                                    //  transition occurs.

    void SetTemperature (unsigned long t) {
      eTempState newState;

      // Work out whether this new temperature (t) is
      // solid,liquid,gas

      if (t >= lBoilingPoint) newState = GAS;
      else if (t >= lFreezingPoint) newState = LIQUID;
      else newState = SOLID

      if (newState != m_State.GetState())
        m_State.SetState( newState ); // This leaves the state
                                      // machine to handle all the changes
                                      // when you transition.
      m_lTemperature = t;
    }
  }

  Class CWater : public CMaterial {

    CWater() : CMaterial( waters freezingpoint in kelvin, the
    boiling point ) {}  // Teach me to be a smartarse and use kelvin
                        // as I don't know the transition point in
                        // that scale :)
  }

Of course this is all pretty simple, the artistry is in having a
decent flexible FSM, and I'm not sure if you have one? If not, you
can pinch the implementation from 'Massively Multi-player Game
Programming', Thor Alexander:

 http://www.amazon.co.uk/exec/obidos/ASIN/1584502436/202-4712135-1906243.

It's a decent book, although some parts are better than others.

Dan
_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the mud-dev-archive mailing list