Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/game/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,12 @@ struct INTERIMDATA {

CEREAL_CLASS_VERSION(INTERIMDATA, 1);

struct AssetData {
std::vector<struct MissionSequenceKey> sSeq; // Success sequences
std::vector<struct MissionSequenceKey> fSeq; // Failure sequences
std::vector <struct XFails> fails; // Failure texts and codes
};

#pragma pack(pop)

// Double-check that the structs we write to disk have the proper size
Expand Down
9 changes: 8 additions & 1 deletion src/game/game_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ char dayOnMoon = 20;
char AI[2] = {0, 0};
// Used to hold mid-turn save game related information
INTERIMDATA interimData;
struct AssetData *Assets;

const char *S_Name[] = {
"LAUNCH",
Expand Down Expand Up @@ -215,13 +216,19 @@ int game_main_impl(int argc, char *argv[])

xMODE = 0;

Data = (Players *)xmalloc(sizeof(struct Players) + 1);
Data = new struct Players;
buffer = (char *)xmalloc(BUFFER_SIZE);

DEBUG3("main buffer %p (%d)", buffer, BUFFER_SIZE);

memset(buffer, 0x00, BUFFER_SIZE);

Assets = new struct AssetData;

DESERIALIZE_JSON_FILE(&Assets->sSeq, locate_file("seq.json", FT_DATA));
DESERIALIZE_JSON_FILE(&Assets->fSeq, locate_file("fseq.json", FT_DATA));
DESERIALIZE_JSON_FILE(&Assets->fails, locate_file("fails.json", FT_DATA));

OpenEmUp(); // OPEN SCREEN AND SETUP GOODIES

if (options.want_intro) {
Expand Down
1 change: 1 addition & 0 deletions src/game/game_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ extern char *buffer;
extern int32_t xMODE;
extern const char *S_Name[];
extern INTERIMDATA interimData;
extern struct AssetData *Assets;

#endif // GAME_MAIN_H
45 changes: 18 additions & 27 deletions src/game/mis_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ void PlaySequence(char plr, int step, const char *InSeq, char mode)
char scratch[SCRATCH_SIZE];
std::vector<struct Infin> Mob;
std::vector<struct OF> Mob2;
std::vector<struct MissionSequenceKey> sSeq, fSeq;
char *fname;
std::string ID;

Expand Down Expand Up @@ -225,68 +224,60 @@ void PlaySequence(char plr, int step, const char *InSeq, char mode)
AEPT = 0;
}

if (mode == 0) {

fname = locate_file("seq.json", FT_DATA);
DESERIALIZE_JSON_FILE(&sSeq, fname);

} else {

fname = locate_file("fseq.json", FT_DATA);
DESERIALIZE_JSON_FILE(&fSeq, fname);
if (mode == 1) {

/* i: the first element in fSeq belonging to the right step */
for (i = 0; i < fSeq.size(); i++) {
if (strncmp(fSeq.at(i).MissionStep.c_str(), Mev[step].FName, 4) == 0) {
for (i = 0; i < Assets->fSeq.size(); i++) {
if (strncmp(Assets->fSeq.at(i).MissionStep.c_str(), Mev[step].FName, 4) == 0) {
break;
}
}

if (i == fSeq.size()) {
if (i == Assets->fSeq.size()) {
err = 1;
}

}

if (mode == 0) {
j = 0;
ID = sSeq.at(j).MissionIdSequence;
ID = Assets->sSeq.at(j).MissionIdSequence;

while (strncmp(&ID[3], Seq, strlen(&ID[3])) != 0) {
j++;
if (j == sSeq.size()) {
if (j == Assets->sSeq.size()) {
err = 1;
break;
}
else {
ID = sSeq.at(j).MissionIdSequence;
ID = Assets->sSeq.at(j).MissionIdSequence;
}
}

if (ID[2] - 0x30 == 1) {
if (fem == 0) {
j++;
ID = sSeq.at(j).MissionIdSequence;
ID = Assets->sSeq.at(j).MissionIdSequence;
}
}
} else if (err == 0) {
j = i;
ID = fSeq.at(j).MissionIdSequence;
ID = Assets->fSeq.at(j).MissionIdSequence;

while (strncmp(&ID[3], Seq, strlen(&ID[3])) != 0) {
j++;
if (j == fSeq.size()) {
if (j == Assets->fSeq.size()) {
err = 1;
break;
}
else {
if (strncmp(fSeq.at(j).MissionStep.c_str(), Mev[step].FName, 4) != 0) {
if (strncmp(Assets->fSeq.at(j).MissionStep.c_str(), Mev[step].FName, 4) != 0) {
// j is already entering the next MissionStep
err = 1;
break;
}
else {
ID = fSeq.at(j).MissionIdSequence;
ID = Assets->fSeq.at(j).MissionIdSequence;
}
}
}
Expand All @@ -304,9 +295,9 @@ void PlaySequence(char plr, int step, const char *InSeq, char mode)
max = (unsigned)(ID[0] - 0x30);
j += Mev[step].rnum % max;
if (mode == 0) {
ID = sSeq.at(j).MissionIdSequence;
ID = Assets->sSeq.at(j).MissionIdSequence;
} else {
ID = fSeq.at(j).MissionIdSequence;
ID = Assets->fSeq.at(j).MissionIdSequence;
}
}

Expand Down Expand Up @@ -387,15 +378,15 @@ void PlaySequence(char plr, int step, const char *InSeq, char mode)
char name[20]; /** \todo assumption about seq_filename len */

if (mode == 0) {
play_audio(sSeq.at(k).audio.at(i), mode);
play_audio(Assets->sSeq.at(k).audio.at(i), mode);
} else {
play_audio(fSeq.at(k).audio.at(i), mode);
play_audio(Assets->fSeq.at(k).audio.at(i), mode);
}

if (mode == 0) {
strntcpy(seq_name, sSeq.at(k).video.at(i).c_str(), sizeof(seq_name));
strntcpy(seq_name, Assets->sSeq.at(k).video.at(i).c_str(), sizeof(seq_name));
} else {
strntcpy(seq_name, fSeq.at(k).video.at(i).c_str(), sizeof(seq_name));
strntcpy(seq_name, Assets->fSeq.at(k).video.at(i).c_str(), sizeof(seq_name));
}

snprintf(name, sizeof(name), "%s.ogg", seq_name);
Expand Down
16 changes: 6 additions & 10 deletions src/game/mis_m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,21 @@ void BranchIfAlive(int *FNote);
*/
void GetFailStat(struct XFails *Now, char *FName, int rnum)
{
std::vector <struct XFails> fails;

DEBUG2("->GetFailStat(struct XFails *Now,char *FName,int rnum %d)",
rnum);
assert(Now != NULL);

DESERIALIZE_JSON_FILE(&fails, locate_file("fails.json", FT_DATA));

for (int i = 0; i < fails.size(); i++) {
if (!xstrncasecmp(fails.at(i).MissionStep.c_str(), FName, 4)) {
for (int i = 0; i < Assets->fails.size(); i++) {
if (!xstrncasecmp(Assets->fails.at(i).MissionStep.c_str(), FName, 4)) {
if (rnum < 0) { // unmanned
if (fails.at(i).percentage == rnum) {
*Now = fails.at(i);
if (Assets->fails.at(i).percentage == rnum) {
*Now = Assets->fails.at(i);
break;
}
}
else { // manned
if (fails.at(i).percentage > rnum) {
*Now = fails.at(i);
if (Assets->fails.at(i).percentage > rnum) {
*Now = Assets->fails.at(i);
break;
}
}
Expand Down