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

  1. -- pool 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 character = getStateObjectFromID(msg.sender);
  12.         local button;
  13.         local stateMachineName = character.walkSO.getStateMachine().getName();
  14.         --print("buildMenu stateMachineName: " .. stateMachineName);
  15.         button = addPieMenuButton("pm_enterPool", "enterPool");
  16.         button.addDescription(ACTIVITY, "swim");
  17.     end )
  18.     
  19.     -- swim
  20.     onMsg("enterPool", function(msg)
  21.     
  22.         local character = getStateObjectFromID(msg.sender);
  23.         
  24.         -- check if activity if possible
  25.         local possible, result, activity = activityPossible(character, "swim", this);
  26.         
  27.         -- don't care if timeslot is not fulfilled
  28.                          if (possible or enumCompare(result, TIMESLOT)) then
  29.             local entryPoints = this.getEntryPoints(character);
  30.             for p = 1, getn(entryPoints) do
  31.                 print(" entryPoint " .. p);
  32.                 local actionPoint = entryPoints[p];
  33.                                                     
  34.                 -- get the walk state object
  35.                 local wso = character.walkSO;
  36.                 if (wso.walkToActionPoint(actionPoint)) then
  37.                     wso.queueStateMachine("poolChar.sitDown", this);
  38.                     return
  39.                 end
  40.             
  41.             end
  42.             print("no path found");
  43.             instantAbort(character, EMOTICON_NOPATH, "emoThink")
  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.             
  60. endStateMachine()
  61.