home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles (French)
/
Singles-FrenchVersion-Win95.iso
/
data1.cab
/
Statemachine
/
hifi.lua
< prev
next >
Wrap
Text File
|
2004-03-05
|
5KB
|
156 lines
-- hifi state machine
beginStateMachine()
onMsg("buildMenu", function(msg)
if (repairMenu()) then return end
-- build the pie menu
clearPieMenu();
button = addPieMenuButton("pm_dance", "dance");
button.addDescription(ACTIVITY, "dance");
button = addPieMenuButton("pm_rockMusic", "music1");
button.addDescription(DONTQUEUE, "true");
--button = addPieMenuButton("pm_danceMusic", "music2");
if getGameObjectServer().addListener(0) > 0 then
button = addPieMenuButton("pm_switchOff", "aus");
button.addDescription(DONTQUEUE, "true");
end
-- button.addIcon("guiIconSpass");
end )
--
onMsg("dance", function(msg)
-- get character who initiated this action
local character = getStateObjectFromID(msg.sender);
-- if this is broken: abort characters action
if abortIfBroken(character) then return end;
-- check if activity if possible
local possible, result, activity = activityPossible(character, msg.name, this);
-- don't care if timeslot is not fulfilled
if (possible or enumCompare(result, TIMESLOT)) then
-- walk to the closest action point
local actionPoint = character.getClosestFreeActionPoint(character, this, {"dance1", "dance2"});
if (actionPoint) then
-- get the walk state object
local wso = character.walkSO;
local wsoContext = StateMachineContext();
wsoContext.storeData("actionPointName", actionPoint.getName());
if (wso.walkToActionPoint(actionPoint)) then
wso.queueStateMachine("hifiChar.dance", this, wsoContext);
else
print("no path found");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found");
instantAbort(character, EMOTICON_CANNOT, "emoThink")
end
else
-- activity not possible
print(msg.name .. " not possible");
local emoticon;
if (enumCompare(result, NO_CONDITION)) then
emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
else
emoticon = EMOTICON_CANNOT;
end
instantAbort(character, emoticon, "emoThink");
end
end )
onMsg("addListener", function(msg)
-- increase number of listeners for this object for relationship control (are mike and elaine dancing together?)
local numListeners = retrieveData("numListeners", 0) + 1;
storeData("numListeners", numListeners);
-- increase number of global listeners for music control
local s = getGameObjectServer();
if (s.addListener(1) == 1) then
--loopSound("radioGitklirr");
s.setMusic("radioGitklirr");
end
end )
onMsg("removeListener", function(msg)
-- decrease number of listeners for this object
local numListeners = max(retrieveData("numListeners", 0) - 1, 0);
storeData("numListeners", numListeners);
-- decrease number of global listeners
local s = getGameObjectServer();
if (s.addListener(-1) == 0) then
--stopSound("radioGitklirr");
s.setMusic("");
end
end )
onMsg("music1", function(msg)
local s = getGameObjectServer();
if s.addListener(0) == 0 then
s.addListener(1);
end
s.setMusic("radioGitklirr");
-- local character = getStateObjectFromID(msg.sender);
-- character.walkSO.nextAction();
end )
onMsg("music2", function(msg)
local s = getGameObjectServer();
if s.addListener(0) == 0 then
s.addListener(1);
end
s.setMusic("danceMusic");
end )
onMsg("aus", function(msg)
local s = getGameObjectServer();
s.addListener(-999); -- remove all listeners
s.setMusic("");
-- local character = getStateObjectFromID(msg.sender);
-- character.walkSO.nextAction();
end )
-- repair
onMsg("repair", function(msg)
print("onMsg repair");
-- get character who initiated this action
local character = getStateObjectFromID(msg.sender);
-- walk to the closest action point
local actionPoint = character.getFreeActionPoint(this, "repair");
-- get the walk state object
local wso = character.walkSO;
if (actionPoint) then
-- create state machine contexts
local wsoContext = StateMachineContext();
-- store the action point
wsoContext.storeData("actionPointName", actionPoint.getName());
if (wso.walkToActionPoint(actionPoint)) then
wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
else
print("no path found");
instantAbort(character, EMOTICON_NOPATH, "emoThink")
end
else
print("no action point found");
instantAbort(character, EMOTICON_CANNOT, "emoThink")
end
end )
endStateMachine()