Skip to content

Commit bb8e284

Browse files
committed
add options menu
fix #98 (we now replicate amiga and dos behavior depending on version for the in game map visible tiles)
1 parent f2b283a commit bb8e284

14 files changed

Lines changed: 549 additions & 172 deletions

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ set(CMAKE_CXX_STANDARD 14)
1515
option(OPENFODDER_ENABLE_FFMPEG "Enable FFmpeg intro video playback" OFF)
1616
option(OPENFODDER_AUTO_FFMPEG "Auto-enable FFmpeg when found (non-Windows)" ON)
1717

18+
if(MSVC)
19+
# Enable Hot Reload (Edit and Continue) for Debug builds.
20+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<CONFIG:Debug>,EditAndContinue,ProgramDatabase>")
21+
add_compile_options($<$<CONFIG:Debug>:/ZI>)
22+
add_link_options($<$<CONFIG:Debug>:/INCREMENTAL>)
23+
endif()
24+
1825
if(EMSCRIPTEN)
1926
set(OPENFODDER_EMSCRIPTEN ON)
2027
else()

Source/Briefing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,10 @@ void cFodder::Briefing_Intro_Helicopter_Play(const bool pShowHelicopter, eTileTy
505505
return;
506506

507507
mSurface->clearBuffer();
508-
mWindow->SetScreenSize(mVersionCurrent->GetScreenSize());
508+
mWindow->SetScreenSize(mVersionCurrent->GetScreenSize());
509509

510510
if (pTileset >= eTileTypes_Hid)
511-
pTileset = eTileTypes_Jungle;
511+
pTileset = eTileTypes_Jungle;
512512

513513
mGraphics->Mission_Intro_Load_Resources(pTileset);
514514
mGraphics->SetActiveSpriteSheet(eGFX_BRIEFING);
@@ -520,7 +520,7 @@ void cFodder::Briefing_Intro_Helicopter_Play(const bool pShowHelicopter, eTileTy
520520
//Briefing_Intro_Helicopter_Draw_Mission_Name();
521521
mSurface->Save();
522522

523-
// Prior to mission 4, the UFO is not shown on the mission intro
523+
// Prior to mission 4, the UFO is not shown on the mission intro
524524
bool ShowHelicopter = true;
525525
if (mVersionCurrent->isCannonFodder2() && mGame_Data.mMission_Number < 4 && !pShowHelicopter)
526526
ShowHelicopter = false;

Source/Camera.cpp

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ void cFodder::Camera_Speed_Calculate()
288288

289289
// loc_11B9C
290290
// Calculate maximum right position of camera
291-
Data0 = mMapLoaded->getWidthPixels() - getCameraWidth();
291+
const int32 originXPixels = (int32)getMapVisibleOriginX() << 4;
292+
Data0 = originXPixels + getMapVisibleWidthPixels() - getCameraWidth();
292293
Data0 = (Data0 << 16) | (Data0 >> 16);
293294

294295
int32 Data4 = mCameraX + mCamera_Speed_X;
@@ -298,7 +299,8 @@ void cFodder::Camera_Speed_Calculate()
298299
mCamera_Speed_X = Data0;
299300
}
300301
// loc_11BE8
301-
Data0 = mMapLoaded->getHeightPixels() - getCameraHeight();
302+
const int32 originYPixels = (int32)getMapVisibleOriginY() << 4;
303+
Data0 = originYPixels + getMapVisibleHeightPixels() - getCameraHeight();
302304
Data0 = (Data0 << 16) | (Data0 >> 16);
303305

304306
Data4 = mCameraY + mCamera_Speed_Y;
@@ -353,23 +355,30 @@ void cFodder::Camera_SetTargetToStartPosition()
353355
int16 Data0 = mCameraX >> 16;
354356
int16 Data4 = mCameraY >> 16;
355357

358+
const int16 originXPixels = (int16)getMapVisibleOriginX() << 4;
359+
const int16 originYPixels = (int16)getMapVisibleOriginY() << 4;
360+
356361
int16 Data8 = mCamera_StartPosition_X;
357362
Data8 -= (getCameraWidth() / 2) - 8;
358-
if (Data8 < 0)
359-
Data8 = 0;
363+
if (Data8 < originXPixels)
364+
Data8 = originXPixels;
360365

361-
int16 Data10 = mMapLoaded->getWidthPixels();
366+
int16 Data10 = originXPixels + (int16)getMapVisibleWidthPixels();
362367
Data10 -= (getCameraWidth() / 2) - 8;
368+
if (Data10 < originXPixels)
369+
Data10 = originXPixels;
363370
if (Data8 >= Data10)
364371
Data8 = Data10;
365372

366373
int16 DataC = mCamera_StartPosition_Y;
367374
DataC -= (getCameraHeight() - 8) / 2;
368-
if (DataC < 0)
369-
DataC = 0;
375+
if (DataC < originYPixels)
376+
DataC = originYPixels;
370377

371-
Data10 = mMapLoaded->getHeightPixels();
378+
Data10 = originYPixels + (int16)getMapVisibleHeightPixels();
372379
Data10 -= (getCameraHeight() - 8) / 2;
380+
if (Data10 < originYPixels)
381+
Data10 = originYPixels;
373382
if (DataC >= Data10)
374383
DataC = Data10;
375384

@@ -465,21 +474,31 @@ void cFodder::Camera_Pan_ComputeSpeed()
465474

466475
Data4 >>= 4;
467476

468-
int16 Data8 = mMapLoaded->getWidth();
469-
Data8 -= (getCameraWidth() >> 4) + 1;
477+
int16 MinTileX = getMapVisibleOriginX();
478+
int16 MinTileY = getMapVisibleOriginY();
479+
480+
int16 Data8 = getMapVisibleOriginX() + getMapVisibleWidth();
481+
const int16 cameraTiles = (getCameraWidth() >> 4);
482+
const int16 rightPadding = isAmigaMapBounds() ? 0 : 1;
483+
Data8 -= cameraTiles + rightPadding;
470484

471-
if (Data8 < 0)
472-
Data8 = 0;
485+
if (Data8 < MinTileX)
486+
Data8 = MinTileX;
473487

474-
if (Data0 >= Data8)
488+
if (Data0 < MinTileX)
489+
Data0 = MinTileX;
490+
if (Data0 > Data8)
475491
Data0 = Data8;
476492

477-
Data8 = mMapLoaded->getHeight();
478-
Data8 -= (getCameraHeight() + 32) >> 4;
479-
if (Data8 < 0)
480-
Data8 = 0;
493+
Data8 = getMapVisibleOriginY() + getMapVisibleHeight();
494+
const int16 yPadPixels = isAmigaMapBounds() ? 16 : 32;
495+
Data8 -= (getCameraHeight() + yPadPixels) >> 4;
496+
if (Data8 < MinTileY)
497+
Data8 = MinTileY;
481498

482-
if (Data4 >= Data8)
499+
if (Data4 < MinTileY)
500+
Data4 = MinTileY;
501+
if (Data4 > Data8)
483502
Data4 = Data8;
484503

485504
Data8 = mCameraX >> 16;
@@ -554,15 +573,13 @@ void cFodder::Camera_TileSpeedX_Set()
554573
mCamera_TileSpeed_Overflow = 0;
555574

556575
int32 dword_39F5A = mCameraX;
576+
const int32 minCameraX = ((int32)getMapVisibleOriginX() << 4) << 16;
557577

558578
mCameraX += mCamera_Speed_X;
559-
if (mCameraX < 0)
579+
if (mCameraX < minCameraX)
560580
{
561-
mCamera_Speed_X = dword_39F5A;
562-
if (mCamera_Speed_X)
563-
mCamera_Speed_X = -mCamera_Speed_X;
564-
565-
mCameraX = 0;
581+
mCamera_Speed_X = 0;
582+
mCameraX = minCameraX;
566583
}
567584
// loc_12147
568585
mCamera_TileSpeedX += mCamera_Speed_X;
@@ -596,16 +613,13 @@ void cFodder::Camera_TileSpeedY_Set()
596613
{
597614

598615
int32 dword_39F5A = mCameraY;
616+
const int32 minCameraY = ((int32)getMapVisibleOriginY() << 4) << 16;
599617

600618
mCameraY += mCamera_Speed_Y;
601-
if (mCameraY < 0)
619+
if (mCameraY < minCameraY)
602620
{
603-
mCamera_Speed_Y = dword_39F5A;
604-
605-
if (mCamera_Speed_Y)
606-
mCamera_Speed_Y = -mCamera_Speed_Y;
607-
608-
mCameraY = 0;
621+
mCamera_Speed_Y = 0;
622+
mCameraY = minCameraY;
609623
}
610624

611625
// loc_121F2

Source/CampaignSelect.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ void cFodder::Campaign_Select_DrawMenu(const char* pTitle, const char* pSubTitle
103103
GUI_Button_Draw_SmallAt("ABOUT", 0xA, 0xB3 + YOffset);
104104
GUI_Button_Setup(&cFodder::GUI_Button_Show_About);
105105

106+
GUI_Button_Draw_SmallAt("OPTIONS", 0xA, 0x9C + YOffset);
107+
GUI_Button_Setup(&cFodder::GUI_Button_Show_Options);
108+
106109

107110
int16 ItemCount = 0;
108111

@@ -432,6 +435,15 @@ void cFodder::Campaign_Select_File_Cycle(const char* pTitle, const char* pSubTit
432435
if (mMouse_Button_Left_Toggle)
433436
GUI_Handle_Element_Mouse_Check(mGUI_Elements);
434437

438+
if (mGUI_SaveLoadAction == 5) {
439+
Options_Menu_Run();
440+
mGUI_SaveLoadAction = 0;
441+
mMouse_Button_Left_Toggle = 0;
442+
mGraphics->PaletteSet();
443+
mSurface->palette_FadeTowardNew();
444+
mSurface->Save();
445+
}
446+
435447
GUI_Button_Load_MouseWheel();
436448
}
437449

Source/Fodder.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,13 +2132,19 @@ void cFodder::keyProcess(uint8 pKeyCode, bool pPressed)
21322132
}
21332133

21342134
if ((pKeyCode == SDL_SCANCODE_EQUALS && pPressed) || (pKeyCode == SDL_SCANCODE_KP_PLUS && pPressed))
2135+
{
21352136
mWindow->WindowIncrease();
2137+
}
21362138

21372139
if ((pKeyCode == SDL_SCANCODE_MINUS && pPressed) || (pKeyCode == SDL_SCANCODE_KP_MINUS && pPressed))
2140+
{
21382141
mWindow->WindowDecrease();
2142+
}
21392143

21402144
if (pKeyCode == SDL_SCANCODE_F11 && pPressed)
2145+
{
21412146
mWindow->ToggleFullscreen();
2147+
}
21422148

21432149
if (pKeyCode == SDL_SCANCODE_F12 && pPressed)
21442150
{
@@ -2392,7 +2398,6 @@ cDimension cFodder::getSurfaceSize() const
23922398

23932399
cDimension cFodder::getWindowSize() const
23942400
{
2395-
23962401
if (!mParams->mWindowColumns || !mParams->mWindowRows)
23972402
{
23982403
if (mVersionCurrent)
@@ -2425,6 +2430,65 @@ int16 cFodder::getWindowColumns() const
24252430
return (int16)mParams->mWindowColumns;
24262431
}
24272432

2433+
bool cFodder::isAmigaMapBounds() const
2434+
{
2435+
return mVersionCurrent && mVersionCurrent->isAmiga();
2436+
}
2437+
2438+
int16 cFodder::getMapVisibleOriginX() const
2439+
{
2440+
if (isAmigaMapBounds())
2441+
return 1;
2442+
return 0;
2443+
}
2444+
2445+
int16 cFodder::getMapVisibleOriginY() const
2446+
{
2447+
return 0;
2448+
}
2449+
2450+
int16 cFodder::getMapVisibleWidth() const
2451+
{
2452+
if (!mMapLoaded)
2453+
return 0;
2454+
2455+
int16 width = static_cast<int16>(mMapLoaded->getWidth());
2456+
if (isAmigaMapBounds())
2457+
{
2458+
width -= 2;
2459+
if (width < 0)
2460+
width = 0;
2461+
}
2462+
return width;
2463+
}
2464+
2465+
int16 cFodder::getMapVisibleHeight() const
2466+
{
2467+
if (!mMapLoaded)
2468+
return 0;
2469+
2470+
int16 height = static_cast<int16>(mMapLoaded->getHeight());
2471+
if (isAmigaMapBounds())
2472+
{
2473+
const int16 cameraTiles = (getCameraHeight() >> 4);
2474+
if (height == cameraTiles + 1)
2475+
height -= 1;
2476+
if (height < 0)
2477+
height = 0;
2478+
}
2479+
return height;
2480+
}
2481+
2482+
int32 cFodder::getMapVisibleWidthPixels() const
2483+
{
2484+
return (int32)getMapVisibleWidth() << 4;
2485+
}
2486+
2487+
int32 cFodder::getMapVisibleHeightPixels() const
2488+
{
2489+
return (int32)getMapVisibleHeight() << 4;
2490+
}
2491+
24282492
void cFodder::DataNotFound()
24292493
{
24302494
g_Debugger->Error("No game data could be found, including the demos, have you installed the data pack?");

Source/Fodder.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class cFodder {
9393
bool mSoundDisabled;
9494

9595
bool mVersionPlatformSwitchDisabled;
96+
9697
const sGameVersion* mVersionDefault; // Version to switch back to when looking for data
9798
const sGameVersion* mVersionCurrent; // Version currently being used
9899
bool mVersionReturnAfterPhase; // Return to default data after phase
@@ -1171,6 +1172,7 @@ class cFodder {
11711172
void GUI_Button_Load_Down();
11721173
void GUI_Button_Load_Exit();
11731174
void GUI_Button_Show_About();
1175+
void GUI_Button_Show_Options();
11741176
void GUI_Button_Filename();
11751177

11761178
int16 GUI_Button_NoAction();
@@ -1386,6 +1388,13 @@ class cFodder {
13861388

13871389
int16 getWindowRows() const;
13881390
int16 getWindowColumns() const;
1391+
bool isAmigaMapBounds() const;
1392+
int16 getMapVisibleOriginX() const;
1393+
int16 getMapVisibleOriginY() const;
1394+
int16 getMapVisibleWidth() const;
1395+
int16 getMapVisibleHeight() const;
1396+
int32 getMapVisibleWidthPixels() const;
1397+
int32 getMapVisibleHeightPixels() const;
13891398

13901399
int16 getCameraWidth() const;
13911400
int16 getCameraHeight() const;

Source/GUI_Element.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,12 @@ void cFodder::GUI_Button_Show_About()
14071407
mGUI_SaveLoadAction = 4;
14081408
}
14091409

1410+
void cFodder::GUI_Button_Show_Options()
1411+
{
1412+
mGUI_Select_File_String_Input_Callback = 0;
1413+
mGUI_SaveLoadAction = 5;
1414+
}
1415+
14101416
void cFodder::GUI_Input_CheckKey()
14111417
{
14121418

Source/Intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void cFodder::Intro_PlayVideo() {
267267
return;
268268
}
269269

270-
if (mStartParams && mStartParams->mDisableVideo)
270+
if (mStartParams && (mStartParams->mDisableVideo || mStartParams->mDisableIntroVideo))
271271
return;
272272
#ifdef OPENFODDER_ENABLE_FFMPEG
273273
cVideoMPEG introVideo;

0 commit comments

Comments
 (0)