diff options
Diffstat (limited to 'engines/pegasus/Game_Shell')
-rwxr-xr-x | engines/pegasus/Game_Shell/CGameState.cpp | 252 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CGameState.h | 107 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CInventory.cpp | 175 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CInventory.h | 80 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CItem.cpp | 111 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CItem.h | 84 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CItemList.cpp | 79 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/CItemList.h | 60 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/Headers/Game_Shell_Constants.h | 81 | ||||
-rwxr-xr-x | engines/pegasus/Game_Shell/Headers/Game_Shell_Types.h | 80 |
10 files changed, 1109 insertions, 0 deletions
diff --git a/engines/pegasus/Game_Shell/CGameState.cpp b/engines/pegasus/Game_Shell/CGameState.cpp new file mode 100755 index 0000000000..70a55450dd --- /dev/null +++ b/engines/pegasus/Game_Shell/CGameState.cpp @@ -0,0 +1,252 @@ +/* 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/Game_Shell/CGameState.h" +#include "pegasus/Game_Shell/Headers/Game_Shell_Constants.h" + +namespace Pegasus { + +tNeighborhoodID CGameState::gCurrentNeighborhood = kNoNeighborhoodID; +tRoomID CGameState::gCurrentRoom = kNoRoomID; +tDirectionConstant CGameState::gCurrentDirection = kNoDirection; +tNeighborhoodID CGameState::gNextNeighborhoodID = kNoNeighborhoodID; +tRoomID CGameState::gNextRoomID = kNoRoomID; +tDirectionConstant CGameState::gNextDirection = kNoDirection; +tNeighborhoodID CGameState::gLastNeighborhood = kNoNeighborhoodID; +tRoomID CGameState::gLastRoom = kNoRoomID; +tDirectionConstant CGameState::gLastDirection = kNoDirection; +tRoomID CGameState::gOpenDoorRoom = kNoRoomID; +tDirectionConstant CGameState::gOpenDoorDirection = kNoDirection; + +Common::Error CGameState::WriteGameState(Common::WriteStream *stream) { + stream->writeUint16BE(gCurrentNeighborhood); + stream->writeUint16BE(gCurrentRoom); + stream->writeByte(gCurrentDirection); + stream->writeUint16BE(gNextNeighborhoodID); + stream->writeUint16BE(gNextRoomID); + stream->writeByte(gNextDirection); + stream->writeUint16BE(gLastNeighborhood); + stream->writeUint16BE(gLastRoom); + stream->writeUint16BE(gOpenDoorRoom); + stream->writeByte(gOpenDoorDirection); + + if (stream->err()) + return Common::kWritingFailed; + + return Common::kNoError; +} + +Common::Error CGameState::ReadGameState(Common::ReadStream *stream) { + gCurrentNeighborhood = stream->readUint16BE(); + gCurrentRoom = stream->readUint16BE(); + gCurrentDirection = stream->readByte(); + gNextNeighborhoodID = stream->readUint16BE(); + gNextRoomID = stream->readUint16BE(); + gNextDirection = stream->readByte(); + gLastNeighborhood = stream->readUint16BE(); + gLastRoom = stream->readUint16BE(); + gOpenDoorRoom = stream->readUint16BE(); + gOpenDoorDirection = stream->readByte(); + + if (stream->err()) + return Common::kReadingFailed; + + return Common::kNoError; +} + +void CGameState::ResetGameState() { + gCurrentNeighborhood = kNoNeighborhoodID; + gCurrentRoom = kNoRoomID; + gCurrentDirection = kNoDirection; + gNextNeighborhoodID = kNoNeighborhoodID; + gNextRoomID = kNoRoomID; + gNextDirection = kNoDirection; + gLastNeighborhood = kNoNeighborhoodID; + gLastRoom = kNoRoomID; + gLastDirection = kNoDirection; + gOpenDoorRoom = kNoRoomID; + gOpenDoorDirection = kNoDirection; +} + +void CGameState::GetCurrentLocation(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) { + neighborhood = gCurrentNeighborhood; + room = gCurrentRoom; + direction = gCurrentDirection; +} + +void CGameState::SetCurrentLocation(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) { + gLastNeighborhood = gCurrentNeighborhood; + gLastRoom = gCurrentRoom; + gLastDirection = gCurrentDirection; + gCurrentNeighborhood = neighborhood; + gCurrentRoom = room; + gCurrentDirection = direction; +} + +tNeighborhoodID CGameState::GetCurrentNeighborhood() { + return gCurrentNeighborhood; +} + +void CGameState::SetCurrentNeighborhood(const tNeighborhoodID neighborhood) { + gLastNeighborhood = gCurrentNeighborhood; + gCurrentNeighborhood = neighborhood; +} + +tRoomID CGameState::GetCurrentRoom() { + return gCurrentRoom; +} + +void CGameState::SetCurrentRoom(const tRoomID room) { + gLastRoom = gCurrentRoom; + gCurrentRoom = room; +} + +tDirectionConstant CGameState::GetCurrentDirection() { + return gCurrentDirection; +} + +void CGameState::SetCurrentDirection(const tDirectionConstant direction) { + gLastDirection = gCurrentDirection; + gCurrentDirection = direction; +} + +tRoomViewID CGameState::GetCurrentRoomAndView() { + return MakeRoomView(gCurrentRoom, gCurrentDirection); +} + +void CGameState::GetNextLocation(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) { + neighborhood = gNextNeighborhoodID; + room = gNextRoomID; + direction = gNextDirection; +} + +void CGameState::SetNextLocation(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) { + gNextNeighborhoodID = neighborhood; + gNextRoomID = room; + gNextDirection = direction; +} + +tNeighborhoodID CGameState::GetNextNeighborhood() { + return gNextNeighborhoodID; +} + +void CGameState::SetNextNeighborhood(const tNeighborhoodID neighborhood) { + gNextNeighborhoodID = neighborhood; +} + +tRoomID CGameState::GetNextRoom() { + return gNextRoomID; +} + +void CGameState::SetNextRoom(const tRoomID room) { + gNextRoomID = room; +} + +tDirectionConstant CGameState::GetNextDirection() { + return gNextDirection; +} + +void CGameState::SetNextDirection(const tDirectionConstant direction) { + gNextDirection = direction; +} + +void CGameState::GetLastLocation(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction) { + neighborhood = gCurrentNeighborhood; + room = gCurrentRoom; + direction = gCurrentDirection; +} + +void CGameState::SetLastLocation(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) { + gCurrentNeighborhood = neighborhood; + gCurrentRoom = room; + gCurrentDirection = direction; +} + +tNeighborhoodID CGameState::GetLastNeighborhood() { + return gLastNeighborhood; +} + +void CGameState::SetLastNeighborhood(const tNeighborhoodID neighborhood) { + gLastNeighborhood = neighborhood; +} + +tRoomID CGameState::GetLastRoom() { + return gLastRoom; +} + +void CGameState::SetLastRoom(const tRoomID room) { + gLastRoom = room; +} + +tDirectionConstant CGameState::GetLastDirection() { + return gLastDirection; +} + +void CGameState::SetLastDirection(const tDirectionConstant direction) { + gLastDirection = direction; +} + +tRoomViewID CGameState::GetLastRoomAndView() { + return MakeRoomView(gLastRoom, gLastDirection); +} + +void CGameState::GetOpenDoorLocation(tRoomID &room, tDirectionConstant &direction) { + room = gOpenDoorRoom; + direction = gOpenDoorDirection; +} + +void CGameState::SetOpenDoorLocation(const tRoomID room, const tDirectionConstant direction) { + gOpenDoorRoom = room; + gOpenDoorDirection = direction; +} + +tRoomID CGameState::GetOpenDoorRoom() { + return gOpenDoorRoom; +} + +void CGameState::SetOpenDoorRoom(const tRoomID room) { + gOpenDoorRoom = room; +} + +tDirectionConstant CGameState::GetOpenDoorDirection() { + return gOpenDoorDirection; +} + +void CGameState::SetOpenDoorDirection(const tDirectionConstant direction) { + gOpenDoorDirection = direction; +} + +tRoomViewID CGameState::GetDoorOpenRoomAndView() { + return MakeRoomView(gOpenDoorRoom, gOpenDoorDirection); +} + +bool CGameState::IsCurrentDoorOpen() { + return gOpenDoorRoom == gCurrentRoom && gOpenDoorDirection == gCurrentDirection; +} + +} // End of namespace Pegasus diff --git a/engines/pegasus/Game_Shell/CGameState.h b/engines/pegasus/Game_Shell/CGameState.h new file mode 100755 index 0000000000..b7ad71bb50 --- /dev/null +++ b/engines/pegasus/Game_Shell/CGameState.h @@ -0,0 +1,107 @@ +/* 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_CGAMESTATE_H +#define PEGASUS_GAMESHELL_CGAMESTATE_H + +#include "pegasus/Game_Shell/Headers/Game_Shell_Types.h" + +namespace Common { + class Error; + class ReadStream; + class WriteStream; +} + +namespace Pegasus { + +class CGameState { +public: + static Common::Error WriteGameState(Common::WriteStream *stream); + static Common::Error ReadGameState(Common::ReadStream *stream); + + static void ResetGameState(); + + static void GetCurrentLocation(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction); + static void SetCurrentLocation(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); + + static tNeighborhoodID GetCurrentNeighborhood(); + static void SetCurrentNeighborhood(const tNeighborhoodID neighborhood); + static tRoomID GetCurrentRoom(); + static void SetCurrentRoom(const tRoomID room); + static tDirectionConstant GetCurrentDirection(); + static void SetCurrentDirection(const tDirectionConstant direction); + + static tRoomViewID GetCurrentRoomAndView(); + + static void GetNextLocation(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction); + static void SetNextLocation(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); + + static tNeighborhoodID GetNextNeighborhood(); + static void SetNextNeighborhood(const tNeighborhoodID neighborhood); + static tRoomID GetNextRoom(); + static void SetNextRoom(const tRoomID room); + static tDirectionConstant GetNextDirection(); + static void SetNextDirection(const tDirectionConstant direction); + + static void GetLastLocation(tNeighborhoodID &neighborhood, tRoomID &room, tDirectionConstant &direction); + static void SetLastLocation(const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); + + static tNeighborhoodID GetLastNeighborhood(); + static void SetLastNeighborhood(const tNeighborhoodID neighborhood); + static tRoomID GetLastRoom(); + static void SetLastRoom(const tRoomID room); + static tDirectionConstant GetLastDirection(); + static void SetLastDirection(const tDirectionConstant direction); + + static tRoomViewID GetLastRoomAndView(); + + static void GetOpenDoorLocation(tRoomID &room, tDirectionConstant &direction); + static void SetOpenDoorLocation(const tRoomID room, const tDirectionConstant direction); + static tRoomID GetOpenDoorRoom(); + static void SetOpenDoorRoom(const tRoomID room); + static tDirectionConstant GetOpenDoorDirection(); + static void SetOpenDoorDirection(const tDirectionConstant direction); + + static tRoomViewID GetDoorOpenRoomAndView(); + + static bool IsCurrentDoorOpen(); + +protected: + static tNeighborhoodID gCurrentNeighborhood; + static tRoomID gCurrentRoom; + static tDirectionConstant gCurrentDirection; + static tNeighborhoodID gNextNeighborhoodID; + static tRoomID gNextRoomID; + static tDirectionConstant gNextDirection; + static tNeighborhoodID gLastNeighborhood; + static tRoomID gLastRoom; + static tDirectionConstant gLastDirection; + static tRoomID gOpenDoorRoom; + static tDirectionConstant gOpenDoorDirection; +}; + +} // End of namespace Pegasus + +#endif diff --git a/engines/pegasus/Game_Shell/CInventory.cpp b/engines/pegasus/Game_Shell/CInventory.cpp new file mode 100755 index 0000000000..3747beda89 --- /dev/null +++ b/engines/pegasus/Game_Shell/CInventory.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/Game_Shell/CItem.h" +#include "pegasus/Game_Shell/CInventory.h" +#include "pegasus/Game_Shell/Headers/Game_Shell_Constants.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 new file mode 100755 index 0000000000..57ea1c99cc --- /dev/null +++ b/engines/pegasus/Game_Shell/CInventory.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_GAMESHELL_CINVENTORY_H +#define PEGASUS_GAMESHELL_CINVENTORY_H + +#include "pegasus/Game_Shell/CItemList.h" +#include "pegasus/Game_Shell/Headers/Game_Shell_Types.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 new file mode 100755 index 0000000000..af0bff42e3 --- /dev/null +++ b/engines/pegasus/Game_Shell/CItem.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/Game_Shell/CItem.h" +#include "pegasus/Game_Shell/CItemList.h" +#include "pegasus/Game_Shell/Headers/Game_Shell_Constants.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 new file mode 100755 index 0000000000..cb0931c8bd --- /dev/null +++ b/engines/pegasus/Game_Shell/CItem.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_GAMESHELL_CITEM_H +#define PEGASUS_GAMESHELL_CITEM_H + +#include "pegasus/MMShell/Utilities/MMIDObject.h" +#include "pegasus/Game_Shell/Headers/Game_Shell_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) + +*/ + +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 new file mode 100755 index 0000000000..256a895797 --- /dev/null +++ b/engines/pegasus/Game_Shell/CItemList.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/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 new file mode 100755 index 0000000000..75a34a0213 --- /dev/null +++ b/engines/pegasus/Game_Shell/CItemList.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_GAMESHELL_CITEMLIST_H +#define PEGASUS_GAMESHELL_CITEMLIST_H + +#include "common/list.h" + +#include "pegasus/Game_Shell/Headers/Game_Shell_Types.h" + +namespace Common { + class ReadStream; + class WriteStream; +} + +namespace Pegasus { + +class CItem; + +class CItemList : public Common::List<CItem *> { +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/Game_Shell/Headers/Game_Shell_Constants.h b/engines/pegasus/Game_Shell/Headers/Game_Shell_Constants.h new file mode 100755 index 0000000000..5d64629d95 --- /dev/null +++ b/engines/pegasus/Game_Shell/Headers/Game_Shell_Constants.h @@ -0,0 +1,81 @@ +/* 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_HEADERS_GAMESHELLCONSTANTS +#define PEGASUS_GAMESHELL_HEADERS_GAMESHELLCONSTANTS + +#include "engines/pegasus/MMShell/MMConstants.h" +#include "engines/pegasus/Game_Shell/Headers/Game_Shell_Types.h" + +namespace Pegasus { + +const tGameID kGameIDNothing = -1; + +const tActorID kNoActorID = kGameIDNothing; +const tActorID kPlayerID = 0; +const tItemID kNoItemID = kGameIDNothing; +const tRoomID kNoRoomID = kGameIDNothing; +const tExtraID kNoExtraID = 0xFFFFFFFF; +const tNeighborhoodID kNoNeighborhoodID = kGameIDNothing; +const tAlternateID kNoAlternateID = 0; +const tGameMenuCommand kMenuCmdNoCommand = 0; + +const tHotSpotActivationID kActivateHotSpotAlways = 0; +const tHotSpotActivationID kActivateHotSpotNever = -1; + +const tItemState kNoItemState = -1; + +const tDirectionConstant kNoDirection = 0xFF; + +const tTurnDirection kNoTurn = 0xFF; +const tTurnDirection kTurnLeft = 0; +const tTurnDirection kTurnRight = 1; +const tTurnDirection kTurnUp = 2; +const tTurnDirection kTurnDown = 3; +const tTurnDirection kMaxTurns = 4; + +const tGameMode kNoMode = -1; +const tGameMode kModeNavigation = 0; +const tGameMode kLastGameShellMode = kModeNavigation; + +const tCanMoveForwardReason kCanMoveForward = 0; +const tCanMoveForwardReason kCantMoveBlocked = kCanMoveForward + 1; +const tCanMoveForwardReason kCantMoveDoorClosed = kCantMoveBlocked + 1; +const tCanMoveForwardReason kCantMoveDoorLocked = kCantMoveDoorClosed + 1; +const tCanMoveForwardReason kCantMoveLastReason = kCantMoveDoorLocked; + +const tCanTurnReason kCanTurn = 0; +const tCanTurnReason kCantTurnNoTurn = kCanTurn + 1; +const tCanTurnReason kCantTurnLastReason = kCantTurnNoTurn; + +const tCanOpenDoorReason kCanOpenDoor = 0; +const tCanOpenDoorReason kCantOpenNoDoor = kCanOpenDoor + 1; +const tCanOpenDoorReason kCantOpenLocked = kCantOpenNoDoor + 1; +const tCanOpenDoorReason kCantOpenAlreadyOpen = kCantOpenLocked + 1; +const tCanOpenDoorReason kCantOpenLastReason = kCantOpenAlreadyOpen; + +} // End of namespace Pegasus + +#endif diff --git a/engines/pegasus/Game_Shell/Headers/Game_Shell_Types.h b/engines/pegasus/Game_Shell/Headers/Game_Shell_Types.h new file mode 100755 index 0000000000..923f7a72dd --- /dev/null +++ b/engines/pegasus/Game_Shell/Headers/Game_Shell_Types.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_GAMESHELL_HEADERS_GAMESHELLTYPES +#define PEGASUS_GAMESHELL_HEADERS_GAMESHELLTYPES + +#include "pegasus/MMShell/MMTypes.h" + +namespace Pegasus { + +typedef tMM16BitID tGameID; + +typedef tGameID tItemID; +typedef tGameID tActorID; +typedef tGameID tRoomID; +typedef tGameID tNeighborhoodID; +typedef tMM8BitU tAlternateID; +typedef tMM8BitS tHotSpotActivationID; + +typedef tMM16BitS tWeightType; + +typedef tMM8BitU tDirectionConstant; +typedef tMM8BitU tTurnDirection; + +// Meant to be room in low 16 bits and direction in high 16 bits. +typedef tMM32BitU tRoomViewID; + +#define MakeRoomView(room, direction) (((tRoomViewID) (room)) | (((tRoomViewID) (direction)) << 16)) + +typedef tMM32BitU tExtraID; + +typedef tMM16BitS tGameMode; + +typedef tMM16BitS tWeightType; + +typedef tMM16BitS tItemState; + +typedef tMM8BitS tDeathReason; + +typedef tMM32BitS tGameMenuCommand; + +typedef tMM32BitS tGameScoreType; + +typedef long tCanMoveForwardReason; + +typedef long tCanTurnReason; + +typedef long tCanOpenDoorReason; + +enum tInventoryResult { + kInventoryOK, + kTooMuchWeight, + kItemNotInInventory +}; + +} // End of namespace Pegasus + +#endif |