[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2.2.2 behave.cpp

Here is the source for our behaviour layer. The CreateBehaviour() function in BehaviourLayer will compare the given name parameter with the possible names for behaviours and then create the appropriate subclass of BehaviourCommon.

Given the new behaviour for the example Quest an extra else if case has been added.

 
iCelBehaviour* BehaviourLayer::CreateBehaviour (iCelEntity* entity,
	const char* name)
{
  iCelBehaviour* behave = 0;
  if (!strcmp (name, "level_behave"))
    behave = new BehaviourLevel (entity, this, pl);
  else if (!strcmp (name, "player_behave"))
    behave = new BehaviourPlayer (entity, this, pl);
  else if (!strcmp (name, "box_behave"))
    behave = new BehaviourBox (entity, this, pl);
  else if (!strcmp (name, "badone_behave"))
    behave = new BehaviourBadOne (entity, this, pl);
  else if (!strcmp (name, "quest_behave"))   
    behave = new BehaviourQuest (entity, this, pl);


  if (behave)
  {
    entity->SetBehaviour (behave);
    // There is now a reference in the entity. We destroy
    // our own reference here.
    behave->DecRef ();
  }
  return behave;
}

The Quest behaviour SendMessage must be defined. However, again like the level behaviour, the Quest behaviour does not do anything in this tutorial.

 
bool BehaviourQuest::SendMessage (csStringID msg_id, 
  iCelPropertyClass* pc, 
  celData& ret, iCelParameterBlock* params, va_list arg) 
{ 
  return BehaviourCommon::SendMessage (msg_id, pc, ret, params, arg); 


This document was generated using texi2html 1.76.