From cb7b382acfd29957c9522b08b6460526fc73983c Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 2 Sep 2011 01:06:17 -0400 Subject: PEGASUS: Restructure remaining (already converted) Game Shell classes --- engines/pegasus/Game_Shell/CInventory.cpp | 175 ----------------- engines/pegasus/Game_Shell/CInventory.h | 80 -------- engines/pegasus/Game_Shell/CItem.cpp | 111 ----------- engines/pegasus/Game_Shell/CItem.h | 255 ------------------------- engines/pegasus/Game_Shell/CItemList.cpp | 79 -------- engines/pegasus/Game_Shell/CItemList.h | 60 ------ engines/pegasus/MMShell/Sounds/MMSound.cpp | 126 ------------ engines/pegasus/MMShell/Sounds/MMSound.h | 84 -------- engines/pegasus/MMShell/Utilities/MMIDObject.h | 14 +- engines/pegasus/gamestate.cpp | 8 +- engines/pegasus/gamestate.h | 6 +- engines/pegasus/items/inventory.cpp | 175 +++++++++++++++++ engines/pegasus/items/inventory.h | 80 ++++++++ engines/pegasus/items/item.cpp | 111 +++++++++++ engines/pegasus/items/item.h | 255 +++++++++++++++++++++++++ engines/pegasus/items/itemlist.cpp | 79 ++++++++ engines/pegasus/items/itemlist.h | 60 ++++++ engines/pegasus/menu.cpp | 15 +- engines/pegasus/module.mk | 8 +- engines/pegasus/sound.cpp | 126 ++++++++++++ engines/pegasus/sound.h | 84 ++++++++ 21 files changed, 995 insertions(+), 996 deletions(-) delete mode 100755 engines/pegasus/Game_Shell/CInventory.cpp delete mode 100755 engines/pegasus/Game_Shell/CInventory.h delete mode 100755 engines/pegasus/Game_Shell/CItem.cpp delete mode 100755 engines/pegasus/Game_Shell/CItem.h delete mode 100755 engines/pegasus/Game_Shell/CItemList.cpp delete mode 100755 engines/pegasus/Game_Shell/CItemList.h delete mode 100755 engines/pegasus/MMShell/Sounds/MMSound.cpp delete mode 100755 engines/pegasus/MMShell/Sounds/MMSound.h create mode 100755 engines/pegasus/items/inventory.cpp create mode 100755 engines/pegasus/items/inventory.h create mode 100755 engines/pegasus/items/item.cpp create mode 100755 engines/pegasus/items/item.h create mode 100755 engines/pegasus/items/itemlist.cpp create mode 100755 engines/pegasus/items/itemlist.h create mode 100755 engines/pegasus/sound.cpp create mode 100755 engines/pegasus/sound.h (limited to 'engines/pegasus') diff --git a/engines/pegasus/Game_Shell/CInventory.cpp b/engines/pegasus/Game_Shell/CInventory.cpp deleted file mode 100755 index 64e62b4406..0000000000 --- a/engines/pegasus/Game_Shell/CInventory.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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 "pegasus/constants.h" -#include "pegasus/Game_Shell/CItem.h" -#include "pegasus/Game_Shell/CInventory.h" - -namespace Pegasus { - -CInventory::CInventory() { - fWeightLimit = 100; - fOwnerID = kNoActorID; - fReferenceCount = 0; -} - -CInventory::~CInventory() { -} - -void CInventory::SetWeightLimit(tWeightType limit) { - fWeightLimit = limit; - // *** What to do if the new weight limit is greater than the current weight? -} - -tWeightType CInventory::GetWeight() { - tWeightType result = 0; - - for (CItemIterator it = fInventoryList.begin(); it != fInventoryList.end(); it++) - result += (*it)->GetItemWeight(); - - return result; -} - -// If the item already belongs, just return kInventoryOK. -tInventoryResult CInventory::AddItem(CItem *item) { - if (ItemInInventory(item)) - return kInventoryOK; - - if (GetWeight() + item->GetItemWeight() > fWeightLimit) - return kTooMuchWeight; - - fInventoryList.push_back(item); - item->SetItemOwner(fOwnerID); - - ++fReferenceCount; - return kInventoryOK; -} - -tInventoryResult CInventory::RemoveItem(CItem *item) { - for (CItemIterator it = fInventoryList.begin(); it != fInventoryList.end(); it++) { - if (*it == item) { - fInventoryList.erase(it); - item->SetItemOwner(kNoActorID); - - ++fReferenceCount; - return kInventoryOK; - } - } - - return kItemNotInInventory; -} - -tInventoryResult CInventory::RemoveItem(tItemID id) { - CItem *item = FindItemByID(id); - - if (item) { - fInventoryList.remove(item); - item->SetItemOwner(kNoActorID); - - ++fReferenceCount; - return kInventoryOK; - } - - return kItemNotInInventory; -} - -void CInventory::RemoveAllItems() { - fInventoryList.clear(); - ++fReferenceCount; -} - -bool CInventory::ItemInInventory(CItem *item) { - for (CItemIterator it = fInventoryList.begin(); it != fInventoryList.end(); it++) - if (*it == item) - return true; - - return false; -} - -bool CInventory::ItemInInventory(tItemID id) { - return FindItemByID(id) != NULL; -} - -CItem *CInventory::GetItemAt(int32 index) { - int32 i = 0; - for (CItemIterator it = fInventoryList.begin(); it != fInventoryList.end(); it++, i++) - if (i == index) - return *it; - - return 0; -} - -tItemID CInventory::GetItemIDAt(int32 index) { - CItem *item = GetItemAt(index); - - if (item) - return item->GetObjectID(); - - return kNoItemID; -} - -CItem *CInventory::FindItemByID(tItemID id) { - return fInventoryList.FindItemByID(id); -} - -// Return -1 if not found. - -int32 CInventory::FindIndexOf(CItem *item) { - uint32 i = 0; - for (CItemIterator it = fInventoryList.begin(); it != fInventoryList.end(); it++, i++) - if (*it == item) - return i; - - return -1; -} - -// Return -1 if not found. - -int32 CInventory::FindIndexOf(tItemID id) { - uint32 i = 0; - for (CItemIterator it = fInventoryList.begin(); it != fInventoryList.end(); it++, i++) - if ((*it)->GetObjectID() == id) - return i; - - return -1; -} - -tWeightType CInventory::GetWeightLimit() { - return fWeightLimit; -} - -int32 CInventory::GetNumItems() { - return fInventoryList.size(); -} - -void CInventory::SetOwnerID(const tActorID id) { - fOwnerID = id; -} - -tActorID CInventory::GetOwnerID() const { - return fOwnerID; -} - -} // End of namespae Pegasus diff --git a/engines/pegasus/Game_Shell/CInventory.h b/engines/pegasus/Game_Shell/CInventory.h deleted file mode 100755 index 45af5c379c..0000000000 --- a/engines/pegasus/Game_Shell/CInventory.h +++ /dev/null @@ -1,80 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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. - * - */ - -#ifndef PEGASUS_GAMESHELL_CINVENTORY_H -#define PEGASUS_GAMESHELL_CINVENTORY_H - -#include "pegasus/types.h" -#include "pegasus/Game_Shell/CItemList.h" - -namespace Pegasus { - -class CItem; - -// Inventories have a "current item". This item is the default item the player can -// use. In a text adventure system, the current item would be "it", as in -// "Hit the troll with it," where "it" would refer to some weapon which is the current -// item. In a graphic adventure, the current item would be the item the user selects -// to use with the mouse or other pointing device. - -class CInventory { -public: - CInventory(); - virtual ~CInventory(); - - tWeightType GetWeightLimit(); - void SetWeightLimit(tWeightType limit); - tWeightType GetWeight(); - - virtual tInventoryResult AddItem(CItem *item); - virtual tInventoryResult RemoveItem(CItem *item); - virtual tInventoryResult RemoveItem(tItemID id); - virtual bool ItemInInventory(CItem *item); - virtual bool ItemInInventory(tItemID id); - virtual CItem *GetItemAt(int32 index); - virtual tItemID GetItemIDAt(int32 index); - virtual CItem *FindItemByID(tItemID id); - virtual int32 FindIndexOf(CItem *item); - virtual int32 FindIndexOf(tItemID id); - int32 GetNumItems(); - virtual void RemoveAllItems(); - - void SetOwnerID(const tActorID id); - tActorID GetOwnerID() const; - - uint32 GetReferenceCount() { return fReferenceCount; } - -protected: - tWeightType fWeightLimit; - tActorID fOwnerID; - CItemList fInventoryList; - -private: - uint32 fReferenceCount; -}; - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/Game_Shell/CItem.cpp b/engines/pegasus/Game_Shell/CItem.cpp deleted file mode 100755 index b96c24ce49..0000000000 --- a/engines/pegasus/Game_Shell/CItem.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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/error.h" -#include "common/stream.h" - -#include "pegasus/constants.h" -#include "pegasus/Game_Shell/CItem.h" -#include "pegasus/Game_Shell/CItemList.h" - -namespace Pegasus { - -CItem::CItem(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) : MMIDObject(id) { - fItemNeighborhood = neighborhood; - fItemRoom = room; - fItemDirection = direction; - fItemWeight = 1; - fItemOwnerID = kNoActorID; - fItemState = 0; - - gAllItems.push_back(this); -} - -CItem::~CItem() { -} - -Common::Error CItem::WriteToStream(Common::WriteStream *stream) { - stream->writeUint16BE(fItemNeighborhood); - stream->writeUint16BE(fItemRoom); - stream->writeByte(fItemDirection); - stream->writeUint16BE(fItemOwnerID); - stream->writeUint16BE(fItemState); - - if (stream->err()) - return Common::kWritingFailed; - - return Common::kNoError; -} - -Common::Error CItem::ReadFromStream(Common::ReadStream *stream) { - fItemNeighborhood = stream->readUint16BE(); - fItemRoom = stream->readUint16BE(); - fItemDirection = stream->readByte(); - fItemOwnerID = stream->readUint16BE(); - fItemState = stream->readUint16BE(); - - if (stream->err()) - return Common::kReadingFailed; - - return Common::kNoError; -} - -tActorID CItem::GetItemOwner() const { - return fItemOwnerID; -} - -void CItem::SetItemOwner(const tActorID owner) { - fItemOwnerID = owner; -} - -tWeightType CItem::GetItemWeight() { - return fItemWeight; -} - -tItemState CItem::GetItemState() const { - return fItemState; -} - -void CItem::SetItemState(const tItemState state) { - fItemState = state; -} - -void CItem::GetItemRoom(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) const { - neighborhood = fItemNeighborhood; - room = fItemRoom; - direction = fItemDirection; -} - -void CItem::SetItemRoom(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) { - fItemNeighborhood = neighborhood; - fItemRoom = room; - fItemDirection = direction; -} - -tNeighborhoodID CItem::GetItemNeighborhood() const { - return fItemNeighborhood; -} - -} // End of namespace Pegasus diff --git a/engines/pegasus/Game_Shell/CItem.h b/engines/pegasus/Game_Shell/CItem.h deleted file mode 100755 index c923e1c69c..0000000000 --- a/engines/pegasus/Game_Shell/CItem.h +++ /dev/null @@ -1,255 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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. - * - */ - -#ifndef PEGASUS_GAMESHELL_CITEM_H -#define PEGASUS_GAMESHELL_CITEM_H - -#include "pegasus/MMShell/Utilities/MMIDObject.h" -#include "pegasus/types.h" - -namespace Common { - class Error; - class ReadStream; - class WriteStream; -} - -namespace Pegasus { - -/* - - CItem is an object which can be picked up and carried around. - CItems have - a location - an ID. - weight - an owner (kNoActorID if no one is carrying the CItem) - -*/ - -// Item IDs. - -const tItemID kAirMask = 7; -const tItemID kAntidote = 8; -const tItemID kArgonCanister = 9; -const tItemID kCardBomb = 10; -const tItemID kCrowbar = 11; -const tItemID kGasCanister = 12; -const tItemID kHistoricalLog = 13; -const tItemID kJourneymanKey = 14; -const tItemID kKeyCard = 15; -const tItemID kMachineGun = 16; -const tItemID kMarsCard = 17; -const tItemID kNitrogenCanister = 18; -const tItemID kOrangeJuiceGlassFull = 19; -const tItemID kOrangeJuiceGlassEmpty = 20; -const tItemID kPoisonDart = 21; -const tItemID kSinclairKey = 22; -const tItemID kStunGun = 23; -const tItemID kArgonPickup = 24; - -// Biochips. - -const tItemID kAIBiochip = 0; -const tItemID kInterfaceBiochip = 1; -const tItemID kMapBiochip = 2; -const tItemID kOpticalBiochip = 3; -const tItemID kPegasusBiochip = 4; -const tItemID kRetinalScanBiochip = 5; -const tItemID kShieldBiochip = 6; - -const tItemID kNumItems = 25; - -// Item States. - -const tItemState kAI000 = 0; -const tItemState kAI005 = 1; -const tItemState kAI006 = 2; -const tItemState kAI010 = 3; -const tItemState kAI015 = 4; -const tItemState kAI016 = 5; -const tItemState kAI020 = 6; -const tItemState kAI024 = 7; -const tItemState kAI100 = 8; -const tItemState kAI101 = 9; -const tItemState kAI105 = 10; -const tItemState kAI106 = 11; -const tItemState kAI110 = 12; -const tItemState kAI111 = 13; -const tItemState kAI115 = 14; -const tItemState kAI116 = 15; -const tItemState kAI120 = 16; -const tItemState kAI121 = 17; -const tItemState kAI124 = 18; -const tItemState kAI125 = 19; -const tItemState kAI126 = 20; -const tItemState kAI200 = 21; -const tItemState kAI201 = 22; -const tItemState kAI202 = 23; -const tItemState kAI205 = 24; -const tItemState kAI206 = 25; -const tItemState kAI210 = 26; -const tItemState kAI211 = 27; -const tItemState kAI212 = 28; -const tItemState kAI215 = 29; -const tItemState kAI216 = 30; -const tItemState kAI220 = 31; -const tItemState kAI221 = 32; -const tItemState kAI222 = 33; -const tItemState kAI224 = 34; -const tItemState kAI225 = 35; -const tItemState kAI226 = 36; -const tItemState kAI300 = 37; -const tItemState kAI301 = 38; -const tItemState kAI302 = 39; -const tItemState kAI303 = 40; -const tItemState kAI305 = 41; -const tItemState kAI306 = 42; -const tItemState kAI310 = 43; -const tItemState kAI311 = 44; -const tItemState kAI312 = 45; -const tItemState kAI313 = 46; -const tItemState kAI315 = 47; -const tItemState kAI316 = 48; -const tItemState kAI320 = 49; -const tItemState kAI321 = 50; -const tItemState kAI322 = 51; -const tItemState kAI323 = 52; -const tItemState kAI324 = 53; -const tItemState kAI325 = 54; -const tItemState kAI326 = 55; -const tItemState kNormalItem = 56; -const tItemState kMapUnavailable = 57; -const tItemState kMapEngaged = 58; -const tItemState kOptical000 = 59; -const tItemState kOptical001 = 60; -const tItemState kOptical002 = 61; -const tItemState kOptical010 = 62; -const tItemState kOptical011 = 63; -const tItemState kOptical012 = 64; -const tItemState kOptical020 = 65; -const tItemState kOptical021 = 66; -const tItemState kOptical100 = 67; -const tItemState kOptical101 = 68; -const tItemState kOptical102 = 69; -const tItemState kOptical110 = 70; -const tItemState kOptical111 = 71; -const tItemState kOptical112 = 72; -const tItemState kOptical120 = 73; -const tItemState kOptical121 = 74; -const tItemState kOptical200 = 75; -const tItemState kOptical201 = 76; -const tItemState kOptical210 = 77; -const tItemState kOptical211 = 78; -const tItemState kPegasusTSA00 = 79; -const tItemState kPegasusTSA10 = 80; -const tItemState kPegasusPrehistoric00 = 81; -const tItemState kPegasusPrehistoric01 = 82; -const tItemState kPegasusPrehistoric10 = 83; -const tItemState kPegasusPrehistoric11 = 84; -const tItemState kPegasusMars00 = 85; -const tItemState kPegasusMars01 = 86; -const tItemState kPegasusMars10 = 87; -const tItemState kPegasusMars11 = 88; -const tItemState kPegasusNorad00 = 89; -const tItemState kPegasusNorad01 = 90; -const tItemState kPegasusNorad10 = 91; -const tItemState kPegasusNorad11 = 92; -const tItemState kPegasusWSC00 = 93; -const tItemState kPegasusWSC01 = 94; -const tItemState kPegasusWSC10 = 95; -const tItemState kPegasusWSC11 = 96; -const tItemState kPegasusCaldoria = 97; -const tItemState kRetinalSimulating = 98; -const tItemState kShieldNormal = 99; -const tItemState kShieldRadiation = 100; -const tItemState kShieldPlasma = 101; -const tItemState kShieldCardBomb = 102; -const tItemState kShieldDraining = 103; -const tItemState kAirMaskEmptyOff = 104; -const tItemState kAirMaskEmptyFilter = 105; -const tItemState kAirMaskLowOff = 106; -const tItemState kAirMaskLowFilter = 107; -const tItemState kAirMaskLowOn = 108; -const tItemState kAirMaskFullOff = 109; -const tItemState kAirMaskFullFilter = 110; -const tItemState kAirMaskFullOn = 111; -const tItemState kArgonEmpty = 112; -const tItemState kArgonFull = 113; -const tItemState kFlashlightOff = 114; -const tItemState kFlashlightOn = 115; -const tItemState kNitrogenEmpty = 116; -const tItemState kNitrogenFull = 117; -const tItemState kFullGlass = 118; - -// Extra IDs. - -const uint32 kRetinalScanSearching = 0; -const uint32 kRetinalScanActivated = 1; -const uint32 kShieldIntro = 2; -const uint32 kRemoveAirMask = 3; -const uint32 kRemoveArgon = 4; -const uint32 kRemoveCrowbar = 5; -const uint32 kGasCanLoop = 6; -const uint32 kRemoveJourneymanKey = 7; -const uint32 kRemoveMarsCard = 8; -const uint32 kRemoveNitrogen = 9; -const uint32 kRemoveGlass = 10; -const uint32 kRemoveDart = 11; -const uint32 kRemoveSinclairKey = 12; - -class CItem : public MMIDObject { -public: - CItem(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); - virtual ~CItem(); - - // WriteToStream writes everything EXCEPT the item's ID. - // It is assumed that the calling function will write and read the ID. - virtual Common::Error WriteToStream(Common::WriteStream *stream); - virtual Common::Error ReadFromStream(Common::ReadStream *stream); - - virtual tActorID GetItemOwner() const; - virtual void SetItemOwner(const tActorID owner); - - void GetItemRoom(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) const; - void SetItemRoom(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); - tNeighborhoodID GetItemNeighborhood() const; - - virtual tWeightType GetItemWeight(); - - virtual void SetItemState(const tItemState state); - virtual tItemState GetItemState() const; - -protected: - tNeighborhoodID fItemNeighborhood; - tRoomID fItemRoom; - tDirectionConstant fItemDirection; - tActorID fItemOwnerID; - tWeightType fItemWeight; - tItemState fItemState; -}; - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/Game_Shell/CItemList.cpp b/engines/pegasus/Game_Shell/CItemList.cpp deleted file mode 100755 index 256a895797..0000000000 --- a/engines/pegasus/Game_Shell/CItemList.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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/error.h" -#include "common/stream.h" - -#include "engines/pegasus/Game_Shell/CItem.h" -#include "engines/pegasus/Game_Shell/CItemList.h" - -namespace Pegasus { - -// TODO: Don't use global construction! -CItemList gAllItems; - -CItemList::CItemList() { -} - -CItemList::~CItemList() { -} - -Common::Error CItemList::WriteToStream(Common::WriteStream *stream) { - stream->writeUint32BE(size()); - - for (CItemIterator it = begin(); it != end(); it++) { - stream->writeUint16BE((*it)->GetObjectID()); - (*it)->WriteToStream(stream); - } - - if (stream->err()) - return Common::kWritingFailed; - - return Common::kNoError; -} - -Common::Error CItemList::ReadFromStream(Common::ReadStream *stream) { - uint32 itemCount = stream->readUint32BE(); - - for (uint32 i = 0; i < itemCount; i++) { - tItemID itemID = stream->readUint16BE(); - gAllItems.FindItemByID(itemID)->ReadFromStream(stream); - } - - if (stream->err()) - return Common::kReadingFailed; - - return Common::kNoError; -} - -CItem *CItemList::FindItemByID(const tItemID id) { - for (CItemIterator it = begin(); it != end(); it++) - if ((*it)->GetObjectID() == id) - return *it; - - return 0; -} - -} // End of namespace Pegasus diff --git a/engines/pegasus/Game_Shell/CItemList.h b/engines/pegasus/Game_Shell/CItemList.h deleted file mode 100755 index d4c0d56272..0000000000 --- a/engines/pegasus/Game_Shell/CItemList.h +++ /dev/null @@ -1,60 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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. - * - */ - -#ifndef PEGASUS_GAMESHELL_CITEMLIST_H -#define PEGASUS_GAMESHELL_CITEMLIST_H - -#include "common/list.h" - -#include "pegasus/types.h" - -namespace Common { - class ReadStream; - class WriteStream; -} - -namespace Pegasus { - -class CItem; - -class CItemList : public Common::List { -public: - CItemList(); - virtual ~CItemList(); - - virtual Common::Error WriteToStream(Common::WriteStream *stream); - virtual Common::Error ReadFromStream(Common::ReadStream *stream); - - CItem *FindItemByID(const tItemID id); -}; - -typedef CItemList::iterator CItemIterator; - -// TODO: Don't use global construction! -extern CItemList gAllItems; - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/MMShell/Sounds/MMSound.cpp b/engines/pegasus/MMShell/Sounds/MMSound.cpp deleted file mode 100755 index 23ac60bced..0000000000 --- a/engines/pegasus/MMShell/Sounds/MMSound.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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 "audio/audiostream.h" -#include "audio/decoders/aiff.h" -#include "common/file.h" -#include "common/system.h" - -#include "engines/pegasus/MMShell/Sounds/MMSound.h" - -namespace Pegasus { - -MMSound::MMSound() { - _aiffStream = 0; - _volume = 0xFF; -} - -MMSound::~MMSound() { - DisposeSound(); -} - -void MMSound::DisposeSound() { - StopSound(); - delete _aiffStream; _aiffStream = 0; -} - -void MMSound::InitFromAIFFFile(const Common::String &fileName) { - Common::File *file = new Common::File(); - if (!file->open(fileName)) { - delete file; - return; - } - - _aiffStream = Audio::makeAIFFStream(file, DisposeAfterUse::YES); -} - -#if 0 -// TODO! -void MMSound::AttachFader(MMSoundFader *theFader) { - if (fTheFader) - fTheFader->AttachSound(NULL); - - fTheFader = theFader; - - if (fTheFader) - fTheFader->AttachSound(this); -} -#endif - -void MMSound::PlaySound() { - if (!SoundLoaded()) - return; - - StopSound(); - -#if 0 - // TODO! - if (fTheFader) - this->SetVolume(fTheFader->GetFaderValue()); -#endif - - g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, _aiffStream, -1, _volume, 0, DisposeAfterUse::NO); -} - -void MMSound::LoopSound() { - if (!SoundLoaded()) - return; - - StopSound(); - - // Create a looping stream - Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_aiffStream, 0, DisposeAfterUse::NO); - -#if 0 - // TODO! - // Assume that if there is a fader, we're going to fade the sound in. - if (fTheFader) - this->SetVolume(0); -#endif - - g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, loopStream, -1, _volume, 0, DisposeAfterUse::YES); -} - -void MMSound::StopSound(void) { - g_system->getMixer()->stopHandle(_handle); -} - -void MMSound::SetVolume(const uint16 volume) { - // Clipping the volume to [0x00, 0xFF] instead of Apple's [0, 0x100] - // We store the volume in case SetVolume is called before the sound starts - - _volume = (volume == 0x100) ? 0xFF : volume; - g_system->getMixer()->setChannelVolume(_handle, _volume); -} - -bool MMSound::IsPlaying() { - return SoundLoaded() && g_system->getMixer()->isSoundHandleActive(_handle); -} - -bool MMSound::SoundLoaded() const { - return _aiffStream != 0; -} - -} // End of namespace Pegasus diff --git a/engines/pegasus/MMShell/Sounds/MMSound.h b/engines/pegasus/MMShell/Sounds/MMSound.h deleted file mode 100755 index bb5578266d..0000000000 --- a/engines/pegasus/MMShell/Sounds/MMSound.h +++ /dev/null @@ -1,84 +0,0 @@ -/* 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. - * - * Additional copyright for this file: - * Copyright (C) 1995-1997 Presto Studios, Inc. - * - * 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. - * - */ - -#ifndef PEGASUS_MMSHELL_SOUNDS_MMSOUND_H -#define PEGASUS_MMSHELL_SOUNDS_MMSOUND_H - -#include "audio/mixer.h" -#include "common/str.h" - -namespace Audio { - class AudioStream; - class RewindableAudioStream; -} - -namespace Pegasus { - -// TODO! -//class MMSoundFader; - -// Things you might want to do with sound: -// Start it -// Stop it -// Loop it -// Pause it -// Set the volume -// Set the pitch (rate) -// Pan the sound -// Change these settings dynamically over time - -class MMSound { -public: - MMSound(); - ~MMSound(); - - // We only have one access point here because we should - // only be opening an AIFF file from a file name. We're - // not using the resource fork string resources. - void InitFromAIFFFile(const Common::String &fileName); - - void DisposeSound(); - bool SoundLoaded() const; - void PlaySound(); - void LoopSound(); - void StopSound(); - void SetVolume(const uint16 volume); - bool IsPlaying(); - - // TODO! - //void AttachFader(MMSoundFader*); - -protected: - Audio::RewindableAudioStream *_aiffStream; - Audio::SoundHandle _handle; - byte _volume; - - // TODO! - //MMSoundFader *fTheFader; -}; - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/MMShell/Utilities/MMIDObject.h b/engines/pegasus/MMShell/Utilities/MMIDObject.h index b45c7544b3..112d3b8275 100755 --- a/engines/pegasus/MMShell/Utilities/MMIDObject.h +++ b/engines/pegasus/MMShell/Utilities/MMIDObject.h @@ -38,29 +38,29 @@ public: MMIDObject(const tMM32BitID id); ~MMIDObject(); - tMM32BitID GetObjectID() const; + tMM32BitID getObjectID() const; private: - tMM32BitID fObjectID; + tMM32BitID _objectID; }; inline MMIDObject::MMIDObject(const tMM32BitID id) { - fObjectID = id; + _objectID = id; } inline MMIDObject::~MMIDObject() { } -inline tMM32BitID MMIDObject::GetObjectID() const { - return fObjectID; +inline tMM32BitID MMIDObject::getObjectID() const { + return _objectID; } inline int operator==(const MMIDObject &arg1, const MMIDObject &arg2) { - return arg1.fObjectID == arg2.fObjectID; + return arg1._objectID == arg2._objectID; } inline int operator!=(const MMIDObject &arg1, const MMIDObject &arg2) { - return arg1.fObjectID != arg2.fObjectID; + return arg1._objectID != arg2._objectID; } } // End of namespace Pegasus diff --git a/engines/pegasus/gamestate.cpp b/engines/pegasus/gamestate.cpp index 2f4aed6188..bc88c5ed22 100755 --- a/engines/pegasus/gamestate.cpp +++ b/engines/pegasus/gamestate.cpp @@ -1530,12 +1530,12 @@ bool GameStateManager::isTakenItemID(tItemID id) { return _itemTakenFlags.getFlag(id); } -void GameStateManager::setTakenItem(CItem *item, bool value) { - setTakenItemID(item->GetObjectID(), value); +void GameStateManager::setTakenItem(Item *item, bool value) { + setTakenItemID(item->getObjectID(), value); } -bool GameStateManager::isTakenItem(CItem *item) { - return isTakenItemID(item->GetObjectID()); +bool GameStateManager::isTakenItem(Item *item) { + return isTakenItemID(item->getObjectID()); } void GameStateManager::setCaldoriaFuseTimeLimit(const TimeValue timeLimit) { diff --git a/engines/pegasus/gamestate.h b/engines/pegasus/gamestate.h index af790ce283..4118b5d519 100755 --- a/engines/pegasus/gamestate.h +++ b/engines/pegasus/gamestate.h @@ -29,7 +29,7 @@ #include "common/singleton.h" #include "pegasus/types.h" -#include "pegasus/Game_Shell/CItem.h" +#include "pegasus/items/item.h" namespace Common { class Error; @@ -615,8 +615,8 @@ public: bool allTimeZonesFinished(); void setTakenItemID(tItemID, bool); bool isTakenItemID(tItemID); - void setTakenItem(CItem*, bool); - bool isTakenItem(CItem*); + void setTakenItem(Item*, bool); + bool isTakenItem(Item*); // Caldoria void setCaldoriaFuseTimeLimit(const TimeValue); diff --git a/engines/pegasus/items/inventory.cpp b/engines/pegasus/items/inventory.cpp new file mode 100755 index 0000000000..8f7eb46fd4 --- /dev/null +++ b/engines/pegasus/items/inventory.cpp @@ -0,0 +1,175 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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 "pegasus/constants.h" +#include "pegasus/items/item.h" +#include "pegasus/items/inventory.h" + +namespace Pegasus { + +Inventory::Inventory() { + _weightLimit = 100; + _ownerID = kNoActorID; + _referenceCount = 0; +} + +Inventory::~Inventory() { +} + +void Inventory::setWeightLimit(tWeightType limit) { + _weightLimit = limit; + // *** What to do if the new weight limit is greater than the current weight? +} + +tWeightType Inventory::getWeight() { + tWeightType result = 0; + + for (ItemIterator it = _inventoryList.begin(); it != _inventoryList.end(); it++) + result += (*it)->getItemWeight(); + + return result; +} + +// If the item already belongs, just return kInventoryOK. +tInventoryResult Inventory::addItem(Item *item) { + if (itemInInventory(item)) + return kInventoryOK; + + if (getWeight() + item->getItemWeight() > _weightLimit) + return kTooMuchWeight; + + _inventoryList.push_back(item); + item->setItemOwner(_ownerID); + + ++_referenceCount; + return kInventoryOK; +} + +tInventoryResult Inventory::removeItem(Item *item) { + for (ItemIterator it = _inventoryList.begin(); it != _inventoryList.end(); it++) { + if (*it == item) { + _inventoryList.erase(it); + item->setItemOwner(kNoActorID); + + ++_referenceCount; + return kInventoryOK; + } + } + + return kItemNotInInventory; +} + +tInventoryResult Inventory::removeItem(tItemID id) { + Item *item = findItemByID(id); + + if (item) { + _inventoryList.remove(item); + item->setItemOwner(kNoActorID); + + ++_referenceCount; + return kInventoryOK; + } + + return kItemNotInInventory; +} + +void Inventory::removeAllItems() { + _inventoryList.clear(); + ++_referenceCount; +} + +bool Inventory::itemInInventory(Item *item) { + for (ItemIterator it = _inventoryList.begin(); it != _inventoryList.end(); it++) + if (*it == item) + return true; + + return false; +} + +bool Inventory::itemInInventory(tItemID id) { + return findItemByID(id) != NULL; +} + +Item *Inventory::getItemAt(int32 index) { + int32 i = 0; + for (ItemIterator it = _inventoryList.begin(); it != _inventoryList.end(); it++, i++) + if (i == index) + return *it; + + return 0; +} + +tItemID Inventory::getItemIDAt(int32 index) { + Item *item = getItemAt(index); + + if (item) + return item->getObjectID(); + + return kNoItemID; +} + +Item *Inventory::findItemByID(tItemID id) { + return _inventoryList.findItemByID(id); +} + +// Return -1 if not found. + +int32 Inventory::findIndexOf(Item *item) { + uint32 i = 0; + for (ItemIterator it = _inventoryList.begin(); it != _inventoryList.end(); it++, i++) + if (*it == item) + return i; + + return -1; +} + +// Return -1 if not found. + +int32 Inventory::findIndexOf(tItemID id) { + uint32 i = 0; + for (ItemIterator it = _inventoryList.begin(); it != _inventoryList.end(); it++, i++) + if ((*it)->getObjectID() == id) + return i; + + return -1; +} + +tWeightType Inventory::getWeightLimit() { + return _weightLimit; +} + +int32 Inventory::getNumItems() { + return _inventoryList.size(); +} + +void Inventory::setOwnerID(const tActorID id) { + _ownerID = id; +} + +tActorID Inventory::getOwnerID() const { + return _ownerID; +} + +} // End of namespae Pegasus diff --git a/engines/pegasus/items/inventory.h b/engines/pegasus/items/inventory.h new file mode 100755 index 0000000000..7da782f00e --- /dev/null +++ b/engines/pegasus/items/inventory.h @@ -0,0 +1,80 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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. + * + */ + +#ifndef PEGASUS_ITEMS_INVENTORY_H +#define PEGASUS_ITEMS_INVENTORY_H + +#include "pegasus/types.h" +#include "pegasus/items/itemlist.h" + +namespace Pegasus { + +class Item; + +// Inventories have a "current item". This item is the default item the player can +// use. In a text adventure system, the current item would be "it", as in +// "Hit the troll with it," where "it" would refer to some weapon which is the current +// item. In a graphic adventure, the current item would be the item the user selects +// to use with the mouse or other pointing device. + +class Inventory { +public: + Inventory(); + virtual ~Inventory(); + + tWeightType getWeightLimit(); + void setWeightLimit(tWeightType limit); + tWeightType getWeight(); + + virtual tInventoryResult addItem(Item *item); + virtual tInventoryResult removeItem(Item *item); + virtual tInventoryResult removeItem(tItemID id); + virtual bool itemInInventory(Item *item); + virtual bool itemInInventory(tItemID id); + virtual Item *getItemAt(int32 index); + virtual tItemID getItemIDAt(int32 index); + virtual Item *findItemByID(tItemID id); + virtual int32 findIndexOf(Item *item); + virtual int32 findIndexOf(tItemID id); + int32 getNumItems(); + virtual void removeAllItems(); + + void setOwnerID(const tActorID id); + tActorID getOwnerID() const; + + uint32 getReferenceCount() { return _referenceCount; } + +protected: + tWeightType _weightLimit; + tActorID _ownerID; + ItemList _inventoryList; + +private: + uint32 _referenceCount; +}; + +} // End of namespace Pegasus + +#endif diff --git a/engines/pegasus/items/item.cpp b/engines/pegasus/items/item.cpp new file mode 100755 index 0000000000..934dce6f2d --- /dev/null +++ b/engines/pegasus/items/item.cpp @@ -0,0 +1,111 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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/error.h" +#include "common/stream.h" + +#include "pegasus/constants.h" +#include "pegasus/items/item.h" +#include "pegasus/items/itemlist.h" + +namespace Pegasus { + +Item::Item(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) : MMIDObject(id) { + _itemNeighborhood = neighborhood; + _itemRoom = room; + _itemDirection = direction; + _itemWeight = 1; + _itemOwnerID = kNoActorID; + _itemState = 0; + + g_allItems.push_back(this); +} + +Item::~Item() { +} + +Common::Error Item::writeToStream(Common::WriteStream *stream) { + stream->writeUint16BE(_itemNeighborhood); + stream->writeUint16BE(_itemRoom); + stream->writeByte(_itemDirection); + stream->writeUint16BE(_itemOwnerID); + stream->writeUint16BE(_itemState); + + if (stream->err()) + return Common::kWritingFailed; + + return Common::kNoError; +} + +Common::Error Item::readFromStream(Common::ReadStream *stream) { + _itemNeighborhood = stream->readUint16BE(); + _itemRoom = stream->readUint16BE(); + _itemDirection = stream->readByte(); + _itemOwnerID = stream->readUint16BE(); + _itemState = stream->readUint16BE(); + + if (stream->err()) + return Common::kReadingFailed; + + return Common::kNoError; +} + +tActorID Item::getItemOwner() const { + return _itemOwnerID; +} + +void Item::setItemOwner(const tActorID owner) { + _itemOwnerID = owner; +} + +tWeightType Item::getItemWeight() { + return _itemWeight; +} + +tItemState Item::getItemState() const { + return _itemState; +} + +void Item::setItemState(const tItemState state) { + _itemState = state; +} + +void Item::getItemRoom(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) const { + neighborhood = _itemNeighborhood; + room = _itemRoom; + direction = _itemDirection; +} + +void Item::setItemRoom(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) { + _itemNeighborhood = neighborhood; + _itemRoom = room; + _itemDirection = direction; +} + +tNeighborhoodID Item::getItemNeighborhood() const { + return _itemNeighborhood; +} + +} // End of namespace Pegasus diff --git a/engines/pegasus/items/item.h b/engines/pegasus/items/item.h new file mode 100755 index 0000000000..37ad54e5e7 --- /dev/null +++ b/engines/pegasus/items/item.h @@ -0,0 +1,255 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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. + * + */ + +#ifndef PEGASUS_ITEMS_ITEM_H +#define PEGASUS_ITEMS_ITEM_H + +#include "pegasus/MMShell/Utilities/MMIDObject.h" +#include "pegasus/types.h" + +namespace Common { + class Error; + class ReadStream; + class WriteStream; +} + +namespace Pegasus { + +/* + + Item is an object which can be picked up and carried around. + Items have + a location + an ID. + weight + an owner (kNoActorID if no one is carrying the Item) + +*/ + +// Item IDs. + +const tItemID kAirMask = 7; +const tItemID kAntidote = 8; +const tItemID kArgonCanister = 9; +const tItemID kCardBomb = 10; +const tItemID kCrowbar = 11; +const tItemID kGasCanister = 12; +const tItemID kHistoricalLog = 13; +const tItemID kJourneymanKey = 14; +const tItemID kKeyCard = 15; +const tItemID kMachineGun = 16; +const tItemID kMarsCard = 17; +const tItemID kNitrogenCanister = 18; +const tItemID kOrangeJuiceGlassFull = 19; +const tItemID kOrangeJuiceGlassEmpty = 20; +const tItemID kPoisonDart = 21; +const tItemID kSinclairKey = 22; +const tItemID kStunGun = 23; +const tItemID kArgonPickup = 24; + +// Biochips. + +const tItemID kAIBiochip = 0; +const tItemID kInterfaceBiochip = 1; +const tItemID kMapBiochip = 2; +const tItemID kOpticalBiochip = 3; +const tItemID kPegasusBiochip = 4; +const tItemID kRetinalScanBiochip = 5; +const tItemID kShieldBiochip = 6; + +const tItemID kNumItems = 25; + +// Item States. + +const tItemState kAI000 = 0; +const tItemState kAI005 = 1; +const tItemState kAI006 = 2; +const tItemState kAI010 = 3; +const tItemState kAI015 = 4; +const tItemState kAI016 = 5; +const tItemState kAI020 = 6; +const tItemState kAI024 = 7; +const tItemState kAI100 = 8; +const tItemState kAI101 = 9; +const tItemState kAI105 = 10; +const tItemState kAI106 = 11; +const tItemState kAI110 = 12; +const tItemState kAI111 = 13; +const tItemState kAI115 = 14; +const tItemState kAI116 = 15; +const tItemState kAI120 = 16; +const tItemState kAI121 = 17; +const tItemState kAI124 = 18; +const tItemState kAI125 = 19; +const tItemState kAI126 = 20; +const tItemState kAI200 = 21; +const tItemState kAI201 = 22; +const tItemState kAI202 = 23; +const tItemState kAI205 = 24; +const tItemState kAI206 = 25; +const tItemState kAI210 = 26; +const tItemState kAI211 = 27; +const tItemState kAI212 = 28; +const tItemState kAI215 = 29; +const tItemState kAI216 = 30; +const tItemState kAI220 = 31; +const tItemState kAI221 = 32; +const tItemState kAI222 = 33; +const tItemState kAI224 = 34; +const tItemState kAI225 = 35; +const tItemState kAI226 = 36; +const tItemState kAI300 = 37; +const tItemState kAI301 = 38; +const tItemState kAI302 = 39; +const tItemState kAI303 = 40; +const tItemState kAI305 = 41; +const tItemState kAI306 = 42; +const tItemState kAI310 = 43; +const tItemState kAI311 = 44; +const tItemState kAI312 = 45; +const tItemState kAI313 = 46; +const tItemState kAI315 = 47; +const tItemState kAI316 = 48; +const tItemState kAI320 = 49; +const tItemState kAI321 = 50; +const tItemState kAI322 = 51; +const tItemState kAI323 = 52; +const tItemState kAI324 = 53; +const tItemState kAI325 = 54; +const tItemState kAI326 = 55; +const tItemState kNormalItem = 56; +const tItemState kMapUnavailable = 57; +const tItemState kMapEngaged = 58; +const tItemState kOptical000 = 59; +const tItemState kOptical001 = 60; +const tItemState kOptical002 = 61; +const tItemState kOptical010 = 62; +const tItemState kOptical011 = 63; +const tItemState kOptical012 = 64; +const tItemState kOptical020 = 65; +const tItemState kOptical021 = 66; +const tItemState kOptical100 = 67; +const tItemState kOptical101 = 68; +const tItemState kOptical102 = 69; +const tItemState kOptical110 = 70; +const tItemState kOptical111 = 71; +const tItemState kOptical112 = 72; +const tItemState kOptical120 = 73; +const tItemState kOptical121 = 74; +const tItemState kOptical200 = 75; +const tItemState kOptical201 = 76; +const tItemState kOptical210 = 77; +const tItemState kOptical211 = 78; +const tItemState kPegasusTSA00 = 79; +const tItemState kPegasusTSA10 = 80; +const tItemState kPegasusPrehistoric00 = 81; +const tItemState kPegasusPrehistoric01 = 82; +const tItemState kPegasusPrehistoric10 = 83; +const tItemState kPegasusPrehistoric11 = 84; +const tItemState kPegasusMars00 = 85; +const tItemState kPegasusMars01 = 86; +const tItemState kPegasusMars10 = 87; +const tItemState kPegasusMars11 = 88; +const tItemState kPegasusNorad00 = 89; +const tItemState kPegasusNorad01 = 90; +const tItemState kPegasusNorad10 = 91; +const tItemState kPegasusNorad11 = 92; +const tItemState kPegasusWSC00 = 93; +const tItemState kPegasusWSC01 = 94; +const tItemState kPegasusWSC10 = 95; +const tItemState kPegasusWSC11 = 96; +const tItemState kPegasusCaldoria = 97; +const tItemState kRetinalSimulating = 98; +const tItemState kShieldNormal = 99; +const tItemState kShieldRadiation = 100; +const tItemState kShieldPlasma = 101; +const tItemState kShieldCardBomb = 102; +const tItemState kShieldDraining = 103; +const tItemState kAirMaskEmptyOff = 104; +const tItemState kAirMaskEmptyFilter = 105; +const tItemState kAirMaskLowOff = 106; +const tItemState kAirMaskLowFilter = 107; +const tItemState kAirMaskLowOn = 108; +const tItemState kAirMaskFullOff = 109; +const tItemState kAirMaskFullFilter = 110; +const tItemState kAirMaskFullOn = 111; +const tItemState kArgonEmpty = 112; +const tItemState kArgonFull = 113; +const tItemState kFlashlightOff = 114; +const tItemState kFlashlightOn = 115; +const tItemState kNitrogenEmpty = 116; +const tItemState kNitrogenFull = 117; +const tItemState kFullGlass = 118; + +// Extra IDs. + +const uint32 kRetinalScanSearching = 0; +const uint32 kRetinalScanActivated = 1; +const uint32 kShieldIntro = 2; +const uint32 kRemoveAirMask = 3; +const uint32 kRemoveArgon = 4; +const uint32 kRemoveCrowbar = 5; +const uint32 kGasCanLoop = 6; +const uint32 kRemoveJourneymanKey = 7; +const uint32 kRemoveMarsCard = 8; +const uint32 kRemoveNitrogen = 9; +const uint32 kRemoveGlass = 10; +const uint32 kRemoveDart = 11; +const uint32 kRemoveSinclairKey = 12; + +class Item : public MMIDObject { +public: + Item(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); + virtual ~Item(); + + // WriteToStream writes everything EXCEPT the item's ID. + // It is assumed that the calling function will write and read the ID. + virtual Common::Error writeToStream(Common::WriteStream *stream); + virtual Common::Error readFromStream(Common::ReadStream *stream); + + virtual tActorID getItemOwner() const; + virtual void setItemOwner(const tActorID owner); + + void getItemRoom(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) const; + void setItemRoom(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); + tNeighborhoodID getItemNeighborhood() const; + + virtual tWeightType getItemWeight(); + + virtual void setItemState(const tItemState state); + virtual tItemState getItemState() const; + +protected: + tNeighborhoodID _itemNeighborhood; + tRoomID _itemRoom; + tDirectionConstant _itemDirection; + tActorID _itemOwnerID; + tWeightType _itemWeight; + tItemState _itemState; +}; + +} // End of namespace Pegasus + +#endif diff --git a/engines/pegasus/items/itemlist.cpp b/engines/pegasus/items/itemlist.cpp new file mode 100755 index 0000000000..2b980d6f5f --- /dev/null +++ b/engines/pegasus/items/itemlist.cpp @@ -0,0 +1,79 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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/error.h" +#include "common/stream.h" + +#include "engines/pegasus/items/item.h" +#include "engines/pegasus/items/itemlist.h" + +namespace Pegasus { + +// TODO: Don't use global construction! +ItemList g_allItems; + +ItemList::ItemList() { +} + +ItemList::~ItemList() { +} + +Common::Error ItemList::writeToStream(Common::WriteStream *stream) { + stream->writeUint32BE(size()); + + for (ItemIterator it = begin(); it != end(); it++) { + stream->writeUint16BE((*it)->getObjectID()); + (*it)->writeToStream(stream); + } + + if (stream->err()) + return Common::kWritingFailed; + + return Common::kNoError; +} + +Common::Error ItemList::readFromStream(Common::ReadStream *stream) { + uint32 itemCount = stream->readUint32BE(); + + for (uint32 i = 0; i < itemCount; i++) { + tItemID itemID = stream->readUint16BE(); + g_allItems.findItemByID(itemID)->readFromStream(stream); + } + + if (stream->err()) + return Common::kReadingFailed; + + return Common::kNoError; +} + +Item *ItemList::findItemByID(const tItemID id) { + for (ItemIterator it = begin(); it != end(); it++) + if ((*it)->getObjectID() == id) + return *it; + + return 0; +} + +} // End of namespace Pegasus diff --git a/engines/pegasus/items/itemlist.h b/engines/pegasus/items/itemlist.h new file mode 100755 index 0000000000..dd9a4ba023 --- /dev/null +++ b/engines/pegasus/items/itemlist.h @@ -0,0 +1,60 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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. + * + */ + +#ifndef PEGASUS_ITEMS_ITEMLIST_H +#define PEGASUS_ITEMS_ITEMLIST_H + +#include "common/list.h" + +#include "pegasus/types.h" + +namespace Common { + class ReadStream; + class WriteStream; +} + +namespace Pegasus { + +class Item; + +class ItemList : public Common::List { +public: + ItemList(); + virtual ~ItemList(); + + virtual Common::Error writeToStream(Common::WriteStream *stream); + virtual Common::Error readFromStream(Common::ReadStream *stream); + + Item *findItemByID(const tItemID id); +}; + +typedef ItemList::iterator ItemIterator; + +// TODO: Don't use global construction! +extern ItemList g_allItems; + +} // End of namespace Pegasus + +#endif diff --git a/engines/pegasus/menu.cpp b/engines/pegasus/menu.cpp index 577d96aa82..49d60144d6 100644 --- a/engines/pegasus/menu.cpp +++ b/engines/pegasus/menu.cpp @@ -25,8 +25,7 @@ #include "pegasus/console.h" #include "pegasus/pegasus.h" - -#include "pegasus/MMShell/Sounds/MMSound.h" +#include "pegasus/sound.h" namespace Pegasus { @@ -46,9 +45,9 @@ enum { }; void PegasusEngine::runMainMenu() { - MMSound sound; - sound.InitFromAIFFFile("Sounds/Main Menu.aiff"); - sound.LoopSound(); + Sound sound; + sound.initFromAIFFFile("Sounds/Main Menu.aiff"); + sound.loopSound(); // Note down how long since the last click uint32 lastClickTime = _system->getMillis(); @@ -86,14 +85,14 @@ void PegasusEngine::runMainMenu() { case Common::KEYCODE_RETURN: if (buttonSelected != kDifficultyButton) { drawMenuButtonSelected(buttonSelected); - sound.StopSound(); + sound.stopSound(); setGameMode(buttonSelected); if (_gameMode != kMainMenuMode) return; drawMenu(buttonSelected); - sound.LoopSound(); + sound.loopSound(); } break; case Common::KEYCODE_d: @@ -122,7 +121,7 @@ void PegasusEngine::runMainMenu() { return; // Too slow! Go back and show the intro again. - sound.StopSound(); + sound.stopSound(); _video->playMovie(_introDirectory + "/LilMovie.movie"); _gameMode = kIntroMode; } diff --git a/engines/pegasus/module.mk b/engines/pegasus/module.mk index 4840190a00..4f44050787 100644 --- a/engines/pegasus/module.mk +++ b/engines/pegasus/module.mk @@ -9,15 +9,15 @@ MODULE_OBJS = \ menu.o \ overview.o \ pegasus.o \ + sound.o \ video.o \ - Game_Shell/CInventory.o \ - Game_Shell/CItem.o \ - Game_Shell/CItemList.o \ + items/inventory.o \ + items/item.o \ + items/itemlist.o \ MMShell/Base_Classes/MMFunctionPtr.o \ MMShell/Notification/MMNotification.o \ MMShell/Notification/MMNotificationManager.o \ MMShell/Notification/MMNotificationReceiver.o \ - MMShell/Sounds/MMSound.o \ MMShell/Utilities/MMResourceFile.o \ MMShell/Utilities/MMTimeValue.o \ MMShell/Utilities/MMUtilities.o \ diff --git a/engines/pegasus/sound.cpp b/engines/pegasus/sound.cpp new file mode 100755 index 0000000000..5fcac1134a --- /dev/null +++ b/engines/pegasus/sound.cpp @@ -0,0 +1,126 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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 "audio/audiostream.h" +#include "audio/decoders/aiff.h" +#include "common/file.h" +#include "common/system.h" + +#include "pegasus/sound.h" + +namespace Pegasus { + +Sound::Sound() { + _aiffStream = 0; + _volume = 0xFF; +} + +Sound::~Sound() { + disposeSound(); +} + +void Sound::disposeSound() { + stopSound(); + delete _aiffStream; _aiffStream = 0; +} + +void Sound::initFromAIFFFile(const Common::String &fileName) { + Common::File *file = new Common::File(); + if (!file->open(fileName)) { + delete file; + return; + } + + _aiffStream = Audio::makeAIFFStream(file, DisposeAfterUse::YES); +} + +#if 0 +// TODO! +void Sound::attachFader(SoundFader *fader) { + if (_fader) + _fader->attachSound(NULL); + + _fader = fader; + + if (_fader) + _fader->attachSound(this); +} +#endif + +void Sound::playSound() { + if (!isSoundLoaded()) + return; + + stopSound(); + +#if 0 + // TODO! + if (_fader) + setVolume(_fader->getFaderValue()); +#endif + + g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, _aiffStream, -1, _volume, 0, DisposeAfterUse::NO); +} + +void Sound::loopSound() { + if (!isSoundLoaded()) + return; + + stopSound(); + + // Create a looping stream + Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_aiffStream, 0, DisposeAfterUse::NO); + +#if 0 + // TODO! + // Assume that if there is a fader, we're going to fade the sound in. + if (_fader) + setVolume(0); +#endif + + g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, loopStream, -1, _volume, 0, DisposeAfterUse::YES); +} + +void Sound::stopSound(void) { + g_system->getMixer()->stopHandle(_handle); +} + +void Sound::setVolume(const uint16 volume) { + // Clipping the volume to [0x00, 0xFF] instead of Apple's [0, 0x100] + // We store the volume in case SetVolume is called before the sound starts + + _volume = (volume == 0x100) ? 0xFF : volume; + g_system->getMixer()->setChannelVolume(_handle, _volume); +} + +bool Sound::isPlaying() { + return isSoundLoaded() && g_system->getMixer()->isSoundHandleActive(_handle); +} + +bool Sound::isSoundLoaded() const { + return _aiffStream != 0; +} + +} // End of namespace Pegasus diff --git a/engines/pegasus/sound.h b/engines/pegasus/sound.h new file mode 100755 index 0000000000..62ce51a605 --- /dev/null +++ b/engines/pegasus/sound.h @@ -0,0 +1,84 @@ +/* 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. + * + * Additional copyright for this file: + * Copyright (C) 1995-1997 Presto Studios, Inc. + * + * 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. + * + */ + +#ifndef PEGASUS_SOUND_H +#define PEGASUS_SOUND_H + +#include "audio/mixer.h" +#include "common/str.h" + +namespace Audio { + class AudioStream; + class RewindableAudioStream; +} + +namespace Pegasus { + +// TODO! +//class MMSoundFader; + +// Things you might want to do with sound: +// Start it +// Stop it +// Loop it +// Pause it +// Set the volume +// Set the pitch (rate) +// Pan the sound +// Change these settings dynamically over time + +class Sound { +public: + Sound(); + ~Sound(); + + // We only have one access point here because we should + // only be opening an AIFF file from a file name. We're + // not using the resource fork string resources. + void initFromAIFFFile(const Common::String &fileName); + + void disposeSound(); + bool isSoundLoaded() const; + void playSound(); + void loopSound(); + void stopSound(); + void setVolume(const uint16 volume); + bool isPlaying(); + + // TODO! + //void attachFader(SoundFader *fader); + +protected: + Audio::RewindableAudioStream *_aiffStream; + Audio::SoundHandle _handle; + byte _volume; + + // TODO! + //SoundFader *_fader; +}; + +} // End of namespace Pegasus + +#endif -- cgit v1.2.3