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

  1. -- fridge oldschool 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 button;
  12.         button = addPieMenuButton("pm_eatSnack", "eatSnack");
  13.         button.addDescription(ACTIVITY, "eatSnack");
  14. --        button = addPieMenuButton("pm_eatVegSnack", "eatVegSnack");
  15. --        button.addDescription(ACTIVITY, "eatVegSnack");
  16.         -- button.addIcon("guiIconHunger");
  17.         button = addPieMenuButton("pm_eatBreakfast", "eatBreakfast");
  18.         button.addDescription(ACTIVITY, "eatBreakfast");
  19.         button.addDescription(HIDE_IF_UNSELECTABLE, "true")
  20. --        button = addPieMenuButton("pm_eatSupper", "eatBreakfast");
  21. --        button.addDescription(ACTIVITY, "eatSupper");
  22.         button = addPieMenuButton("pm_eatDinner", "eatDinner");
  23.         button.addDescription(ACTIVITY, "eatDinner");
  24.         button.addDescription(HIDE_IF_UNSELECTABLE, "true")
  25.         -- button.addIcon("guiIconHunger");
  26.     end )
  27.  
  28.     -- open the fridge and eat a snack
  29.     onMsg("eatSnack", 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.         -- if this is broken: abort characters action
  35.         if abortIfBroken(character) then return end;
  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.             -- walk to the closest action point
  43.             local actionPoint = character.getFreeActionPoint(this, "open");
  44.             -- get the walk state object
  45.             local wso = character.walkSO;
  46.             if (actionPoint) then
  47.                 -- create state machine contexts
  48.                 local wsoContext = StateMachineContext();
  49.                 -- store the action point
  50.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  51.                 wsoContext.storeData("snackCommand", "eatSnack");
  52.                 if (wso.walkToActionPoint(actionPoint)) then
  53.                     wso.queueStateMachine("fridgeSnackChar.open", this, wsoContext);
  54.                 else
  55.                     print("no path found");
  56.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  57.                 end
  58.             else
  59.                 print("no action point found");
  60.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  61.             end
  62.         else
  63.             -- activity not possible
  64.             print(msg.name .. " not possible");
  65.             
  66.             local emoticon;
  67.             if (enumCompare(result, NO_CONDITION)) then
  68.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  69.             else
  70.                 emoticon = EMOTICON_CANNOT;
  71.             end
  72.             instantAbort(character, emoticon, "emoThink");
  73.         end
  74.     end )
  75.     
  76.     
  77.     -- open the fridge and eat a snack
  78.     onMsg("eatVegSnack", function(msg)
  79.         -- get the game object server
  80.         local gameObjectServer = getGameObjectServer();
  81.         -- get character who initiated this action
  82.         local character = getStateObjectFromID(msg.sender);
  83.         -- check if activity if possible
  84.         local possible, result, activity = activityPossible(character, msg.name, this);
  85.         
  86.         -- don't care if timeslot is not fulfilled
  87.         if (possible or enumCompare(result, TIMESLOT)) then
  88.             -- if this is broken: abort characters action
  89.             if abortIfBroken(character) then return end;        
  90.             -- walk to the closest action point
  91.             local actionPoint = character.getFreeActionPoint(this, "open");
  92.             if (actionPoint) then
  93.                 -- get the walk state object
  94.                 local wso = character.walkSO;
  95.                 -- create state machine contexts
  96.                 local wsoContext = StateMachineContext();
  97.                 -- store the action point
  98.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  99.                 wsoContext.storeData("snackCommand", "eatVegSnack");
  100.                 --wsoContext.storeData("snackCommand", "eatSnack");
  101.                 if (wso.walkToActionPoint(actionPoint)) then
  102.                     wso.queueStateMachine("fridgeSnackChar.open", this, wsoContext);
  103.                 else
  104.                     print("no path found");
  105.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  106.                 end
  107.             else
  108.                 print("no action point found");
  109.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  110.             end
  111.         else
  112.             -- activity not possible
  113.             print(msg.name .. " not possible");
  114.             
  115.             local emoticon;
  116.             if (enumCompare(result, NO_CONDITION)) then
  117.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  118.             else
  119.                 emoticon = EMOTICON_CANNOT;
  120.             end
  121.             instantAbort(character, emoticon, "emoThink");
  122.         end
  123.     end )
  124.     
  125.     
  126.     -- open the fridge and take breakfast
  127.     onMsg("eatBreakfast", function(msg)
  128.         -- get the game object server
  129.         local gameObjectServer = getGameObjectServer();
  130.         -- get character who initiated this action
  131.         local character = getStateObjectFromID(msg.sender);
  132.         -- check if activity if possible
  133.         local possible, result, activity = activityPossible(character, msg.name, this);
  134.         
  135.         -- don't care if timeslot is not fulfilled
  136.         if (possible or enumCompare(result, TIMESLOT)) then
  137.             -- if this is broken: abort characters action
  138.             if abortIfBroken(character) then return end;        
  139.             -- walk to the closest action point
  140.             local actionPoint = character.getFreeActionPoint(this, "open");
  141.             if (actionPoint) then
  142.                 -- get the walk state object
  143.                 local wso = character.walkSO;
  144.                 -- create state machine contexts
  145.                 local wsoContext = StateMachineContext();
  146.                 -- store the action point
  147.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  148.                 wsoContext.storeData("tabletType", "tabletBreakfast");
  149.                 if (wso.walkToActionPoint(actionPoint)) then
  150.                     wso.queueStateMachine("fridgeTabletChar.open", this, wsoContext);
  151.                 else
  152.                     print("no path found");
  153.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  154.                 end
  155.             else
  156.                 print("no action point found");
  157.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  158.             end
  159.         else
  160.             -- activity not possible
  161.             print(msg.name .. " not possible");
  162.             
  163.             local emoticon;
  164.             if (enumCompare(result, NO_CONDITION)) then
  165.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  166.             else
  167.                 emoticon = EMOTICON_CANNOT;
  168.             end
  169.             instantAbort(character, emoticon, "emoThink");
  170.         end
  171.     end )
  172.     
  173.     -- open the fridge and take dinner
  174.     onMsg("eatDinner", function(msg)
  175.         -- get the game object server
  176.         local gameObjectServer = getGameObjectServer();
  177.         -- get character who initiated this action
  178.         local character = getStateObjectFromID(msg.sender);
  179.         
  180.         local possible, result, activity = activityPossible(character, msg.name, this);
  181.  
  182.         -- don't care if timeslot is not fulfilled
  183.         if (possible or enumCompare(result, TIMESLOT)) then
  184.             -- if this is broken: abort characters action
  185.             if abortIfBroken(character) then return end;        
  186.             -- walk to the closest action point
  187.             local actionPoint = character.getFreeActionPoint(this, "open");
  188.             if (actionPoint) then
  189.                 -- get the walk state object
  190.                 local wso = character.walkSO;
  191.                 -- create state machine contexts
  192.                 local wsoContext = StateMachineContext();
  193.                 -- store the action point
  194.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  195.                 wsoContext.storeData("tabletType", "tabletDinner");
  196.                 if (wso.walkToActionPoint(actionPoint)) then
  197.                     wso.queueStateMachine("fridgeTabletChar.open", this, wsoContext);
  198.                 else
  199.                     print("no path found");
  200.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  201.                 end
  202.             else
  203.                 print("no action point found");
  204.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  205.             end
  206.         else
  207.             -- activity not possible
  208.             print(msg.name .. " not possible");
  209.             
  210.             local emoticon;
  211.             if (enumCompare(result, NO_CONDITION)) then
  212.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  213.             else
  214.                 emoticon = EMOTICON_CANNOT;
  215.             end
  216.             instantAbort(character, emoticon, "emoThink");
  217.         end
  218.     end )
  219.     -- repair
  220.     onMsg("repair", function(msg)
  221.     
  222.         print("onMsg repair");
  223.         -- get character who initiated this action
  224.         local character = getStateObjectFromID(msg.sender);
  225.         -- walk to the closest action point
  226.         local actionPoint = character.getFreeActionPoint(this, "repair");
  227.         -- get the walk state object
  228.         local wso = character.walkSO;
  229.         if (actionPoint) then
  230.             -- create state machine contexts
  231.             local wsoContext = StateMachineContext();
  232.             -- store the action point
  233.             wsoContext.storeData("actionPointName", actionPoint.getName());
  234.             if (wso.walkToActionPoint(actionPoint)) then
  235.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  236.             else
  237.                 print("no path found");
  238.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  239.             end
  240.         else
  241.             print("no action point found");
  242.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  243.         end
  244.     end )
  245.                 
  246. endStateMachine()
  247.