-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddon.cpp
More file actions
249 lines (203 loc) · 6.41 KB
/
Copy pathaddon.cpp
File metadata and controls
249 lines (203 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*******************************************************************************
* O P E N T S
*******************************************************************************
* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright 2026 OpenTS contributors
*
* See LICENSE.md for applicable additional terms and warranty disclaimers.
******************************************************************************/
#include "always.h"
#include "addon.h"
#include "assert.h"
#include "ccfile.h"
#include "data.h"
#include "init.h"
#include "language\language.h"
#include "ownrdraw.h"
BOOL CALLBACK Select_Game_Type_Dialog_Proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam);
int AvailableAddOns = 1 << ADDON_BASE_GAME;
int ActiveAddOns = 1 << ADDON_BASE_GAME;
AddonType RequiredAddon = ADDON_BASE_GAME;
/// <summary>
/// Steps an addon type on to the value after it.
/// </summary>
/// <returns>Returns with the incremented value.</returns>
AddonType operator++(AddonType & val)
{
val = AddonType(int(val) + 1);
return(val);
}
/// <summary>
/// Steps an addon type back to the value before it.
/// </summary>
/// <returns>Returns with the decremented value.</returns>
AddonType operator--(AddonType & val)
{
val = AddonType(int(val) - 1);
return(val);
}
/// <summary>
/// Asks the player which game they wish to play.
/// This routine puts up the game type dialog whenever an expansion has been detected, and
/// enables whichever addon the player settles on. With nothing but the base game present
/// there is no choice to make, so the dialog never appears.
/// </summary>
/// <param name="type">The addon that the player chose to play.</param>
/// <returns>bool; Should the game carry on? Returns false if the player backed out.</returns>
bool Select_Game_Type_Dialog(AddonType &type)
{
int retval;
type = ADDON_BASE_GAME;
if (Addon_Installed(ADDON_ANY)) {
HWND dialog = OwnerDraw::Begin_Dialog(IDD_SELECT_GAME_TYPE, Select_Game_Type_Dialog_Proc);
if (dialog != 0) {
SetWindowLong(dialog, DWL_USER, (LONG)&retval);
OwnerDraw::Display_Dialog(dialog);
retval = -1;
while (retval == -1) {
if (OwnerDraw::Dialog_Message_Handler() == true) {
break;
}
Title_Screen_Restore(false);
}
ShowWindow(dialog, SW_HIDE);
UpdateWindow(MainWindow);
OwnerDraw::End_Dialog(dialog);
ActiveAddOns = 1 << ADDON_BASE_GAME;
switch (retval) {
default:
type = ADDON_BASE_GAME;
break;
case IDC_GAMETYPE_FIRESTORM:
Enable_Addon(ADDON_FIRESTORM);
type = ADDON_FIRESTORM;
break;
case IDCANCEL:
return(false);
}
}
Set_Required_Addon(type);
return(true);
}
return(true);
}
/// <summary>
/// Handles the messages for the game type selection dialog.
/// This routine stashes the control that the player pressed into the caller's result
/// variable, which is what lets the dialog loop know it can stop.
/// </summary>
BOOL CALLBACK Select_Game_Type_Dialog_Proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
int * retval;
int rc = OwnerDraw::Default_Dialog_Proc(window, message, wparam, lparam);
if (rc == 0) {
switch (message) {
case WM_COMMAND:
retval = (int *)GetWindowLong(window, DWL_USER);
*retval = LOWORD(wparam);
break;
}
rc = 0;
}
return(rc);
}
/// <summary>
/// Determines which addons are installed on this machine.
/// This routine is called during startup and looks for the data files that each expansion
/// ships with. What it finds decides whether the player is offered a game type at all.
/// </summary>
void Detect_Addons(void)
{
AvailableAddOns = (1 << ADDON_BASE_GAME);
ActiveAddOns = (1 << ADDON_BASE_GAME);
if (CCFileClass("EXPAND01.MIX").Is_Available() == true && CCFileClass("FIRESTRM.INI").Is_Available() == true) {
AvailableAddOns |= (1 << ADDON_FIRESTORM);
}
}
/// <summary>
/// Is the specified addon installed on this machine?
/// Pass ADDON_ANY to ask whether any expansion at all was found.
/// </summary>
/// <returns>bool; Is the addon present?</returns>
bool Addon_Installed(AddonType addon)
{
if (addon == ADDON_ANY) {
return((AvailableAddOns & ~(1 << ADDON_BASE_GAME)) != false);
}
return((AvailableAddOns & (1 << addon)) != false);
}
/// <summary>
/// Is the specified addon switched on?
/// An addon must be both installed and enabled to count. Pass ADDON_ANY to ask whether any
/// expansion at all is currently in force.
/// </summary>
/// <returns>bool; Is the addon active?</returns>
bool Addon_Enabled(AddonType addon)
{
if (addon == ADDON_ANY) {
return((ActiveAddOns & AvailableAddOns & ~(1 << ADDON_BASE_GAME)) != false);
}
return((ActiveAddOns & AvailableAddOns & (1 << addon)) != false);
}
/// <summary>
/// Switches on an installed addon.
/// Only an addon that was actually detected can be enabled, so asking for one that is not
/// present is harmless. Pass ADDON_ANY to switch on everything that is installed.
/// </summary>
void Enable_Addon(AddonType addon)
{
if (addon == ADDON_ANY) {
ActiveAddOns = AvailableAddOns;
} else if (addon > ADDON_BASE_GAME) {
ActiveAddOns |= AvailableAddOns & (1 << addon);
}
}
/// <summary>
/// Switches an addon back off.
/// Pass ADDON_ANY to drop all the way back to the base game.
/// </summary>
void Disable_Addon(AddonType addon)
{
if (addon == ADDON_ANY) {
ActiveAddOns = (1 << ADDON_BASE_GAME);
} else if (addon > ADDON_BASE_GAME) {
ActiveAddOns &= ~(1 << addon);
}
}
/// <summary>
/// Is the specified addon the one the current game demands?
/// </summary>
/// <returns>bool; Is this the required addon?</returns>
bool Is_Required_Addon(AddonType addon)
{
return(addon == RequiredAddon);
}
/// <summary>
/// Fetches the addon that the current game demands.
/// </summary>
/// <returns>Returns with the required addon.</returns>
AddonType Get_Required_Addon(void)
{
return(RequiredAddon);
}
/// <summary>
/// Sets the addon that the current game demands.
/// This routine is called when the player picks a game type from the menus, and again when
/// a scenario or a saved game states which addon its rules were built for.
/// </summary>
void Set_Required_Addon(AddonType addon)
{
RequiredAddon = addon;
}
/// <summary>
/// Fetches the display name of an addon.
/// </summary>
/// <returns>Returns with the localized title text for the addon specified.</returns>
const char * Get_Addon_Title(AddonType addon)
{
static int _id[ADDON_COUNT] = {
TXT_SHORT_TITLE,
TXT_EXPANSION_TITLE,
};
return(Fetch_String(_id[addon]));
}