scummvm/engines/dm/inventory.cpp

209 lines
7.5 KiB
C++
Raw Normal View History

2016-08-26 22:36:31 +02:00
/* 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.
*
*/
/*
* Based on the Reverse Engineering work of Christophe Fontanel,
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
*/
#include "inventory.h"
2016-06-19 18:05:19 +02:00
#include "dungeonman.h"
#include "eventman.h"
#include "menus.h"
#include "gfx.h"
#include "text.h"
namespace DM {
2016-06-19 18:05:19 +02:00
Box gBoxFloppyZzzCross = Box(174, 218, 2, 12); // @ G0041_s_Graphic562_Box_ViewportFloppyZzzCross
Box gBoxPanel = Box(80, 223, 52, 124);
Box gBoxFood = Box(112, 159, 60, 68); // @ G0035_s_Graphic562_Box_Food
Box gBoxWater = Box(112, 159, 83, 91); // @ G0036_s_Graphic562_Box_Water
Box gBoxPoisoned = Box(112, 207, 105, 119); // @ G0037_s_Graphic562_Box_Poisoned
InventoryMan::InventoryMan(DMEngine *vm) : _vm(vm) {
_panelContent = kPanelContentFoodWaterPoisoned;
for (uint16 i = 0; i < 8; ++i)
_chestSlots[i] = Thing::_thingNone;
}
2016-06-19 18:05:19 +02:00
void InventoryMan::toggleInventory(ChampionIndex championIndex) {
ChampionMan &cm = *_vm->_championMan;
EventManager &em = *_vm->_eventMan;
DisplayMan &dm = *_vm->_displayMan;
if ((championIndex != kChampionCloseInventory) && !cm._champions[championIndex]._currHealth)
2016-06-19 18:05:19 +02:00
return;
if (_vm->_pressingEye || _vm->_pressingMouth)
return;
_vm->_stopWaitingForPlayerInput = true;
int16 invChampOrdinal = _inventoryChampionOrdinal; // copy, as the original will be edited
2016-06-23 23:12:39 +02:00
if (_vm->indexToOrdinal(championIndex) == invChampOrdinal) {
championIndex = kChampionCloseInventory;
2016-06-19 18:05:19 +02:00
}
Champion *champion;
if (invChampOrdinal) {
2016-06-23 23:12:39 +02:00
_inventoryChampionOrdinal = _vm->indexToOrdinal(kChampionNone);
2016-06-19 18:05:19 +02:00
warning("MISSING CODE: F0334_INVENTORY_CloseChest");
2016-06-23 23:12:39 +02:00
champion = &cm._champions[_vm->ordinalToIndex(invChampOrdinal)];
2016-06-19 18:05:19 +02:00
if (champion->_currHealth && !cm._candidateChampionOrdinal) {
champion->setAttributeFlag(kChampionAttributeStatusBox, true);
2016-06-23 23:12:39 +02:00
cm.drawChampionState((ChampionIndex)_vm->ordinalToIndex(invChampOrdinal));
2016-06-19 18:05:19 +02:00
}
if (cm._partyIsSleeping) {
return;
}
if (championIndex == kChampionCloseInventory) {
2016-06-19 18:05:19 +02:00
em._refreshMousePointerInMainLoop = true;
_vm->_menuMan->drawMovementArrows();
em._secondaryMouseInput = gSecondaryMouseInput_Movement;
warning("MISSING CODE: set G0444_ps_SecondaryKeyboardInput");
warning("MISSING CODE: F0357_COMMAND_DiscardAllInput");
return;
}
}
dm._useByteBoxCoordinates = false;
2016-06-23 23:12:39 +02:00
_inventoryChampionOrdinal = _vm->indexToOrdinal(championIndex);
2016-06-19 18:05:19 +02:00
if (!invChampOrdinal) {
warning("MISSING CODE: F0136_VIDEO_ShadeScreenBox");
}
champion = &cm._champions[championIndex];
int16 w = dm.getWidth(kInventoryGraphicIndice);
int16 h = dm.getHeight(kInventoryGraphicIndice);
dm.blitToScreen(dm.getBitmap(kInventoryGraphicIndice), w, 0, 0, 0, w, 0, h, kColorNoTransparency, gDungeonViewport);
if (cm._candidateChampionOrdinal) {
dm.clearScreenBox(kColorDarkestGray, gBoxFloppyZzzCross, gDungeonViewport);
}
_vm->_textMan->printToViewport(5, 116, kColorLightestGray, "HEALTH");
_vm->_textMan->printToViewport(5, 124, kColorLightestGray, "STAMINA");
_vm->_textMan->printToViewport(5, 132, kColorLightestGray, "MANA");
2016-06-19 18:05:19 +02:00
for (uint16 slotIndex = kChampionSlotReadyHand; slotIndex < kChampionSlotChest_1; slotIndex++) {
_vm->_championMan->drawSlot(championIndex, (ChampionSlot)slotIndex);
}
2016-06-19 18:05:19 +02:00
champion->setAttributeFlag(kChampionAttributeViewport, true);
champion->setAttributeFlag(kChampionAttributeStatusBox, true);
champion->setAttributeFlag(kChampionAttributePanel, true);
champion->setAttributeFlag(kChampionAttributeLoad, true);
champion->setAttributeFlag(kChampionAttributeStatistics, true);
champion->setAttributeFlag(kChampionAttributeNameTitle, true);
cm.drawChampionState(championIndex);
2016-06-19 18:05:19 +02:00
em._mousePointerBitmapUpdated = true;
em._secondaryMouseInput = gSecondaryMouseInput_ChampionInventory;
warning("MISSING CODE: set G0444_ps_SecondaryKeyboardInput");
warning("MISSING CODE: F0357_COMMAND_DiscardAllInput");
}
void InventoryMan::drawStatusBoxPortrait(ChampionIndex championIndex) {
DisplayMan &dispMan = *_vm->_displayMan;
dispMan._useByteBoxCoordinates = false;
Box box;
box._y1 = 0;
box._y2 = 28 + 1;
box._x1 = championIndex * kChampionStatusBoxSpacing + 7;
box._x2 = box._x1 + 31 + 1;
dispMan.blitToScreen(_vm->_championMan->_champions[championIndex]._portrait, 32, 0, 0, box, kColorNoTransparency);
}
2016-06-19 18:05:19 +02:00
void InventoryMan::drawPanelHorizontalBar(int16 x, int16 y, int16 pixelWidth, Color color) {
Box box;
box._x1 = x;
box._x2 = box._x1 + pixelWidth + 1;
box._y1 = y;
box._y2 = box._y1 + 6 + 1;
_vm->_displayMan->_useByteBoxCoordinates = false;
_vm->_displayMan->clearScreenBox(color, box);
}
void InventoryMan::drawPanelFoodOrWaterBar(int16 amount, int16 y, Color color) {
if (amount < -512) {
color = kColorRed;
} else if (amount < 0) {
color = kColorYellow;
}
int16 pixelWidth = amount + 1024;
if (pixelWidth == 3072) {
pixelWidth = 3071;
}
pixelWidth /= 32;
drawPanelHorizontalBar(115, y + 2, pixelWidth, kColorBlack);
drawPanelHorizontalBar(113, y, pixelWidth, color);
}
void InventoryMan::drawPanelFoodWaterPoisoned() {
Champion &champ = _vm->_championMan->_champions[_inventoryChampionOrdinal];
warning("MISSING CODE: F0334_INVENTORY_CloseChest");
DisplayMan &dispMan = *_vm->_displayMan;
dispMan.blitToScreen(dispMan.getBitmap(kPanelEmptyIndice), 144, 0, 0, gBoxPanel, kColorRed);
dispMan.blitToScreen(dispMan.getBitmap(kFoodLabelIndice), 48, 0, 0, gBoxFood, kColorDarkestGray);
dispMan.blitToScreen(dispMan.getBitmap(kWaterLabelIndice), 48, 0, 0, gBoxWater, kColorDarkestGray);
if (champ._poisonEventCount) {
dispMan.blitToScreen(dispMan.getBitmap(kPoisionedLabelIndice), 96, 0, 0, gBoxPoisoned, kColorDarkestGray);
}
drawPanelFoodOrWaterBar(champ._food, 69, kColorLightBrown);
drawPanelFoodOrWaterBar(champ._water, 92, kColorBlue);
}
void InventoryMan::drawPanelResurrectReincarnate() {
_panelContent = kPanelContentResurrectReincarnate;
_vm->_displayMan->blitToScreen(_vm->_displayMan->getBitmap(kPanelResurectReincaranteIndice), 144, 0, 0, gBoxPanel, kColorDarkGreen, gDungeonViewport);
}
2016-06-21 15:09:24 +02:00
void InventoryMan::drawPanel() {
warning("MISSING CODE: F0334_INVENTORY_CloseChest, altho adding it may reintroduce BUG0_48");
ChampionMan &cm = *_vm->_championMan;
if (cm._candidateChampionOrdinal) {
drawPanelResurrectReincarnate();
return;
}
2016-06-23 23:12:39 +02:00
Thing thing = cm._champions[_vm->ordinalToIndex(_inventoryChampionOrdinal)].getSlot(kChampionSlotActionHand);
2016-06-21 15:09:24 +02:00
_panelContent = kPanelContentFoodWaterPoisoned;
switch (thing.getType()) {
case kContainerThingType:
_panelContent = kPanelContentChest;
break;
case kScrollThingType:
_panelContent = kPanelContentScroll;
break;
default:
thing = Thing::_thingNone;
break;
}
if (thing == Thing::_thingNone) {
drawPanelFoodWaterPoisoned();
} else {
warning("MISSING CODE: F0342_INVENTORY_DrawPanel_Object(L1075_T_Thing, C0_FALSE);");
}
}
}