home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / examples / road / common.scc < prev    next >
Encoding:
Text File  |  2006-12-06  |  28.3 KB  |  1,016 lines

  1. /* ScummC
  2.  * Copyright (C) 2006  Alban Bedel
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.  *
  18.  */
  19.  
  20. // include all the vars used by the engine itself
  21. #include <scummVars6.s>
  22. #include "common.sch"
  23.  
  24. // The room we start in
  25. room Road;
  26.  
  27. bit verbsOn,cursorOn,cursorLoaded;
  28.  
  29. int sntcVerb,sntcObjA,sntcObjB;
  30. int selVerb,altVerb;
  31. int tryPick;
  32. int* invObj;
  33.  
  34. room ResRoom {
  35.  
  36.     // define the charset we are going to use
  37.     // the gui use the first charset, so te be sure force its address
  38.     chset chset1 @ 1 = "vera-gui.char";
  39.     // our standard charset
  40.     chset chtest = "vera.char";
  41.     // dialog charset
  42.     chset dialogCharset = "vera-small.char";
  43.     // and the costume for our actor
  44.     cost egoCost = "devil.cost";
  45.  
  46.     // an object for the cursor image
  47.     object cursor {
  48.         x = 0;
  49.         y = 0;
  50.         w = 16;
  51.         h = 16;
  52.         name = "cursor";
  53.         states = {
  54.             { 3, 3, "cursor.bmp" }
  55.         };
  56.     }
  57.  
  58.     // the inventory icons
  59.     object axe {
  60.         w = 40;
  61.         h = 16;
  62.         x = 0;
  63.         name = "the axe";
  64.         states = {
  65.             { 0, 0, "inv_axe.bmp" }
  66.         };
  67.         state = 1;
  68.     }
  69.  
  70.     local script localTest() {
  71.         dbgPrint("Ltst");
  72.     }
  73.  
  74.     // some startup scripts
  75.  
  76.     // set the actor costume, etc
  77.     script setupActors() {
  78.         // create the actor
  79.         setCurrentActor(hero);
  80.         initActor();
  81.         setActorCostume(egoCost);
  82.         setActorTalkPos(-60,-60);
  83.         setActorName("Beasty");
  84.         setActorWalkSpeed(2,1);
  85.         setActorTalkColor(BEASTY_COLOR);
  86.         setActorWidth(40);
  87.         setActorAnimSpeed(2);
  88.         // set VAR_EGO so we can use the *Ego* functions
  89.         VAR_EGO = hero;
  90.     }
  91.  
  92.     // setup all the verbs
  93.     script setupVerbs() {
  94.         int color,hiColor,dimColor,l,c,vrb;
  95.  
  96.         color = VERB_COLOR;
  97.         hiColor = VERB_HI_COLOR;
  98.         dimColor = VERB_DIM_COLOR;
  99.  
  100.         sntcVerb = WalkTo;
  101.         //sntcObjA = 0;
  102.         //sntcObjB = 0;
  103.  
  104.         setCurrentVerb(SntcLine);
  105.         initVerb();
  106.         setVerbName("%v{sntcVerb} %n{sntcObjA} %s{sntcPrepo} %n{sntcObjB}");
  107.         setVerbXY(160,145);
  108.         setVerbColor(color);
  109.         setVerbHiColor(hiColor);
  110.         verbCenter();
  111.  
  112.         setCurrentVerb(WalkTo);
  113.         initVerb();
  114.         setVerbName("Walk to");
  115.         setVerbKey('w');
  116.  
  117.         setCurrentVerb(Give);
  118.         initVerb();
  119.         setVerbName("Give");
  120.         setVerbXY(10,156);
  121.         setVerbColor(color);
  122.         setVerbHiColor(hiColor);
  123.         setVerbDimColor(dimColor);
  124.         setVerbKey('g');
  125.         
  126.         setCurrentVerb(PickUp);
  127.         initVerb();
  128.         setVerbName("Pick up");
  129.         setVerbXY(50,156);
  130.         setVerbColor(color);
  131.         setVerbHiColor(hiColor);
  132.         setVerbDimColor(dimColor);
  133.         setVerbKey('p');
  134.  
  135.         setCurrentVerb(Use);
  136.         initVerb();
  137.         setVerbName("Use");
  138.         setVerbXY(100,156);
  139.         setVerbColor(color);
  140.         setVerbHiColor(hiColor);
  141.         setVerbDimColor(dimColor);
  142.         setVerbKey('u');
  143.  
  144.         setCurrentVerb(Open);
  145.         initVerb();
  146.         setVerbName("Open");
  147.         setVerbXY(10,170);
  148.         setVerbColor(color);
  149.         setVerbHiColor(hiColor);
  150.         setVerbDimColor(dimColor);
  151.         setVerbKey('o');
  152.  
  153.         setCurrentVerb(LookAt);
  154.         initVerb();
  155.         setVerbName("Look at");
  156.         setVerbXY(50,170);
  157.         setVerbColor(color);
  158.         setVerbHiColor(hiColor);
  159.         setVerbDimColor(dimColor);
  160.         setVerbKey('l');
  161.  
  162.         setCurrentVerb(Push);
  163.         initVerb();
  164.         setVerbName("Push");
  165.         setVerbXY(100,170);
  166.         setVerbColor(color);
  167.         setVerbHiColor(hiColor);
  168.         setVerbDimColor(dimColor);
  169.         //setVerbKey('');
  170.  
  171.         setCurrentVerb(Close);
  172.         initVerb();
  173.         setVerbName("Close");
  174.         setVerbXY(10,184);
  175.         setVerbColor(color);
  176.         setVerbHiColor(hiColor);
  177.         setVerbDimColor(dimColor);
  178.         setVerbKey('c');
  179.  
  180.         setCurrentVerb(TalkTo);
  181.         initVerb();
  182.         setVerbName("Talk to");
  183.         setVerbXY(50,184);
  184.         setVerbColor(color);
  185.         setVerbHiColor(hiColor);
  186.         setVerbDimColor(dimColor);
  187.         setVerbKey('t');
  188.  
  189.         setCurrentVerb(Pull);
  190.         initVerb();
  191.         setVerbName("Pull");
  192.         setVerbXY(100,184);
  193.         setVerbColor(color);
  194.         setVerbHiColor(hiColor);
  195.         setVerbDimColor(dimColor);
  196.         //setVerbKey('');
  197.  
  198.         setCurrentVerb(invUp);
  199.         initVerb();
  200.         setVerbName("\x03");
  201.         setVerbXY(135,160);
  202.         setVerbColor(color);
  203.         setVerbHiColor(hiColor);
  204.         setVerbDimColor(dimColor);
  205.         //verbCenter();
  206.  
  207.         setCurrentVerb(invDown);
  208.         initVerb();
  209.         setVerbName("\x02");
  210.         setVerbXY(135,182);
  211.         setVerbColor(color);
  212.         setVerbHiColor(hiColor);
  213.         setVerbDimColor(dimColor);
  214.         //verbCenter();
  215.         
  216.  
  217.         for(l = 0,vrb = invSlot0 ; l < 2 ; l++)
  218.             for(c = 0 ; c < 4 ; c++, vrb++) {
  219.                 setCurrentVerb(vrb);
  220.                 initVerb();
  221.                 //verbCenter();
  222.                 setVerbXY(160 + c*40,160 + l*20);
  223.             }
  224.         dimInt(invObj,8);
  225.  
  226.     }
  227.  
  228.     // turn on all the verb for the interface 
  229.     // and fire the mouse watching thread
  230.     script showVerbs(int show) {
  231.         int* vrb;
  232.         int i;
  233.        
  234.         if(!!show == verbsOn) return;
  235.  
  236.         vrb[0] = [ Give, PickUp, Use, Open,
  237.                    LookAt, Push, Close, TalkTo,
  238.                    Pull, SntcLine, invUp, invDown ];
  239.         
  240.         for(i = 0 ; i < 12 ; i++) {
  241.             setCurrentVerb(vrb[i]);
  242.             if(show)
  243.                 setVerbOn();
  244.             else
  245.                 setVerbOff();
  246.             redrawVerb();
  247.         }
  248.         undim(vrb);
  249.  
  250.         for(i = 0 ; i < 8 ; i++) {
  251.             setCurrentVerb(invSlot0+i);
  252.             if(show)
  253.                 setVerbOn();
  254.             else
  255.                 setVerbOff();
  256.             redrawVerb();
  257.         }
  258.  
  259.         verbsOn = !!show;
  260.  
  261.     }
  262.  
  263.  
  264.     // this script run in the background cheking where the mouse is
  265.     // and update the sentence and set the alt verb
  266.     script mouseWatch() {
  267.         int vrb,obj,target,alt;
  268.  
  269.         // we run forever (well until someone kill us)
  270.         while(1) {
  271.             unless(cursorOn) {
  272.                 if(altVerb) {
  273.                     setCurrentVerb(altVerb);
  274.                     setVerbOn();
  275.                     redrawVerb();
  276.                     altVerb = 0;
  277.                 }
  278.                 do breakScript() until(cursorOn);
  279.                         
  280.             }
  281.             if(isScriptRunning(VAR_SENTENCE_SCRIPT)) {
  282.                  breakScript();
  283.                 continue;
  284.             }
  285.  
  286.             // read the current state
  287.  
  288.             // find what verb should be displayed and the
  289.             // object under the pointer
  290.             vrb = 0;
  291.             obj = getActorAt(VAR_VIRT_MOUSE_X,VAR_VIRT_MOUSE_Y);
  292.             if(obj == VAR_EGO)
  293.                 obj = 0;
  294.             unless(obj)
  295.                 obj = getObjectAt(VAR_VIRT_MOUSE_X,VAR_VIRT_MOUSE_Y);
  296.             unless(obj) {
  297.                 obj = getVerbAt(VAR_MOUSE_X,VAR_MOUSE_Y);
  298.                 if(obj >= invSlot0 && obj <= invSlot7) {
  299.                     obj = findInventory(VAR_EGO,obj-invSlot0+1);
  300.                     if(!selVerb || selVerb == PickUp)
  301.                         vrb = Use;
  302.                     else
  303.                         vrb = selVerb;
  304.                 } else
  305.                     obj = 0;
  306.             }
  307.             unless(vrb)
  308.                 vrb = selVerb ? selVerb : WalkTo;                    
  309.             
  310.             if(sntcPrepo) {
  311.                 target = sntcObjB;
  312.                 if(obj == sntcObjA) obj = 0;
  313.             } else target = sntcObjA;
  314.             
  315.             //dbgPrint("%i{vrb} <> %i{sntcVerb} | %i{obj} <> %i{target}");
  316.             unless(vrb == sntcVerb && obj == target) {
  317.                 sntcVerb = vrb;
  318.                 if(sntcPrepo) sntcObjB = obj;
  319.                 else sntcObjA = obj;
  320.                 setCurrentVerb(SntcLine);
  321.                 redrawVerb();
  322.             }
  323.  
  324.  
  325.             if(obj) {
  326.                 if(obj <= 0xF)
  327.                     alt = TalkTo;
  328.                 else if(obj is Openable)
  329.                     alt = getObjectState(obj) ? Close : Open;
  330.                 else
  331.                     alt = LookAt;
  332.             } else
  333.                 alt = 0;
  334.  
  335.             if(alt != altVerb) {
  336.                 if(altVerb) {
  337.                     setCurrentVerb(altVerb);
  338.                     setVerbOn();
  339.                     redrawVerb();
  340.                 }
  341.                 if(alt) {
  342.                     setCurrentVerb(alt);
  343.                     verbDim();
  344.                     redrawVerb();
  345.                 }
  346.                 altVerb = alt;
  347.             }
  348.  
  349.             breakScript();
  350.         }
  351.     }
  352.  
  353.  
  354.     // setup the cursor
  355.     script showCursor() {
  356.         
  357.         if(cursorOn) return;
  358. /*
  359.         unless(cursorLoaded) {
  360.             cursorLoaded = 1;
  361.             loadFlObject(cursor,ResRoom);
  362.             setCursorImage(cursor,ResRoom);
  363.             setCursorTransparency(31);
  364.         }
  365. */
  366.         cursorOn();
  367.         userPutOn();
  368.         cursorOn = 1;
  369.     }
  370.  
  371.     script hideCursor() {
  372.         unless(cursorOn) return;
  373.         
  374.         cursorOff();
  375.         userPutOff();
  376.         cursorOn = 0;
  377.     }
  378.  
  379.     script cutsceneStart(int type) {
  380.         dbgPrint("cutscene start");
  381.         hideCursor();
  382.         if(type > 0) {
  383.             // We need to break here to make sure the mouse watch script
  384.             // stop. Otherwise it might turn on the alt verb again,
  385.             breakScript();
  386.             showVerbs(0);
  387.         }
  388.     }
  389.  
  390.     script cutsceneEnd(int type) {
  391.         dbgPrint("cutscene end");
  392.         showCursor();
  393.         if(type > 1)
  394.             showVerbs(1);
  395.     }
  396.  
  397.     script resetSntc(int vrb) {
  398.         sntcObjA = 0;
  399.         if(sntcPrepo) {
  400.             undim(sntcPrepo);
  401.             sntcObjB = 0;
  402.         }
  403.         selVerb = vrb;
  404.         setCurrentVerb(SntcLine);
  405.         redrawVerb();
  406.     }
  407.  
  408.     script defaultAction(int vrb, int objA, int objB) {
  409.         switch(vrb) {
  410.         case WalkTo:
  411.             return;
  412.             
  413.         case PickUp:
  414.             if(objA <= 0xF)
  415.                 egoSay("I can't carry him around.");
  416.             else
  417.                 egoSay("I can't pick that up.");
  418.             break;
  419.             
  420.         case Use:
  421.             if(objA <= 0xF) {
  422.                 if(objB)
  423.                     egoSay("I can't use that on someone!");
  424.                 else
  425.                     egoSay("I can't just *use* someone!");
  426.             } else
  427.                 egoSay("I can't use that !");
  428.             break;
  429.             
  430.         case LookAt:
  431.             if(objA <= 0xF)
  432.                 egoSay("There is nothing special about him.");
  433.             else
  434.                 egoSay("There is nothing special about it.");
  435.             break;
  436.             
  437.         case Push:
  438.         case Pull:
  439.             if(objA <= 0xF)
  440.                 egoSay("That wouldn't be very nice.");
  441.             else
  442.                 egoSay("I don't feel in shape today.");
  443.             break;
  444.             
  445.         case Open:
  446.             if(objA <= 0xF) {
  447.                 egoSay("You know these human bodies aren't very resistant, if i open it he might die.");
  448.                 break;
  449.             }
  450.             if(objA is !Openable) {
  451.                 egoSay("It's not the kind of thing that can be opened.");
  452.                 break;
  453.             }
  454.             if(getObjectState(objA)) {
  455.                 egoSay("It's already open.");
  456.                 break;
  457.             }
  458.             // some sound would be nice
  459.             setObjectState(objA,1);
  460.             if(getObjectVerbEntrypoint(objA,SetBoxes))
  461.                 startObject2(objA,SetBoxes, [ vrb, objA ]);
  462.             break;
  463.             
  464.         case Close:
  465.             if(objA <= 0xF) {
  466.                 egoSay("Closing someone ?\wThat hardly make any sense.");
  467.                 break;
  468.             }            
  469.             if(objA is !Openable) {
  470.                 egoSay("I don't think that this can be closed.");
  471.                 break;
  472.             }
  473.             unless(getObjectState(objA)) {
  474.                 egoSay("It's already closed.");
  475.                 break;
  476.             }
  477.             setObjectState(objA,0);
  478.             if(getObjectVerbEntrypoint(objA,SetBoxes))
  479.                 startObject2(objA,SetBoxes, [ vrb, objA ]);
  480.             break;
  481.                 
  482.         default:
  483.             egoSay("Hmm. No.");
  484.             break;
  485.         }
  486.         waitForMessage();
  487.     }
  488.  
  489.     // the sentence script, doSentence call it
  490.     script sentenceHandler(int vrb, int objA, int objB) {
  491.         int owner,tmp,act;
  492.  
  493.         // click on the sentence line, make it as if the user
  494.         // clicked the currently selected objects
  495.         if(vrb == SntcLine) {
  496.             vrb = sntcVerb;
  497.             objA = sntcObjA;
  498.             objB = sntcObjB;
  499.         }
  500.  
  501.         // look who own the object
  502.         owner = getObjectOwner(objA);
  503.  
  504.         // with use and give we must own it first
  505.         while(isAnyOf(vrb, [ Use, Give ])) {
  506.             unless(objB) {
  507.                 if(getObjectVerbEntrypoint(objA,Preposition)) {
  508.                     startObject2(objA,Preposition,[ vrb, objA ]);
  509.                     if(sntcPrepo) {
  510.                         setCurrentVerb(SntcLine);
  511.                         redrawVerb();
  512.                         return;
  513.                     }
  514.                 }
  515.                 break;
  516.             }
  517.  
  518.             // we must pick it up first
  519.             if(owner != VAR_EGO) {
  520.                 if(tryPick == objA) { // pickup failed
  521.                     tryPick = 0;
  522.                     return;
  523.                 }
  524.                 // try to pickup then do our action again
  525.                 tryPick = objA;
  526.                 doSentence(vrb,objA,0,objB);
  527.                 doSentence(PickUp,objA,0,0);
  528.                 return;
  529.             } else
  530.                 tryPick = 0;
  531.             break;
  532.         }
  533.         
  534.         // if the object is in the room walk there
  535.         if(objA <= 0xF || owner == 0xF) {
  536.             walkActorToObj(VAR_EGO,objA,0);
  537.             waitForActor(VAR_EGO);
  538.             // This is needed when walking to an actor
  539.             if(objA <= 0xF)
  540.                 actorFace(VAR_EGO,objA);
  541.         } else if(objB) if(objB <= 0xF || getObjectOwner(objB) == 0xF) {
  542.             walkActorToObj(VAR_EGO,objB,0);
  543.             waitForActor(VAR_EGO);
  544.             if(objB <= 0xF)
  545.                 actorFace(VAR_EGO,objB);
  546.         }
  547.  
  548.         // switch the objects
  549.         if(objB) {
  550.             dbgPrint("Switch objects");
  551.             tmp = objA;
  552.             objA = objB;
  553.             objB = tmp;
  554.         }
  555.  
  556.         // Take the actorObject if it exist
  557.         if(objA <= 0xF) if(actorObject[objA]) {
  558.             act = objA;
  559.             objA = actorObject[objA];
  560.         }
  561.  
  562.         // if the object implement the verb call that
  563.         if(getObjectVerbEntrypoint(objA,vrb)) {
  564.             startObject(2,objA,vrb,[ vrb, objA, objB ]);
  565.             // if the verb locked the cursor wait until its unlocked
  566.             do breakScript() until(cursorOn);
  567.         } else {
  568.             //otherwise use our default:
  569.             defaultAction(vrb, act ? act : objA, objB);
  570.  
  571.         }
  572.         // if the verb need objB we are done for now
  573.         if(sntcPrepo && !objB) return;
  574.  
  575.         // all done, reset the sentence
  576.         resetSntc(0);
  577.     }
  578.  
  579.     script keyboardHandler(int key) {
  580.         switch(key) {
  581.         case 'o':
  582.             egoSay("Hooo");
  583.             break;
  584.         case 'r':
  585.             egoSay("Let's restart.");
  586.             waitForMessage();
  587.             restartGame();
  588.             break;
  589.         case 'q':
  590.             shutdown();
  591.             break;
  592.         }
  593.     }
  594.  
  595.     // This script receive the keyboard and mouse events
  596.     script inputHandler(int area,int cmd, int btn) {
  597.         int vrb,obj,objB,x;
  598.  
  599.         dbgPrintBegin();
  600.         dbgPrint("Area=%i{area} cmd=%i{cmd} button=%i{btn}");
  601.         dbgPrintEnd();
  602.  
  603.         egoPrintBegin();
  604.         egoPrintOverhead();
  605.         actorPrintEnd();
  606.  
  607.         if(area == 4) { // area 4 is the keyboard
  608.             keyboardHandler(cmd);
  609.             return;
  610.         }
  611.  
  612.         // A verb was clicked
  613.         if(isAnyOf(cmd, [ Give,  PickUp, Use, 
  614.                           Open,  LookAt, Push,
  615.                           Close, TalkTo, Pull ])) {
  616.             resetSntc(cmd);
  617.             return;
  618.         }
  619.  
  620.         // now are left: room click and inventory
  621.         // stop any currently running sentence
  622.         stopSentence();
  623.         // (re)start the mouse script, giving it a chance to update
  624.         // the sentence.
  625.         // Note that it's a non recursive call hence it will kill the script
  626.         // then start it again.
  627.         mouseWatch();
  628.  
  629.         // button 2 was cliked but not on an object: cancel
  630.         if(btn == 2) unless(sntcPrepo ? sntcObjB : sntcObjA) {
  631.             // stop walking
  632.             setCurrentActor(VAR_EGO);
  633.             setActorStanding();
  634.             resetSntc(0);
  635.             return;
  636.         }
  637.  
  638.         // an object was cliked
  639.         if(sntcPrepo ? sntcObjB : sntcObjA) {
  640.             // an inventory object was cliked
  641.             // select the verb that is displayed
  642.             // We need this to keep Use when PickUp
  643.             // was originaly selected
  644.             if(cmd) selVerb = sntcVerb;
  645.             // button 2: select the alternat verb
  646.             if(btn == 2 && altVerb) {
  647.                 selVerb = altVerb;
  648.                 mouseWatch();
  649.             }
  650.             // queue the sentence
  651.             doSentence(sntcVerb,sntcObjA,0,sntcObjB);
  652.             return;
  653.         }
  654.         // click on nothing, ignore non room clicks
  655.         if(area != 2) return;
  656.  
  657.         // reset the sentence so we get WalkTo again
  658.         if(selVerb) resetSntc(0);
  659.         
  660.         // then go there
  661.         walkActorTo(VAR_EGO,VAR_VIRT_MOUSE_X,VAR_VIRT_MOUSE_Y);
  662.     }
  663.  
  664.     script setInventoryIcon(int icon, int slot) {
  665.         setCurrentVerb(slot);
  666.         setVerbObject(icon,ResRoom);
  667.         redrawVerb();
  668.     }
  669.  
  670.     script inventoryHandler(int obj) {
  671.         int i, count;
  672.         //unless(obj) return;
  673.  
  674.         count = getInventoryCount(hero);
  675.  
  676.         dbgPrint("%i{count} obj in inv");
  677.  
  678.  
  679.         for(i = 0 ; i < 8 ; i++) {
  680.             if(i < count) {
  681.                 obj = findInventory(hero,i+1);
  682.                 startObject2(obj,Icon, [ setInventoryIcon, invSlot0+i ]);
  683.             } else {
  684.                 setCurrentVerb(invSlot0+i);
  685.                 setVerbNameString(0);
  686.                 redrawVerb();
  687.             }
  688.         }
  689.  
  690.     }
  691.  
  692.     //
  693.     // Dialogs stuff
  694.     //
  695.  
  696.     // Reset the dialog list
  697.     script dialogClear(int kill) {
  698.         int i;
  699.         if(dialogList) {
  700.             if(kill) {
  701.                 for(i = 0 ; i < numDialog ; i++)
  702.                     undim(dialogList[i]);
  703.             }
  704.             undim(dialogList);
  705.             dialogList = 0;
  706.         }
  707.         numDialog = numActiveDialog = 0;
  708.     }
  709.  
  710.     // Add an entry to the dialog list
  711.     script dialogAdd(char* str) {
  712.         if(numDialog >= MAX_DIALOG_SENTENCE) {
  713.             dbgPrint("Too many sentences, can't add another one.");
  714.             return;
  715.         }
  716.         unless(dialogList)
  717.             dimInt(dialogList,MAX_DIALOG_SENTENCE);
  718.         dialogList[numDialog] = str;
  719.         numDialog++;
  720.         if(str) numActiveDialog++;
  721.     }
  722.  
  723.     // Remove an entry, if kill is not zero undim the string too
  724.     script dialogRemove(int idx, int kill) {
  725.         int i;
  726.         if(idx < 0 || idx >= numDialog) {
  727.          dbgPrint("Dialog index out of range: %i{idx}, can't remove.");
  728.          return;
  729.         }
  730.         if(dialogList[idx]) {
  731.             numActiveDialog--;
  732.             // Remove the string from the array
  733.             if(kill)
  734.                 undim(dialogList[idx]);
  735.             dialogList[idx] = 0;
  736.         }
  737.         // shift the res
  738.         for(i = idx+1 ; i < numDialog ; i++)
  739.             dialogList[i-1] = dialogList[i];
  740.         numDialog--;
  741.     }
  742.  
  743.     script showDialog() {
  744.         int i,v,d,first,last,firstSentence,lastSentence;
  745.  
  746.         first = last = -1;
  747.         firstSentence = lastSentence = -1;
  748.         // switch the charset
  749.         initCharset(dialogCharset);
  750.         // Dialog lines
  751.         v = 0;
  752.         for(i = 0 ; i < numDialog ; i++) {
  753.             unless(dialogList[i]) continue;
  754.             if(firstSentence < 0) firstSentence = i;
  755.             lastSentence = i;
  756.             if(v < dialogOffset || v >= dialogOffset+MAX_DIALOG_LINES) {
  757.                 v++;
  758.                 continue;
  759.             }
  760.             if(first < 0) first = i;
  761.             last = i;
  762.             setCurrentVerb(dialogVerb0 + d);
  763.             initVerb();
  764.             setVerbNameString(dialogList[i]);
  765.             setVerbXY(12,145+11*d);
  766.             setVerbColor(dialogColor);
  767.             setVerbHiColor(dialogHiColor);
  768.             setVerbOn();
  769.             redrawVerb();
  770.             v++, d++;
  771.         }
  772.         for( ; d < MAX_DIALOG_LINES ; d++) {
  773.             setCurrentVerb(dialogVerb0 + d);
  774.             setVerbOff();
  775.             redrawVerb();
  776.         }
  777.         dbgPrint("Sentence: %i{firstSentence} %i{lastSentence}");
  778.         dbgPrint("Shown: %i{first} %i{last}");
  779.        
  780.         // Up arrow
  781.         setCurrentVerb(dialogUp);
  782.         if(first > firstSentence) {
  783.             initVerb();
  784.             setVerbName("\x03");
  785.             setVerbXY(2,145);
  786.             setVerbColor(dialogColor);
  787.             setVerbHiColor(dialogHiColor);
  788.             setVerbOn();
  789.             redrawVerb();
  790.         } else {
  791.             setVerbOff();
  792.             redrawVerb();
  793.         }            
  794.         // Down arrow
  795.         setCurrentVerb(dialogDown);
  796.         if(last < lastSentence) {
  797.             initVerb();
  798.             setVerbName("\x02");
  799.             setVerbXY(2,145+4*11);
  800.             setVerbColor(dialogColor);
  801.             setVerbHiColor(dialogHiColor);
  802.             setVerbOn();
  803.             redrawVerb();
  804.         } else {
  805.             setVerbOff();
  806.             redrawVerb();
  807.         }
  808.         
  809.         initCharset(chtest);
  810.  
  811.     }
  812.  
  813.     script dialogInputHandler(int area,int cmd, int btn) {
  814.         int i,v,d;
  815.  
  816.         dbgPrintBegin();
  817.         dbgPrint("Area=%i{area} cmd=%i{cmd} button=%i{btn}");
  818.         dbgPrintEnd();
  819.  
  820.         egoPrintBegin();
  821.         egoPrintOverhead();
  822.         actorPrintEnd();
  823.  
  824.         if(area == 4) { // area 4 is the keyboard
  825.             keyboardHandler(cmd);
  826.             return;
  827.         }
  828.  
  829.         if(cmd == dialogUp || cmd == dialogDown) {
  830.             dialogOffset += (cmd == dialogUp ? -1 : 1)*MAX_DIALOG_LINES/2;
  831.             if(dialogOffset > numActiveDialog-MAX_DIALOG_LINES)
  832.                 dialogOffset = numActiveDialog-MAX_DIALOG_LINES;
  833.             if(dialogOffset < 0) dialogOffset = 0;
  834.             dbgPrint("Dialog offset: %i{dialogOffset}");
  835.             showDialog();
  836.             return;
  837.         }
  838.         
  839.         if(cmd < dialogVerb0 || cmd > dialogVerb4)
  840.             return;
  841.  
  842.         // Find the selected sentence
  843.         for(i = 0 ; i < numDialog ; i++) {
  844.             unless(dialogList[i]) continue;
  845.             if(v < dialogOffset || v >= dialogOffset+MAX_DIALOG_LINES) {
  846.                 v++;
  847.                 continue;
  848.             }
  849.             if(d == cmd-dialogVerb0) break;
  850.             v++, d++;
  851.         }
  852.  
  853.         selectedSentence = i;
  854.     }
  855.  
  856.     // Start a dialog
  857.     script dialogStart(int color, int hiColor) {
  858.         int i;
  859.         selectedSentence = -1;
  860.         dialogOffset = 0;
  861.         if(numDialog < 1) {
  862.             dbgPrint("No dialog was setup, nothing to show.");
  863.             selectedSentence = -2;
  864.             return;
  865.         }
  866.         // Hide the normal verbs/inventory
  867.         showVerbs(0);
  868.         // Show our stuff
  869.         // setup the verbs
  870.         dialogColor = color ? color : VERB_COLOR;
  871.         dialogHiColor = hiColor ? hiColor : VERB_HI_COLOR;
  872.         showDialog();
  873.         // Kill the mouseWatch
  874.         if(isScriptRunning(mouseWatch))
  875.             stopScript(mouseWatch);
  876.         // Set the dialog input handler
  877.         VAR_VERB_SCRIPT = dialogInputHandler;
  878.     }
  879.  
  880.     script dialogHide() {
  881.         int i;
  882.         for(i = 0 ; i < MAX_DIALOG_LINES ; i++) {
  883.             setCurrentVerb(dialogVerb0 + i);
  884.             setVerbOff();
  885.             redrawVerb();
  886.         }
  887.         setCurrentVerb(dialogUp);
  888.         setVerbOff();
  889.         redrawVerb();
  890.         setCurrentVerb(dialogDown);
  891.         setVerbOff();
  892.         redrawVerb();
  893.     }
  894.  
  895.     script dialogEnd() {
  896.         dialogHide();
  897.         showVerbs(1);
  898.         VAR_VERB_SCRIPT = inputHandler;
  899.         // Restart the mouse watching thread
  900.         mouseWatch();
  901.     }
  902.  
  903.     // The main script is the first thing started by the engine.
  904.     // At that point no room is loaded yet.
  905.     script main (int bootParam) {
  906.         int i,j;
  907.  
  908.         //trace(1,"main");
  909.         // First setup the engine a bit
  910.         // set the F5 key for the main menu
  911.         VAR_MAINMENU_KEY = 319;
  912.         // set the . key to skip text
  913.         VAR_TALKSTOP_KEY = 46;
  914.         // set F8 as the restart key
  915.         VAR_RESTART_KEY = 322;
  916.         // pause key can also be defined in that way instead of
  917.         // doing it in the key handler as we did.
  918.         VAR_PAUSE_KEY = ' ';
  919.         // skip a cutscene
  920.         VAR_CUTSCENEEXIT_KEY = 27;
  921.  
  922.         VAR_GAME_VERSION = 0;
  923.         VAR_GUI_COLORS[0] = [ 0x00, 0x00, 0x43, 0x00, 0xD7, 0x34, 0x52, 0x90, 0x00, 0x6A,
  924.                               0x06, 0x1A, 0xD5, 0xE5, 0xE3, 0xE5, 0xE3, 0xE5, 0xE3, 0xE5,
  925.                               0xE3, 0x00, 0x00, 0x00, 0x00, 0x14, 0xD7, 0xE5, 0xE3, 0xE5,
  926.                               0xE3, 0x37, 0x1C, 0xE5, 0xE3, 0xE5, 0xE3, 0x14, 0xD7, 0xE5,
  927.                               0xE3, 0xE5, 0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ];
  928. //                     0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6 ];
  929.  
  930.  
  931.  
  932.         VAR_DEBUG_PASSWORD[0] = "";
  933.         //VAR_DEBUG_PASSWORD[0] = "pass";
  934.         //for(i = 0 ; VAR_DEBUG_PASSWORD[i] != 0 ; i++)
  935.         //    VAR_DEBUG_PASSWORD[i] = VAR_DEBUG_PASSWORD[i] - 'c';
  936.       
  937.  
  938.         // setup the GUI
  939.         VAR_PAUSE_MSG[0] = "ScummC Paused !";
  940.         VAR_QUIT_MSG[0] = "Are you sure you want to quit ? (Y/N)Y";
  941.         VAR_RESTART_MSG[0] = "Are you sure you want to restart ? (Y/N)Y";
  942.  
  943.         VAR_SAVE_BTN[0] = "Save it";
  944.         VAR_LOAD_BTN[0] = "Load it";
  945.         VAR_PLAY_BTN[0] = "Continue";
  946.         VAR_CANCEL_BTN[0] = "Cancel";
  947.         VAR_QUIT_BTN[0] = "Quit";
  948.         VAR_OK_BTN[0] = "Ok";
  949.  
  950.         VAR_SAVE_MSG[0] = "Saveing '%%s'";
  951.         VAR_LOAD_MSG[0] = "Loading '%%s'";
  952.  
  953.         VAR_MAIN_MENU_TITLE[0] = "ScummC test Menu";
  954.         VAR_SAVE_MENU_TITLE[0] = "Save game";
  955.         VAR_LOAD_MENU_TITLE[0] = "Load game";
  956.  
  957.         VAR_NOT_SAVED_MSG[0] = "Game NOT saved";
  958.         VAR_NOT_LOADED_MSG[0] = "Game NOT loaded";
  959.  
  960.         VAR_GAME_DISK_MSG[0] = "Insert disk %%c";
  961.         VAR_ENTER_NAME_MSG[0] = "You must enter a name";
  962.         VAR_SAVE_DISK_MSG[0] = "Insert your save disk";
  963.  
  964.         VAR_OPEN_FAILED_MSG[0] = "Failed to open %%s (%%c%%d)";
  965.         VAR_READ_ERROR_MSG[0] = "Read error on disk %%c (%%c%%d)";
  966.  
  967.         // set the main loop speed
  968.         VAR_TIMER_NEXT = 2;
  969.         
  970.         // set the input handler
  971.         VAR_VERB_SCRIPT = inputHandler;
  972.         VAR_SENTENCE_SCRIPT = sentenceHandler;
  973.         VAR_INVENTORY_SCRIPT = inventoryHandler;
  974.         VAR_CUTSCENE_START_SCRIPT = cutsceneStart;
  975.         VAR_CUTSCENE_END_SCRIPT = cutsceneEnd;
  976.  
  977.         // keep this room in memory even if we leave it,
  978.         // as it contain the charset, costume, etc
  979.         // it's probably not very useful atm bcs we only have one
  980.         // room, but well :)
  981.         loadRoom(ResRoom);
  982.         lockRoom(ResRoom);
  983.  
  984.         loadCostume(egoCost);
  985.         lockCostume(egoCost);
  986.  
  987.         loadRoom(Road);
  988.         lockRoom(Road);
  989.  
  990.         // Initialize the graphic mode.
  991.         // It need to match the room image height otherwise
  992.         // the graphics are going wacky
  993.         setScreen(0,144);
  994.         //setScreen(44,188);
  995.  
  996.         // Create the actor -> obj link
  997.         dimInt(actorObject,0x10);
  998.  
  999.         // init the charset
  1000.         //initCharset(chset1);
  1001.         initCharset(chtest);
  1002.  
  1003.  
  1004.         setupActors();
  1005.         setupVerbs();
  1006.  
  1007.         mouseWatch();
  1008.  
  1009.         // do the box effect
  1010.         screenEffect(0x0005);
  1011.         // start the room
  1012.         startRoom(Road);
  1013.     }
  1014.  
  1015. }
  1016.