void bringWordtoTop(char *str, int wordnum) { // This function reorders the words on the given pred.dic line // by moving the word at position 'wordnum' to the front (that is, right behind // right behind the numerical code word at the start of the line). Common::Array<Common::String> words; char buf[MAXLINELEN]; if (!str) return; strncpy(buf, str, MAXLINELEN); buf[MAXLINELEN - 1] = 0; char *word = strtok(buf, " "); if (!word) { debug("Invalid dictionary line"); return; } words.push_back(word); while ((word = strtok(NULL, " ")) != NULL) words.push_back(word); words.insert_at(1, words.remove_at(wordnum + 1)); Common::String tmp; for (uint8 i = 0; i < words.size(); i++) tmp += words[i] + " "; tmp.deleteLastChar(); memcpy(str, tmp.c_str(), strlen(str)); }
void TestbedExitDialog::init() { _xOffset = 25; _yOffset = 0; Common::String text = "Thank you for using ScummVM testbed! Here are yor summarized results:"; addText(450, 20, text, Graphics::kTextAlignCenter, _xOffset, 15); Common::Array<Common::String> strArray; GUI::ListWidget::ColorList colors; for (Common::Array<Testsuite *>::const_iterator i = _testsuiteList.begin(); i != _testsuiteList.end(); ++i) { strArray.push_back(Common::String::format("%s :", (*i)->getDescription())); colors.push_back(GUI::ThemeEngine::kFontColorNormal); if ((*i)->isEnabled()) { strArray.push_back(Common::String::format("Passed: %d Failed: %d Skipped: %d", (*i)->getNumTestsPassed(), (*i)->getNumTestsFailed(), (*i)->getNumTestsSkipped())); } else { strArray.push_back("Skipped"); } colors.push_back(GUI::ThemeEngine::kFontColorAlternate); } addList(0, _yOffset, 500, 200, strArray, &colors); text = "More Details can be viewed in the Log file : " + ConfParams.getLogFilename(); addText(450, 20, text, Graphics::kTextAlignLeft, 0, 0); if (ConfParams.getLogDirectory().size()) { text = "Directory : " + ConfParams.getLogDirectory(); } else { text = "Directory : ."; } addText(500, 20, text, Graphics::kTextAlignLeft, 0, 0); _yOffset += 5; addButtonXY(_xOffset + 80, _yOffset, 120, 24, "Rerun test suite", kCmdRerunTestbed); addButtonXY(_xOffset + 240, _yOffset, 60, 24, "Close", GUI::kCloseCmd); }
Common::Array<Common::String> SavesSyncRequest::getFilesToDownload() { Common::Array<Common::String> result; for (uint32 i = 0; i < _filesToDownload.size(); ++i) result.push_back(_filesToDownload[i].name()); if (_currentDownloadingFile.name() != "") result.push_back(_currentDownloadingFile.name()); return result; }
Common::Array<const ASTCommand *> ASTLoop::listCommands(uint16 index) const { Common::Array<const ASTCommand *> list; if (condition) { list.push_back(condition->listCommands(index)); } list.push_back(loopBlock->listCommands(index)); return list; }
Common::Array<Resources::Script *> Console::listAllLocationScripts() const { Common::Array<Resources::Script *> scripts; Resources::Level *level = StarkGlobal->getCurrent()->getLevel(); Resources::Location *location = StarkGlobal->getCurrent()->getLocation(); scripts.push_back(level->listChildrenRecursive<Resources::Script>()); scripts.push_back(location->listChildrenRecursive<Resources::Script>()); return scripts; }
Common::Array<const ASTCommand *> ASTCondition::listCommands(uint16 index) const { Common::Array<const ASTCommand *> list; list.push_back(condition->listCommands(index)); list.push_back(thenBlock->listCommands(index)); if (elseBlock) { list.push_back(elseBlock->listCommands(index)); } return list; }
void PackPrince::talkTxtNoDialog() { byte c; std::string line; Common::Array<TalkTxt> normalLinesArray; TalkTxt tempNormalLine; while (1) { // Special dialog data line.clear(); while ((c = _databank.readByte()) != '\r') { line += c; } _databank.readByte(); // skip '\n' if (!line.compare("#HERO")) { tempNormalLine._dialogData = 1; } else if (!line.compare("#OTHER")) { tempNormalLine._dialogData = 4; } else if (!line.compare("#OTHER2")) { tempNormalLine._dialogData = 5; } else if (!line.compare("#PAUSE")) { tempNormalLine._dialogData = 254; tempNormalLine._txt.clear(); normalLinesArray.push_back(tempNormalLine); continue; } else if (!line.compare("#END")) { break; } // Line of text tempNormalLine._txt.clear(); while ((c = _databank.readByte()) != '\r') { c = correctPolishLetter(c); // temporary if (c == '|') { c = 10; } tempNormalLine._txt += c; } c = 0; tempNormalLine._txt += c; _databank.readByte(); // skip '\n' normalLinesArray.push_back(tempNormalLine); } // Offset counting and packing: for (uint i = 0; i < normalLinesArray.size(); i++) { _fFiles.writeByte(normalLinesArray[i]._dialogData); for (uint j = 0; j < normalLinesArray[i]._txt.size(); j++) { _fFiles.writeByte(normalLinesArray[i]._txt[j]); } } _fFiles.writeByte(255); }
Common::Array<reg_t> ListTable::listAllOutgoingReferences(reg_t addr) const { Common::Array<reg_t> tmp; if (!isValidEntry(addr.offset)) { error("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); } const List *list = &(_table[addr.offset]); tmp.push_back(list->first); tmp.push_back(list->last); // We could probably get away with just one of them, but // let's be conservative here. return tmp; }
void WalkRegion::computeVisibilityMatrix() { // Initialize visibility matrix _visibilityMatrix = Common::Array< Common::Array <int> >(); for (uint idx = 0; idx < _nodes.size(); ++idx) { Common::Array<int> arr; for (uint idx2 = 0; idx2 < _nodes.size(); ++idx2) arr.push_back(Infinity); _visibilityMatrix.push_back(arr); } // Calculate visibility been vertecies for (uint j = 0; j < _nodes.size(); ++j) { for (uint i = j; i < _nodes.size(); ++i) { if (isLineOfSight(_nodes[i], _nodes[j])) { // There is a line of sight, so save the distance between the two int distance = _nodes[i].distance(_nodes[j]); _visibilityMatrix[i][j] = distance; _visibilityMatrix[j][i] = distance; } else { // There is no line of sight, so save Infinity as the distance _visibilityMatrix[i][j] = Infinity; _visibilityMatrix[j][i] = Infinity; } } } }
Common::Array<reg_t> Script::listObjectReferences() const { Common::Array<reg_t> tmp; // Locals, if present if (_localsSegment) tmp.push_back(make_reg(_localsSegment, 0)); // All objects (may be classes, may be indirectly reachable) ObjMap::iterator it; const ObjMap::iterator end = _objects.end(); for (it = _objects.begin(); it != end; ++it) { tmp.push_back(it->_value.getPos()); } return tmp; }
bool BuriedEngine::loadState(Common::SeekableReadStream *saveFile, Location &location, GlobalFlags &flags, Common::Array<int> &inventoryItems) { byte header[9]; saveFile->read(header, kSavedGameHeaderSize); // Only compare the first 6 bytes // Win95 version of the game output garbage as the last two bytes if (saveFile->eos() || memcmp(header, s_savedGameHeader, kSavedGameHeaderSizeAlt) != 0) return false; Common::Serializer s(saveFile, 0); if (!syncLocation(s, location)) return false; if (saveFile->eos()) return false; if (!syncGlobalFlags(s, flags)) return false; if (saveFile->eos()) return false; uint16 itemCount = saveFile->readUint16LE(); if (saveFile->eos()) return false; inventoryItems.clear(); for (uint16 i = 0; i < itemCount; i++) inventoryItems.push_back(saveFile->readUint16LE()); return !saveFile->eos(); }
void Inventory::updateState() { Common::Array<uint16> items; for (ItemList::iterator it = _inventory.begin(); it != _inventory.end(); it++) items.push_back(it->var); _vm->_state->updateInventory(items); }
void listSavegames(Common::Array<SavegameDesc> &saves) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); // Load all saves Common::StringList saveNames = saveFileMan->listSavefiles(((SciEngine *)g_engine)->getSavegamePattern()); for (Common::StringList::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) { Common::String filename = *iter; Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { SavegameMetadata meta; if (!get_savegame_metadata(in, &meta)) { // invalid delete in; continue; } delete in; SavegameDesc desc; desc.id = strtol(filename.end() - 3, NULL, 10); desc.date = meta.savegame_date; desc.time = meta.savegame_time; debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id); saves.push_back(desc); } } // Sort the list by creation date of the saves qsort(saves.begin(), saves.size(), sizeof(SavegameDesc), _savegame_index_struct_compare); }
void Graphics::loadMRG(Common::String filename, MRGFile *mrg) { Common::SeekableReadStream *mrgStream = _vm->data.openFile(filename); uint16 num_entries = mrgStream->readUint16LE(); Common::Array<uint32> offsets; for (unsigned int i = 0; i < num_entries; i++) { offsets.push_back(mrgStream->readUint32LE()); } for (unsigned int i = 0; i < num_entries; i++) { bool r = mrgStream->seek(offsets[i], SEEK_SET); assert(r); uint16 width = mrgStream->readUint16LE(); uint16 height = mrgStream->readUint16LE(); byte *pixels = new byte[width * height]; mrgStream->read(pixels, width * height); mrg->heights.push_back(height); mrg->widths.push_back(width); mrg->data.push_back(pixels); } delete mrgStream; }
Common::Array<reg_t> LocalVariables::listAllOutgoingReferences(reg_t addr) const { Common::Array<reg_t> tmp; for (uint i = 0; i < _locals.size(); i++) tmp.push_back(_locals[i]); return tmp; }
Common::Array<reg_t> NodeTable::listAllOutgoingReferences(reg_t addr) const { Common::Array<reg_t> tmp; if (!isValidEntry(addr.offset)) { error("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); } const Node *node = &(_table[addr.offset]); // We need all four here. Can't just stick with 'pred' OR 'succ' because node operations allow us // to walk around from any given node tmp.push_back(node->pred); tmp.push_back(node->succ); tmp.push_back(node->key); tmp.push_back(node->value); return tmp; }
Common::Array<reg_t> DataStack::listAllOutgoingReferences(reg_t object) const { Common::Array<reg_t> tmp; for (int i = 0; i < _capacity; i++) tmp.push_back(_entries[i]); return tmp; }
Common::Array<AgeData> Database::loadAges(Common::ReadStreamEndian &s) { Common::Array<AgeData> ages; for (uint i = 0; i < 10; i++) { AgeData age; if (_vm->getPlatform() == Common::kPlatformPS2) { // Really 64-bit values age.id = s.readUint32LE(); s.readUint32LE(); age.disk = s.readUint32LE(); s.readUint32LE(); age.roomCount = s.readUint32LE(); s.readUint32LE(); age.roomsOffset = s.readUint32LE() - _executableVersion->baseOffset; s.readUint32LE(); age.labelId = s.readUint32LE(); s.readUint32LE(); } else { age.id = s.readUint32(); age.disk = s.readUint32(); age.roomCount = s.readUint32(); age.roomsOffset = s.readUint32() - _executableVersion->baseOffset; age.labelId = s.readUint32(); } ages.push_back(age); } return ages; }
Common::Array<Opcode> Database::loadOpcodes(Common::ReadStreamEndian &s) { Common::Array<Opcode> script; while (1) { Opcode opcode; uint16 code = s.readUint16(); opcode.op = code & 0xff; uint8 count = code >> 8; if (count == 0 && opcode.op == 0) break; // The v1.0 executables use a slightly different opcode set // Since it's a simple conversion, we'll handle that here if ((_executableVersion->flags & kFlagVersion10) && opcode.op >= 122) opcode.op++; for (int i = 0; i < count; i++) { int16 value = s.readSint16(); opcode.args.push_back(value); } script.push_back(opcode); } return script; }
void Database::loadRoomNodeScripts(Common::SeekableSubReadStreamEndian *file, Common::Array<NodePtr> &nodes) { uint zipIndex = 0; while (1) { int16 id = file->readUint16(); // End of list if (id == 0) break; if (id <= -10) error("Unimplemented node list command"); if (id > 0) { // Normal node NodePtr node = NodePtr(new NodeData()); node->id = id; node->zipBitIndex = zipIndex; node->scripts = loadCondScripts(*file); node->hotspots = loadHotspots(*file); nodes.push_back(node); } else { // Several nodes sharing the same scripts Common::Array<int16> nodeIds; for (int i = 0; i < -id; i++) { nodeIds.push_back(file->readUint16()); } Common::Array<CondScript> scripts = loadCondScripts(*file); Common::Array<HotSpot> hotspots = loadHotspots(*file); for (int i = 0; i < -id; i++) { NodePtr node = NodePtr(new NodeData()); node->id = nodeIds[i]; node->zipBitIndex = zipIndex; node->scripts = scripts; node->hotspots = hotspots; nodes.push_back(node); } } zipIndex++; } }
Common::Array<uint32> Archive::getResourceTypeList() const { Common::Array<uint32> typeList; for (TypeMap::const_iterator it = _types.begin(); it != _types.end(); it++) typeList.push_back(it->_key); return typeList; }
SpriteResource::SpriteResource(AccessEngine *vm, Resource *res) { Common::Array<uint32> offsets; int count = res->_stream->readUint16LE(); for (int i = 0; i < count; i++) offsets.push_back(res->_stream->readUint32LE()); offsets.push_back(res->_size); // For easier calculations of Noctropolis sizes // Build up the frames for (int i = 0; i < count; ++i) { res->_stream->seek(offsets[i]); int frameSize = offsets[i + 1] - offsets[i]; SpriteFrame *frame = new SpriteFrame(vm, res->_stream, frameSize); _frames.push_back(frame); } }
// Print a list of all registered commands (and variables, if any), // nicely word-wrapped. bool Debugger::Cmd_Help(int argc, const char **argv) { #ifndef USE_TEXT_CONSOLE const int charsPerLine = _debuggerDialog->getCharsPerLine(); #elif defined(USE_READLINE) int charsPerLine, rows; rl_get_screen_size(&rows, &charsPerLine); #else // Can we do better? const int charsPerLine = 80; #endif int width, size; uint i; DebugPrintf("Commands are:\n"); // Obtain a list of sorted command names Common::Array<Common::String> cmds; CommandsMap::const_iterator iter, e = _cmds.end(); for (iter = _cmds.begin(); iter != e; ++iter) { cmds.push_back(iter->_key); } sort(cmds.begin(), cmds.end()); // Print them all width = 0; for (i = 0; i < cmds.size(); i++) { size = cmds[i].size() + 1; if ((width + size) >= charsPerLine) { DebugPrintf("\n"); width = size; } else width += size; DebugPrintf("%s ", cmds[i].c_str()); } DebugPrintf("\n"); if (!_dvars.empty()) { DebugPrintf("\n"); DebugPrintf("Variables are:\n"); width = 0; for (i = 0; i < _dvars.size(); i++) { size = _dvars[i].name.size() + 1; if ((width + size) >= charsPerLine) { DebugPrintf("\n"); width = size; } else width += size; DebugPrintf("%s ", _dvars[i].name.c_str()); } DebugPrintf("\n"); } return true; }
Database::Database(Myst3Engine *vm) : _vm(vm), _currentRoomID(0), _executableVersion(0), _currentRoomData(0) { _executableVersion = _vm->getExecutableVersion(); if (_executableVersion != 0) { debug("Initializing database from %s (Platform: %s) (%s)", _executableVersion->executable, getPlatformDescription(_vm->getPlatform()), _executableVersion->description); } else { error("Could not find any executable to load"); } // Load the ages and rooms description Common::SeekableSubReadStreamEndian *file = openDatabaseFile(); file->seek(_executableVersion->ageTableOffset); _ages = loadAges(*file); for (uint i = 0; i < _ages.size(); i++) { file->seek(_ages[i].roomsOffset); // Read the room offset table Common::Array<uint32> roomsOffsets; for (uint j = 0; j < _ages[i].roomCount; j++) { uint32 offset = file->readUint32() - _executableVersion->baseOffset; roomsOffsets.push_back(offset); } // Load the rooms for (uint j = 0; j < roomsOffsets.size(); j++) { file->seek(roomsOffsets[j]); _ages[i].rooms.push_back(loadRoomDescription(*file)); } } file->seek(_executableVersion->nodeInitScriptOffset); _nodeInitScript = loadOpcodes(*file); file->seek(_executableVersion->soundNamesOffset); loadSoundNames(file); // TODO: Remove once the offset table is complete if (!_executableVersion->ambientCuesOffset) { error("The description for this executable (%s, %s) does not contain the ambient cues offset. Please contact the ResidualVM team.", _executableVersion->executable, _executableVersion->description); } file->seek(_executableVersion->ambientCuesOffset); loadAmbientCues(file); preloadCommonRooms(file); initializeZipBitIndexTable(file); delete file; }
void TabWidget::drawWidget() { Common::Array<Common::String> tabs; for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) { tabs.push_back(_tabs[i].title); } g_gui.theme()->drawDialogBackgroundClip(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP+_tabHeight), getBossClipRect(), _bodyBackgroundType); g_gui.theme()->drawTabClip(Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad); }
Common::Array<const ASTCommand *> ASTCommand::listCommands(uint16 index) const { Common::Array<const ASTCommand *> list; if (_index == index) { list.push_back(this); } return list; }
Common::Array<const ASTCommand *> ASTBlock::listCommands(uint16 index) const { Common::Array<const ASTCommand *> list; for (uint i = 0; i < _children.size(); i++) { list.push_back(_children[i]->listCommands(index)); } return list; }
void HiRes5Engine::init() { _graphics = new Graphics_v3(*_display); insertDisk(2); StreamPtr stream(_disk->createReadStream(0x5, 0x0, 0x02)); loadRegionLocations(*stream, kRegions); stream.reset(_disk->createReadStream(0xd, 0x2, 0x04)); loadRegionInitDataOffsets(*stream, kRegions); stream.reset(_disk->createReadStream(0x7, 0xe)); _strings.verbError = readStringAt(*stream, 0x4f); _strings.nounError = readStringAt(*stream, 0x8e); _strings.enterCommand = readStringAt(*stream, 0xbc); stream.reset(_disk->createReadStream(0x7, 0xc)); _strings.lineFeeds = readString(*stream); stream.reset(_disk->createReadStream(0x8, 0x3, 0x00, 2)); _strings_v2.saveInsert = readStringAt(*stream, 0x66); _strings_v2.saveReplace = readStringAt(*stream, 0x112); _strings_v2.restoreInsert = readStringAt(*stream, 0x180); _strings.playAgain = readStringAt(*stream, 0x247, 0xff); _messageIds.cantGoThere = 110; _messageIds.dontUnderstand = 112; _messageIds.itemDoesntMove = 114; _messageIds.itemNotHere = 115; _messageIds.thanksForPlaying = 113; stream.reset(_disk->createReadStream(0xe, 0x1, 0x13, 4)); loadItemDescriptions(*stream, kItems); stream.reset(_disk->createReadStream(0x8, 0xd, 0xfd, 1)); loadDroppedItemOffsets(*stream, 16); stream.reset(_disk->createReadStream(0xb, 0xa, 0x05, 1)); loadItemPicIndex(*stream, kItems); stream.reset(_disk->createReadStream(0x7, 0x8, 0x01)); for (uint i = 0; i < kItems; ++i) _itemTimeLimits.push_back(stream->readByte()); if (stream->eos() || stream->err()) error("Failed to read item time limits"); stream.reset(_disk->createReadStream(0x8, 0x2, 0x2d)); _gameStrings.itemTimeLimit = readString(*stream); stream.reset(_disk->createReadStream(0x8, 0x7, 0x02)); _gameStrings.carryingTooMuch = readString(*stream); stream.reset(_disk->createReadStream(0xc, 0xb, 0x20)); loadSong(*stream); }
void OpenGLGraphicsManager::displayMessageOnOSD(const char *msg) { #ifdef USE_OSD // HACK: Actually no client code should use graphics functions from // another thread. But the MT-32 emulator still does, thus we need to // make sure this doesn't happen while a updateScreen call is done. Common::StackLock lock(_osdMutex); // Slip up the lines. Common::Array<Common::String> osdLines; Common::StringTokenizer tokenizer(msg, "\n"); while (!tokenizer.empty()) { osdLines.push_back(tokenizer.nextToken()); } // Do the actual drawing like the SDL backend. const Graphics::Font *font = getFontOSD(); Graphics::Surface *dst = _osd->getSurface(); _osd->fill(0); _osd->flagDirty(); // Determine a rect which would contain the message string (clipped to the // screen dimensions). const int vOffset = 6; const int lineSpacing = 1; const int lineHeight = font->getFontHeight() + 2 * lineSpacing; int width = 0; int height = lineHeight * osdLines.size() + 2 * vOffset; for (uint i = 0; i < osdLines.size(); i++) { width = MAX(width, font->getStringWidth(osdLines[i]) + 14); } // Clip the rect width = MIN<int>(width, dst->w); height = MIN<int>(height, dst->h); int dstX = (dst->w - width) / 2; int dstY = (dst->h - height) / 2; // Draw a dark gray rect. const uint32 color = dst->format.RGBToColor(40, 40, 40); dst->fillRect(Common::Rect(dstX, dstY, dstX + width, dstY + height), color); // Render the message, centered, and in white const uint32 white = dst->format.RGBToColor(255, 255, 255); for (uint i = 0; i < osdLines.size(); ++i) { font->drawString(dst, osdLines[i], dstX, dstY + i * lineHeight + vOffset + lineSpacing, width, white, Graphics::kTextAlignCenter); } // Init the OSD display parameters. _osdAlpha = kOSDInitialAlpha; _osdFadeStartTime = g_system->getMillis() + kOSDFadeOutDelay; #endif }
bool Console::Cmd_GiveItem(int argc, const char **argv) { if (argc != 2) { debugPrintf("Usage: %s <ID | name>\n", argv[0]); return true; } Common::List<Item>::iterator item; char *end; uint id = strtoul(argv[1], &end, 0); if (*end != 0) { Common::Array<Item *> matches; Common::String name = toAppleWord(argv[1]); if (!_engine->_nouns.contains(name)) { debugPrintf("Item '%s' not found\n", argv[1]); return true; } byte noun = _engine->_nouns[name]; for (item = _engine->_state.items.begin(); item != _engine->_state.items.end(); ++item) { if (item->noun == noun) matches.push_back(&*item); } if (matches.size() == 0) { debugPrintf("Item '%s' not found\n", argv[1]); return true; } if (matches.size() > 1) { debugPrintf("Multiple matches found, please use item ID:\n"); for (uint i = 0; i < matches.size(); ++i) printItem(*matches[i]); return true; } matches[0]->room = IDI_ANY; debugPrintf("OK\n"); return true; } for (item = _engine->_state.items.begin(); item != _engine->_state.items.end(); ++item) if (item->id == id) { item->room = IDI_ANY; debugPrintf("OK\n"); return true; } debugPrintf("Item %i not found\n", id); return true; }