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

  1. -- bed  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_sleep", "sleep");
  13.         button.addDescription(ACTIVITY, "sleep");
  14.         -- can always be selected by user
  15.         button.addDescription(ALWAYS_USERSELECTABLE, "true");
  16.         
  17.         local character = getStateObjectFromID(msg.sender);
  18.  
  19.         if (not isUser(character, this, {"lie"})) then    
  20.             local otherUsers = getOtherUsers(character, this, "lie")
  21.             if (getn(otherUsers) > 0) then
  22.                 local characterInBed = otherUsers[1];
  23.                 if activityPossible(character, "getIntimateBed", characterInBed) then
  24.                     button = addPieMenuButton("pm_getIntimateBed", "getIntimateBed");
  25.                     button.addDescription(ACTIVITY, "getIntimateBed");
  26.                 else
  27.                     -- add grayed out
  28.                     button = addPieMenuButton("pm_getIntimateBed", "getIntimateBed");
  29.                     button.addDescription(GRAYED_OUT, "true");
  30.                 end;
  31.             end
  32.         end
  33.         
  34. --        local occupants = getCharactersWithActivity("sleep");
  35. --        if (getn(occupants)>0) then
  36. --            
  37. --            button = addPieMenuButton("pm_getIntimateBed", "getIntimateBed");
  38. --            button.addDescription(ACTIVITY, "getIntimateBed");
  39. --            --button.addDescription(DONTQUEUE, "true");
  40. --        end
  41.         
  42.         
  43.     end )
  44.     
  45.     -- get intimate with a bed occupant
  46.     onMsg("getIntimateBed", function(msg)
  47.         local character = getStateObjectFromID(msg.sender);
  48.         
  49.         -- check if activity if possible
  50.         local possible, result, activity = activityPossible(character, msg.name, this);
  51.  
  52.         -- don't care if timeslot is not fulfilled
  53.         if (possible or enumCompare(result, TIMESLOT)) then
  54.             local occupants = getOtherUsers(character, this, "lie")
  55.             
  56.             if (getn(occupants) == 0) then 
  57.                 print("doublebed.lua::getIntimateBed no occupants found");
  58.                 instantAbort(character, EMOTICON_CANNOT, "emoThink");
  59.                 return
  60.             end
  61.             
  62.             local occupant = occupants[1];
  63.             character.sendMsg("getIntimateBed", occupant);
  64.         else
  65.             -- activity not possible
  66.             print(msg.name .. " not possible");
  67.             
  68.             local emoticon;
  69.             if (enumCompare(result, NO_CONDITION)) then
  70.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  71.             else
  72.                 emoticon = EMOTICON_CANNOT;
  73.             end
  74.             instantAbort(character, emoticon, "emoThink");
  75.         end
  76.         
  77.     end )
  78.     
  79.     -- get intimate with a bed occupant
  80.     onMsg("getIntimateBedShortcut", function(msg)
  81.         local character = getStateObjectFromID(msg.sender);
  82.         
  83.         
  84.         --local occupants = getCharactersWithActivity("sleep");
  85.         local occupants = getOtherUsers(character, this, "lie")
  86.         
  87.         if (getn(occupants) == 0) then 
  88.             print("doublebed.lua::getIntimateBed no occupants found");
  89.             --instantAbort(character, EMOTICON_CANNOT, "emoThink");
  90.             return
  91.         end
  92.         
  93.         local occupant = occupants[1];
  94.         character.sendMsg("getIntimateBedShortcut", occupant);
  95.         
  96.     end )
  97.  
  98.     -- lay on bed
  99.     onMsg("sleep", function(msg)
  100.         -- get the game object server
  101.         local gameObjectServer = getGameObjectServer();
  102.         -- get character who initiated this action
  103.         local character = getStateObjectFromID(msg.sender);
  104.         
  105.         -- check if activity if possible
  106.         local possible, result, activity = activityPossible(character, msg.name, this);
  107.         
  108.         -- don't care if timeslot is not fulfilled
  109.         if (possible or enumCompare(result, TIMESLOT)) then
  110.  
  111.             -- check if sombody else in bed, and if we can share a bed with him
  112.             local occupants = getOtherUsers(character, this, "lie");
  113.             if (getn(occupants) > 0) then 
  114.                 local occupant = occupants[1];
  115.                 if (not activityPossible(character, "inBedTogether", occupant)) then
  116.                     instantAbort(character, EMOTICON_SHY, "emoRefuseChar", occupant);
  117.                     return
  118.                 end
  119.             end
  120.             
  121.             -- walk to the closest action point
  122.             local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"layDown1", "layDown2"});
  123.             -- get the walk state object
  124.             local wso = character.walkSO;
  125.             if (actionPoint) then
  126.                 -- create state machine contexts
  127.                 local wsoContext = StateMachineContext();
  128.                 -- store the action point
  129.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  130.                 if (wso.walkToActionPoint(actionPoint)) then
  131.                     wso.queueStateMachine("doublebedChar.layDown", this, wsoContext);
  132.                 else
  133.                     print("no path found");
  134.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  135.                 end
  136.             else
  137.                 print("doublebed.lua: no action point found of layDown1, layDown2");
  138.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  139.             end
  140.         else
  141.             -- activity not possible
  142.             print(msg.name .. " not possible");
  143.             
  144.             local emoticon;
  145.             if (enumCompare(result, NO_CONDITION)) then
  146.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  147.             else
  148.                 emoticon = EMOTICON_CANNOT;
  149.             end
  150.             instantAbort(character, emoticon, "emoThink");
  151.         end
  152.     end )
  153.             
  154. endStateMachine()
  155.