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

  1. -- armchair 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.         -- if this is broken: abort characters action
  23.         if abortIfBroken(character) then return end;        
  24.         
  25.         -- check if activity if possible
  26.         local possible, result, activity = activityPossible(character, msg.name, this);
  27.                                   
  28.         -- don't care if timeslot is not fulfilled
  29.         if (possible or enumCompare(result, TIMESLOT)) then
  30.             -- walk to the closest action point
  31.             local actionPoint = character.getFreeActionPoint(this, "sit");
  32.             -- get the walk state object
  33.             local wso = character.walkSO;
  34.             if (actionPoint) then
  35.                 -- create state machine contexts
  36.                 local wsoContext = StateMachineContext();
  37.                 -- store the action point
  38.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  39.                 if (wso.walkToActionPoint(actionPoint)) then
  40.                     --wso.queueStateMachine("armchairChar.sitDown", this, wsoContext);
  41.                     wso.queueStateMachine("sofaChar.sitDown", this, wsoContext);
  42.                 else
  43.                     print("no path found");
  44.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  45.                 end
  46.             else
  47.                 print("no action point found");
  48.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  49.             end
  50.         else
  51.             -- activity not possible
  52.             print(msg.name .. " not possible");
  53.             
  54.             local emoticon;
  55.             if (enumCompare(result, NO_CONDITION)) then
  56.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  57.             else
  58.                 emoticon = EMOTICON_CANNOT;
  59.             end
  60.             instantAbort(character, emoticon, "emoThink");
  61.         end
  62.     end )
  63.     
  64.     
  65.     -- repair
  66.     onMsg("repair", function(msg)
  67.     
  68.         print("onMsg repair");
  69.         -- get character who initiated this action
  70.         local character = getStateObjectFromID(msg.sender);
  71.         -- walk to the closest action point
  72.         local actionPoint = character.getFreeActionPoint(this, "repair");
  73.         -- get the walk state object
  74.         local wso = character.walkSO;
  75.         if (actionPoint) then
  76.             -- create state machine contexts
  77.             local wsoContext = StateMachineContext();
  78.             -- store the action point
  79.             wsoContext.storeData("actionPointName", actionPoint.getName());
  80.             if (wso.walkToActionPoint(actionPoint)) then
  81.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  82.             else
  83.                 print("no path found");
  84.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  85.             end
  86.         else
  87.             print("no action point found");
  88.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  89.         end
  90.     end )
  91.     
  92.  
  93.  
  94.             
  95. endStateMachine()
  96.