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

  1. -- trashcan state machine
  2.  
  3. beginStateMachine()
  4.  
  5.  
  6.     onEnter(function(msg)
  7.         local fillLevel = retrieveData("fillLevel", 0.0);
  8.         storeData("fillLevel", fillLevel);
  9.         local stink = findChildGO("stink");
  10.         stink.setEmitRate(0.0);
  11.     end )
  12.  
  13.  
  14.     onMsg("buildMenu", function(msg)
  15.     
  16.         if (repairMenu()) then return end
  17.     
  18.         -- build the pie menu
  19.         clearPieMenu();
  20.         
  21.         local button = addPieMenuButton("pm_bringOutTrash", "takeTrash");
  22.         button.addDescription(ACTIVITY, "takeTrash");
  23.         button.addDescription(ACTIVITY, "improveTrashTidiness");
  24.         button.addIcon("guiIconWohnung");
  25.  
  26.     end )
  27.  
  28.     -- 
  29.     onMsg("takeTrash", function(msg)
  30.         -- get the game object server
  31.         local gameObjectServer = getGameObjectServer();
  32.         -- get character who initiated this action
  33.         local character = getStateObjectFromID(msg.sender);
  34.         
  35.         -- check if activity if possible
  36.         local possible, result, activity = activityPossible(character, msg.name, this);
  37.         
  38.         -- don't care if timeslot is not fulfilled
  39.         if (possible or enumCompare(result, TIMESLOT)) then
  40.             -- walk to the closest action point
  41.             local actionPoint = character.getClosestFreeActionPoint(character, this, {"take1", "take2", "take3", "take4",
  42.             "take5", "take6", "take7", "take8"});
  43.     
  44.             if (actionPoint) then
  45.                 -- get the walk state object
  46.                 local wso = character.walkSO;
  47.                 local wsoContext = StateMachineContext();
  48.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  49.                 if (wso.walkToActionPoint(actionPoint)) then
  50.                     wso.queueStateMachine("trashcanChar.takeTrash", this, wsoContext);
  51.                 else
  52.                     print("no path found");
  53.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  54.                 end
  55.             else
  56.                 print("no action point found");
  57.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  58.             end
  59.         else
  60.             -- activity not possible
  61.             print(msg.name .. " not possible");
  62.             
  63.             local emoticon;
  64.             if (enumCompare(result, NO_CONDITION)) then
  65.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  66.             else
  67.                 emoticon = EMOTICON_CANNOT;
  68.             end
  69.             instantAbort(character, emoticon, "emoThink");
  70.         end
  71.     end )
  72.             
  73.             
  74. endStateMachine()
  75.