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

  1. -- boxing bag 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_box", "box");
  12.         button.addDescription(ACTIVITY, "box");
  13.         -- button.addIcon("guiIconSpass");
  14.  
  15.     end )
  16.  
  17.     -- 
  18.     onMsg("box", function(msg)
  19.         -- get character who initiated this action
  20.         local character = getStateObjectFromID(msg.sender);
  21.         
  22.         -- check if activity if possible
  23.         local possible, result, activity = activityPossible(character, msg.name, this);
  24.         
  25.         -- don't care if timeslot is not fulfilled
  26.         if (possible or enumCompare(result, TIMESLOT)) then
  27.             -- walk to the closest action point
  28.             local actionPoint = character.getClosestFreeActionPoint(character, this, {"box1", "box2", "box3"});
  29.             -- get the walk state object
  30.             local wso = character.walkSO;
  31.             if (actionPoint) then
  32.                 if (wso.walkToActionPoint(actionPoint)) then
  33.                     -- create state machine contexts
  34.                     local wsoContext = StateMachineContext();
  35.                     -- store the action point
  36.                     wsoContext.storeData("actionPointName", actionPoint.getName());
  37.                     
  38.                     wso.queueStateMachine("boxingbagChar.box", 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. endStateMachine()
  62.