-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfortunestreetdata.cpp
560 lines (518 loc) · 20 KB
/
fortunestreetdata.cpp
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
#include "fortunestreetdata.h"
#include "orderedmap.h"
#include "qdebug.h"
#include <QtMath>
#include <QSet>
#include <QIODevice>
//#include <QDebug>
QDataStream &operator>>(QDataStream &stream, WaypointData &data) {
stream >> data.entryId;
for (quint8 &dest: data.destinations) {
stream >> dest;
}
return stream;
}
QDataStream &operator<<(QDataStream &stream, const WaypointData &data) {
stream << data.entryId;
for (quint8 dest: data.destinations) {
stream << dest;
}
return stream;
}
int SquareData::getValueFromShopModel(int shopModel) {
return shopModel*10;
}
void SquareData::updateValueFromShopModel() {
value = getValueFromShopModel(shopModel);
}
qreal SquareData::getYield() {
if(value == 0) return 0;
return (qreal) price / (qreal) value;
}
SquareData &SquareData::syncForMultiState(const SquareData &other)
{
squareType = other.squareType;
if (squareType == Property) {
districtDestinationId = other.districtDestinationId;
}
oneWayLift = other.oneWayLift;
value = other.value;
price = other.price;
shopModel = other.shopModel;
return *this;
}
bool SquareData::operator==(const SquareData &other) const
{
QByteArray arr0, arr1;
QDataStream ds0(&arr0, QIODevice::WriteOnly), ds1(&arr1, QIODevice::WriteOnly);
ds0 << *this;
ds1 << other;
return arr0 == arr1 && validDirections == other.validDirections;
}
bool SquareData::operator!=(const SquareData &other) const {
return !(*this == other);
}
QDataStream &operator>>(QDataStream &stream, SquareData &data) {
stream >> data.squareType;
stream >> data.positionX >> data.positionY;
stream >> data.unknown1;
for (auto &waypoint: data.waypoints) {
stream >> waypoint;
}
stream >> data.districtDestinationId;
stream >> data.oneWayLift;
stream >> data.value >> data.price;
stream >> data.unknown2;
stream >> data.shopModel;
return stream;
}
QDataStream &operator<<(QDataStream &stream, const SquareData &data) {
stream << data.squareType;
stream << data.positionX << data.positionY;
stream << data.unknown1;
for (auto &waypoint: data.waypoints) {
stream << waypoint;
}
stream << data.districtDestinationId;
stream << data.oneWayLift;
stream << data.value << data.price;
stream << data.unknown2;
stream << data.shopModel;
return stream;
}
QDataStream &operator>>(QDataStream &stream, Header &data) {
char header[4];
stream.readRawData(header, 4);
if (QByteArray(header, 4) != data.magicNumber) {
stream.setStatus(QDataStream::ReadCorruptData);
} else {
stream >> data.headerSize;
}
return stream;
}
QDataStream &operator<<(QDataStream &stream, const Header &data) {
stream.writeRawData(data.magicNumber, 4);
stream << data.headerSize;
return stream;
}
QDataStream &operator>>(QDataStream &stream, BoardInfo &data) {
stream >> data.header;
stream.skipRawData(8);
stream >> data.initialCash;
stream >> data.targetAmount;
stream >> data.baseSalary >> data.salaryIncrement;
stream >> data.maxDiceRoll;
stream >> data.galaxyStatus;
stream >> data.versionFlag;
return stream;
}
QDataStream &operator<<(QDataStream &stream, const BoardInfo &data) {
stream << Header(data.header.getMagicNumber(), BoardInfo::SIZE);
stream << (quint64)0;
stream << data.initialCash;
stream << data.targetAmount;
stream << data.baseSalary << data.salaryIncrement;
stream << data.maxDiceRoll;
stream << data.galaxyStatus;
stream << data.versionFlag;
return stream;
}
QDataStream &operator>>(QDataStream &stream, BoardData &data) {
quint16 squareCount;
stream >> data.header;
stream.skipRawData(4);
stream >> squareCount;
stream.skipRawData(2);
for (quint16 i=0; i<squareCount; ++i) {
SquareData square(i);
stream >> square;
data.squares.append(square);
}
return stream;
}
QDataStream &operator<<(QDataStream &stream, const BoardData &data) {
stream << Header(data.header.getMagicNumber(), BoardData::SIZE + SquareData::SIZE*data.squares.size());
stream << (quint32)0;
stream << (quint16)data.squares.size();
stream << (quint16)0;
for (const auto &square: data.squares) {
stream << square;
}
return stream;
}
QDataStream &operator>>(QDataStream &stream, BoardFile &data) {
stream >> data.header;
stream >> data.unknown;
stream >> data.boardInfo;
stream >> data.boardData;
if (data.boardInfo.versionFlag >= 1) {
data.readAutopathData(stream);
}
if (data.boardInfo.versionFlag >= 2) {
stream >> data.boardInfo.autopathRange >> data.boardInfo.straightLineTolerance;
}
if (data.boardInfo.versionFlag >= 3) {
stream >> data.boardInfo.useAdvancedAutoPath;
}
return stream;
}
QDataStream &operator<<(QDataStream &stream, const BoardFile &data) {
stream << Header(data.header.getMagicNumber(), BoardFile::SIZE + SquareData::SIZE*data.boardData.squares.size());
stream << data.unknown;
stream << data.boardInfo;
stream << data.boardData;
if (data.boardInfo.versionFlag >= 1) {
data.writeAutopathData(stream);
}
if (data.boardInfo.versionFlag >= 2) {
stream << data.boardInfo.autopathRange << data.boardInfo.straightLineTolerance;
}
if (data.boardInfo.versionFlag >= 3) {
stream << data.boardInfo.useAdvancedAutoPath;
}
return stream;
}
static_assert(sizeof(AutoPath::DIRECTIONS)/sizeof(AutoPath::Direction) <= 8, "too many directions to fit into a 64-bit integer");
void BoardFile::readAutopathData(QDataStream &stream) {
for (auto &square: boardData.squares) {
square.validDirections.clear();
quint64 autopathFlags;
stream >> autopathFlags;
for (auto from: AutoPath::DIRECTIONS) {
for (auto to: AutoPath::DIRECTIONS) {
if (autopathFlags & ( Q_UINT64_C(0x1) << (from * 8 + to) )) {
square.validDirections.insert(from, to);
}
}
}
}
}
void BoardFile::writeAutopathData(QDataStream &stream) const {
for (auto &square: boardData.squares) {
quint64 autopathFlags = 0;
for (auto it=square.validDirections.begin(); it!=square.validDirections.end(); ++it) {
autopathFlags |= Q_UINT64_C(0x1) << (it.key()*8 + it.value());
}
stream << autopathFlags;
}
}
bool BoardFile::operator==(const BoardFile &other) const {
QByteArray thisArr, otherArr;
QDataStream thisStream(&thisArr, QIODevice::WriteOnly), otherStream(&otherArr, QIODevice::WriteOnly);
thisStream << (*this);
otherStream << other;
return thisArr == otherArr;
}
bool BoardFile::operator!=(const BoardFile &other) const {
return !(*this == other);
}
void BoardFile::verify(QStringList &errors, QStringList &warnings) {
QVector<int> districtCount(12);
int highestDistrict = -1;
if (boardData.squares.size() < 3) {
errors << "Board must have at least 3 squares.";
}
if (boardData.squares.size() > 86) {
errors << "Board must have a maximum of 86 squares.";
}
if (boardInfo.maxDiceRoll < 1 || boardInfo.maxDiceRoll > 9) {
errors << "Maximum dice roll must be between 1 and 9 inclusive.";
}
for (auto &square: boardData.squares) {
if (square.squareType == Property || square.squareType == VacantPlot) {
if (square.districtDestinationId >= 12) {
warnings << QString("Square %1 has district value %2. Maximum is 11.").arg(square.id).arg(square.districtDestinationId);
} else {
++districtCount[square.districtDestinationId];
highestDistrict = qMax(highestDistrict, (int)square.districtDestinationId);
}
}
// ignore waypoints for one-way alleys
if (square.squareType == OneWayAlleyDoorA
|| square.squareType == OneWayAlleyDoorB
|| square.squareType == OneWayAlleyDoorC
|| square.squareType == OneWayAlleyDoorD
|| square.squareType == OneWayAlleySquare) {
continue;
}
// ensure the ID set on a Switch Square is not 94 or higher
if (square.squareType == SwitchSquare){
if(square.districtDestinationId > 93){
errors << "The Board State ID of all Switch Squares must be 93 or lower.";
}
}
// ensure Lift/Magmalice Square is connected to a Lift End or Magmalice square
if (square.squareType == LiftMagmaliceSquareStart){
// if it doesn't exist
if(square.districtDestinationId > boardData.squares.size()){
errors << QString("The destination square of Lift/Magmalice Start square with ID %1 was not found.").arg(square.id);
} else {
SquareData &destSquare = boardData.squares[square.districtDestinationId];
// if the destination square is not a Magmalice square
if(destSquare.squareType == MagmaliceSquare || destSquare.squareType == LiftSquareEnd){
// do nothing
} else {
errors << QString("The destination of Lift/Magmalice Start square with ID %1 is not a Magmalice square or a Lift End square.").arg(square.id);
}
}
}
// ensure Magmalice Square or Lift End is connected to a Lift/Magmalice Start square
if (square.squareType == MagmaliceSquare || square.squareType == LiftSquareEnd){
// if it doesn't exist
if(square.districtDestinationId > boardData.squares.size()){
errors << QString("The destination of Magmalice square with ID %1 was not found.").arg(square.id);
} else {
SquareData &destSquare = boardData.squares[square.districtDestinationId];
// if the destination square is not a Lift/Magmalice Start square
if(destSquare.squareType != LiftMagmaliceSquareStart){
errors << QString("The destination of Magmalice square with ID %1 is not a Lift/Magmalice Start square.").arg(square.id);
}
}
}
// if all of a square's waypoints have undefined Entry IDs
auto waypoints = square.waypoints;
if(waypoints[0].entryId == 255 && waypoints[1].entryId == 255 && waypoints[2].entryId == 255 && waypoints[3].entryId == 255){
warnings << QString("All of the waypoint entry IDs for Square ID %1 are undefined.").arg(square.id);
}
QSet<quint8> destinations;
for (int i=0; i<4; ++i) {
if (square.waypoints[i].entryId > boardData.squares.size()) {
if (square.waypoints[i].entryId != 255) {
errors << QString("Starting square of Waypoint %1 of Square %2 is Square %3 which does not exist")
.arg(i+1).arg(square.id).arg(square.waypoints[i].entryId);
} else {
// Since this waypoint has an entry point of 255, we ignore it entirely.
continue;
}
} else {
auto &otherSquare = boardData.squares[square.waypoints[i].entryId];
if (qAbs(square.positionX - otherSquare.positionX) > 96
|| qAbs(square.positionY - otherSquare.positionY) > 96) {
warnings << QString("Starting square of Waypoint %1 of Square %2 is Square %3 which is too far")
.arg(i+1).arg(square.id).arg(square.waypoints[i].entryId);
}
}
if(square.squareType == LiftMagmaliceSquareStart || square.squareType == MagmaliceSquare || square.squareType == LiftSquareEnd){
// if the square is one of these types, don't perform the next check, as these squares can actually work this way.
} else {
// if it's not a Lift/Magmalice square, and its waypoint's entry ID is defined, but all destinations are undefined
if(square.waypoints[i].entryId != 255 &&
square.waypoints[i].destinations[0] == 255 &&
square.waypoints[i].destinations[1] == 255 &&
square.waypoints[i].destinations[2] == 255 &&
square.waypoints[i].destinations[3] == 255){
warnings << QString("All destinations for waypoint %1 of Square ID %2 are undefined.").arg(i).arg(square.id);
}
}
for (int j=0; j<3; ++j) {
auto dest = square.waypoints[i].destinations[j];
destinations.insert(dest);
if (dest > boardData.squares.size()) {
if (dest != 255) {
errors << QString("Destination square #%4 of Waypoint %1 of Square %2 is Square %3 which does not exist")
.arg(i+1).arg(square.id).arg(dest).arg(j+1);
}
} else {
auto &otherSquare = boardData.squares[dest];
if (qAbs(square.positionX - otherSquare.positionX) > 96
|| qAbs(square.positionY - otherSquare.positionY) > 96) {
warnings << QString("Destination square #%4 of Waypoint %1 of Square %2 is Square %3 which is too far")
.arg(i+1).arg(square.id).arg(dest).arg(j+1);
}
if (otherSquare.squareType == OneWayAlleySquare &&
square.squareType != OneWayAlleyDoorA &&
square.squareType != OneWayAlleyDoorB &&
square.squareType != OneWayAlleyDoorC &&
square.squareType != OneWayAlleyDoorD) {
warnings << QString("Destination square #%4 of Waypoint %1 of Square %2 is Square %3 which is a One Way Alley Square")
.arg(i+1).arg(square.id).arg(dest).arg(j+1);
}
}
}
}
destinations.remove(255);
if (destinations.size() > 4) {
errors << QString("Square %1 has %2 destinations, which is more than the maximum of 4.")
.arg(square.id).arg(destinations.size());
}
}
for (int i=0; i<=highestDistrict; ++i) {
if (districtCount[i] == 0) {
errors << QString("Did you skip District %1 when assigning districts?").arg(i);
} else if (districtCount[i] > 6) {
errors << QString("District %1 has %2 shops which is more than the maximum of 6").arg(i).arg(districtCount[i]);
}
}
}
OrderedMap<QString, SquareType> textToSquareTypes = {
{"Property", Property},
{"Bank", Bank},
{"Venture", VentureSquare},
{"Spade", SuitSquareSpade},
{"Heart", SuitSquareHeart},
{"Diamond", SuitSquareDiamond},
{"Club", SuitSquareClub},
{"Spade (Change-of-Suit)", ChangeOfSuitSquareSpade},
{"Heart (Change-of-Suit)", ChangeOfSuitSquareHeart},
{"Diamond (Change-of-Suit)", ChangeOfSuitSquareDiamond},
{"Club (Change-of-Suit)", ChangeOfSuitSquareClub},
{"Take-A-Break", TakeABreakSquare},
{"Boon", BoonSquare},
{"Boom", BoomSquare},
{"Stockbroker", StockBrokerSquare},
{"Roll On", RollOnSquare},
{"Arcade", ArcadeSquare},
{"Switch", SwitchSquare},
{"Cannon", CannonSquare},
{"Backstreet A", BackStreetSquareA},
{"Backstreet B", BackStreetSquareB},
{"Backstreet C", BackStreetSquareC},
{"Backstreet D", BackStreetSquareD},
{"Backstreet E", BackStreetSquareE},
{"One-Way Alley Door A", OneWayAlleyDoorA},
{"One-Way Alley Door B", OneWayAlleyDoorB},
{"One-Way Alley Door C", OneWayAlleyDoorC},
{"One-Way Alley Door D", OneWayAlleyDoorD},
{"Lift/Magmalice Start", LiftMagmaliceSquareStart},
{"Lift End", LiftSquareEnd},
{"Magmalice", MagmaliceSquare},
{"One-Way Alley End", OneWayAlleySquare},
{"Event", EventSquare},
{"Vacant Plot", VacantPlot}
};
OrderedMap<QString, quint8> textToShopTypes = {
{"",0},
{"Scrap-paper shop",5},
{"Wool shop",6},
{"Bottle store",7},
{"Secondhand book shop",8},
{"Scrap-metal supplier",9},
{"Stationery shop",10},
{"General store",11},
{"Florist's",12},
{"Ice-cream shop",13},
{"Comic-book shop",14},
{"Dairy",15},
{"Doughnut shop",16},
{"Pizza shack",17},
{"Bakery",18},
{"Grocery store",19},
{"Pharmacy",20},
{"Fish market",21},
{"Toy shop",22},
{"Bookshop",23},
{"Cosmetics boutique",24},
{"T-shirt shop",25},
{"Fruit stall",26},
{"Photography studio",27},
{"Coffee shop",28},
{"Butcher shop",29},
{"Restaurant",30},
{"Barbershop",31},
{"Hat boutique",32},
{"Hardware store",33},
{"Gift shop",34},
{"Launderette",35},
{"Shoe shop",36},
{"Clothing store",37},
{"Optician's",38},
{"Clockmaker's",39},
{"Furniture shop",40},
{"Sports shop",41},
{"Locksmith's",42},
{"Glassmaker's",43},
{"Sushi restaurant",44},
{"Art gallery",45},
{"Leatherware boutique",46},
{"Pet shop",47},
{"Nail salon",48},
{"Spice shop",49},
{"Music shop",50},
{"Surf shop",51},
{"Boating shop",52},
{"Cartographer's",53},
{"Alloy rims shop",54},
{"Fashion boutique",55},
{"Waxworks",56},
{"Lens shop",57},
{"Kaleidoscope shop",58},
{"Crystal ball shop",59},
{"Gemstone supplier",61},
{"Taxidermy studio",62},
{"Antiques dealer's",65},
{"Goldsmith's",68},
{"Fossil shop",70},
{"Music-box shop",72},
{"Marionette workshop",75},
{"Health shop",76},
{"Organic food shop",80},
{"Bridal boutique",81},
{"Autograph shop",85},
{"Meteorite shop",90},
{"Department store",98}
};
QString squareTypeToText(SquareType type) {
for (auto it = textToSquareTypes.begin(); it != textToSquareTypes.end(); ++it) {
if (it.value() == type) {
return it.key();
}
}
return "";
}
SquareType textToSquareType(QString string) { return textToSquareTypes.value(string, Property); }
QList<QString> squareTexts() { return textToSquareTypes.keys(); }
QString shopTypeToText(quint8 shopType) {
for (auto it = textToShopTypes.begin(); it != textToShopTypes.end(); ++it) {
if (it.value() == shopType) {
return it.key();
}
}
return "Unused";
}
QString shopTypeToTextWithValue(quint8 shopType) {
for (auto it = textToShopTypes.begin(); it != textToShopTypes.end(); ++it) {
if (it.value() == shopType) {
return QString("(%1 G) %2").arg(SquareData::getValueFromShopModel(shopType)).arg(it.key());;
}
}
return "Unused";
}
quint8 textToShopType(QString string) {
for (auto it = textToShopTypes.begin(); it != textToShopTypes.end(); ++it) {
auto shopName = it.key();
if(shopName.isEmpty())
continue;
auto shopType = it.value();
if(string.contains(shopName))
return shopType;
}
return 0;
}
QList<QString> shopTexts() { return textToShopTypes.keys(); }
QList<QString> shopTextsWithValues() {
QList<QString> shopTexts;
for (auto it = textToShopTypes.begin(); it != textToShopTypes.end(); ++it) {
auto shopType = it.value();
if(it.key().isEmpty())
shopTexts << it.key();
else
shopTexts << QString("(%1 G) %2").arg(SquareData::getValueFromShopModel(shopType)).arg(it.key());
}
return shopTexts;
}
bool BoardInfo::operator==(const BoardInfo &other) const
{
return initialCash == other.initialCash
&& baseSalary == other.baseSalary
&& targetAmount == other.targetAmount
&& salaryIncrement == other.salaryIncrement
&& maxDiceRoll == other.maxDiceRoll
&& galaxyStatus == other.galaxyStatus
&& versionFlag == other.versionFlag
&& autopathRange == other.autopathRange
&& straightLineTolerance == other.straightLineTolerance
&& useAdvancedAutoPath == other.useAdvancedAutoPath;
}
bool BoardInfo::operator!=(const BoardInfo &other) const {
return !(*this == other);
}