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

  1. property lsMachineProfile, lsLocations, lsLiveHotspots, lsAllHotspots, lsOnstage, lsEarshot, purgeList, lsAlwaysOnstage, sharedSprite, puppetTrans, lsInventory, lsInventoryData, inventoryStatus, lsForegroundData, lsMultiframes, loadedLocations, locationSublists, gHotSublist, basePalette, queuedSound, cursorQuality, ancestor
  2.  
  3. on birth me
  4.   global gTransQuality, gCPU, gOriginPoint, gMenuBottomY, gInventoryTopY
  5.   set lsMachineProfile to [#machineType: [#Mac, #powerMac, #PC], #horsePower: 0, #cursors: [#chevette, #yugo, #cadillac], #transitions: [#turnRight: "02,1,16,TRUE", #turnLeft: "01,1,16,TRUE", #forward: "26,2,0,TRUE", #lookAt: "26,2,0,TRUE", #backOff: "26,2,0,TRUE", #lookUp: "03,1,16,TRUE", #lookDown: "04,1,16,TRUE", #fadeIn: "26,2,0,TRUE", #slowMontage: "26,3,0,TRUE", #nextPage: "2,2,16,TRUE", #prevPage: "1,2,16,TRUE"], #sound: [#stradivarius, #closeAndPlay]]
  6.   set ancestor to birth(script "cPuppeteer.2")
  7.   set gTransQuality to #Best
  8.   set cursorQuality to #cadillac
  9.   set lsLocations to [:]
  10.   set locationSublists to []
  11.   set lsAllHotspots to []
  12.   set lsLiveHotspots to []
  13.   set lsOnstage to []
  14.   set lsEarshot to []
  15.   set purgeList to []
  16.   set sharedSprite to 0
  17.   set puppetTrans to #None
  18.   set lsInventory to [#None, #None, #None, #None, #None, #None, #None]
  19.   set lsInventoryData to [:]
  20.   set inventoryStatus to #cool
  21.   set loadedLocations to []
  22.   set basePalette to "ROXY base"
  23.   set queuedSound to #None
  24.   if gCPU = #mistakenNotionOfaPC then
  25.     set gOriginPoint to point(the stageLeft, the stageTop)
  26.     set originY to getAt(gOriginPoint, 2)
  27.     set gMenuBottomY to originY + 30
  28.     set gInventoryTopY to originY + 380
  29.   else
  30.     set gOriginPoint to point(0, 0)
  31.     set gMenuBottomY to 30
  32.     set gInventoryTopY to 380
  33.   end if
  34.   return me
  35. end
  36.  
  37. on enterNewDomain me, castList, multiFrameData, foregroundData, inventoryData
  38.   set oldFreeMem to the freeBytes
  39.   set tempVar to EMPTY
  40.   repeat with i in castList
  41.     put i after tempVar
  42.   end repeat
  43.   set lsLocations to value(tempVar)
  44.   REPORT2("Puppeteer: I've initialized lsLocations (from text cast) at " & the timer & " ticks")
  45.   set loadedLocations to []
  46.   if listp(lsLocations) then
  47.     set locationSublists to []
  48.     set loadedLocations to []
  49.     repeat with i = 1 to count(lsLocations)
  50.       append(locationSublists, getPropAt(lsLocations, i))
  51.     end repeat
  52.     REPORT2("Puppeteer: I've initialized LocationSublists (the room-by-room 'hotlist') at " & the timer & " ticks")
  53.   end if
  54.   set tempVar to 0
  55.   if the paramCount > 2 then
  56.     set lsMultiframes to value(field multiFrameData)
  57.     REPORT2("Puppeteer: I've initialized lsMultiframes at " & the timer & " ticks")
  58.   end if
  59.   if the paramCount > 3 then
  60.     set lsForegroundData to value(field foregroundData)
  61.     REPORT2("Puppeteer: I've initialized lsForegroundData at " & the timer & " ticks")
  62.   end if
  63.   if the paramCount > 4 then
  64.     set lsInventoryData to value(field inventoryData)
  65.     REPORT2("Puppeteer: I've initialized lsInventory at " & the timer & " ticks")
  66.   end if
  67.   initMultiFrames()
  68.   REPORT2("Puppeteer: initMultiframes() complete at " & the timer & " ticks")
  69.   set purgeList to []
  70. end
  71.  
  72. on moveToLocation me
  73.   global oStoryteller, g16bit, oFixPal, gCurrentPalette, oMemory
  74.   repeat with z in purgeList
  75.     unLoadCast(z)
  76.   end repeat
  77.   set purgeList to []
  78.   set newLocation to getState(oStoryteller, #currentLocation)
  79.   if getLocationStatus(me, newLocation) = #stored then
  80.     loadLocationData(me, newLocation)
  81.     REPORT(">> location-data (lists) for ΓÇó" & newLocation & "ΓÇó just loaded (" & the timer & " ticks)")
  82.   else
  83.     REPORT(">> location-data (lists) for ΓÇó" & newLocation & "ΓÇó already loaded (" & the timer & " ticks)")
  84.   end if
  85.   set locList to getLocationPointer(me, newLocation)
  86.   set lsAllHotspots to getProp(locList, #Hotspots)
  87.   set lsOnstage to getProp(locList, #onStage)
  88.   set newSounds to getaProp(locList, #earShot)
  89.   if voidp(newSounds) then
  90.   else
  91.     set lsEarshot to newSounds
  92.   end if
  93.   REPORT(">> location hotlist-pointers updated (" & the timer & " ticks)")
  94.   if the colorDepth = 8 then
  95.     set newPalette to 0
  96.     set firstOnstageCast to 0
  97.     if count(lsOnstage) then
  98.       set firstOnstageCast to getProp(getAt(lsOnstage, 1), #castNum)
  99.     end if
  100.     if firstOnstageCast > 0 then
  101.       set newPalette to the palette of cast firstOnstageCast
  102.     end if
  103.     if (newPalette <> basePalette) and (newPalette <> 0) and (newPalette <> gCurrentPalette) then
  104.       set gCurrentPalette to newPalette
  105.       puppetPalette(newPalette, 60)
  106.       updateStage()
  107.       oFixPal(mPatchIt)
  108.       REPORT(">> palette changed and patched (" & the timer & " ticks)")
  109.     else
  110.     end if
  111.   end if
  112.   updateDisplay(me)
  113.   REPORT(">> 'updateDisplay()' done (" & the timer & " ticks)")
  114. end
  115.  
  116. on getLocationPointer me, locName, sublistFlag
  117.   set mySublist to #None
  118.   if string(locName) starts string(gHotSublist) then
  119.     set mySublist to gHotSublist
  120.   end if
  121.   repeat with j in locationSublists
  122.     if string(locName) starts string(j) then
  123.       set mySublist to j
  124.       set gHotSublist to j
  125.     end if
  126.   end repeat
  127.   if mySublist = #None then
  128.     put "Hmm, couldn't find an appropriate sublist for location #" & locName
  129.     return #None
  130.   else
  131.     if the paramCount = 3 then
  132.       if sublistFlag = #sublist then
  133.         return mySublist
  134.       end if
  135.     else
  136.       return getProp(getProp(lsLocations, mySublist), locName)
  137.     end if
  138.   end if
  139. end
  140.  
  141. on getLocationStatus me, locName
  142.   global oStoryteller
  143.   set testLoc to getLocationPointer(me, locName)
  144.   if ilk(testLoc, #propList) then
  145.     return #loaded
  146.   end if
  147.   if ilk(testLoc, #linearList) then
  148.     return #stored
  149.   end if
  150.   if voidp(testLoc) then
  151.     setAt(getProp(the lsStateData of oStoryteller, #currentLocation), 1, getAt(getProp(the lsStateData of oStoryteller, #previousLocation), 1))
  152.     alert("getLocationStatus : Hey! This location (#" & locName & ") isn't a stub-number OR a list..")
  153.     abort()
  154.   end if
  155.   return #error
  156. end
  157.  
  158. on loadLocationData me, locName
  159.   global builderwindow, gLocData
  160.   set stubNumber to getLocationPointer(me, locName)
  161.   if not ilk(stubNumber, #linearList) then
  162.     alert("Invalid stub-number! Perhaps this list is already loaded..")
  163.     return #error
  164.   end if
  165.   if voidp(gLocData) then
  166.     setProp(getProp(lsLocations, gHotSublist), locName, value(field getAt(stubNumber, 1)))
  167.   else
  168.     setProp(getProp(lsLocations, gHotSublist), locName, value(char getAt(stubNumber, 2) to getAt(stubNumber, 3) of getProp(gLocData, gHotSublist)))
  169.   end if
  170.   setaProp(getaProp(getProp(lsLocations, gHotSublist), locName), #storageCast, stubNumber)
  171.   append(loadedLocations, [locName, stubNumber])
  172.   REPORT(">>> New list assigned value (" & the timer & " ticks)")
  173.   if (count(loadedLocations) > 12) and not getPos(the windowList, builderwindow) then
  174.     set firstBorn to getAt(loadedLocations, 1)
  175.     set locName to getAt(firstBorn, 1)
  176.     setProp(getProp(lsLocations, getLocationPointer(me, locName, #sublist)), locName, getAt(firstBorn, 2))
  177.     deleteAt(loadedLocations, 1)
  178.     REPORT(">>> oldest location purged.. (" & the timer & " ticks)")
  179.   end if
  180.   return #OK
  181. end
  182.  
  183. on purgeLocationData me, locName
  184.   set stubNumber to getaProp(getaProp(getProp(lsLocations, gHotSublist), locName), #storageCast)
  185.   if voidp(stubNumber) then
  186.     alert("No #storageCast for this location. A new location, perhaps?")
  187.     return #error
  188.   end if
  189.   setProp(getProp(lsLocations, gHotSublist), locName, stubNumber)
  190. end
  191.  
  192. on updateDisplay me, optionSwitch
  193.   global lastScoreSprite, oStoryteller, gSoundPath, gOriginPoint, gSndStart, gSoundDelay
  194.   if queuedSound <> #None then
  195.     soundEffect(queuedSound)
  196.     updateStage()
  197.     set queuedSound to #None
  198.     set sndFlag to 1
  199.   else
  200.     set sndFlag to 0
  201.   end if
  202.   set useLocalBeds to #on
  203.   set lsLiveHotspots to []
  204.   REPORT(">>> 'updateDisplay()' started ( " & the timer & " ticks )")
  205.   if listp(lsEarshot) then
  206.     if count(lsEarshot) then
  207.       if getState(oStoryteller, #currentDomain) = "ROXY" then
  208.         set houseHumVol to getAt(lsEarshot, 1)
  209.         if houseHumVol > 0 then
  210.           setLoop(#houseHum, houseHumVol)
  211.         else
  212.           endLoop(#houseHum)
  213.         end if
  214.         set phoneVol to getAt(lsEarshot, 2)
  215.         if (getState(oStoryteller, #ghostlyPhoneCall) = #ringingNow) and (phoneVol <> 0) then
  216.           setLoop(#phoneRinging, phoneVol)
  217.         end if
  218.         if getState(oStoryteller, #AMBERVISION) = #on then
  219.           playDomainEntrySound()
  220.         end if
  221.       end if
  222.     end if
  223.   end if
  224.   repeat with i in lsOnstage
  225.     if evaluate(oStoryteller, getProp(i, #showIF)) then
  226.       set assignedCast to getProp(i, #castNum)
  227.       if not integerp(assignedCast) then
  228.         set triggerVar to getAt(assignedCast, 1)
  229.         set frameStack to getaProp(lsMultiframes, getAt(assignedCast, 2))
  230.         if voidp(frameStack) then
  231.           alert("Whoa, grabbed a void from lsMultiframes, trying to get: " & getAt(assignedCast, 2))
  232.           exit
  233.         end if
  234.         if triggerVar = #AMBERVISION then
  235.           if getState(oStoryteller, #AMBERVISION) <> #on then
  236.             set assignedCast to getaProp(frameStack, #off)
  237.           else
  238.             set assignedCast to getaProp(frameStack, getState(oStoryteller, triggerVar))
  239.           end if
  240.         else
  241.           set assignedCast to getaProp(frameStack, getState(oStoryteller, triggerVar))
  242.         end if
  243.         if voidp(assignedCast) then
  244.           alert("Whoa, grabbed a void from the framestack, trying to get prop ' " & getState(oStoryteller, triggerVar) & "' from the state-var '#" & triggerVar & "'")
  245.           exit
  246.         end if
  247.       end if
  248.       append(purgeList, assignedCast)
  249.       if integerp(getProp(i, #channel)) or (getProp(i, #channel) = #shared) then
  250.         if getProp(i, #channel) <> #shared then
  251.           set sharedSprite to lastScoreSprite + getProp(i, #channel)
  252.         end if
  253.         puppetSprite(sharedSprite, 1)
  254.         set the castNum of sprite sharedSprite to assignedCast
  255.         set the ink of sprite sharedSprite to getProp(i, #ink)
  256.         set the loc of sprite sharedSprite to getProp(i, #coords) + gOriginPoint
  257.       else
  258.         if (getProp(i, #channel) = #sound) and (useLocalBeds = #on) then
  259.           set sndVolume to getProp(i, #earShot)
  260.           if sndVolume < 0 then
  261.             endLoop(value(getProp(i, #castName)))
  262.           else
  263.             setLoop(value(getProp(i, #castName)), sndVolume)
  264.           end if
  265.         end if
  266.         if getProp(i, #channel) = #video then
  267.           set videoSprite to 44
  268.           if the castNum of sprite videoSprite = 7 then
  269.             puppetSprite(videoSprite, 1)
  270.             set the castNum of sprite videoSprite to assignedCast
  271.             set vidCoords to getProp(i, #coords) + gOriginPoint
  272.             if optionSwitch = #fastVideo then
  273.               set the loc of sprite videoSprite to vidCoords
  274.             else
  275.               set the video of member assignedCast to 0
  276.             end if
  277.           end if
  278.         end if
  279.       end if
  280.       next repeat
  281.     end if
  282.     if integerp(getProp(i, #channel)) then
  283.       set unwantedSprite to lastScoreSprite + getProp(i, #channel)
  284.     end if
  285.     set the castNum of sprite unwantedSprite to 6
  286.     set the loc of sprite unwantedSprite to point(320, -360) + gOriginPoint
  287.   end repeat
  288.   REPORT(">>> onstage cast evaluated and placed on-stage ( " & the timer & " ticks )   [through sprite " & sharedSprite & "]")
  289.   repeat with i = sharedSprite + 1 to 37
  290.     set the castNum of sprite i to 6
  291.     set the loc of sprite i to point(320, -360) + gOriginPoint
  292.   end repeat
  293.   REPORT(">>> remaining sprites placed off-screen ( " & the timer & " ticks )")
  294.   repeat with i in lsAllHotspots
  295.     if evaluate(oStoryteller, getAt(i, 4)) then
  296.       append(lsLiveHotspots, i)
  297.     end if
  298.   end repeat
  299.   REPORT(">>> hot-spots evaluated and placed on-stage ( " & the timer & " ticks )")
  300.   if puppetTrans <> #None then
  301.     do("puppetTransition " & puppetTrans)
  302.   end if
  303.   REPORT(">>> puppetTransition done ( " & the timer & " ticks )")
  304.   set myMem to the freeBytes
  305.   if sndFlag = 1 then
  306.     set startT to getAt(gSndStart, 2)
  307.     repeat while the ticks < (startT + gSoundDelay)
  308.     end repeat
  309.   end if
  310.   updateStage()
  311.   if optionSwitch <> #fastVideo then
  312.     set the loc of sprite videoSprite to vidCoords
  313.     set the video of member the castNum of sprite 44 to 1
  314.   end if
  315.   REPORT(">>> updateStage done ( " & the timer & " ticks )")
  316.   set loadSize to (myMem - the freeBytes) / 1024
  317.   REPORT("    (loaded " & loadSize & " K, then performed transition [" & puppetTrans & "] )")
  318.   set puppetTrans to #None
  319. end
  320.  
  321. on setTransition me, transitionID
  322.   global gStopTransitions
  323.   if gStopTransitions then
  324.     exit
  325.   end if
  326.   if stringp(transitionID) then
  327.     set puppetTrans to transitionID
  328.   else
  329.     set transList to getProp(lsMachineProfile, #transitions)
  330.     set puppetTrans to getProp(transList, transitionID)
  331.   end if
  332. end
  333.  
  334. on DoHotspots me
  335.   global gCurrentHotspot, thisCursor, domainIsReady
  336.   if domainIsReady = 0 then
  337.     exit
  338.   end if
  339.   if listp(gCurrentHotspot) then
  340.     disablePeekAlert()
  341.     set cmdList to getAt(gCurrentHotspot, 3)
  342.     set howManyLines to count(cmdList)
  343.     repeat with i = 1 to howManyLines
  344.       if i = howManyLines then
  345.         enablePeekAlert()
  346.       end if
  347.       do(getAt(cmdList, i))
  348.     end repeat
  349.   end if
  350.   set gCurrentHotspot to #None
  351. end
  352.