home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / easel.lua < prev    next >
Text File  |  2004-03-05  |  2KB  |  63 lines

  1. -- easel state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button;
  12.         button = addPieMenuButton("pm_paint", "paint");
  13.         button.addDescription(ACTIVITY, "paint");
  14.     end )
  15.  
  16.     -- 
  17.     onMsg("paint", function(msg)
  18.         -- get the game object server
  19.         local gameObjectServer = getGameObjectServer();
  20.         -- get character who initiated this action
  21.         local character = getStateObjectFromID(msg.sender);
  22.         
  23.         -- check if activity if possible
  24.         local possible, result, activity = activityPossible(character, msg.name, this);
  25.         
  26.         -- don't care if timeslot is not fulfilled
  27.         if (possible or enumCompare(result, TIMESLOT)) then
  28.             -- walk to the closest action point
  29.             local actionPoint = character.getFreeActionPoint(this, "paint");
  30.     
  31.             if (actionPoint) then
  32.                 -- get the walk state object
  33.                 local wso = character.walkSO;
  34.                 local wsoContext = StateMachineContext();
  35.                 -- store the action point
  36.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  37.                 if (wso.walkToActionPoint(actionPoint)) then
  38.                     wso.queueStateMachine("easelChar.paint", this, wsoContext);
  39.                 else
  40.                     print("no path found");
  41.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  42.                 end
  43.             else
  44.                 print("no action point found");
  45.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  46.             end
  47.         else
  48.             -- activity not possible
  49.             print(msg.name .. " not possible");
  50.             
  51.             local emoticon;
  52.             if (enumCompare(result, NO_CONDITION)) then
  53.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  54.             else
  55.                 emoticon = EMOTICON_CANNOT;
  56.             end
  57.             instantAbort(character, emoticon, "emoThink");
  58.         end
  59.     end )
  60.             
  61.             
  62. endStateMachine()
  63.