1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "ultima/ultima4/game/context.h"
24 #include "ultima/ultima4/conversation/conversation.h"
25 #include "ultima/ultima4/conversation/dialogueloader_hw.h"
26 #include "ultima/ultima4/game/player.h"
27 #include "ultima/ultima4/filesys/savegame.h"
28 #include "ultima/ultima4/filesys/u4file.h"
29 #include "ultima/ultima4/core/utils.h"
30 #include "ultima/ultima4/ultima4.h"
31 #include "ultima/shared/std/containers.h"
32
33 namespace Ultima {
34 namespace Ultima4 {
35
36 Response *hawkwindGetAdvice(const DynamicResponse *kw);
37 Response *hawkwindGetIntro(const DynamicResponse *dynResp);
38
39 /* Hawkwind text indexes */
40 #define HW_SPEAKONLYWITH 40
41 #define HW_RETURNWHEN 41
42 #define HW_ISREVIVED 42
43 #define HW_WELCOME 43
44 #define HW_GREETING1 44
45 #define HW_GREETING2 45
46 #define HW_PROMPT 46
47 #define HW_DEFAULT 49
48 #define HW_ALREADYAVATAR 50
49 #define HW_GOTOSHRINE 51
50 #define HW_BYE 52
51
52 /**
53 * A special case dialogue loader for Hawkwind.
54 */
load(Common::SeekableReadStream * source)55 Dialogue *U4HWDialogueLoader::load(Common::SeekableReadStream *source) {
56 Std::vector<Common::String> &hawkwindText = g_ultima->_hawkwindText;
57 hawkwindText = u4read_stringtable("hawkwind");
58
59 Dialogue *dlg = new Dialogue();
60 dlg->setTurnAwayProb(0);
61
62 dlg->setName("Hawkwind");
63 dlg->setPronoun("He");
64 dlg->setPrompt(hawkwindText[HW_PROMPT]);
65 Response *intro = new DynamicResponse(&hawkwindGetIntro);
66 dlg->setIntro(intro);
67 dlg->setLongIntro(intro);
68 dlg->setDefaultAnswer(new Response(Common::String("\n" + hawkwindText[HW_DEFAULT])));
69
70 for (int v = 0; v < VIRT_MAX; v++) {
71 Common::String virtue(getVirtueName((Virtue) v));
72 lowercase(virtue);
73 virtue = virtue.substr(0, 4);
74 dlg->addKeyword(virtue, new DynamicResponse(&hawkwindGetAdvice, virtue));
75 }
76
77 Response *bye = new Response(hawkwindText[HW_BYE]);
78 bye->add(g_responseParts->STOPMUSIC);
79 bye->add(g_responseParts->END);
80 dlg->addKeyword("bye", bye);
81 dlg->addKeyword("", bye);
82
83 return dlg;
84 }
85
86 /**
87 * Generate the appropriate response when the player asks Lord British
88 * for help. The help text depends on the current party status; when
89 * one quest item is complete, Lord British provides some direction to
90 * the next one.
91 */
hawkwindGetAdvice(const DynamicResponse * dynResp)92 Response *hawkwindGetAdvice(const DynamicResponse *dynResp) {
93 Common::String text;
94 int virtue = -1, virtueLevel = -1;
95 Std::vector<Common::String> &hawkwindText = g_ultima->_hawkwindText;
96
97 /* check if asking about a virtue */
98 for (int v = 0; v < VIRT_MAX; v++) {
99 if (scumm_strnicmp(dynResp->getParam().c_str(), getVirtueName((Virtue) v), 4) == 0) {
100 virtue = v;
101 virtueLevel = g_ultima->_saveGame->_karma[v];
102 break;
103 }
104 }
105 if (virtue != -1) {
106 text = "\n\n";
107 if (virtueLevel == 0)
108 text += hawkwindText[HW_ALREADYAVATAR] + "\n";
109 else if (virtueLevel < 80)
110 text += hawkwindText[(virtueLevel / 20) * 8 + virtue];
111 else if (virtueLevel < 99)
112 text += hawkwindText[3 * 8 + virtue];
113 else /* virtueLevel >= 99 */
114 text = hawkwindText[4 * 8 + virtue] + hawkwindText[HW_GOTOSHRINE];
115 } else {
116 text = Common::String("\n") + hawkwindText[HW_DEFAULT];
117 }
118
119 return new Response(text);
120 }
121
hawkwindGetIntro(const DynamicResponse * dynResp)122 Response *hawkwindGetIntro(const DynamicResponse *dynResp) {
123 Response *intro = new Response("");
124 Std::vector<Common::String> &hawkwindText = g_ultima->_hawkwindText;
125
126 if (g_context->_party->member(0)->getStatus() == STAT_SLEEPING ||
127 g_context->_party->member(0)->getStatus() == STAT_DEAD) {
128 intro->add(hawkwindText[HW_SPEAKONLYWITH] + g_context->_party->member(0)->getName() +
129 hawkwindText[HW_RETURNWHEN] + g_context->_party->member(0)->getName() +
130 hawkwindText[HW_ISREVIVED]);
131 intro->add(g_responseParts->END);
132 } else {
133 intro->add(g_responseParts->STARTMUSIC_HW);
134 intro->add(g_responseParts->HAWKWIND);
135
136 intro->add(hawkwindText[HW_WELCOME] + g_context->_party->member(0)->getName() +
137 hawkwindText[HW_GREETING1] + hawkwindText[HW_GREETING2]);
138 }
139
140 return intro;
141 }
142
143 } // End of namespace Ultima4
144 } // End of namespace Ultima
145