home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 39 / PCGAMER39.bin / games / amber / amberhub.dxr / 00015_cStoryteller.ls < prev    next >
Encoding:
Text File  |  1996-11-08  |  12.6 KB  |  377 lines

  1. property lsStateData, currentGameFile, ancestor
  2.  
  3. on birth me
  4.   set lsStateData to [:]
  5.   set ancestor to birth(script "cStoryteller.2")
  6.   set currentGameFile to #None
  7.   return me
  8. end
  9.  
  10. on newGame me
  11.   global domainIsReady, gCPU
  12.   installMenu(0)
  13.   updateStage()
  14.   if objectp(oBackdrop) then
  15.     oBackdrop(mPatToWindow, -5)
  16.   end if
  17.   set domainIsReady to 0
  18.   suspendSounds(#fadeOut)
  19.   gammaFade(#down)
  20.   repeat with whichSprite = 1 to 48
  21.     set the loc of sprite whichSprite to point(-1000, -1000)
  22.     puppetSprite(whichSprite, 0)
  23.   end repeat
  24.   updateStage()
  25.   if the colorDepth <> 16 then
  26.     setColor(16)
  27.   end if
  28.   gammaFade(#clearStage)
  29.   set lsStateData to [:]
  30.   set currentGameFile to #None
  31.   enterNewDomain(me, "ROXY")
  32. end
  33.  
  34. on loadSavedGame me, jumpSwitch
  35.   global builderwindow, oUtility, oStoryteller, gSavePath, gAmberPath, domainIsReady, oGrabber, gSoundPath, oPuppeteer, gCDswapStash, gSoundPath2, gCPU, thisCursor, lastCursor, gDeferredTransit, gHorsepower
  36.   if jumpSwitch <> #jumping then
  37.     installMenu(0)
  38.     updateStage()
  39.     if objectp(oBackdrop) then
  40.       oBackdrop(mPatToWindow, -5)
  41.     end if
  42.     REPORT2("ΓÇó> Starting timer for loadSavedGame( oStoryteller )...")
  43.     startTimer()
  44.     oUtility(mSetDefaultPath, gSavePath)
  45.     if gCPU = #PC then
  46.       set loadTest to new(xtra("FileIO"))
  47.       if not objectp(loadTest) then
  48.         alert("Sorry, there's some problem creating a fileio object.")
  49.         quit()
  50.       end if
  51.       setFilterMask(loadTest, "Amber: Journeys Beyond saved games,*.sav")
  52.       set strCurrentFile to displayOpen(loadTest)
  53.     else
  54.       set hCurrentFile to FileIO(mnew, "?append", "HFE ")
  55.     end if
  56.     if voidp(strCurrentFile) then
  57.     end if
  58.     if objectp(oPuppeteer) then
  59.       refreshVidSprites(oPuppeteer)
  60.     end if
  61.     if the movie contains "AMBERHUB" then
  62.       put "<!>  Sorry, can't cursorDance in AMBERHUB"
  63.     else
  64.       set thisCursor to #pointer
  65.       set lastCursor to #bogus
  66.       cursorDance()
  67.     end if
  68.     if voidp(strCurrentFile) then
  69.       set gDeferredTransit to #None
  70.       set loadTest to 0
  71.       if the movie contains "AMBERHUB" then
  72.         installMenu(the number of member "Amber menus")
  73.       end if
  74.       if the number of menus > 1 then
  75.         set the checkMark of menuItem (8 - the soundLevel) of menu 2 to 1
  76.       end if
  77.       return #cancelled
  78.     else
  79.     end if
  80.     set domainIsReady to 0
  81.     suspendSounds(#fadeOut)
  82.     openFile(loadTest, strCurrentFile, 1)
  83.     setPosition(loadTest, 0)
  84.     set currentGameFile to strCurrentFile
  85.     set lsStateData to value(readFile(loadTest))
  86.     if not listp(lsStateData) then
  87.       alert("Sorry, there's some problem with this file.")
  88.       quit()
  89.     end if
  90.     setState(me, #horsePower, gHorsepower)
  91.     set gDeferredTransit to "nothing  --waiting for " & getState(oStoryteller, #currentDomain)
  92.     set loadTest to 0
  93.     unLoadCast()
  94.     gammaFade(#down)
  95.     repeat with whichSprite = 1 to 48
  96.       set the loc of sprite whichSprite to point(-1000, -1000)
  97.       puppetSprite(whichSprite, 0)
  98.     end repeat
  99.     updateStage()
  100.     gammaFade(#clearStage)
  101.     set destination to getState(oStoryteller, #currentDomain)
  102.     set gCDswapStash to [#destination: destination, #loadFrame: #None, #callingHandler: #loadSavedGame]
  103.     ensureProperCD(me, destination)
  104.   else
  105.     set destination to getState(oStoryteller, #currentDomain)
  106.   end if
  107.   if gCPU = #PC then
  108.     set pathDelim to "\"
  109.   end if
  110.   if gCPU = #Mac then
  111.     set pathDelim to ":"
  112.   end if
  113.   set the searchPath to [gAmberPath & destination & pathDelim, gSoundPath]
  114.   put "new searchPath (before entering domain-movie) ="
  115.   put the searchPath
  116.   go(1, destination)
  117.   if destination = "roxy" then
  118.     set movieFolder to "movies" & pathDelim
  119.   end if
  120.   if destination = "margaret" then
  121.     set movieFolder to "Movies_M" & pathDelim
  122.   end if
  123.   if destination = "brice" then
  124.     set movieFolder to "Movies_B" & pathDelim
  125.   end if
  126.   if destination = "edwin" then
  127.     set movieFolder to "Movies_E" & pathDelim
  128.   end if
  129.   set the searchPath to [gAmberPath & destination & pathDelim & movieFolder, gSoundPath]
  130.   put "new searchPath (after entering domain-movie) ="
  131.   put the searchPath
  132.   if gCPU = #PC then
  133.     set gSoundPath2 to gAmberPath & "CD_DATA\"
  134.   else
  135.     set gSoundPath2 to gAmberPath & "CD_SOUNDS:"
  136.   end if
  137.   put "new gSoundPath2 = "
  138.   put gSoundPath2
  139.   if getPos(the windowList, builderwindow) then
  140.     put "trying to display state"
  141.     displayState()
  142.   end if
  143. end
  144.  
  145. on saveCurrentGame me, overWriteOrSaveAs
  146.   global oUtility, gSavePath, gCPU, oPuppeteer, thisCursor, lastCursor
  147.   writePrefsFile(oPuppeteer)
  148.   oUtility(mSetDefaultPath, gSavePath)
  149.   if overWriteOrSaveAs = #overWrite then
  150.     if currentGameFile = #None then
  151.       set overWriteOrSaveAs to #saveAs
  152.     else
  153.       set saveTest to new(xtra("FileIO"))
  154.       if not objectp(saveTest) then
  155.         put "Sorry, there's some problem creating a fileio object."
  156.         return #fileio_error
  157.       end if
  158.       openFile(saveTest, currentGameFile, 2)
  159.       if error(saveTest, status(saveTest)) <> "OK" then
  160.         put error(saveTest, status(saveTest))
  161.         set saveTest to 0
  162.         return #fileio_error
  163.       else
  164.         put "name: " & fileName(saveTest)
  165.         setPosition(saveTest, 0)
  166.         set saveString to string(lsStateData)
  167.         put "writeString result: " & writeString(saveTest, saveString)
  168.         put "helpful error code: " & error(saveTest, status(saveTest))
  169.         set saveTest to 0
  170.         return #OK
  171.       end if
  172.     end if
  173.   end if
  174.   if overWriteOrSaveAs = #saveAs then
  175.     set saveTest to new(xtra("FileIO"))
  176.     if not objectp(saveTest) then
  177.       alert("Sorry, there's some problem creating a fileio object.")
  178.       quit()
  179.     end if
  180.     setFilterMask(saveTest, "Amber: Journeys Beyond saved games,*.sav")
  181.     set strCurrentFile to displaySave(saveTest, "Save Game as", "my saved game.sav")
  182.     if objectp(oPuppeteer) then
  183.       refreshVidSprites(oPuppeteer)
  184.     end if
  185.     if the movie contains "AMBERHUB" then
  186.     else
  187.       set thisCursor to #pointer
  188.       set lastCursor to #bogus
  189.       cursorDance()
  190.     end if
  191.     if strCurrentFile <> EMPTY then
  192.       createFile(saveTest, strCurrentFile)
  193.       set saveError to error(saveTest, status(saveTest))
  194.       if (saveError <> "OK") and (saveError <> "File already exists") then
  195.         alert("Sorry, there was an error creating the saved-game file: " & saveError)
  196.       end if
  197.       openFile(saveTest, strCurrentFile, 2)
  198.       writeString(saveTest, string(lsStateData))
  199.       set writeError to error(saveTest, status(saveTest))
  200.       if writeError <> "OK" then
  201.         alert("Sorry, there was an error writing the saved-game file: " & writeError)
  202.       end if
  203.     else
  204.       put "error: " & error(saveTest, status(saveTest))
  205.     end if
  206.     set saveTest to 0
  207.   end if
  208. end
  209.  
  210. on enterNewDomain me, destination, desiredFrame, jumpSwitch
  211.   global domainIsReady, gAmberPath, gSoundPath, gCDswapStash, gSoundPath2, gCPU, gCurrentHotspot, gDeferredTransit, gHorsepower
  212.   set gDeferredTransit to "nothing   --waiting for " & destination
  213.   if jumpSwitch <> #jumping then
  214.     if (destination = "ROXY") and (count(lsStateData) > 0) then
  215.       set recentOuterDomain to value("#" & getState(me, #currentDomain))
  216.       set frozenRoxy to getProp(lsStateData, #StateOnIce)
  217.       set ghostList to getProp(frozenRoxy, #ghostsRemaining)
  218.       set ghostPosition to getPos(ghostList, recentOuterDomain)
  219.       if ghostPosition <> 0 then
  220.         deleteAt(ghostList, ghostPosition)
  221.       end if
  222.       set lastDomainName to string(recentOuterDomain)
  223.     else
  224.       set lastDomainName to #neverMind
  225.     end if
  226.     set gCDswapStash to [#destination: destination, #loadFrame: desiredFrame, #callingHandler: #enterNewDomain]
  227.     ensureProperCD(me, destination, lastDomainName)
  228.   else
  229.   end if
  230.   if gCPU = #PC then
  231.     set pathDelim to "\"
  232.   end if
  233.   if gCPU = #Mac then
  234.     set pathDelim to ":"
  235.   end if
  236.   set the searchPath to [gAmberPath & destination & pathDelim, gSoundPath]
  237.   put "new searchPath (before entering domain-movie) ="
  238.   put the searchPath
  239.   REPORT2("ΓÇó> Starting timer for enterNewDomain( oStoryteller )...")
  240.   startTimer()
  241.   set domainIsReady to 0
  242.   set gCurrentHotspot to #None
  243.   if desiredFrame <> 0 then
  244.     go(desiredFrame, destination)
  245.   else
  246.     go(1, destination)
  247.   end if
  248.   if destination = "roxy" then
  249.     set movieFolder to "movies" & pathDelim
  250.   end if
  251.   if destination = "margaret" then
  252.     set movieFolder to "Movies_M" & pathDelim
  253.   end if
  254.   if destination = "brice" then
  255.     set movieFolder to "Movies_B" & pathDelim
  256.   end if
  257.   if destination = "edwin" then
  258.     set movieFolder to "Movies_E" & pathDelim
  259.   end if
  260.   set the searchPath to [gAmberPath & destination & pathDelim & movieFolder, gSoundPath]
  261.   put "new searchPath (after entering domain-movie) ="
  262.   put the searchPath
  263.   if gCPU = #PC then
  264.     set gSoundPath2 to gAmberPath & "CD_DATA\"
  265.   else
  266.     set gSoundPath2 to gAmberPath & "CD_SOUNDS:"
  267.   end if
  268.   put "new gSoundPath2 = "
  269.   put gSoundPath2
  270.   REPORT2("[enterNewDomain of oStoryteller]: Just finished 'go to movie ''ROXY'' ' ( at " & the timer & " ticks)")
  271.   if destination = "ROXY" then
  272.     if count(lsStateData) > 0 then
  273.       set lastOuterDomain to getState(me, #currentDomain)
  274.       set savedRoxy to getProp(lsStateData, #StateOnIce)
  275.       set lsStateData to savedRoxy
  276.       setState(me, #horsePower, gHorsepower)
  277.       setState(me, #lastDomainVisited, lastOuterDomain)
  278.       if lastOuterDomain = "MARGARET" then
  279.         setProp(lsStateData, #currentLocation, [#DarkUp_40sReentry])
  280.       end if
  281.       if lastOuterDomain = "BRICE" then
  282.         setProp(lsStateData, #currentLocation, [#Ggaz_Reentry])
  283.       end if
  284.       if lastOuterDomain = "EDWIN" then
  285.         setProp(lsStateData, #currentLocation, [#Gbhs_Reentry1])
  286.       end if
  287.     else
  288.       set lsStateData to value(field "stateData")
  289.       REPORT2("Just put stored state-data into lsStateData of oPuppeteer, at" & the timer & " ticks..")
  290.       setState(me, #horsePower, gHorsepower)
  291.     end if
  292.   else
  293.     if count(lsStateData) then
  294.       setProp(lsStateData, #houseLightsAreOn, [0, 1])
  295.       setState(me, #AMBERVISION, #off)
  296.       endLoop(#amberHum)
  297.       setState(me, #inventoryStatus, #hot)
  298.     end if
  299.     set storedState to lsStateData
  300.     set lsStateData to value(field "stateData")
  301.     REPORT2("Just put stored state-data into lsStateData of oPuppeteer, at" & the timer & " ticks..")
  302.     addProp(lsStateData, #StateOnIce, storedState)
  303.     REPORT2("Just stashed Roxy's state-data into #stateOnIce, at" & the timer & " ticks..")
  304.     setState(me, #horsePower, gHorsepower)
  305.   end if
  306.   set theTime to the timer
  307.   REPORT2(" enterNewDomain( oStoryteller ) done: at " & theTime & " ticks")
  308. end
  309.  
  310. on getState me, stateVar
  311.   return getAt(getProp(lsStateData, stateVar), 1)
  312. end
  313.  
  314. on setState me, stateVar, suggestion
  315.   global builderwindow
  316.   set valueList to getProp(lsStateData, stateVar)
  317.   if count(valueList) > 1 then
  318.     set oldPos to getPos(valueList, suggestion)
  319.     if oldPos then
  320.       addAt(valueList, 1, suggestion)
  321.       deleteAt(valueList, oldPos + 1)
  322.       if getPos(the windowList, builderwindow) then
  323.         tell builderwindow
  324.           showState(stateVar)
  325.         end tell
  326.       end if
  327.       return #OK
  328.     else
  329.       return #badValue
  330.     end if
  331.   else
  332.     set customFuncResult to value("set" & stateVar & "( #" & suggestion & " )")
  333.     if getPos(the windowList, builderwindow) then
  334.       tell builderwindow
  335.         showState(stateVar)
  336.       end tell
  337.     end if
  338.     return customFuncResult
  339.   end if
  340. end
  341.  
  342. on evaluate me, IFlist
  343.   set myProp to getPropAt(IFlist, 1)
  344.   if myProp = #equals then
  345.     return getState(me, getAt(getAt(IFlist, 1), 1)) = getAt(getAt(IFlist, 1), 2)
  346.   end if
  347.   if myProp = #less then
  348.     return getState(me, getAt(getAt(IFlist, 1), 1)) < getAt(getAt(IFlist, 1), 2)
  349.   end if
  350.   if myProp = #not then
  351.     return getState(me, getAt(getAt(IFlist, 1), 1)) <> getAt(getAt(IFlist, 1), 2)
  352.   end if
  353.   if myProp = #greater then
  354.     return getState(me, getAt(getAt(IFlist, 1), 1)) > getAt(getAt(IFlist, 1), 2)
  355.   end if
  356.   if myProp = #includes then
  357.     return getPos(getProp(lsStateData, getAt(getAt(IFlist, 1), 1)), getAt(getAt(IFlist, 1), 2))
  358.   end if
  359.   if myProp = #lacks then
  360.     return not getPos(getProp(lsStateData, getAt(getAt(IFlist, 1), 1)), getAt(getAt(IFlist, 1), 2))
  361.   end if
  362.   if myProp = #and then
  363.     set subList1 to [:]
  364.     set subList2 to [:]
  365.     addProp(subList1, getPropAt(getAt(IFlist, 1), 1), getAt(getAt(IFlist, 1), 1))
  366.     addProp(subList2, getPropAt(getAt(IFlist, 1), 2), getAt(getAt(IFlist, 1), 2))
  367.     return evaluate(me, subList1) and evaluate(me, subList2)
  368.   end if
  369.   if myProp = #or then
  370.     set subList1 to [:]
  371.     set subList2 to [:]
  372.     addProp(subList1, getPropAt(getAt(IFlist, 1), 1), getAt(getAt(IFlist, 1), 1))
  373.     addProp(subList2, getPropAt(getAt(IFlist, 1), 2), getAt(getAt(IFlist, 1), 2))
  374.     return evaluate(me, subList1) or evaluate(me, subList2)
  375.   end if
  376. end
  377.