From da0669b82bcc29fd6b926d27c63812aa17164f10 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 7 Aug 2016 11:45:27 -0400 Subject: TITANIC: Add getNewRandomNumber to CGameObject --- engines/titanic/core/game_object.cpp | 10 ++++++++++ engines/titanic/core/game_object.h | 5 +++++ 2 files changed, 15 insertions(+) (limited to 'engines/titanic') diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 73e3511319..89e3ded248 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -1392,6 +1392,16 @@ void CGameObject::resetMail() { mailMan->resetValue(); } +int CGameObject::getNewRandomNumber(int max, int *oldVal) { + if (oldVal) { + int startingVal = *oldVal; + while (*oldVal == startingVal && max > 0) + *oldVal = g_vm->getRandomNumber(max); + } else { + return g_vm->getRandomNumber(max); + } +} + /*------------------------------------------------------------------------*/ CRoomItem *CGameObject::getRoom() const { diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index fdbbcd6959..665fc6cf37 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -513,6 +513,11 @@ protected: * Scroll text down */ void scrollTextDown(); + + /** + * Gets a new random number + */ + int getNewRandomNumber(int max, int *oldVal = nullptr); public: bool _isMail; int _id; -- cgit v1.2.3