home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
sofaChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
25KB
|
950 lines
-- sofa character state machine
beginStateMachine()
onEnter(function(msg)
-- local sofa = retrieveStateObject("sofa");
-- if (not sofa) then
-- -- no sofa was stored
-- sofa = getStateObjectFromID(msg.sender);
-- storeStateObject("sofa", sofa);
-- end
print("onEnter sofaChar");
local sofa = getStoredOrSender({"sofa", "seat"}, msg);
if (not sofa) then
-- sofa does not exist anymore
print("onEnter sofaChar sofa does not exist anymore");
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
print("onEnter sofaChar sofa does exist");
storeStateObject("sofa", sofa);
end
--freeHands(getParent());
end )
onExit(function(msg)
print("sofaChar EXIT");
-- local sofa = retrieveStateObject("sofa");
-- if (sofa) then
-- getParent().unlockActionPoints(sofa);
-- getParent().stopAllActivities(sofa);
-- removeStateObject("sofa");
-- end
unlockAll("sofa");
local partner = retrieveStateObject("partner");
if (partner) then
getParent().unlockActionPoints(partner.getParent());
getParent().stopAllActivities(partner.getParent());
removeStateObject("partner");
end;
getParent().stopAllActivities();
end )
-- -- test if we need to cancel
-- onMsg("test", function(msg)
-- if testCancel() or testCancelSleeping() then
-- setState("getup");
-- else
-- sendDelayedMsgThis("test", 1000);
-- end
-- end )
onMsg("waitIntimate", function(msg)
local sofa = retrieveStateObject("sofa");
getParent().queueCommand("pm_getIntimateSofa", "waitIntimate", sofa, "");
end )
-- sit down on sofa
state("sitDown")
onEnter(function(msg)
local sofa = retrieveStateObject("sofa");
local actionPointName = retrieveData("actionPointName");
if exitIfWrongPosition(getParent(), sofa, actionPointName) then return end;
if (getParent().isActionPointLocked(sofa, actionPointName)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoint(sofa, actionPointName);
if (retrieveData("sitState") == "playGuitar") then
getParent().handSO.stopAnimation(0.0);
startAnimation("playGuitarSitdown", false, 1.0, 0.0);
else
setPose("sitdownArmchair");
end
--sofa.playSound("Sofa setzen");
sendDelayedMsgThis("sitSound", 1900);
end
end )
onMsg("sitSound", function(msg)
local sofa = retrieveStateObject("sofa");
sofa.playSound("Sofa setzen");
end )
onMsg("end", function(msg)
if testCancel() then
setState("standUp");
else
--setState("sit");
setState(retrieveData("sitState", "sit"));
end
end )
-----------------------------------------------------------------------------------------------------
-- -- sit down on sofa
-- state("sitDownToWatchTV")
--
-- onEnter(function(msg)
-- print("onEnter sitDownToWatchTV");
--
-- local sofa = retrieveStateObject("sofa");
--
-- local actionPointName = retrieveData("actionPointName");
-- if (getParent().isActionPointLocked(sofa, actionPointName)) then
-- -- action point is locked
-- getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", getParent().walkSO);
-- exitStateMachine();
-- else
-- getParent().lockActionPoint(sofa, actionPointName);
-- setPose("sitdownArmchair");
-- sofa.playSound("Sofa setzen");
-- end
-- end )
--
-- onMsg("end", function(msg)
-- if testCancel() then
-- setState("standUp");
-- else
-- setState("watchTV");
-- end
-- end )
----------------------------------------------------------------------------------------
state("watchTV")
onEnter(function(msg)
print("onEnter sofaChar.watchTV");
startAnimation(genderize(getParent(), "sitPoseArmchair"));
local tv = retrieveStateObject("tv");
local channel = retrieveData("channel");
if (not tv) then
setState("watchTVstop");
return
end
print("start watch " .. channel);
local watch = getParent().startActivity("watch" .. channel, tv);
local length, scale = getActivityLength(watch);
storeData("scale", scale);
sendDelayedMsgThis("complete", length);
setTopQueueEntry(getParent(), "pm_watch" .. channel)
local sofa = retrieveStateObject("sofa");
getParent().startActivity("sit", sofa);
sendDelayedMsgThis("act", 5000);
-- actionComplete();
local remoteControl = getParent().loadGameObject("StandardGO","remoteControl");
if (not remoteControl) then
print("remoteControl not loaded");
else
storeStateObject("remoteControl", remoteControl);
getParent().attachRightObjectHolder(remoteControl);
sendMsgThis("switch", channel);
end
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end )
onExit(function(msg)
-- local tv = retrieveStateObject("tv");
-- getParent().stopAllActivities(tv);
-- sendMsg("stopWatch", tv);
print("onExit sofaChar.watchTV");
local tv = retrieveStateObject("tv");
if (tv) then
getParent().unlockActionPoints(tv);
getParent().stopAllActivities(tv);
removeStateObject("tv");
sendMsg("stopWatch", tv);
end
local hands = getParent().handSO;
hands.stopAnimation();
getParent().detachRightObjectHolder();
local remoteControl = retrieveStateObject("remoteControl");
if (remoteControl) then remoteControl.deleteGameObject(); end
end )
onMsg("switch", function(msg)
print("onMsg switch " .. msg.data);
local tv = retrieveStateObject("tv");
local currentChannel = tv.getState();
-- if (msg.data == currentChannel) then
-- print("no need to swtich to " .. msg.data);
-- return
-- end;
local hands = getParent().handSO;
hands.startAnimation("remoteControl");
sendDelayedMsgThis("tvSwitch", 500, msg.data);
end )
onMsg("tvSwitch", function(msg)
print("onMsg tvSwitch " .. msg.data);
local tv = retrieveStateObject("tv");
sendMsg("switch", tv, msg.data);
--getParent().replaceQueueEntry(0, "pm_watch" .. msg.data);
end )
onMsg("tvOff", function(msg)
print("onMsg tvOff");
setState("watchTVstop");
end )
onMsg("tvSwitched", function(msg)
print("onMsg tvSwitched");
--getParent().replaceQueueEntry(0, "pm_watch" .. msg.data);
setTopQueueEntry(getParent(), "pm_watch" .. msg.data)
local tv = retrieveStateObject("tv");
tv.lock(); --prevent breaking on switch
getParent().stopAllActivities(tv);
getParent().startActivity("watch" .. msg.data, tv);
tv.unlock(); --prevent breaking on switch
end )
onMsg("complete", function(msg)
setState("watchTVstop");
end )
-- onMsg("queue", function(msg)
-- exitStateMachine();
-- end )
onMsg("act", function(msg)
doSomething();
sendDelayedMsgThis("act", 5000);
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
setState("watchTVstop");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
state("watchTVstop")
onEnter(function(msg)
local sofa = retrieveStateObject("sofa");
queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
setState("standUp");
end )
----------------------------------------------------------------------------------------
state("readBook")
onEnter(function(msg)
startAnimation(genderize(getParent(), "sitPoseArmchair"));
-- remove closed book
getParent().detachLeftObjectHolder();
local book = retrieveStateObject("book");
if (book) then book.deleteGameObject(); end
-- load open book
book = getParent().loadGameObject("StandardGO","bookOpen");
if (not book) then
print("create bookOpen failed");
end
storeStateObject("book", book);
getParent().attachLeftObjectHolder(book);
local hands = getParent().handSO;
hands.stopAnimation();
startAnimation("readBookPage");
local sofa = retrieveStateObject("sofa");
getParent().startActivity("sit", sofa);
print(" read activity " .. retrieveData("bookType", " UNKONWN "));
local readBook = getParent().startActivity("read" .. retrieveData("bookType", "Novel"), book);
local length, scale = getActivityLength(readBook);
storeData("length", length);
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("turnPage", 3000);
-- this.actionComplete();
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end )
onExit(function(msg)
local book = retrieveStateObject("book");
if (book) then
getParent().stopAllActivities(book);
end
freeHands(getParent());
end )
onMsg("turnPage", function(msg)
startAnimation("readBookPage");
sendDelayedMsgThis("turnPage", random(5000, 20000));
end )
onMsg("end", function(msg)
if (testCancel()) then
setState("readBookStop");
end
end )
-- onMsg("queue", function(msg)
-- setState("readBookStop");
-- end )
onMsg("complete", function(msg)
setState("readBookStop");
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
setState("readBookStop");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
state("readBookStop")
onEnter(function(msg)
local sofa = retrieveStateObject("sofa");
queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
setState("standUp");
end )
----------------------------------------------------------------------------------------
state("playGuitar")
onEnter(function(msg)
local guitarRack = retrieveStateObject("guitarRack");
local play = getParent().startActivity("playGuitar", guitarRack);
local length, scale = getActivityLength(play);
storeData("scale", scale);
local sofa = retrieveStateObject("sofa");
getParent().startActivity("sit", sofa);
startAnimation("playGuitarLoop");
sendDelayedMsgThis("stopPlaying", length);
--this.actionComplete();
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
getParent().loopSound("guitar");
end )
onExit(function(msg)
getParent().stopSound("guitar");
freeHands(getParent());
local guitarRack = retrieveStateObject("guitarRack");
if (guitarRack) then
guitarRack.setChildEnable("guitar", true)
getParent().stopAllActivities(guitarRack);
getParent().unlockActionPoints(guitarRack);
removeStateObject("guitarRack");
end
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("stopPlaying");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("stopPlaying");
else
startAnimation("playGuitarLoop");
end
end )
onMsg("stopPlaying", function(msg)
setState("playGuitarStop");
end )
state("playGuitarStop")
onEnter(function(msg)
local sofa = retrieveStateObject("sofa");
queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
setState("standUp");
end )
-- onReturn(function(msg)
-- print("onReturn sitDownToWatchTV");
-- setState("standUp");
-- end )
-- state("watchTV")
--
-- onEnter(function(msg)
-- print("onEnter watchTV");
-- enterStateMachine("tvChar.watch");
-- end )
--
--
-- onReturn(function(msg)
-- local sofa = retrieveStateObject("sofa");
-- --getParent().queueCommand("pm_sitdown", "sit", sofa, "");
-- --setTopQueueEntry(getParent(), "pm_sitdown", true);
-- queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
-- setState("standUp");
--
-- end )
-- -- sit on sofa
-- state("sit")
--
-- onEnter(function(msg)
-- startAnimation("sitPoseArmchair");
--
-- local sofa = retrieveStateObject("sofa");
-- local sit = getParent().startActivity("sit", sofa);
--
-- sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
--
-- end )
--
-- onMsg("queue", function(msg)
-- setState("standUp");
-- end )
--
-- onMsg("act", function(msg)
-- doSomething();
-- sendDelayedMsgThis("act", 5000);
-- end )
--
-- onMsg("end", function(msg)
-- actionComplete();
-- end )
--
-- onMsg("testCancel", function(msg)
-- if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
-- setState("standUp");
-- else
-- sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
-- end
-- end )
state("sit")
onEnter(function(msg)
startAnimation(genderize(getParent(), "sitPoseArmchair"), false, 1.0, 1000);
--setTopQueueEntry(getParent(), "pm_sitdown");
end )
onMsg("end", function(msg)
if testCancel() then
setState("sitStop");
else
local sofa = retrieveStateObject("sofa");
local sit = getParent().startActivity("sit", sofa);
local length = sit.getLength();
storeData("length", length);
sendDelayedMsgThis("act", length);
actionComplete();
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("queue", function(msg)
setState("sitStop");
end )
onMsg("act", function(msg)
doSomething();
sendDelayedMsgThis("act", 5000);
end )
onMsg("testCancel", function(msg)
if testCancel() or (this.getParent().getActivityQueueCount() > 1) or (not this.getParent().getCurrentActivityGain()) then
setState("sitStop");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
state("sitStop")
onEnter(function(msg)
startAnimation(genderize(getParent(), "sitPoseArmchair"), false, -1.0);
local sofa = retrieveStateObject("sofa");
--sofa.playSound("Sofa setzen");
end )
onMsg("end", function(msg)
setState("standUp");
end )
-- stand up from sofa
state("standUp")
onEnter(function(msg)
local sofa = retrieveStateObject("sofa");
local character = getParent();
-- drop stuff like remote control or book
freeHands(character);
-- check if we schould really stand up
if checkShortcut(sofa, {"sit", "waitIntimate"}, {"sit", "waitIntimate"}) then return end;
if (retrieveData("actionPointName") == "sit2" and not character.isOneActionPointLocked(sofa)) then
if checkShortcut(sofa, {"nap"}, {"layDownFromSit"}) then return end;
end;
if checkWatchShortcut(sofa, {"watch"}, {"watchTV"}, {"watchShortcut"}) then
return
end;
local others = getOtherUsers(character, sofa, "sit");
local other = others[1];
if (other) then
local possible, mirrorAnims = getSofaIteractionInfo(character, other);
if (possible) then
if checkShortcut(other, {"getIntimateSofa"}, {"waitIntimate"}, {"getIntimateSofaShortcut"}) then
return
end
end
else
print("standUp check shortcuts; no OtherUsers found");
end
-- stand up
startAnimation("standupArmchair");
getParent().stopAllActivities(sofa);
sendDelayedMsgThis("sitSound", 400);
end )
onMsg("sitSound", function(msg)
local sofa = retrieveStateObject("sofa");
sofa.playSound("Sofa setzen");
end )
onMsg("end", function(msg)
flipPoseDirection();
exitAndGoAway();
end )
-- lay down on sofa: sit down first
state("layDown")
onEnter(function(msg)
setPose("sitdownArmchair");
local sofa = retrieveStateObject("sofa");
if (getParent().isOneActionPointLocked(sofa)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(sofa);
end
end )
onMsg("end", function(msg)
if testCancel() then
setState("standUp")
else
setState("layDownFromSit");
end
end )
-- lay down on sofa from sit
state("layDownFromSit")
onEnter(function(msg)
startAnimation("laydownSofa");
local sofa = retrieveStateObject("sofa");
getParent().lockActionPoints(sofa);
end )
onMsg("end", function(msg)
if testCancel() then
setState("getup");
else
local sofa = retrieveStateObject("sofa");
local nap = getParent().startActivity("nap", sofa);
-- local length, scale = getActivityLength(nap);
local length = nap.getLength();
--getParent().setMimic("eyeClose");
sendMsg("eyeClose", getParent().mimicSO);
-- character now sleeping
getParent().setSleeping(true);
-- sendDelayedMsgThis("test", 1000);
-- sendDelayedMsgThis("act", 5000);
--actionComplete();
sendDelayedMsgThis("getUp", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("queue", function(msg)
setState("getup");
end )
onMsg("getUp", function(msg)
setState("getup");
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
setState("getup");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("act", function(msg)
sendDelayedMsgThis("act", 5000);
end )
-- stand up from laying down
state("getup")
onEnter(function(msg)
local sofa = retrieveStateObject("sofa");
startAnimation("getupSofa");
-- character not sleeping anymore
getParent().setSleeping(false);
getParent().sendMsgThis("smile");
getParent().stopAllActivities(sofa);
sendMsg("neutral", getParent().mimicSO);
end )
onMsg("end", function(msg)
local sofa = retrieveStateObject("sofa");
getParent().unlockActionPoints(sofa);
getParent().lockActionPoint(sofa, "sit2");
setState("standUp");
end )
-- -- sit down on sofa to get initmate
-- state("sitDownToGetIntimate")
--
-- onEnter(function(msg)
-- local sofa = retrieveStateObject("sofa");
--
-- local actionPointName = retrieveData("actionPointName");
-- print("sitDownToGetIntimate");
-- if (getParent().isActionPointLocked(sofa, actionPointName)) then
-- -- action point is locked
-- getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- sendMsg("emoThink", getParent().walkSO);
-- exitStateMachine();
-- else
-- getParent().lockActionPoint(sofa, actionPointName);
-- setPose("sitdownArmchair");
-- sofa.playSound("Sofa setzen");
-- end
-- end )
--
-- onMsg("end", function(msg)
-- if (testCancel()) then
-- setState("getup");
-- else
-- local sofa = retrieveStateObject("sofa");
-- getParent().startActivity("sit", sofa);
-- setState("waitIntimate");
-- end
-- end )
---------------------------------------------------------------------------------------------------
-- wait intimate
state("waitIntimate")
onEnter(function(msg)
print("-- sofa waitIntimate --");
-- startAnimation("sleepingTurnToLeftSide", retrieveData("mirrorAnims"));
sendDelayedMsgThis("sendReadyMsg", 1000);
sendDelayedMsgThis("stopWaiting", 30000);
sendMsg("neutral", getParent().mimicSO);
getParent().setEmoticon("");
end )
onMsg("sendReadyMsg", function(msg)
if testCancel() then
sendMsgThis("stopWaiting");
else
local partner = retrieveStateObject("partner");
if (not partner) then
print("sendReadyMsg no partner found");
sendMsgThis("stopWaiting");
return
end
sendMsg("partnerReady", partner);
sendDelayedMsgThis("sendReadyMsg", 1000);
end
end )
onMsg("stopWaiting", function(msg)
local sofa = retrieveStateObject("sofa");
queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
setState("standUp");
--setState("sit");
end )
onMsg("partnerReady", function(msg)
setState("sitCloser");
local partner = retrieveStateObject("partner");
partner.setState("sitCloser");
end )
onMsg("partnerCancel", function(msg)
setState("sit");
end )
onMsg("end", function(msg)
if testCancel() then
sendMsgThis("stopWaiting");
else
actionComplete();
end
end )
state("sitCloser")
onEnter(function(msg)
print("-- sitCloser --");
local activePart = retrieveData("activePart");
getParent().replaceQueueEntry(0, "pm_getIntimateSofa");
startAnimation(genderize(getParent(), "sofaSitClose"), retrieveData("mirrorAnims"));
end )
onMsg("partnerCancel", function(msg)
setState("sitCloserStop");
end )
onMsg("end", function(msg)
if (testCancel()) then
setState("sitCloserStop");
local partner = retrieveStateObject("partner");
sendMsg("partnerCancel", partner);
else
setState("holdInArms");
end
end )
state("holdInArms")
onEnter(function(msg)
print("-- holdInArms --");
local activePart = retrieveData("activePart");
startAnimation(genderize(getParent(), "sofaHold"), retrieveData("mirrorAnims"));
end )
onMsg("partnerCancel", function(msg)
setState("holdInArmsStop");
end )
onMsg("end", function(msg)
if (testCancel()) then
setState("holdInArmsStop");
local partner = retrieveStateObject("partner");
sendMsg("partnerCancel", partner);
else
setState("holdKiss");
end
end )
state("holdKiss")
onEnter(function(msg)
print("-- holdKiss --");
--local activePart = retrieveData("activePart");
local partner = retrieveStateObject("partner");
local kissIntimate = getParent().startActivity("kissIntimate", partner.getParent());
local length, scale = getActivityLength(kissIntimate);
startAnimation(genderize(getParent(), "sofaKissLoop"), retrieveData("mirrorAnims"));
sendDelayedMsgThis("stopKissing", length);
--this.actionComplete();
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end )
onMsg("stopKissing", function(msg)
setState("holdInArmsStop");
local partner = retrieveStateObject("partner");
getParent().stopActivity("kissIntimate", partner.getParent());
sendMsg("partnerCancel", partner);
end )
onMsg("testCancel", function(msg)
if testCancel() then
sendMsgThis("stopKissing");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("partnerCancel", function(msg)
sendMsgThis("stopKissing");
end )
onMsg("queue", function(msg)
sendMsgThis("stopKissing");
end )
onMsg("end", function(msg)
if (testCancel()) then
sendMsgThis("stopKissing");
else
startAnimation(genderize(getParent(), "sofaKissLoop"), retrieveData("mirrorAnims"));
end
end )
state("holdInArmsStop")
onEnter(function(msg)
print("-- holdInArmsStop --");
startAnimation(genderize(getParent(), "sofaHoldStop"), retrieveData("mirrorAnims"), 1.0, SEX_FADE_TIME);
end )
onMsg("end", function(msg)
setState("sitCloserStop");
end )
state("sitCloserStop")
onEnter(function(msg)
print("-- sitCloserStop --");
local activePart = retrieveData("activePart");
startAnimation(genderize(getParent(), "sofaSitCloseStop"), retrieveData("mirrorAnims"));
end )
onMsg("end", function(msg)
--setState("sit");
local sofa = retrieveStateObject("sofa");
queueFollowCommand(getParent(), "pm_sitdown", "sit", sofa, "");
setState("standUp");
end )
endStateMachine()