home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
ovenChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
9KB
|
357 lines
-- oven character state machine
beginStateMachine()
onEnter(function(msg)
local oven = getStateObjectFromID(msg.sender);
storeStateObject("oven", oven);
-- local tablet = retrieveStateObject("tablet");
-- if (tablet) then
-- tablet.deleteGameObject();
-- end
-- getParent().detachRightObjectHolder();
-- getParent().detachLeftObjectHolder();
--
-- -- we need free hands for cooking
-- local hands = getParent().handSO;
-- if (not hands) then
-- print("no hands found");
-- else
-- hands.stopPose();
-- end
if (oven) then
-- oven does exist
local actionPointName = retrieveData("actionPointName");
if exitIfWrongPosition(getParent(), oven, actionPointName) then return end;
if (getParent().isOneActionPointLocked(oven)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(oven);
end
else
-- oven does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
end )
onExit(function(msg)
local pot = retrieveStateObject("pot");
if (pot) then
pot.deleteGameObject();
removeStateObject("pot");
end;
local spoon = retrieveStateObject("spoon");
if (spoon) then
spoon.deleteGameObject();
removeStateObject("spoon");
end;
local oven = retrieveStateObject("oven");
--oven.setChildEnable("pot", false);
if (oven) then
oven.setChildEnable("spoon", false);
local damp = oven.findChildGO("damp");
damp.setEmitRate(0.0);
oven.setChildEnable("damp", false);
-- getParent().unlockActionPoints(oven);
-- removeStateObject("oven");
end;
unlockAll("oven");
getParent().stopAllActivities();
end )
-- open the oven
state("open")
onEnter(function(msg)
local oven = retrieveStateObject("oven");
-- create the cracker box
local pot = oven.createGameObject("pot");
storeStateObject("pot", pot);
local spoon = oven.createGameObject("spoon");
storeStateObject("spoon", spoon);
-- start to open the oven
startAnimation("openOven");
oven.startAnimation("ovenDoorOpen");
-- send a delayed message for open sound
sendDelayedMsgThis("openSound", 0);
-- send a delayed message for attach
sendDelayedMsgThis("grabPot", 3000);
sendDelayedMsgThis("dropPot", 4880);
-- send a delayed message for close sound
--sendDelayedMsgThis("closeSound", 6000);
end )
onMsg("openSound", function(msg)
local oven = retrieveStateObject("oven");
oven.playSound("openOven");
end)
onMsg("grabPot", function(msg)
-- attach pot to left hand of character
local oven = retrieveStateObject("oven");
local pot = retrieveStateObject("pot");
print("setChildEnable");
oven.setChildEnable("pot", true);
getParent().attachLeftObjectHolder(pot);
end)
onMsg("dropPot", function(msg)
local oven = retrieveStateObject("oven");
getParent().detachLeftObjectHolder();
oven.setChildEnable("spoon", true);
end)
onMsg("closeSound", function(msg)
local oven = retrieveStateObject("oven");
oven.playSound("fridgeClose");
end)
onMsg("end", function(msg)
if testCancel() then
-- freeHands(getParent());
-- -- remove the pot
-- local pot = retrieveStateObject("pot");
-- if (pot) then
-- getParent().detachRightObjectHolder();
-- pot.deleteGameObject();
-- end
-- -- remove the spoon
-- local spoon = getParent().getRightHeldObject();
-- if (spoon) then
-- getParent().detachRightObjectHolder();
-- spoon.deleteGameObject();
-- end
freeHands(getParent());
local oven = retrieveStateObject("oven");
oven.setChildEnable("spoon", false);
oven.setChildEnable("pot", false);
exitStateMachine();
else
setState("cookTaste");
end
end )
onExit(function(msg)
-- getParent().detachObjectAnimator();
end)
state("cookTaste")
onEnter(function(msg)
local oven = retrieveStateObject("oven");
local cook = getParent().startActivity("cook", oven)
local length, scale = getActivityLength(cook);
storeData("scale", scale);
-- animation
startAnimation("cookTaste", false, scale);
sendDelayedMsgThis("grabSpoon", 800/scale);
-- sounds
oven.playSound("cookingFadein");
sendDelayedMsgThis("cookingLoopSound", 1360/scale);
sendDelayedMsgThis("completeCooking", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
sendDelayedMsgThis("moreDamp", 1000);
oven.setChildEnable("damp", true);
end )
onExit(function(msg)
local oven = retrieveStateObject("oven");
getParent().stopAllActivities(oven);
local damp = oven.findChildGO("damp");
damp.setEmitRate(0.0);
oven.setChildEnable("damp", FALSE);
createTrash(0.2);
end )
onMsg("grabSpoon", function(msg)
-- attach spoon to right hand of character
local oven = retrieveStateObject("oven");
oven.setChildEnable("spoon", true);
getParent().attachRightObjectHolder(oven, "spoon");
sendDelayedMsgThis("dropSpoon", 2960/retrieveData("scale"));
end)
onMsg("dropSpoon", function(msg)
getParent().detachRightObjectHolder();
end)
onMsg("moreDamp", function(msg)
local oven = retrieveStateObject("oven");
local damp = oven.findChildGO("damp");
local rate = damp.getEmitRate();
if (rate < MAX_OVEN_DAMP_RATE) then
damp.setEmitRate(rate + (0.1 * MAX_OVEN_DAMP_RATE));
sendDelayedMsgThis("moreDamp", 1000);
end;
end)
onMsg("cookingLoopSound", function(msg)
print("cookingLoopSound");
local oven = retrieveStateObject("oven");
oven.loopSound("cookingLoop");
end)
onMsg("cancelCooking", function(msg)
print("cancelCooking");
-- local pot = getParent().getLeftHeldObject();
-- if (pot) then
-- getParent().detachLeftObjectHolder();
-- pot.deleteGameObject();
-- end
-- -- remove the spoon
-- local spoon = getParent().getRightHeldObject();
-- if (spoon) then
-- getParent().detachRightObjectHolder();
-- spoon.deleteGameObject();
-- end
freeHands(getParent());
local oven = retrieveStateObject("oven");
oven.setChildEnable("spoon", false);
oven.setChildEnable("pot", false);
oven.stopSound("cookingLoop");
oven.playSound("cookingFadeout");
exitAndGoAway();
end)
onMsg("completeCooking", function(msg)
print("completeCooking");
local oven = retrieveStateObject("oven");
freeHands(getParent());
--oven.setChildEnable("pot", false);
-- leave the cooked food on the oven
sendDelayedMsg("hidePot", oven, OVEN_FOOD_REMAIN_TIME);
oven.setChildEnable("spoon", false);
-- -- attach tablet
-- print("create tablet");
-- local tablet = getParent().loadGameObject("StandardGO", "tabletCooked");
-- --storeStateObject("tablet", tablet);
-- getParent().handSO.setPose("leftHandHold");
-- getParent().attachLeftObjectHolder(tablet);
--
-- oven.stopSound("cookingLoop");
-- oven.playSound("cookingFadeout");
--
-- getParent().replaceQueueEntry(0, "pm_eat");
--
-- local wsoContext = StateMachineContext();
-- wsoContext.storeStateObject("tablet", tablet);
-- wsoContext.storeStateObject("tableObject", tablet);
-- wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
-- queueStateMachine("tableChairChar.findChair", this, wsoContext);
-- exitStateMachine();
getParent().pushCommand("pm_takeFood", "takeFood", oven, "");
exitStateMachine();
end)
onMsg("testCancel", function(msg)
if testCancel() then
sendMsgThis("cancelCooking");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("cancelCooking");
else
-- animation
local scale = retrieveData("scale");
startAnimation("cookTaste", false, scale);
sendDelayedMsgThis("grabSpoon", 800/scale);
end
end )
state("takeFood")
onEnter(function(msg)
local oven = retrieveStateObject("oven");
if (oven.getChildEnable("pot")) then
-- attach tablet
print("create tablet");
local tablet = getParent().loadGameObject("StandardGO", "tabletCooked");
getParent().handSO.setPose("leftHandHold");
getParent().attachLeftObjectHolder(tablet);
getParent().replaceQueueEntry(0, "pm_eat");
-- find place to eat
local wsoContext = StateMachineContext();
wsoContext.storeStateObject("tablet", tablet);
wsoContext.storeStateObject("tableObject", tablet);
wsoContext.storeData("chairCommand", "eatByTableChar.sitDown");
wsoContext.storeData("checkPartnerChair", true);
queueStateMachine("tableChairChar.findChair", this, wsoContext);
exitStateMachine();
else
exitAndGoAway();
end
end)
endStateMachine()