/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "common/system.h" #include "graphics/palette.h" #include "common/file.h" #include "common/rect.h" #include "engines/util.h" #include "hopkins/files.h" #include "hopkins/globals.h" #include "hopkins/hopkins.h" namespace Hopkins { ObjectsManager::ObjectsManager() { PRIORITY = 0; } void ObjectsManager::setParent(HopkinsEngine *vm) { _vm = vm; } byte *ObjectsManager::CHANGE_OBJET(int objIndex) { byte *result = ObjectsManager::CAPTURE_OBJET(objIndex, 1); GLOBALS.Bufferobjet = result; GLOBALS.Nouv_objet = 1; GLOBALS.OBJET_EN_COURS = objIndex; return result; } byte *ObjectsManager::CAPTURE_OBJET(int objIndex, int mode) { byte *result = NULL; byte *dataP; dataP = 0; int val1 = GLOBALS.ObjetW[objIndex].field0; int val2 = GLOBALS.ObjetW[objIndex].field1; if (mode == 1) ++val2; if (val1 != GLOBALS.NUM_FICHIER_OBJ) { if (GLOBALS.ADR_FICHIER_OBJ != PTRNUL) ObjectsManager::DEL_FICHIER_OBJ(); if (val1 == 1) { FileManager::CONSTRUIT_SYSTEM("OBJET1.SPR"); GLOBALS.ADR_FICHIER_OBJ = ObjectsManager::CHARGE_SPRITE(GLOBALS.NFICHIER); } GLOBALS.NUM_FICHIER_OBJ = val1; } int width = ObjectsManager::Get_Largeur(GLOBALS.ADR_FICHIER_OBJ, val2); int height = ObjectsManager::Get_Hauteur(GLOBALS.ADR_FICHIER_OBJ, val2); GLOBALS.OBJL = width; GLOBALS.OBJH = height; switch (mode) { case 0: dataP = GLOBALS.dos_malloc2(height * width); if (dataP == PTRNUL) error("CAPTURE_OBJET"); ObjectsManager::capture_mem_sprite(GLOBALS.ADR_FICHIER_OBJ, dataP, val2); break; case 1: ObjectsManager::sprite_alone(GLOBALS.ADR_FICHIER_OBJ, GLOBALS.Bufferobjet, val2); result = GLOBALS.Bufferobjet; break; case 3: ObjectsManager::capture_mem_sprite(GLOBALS.ADR_FICHIER_OBJ, GLOBALS.INVENTAIRE_OBJET, val2); result = GLOBALS.INVENTAIRE_OBJET; break; default: result = dataP; break; } return result; } void ObjectsManager::set_offsetxy(byte *data, int idx, int xp, int yp, bool isSize) { byte *startP = data + 3; for (int i = idx; i; --i) startP += READ_LE_UINT32(startP) + 16; byte *rectP = startP + 8; if (isSize == 1) { // Set size byte *pointP = rectP + 4; WRITE_LE_UINT16(pointP, xp); WRITE_LE_UINT16(pointP + 2, yp); } else { // Set position WRITE_LE_UINT16(rectP, xp); WRITE_LE_UINT16(rectP + 2, yp); } } int ObjectsManager::Get_Largeur(const byte *objectData, int idx) { const byte *rectP = objectData + 3; for (int i = idx; i; --i) rectP += READ_LE_UINT32(rectP) + 16; return (int16)READ_LE_UINT16(rectP + 4); } int ObjectsManager::Get_Hauteur(const byte *objectData, int idx) { const byte *rectP = objectData + 3; for (int i = idx; i; --i) rectP += READ_LE_UINT32(rectP) + 16; return (int16)READ_LE_UINT16(rectP + 6); } int ObjectsManager::sprite_alone(const byte *objectData, byte *sprite, int objIndex) { const byte *objP = objectData + 3; for (int i = objIndex; i; --i) { objP += READ_LE_UINT32(objP) + 16; } objP += 4; int result = READ_LE_UINT16(objP) * READ_LE_UINT16(objP + 2); memcpy(sprite + 3, objP - 4, result + 16); return result; } byte *ObjectsManager::DEL_FICHIER_OBJ() { GLOBALS.NUM_FICHIER_OBJ = 0; if (GLOBALS.ADR_FICHIER_OBJ != PTRNUL) GLOBALS.ADR_FICHIER_OBJ = FileManager::LIBERE_FICHIER(GLOBALS.ADR_FICHIER_OBJ); byte *result = PTRNUL; GLOBALS.ADR_FICHIER_OBJ = PTRNUL; return result; } byte *ObjectsManager::CHARGE_SPRITE(const Common::String &file) { FileManager::DMESS1(); return FileManager::CHARGE_FICHIER(file); } int ObjectsManager::capture_mem_sprite(const byte *objectData, byte *sprite, int objIndex) { const byte *objP = objectData + 3; for (int i = objIndex; i; --i) { objP += READ_LE_UINT32(objP) + 16; } objP += 4; int result = READ_LE_UINT16(objP) * READ_LE_UINT16(objP + 2); memcpy(sprite, objP + 12, result); return result; } int ObjectsManager::AJOUTE_OBJET(int objIndex) { bool flag = false; int arrIndex = 0; do { ++arrIndex; if (!GLOBALS.INVENTAIRE[arrIndex]) flag = true; if (arrIndex == 32) flag = true; } while (!flag); GLOBALS.INVENTAIRE[arrIndex] = objIndex; return arrIndex; } void ObjectsManager::INIT_BOB() { for (int idx = 0; idx < 35; ++idx) { BOB_ZERO(idx); } } void ObjectsManager::BOB_ZERO(int idx) { BobItem &bob = _vm->_globals.Bob[idx]; Liste2Item &item = _vm->_globals.Liste2[idx]; bob.field0 = 0; bob.field4 = PTRNUL; bob.field8 = 0; bob.fieldA = 0; bob.fieldC = 0; bob.fieldE = 0; bob.field10 = 0; bob.field12 = 0; bob.field14 = 0; bob.field16 = 0; bob.field18 = PTRNUL; bob.field1A = 0; bob.field1C = 0; bob.field1E = 0; bob.field20 = 0; bob.field22 = 0; bob.field24 = 0; bob.field26 = 0; bob.field28 = 0; bob.field2A = 0; bob.field2C = 0; bob.field30 = PTRNUL; bob.field34 = 0; bob.field36 = 0; bob.field38 = 0; bob.field46 = 0; item.field0 = 0; item.field2 = 0; item.field4 = 0; item.field6 = 0; item.field8 = 0; } void ObjectsManager::BOB_VISU(int idx) { int v1; const byte *data; int16 v6; int16 v7; int16 v8; int16 v9; PRIORITY = 1; if (!_vm->_globals.Bob[idx].field0) { BOB_ZERO(idx); data = _vm->_globals.Bqe_Anim[idx].data; v1 = READ_LE_UINT16(data); v9 = READ_LE_UINT16(data + 2); v8 = READ_LE_UINT16(data + 4); v7 = READ_LE_UINT16(data + 6); v6 = READ_LE_UINT16(data + 8); if (READ_LE_UINT16(data)) { if (_vm->_globals.Bank[idx].field4) { if (!v9) v9 = 1; if (!v6) v6 = -1; if (READ_LE_UINT16(data + 24)) { _vm->_globals.Bob[idx].field3A = 0; if (_vm->_globals.Bank[idx].fileHeader == 1) { _vm->_globals.Bob[idx].field3A = 1; _vm->_globals.Bob[idx].field36 = 0; _vm->_globals.Bob[idx].field38 = 0; } _vm->_globals.Bob[idx].field18 = _vm->_globals.Bqe_Anim[idx].data; _vm->_globals.Bob[idx].field0 = 10; _vm->_globals.Bob[idx].field4 = _vm->_globals.Bank[idx].data; _vm->_globals.Bob[idx].field1E = v9; _vm->_globals.Bob[idx].field20 = v6; _vm->_globals.Bob[idx].field22 = v8; _vm->_globals.Bob[idx].field24 = v7; } } } } } void ObjectsManager::BOB_OFF(int idx) { if (_vm->_globals.Bob[idx].field0 == 3) _vm->_globals.Bob[idx].field0 = 4; else if (_vm->_globals.Bob[idx].field0 == 10) _vm->_globals.Bob[idx].field0 = 11; } } // End of namespace Hopkins