Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#include "GameLogic/ScriptEngine.h"
#include "GameLogic/SidesList.h"

static Bool g_isLegacyCounter[ScriptEngine::MAX_COUNTERS];
static Bool g_cachedLegacyFrameAdvanced = FALSE;

// These are for debugger window
static int st_LastCurrentFrame;
Expand Down Expand Up @@ -5298,6 +5300,7 @@ void ScriptEngine::reset(void)
m_counters[i].value = 0;
m_counters[i].isCountdownTimer = false;
m_counters[i].name.clear();
g_isLegacyCounter[i] = FALSE;
}
for (i = 0; i < MAX_FLAGS; i++) {
m_flags[i].value = false;
Expand Down Expand Up @@ -5440,6 +5443,7 @@ void ScriptEngine::newMap(void)
m_counters[i].value = 0;
m_counters[i].isCountdownTimer = false;
m_counters[i].name.clear();
g_isLegacyCounter[i] = FALSE;
}
m_numFlags = 1;
for (i = 0; i < MAX_FLAGS; i++) {
Expand Down Expand Up @@ -5523,12 +5527,10 @@ void ScriptEngine::update(void)
*/
#endif
#endif

const bool legacyFrameAdvanced = TheGameLogic->HasLegacyFrameAdvanced();
g_cachedLegacyFrameAdvanced = legacyFrameAdvanced;

#if defined(GENERALS_ONLINE_HIGH_FPS_SERVER)
if (!m_firstUpdate && !TheGameLogic->HasLegacyFrameAdvanced()) {
return;
}
#endif
if (m_firstUpdate) {
createNamedCache();
particleEditorUpdate();
Expand All @@ -5539,13 +5541,17 @@ void ScriptEngine::update(void)
}

if (m_closeWindowTimer > 0) {
if (legacyFrameAdvanced) {
m_closeWindowTimer--;
}
if (m_closeWindowTimer < 1) {
TheScriptActions->closeWindows(FALSE); // Close victory or defeat windows.
}
}
if (m_endGameTimer > 0) {
if (legacyFrameAdvanced) {
m_endGameTimer--;
}
if (m_endGameTimer < 1) {
TheGameLogic->exitGame();
//TheScriptActions->closeWindows(FALSE); // Close victory or defeat windows.
Expand Down Expand Up @@ -5578,7 +5584,9 @@ void ScriptEngine::update(void)
if (m_counters[i].isCountdownTimer) {
// If counter has any time left, decrement. Counters go to -1 and stop.
if (m_counters[i].value >= 0) {
m_counters[i].value--;
if (legacyFrameAdvanced) {
m_counters[i].value--;
}
}
}
}
Expand Down Expand Up @@ -6406,7 +6414,13 @@ void ScriptEngine::setCounter(ScriptAction* pAction)
pAction->getParameter(0)->friend_setInt(counterNdx);
}
Int value = pAction->getParameter(1)->getInt();
m_counters[counterNdx].value = value;
if (g_isLegacyCounter[counterNdx]) {
if (g_cachedLegacyFrameAdvanced) {
m_counters[counterNdx].value = value;
}
} else {
m_counters[counterNdx].value = value;
}
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -6474,7 +6488,13 @@ void ScriptEngine::addCounter(ScriptAction* pAction)
counterNdx = allocateCounter(pAction->getParameter(1)->getString());
pAction->getParameter(1)->friend_setInt(counterNdx);
}
m_counters[counterNdx].value += value;
if (g_isLegacyCounter[counterNdx]) {
if (g_cachedLegacyFrameAdvanced) {
m_counters[counterNdx].value += value;
}
} else {
m_counters[counterNdx].value += value;
}
}

//-------------------------------------------------------------------------------------------------
Expand All @@ -6489,7 +6509,13 @@ void ScriptEngine::subCounter(ScriptAction* pAction)
counterNdx = allocateCounter(pAction->getParameter(1)->getString());
pAction->getParameter(1)->friend_setInt(counterNdx);
}
m_counters[counterNdx].value -= value;
if (g_isLegacyCounter[counterNdx]) {
if (g_cachedLegacyFrameAdvanced) {
m_counters[counterNdx].value -= value;
}
} else {
m_counters[counterNdx].value -= value;
}
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -6802,6 +6828,7 @@ void ScriptEngine::setTimer(ScriptAction* pAction, Bool millisecondTimer, Bool r
m_counters[counterNdx].value = value;
}
m_counters[counterNdx].isCountdownTimer = true;
g_isLegacyCounter[counterNdx] = TRUE;
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -6831,6 +6858,7 @@ void ScriptEngine::restartTimer(ScriptAction* pAction)
}
if (m_counters[counterNdx].value > 0) {
m_counters[counterNdx].isCountdownTimer = true;
g_isLegacyCounter[counterNdx] = TRUE;
}
}

Expand All @@ -6839,24 +6867,46 @@ void ScriptEngine::restartTimer(ScriptAction* pAction)
//-------------------------------------------------------------------------------------------------
void ScriptEngine::adjustTimer(ScriptAction* pAction, Bool millisecondTimer, Bool add)
{
DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 2, ("Not enough parameters."));
Int counterNdx = pAction->getParameter(1)->getInt();
if (counterNdx == 0) {
counterNdx = allocateCounter(pAction->getParameter(1)->getString());
pAction->getParameter(1)->friend_setInt(counterNdx);
}
if (millisecondTimer) {
Real value = pAction->getParameter(0)->getReal();
if (!add)
value = -value;
m_counters[counterNdx].value += REAL_TO_INT_CEIL(ConvertDurationFromMsecsToFrames(value * 1000));
}
else {
Int value = pAction->getParameter(0)->getInt();
if (!add)
value = -value;
m_counters[counterNdx].value += value;
}
DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 2, ("Not enough parameters."));
Int counterNdx = pAction->getParameter(1)->getInt();
if (counterNdx == 0) {
counterNdx = allocateCounter(pAction->getParameter(1)->getString());
pAction->getParameter(1)->friend_setInt(counterNdx);
}

if (millisecondTimer) {
Real value = pAction->getParameter(0)->getReal();
if (!add)
value = -value;

#if defined(GENERALS_ONLINE_HIGH_FPS_SERVER)
const int LEGACY_FPS_INT = BaseFps;
Int delta = REAL_TO_INT_CEIL(value * (Real)LEGACY_FPS_INT);
#else
Int delta = REAL_TO_INT_CEIL(ConvertDurationFromMsecsToFrames(value * 1000));
#endif

if (g_isLegacyCounter[counterNdx]) {
if (g_cachedLegacyFrameAdvanced) {
m_counters[counterNdx].value += delta;
}
} else {
m_counters[counterNdx].value += delta;
}
}
else {
Int value = pAction->getParameter(0)->getInt();
if (!add)
value = -value;

if (g_isLegacyCounter[counterNdx]) {
if (g_cachedLegacyFrameAdvanced) {
m_counters[counterNdx].value += value;
}
} else {
m_counters[counterNdx].value += value;
}
}
}

//-------------------------------------------------------------------------------------------------
Expand Down
Loading