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

  1. -- door state machine
  2.  
  3. DOORBEHAVIOR = "doorBehaviour";
  4. DOORBEHAVIOR_AUTO = nil;
  5. DOORBEHAVIOR_ALWAYS_OPEN = "open";
  6. DOORBEHAVIOR_ALWAYS_CLOSED = "closed";
  7.  
  8. beginStateMachine()
  9.  
  10.     onEnter(function(msg)    
  11.         this.getGameObjectServer().scanApartment();
  12.         if (isBathroomDoor(this)) then
  13.             setState("closed")
  14.         else
  15.             setState("openLeft")
  16.         end
  17.         
  18.         this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_AUTO);
  19.     end )
  20.  
  21.     state("closed")
  22.         onEnter(function(msg)
  23.             setWalkability(0);
  24.         end )
  25.         
  26.         onMsg("openDoorLeft", function(msg)
  27.         
  28.             if (msg.sender == NO_OBJECT_ID) then
  29.                 this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_OPEN);
  30.             end
  31.             
  32.             setState("openLeft");
  33.         end )
  34.         
  35.         onMsg("openDoorRight", function(msg)
  36.         
  37.             if (msg.sender == NO_OBJECT_ID) then
  38.                 this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_OPEN);
  39.             end
  40.             
  41.             setState("openRight");
  42.         end )
  43.         
  44.         onMsg("buildMenu", function(msg)
  45.             -- build the pie menu
  46.             clearPieMenu();
  47.             local button ;
  48.             button = addPieMenuButton("pm_open", "openDoorLeft");
  49.             button.addDescription(USERACTION, "true");
  50.         end )
  51.     
  52.     state("openLeft")
  53.         
  54.         onEnter(function(msg)
  55.             startAnimation("doorOpenLeft");
  56.             setWalkability(1)
  57.             playSound("doorOpenClose");
  58.         end )
  59.         
  60.         onExit(function(msg)
  61.             startAnimation("doorCloseLeft");
  62.         end )
  63.         
  64.         onMsg("closeDoorLeft", function(msg)
  65.         
  66.             if (msg.sender == NO_OBJECT_ID) then
  67.                 this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
  68.             end
  69.             
  70.             local doorBehavior = this.retrieveData(DOORBEHAVIOR);
  71.             
  72.             if ((msg.sender == NO_OBJECT_ID)
  73.             or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
  74.             or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
  75.                 setState("closed");
  76.             end
  77.         end )
  78.         
  79.         onMsg("closeDoorRight", function(msg)
  80.         
  81.             if (msg.sender == NO_OBJECT_ID) then
  82.                 this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
  83.             end
  84.             
  85.             local doorBehavior = this.retrieveData(DOORBEHAVIOR);
  86.             
  87.             if ((msg.sender == NO_OBJECT_ID)
  88.             or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
  89.             or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
  90.                 setState("closed");
  91.             end
  92.         end )
  93.         
  94.         onMsg("buildMenu", function(msg)
  95.             -- build the pie menu
  96.             clearPieMenu();
  97.             local button ;
  98.             button = addPieMenuButton("pm_close", "closeDoorLeft");
  99.             button.addDescription(USERACTION, "true");
  100.         end )
  101.         
  102.     state("openRight")
  103.     
  104.         onEnter(function(msg)
  105.             startAnimation("doorOpenRight");
  106.             setWalkability(2)
  107.             playSound("doorOpenClose");
  108.         end )
  109.         
  110.         onExit(function(msg)
  111.             startAnimation("doorCloseRight");
  112.         end )
  113.         
  114.         onMsg("closeDoorLeft", function(msg)
  115.         
  116.             if (msg.sender == NO_OBJECT_ID) then
  117.                 this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
  118.             end
  119.             
  120.             local doorBehavior = this.retrieveData(DOORBEHAVIOR);
  121.             
  122.             if ((msg.sender == NO_OBJECT_ID)
  123.             or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
  124.             or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
  125.                 setState("closed");
  126.             end
  127.         end )
  128.         
  129.         onMsg("closeDoorRight", function(msg)
  130.         
  131.             if (msg.sender == NO_OBJECT_ID) then
  132.                 this.storeData(DOORBEHAVIOR, DOORBEHAVIOR_ALWAYS_CLOSED);
  133.             end
  134.             
  135.             local doorBehavior = this.retrieveData(DOORBEHAVIOR);
  136.  
  137.             if ((msg.sender == NO_OBJECT_ID)
  138.             or ((doorBehavior == DOORBEHAVIOR_AUTO) and isBathroomDoor(this))
  139.             or (doorBehavior == DOORBEHAVIOR_ALWAYS_CLOSED)) then
  140.                 setState("closed");
  141.             end
  142.         end )
  143.         
  144.         onMsg("buildMenu", function(msg)
  145.             -- build the pie menu
  146.             clearPieMenu();
  147.             local button ;
  148.             button = addPieMenuButton("pm_close", "closeDoorRight");
  149.             button.addDescription(USERACTION, "true");
  150.         end )
  151.     
  152. endStateMachine()
  153.