home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / chip_20022115.iso / amiga / chipgame / scummvm_aga.lha / ScummVM_AGA / src / verbs.cpp < prev   
Encoding:
C/C++ Source or Header  |  2002-01-05  |  6.7 KB  |  282 lines

  1. /* ScummVM - Scumm Interpreter
  2.  * Copyright (C) 2001  Ludvig Strigeus
  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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  *
  18.  * $Header: /cvsroot/scummvm/scummvm/verbs.cpp,v 1.8 2001/11/08 18:37:42 strigeus Exp $
  19.  *
  20.  */
  21.  
  22. #include "stdafx.h"
  23. #include "scumm.h"
  24.  
  25. void Scumm::redrawVerbs() {
  26.     int i;
  27.     for (i=0; i<_maxVerbs; i++)
  28.         drawVerb(i, 0);
  29.     verbMouseOver(0);
  30. }
  31.  
  32. void Scumm::checkExecVerbs() {
  33.     int i,over;
  34.     VerbSlot *vs;
  35.  
  36.     if (_userPut<=0 || _mouseButStat==0)
  37.         return;
  38.  
  39.     if (_mouseButStat < 0x200) {
  40.         /* Check keypresses */
  41.         vs = &_verbs[1];
  42.         for (i=1; i<_maxVerbs; i++,vs++) {
  43.             if (vs->verbid && vs->saveid==0 && vs->curmode==1) {
  44.                 if (_mouseButStat == vs->key) {
  45.                     runInputScript(1, vs->verbid, 1);
  46.                     return;
  47.                 }
  48.             }
  49.         }
  50.         runInputScript(4, _mouseButStat, 1);
  51.     } else if (_mouseButStat&0xC000) {
  52.         byte code = _mouseButStat&0x8000 ? 1 : 2;
  53.         if (mouse.y >= virtscr[0].topline && mouse.y < virtscr[0].topline + virtscr[0].height) {
  54.             over = checkMouseOver(mouse.x, mouse.y);
  55.             if (over != 0) {
  56.                 runInputScript(1,_verbs[over].verbid,code);
  57.                 return;
  58.             }
  59.             runInputScript(2, 0, code);
  60.         } else {
  61.             over=checkMouseOver(mouse.x, mouse.y);
  62.             runInputScript(1, over!=0 ? _verbs[over].verbid : 0, code);
  63.         }
  64.     }
  65. }
  66.  
  67. void Scumm::verbMouseOver(int verb) {
  68.     if (_verbMouseOver==verb)
  69.         return;
  70.  
  71.     if (_verbs[_verbMouseOver].type!=1) {
  72.         drawVerb(_verbMouseOver, 0);
  73.         _verbMouseOver = verb;
  74.     }
  75.  
  76.     if (_verbs[verb].type!=1 && _verbs[verb].hicolor) {
  77.         drawVerb(verb, 1);
  78.         _verbMouseOver = verb;
  79.     }
  80. }
  81.  
  82. int Scumm::checkMouseOver(int x, int y) {
  83.     VerbSlot *vs;
  84.     int i = _maxVerbs-1;
  85.  
  86.     vs = &_verbs[i];
  87.     do {
  88.         if (vs->curmode!=1 || !vs->verbid || vs->saveid ||
  89.                 y < vs->y || y >= vs->bottom)
  90.                 continue;
  91.         if (vs->center) {
  92.             if (x < -(vs->right - vs->x - vs->x) || x >= vs->right)
  93.                     continue;
  94.         } else {
  95.             if (x < vs->x || x >= vs->right)
  96.                 continue;
  97.         }
  98.         return i;
  99.     } while (--vs,--i);
  100.     return 0;
  101. }
  102.  
  103. void Scumm::drawVerb(int vrb, int mode) {
  104.     VerbSlot *vs;
  105.     byte color;
  106.     byte tmp;
  107.  
  108.     if (!vrb)
  109.         return;
  110.  
  111.     vs = &_verbs[vrb];
  112.  
  113.     if (!vs->saveid && vs->curmode && vs->verbid) {
  114.         if (vs->type==1) {
  115.             drawVerbBitmap(vrb, vs->x, vs->y);
  116.             return;
  117.         }
  118.         restoreVerbBG(vrb);
  119.  
  120.         string[4].charset = vs->charset_nr;
  121.         string[4].xpos = vs->x;
  122.         string[4].ypos = vs->y;
  123.         string[4].right = 319;
  124.         string[4].center = vs->center;
  125.         if (mode && vs->hicolor)
  126.             color = vs->hicolor;
  127.         else
  128.             color = vs->color;
  129.         string[4].color = color;
  130.         if (vs->curmode==2)
  131.             string[4].color = vs->dimcolor;
  132.         _messagePtr = getResourceAddress(rtVerb, vrb);
  133.         assert(_messagePtr);
  134.         tmp = charset._center;
  135.         charset._center = 0;
  136.         drawString(4);
  137.         charset._center = tmp;
  138.         vs->right = charset._strRight;
  139.         vs->bottom = charset._strBottom;
  140.         vs->oldleft = charset._strLeft;
  141.         vs->oldright = charset._strRight;
  142.         vs->oldtop = charset._strTop;
  143.         vs->oldbottom = charset._strBottom;
  144.         charset._strLeft = charset._strRight;
  145.     } else {
  146.         restoreVerbBG(vrb);
  147.     }
  148. }
  149.  
  150. void Scumm::restoreVerbBG(int verb) {
  151.     VerbSlot *vs;
  152.  
  153.     vs = &_verbs[verb];
  154.  
  155.     if (vs->oldleft != -1) {
  156.         _bkColor = vs->bkcolor;
  157.         restoreBG(vs->oldleft, vs->oldtop, vs->oldright, vs->oldbottom);
  158.         vs->oldleft = -1;
  159.     }
  160. }
  161.  
  162. void Scumm::drawVerbBitmap(int vrb, int x, int y) {
  163.     int nozbufs;
  164.     VirtScreen *vs;
  165.     VerbSlot *vst;
  166.     byte twobufs, *imptr;
  167.     int ydiff, xstrip;
  168.     int imgw, imgh;
  169.     int i,tmp;
  170.     byte *IMHD_ptr;
  171.     byte *obim;
  172.  
  173.     if ((vs=findVirtScreen(y)) == NULL)
  174.         return;
  175.  
  176.     _lastXstart = virtscr[0].xstart;
  177.     
  178.     gdi.disableZBuffer();
  179.  
  180.     twobufs = vs->alloctwobuffers;
  181.     vs->alloctwobuffers = 0;
  182.  
  183.     xstrip = x>>3;
  184.     ydiff = y - vs->topline;
  185.  
  186.  
  187.     obim = getResourceAddress(rtVerb, vrb);
  188.     IMHD_ptr = findResource(MKID('IMHD'), obim, 0);
  189.  
  190.     imgw = READ_LE_UINT16(IMHD_ptr+0x14) >> 3;
  191.     imgh = READ_LE_UINT16(IMHD_ptr+0x16) >> 3;
  192.     
  193.     imptr = findResource(MKID('IM01'), obim, 0);
  194.     if (!imptr)
  195.         error("No image for verb %d", vrb);
  196.  
  197.     for (i=0; i<imgw; i++) {
  198.         tmp = xstrip + i;
  199.         if ((uint)tmp < 40)
  200.             gdi.drawBitmap(imptr, vs, tmp, ydiff, imgh<<3, i, 1, true);
  201.     }
  202.  
  203.     vst = &_verbs[vrb];
  204.     vst->right = vst->x + imgw*8;
  205.     vst->bottom = vst->y + imgh*8;
  206.     vst->oldleft = vst->x;
  207.     vst->oldright = vst->right;
  208.     vst->oldtop = vst->y;
  209.     vst->oldbottom = vst->bottom;
  210.     
  211.     gdi.enableZBuffer();
  212.  
  213.     vs->alloctwobuffers = twobufs;
  214. }
  215.  
  216. int Scumm::getVerbSlot(int id, int mode) {
  217.     int i;
  218.     for (i=1; i<_maxVerbs; i++) {
  219.         if (_verbs[i].verbid == id && _verbs[i].saveid == mode) {
  220.             return i;
  221.         }
  222.     }
  223.     return 0;
  224. }
  225.  
  226. void Scumm::killVerb(int slot) {
  227.     VerbSlot *vs;
  228.  
  229.     if (slot==0)
  230.         return;
  231.  
  232.     vs = &_verbs[slot];
  233.     vs->verbid = 0;
  234.     vs->curmode = 0;
  235.  
  236.     nukeResource(rtVerb, slot);
  237.  
  238.     if (vs->saveid==0) {
  239.         drawVerb(slot, 0);
  240.         verbMouseOver(0);
  241.     }
  242.     vs->saveid = 0;
  243. }
  244.  
  245. void Scumm::setVerbObject(uint room, uint object, uint verb) {
  246.     int numobj, i;
  247.     byte  *obimptr;
  248.     uint32 imoffs,size;
  249.     byte *roomptr;
  250.     ImageHeader *imhd;
  251.     RoomHeader *roomhdr;
  252.  
  253.     if (whereIsObject(object) == 4)
  254.         error("Can't grab verb image from flobject");
  255.  
  256.     ensureResourceLoaded(rtRoom,room);
  257.     roomptr = getResourceAddress(rtRoom, room);
  258.     roomhdr = (RoomHeader*)findResource(MKID('RMHD'), roomptr, 0);
  259.  
  260.     numobj = READ_LE_UINT16(&roomhdr->numObjects);
  261.     if (numobj==0)
  262.         error("No images found in room %d", room);
  263.     if (numobj > _numLocalObjects)
  264.         error("More (%d) than %d objects in room %d", numobj, _numLocalObjects, room);
  265.  
  266.     for (i=0; i<numobj; i++) {
  267.         obimptr = findResource(MKID('OBIM'), roomptr, i);
  268.         if (obimptr==NULL)
  269.             error("Not enough image blocks in room %d", room);
  270.         imhd = (ImageHeader*)findResource(MKID('IMHD'), obimptr, 0);
  271.         if ( READ_LE_UINT16(&imhd->obj_id) == object) {
  272.             imoffs = obimptr - roomptr;
  273.             size = READ_BE_UINT32_UNALIGNED(obimptr+4);
  274.             createResource(rtVerb, verb, size);
  275.             obimptr = getResourceAddress(rtRoom, room) + imoffs;
  276.             memcpy(getResourceAddress(rtVerb, verb), obimptr, size);
  277.             return;
  278.         }
  279.     }
  280.     error("Image %d not found in room %d", object, room);
  281. }
  282.