From 950ca3745dbd851dabbdf98bb962efbc1e3981ea Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 1 Mar 2023 22:14:48 -0800 Subject: [PATCH] MM: MM1: Added Tavern view --- devtools/create_mm/files/mm1/strings_en.yml | 6 + engines/mm/mm1/views_enh/dialogs.h | 2 + engines/mm/mm1/views_enh/locations/tavern.cpp | 168 ++++++++++++++++++ engines/mm/mm1/views_enh/locations/tavern.h | 65 +++++++ .../mm/mm1/views_enh/locations/training.cpp | 5 - engines/mm/mm1/views_enh/locations/training.h | 1 - engines/mm/module.mk | 1 + 7 files changed, 242 insertions(+), 6 deletions(-) create mode 100644 engines/mm/mm1/views_enh/locations/tavern.cpp create mode 100644 engines/mm/mm1/views_enh/locations/tavern.h diff --git a/devtools/create_mm/files/mm1/strings_en.yml b/devtools/create_mm/files/mm1/strings_en.yml index 7d13522208e..3b5c772c4be 100644 --- a/devtools/create_mm/files/mm1/strings_en.yml +++ b/devtools/create_mm/files/mm1/strings_en.yml @@ -516,6 +516,12 @@ enhdialogs: select: "Select" exit: "Exit" non_caster: "Not a spell caster..." + tavern: + title: "Tavern" + drink: "\x01""37Drink" + gather: "\x01""37Gather" + tip: "\x01""37Tip" + rumor: "\x01""37Rumors" temple: title: "Temple" heal: "\x01""37Heal" diff --git a/engines/mm/mm1/views_enh/dialogs.h b/engines/mm/mm1/views_enh/dialogs.h index 13be24d3482..00fea4abc16 100644 --- a/engines/mm/mm1/views_enh/dialogs.h +++ b/engines/mm/mm1/views_enh/dialogs.h @@ -36,6 +36,7 @@ #include "mm/mm1/views_enh/quick_ref.h" #include "mm/mm1/views_enh/interactions/statue.h" #include "mm/mm1/views_enh/locations/market.h" +#include "mm/mm1/views_enh/locations/tavern.h" #include "mm/mm1/views_enh/locations/temple.h" #include "mm/mm1/views_enh/locations/training.h" #include "mm/mm1/views_enh/spells/cast_spell.h" @@ -54,6 +55,7 @@ private: Views::Title _title; ViewsEnh::Interactions::Statue _statue; ViewsEnh::Locations::Market _market; + ViewsEnh::Locations::Tavern _tavern; ViewsEnh::Locations::Temple _temple; ViewsEnh::Locations::Training _training; ViewsEnh::Spells::CastSpell _castSpell; diff --git a/engines/mm/mm1/views_enh/locations/tavern.cpp b/engines/mm/mm1/views_enh/locations/tavern.cpp new file mode 100644 index 00000000000..b501263865f --- /dev/null +++ b/engines/mm/mm1/views_enh/locations/tavern.cpp @@ -0,0 +1,168 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 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, see . + * + */ + +#include "mm/mm1/views_enh/locations/tavern.h" +#include "mm/mm1/globals.h" +#include "mm/mm1/mm1.h" +#include "mm/mm1/sound.h" + +namespace MM { +namespace MM1 { +namespace ViewsEnh { +namespace Locations { + +Tavern::Tavern() : Location("Tavern", LOC_TAVERN) { + addButton(&_escSprite, Common::Point(24, 100), 0, KEYBIND_ESCAPE); +} + +void Tavern::draw() { + Location::draw(); + const Character &c = *g_globals->_currCharacter; + + setReduced(false); + writeLine(0, STRING["enhdialogs.tavern.title"], ALIGN_MIDDLE); + writeLine(1, STRING["enhdialogs.location.options_for"], ALIGN_MIDDLE); + writeLine(3, c._name, ALIGN_MIDDLE); + + writeLine(5, STRING["enhdialogs.tavern.drink"], ALIGN_LEFT, 10); + writeLine(6, STRING["enhdialogs.tavern.gather"], ALIGN_LEFT, 10); + writeLine(7, STRING["enhdialogs.tavern.tip"], ALIGN_LEFT, 10); + writeLine(8, STRING["enhdialogs.tavern.rumor"], ALIGN_LEFT, 10); + + writeLine(10, STRING["enhdialogs.location.gold"]); + writeLine(10, Common::String::format("%d", + g_globals->_currCharacter->_gold), ALIGN_RIGHT); + + setReduced(true); + writeString(27, 122, STRING["enhdialogs.location.esc"]); +} + +bool Tavern::msgGame(const GameMessage &msg) { + Location::msgGame(msg); +/* + if (msg._name == "UPDATE") + checkCharacter(); + */ + return true; +} + +bool Tavern::msgKeypress(const KeypressMessage &msg) { + // If a delay is active, end it + if (endDelay()) + return true; + + switch (msg.keycode) { + case Common::KEYCODE_d: + haveADrink(); + break; + case Common::KEYCODE_g: + g_globals->_currCharacter->gatherGold(); + redraw(); + break; + case Common::KEYCODE_t: + tipBartender(); + break; + case Common::KEYCODE_r: + listenForRumors(); + break; + default: + return Location::msgKeypress(msg); + break; + } + + return true; +} + +bool Tavern::msgAction(const ActionMessage &msg) { + if (endDelay()) + return true; + + if (msg._action == KEYBIND_ESCAPE) { + leave(); + return true; + } + + return Location::msgAction(msg); +} + +void Tavern::messageShown() { + redraw(); +} + + +void Tavern::haveADrink() { + if (g_globals->_currCharacter->_condition) { + Sound::sound(SOUND_2); + displayMessage(STRING["dialogs.tavern.terrible"]); + + } else if (subtractGold(1)) { + if (++g_globals->_currCharacter->_numDrinks < 3 || + g_engine->getRandomNumber(10) < + g_globals->_currCharacter->_endurance) { + displayMessage(STRING["dialogs.tavern.great_stuff"]); + + } else { + if (!(g_globals->_currCharacter->_condition & BAD_CONDITION)) + g_globals->_currCharacter->_condition |= POISONED; + + Sound::sound(SOUND_2); + displayMessage(STRING["dialogs.tavern.you_feel_sick"]); + } + } +} + +void Tavern::tipBartender() { + if (g_globals->_currCharacter->_condition) { + displayMessage(STRING["dialogs.tavern.go_see_clerics"]); + + } else if (subtractGold(1)) { + if (g_globals->_currCharacter->_numDrinks == 0) { + displayMessage(STRING["dialogs.tavern.have_a_drink"]); + + } else if (g_engine->getRandomNumber(3) != 3) { + displayMessage(STRING["dialogs.tavern.have_another_round"]); + + } else { + int townNum = g_maps->_currentMap->dataByte(Maps::MAP_ID); + displayMessage(STRING[Common::String::format( + "dialogs.tavern.tips.%d_%d", + townNum, g_globals->_currCharacter->_numDrinks + )]); + } + } +} + +void Tavern::listenForRumors() { + Common::String msg = STRING["dialogs.tavern.rumors.none"]; + if (!g_globals->_heardRumor) { + g_globals->_heardRumor = true; + msg = STRING[Common::String::format( + "dialogs.tavern.rumors.%d", + g_engine->getRandomNumber(16))]; + } + + displayMessage(msg); +} + +} // namespace Location +} // namespace ViewsEnh +} // namespace MM1 +} // namespace MM diff --git a/engines/mm/mm1/views_enh/locations/tavern.h b/engines/mm/mm1/views_enh/locations/tavern.h new file mode 100644 index 00000000000..a751b260b24 --- /dev/null +++ b/engines/mm/mm1/views_enh/locations/tavern.h @@ -0,0 +1,65 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 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, see . + * + */ + +#ifndef MM1_VIEWS_ENH_LOCATIONS_TAVERN_H +#define MM1_VIEWS_ENH_LOCATIONS_TAVERN_H + +#include "mm/mm1/views_enh/locations/location.h" +#include "mm/mm1/data/character.h" + +namespace MM { +namespace MM1 { +namespace ViewsEnh { +namespace Locations { + +class Tavern : public Location { +private: + /** + * Have a drink + */ + void haveADrink(); + + /** + * Tip the bartender + */ + void tipBartender(); + + /** + * Listen for rumors + */ + void listenForRumors(); + +public: + Tavern(); + + void draw() override; + bool msgGame(const GameMessage &msg); + bool msgKeypress(const KeypressMessage &msg) override; + bool msgAction(const ActionMessage &msg) override; + void messageShown() override; +}; + +} // namespace Locations +} // namespace ViewsEnh +} // namespace MM1 +} // namespace MM + +#endif diff --git a/engines/mm/mm1/views_enh/locations/training.cpp b/engines/mm/mm1/views_enh/locations/training.cpp index 986b1c9ef99..d45ef0b4ca5 100644 --- a/engines/mm/mm1/views_enh/locations/training.cpp +++ b/engines/mm/mm1/views_enh/locations/training.cpp @@ -197,11 +197,6 @@ void Training::train() { } } -void Training::timeout() { - checkCharacter(); - Location::timeout(); -} - void Training::messageShown() { checkCharacter(); redraw(); diff --git a/engines/mm/mm1/views_enh/locations/training.h b/engines/mm/mm1/views_enh/locations/training.h index 40f59361032..f59dd239e3f 100644 --- a/engines/mm/mm1/views_enh/locations/training.h +++ b/engines/mm/mm1/views_enh/locations/training.h @@ -61,7 +61,6 @@ public: bool msgGame(const GameMessage &msg); bool msgKeypress(const KeypressMessage &msg) override; bool msgAction(const ActionMessage &msg) override; - void timeout() override; void messageShown() override; }; diff --git a/engines/mm/module.mk b/engines/mm/module.mk index d3eb315d750..de16235aa71 100644 --- a/engines/mm/module.mk +++ b/engines/mm/module.mk @@ -146,6 +146,7 @@ MODULE_OBJS += \ mm1/views_enh/interactions/statue.o \ mm1/views_enh/locations/location.o \ mm1/views_enh/locations/market.o \ + mm1/views_enh/locations/tavern.o \ mm1/views_enh/locations/temple.o \ mm1/views_enh/locations/training.o \ mm1/maps/maps.o \