// Save the prepared API information. bool QsciAPIs::savePrepared(const QString &filename) const { QString pname = prepName(filename, true); if (pname.isEmpty()) return false; // Write the prepared data to a memory buffer. QByteArray pdata; QDataStream pds(&pdata, QIODevice::WriteOnly); // Use a serialisation format supported by Qt v3.0 and later. pds.setVersion(QDataStream::Qt_3_0); pds << PreparedDataFormatVersion; pds << lexer()->lexer(); pds << prep->wdict; pds << prep->raw_apis; // Compress the data and write it. QFile pf(pname); if (!pf.open(QIODevice::WriteOnly|QIODevice::Truncate)) return false; if (pf.write(qCompress(pdata)) < 0) { pf.close(); return false; } pf.close(); return true; }
// Check that a prepared API file exists. bool QsciAPIs::isPrepared(const QString &filename) const { QString pname = prepName(filename); if (pname.isEmpty()) return false; QFileInfo fi(pname); return fi.exists(); }
// Return the name of the default prepared API file. QString QsciAPIs::defaultPreparedName() const { return prepName(QString()); }
// Load the prepared API information. bool QsciAPIs::loadPrepared(const QString &filename) { QString pname = prepName(filename); if (pname.isEmpty()) return false; // Read the prepared data and decompress it. QFile pf(pname); if (!pf.open(QIODevice::ReadOnly)) return false; QByteArray cpdata = pf.readAll(); pf.close(); if (cpdata.count() == 0) return false; QByteArray pdata = qUncompress(cpdata); // Extract the data. QDataStream pds(pdata); unsigned char vers; pds >> vers; if (vers > PreparedDataFormatVersion) return false; char *lex_name; pds >> lex_name; if (qstrcmp(lex_name, lexer()->lexer()) != 0) { delete[] lex_name; return false; } delete[] lex_name; prep->wdict.clear(); pds >> prep->wdict; if (!lexer()->caseSensitive()) { // Build up the case dictionary. prep->cdict.clear(); QMap<QString, WordIndexList>::const_iterator it = prep->wdict.begin(); while (it != prep->wdict.end()) { prep->cdict[it.key().toUpper()] = it.key(); ++it; } } prep->raw_apis.clear(); pds >> prep->raw_apis; // Allow the raw API information to be modified. apis = prep->raw_apis; return true; }
static monster_t *convertMonster(b2mon_t *inMonster) { monster_t *m; int i; for (i = 0; i < 16; i++) { if (inMonster->name[i] & 0x80) inMonster->name[i] ^= 0x80; if ((inMonster->name[i] == '/') || (inMonster->name[i] == '\\')) inMonster->name[i] = '^'; if (inMonster->name[i] == 0x7f) inMonster->name[i] = '\0'; } if (inMonster->name[0] == '\0') return NULL; m = monster_new(); m->singular = prepName(inMonster->name, 0); m->plural = prepName(inMonster->name, 1); m->picture = getPicMacro(inMonster->picindex); m->reward = ((inMonster->numattacks + 1) * inMonster->basemelee) << 7; m->hpRndNdice = 1; m->hpRndDie = inMonster->hpRnd; m->hpBase = inMonster->hpBase; m->groupSize = (inMonster->maxgrp << 1) + 1; m->distance = (inMonster->flags >> 4) * 10; m->advSpeed = inMonster->advancespeed * 10; m->willAdvance = willAdvance(inMonster); m->baseAC = 10 - inMonster->baseac2hit; m->breathSaveLo = inMonster->basemelee >> 3; m->breathSaveHi = (inMonster->basemelee >> 3) + 8; m->spellSaveLo = m->breathSaveLo; m->spellSaveHi = m->breathSaveHi; m->toHitLo = inMonster->baseac2hit; m->toHitHi = inMonster->baseac2hit + 3; m->pronoun = (inMonster->flags & 1) ? 0 : 1; m->numAttacks = inMonster->numattacks + 1; #define CAP(x,y) ((x) > (y)) ? (y) : (x) m->priorityLo = CAP(((inMonster->basemelee << 2) | 1), 0xff); m->priorityLo = CAP((((inMonster->basemelee << 2) | 1) + 31), 0xff); #undef CAP switch (inMonster->picindex) { case 33: case 53: case 57: case 60: m->repel.spellcaster = 1; break; case 34: case 35: case 37: case 40: case 41: case 54: m->repel.evil = 1; break; } for (i = 0; i < 4; i++) { monsterAttack_t *ma = NULL; uint8_t att; att = inMonster->attTypes[i]; if (att == 0) { bteAttack_t *ba; ma = monsterAttack_new(ACT_MELEE); ma->action = btAction_new(FUNC_NONE, EFFECT_ATTACK); ba = btEffect_attack(ma->action->effect); ba->dieval = 4; ba->ndice = inMonster->basemelee; ba->spAttack = inMonster->meleeatttype & 0x0f; if (ba->spAttack > 9) ba->spAttack = 0; ba->attype = 8; ba->meleeString = ((inMonster->meleeatttype & 0xf0) >> 4) + 1; } else if (att < 79) {