├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .gitmodules ├── .travis.yml ├── BUGS.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── COPYING ├── COPYING.BSD.txt ├── COPYING.LGPLv2.1.txt ├── COPYING.MIT.txt ├── COPYING.ZLIB.txt ├── EMakefile ├── FreeDesktop ├── openfodder.appdata.xml ├── openfodder.desktop └── openfodder.png ├── IDEAS.md ├── INSTALL.md ├── Makefile ├── Projects ├── OpenFodder.aps ├── OpenFodder.rc ├── VS2015 │ ├── OpenFodder.sln │ ├── OpenFodder.vcxproj │ ├── OpenFodder.vcxproj.filters │ ├── OpenFodder.vcxproj.user │ ├── gitver.cmd │ └── packages.config ├── VS2017 │ ├── OpenFodder.sln │ ├── OpenFodder.vcxproj │ ├── OpenFodder.vcxproj.filters │ ├── OpenFodder.vcxproj.user │ ├── gitver.cmd │ ├── openfodder.ini │ └── packages.config ├── WinInstaller │ ├── build.cmd │ ├── installer.nsi │ └── openfodder.ini ├── emscripten │ ├── build_emscripten.cmd │ ├── httpd.conf │ └── openfodder.ini ├── openfodder.ico └── resource.h ├── README.md ├── Source ├── .gitignore ├── About.cpp ├── About.hpp ├── Amiga │ ├── Graphics_Amiga.cpp │ ├── Graphics_Amiga.hpp │ ├── Graphics_Amiga2.cpp │ ├── Graphics_Amiga2.hpp │ ├── IntroData_Amiga.cpp │ ├── Resource_Amiga_File.cpp │ ├── Resource_Amiga_File.hpp │ ├── Sound_Amiga.cpp │ ├── Sound_Amiga.hpp │ ├── SpriteData_Amiga.hpp │ ├── audiostream.hpp │ ├── dernc.cpp │ ├── dernc.hpp │ ├── paula.cpp │ ├── paula.hpp │ ├── rjp1.cpp │ └── rjp1.hpp ├── Campaign.cpp ├── Campaign.hpp ├── CopyProtection.cpp ├── CopyProtection.hpp ├── Debugger.cpp ├── Debugger.hpp ├── Dimension.hpp ├── Event.cpp ├── Event.hpp ├── Fodder.cpp ├── Fodder.hpp ├── FontData.cpp ├── FontData.hpp ├── GUI_Element.cpp ├── GUI_Element.hpp ├── GameData.cpp ├── GameData.hpp ├── Graphics.cpp ├── Graphics.hpp ├── IntroData.hpp ├── Map │ ├── Map.cpp │ ├── Map.hpp │ ├── Original.cpp │ ├── Original.hpp │ ├── Random.cpp │ └── Random.hpp ├── MapData.cpp ├── PC │ ├── Graphics_PC.cpp │ ├── Graphics_PC.hpp │ ├── IntroData_PC.cpp │ ├── Resource_PC_CD.cpp │ ├── Resource_PC_CD.hpp │ ├── Sound_PC.cpp │ ├── Sound_PC.hpp │ ├── Sound_PC2.cpp │ ├── Sound_PC2.hpp │ ├── SpriteData_PC.hpp │ └── VocTable.hpp ├── Parameters.cpp ├── Parameters.hpp ├── Position.hpp ├── Recruits.cpp ├── Recruits.hpp ├── ResourceMan.cpp ├── ResourceMan.hpp ├── Resources.cpp ├── Resources.hpp ├── ScriptingEngine.cpp ├── ScriptingEngine.hpp ├── Sound.cpp ├── Sound.hpp ├── SpriteSheet.cpp ├── SpriteSheet.hpp ├── Sprites.cpp ├── Sprites.hpp ├── Start.cpp ├── Start_Emscripten.cpp ├── Structures │ ├── Barracks.cpp │ └── Barracks.hpp ├── Surface.cpp ├── Surface.hpp ├── Tiles.cpp ├── Tiles.hpp ├── Types.hpp ├── UnitTesting.cpp ├── UnitTesting.hpp ├── Utils │ ├── SimplexIslands.cpp │ ├── SimplexIslands.hpp │ ├── SimplexNoise.cpp │ ├── SimplexNoise.hpp │ ├── cxxopts.hpp │ ├── diamondsquare.hpp │ ├── duk_config.h │ ├── duk_trans_socket.h │ ├── duk_trans_socket_unix.c │ ├── duk_trans_socket_windows.cpp │ ├── dukglue │ │ ├── detail_class_proto.h │ │ ├── detail_constructor.h │ │ ├── detail_function.h │ │ ├── detail_method.h │ │ ├── detail_primitive_types.h │ │ ├── detail_refs.h │ │ ├── detail_stack.h │ │ ├── detail_traits.h │ │ ├── detail_typeinfo.h │ │ ├── detail_types.h │ │ ├── dukexception.h │ │ ├── dukglue.h │ │ ├── dukvalue.h │ │ ├── public_util.h │ │ ├── register_class.h │ │ ├── register_function.h │ │ └── register_property.h │ ├── duktape.cpp │ ├── duktape.h │ ├── ini.hpp │ ├── json.hpp │ ├── md5.cpp │ ├── md5.hpp │ ├── micropather.cpp │ ├── micropather.h │ ├── pseudorand.hpp │ └── stb_image.h ├── Version.hpp ├── Versions.cpp ├── Versions.hpp ├── Versions_Files.hpp ├── Window.cpp ├── Window.hpp ├── stdafx.cpp └── stdafx.hpp ├── cmake ├── FindSDL2.cmake ├── FindSDL2Mixer.cmake └── gitver.hpp.in └── openfodder.ini.example /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.cmd text eol=crlf 4 | *.sln text eol=crlf 5 | *.vcxproj text eol=crlf 6 | 7 | *.props text eol=crlf 8 | *.filters text eol=crlf 9 | *.user text eol=crlf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - OS: [e.g. Windows] 25 | - Version [e.g. 10] 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Run"] 2 | path = Run 3 | url = https://github.com/OpenFodder/data 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | dist: bionic 4 | sudo: required 5 | 6 | compiler: 7 | - clang 8 | 9 | before_install: 10 | - sudo apt-get update 11 | - sudo apt-get install libsdl2-dev libsdl2-mixer-dev libegl1-mesa-dev libgles2-mesa-dev 12 | 13 | before_script: mkdir obj 14 | script: 15 | - make 16 | - cd Run 17 | - git clone --depth=50 https://github.com/OpenFodder/tests.git Tests 18 | - ./OpenFodder --unit-test-headless -------------------------------------------------------------------------------- /BUGS.md: -------------------------------------------------------------------------------- 1 | # Cannon Fodder Original Engine Bugs 2 | 3 | Issues in the original engine which have been fixed (unfortunately this list is not complete, as some bugs have been fixed and forgotten) 4 | 5 | * The second and third squad grenade and rocket count did not refresh after using either weapon 6 | 7 | * If the mouse was kept in the sidebar while changing squads, the camera would get stuck in a back and forth pattern 8 | 9 | * Out of bounds memory accesses. Numerous code accessed past either the beginning or end of a few arrays. This was not really a noticable problem on the Amiga or in Dos but is on a modern OS with virtual memory (especially on dynamically allocated memory) 10 | 11 | * Having a grenade explode at the bottom right corner of a map would cause memory corruption after the map array 12 | 13 | * Soldier sprite frame numbers occasionally went out of range, leading to crashes or incorrect sprite rendering. This wasn’t an issue in the original, as the memory layout ensured an overflow into the next set of soldier frame data 14 | 15 | * During Sprite_Handle_Troop_Direct_TowardMouse, the sprite frame could become invalid if Sprite_Handle_Troop_Animation changed the animation type and the new type didn’t include the current frame number. 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10.0) 2 | 3 | if (POLICY CMP0025) 4 | cmake_policy(SET CMP0025 NEW) 5 | endif () 6 | 7 | if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 8 | message(STATUS "No build type selected, default to Release.") 9 | set(CMAKE_BUILD_TYPE "Release") 10 | endif() 11 | 12 | project(openfodder VERSION 1.5.4 LANGUAGES CXX) 13 | 14 | set(CMAKE_CXX_STANDARD 14) 15 | 16 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${openfodder_SOURCE_DIR}/cmake) 17 | 18 | find_package(SDL2 REQUIRED) 19 | find_package(SDL2Mixer REQUIRED) 20 | find_package(Threads REQUIRED) 21 | 22 | # Locate git binary to provide information to the build environment 23 | find_package(Git) 24 | 25 | if(GIT_FOUND) 26 | # Define short commit hash. 27 | execute_process( 28 | COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD 29 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 30 | OUTPUT_VARIABLE OPENFODDER_COMMIT_SHA1_SHORT 31 | OUTPUT_STRIP_TRAILING_WHITESPACE 32 | ERROR_QUIET 33 | ) 34 | else() 35 | # Fallback in case the git exe can't be found. 36 | set(OPENFODDER_COMMIT_SHA1_SHORT "deadbeef") 37 | endif() 38 | 39 | configure_file(cmake/gitver.hpp.in Source/gitver.hpp @ONLY) 40 | 41 | file(GLOB_RECURSE GAMEENGINE_HEADERS "Source/*.hpp") 42 | file(GLOB_RECURSE GAMEENGINE_SOURCE "Source/*.cpp") 43 | 44 | add_executable(openfodder ${GAMEENGINE_SOURCE} ${GAMEENGINE_HEADERS}) 45 | 46 | target_include_directories(openfodder PRIVATE 47 | Source 48 | ${CMAKE_CURRENT_BINARY_DIR}/Source) 49 | 50 | target_link_libraries(openfodder SDL2::SDL2 SDL2_mixer::SDL2_mixer Threads::Threads) 51 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for taking the time to consider contributing! 4 | 5 | Your first step should be to join us in the official [Discord](https://discord.gg/4mX2wFM) channel. 6 | -------------------------------------------------------------------------------- /COPYING.BSD.txt: -------------------------------------------------------------------------------- 1 | NOTE: Only certain parts of OpenFodder are under the BSD license. 2 | The majority of the files are under the GNU GPL3. See the headers of the 3 | individual files to find out the exact license. 4 | 5 | The term "BSD license" refers to any BSD-like license, as they are sometimes 6 | hard to tell apart. No slight against other licenses is intended. 7 | 8 | 9 | DE-RNC use the following license: 10 | 11 | Copyright (c) 2007, Alexander Gitter 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, 17 | this list of conditions and the following disclaimer. 18 | * Redistributions in binary form must reproduce the above copyright notice, 19 | this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution. 21 | * Neither the name of the author nor the names of the contributors may be 22 | used to endorse or promote products derived from this software without 23 | specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 29 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 32 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /COPYING.ZLIB.txt: -------------------------------------------------------------------------------- 1 | Copyright notice: 2 | 3 | (C) 1995-2004 Jean-loup Gailly and Mark Adler 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | Jean-loup Gailly Mark Adler 22 | jloup@gzip.org madler@alumni.caltech.edu 23 | 24 | If you use the zlib library in a product, we would appreciate *not* 25 | receiving lengthy legal documents to sign. The sources are provided 26 | for free but without warranty of any kind. The library has been 27 | entirely written by Jean-loup Gailly and Mark Adler; it does not 28 | include third-party code. 29 | 30 | If you redistribute modified sources, we would appreciate that you include 31 | in the file ChangeLog history information documenting your changes. Please 32 | read the FAQ for more information on the distribution of modified source 33 | versions. 34 | -------------------------------------------------------------------------------- /EMakefile: -------------------------------------------------------------------------------- 1 | 2 | pathInc = -I./Source/ 3 | Libs = -s USE_SDL=2 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_TRAP_MODE='clamp' 4 | DLibs = -s USE_SDL=2 5 | 6 | CC = em++ -Wall -std=c++0x -O3 -ferror-limit=100 $(pathInc) $(Libs) --no-heap-copy --preload-file Run@/ -o RunE/OpenFodder.html 7 | 8 | all : fodder 9 | 10 | fodder: main 11 | 12 | main: 13 | $(CC) Source/About.cpp Source/Structures/Barracks.cpp Source/Campaign.cpp Source/CopyProtection.cpp Source/Debugger.cpp Source/Amiga/dernc.cpp Source/Event.cpp Source/Fodder.cpp Source/FontData.cpp Source/GameData.cpp Source/Graphics.cpp Source/Amiga/Graphics_Amiga.cpp Source/Amiga/Graphics_Amiga2.cpp Source/PC/Graphics_PC.cpp Source/GUI_Element.cpp Source/Amiga/IntroData_Amiga.cpp Source/PC/IntroData_PC.cpp Source/Map.cpp Source/Utils/md5.cpp Source/Parameters.cpp Source/Amiga/paula.cpp Source/Recruits.cpp Source/Amiga/Resource_Amiga_File.cpp Source/PC/Resource_PC_CD.cpp Source/ResourceMan.cpp Source/Resources.cpp Source/Amiga/rjp1.cpp Source/Utils/SimplexNoise.cpp Source/Sound.cpp Source/Amiga/Sound_Amiga.cpp Source/PC/Sound_PC.cpp Source/PC/Sound_PC2.cpp Source/Sprites.cpp Source/SpriteSheet.cpp Source/Start_Emscripten.cpp Source/stdafx.cpp Source/Surface.cpp Source/Tiles.cpp Source/UnitTesting.cpp Source/Versions.cpp Source/Window.cpp 14 | # mv *.o obj -------------------------------------------------------------------------------- /FreeDesktop/openfodder.appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | openfodder.desktop 4 | CC0-1.0 5 | GPL-3.0 6 | OpenFodder 7 | An open-source port of the DOS shoot-em-up Tyrian. 8 | 9 |

Open Fodder is an open source version of the Cannon Fodder engine, for modern operating systems.

10 |

The game is military-themed and based on shooting action but with a strategy game-style control system. The player directs troops through numerous missions, battling enemy infantry, vehicles and installations.

11 |
12 | http://openfodder.com/ 13 | https://github.com/openfodder/openfodder/issues 14 | 15 | intense 16 | intense 17 | 18 | 19 | 20 | 21 | 22 | 23 | https://user-images.githubusercontent.com/1327406/49718991-f1bd6e00-fcaf-11e8-88e3-68136828c2d1.png 24 | 25 | 26 |
27 | -------------------------------------------------------------------------------- /FreeDesktop/openfodder.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Open Fodder 3 | GenericName=Action-Strategy Shoot 'em 4 | Comment=An open source port of Cannon Fodder 5 | Icon=openfodder 6 | Exec=openfodder 7 | Terminal=false 8 | Type=Application 9 | Categories=Game;ActionGame; 10 | -------------------------------------------------------------------------------- /FreeDesktop/openfodder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFodder/openfodder/0e0c5a26eb848ee1d3a0a0ed16b463020a38307c/FreeDesktop/openfodder.png -------------------------------------------------------------------------------- /IDEAS.md: -------------------------------------------------------------------------------- 1 | # Open Fodder future ideas 2 | 3 | Just a few ideas for potential future enhancements 4 | 5 | * Multiplayer mode 6 | ** Arena: Large maps with many players in a death match scenario (C&C Sole Survivor style??) 7 | ** Coop: Squads created ecah phase with split troops between each squad, each player controls a squad (upto max of 3 squads -- engine limit) 8 | 9 | * Campaign / Mission centre 10 | ** Download other players campaigns 11 | 12 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Open Fodder Installation instructions 2 | 3 | ## About 4 | 5 | Open Fodder requires campaign and mission information, as well as the data files from a retail release of Cannon Fodder. These files must be installed to certain locations depending on your operating system, please see the details below for instructions. 6 | 7 | 8 | ### OS Specific 9 | 10 | #### Windows 11 | 12 | Download the [installer package](https://github.com/OpenFodder/openfodder/releases). 13 | 14 | The Windows version of Open Fodder defaults to using and installing data to the location '%USERPROFILE%/Documents/OpenFodder'. 15 | While the demos will be installed as part of the Windows installer package, you will be required to copy a full retail release into this folder (following the instructions below, or when prompted to select it during the installer) 16 | 17 | 18 | #### Linux / Unix 19 | 20 | Open Fodder will check the environment variable $XDG_DATA_DIRS and iterate each path checking for the data folder "/OpenFodder/". 21 | Failure to locate the folder in these paths, will result in a check of $HOME/.local/share/OpenFodder. 22 | Failure on this path, will fall back to the current working directory. 23 | 24 | 25 | ## Data 26 | 27 | ### Campaign Data 28 | 29 | The campaign information was originally hardcoded in the executable, this is required to play and is downloadable alonside six demos from (https://github.com/OpenFodder/data/releases/download/1.6.0/Data.pack.1.6.0.zip). 30 | 31 | This data is packaged with the Windows Installer, but will be a required download if you're compiling / running on Linux/Unix. 32 | 33 | ### Retail Data 34 | 35 | #### Dos CD Version 36 | 37 | Copy 'CF_ENG.DAT' from the CD (or the GOG install destination) to the OpenFodder/Data/Dos_CD folder 38 | 39 | #### Amiga 40 | 41 | Please be aware, Cannon Fodder 2 is a typical AmigaDOS disk (SOS Unpacker will not work). Use an ADF tool on your machine, such as Directory Opus on Windows with the firy plugin (https://github.com/segrax/directory_opus_firy_plugin) 42 | 43 | ##### Option1. SOS Unpacker 44 | 45 | Use the [SOS Unpacker](https://github.com/OpenFodder/SOS_Unpacker) to unpack Kyroflux 'CT Raw' images of your Cannon Fodder disks, then copy the contents of 'out' into the OpenFodder/Data/Amiga directory. 46 | 47 | ##### Option2. WHDLoad 48 | 49 | Use the [WHDLoad installer](http://www.whdload.de/games/CannonFodder.html) on an Amiga or an emulator (WinUAE/UAE) to extract the game files from the original floppy disks, then copy the contents of 'cf_data' into the OpenFodder/Data/Amiga directory. 50 | 51 | 52 | #### Amiga CD32 53 | 54 | Copy the files from the 'Fodder' folder on the CD-Rom, to the OpenFodder/Data/Amiga_CD folder. For the final video, Extract Track2 from the CD and name it 'Track2.mpg', placed in the Amiga_CD folder. 55 | 56 | * Please note: The video playback is not yet supported 57 | 58 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | pathInc = -I/usr/include/directfb/direct -I/usr/include/directfb -I./Source/ 3 | Libs = `sdl2-config --cflags` 4 | DLibs = `sdl2-config --libs` -L/usr/local/lib -lSDL2_mixer 5 | 6 | CC = clang++ $(CXXFLAGS) -c -Wall -std=c++14 -ferror-limit=100 $(pathInc) $(Libs) 7 | LD = clang++ $(LDFLAGS) obj/*.o -lpthread $(DLibs) 8 | 9 | all : fodder 10 | 11 | fodder: main 12 | mv *.o obj/ 13 | $(LD) -o Run/OpenFodder 14 | 15 | main: 16 | git log -n 1 --pretty="const char* gitversion=\"%h\";" > ./Source/gitver.hpp 17 | $(CC) Source/*.cpp Source/PC/*.cpp Source/Amiga/*.cpp Source/Structures/*.cpp Source/Utils/*.cpp Source/Map/*.cpp 18 | mkdir -p obj 19 | 20 | clean: 21 | rm obj/*.o 22 | 23 | 24 | -------------------------------------------------------------------------------- /Projects/OpenFodder.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFodder/openfodder/0e0c5a26eb848ee1d3a0a0ed16b463020a38307c/Projects/OpenFodder.aps -------------------------------------------------------------------------------- /Projects/OpenFodder.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFodder/openfodder/0e0c5a26eb848ee1d3a0a0ed16b463020a38307c/Projects/OpenFodder.rc -------------------------------------------------------------------------------- /Projects/VS2015/OpenFodder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenFodder", "OpenFodder.vcxproj", "{37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|Win32.Build.0 = Debug|Win32 18 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|x64.ActiveCfg = Debug|x64 19 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|x64.Build.0 = Debug|x64 20 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|Win32.ActiveCfg = Release|Win32 21 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|Win32.Build.0 = Release|Win32 22 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|x64.ActiveCfg = Release|x64 23 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Projects/VS2015/OpenFodder.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WindowsLocalDebugger 5 | 6 | 7 | 8 | 9 | WindowsLocalDebugger 10 | 11 | 12 | 13 | 14 | WindowsLocalDebugger 15 | 16 | 17 | WindowsLocalDebugger 18 | --window 19 | 20 | -------------------------------------------------------------------------------- /Projects/VS2015/gitver.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | if exist ..\..\.git\ ( 3 | git --version >nul 2>&1 && ( 4 | git log -n 1 --pretty="const char* gitversion=\"%%h\";" > ..\..\Source\gitver.hpp 5 | ) || (echo const char* gitversion="unknown install git";> ..\..\Source\gitver.hpp) 6 | ) else (echo const char* gitversion="unknown no git folder";> ..\..\Source\gitver.hpp) 7 | -------------------------------------------------------------------------------- /Projects/VS2015/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Projects/VS2017/OpenFodder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31402.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenFodder", "OpenFodder.vcxproj", "{37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release_JSDebug|x64 = Release_JSDebug|x64 13 | Release_JSDebug|x86 = Release_JSDebug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|x64.ActiveCfg = Debug|x64 19 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|x64.Build.0 = Debug|x64 20 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|x86.ActiveCfg = Debug|Win32 21 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Debug|x86.Build.0 = Debug|Win32 22 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release_JSDebug|x64.ActiveCfg = Release_JSDebug|x64 23 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release_JSDebug|x64.Build.0 = Release_JSDebug|x64 24 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release_JSDebug|x86.ActiveCfg = Release_JSDebug|Win32 25 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release_JSDebug|x86.Build.0 = Release_JSDebug|Win32 26 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|x64.ActiveCfg = Release|x64 27 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|x64.Build.0 = Release|x64 28 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|x86.ActiveCfg = Release|Win32 29 | {37C57A15-FFBF-41E2-9549-4E5CDB50C7D1}.Release|x86.Build.0 = Release|Win32 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {FBC3AF8A-23B4-4C4F-9DE2-834346A80AC1} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Projects/VS2017/OpenFodder.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WindowsLocalDebugger 5 | --mission 2 --phase 2 6 | 7 | 8 | WindowsLocalDebugger 9 | 10 | 11 | 12 | 13 | WindowsLocalDebugger 14 | 15 | 16 | 17 | WindowsLocalDebugger 18 | --window --window-scale 4 19 | 20 | 21 | WindowsLocalDebugger 22 | --window --window-scale 2 --random --campaign "Cannon Fodder" --skipintro --columns 40 --rows 30 --debugger 23 | 24 | 25 | WindowsLocalDebugger 26 | --window --window-scale 2 27 | 28 | -------------------------------------------------------------------------------- /Projects/VS2017/gitver.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | if exist ..\..\.git\ ( 3 | git --version >nul 2>&1 && ( 4 | git log -n 1 --pretty="const char* gitversion=\"%%h\";" > ..\..\Source\gitver.hpp 5 | ) || (echo const char* gitversion="unknown install git";> ..\..\Source\gitver.hpp) 6 | ) else (echo const char* gitversion="unknown no git folder";> ..\..\Source\gitver.hpp) 7 | -------------------------------------------------------------------------------- /Projects/VS2017/openfodder.ini: -------------------------------------------------------------------------------- 1 | ; OpenFodder 2 | ; 3 | ; 4 | 5 | [openfodder] 6 | window=false 7 | cheats=false 8 | scale=auto 9 | mouse-locked=true 10 | integer = false 11 | ;columns = 50 12 | ;rows = 30 13 | 14 | [paths] 15 | ;path1=../../Run 16 | path2=d:/games/openfodder 17 | 18 | [engine] 19 | platform=amiga 20 | maxsprite=45 21 | maxspawn=10 22 | 23 | [skip] 24 | intro=true 25 | briefing=true 26 | service=true 27 | hill=true -------------------------------------------------------------------------------- /Projects/VS2017/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Projects/WinInstaller/build.cmd: -------------------------------------------------------------------------------- 1 | docker run --rm -v "%cd%\..\..":/build binfalse/nsis projects/WinInstaller/installer.nsi 2 | @pause -------------------------------------------------------------------------------- /Projects/WinInstaller/openfodder.ini: -------------------------------------------------------------------------------- 1 | ; OpenFodder 2 | ; 3 | ; Example ini settings are the engine defaults 4 | ; 5 | 6 | [openfodder] 7 | 8 | ; Start the game in a window 9 | window=true 10 | 11 | ; Enable cheat keys 12 | cheats=false 13 | 14 | ; Window size multipler by original game resolution (Amiga 320x225, Dos 320x200) 15 | ; auto finds a size approximately half your screen resolution 16 | ; values such as 1, 2 or 3+ are multiples of the original resolution 17 | scale=auto 18 | 19 | ; Use integer scaling (default), or use non-integer scaling to fit the image to display height 20 | ; while preserving the original 4:3 aspect ratio. 21 | ; When doing non-integer scaling in fullscreen mode, linear filtering is applied 22 | ; to avoid ugly irregular pixels and shimmering artifacts. 23 | integer=true 24 | 25 | ; Number of map tiles to draw horizontally (0 for platform default) 26 | columns=0 27 | 28 | ; Number of map tiles to draw vertically (0 for platform default) 29 | rows=0 30 | 31 | ; Don't set mouse cursor x/y, use raw values (this alters the behaviour of the in-game camera window) -- Useful for VMs 32 | alternate-mouse=false 33 | 34 | ; The mouse is locked to the window 35 | mouse-locked=false 36 | 37 | ; Enable copy protection screen on Dos CD release 38 | copyprotection=false 39 | 40 | 41 | [paths] 42 | ; Paths to data base folder 43 | ; There is no limit to the number paths in this section (eg, path1, path2... path10) 44 | ;path1=c:/games/openfodder 45 | ;path2=d:/games/openfodder 46 | ;path3=d:/games/openfodder 47 | 48 | ; 49 | ; 50 | [engine] 51 | 52 | ; Default platform (amiga/pc) 53 | platform=amiga 54 | 55 | ; Game engine to use in single/random maps (cf1/cf2) 56 | game=cf1 57 | 58 | ; Maximum number of sprites in game (original engine is 45) 59 | maxsprite=45 60 | 61 | ; Maximum number of enemies which can spawn (original engine is 10) 62 | maxspawn=10 63 | 64 | 65 | [skip] 66 | 67 | ; Skip the game introduction screens 68 | intro=false 69 | 70 | ; Skip the briefing screen 71 | briefing=false 72 | 73 | ; Skip the killed in action / promotion screens 74 | service=false 75 | 76 | ; Skip the hill recruit screen 77 | hill=false 78 | -------------------------------------------------------------------------------- /Projects/emscripten/build_emscripten.cmd: -------------------------------------------------------------------------------- 1 | copy openfodder.ini ..\..\Run 2 | docker run --rm -v %cd%\..\..\:/src -t apiaryio/emcc make -f EMakefile 3 | 4 | docker stop openfodder-web 5 | docker run --rm -v %cd%\..\..\RunE:/usr/local/apache2/htdocs/ -v %cd%\httpd.conf:/usr/local/apache2/conf/httpd.conf -dit --name openfodder-web -p 8080:80 httpd:2.4 6 | 7 | @pause -------------------------------------------------------------------------------- /Projects/emscripten/openfodder.ini: -------------------------------------------------------------------------------- 1 | ; OpenFodder 2 | ; 3 | ; 4 | 5 | [openfodder] 6 | window=true 7 | cheats=false 8 | scale=3 9 | 10 | [paths] 11 | ;path1=../../Run 12 | ;path2=d:/games/openfodder 13 | 14 | [engine] 15 | platform=amiga 16 | maxsprite=45 17 | maxspawn=10 18 | 19 | [skip] 20 | intro=false 21 | briefing=false 22 | service=false 23 | hill=false -------------------------------------------------------------------------------- /Projects/openfodder.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFodder/openfodder/0e0c5a26eb848ee1d3a0a0ed16b463020a38307c/Projects/openfodder.ico -------------------------------------------------------------------------------- /Projects/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by OpenFodder1.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /Source/.gitignore: -------------------------------------------------------------------------------- 1 | gitver.hpp 2 | -------------------------------------------------------------------------------- /Source/About.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | #include "gitver.hpp" 25 | 26 | static std::string compiled = std::string(__DATE__) + " AT " + std::string(__TIME__); 27 | static std::string version = "VERSION " + std::string(gitversion); 28 | 29 | const size_t TEXTPOS_BUILD = 250; 30 | const size_t TEXTPOS_TEAM = 400; 31 | const size_t TEXTPOS_THANKS = 550; 32 | const size_t TEXTPOS_POWERED = 660; 33 | 34 | cAbout::cAbout() { 35 | std::transform(compiled.begin(), compiled.end(), compiled.begin(), ::toupper); 36 | std::transform(version.begin(), version.end(), version.begin(), ::toupper); 37 | std::replace(compiled.begin(), compiled.end(), ':', ' '); 38 | 39 | std::vector AboutText = { 40 | { TEXTPOS_BUILD + 0 , "OPEN FODDER"}, 41 | //{ TEXTPOS_BUILD + 10 , "BUILD VERSION "}, 42 | { TEXTPOS_BUILD + 10, version.c_str()}, 43 | { TEXTPOS_BUILD + 20, compiled.c_str()}, 44 | { TEXTPOS_BUILD + 30, "WWW DOT OPENFODDER DOT COM"}, 45 | 46 | { TEXTPOS_TEAM + 0 , "THE TEAM" }, 47 | { TEXTPOS_TEAM + 20 , "PROJECT LEAD" }, 48 | { TEXTPOS_TEAM + 30, "ROBERT CROSSFIELD" }, 49 | 50 | { TEXTPOS_TEAM + 80, "ENGINE" }, 51 | { TEXTPOS_TEAM + 90, "ROBERT CROSSFIELD" }, 52 | { TEXTPOS_TEAM + 100, "ALESSANDRO PETRALIA" }, 53 | 54 | { TEXTPOS_TEAM + 120, "SCRIPTING" }, 55 | { TEXTPOS_TEAM + 130, "STARWINDZ" }, 56 | 57 | 58 | { TEXTPOS_THANKS + 0 , "THANKS TO" }, 59 | { TEXTPOS_THANKS + 10, "SENSIBLE SOFTWARE"}, 60 | { TEXTPOS_THANKS + 20, "STOO CAMBRIDGE"}, 61 | { TEXTPOS_THANKS + 30, "CLAIRE CROSSFIELD"}, 62 | { TEXTPOS_THANKS + 40, "LACHIE CROSSFIELD"}, 63 | { TEXTPOS_THANKS + 50, "RILEY ELLETT"}, 64 | { TEXTPOS_THANKS + 60, "SCUMMVM"}, 65 | 66 | { TEXTPOS_POWERED + 0, "POWERED BY"}, 67 | { TEXTPOS_POWERED + 10, "CPP17"}, 68 | { TEXTPOS_POWERED + 20, "SDL2"}, 69 | { TEXTPOS_POWERED + 30, "DUKTAPE"}, 70 | { TEXTPOS_POWERED + 40, "DUKGLUE"}, 71 | { TEXTPOS_POWERED + 50, "IDA"}, 72 | 73 | // Just for fun: loc_2B48E 74 | { 1100, "PUSH CX"}, 75 | { 1110, "PUSH SI"}, 76 | { 1120, "PUSH DI"}, 77 | { 1130, "MOV CX 16H"}, 78 | 79 | { 1150, "MOV BX ES SI"}, 80 | { 1160, "AND BX 1FFH"}, 81 | { 1170, "PUSH CS"}, 82 | { 1180, "CALL SUB 2B4B8"}, 83 | { 1190, "ADD SI 2"}, 84 | 85 | { 1500, "W W W DOT O P E N F O D D E R DOT C O M"} 86 | }; 87 | 88 | mSurface = new cSurface(0, 0); 89 | mSurface->LoadPng(g_ResourceMan->GetAboutFile()); 90 | 91 | g_Fodder->mGraphics->PaletteSet(); 92 | g_Fodder->Phase_EngineReset(); 93 | g_Fodder->mMouseSpriteNew = eSprite_pStuff_Mouse_Target; 94 | g_Fodder->mService_Draw_List.clear(); 95 | 96 | g_Fodder->mGraphics->Load_Service_Data(); 97 | g_Fodder->mGraphics->SetActiveSpriteSheet(eGFX_SERVICE); 98 | g_Fodder->mGraphics->PaletteSet(); 99 | 100 | 101 | for (auto& Text : AboutText) { 102 | g_Fodder->Service_Draw_String(Text.mText, false, Text.mPosition); 103 | } 104 | 105 | g_Fodder->mSound->Music_Play(PLATFORM_BASED(16, CANNON_BASED(16, 20))); 106 | } 107 | 108 | cAbout::~cAbout() { 109 | 110 | delete mSurface; 111 | } 112 | 113 | bool cAbout::Cycle() { 114 | 115 | g_Fodder->GUI_Element_Reset(); 116 | 117 | g_Fodder->mSurface->palette_FadeTowardNew(); 118 | g_Fodder->mSurface->clearBuffer(); 119 | 120 | g_Fodder->mGraphics->SetActiveSpriteSheet(eGFX_BRIEFING); 121 | g_Fodder->Service_Draw_List(); 122 | 123 | if (g_Fodder->mInterruptTick % 2 == 0) 124 | g_Fodder->Service_ScrollUp_DrawList(); 125 | 126 | { 127 | g_Fodder->mString_GapCharID = 0x25; 128 | g_Fodder->String_Print_Large("Open Fodder", true, 0x01); 129 | g_Fodder->mString_GapCharID = 0x00; 130 | 131 | g_Fodder->GUI_Button_Draw_Small("BACK", 0xB3 + PLATFORM_BASED(0, 25)); 132 | g_Fodder->GUI_Button_Setup_Small(&cFodder::GUI_Button_Load_Exit); 133 | } 134 | 135 | if (g_Fodder->mPhase_Aborted) 136 | g_Fodder->GUI_Button_Load_Exit(); 137 | 138 | if (g_Fodder->mMouse_Button_Left_Toggle) { 139 | g_Fodder->GUI_Handle_Element_Mouse_Check(g_Fodder->mGUI_Elements); 140 | 141 | if (g_Fodder->mGUI_SaveLoadAction == 1) { 142 | 143 | g_Fodder->mSurface->paletteNew_SetToBlack(); 144 | g_Fodder->mSurface->palette_FadeTowardNew(); 145 | } 146 | 147 | } 148 | 149 | g_Fodder->Mouse_DrawCursor(); 150 | 151 | g_Fodder->mSurface->draw(); 152 | g_Fodder->Video_Sleep(mSurface, true); 153 | g_Fodder->mWindow->RenderAt(g_Fodder->mSurface); 154 | //g_Fodder->Video_SurfaceRender(false, false, 0, false); 155 | 156 | if (g_Fodder->mGUI_SaveLoadAction == 1 && !g_Fodder->mSurface->isPaletteAdjusting()) 157 | return false; 158 | 159 | return true; 160 | } 161 | -------------------------------------------------------------------------------- /Source/About.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cAbout { 24 | 25 | cSurface* mSurface; 26 | 27 | public: 28 | cAbout(); 29 | ~cAbout(); 30 | 31 | bool Cycle(); 32 | }; 33 | -------------------------------------------------------------------------------- /Source/Amiga/Graphics_Amiga.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | const extern sSpriteSheet* mSpriteSheetTypes_InGame_Amiga[]; 24 | const extern sSpriteSheet* mSpriteSheetTypes_InGame_Amiga_TheOne[]; 25 | const extern sSpriteSheet* mSpriteSheetTypes_Font_Amiga[]; 26 | const extern sSpriteSheet* mSpriteSheetTypes_Recruit_Amiga[]; 27 | const extern sSpriteSheet* mSpriteSheetTypes_Hill_Amiga[]; 28 | const extern sSpriteSheet* mSpriteSheetTypes_Briefing_Amiga[]; 29 | const extern sSpriteSheet* mSpriteSheetTypes_Service_Amiga[]; 30 | 31 | 32 | 33 | struct sHillOverlay_Amiga { 34 | int16 mSpriteType; 35 | int16 mFrame; 36 | int16 mX; 37 | int16 mY; 38 | }; 39 | 40 | struct sStruct0_Amiga { 41 | int16 mSpriteSheet; // 0 = mDataHillData : 1 = mSpriteSheet_RankFont 42 | int16 mOffset; 43 | int16 mWidth; 44 | int16 mHeight; 45 | }; 46 | 47 | class cGraphics_Amiga : public cGraphics { 48 | protected: 49 | int32 Heli_VeryBack; 50 | int32 Heli_Back; 51 | int32 Heli_middle; 52 | int32 Heli_Front; 53 | int32 Heli_TextPos; 54 | int32 Heli_TextPosBottom; 55 | 56 | int16 word_3292; 57 | int16 word_32D2; 58 | int16 word_3316; 59 | 60 | tSharedBuffer mBlkData; 61 | 62 | sILBM_BMHD* mBMHD_Current; 63 | uint16 mCursorPalette; 64 | 65 | 66 | virtual void DecodePalette(const uint8* pData, size_t pColorID, const size_t pColors); 67 | virtual sImage DecodeIFF(const std::string& pFilename); 68 | 69 | public: 70 | cGraphics_Amiga(); 71 | virtual ~cGraphics_Amiga(); 72 | 73 | virtual sImage Decode_Image(const std::string& pFilename, const size_t pCount, const size_t pPaletteOffset = 0, const size_t pStartIndex = 0); 74 | 75 | virtual void SetCursorPalette( uint16 pIndex ); 76 | 77 | virtual void DrawPixel(uint8* pSource, uint8* pDestination, uint16 pSourceX, uint16 pSourceY, uint16 pX, uint16 pY); 78 | virtual void DrawPixels_8( uint8* pSource, uint8* pDestination ); 79 | virtual void DrawPixels_16( uint8* pSource, uint8* pDestination, const uint8 pPalleteIndex ); 80 | 81 | virtual void Load_And_Draw_Image( const std::string &pFilename, unsigned int pColors = 0, size_t pBackColor = 0 ); 82 | 83 | virtual uint8* GetSpriteData( uint16 pSegment ); 84 | virtual void Mouse_DrawCursor(); 85 | virtual void Tile_Prepare_Gfx(); 86 | virtual void Load_pStuff(); 87 | virtual void Load_Sprite_Font(); 88 | virtual void Load_Hill_Data(); 89 | virtual void Load_Service_Data(); 90 | 91 | virtual void Map_Load_Resources(); 92 | virtual void Map_Tile_Draw(cSurface *pTarget, uint16 pTile, uint16 pX, uint16 pY, uint16 pOffset); 93 | virtual void MapTiles_Draw(); 94 | virtual void Hill_Prepare_Overlays(); 95 | virtual void MapOverview_Render_Tiles( uint16 pTile, uint16 pDestX, uint16 pDestY ); 96 | 97 | virtual void PaletteSetOverview(); 98 | virtual void PaletteSet(cSurface *pTarget); 99 | virtual void PaletteBriefingSet(); 100 | 101 | virtual void PaletteLoad( const uint8 *pBuffer, uint32 pColors, uint32 pColorID = 0 ); 102 | 103 | virtual void Video_Draw_16_Offset( int16 pCx ); 104 | virtual void Video_Draw_16( const uint8* RowPallete = 0 ); 105 | virtual void Video_Draw_8( cSurface *pTarget = 0, const uint8* RowPallete = 0 ); 106 | virtual void Video_Draw_8_Alt( const uint8* RowPallete = 0 ); 107 | 108 | virtual void SetActiveSpriteSheet(eGFX_Types pSpriteType ); 109 | 110 | virtual void Sidebar_Copy_To_Surface( int16 pStartY, cSurface* pSurface = 0); 111 | virtual void Sidebar_Copy_Sprite_To_ScreenBufPtr( int16 pSpriteType, size_t pX, size_t pY ); 112 | virtual void Sidebar_Copy_ScreenBuffer( uint16 pRow, int16 pRows, int16 pCopyToScreen, uint32*& pBuffer); 113 | 114 | virtual void Recruit_Sprite_Draw(int16 pRows, int16 pColumns, int16 pData8, int16 pData10, int16 pData14, int16 pDataC, uint8* pData20 ); 115 | 116 | virtual bool Sprite_OnScreen_Check( ); 117 | virtual bool Sprite_OnScreen_Check(bool p16bit = false); 118 | 119 | virtual void Mission_Intro_Play( const bool pShowHelicopter, const eTileTypes pTileset, const std::string pTop, const std::string pBottom); 120 | virtual void Mission_Intro_Load_Resources(const eTileTypes pTileset); 121 | virtual void Mission_Intro_DrawHelicopter( uint16 pID ); 122 | virtual void Briefing_Helicopter_Background_Unk(); 123 | virtual void Briefing_Helicopter_Background_Unk_1(); 124 | 125 | virtual void Recruit_Draw_Hill(); 126 | virtual void Recruit_Draw_HomeAway(); 127 | virtual void Service_Draw( int16 pSpriteID, int16 pX, int16 pY); 128 | }; 129 | -------------------------------------------------------------------------------- /Source/Amiga/Graphics_Amiga2.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | const extern sSpriteSheet* mSpriteSheetTypes_InGame_Amiga_CF2[]; 24 | 25 | class cGraphics_Amiga2 : public cGraphics_Amiga { 26 | 27 | public: 28 | 29 | virtual void Load_pStuff(); 30 | virtual void Load_And_Draw_Image(const std::string &pFilename, unsigned int pColors, size_t pBackColor); 31 | virtual void Load_Service_Data(); 32 | 33 | sImage Decode_Image(const std::string& pFilename, const size_t pCount, const size_t pPaletteOffset, const size_t pStartIndex); 34 | 35 | tSharedBuffer GetPalette(const std::string pFilename); 36 | virtual sImage GetImage(const std::string& pFilename, const size_t pPaletteIndex); 37 | 38 | virtual void Map_Load_Resources(); 39 | virtual void Mission_Intro_Load_Resources(const eTileTypes pTileset); 40 | 41 | virtual void SetActiveSpriteSheet(eGFX_Types pSpriteType); 42 | 43 | void Recruit_Draw_Hill(); 44 | 45 | cGraphics_Amiga2(); 46 | ~cGraphics_Amiga2(); 47 | }; 48 | -------------------------------------------------------------------------------- /Source/Amiga/IntroData_Amiga.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "Types.hpp" 24 | #include 25 | #include "IntroData.hpp" 26 | 27 | 28 | const sIntroString mIntro_0[] = { 29 | { 0x50, "This game is not in any way" }, 30 | { 0x68, "endorsed by the" }, 31 | { 0x82, "ROYAL BRITISH LEGION" }, 32 | { 0, 0 } 33 | }; 34 | 35 | const sIntroString mIntro_1[] = { 36 | { 0xCC, "A Sensible Software Game" }, 37 | { 0, 0 } 38 | }; 39 | 40 | const sIntroString mIntro_2[] = { 41 | { 0x64, "STARRING" }, 42 | { 0, 0 } 43 | }; 44 | 45 | const sIntroString mIntro_3[] = { 46 | { 0xA4, "JOOLS" }, 47 | { 0xB5, "as" }, 48 | { 0xC8, "James Dean" }, 49 | { 0, 0 } 50 | }; 51 | 52 | const sIntroString mIntro_4[] = { 53 | { 0xA4, "STOO" }, 54 | { 0xB4, "as" }, 55 | { 0xC8, "Elvis" }, 56 | { 0, 0 } 57 | }; 58 | 59 | const sIntroString mIntro_5[] = { 60 | { 0xA4, "RICHARD JOSEPH" }, 61 | { 0xB4, "as" }, 62 | { 0xC8, "Sgt. Bilko" }, 63 | { 0, 0 } 64 | }; 65 | 66 | const sIntroString mIntro_6[] = { 67 | { 0x64, "Co. STARRING" }, 68 | { 0, 0 } 69 | }; 70 | 71 | const sIntroString mIntro_7[] = { 72 | { 0xA4, "CHRIS YATES" }, 73 | { 0xB4, "as" }, 74 | { 0xC8, "JR out of Dallas" }, 75 | { 0, 0 } 76 | }; 77 | 78 | const sIntroString mIntro_8[] = { 79 | { 0xA4, "JON HARE" }, 80 | { 0xB5, "as" }, 81 | { 0xC8, "Vera Lynn" }, 82 | { 0, 0 } 83 | }; 84 | 85 | const sIntroString mIntro_9[] = { 86 | { 0x64, "SPECIAL GUEST STAR" }, 87 | { 0, 0 } 88 | }; 89 | 90 | const sIntroString mIntro_10[] = { 91 | { 0xA4, "CHRIS CHAPMAN" }, 92 | { 0xB4, "as" }, 93 | { 0xC8, "Norman Wisdom" }, 94 | { 0, 0 } 95 | }; 96 | 97 | const sIntroString mIntro_11[] = { 98 | { 0x50, "Jools" }, 99 | { 0x8C, "Stoo" }, 100 | { 0x3C, "Program Design" }, 101 | { 0x78, "Graphic Design" }, 102 | { 0, 0 } 103 | }; 104 | 105 | const sIntroString mIntro_12[] = { 106 | { 0x32, "Richard Joseph" }, 107 | { 0x6E, "Jon Hare" }, 108 | { 0xAA, "David Hindley" }, 109 | { 0x1E, "Sound effects and Music" }, 110 | { 0x5A, "Original Soundtrack"}, 111 | { 0x96, "Cameraman" }, 112 | { 0, 0 } 113 | }; 114 | 115 | const sIntroString mIntro_13[] = { 116 | { 0x28, "Steve Cook" }, 117 | { 0x5A, "Graftgold" }, 118 | { 0x8C, "Hammonds Hire" }, 119 | { 0xBE, "Peter Hickman" }, 120 | { 0x14, "Vehicle and Stunts" }, 121 | { 0x46, "Flatbed Scanning" }, 122 | { 0x78, "Costumes" }, 123 | { 0xAA, "Mr Virgin" }, 124 | { 0, 0 } 125 | }; 126 | 127 | const sIntroString mIntro_14[] = { 128 | { 0xD2, "Sensible Software." }, 129 | { 0xBE, "Designed By" }, 130 | { 0, 0 } 131 | }; 132 | 133 | std::vector< sIntroText > mIntroText_Amiga = { 134 | { 0xFF, mIntro_0 }, 135 | { 0x31, mIntro_1 }, 136 | { 0xFF, mIntro_2 }, 137 | { 0x32, mIntro_3 }, 138 | { 0x33, mIntro_4 }, 139 | { 0x34, mIntro_5 }, 140 | { 0xFF, mIntro_6 }, 141 | { 0x36, mIntro_7 }, 142 | { 0x35, mIntro_8 }, 143 | { 0xFF, mIntro_9 }, 144 | { 0x37, mIntro_10 }, 145 | { 0xFF, mIntro_11 }, 146 | { 0xFF, mIntro_12 }, 147 | { 0xFF, mIntro_13 }, 148 | { 0x38, mIntro_14 }, 149 | { 0, 0 }, 150 | { 0, 0 }, 151 | { 0, 0 } 152 | }; 153 | 154 | std::vector< sIntroText > mIntroText_Amiga2 = { 155 | { 0, 0 }, 156 | { 0x31, 0 }, 157 | { 0x32, 0 }, 158 | { 0x33, 0 }, 159 | { 0x34, 0 }, 160 | { 0x35, 0 }, 161 | { 0x36, 0 }, 162 | { 0x37, 0 }, 163 | { 0x38, 0 }, 164 | { 0x39, 0 }, 165 | { 0x61, 0 }, 166 | { 0x62, 0 }, 167 | { 0x63, 0 }, 168 | { 0x64, 0 }, 169 | { 0, 0 } 170 | }; 171 | -------------------------------------------------------------------------------- /Source/Amiga/Resource_Amiga_File.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | #include "Amiga/dernc.hpp" 25 | #include "Amiga/Resource_Amiga_File.hpp" 26 | 27 | cResource_Amiga_File::cResource_Amiga_File( ) : cResources() { 28 | 29 | } 30 | 31 | cResource_Amiga_File::~cResource_Amiga_File() { 32 | 33 | } 34 | 35 | tSharedBuffer cResource_Amiga_File::fileGet( std::string pFilename ) { 36 | 37 | auto File = cResources::fileGet( pFilename ); 38 | if (!File->size()) { 39 | //std::cout << "File " << pFilename << " Not Found!\n"; 40 | //exit( 1 ); 41 | return File; 42 | } 43 | uint32 Header = readBEDWord( File->data() ); 44 | 45 | if (Header != 'RNC\01') 46 | return File; 47 | 48 | uint32 Size = readBEDWord( File->data() + 4 ); 49 | 50 | auto Unpacked = std::make_shared>(); 51 | Unpacked->resize( Size ); 52 | 53 | rnc_unpack (File->data(), Unpacked->data()); 54 | 55 | return Unpacked; 56 | } 57 | -------------------------------------------------------------------------------- /Source/Amiga/Resource_Amiga_File.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cResource_Amiga_File : public cResources { 24 | 25 | uint8* file_Get( cResource_File *pFile, size_t &pFileSize, bool pDecode ); 26 | 27 | public: 28 | 29 | cResource_Amiga_File( ); 30 | virtual ~cResource_Amiga_File(); 31 | 32 | virtual tSharedBuffer fileGet( std::string pFilename ); 33 | }; 34 | -------------------------------------------------------------------------------- /Source/Amiga/Sound_Amiga.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sSoundData { 24 | const char* mSongData; 25 | const char* mInstrumentData; 26 | }; 27 | 28 | struct sSound { 29 | tSharedBuffer mCurrentMusicSongData; 30 | tSharedBuffer mCurrentMusicInstrumentData; 31 | 32 | const sSoundData* mTrack; 33 | 34 | sSound() { 35 | 36 | mTrack = 0; 37 | } 38 | }; 39 | 40 | class cSound_Amiga : public cSound { 41 | Audio::Rjp1* mCurrentMusic; 42 | sSound mSound_Music; 43 | sSound mSound_Sfx; 44 | 45 | SDL_AudioSpec* mAudioSpec; 46 | int mVal; 47 | SDL_mutex* mLock; 48 | 49 | std::vector mCurrentSfx; 50 | 51 | 52 | private: 53 | 54 | bool devicePrepare(); 55 | 56 | public: 57 | 58 | cSound_Amiga(); 59 | ~cSound_Amiga(); 60 | 61 | void audioBufferFill( short *pBuffer, int pBufferSize ); 62 | 63 | int16 Track_Load( sSound* pSound, int16 pTrack, int16 pSong ); 64 | void Sound_Play( int16 pTileset, int16 pSoundEffect, int16 pVolume, int16 pIndex); 65 | 66 | void Music_Play( int16 pTrack, int16 pSong); 67 | void Music_Stop(); 68 | void Music_SetVolume(int16 pChannel, int16 pVolume); 69 | int16 Music_GetVolume(int16 pChannel); 70 | 71 | void Sound_Stop(); 72 | 73 | 74 | }; 75 | -------------------------------------------------------------------------------- /Source/Amiga/audiostream.hpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | #ifndef AUDIO_AUDIOSTREAM_H 24 | #define AUDIO_AUDIOSTREAM_H 25 | 26 | namespace Audio { 27 | 28 | /** 29 | * Generic audio input stream. Subclasses of this are used to feed arbitrary 30 | * sampled audio data into ScummVM's audio mixer. 31 | */ 32 | class AudioStream { 33 | public: 34 | int16 mVolume; 35 | 36 | virtual ~AudioStream() {} 37 | 38 | /** 39 | * Fill the given buffer with up to numSamples samples. Returns the actual 40 | * number of samples read, or -1 if a critical error occurred (note: you 41 | * *must* check if this value is less than what you requested, this can 42 | * happen when the stream is fully used up). 43 | * 44 | * Data has to be in native endianess, 16 bit per sample, signed. For stereo 45 | * stream, buffer will be filled with interleaved left and right channel 46 | * samples, starting with a left sample. Furthermore, the samples in the 47 | * left and right are summed up. So if you request 4 samples from a stereo 48 | * stream, you will get a total of two left channel and two right channel 49 | * samples. 50 | */ 51 | virtual int readBuffer(int16 *buffer, const int numSamples) = 0; 52 | 53 | /** Is this a stereo stream? */ 54 | virtual bool isStereo() const = 0; 55 | 56 | /** Sample rate of the stream. */ 57 | virtual int getRate() const = 0; 58 | 59 | /** 60 | * End of data reached? If this returns true, it means that at this 61 | * time there is no data available in the stream. However there may be 62 | * more data in the future. 63 | * This is used by e.g. a rate converter to decide whether to keep on 64 | * converting data or stop. 65 | */ 66 | virtual bool endOfData() const = 0; 67 | 68 | /** 69 | * End of stream reached? If this returns true, it means that all data 70 | * in this stream is used up and no additional data will appear in it 71 | * in the future. 72 | * This is used by the mixer to decide whether a given stream shall be 73 | * removed from the list of active streams (and thus be destroyed). 74 | * By default this maps to endOfData() 75 | */ 76 | virtual bool endOfStream() const { return endOfData(); } 77 | }; 78 | 79 | /** 80 | * A rewindable audio stream. This allows for reseting the AudioStream 81 | * to its initial state. Note that rewinding itself is not required to 82 | * be working when the stream is being played by Mixer! 83 | */ 84 | class RewindableAudioStream : public virtual AudioStream { 85 | public: 86 | /** 87 | * Rewinds the stream to its start. 88 | * 89 | * @return true on success, false otherwise. 90 | */ 91 | virtual bool rewind() = 0; 92 | }; 93 | 94 | /** 95 | * A looping audio stream. This object does nothing besides using 96 | * a RewindableAudioStream to play a stream in a loop. 97 | */ 98 | class LoopingAudioStream : public AudioStream { 99 | public: 100 | /** 101 | * Creates a looping audio stream object. 102 | * 103 | * Note that on creation of the LoopingAudioStream object 104 | * the underlying stream will be rewound. 105 | * 106 | * @see makeLoopingAudioStream 107 | * 108 | * @param stream Stream to loop 109 | * @param loops How often to loop (0 = infinite) 110 | * @param disposeAfterUse Destroy the stream after the LoopingAudioStream has finished playback. 111 | */ 112 | LoopingAudioStream(RewindableAudioStream *stream, size_t loops); 113 | 114 | int readBuffer(int16 *buffer, const int numSamples); 115 | bool endOfData() const; 116 | bool endOfStream() const; 117 | 118 | bool isStereo() const { return _parent->isStereo(); } 119 | int getRate() const { return _parent->getRate(); } 120 | 121 | /** 122 | * Returns number of loops the stream has played. 123 | */ 124 | size_t getCompleteIterations() const { return _completeIterations; } 125 | private: 126 | RewindableAudioStream* _parent; 127 | 128 | size_t _loops; 129 | size_t _completeIterations; 130 | }; 131 | 132 | /** 133 | * Wrapper functionality to efficiently create a stream, which might be looped. 134 | * 135 | * Note that this function does not return a LoopingAudioStream, because it does 136 | * not create one when the loop count is "1". This allows to keep the runtime 137 | * overhead down, when the code does not require any functionality only offered 138 | * by LoopingAudioStream. 139 | * 140 | * @param stream Stream to loop (will be automatically destroyed, when the looping is done) 141 | * @param loops How often to loop (0 = infinite) 142 | * @return A new AudioStream, which offers the desired functionality. 143 | */ 144 | AudioStream *makeLoopingAudioStream(RewindableAudioStream *stream, size_t loops); 145 | 146 | } // End of namespace Audio 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /Source/Amiga/dernc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * dernc.h define exported routines from dernc.c 3 | */ 4 | 5 | /** 6 | * DERNC From: https://github.com/alexandergitter/THViewer 7 | */ 8 | 9 | #ifndef RNC_DERNC_H 10 | #define RNC_DERNC_H 11 | 12 | /* 13 | * Routines 14 | */ 15 | long rnc_ulen (void *packed); 16 | #ifndef COMPRESSOR 17 | long rnc_unpack (void *packed, void *unpacked); 18 | #else 19 | long rnc_unpack (void *packed, void *unpacked, long *leeway); 20 | #endif 21 | const char *rnc_error (long errcode); 22 | long rnc_crc (void *data, long len); 23 | 24 | /* 25 | * Error returns 26 | */ 27 | #define RNC_FILE_IS_NOT_RNC -1 28 | #define RNC_HUF_DECODE_ERROR -2 29 | #define RNC_FILE_SIZE_MISMATCH -3 30 | #define RNC_PACKED_CRC_ERROR -4 31 | #define RNC_UNPACKED_CRC_ERROR -5 32 | 33 | /* 34 | * The compressor needs this define 35 | */ 36 | #define RNC_SIGNATURE 0x524E4301 /* "RNC\001" */ 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Source/Amiga/rjp1.hpp: -------------------------------------------------------------------------------- 1 | /* ScummVM - Graphic Adventure Engine 2 | * 3 | * ScummVM is the legal property of its developers, whose names 4 | * are too numerous to list here. Please refer to the COPYRIGHT 5 | * file distributed with this source distribution. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | * 21 | */ 22 | 23 | /** 24 | * @file 25 | * Sound decoder used in engines: 26 | * - queen 27 | */ 28 | 29 | #ifndef AUDIO_MODS_RJP1_H 30 | #define AUDIO_MODS_RJP1_H 31 | 32 | namespace Audio { 33 | 34 | struct Rjp1Channel { 35 | const int8 *waveData; 36 | const int8 *modulatePeriodData; 37 | const int8 *modulateVolumeData; 38 | const int8 *envelopeData; 39 | uint16 volumeScale; 40 | int16 volume; 41 | uint16 modulatePeriodBase; 42 | uint32 modulatePeriodLimit; 43 | uint32 modulatePeriodIndex; 44 | uint16 modulateVolumeBase; 45 | uint32 modulateVolumeLimit; 46 | uint32 modulateVolumeIndex; 47 | uint8 freqStep; 48 | uint32 freqInc; 49 | uint32 freqInit; 50 | const uint8 *noteData; 51 | const uint8 *sequenceOffsets; 52 | const uint8 *sequenceData; 53 | uint8 loopSeqCount; 54 | uint8 loopSeqCur; 55 | uint8 loopSeq2Count; 56 | uint8 loopSeq2Cur; 57 | bool active; 58 | int16 modulatePeriodInit; 59 | int16 modulatePeriodNext; 60 | bool setupNewNote; 61 | int8 envelopeMode; 62 | int8 envelopeScale; 63 | int8 envelopeEnd1; 64 | int8 envelopeEnd2; 65 | int8 envelopeStart; 66 | int8 envelopeVolume; 67 | uint8 currentInstrument; 68 | const int8 *data; 69 | uint16 pos; 70 | uint16 len; 71 | uint16 repeatPos; 72 | uint16 repeatLen; 73 | bool isSfx; 74 | }; 75 | 76 | class Rjp1 : public Paula { 77 | public: 78 | 79 | struct Vars { 80 | int8 *instData; 81 | uint32 instDataSize; 82 | 83 | uint8 *songData[7]; 84 | uint32 songDataSize[7]; 85 | 86 | uint8 activeChannelsMask; 87 | uint8 currentChannel; 88 | int subsongsCount; 89 | int instrumentsCount; 90 | }; 91 | 92 | Rjp1(int rate, bool stereo); 93 | virtual ~Rjp1(); 94 | 95 | bool load(tSharedBuffer songData, tSharedBuffer instrumentsData); 96 | void unload(); 97 | 98 | void startPattern(int ch, int pat); 99 | void startSong(int song); 100 | 101 | protected: 102 | 103 | void startSequence(uint8 channelNum, uint8 seqNum); 104 | void turnOffChannel(Rjp1Channel *channel); 105 | void playChannel(Rjp1Channel *channel); 106 | void turnOnChannel(Rjp1Channel *channel); 107 | bool executeSfxSequenceOp(Rjp1Channel *channel, uint8 code, const uint8 *&p); 108 | bool executeSongSequenceOp(Rjp1Channel *channel, uint8 code, const uint8 *&p); 109 | void playSongSequence(Rjp1Channel *channel); 110 | void modulateVolume(Rjp1Channel *channel); 111 | void modulatePeriod(Rjp1Channel *channel); 112 | void setupNote(Rjp1Channel *channel, int16 freq); 113 | void setupInstrument(Rjp1Channel *channel, uint8 num); 114 | void setRelease(Rjp1Channel *channel); 115 | void modulateVolumeEnvelope(Rjp1Channel *channel); 116 | void setSustain(Rjp1Channel *channel); 117 | void setDecay(Rjp1Channel *channel); 118 | void modulateVolumeWaveform(Rjp1Channel *channel); 119 | void setVolume(Rjp1Channel *channel); 120 | 121 | void stopPaulaChannel(size_t channel); 122 | void setupPaulaChannel(size_t channel, const int8 *waveData, uint16 offset, uint16 len, uint16 repeatPos, uint16 repeatLen); 123 | 124 | virtual void interrupt(); 125 | 126 | Vars _vars; 127 | Rjp1Channel _channelsTable[4]; 128 | 129 | static const int16 _periodsTable[]; 130 | static const int _periodsCount; 131 | }; 132 | class AudioStream; 133 | 134 | /* 135 | * Factory function for RichardJoseph1 modules. Reads all data from the 136 | * given songData and instrumentsData streams and creates an AudioStream 137 | * from this. No references to these stream objects are kept. 138 | */ 139 | Rjp1 *makeRjp1Stream(tSharedBuffer songData, tSharedBuffer instrumentsData, int num, int rate = 44100, bool stereo = true); 140 | 141 | } // End of namespace Audio 142 | 143 | #endif 144 | -------------------------------------------------------------------------------- /Source/CopyProtection.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sCopyProtection { 24 | int16 mPage; 25 | int16 mParagraph; 26 | int16 mLine; 27 | int16 mWord; 28 | const uint8* mAnswer; 29 | }; 30 | 31 | //extern const sCopyProtection mCopyProtection_Values[]; 32 | -------------------------------------------------------------------------------- /Source/Debugger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | #ifdef WIN32 26 | #include 27 | #endif 28 | 29 | cDebugger::cDebugger() { 30 | 31 | } 32 | 33 | bool cDebugger::ConsoleOpen() { 34 | static bool Alloced = false; 35 | 36 | if (Alloced) 37 | return true; 38 | /* 39 | #ifdef _CONSOLE 40 | return true; 41 | #endif*/ 42 | if (g_Fodder->mParams->mAppVeyor) 43 | return true; 44 | 45 | #ifdef WIN32 46 | static bool attached = AttachConsole(ATTACH_PARENT_PROCESS); 47 | if (!attached) 48 | attached = AllocConsole(); 49 | 50 | FILE *stream, *stream2, *stream3; 51 | 52 | freopen_s(&stream, "CONIN$", "r", stdin); 53 | freopen_s(&stream2, "CONOUT$", "w", stdout); 54 | freopen_s(&stream3, "CONOUT$", "w", stderr); 55 | 56 | Alloced = true; 57 | std::ios::sync_with_stdio(true); 58 | std::wcout.clear(); 59 | std::cout.clear(); 60 | std::wcerr.clear(); 61 | std::cerr.clear(); 62 | std::wcin.clear(); 63 | std::cin.clear(); 64 | #endif 65 | return true; 66 | } 67 | 68 | void cDebugger::ClearConsole() { 69 | 70 | #ifdef WIN32 71 | system("cls"); 72 | #else 73 | system("clear"); 74 | #endif 75 | } 76 | 77 | void cDebugger::Output(const std::string pMessage) { 78 | #ifdef WIN32 79 | OutputDebugStringA(pMessage.c_str()); 80 | #endif 81 | std::cout << pMessage; 82 | } 83 | 84 | void cDebugger::Notice(const std::string& pMessage) { 85 | ConsoleOpen(); 86 | 87 | if (g_Fodder->mParams->mAppVeyor) { 88 | std::string Command = "appveyor AddMessage "; 89 | Command += "\"" + pMessage + "\""; 90 | Command += " -Category Information"; 91 | system(Command.c_str()); 92 | } 93 | else { 94 | Output(pMessage + "\n" ); 95 | } 96 | 97 | } 98 | 99 | void cDebugger::Error(const std::string& pMessage) { 100 | ConsoleOpen(); 101 | if (g_Fodder->mParams->mAppVeyor) { 102 | std::string Command = "appveyor AddMessage "; 103 | Command += "\"" + pMessage + "\""; 104 | Command += " -Category Error"; 105 | system(Command.c_str()); 106 | } 107 | else { 108 | Output(pMessage + "\n"); 109 | } 110 | } 111 | 112 | void cDebugger::TestStart(const std::string& pName, const std::string& pGroup) { 113 | ConsoleOpen(); 114 | if (g_Fodder->mParams->mAppVeyor) { 115 | std::string Command = "appveyor AddTest"; 116 | 117 | Command += " -Name \"" + pName + "\""; 118 | Command += " -Framework NUnit -FileName \"" + pGroup + "\""; 119 | Command += " -Outcome Running"; 120 | system(Command.c_str()); 121 | } 122 | else { 123 | std::cout << "[Test] " << pName << ": starting\n"; 124 | } 125 | } 126 | 127 | void cDebugger::TestComplete(const std::string& pName, const std::string& pGroup, const std::string& pMessage, const size_t pTime, eTestState pTestState) { 128 | ConsoleOpen(); 129 | if (g_Fodder->mParams->mAppVeyor) { 130 | std::string Command = "appveyor UpdateTest"; 131 | Command += " -Name \"" + pName + "\""; 132 | Command += " -Framework NUnit -FileName \"" + pGroup +"\""; 133 | if (pTestState == eTest_Failed) 134 | Command += " -ErrorMessage \"" + pMessage + "\""; 135 | 136 | Command += " -Duration " + std::to_string(pTime); 137 | Command += " -Outcome "; 138 | 139 | switch (pTestState) { 140 | case eTest_Passed: 141 | Command += "Passed"; 142 | break; 143 | case eTest_Failed: 144 | Command += "Failed"; 145 | break; 146 | case eTest_Skipped: 147 | Command += "Skipped"; 148 | break; 149 | case eTest_Running: 150 | Command += "Running"; 151 | break; 152 | } 153 | 154 | system(Command.c_str()); 155 | } 156 | else { 157 | if(pTestState == eTest_Passed) 158 | std::cout << "[Test] " << pName << ": Passed - " << pMessage << "\n"; 159 | else 160 | std::cout << "[Test] " << pName << ": Failed - " << pMessage << "\n"; 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Source/Debugger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | enum eTestState { 24 | eTest_Running, 25 | eTest_Passed, 26 | eTest_Failed, 27 | eTest_Skipped 28 | }; 29 | 30 | class cDebugger { 31 | 32 | protected: 33 | bool ConsoleOpen(); 34 | 35 | void Output(const std::string pMessage); 36 | 37 | public: 38 | cDebugger(); 39 | 40 | void ClearConsole(); 41 | 42 | void Notice(const std::string& pMessage); 43 | void Error(const std::string& pMessage); 44 | 45 | void TestStart( const std::string& pName, const std::string& pGroup ); 46 | void TestComplete(const std::string& pName, const std::string& pGroup, const std::string& pMessage, const size_t pTime, eTestState pTestState); 47 | 48 | }; 49 | -------------------------------------------------------------------------------- /Source/Dimension.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cDimension { 24 | public: 25 | unsigned int mWidth, mHeight; 26 | 27 | public: 28 | cDimension() : mWidth( 0 ), mHeight( 0 ) {} 29 | cDimension( unsigned int pWidth, unsigned int pHeight ) : mWidth( pWidth ), mHeight( pHeight ) {} 30 | 31 | void Set( unsigned int pWidth, unsigned int pHeight ) { mWidth = pWidth; mHeight = pHeight; } 32 | 33 | unsigned int WidthByHeight() { return mWidth * mHeight; } 34 | int getWidth() const { return mWidth; } 35 | int getHeight() const { return mHeight; } 36 | 37 | cPosition getCentre() const { return { mWidth / 2, mHeight / 2 }; }; 38 | 39 | cDimension operator/(const cDimension& pDim) { 40 | return cDimension(mWidth / pDim.mWidth, mHeight / pDim.mHeight); 41 | } 42 | 43 | bool operator==(const cDimension& pRight) { 44 | return mWidth == pRight.mWidth && mHeight == pRight.mHeight; 45 | } 46 | 47 | cDimension operator+(const cDimension& pRight) { 48 | 49 | return cDimension(mWidth + pRight.mWidth, mHeight + pRight.mHeight); 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /Source/Event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | cEvent::cEvent( const eEventType& pType ) { 26 | 27 | mHasFocus = false; 28 | mType = pType; 29 | mButton = 0; 30 | mButtonCount = 0; 31 | } 32 | 33 | cEvent::~cEvent() { 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Source/Event.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | enum eEventType { 24 | eEvent_None = 0, 25 | eEvent_KeyDown = 1, 26 | eEvent_KeyUp = 2, 27 | eEvent_MouseMove = 3, 28 | eEvent_MouseLeftDown = 4, 29 | eEvent_MouseLeftUp = 5, 30 | eEvent_MouseRightDown = 6, 31 | eEvent_MouseRightUp = 7, 32 | eEvent_MouseWheel = 8, 33 | eEvent_Quit = 10, 34 | eEvent_Focus = 11, 35 | }; 36 | 37 | class cEvent { 38 | public: 39 | eEventType mType; 40 | 41 | unsigned int mButton; 42 | unsigned int mButtonCount; 43 | 44 | cPosition mPosition; 45 | cPosition mPositionRelative; 46 | bool mHasFocus; 47 | 48 | public: 49 | cEvent( const eEventType& pType = eEvent_None ); 50 | virtual ~cEvent(); 51 | }; 52 | -------------------------------------------------------------------------------- /Source/FontData.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFodder/openfodder/0e0c5a26eb848ee1d3a0a0ed16b463020a38307c/Source/FontData.cpp -------------------------------------------------------------------------------- /Source/FontData.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | const extern uint8 mFont_Briefing_Width[]; 24 | const extern uint8 mFont_Recruit_Width[]; 25 | const extern uint8 mFont_Sidebar_Width[]; 26 | const extern uint8 mFont_Underlined_Width[]; 27 | const extern uint8 mFont_Service_Width[]; 28 | const extern uint8 mFont_Intro_Width[]; 29 | const extern uint8 mFont_Service_PalleteIndex[]; 30 | const extern uint8 mFont_Service_PalleteIndex_Amiga[]; 31 | 32 | const extern uint8 mFont_ServiceName_Width[]; 33 | const extern unsigned char mGUI_Font_SpecialCharacters[]; 34 | -------------------------------------------------------------------------------- /Source/GUI_Element.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cFodder; 24 | 25 | struct sGUI_Element { 26 | int16 (cFodder::*field_0)(); 27 | int16 mX; 28 | int16 mWidth; 29 | int16 mY; 30 | int16 mHeight; 31 | void (cFodder::*mMouseInsideFuncPtr)(); // field_c 32 | }; 33 | 34 | struct sGUI_SquadVehicleIcon { 35 | int16 mVehicleType; 36 | int16 mIconID; 37 | }; 38 | 39 | // Menu Buttons 40 | extern const sGUI_Element mAfx_Buttons[]; 41 | extern const sGUI_Element mPlus_Buttons[]; 42 | extern const sGUI_Element mPlusQuiz_Buttons[]; 43 | extern const sGUI_Element mAmigaAction_Buttons[]; 44 | 45 | // Sidebar Squad Icons 46 | extern const int16 mGUI_Squad_Icons[]; 47 | extern const int16 mGUI_Squad_Active_Icons[]; 48 | extern const int16 mGUI_Squad_Inactive_Icons[]; 49 | extern const int16 mGUI_Squad_Split_Icons[]; 50 | extern const sGUI_SquadVehicleIcon mGUI_Squad_Vehicle_Icons[]; 51 | 52 | extern const int8 mGUI_Sidebar_TroopList_Sprite_Modifier[]; 53 | 54 | -------------------------------------------------------------------------------- /Source/Graphics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | cGraphics::cGraphics() { 26 | 27 | mFodder = g_Fodder; 28 | mSurface = g_Fodder->mSurface; 29 | mImageOriginal = mSurface; 30 | 31 | mImageTemporary.mData->resize(100000); 32 | } 33 | 34 | void cGraphics::SetImage( cSurface* pImage ) { 35 | mSurface = pImage; 36 | } 37 | 38 | void cGraphics::SetImageOriginal() { 39 | 40 | mSurface = mImageOriginal; 41 | } 42 | 43 | void cGraphics::SetSurfaceOriginal(cSurface* pImage) { 44 | mImageOriginal = pImage; 45 | } -------------------------------------------------------------------------------- /Source/IntroData.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sIntroString { 24 | uint32 mPosition; 25 | const char* mText; 26 | }; 27 | 28 | struct sIntroText { 29 | uint32 mImageNumber; 30 | const sIntroString* mText; 31 | }; 32 | 33 | extern std::vector< sIntroText > mIntroText_PC; 34 | extern std::vector< sIntroText > mIntroText_PC2; 35 | extern std::vector< sIntroText > mIntroText_Amiga; 36 | extern std::vector< sIntroText > mIntroText_Amiga2; 37 | -------------------------------------------------------------------------------- /Source/Map/Map.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | sMapParams::sMapParams(size_t pWidth, size_t pHeight, eTileTypes pTileType, eTileSub pTileSub) { 26 | mTileType = pTileType; 27 | mTileSub = pTileSub; 28 | mWidth = pWidth; 29 | mHeight = pHeight; 30 | } 31 | 32 | sMapParams::sMapParams(size_t pSeed) { 33 | mTileType = eTileTypes_Jungle; 34 | mTileSub = eTileSub_0; 35 | mWidth = 30; 36 | mHeight = 20; 37 | 38 | if (pSeed) 39 | mRandom.setSeed((int16)pSeed); 40 | } 41 | 42 | cMap::cMap() { 43 | mData = std::make_shared>(); 44 | mTile_Ptr = 0; 45 | } 46 | 47 | int32 cMap::Tile_Get(const size_t pTileX, const size_t pTileY) { 48 | if (pTileX > mParams.mWidth || pTileY > mParams.mHeight) 49 | return -1; 50 | 51 | size_t Tile = (((pTileY * mParams.mWidth) + pTileX)) + mParams.mWidth; 52 | 53 | uint8* CurrentMapPtr = mData->data() + mTile_Ptr + (Tile * 2); 54 | if (CurrentMapPtr > mData->data() + mData->size()) 55 | return -1; 56 | 57 | return readLE(CurrentMapPtr); 58 | } 59 | 60 | void cMap::Tile_Set(const size_t pTileX, const size_t pTileY, const size_t pTileID) { 61 | if (pTileX > mParams.mWidth || pTileY > mParams.mHeight) 62 | return; 63 | 64 | size_t Tile = (((pTileY * mParams.mWidth) + pTileX)) + mParams.mWidth; 65 | 66 | uint8* CurrentMapPtr = mData->data() + mTile_Ptr + (Tile * 2); 67 | if (CurrentMapPtr > mData->data() + mData->size()) 68 | return; 69 | 70 | writeLEWord(CurrentMapPtr, (uint16)pTileID); 71 | } 72 | 73 | void cMap::Sprite_Add(size_t pSpriteID, size_t pSpriteX, size_t pSpriteY) { 74 | sSprite First; 75 | 76 | First.field_18 = static_cast(pSpriteID); 77 | First.field_0 = static_cast(pSpriteX); 78 | First.field_4 = static_cast(pSpriteY); 79 | First.field_26 = static_cast(pSpriteX); 80 | First.field_28 = static_cast(pSpriteY); 81 | mSprites.push_back(First); 82 | 83 | switch (pSpriteID) { 84 | case eSprite_BoilingPot: // 1 Null 85 | case eSprite_Tank_Human: 86 | case eSprite_VehicleNoGun_Human: 87 | case eSprite_VehicleGun_Human: 88 | case eSprite_VehicleNoGun_Enemy: 89 | case eSprite_VehicleGun_Enemy: 90 | case eSprite_Vehicle_Unk_Enemy: 91 | First.field_18 = eSprite_Null; 92 | mSprites.push_back(First); 93 | break; 94 | 95 | case eSprite_Helicopter_Grenade_Enemy: // 3 Nulls 96 | case eSprite_Helicopter_Unarmed_Enemy: 97 | case eSprite_Helicopter_Missile_Enemy: 98 | case eSprite_Helicopter_Homing_Enemy: 99 | case eSprite_Helicopter_Homing_Enemy2: 100 | First.field_18 = eSprite_Null; 101 | mSprites.push_back(First); 102 | mSprites.push_back(First); 103 | mSprites.push_back(First); 104 | break; 105 | 106 | // Fall Through 107 | case eSprite_Helicopter_Grenade_Human: // 2 Nulls 108 | case eSprite_Helicopter_Unarmed_Human: 109 | case eSprite_Helicopter_Missile_Human: 110 | case eSprite_Helicopter_Homing_Human: 111 | case eSprite_Helicopter_Grenade_Human_Called: 112 | case eSprite_Helicopter_Unarmed_Human_Called: 113 | case eSprite_Helicopter_Missile_Human_Called: 114 | case eSprite_Helicopter_Homing_Human_Called: 115 | case eSprite_Tank_Enemy: 116 | First.field_18 = eSprite_Null; 117 | mSprites.push_back(First); 118 | mSprites.push_back(First); 119 | break; 120 | } 121 | } 122 | 123 | void cMap::Structure_Add(const sStructure& pStructure, size_t pTileX, size_t pTileY) { 124 | 125 | for (const auto& Piece : pStructure.mTiles) { 126 | Tile_Set(pTileX + Piece.mX, pTileY + Piece.mY, Piece.mTileID); 127 | } 128 | 129 | // Add the sprites 130 | for (const auto& Sprite : pStructure.mSprites) { 131 | auto Sheet = &mSpriteSheetTypes_InGame_Amiga[Sprite.mSpriteID][0]; 132 | 133 | // - 0x40 because no sidebar 134 | Sprite_Add(Sprite.mSpriteID, ((pTileX) * 16) + (Sprite.mX - Sheet->mModX), 135 | ((pTileY) * 16) + (Sprite.mY - Sheet->mModY)); 136 | } 137 | } 138 | 139 | void cMap::ClearTiles(const size_t pTileID) { 140 | 141 | mData->resize(0x60 + ((mParams.mWidth * mParams.mHeight) * 2), (uint8)pTileID); 142 | mTile_Ptr = (int32)((0x60) - (mParams.mWidth * 2)); 143 | } 144 | 145 | tSharedBuffer cMap::getData() const { 146 | return mData; 147 | } 148 | 149 | std::vector cMap::getSprites() const { 150 | return mSprites; 151 | } 152 | -------------------------------------------------------------------------------- /Source/Map/Map.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sSprite; 24 | 25 | struct sMapParams { 26 | size_t mWidth; 27 | size_t mHeight; 28 | eTileTypes mTileType; 29 | eTileSub mTileSub; 30 | cPseudorand mRandom; 31 | 32 | sMapParams(size_t pWidth, size_t pHeight, eTileTypes pTileType, eTileSub pTileSub = eTileSub::eTileSub_0); 33 | sMapParams(size_t pSeed = 0); 34 | 35 | size_t getWidth() { return mWidth; } 36 | void setWidth(const size_t pWidth) { mWidth = pWidth; } 37 | 38 | size_t getHeight() { return mHeight; } 39 | void setHeight(const size_t pHeight) { mHeight = pHeight; } 40 | 41 | eTileTypes getTiletype() { return mTileType; } 42 | void setTiletype(eTileTypes pTiletypes) { mTileType = pTiletypes; } 43 | 44 | eTileSub getTileSub() { return mTileSub; } 45 | void setTileSub(eTileSub pTileSub) { mTileSub = pTileSub; } 46 | 47 | }; 48 | 49 | class cMap { 50 | 51 | protected: 52 | sMapParams mParams; 53 | tSharedBuffer mData; 54 | 55 | int32 mTile_Ptr; 56 | 57 | std::vector mSprites; 58 | 59 | protected: 60 | 61 | int32 Tile_Get(const size_t pTileX, const size_t pTileY); 62 | void Tile_Set(const size_t pTileX, const size_t pTileY, const size_t pTileID); 63 | void Sprite_Add(size_t pSpriteID, size_t pSpriteX, size_t pSpriteY); 64 | void Structure_Add(const sStructure& pStructure, size_t pTileX, size_t pTileY); 65 | 66 | public: 67 | cMap(); 68 | 69 | void ClearTiles(const size_t pTileID); 70 | 71 | sMapParams *getMapParams() { return &mParams; } 72 | eTileTypes getTileType() const { return mParams.mTileType; } 73 | eTileSub getTileSub() const { return mParams.mTileSub; } 74 | 75 | int32 getArea() const { return static_cast(mParams.mWidth * mParams.mHeight); } 76 | int32 getWidth() const { return static_cast(mParams.mWidth); } 77 | int32 getHeight() const { return static_cast(mParams.mHeight); } 78 | 79 | int32 getAreaPixels() const { return getWidthPixels() * getHeightPixels(); } 80 | int32 getWidthPixels() const { return static_cast(mParams.mWidth) << 4; } 81 | int32 getHeightPixels() const { return static_cast(mParams.mHeight) << 4; } 82 | 83 | virtual bool load(tSharedBuffer pMapFile, tSharedBuffer pSptFile, const bool pCF2) = 0; 84 | virtual bool save(std::string pFilename, const bool CF1) = 0; 85 | 86 | tSharedBuffer getData() const; 87 | std::vector getSprites() const; 88 | }; 89 | -------------------------------------------------------------------------------- /Source/Map/Original.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cOriginalMap : public cMap { 24 | 25 | private: 26 | 27 | void loadCF1Map(tSharedBuffer pMapData); 28 | void loadCF1Spt(tSharedBuffer pSpriteData, bool pCF2); 29 | 30 | bool saveCF1Map(const std::string& pFilename); 31 | bool saveCF1Sprites(std::string pFilename); 32 | 33 | protected: 34 | 35 | void saveHeader(); 36 | void SetTileTypeFromHeader(); 37 | void SetTileTypeInHeader(); 38 | 39 | public: 40 | cOriginalMap() : cMap() {}; 41 | cOriginalMap(tSharedBuffer pMapFile, tSharedBuffer pSptFile, const bool pCF2); 42 | 43 | virtual bool load(tSharedBuffer pMapFile, tSharedBuffer pSptFile, const bool pCF2) override; 44 | virtual bool save(std::string pFilename, const bool CF1) override; 45 | }; 46 | -------------------------------------------------------------------------------- /Source/Map/Random.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | #include "Utils/micropather.h" 23 | 24 | class cScriptingEngine; 25 | 26 | class cRandomMap : public cOriginalMap, public micropather::Graph { 27 | friend class cScriptingEngine; 28 | private: 29 | 30 | protected: 31 | const int8* mPathTilesNotTouchable; 32 | size_t mPathSearchUnitType; 33 | 34 | int Passable(int nx, int ny); 35 | 36 | virtual float LeastCostEstimate(cPosition* nodeStart, cPosition* nodeEnd); 37 | virtual void AdjacentCost(cPosition* node, std::vector< micropather::StateCost > *neighbors); 38 | virtual void PrintStateInfo(cPosition* node); 39 | 40 | public: 41 | cRandomMap(const sMapParams& pParams); 42 | 43 | bool CheckRadiusTileID(std::vector pTileIDs, cPosition* pPosition, int32 pRadius); 44 | bool CheckRadiusFeatures(const std::vector& pType, cPosition* pPosition, int32 pRadius); 45 | bool CheckRadiusSprites(cPosition* pPosition, int32 pRadius); 46 | 47 | void create(size_t pWidth, size_t pHeight, eTileTypes pTileType, eTileSub pTileSub = eTileSub::eTileSub_0); 48 | 49 | std::vector calculatePath(size_t pSpriteType, cPosition* Pos1, cPosition* Pos2); 50 | int32 getSpriteTypeCount(size_t pSpriteType); 51 | std::vector getSpritesByType(size_t pSpriteType); 52 | float getRandomFloat(float pMin, float pMax); 53 | int32 getRandomInt(int32 pMin = 0, int32 pMax = 0); 54 | int16 getSeed() const; 55 | void setSeed(const int16 pSeed); 56 | 57 | cPosition* getRandomXYByTileID(std::vector pTiles, size_t pRadius); 58 | cPosition* getRandomXYByFeatures(std::vector pFeatures, size_t pRadius, bool pIgnoreSprites); 59 | cPosition* getRandomXYByTerrainType(eTerrainFeature pType, size_t pRadius); 60 | 61 | int32 getDistanceBetweenPositions(cPosition* pPos1, cPosition* pPos2); 62 | 63 | std::vector> createDiamondSquare(); 64 | 65 | std::vector> createSimplexIslands(size_t pOctaves, float pRoughness, float pScale, short pSeed, bool pRadialEnabled, float pEdgeFade); 66 | std::vector> createSimplexNoise(size_t pOctaves, float pFrequency, float pLacunarity, float pPersistence); 67 | }; 68 | 69 | -------------------------------------------------------------------------------- /Source/PC/Graphics_PC.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | const extern sSpriteSheet* mSpriteSheetTypes_InGame_PC[]; 24 | const extern sSpriteSheet* mSpriteSheetTypes_Font_PC[]; 25 | const extern sSpriteSheet* mSpriteSheetTypes_Recruit_PC[]; 26 | const extern sSpriteSheet* mSpriteSheetTypes_Hill_PC[]; 27 | const extern sSpriteSheet* mSpriteSheetTypes_Briefing_PC[]; 28 | const extern sSpriteSheet* mSpriteSheetTypes_Service_PC[]; 29 | 30 | const extern uint8 mUnkStringModifier_Recruit[]; 31 | 32 | class cGraphics_PC : public cGraphics { 33 | int32 mRecruitDestX; 34 | int32 dword_44A3E; 35 | int32 mRecruitDestY; 36 | 37 | uint8* mTile_Gfx_Ptrs[480]; 38 | 39 | sImage mImageRecruit; 40 | tSharedBuffer mBriefing_ParaHeli; 41 | tSharedBuffer mMission_Intro_Gfx_Clouds1; 42 | tSharedBuffer mMission_Intro_Gfx_Clouds2; 43 | tSharedBuffer mMission_Intro_Gfx_Clouds3; 44 | tSharedBuffer mMission_Intro_Gfx_TreesMain; 45 | 46 | uint16 mMission_Intro_DrawX; 47 | uint16 mMission_Intro_DrawY; 48 | 49 | int32 Heli_VeryBack; 50 | int32 Heli_Back; 51 | int32 Heli_middle; 52 | int32 Heli_Front; 53 | int32 Heli_TextPos; 54 | int32 Heli_TextPosBottom; 55 | 56 | public: 57 | virtual ~cGraphics_PC(); 58 | 59 | virtual uint8* GetSpriteData( uint16 pSegment ); 60 | virtual void Mouse_DrawCursor(); 61 | 62 | virtual void Tile_Prepare_Gfx(); 63 | virtual void Load_pStuff(); 64 | virtual void Load_Sprite_Font(); 65 | virtual void Load_Hill_Data(); 66 | virtual void Load_Service_Data(); 67 | 68 | virtual void Load_And_Draw_Image( const std::string &pFilename, unsigned int pColors, size_t pBackColor); 69 | virtual sImage Decode_Image(const std::string& pFilename, const size_t pCount, const size_t pPaletteOffset, const size_t pStartIndex); 70 | 71 | virtual void Map_Load_Resources(); 72 | virtual void Map_Tile_Draw(cSurface *pTarget, uint16 pTile, uint16 pX, uint16 pY, uint16 pOffset); 73 | virtual void MapTiles_Draw(); 74 | virtual void MapOverview_Render_Tiles( uint16 pTile, uint16 pDestX, uint16 pDestY ); 75 | 76 | virtual void PaletteSetOverview(); 77 | virtual void PaletteSet(cSurface *pTarget); 78 | virtual void PaletteLoad( const uint8 *pBuffer, uint32 pColors, uint32 pColorID = 0 ); 79 | virtual void SetActiveSpriteSheet(eGFX_Types pSpriteType ); 80 | 81 | uint8 Video_Get_Pixel(uint8* pSi, int16 pX, int16 pY); 82 | void Video_Put_Pixel(uint8* pDi, uint8 pAl); 83 | 84 | virtual void Video_Draw_16(const uint8* RowPallete = 0); 85 | virtual void Video_Draw_8(cSurface *pTarget = 0, const uint8* RowPallete = 0); 86 | 87 | virtual void Sidebar_Copy_To_Surface( int16 pStartY, cSurface* pSurface = 0); 88 | virtual void Sidebar_Copy_Sprite_To_ScreenBufPtr( int16 pSpriteType, size_t pX, size_t pY ); 89 | virtual void Sidebar_Copy_ScreenBuffer( uint16 pRow, int16 pRows, int16 pCopyToScreen, uint32*& Data20 ); 90 | 91 | virtual void Recruit_Sprite_Draw( int16 pColumns, int16 pRows, int16 pData8, int16 pData10, int16 pData14, int16 pDataC, uint8* pGraphics ); 92 | 93 | virtual bool Sprite_OnScreen_Check(); 94 | 95 | virtual void Mission_Intro_Load_Resources(const eTileTypes pTileset); 96 | virtual void Mission_Intro_DrawHelicopter( uint16 ); 97 | 98 | void Mission_Intro_Play( const bool pShowHelicopter, const eTileTypes pTileset, const std::string pTop, const std::string pBottom); 99 | 100 | void Mission_Intro_Render_2(tSharedBuffer pDs, int16 pCx); 101 | void Mission_Intro_Render_1(tSharedBuffer pDs, int16 pCx); 102 | 103 | void Briefing_Helicopter_Background_Unk_1(); 104 | 105 | void sub_15B98(tSharedBuffer pDs, int16 pCx); 106 | 107 | virtual void Recruit_Draw_Hill(); 108 | virtual void Recruit_Draw_HomeAway(); 109 | }; 110 | -------------------------------------------------------------------------------- /Source/PC/IntroData_PC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "Types.hpp" 24 | #include 25 | #include "IntroData.hpp" 26 | 27 | 28 | // Intro_0 has had +0x19 added to each string 29 | const sIntroString mIntro_0[] = { 30 | { 0x5F, "This game is not in any way" }, 31 | { 0x77, "endorsed by the" }, 32 | { 0x91, "ROYAL BRITISH LEGION" }, 33 | { 0, 0 } 34 | }; 35 | 36 | const sIntroString mIntro_1[] = { 37 | { 0xCC, "A Sensible Software Game" }, 38 | { 0, 0 } 39 | }; 40 | 41 | const sIntroString mIntro_2[] = { 42 | { 0x64, "STARRING" }, 43 | { 0, 0 } 44 | }; 45 | 46 | const sIntroString mIntro_3[] = { 47 | { 0xA4, "JOOLS" }, 48 | { 0xB5, "as" }, 49 | { 0xC8, "James Dean" }, 50 | { 0, 0 } 51 | }; 52 | 53 | const sIntroString mIntro_4[] = { 54 | { 0xA4, "STOO" }, 55 | { 0xB4, "as" }, 56 | { 0xC8, "Elvis" }, 57 | { 0, 0 } 58 | }; 59 | 60 | const sIntroString mIntro_5[] = { 61 | { 0xA4, "RICHARD JOSEPH" }, 62 | { 0xB4, "as" }, 63 | { 0xC8, "Sgt. Bilko" }, 64 | { 0, 0 } 65 | }; 66 | 67 | const sIntroString mIntro_6[] = { 68 | { 0x64, "Co. STARRING" }, 69 | { 0, 0 } 70 | }; 71 | 72 | const sIntroString mIntro_7[] = { 73 | { 0xA4, "CHRIS YATES" }, 74 | { 0xB4, "as" }, 75 | { 0xC8, "JR out of Dallas" }, 76 | { 0, 0 } 77 | }; 78 | 79 | const sIntroString mIntro_8[] = { 80 | { 0xA4, "JON HARE" }, 81 | { 0xB5, "as" }, 82 | { 0xC8, "Vera Lynn" }, 83 | { 0, 0 } 84 | }; 85 | 86 | const sIntroString mIntro_9[] = { 87 | { 0x64, "SPECIAL GUEST STAR" }, 88 | { 0, 0 } 89 | }; 90 | 91 | const sIntroString mIntro_10[] = { 92 | { 0xA4, "CHRIS CHAPMAN" }, 93 | { 0xB4, "as" }, 94 | { 0xC8, "Norman Wisdom" }, 95 | { 0, 0 } 96 | }; 97 | 98 | const sIntroString mIntro_11[] = { 99 | { 0x50, "Jools" }, 100 | { 0x8C, "Stoo" }, 101 | { 0x3C, "Program Design" }, 102 | { 0x78, "Graphic Design" }, 103 | { 0, 0 } 104 | }; 105 | 106 | const sIntroString mIntro_12[] = { 107 | { 0x32, "Richard Joseph" }, 108 | { 0x6E, "Jon Hare" }, 109 | { 0xAA, "David Hindley" }, 110 | { 0x1E, "Sound effects and Music" }, 111 | { 0x5A, "Original Soundtrack"}, 112 | { 0x96, "Cameraman" }, 113 | { 0, 0 } 114 | }; 115 | 116 | const sIntroString mIntro_13[] = { 117 | { 0x28, "Steve Cook" }, 118 | { 0x5A, "Graftgold" }, 119 | { 0x8C, "Hammonds Hire" }, 120 | { 0xBE, "Peter Hickman" }, 121 | { 0x19, "Vehicle and Stunts" }, 122 | { 0x46, "Flatbed Scanning" }, 123 | { 0x78, "Costumes" }, 124 | { 0xAA, "Mr Virgin" }, 125 | { 0, 0 } 126 | }; 127 | 128 | const sIntroString mIntro_14[] = { 129 | { 0x19, "An Audio Visual Magic" }, 130 | { 0x2D, "Entertainment Conversion" }, 131 | { 0x4B, "PC Programming" }, 132 | { 0x5F, "Adrian Youlden" }, 133 | { 0x7D, "PC Graphics" }, 134 | { 0x91, "Mark Smith" }, 135 | { 0xAF, "PC Sound and Music" }, 136 | { 0xC3, "Nigel Taylor" }, 137 | { 0, 0 } 138 | }; 139 | 140 | const sIntroString mIntro_15[] = { 141 | { 0x19, "PC Version Produced" }, 142 | { 0x2D, "by" }, 143 | { 0x4B, "Gavin Wade" }, 144 | { 0x5F, "and" }, 145 | { 0x73, "Scott Walsh" }, 146 | { 0, 0 } 147 | }; 148 | 149 | const sIntroString mIntro_16[] = { 150 | { 0xD2, "Sensible Software." }, 151 | { 0xBE, "Designed By" }, 152 | { 0, 0 } 153 | }; 154 | 155 | std::vector< sIntroText > mIntroText_PC = { 156 | { 0xFF, mIntro_0 }, 157 | { 0x31, mIntro_1 }, 158 | { 0xFF, mIntro_2 }, 159 | { 0x32, mIntro_3 }, 160 | { 0x33, mIntro_4 }, 161 | { 0x34, mIntro_5 }, 162 | { 0xFF, mIntro_6 }, 163 | { 0x36, mIntro_7 }, 164 | { 0x35, mIntro_8 }, 165 | { 0xFF, mIntro_9 }, 166 | { 0x37, mIntro_10 }, 167 | { 0xFF, mIntro_11 }, 168 | { 0xFF, mIntro_12 }, 169 | { 0xFF, mIntro_13 }, 170 | { 0xFF, mIntro_14 }, 171 | { 0xFF, mIntro_15 }, 172 | { 0x38, mIntro_16 }, 173 | { 0, 0 } 174 | }; 175 | 176 | std::vector< sIntroText > mIntroText_PC2 = { 177 | { 0, 0 }, 178 | { 0x31, 0 }, 179 | { 0x32, 0 }, 180 | { 0x33, 0 }, 181 | { 0x34, 0 }, 182 | { 0x35, 0 }, 183 | { 0x36, 0 }, 184 | { 0x37, 0 }, 185 | { 0x38, 0 }, 186 | { 0x39, 0 }, 187 | { 0x61, 0 }, 188 | { 0x62, 0 }, 189 | { 0x63, 0 }, 190 | { 0x64, 0 }, 191 | { 0x65, 0 }, 192 | { 0, 0 } 193 | }; 194 | -------------------------------------------------------------------------------- /Source/PC/Resource_PC_CD.hpp: -------------------------------------------------------------------------------- 1 | 2 | class cResource_PC_CD : public cResources { 3 | 4 | tSharedBuffer mData; 5 | uint8* mDataCurrent; 6 | 7 | std::vector< cResource_File > mFiles; 8 | 9 | uint8* mCurPtr; 10 | 11 | int16 word_26DBE[0x273]; 12 | int16 word_272A4[0x13A]; 13 | int16 word_27518[0x273]; 14 | int16 word_279FE[0x273]; 15 | int16 word_27EE4; 16 | uint8 byte_27EE6[0x1A3B]; 17 | static const uint8 byte_29921[0x100]; 18 | static const uint8 byte_29A21[0x101]; 19 | 20 | uint8 data_Read(); 21 | 22 | void sub_26AA4(); 23 | void sub_26B11(); 24 | uint16 sub_26C06(); 25 | uint16 sub_26CDF(); 26 | 27 | uint8 byte_26DB0; 28 | 29 | int16 mBytesRead, word_26DA8; 30 | int32 word_26DBA; 31 | uint16 word_26DAA, word_26DB4, saveSI, saveBP; 32 | 33 | bool headerLoad(); 34 | tSharedBuffer file_Get( cResource_File *pFile, bool pDecode ); 35 | 36 | 37 | public: 38 | 39 | cResource_PC_CD( const std::string& pDataFile ); 40 | virtual ~cResource_PC_CD(); 41 | 42 | virtual tSharedBuffer fileGet( std::string pFilename ); 43 | 44 | std::vector< cResource_File >* filesGet( ) { return &mFiles; } 45 | 46 | void ExtractFiles(); 47 | }; 48 | -------------------------------------------------------------------------------- /Source/PC/Sound_PC.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cSound_PC : public cSound { 24 | bool mSound; 25 | 26 | Mix_Music* mMusicPlaying; 27 | 28 | std::vector mMixerChunks; 29 | 30 | tSharedBuffer * word_42316[7]; 31 | tSharedBuffer dword_42320[0x3C]; 32 | tSharedBuffer dword_42410[0x3C]; 33 | tSharedBuffer dword_42500[0x3C]; 34 | tSharedBuffer dword_425F0[0x3C]; 35 | tSharedBuffer dword_426E0[0x3C]; 36 | 37 | private: 38 | bool devicePrepare(); 39 | void Sound_Voc_Load(); 40 | 41 | public: 42 | 43 | cSound_PC(); 44 | ~cSound_PC(); 45 | 46 | void Sound_Play( int16 pTileset, int16 pSoundEffect, int16 pVolume, int16 pIndex); 47 | 48 | void Music_Play( int16 pTrack, int16 pSong); 49 | void Music_PlayFile( const std::string& pFilename ); 50 | void Music_Stop(); 51 | 52 | void MixerChannelFinished( int32 pChannel ); 53 | }; 54 | -------------------------------------------------------------------------------- /Source/PC/Sound_PC2.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sSoundMap { 24 | int16 mEffectID; 25 | int16 mUnk; 26 | }; 27 | 28 | class cSound_PC2 : public cSound { 29 | bool mSound; 30 | 31 | Mix_Music* mMusicPlaying; 32 | std::vector mMixerChunks; 33 | std::vector mSoundEffects; 34 | 35 | private: 36 | bool devicePrepare(); 37 | void Sound_Voc_Load(); 38 | 39 | public: 40 | 41 | cSound_PC2(); 42 | ~cSound_PC2(); 43 | 44 | void Sound_Play( int16 pBx, int16 pData4, int16 pData8, int16 pIndex); 45 | 46 | void Music_Play( int16 pTrack, int16 pSong); 47 | void Music_PlayFile( const char* pFilename ); 48 | void Music_Stop(); 49 | 50 | void MixerChannelFinished( int32 pChannel ); 51 | }; 52 | -------------------------------------------------------------------------------- /Source/PC/VocTable.hpp: -------------------------------------------------------------------------------- 1 | struct struct_Voc { 2 | uint8 field_0; 3 | uint8 field_1; 4 | const char mFilename[10]; 5 | }; 6 | 7 | const struct_Voc mVocTable[] = { 8 | { 0x09, 0x02, "ALL02.VOC" }, 9 | { 0x09, 0x03, "ALL03.VOC" }, 10 | { 0x09, 0x04, "ALL04.VOC" }, 11 | { 0x09, 0x05, "ALL05.VOC" }, 12 | { 0x09, 0x06, "ALL06.VOC" }, 13 | { 0x09, 0x07, "ALL07.VOC" }, 14 | { 0x09, 0x08, "ALL08.VOC" }, 15 | { 0x09, 0x09, "ALL09.VOC" }, 16 | { 0x09, 0x0B, "ALL11.VOC" }, 17 | { 0x09, 0x0C, "ALL12.VOC" }, 18 | { 0x09, 0x0D, "ALL13.VOC" }, 19 | { 0x09, 0x0F, "ALL15.VOC" }, 20 | { 0x09, 0x10, "ALL16.VOC" }, 21 | { 0x09, 0x11, "ALL17.VOC" }, 22 | { 0x09, 0x12, "ALL18.VOC" }, 23 | { 0x09, 0x13, "ALL19.VOC" }, 24 | { 0x09, 0x14, "ALL20.VOC" }, 25 | { 0x09, 0x15, "ALL21.VOC" }, 26 | { 0x09, 0x16, "ALL22.VOC" }, 27 | { 0x09, 0x2D, "ALL46.VOC" }, // This sound is missing in the original DOS version 28 | { 0x09, 0x2E, "ALL46.VOC" }, 29 | { 0x09, 0x33, "ALL51.VOC" }, 30 | { 0x09, 0x34, "ALL52.VOC" }, 31 | { 0x09, 0x35, "ALL53.VOC" }, 32 | { 0x09, 0x36, "ALL54.VOC" }, 33 | { 0x09, 0x38, "ALL56.VOC" }, 34 | { 0x09, 0x39, "ALL57.VOC" }, 35 | { 0x09, 0x3A, "ALL58.VOC" }, 36 | { 0x09, 0x3B, "ALL59.VOC" }, 37 | 38 | { 0x00, 0x1A, "JUN26.VOC" }, 39 | { 0x00, 0x1B, "JUN27.VOC" }, 40 | { 0x00, 0x1C, "JUN28.VOC" }, 41 | 42 | { 0x01, 0x1A, "DES26.VOC" }, 43 | { 0x02, 0x1A, "ICE26.VOC" }, 44 | 45 | { 0x02, 0x1E, "ICE30.VOC" }, 46 | { 0x02, 0x1F, "ICE31.VOC" }, 47 | 48 | { 0x03, 0x1A, "MOR26.VOC" }, 49 | { 0x03, 0x1C, "MOR28.VOC" }, 50 | 51 | { 0x04, 0x1A, "INT26.VOC" }, 52 | { 0xFF, 0xFF, "" } 53 | }; 54 | -------------------------------------------------------------------------------- /Source/Parameters.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | namespace cxxopts { 24 | class Options; 25 | } 26 | 27 | class sFodderParameters { 28 | public: 29 | static cxxopts::Options* mCliOptions; 30 | 31 | bool mAppVeyor; // Running on AppVeyor 32 | bool mShowAbout; // Show the about screen 33 | bool mSkipIntro; // Skip the OpenFodder intro, and the game intro 34 | bool mSkipRecruit; // Skip the recruit screen and go straight into the mission 35 | bool mSkipBriefing; // Skip mission briefing 36 | bool mSkipService; // Skip mission debrief 37 | 38 | bool mMouseAlternative; // Use the alternate mouse behaviour 39 | bool mMouseLocked; // Mouse is locked to window 40 | 41 | bool mWindowMode; // Start in a window 42 | bool mIntegerScaling; // Use integer scaling in fullscreen mode 43 | size_t mWindowScale; // Start with window scaled at 44 | size_t mWindowRows; 45 | size_t mWindowColumns; 46 | 47 | bool mRandom; // Start a random map 48 | bool mRandomSave; // Create a random map 49 | std::string mRandomFilename;// Name to save random map as 50 | 51 | std::string mScriptRun; // Name of a script to run 52 | 53 | ePlatform mDefaultPlatform; // Default platform to use 54 | eGame mDefaultGame; // Default game to use for single/random 55 | 56 | bool mDemoRecord; // Recording a demo 57 | bool mDemoPlayback; // Playing back a demo 58 | size_t mDemoRecordResumeCycle; // Record a demo, after playing back the event queue up until this cycle 59 | std::string mDemoFile; // The Demo file to save/load to/from 60 | 61 | int64 mSleepDelta; // Engine sleep delta 62 | 63 | std::string mSingleMap; // Name of single map to load 64 | std::string mCampaignName; // Campaign to start 65 | size_t mMissionNumber; // Mission to start on 66 | size_t mPhaseNumber; // Phase to start on 67 | 68 | bool mCheatsEnabled; 69 | bool mUnitTesting; // Execute unit testing 70 | bool mSinglePhase; // Play a single phase 71 | bool mPlayground; // Launch into the sprite playground 72 | 73 | bool mDisableVideo; // Disable all video output 74 | bool mDisableSound; // Disable all sound 75 | 76 | bool mDebugger; 77 | 78 | size_t mSpritesMax; 79 | size_t mSpawnEnemyMax; 80 | 81 | bool mShowHelp; 82 | bool mCopyProtection; 83 | 84 | sFodderParameters() { 85 | clear(); 86 | } 87 | 88 | virtual ~sFodderParameters() { 89 | } 90 | 91 | virtual void clear() { 92 | 93 | mDebugger = false; 94 | 95 | mShowHelp = false; 96 | mShowAbout = false; 97 | mPlayground = false; 98 | mDisableSound = false; 99 | mDisableVideo = false; 100 | mSleepDelta = 20; 101 | 102 | mAppVeyor = false; 103 | mSkipService = false; 104 | mSkipBriefing = false; 105 | mSkipIntro = false; 106 | mSkipRecruit = false; 107 | 108 | mMissionNumber = 0; 109 | mPhaseNumber = 0; 110 | mMouseAlternative = false; 111 | mMouseLocked = false; 112 | 113 | mWindowMode = false; 114 | mIntegerScaling = true; 115 | mWindowScale = 0; 116 | 117 | mWindowRows = 0; 118 | mWindowColumns = 0; 119 | 120 | mRandom = false; 121 | mRandomSave = false; 122 | 123 | mDefaultPlatform = ePlatform::Any; 124 | mDefaultGame = eGame::CF1; 125 | 126 | mDemoRecord = false; 127 | mDemoPlayback = false; 128 | mDemoRecordResumeCycle = 0; 129 | 130 | mCheatsEnabled = false; 131 | mUnitTesting = false; 132 | mSinglePhase = false; 133 | mSpritesMax = 45; 134 | mSpawnEnemyMax = 10; 135 | 136 | mCopyProtection = false; 137 | } 138 | 139 | protected: 140 | virtual void PrepareOptions(); 141 | virtual bool ProcessCLI(int argc, char *argv[]); 142 | bool ProcessINI(); 143 | 144 | 145 | public: 146 | std::string ToJson(); 147 | bool FromJson(const std::string& pJson); 148 | 149 | void Process(int argc, char *argv[]) { 150 | ProcessINI(); 151 | ProcessCLI(argc, argv); 152 | } 153 | 154 | bool isOriginalSpriteMax() const { return mSpritesMax == 45; } 155 | int32 getSpritesMax() const { return (int32) mSpritesMax; } 156 | }; 157 | -------------------------------------------------------------------------------- /Source/Position.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cPosition { 24 | public: 25 | int mX, mY; 26 | 27 | public: 28 | cPosition() : mX( 0 ), mY( 0 ) {} 29 | cPosition( unsigned int pX, unsigned int pY ) : mX( pX ), mY( pY ) {} 30 | 31 | void Set( unsigned int pX, unsigned int pY ) { mX = pX; mY = pY; } 32 | void Clear() { mX = 0; mY = 0; } 33 | 34 | int distanceTo(const cPosition& pPosition) const { 35 | 36 | int X = mX - pPosition.mX; 37 | int Y = mY - pPosition.mY; 38 | 39 | if (X < 0) 40 | X = -X; 41 | if (Y < 0) 42 | Y = -Y; 43 | 44 | return X + Y; 45 | } 46 | 47 | bool operator== (const cPosition& pPosition) const { 48 | 49 | return pPosition.mX == mX && pPosition.mY == mY; 50 | 51 | } 52 | 53 | bool operator!= (const cPosition& pPosition) const { 54 | 55 | return !(*this == pPosition); 56 | 57 | } 58 | cPosition& operator+= (const cPosition& pPosition) { 59 | 60 | mX += pPosition.mX; 61 | mY += pPosition.mY; 62 | 63 | return *this; 64 | } 65 | 66 | cPosition& operator-= (const cPosition& pPosition) { 67 | 68 | mX -= pPosition.mX; 69 | mY -= pPosition.mY; 70 | 71 | return *this; 72 | } 73 | 74 | cPosition operator-(const cPosition& pPosition) const { 75 | 76 | return cPosition( mX - pPosition.mX, mY - pPosition.mY ); 77 | } 78 | 79 | cPosition operator+(const cPosition& pPosition) const { 80 | 81 | return cPosition(mX + pPosition.mX, mY + pPosition.mY); 82 | } 83 | 84 | cPosition* operator*(const size_t pMultiplier) { 85 | mX *= (int)pMultiplier; 86 | mY *= (int)pMultiplier; 87 | 88 | return this; 89 | } 90 | 91 | bool operator<(const cPosition& pRight) const { 92 | 93 | if (mY < pRight.mY) 94 | return true; 95 | 96 | return mX < pRight.mX; 97 | } 98 | int getY() const { return (int) mY; } 99 | void setY(int pY) { mY = pY; } 100 | 101 | int getX() const { return (int) mX; } 102 | void setX(int pX) { mX = pX; } 103 | inline int16 x() const { 104 | return (int16)mX; 105 | } 106 | 107 | inline int16 y() const { 108 | return (int16)mY; 109 | } 110 | }; 111 | -------------------------------------------------------------------------------- /Source/Recruits.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sRecruit { 24 | char mName[7]; 25 | 26 | uint8 field_6; 27 | int8 field_7; 28 | int8 field_8; 29 | }; 30 | 31 | struct sRecruit_Sprites { 32 | int16 mSpriteType; 33 | int16 mFrame; 34 | int16 field_4; 35 | int16 field_6; 36 | int16* field_8; 37 | }; 38 | 39 | struct sRecruit_Screen_Pos { 40 | int16 mX; 41 | int16 mY; 42 | int16 mFrame; 43 | }; 44 | 45 | struct sRecruitRendered { 46 | uint32* mDataPtr; 47 | int16 mPosition; 48 | 49 | sRecruitRendered(uint32* pDataPtr, int16 pPosition) { 50 | mDataPtr = pDataPtr; 51 | mPosition = pPosition; 52 | } 53 | }; 54 | 55 | struct sGravePosition { 56 | int16 mX; 57 | int16 mY; 58 | }; 59 | 60 | extern const std::vector mGravePositions; 61 | extern const struct sRecruit mRecruits[]; 62 | extern const struct sRecruit_Sprites mRecruitSprite[34]; 63 | extern struct sRecruit_Screen_Pos mRecruit_Screen_Positions[294]; 64 | 65 | extern const int16 mRecruit_Truck_Anim_Welcome[]; 66 | extern const int16 mRecruit_Truck_Anim_SwingArm[]; 67 | extern const int16 mRecruit_Truck_Anim_PassTroop[]; 68 | extern const int16 mRecruit_Truck_Anim_CloseDoor[]; 69 | 70 | extern const int16 mRecruit_Shirt_Colors[]; 71 | extern const int16 mRecruit_Hill_Position_Gaps[]; 72 | -------------------------------------------------------------------------------- /Source/ResourceMan.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cResourceMan { 24 | typedef std::map tStringMap; 25 | 26 | std::vector mAllPaths; 27 | std::vector mValidPaths; 28 | 29 | std::map mReleasePath; 30 | std::map mCampaigns; 31 | 32 | std::map mMaps; 33 | std::map mSaves; 34 | std::map mTests; 35 | 36 | std::multimap mReleaseFiles; 37 | 38 | std::string mCustomMapPath; 39 | 40 | protected: 41 | void addBaseDir(std::string pPath); 42 | void addDefaultDirs(); 43 | void validatePaths(); 44 | 45 | 46 | std::string FileMD5(const std::string& pFile); 47 | 48 | void findCampaigns(); 49 | void findVersions(); 50 | void findSaves(); 51 | void findCustomMaps(); 52 | 53 | public: 54 | 55 | cResourceMan(); 56 | 57 | void addDir(const std::string& pPath); 58 | 59 | void refresh(); 60 | 61 | std::string FindVersionPath(const sGameVersion* pVersion) const; 62 | std::string GetFilePath(const sGameVersion* pVersion, std::string pFile) const; 63 | 64 | tSharedBuffer FileRead(const std::string& pFile); 65 | std::string FileReadStr(const std::string& pFile); 66 | 67 | std::string PathGenerate(const std::string& pFile, eDataType pDataType) const; 68 | 69 | std::string GetAboutFile() const; 70 | std::string GetWavPath(const std::string& pFile) const; 71 | 72 | std::string GetCampaignData(const std::string& pName); 73 | std::string GetMapPath(const std::string& pName) const; 74 | 75 | std::string GetSave(const std::string &pName) const; 76 | std::string GetSaveNewName() const; 77 | 78 | std::string GetTestPath(const sGameVersion* pVersion, const std::string pFile) const; 79 | std::string GetScriptPath(const std::string& pType) const; 80 | 81 | std::vector GetAvailable() const; 82 | std::vector GetCampaigns() const; 83 | std::vector GetSaves() const; 84 | std::vector GetMaps() const; 85 | 86 | bool isCampaignAvailable(std::string pName) const; 87 | bool isDataAvailable() const; 88 | 89 | std::vector getValidPaths() const; 90 | std::vector getAllPaths() const; 91 | 92 | std::string getCustomMapPath() const { return mCustomMapPath; } 93 | 94 | 95 | std::vector DirectoryList(const std::string& pPath, const std::string& pExtension); 96 | bool FileExists(const std::string& pPath) const; 97 | 98 | std::string getcwd(); 99 | 100 | }; -------------------------------------------------------------------------------- /Source/Resources.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | #include "Amiga/dernc.hpp" 25 | 26 | cResources::cResources( ) { 27 | 28 | } 29 | 30 | tSharedBuffer cResources::fileGet( std::string pFilename ) { 31 | auto File = g_ResourceMan->FileRead(g_Fodder->mVersionCurrent->getDataFilePath(pFilename)); 32 | 33 | if (File->size()) { 34 | 35 | return fileDeRNC(File); 36 | } 37 | return File; 38 | } 39 | 40 | tSharedBuffer cResources::fileDeRNC(tSharedBuffer pBuffer) { 41 | uint32 Header = readBEDWord(pBuffer->data()); 42 | if (Header != 'RNC\01') 43 | return pBuffer; 44 | 45 | uint32 Size = readBEDWord(pBuffer->data() + 4); 46 | 47 | auto Unpacked = std::make_shared>(); 48 | Unpacked->resize(Size); 49 | rnc_unpack(pBuffer->data(), Unpacked->data()); 50 | return Unpacked; 51 | } 52 | 53 | size_t cResources::fileLoadTo( const std::string& pFilename, uint8* pTarget ) { 54 | 55 | auto File = fileGet( pFilename ); 56 | 57 | if (File->size()) { 58 | std::memcpy( pTarget, File->data(), File->size() ); 59 | return File->size(); 60 | } 61 | 62 | return false; 63 | } 64 | -------------------------------------------------------------------------------- /Source/Resources.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cSurface; 24 | 25 | struct cResource_File { 26 | std::string mName; 27 | uint32 mAddressStart; 28 | uint32 mSize; 29 | 30 | cResource_File( std::string pName, uint32 pStart, uint32 pEnd ) : 31 | mName( pName ), mAddressStart( pStart ), mSize( pEnd ) { } 32 | 33 | }; 34 | 35 | class cResources { 36 | protected: 37 | 38 | tSharedBuffer fileDeRNC(tSharedBuffer pBuffer); 39 | 40 | public: 41 | cResources( ); 42 | virtual ~cResources() { }; 43 | 44 | virtual tSharedBuffer fileGet( std::string pFilename ); 45 | 46 | size_t fileLoadTo( const std::string& pFilename, uint8* pTarget ); 47 | }; 48 | -------------------------------------------------------------------------------- /Source/ScriptingEngine.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct duk_hthread; 24 | class cRandomMap; 25 | 26 | class cScriptFileIO { 27 | std::fstream mStream; 28 | 29 | public: 30 | cScriptFileIO(std::string pFilename, bool pRead = false); 31 | ~cScriptFileIO(); 32 | 33 | bool isOpen(); 34 | void close(); 35 | std::string readLine(); 36 | void writeLine(std::string pStr); 37 | }; 38 | 39 | class cScriptingEngine { 40 | duk_hthread *mContext; 41 | 42 | protected: 43 | 44 | cCampaign* getCampaign(); 45 | std::shared_ptr getMap(); 46 | std::shared_ptr getPhase(); 47 | std::shared_ptr getMission(); 48 | 49 | std::shared_ptr phaseCreate(); 50 | std::shared_ptr missionCreate(); 51 | 52 | void guiPrintString(const std::string& pText, const size_t pX, const size_t pY, const bool pLarge, const bool pUnderline); 53 | 54 | void mapSave(); 55 | 56 | 57 | bool scriptCall(const std::string& pFilename); 58 | bool scriptRun(const std::string& pJS, const std::string& pFilename); 59 | bool scriptsLoadFolder(const std::string& pFolder); 60 | void spritesCreateObject(); 61 | 62 | public: 63 | 64 | cScriptingEngine(); 65 | ~cScriptingEngine(); 66 | 67 | void init(); 68 | void debuggerEnable(); 69 | duk_hthread *getContext() { return mContext; } 70 | 71 | bool Run(const std::string& pScript); 72 | }; -------------------------------------------------------------------------------- /Source/Sound.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | cSound::cSound() { 26 | mPlayingTrack = -1; 27 | } -------------------------------------------------------------------------------- /Source/Sound.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | enum eSound_Effect { 24 | eSound_Effect_Grenade = 0x0F, 25 | eSound_Effect_BuildingDoor2 = 0x10, 26 | eSound_Effect_DoorCloseDoor = 0x29, 27 | eSound_Effect_Spear = 0x2A, 28 | eSound_Effect_Vehicle_Sinking = 0x2B, 29 | eSound_Effect_Turret_Fire = 0x2C, 30 | eSound_Effect_Missile_Launch = 0x2D, 31 | eSound_Effect_Rocket = 0x2E, 32 | }; 33 | 34 | struct sChunkPlaying { 35 | int32 mChannel; 36 | Mix_Chunk* mCurrentChunk; 37 | }; 38 | 39 | class cSound { 40 | 41 | virtual bool devicePrepare() = 0; 42 | 43 | protected: 44 | int16 mPlayingTrack; 45 | int16 mPlayingSong; 46 | 47 | public: 48 | 49 | cSound(); 50 | virtual ~cSound() { }; 51 | 52 | virtual void Sound_Play( int16 pTileset, int16 pSoundEffect, int16 pVolume, int16 pIndex ) = 0; 53 | virtual void Sound_Stop() { } 54 | 55 | virtual void Music_Play( int16 pTrack, int16 pSong = -1) = 0; 56 | virtual void Music_Stop() = 0; 57 | virtual void Music_SetVolume(int16 pChannel, int16 pVolume) {}; 58 | virtual int16 Music_GetVolume(int16 pChannel) { return 0; } 59 | virtual void Stop() { 60 | Music_Stop(); 61 | Sound_Stop(); 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /Source/SpriteSheet.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | uint8* sSpriteSheet::GetGraphicsPtr() const { 26 | 27 | return g_Fodder->mGraphics->GetSpriteData(mLoadSegment) + mLoadOffset; 28 | } 29 | 30 | uint8* sSpriteSheet_pstuff::GetGraphicsPtr(uint16 pOffset) const { 31 | 32 | return g_Fodder->mGraphics->GetSpriteData( eGFX_PSTUFF ) + pOffset; 33 | } 34 | -------------------------------------------------------------------------------- /Source/SpriteSheet.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sSpriteSheet { 24 | uint16 mLoadOffset; 25 | uint16 mLoadSegment; 26 | int16 field_4; 27 | int16 field_6; 28 | int16 mColCount; 29 | int16 mRowCount; 30 | int16 mPalleteIndex; 31 | int8 mModX; 32 | int8 mModY; 33 | 34 | uint8* GetGraphicsPtr() const; 35 | }; 36 | 37 | struct sSpriteSheet_pstuff { 38 | int16 mX; 39 | int16 mY; 40 | int16 mColumns; 41 | int16 mRows; 42 | 43 | uint8* GetGraphicsPtr(uint16 pOffset) const; 44 | }; -------------------------------------------------------------------------------- /Source/Start.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | #include 25 | 26 | #ifndef _OFED 27 | #ifndef _OFBOT 28 | 29 | int start(int argc, char *argv[]) { 30 | g_Debugger = std::make_shared(); 31 | g_Window = std::make_shared(); 32 | g_ResourceMan = std::make_shared(); 33 | g_Fodder = std::make_shared(g_Window); 34 | 35 | auto Params = std::make_shared(); 36 | Params->Process(argc, argv); 37 | 38 | if (Params->mShowHelp) 39 | return 0; 40 | 41 | g_Fodder->Prepare(Params); 42 | std::thread myThread(&cFodder::Interrupt_Sim, g_Fodder); 43 | int result = 0; 44 | 45 | if (g_Fodder->mStartParams->mUnitTesting) { 46 | cUnitTesting Testing; 47 | result = Testing.Start() ? 0 : -1; 48 | } 49 | else if (g_Fodder->mStartParams->mRandomSave) { 50 | sMapParams Params(g_Fodder->mRandom.get()); 51 | g_Fodder->CreateRandom(Params); 52 | } 53 | else { 54 | g_Fodder->Start(); 55 | g_Fodder->mGame_Data.mDemoRecorded.save(); 56 | } 57 | 58 | { 59 | g_Fodder->mExit = true; 60 | myThread.join(); 61 | } 62 | return result; 63 | } 64 | 65 | // Debug stuff 66 | void quickServiceScreen() { 67 | g_Fodder->VersionSwitch(g_Fodder->mVersions->GetRetail(g_Fodder->mParams->mDefaultPlatform, g_Fodder->mParams->mDefaultGame)); 68 | g_Fodder->mGame_Data.mCampaign.Clear(); 69 | g_Fodder->mGame_Data.mCampaign.LoadCampaign("Cannon Fodder", false); 70 | 71 | g_Fodder->Game_Setup(); 72 | g_Fodder->Map_Load(); 73 | g_Fodder->Map_Load_Sprites(); 74 | 75 | //g_Fodder->Phase_Prepare(); 76 | g_Fodder->Phase_Soldiers_Count(); 77 | g_Fodder->mGame_Data.Soldier_Sort(); 78 | g_Fodder->Phase_Soldiers_Prepare(false); 79 | g_Fodder->Phase_Soldiers_AttachToSprites(); 80 | g_Fodder->Service_Show(); 81 | } 82 | 83 | 84 | #endif 85 | #endif 86 | -------------------------------------------------------------------------------- /Source/Start_Emscripten.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #ifdef EMSCRIPTEN 24 | #include "stdafx.hpp" 25 | cAbout* About = 0; 26 | 27 | void phase_loop(); 28 | void menu_loop() { 29 | static int16 result = -1; 30 | if (result == -1) { 31 | 32 | g_Fodder->VersionSwitch(g_Fodder->mVersions->GetForCampaign("Amiga Format Christmas Special")); 33 | g_Fodder->mGame_Data.mCampaign.Clear(); 34 | 35 | result = 0; 36 | g_Fodder->Campaign_Select_Setup(); 37 | return; 38 | } 39 | 40 | if (About) { 41 | 42 | if (About->Cycle()) { 43 | g_Fodder->mWindow->RenderAt(g_Fodder->mSurface); 44 | g_Fodder->mWindow->FrameEnd(); 45 | g_Fodder->Cycle_End(); 46 | return; 47 | } 48 | 49 | delete About; 50 | About = 0; 51 | g_Fodder->mGUI_SaveLoadAction = 0; 52 | result = -1; 53 | return; 54 | } 55 | 56 | g_Fodder->Campaign_Select_File_Cycle("OPEN FODDER", "SELECT CAMPAIGN"); 57 | if(g_Fodder->mGUI_SaveLoadAction == 3 || g_Fodder->mGUI_SaveLoadAction == 0) { 58 | return; 59 | } 60 | if (g_Fodder->mGUI_SaveLoadAction == 4) { 61 | g_Fodder->mGUI_SaveLoadAction = 0; 62 | About = new cAbout(); 63 | return; 64 | } 65 | 66 | g_Fodder->mPhase_Aborted = false; 67 | g_Fodder->mPhase_In_Progress = false; 68 | 69 | std::string Campaign = g_Fodder->mCampaignList[g_Fodder->mGUI_Select_File_CurrentIndex + g_Fodder->mGUI_Select_File_SelectedFileIndex]; 70 | if (g_Fodder->mGUI_SaveLoadAction == 1) 71 | Campaign = ""; 72 | 73 | g_Fodder->VersionSwitch(g_Fodder->mVersions->GetForCampaign(Campaign)); 74 | g_Fodder->mGame_Data.mCampaign.LoadCampaign(Campaign, Campaign != g_Fodder->mVersionCurrent->mName); 75 | g_Fodder->Game_Setup(); 76 | 77 | result = -1; 78 | emscripten_cancel_main_loop(); 79 | emscripten_set_main_loop(phase_loop, 24, 1); 80 | } 81 | 82 | void phase_loop() { 83 | static int16 result = -1; 84 | 85 | // No recruits left? 86 | if (result != 1) { 87 | if (!g_Fodder->mGame_Data.mRecruits_Available_Count) { 88 | emscripten_cancel_main_loop(); 89 | emscripten_set_main_loop(menu_loop, 24, 1); 90 | 91 | result = -1; 92 | } 93 | } 94 | 95 | if (result == 0) { 96 | // Game Won? 97 | if (!g_Fodder->mGame_Data.Phase_Next()) { 98 | emscripten_cancel_main_loop(); 99 | emscripten_set_main_loop(menu_loop, 24, 1); 100 | // Break to version screen 101 | return; 102 | } 103 | result = -1; 104 | } 105 | 106 | if (result == -1) { 107 | if (g_Fodder->mPhase_Aborted2) { 108 | g_Fodder->mPhase_Aborted2 = false; 109 | emscripten_cancel_main_loop(); 110 | emscripten_set_main_loop(menu_loop, 24, 1); 111 | return; 112 | } 113 | g_Fodder->Phase_EngineReset(); 114 | g_Fodder->Phase_SquadPrepare(); 115 | g_Fodder->Phase_Prepare(); 116 | } 117 | 118 | // -1 = Phase Try Again 119 | // 0 = Phase Won 120 | // 1 = Phase Running 121 | 122 | result = g_Fodder->Phase_Cycle(); 123 | g_Fodder->Cycle_End(); 124 | } 125 | 126 | int start(int argc, char *argv[]) { 127 | 128 | g_Debugger = std::make_shared(); 129 | g_Window = std::make_shared(); 130 | g_ResourceMan = std::make_shared(); 131 | g_Fodder = std::make_shared(g_Window); 132 | 133 | auto Params = std::make_shared(); 134 | Params->Process(argc, argv); 135 | 136 | if (Params->mShowHelp) 137 | return 0; 138 | 139 | Params->mCheatsEnabled = true; 140 | Params->mMouseAlternative = true; 141 | g_Fodder->Prepare(Params); 142 | g_Fodder->Phase_SquadPrepare(); 143 | 144 | emscripten_set_main_loop(menu_loop, 24, 1); 145 | 146 | //g_Fodder->Service_Show(); 147 | 148 | return 0; 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /Source/Structures/Barracks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | const std::vector mStructuresBarracksWithSoldier = { 26 | 27 | // Jungle 28 | { 29 | { 30 | { 1, 0, 333 }, 31 | { 2, 0, 334 }, 32 | 33 | { 0, 1, 352 }, 34 | { 1, 1, 353 }, 35 | { 2, 1, 354 }, 36 | 37 | { 0, 2, 372 }, 38 | { 1, 2, 373 }, 39 | { 2, 2, 374 }, 40 | { 3, 2, 375 }, 41 | 42 | { 0, 3, 392 }, 43 | { 1, 3, 393 }, 44 | { 2, 3, 394 }, 45 | }, 46 | 47 | { 48 | { 13, 18, eSprite_BuildingRoof }, 49 | { 9, 50, eSprite_BuildingDoor } 50 | }, 51 | }, 52 | 53 | // Ice 54 | { 55 | { 56 | { 1, 0, 245 }, 57 | { 2, 0, 246 }, 58 | { 3, 0, 247 }, 59 | 60 | { 0, 1, 264 }, 61 | { 1, 1, 265 }, 62 | { 2, 1, 266 }, 63 | { 3, 1, 267 }, 64 | 65 | { 0, 2, 284 }, 66 | { 1, 2, 285 }, 67 | { 2, 2, 286 }, 68 | { 3, 2, 287 }, 69 | }, 70 | { 71 | { 23, 11, eSprite_BuildingRoof }, 72 | { 20, 43, eSprite_BuildingDoor } 73 | }, 74 | }, 75 | 76 | 77 | // Desert 78 | { 79 | { 80 | { 0, 0, 196 }, 81 | { 1, 0, 197 }, 82 | { 2, 0, 198 }, 83 | 84 | { 0, 1, 216 }, 85 | { 1, 1, 217 }, 86 | { 2, 1, 218 }, 87 | 88 | { 0, 2, 236 }, 89 | { 1, 2, 237 }, 90 | { 2, 2, 238 }, 91 | }, 92 | { 93 | { 12, 1, eSprite_BuildingRoof }, 94 | { 7, 32, eSprite_BuildingDoor } 95 | }, 96 | }, 97 | 98 | 99 | // Moors 100 | { 101 | { 102 | { 1, 0, 335 }, 103 | { 2, 0, 336 }, 104 | 105 | { 0, 1, 354 }, 106 | { 1, 1, 355 }, 107 | { 2, 1, 356 }, 108 | 109 | { 0, 2, 374 }, 110 | { 1, 2, 375 }, 111 | { 2, 2, 376 }, 112 | 113 | { 0, 3, 394 }, 114 | { 1, 3, 395 }, 115 | { 2, 3, 396 }, 116 | }, 117 | { 118 | { 15, 17, eSprite_BuildingRoof }, 119 | { 7, 49, eSprite_BuildingDoor } 120 | }, 121 | }, 122 | 123 | 124 | // Int 125 | { 126 | { 127 | { 0, 0, 246 }, 128 | { 0, 1, 266 } 129 | }, 130 | { 131 | { 3, 21, eSprite_BuildingDoor } 132 | }, 133 | }, 134 | 135 | // HID 136 | { 137 | { 138 | { 0, 0, 246 }, 139 | { 0, 1, 266 } 140 | }, 141 | { 142 | { 3, 21, eSprite_BuildingDoor } 143 | }, 144 | }, 145 | 146 | // AFX 147 | { 148 | { 149 | { 0, 0, 371 }, 150 | { 1, 0, 372 }, 151 | { 2, 0, 373 }, 152 | 153 | { 0, 1, 391 }, 154 | { 1, 1, 392 }, 155 | { 2, 1, 393 }, 156 | 157 | { 0, 2, 375 }, 158 | { 1, 2, 376 }, 159 | { 2, 2, 377 }, 160 | 161 | { 0, 3, 395 }, 162 | { 1, 3, 396 }, 163 | { 2, 3, 397 }, 164 | }, 165 | { 166 | { 21, 56, eSprite_BuildingDoor } 167 | }, 168 | }, 169 | }; 170 | -------------------------------------------------------------------------------- /Source/Structures/Barracks.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | extern const std::vector mStructuresBarracksWithSoldier; 24 | -------------------------------------------------------------------------------- /Source/Surface.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | const size_t g_MaxColors = 0xFF; 24 | 25 | class cPalette { 26 | public: 27 | uint8 mRed; 28 | uint8 mGreen; 29 | uint8 mBlue; 30 | 31 | cPalette() { mRed = 0; mGreen = 0; mBlue = 0; } 32 | 33 | uint8 getPos( size_t i ) { if (i == 0) return mRed; if (i == 1) return mGreen; if (i == 2) return mBlue; return 0; } 34 | void setPos( size_t i, uint8 pval ) { 35 | if( i == 0 ) 36 | mRed = pval; 37 | if( i == 1 ) 38 | mGreen = pval; 39 | if( i == 2 ) 40 | mBlue = pval; 41 | } 42 | }; 43 | 44 | 45 | class cSurface { 46 | protected: 47 | bool mIsLoadedImage; 48 | cPalette mPalette[ g_MaxColors ]; 49 | cPalette mPaletteNew[ g_MaxColors ]; 50 | 51 | uint32 mPaletteSDL[ g_MaxColors ]; 52 | 53 | uint8* mSurfaceBuffer; // Loaded Image (uses palette indexs) 54 | uint8* mSurfaceBufferSaved; 55 | size_t mSurfaceBufferSize; 56 | 57 | SDL_Surface* mSDLSurface; 58 | SDL_Texture* mTexture; 59 | 60 | size_t mWidth, mHeight; 61 | bool mPaletteAdjusting; 62 | 63 | 64 | void clearSDLSurface(uint32 pColor = 0); // Clear the surface 65 | 66 | void paletteSDLColorSet( size_t id, cPalette *pPalette ); // Set a color in the palette 67 | 68 | 69 | public: 70 | void surfaceSetToPalette(); 71 | void surfaceSetToPaletteNew(); 72 | cSurface( size_t pWidth, size_t pHeight ); 73 | cSurface( const cDimension& pDimension ); 74 | ~cSurface(); 75 | 76 | void clearBuffer(size_t pColor = 0); 77 | 78 | void draw(const int16 pSkipX = 16, const int16 pSkipY = 16); // Draw image to SDL Surface 79 | void copyFrom(const cSurface* pFrom); 80 | void mergeFrom(const cSurface* pFrom); 81 | void mergeSurfaceBuffer(const cSurface* pFrom); 82 | 83 | bool LoadPng(const std::string &pFile); 84 | 85 | void Save(); 86 | void Restore(); 87 | 88 | void palette_SetToBlack(); 89 | bool palette_FadeTowardNew(); 90 | void palette_SetFromNew(); 91 | 92 | void paletteSet( cPalette* pPalette, uint32 pColorID = 0, uint32 pColors = g_MaxColors, bool pUseNow = false ); 93 | 94 | void paletteNew_SetToBlack(); 95 | 96 | inline SDL_Surface* GetSurface() const { return mSDLSurface; } 97 | inline SDL_Texture* GetTexture() const { return mTexture; }; 98 | inline uint8* GetSurfaceBuffer() const { return mSurfaceBuffer; } 99 | inline size_t GetSurfaceBufferSize() const { return mSurfaceBufferSize; } 100 | 101 | inline size_t GetWidth() const { return mWidth; } 102 | inline size_t GetHeight() const { return mHeight; } 103 | 104 | inline bool isPaletteAdjusting() const { return mPaletteAdjusting; } 105 | inline void resetPaletteAdjusting() { mPaletteAdjusting = false; } 106 | }; 107 | -------------------------------------------------------------------------------- /Source/Tiles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | const std::vector mTileTypes = { 26 | { eTileTypes_Jungle, "jun", "Jungle" }, 27 | { eTileTypes_Desert, "des", "Desert" }, 28 | { eTileTypes_Ice, "ice", "Ice" }, 29 | { eTileTypes_Moors, "mor", "Moors" }, 30 | { eTileTypes_Int, "int", "Interior" }, 31 | { eTileTypes_Hid, "hid", "Hid" }, // Unknown 32 | { eTileTypes_AFX, "afx", "AmigaFormat" } // Amiga Format Christmas Special 33 | }; 34 | 35 | const int16 TILE_WIDTH_PIXELS = 16; 36 | const int16 TILE_HEIGHT_PIXELS = 16; 37 | 38 | const int16* mTiles_Indestructible[] = { 39 | mTiles_Indestructible_Jungle, // JUN 40 | mTiles_Indestructible_Desert, // DES 41 | mTiles_Indestructible_Ice, // ICE 42 | mTiles_Indestructible_Moors, // MOR 43 | mTiles_Indestructible_Internal, // INT 44 | mTiles_Indestructible_Jungle, // HID 45 | mTiles_Indestructible_Ice // AFX 46 | }; 47 | 48 | const int8 mTiles_NotFlyable[] = { 49 | 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1 50 | }; 51 | 52 | const int8 mTiles_NotDriveable[] = { 53 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 54 | }; 55 | 56 | const int8 mTiles_NotWalkable[] = { 57 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 58 | }; 59 | 60 | const int16 mTiles_Indestructible_Jungle[] = { 61 | 267, 268, 269, 287, 288, 289, 307, 308, 309, 98, 62 | 177, 217, -1 63 | }; 64 | 65 | const int16 mTiles_Indestructible_Desert[] = { 66 | 9, 10, 11, 29, 30, 31, 50, -1 67 | }; 68 | 69 | const int16 mTiles_Indestructible_Ice[] = { 70 | 307, 308, 309, 327, 328, 329, 71 | 348, 349, 363, 378, 379, -1 72 | }; 73 | 74 | const int16 mTiles_Indestructible_Moors[] = { 75 | 257, 276, 277, 160, 161, 162, 180, 76 | 181, 182, 201, 306, 384, 398, -1 77 | }; 78 | 79 | const int16 mTiles_Indestructible_Internal[] = { 80 | 23, 40, 41, 42, 63, 103, 50, 51, 70, 81 | 71, 90, 91, 346, 331, 351, -1, 82 | }; 83 | -------------------------------------------------------------------------------- /Source/Tiles.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | enum eTerrainFeature { 24 | eTerrainFeature_Land = 0, 25 | eTerrainFeature_Rocky = 1, 26 | eTerrainFeature_Rocky2 = 2, 27 | eTerrainFeature_Block = 3, 28 | eTerrainFeature_QuickSand = 4, 29 | eTerrainFeature_WaterEdge = 5, 30 | eTerrainFeature_Water = 6, 31 | eTerrainFeature_Snow = 7, // Reduce unit speed 32 | eTerrainFeature_QuickSandEdge = 8, 33 | eTerrainFeature_Drop = 9, 34 | eTerrainFeature_Drop2 = 0x0A, 35 | eTerrainFeature_Sink = 0x0B, 36 | eTerrainFeature_C = 0x0C, 37 | eTerrainFeature_D = 0x0D, 38 | eTerrainFeature_Jump = 0x0E 39 | }; 40 | 41 | struct sTileType { 42 | eTileTypes mType; 43 | std::string mName; 44 | std::string mFullName; 45 | }; 46 | 47 | struct sTileTrack { 48 | uint16_t X; 49 | uint16_t Y; 50 | uint8_t Track; 51 | 52 | sTileTrack(uint16_t pX,uint16_t pY, uint8_t pTrack) { 53 | X = pX; 54 | Y = pY; 55 | Track = pTrack; 56 | } 57 | }; 58 | 59 | struct sStructureTile { 60 | int16 mX; 61 | int16 mY; 62 | uint16 mTileID; 63 | 64 | sStructureTile(int16 pMapX, int16 pMapY, uint16 pID) { 65 | mX = pMapX; 66 | mY = pMapY; 67 | mTileID = pID; 68 | } 69 | 70 | }; 71 | 72 | struct sStructureSprite { 73 | int16 mX; 74 | int16 mY; 75 | uint16 mSpriteID; 76 | 77 | sStructureSprite(int16 pTileX, int16 pTileY, uint16 pSpriteID) { 78 | mX = pTileX; 79 | mY = pTileY; 80 | mSpriteID = pSpriteID; 81 | } 82 | }; 83 | 84 | struct sStructure { 85 | std::vector mTiles; 86 | std::vector mSprites; 87 | 88 | int16 MaxWidth() const { 89 | int16 Width = 0; 90 | 91 | for (auto Tile : mTiles) { 92 | if (Width < Tile.mX) 93 | Width = Tile.mX; 94 | } 95 | return Width; 96 | } 97 | 98 | int16 MaxHeight() const { 99 | int16 Height = 0; 100 | 101 | for (auto Tile : mTiles) { 102 | if (Height < Tile.mY) 103 | Height = Tile.mY; 104 | } 105 | return Height; 106 | } 107 | }; 108 | 109 | extern const int8 mTiles_NotFlyable[]; 110 | extern const int8 mTiles_NotDriveable[]; 111 | extern const int8 mTiles_NotWalkable[]; 112 | 113 | extern const int16 mTiles_Indestructible_Jungle[]; 114 | extern const int16 mTiles_Indestructible_Desert[]; 115 | extern const int16 mTiles_Indestructible_Ice[]; 116 | extern const int16 mTiles_Indestructible_Moors[]; 117 | extern const int16 mTiles_Indestructible_Internal[]; 118 | 119 | extern const int16* mTiles_Indestructible[]; 120 | 121 | extern const std::vector mTileTypes; 122 | 123 | extern const int16 TILE_WIDTH_PIXELS; 124 | extern const int16 TILE_HEIGHT_PIXELS; -------------------------------------------------------------------------------- /Source/Types.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #ifdef WIN64 24 | typedef unsigned char uint8; //!< One byte 25 | typedef unsigned short uint16; //!< Two bytes 26 | typedef unsigned int uint32; //!< Four bytes 27 | typedef unsigned long long int uint64; //!< Eight bytes 28 | 29 | typedef signed char int8; //!< One byte 30 | typedef signed short int16; //!< Two bytes 31 | typedef signed int int32; //!< Four bytes 32 | typedef signed long long int int64; //!< Eight bytes 33 | 34 | 35 | #else 36 | typedef unsigned char uint8; //!< One byte 37 | typedef unsigned short uint16; //!< Two bytes 38 | typedef unsigned int uint32; //!< Four bytes 39 | typedef unsigned long uint64; //!< Eight bytes 40 | 41 | typedef signed char int8; //!< One byte 42 | typedef signed short int16; //!< Two bytes 43 | typedef signed int int32; //!< Four bytes 44 | typedef signed long int64; //!< Eight bytes 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Source/UnitTesting.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cUnitTesting { 24 | 25 | protected: 26 | std::string getCurrentTestFileName(); 27 | std::string getCurrentTestName(); 28 | 29 | void setDemoName(); 30 | 31 | void EngineSetup(); 32 | bool RunTests(const std::string pCampaign); 33 | 34 | public: 35 | 36 | cUnitTesting(); 37 | bool Start(); 38 | }; -------------------------------------------------------------------------------- /Source/Utils/SimplexIslands.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SimplexIslands.hpp" 3 | 4 | SimplexIslands::SimplexIslands() { 5 | 6 | grad3 = { 7 | {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, 8 | {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, 9 | {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1} 10 | }; 11 | 12 | grad4 = { 13 | {0,1,1,1},{0,1,1,-1},{0,1,-1,1},{0,1,-1,-1}, 14 | {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, 15 | {1,0,1,1},{1,0,1,-1},{1,0,-1,1},{1,0,-1,-1}, 16 | {-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1}, 17 | {1,1,0,1},{1,1,0,-1},{1,-1,0,1},{1,-1,0,-1}, 18 | {-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1}, 19 | {1,1,1,0},{1,1,-1,0},{1,-1,1,0},{1,-1,-1,0}, 20 | {-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0} }; 21 | 22 | for (int i = 0; i < 512; i++) 23 | { 24 | perm[i] = p[i & 255]; 25 | permMod12[i] = (short)(perm[i] % 12); 26 | } 27 | 28 | // Skewing and unskewing factors for 2, 3, and 4 dimensions 29 | F2 = 0.5*(sqrt(3.0) - 1.0); 30 | G2 = (3.0 - sqrt(3.0)) / 6.0; 31 | F3 = 1.0 / 3.0; 32 | G3 = 1.0 / 6.0; 33 | F4 = (sqrt(5.0) - 1.0) / 4.0; 34 | G4 = (5.0 - sqrt(5.0)) / 20.0; 35 | 36 | 37 | } 38 | 39 | short SimplexIslands::pbak[] = { 151,160,137,91,90,15, 40 | 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 41 | 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 42 | 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 43 | 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 44 | 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 45 | 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 46 | 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 47 | 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 48 | 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 49 | 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 50 | 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 51 | 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 }; 52 | 53 | short SimplexIslands::p[] = { 151,160,137,91,90,15, 54 | 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 55 | 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 56 | 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 57 | 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 58 | 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 59 | 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 60 | 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 61 | 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 62 | 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 63 | 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 64 | 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 65 | 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 }; -------------------------------------------------------------------------------- /Source/Utils/SimplexNoise.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SimplexNoise.h 3 | * @brief A Perlin Simplex Noise C++ Implementation (1D, 2D, 3D). 4 | * 5 | * Copyright (c) 2014-2018 Sebastien Rombauts (sebastien.rombauts@gmail.com) 6 | * 7 | * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt 8 | * or copy at http://opensource.org/licenses/MIT) 9 | */ 10 | #pragma once 11 | 12 | #include // size_t 13 | 14 | /** 15 | * @brief A Perlin Simplex Noise C++ Implementation (1D, 2D, 3D, 4D). 16 | */ 17 | class SimplexNoise { 18 | public: 19 | // 1D Perlin simplex noise 20 | float noiseX(float x); 21 | // 2D Perlin simplex noise 22 | float noiseXY(float x, float y); 23 | // 3D Perlin simplex noise 24 | float noiseXYZ(float x, float y, float z); 25 | 26 | // Fractal/Fractional Brownian Motion (fBm) noise summation 27 | float fractalX(size_t octaves, float x); 28 | float fractalXY(size_t octaves, float x, float y); 29 | float fractalXYZ(size_t octaves, float x, float y, float z); 30 | 31 | 32 | /** 33 | * Constructor of to initialize a fractal noise summation 34 | * 35 | * @param[in] frequency Frequency ("width") of the first octave of noise (default to 1.0) 36 | * @param[in] amplitude Amplitude ("height") of the first octave of noise (default to 1.0) 37 | * @param[in] lacunarity Lacunarity specifies the frequency multiplier between successive octaves (default to 2.0). 38 | * @param[in] persistence Persistence is the loss of amplitude between successive octaves (usually 1/lacunarity) 39 | */ 40 | explicit SimplexNoise(float frequency = 1.0f, 41 | float lacunarity = 2.0f, 42 | float persistence = 0.5f) : 43 | mFrequency(frequency), 44 | mAmplitude(frequency), 45 | mLacunarity(lacunarity), 46 | mPersistence(persistence) { 47 | } 48 | 49 | void normalizeArray(std::vector>& pNoise); 50 | std::vector> create( size_t pWidth, size_t pHeight, size_t pOctaves ); 51 | 52 | private: 53 | // Parameters of Fractional Brownian Motion (fBm) : sum of N "octaves" of noise 54 | float mFrequency; ///< Frequency ("width") of the first octave of noise (default to 1.0) 55 | float mAmplitude; ///< Amplitude ("height") of the first octave of noise (default to 1.0) 56 | float mLacunarity; ///< Lacunarity specifies the frequency multiplier between successive octaves (default to 2.0). 57 | float mPersistence; ///< Persistence is the loss of amplitude between successive octaves (usually 1/lacunarity) 58 | }; 59 | -------------------------------------------------------------------------------- /Source/Utils/duk_trans_socket.h: -------------------------------------------------------------------------------- 1 | #if !defined(DUK_TRANS_SOCKET_H_INCLUDED) 2 | #define DUK_TRANS_SOCKET_H_INCLUDED 3 | 4 | #include "duktape.h" 5 | 6 | void duk_trans_socket_init(void); 7 | void duk_trans_socket_finish(void); 8 | void duk_trans_socket_waitconn(void); 9 | duk_size_t duk_trans_socket_read_cb(void *udata, char *buffer, duk_size_t length); 10 | duk_size_t duk_trans_socket_write_cb(void *udata, const char *buffer, duk_size_t length); 11 | duk_size_t duk_trans_socket_peek_cb(void *udata); 12 | void duk_trans_socket_read_flush_cb(void *udata); 13 | void duk_trans_socket_write_flush_cb(void *udata); 14 | 15 | #endif /* DUK_TRANS_SOCKET_H_INCLUDED */ 16 | -------------------------------------------------------------------------------- /Source/Utils/dukglue/detail_constructor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "detail_stack.h" 4 | #include "detail_traits.h" 5 | 6 | namespace dukglue { 7 | namespace detail { 8 | 9 | template 10 | static duk_ret_t call_native_constructor(duk_context* ctx) 11 | { 12 | if (!duk_is_constructor_call(ctx)) { 13 | duk_error(ctx, DUK_RET_TYPE_ERROR, "Constructor must be called with new T()."); 14 | return DUK_RET_TYPE_ERROR; 15 | } 16 | 17 | // construct the new instance 18 | auto constructor_args = dukglue::detail::get_stack_values(ctx); 19 | Cls* obj = dukglue::detail::apply_constructor(std::move(constructor_args)); 20 | 21 | duk_push_this(ctx); 22 | 23 | // make the new script object keep the pointer to the new object instance 24 | duk_push_pointer(ctx, obj); 25 | duk_put_prop_string(ctx, -2, "\xFF" "obj_ptr"); 26 | 27 | // register it 28 | if (!managed) 29 | dukglue::detail::RefManager::register_native_object(ctx, obj); 30 | 31 | duk_pop(ctx); // pop this 32 | 33 | return 0; 34 | } 35 | 36 | template 37 | static duk_ret_t managed_finalizer(duk_context* ctx) 38 | { 39 | duk_get_prop_string(ctx, 0, "\xFF" "obj_ptr"); 40 | Cls* obj = (Cls*) duk_require_pointer(ctx, -1); 41 | duk_pop(ctx); // pop obj_ptr 42 | 43 | if (obj != NULL) { 44 | delete obj; 45 | 46 | // for safety, set the pointer to undefined 47 | duk_push_undefined(ctx); 48 | duk_put_prop_string(ctx, 0, "\xFF" "obj_ptr"); 49 | } 50 | 51 | return 0; 52 | } 53 | 54 | template 55 | static duk_ret_t call_native_deleter(duk_context* ctx) 56 | { 57 | duk_push_this(ctx); 58 | duk_get_prop_string(ctx, -1, "\xFF" "obj_ptr"); 59 | 60 | if (!duk_is_pointer(ctx, -1)) { 61 | duk_error(ctx, DUK_RET_REFERENCE_ERROR, "Object has already been invalidated; cannot delete."); 62 | return DUK_RET_REFERENCE_ERROR; 63 | } 64 | 65 | Cls* obj = static_cast(duk_require_pointer(ctx, -1)); 66 | dukglue_invalidate_object(ctx, obj); 67 | delete obj; 68 | 69 | duk_pop_2(ctx); 70 | return 0; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Source/Utils/dukglue/detail_function.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "detail_stack.h" 4 | 5 | namespace dukglue 6 | { 7 | namespace detail 8 | { 9 | // This struct can be used to generate a Duktape C function that 10 | // pulls the argument values off the stack (with type checking), 11 | // calls the appropriate function with them, and puts the function's 12 | // return value (if any) onto the stack. 13 | template 14 | struct FuncInfoHolder 15 | { 16 | typedef RetType(*FuncType)(Ts...); 17 | 18 | template 19 | struct FuncCompiletime 20 | { 21 | // The function to call is embedded into call_native_function at 22 | // compile-time through template magic. 23 | // Performance is so similar to run-time function calls that 24 | // this is not recommended due to the ugly syntax it requires. 25 | static duk_ret_t call_native_function(duk_context* ctx) 26 | { 27 | auto bakedArgs = dukglue::detail::get_stack_values(ctx); 28 | actually_call(ctx, bakedArgs); 29 | return std::is_void::value ? 0 : 1; 30 | } 31 | 32 | private: 33 | // this mess is to support functions with void return values 34 | 35 | template 36 | static typename std::enable_if::value>::type actually_call(duk_context* ctx, const std::tuple& args) 37 | { 38 | // ArgStorage has some static_asserts in it that validate value types, 39 | // so we typedef it to force ArgStorage to compile and run the asserts 40 | typedef typename dukglue::types::ArgStorage::type ValidateReturnType; 41 | 42 | RetType return_val = dukglue::detail::apply_fp(funcToCall, args); 43 | 44 | using namespace dukglue::types; 45 | DukType::type>::template push(ctx, std::move(return_val)); 46 | } 47 | 48 | template 49 | static typename std::enable_if::value>::type actually_call(duk_context* ctx, const std::tuple& args) 50 | { 51 | dukglue::detail::apply_fp(funcToCall, args); 52 | } 53 | }; 54 | 55 | struct FuncRuntime 56 | { 57 | // Pull the address of the function to call from the 58 | // Duktape function object at run time. 59 | static duk_ret_t call_native_function(duk_context* ctx) 60 | { 61 | duk_push_current_function(ctx); 62 | duk_get_prop_string(ctx, -1, "\xFF" "func_ptr"); 63 | void* fp_void = duk_require_pointer(ctx, -1); 64 | if (fp_void == NULL) { 65 | duk_error(ctx, DUK_RET_TYPE_ERROR, "what even"); 66 | return DUK_RET_TYPE_ERROR; 67 | } 68 | 69 | duk_pop_2(ctx); 70 | 71 | static_assert(sizeof(RetType(*)(Ts...)) == sizeof(void*), "Function pointer and data pointer are different sizes"); 72 | RetType(*funcToCall)(Ts...) = reinterpret_cast(fp_void); 73 | 74 | actually_call(ctx, funcToCall, dukglue::detail::get_stack_values(ctx)); 75 | return std::is_void::value ? 0 : 1; 76 | } 77 | 78 | // this mess is to support functions with void return values 79 | template 80 | static typename std::enable_if::value>::type actually_call(duk_context* ctx, RetType(*funcToCall)(Ts...), const std::tuple& args) 81 | { 82 | // ArgStorage has some static_asserts in it that validate value types, 83 | // so we typedef it to force ArgStorage to compile and run the asserts 84 | typedef typename dukglue::types::ArgStorage::type ValidateReturnType; 85 | 86 | RetType return_val = dukglue::detail::apply_fp(funcToCall, args); 87 | 88 | using namespace dukglue::types; 89 | DukType::type>::template push(ctx, std::move(return_val)); 90 | } 91 | 92 | template 93 | static typename std::enable_if::value>::type actually_call(duk_context* ctx, RetType(*funcToCall)(Ts...), const std::tuple& args) 94 | { 95 | dukglue::detail::apply_fp(funcToCall, args); 96 | } 97 | }; 98 | }; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Source/Utils/dukglue/detail_stack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "detail_traits.h" 6 | #include "detail_types.h" 7 | 8 | #include 9 | 10 | namespace dukglue 11 | { 12 | namespace detail 13 | { 14 | // Helper to get the argument tuple type, with correct storage types. 15 | template 16 | struct ArgsTuple { 17 | typedef std::tuple::type...> type; 18 | }; 19 | 20 | // Helper to get argument indices. 21 | // Call read for every Ts[i], for matching argument index Index[i]. 22 | // The traits::index_tuple is used for type inference. 23 | // A concrete example: 24 | // get_values(duktape_context) 25 | // get_values_helper<{int, bool}, {0, 1}>(ctx, ignored) 26 | // std::make_tuple(read(ctx, 0), read(ctx, 1)) 27 | template 28 | typename ArgsTuple::type get_stack_values_helper(duk_context* ctx, dukglue::detail::index_tuple) 29 | { 30 | using namespace dukglue::types; 31 | return std::forward_as_tuple(DukType::type>::template read::type>(ctx, Indexes)...); 32 | } 33 | 34 | // Returns an std::tuple of the values asked for in the template parameters. 35 | // Values will remain on the stack. 36 | // Values are indexed from the bottom of the stack up (0, 1, ...). 37 | // If a value does not exist or does not have the expected type, an error is thrown 38 | // through Duktape (with duk_error(...)), and the function does not return 39 | template 40 | typename ArgsTuple::type get_stack_values(duk_context* ctx) 41 | { 42 | // We need the argument indices for read_value, and we need to be able 43 | // to unpack them as a template argument to match Ts. 44 | // So, we use traits::make_indexes, which returns a traits::index_tuple<0, 1, 2, ...> object. 45 | // We pass that into a helper function so we can put a name to that <0, 1, ...> template argument. 46 | // Here, the type of Args isn't important, the length of it is. 47 | auto indices = typename dukglue::detail::make_indexes::type(); 48 | return get_stack_values_helper(ctx, indices); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Source/Utils/dukglue/detail_traits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace dukglue 6 | { 7 | namespace detail 8 | { 9 | ////////////////////////////////////////////////////////////////////////////////////////////// 10 | 11 | // Credit to LuaState for this code: 12 | // https://github.com/AdUki/LuaState/blob/master/include/Traits.h 13 | 14 | template struct index_tuple {}; 15 | 16 | template 17 | struct make_indexes_impl; 18 | 19 | template 20 | struct make_indexes_impl, T, Types...> 21 | { 22 | typedef typename make_indexes_impl, Types...>::type type; 23 | }; 24 | 25 | template 26 | struct make_indexes_impl > 27 | { 28 | typedef index_tuple type; 29 | }; 30 | 31 | template 32 | struct make_indexes : make_indexes_impl<0, index_tuple<>, Types...> 33 | {}; 34 | 35 | ////////////////////////////////////////////////////////////////////////////////////////////// 36 | 37 | template 38 | struct indexes {}; 39 | 40 | template 41 | struct indexes_builder : indexes_builder {}; 42 | 43 | template 44 | struct indexes_builder<0, Is...> { 45 | typedef indexes index; 46 | }; 47 | 48 | ////////////////////////////////////////////////////////////////////////////////////////////// 49 | 50 | // This mess is used to use function arugments stored in an std::tuple to an 51 | // std::function, function pointer, or method. 52 | 53 | // std::function 54 | template 55 | Ret apply_helper(std::function pf, index_tuple< Indexes... >, std::tuple&& tup) 56 | { 57 | return pf(std::forward(std::get(tup))...); 58 | } 59 | 60 | template 61 | Ret apply(std::function pf, const std::tuple& tup) 62 | { 63 | return apply_helper(pf, typename make_indexes::type(), std::tuple(tup)); 64 | } 65 | 66 | // function pointer 67 | template 68 | Ret apply_fp_helper(Ret(*pf)(Args...), index_tuple< Indexes... >, std::tuple&& tup) 69 | { 70 | return pf(std::forward(std::get(tup))...); 71 | } 72 | 73 | template 74 | Ret apply_fp(Ret(*pf)(Args...), const std::tuple& tup) 75 | { 76 | return apply_fp_helper(pf, typename make_indexes::type(), std::tuple(tup)); 77 | } 78 | 79 | // method pointer 80 | template 81 | Ret apply_method_helper(Ret(Cls::*pf)(Args...), index_tuple< Indexes... >, Cls* obj, std::tuple&& tup) 82 | { 83 | return (*obj.*pf)(std::forward(std::get(tup))...); 84 | } 85 | 86 | template 87 | Ret apply_method(Ret(Cls::*pf)(Args...), Cls* obj, const std::tuple& tup) 88 | { 89 | return apply_method_helper(pf, typename make_indexes::type(), obj, std::tuple(tup)); 90 | } 91 | 92 | // const method pointer 93 | template 94 | Ret apply_method_helper(Ret(Cls::*pf)(Args...) const, index_tuple< Indexes... >, Cls* obj, std::tuple&& tup) 95 | { 96 | return (*obj.*pf)(std::forward(std::get(tup))...); 97 | } 98 | 99 | template 100 | Ret apply_method(Ret(Cls::*pf)(Args...) const, Cls* obj, const std::tuple& tup) 101 | { 102 | return apply_method_helper(pf, typename make_indexes::type(), obj, std::tuple(tup)); 103 | } 104 | 105 | // constructor 106 | template 107 | Cls* apply_constructor_helper(index_tuple< Indexes... >, std::tuple&& tup) 108 | { 109 | return new Cls(std::forward(std::get(tup))...); 110 | } 111 | 112 | template 113 | Cls* apply_constructor(const std::tuple& tup) 114 | { 115 | return apply_constructor_helper(typename make_indexes::type(), std::tuple(tup)); 116 | } 117 | 118 | ////////////////////////////////////////////////////////////////////////////////////////////// 119 | 120 | 121 | } 122 | } -------------------------------------------------------------------------------- /Source/Utils/dukglue/detail_typeinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace dukglue 6 | { 7 | namespace detail 8 | { 9 | // same as duk_get_type_name, which is private for some reason *shakes fist* 10 | static const char* get_type_name(duk_int_t type_idx) { 11 | static const char* names[] = { 12 | "none", 13 | "undefined", 14 | "null", 15 | "boolean", 16 | "number", 17 | "string", 18 | "object", 19 | "buffer", 20 | "pointer", 21 | "lightfunc" 22 | }; 23 | 24 | if (type_idx >= 0 && type_idx < sizeof(names) / sizeof(names[0])) 25 | return names[type_idx]; 26 | else 27 | return "unknown"; 28 | } 29 | 30 | class TypeInfo 31 | { 32 | public: 33 | TypeInfo(std::type_index&& idx) : index_(idx), base_(nullptr) {} 34 | TypeInfo(const TypeInfo& rhs) : index_(rhs.index_), base_(rhs.base_) {} 35 | 36 | inline void set_base(TypeInfo* base) { 37 | base_ = base; 38 | } 39 | 40 | template 41 | bool can_cast() const { 42 | if (index_ == typeid(T)) 43 | return true; 44 | 45 | if (base_) 46 | return base_->can_cast(); 47 | 48 | return false; 49 | } 50 | 51 | inline bool operator<(const TypeInfo& rhs) const { return index_ < rhs.index_; } 52 | inline bool operator<=(const TypeInfo& rhs) const { return index_ <= rhs.index_; } 53 | inline bool operator>(const TypeInfo& rhs) const { return index_ > rhs.index_; } 54 | inline bool operator>=(const TypeInfo& rhs) const { return index_ >= rhs.index_; } 55 | inline bool operator==(const TypeInfo& rhs) const { return index_ == rhs.index_; } 56 | inline bool operator!=(const TypeInfo& rhs) const { return index_ != rhs.index_; } 57 | 58 | private: 59 | std::type_index index_; 60 | TypeInfo* base_; 61 | }; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Source/Utils/dukglue/dukexception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class DukException : public std::exception 7 | { 8 | public: 9 | virtual const char* what() const noexcept override 10 | { 11 | return mMsg.c_str(); 12 | } 13 | 14 | template 15 | DukException& operator<<(T rhs) 16 | { 17 | std::stringstream ss; 18 | ss << mMsg << rhs; 19 | mMsg = ss.str(); 20 | return *this; 21 | } 22 | 23 | protected: 24 | std::string mMsg; 25 | }; 26 | 27 | class DukErrorException : public DukException 28 | { 29 | public: 30 | DukErrorException(duk_context* ctx, int return_code, bool pop_error = true) { 31 | if (return_code != 0) { 32 | duk_get_prop_string(ctx, -1, "stack"); 33 | mMsg = duk_safe_to_string(ctx, -1); 34 | duk_pop(ctx); 35 | 36 | if (pop_error) 37 | duk_pop(ctx); 38 | } 39 | } 40 | }; -------------------------------------------------------------------------------- /Source/Utils/dukglue/dukglue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "register_function.h" 4 | #include "register_class.h" 5 | #include "register_property.h" 6 | #include "public_util.h" 7 | #include "dukvalue.h" -------------------------------------------------------------------------------- /Source/Utils/dukglue/register_function.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "detail_function.h" 4 | 5 | // Register a function, embedding the function address at compile time. 6 | // According to benchmarks, there's really not much reason to do this 7 | // (inconsistent 2-3% performance improvement for a 10,000 function call stress test averaged over 100 runs), 8 | // since it has much uglier syntax and may bloat executable size if you have many functions with identical signatures. 9 | template 10 | void dukglue_register_function_compiletime(duk_context* ctx, RetType(*)(Ts...), const char* name) 11 | { 12 | static_assert(std::is_same::value, 13 | "Mismatching function pointer template parameter and function pointer argument types. " 14 | "Try: dukglue_register_function(ctx, \"funcName\", func)"); 15 | 16 | duk_c_function evalFunc = dukglue::detail::FuncInfoHolder::template FuncActual::call_native_function; 17 | 18 | duk_push_c_function(ctx, evalFunc, sizeof...(Ts)); 19 | duk_put_global_string(ctx, name); 20 | } 21 | 22 | // Register a function. 23 | template 24 | void dukglue_register_function(duk_context* ctx, RetType(*funcToCall)(Ts...), const char* name) 25 | { 26 | duk_c_function evalFunc = dukglue::detail::FuncInfoHolder::FuncRuntime::call_native_function; 27 | 28 | duk_push_c_function(ctx, evalFunc, sizeof...(Ts)); 29 | 30 | static_assert(sizeof(RetType(*)(Ts...)) == sizeof(void*), "Function pointer and data pointer are different sizes"); 31 | duk_push_pointer(ctx, reinterpret_cast(funcToCall)); 32 | duk_put_prop_string(ctx, -2, "\xFF" "func_ptr"); 33 | 34 | duk_put_global_string(ctx, name); 35 | } 36 | -------------------------------------------------------------------------------- /Source/Utils/dukglue/register_property.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "detail_method.h" 4 | 5 | // const getter, setter 6 | template 7 | void dukglue_register_property(duk_context* ctx, 8 | RetT(Cls::*getter)() const, 9 | void(Cls::*setter)(ArgT), 10 | const char* name) 11 | { 12 | dukglue_register_property(ctx, getter, setter, name); 13 | } 14 | 15 | // const getter, no setter 16 | template 17 | void dukglue_register_property(duk_context* ctx, 18 | RetT(Cls::*getter)() const, 19 | std::nullptr_t setter, 20 | const char* name) 21 | { 22 | dukglue_register_property(ctx, getter, setter, name); 23 | } 24 | 25 | // non-const getter, setter 26 | template 27 | void dukglue_register_property(duk_context* ctx, 28 | RetT(Cls::*getter)(), 29 | void(Cls::*setter)(ArgT), 30 | const char* name) 31 | { 32 | dukglue_register_property(ctx, getter, setter, name); 33 | } 34 | 35 | // non-const getter, no setter 36 | template 37 | void dukglue_register_property(duk_context* ctx, 38 | RetT(Cls::*getter)(), 39 | std::nullptr_t setter, 40 | const char* name) 41 | { 42 | dukglue_register_property(ctx, getter, setter, name); 43 | } 44 | 45 | // no getter, setter 46 | template 47 | void dukglue_register_property(duk_context* ctx, 48 | std::nullptr_t getter, 49 | void(Cls::*setter)(ArgT), 50 | const char* name) 51 | { 52 | dukglue_register_property(ctx, getter, setter, name); 53 | } 54 | 55 | // no getter, no setter 56 | template 57 | void dukglue_register_property(duk_context* ctx, std::nullptr_t getter, std::nullptr_t setter, const char* name) 58 | { 59 | // strictly speaking I think duktape can probably handle neither 60 | // (according to the wonderful API docs), but I don't know why you 61 | // would want to do this in the first place 62 | static_assert(std::is_void::value, "Must have getter or setter"); 63 | } 64 | 65 | inline duk_ret_t dukglue_throw_error(duk_context* ctx) 66 | { 67 | duk_error(ctx, DUK_ERR_TYPE_ERROR, "Property does not have getter or setter."); 68 | } 69 | 70 | template 71 | void dukglue_register_property(duk_context* ctx, 72 | typename std::conditional::type getter, 73 | void(Cls::*setter)(ArgT), 74 | const char* name) 75 | { 76 | using namespace dukglue::detail; 77 | typedef MethodInfo GetterMethodInfo; 78 | typedef MethodInfo SetterMethodInfo; 79 | 80 | ProtoManager::push_prototype(ctx); 81 | 82 | // push key 83 | duk_push_string(ctx, name); 84 | 85 | // push getter 86 | if (getter != nullptr) { 87 | duk_c_function method_func = GetterMethodInfo::MethodRuntime::call_native_method; 88 | 89 | duk_push_c_function(ctx, method_func, 0); 90 | 91 | duk_push_pointer(ctx, new typename GetterMethodInfo::MethodHolder{ getter }); 92 | duk_put_prop_string(ctx, -2, "\xFF" "method_holder"); // consumes raw method pointer 93 | 94 | // make sure we free the method_holder when this function is removed 95 | duk_push_c_function(ctx, GetterMethodInfo::MethodRuntime::finalize_method, 1); 96 | duk_set_finalizer(ctx, -2); 97 | } else { 98 | duk_push_c_function(ctx, dukglue_throw_error, 1); 99 | } 100 | 101 | if (setter != nullptr) { 102 | duk_c_function method_func = SetterMethodInfo::MethodRuntime::call_native_method; 103 | 104 | duk_push_c_function(ctx, method_func, 1); 105 | 106 | duk_push_pointer(ctx, new typename SetterMethodInfo::MethodHolder{ setter }); 107 | duk_put_prop_string(ctx, -2, "\xFF" "method_holder"); // consumes raw method pointer 108 | 109 | // make sure we free the method_holder when this function is removed 110 | duk_push_c_function(ctx, SetterMethodInfo::MethodRuntime::finalize_method, 1); 111 | duk_set_finalizer(ctx, -2); 112 | } else { 113 | duk_push_c_function(ctx, dukglue_throw_error, 1); 114 | } 115 | 116 | duk_uint_t flags = DUK_DEFPROP_HAVE_GETTER 117 | | DUK_DEFPROP_HAVE_SETTER 118 | | DUK_DEFPROP_HAVE_CONFIGURABLE /* set not configurable (from JS) */ 119 | | DUK_DEFPROP_FORCE /* allow overriding built-ins and previously defined properties */; 120 | 121 | duk_def_prop(ctx, -4, flags); 122 | duk_pop(ctx); // pop prototype 123 | } 124 | -------------------------------------------------------------------------------- /Source/Utils/md5.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Christophe Devine c.devine@cr0.net 3 | http://www.cr0.net:8040/code/crypto/ 4 | */ 5 | 6 | typedef struct 7 | { 8 | uint32 total[2]; 9 | uint32 state[4]; 10 | uint8 buffer[64]; 11 | } 12 | md5_context; 13 | 14 | void md5_starts( md5_context *ctx ); 15 | void md5_update( md5_context *ctx, uint8 *input, uint32 length ); 16 | void md5_finish( md5_context *ctx, uint8 digest[16] ); 17 | -------------------------------------------------------------------------------- /Source/Utils/pseudorand.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cPseudorand { 24 | private: 25 | int16 mRandom_0; 26 | int16 mRandom_1; 27 | int16 mRandom_2; 28 | int16 mRandom_3; 29 | 30 | int16 mStartingSeed; 31 | public: 32 | 33 | cPseudorand(int16 pSeed = 0) { 34 | if (!pSeed) { 35 | const time_t now = time(0); 36 | tm* ltm; 37 | #ifndef _WIN32 38 | ltm = localtime(&now); 39 | #else 40 | ltm = new tm(); 41 | localtime_s(ltm, &now); 42 | #endif 43 | pSeed = tool_DecimalToBinaryCodedDecimal(ltm->tm_sec); 44 | pSeed |= tool_DecimalToBinaryCodedDecimal(ltm->tm_min) << 8; 45 | pSeed += 0x40B; 46 | #ifdef _WIN32 47 | delete ltm; 48 | #endif 49 | } 50 | setSeed(pSeed); 51 | } 52 | 53 | void setSeed(int16 pSeed) { 54 | mStartingSeed = pSeed; 55 | 56 | mRandom_0 = mStartingSeed; 57 | mRandom_1 = -mStartingSeed; 58 | mRandom_2 = 1; 59 | mRandom_3 = 0; 60 | } 61 | 62 | void setSeed(int16 pSeed0, int16 pSeed1, int16 pSeed2, int16 pSeed3 ) { 63 | mStartingSeed = 0; 64 | 65 | mRandom_0 = pSeed0; 66 | mRandom_1 = pSeed1; 67 | mRandom_2 = pSeed2; 68 | mRandom_3 = pSeed3; 69 | } 70 | 71 | void getSeeds(int16& pSeed0, int16& pSeed1, int16& pSeed2, int16& pSeed3) { 72 | pSeed0 = mRandom_0; 73 | pSeed1 = mRandom_1; 74 | pSeed2 = mRandom_2; 75 | pSeed3 = mRandom_3; 76 | } 77 | 78 | int16 getStartingSeed() const { 79 | return mStartingSeed; 80 | } 81 | 82 | 83 | float getf(float pMin, float pMax) { 84 | 85 | return pMin + static_cast (getu() % RAND_MAX) / (static_cast (RAND_MAX) / (pMax - pMin)); 86 | } 87 | 88 | uint16 getu() { 89 | return (uint16)get(); 90 | } 91 | 92 | uint16 getu(size_t pMin, size_t pMax) { 93 | return (uint16)(pMin + (getu() % static_cast(pMax - pMin + 1))); 94 | } 95 | 96 | int16 get() { 97 | int16 Data0 = mRandom_0; 98 | int16 Data2 = mRandom_1; 99 | int16 Data4 = mRandom_2; 100 | int16 Data6 = mRandom_3; 101 | 102 | uint32 Dat4 = Data4 | (Data6 << 16); 103 | uint8 CF = Data4 & 1; 104 | uint32 Data8 = Data0 | (Data2 << 16); 105 | 106 | uint8 CF2 = Data8 & 1; 107 | Data8 >>= 1; 108 | 109 | if (CF) 110 | Data8 |= 0x80000000; 111 | 112 | Dat4 += CF2; 113 | Data4 = Dat4 & 0xFFFF; 114 | Data6 = Dat4 >> 16; 115 | 116 | for (uint16 cx = 0x0C; cx > 0; --cx) { 117 | CF = 0; 118 | 119 | if (Data0 & 0x8000) 120 | CF = 1; 121 | Data0 <<= 1; 122 | Data2 <<= 1; 123 | if (CF) 124 | Data2 |= 1; 125 | } 126 | 127 | int16 DataA = Data8 >> 16; 128 | 129 | Data0 ^= Data8 & 0xFFFF; 130 | Data2 ^= DataA; 131 | Data8 = Data0; 132 | DataA = Data2; 133 | 134 | int16 ax = Data8; 135 | int16 bx = DataA; 136 | Data8 = bx; 137 | DataA = ax; 138 | 139 | Data8 >>= 4; 140 | Data0 ^= Data8; 141 | 142 | mRandom_0 = Data0; 143 | mRandom_1 = Data2; 144 | mRandom_2 = Data4; 145 | mRandom_3 = Data6; 146 | return Data0; 147 | } 148 | }; -------------------------------------------------------------------------------- /Source/Version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | enum ePlatform { 24 | Any = 0, 25 | PC = 1, 26 | Amiga = 2 27 | }; 28 | 29 | enum eRelease { 30 | Retail = 0, 31 | PCFormat, 32 | AmigaXMAS, 33 | AmigaPower, 34 | AmigaTheOne, 35 | AmigaAction, 36 | AmigaNotVeryFestive, 37 | AmigaAlienLevels, 38 | 39 | Custom, 40 | eRandom 41 | }; 42 | 43 | enum eGame { 44 | CF1 = 0, 45 | CF2 = 1 46 | }; 47 | 48 | enum eCustomMode { 49 | eCustomMode_None = 0, 50 | eCustomMode_Map = 1, 51 | eCustomMode_Set = 2 52 | }; 53 | 54 | enum eGFX_Types { 55 | eGFX_IN_GAME = 0, 56 | eGFX_IN_GAME2 = 1, 57 | eGFX_FONT = 2, 58 | eGFX_HILL = 3, 59 | eGFX_RECRUIT = 4, 60 | eGFX_BRIEFING = 5, 61 | eGFX_SERVICE = 6, 62 | 63 | eGFX_RANKFONT = 7, 64 | eGFX_PSTUFF = 8, 65 | 66 | eGFX_BRIEFING_AMIGA_1 = 9, 67 | eGFX_BRIEFING_AMIGA_2 = 10, 68 | eGFX_BRIEFING_AMIGA_3 = 11 69 | }; 70 | 71 | enum eTileTypes { 72 | eTileTypes_Jungle = 0, 73 | eTileTypes_Desert = 1, 74 | eTileTypes_Ice = 2, 75 | eTileTypes_Moors = 3, 76 | eTileTypes_Int = 4, 77 | eTileTypes_Hid = 5, 78 | eTileTypes_AFX = 6, // Amiga Format Christmas Special 79 | }; 80 | 81 | enum eTileSub { 82 | eTileSub_0 = 0, 83 | eTileSub_1 = 1 84 | }; 85 | 86 | struct sTileset { 87 | eTileTypes Type; 88 | std::vector Subs; 89 | }; 90 | 91 | struct sVersion { 92 | std::string mName; 93 | 94 | eGame mGame; 95 | ePlatform mPlatform; 96 | eRelease mRelease; 97 | 98 | sVersion() { 99 | mName = ""; 100 | mGame = eGame::CF1; 101 | mPlatform = ePlatform::Any; 102 | mRelease = eRelease::Retail; 103 | } 104 | 105 | sVersion(const std::string& pName, eGame pGame, ePlatform pPlatform, eRelease pRelease) { 106 | mName = pName; 107 | mGame = pGame; 108 | mPlatform = pPlatform; 109 | mRelease = pRelease; 110 | } 111 | 112 | bool isCannonFodder1() const { 113 | return mGame == eGame::CF1; 114 | } 115 | 116 | bool isCannonFodder2() const { 117 | return mGame == eGame::CF2; 118 | } 119 | 120 | bool isCustom() const { 121 | return mRelease == eRelease::Custom || isRandom(); 122 | } 123 | 124 | bool isRandom() const { 125 | return mRelease == eRelease::eRandom; 126 | } 127 | 128 | bool isRetail() const { 129 | return mRelease == eRelease::Retail; 130 | } 131 | 132 | bool isPCFormat() const { 133 | return mRelease == eRelease::PCFormat; 134 | } 135 | 136 | bool isAmigaXmas() const { 137 | return mRelease == eRelease::AmigaXMAS; 138 | } 139 | 140 | bool isAmigaPower() const { 141 | return mRelease == eRelease::AmigaPower; 142 | } 143 | 144 | bool isAmigaTheOne() const { 145 | return mRelease == eRelease::AmigaTheOne; 146 | } 147 | 148 | bool isAmigaAction() const { 149 | return mRelease == eRelease::AmigaAction; 150 | } 151 | 152 | bool isAmigaNotVeryFestive() const { 153 | return mRelease == eRelease::AmigaNotVeryFestive; 154 | } 155 | 156 | bool isAmigaAlienLevels() const { 157 | return mRelease == eRelease::AmigaAlienLevels; 158 | } 159 | 160 | bool isAmiga() const { 161 | return mPlatform == ePlatform::Amiga; 162 | } 163 | 164 | bool isPC() const { 165 | return mPlatform == ePlatform::PC; 166 | } 167 | 168 | bool isSingle() const { 169 | return mName == "Single Map"; 170 | } 171 | 172 | /** 173 | * Is this version a demo? 174 | * 175 | * NOTE: The PC-Format version is not considered a demo, as it is very close to the dos retail 176 | */ 177 | bool isDemo() const { 178 | return mRelease == eRelease::AmigaXMAS || 179 | mRelease == eRelease::AmigaPower || 180 | mRelease == eRelease::AmigaTheOne || 181 | mRelease == eRelease::AmigaAction || 182 | mRelease == eRelease::AmigaNotVeryFestive || 183 | mRelease == eRelease::AmigaAlienLevels; 184 | } 185 | 186 | bool isCoverDisk() const { 187 | 188 | return (isAmigaPower() || isAmigaAction() || isAmigaTheOne()); 189 | } 190 | }; 191 | -------------------------------------------------------------------------------- /Source/Versions.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | struct sFile { 24 | const char* mName; 25 | const char* mChecksum; 26 | }; 27 | 28 | class cResources; 29 | class cGraphics; 30 | class cSound; 31 | 32 | struct sGameVersion : public sVersion { 33 | 34 | const std::string mDataPath; 35 | const std::vector mFiles; 36 | 37 | sGameVersion(const std::string& pName, eGame pGame, ePlatform pPlatform, eRelease pRelease, const std::string& pDataPath, const std::vector& pFiles) : 38 | sVersion(pName,pGame,pPlatform,pRelease), mDataPath(pDataPath), mFiles(pFiles) { 39 | 40 | } 41 | 42 | bool hasGfx(eGFX_Types pGfxType) const { 43 | auto gfx = getGfxTypes(); 44 | return std::find(gfx.begin(), gfx.end(), pGfxType) != gfx.end(); 45 | } 46 | 47 | bool hasTileset(eTileTypes pTileType, eTileSub pSub = eTileSub::eTileSub_0 ) const { 48 | auto tiles = getTileTypes(); 49 | 50 | return std::find_if(tiles.begin(), tiles.end(), 51 | [pTileType, pSub](const sTileset& ms) { 52 | if (ms.Type != pTileType) 53 | return false; 54 | 55 | return std::find(ms.Subs.begin(), ms.Subs.end(), pSub) != ms.Subs.end(); 56 | } 57 | ) != tiles.end(); 58 | } 59 | 60 | bool hasBriefingScreen() const { 61 | return hasGfx(eGFX_BRIEFING); 62 | } 63 | 64 | bool hasServiceScreen() const { 65 | return hasGfx(eGFX_SERVICE); 66 | } 67 | 68 | cDimension GetScreenSize() const { 69 | if (isAmiga()) 70 | return { 320,225 }; 71 | 72 | return { 320,200 }; 73 | } 74 | 75 | cDimension GetSecondScreenSize() const { 76 | if (isAmiga()) 77 | return { 320,260 }; 78 | 79 | return { 320,200 }; 80 | } 81 | 82 | std::vector getGfxTypes() const; 83 | std::vector getTileTypes() const; 84 | 85 | std::vector* getIntroData() const; 86 | 87 | std::shared_ptr GetResources() const; 88 | std::shared_ptr GetGraphics() const; 89 | std::shared_ptr GetSound() const; 90 | bool CanUseAmigaSound() const; 91 | 92 | std::string getDataPath() const; 93 | std::string getDataFilePath(std::string pFile) const; 94 | }; 95 | 96 | class cVersions { 97 | 98 | protected: 99 | 100 | public: 101 | 102 | bool isCampaignKnown(const std::string& pName) const; 103 | bool isCampaignAvailable(const std::string& pName) const; 104 | 105 | std::vector GetCampaignNames() const; 106 | 107 | const sGameVersion* GetForCampaign(const std::string& pCampaign) const; 108 | const sGameVersion* GetForCampaign(const std::string& pCampaign, const ePlatform pPlatform) const; 109 | const sGameVersion* GetForTileset(eTileTypes pTileType, eTileSub pSub) const; 110 | const sGameVersion* GetRetail(const ePlatform pPlatform, const eGame pGame) const; 111 | const sGameVersion* GetDemo() const; 112 | }; 113 | 114 | extern const sGameVersion KnownGameVersions[20]; -------------------------------------------------------------------------------- /Source/Window.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | class cWindow { 24 | 25 | protected: 26 | SDL_Window* mWindow; 27 | SDL_Renderer* mRenderer; 28 | 29 | std::vector mEvents; 30 | 31 | cDimension mOriginalResolution; 32 | 33 | cDimension mScreenSize; 34 | 35 | uint8 mScaler, mScalerPrevious; 36 | 37 | bool mWindowMode; 38 | bool mHasFocus; 39 | bool mResized; 40 | 41 | protected: 42 | 43 | 44 | public: 45 | 46 | cWindow(); 47 | virtual ~cWindow(); 48 | 49 | void CalculateWindowSize(); 50 | int16 CalculateFullscreenSize(); 51 | 52 | bool CanChangeToMultiplier( const int pNewMultiplier ); 53 | 54 | bool Cycle(); 55 | 56 | std::vector* EventGet(); 57 | virtual void EventCheck(); 58 | virtual void FrameEnd(); 59 | 60 | virtual bool InitWindow( const std::string& pWindowTitle ); 61 | 62 | virtual void PositionWindow(); 63 | 64 | virtual void RenderAt( cSurface* pImage ); 65 | virtual void RenderShrunk( cSurface* pImage ); 66 | 67 | void WindowIncrease(); 68 | void WindowDecrease(); 69 | 70 | bool isFullscreen() const; 71 | bool isGrabbed() const; 72 | bool isMouseInside() const; 73 | bool isResized() const; 74 | bool isMouseButtonPressed_Global() const; 75 | 76 | void SetCursor(); 77 | 78 | void SetMousePosition(const cPosition& pPosition); 79 | 80 | void SetScreenSize( const cDimension& pDimension ); 81 | void SetOriginalRes( const cDimension& pDimension ); 82 | 83 | void SetWindowTitle( const std::string& pWindowTitle ); 84 | void SetWindowSize(const int pMultiplier); 85 | 86 | void ToggleFullscreen(); 87 | void ClearResized(); 88 | 89 | SDL_Renderer* GetRenderer() const { return mRenderer; }; 90 | 91 | cPosition GetWindowPosition() const; 92 | int32 GetWindowWidth() const; 93 | int32 GetWindowHeight() const; 94 | 95 | cDimension GetWindowSize() const; 96 | cDimension GetScreenSize() const { return mScreenSize; } 97 | bool GetWindowMode() const { return mWindowMode; } 98 | bool hasFocusEvent() const { return mHasFocus; } 99 | void clearFocus() { mHasFocus = false; } 100 | cDimension GetScale() const; 101 | 102 | void SetRelativeMouseMode(bool pEnable); 103 | void ToggleVSync(bool pEnabled); 104 | int GetRefreshRate(); 105 | 106 | 107 | }; 108 | 109 | class cWindowNull : public cWindow { 110 | 111 | public: 112 | virtual ~cWindowNull() {} 113 | virtual bool InitWindow(const std::string& pWindowTitle); 114 | }; -------------------------------------------------------------------------------- /Source/stdafx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include "stdafx.hpp" 24 | 25 | std::shared_ptr g_Resource; 26 | std::shared_ptr g_Window; 27 | std::shared_ptr g_Fodder; 28 | std::shared_ptr g_Debugger; 29 | std::shared_ptr g_ResourceMan; 30 | std::shared_ptr g_ScriptingEngine; 31 | 32 | const char gPathSeperator = '/'; 33 | 34 | int main(int argc, char *argv[]) { 35 | auto result = start(argc, argv); 36 | if (result == -1) { 37 | std::cout << "Press enter to continue\n"; 38 | std::cin.get(); 39 | } 40 | 41 | return result; 42 | } 43 | 44 | /** 45 | * 46 | * @param pBuffer 47 | * @param pSize Number of words 48 | */ 49 | void tool_EndianSwap(uint8 *pBuffer, size_t pSize) { 50 | uint8 *pDest = pBuffer; 51 | 52 | pSize /= 2; 53 | 54 | while (pSize--) { 55 | uint8 al = *pBuffer++; 56 | uint8 ah = *pBuffer++; 57 | 58 | *pDest++ = ah; 59 | *pDest++ = al; 60 | } 61 | } 62 | 63 | std::string tool_StripLeadingZero(const std::string& pValue) { 64 | std::string Final = pValue; 65 | 66 | while (*Final.begin() == 0x30 && Final.length() > 1) { 67 | 68 | Final.erase(Final.begin()); 69 | } 70 | 71 | return Final; 72 | } 73 | 74 | uint16 tool_DecimalToBinaryCodedDecimal(uint16 pDecimal) { 75 | 76 | return ((pDecimal / 10) << 4) + (pDecimal % 10); 77 | } 78 | -------------------------------------------------------------------------------- /Source/stdafx.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Open Fodder 3 | * --------------- 4 | * 5 | * Copyright (C) 2008-2024 Open Fodder 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #ifndef EMSCRIPTEN 39 | #include 40 | #else 41 | #include 42 | #include 43 | #endif 44 | 45 | #include "Types.hpp" 46 | 47 | typedef std::shared_ptr> tSharedBuffer; 48 | 49 | enum eDataType { 50 | eData = 0, 51 | eSave, 52 | eCampaign, 53 | eTest, 54 | eRoot, 55 | eScript, 56 | eNone, 57 | }; 58 | 59 | int start(int argc, char *argv[]); 60 | void tool_EndianSwap( uint8* pBuffer, size_t pSize ); 61 | std::string tool_StripLeadingZero( const std::string& pValue ); 62 | uint16 tool_DecimalToBinaryCodedDecimal( uint16 pDecimal ); 63 | 64 | // Read a BE word from the buffer 65 | inline uint16 readBEWord( const void *buffer ) { 66 | const uint8* bytes = (const uint8*) buffer; 67 | 68 | return uint16((bytes[0] << 8) + bytes[1]); 69 | } 70 | 71 | // Write a LE word in BE 72 | inline void writeBEWord( const void *buffer, uint16 pValue ) { 73 | uint8* bytes = (uint8*) buffer; 74 | 75 | bytes[0] = (uint8) (pValue >> 8); 76 | bytes[1] = (uint8) (pValue & 0xFF); 77 | } 78 | 79 | // Read a LE DWord in BE 80 | inline uint32 readBEDWord( const void *buffer ) { 81 | const uint8* bytes = (const uint8*) buffer; 82 | 83 | return uint32((bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + (bytes[3])); 84 | } 85 | 86 | // Read little endian from the buffer 87 | template inline tRet readLE(const void *pBuffer) { 88 | const tRet* data = (const tRet*)pBuffer; 89 | return *data; 90 | } 91 | 92 | inline void writeLEWord( const void *buffer, uint16 pValue ) { 93 | uint16* wordBytes = (uint16 *) buffer; 94 | *wordBytes = pValue; 95 | } 96 | 97 | #ifndef _WIN32 98 | #include 99 | #define Sleep( a ) usleep( a * 1000 ); 100 | 101 | #define _stricmp( a, b ) strcmp(a, b) 102 | #endif 103 | 104 | #include "Debugger.hpp" 105 | #include "Utils/pseudorand.hpp" 106 | 107 | #include "Position.hpp" 108 | #include "Dimension.hpp" 109 | #include "Event.hpp" 110 | 111 | #include "Surface.hpp" 112 | #include "Version.hpp" 113 | #include "Resources.hpp" 114 | 115 | #include "Parameters.hpp" 116 | 117 | #include "PC/Resource_PC_CD.hpp" 118 | //#include "Amiga/Resource_Amiga_File.hpp" 119 | 120 | #include "CopyProtection.hpp" 121 | #include "IntroData.hpp" 122 | #include "Tiles.hpp" 123 | 124 | #include "Map/Map.hpp" 125 | #include "Map/Original.hpp" 126 | //#include "Map/Random.hpp" 127 | 128 | #include "Campaign.hpp" 129 | #include "FontData.hpp" 130 | #include "Graphics.hpp" 131 | #include "Recruits.hpp" 132 | #include "Versions.hpp" 133 | #include "ResourceMan.hpp" 134 | 135 | #include "Window.hpp" 136 | #include "Sound.hpp" 137 | #include "GUI_Element.hpp" 138 | #include "SpriteSheet.hpp" 139 | #include "Fodder.hpp" 140 | 141 | #include "Structures/Barracks.hpp" 142 | 143 | #include "PC/Graphics_PC.hpp" 144 | #include "PC/Sound_PC.hpp" 145 | #include "PC/Sound_PC2.hpp" 146 | 147 | #include "Amiga/paula.hpp" 148 | #include "Amiga/rjp1.hpp" 149 | #include "Amiga/Sound_Amiga.hpp" 150 | #include "Amiga/Graphics_Amiga.hpp" 151 | #include "Amiga/Graphics_Amiga2.hpp" 152 | 153 | #include "About.hpp" 154 | #include "UnitTesting.hpp" 155 | 156 | #include "ScriptingEngine.hpp" 157 | 158 | extern std::shared_ptr g_Resource; 159 | extern std::shared_ptr g_Window; 160 | extern std::shared_ptr g_Fodder; 161 | extern std::shared_ptr g_Debugger; 162 | extern std::shared_ptr g_ResourceMan; 163 | extern std::shared_ptr g_ScriptingEngine; 164 | 165 | extern const char gPathSeperator; 166 | 167 | #define CANNON_BASED( pCF1, pCF2 ) (g_Fodder->mVersionCurrent->isCannonFodder1() ? pCF1 : pCF2 ) 168 | #define PLATFORM_BASED( pPC, pAmiga ) (g_Fodder->mVersionCurrent->isAmiga() ? pAmiga : pPC ) 169 | -------------------------------------------------------------------------------- /cmake/gitver.hpp.in: -------------------------------------------------------------------------------- 1 | const char* gitversion = "@OPENFODDER_COMMIT_SHA1_SHORT@"; 2 | -------------------------------------------------------------------------------- /openfodder.ini.example: -------------------------------------------------------------------------------- 1 | ; OpenFodder 2 | ; 3 | ; Example ini settings are the engine defaults 4 | ; 5 | 6 | [openfodder] 7 | 8 | ; Start the game in a window 9 | window=true 10 | 11 | ; Enable cheat keys 12 | cheats=false 13 | 14 | ; Window size multipler by original game resolution (Amiga 320x225, Dos 320x200) 15 | ; auto finds a size approximately half your screen resolution 16 | ; values such as 1, 2 or 3+ are multiples of the original resolution 17 | scale=auto 18 | 19 | ; Use integer scaling (default), or use non-integer scaling to fit the image to display height 20 | ; while preserving the original 4:3 aspect ratio. 21 | ; When doing non-integer scaling in fullscreen mode, linear filtering is applied 22 | ; to avoid ugly irregular pixels and shimmering artifacts. 23 | integer=true 24 | 25 | ; Number of map tiles to draw horizontally (0 for platform default) 26 | columns=0 27 | 28 | ; Number of map tiles to draw vertically (0 for platform default) 29 | rows=0 30 | 31 | ; Don't set mouse cursor x/y, use raw values (this alters the behaviour of the in-game camera window) -- Useful for VMs 32 | alternate-mouse=false 33 | 34 | ; The mouse is locked to the window 35 | mouse-locked=false 36 | 37 | ; Enable copy protection screen on Dos CD release 38 | copyprotection=false 39 | 40 | 41 | [paths] 42 | ; Paths to data base folder 43 | ; There is no limit to the number paths in this section (eg, path1, path2... path10) 44 | ;path1=c:/games/openfodder 45 | ;path2=d:/games/openfodder 46 | ;path3=d:/games/openfodder 47 | 48 | ; 49 | ; 50 | [engine] 51 | 52 | ; Default platform (amiga/pc) 53 | platform=amiga 54 | 55 | ; Game engine to use in single/random maps (cf1/cf2) 56 | game=cf1 57 | 58 | ; Maximum number of sprites in game (original engine is 45) 59 | maxsprite=45 60 | 61 | ; Maximum number of enemies which can spawn (original engine is 10) 62 | maxspawn=10 63 | 64 | 65 | [skip] 66 | 67 | ; Skip the game introduction screens 68 | intro=false 69 | 70 | ; Skip the briefing screen 71 | briefing=false 72 | 73 | ; Skip the killed in action / promotion screens 74 | service=false 75 | 76 | ; Skip the hill recruit screen 77 | hill=false 78 | --------------------------------------------------------------------------------