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

  1. -- toilet character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.     
  6.         print("toilet character state machine onEnter");
  7.         local toilet = getStateObjectFromID(msg.sender);
  8.         storeStateObject("toilet", toilet);
  9.         
  10.         if (toilet) then
  11.             --toilet does exist
  12.             local actionPointName = retrieveData("actionPointName");
  13.             if exitIfWrongPosition(getParent(), toilet, actionPointName) then return end;
  14.  
  15.             if (getParent().isOneActionPointLocked(toilet)) then
  16.                 -- action point is locked
  17.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  18.                 sendMsg("emoThink", getParent().walkSO);
  19.                 exitStateMachine();
  20.             else
  21.                 getParent().lockActionPoints(toilet);                
  22.             end
  23.         else
  24.             -- chair does not exist anymore
  25.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  26.             sendMsg("emoThink", getParent().walkSO);
  27.             exitStateMachine();
  28.         end
  29.         
  30.         freeHands(getParent());
  31.                 
  32.     end )
  33.     
  34.     onExit(function(msg)            
  35.         local toilet = retrieveStateObject("toilet");
  36.         getParent().unlockActionPoints(toilet);
  37.         getParent().stopAllActivities(toilet);
  38.         toilet.setChildEnable("stink", false);
  39.         removeStateObject("toilet");
  40.         getParent().enableBlend(false);            
  41.     end )
  42.     
  43.     -- sit down on toilet
  44.     state("sitDown")
  45.     
  46.         onEnter(function(msg)
  47.         
  48.             local character = getParent();        
  49.             local other, result = getDisturbingChar(character, "showNaked");
  50.             if (other) then
  51.                 exitStateMachine();
  52.                 character.setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  53.                 other.sendMsg("emoShameChar", character.walkSO);        
  54.                 return    
  55.             end;
  56.         
  57.             print("sitDown onEnter");            
  58.             startAnimation("sitdownToilet");
  59.             
  60.             getParent().enableBlend(true);            
  61.         end )
  62.     
  63.         onMsg("end", function(msg)
  64.             if testCancel() then
  65.                 setState("standUp");
  66.             else
  67.                 setState("sit");
  68.             end
  69.         end )    
  70.     
  71.         onMsg("queue", function(msg)
  72.             setState("standUp");
  73.         end )        
  74.     
  75.         onMsg("sitSound", function(msg)
  76.         end )    
  77.         
  78.     -- sit
  79.     state("sit")
  80.     
  81.         onEnter(function(msg)
  82.             print("sitDown onEnter");            
  83.             --actionComplete();
  84.             
  85.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  86.             sendDelayedMsgThis("stink", 5*1000);
  87.             
  88.             local toilet = retrieveStateObject("toilet");
  89.             dirtify(toilet, DIRTIFY_PER_SIT_TOILET);
  90.             
  91.             local sitToilet = getParent().startActivity("sitToilet", toilet);
  92.             local length, scale = getActivityLength(sitToilet);
  93.         
  94.             sendDelayedMsgThis("complete", length);
  95.  
  96.         end )
  97.         
  98.         onExit(function(msg)
  99.             local toilet = retrieveStateObject("toilet");
  100.             getParent().stopActivity("sitToilet", toilet);
  101.         end )
  102.         
  103.         onMsg("stink", function(msg)
  104.             local toilet = retrieveStateObject("toilet");
  105.             toilet.setChildEnable("stink", true);
  106.         end )        
  107.     
  108.         onMsg("complete", function(msg)
  109.             setState("standUp");
  110.         end )        
  111.  
  112.         onMsg("queue", function(msg)
  113.             sendMsgThis("complete");
  114.         end )        
  115.     
  116.         onMsg("testCancel", function(msg)
  117.             -- if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
  118.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  119.             --if testCancel() or (this.getParent().getActivityQueueCount() > 1) then
  120.                 sendMsgThis("complete");
  121.             else
  122.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  123.             end
  124.         end )
  125.         
  126.     -- stand up from toilet
  127.     state("standUp")
  128.     
  129.         onEnter(function(msg)
  130.             startAnimation("standupToilet");
  131.             sendDelayedMsgThis("flushSound", 4200);
  132.             
  133.         end )
  134.         
  135.         onMsg("flushSound", function(msg)
  136.             getParent().playSound("closetFlush");
  137.         end )
  138.     
  139.         onMsg("end", function(msg)
  140.         
  141.             local toilet = retrieveStateObject("toilet");
  142.             toilet.setChildEnable("stink", false);            
  143.             getParent().enableBlend(false);    
  144.                     
  145.             exitAndGoAway();
  146.         end )
  147.         
  148.                 
  149.  
  150.  
  151.     state("cleanStart")
  152.     
  153.         onEnter(function(msg)
  154.             -- grab sponge
  155.             local sponge = getParent().loadGameObject("StandardGO","sponge");
  156.             getParent().attachRightObjectHolder(sponge);
  157.             storeStateObject("sponge", sponge);
  158.             startAnimation("cleanClosetStart");            
  159.             sendDelayedMsgThis("cleanSound", 900);
  160.         end )
  161.         
  162.         onMsg("cleanSound", function(msg)
  163.             local toilet = retrieveStateObject("toilet");
  164.             toilet.playSound("cleanToiletStart", 0.25);
  165.         end )    
  166.     
  167.         onMsg("end", function(msg)
  168.             if (testCancel()) then
  169.                 exitStateMachine();
  170.             else
  171.                 setState("clean");
  172.             end
  173.         end )    
  174.  
  175.         
  176.     -- clean up 
  177.     state("clean")
  178.     
  179.         onEnter(function(msg)
  180.             local toilet = retrieveStateObject("toilet");
  181.             local clean = getParent().startActivity("clean", toilet);
  182.             local length, scale = getActivityLength(clean);
  183.             storeData("scale", scale);
  184.                         
  185.             startAnimation("cleanClosetLoop", false, scale);
  186.             toilet.loopSound("cleanToiletLoop", 0.25);
  187.             
  188.             --sendDelayedMsgThis("complete", length);
  189.             --this.actionComplete();
  190.         end )
  191.         
  192.         onExit(function(msg)
  193.             local toilet = retrieveStateObject("toilet");
  194.             toilet.stopSound("cleanToiletLoop");
  195.         end )    
  196.  
  197.  
  198.         onMsg("complete", function(msg)
  199.             getParent().stopActivity("clean", retrieveStateObject("toilet"));
  200.             setState("cleanEnd");
  201.         end )    
  202.     
  203.         onMsg("end", function(msg)
  204.             local toilet = retrieveStateObject("toilet");
  205.             local dirt = toilet.getDirtiness();
  206.             if (testCancel() or dirt<0.01) then
  207.                 sendMsgThis("complete");
  208.             else
  209.                 local scale = retrieveData("scale");
  210.                 startAnimation("cleanClosetLoop", false, scale, 500);
  211.                 --toilet.playSound("cleanToilet");
  212.                 clean(toilet, CLEAN_PER_LOOP);            
  213.             end
  214.         end )    
  215.                     
  216.         
  217.     state("cleanEnd")
  218.     
  219.         onEnter(function(msg)
  220.  
  221.             startAnimation("cleanClosetEnd");            
  222.             sendDelayedMsgThis("cleanSound", 600);
  223.             sendDelayedMsgThis("cleanSound", 1650);
  224.         end )
  225.     
  226.         onMsg("cleanSound", function(msg)
  227.             local toilet = retrieveStateObject("toilet");
  228.             toilet.playSound("cleanToiletStart", 0.25);
  229.         end )    
  230.  
  231.         onMsg("end", function(msg)
  232.             -- remove sponge
  233.             local sponge = getParent().getRightHeldObject()
  234.             getParent().detachRightObjectHolder();
  235.             if (sponge) then sponge.deleteGameObject(); end
  236.             
  237.             if (not testCancel()) then queueNextClean(getParent()) end;
  238.             exitAndGoAway();
  239.         end )    
  240.         
  241.     
  242. endStateMachine()