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

  1. -- guitar character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local guitarRack = getStateObjectFromID(msg.sender);
  6.         storeStateObject("guitarRack", guitarRack);
  7.         
  8.         if (guitarRack) then
  9.             -- guitarRack does exist
  10.             if exitIfWrongPosition(getParent(), guitarRack, retrieveData("actionPointName")) then return end;            
  11.             
  12.             if (getParent().isOneActionPointLocked(guitarRack)) then
  13.                 -- action point is locked
  14.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  15.                 sendMsg("emoThink", getParent().walkSO);
  16.                 exitStateMachine();
  17.             else
  18.                 getParent().lockActionPoints(guitarRack);
  19.             end
  20.         else
  21.             -- guitarRack does not exist anymore
  22.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  23.             sendMsg("emoThink", getParent().walkSO);
  24.             exitStateMachine();
  25.         end
  26.         
  27.         freeHands(getParent());
  28.                 
  29.     end )
  30.     
  31.     onExit(function(msg)
  32.     
  33.         freeHands(getParent());
  34.         removeStateObject("guitar");
  35.         
  36. --        local guitarRack = retrieveStateObject("guitarRack");
  37. --        getParent().unlockActionPoints(guitarRack);
  38. --        getParent().stopAllActivities(guitarRack);
  39. --        removeStateObject("guitarRack");
  40.         
  41.         unlockAll("guitarRack");        
  42.                                 
  43.                                 getParent().stopAllActivities();
  44.     end )
  45.     
  46.     state("takeGuitar")
  47.     
  48.         onEnter(function(msg)
  49.         
  50.             --startAnimation("playGuitarLoop");
  51.             
  52.             local guitarRack = retrieveStateObject("guitarRack");
  53.             local guitar = guitarRack.createGameObject("guitar");
  54.             storeStateObject("guitar", guitar);
  55.             getParent().attachLeftObjectHolder(guitarRack, "guitar");
  56.             getParent().handSO.setPose("leftHandHoldVert");
  57.             
  58.             setState("lookForSeat");
  59.             
  60.         end )
  61.     
  62.         
  63. --        onMsg("queue", function(msg)
  64. --            getParent().detachLeftObjectHolder();
  65. --            exitStateMachine();
  66. --        end )    
  67. --
  68. --        onMsg("end", function(msg)
  69. --            if testCancel() then
  70. --                getParent().detachLeftObjectHolder();
  71. --                exitStateMachine();
  72. --            else
  73. --                startAnimation("playGuitarLoop");
  74. --            end
  75. --        end )    
  76.         
  77.  
  78. --    state("lookForSeat")
  79. --        print("lookForSeat");
  80. --    
  81. --        onEnter(function(msg)
  82. --            -- find a sofa to play guitar
  83. --            local seat, actionPoint = getNextReadSit(getParent());
  84. --            if (not seat) then
  85. --                sendMsgThis("noPlaceToPlay");
  86. --                return            
  87. --            end
  88. --            
  89. --            local wso = getParent().walkSO;
  90. --            if (wso.walkToActionPoint(actionPoint)) then
  91. --            
  92. --                -- create state machine contexts
  93. --                local wsoContext = StateMachineContext();
  94. --                wsoContext.storeStateObject("seat", seat);
  95. --                wsoContext.storeStateObject("guitarRack", retrieveStateObject("guitarRack"));
  96. --                wsoContext.storeStateObject("guitar", retrieveStateObject("guitar"));
  97. --                wsoContext.storeData("actionPointName", actionPoint.getName());
  98. --                
  99. --                wso.queueStateMachine("sofaGuitarChar.sitDown", this, wsoContext);                
  100. --                exitStateMachine();
  101. --            else
  102. --                print("no path found");
  103. --                character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  104. --                sendMsg("emoThink", character.walkSO);
  105. --                sendMsgThis("noPlaceToPlay");
  106. --            end
  107. --            
  108. --            
  109. --            
  110. --            
  111. --        end)
  112.  
  113.  
  114.  
  115.     state("lookForSeat")
  116.         print("lookForSeat");
  117.     
  118.         onEnter(function(msg)
  119.             -- find a sofa to play guitar
  120.             local seat, actionPoint = getNextReadSit(getParent());
  121.             if (not seat) then
  122.                 sendMsgThis("noPlaceToPlay");
  123.                 return            
  124.             end
  125.             
  126.             --local wso = getParent().walkSO;
  127.             if (walkToPointImmediate(actionPoint)) then
  128.             
  129.                 -- create state machine contexts
  130. --                local wsoContext = StateMachineContext();
  131. --                wsoContext.storeStateObject("seat", seat);
  132. --                wsoContext.storeStateObject("guitarRack", retrieveStateObject("guitarRack"));
  133. --                wsoContext.storeStateObject("guitar", retrieveStateObject("guitar"));
  134. --                wsoContext.storeData("actionPointName", actionPoint.getName());
  135.                 
  136. --                wso.queueStateMachine("sofaGuitarChar.sitDown", this, wsoContext);                
  137. --                exitStateMachine();
  138.  
  139.                 storeStateObject("sofa", seat);
  140.                 storeData("actionPointName", actionPoint.getName());
  141.                 enterStateMachine("subwalk.walk");
  142.             else
  143.                 print("no path found");
  144.                 character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  145.                 sendMsg("emoThink", character.walkSO);
  146.                 sendMsgThis("noPlaceToPlay");
  147.             end
  148.             
  149.         end)
  150.  
  151.         onReturn(function(msg)
  152.             print("lookForSeat onReturn");
  153.             setState("sitAndPlay");
  154.         end)
  155.  
  156.  
  157.  
  158.         onMsg("noPlaceToPlay", function(msg)
  159.         
  160.             print("no place to play");
  161.             -- detach book if attached to left hand
  162. --            getParent().detachLeftObjectHolder();
  163. --            getParent().detachRightObjectHolder();
  164. --            local guitar = retrieveStateObject("guitar");
  165. --            if (guitar) then guitar.deleteGameObject(); end
  166. --            getParent().handSO.stopPose();
  167.             
  168.             getParent().setEmoticon(EMOTICON_NOSOFA, EMOTICON_DELAY);            
  169.             sendMsg("emoThink", getParent().walkSO);
  170.             exitStateMachine();
  171.         end)
  172.  
  173.     state("sitAndPlay")
  174.     
  175.         onEnter(function(msg)
  176.             print("sitAndPlay onEnter");
  177.             storeData("sitState", "playGuitar");
  178.             enterStateMachine("sofaChar.sitDown");
  179. --            enterStateMachine("sofaGuitarChar.sitDown");
  180.         end)
  181.         
  182.         onReturn(function(msg)
  183.             print("sitAndPlay onReturn");
  184.             exitStateMachine();
  185.         end)
  186.  
  187.  
  188.                 
  189. endStateMachine()
  190.