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

  1. -- sofa character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         
  6. --        local sofa = retrieveStateObject("sofa");
  7. --        if (not sofa) then
  8. --            -- no sofa was stored
  9. --            sofa = getStateObjectFromID(msg.sender);
  10. --            storeStateObject("sofa", sofa);
  11. --        end
  12.  
  13.         print("onEnter sofaChar");    
  14.  
  15.         local sofa = getStoredOrSender({"sofa", "seat"}, msg);
  16.         if (not sofa) then
  17.             -- sofa does not exist anymore
  18.             print("onEnter sofaChar sofa does not exist anymore");    
  19.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  20.             sendMsg("emoThink", getParent().walkSO);
  21.             exitStateMachine();
  22.         else
  23.             print("onEnter sofaChar sofa does exist");    
  24.             storeStateObject("sofa", sofa);
  25.         end
  26.         
  27.         --freeHands(getParent());
  28.                 
  29.     end )
  30.     
  31.     onExit(function(msg)
  32.         print("sofaChar EXIT");
  33.         
  34. --        local sofa = retrieveStateObject("sofa");
  35. --        if (sofa) then
  36. --            getParent().unlockActionPoints(sofa);
  37. --            getParent().stopAllActivities(sofa);
  38. --            removeStateObject("sofa");
  39. --        end
  40.         unlockAll("sofa");
  41.                         
  42.         
  43.         local partner = retrieveStateObject("partner");
  44.         if (partner) then
  45.             getParent().unlockActionPoints(partner.getParent());
  46.             getParent().stopAllActivities(partner.getParent());
  47.             removeStateObject("partner");
  48.         end;
  49.             
  50.         getParent().stopAllActivities();    
  51.     end )
  52.     
  53.     
  54. --    -- test if we need to cancel
  55. --    onMsg("test", function(msg)
  56. --        if testCancel() or testCancelSleeping() then
  57. --            setState("getup");
  58. --        else
  59. --            sendDelayedMsgThis("test", 1000);
  60. --        end
  61. --    end )
  62.     
  63.     onMsg("waitIntimate", function(msg)
  64.         local sofa = retrieveStateObject("sofa");
  65.         getParent().queueCommand("pm_getIntimateSofa", "waitIntimate", sofa, "");
  66.     end )
  67.     
  68.     
  69.     
  70.     -- sit down on sofa
  71.     state("sitDown")
  72.     
  73.         onEnter(function(msg)
  74.             local sofa = retrieveStateObject("sofa");
  75.             local actionPointName = retrieveData("actionPointName");
  76.             if exitIfWrongPosition(getParent(), sofa, actionPointName) then return end;                
  77.  
  78.             if (getParent().isActionPointLocked(sofa, actionPointName)) then
  79.                 -- action point is locked
  80.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  81.                 sendMsg("emoThink", getParent().walkSO);
  82.                 exitStateMachine();
  83.             else
  84.                 getParent().lockActionPoint(sofa, actionPointName);
  85.                 if (retrieveData("sitState") == "playGuitar") then
  86.                     getParent().handSO.stopAnimation(0.0);
  87.                     startAnimation("playGuitarSitdown", false, 1.0, 0.0);
  88.                 else
  89.                     setPose("sitdownArmchair");
  90.                 end
  91.                 --sofa.playSound("Sofa setzen");
  92.                 sendDelayedMsgThis("sitSound", 1900);
  93.             end
  94.         end )
  95.         
  96.         onMsg("sitSound", function(msg)
  97.             local sofa = retrieveStateObject("sofa");
  98.             sofa.playSound("Sofa setzen");
  99.         end )
  100.     
  101.         onMsg("end", function(msg)
  102.             if testCancel() then
  103.                 setState("standUp");
  104.             else
  105.                 --setState("sit");
  106.                 setState(retrieveData("sitState", "sit"));
  107.             end        
  108.         end )
  109.     -----------------------------------------------------------------------------------------------------    
  110.         
  111. --    -- sit down on sofa
  112. --    state("sitDownToWatchTV")
  113. --    
  114. --        onEnter(function(msg)
  115. --            print("onEnter sitDownToWatchTV");    
  116. --
  117. --            local sofa = retrieveStateObject("sofa");
  118. --            
  119. --            local actionPointName = retrieveData("actionPointName");
  120. --            if (getParent().isActionPointLocked(sofa, actionPointName)) then
  121. --                -- action point is locked
  122. --                getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  123. --                sendMsg("emoThink", getParent().walkSO);
  124. --                exitStateMachine();
  125. --            else
  126. --                getParent().lockActionPoint(sofa, actionPointName);
  127. --                setPose("sitdownArmchair");            
  128. --                sofa.playSound("Sofa setzen");
  129. --            end
  130. --        end )
  131. --    
  132. --        onMsg("end", function(msg)
  133. --            if testCancel() then
  134. --                setState("standUp");
  135. --            else
  136. --                setState("watchTV");
  137. --            end        
  138. --        end )    
  139.         
  140.     ----------------------------------------------------------------------------------------    
  141.     state("watchTV")
  142.         
  143.         onEnter(function(msg)
  144.             print("onEnter sofaChar.watchTV");
  145.             
  146.             startAnimation(genderize(getParent(), "sitPoseArmchair"));
  147.             
  148.         
  149.             local tv = retrieveStateObject("tv");
  150.             local channel = retrieveData("channel");
  151.             
  152.             if (not tv) then
  153.                 setState("watchTVstop");
  154.                 return
  155.             end 
  156.             
  157.             print("start watch " .. channel);
  158.             
  159.             local watch = getParent().startActivity("watch" .. channel, tv);
  160.             local length, scale = getActivityLength(watch);
  161.             storeData("scale", scale);
  162.             sendDelayedMsgThis("complete", length);
  163.             setTopQueueEntry(getParent(), "pm_watch" .. channel)
  164.             
  165.             local sofa = retrieveStateObject("sofa");
  166.             getParent().startActivity("sit", sofa);
  167.             
  168.             sendDelayedMsgThis("act", 5000);
  169. --                actionComplete();
  170.  
  171.             local remoteControl = getParent().loadGameObject("StandardGO","remoteControl");
  172.             if (not remoteControl) then
  173.                 print("remoteControl not loaded");
  174.             else
  175.                 storeStateObject("remoteControl", remoteControl);
  176.                 getParent().attachRightObjectHolder(remoteControl);
  177.                 sendMsgThis("switch", channel);
  178.             end
  179.             
  180.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  181.                 
  182.         end )
  183.         
  184.         
  185.         onExit(function(msg)
  186.             
  187. --            local tv = retrieveStateObject("tv");
  188. --            getParent().stopAllActivities(tv);
  189. --            sendMsg("stopWatch", tv);
  190.                         
  191.             print("onExit sofaChar.watchTV");
  192.  
  193.             local tv = retrieveStateObject("tv");
  194.             if (tv) then
  195.                 getParent().unlockActionPoints(tv);
  196.                 getParent().stopAllActivities(tv);
  197.                 removeStateObject("tv");
  198.                 sendMsg("stopWatch", tv);
  199.             end
  200.         
  201.             local hands = getParent().handSO;
  202.             hands.stopAnimation();
  203.             
  204.             getParent().detachRightObjectHolder();                            
  205.             local remoteControl = retrieveStateObject("remoteControl");            
  206.             if (remoteControl) then remoteControl.deleteGameObject(); end
  207.             
  208.         end )
  209.     
  210.     
  211.         onMsg("switch", function(msg)
  212.             print("onMsg switch " .. msg.data);
  213.             local tv = retrieveStateObject("tv");
  214.             local currentChannel = tv.getState();
  215.                         
  216. --            if (msg.data == currentChannel) then
  217. --                print("no need to swtich to " .. msg.data);
  218. --                return
  219. --            end;
  220.             
  221.             local hands = getParent().handSO;
  222.             hands.startAnimation("remoteControl");
  223.             sendDelayedMsgThis("tvSwitch", 500, msg.data);
  224.         end )
  225.         
  226.         onMsg("tvSwitch", function(msg)
  227.             print("onMsg tvSwitch " .. msg.data);
  228.             
  229.             local tv = retrieveStateObject("tv");
  230.             sendMsg("switch", tv, msg.data);
  231.             
  232.             --getParent().replaceQueueEntry(0, "pm_watch" .. msg.data);
  233.             
  234.         end )
  235.         
  236.         onMsg("tvOff", function(msg)
  237.             print("onMsg tvOff");
  238.             setState("watchTVstop");
  239.         end )
  240.         
  241.         onMsg("tvSwitched", function(msg)
  242.             print("onMsg tvSwitched");
  243.             --getParent().replaceQueueEntry(0, "pm_watch" .. msg.data);
  244.             setTopQueueEntry(getParent(), "pm_watch" .. msg.data)
  245.             
  246.             local tv = retrieveStateObject("tv");
  247.             tv.lock(); --prevent breaking on switch
  248.             getParent().stopAllActivities(tv);
  249.             getParent().startActivity("watch" .. msg.data, tv);
  250.             tv.unlock(); --prevent breaking on switch
  251.         end )
  252.  
  253.         onMsg("complete", function(msg)
  254.             setState("watchTVstop");
  255.         end )
  256.  
  257. --        onMsg("queue", function(msg)
  258. --            exitStateMachine();
  259. --        end )
  260.  
  261.         onMsg("act", function(msg)
  262.             doSomething();
  263.             sendDelayedMsgThis("act", 5000);
  264.         end )
  265.         
  266.         onMsg("testCancel", function(msg)
  267.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  268.                 setState("watchTVstop");
  269.             else
  270.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  271.             end
  272.         end )
  273.         
  274.         
  275.         
  276.     state("watchTVstop")
  277.     
  278.         onEnter(function(msg)
  279.             local sofa = retrieveStateObject("sofa");
  280.             queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
  281.             setState("standUp");
  282.         end )
  283.         
  284.     ----------------------------------------------------------------------------------------
  285.     state("readBook")
  286.     
  287.         onEnter(function(msg)
  288.         
  289.             startAnimation(genderize(getParent(), "sitPoseArmchair"));
  290.         
  291.             -- remove closed book
  292.             getParent().detachLeftObjectHolder();    
  293.             local book = retrieveStateObject("book");
  294.             if (book) then book.deleteGameObject(); end
  295.             
  296.             -- load open book
  297.             book = getParent().loadGameObject("StandardGO","bookOpen");
  298.             if (not book) then
  299.                 print("create bookOpen failed");
  300.             end
  301.             storeStateObject("book", book);
  302.             getParent().attachLeftObjectHolder(book);
  303.                                     
  304.             local hands = getParent().handSO;
  305.             hands.stopAnimation();
  306.             
  307.             startAnimation("readBookPage");
  308.             
  309.             local sofa = retrieveStateObject("sofa");
  310.             getParent().startActivity("sit", sofa);
  311.             
  312.             print(" read activity " .. retrieveData("bookType", " UNKONWN "));
  313.             local readBook = getParent().startActivity("read" .. retrieveData("bookType", "Novel"), book);
  314.             local length, scale = getActivityLength(readBook);
  315.             storeData("length", length);
  316.             
  317.             sendDelayedMsgThis("complete", length);
  318.             sendDelayedMsgThis("turnPage", 3000);
  319.         
  320. --            this.actionComplete();
  321.             
  322.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  323.  
  324.         end )
  325.         
  326.         onExit(function(msg)
  327.             local book = retrieveStateObject("book");
  328.             if (book) then 
  329.                 getParent().stopAllActivities(book);
  330.             end
  331.             freeHands(getParent());
  332.         end )
  333.         
  334.         onMsg("turnPage", function(msg)
  335.             startAnimation("readBookPage");
  336.             sendDelayedMsgThis("turnPage", random(5000, 20000));
  337.         end )
  338.  
  339.         onMsg("end", function(msg)
  340.             if (testCancel()) then
  341.                 setState("readBookStop");
  342.             end
  343.         end )
  344.  
  345. --        onMsg("queue", function(msg)
  346. --            setState("readBookStop");
  347. --        end )
  348.  
  349.         onMsg("complete", function(msg)
  350.             setState("readBookStop");
  351.         end )
  352.         
  353.         onMsg("testCancel", function(msg)
  354.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  355.                 setState("readBookStop");
  356.             else
  357.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  358.             end
  359.         end )
  360.  
  361.     state("readBookStop")
  362.     
  363.         onEnter(function(msg)
  364.             local sofa = retrieveStateObject("sofa");
  365.             queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
  366.             setState("standUp");
  367.         end )
  368.         
  369.         
  370.     ----------------------------------------------------------------------------------------
  371.  
  372.  
  373.     state("playGuitar")
  374.     
  375.         onEnter(function(msg)
  376.         
  377.             local guitarRack = retrieveStateObject("guitarRack");
  378.             local play = getParent().startActivity("playGuitar", guitarRack);
  379.             local length, scale = getActivityLength(play);
  380.             storeData("scale", scale);
  381.             
  382.             local sofa = retrieveStateObject("sofa");
  383.             getParent().startActivity("sit", sofa);            
  384.         
  385.             startAnimation("playGuitarLoop");
  386.             sendDelayedMsgThis("stopPlaying", length);
  387.             --this.actionComplete();
  388.             
  389.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  390.             
  391.             getParent().loopSound("guitar");
  392.         end )    
  393.         
  394.         
  395.         onExit(function(msg)
  396.             getParent().stopSound("guitar");                        
  397.             freeHands(getParent());
  398.             
  399.             local guitarRack = retrieveStateObject("guitarRack");
  400.             if (guitarRack) then  
  401.                 guitarRack.setChildEnable("guitar", true) 
  402.                 getParent().stopAllActivities(guitarRack);
  403.                 getParent().unlockActionPoints(guitarRack);
  404.                 removeStateObject("guitarRack");
  405.             end
  406.         end )    
  407.         
  408.         
  409.         
  410.         onMsg("testCancel", function(msg)
  411.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  412.                 sendMsgThis("stopPlaying");
  413.             else
  414.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  415.             end
  416.         end )
  417.         
  418.  
  419.         onMsg("end", function(msg)
  420.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  421.                 sendMsgThis("stopPlaying");
  422.             else
  423.                 startAnimation("playGuitarLoop");
  424.             end
  425.         end )
  426.  
  427.         onMsg("stopPlaying", function(msg)
  428.             setState("playGuitarStop");
  429.         end )
  430.  
  431.  
  432.  
  433.     state("playGuitarStop")
  434.     
  435.         onEnter(function(msg)
  436.             local sofa = retrieveStateObject("sofa");
  437.             queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
  438.             setState("standUp");
  439.         end )
  440.  
  441.  
  442.         
  443.         
  444.             
  445. --        onReturn(function(msg)
  446. --            print("onReturn sitDownToWatchTV");    
  447. --            setState("standUp");
  448. --        end )    
  449.         
  450.         
  451. --    state("watchTV")
  452. --    
  453. --        onEnter(function(msg)
  454. --            print("onEnter watchTV");    
  455. --            enterStateMachine("tvChar.watch");
  456. --        end )
  457. --    
  458. --            
  459. --        onReturn(function(msg)
  460. --            local sofa = retrieveStateObject("sofa");
  461. --            --getParent().queueCommand("pm_sitdown", "sit", sofa, "");
  462. --            --setTopQueueEntry(getParent(), "pm_sitdown", true);
  463. --            queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
  464. --            setState("standUp");
  465. --            
  466. --        end )    
  467.             
  468.     
  469.  
  470.         
  471. --    -- sit on sofa
  472. --    state("sit")
  473. --    
  474. --        onEnter(function(msg)
  475. --            startAnimation("sitPoseArmchair");            
  476. --            
  477. --            local sofa = retrieveStateObject("sofa");
  478. --            local sit = getParent().startActivity("sit", sofa);
  479. --                        
  480. --            sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  481. --            
  482. --        end )
  483. --    
  484. --        onMsg("queue", function(msg)
  485. --            setState("standUp");
  486. --        end )
  487. --        
  488. --        onMsg("act", function(msg)
  489. --            doSomething();
  490. --            sendDelayedMsgThis("act", 5000);
  491. --        end )
  492. --        
  493. --        onMsg("end", function(msg)
  494. --            actionComplete();
  495. --        end )    
  496. --    
  497. --        onMsg("testCancel", function(msg)
  498. --            if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
  499. --                setState("standUp");
  500. --            else
  501. --                sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  502. --            end
  503. --        end )
  504.         
  505.         
  506.     state("sit")
  507.     
  508.         onEnter(function(msg)
  509.             startAnimation(genderize(getParent(), "sitPoseArmchair"), false, 1.0, 1000);
  510.             --setTopQueueEntry(getParent(), "pm_sitdown");
  511.         end )
  512.     
  513.         onMsg("end", function(msg)
  514.             if testCancel() then
  515.                 setState("sitStop");
  516.             else
  517.                 local sofa = retrieveStateObject("sofa");
  518.                 local sit = getParent().startActivity("sit", sofa);
  519.                 
  520.                 local length = sit.getLength();
  521.                 storeData("length", length);
  522.                 sendDelayedMsgThis("act", length);                
  523.                 actionComplete();                
  524.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  525.             end
  526.         end )    
  527.     
  528.         onMsg("queue", function(msg)
  529.             setState("sitStop");
  530.         end )    
  531.  
  532.         onMsg("act", function(msg)
  533.             doSomething();
  534.             sendDelayedMsgThis("act", 5000);
  535.         end )
  536.         
  537.         onMsg("testCancel", function(msg)
  538.             if testCancel() or (this.getParent().getActivityQueueCount() > 1)  or (not this.getParent().getCurrentActivityGain()) then
  539.                 setState("sitStop");
  540.             else
  541.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  542.             end
  543.         end )
  544.         
  545.  
  546.     state("sitStop")
  547.     
  548.         onEnter(function(msg)
  549.             startAnimation(genderize(getParent(), "sitPoseArmchair"), false, -1.0);
  550.             local sofa = retrieveStateObject("sofa");
  551.             --sofa.playSound("Sofa setzen");
  552.         end )
  553.     
  554.         onMsg("end", function(msg)
  555.             setState("standUp");
  556.         end )    
  557.         
  558.         
  559.         
  560.         
  561.         
  562.     -- stand up from sofa
  563.     state("standUp")
  564.     
  565.         onEnter(function(msg)
  566.             local sofa = retrieveStateObject("sofa");
  567.             local character = getParent();
  568.             
  569.             -- drop stuff like remote control or book
  570.             freeHands(character);
  571.             
  572.             -- check if we schould really stand up
  573.             
  574.             if checkShortcut(sofa, {"sit", "waitIntimate"}, {"sit", "waitIntimate"}) then return end;
  575.             
  576.             if (retrieveData("actionPointName") == "sit2" and not character.isOneActionPointLocked(sofa)) then
  577.                 if checkShortcut(sofa, {"nap"}, {"layDownFromSit"}) then return end;
  578.             end;
  579.             
  580.             if checkWatchShortcut(sofa, {"watch"}, {"watchTV"}, {"watchShortcut"}) then 
  581.                 return 
  582.             end;
  583.             
  584.                                     
  585.             local others = getOtherUsers(character, sofa, "sit");
  586.             local other = others[1];
  587.             if (other) then            
  588.                 local possible, mirrorAnims = getSofaIteractionInfo(character, other);
  589.                 if (possible) then
  590.                     if checkShortcut(other, {"getIntimateSofa"}, {"waitIntimate"}, {"getIntimateSofaShortcut"}) then
  591.                         return
  592.                     end
  593.                 end
  594.             else
  595.                 print("standUp check shortcuts; no OtherUsers found");
  596.             end
  597.             
  598.             
  599.             -- stand up
  600.             startAnimation("standupArmchair");
  601.             getParent().stopAllActivities(sofa);
  602.             
  603.             sendDelayedMsgThis("sitSound", 400);
  604.             
  605.         end )
  606.         
  607.         
  608.         onMsg("sitSound", function(msg)
  609.             local sofa = retrieveStateObject("sofa");
  610.             sofa.playSound("Sofa setzen");
  611.         end )
  612.         
  613.     
  614.         onMsg("end", function(msg)
  615.             flipPoseDirection();
  616.             exitAndGoAway();
  617.         end )    
  618.     
  619.     -- lay down on sofa: sit down first
  620.     state("layDown")
  621.     
  622.         onEnter(function(msg)
  623.             setPose("sitdownArmchair");
  624.             local sofa = retrieveStateObject("sofa");
  625.                         
  626.             if (getParent().isOneActionPointLocked(sofa)) then
  627.                 -- action point is locked
  628.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  629.                 sendMsg("emoThink", getParent().walkSO);
  630.                 exitStateMachine();
  631.             else
  632.                 getParent().lockActionPoints(sofa);
  633.             end
  634.         end )
  635.     
  636.         onMsg("end", function(msg)
  637.             if testCancel() then
  638.                 setState("standUp")
  639.             else
  640.                 setState("layDownFromSit");
  641.             end
  642.         end )    
  643.         
  644.     -- lay down on sofa from sit
  645.     state("layDownFromSit")
  646.     
  647.         onEnter(function(msg)
  648.             startAnimation("laydownSofa");
  649.             local sofa = retrieveStateObject("sofa");
  650.             getParent().lockActionPoints(sofa);
  651.             
  652.         end )
  653.     
  654.         onMsg("end", function(msg)
  655.         
  656.             if testCancel() then
  657.                 setState("getup");
  658.             else
  659.                 local sofa = retrieveStateObject("sofa");
  660.                 local nap = getParent().startActivity("nap", sofa);
  661.                 -- local length, scale = getActivityLength(nap);
  662.                 local length = nap.getLength();
  663.                 --getParent().setMimic("eyeClose");
  664.                 sendMsg("eyeClose", getParent().mimicSO);
  665.                 
  666.                 -- character now sleeping
  667.                 getParent().setSleeping(true);
  668.                 
  669.                 -- sendDelayedMsgThis("test", 1000);
  670.                 -- sendDelayedMsgThis("act", 5000);
  671.                 
  672.                 --actionComplete();
  673.                 sendDelayedMsgThis("getUp", length);
  674.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  675.             end
  676.         
  677.         end )    
  678.     
  679.         onMsg("queue", function(msg)
  680.             setState("getup");
  681.         end )
  682.         
  683.         onMsg("getUp", function(msg)
  684.             setState("getup");
  685.         end )
  686.  
  687.         onMsg("testCancel", function(msg)
  688.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  689.                 setState("getup");
  690.             else
  691.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  692.             end
  693.         end )
  694.                 
  695.         onMsg("act", function(msg)
  696.             sendDelayedMsgThis("act", 5000);
  697.         end )
  698.         
  699.     -- stand up from laying down
  700.     state("getup")
  701.     
  702.         onEnter(function(msg)
  703.         
  704.             local sofa = retrieveStateObject("sofa");
  705.         
  706.             startAnimation("getupSofa");
  707.             
  708.             -- character not sleeping anymore
  709.             getParent().setSleeping(false);
  710.             
  711.             getParent().sendMsgThis("smile");
  712.             getParent().stopAllActivities(sofa);
  713.             
  714.             sendMsg("neutral", getParent().mimicSO);
  715.         end )
  716.     
  717.         onMsg("end", function(msg)
  718.         
  719.             local sofa = retrieveStateObject("sofa");
  720.             getParent().unlockActionPoints(sofa);
  721.             getParent().lockActionPoint(sofa, "sit2");
  722.                     
  723.             setState("standUp");
  724.         end )    
  725.         
  726.         
  727.  
  728.  
  729.  
  730. --    -- sit down on sofa to get initmate
  731. --    state("sitDownToGetIntimate")
  732. --    
  733. --        onEnter(function(msg)
  734. --            local sofa = retrieveStateObject("sofa");
  735. --            
  736. --            local actionPointName = retrieveData("actionPointName");
  737. --            print("sitDownToGetIntimate");
  738. --            if (getParent().isActionPointLocked(sofa, actionPointName)) then
  739. --                -- action point is locked
  740. --                getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  741. --                sendMsg("emoThink", getParent().walkSO);
  742. --                exitStateMachine();
  743. --            else
  744. --                getParent().lockActionPoint(sofa, actionPointName);
  745. --                setPose("sitdownArmchair");            
  746. --                sofa.playSound("Sofa setzen");
  747. --            end
  748. --        end )
  749. --    
  750. --        onMsg("end", function(msg)
  751. --            if (testCancel()) then
  752. --                setState("getup");
  753. --            else
  754. --                local sofa = retrieveStateObject("sofa");
  755. --                getParent().startActivity("sit", sofa);
  756. --                setState("waitIntimate");
  757. --            end
  758. --        end )    
  759.     
  760.     ---------------------------------------------------------------------------------------------------
  761.     
  762.     -- wait intimate
  763.     state("waitIntimate")
  764.     
  765.         onEnter(function(msg)
  766.             print("-- sofa waitIntimate --");
  767.             -- startAnimation("sleepingTurnToLeftSide", retrieveData("mirrorAnims"));
  768.                         
  769.             sendDelayedMsgThis("sendReadyMsg", 1000);
  770.             sendDelayedMsgThis("stopWaiting", 30000);
  771.             
  772.             sendMsg("neutral", getParent().mimicSO);
  773.             getParent().setEmoticon("");
  774.             
  775.         end )
  776.         
  777.         onMsg("sendReadyMsg", function(msg)
  778.             if testCancel() then
  779.                 sendMsgThis("stopWaiting");
  780.             else
  781.                 local partner = retrieveStateObject("partner");
  782.                 if (not partner) then
  783.                     print("sendReadyMsg no partner found");
  784.                     sendMsgThis("stopWaiting");
  785.                     return
  786.                 end
  787.                 sendMsg("partnerReady", partner);
  788.                 sendDelayedMsgThis("sendReadyMsg", 1000);
  789.             end
  790.         end )
  791.     
  792.         onMsg("stopWaiting", function(msg)
  793.             local sofa = retrieveStateObject("sofa");
  794.             queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
  795.             setState("standUp");
  796.             --setState("sit");
  797.         end )
  798.     
  799.         onMsg("partnerReady", function(msg)
  800.             setState("sitCloser");
  801.             local partner = retrieveStateObject("partner");
  802.             partner.setState("sitCloser");
  803.         end )
  804.         
  805.         onMsg("partnerCancel", function(msg)
  806.             setState("sit");
  807.         end )
  808.  
  809.     
  810.         onMsg("end", function(msg)
  811.             if testCancel() then
  812.                 sendMsgThis("stopWaiting");
  813.             else
  814.                 actionComplete();
  815.             end
  816.         end )    
  817.  
  818.     state("sitCloser")
  819.     
  820.         onEnter(function(msg)
  821.             print("-- sitCloser --");
  822.             local activePart = retrieveData("activePart");
  823.             
  824.             getParent().replaceQueueEntry(0, "pm_getIntimateSofa");
  825.  
  826.             startAnimation(genderize(getParent(), "sofaSitClose"), retrieveData("mirrorAnims"));
  827.  
  828.         end )
  829.         
  830.         onMsg("partnerCancel", function(msg)
  831.             setState("sitCloserStop");
  832.         end )
  833.                 
  834.         onMsg("end", function(msg)
  835.             if (testCancel()) then
  836.                 setState("sitCloserStop");
  837.                 local partner = retrieveStateObject("partner");
  838.                 sendMsg("partnerCancel", partner);
  839.             else            
  840.                 setState("holdInArms");
  841.             end
  842.         end )
  843.         
  844.     state("holdInArms")
  845.     
  846.         onEnter(function(msg)
  847.             print("-- holdInArms --");
  848.             local activePart = retrieveData("activePart");
  849.  
  850.             startAnimation(genderize(getParent(), "sofaHold"), retrieveData("mirrorAnims"));
  851.  
  852.         end )
  853.         
  854.         onMsg("partnerCancel", function(msg)
  855.             setState("holdInArmsStop");
  856.         end )
  857.                 
  858.         onMsg("end", function(msg)
  859.             if (testCancel()) then
  860.                 setState("holdInArmsStop");
  861.                 local partner = retrieveStateObject("partner");
  862.                 sendMsg("partnerCancel", partner);
  863.             else            
  864.                 setState("holdKiss");
  865.             end
  866.         end )
  867.         
  868.     state("holdKiss")
  869.     
  870.         onEnter(function(msg)
  871.             print("-- holdKiss --");
  872.             --local activePart = retrieveData("activePart");
  873.             local partner = retrieveStateObject("partner");
  874.             local kissIntimate = getParent().startActivity("kissIntimate", partner.getParent());
  875.             local length, scale = getActivityLength(kissIntimate);
  876.  
  877.             startAnimation(genderize(getParent(), "sofaKissLoop"), retrieveData("mirrorAnims"));
  878.             
  879.             sendDelayedMsgThis("stopKissing", length);
  880.             --this.actionComplete();
  881.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  882.                         
  883.         end )
  884.         
  885.         onMsg("stopKissing", function(msg)
  886.             setState("holdInArmsStop");
  887.             local partner = retrieveStateObject("partner");
  888.             getParent().stopActivity("kissIntimate", partner.getParent());
  889.             sendMsg("partnerCancel", partner);            
  890.         end )
  891.         
  892.         onMsg("testCancel", function(msg)
  893.             if testCancel() then
  894.                 sendMsgThis("stopKissing");            
  895.             else
  896.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  897.             end
  898.         end )            
  899.         
  900.         
  901.         onMsg("partnerCancel", function(msg)
  902.             sendMsgThis("stopKissing");            
  903.         end )
  904.     
  905.         onMsg("queue", function(msg)
  906.             sendMsgThis("stopKissing");            
  907.         end )        
  908.             
  909.         onMsg("end", function(msg)
  910.             if (testCancel()) then
  911.                 sendMsgThis("stopKissing");            
  912.             else
  913.                 startAnimation(genderize(getParent(), "sofaKissLoop"), retrieveData("mirrorAnims"));
  914.             end
  915.     
  916.         end )
  917.         
  918.     state("holdInArmsStop")
  919.     
  920.         onEnter(function(msg)
  921.             print("-- holdInArmsStop --");
  922.             startAnimation(genderize(getParent(), "sofaHoldStop"), retrieveData("mirrorAnims"), 1.0, SEX_FADE_TIME);
  923.  
  924.         end )
  925.                     
  926.         onMsg("end", function(msg)
  927.             setState("sitCloserStop");
  928.         end )
  929.                 
  930.     state("sitCloserStop")
  931.     
  932.         onEnter(function(msg)
  933.             print("-- sitCloserStop --");
  934.             local activePart = retrieveData("activePart");
  935.  
  936.             startAnimation(genderize(getParent(), "sofaSitCloseStop"), retrieveData("mirrorAnims"));
  937.  
  938.         end )
  939.                         
  940.         onMsg("end", function(msg)
  941.             --setState("sit");
  942.             local sofa = retrieveStateObject("sofa");
  943.             queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
  944.             setState("standUp");
  945.         end )
  946.         
  947.         
  948.     
  949. endStateMachine()
  950.