diff options
-rw-r--r-- | queen/cutaway.cpp | 137 | ||||
-rw-r--r-- | queen/cutaway.h | 33 | ||||
-rw-r--r-- | queen/talk.cpp | 169 | ||||
-rw-r--r-- | queen/talk.h | 251 |
4 files changed, 408 insertions, 182 deletions
diff --git a/queen/cutaway.cpp b/queen/cutaway.cpp index fd93b40d87..1f43f190fe 100644 --- a/queen/cutaway.cpp +++ b/queen/cutaway.cpp @@ -23,6 +23,7 @@ #include "cutaway.h" #include "graphics.h" #include "talk.h" +#include "walk.h" namespace Queen { @@ -49,8 +50,6 @@ namespace Queen { CURRSONG JOEF (Joe's face direction) JX,JY (Joe's coordintes) - PERSON_FACE - PERSON_FACE_MAX */ @@ -59,8 +58,9 @@ void Cutaway::run( char *nextFilename, Graphics *graphics, Logic *logic, - Resource *resource) { - Cutaway *cutaway = new Cutaway(filename, graphics,logic, resource); + Resource *resource, + Walk *walk) { + Cutaway *cutaway = new Cutaway(filename, graphics,logic, resource, walk); cutaway->run(nextFilename); delete cutaway; } @@ -69,8 +69,10 @@ Cutaway::Cutaway( const char *filename, Graphics *graphics, Logic *logic, - Resource *resource) -: _logic(logic), _resource(resource), _graphics(graphics), _quit(false), _lastSong(0), _songBeforeComic(0) { + Resource *resource, + Walk *walk) +: _graphics(graphics), _logic(logic), _resource(resource), _walk(walk), + _quit(false), _personFaceCount(0), _lastSong(0), _songBeforeComic(0) { memset(&_bankNames, 0, sizeof(_bankNames)); load(filename); } @@ -82,6 +84,8 @@ Cutaway::~Cutaway() { void Cutaway::load(const char *filename) { byte *ptr; + debug(0, "----- Cutaway::load(\"%s\") -----", filename); + ptr = _fileData = _resource->loadFile(filename, 20); if (!_fileData) { error("Failed to load resource data file '%s'", filename); @@ -302,7 +306,7 @@ void Cutaway::limitBob(CutawayObject &object) { warning("QueenCutaway::limitBob called with objectNumber = %i", object.objectNumber); return; } - + BobSlot *bob = _graphics->bob( _logic->findBob(object.objectNumber) ); @@ -335,7 +339,7 @@ void Cutaway::changeRooms(CutawayObject &object) { if (_finalRoom != object.room) { int firstObjectInRoom = _logic->roomData(object.room) + 1; - int lastObjectInRoom = _logic->roomData(object.room) + 0; // XXX _logic->objMax(object.room); + int lastObjectInRoom = _logic->roomData(object.room) + _logic->objMax(object.room); for (int i = firstObjectInRoom; i <= lastObjectInRoom; i++) { ObjectData *objectData = _logic->objectData(i); @@ -372,35 +376,36 @@ void Cutaway::changeRooms(CutawayObject &object) { // set coordinates for Joe if he is on screen - // XXX this is global data! - int joeX = 0; - int joeY = 0; + _logic->joeX(0); + _logic->joeY(0); for (int i = 0; i < object.personCount; i++) { if (PERSON_JOE == object.person[i]) { - joeX = object.bobStartX; - joeY = object.bobStartY; + _logic->joeX(object.bobStartX); + _logic->joeY(object.bobStartY); } } - // XXX OLDROOM=IROOM; + _logic->oldRoom(_initialRoom); - if (!joeX && !joeY) { - // XXX DISP_ROOM(ROOM_NAMEstr[ROOM],0,SF); + RoomDisplayMode mode; + + if (!_logic->joeX() && !_logic->joeY()) { + mode = RDM_FADE_NOJOE; } else { - // XXX We need to display Joe on screen -#if 0 - if(ROOMFADE==1) - DISP_ROOM(ROOM_NAMEstr[ROOM],2,SF); + // We need to display Joe on screen + if (_roomFade == 1) + mode = RDM_NOFADE_JOE; else - DISP_ROOM(ROOM_NAMEstr[ROOM],3,SF); -#endif + mode = RDM_FADE_JOE_XY; } + _logic->roomDisplay(_logic->roomName(_logic->currentRoom()), mode, 0, 0 /*COMPANEL*/, true); + // XXX CI=FRAMES; - // XXX TROOM=ROOM; + _temporaryRoom = _logic->currentRoom(); restorePersonData(); @@ -597,6 +602,15 @@ byte *Cutaway::handleAnimation(byte *ptr, CutawayObject &object) { return ptr; } +static void findCdCut(const char *basename, int index, char *result) { + // Function find_cd_cut, lines 5-15 in execute.c + + strcpy(result, basename); + for (int i = strlen(basename); i < 5; i++) + result[i] = '_'; + snprintf(result + 5, 2, "%02i", index); +} + void Cutaway::handlePersonRecord( int index, CutawayObject &object, @@ -607,8 +621,7 @@ void Cutaway::handlePersonRecord( if (object.objectNumber == OBJECT_JOE) { if (object.moveToX || object.moveToY) { - // XXX X=IX ; Y=IY; - // XXX MOVE_JOE(0); + // XXX _walk->joeMove(0, object.moveToX, object.moveToY, true); } strcpy(name, "JOE"); } @@ -644,23 +657,26 @@ void Cutaway::handlePersonRecord( } else { if (object.objectNumber > 0) { - // XXX -#if 0 - MTCH=0; - for(K=1;K<=PERSON_FACE_MAX;K++) - { - if(PERSON_FACE[K][0]==OBJECT) MTCH=1; + bool foundPerson = false; + + for (int i = 1; i <= _personFaceCount; i++) { + if (_personFace[i].index == object.objectNumber) { + foundPerson = true; + break; + } } - if(MTCH==0) - { - PERSON_FACE_MAX++; - PERSON_FACE[PERSON_FACE_MAX][0]=OBJECT; - PERSON_FACE[PERSON_FACE_MAX][1]=OBJECT_DATA[OBJECT][7]; + + if (!foundPerson) { + _personFaceCount++; + _personFace[_personFaceCount].index = object.objectNumber; + _personFace[_personFaceCount].image = _logic->objectData(object.objectNumber)->image; } -#endif } - // XXX SPEAK(sentence, name, findCdCut(_basename, index)); + char voiceFilePrefix[MAX_STRING_SIZE]; + findCdCut(_basename, index, voiceFilePrefix); + Talk::speak(sentence, name, voiceFilePrefix, + _graphics, _logic, _resource); } } @@ -711,11 +727,11 @@ void Cutaway::run(char *nextFilename) { debug(0, "Sentence = '%s'", sentence); if (OBJECT_ROOMFADE == object.objectNumber) { - // ROOMFADE = 1; + _roomFade = true; object.objectNumber = OBJECT_JOE; } else { - // ROOMFADE = 0; + _roomFade = false; } if (object.room != _temporaryRoom) @@ -784,10 +800,12 @@ void Cutaway::run(char *nextFilename) { warning("Clean-up stuff needed but not yet implemented"); } - // XXX bobs[0].animating=0; - // XXX bobs[0].moving=0; + BobSlot *joeBob = _graphics->bob(0); + joeBob->animating = 0; + joeBob->moving = 0; // Make sure Joe is clipped! - // XXX bobs[0].y2=149; + joeBob->box.y2 = 149; + // XXX CUTON=0; _quit = false; @@ -808,7 +826,7 @@ void Cutaway::objectCopy(int dummyObjectIndex, int realObjectIndex) { int fromState = (dummyObject->name < 0) ? -1 : 0; - int frameCountReal = 1; + int frameCountReal = 1; int frameCountDummy = 1; int graphic = realObject->image; @@ -816,17 +834,20 @@ void Cutaway::objectCopy(int dummyObjectIndex, int realObjectIndex) { if (graphic > 5000) graphic -= 5000; - // XXX FIND_GRAPHIC(graphic) - // XXX if(EFRAME>0) frameCountReal=(EFRAME-SFRAME)+1; + GraphicData *data = _logic->graphicData(graphic); + + if (data->lastFrame > 0) + frameCountReal = data->lastFrame - data->firstFrame + 1; graphic = dummyObject->image; if (graphic > 0) { if (graphic > 5000) graphic -= 5000; - // XXX FIND_GRAPHIC(graphic) - // XXX if(EFRAME>0) frameCountDummy=(EFRAME-SFRAME)+1; + data = _logic->graphicData(graphic); + if (data->lastFrame > 0) + frameCountDummy = data->lastFrame - data->firstFrame + 1; } } @@ -872,13 +893,11 @@ void Cutaway::goToFinalRoom() { joeRoom != _temporaryRoom && joeRoom != 0) { - // XXX update global Joe coordinates - // JX = joeX; - // JY = joeY; - + _logic->joeX(joeX); + _logic->joeY(joeX); _logic->currentRoom(joeRoom); _logic->oldRoom(_initialRoom); - // XXX DISP_ROOM(ROOM_NAMEstr[ROOM],3,0); + _logic->roomDisplay(_logic->roomName(_logic->currentRoom()), RDM_FADE_JOE_XY, 0, 0 /*COMPANEL*/, true); } if (_quit) { @@ -926,11 +945,11 @@ void Cutaway::goToFinalRoom() { joeRoom != 105 && // XXX hard coded room number joeRoom != 106 && // XXX hard coded room number (joeX || joeY)) { - // XXX bobs[0].x=J_X; - // XXX bobs[0].y=J_Y; - // XXX FIND_SCALE(J_X,J_Y); - // XXX SFACTOR=Param; - // XXX FACE_JOE() + BobSlot *joeBob = _graphics->bob(0); + joeBob->x = joeX; + joeBob->y = joeY; + joeBob->scale = _logic->findScale(joeX, joeY); + _walk->joeFace(); } } @@ -1012,7 +1031,7 @@ void Cutaway::talk(char *nextFilename) { warning("Cutaway::talk() used but not fully implemented"); nextFilename[0] = '\0'; - Talk::run(_talkFile, nextFilename, _graphics, _logic, _resource); + Talk::talk(_talkFile, nextFilename, _graphics, _logic, _resource); } } diff --git a/queen/cutaway.h b/queen/cutaway.h index 81e5100591..8fc373fd25 100644 --- a/queen/cutaway.h +++ b/queen/cutaway.h @@ -26,9 +26,10 @@ namespace Queen { -class Resource; -class Logic; class Graphics; +class Logic; +class Resource; +class Walk; class Cutaway { public: @@ -38,7 +39,8 @@ class Cutaway { char *nextFilename, Graphics *graphics, Logic *logic, - Resource *resource); + Resource *resource, + Walk *walk); private: //! Collection of constants used by QueenCutaway enum { @@ -52,6 +54,7 @@ class Cutaway { MAX_BANK_NAME_COUNT = 5, MAX_FILENAME_LENGTH = 12, MAX_FILENAME_SIZE = (MAX_FILENAME_LENGTH + 1), + MAX_PERSON_FACE_COUNT = 12, MAX_STRING_LENGTH = 255, MAX_STRING_SIZE = (MAX_STRING_LENGTH + 1), LEFT = 1, @@ -121,9 +124,15 @@ class Cutaway { int16 image; }; - Logic *_logic; - Resource *_resource; - Graphics *_graphics; + struct PersonFace { + int16 index; + int16 image; + }; + + Graphics *_graphics; + Logic *_logic; + Resource *_resource; + Walk *_walk; //! Raw .cut file data (without 20 byte header) byte *_fileData; @@ -137,6 +146,9 @@ class Cutaway { //! Pointer to next sentence string in _fileData byte *_nextSentence; + //! ??? + bool _roomFade; + //! Number of cutaway objects at _cutawayData int _cutawayObjectCount; @@ -173,6 +185,12 @@ class Cutaway { //! Number of elements used in _personData array int _personDataCount; + //! Used by handlePersonRecord() + PersonFace _personFace[MAX_PERSON_FACE_COUNT]; + + //! Number of entries in _personFace array + int _personFaceCount; + //! Play this song when leaving cutaway int16 _lastSong; @@ -184,7 +202,8 @@ class Cutaway { const char *filename, Graphics *graphics, Logic *logic, - Resource *resource); + Resource *resource, + Walk *walk); ~Cutaway(); //! Run this cutaway object diff --git a/queen/talk.cpp b/queen/talk.cpp index 16dd32ffc6..625b410910 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -32,7 +32,7 @@ namespace Queen { */ -void Talk::run( +void Talk::talk( const char *filename, char *cutawayFilename, Graphics *graphics, @@ -43,6 +43,19 @@ void Talk::run( delete talk; } +bool Talk::speak( + const char *sentence, + const char *person, + const char *voiceFilePrefix, + Graphics *graphics, + Logic *logic, + Resource *resource) { + Talk *talk = new Talk(graphics, logic, resource); + bool result = talk->speak(sentence, person, voiceFilePrefix); + delete talk; + return result; +} + Talk::Talk( Graphics *graphics, Logic *logic, @@ -415,12 +428,164 @@ void Talk::initialTalk() { } +int Talk::getSpeakCommand(const char *sentence, unsigned &index) { + // Lines 1299-1362 in talk.c + int commandCode = SPEAK_DEFAULT; + + switch (sentence[index]) { + case 'A': + if (sentence[index + 1] == 'O') + commandCode = SPEAK_AMAL_ON; + else + warning("Unknown command string: '%2s'", sentence + index); + break; + + case 'F': + switch (sentence[index + 1]) { + case 'L': + commandCode = SPEAK_FACE_LEFT; + break; + case 'F': + commandCode = SPEAK_FACE_FRONT; + break; + case 'B': + commandCode = SPEAK_FACE_BACK; + break; + case 'R': + commandCode = SPEAK_FACE_RIGHT; + break; + default: + warning("Unknown command string: '%2s'", sentence + index); + break; + } + break; + + case 'G': + switch (sentence[index + 1]) { + case 'D': + // XXX GRAB_DIR("DOWN",0); + break; + case 'M': + // XXX GRAB_DIR("MID",0); + break; + default: + warning("Unknown command string: '%2s'", sentence + index); + break; + } + commandCode = SPEAK_NONE; + break; + + case 'X': + // For example *XY00(237,112) + if (sentence[index + 1] == 'Y') { + commandCode = atoi(sentence + index + 2); + // XXX int x = atoi(sentence + index + 5); + // XXX int y = atoi(sentence + index + 9); + // XXX MOVE_SPEAK(person, x, y) + index += 11; + /// XXX personWalking = true; + } + else + warning("Unknown command string: '%2s'", sentence + index); + break; + + default: + if (sentence[index + 0] >= '0' && sentence[index + 0] <= '9' && + sentence[index + 1] >= '0' && sentence[index + 1] <= '9') { + commandCode = (sentence[index] - '0') * 10 + (sentence[index + 1] - '0'); + } + else + warning("Unknown command string: '%2s'", sentence + index); + } + + index += 2; + + return commandCode; +} + + bool Talk::speak(const char *sentence, const char *person, const char *voiceFilePrefix) { + // Function SPEAK, lines 1266-1384 in talk.c + bool personWalking = false; + bool talkHead; + unsigned segmentIndex = 0; + unsigned segmentStart = 0; + unsigned i; + debug(0, "Sentence '%s' is said by person '%s' and voice files with prefix '%s' played", sentence, person, voiceFilePrefix); - return false; // XXX + + if (sentence[0] == '\0') { + goto exit; + } + + if (0 == strcmp(person, "FAYE-H") || + 0 == strcmp(person, "FRANK-H") || + 0 == strcmp(person, "AZURA-H") || + 0 == strcmp(person, "X3_RITA-H")) + talkHead = true; + else + talkHead = false; + + // XXX CLEAR_COMMAND(false) + + for (i = 0; i < strlen(sentence); i++) { + if (sentence[i] == '*') { + int segmentLength = i - segmentStart; + + i++; + int command = getSpeakCommand(sentence, i); + + if (SPEAK_NONE != command) { + speakSegment( + sentence + segmentStart, + segmentLength, + person, + command, + voiceFilePrefix, + segmentIndex); + // XXX if (JOEWALK == 2) break + } + + segmentIndex++; + segmentStart = i; + } + } + + if (segmentStart != i) { + speakSegment( + sentence + segmentStart, + i - segmentStart, + person, + 0, + voiceFilePrefix, + segmentIndex); + } + +exit: + return personWalking; +} + +void Talk::speakSegment( + const char *segment, + int length, + const char *person, + int command, + const char *voiceFilePrefix, + int index) { + // Function SPEAK_SUB, lines 1406-1870 in talk.c + char voiceFileName[MAX_STRING_SIZE]; + snprintf(voiceFileName, sizeof(voiceFileName), "%s%1x", voiceFilePrefix, index); + + //debug(0, "Sentence segment '%*s' is said by person '%s' and voice file '%s' is played", + // length, segment, person, voiceFileName); + + debug(0, "Playing voice file '%s'", voiceFileName); + + } + byte *Talk::getString(byte *ptr, char *str, int maxLength, int align) { int length = *ptr; ptr++; diff --git a/queen/talk.h b/queen/talk.h index 0c669fd9f8..7ec2f9c7c0 100644 --- a/queen/talk.h +++ b/queen/talk.h @@ -31,128 +31,151 @@ class Logic; class Resource; class Talk { - public: - - //! Public interface to run a talk from a file - static void run( - const char *filename, - char *cutawayFilename, - Graphics *graphics, - Logic *logic, - Resource *resource); - - //! Public interface to speak a sentence -#if 0 - static void run( - const char *sentence, - const char *person, - int noun, - Logic *logic, - Resource *resource); -#endif - - //! Read a string from ptr and return new ptr - static byte *getString(byte *ptr, char *str, int maxLength, int align = 2); - - private: - //! Collection of constants used by Talk - enum { - MAX_STRING_LENGTH = 255, - MAX_STRING_SIZE = (MAX_STRING_LENGTH + 1), - MAX_TEXT_WIDTH = (320-18), - PUSHUP = 4, - TALK_SELECTED_COUNT = 86, - SENTENCE_BOB_1 = 62, - SENTENCE_BOB_2 = 63 - }; - - //! TODO Move this to struct.h later! - struct TalkSelected { - int16 hasTalkedTo; - int16 values[4]; - }; - - struct DialogueNode { - int16 head; - int16 dialogueNodeValue1; - int16 gameStateIndex; - int16 gameStateValue; - }; - - Graphics *_graphics; - Logic *_logic; - Resource *_resource; - - //! Raw .dog file data (without 20 byte header) - byte *_fileData; - - //! Number of dialogue levels - int16 _levelMax; - - //! Unique key for this dialogue - int16 _uniqueKey; - - //! Used to select voice files - int16 _talkKey; - - //! Used by findDialogueString - int16 _pMax; - - //! String data - byte *_person1Ptr; - - //! Data used if we have talked to the person before - byte *_person2Ptr; - - //! Data used if we haven't talked to the person before - byte *_joePtr; - - //! Set to true to quit talking - bool _quit; - - //! IDs for sentences - DialogueNode _dialogueTree[18][6]; - - //! TODO Move this to the Logic class later! - TalkSelected _talkSelected[TALK_SELECTED_COUNT]; - - //! Greeting from person Joe has talked to before - char _person2String[MAX_STRING_SIZE]; - - int _oldSelectedSentenceIndex; - int _oldSelectedSentenceValue; - - char _talkString[5][MAX_STRING_SIZE]; - char _joeVoiceFilePrefix[5][MAX_STRING_SIZE]; - - Talk(Graphics *graphics, Logic *logic, Resource *resource); - ~Talk(); - - //! Perform talk in file and return a cutaway filename - void talk(const char *filename, char *cutawayFilename); + public: + + //! Public interface to run a talk from a file + static void talk( + const char *filename, + char *cutawayFilename, + Graphics *graphics, + Logic *logic, + Resource *resource); + + //! Public interface to speak a sentence + static bool speak( + const char *sentence, + const char *person, + const char *voiceFilePrefix, + Graphics *graphics, + Logic *logic, + Resource *resource); + + //! Read a string from ptr and return new ptr + static byte *getString(byte *ptr, char *str, int maxLength, int align = 2); + + private: + //! Collection of constants used by Talk + enum { + MAX_STRING_LENGTH = 255, + MAX_STRING_SIZE = (MAX_STRING_LENGTH + 1), + MAX_TEXT_WIDTH = (320-18), + PUSHUP = 4, + TALK_SELECTED_COUNT = 86, + SENTENCE_BOB_1 = 62, + SENTENCE_BOB_2 = 63 + }; + + //! Special commands for speech + enum { + SPEAK_DEFAULT = 0, + SPEAK_FACE_LEFT = -1, + SPEAK_FACE_RIGHT = -2, + SPEAK_FACE_FRONT = -3, + SPEAK_FACE_BACK = -4, + SPEAK_AMAL_ON = -7, + SPEAK_PAUSE = -8, + SPEAK_NONE = -9 + }; + + //! TODO Move this to struct.h later! + struct TalkSelected { + int16 hasTalkedTo; + int16 values[4]; + }; + + struct DialogueNode { + int16 head; + int16 dialogueNodeValue1; + int16 gameStateIndex; + int16 gameStateValue; + }; + + Graphics *_graphics; + Logic *_logic; + Resource *_resource; + + //! Raw .dog file data (without 20 byte header) + byte *_fileData; + + //! Number of dialogue levels + int16 _levelMax; + + //! Unique key for this dialogue + int16 _uniqueKey; + + //! Used to select voice files + int16 _talkKey; + + //! Used by findDialogueString + int16 _pMax; + + //! String data + byte *_person1Ptr; + + //! Data used if we have talked to the person before + byte *_person2Ptr; + + //! Data used if we haven't talked to the person before + byte *_joePtr; + + //! Set to true to quit talking + bool _quit; + + //! IDs for sentences + DialogueNode _dialogueTree[18][6]; + + //! TODO Move this to the Logic class later! + TalkSelected _talkSelected[TALK_SELECTED_COUNT]; + + //! Greeting from person Joe has talked to before + char _person2String[MAX_STRING_SIZE]; + + int _oldSelectedSentenceIndex; + int _oldSelectedSentenceValue; + + char _talkString[5][MAX_STRING_SIZE]; + char _joeVoiceFilePrefix[5][MAX_STRING_SIZE]; + + Talk(Graphics *graphics, Logic *logic, Resource *resource); + ~Talk(); + + //! Perform talk in file and return a cutaway filename + void talk(const char *filename, char *cutawayFilename); + + //! Load talk data from .dog file + void load(const char *filename); + + //! First things spoken + void initialTalk(); - //! Load talk data from .dog file - void load(const char *filename); + //! Find a string in the dialogue tree + void findDialogueString(byte *ptr, int16 id, char *str); - //! First things spoken - void initialTalk(); + //! Get TalkSelected struct for this talk + TalkSelected *talkSelected(); - //! Find a string in the dialogue tree - void findDialogueString(byte *ptr, int16 id, char *str); + //! The sentence will not be displayed again + void disableSentence(int oldLevel, int selectedSentence); - //! Speak sentence - bool speak(const char *sentence, const char *person, const char *voiceFilePrefix); + //! Select what to say + int16 selectSentence(); - //! Get TalkSelected struct for this talk - TalkSelected *talkSelected(); + //! Speak sentence + bool speak(const char *sentence, const char *person, const char *voiceFilePrefix); - //! The sentence will not be displayed again - void disableSentence(int oldLevel, int selectedSentence); + //! Convert command in sentence to command code + int getSpeakCommand(const char *sentence, unsigned &index); - //! Select what to say - int16 selectSentence(); + //! Speak a part of a sentence + void speakSegment( + const char *segment, + int length, + const char *person, + int command, + const char *voiceFilePrefix, + int index); - static int splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]); + static int splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]); }; |