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

  1. -- oven state machine
  2.  
  3. beginStateMachine()
  4.  
  5.  
  6.     onEnter(function(msg)
  7.         local damp = findChildGO("damp");
  8.         damp.setEmitRate(0.0);
  9.     end )
  10.  
  11.  
  12.     onMsg("buildMenu", function(msg)
  13.     
  14.         if (repairMenu()) then return end
  15.     
  16.         -- build the pie menu
  17.         clearPieMenu();
  18.         
  19.         if (getChildEnable("pot")) then
  20.             button = addPieMenuButton("pm_takeFood", "takeFood");
  21.             button.addDescription(ACTIVITY, "eat");
  22.         else
  23.             button = addPieMenuButton("pm_cook", "cook");
  24.             button.addDescription(ACTIVITY, "cook");
  25.             button.addDescription(ACTIVITY, "eat");
  26.         end
  27.         
  28.     end )
  29.  
  30.     -- 
  31.     onMsg("cook", function(msg)
  32.         -- get the game object server
  33.         local gameObjectServer = getGameObjectServer();
  34.         -- get character who initiated this action
  35.         local character = getStateObjectFromID(msg.sender);
  36.         
  37.         -- check if activity if possible
  38.         local possible, result, activity = activityPossible(character, msg.name, this);
  39.         
  40.         -- don't care if timeslot is not fulfilled
  41.         if (possible or enumCompare(result, TIMESLOT)) then
  42.             -- if this is broken: abort characters action
  43.             if abortIfBroken(character) then return end;        
  44.             -- walk to the closest action point
  45.             local actionPoint = character.getFreeActionPoint(this, "cook");
  46.             if (actionPoint) then    
  47.                 -- get the walk state object
  48.                 local wso = character.walkSO;
  49.                 -- create state machine contexts
  50.                 local wsoContext = StateMachineContext();
  51.                 -- store the action point
  52.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  53.                 if (wso.walkToActionPoint(actionPoint)) then
  54.                     -- notify current mission 
  55.                     character.sendMsg("cook", gameObjectServer.mission);
  56.                     -- enque action
  57.                     wso.queueStateMachine("ovenChar.open", this, wsoContext);
  58.                 else
  59.                     print("no path found");
  60.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  61.                 end
  62.             else
  63.                 print("no action point found");
  64.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  65.             end
  66.         else
  67.             -- activity not possible
  68.             print(msg.name .. " not possible");
  69.             
  70.             local emoticon;
  71.             if (enumCompare(result, NO_CONDITION)) then
  72.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  73.             else
  74.                 emoticon = EMOTICON_CANNOT;
  75.             end
  76.             instantAbort(character, emoticon, "emoThink");
  77.         end
  78.     end )
  79.     
  80.     
  81.     
  82.     -- takeFood
  83.     onMsg("takeFood", function(msg)
  84.     
  85.         print("onMsg takeFood");
  86.         
  87.         -- get the game object server
  88.         local gameObjectServer = getGameObjectServer();
  89.         -- get character who initiated this action
  90.         local character = getStateObjectFromID(msg.sender);
  91.         
  92.         -- check if activity if possible
  93.         local possible, result, activity = activityPossible(character, "eat", this);
  94.  
  95.         -- don't care if timeslot is not fulfilled
  96.         if (possible or enumCompare(result, TIMESLOT)) then
  97.             -- if this is broken: abort characters action
  98.             if abortIfBroken(character) then return end;        
  99.             -- walk to the closest action point
  100.             local actionPoint = character.getFreeActionPoint(this, "cook");
  101.             if (actionPoint) then
  102.                 -- get the walk state object
  103.                 local wso = character.walkSO;
  104.                 -- create state machine contexts
  105.                 local wsoContext = StateMachineContext();
  106.                 -- store the action point
  107.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  108.                 if (wso.walkToActionPoint(actionPoint)) then
  109.                     wso.queueStateMachine("ovenChar.takeFood", this, wsoContext);
  110.                 else
  111.                     print("no path found");
  112.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  113.                 end
  114.             else
  115.                 print("no action point found");
  116.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  117.             end
  118.         else
  119.             -- activity not possible
  120.             print(msg.name .. " not possible");
  121.             
  122.             local emoticon;
  123.             if (enumCompare(result, NO_CONDITION)) then
  124.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  125.             else
  126.                 emoticon = EMOTICON_CANNOT;
  127.             end
  128.             instantAbort(character, emoticon, "emoThink");
  129.         end
  130.  
  131.     end )
  132.     
  133.     
  134.     
  135.     -- repair
  136.     onMsg("hidePot", function(msg)
  137.     
  138.         print("onMsg hidePot");
  139.         this.setChildEnable("pot", false);
  140.  
  141.     end )
  142.     
  143.     -- repair
  144.     onMsg("repair", function(msg)
  145.     
  146.         print("onMsg repair");
  147.         -- get character who initiated this action
  148.         local character = getStateObjectFromID(msg.sender);
  149.         -- walk to the closest action point
  150.         local actionPoint = character.getFreeActionPoint(this, "repair");
  151.         -- get the walk state object
  152.         local wso = character.walkSO;
  153.         if (actionPoint) then
  154.             -- create state machine contexts
  155.             local wsoContext = StateMachineContext();
  156.             -- store the action point
  157.             wsoContext.storeData("actionPointName", actionPoint.getName());
  158.             if (wso.walkToActionPoint(actionPoint)) then
  159.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  160.             else
  161.                 print("no path found");
  162.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  163.             end
  164.         else
  165.             print("no action point found");
  166.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  167.         end
  168.     end )
  169.     
  170.                 
  171.     
  172.             
  173. endStateMachine()
  174.