home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
bookshelfChar.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
10KB
|
357 lines
-- bookshelf character state machine
beginStateMachine()
onEnter(function(msg)
end )
onExit(function(msg)
-- local bookshelf = retrieveStateObject("bookshelf");
-- if (bookshelf) then
-- getParent().unlockActionPoints(bookshelf);
-- removeStateObject("bookshelf");
-- end;
unlockAll("bookshelf");
unlockAll("book");
getParent().stopAllActivities();
end )
state("takeBoardgame")
onEnter(function(msg)
local bookshelf = retrieveStateObject("bookshelf");
startAnimation("takeBoardgame");
if (bookshelf) then
-- bookshelf does exist
if exitIfWrongPosition(getParent(), bookshelf, retrieveData("actionPointName")) then return end;
if (getParent().isOneActionPointLocked(bookshelf)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(bookshelf);
end
else
-- bookshelf does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
freeHands(getParent());
sendDelayedMsgThis("grabBoardgame", 1000);
end )
onMsg("grabBoardgame", function(msg)
print("create game");
local boardgame = getParent().loadGameObject("StandardGO","boardgameBox");
if (not boardgame) then
print("create boardgame failed");
end
storeStateObject("boardgame", boardgame);
getParent().attachLeftObjectHolder(boardgame);
local hso = getParent().handSO;
if (not hso) then
print("no hands found");
else
hso.setPose("leftHandHold");
end
end)
onMsg("end", function(msg)
if testCancel() then
freeHands(getParent());
exitAndGoAway();
else
--setState("lookForChair");
local boardgame = getParent().getLeftHeldObject();
local wsoContext = StateMachineContext();
wsoContext.storeStateObject("boardgame", boardgame);
wsoContext.storeStateObject("tableObject", boardgame);
wsoContext.storeData("chairCommand", "playByTableChar.sitDownWithGame");
wsoContext.storeData("checkPartnerChair", true);
queueStateMachine("tableChairChar.findChair", this, wsoContext);
exitStateMachine();
end
end )
onExit(function(msg)
-- getParent().detachObjectAnimator();
end)
-- -- look for free chair
-- state("lookForChair")
-- print("lookForChair");
--
-- onEnter(function(msg)
--
-- local tablet = retrieveStateObject("tablet");
--
-- getParent().handSO.setPose("leftHandHold");
-- getParent().attachLeftObjectHolder(tablet);
--
-- local wsoContext = StateMachineContext();
-- wsoContext.storeStateObject("boardgame", boardgame);
-- wsoContext.storeStateObject("tableObject", boardgame);
-- wsoContext.storeData("chairCommand", "playByTableChar.sitDownWithGame");
-- queueStateMachine("tableChairChar.findChair", this, wsoContext);
-- exitStateMachine();
-- end)
--
--
--
-- -- look for free chair
-- state("lookForChair")
-- print("lookForChair");
--
-- onEnter(function(msg)
-- -- find a chair to eat
-- local boardgame = retrieveStateObject("boardgame");
--
-- local table, tableActionPointName, chair = getNextFreeChairByTable(getParent());
-- if (chair) then
--
-- -- go to chair
-- local actionPoint = getParent().getClosestFreeActionPoint(getParent(), chair, {"sit1", "sit2"});
-- if (actionPoint) then
--
-- print("free chair found , ap:" .. actionPoint.getName());
--
--
-- if (walkToActionPoint(actionPoint)) then
--
--
-- exitStateMachine();
-- storeStateObject("chair", chair);
-- storeStateObject("table", table);
-- storeStateObject("boardgame", boardgame);
-- storeStateObject("tableObject", boardgame);
-- storeData("tableActionPointName", tableActionPointName);
-- storeData("chairActionPointName", actionPoint.getName());
--
--
-- queueStateMachine("playByTableChar.sitDownWithGame", this);
--
-- local hso = getParent().handSO;
-- hso.stopPose();
--
-- local mirror = (actionPoint.getName() == "sit2");
-- print("actionPoint.getName(): ", actionPoint.getName());
-- print("mirror: ", mirror);
-- hso.setPose("leftHandHold", mirror);
--
--
-- if (mirror) then
-- print("switch hands");
-- -- switch hands
-- getParent().detachLeftObjectHolder();
-- getParent().attachRightObjectHolder(boardgame);
-- --else
-- -- getParent().attachLeftObjectHolder(boardgame);
-- end
--
-- else
-- -- no path to chair was found
-- print("no path to action point");
-- sendMsgThis("noPlaceToPlay");
-- end
--
-- else
-- print("no free action point");
-- sendMsgThis("noPlaceToPlay");
-- end
--
-- --exitStateMachine();
-- else
-- print("no free chair");
-- sendMsgThis("noPlaceToPlay");
-- end
--
--
--
--
--
--
--
--
--
-- end)
--
-- onMsg("noPlaceToPlay", function(msg)
-- print("no place to play");
-- -- detach boardgame if attached to left hand
-- getParent().detachLeftObjectHolder();
-- getParent().detachRightObjectHolder();
-- local boardgame = retrieveStateObject("boardgame");
-- if (boardgame) then
-- boardgame.deleteGameObject();
-- end
-- local hso = getParent().handSO;
-- hso.stopPose();
--
-- getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
-- exitStateMachine();
-- sendMsg("emoThink", getParent().walkSO);
-- end)
state("takeBook")
onEnter(function(msg)
local bookshelf = retrieveStateObject("bookshelf");
if (bookshelf) then
-- bookshelf does exist
if exitIfWrongPosition(getParent(), bookshelf, retrieveData("actionPointName")) then return end;
if (getParent().isOneActionPointLocked(bookshelf)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(bookshelf);
startAnimation("takeBook");
freeHands(getParent());
sendDelayedMsgThis("grabBook", 1000);
end
else
-- bookshelf does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
end )
onMsg("grabBook", function(msg)
print("create book");
local book = getParent().loadGameObject("StandardGO","bookClosed");
if (not book) then
print("create bookClosed failed");
end
storeStateObject("book", book);
getParent().attachLeftObjectHolder(book);
end)
onMsg("end", function(msg)
if testCancel() then
-- detach book if attached to left hand
local book = getParent().getLeftHeldObject();
if (book) then
getParent().detachLeftObjectHolder();
book.deleteGameObject();
end
-- local hso = getParent().handSO;
-- hso.stopPose();
exitStateMachine();
else
local hso = getParent().handSO;
if (not hso) then
print("no hands found");
else
hso.setPose("leftHandHoldLow");
end
setState("lookForSeat");
end
end )
onExit(function(msg)
-- getParent().detachObjectAnimator();
end)
state("lookForSeat")
print("lookForSeat");
onEnter(function(msg)
-- find a sofa to eat
local seat, actionPoint = getNextReadSit(getParent());
if (not seat) then
sendMsgThis("noPlaceToRead");
return
end
local wso = getParent().walkSO;
if (wso.walkToActionPoint(actionPoint)) then
-- create state machine contexts
local wsoContext = StateMachineContext();
--wsoContext.storeStateObject("seat", seat);
wsoContext.storeStateObject("book", retrieveStateObject("book"));
wsoContext.storeData("actionPointName", actionPoint.getName());
wsoContext.storeData("sitState", "readBook");
wsoContext.storeData("bookType", retrieveData("bookType", "Novel"));
wso.queueStateMachine("sofaChar.sitDown", seat, wsoContext);
exitStateMachine();
else
print("no path found");
sendMsgThis("noPlaceToRead");
end
end)
onMsg("noPlaceToRead", function(msg)
print("no place to read");
-- detach book if attached to left hand
local character = getParent();
-- character.detachLeftObjectHolder();
-- character.detachRightObjectHolder();
-- local book = retrieveStateObject("book");
-- if (book) then
-- book.deleteGameObject();
-- end
-- character.handSO.stopPose();
freeHands(getParent());
instantAbort(character, EMOTICON_NOPATH, "emoThink");
exitStateMachine();
-- getParent().setEmoticon(EMOTICON_NOSOFA, EMOTICON_DELAY);
-- exitStateMachine();
-- sendMsg("emoThink", getParent().walkSO);
end)
endStateMachine()