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

  1. -- bookshelf character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     end )
  6.     
  7.     onExit(function(msg)
  8. --        local bookshelf = retrieveStateObject("bookshelf");
  9. --        if (bookshelf) then
  10. --            getParent().unlockActionPoints(bookshelf);
  11. --            removeStateObject("bookshelf");
  12. --        end;
  13.         unlockAll("bookshelf");
  14.         unlockAll("book");
  15.                                    
  16.         getParent().stopAllActivities();
  17.     end )
  18.     
  19.     state("takeBoardgame")
  20.     
  21.         onEnter(function(msg)
  22.             local bookshelf = retrieveStateObject("bookshelf");
  23.             startAnimation("takeBoardgame");
  24.                         
  25.             if (bookshelf) then
  26.                 -- bookshelf does exist
  27.                 
  28.                 if exitIfWrongPosition(getParent(), bookshelf, retrieveData("actionPointName")) then return end;    
  29.                 
  30.                 
  31.                 if (getParent().isOneActionPointLocked(bookshelf)) then
  32.                     -- action point is locked
  33.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  34.                     sendMsg("emoThink", getParent().walkSO);
  35.                     exitStateMachine();
  36.                 else
  37.                     getParent().lockActionPoints(bookshelf);
  38.                 end
  39.             else
  40.                 -- bookshelf does not exist anymore
  41.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  42.                 sendMsg("emoThink", getParent().walkSO);
  43.                 exitStateMachine();
  44.             end
  45.             
  46.             freeHands(getParent());            
  47.             sendDelayedMsgThis("grabBoardgame", 1000);
  48.         end )
  49.     
  50.  
  51.         onMsg("grabBoardgame", function(msg)
  52.             print("create game");
  53.             local boardgame = getParent().loadGameObject("StandardGO","boardgameBox");
  54.             if (not boardgame) then
  55.                 print("create boardgame failed");
  56.             end
  57.             
  58.             storeStateObject("boardgame", boardgame);
  59.             getParent().attachLeftObjectHolder(boardgame);            
  60.             
  61.             local hso = getParent().handSO;
  62.             if (not hso) then
  63.                 print("no hands found");
  64.             else
  65.                 hso.setPose("leftHandHold");
  66.             end
  67.             
  68.         end)
  69.  
  70.  
  71.         onMsg("end", function(msg)
  72.             if testCancel() then
  73.                 freeHands(getParent());
  74.                 exitAndGoAway();
  75.             else            
  76.                 --setState("lookForChair");
  77.                 
  78.                 local boardgame = getParent().getLeftHeldObject();
  79.                 local wsoContext = StateMachineContext();
  80.                 wsoContext.storeStateObject("boardgame", boardgame);
  81.                 wsoContext.storeStateObject("tableObject", boardgame);
  82.                 wsoContext.storeData("chairCommand", "playByTableChar.sitDownWithGame");
  83.                 wsoContext.storeData("checkPartnerChair", true);
  84.                 queueStateMachine("tableChairChar.findChair", this, wsoContext);
  85.                 exitStateMachine();
  86.                                 
  87.             end
  88.         end )    
  89.         
  90.         onExit(function(msg)
  91.             -- getParent().detachObjectAnimator();
  92.         end)
  93.         
  94.         
  95.         
  96.         
  97.         
  98. --    -- look for free chair
  99. --    state("lookForChair")
  100. --        print("lookForChair");
  101. --    
  102. --        onEnter(function(msg)                
  103. --                
  104. --            local tablet = retrieveStateObject("tablet");
  105. --                                                
  106. --            getParent().handSO.setPose("leftHandHold");
  107. --            getParent().attachLeftObjectHolder(tablet);                            
  108. --            
  109. --            local wsoContext = StateMachineContext();
  110. --            wsoContext.storeStateObject("boardgame", boardgame);
  111. --            wsoContext.storeStateObject("tableObject", boardgame);
  112. --            wsoContext.storeData("chairCommand", "playByTableChar.sitDownWithGame");
  113. --            queueStateMachine("tableChairChar.findChair", this, wsoContext);
  114. --            exitStateMachine();
  115. --        end)
  116. --        
  117. --        
  118.         
  119.         
  120.         
  121. --        
  122. --    -- look for free chair
  123. --    state("lookForChair")
  124. --        print("lookForChair");
  125. --    
  126. --        onEnter(function(msg)
  127. --                -- find a chair to eat
  128. --                local boardgame = retrieveStateObject("boardgame");
  129. --
  130. --                local table, tableActionPointName, chair = getNextFreeChairByTable(getParent());
  131. --                if (chair) then
  132. --                    
  133. --                    -- go to chair
  134. --                    local actionPoint = getParent().getClosestFreeActionPoint(getParent(), chair, {"sit1", "sit2"});
  135. --                    if (actionPoint) then
  136. --                    
  137. --                        print("free chair found , ap:" .. actionPoint.getName());
  138. --                
  139. --                        
  140. --                        if (walkToActionPoint(actionPoint)) then
  141. --                        
  142. --                                                        
  143. --                            exitStateMachine();
  144. --                            storeStateObject("chair", chair);
  145. --                            storeStateObject("table", table);
  146. --                            storeStateObject("boardgame", boardgame);
  147. --                            storeStateObject("tableObject", boardgame);
  148. --                            storeData("tableActionPointName", tableActionPointName);
  149. --                            storeData("chairActionPointName", actionPoint.getName());
  150. --                        
  151. --                        
  152. --                            queueStateMachine("playByTableChar.sitDownWithGame", this);
  153. --                            
  154. --                            local hso = getParent().handSO;
  155. --                            hso.stopPose();
  156. --                                                        
  157. --                            local mirror = (actionPoint.getName() == "sit2");
  158. --                            print("actionPoint.getName(): ", actionPoint.getName()); 
  159. --                            print("mirror: ", mirror);
  160. --                            hso.setPose("leftHandHold", mirror);
  161. --                            
  162. --                            
  163. --                            if (mirror) then
  164. --                                print("switch hands");
  165. --                                -- switch hands
  166. --                                getParent().detachLeftObjectHolder();
  167. --                                getParent().attachRightObjectHolder(boardgame);                            
  168. --                            --else
  169. --                            --    getParent().attachLeftObjectHolder(boardgame);                            
  170. --                            end
  171. --                            
  172. --                        else
  173. --                            -- no path to chair was found
  174. --                            print("no path to action point");
  175. --                            sendMsgThis("noPlaceToPlay");
  176. --                        end
  177. --                                                
  178. --                    else
  179. --                        print("no free action point");
  180. --                        sendMsgThis("noPlaceToPlay");
  181. --                    end
  182. --                    
  183. --                    --exitStateMachine();                
  184. --                else
  185. --                    print("no free chair");
  186. --                    sendMsgThis("noPlaceToPlay");
  187. --                end
  188. --                
  189. --                
  190. --                
  191. --                
  192. --        
  193. --                
  194. --                            
  195. --                                                        
  196. --        
  197. --        end)
  198. --        
  199. --    onMsg("noPlaceToPlay", function(msg)
  200. --            print("no place to play");
  201. --            -- detach boardgame if attached to left hand
  202. --            getParent().detachLeftObjectHolder();
  203. --            getParent().detachRightObjectHolder();
  204. --            local boardgame = retrieveStateObject("boardgame");
  205. --            if (boardgame) then
  206. --                boardgame.deleteGameObject();
  207. --            end
  208. --            local hso = getParent().handSO;
  209. --            hso.stopPose();
  210. --            
  211. --            getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);            
  212. --            exitStateMachine();
  213. --            sendMsg("emoThink", getParent().walkSO);
  214. --        end)
  215.         
  216.         
  217.  
  218.  
  219.  
  220.  
  221.     state("takeBook")
  222.     
  223.         onEnter(function(msg)
  224.         
  225.             local bookshelf = retrieveStateObject("bookshelf");
  226.             if (bookshelf) then
  227.                 -- bookshelf does exist
  228.                 
  229.                 if exitIfWrongPosition(getParent(), bookshelf, retrieveData("actionPointName")) then return end;                
  230.                 
  231.                 if (getParent().isOneActionPointLocked(bookshelf)) then
  232.                     -- action point is locked
  233.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  234.                     sendMsg("emoThink", getParent().walkSO);
  235.                     exitStateMachine();
  236.                 else
  237.                     getParent().lockActionPoints(bookshelf);
  238.                     startAnimation("takeBook");
  239.                     freeHands(getParent());            
  240.                     sendDelayedMsgThis("grabBook", 1000);
  241.                 end
  242.             else
  243.                 -- bookshelf does not exist anymore
  244.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  245.                 sendMsg("emoThink", getParent().walkSO);
  246.                 exitStateMachine();
  247.             end
  248.             
  249.         end )
  250.     
  251.  
  252.         onMsg("grabBook", function(msg)
  253.             print("create book");
  254.             local book = getParent().loadGameObject("StandardGO","bookClosed");
  255.             if (not book) then
  256.                 print("create bookClosed failed");
  257.             end
  258.             
  259.             storeStateObject("book", book);
  260.             getParent().attachLeftObjectHolder(book);            
  261.             
  262.             
  263.         end)
  264.  
  265.  
  266.         onMsg("end", function(msg)
  267.             if testCancel() then
  268.                 -- detach book if attached to left hand
  269.                 local book = getParent().getLeftHeldObject();
  270.                 if (book) then
  271.                     getParent().detachLeftObjectHolder();
  272.                     book.deleteGameObject();
  273.                 end
  274. --                local hso = getParent().handSO;
  275. --                hso.stopPose();
  276.                 exitStateMachine();
  277.             else            
  278.                 local hso = getParent().handSO;
  279.                 if (not hso) then
  280.                     print("no hands found");
  281.                 else
  282.                     hso.setPose("leftHandHoldLow");
  283.                 end
  284.                 setState("lookForSeat");                
  285.             end
  286.         end )    
  287.         
  288.         onExit(function(msg)
  289.             -- getParent().detachObjectAnimator();
  290.         end)
  291.  
  292.  
  293.  
  294.     state("lookForSeat")
  295.         print("lookForSeat");
  296.     
  297.         onEnter(function(msg)
  298.             -- find a sofa to eat
  299.             local seat, actionPoint = getNextReadSit(getParent());
  300.             if (not seat) then
  301.                 sendMsgThis("noPlaceToRead");
  302.                 return            
  303.             end
  304.             
  305.             local wso = getParent().walkSO;
  306.             if (wso.walkToActionPoint(actionPoint)) then
  307.             
  308.                 -- create state machine contexts
  309.                 local wsoContext = StateMachineContext();
  310.                 --wsoContext.storeStateObject("seat", seat);
  311.                 wsoContext.storeStateObject("book", retrieveStateObject("book"));
  312.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  313.                 wsoContext.storeData("sitState", "readBook");
  314.                 wsoContext.storeData("bookType", retrieveData("bookType", "Novel"));
  315.                 
  316.                 wso.queueStateMachine("sofaChar.sitDown", seat, wsoContext);                
  317.                 exitStateMachine();
  318.             else
  319.                 print("no path found");
  320.                 sendMsgThis("noPlaceToRead");
  321.             end
  322.             
  323.             
  324.             
  325.             
  326.         end)
  327.  
  328.  
  329.     onMsg("noPlaceToRead", function(msg)
  330.             print("no place to read");
  331.             -- detach book if attached to left hand
  332.             local character = getParent();
  333. --            character.detachLeftObjectHolder();
  334. --            character.detachRightObjectHolder();
  335. --            local book = retrieveStateObject("book");
  336. --            if (book) then
  337. --                book.deleteGameObject();
  338. --            end
  339. --            character.handSO.stopPose();
  340.  
  341.             freeHands(getParent());
  342.             
  343.             instantAbort(character, EMOTICON_NOPATH, "emoThink");
  344.             exitStateMachine();
  345.             
  346.             
  347. --            getParent().setEmoticon(EMOTICON_NOSOFA, EMOTICON_DELAY);            
  348. --            exitStateMachine();
  349. --            sendMsg("emoThink", getParent().walkSO);
  350.         end)
  351.  
  352.  
  353.  
  354.     
  355.         
  356. endStateMachine()
  357.