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
1 change: 1 addition & 0 deletions data/gamedata/urast.json
Original file line number Diff line number Diff line change
Expand Up @@ -22331,6 +22331,7 @@
"value9": 0
}
},
"Mail" : -1,
"Mev": {
"value0": {
"value0": {
Expand Down
11 changes: 5 additions & 6 deletions src/game/admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "filesystem.h"
#include "options.h"
#include "prest.h"

#include "pbm.h"

#include <zlib.h>

Expand Down Expand Up @@ -954,7 +954,7 @@ void autosave_game(const char *name)
* length as SaveFileHdr::Name, plus delimiter.
*
* \param name The string location where the name is stored.
* \return the user-supplied file name, ("" if aborted).
s * \return the user-supplied file name, ("" if aborted).
* \throws IOException if insufficient disk space remaining.
*/
std::string GetBlockName()
Expand Down Expand Up @@ -1603,7 +1603,6 @@ void LoadGame(const char *filename)
LOAD = 1;
} else if (GetSaveType(header) == SAVEGAME_PlayByMail) {
Option = -1;
MAIL = !(header.Country[0] == 8);

Data->plr[0] = Data->Def.Plr1 = plr[0] = 0;
Data->plr[1] = Data->Def.Plr2 = plr[1] = 1;
Expand Down Expand Up @@ -1894,14 +1893,14 @@ void write_save_file(const char *Name, SaveFileHdr header)

// Play-By-Mail save game hack
//
// If MAIL == 0, we are playing as the U.S. We need to
// If MAIL_PLAYER == 0, we are playing as the U.S. We need to
// save the game such that the U.S. starts again
if (MAIL == 0) {
if (MAIL_PLAYER == 0) {
Data->Def.Plr1 = 8;
Data->Def.Plr2 = 0;
}
// Playing as the Soviets
else if ((MAIL == 1)) {
else if ((MAIL_PLAYER == 1)) {
Data->Def.Plr1 = 0;
Data->Def.Plr2 = 9;
}
Expand Down
8 changes: 7 additions & 1 deletion src/game/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,12 @@ struct Players {
int8_t Season; /**< Season of Year */
struct PrestType Prestige[MAXIMUM_PRESTIGE_NUM]; /**< Definitions of Prest Vals */
struct BuzzData P[NUM_PLAYERS]; /**< Player Game Data */
int8_t unused_EMark[4] ; /**< unused - Event Marker */
int8_t unused_EMark[3] ; /**< unused - Event Marker */
int8_t Events[MAXIMUM_NEWS_EVENTS]; /**< History of Event Cards */
int8_t Count; /**< Number of Events Picked */
int8_t PD[NUM_PLAYERS][MAXIMUM_PRESTIGE_NUM]; /**< Prestige First Displayed: First Bit: Seen in MisRev, Second Bit: Seen by Opponent */
int8_t Mile[NUM_PLAYERS][10]; /**< MileStone Calcs */
int8_t Mail; /* Current status of PBEM game */
struct MisEval Mev[MAX_LAUNCHPADS][60]; /** < Mission eval for mail games */
int8_t Step[MAX_LAUNCHPADS]; /** Number of mission steps for mail games */

Expand All @@ -875,6 +876,9 @@ struct Players {
ar(CEREAL_NVP(Count));
ar(CEREAL_NVP(PD));
ar(CEREAL_NVP(Mile));
if (version > 0) {
ar(CEREAL_NVP(Mail));
}
ar(CEREAL_NVP(Mev));
ar(CEREAL_NVP(Step));

Expand All @@ -885,6 +889,8 @@ struct Players {
}
};

CEREAL_CLASS_VERSION(struct Players, 1)

struct MisAst { // This struct will be -1's if empty
struct Astros *A;
char loc;
Expand Down
1 change: 1 addition & 0 deletions src/game/endgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "pace.h"
#include "endianness.h"
#include "filesystem.h"
#include "pbm.h"


char PF[29][40] = {
Expand Down
89 changes: 54 additions & 35 deletions src/game/game_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ std::array<char, 2> IDLE;
char *buffer;
char pNeg[NUM_PLAYERS][MAX_MISSIONS];
int32_t xMODE;
char MAIL = -1;
char Option = -1;
int fOFF = -1;
// true for fullscreen mission playback, false otherwise
Expand Down Expand Up @@ -502,7 +501,7 @@ void MainLoop(void)
// Turn 1 is Spring 1957. The event count begins at 0, and is
// incremented as the news event text is being generated.
turn = 2 * (Data->Year - 57) + Data->Season + 1; // Start on turn 1
newTurn = (turn > Data->P[0].eCount); // eCount starts at 0.
newTurn = (turn > Data->P[MAIL_INVERTED == 1 ? 1 : 0].eCount); // eCount starts at 0.

LOAD = 0; // CLEAR LOAD FLAG

Expand Down Expand Up @@ -542,29 +541,32 @@ void MainLoop(void)
if (Data->Season == 0) {
CalcPresRev();
}

// Intel only gets updated in the fall, because there are
// only 30 Intel Briefing slots in the save record per
// player.
// Also, check to make sure this isn't an autosave repeating
// the start-of-turn actions.
for (i = 0; i < NUM_PLAYERS; i++) {
if (Data->Season == 1 && newTurn) {
IntelPhase(plr[i] - 2 * AI[i], 0);
}
}

}

for (i = 0; i < NUM_PLAYERS; i++) {

if (!i && (MAIL == 1)) { // Soviet turn coming up
if (!i && (MAIL_PLAYER == 1)) { // Soviet turn coming up
continue;
}

if (i && (MAIL == 0)) { // U.S. turn coming up
if (i && (MAIL_PLAYER == 0)) { // U.S. turn coming up
continue;
}

xMODE &= ~xMODE_CLOUDS; // reset clouds for spaceport

// Intel only gets updated in the fall, because there are
// only 30 Intel Briefing slots in the save record per
// player.
// Also, check to make sure this isn't an autosave repeating
// the start-of-turn actions.
if (Data->Season == 1 && newTurn) {
IntelPhase(plr[i] - 2 * AI[i], 0);
}

// computer vs. human

if ((IDLE[0] > 12 || IDLE[1] > 12) || ((AI[i] && plr[other(i)] < NUM_PLAYERS && ((Data->Def.Lev1 != 0 && other(i) == 0) || (Data->Def.Lev2 != 0 && other(i) == 1))))) {
Expand All @@ -591,7 +593,7 @@ void MainLoop(void)
VerifySF(plr[i]);

// Show prestige resulution from the previous turn
if (MAIL == 0) {
if (MAIL == 1 || MAIL == 2) {

if (Data->Prestige[Prestige_MannedLunarLanding].Place != -1) {
UpdateRecords(1);
Expand All @@ -601,14 +603,14 @@ void MainLoop(void)
return;
}

if (Data->Year == 77 && Data->Season == 1 && Data->Prestige[Prestige_MannedLunarLanding].Place == -1 && newTurn == false) { // Nobody won
if (Data->Year == 77 && Data->Season == 1 && Data->Prestige[Prestige_MannedLunarLanding].Place == -1 && MAIL == 1) { // Nobody won
SpecialEnd();
FadeOut(2, 10, 0, 0);
return;
}

PlayAllFirsts(MAIL_OPPONENT);
ShowPrestigeResults(MAIL);
ShowPrestigeResults(MAIL_PLAYER);
}

News(plr[i]); // EVENT FOR PLAYER
Expand Down Expand Up @@ -643,8 +645,9 @@ void MainLoop(void)

// Only increase the global event counter if this is really a new
// turn and not one already played in a save game
if(Data->Count == 2 * (2 * (Data->Year - 57) + Data->Season) + i) {
Data->Count++;
if(Data->Count == 2 * (2 * (Data->Year - 57) + Data->Season)
+ MAIL_INVERTED == 1 ? 1^i : i) {
Data->Count++;
}

if (QUIT) {
Expand All @@ -653,13 +656,14 @@ void MainLoop(void)
}

// Generate copy of the prestige data to be sent later to the
// Soviet side. We need to keep filling the prestige data to
// other side. We need to keep filling the prestige data to
// prevent unwarranted milestone/duration penalties, but the
// actual prestige resolution is done after the Soviet turn.
if (MAIL == 0) {
// actual prestige resolution is done after the opponent's
// turn.
if (MAIL == 0 || MAIL == 3) {
memcpy(oldPrestige, Data->Prestige, MAXIMUM_PRESTIGE_NUM * sizeof(struct PrestType));
// Save the current mission counter
old_mission_count = Data->P[0].PastMissionCount;
old_mission_count = Data->P[MAIL_PLAYER].PastMissionCount;
}

DockingKludge(); // fixup for both sides
Expand All @@ -685,21 +689,30 @@ void MainLoop(void)
prest = Launch(Order[i].plr, Order[i].loc);

// check for prestige firsts
if (AI[Order[i].plr] == 1 || (MAIL == 1 && Order[i].plr == 0) && Data->Prestige[Prestige_MannedLunarLanding].Place == -1) { // supposed to be 1
if (AI[Order[i].plr] == 1 || (MAIL == 1 && Order[i].plr == 0) || (MAIL == 2 && Order[i].plr == 1) && Data->Prestige[Prestige_MannedLunarLanding].Place == -1) { // supposed to be 1
PlayAllFirsts(Order[i].plr);
}

if (Data->Prestige[Prestige_MannedLunarLanding].Place != -1) {
if (MAIL != 0) {
if (MAIL != 0 && MAIL != 3) {
UpdateRecords(1);
NewEnd(Data->Prestige[Prestige_MannedLunarLanding].Place, Order[i].loc);

// Immediately hand over to the other player
MailSwitchEndgame();

return;
}

MailSwitchPlayer();
return;
// TODO: Don't perform missions after the L.L.
else {
break;
}


}

if (!(AI[Order[i].plr] || (MAIL == 1 && Order[i].plr == 0)) && prest != -20) { // -20 means scrubbed
if (!(AI[Order[i].plr] || (MAIL == 1 && Order[i].plr == 0) || (MAIL == 2 && Order[i].plr == 1)) && prest != -20) { // -20 means scrubbed
MisRev(Order[i].plr, prest, Data->P[Order[i].plr].PastMissionCount - 1);
}
}
Expand All @@ -708,11 +721,13 @@ void MainLoop(void)
} //for(i=0...
}

if (MAIL == 0) { // Hand over to the Soviet side
if (MAIL == 0 || MAIL == 3) { // Hand over to the other side
// Restore mission counter
Data->P[0].PastMissionCount = old_mission_count;
// Restore prestige data to the status before the U.S. missions
Data->P[MAIL_PLAYER].PastMissionCount = old_mission_count;
// Restore prestige data to the status before the missions
memcpy(Data->Prestige, oldPrestige, MAXIMUM_PRESTIGE_NUM * sizeof(struct PrestType));
MAIL = MAIL_NEXT;

MailSwitchPlayer();
return;
}
Expand All @@ -722,7 +737,7 @@ void MainLoop(void)
if (Data->Year == 77 && Data->Season == 1 && Data->Prestige[Prestige_MannedLunarLanding].Place == -1) {
// nobody wins .....
SpecialEnd();
MailSwitchPlayer();
MailSwitchEndgame();
return;
}

Expand Down Expand Up @@ -776,12 +791,16 @@ void MainLoop(void)
Data->Season++;
}

newTurn = true;

if (MAIL == 1) { // Hand back to the U.S. side
MailSwitchPlayer();
return;
// End of turn MAIL update
if (MAIL == 1) {
MAIL = 3;
}
else if (MAIL == 2) {
MAIL = 0;
}

newTurn = true;

}

Expand Down
1 change: 0 additions & 1 deletion src/game/game_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void PauseMouse(void);
void GetMouse_fast(void);

extern char Option;
extern char MAIL;
extern int fOFF;
extern char AI[2];
extern char manOnMoon;
Expand Down
9 changes: 5 additions & 4 deletions src/game/mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "filesystem.h"
#include "randomize.h"
#include "data.h"
#include "pbm.h"

Equipment *MH[2][8]; // Pointer to the hardware
struct MisAst MA[2][4]; //[2][4]
Expand Down Expand Up @@ -120,8 +121,8 @@ int Launch(char plr, char mis)
STEP = FINAL = JOINT = PastBANG = 0;
MisStat = tMen = 0x00; // clear mission status flags

// Don't do U.S. missions twice, just update prestige data
if (MAIL == 1 && plr == 0) {
// Don't do missions twice, just update prestige data
if ((MAIL == 1 && plr == 0) || (MAIL == 2 && plr == 1)) {
STEPnum = Data->Step[mis];
memcpy(Mev, Data->Mev[mis], 60 * sizeof(struct MisEval));
// Check for Mission death
Expand Down Expand Up @@ -350,7 +351,7 @@ int Launch(char plr, char mis)

// if (!AI[plr]) KillMusic();

if (MAIL == 0) {
if (MAIL == 0 || MAIL == 3) {
Data->Step[mis] = STEPnum;
}

Expand All @@ -373,7 +374,7 @@ int Launch(char plr, char mis)
}
}

if (MAIL == 0) {
if (MAIL == 0 || MAIL == 3) {
memcpy(Data->Mev[mis], Mev, 60 * sizeof(struct MisEval));
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/newmis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ OrderMissions(void)
for (i = 0; i < NUM_PLAYERS; i++) {
for (j = 0; j < MAX_MISSIONS; j++) {
// Don't run the Soviet missions during the U.S. turn
if (!(MAIL_PLAYER == 0 && i == MAIL_OPPONENT)) {
if (!((MAIL == 0 && i == 1) || (MAIL == 3 && i == 0))) {
if (Data->P[i].Mission[j].MissionCode
&& Data->P[i].Mission[j].part != 1) {
Order[k].plr = i;
Expand Down
9 changes: 9 additions & 0 deletions src/game/news.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,16 @@ News(char plr)
void
AIEvent(char plr)
{
int turn = 2 * (Data->Year - 57) + Data->Season + 1; // start at turn 1
bool freshNews = (turn > Data->P[plr].eCount);

ResolveEvent(plr);

// Do not update event counter when loading saved game
if (freshNews) {
Data->P[plr].eCount++;
assert(Data->P[plr].eCount < MAX_NEWS_ITEMS / 2);
}
}

// ResolveEvent seems to set a flag in the BadCard array
Expand Down
Loading