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

  1. -- cleaning floor character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         local hooverRack = getStateObjectFromID(msg.sender);
  7.         storeStateObject("hooverRack", hooverRack);
  8.         
  9.         
  10.         if (hooverRack) then
  11.             -- hooverRack does exist
  12.             
  13.             if exitIfWrongPosition(getParent(), hooverRack, retrieveData("actionPointName")) then return end;    
  14.             
  15.             
  16.             if (getParent().isOneActionPointLocked(hooverRack)) then
  17.                 -- action point is locked
  18.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  19.                 sendMsg("emoThink", getParent().walkSO);
  20.                 freeHands(getParent());
  21.                 exitStateMachine();
  22.             else
  23.                 getParent().lockActionPoints(hooverRack);
  24.             end
  25.         else
  26.             -- guitarRack does not exist anymore
  27.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  28.             sendMsg("emoThink", getParent().walkSO);
  29.             freeHands(getParent());
  30.             exitStateMachine();
  31.         end
  32.         
  33.         
  34.                         
  35.     end )
  36.     
  37.     onExit(function(msg)
  38.     end )
  39.     
  40.     onReturn(function(msg)
  41.         print("cleaning floor character onReturn");
  42.         setState("clean");
  43.     end )
  44.     
  45.     
  46.     state("takeHoover")
  47.     
  48.         onEnter(function(msg)
  49.                     
  50.             local hooverRack = retrieveStateObject("hooverRack");
  51.             local hoover = hooverRack.createGameObject("hoover");
  52.             this.getStateMachineContext(1).storeStateObject("hoover", hoover);
  53.             getParent().attachRightObjectHolder(hooverRack, "hoover");
  54.             
  55.             local cleanFloor = getParent().startActivity("cleanFloor", hooverRack);
  56.             
  57.             hoover.loopSound("hooverLoop");            
  58.  
  59.             setState("findDirt");
  60.             
  61.             
  62.             
  63.         end )
  64.     
  65.         
  66.     
  67.     state("findDirt")
  68.     
  69.         onEnter(function(msg)
  70.         
  71.             print("findDirt onEnter");
  72.             
  73.             local actionPoint = getParent().getNextCleaningPoint(DIRT_DISTANCE);
  74.             
  75.             if (actionPoint) then
  76.                 if (walkToPointImmediate(actionPoint)) then
  77.                     getParent().handSO.setPose("hooverHoldPose");
  78.                     enterStateMachine("subwalk.walk");
  79.                     return
  80.                 end
  81.             end
  82.             
  83.                         
  84.             -- no accessible dirt found
  85.             print("no accessible dirt found");
  86.             setState("stopClean");
  87.             
  88.         end )
  89.         
  90.         
  91.         
  92.         
  93.         
  94.     
  95.     state("clean")
  96.     
  97.         onEnter(function(msg)
  98.             print("clean onEnter   ------------->");
  99.             
  100.             
  101.             if (testCancel()) then
  102.                 print("clean onEnter testCancel() true");
  103.                 setState("stopClean");
  104.             else
  105.                 
  106.                 local hooverRack = retrieveStateObject("hooverRack");
  107.                 local cleanFloor = getParent().createActivity("cleanFloor", hooverRack);
  108.                 local length, scale = getActivityLength(cleanFloor);
  109.                 
  110.                 print(">>>>>>>>>>> length, scale: " .. length .. "," .. scale);
  111.                 
  112.                                 
  113.                 --local length = cleanFloor.getLength(); -- 1666<length<15000
  114.                 --length = ((length-1666)/(15000-1666)); -- 0<length<1 
  115.                 --local radius = 1.5 - (length * 1.25); -- 0.25<radius<1.5 
  116.                 
  117.                 scale = ((scale - 1.0) * HOOVER_RADIUS_BONUS) + 1.0;
  118.                 
  119.                 print(">>>>>>>>>>> scale2:" .. scale);
  120.  
  121.                 local radius = hooverRack.range;
  122.                 radius = radius * scale;
  123.                 
  124.                 print(">>>>>>>>>>> clean radius: " .. radius);
  125.                 
  126.                 getParent().clearDirt(DIRT_DISTANCE, radius);
  127.                 
  128.                 getParent().handSO.stopAnimation(0.0);
  129.                 startAnimation("cleanFloor", false, 1.0, 0.0);
  130.                 
  131.             end
  132.  
  133.         end )
  134.         
  135.         onMsg("stopHandPose", function(msg)
  136.             getParent().handSO.stopPose();
  137.         end )    
  138.         
  139.         
  140.         onExit(function(msg)
  141. --            local hooverRack = retrieveStateObject("hooverRack");
  142. --            getParent().stopActivity("cleanFloor", hooverRack);
  143.             print("clean onExit   <-------------");
  144.         end )
  145.          
  146.         onMsg("end", function(msg)
  147.             if testCancel() then
  148.                 setState("stopClean");
  149.             else
  150.                 if (getParent().getCondition(NEED_TIREDNESS) < 0.1) then
  151.                     getParent().setEmoticon(EMOTICON_SLEEPY, EMOTICON_DELAY);
  152.                     setState("stopClean");
  153.                 else
  154.                     setState("findDirt");
  155.                 end
  156.             end
  157.         end )    
  158.         
  159.         
  160.     state("stopClean")
  161.     
  162.         onEnter(function(msg)
  163.             print("stopClean onEnter");
  164.             local hoover = this.getStateMachineContext(1).retrieveStateObject("hoover", this.getStateObjectServer());
  165.             hoover.stopSound("hooverLoop");        
  166.                 
  167.             freeHands(getParent());
  168.             
  169. --            local hooverRack = retrieveStateObject("hooverRack");
  170. --            if (hooverRack) then
  171. --                getParent().unlockActionPoints(hooverRack);
  172. --                getParent().stopAllActivities(hooverRack);
  173. --                removeStateObject("hooverRack");
  174. --            end
  175.  
  176.             unlockAll("hooverRack");
  177.             
  178.             --hoover.playSound("hooverStop");            
  179.  
  180.             this.getStateMachineContext(1).removeStateObject("hoover");
  181.             
  182.             exitAndGoAway();
  183.             
  184.             getParent().stopAllActivities();
  185.             
  186.         end )
  187.     
  188.         
  189.                 
  190. endStateMachine()
  191.