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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/* 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 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 "scumm/he/intern_he.h"
#include "scumm/he/logic_he.h"
namespace Scumm {
/**
* Logic code for:
* Backyard Football
* Backyard Football 2002
*/
class LogicHEfootball : public LogicHE {
public:
LogicHEfootball(ScummEngine_v90he *vm) : LogicHE(vm) {}
int versionID();
int32 dispatch(int op, int numArgs, int32 *args);
private:
int op_1004(int32 *args);
int op_1006(int32 *args);
int op_1007(int32 *args);
int op_1010(int32 *args);
int op_1022(int32 *args);
int op_1023(int32 *args);
int op_1024(int32 *args);
};
int LogicHEfootball::versionID() {
return 1;
}
int32 LogicHEfootball::dispatch(int op, int numArgs, int32 *args) {
int res = 0;
switch (op) {
case 1004:
res = op_1004(args);
break;
case 1006:
res = op_1006(args);
break;
case 1007:
res = op_1007(args);
break;
case 1010:
res = op_1010(args);
break;
case 1022:
res = op_1022(args);
break;
case 1023:
res = op_1023(args);
break;
case 1024:
res = op_1024(args);
break;
case 8221968:
// Someone had a fun and used his birthday as opcode number
res = getFromArray(args[0], args[1], args[2]);
break;
case 1492: case 1493: case 1494: case 1495: case 1496:
case 1497: case 1498: case 1499: case 1500: case 1501:
case 1502: case 1503: case 1504: case 1505: case 1506:
case 1507: case 1508: case 1509: case 1510: case 1511:
case 1512: case 1513: case 1514: case 1555:
// DirectPlay-related
// 1513: initialize
// 1555: set fake lag
break;
case 2200: case 2201: case 2202: case 2203: case 2204:
case 2205: case 2206: case 2207: case 2208: case 2209:
case 2210: case 2211: case 2212: case 2213: case 2214:
case 2215: case 2216: case 2217: case 2218: case 2219:
case 2220: case 2221: case 2222: case 2223: case 2224:
case 2225: case 2226: case 2227: case 2228:
// Boneyards-related
break;
case 3000: case 3001: case 3002: case 3003: case 3004:
// Internet-related
// 3000: check for updates
// 3001: check network status
// 3002: autoupdate
// 3003: close connection
break;
default:
LogicHE::dispatch(op, numArgs, args);
warning("Tell sev how to reproduce it (%d)", op);
}
return res;
}
int LogicHEfootball::op_1004(int32 *args) {
// Identical to LogicHEsoccer::op_1004
double res, a2, a4, a5;
a5 = ((double)args[4] - (double)args[1]) / ((double)args[5] - (double)args[2]);
a4 = ((double)args[3] - (double)args[0]) / ((double)args[5] - (double)args[2]);
a2 = (double)args[2] - (double)args[0] * a4 - args[1] * a5;
res = (double)args[6] * a4 + (double)args[7] * a5 + a2;
writeScummVar(108, (int32)res);
writeScummVar(109, (int32)a2);
writeScummVar(110, (int32)a5);
writeScummVar(111, (int32)a4);
return 1;
}
int LogicHEfootball::op_1006(int32 *args) {
// This seems to be more or less the inverse of op_1010
const double a1 = args[1];
double res;
// 2.9411764e-4 = 1/3400
// 5.3050399e-2 = 1/18.85 = 20/377
// 1.1764706e-2 = 1/85 = 40/3400
// 1.2360656e-1 = 377/3050
res = (1.0 - a1 * 2.9411764e-4 * 5.3050399e-2) * 1.2360656e-1 * args[0] +
a1 * 1.1764706e-2 + 46;
// Shortened / optimized version of that formula:
// res = (377.0 - a1 / 170.0) / 3050.0 * args[0] + a1 / 85.0 + 46;
writeScummVar(108, (int32)res);
// 1.2360656e-1 = 377/3050
// 1.1588235e-1 = 197/1700 = 394/3400
res = 640.0 - args[2] * 1.2360656e-1 - a1 * 1.1588235e-1 - 26;
writeScummVar(109, (int32)res);
return 1;
}
int LogicHEfootball::op_1007(int32 *args) {
double res, temp;
temp = (double)args[1] * 0.32;
if (temp > 304.0)
res = -args[2] * 0.142;
else
res = args[2] * 0.142;
res += temp;
writeScummVar(108, (int32)res);
res = (1000.0 - args[2]) * 0.48;
writeScummVar(109, (int32)res);
return 1;
}
int LogicHEfootball::op_1010(int32 *args) {
// This seems to be more or less the inverse of op_1006
double a1 = (640.0 - (double)args[1] - 26.0) / 1.1588235e-1;
// 2.9411764e-4 = 1/3400
// 5.3050399e-2 = 1/18.85 = 20/377
// 1.1764706e-2 = 1/85 = 40/3400
// 1.2360656e-1 = 377/3050
double a0 = ((double)args[0] - 46 - a1 * 1.1764706e-2) /
((1.0 - a1 * 2.9411764e-4 * 5.3050399e-2) * 1.2360656e-1);
writeScummVar(108, (int32)a0);
writeScummVar(109, (int32)a1);
return 1;
}
int LogicHEfootball::op_1022(int32 *args) {
double res;
double var10 = args[4] - args[1];
double var8 = args[5] - args[2];
double var6 = args[3] - args[0];
res = sqrt(var8 * var8 + var6 * var6 + var10 * var10);
if (res >= (double)args[6]) {
var8 = (double)args[6] * var8 / res;
var10 = (double)args[6] * var10 / res;
res = (double)args[6] * var6 / res;
}
writeScummVar(108, (int32)res);
writeScummVar(109, (int32)var10);
writeScummVar(110, (int32)var8);
return 1;
}
int LogicHEfootball::op_1023(int32 *args) {
double var10, var18, var20, var28, var30, var30_;
double argf[7];
for (int i = 0; i < 7; i++)
argf[i] = args[i];
var10 = (argf[3] - argf[1]) / (argf[2] - argf[0]);
var28 = var10 * var10 + 1;
var20 = argf[0] * var10;
var18 = (argf[5] + argf[1] + var20) * argf[4] * var10 * 2 +
argf[6] * argf[6] * var28 + argf[4] * argf[4] -
argf[0] * argf[0] * var10 * var10 -
argf[5] * argf[0] * var10 * 2 -
argf[5] * argf[1] * 2 -
argf[1] * argf[1] - argf[5] * argf[5];
if (var18 >= 0) {
var18 = sqrt(var18);
var30_ = argf[4] + argf[5] * var10 + argf[1] * var10 + argf[0] * var10 * var10;
var30 = (var30_ - var18) / var28;
var18 = (var30_ + var18) / var28;
if ((argf[0] - var30 < 0) && (argf[0] - var18 < 0)) {
var30_ = var30;
var30 = var18;
var18 = var30_;
}
var28 = var18 * var10 - var20 - argf[1];
var20 = var30 * var10 - var20 - argf[1];
} else {
var18 = 0;
var20 = 0;
var28 = 0;
var30 = 0;
}
writeScummVar(108, (int32)var18);
writeScummVar(109, (int32)var28);
writeScummVar(110, (int32)var30);
writeScummVar(111, (int32)var20);
return 1;
}
int LogicHEfootball::op_1024(int32 *args) {
writeScummVar(108, 0);
writeScummVar(109, 0);
writeScummVar(110, 0);
writeScummVar(111, 0);
return 1;
}
LogicHE *makeLogicHEfootball(ScummEngine_v90he *vm) {
return new LogicHEfootball(vm);
}
} // End of namespace Scumm
|