mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-16 14:50:17 +00:00
CHEWY: Refactor the functionality for item usage descriptions
This commit is contained in:
parent
27dc8075fb
commit
9cab6a68da
@ -41,13 +41,6 @@ bool AtsTxtHeader::load(Common::SeekableReadStream *src) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InvUse::load(Common::SeekableReadStream *src) {
|
||||
_objId = src->readSint16LE();
|
||||
_objNr = src->readSint16LE();
|
||||
_txtNr = src->readSint16LE();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AadInfo::load(Common::SeekableReadStream *src) {
|
||||
_x = src->readSint16LE();
|
||||
_y = src->readSint16LE();
|
||||
@ -122,6 +115,8 @@ Atdsys::Atdsys() {
|
||||
_adsnb._blkNr = 0;
|
||||
_adsnb._endNr = 0;
|
||||
_adsStackPtr = 0;
|
||||
|
||||
initItemUseWith();
|
||||
}
|
||||
|
||||
Atdsys::~Atdsys() {
|
||||
@ -135,6 +130,29 @@ Atdsys::~Atdsys() {
|
||||
delete _dialogResource;
|
||||
}
|
||||
|
||||
void Atdsys::initItemUseWith() {
|
||||
int16 objA, objB, txtNum;
|
||||
|
||||
Common::File f;
|
||||
f.open(INV_USE_IDX);
|
||||
|
||||
// The file is 25200 bytes, and contains 25200 / 50 / 6 = 84 blocks
|
||||
int totalEntries = f.size() / 6;
|
||||
|
||||
for (int entry = 0; entry < totalEntries; entry++) {
|
||||
objA = f.readSint16LE();
|
||||
objB = f.readSint16LE();
|
||||
txtNum = f.readSint16LE();
|
||||
|
||||
assert(objA <= 255 && objB <= 65535);
|
||||
|
||||
const uint32 key = (objA & 0xff) << 16 | objB;
|
||||
_itemUseWithDesc[key] = txtNum;
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
void Atdsys::set_delay(int16 *delay, int16 silent) {
|
||||
_atdsv._delay = delay;
|
||||
_atdsv._silent = silent;
|
||||
@ -368,20 +386,13 @@ void Atdsys::set_handle(const char *fname, int16 mode, Common::Stream *handle, i
|
||||
}
|
||||
|
||||
void Atdsys::open_handle(const char *fname, int16 mode) {
|
||||
char *tmp_adr = nullptr;
|
||||
|
||||
if (mode != INV_IDX_DATA)
|
||||
tmp_adr = atds_adr(fname, 0, 20000);
|
||||
_atdsMem[mode] = atds_adr(fname, 0, 20000);
|
||||
|
||||
Common::File *f = new Common::File();
|
||||
f->open(fname);
|
||||
if (f->isOpen()) {
|
||||
close_handle(mode);
|
||||
_atdsHandle[mode] = f;
|
||||
_atdsMem[mode] = tmp_adr;
|
||||
|
||||
if (mode == INV_IDX_DATA)
|
||||
_atdsMem[INV_IDX_HANDLE] = (char *)MALLOC(INV_STRC_NR * sizeof(InvUse));
|
||||
} else {
|
||||
error("Error reading from %s", fname);
|
||||
}
|
||||
@ -1320,44 +1331,17 @@ void Atdsys::show_item(int16 diaNr, int16 blockNr, int16 itemNr) {
|
||||
}
|
||||
|
||||
int16 Atdsys::calc_inv_no_use(int16 curInv, int16 testNr, int16 mode) {
|
||||
int16 txt_nr = -1;
|
||||
if (curInv != -1) {
|
||||
if (_invBlockNr != curInv) {
|
||||
_invBlockNr = curInv + 1;
|
||||
load_atds(_invBlockNr + _atdsPoolOff[mode], INV_USE_DATA);
|
||||
|
||||
Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(
|
||||
_atdsHandle[INV_IDX_HANDLE]);
|
||||
if (rs) {
|
||||
rs->seek(InvUse::SIZE() * _invBlockNr
|
||||
* INV_STRC_NR, SEEK_SET);
|
||||
|
||||
InvUse *iu = (InvUse *)_atdsMem[INV_IDX_HANDLE];
|
||||
for (int16 i = 0; i < INV_STRC_NR; ++i, ++iu) {
|
||||
if (!iu->load(rs)) {
|
||||
error("calc_inv_no_use error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error("calc_inv_no_use error");
|
||||
}
|
||||
}
|
||||
|
||||
InvUse *iu = (InvUse *)_atdsMem[INV_IDX_HANDLE];
|
||||
bool ok = false;
|
||||
|
||||
for (int16 i = 0; i < INV_STRC_NR && !ok; i++) {
|
||||
if (iu[i]._objId == mode) {
|
||||
if (iu[i]._objNr == testNr) {
|
||||
txt_nr = iu[i]._txtNr;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return txt_nr;
|
||||
assert(mode <= 255 && testNr <= 65535);
|
||||
|
||||
const uint32 key = (mode & 0xff) << 16 | testNr;
|
||||
return (_itemUseWithDesc.contains(key)) ? _itemUseWithDesc[key] : -1;
|
||||
}
|
||||
|
||||
int16 Atdsys::getStereoPos(int16 x) {
|
||||
|
@ -36,7 +36,6 @@ namespace Chewy {
|
||||
#define ATS_DATA 1
|
||||
#define ADS_DATA 2
|
||||
#define INV_USE_DATA 4
|
||||
#define INV_IDX_DATA 5
|
||||
#define INV_ATS_DATA 6
|
||||
|
||||
#define MAX_HANDLE 8
|
||||
@ -44,7 +43,6 @@ namespace Chewy {
|
||||
#define ATS_HANDLE 1
|
||||
#define ADS_HANDLE 2
|
||||
#define INV_USE_HANDLE 4
|
||||
#define INV_IDX_HANDLE 5
|
||||
#define INV_ATS_HANDLE 6
|
||||
#define ATDS_HANDLE 7
|
||||
|
||||
@ -117,16 +115,6 @@ struct AtdsVar {
|
||||
#define IUID_DET 4
|
||||
#define IUID_PLAYER 5
|
||||
#define INV_USE_DEF 16
|
||||
#define INV_STRC_NR 30
|
||||
|
||||
struct InvUse {
|
||||
int16 _objId;
|
||||
int16 _objNr;
|
||||
int16 _txtNr;
|
||||
|
||||
bool load(Common::SeekableReadStream *src);
|
||||
static constexpr int SIZE() { return 6; }
|
||||
};
|
||||
|
||||
struct AadInfo {
|
||||
int16 _x;
|
||||
@ -323,6 +311,7 @@ public:
|
||||
|
||||
private:
|
||||
int16 get_delay(int16 txt_len);
|
||||
void initItemUseWith();
|
||||
|
||||
Common::Stream *_atdsHandle[MAX_HANDLE] = { nullptr };
|
||||
char *_atdsMem[MAX_HANDLE] = { nullptr };
|
||||
@ -365,6 +354,8 @@ private:
|
||||
int16 _mousePush = 0;
|
||||
int _printDelayCount1 = 0;
|
||||
DialogResource *_dialogResource;
|
||||
|
||||
Common::HashMap<uint32, uint16> _itemUseWithDesc;
|
||||
};
|
||||
|
||||
} // namespace Chewy
|
||||
|
@ -188,7 +188,6 @@ void init_atds() {
|
||||
_G(atds)->set_handle(ATDS_TXT, INV_USE_DATA, handle, USE_TAP_OFF, USE_TAP_MAX);
|
||||
_G(atds)->init_ats_mode(INV_USE_DATA, _G(spieler).InvUse);
|
||||
_G(atds)->init_ats_mode(INV_USE_DEF, _G(spieler).InvUseDef);
|
||||
_G(atds)->open_handle(INV_USE_IDX, INV_IDX_DATA);
|
||||
_G(spieler).AadSilent = 10;
|
||||
_G(spieler).DelaySpeed = 5;
|
||||
_G(spieler_vector)[P_CHEWY].Delay = _G(spieler).DelaySpeed;
|
||||
|
Loading…
Reference in New Issue
Block a user