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

  1. -- camera 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_takePictures", "takePicture");
  13.         button.addDescription(ACTIVITY, "takePicture");
  14.         -- button.addIcon("guiIconHygiene");
  15.     end )
  16.  
  17.     -- 
  18.     onMsg("takePicture", function(msg)
  19.         -- get the game object server
  20.         local gameObjectServer = getGameObjectServer();
  21.         -- get character who initiated this action
  22.         local character = getStateObjectFromID(msg.sender);
  23.         
  24.         -- check if activity if possible
  25.         local possible, result, activity = activityPossible(character, msg.name, this);
  26.         
  27.         -- don't care if timeslot is not fulfilled
  28.         if (possible or enumCompare(result, TIMESLOT)) then
  29.             -- walk to the closest action point
  30.             local actionPoint = character.getFreeActionPoint(this, "use");
  31.             if (actionPoint) then
  32.                 -- get the walk state object
  33.                 local wso = character.walkSO;
  34.                 if (wso.walkToActionPoint(actionPoint)) then
  35.                     wso.queueStateMachine("cameraChar.waitForPartner", this);
  36.                 else
  37.                     print("no path found");
  38.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  39.                 end
  40.             else
  41.                 print("no action point found");
  42.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  43.             end
  44.         else
  45.             -- activity not possible
  46.             print(msg.name .. " not possible");
  47.             
  48.             local emoticon;
  49.             if (enumCompare(result, NO_CONDITION)) then
  50.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  51.             else
  52.                 emoticon = EMOTICON_CANNOT;
  53.             end
  54.             instantAbort(character, emoticon, "emoThink");
  55.         end
  56.     end )
  57.             
  58.             
  59. endStateMachine()
  60.