Skip to content

Commit

Permalink
enums and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
qndel authored and AJenbo committed Oct 22, 2020
1 parent fb81425 commit e31a7bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
16 changes: 8 additions & 8 deletions Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ BOOL msg_wait_resync()
return FALSE;
}

if (sgbDeltaChunks != 21) {
if (sgbDeltaChunks != MAX_CHUNKS) {
DrawDlg("Unable to get level data");
msg_free_packets();
return FALSE;
Expand All @@ -115,9 +115,9 @@ int msg_wait_for_turns()
BOOL received;
DWORD turns;

if (!sgbDeltaChunks) {
if (sgbDeltaChunks == 0) {
nthread_send_and_recv_turn(0, 0);
if (!SNetGetOwnerTurnsWaiting(&turns) && SErrGetLastError() == STORM_ERROR_NOT_IN_GAME)
if (!SNetGetOwnerTurnsWaiting(&turns) && DERROR() == STORM_ERROR_NOT_IN_GAME)
return 100;
if (GetTickCount() - sgdwOwnerWait <= 2000 && turns < gdwTurnsInTransit)
return 0;
Expand All @@ -136,11 +136,11 @@ int msg_wait_for_turns()
gbDeltaSender = myplr;
nthread_set_turn_upper_bit();
}
if (sgbDeltaChunks == 20) {
sgbDeltaChunks = 21;
if (sgbDeltaChunks == MAX_CHUNKS - 1) {
sgbDeltaChunks = MAX_CHUNKS;
return 99;
}
return 100 * sgbDeltaChunks / 21;
return 100 * sgbDeltaChunks / MAX_CHUNKS;
}

void run_delta_info()
Expand Down Expand Up @@ -1193,7 +1193,7 @@ DWORD On_DLEVEL(int pnum, TCmd *pCmd)
}
if (sgbRecvCmd == CMD_DLEVEL_END) {
if (p->bCmd == CMD_DLEVEL_END) {
sgbDeltaChunks = 20;
sgbDeltaChunks = MAX_CHUNKS - 1;
return p->wBytes + sizeof(*p);
} else if (p->bCmd == CMD_DLEVEL_0 && p->wOffset == 0) {
sgdwRecvOffset = 0;
Expand All @@ -1204,7 +1204,7 @@ DWORD On_DLEVEL(int pnum, TCmd *pCmd)
} else if (sgbRecvCmd != p->bCmd) {
DeltaImportData(sgbRecvCmd, sgdwRecvOffset);
if (p->bCmd == CMD_DLEVEL_END) {
sgbDeltaChunks = 20;
sgbDeltaChunks = MAX_CHUNKS - 1;
sgbRecvCmd = CMD_DLEVEL_END;
return p->wBytes + sizeof(*p);
} else {
Expand Down
12 changes: 2 additions & 10 deletions Source/nthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ void nthread_terminate_game(const char *pszFcn)
{
DWORD sErr;

#ifdef HELLFIRE
sErr = GetLastError();
#else
sErr = SErrGetLastError();
#endif
sErr = DERROR();
if (sErr == STORM_ERROR_INVALID_PLAYER) {
return;
} else if (sErr == STORM_ERROR_GAME_TERMINATED) {
Expand Down Expand Up @@ -92,11 +88,7 @@ BOOL nthread_recv_turns(BOOL *pfSendAsync)
return TRUE;
}
if (!SNetReceiveTurns(0, MAX_PLRS, (char **)glpMsgTbl, gdwMsgLenTbl, (LPDWORD)player_state)) {
#ifdef HELLFIRE
if (GetLastError() != STORM_ERROR_NO_MESSAGES_WAITING)
#else
if (SErrGetLastError() != STORM_ERROR_NO_MESSAGES_WAITING)
#endif
if (DERROR() != STORM_ERROR_NO_MESSAGES_WAITING)
nthread_terminate_game("SNetReceiveTurns");
sgbTicsOutOfSync = FALSE;
sgbSyncCountdown = 1;
Expand Down
7 changes: 1 addition & 6 deletions Source/wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ BOOL WOpenFile(const char *FileName, HANDLE *phsFile, BOOL mayNotExist)
while (1) {
if (SFileOpenFile(FileName, phsFile))
return TRUE;
#ifdef HELLFIRE
if (mayNotExist && GetLastError() == ERROR_FILE_NOT_FOUND)
if (mayNotExist && DERROR() == ERROR_FILE_NOT_FOUND)
break;
#else
if (mayNotExist && SErrGetLastError() == ERROR_FILE_NOT_FOUND)
break;
#endif
WGetFileArchive(NULL, &retry, FileName);
}
return FALSE;
Expand Down
12 changes: 7 additions & 5 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#ifdef HELLFIRE
#define HFAND &&
#define DERROR GetLastError
#else
#define HFAND &
#define DERROR SErrGetLastError
#endif

#define DMAXX 40
Expand All @@ -35,17 +37,17 @@
#ifdef HELLFIRE
#define MAX_LVLS 24
#define MAX_LVLMTYPES 24
#define MAX_SPELLS 52
#else
#define MAX_LVLS 16
#define MAX_LVLMTYPES 16
#define MAX_SPELLS 37
#endif

#define MAX_CHUNKS (MAX_LVLS + 5)

// #define MAX_PATH 260
#define MAX_SEND_STR_LEN 80
#ifdef HELLFIRE
#define MAX_SPELLS 52
#else
#define MAX_SPELLS 37
#endif

#define MAXDEAD 31
#define MAXDUNX 112
Expand Down

0 comments on commit e31a7bc

Please sign in to comment.