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

  1. -- chair state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button ;
  11.         button = addPieMenuButton("pm_sitdown", "sit");
  12.         button.addDescription(ACTIVITY, "sit");
  13.         -- button.addIcon("guiIconComfort");
  14.     end )
  15.     
  16.     -- sit on armchair
  17.     onMsg("sit", 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 = nil;
  30.             local table = getTableForChair(this);
  31.             if (table) then
  32.                 actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit1", "sit2"});
  33.             else
  34.                 actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit3"});
  35.             end
  36.             -- get the walk state object
  37.             local wso = character.walkSO;
  38.             if (actionPoint) then
  39.                 -- create state machine contexts
  40.                 local wsoContext = StateMachineContext();
  41.                 -- store the action point
  42.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  43.                 if (wso.walkToActionPoint(actionPoint)) then
  44.                     wso.queueStateMachine("chairChar.sitDown", this, wsoContext);
  45.                 else
  46.                     print("no path found");
  47.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  48.                 end
  49.             else
  50.                 print("no action point found");
  51.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  52.             end
  53.         else
  54.             -- activity not possible
  55.             print(msg.name .. " not possible");
  56.             
  57.             local emoticon;
  58.             if (enumCompare(result, NO_CONDITION)) then
  59.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  60.             else
  61.                 emoticon = EMOTICON_CANNOT;
  62.             end
  63.             instantAbort(character, emoticon, "emoThink");
  64.         end
  65.     end )
  66.             
  67. endStateMachine()
  68.