├── .editorconfig ├── .gitignore ├── CMakeLists.txt ├── LICENSE.txt ├── README-raven.txt ├── README.md ├── build ├── build-unix-debug.sh ├── build-unix-qvms.sh ├── build-unix.sh ├── create-vs2010-x64-projects.bat ├── create-vs2010-x86-projects.bat ├── create-vs2012-x64-projects.bat ├── create-vs2012-x86-projects.bat ├── create-vs2013-x64-projects.bat ├── create-vs2013-x86-projects.bat ├── create-vs2015-x64-projects.bat ├── create-vs2015-x86-projects.bat ├── create-vs2017-x64-projects.bat ├── create-vs2017-x86-projects.bat ├── create-vs2019-x64-projects.bat └── create-vs2019-x86-projects.bat ├── cmake ├── GetGitRevisionDescription.cmake └── GetGitRevisionDescription.cmake.in ├── code ├── CMakeLists.txt ├── api │ ├── mvapi.h │ └── mvmenu.h ├── cgame │ ├── CMakeLists.txt │ ├── animtable.h │ ├── cg_consolecmds.c │ ├── cg_draw.c │ ├── cg_drawtools.c │ ├── cg_effects.c │ ├── cg_ents.c │ ├── cg_event.c │ ├── cg_info.c │ ├── cg_light.c │ ├── cg_lights.h │ ├── cg_local.h │ ├── cg_localents.c │ ├── cg_main.c │ ├── cg_marks.c │ ├── cg_media.h │ ├── cg_multiversion.c │ ├── cg_multiversion.h │ ├── cg_multiversion_syscalls.c │ ├── cg_multiversion_syscalls.h │ ├── cg_newDraw.c │ ├── cg_players.c │ ├── cg_playerstate.c │ ├── cg_predict.c │ ├── cg_public.h │ ├── cg_saga.c │ ├── cg_scoreboard.c │ ├── cg_servercmds.c │ ├── cg_snapshot.c │ ├── cg_syscalls.asm │ ├── cg_syscalls.c │ ├── cg_turret.c │ ├── cg_view.c │ ├── cg_weaponinit.c │ ├── cg_weapons.c │ ├── fx_blaster.c │ ├── fx_bowcaster.c │ ├── fx_bryarpistol.c │ ├── fx_demp2.c │ ├── fx_disruptor.c │ ├── fx_flechette.c │ ├── fx_force.c │ ├── fx_heavyrepeater.c │ ├── fx_local.h │ ├── fx_rocketlauncher.c │ └── tr_types.h ├── game │ ├── CMakeLists.txt │ ├── ai_main.c │ ├── ai_main.h │ ├── ai_util.c │ ├── ai_wpnav.c │ ├── animMappingTable.c │ ├── anims.h │ ├── be_aas.h │ ├── be_ai_char.h │ ├── be_ai_chat.h │ ├── be_ai_gen.h │ ├── be_ai_goal.h │ ├── be_ai_move.h │ ├── be_ai_weap.h │ ├── be_ea.h │ ├── bg_lib.c │ ├── bg_lib.h │ ├── bg_local.h │ ├── bg_misc.c │ ├── bg_multiversion.c │ ├── bg_multiversion.h │ ├── bg_panimate.c │ ├── bg_pmove.c │ ├── bg_public.h │ ├── bg_saber.c │ ├── bg_saga.h │ ├── bg_slidemove.c │ ├── bg_weapons.c │ ├── bg_weapons.h │ ├── botlib.h │ ├── chars.h │ ├── g_active.c │ ├── g_arenas.c │ ├── g_bot.c │ ├── g_client.c │ ├── g_cmds.c │ ├── g_combat.c │ ├── g_items.c │ ├── g_local.h │ ├── g_log.c │ ├── g_main.c │ ├── g_mem.c │ ├── g_misc.c │ ├── g_missile.c │ ├── g_mover.c │ ├── g_multiversion.c │ ├── g_multiversion.h │ ├── g_multiversion_syscalls.c │ ├── g_multiversion_syscalls.h │ ├── g_object.c │ ├── g_public.h │ ├── g_saga.c │ ├── g_session.c │ ├── g_spawn.c │ ├── g_svcmds.c │ ├── g_syscalls.asm │ ├── g_syscalls.c │ ├── g_target.c │ ├── g_team.c │ ├── g_team.h │ ├── g_trigger.c │ ├── g_utils.c │ ├── g_weapon.c │ ├── inv.h │ ├── match.h │ ├── q_math.c │ ├── q_shared.c │ ├── q_shared.h │ ├── surfaceflags.h │ ├── syn.h │ ├── w_force.c │ ├── w_saber.c │ └── w_saber.h ├── ghoul2 │ └── g2.h ├── mv.info ├── mvsdk_setup.h.in ├── qcommon │ ├── game_version.h │ ├── qfiles.h │ └── tags.h ├── renderer │ ├── matcomp.c │ ├── matcomp.h │ └── mdx_format.h └── ui │ ├── CMakeLists.txt │ ├── keycodes.h │ ├── menudef.h │ ├── ui_atoms.c │ ├── ui_force.c │ ├── ui_force.h │ ├── ui_gameinfo.c │ ├── ui_local.h │ ├── ui_main.c │ ├── ui_multiversion.c │ ├── ui_multiversion.h │ ├── ui_multiversion_syscalls.c │ ├── ui_multiversion_syscalls.h │ ├── ui_players.c │ ├── ui_public.h │ ├── ui_shared.c │ ├── ui_shared.h │ ├── ui_syscalls.asm │ └── ui_syscalls.c └── tools ├── CMakeLists.txt ├── COPYRIGHT ├── README ├── README.id ├── asm ├── CMakeLists.txt ├── README.Id ├── cmdlib.c ├── cmdlib.h ├── lib.txt ├── mathlib.h ├── notes.txt ├── ops.txt ├── opstrings.h └── q3asm.c ├── cpp ├── CMakeLists.txt ├── cpp.c ├── cpp.h ├── eval.c ├── getopt.c ├── hideset.c ├── include.c ├── lex.c ├── macro.c ├── nlist.c ├── tokens.c └── unix.c ├── doc ├── 4.html ├── bprint.1 ├── bprint.pdf ├── install.html ├── lcc.1 └── lcc.pdf ├── lcc ├── CMakeLists.txt ├── bytecode.c └── lcc.c ├── qcommon ├── q_platform.h └── qfiles.h └── rcc ├── CMakeLists.txt ├── alloc.c ├── bind.c ├── bytecode.c ├── c.h ├── config.h ├── dag.c ├── dagcheck.c ├── decl.c ├── enode.c ├── error.c ├── event.c ├── expr.c ├── gen.c ├── init.c ├── inits.c ├── input.c ├── lex.c ├── list.c ├── main.c ├── null.c ├── output.c ├── prof.c ├── profio.c ├── simp.c ├── stmt.c ├── string.c ├── sym.c ├── symbolic.c ├── token.h ├── trace.c ├── tree.c └── types.c /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | insert_final_newline = true 8 | indent_style = tab 9 | indent_size = 4 10 | 11 | [*.yml] 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.rst] 16 | indent_style = space 17 | indent_size = 3 18 | 19 | [*.{txt,rst,md}] 20 | charset = utf-8 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ################# 3 | ## Visual Studio 4 | ################# 5 | 6 | ## Ignore Visual Studio temporary files, build results, and 7 | ## files generated by popular Visual Studio add-ons. 8 | 9 | # User-specific files 10 | *.suo 11 | *.user 12 | *.sln.docstates 13 | *_i.c 14 | *_p.c 15 | *.ilk 16 | *.meta 17 | *.obj 18 | *.pch 19 | *.pdb 20 | *.pgc 21 | *.pgd 22 | *.rsp 23 | *.sbr 24 | *.tlb 25 | *.tli 26 | *.tlh 27 | *.tmp 28 | *.vspscc 29 | .builds 30 | *.dotCover 31 | 32 | # Visual C++ cache files 33 | ipch/ 34 | *.aps 35 | *.ncb 36 | *.opensdf 37 | *.sdf 38 | 39 | # Visual Studio profiler 40 | *.psess 41 | *.vsp 42 | 43 | # ReSharper is a .NET coding add-in 44 | _ReSharper* 45 | 46 | ################# 47 | ## Eclipse 48 | ################# 49 | 50 | *.pydevproject 51 | .project 52 | .metadata 53 | bin/ 54 | tmp/ 55 | *.tmp 56 | *.bak 57 | *.swp 58 | *~.nib 59 | local.properties 60 | .classpath 61 | .settings/ 62 | .loadpath 63 | 64 | # External tool builders 65 | .externalToolBuilders/ 66 | 67 | # Locally stored "Eclipse launch configurations" 68 | *.launch 69 | 70 | # CDT-specific 71 | .cproject 72 | 73 | # PDT-specific 74 | .buildpath 75 | 76 | ############ 77 | ## Windows 78 | ############ 79 | 80 | # Windows image file caches 81 | Thumbs.db 82 | 83 | # Folder config file 84 | Desktop.ini 85 | 86 | ############# 87 | ## Unix 88 | ############# 89 | .DS_Store 90 | *.o 91 | *.so 92 | GTAGS 93 | GRTAGS 94 | GPATH 95 | 96 | # ignore all subdirectories of the build directory 97 | code/base/ 98 | code/game/vm/ 99 | code/cgame/vm/ 100 | code/ui/vm/ 101 | 102 | build/*/ 103 | -------------------------------------------------------------------------------- /README-raven.txt: -------------------------------------------------------------------------------- 1 | Activision and Raven are releasing this code for people to learn from and play with. 2 | This code is copyright Activision 2002. This source is released under GNU GPLv2. 3 | 4 | 5 | Some source code in this release is not covered by the GPL: 6 | e.g. 7 | zlib is Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler 8 | 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted subject to the following restrictions: 15 | 16 | 1. The origin of this software must not be misrepresented; you must not 17 | claim that you wrote the original software. If you use this software 18 | in a product, an acknowledgment in the product documentation would be 19 | appreciated but is not required. 20 | 2. Altered source versions must be plainly marked as such, and must not be 21 | misrepresented as being the original software. 22 | 3. This notice may not be removed or altered from any source distribution. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JK2MV - SDK 2 | https://jk2mv.org 3 | 4 | JK2MV (Multi Version) is a modification for Jedi Knight II: Jedi Outcast. It supports all three game versions and comes with various features and optimizations. 5 | The MVSDK (Multi Version - SDK) contains the code of JK2MV's game, cgame and ui modules. 6 | 7 | Main Features: 8 | - Supports 1.02, 1.03 and 1.04 9 | - Works with jk2mp.exe (original 1.02, 1.03 and 1.04 engines), all macOS versions, all jk2mv versions 10 | - Multiarchitecture: 32 and 64 bit support on all platforms 11 | - Fixes for all known security bugs 12 | - Tons of other fixes and improvements 13 | - All of this while maintaining basejk gameplay, nothing has been or will be changed in that regard. 14 | 15 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/ff39df770552430d98ef3661ce3abea6)](https://www.codacy.com/app/mvdevs/mvsdk?utm_source=github.com&utm_medium=referral&utm_content=mvdevs/mvsdk&utm_campaign=Badge_Grade) 16 | 17 | # License 18 | JK2MV - SDK is licensed under GPLv2 as free software. You are free to use, modify and redistribute JK2MV - SDK following the terms in the LICENSE file. Please be aware of the implications of the GPLv2 licence. In short, be prepared to share your code under the same GPLv2 licence. 19 | -------------------------------------------------------------------------------- /build/build-unix-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | type cmake >/dev/null 2>&1 || { echo >&2 "Can't find cmake."; exit 1; } 4 | 5 | BUILD_DIR="`uname`-`uname -m`-debug" 6 | mkdir "$BUILD_DIR" 7 | cd "$BUILD_DIR" 8 | cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ../.. 9 | make 10 | -------------------------------------------------------------------------------- /build/build-unix-qvms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | type cmake >/dev/null 2>&1 || { echo >&2 "Can't find cmake."; exit 1; } 4 | 5 | BUILD_DIR="`uname`-`uname -m`" 6 | mkdir "$BUILD_DIR" 7 | cd "$BUILD_DIR" 8 | cmake -G "Unix Makefiles" ../.. 9 | make qvms 10 | -------------------------------------------------------------------------------- /build/build-unix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | type cmake >/dev/null 2>&1 || { echo >&2 "Can't find cmake."; exit 1; } 4 | 5 | BUILD_DIR="`uname`-`uname -m`" 6 | mkdir "$BUILD_DIR" 7 | cd "$BUILD_DIR" 8 | cmake -G "Unix Makefiles" ../.. 9 | make 10 | -------------------------------------------------------------------------------- /build/create-vs2010-x64-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2010 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc10_x64 15 | cd msvc10_x64 16 | cmake -G "Visual Studio 10 Win64" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2010-x86-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2010 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc10_x86 15 | cd msvc10_x86 16 | cmake -G "Visual Studio 10" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2012-x64-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2012 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc11_x64 15 | cd msvc11_x64 16 | cmake -G "Visual Studio 11 Win64" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2012-x86-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2012 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc11_x86 15 | cd msvc11_x86 16 | cmake -G "Visual Studio 11" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2013-x64-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2013 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc12_x64 15 | cd msvc12_x64 16 | cmake -G "Visual Studio 12 Win64" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2013-x86-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2013 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc12_x86 15 | cd msvc12_x86 16 | cmake -G "Visual Studio 12" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2015-x64-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2015 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc14_x64 15 | cd msvc14_x64 16 | cmake -G "Visual Studio 14 Win64" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2015-x86-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2015 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc14_x86 15 | cd msvc14_x86 16 | cmake -G "Visual Studio 14" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2017-x64-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2017 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc15_x64 15 | cd msvc15_x64 16 | cmake -G "Visual Studio 15 Win64" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2017-x86-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2017 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc15_x86 15 | cd msvc15_x86 16 | cmake -G "Visual Studio 15" ../.. 17 | pause -------------------------------------------------------------------------------- /build/create-vs2019-x64-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2019 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc16_x64 15 | cd msvc16_x64 16 | cmake -G "Visual Studio 16" -A "x64" ../.. 17 | pause 18 | -------------------------------------------------------------------------------- /build/create-vs2019-x86-projects.bat: -------------------------------------------------------------------------------- 1 | @REM Create Skyscraper projects for Visual Studio 2019 using CMake 2 | @echo off 3 | for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X) 4 | if not defined FOUND ( 5 | echo CMake was not found on your system. Please make sure you have installed CMake 6 | echo from http://www.cmake.org/ and cmake.exe is installed to your system's PATH 7 | echo environment variable. 8 | echo. 9 | pause 10 | exit /b 1 11 | ) else ( 12 | echo Found CMake! 13 | ) 14 | mkdir msvc16_x86 15 | cd msvc16_x86 16 | cmake -G "Visual Studio 16" -A "Win32" ../.. 17 | pause 18 | -------------------------------------------------------------------------------- /cmake/GetGitRevisionDescription.cmake: -------------------------------------------------------------------------------- 1 | # - Returns a version string from Git 2 | # 3 | # These functions force a re-configure on each git commit so that you can 4 | # trust the values of the variables in your build system. 5 | # 6 | # get_git_head_revision( [ ...]) 7 | # 8 | # Returns the refspec and sha hash of the current head revision 9 | # 10 | # git_describe( [ ...]) 11 | # 12 | # Returns the results of git describe on the source tree, and adjusting 13 | # the output so that it tests false if an error occurs. 14 | # 15 | # git_get_exact_tag( [ ...]) 16 | # 17 | # Returns the results of git describe --exact-match on the source tree, 18 | # and adjusting the output so that it tests false if there was no exact 19 | # matching tag. 20 | # 21 | # Requires CMake 2.6 or newer (uses the 'function' command) 22 | # 23 | # Original Author: 24 | # 2009-2010 Ryan Pavlik 25 | # http://academic.cleardefinition.com 26 | # Iowa State University HCI Graduate Program/VRAC 27 | # 28 | # Copyright Iowa State University 2009-2010. 29 | # Distributed under the Boost Software License, Version 1.0. 30 | # (See accompanying file LICENSE_1_0.txt or copy at 31 | # http://www.boost.org/LICENSE_1_0.txt) 32 | 33 | if(__get_git_revision_description) 34 | return() 35 | endif() 36 | set(__get_git_revision_description YES) 37 | 38 | # We must run the following at "include" time, not at function call time, 39 | # to find the path to this module rather than the path to a calling list file 40 | get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) 41 | 42 | function(get_git_head_revision _refspecvar _hashvar) 43 | set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") 44 | set(GIT_DIR "${GIT_PARENT_DIR}/.git") 45 | while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories 46 | set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") 47 | get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) 48 | if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) 49 | # We have reached the root directory, we are not in git 50 | set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 51 | set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) 52 | return() 53 | endif() 54 | set(GIT_DIR "${GIT_PARENT_DIR}/.git") 55 | endwhile() 56 | # check if this is a submodule 57 | if(NOT IS_DIRECTORY ${GIT_DIR}) 58 | file(READ ${GIT_DIR} submodule) 59 | string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) 60 | get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) 61 | get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) 62 | endif() 63 | set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") 64 | if(NOT EXISTS "${GIT_DATA}") 65 | file(MAKE_DIRECTORY "${GIT_DATA}") 66 | endif() 67 | 68 | if(NOT EXISTS "${GIT_DIR}/HEAD") 69 | return() 70 | endif() 71 | set(HEAD_FILE "${GIT_DATA}/HEAD") 72 | configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) 73 | 74 | configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" 75 | "${GIT_DATA}/grabRef.cmake" 76 | @ONLY) 77 | include("${GIT_DATA}/grabRef.cmake") 78 | 79 | set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) 80 | set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) 81 | endfunction() 82 | 83 | function(git_describe _var) 84 | if(NOT GIT_FOUND) 85 | find_package(Git QUIET) 86 | endif() 87 | get_git_head_revision(refspec hash) 88 | if(NOT GIT_FOUND) 89 | set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) 90 | return() 91 | endif() 92 | if(NOT hash) 93 | set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) 94 | return() 95 | endif() 96 | 97 | # TODO sanitize 98 | #if((${ARGN}" MATCHES "&&") OR 99 | # (ARGN MATCHES "||") OR 100 | # (ARGN MATCHES "\\;")) 101 | # message("Please report the following error to the project!") 102 | # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") 103 | #endif() 104 | 105 | #message(STATUS "Arguments to execute_process: ${ARGN}") 106 | 107 | execute_process(COMMAND 108 | "${GIT_EXECUTABLE}" 109 | describe 110 | ${hash} 111 | ${ARGN} 112 | WORKING_DIRECTORY 113 | "${CMAKE_CURRENT_SOURCE_DIR}" 114 | RESULT_VARIABLE 115 | res 116 | OUTPUT_VARIABLE 117 | out 118 | ERROR_QUIET 119 | OUTPUT_STRIP_TRAILING_WHITESPACE) 120 | if(NOT res EQUAL 0) 121 | set(out "${out}-${res}-NOTFOUND") 122 | endif() 123 | 124 | set(${_var} "${out}" PARENT_SCOPE) 125 | endfunction() 126 | 127 | function(git_get_exact_tag _var) 128 | git_describe(out --exact-match ${ARGN}) 129 | set(${_var} "${out}" PARENT_SCOPE) 130 | endfunction() 131 | -------------------------------------------------------------------------------- /cmake/GetGitRevisionDescription.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # Internal file for GetGitRevisionDescription.cmake 3 | # 4 | # Requires CMake 2.6 or newer (uses the 'function' command) 5 | # 6 | # Original Author: 7 | # 2009-2010 Ryan Pavlik 8 | # http://academic.cleardefinition.com 9 | # Iowa State University HCI Graduate Program/VRAC 10 | # 11 | # Copyright Iowa State University 2009-2010. 12 | # Distributed under the Boost Software License, Version 1.0. 13 | # (See accompanying file LICENSE_1_0.txt or copy at 14 | # http://www.boost.org/LICENSE_1_0.txt) 15 | 16 | set(HEAD_HASH) 17 | 18 | file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) 19 | 20 | string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) 21 | if(HEAD_CONTENTS MATCHES "ref") 22 | # named branch 23 | string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") 24 | if(EXISTS "@GIT_DIR@/${HEAD_REF}") 25 | configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) 26 | else() 27 | configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) 28 | file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) 29 | if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") 30 | set(HEAD_HASH "${CMAKE_MATCH_1}") 31 | endif() 32 | endif() 33 | else() 34 | # detached HEAD 35 | configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) 36 | endif() 37 | 38 | if(NOT HEAD_HASH) 39 | file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) 40 | string(STRIP "${HEAD_HASH}" HEAD_HASH) 41 | endif() 42 | -------------------------------------------------------------------------------- /code/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | # mv_setup.h preparation 7 | set(MVGLOBALIncludeDirs ${MVGLOBALIncludeDirs} ${CMAKE_BINARY_DIR}) 8 | configure_file("mvsdk_setup.h.in" "${CMAKE_BINARY_DIR}/mvsdk_setup.h" @ONLY) 9 | 10 | add_subdirectory("game") 11 | add_subdirectory("cgame") 12 | add_subdirectory("ui") 13 | 14 | if(BuildQVMs) 15 | # Custom target for building qvm's 16 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/vm_build") 17 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/vm") 18 | 19 | foreach(FILE ${MVGAMEVMSOURCES}) 20 | file(TO_NATIVE_PATH "${FILE}" FILE_NATIVE) 21 | set(MVGAMEVMSOURCES_NATIVE ${MVGAMEVMSOURCES_NATIVE} ${FILE_NATIVE}) 22 | 23 | get_filename_component(FILE ${FILE} NAME_WE) 24 | set(MVGAMEASMFILES ${MVGAMEASMFILES} "${FILE}.asm") 25 | endforeach() 26 | 27 | foreach(FILE ${MVCGAMEVMSOURCES}) 28 | file(TO_NATIVE_PATH "${FILE}" FILE_NATIVE) 29 | set(MVCGAMEVMSOURCES_NATIVE ${MVCGAMEVMSOURCES_NATIVE} ${FILE_NATIVE}) 30 | 31 | get_filename_component(FILE ${FILE} NAME_WE) 32 | set(MVCGAMEASMFILES ${MVCGAMEASMFILES} "${FILE}.asm") 33 | endforeach() 34 | 35 | foreach(FILE ${MVUIVMSOURCES}) 36 | file(TO_NATIVE_PATH "${FILE}" FILE_NATIVE) 37 | set(MVUIVMSOURCES_NATIVE ${MVUIVMSOURCES_NATIVE} ${FILE_NATIVE}) 38 | 39 | get_filename_component(FILE ${FILE} NAME_WE) 40 | set(MVUIASMFILES ${MVUIASMFILES} "${FILE}.asm") 41 | endforeach() 42 | 43 | file(RELATIVE_PATH MVSDK_CGAME_PATH "${CMAKE_CURRENT_BINARY_DIR}/vm_build" "${SRCDir}/cgame") 44 | file(TO_NATIVE_PATH "${MVSDK_CGAME_PATH}" MVSDK_CGAME_PATH) 45 | 46 | file(RELATIVE_PATH MVSDK_GAME_PATH "${CMAKE_CURRENT_BINARY_DIR}/vm_build" "${SRCDir}/game") 47 | file(TO_NATIVE_PATH "${MVSDK_GAME_PATH}" MVSDK_GAME_PATH) 48 | 49 | file(RELATIVE_PATH MVSDK_UI_PATH "${CMAKE_CURRENT_BINARY_DIR}/vm_build" "${SRCDir}/ui") 50 | file(TO_NATIVE_PATH "${MVSDK_UI_PATH}" MVSDK_UI_PATH) 51 | 52 | file(RELATIVE_PATH MVSDK_BIN_PATH "${CMAKE_CURRENT_BINARY_DIR}/vm_build" "${CMAKE_BINARY_DIR}") 53 | file(TO_NATIVE_PATH "${MVSDK_BIN_PATH}" MVSDK_BIN_PATH) 54 | 55 | add_custom_target(qvms 56 | COMMAND $ 57 | "-DQ3_VM" "-DJK2_GAME" "-DMISSIONPACK" "-S" "-Wf-target=bytecode" "-Wf-g" "-I${MVSDK_GAME_PATH}" "-I${MVSDK_UI_PATH}" "-I${MVSDK_BIN_PATH}" ${MVGAMEVMSOURCES_NATIVE} 58 | 59 | COMMAND $ 60 | "-vq3" "-m" "-v" "-o" "${CMAKE_CURRENT_BINARY_DIR}/vm/jk2mpgame.qvm" ${MVGAMEASMFILES} ${MVGAMEASM} 61 | 62 | COMMAND $ 63 | "-DQ3_VM" "-DJK2_CGAME" "-DMISSIONPACK" "-S" "-Wf-target=bytecode" "-Wf-g" "-I${MVSDK_CGAME_PATH}" "-I${MVSDK_GAME_PATH}" "-I${MVSDK_UI_PATH}" "-I${MVSDK_BIN_PATH}" ${MVCGAMEVMSOURCES_NATIVE} 64 | 65 | COMMAND $ 66 | "-vq3" "-m" "-v" "-o" "${CMAKE_CURRENT_BINARY_DIR}/vm/cgame.qvm" ${MVCGAMEASMFILES} ${MVCGAMEASM} 67 | 68 | COMMAND $ 69 | "-DQ3_VM" "-DJK2_UI" "-S" "-Wf-target=bytecode" "-Wf-g" "-I${SRCDir}/cgame" "-I${MVSDK_GAME_PATH}" "-I${MVSDK_UI_PATH}" "-I${MVSDK_BIN_PATH}" ${MVUIVMSOURCES_NATIVE} 70 | 71 | COMMAND $ 72 | "-vq3" "-m" "-v" "-o" "${CMAKE_CURRENT_BINARY_DIR}/vm/ui.qvm" ${MVUIASMFILES} ${MVUIASM} 73 | 74 | WORKING_DIRECTORY 75 | "${CMAKE_CURRENT_BINARY_DIR}/vm_build" 76 | 77 | DEPENDS 78 | ${LCC} ${CPP} ${RCC} ${ASM} 79 | ) 80 | 81 | set_property(TARGET qvms PROPERTY PROJECT_LABEL "Build QVMs") 82 | if(InMV) 83 | set_property(TARGET qvms PROPERTY FOLDER "Modules") 84 | endif() 85 | 86 | if(InMV) 87 | configure_file("mv.info" "mv.info" COPYONLY) 88 | set(AssetsFiles 89 | "vm/jk2mpgame.qvm" 90 | "vm/jk2mpgame.map" 91 | "vm/cgame.qvm" 92 | "vm/cgame.map" 93 | "vm/ui.qvm" 94 | "vm/ui.map" 95 | "mv.info" 96 | ) 97 | 98 | source_group("assetsmv2" FILES ${AssetsFiles}) 99 | 100 | # generate assetsmv2.pk3 101 | if(MultiConfigGenerator) 102 | set(OUTFILE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$/base/assetsmv2.pk3) 103 | else() 104 | set(OUTFILE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/base/assetsmv2.pk3) 105 | endif() 106 | 107 | include(InstallZIP) 108 | add_zip_command(${CMAKE_CURRENT_BINARY_DIR}/assetsmv2.pk3 ${OUTFILE} 109 | DIR "${CMAKE_CURRENT_BINARY_DIR}" 110 | FILES "${AssetsFiles}" 111 | DEPENDS qvms 112 | ) 113 | 114 | add_custom_target(assetsmv2 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/assetsmv2.pk3") 115 | set_property(TARGET assetsmv2 PROPERTY FOLDER "Modules") 116 | 117 | if(WIN32 OR BuildPortableVersion) 118 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/assetsmv2.pk3 DESTINATION "base") 119 | elseif(APPLE) 120 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/assetsmv2.pk3 DESTINATION "jk2mvmp.app/Contents/MacOS/base") 121 | else() 122 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/assetsmv2.pk3 DESTINATION "share/jk2mv/base") 123 | endif() 124 | endif() 125 | endif() 126 | -------------------------------------------------------------------------------- /code/api/mvmenu.h: -------------------------------------------------------------------------------- 1 | #ifndef MVMENU_H 2 | #define MVMENU_H 3 | 4 | #if defined(JK2MV_MENU) || defined(JK2_UI) 5 | # include "../game/q_shared.h" 6 | #else 7 | # include "../qcommon/q_shared.h" 8 | #endif 9 | 10 | 11 | // ##################################################################################################### 12 | // ### Forks of JK2MV should NOT modify any content of this file. Forks should define their own api. ### 13 | // ##################################################################################################### 14 | // ### Removing, adding or modifying defines, flags, functions, etc. might lead to incompatibilities ### 15 | // ### and crashes. ### 16 | // ##################################################################################################### 17 | 18 | // -------------------------------------- Menu Level --------------------------------------- // 19 | // The menulevel is used for mvmenu and ui modules loaded while the client is not ingame. 20 | // Future versions of JK2MV might drop previous menulevels at any time. 21 | // ----------------------------------------------------------------------------------------- // 22 | #define MV_MENULEVEL_MAX 2 23 | #define MV_MENULEVEL_MIN 2 24 | // ----------------------------------------------------------------------------------------- // 25 | 26 | // ---------------------------------------- MVMENU ----------------------------------------- // 27 | 28 | typedef enum { 29 | DL_ACCEPT, 30 | DL_ABORT, 31 | DL_ABORT_BLACKLIST, 32 | } dldecision_t; 33 | 34 | typedef struct { 35 | char name[256]; 36 | int checkksum; 37 | qboolean blacklisted; 38 | } dlfile_t; 39 | 40 | // ******** SYSCALLS ******** // 41 | 42 | #define UI_MVAPI_CONTINUE_DOWNLOAD 300 /* asm: -301 */ 43 | #define UI_MVAPI_GETDLLIST 301 /* asm: -302 */ 44 | #define UI_MVAPI_RMDLPREFIX 302 /* asm: -303 */ 45 | #define UI_MVAPI_DELDLFILE 303 /* asm: -304 */ 46 | 47 | // ----------------------------------------------------------------------------------------- // 48 | 49 | #endif /* MVMENU_H */ 50 | -------------------------------------------------------------------------------- /code/cgame/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | set(MVCGAMEHEADERS 7 | "${SRCDir}/api/mvapi.h" 8 | 9 | "${SRCDir}/cgame/animtable.h" 10 | "${SRCDir}/cgame/cg_lights.h" 11 | "${SRCDir}/cgame/cg_local.h" 12 | "${SRCDir}/cgame/cg_media.h" 13 | "${SRCDir}/cgame/cg_public.h" 14 | "${SRCDir}/cgame/fx_local.h" 15 | "${SRCDir}/cgame/tr_types.h" 16 | "${SRCDir}/cgame/cg_multiversion.h" 17 | "${SRCDir}/cgame/cg_multiversion_syscalls.h" 18 | 19 | "${SRCDir}/game/anims.h" 20 | "${SRCDir}/game/bg_local.h" 21 | "${SRCDir}/game/bg_public.h" 22 | "${SRCDir}/game/bg_saga.h" 23 | "${SRCDir}/game/bg_weapons.h" 24 | "${SRCDir}/game/q_shared.h" 25 | "${SRCDir}/game/surfaceflags.h" 26 | "${SRCDir}/game/bg_multiversion.h" 27 | 28 | "${SRCDir}/ui/ui_shared.h" 29 | 30 | "${SRCDir}/qcommon/qfiles.h" 31 | "${SRCDir}/qcommon/tags.h" 32 | 33 | "${SRCDir}/ghoul2/g2.h" 34 | ) 35 | 36 | set(MVCGAMESOURCES 37 | "${SRCDir}/cgame/cg_main.c" # keep this on top (qvm compiler needs VM_Main as the first compiled function) 38 | "${SRCDir}/cgame/cg_consolecmds.c" 39 | "${SRCDir}/cgame/cg_draw.c" 40 | "${SRCDir}/cgame/cg_drawtools.c" 41 | "${SRCDir}/cgame/cg_effects.c" 42 | "${SRCDir}/cgame/cg_ents.c" 43 | "${SRCDir}/cgame/cg_event.c" 44 | "${SRCDir}/cgame/cg_info.c" 45 | "${SRCDir}/cgame/cg_light.c" 46 | "${SRCDir}/cgame/cg_localents.c" 47 | "${SRCDir}/cgame/cg_marks.c" 48 | "${SRCDir}/cgame/cg_newDraw.c" 49 | "${SRCDir}/cgame/cg_players.c" 50 | "${SRCDir}/cgame/cg_playerstate.c" 51 | "${SRCDir}/cgame/cg_predict.c" 52 | "${SRCDir}/cgame/cg_saga.c" 53 | "${SRCDir}/cgame/cg_scoreboard.c" 54 | "${SRCDir}/cgame/cg_servercmds.c" 55 | "${SRCDir}/cgame/cg_snapshot.c" 56 | "${SRCDir}/cgame/cg_turret.c" 57 | "${SRCDir}/cgame/cg_view.c" 58 | "${SRCDir}/cgame/cg_weaponinit.c" 59 | "${SRCDir}/cgame/cg_weapons.c" 60 | "${SRCDir}/cgame/fx_blaster.c" 61 | "${SRCDir}/cgame/fx_bowcaster.c" 62 | "${SRCDir}/cgame/fx_bryarpistol.c" 63 | "${SRCDir}/cgame/fx_demp2.c" 64 | "${SRCDir}/cgame/fx_disruptor.c" 65 | "${SRCDir}/cgame/fx_flechette.c" 66 | "${SRCDir}/cgame/fx_force.c" 67 | "${SRCDir}/cgame/fx_heavyrepeater.c" 68 | "${SRCDir}/cgame/fx_rocketlauncher.c" 69 | "${SRCDir}/cgame/cg_multiversion.c" 70 | "${SRCDir}/cgame/cg_multiversion_syscalls.c" 71 | "${SRCDir}/game/bg_multiversion.c" 72 | "${SRCDir}/game/animMappingTable.c" 73 | 74 | "${SRCDir}/game/bg_misc.c" 75 | "${SRCDir}/game/bg_panimate.c" 76 | "${SRCDir}/game/bg_pmove.c" 77 | "${SRCDir}/game/bg_saber.c" 78 | "${SRCDir}/game/bg_slidemove.c" 79 | "${SRCDir}/game/bg_weapons.c" 80 | "${SRCDir}/game/q_math.c" 81 | "${SRCDir}/game/q_shared.c" 82 | 83 | "${SRCDir}/ui/ui_shared.c" 84 | ) 85 | 86 | set(MVCGAMEASM 87 | "${SRCDir}/cgame/cg_syscalls.asm" 88 | PARENT_SCOPE 89 | ) 90 | 91 | set(MVCGAMEFILES 92 | ${MVCGAMEHEADERS} 93 | ${MVCGAMESOURCES} 94 | "${SRCDir}/cgame/cg_syscalls.c" 95 | ) 96 | 97 | set(MVCGAMEVMSOURCES ${MVCGAMESOURCES} 98 | "${SRCDir}/game/bg_lib.c" 99 | PARENT_SCOPE 100 | ) 101 | 102 | add_library(${MVCGAME} SHARED ${MVCGAMEFILES}) 103 | 104 | # Defines 105 | set(MVCGAMEDefines ${MVCGAMEDefines} "JK2_CGAME") 106 | set(MVCGAMEIncludeDirs ${MVGLOBALIncludeDirs}) 107 | 108 | set_target_properties(${MVCGAME} PROPERTIES PREFIX "") # remove "lib" prefix for .so/.dylib files 109 | 110 | set_property(TARGET ${MVCGAME} APPEND PROPERTY COMPILE_DEFINITIONS 111 | $<$:${GlobalDefines} ${MVCGAMEDefines} ${DebugDefines}> 112 | $<$:${GlobalDefines} ${MVCGAMEDefines} ${ReleaseDefines}> 113 | $<$:${GlobalDefines} ${MVCGAMEDefines} ${ReleaseDefines}> 114 | ) 115 | 116 | set_target_properties(${MVCGAME} PROPERTIES INCLUDE_DIRECTORIES "${MVCGAMEIncludeDirs}") 117 | set_target_properties(${MVCGAME} PROPERTIES PROJECT_LABEL "CGame Module") 118 | if(InMV) 119 | set_property(TARGET ${MVCGAME} PROPERTY FOLDER "Modules") 120 | endif() 121 | -------------------------------------------------------------------------------- /code/cgame/cg_effects.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mvdevs/mvsdk/29f5f9361405f34bb028670b62d565ff1ece03db/code/cgame/cg_effects.c -------------------------------------------------------------------------------- /code/cgame/cg_light.c: -------------------------------------------------------------------------------- 1 | #include "cg_local.h" 2 | 3 | #if !defined(CG_LIGHTS_H_INC) 4 | #include "cg_lights.h" 5 | #endif 6 | 7 | static clightstyle_t cl_lightstyle[MAX_LIGHT_STYLES]; 8 | static int lastofs; 9 | 10 | /* 11 | ================ 12 | FX_ClearLightStyles 13 | ================ 14 | */ 15 | void CG_ClearLightStyles (void) 16 | { 17 | int i; 18 | 19 | memset (cl_lightstyle, 0, sizeof(cl_lightstyle)); 20 | lastofs = -1; 21 | 22 | for(i=0;ilength) 47 | { 48 | ls->value[0] = ls->value[1] = ls->value[2] = ls->value[3] = 255; 49 | } 50 | else if (ls->length == 1) 51 | { 52 | ls->value[0] = ls->map[0][0]; 53 | ls->value[1] = ls->map[0][1]; 54 | ls->value[2] = ls->map[0][2]; 55 | ls->value[3] = 255; //ls->map[0][3]; 56 | } 57 | else 58 | { 59 | ls->value[0] = ls->map[ofs%ls->length][0]; 60 | ls->value[1] = ls->map[ofs%ls->length][1]; 61 | ls->value[2] = ls->map[ofs%ls->length][2]; 62 | ls->value[3] = 255; //ls->map[ofs%ls->length][3]; 63 | } 64 | trap_R_SetLightStyle(i, *(int*)ls->value); 65 | } 66 | } 67 | 68 | void CG_SetLightstyle (int i) 69 | { 70 | const char *s; 71 | int j, k; 72 | 73 | s = CG_ConfigString( i+CS_LIGHT_STYLES ); 74 | j = strlen (s); 75 | if (j >= MAX_QPATH) 76 | { 77 | Com_Error (ERR_DROP, "svc_lightstyle length=%i", j); 78 | } 79 | 80 | cl_lightstyle[(i/3)].length = j; 81 | for (k=0 ; kcurrentState.pos.trDelta, forward ) == 0.0f ) 16 | { 17 | forward[2] = 1.0f; 18 | } 19 | 20 | trap_FX_PlayEffectID( cgs.effects.blasterShotEffect, cent->lerpOrigin, forward ); 21 | } 22 | 23 | /* 24 | ------------------------- 25 | FX_BlasterAltFireThink 26 | ------------------------- 27 | */ 28 | void FX_BlasterAltFireThink( centity_t *cent, const struct weaponInfo_s *weapon ) 29 | { 30 | vec3_t forward; 31 | 32 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 33 | { 34 | forward[2] = 1.0f; 35 | } 36 | 37 | trap_FX_PlayEffectID( cgs.effects.blasterShotEffect, cent->lerpOrigin, forward ); 38 | } 39 | 40 | /* 41 | ------------------------- 42 | FX_BlasterWeaponHitWall 43 | ------------------------- 44 | */ 45 | void FX_BlasterWeaponHitWall( vec3_t origin, vec3_t normal ) 46 | { 47 | trap_FX_PlayEffectID( cgs.effects.blasterWallImpactEffect, origin, normal ); 48 | } 49 | 50 | /* 51 | ------------------------- 52 | FX_BlasterWeaponHitPlayer 53 | ------------------------- 54 | */ 55 | void FX_BlasterWeaponHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 56 | { 57 | if ( humanoid ) 58 | { 59 | trap_FX_PlayEffectID( cgs.effects.blasterFleshImpactEffect, origin, normal ); 60 | } 61 | else 62 | { 63 | trap_FX_PlayEffectID( cgs.effects.blasterDroidImpactEffect, origin, normal ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /code/cgame/fx_bowcaster.c: -------------------------------------------------------------------------------- 1 | // Bowcaster Weapon 2 | 3 | #include "cg_local.h" 4 | 5 | /* 6 | --------------------------- 7 | FX_BowcasterProjectileThink 8 | --------------------------- 9 | */ 10 | 11 | void FX_BowcasterProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 12 | { 13 | vec3_t forward; 14 | 15 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 16 | { 17 | forward[2] = 1.0f; 18 | } 19 | 20 | trap_FX_PlayEffectID( cgs.effects.bowcasterShotEffect, cent->lerpOrigin, forward ); 21 | } 22 | 23 | /* 24 | --------------------------- 25 | FX_BowcasterHitWall 26 | --------------------------- 27 | */ 28 | 29 | void FX_BowcasterHitWall( vec3_t origin, vec3_t normal ) 30 | { 31 | trap_FX_PlayEffectID( cgs.effects.bowcasterImpactEffect, origin, normal ); 32 | } 33 | 34 | /* 35 | --------------------------- 36 | FX_BowcasterHitPlayer 37 | --------------------------- 38 | */ 39 | 40 | void FX_BowcasterHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 41 | { 42 | trap_FX_PlayEffectID( cgs.effects.bowcasterImpactEffect, origin, normal ); 43 | } 44 | 45 | /* 46 | ------------------------------ 47 | FX_BowcasterAltProjectileThink 48 | ------------------------------ 49 | */ 50 | 51 | void FX_BowcasterAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 52 | { 53 | vec3_t forward; 54 | 55 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 56 | { 57 | forward[2] = 1.0f; 58 | } 59 | 60 | trap_FX_PlayEffectID( cgs.effects.bowcasterShotEffect, cent->lerpOrigin, forward ); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /code/cgame/fx_bryarpistol.c: -------------------------------------------------------------------------------- 1 | // Bryar Pistol Weapon Effects 2 | 3 | #include "cg_local.h" 4 | 5 | /* 6 | ------------------------- 7 | 8 | MAIN FIRE 9 | 10 | ------------------------- 11 | FX_BryarProjectileThink 12 | ------------------------- 13 | */ 14 | void FX_BryarProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 15 | { 16 | vec3_t forward; 17 | 18 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 19 | { 20 | forward[2] = 1.0f; 21 | } 22 | 23 | trap_FX_PlayEffectID( cgs.effects.bryarShotEffect, cent->lerpOrigin, forward ); 24 | } 25 | 26 | /* 27 | ------------------------- 28 | FX_BryarHitWall 29 | ------------------------- 30 | */ 31 | void FX_BryarHitWall( vec3_t origin, vec3_t normal ) 32 | { 33 | trap_FX_PlayEffectID( cgs.effects.bryarWallImpactEffect, origin, normal ); 34 | } 35 | 36 | /* 37 | ------------------------- 38 | FX_BryarHitPlayer 39 | ------------------------- 40 | */ 41 | void FX_BryarHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 42 | { 43 | if ( humanoid ) 44 | { 45 | trap_FX_PlayEffectID( cgs.effects.bryarFleshImpactEffect, origin, normal ); 46 | } 47 | else 48 | { 49 | trap_FX_PlayEffectID( cgs.effects.bryarDroidImpactEffect, origin, normal ); 50 | } 51 | } 52 | 53 | 54 | /* 55 | ------------------------- 56 | 57 | ALT FIRE 58 | 59 | ------------------------- 60 | FX_BryarAltProjectileThink 61 | ------------------------- 62 | */ 63 | void FX_BryarAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 64 | { 65 | vec3_t forward; 66 | int t; 67 | 68 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 69 | { 70 | forward[2] = 1.0f; 71 | } 72 | 73 | // see if we have some sort of extra charge going on 74 | for (t = 1; t < cent->currentState.generic1; t++ ) 75 | { 76 | // just add ourselves over, and over, and over when we are charged 77 | trap_FX_PlayEffectID( cgs.effects.bryarPowerupShotEffect, cent->lerpOrigin, forward ); 78 | } 79 | 80 | // for ( int t = 1; t < cent->gent->count; t++ ) // The single player stores the charge in count, which isn't accessible on the client 81 | 82 | trap_FX_PlayEffectID( cgs.effects.bryarShotEffect, cent->lerpOrigin, forward ); 83 | } 84 | 85 | /* 86 | ------------------------- 87 | FX_BryarAltHitWall 88 | ------------------------- 89 | */ 90 | void FX_BryarAltHitWall( vec3_t origin, vec3_t normal, int power ) 91 | { 92 | switch( power ) 93 | { 94 | case 4: 95 | case 5: 96 | trap_FX_PlayEffectID( cgs.effects.bryarWallImpactEffect3, origin, normal ); 97 | break; 98 | 99 | case 2: 100 | case 3: 101 | trap_FX_PlayEffectID( cgs.effects.bryarWallImpactEffect2, origin, normal ); 102 | break; 103 | 104 | default: 105 | trap_FX_PlayEffectID( cgs.effects.bryarWallImpactEffect, origin, normal ); 106 | break; 107 | } 108 | } 109 | 110 | /* 111 | ------------------------- 112 | FX_BryarAltHitPlayer 113 | ------------------------- 114 | */ 115 | void FX_BryarAltHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 116 | { 117 | if ( humanoid ) 118 | { 119 | trap_FX_PlayEffectID( cgs.effects.bryarFleshImpactEffect, origin, normal ); 120 | } 121 | else 122 | { 123 | trap_FX_PlayEffectID( cgs.effects.bryarDroidImpactEffect, origin, normal ); 124 | } 125 | } 126 | 127 | 128 | //TURRET 129 | /* 130 | ------------------------- 131 | FX_TurretProjectileThink 132 | ------------------------- 133 | */ 134 | void FX_TurretProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 135 | { 136 | vec3_t forward; 137 | 138 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 139 | { 140 | forward[2] = 1.0f; 141 | } 142 | 143 | trap_FX_PlayEffectID( cgs.effects.turretShotEffect, cent->lerpOrigin, forward ); 144 | } 145 | 146 | /* 147 | ------------------------- 148 | FX_TurretHitWall 149 | ------------------------- 150 | */ 151 | void FX_TurretHitWall( vec3_t origin, vec3_t normal ) 152 | { 153 | trap_FX_PlayEffectID( cgs.effects.bryarWallImpactEffect, origin, normal ); 154 | } 155 | 156 | /* 157 | ------------------------- 158 | FX_TurretHitPlayer 159 | ------------------------- 160 | */ 161 | void FX_TurretHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 162 | { 163 | if ( humanoid ) 164 | { 165 | trap_FX_PlayEffectID( cgs.effects.bryarFleshImpactEffect, origin, normal ); 166 | } 167 | else 168 | { 169 | trap_FX_PlayEffectID( cgs.effects.bryarDroidImpactEffect, origin, normal ); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /code/cgame/fx_disruptor.c: -------------------------------------------------------------------------------- 1 | // Disruptor Weapon 2 | 3 | #include "cg_local.h" 4 | #include "fx_local.h" 5 | 6 | /* 7 | --------------------------- 8 | FX_DisruptorMainShot 9 | --------------------------- 10 | */ 11 | static vec3_t WHITE={1.0f,1.0f,1.0f}; 12 | 13 | void FX_DisruptorMainShot( vec3_t start, vec3_t end ) 14 | { 15 | // vec3_t dir; 16 | // float len; 17 | 18 | trap_FX_AddLine( start, end, 0.1f, 6.0f, 0.0f, 19 | 1.0f, 0.0f, 0.0f, 20 | WHITE, WHITE, 0.0f, 21 | 150, trap_R_RegisterShader( "gfx/effects/redLine" ), 22 | FX_SIZE_LINEAR | FX_ALPHA_LINEAR ); 23 | 24 | // VectorSubtract( end, start, dir ); 25 | // len = VectorNormalize( dir ); 26 | 27 | // FX_AddCylinder( start, dir, 5.0f, 5.0f, 0.0f, 28 | // 5.0f, 5.0f, 0.0f, 29 | // len, len, 0.0f, 30 | // 1.0f, 1.0f, 0.0f, 31 | // WHITE, WHITE, 0.0f, 32 | // 400, cgi_R_RegisterShader( "gfx/effects/spiral" ), 0 ); 33 | } 34 | 35 | 36 | /* 37 | --------------------------- 38 | FX_DisruptorAltShot 39 | --------------------------- 40 | */ 41 | void FX_DisruptorAltShot( vec3_t start, vec3_t end, qboolean fullCharge ) 42 | { 43 | trap_FX_AddLine( start, end, 0.1f, 10.0f, 0.0f, 44 | 1.0f, 0.0f, 0.0f, 45 | WHITE, WHITE, 0.0f, 46 | 175, trap_R_RegisterShader( "gfx/effects/redLine" ), 47 | FX_SIZE_LINEAR | FX_ALPHA_LINEAR ); 48 | 49 | if ( fullCharge ) 50 | { 51 | vec3_t YELLER={0.8f,0.7f,0.0f}; 52 | 53 | // add some beef 54 | trap_FX_AddLine( start, end, 0.1f, 7.0f, 0.0f, 55 | 1.0f, 0.0f, 0.0f, 56 | YELLER, YELLER, 0.0f, 57 | 150, trap_R_RegisterShader( "gfx/misc/whiteline2" ), 58 | FX_SIZE_LINEAR | FX_ALPHA_LINEAR ); 59 | } 60 | } 61 | 62 | 63 | /* 64 | --------------------------- 65 | FX_DisruptorAltMiss 66 | --------------------------- 67 | */ 68 | #define FX_ALPHA_WAVE 0x00000008 69 | 70 | void FX_DisruptorAltMiss( vec3_t origin, vec3_t normal ) 71 | { 72 | vec3_t pos, c1, c2; 73 | addbezierArgStruct_t b; 74 | 75 | VectorMA( origin, 4.0f, normal, c1 ); 76 | VectorCopy( c1, c2 ); 77 | c1[2] += 4; 78 | c2[2] += 12; 79 | 80 | VectorAdd( origin, normal, pos ); 81 | pos[2] += 28; 82 | 83 | /* 84 | FX_AddBezier( origin, pos, c1, vec3_origin, c2, vec3_origin, 6.0f, 6.0f, 0.0f, 0.0f, 0.2f, 0.5f, 85 | WHITE, WHITE, 0.0f, 4000, trap_R_RegisterShader( "gfx/effects/smokeTrail" ), FX_ALPHA_WAVE ); 86 | */ 87 | 88 | VectorCopy(origin, b.start); 89 | VectorCopy(pos, b.end); 90 | VectorCopy(c1, b.control1); 91 | VectorCopy(vec3_origin, b.control1Vel); 92 | VectorCopy(c2, b.control2); 93 | VectorCopy(vec3_origin, b.control2Vel); 94 | 95 | b.size1 = 6.0f; 96 | b.size2 = 6.0f; 97 | b.sizeParm = 0.0f; 98 | b.alpha1 = 0.0f; 99 | b.alpha2 = 0.2f; 100 | b.alphaParm = 0.5f; 101 | 102 | VectorCopy(WHITE, b.sRGB); 103 | VectorCopy(WHITE, b.eRGB); 104 | 105 | b.rgbParm = 0.0f; 106 | b.killTime = 4000; 107 | b.shader = trap_R_RegisterShader( "gfx/effects/smokeTrail" ); 108 | b.flags = FX_ALPHA_WAVE; 109 | 110 | trap_FX_AddBezier(&b); 111 | 112 | trap_FX_PlayEffectID( cgs.effects.disruptorAltMissEffect, origin, normal ); 113 | } 114 | 115 | /* 116 | --------------------------- 117 | FX_DisruptorAltHit 118 | --------------------------- 119 | */ 120 | 121 | void FX_DisruptorAltHit( vec3_t origin, vec3_t normal ) 122 | { 123 | trap_FX_PlayEffectID( cgs.effects.disruptorAltHitEffect, origin, normal ); 124 | } 125 | 126 | 127 | 128 | /* 129 | --------------------------- 130 | FX_DisruptorHitWall 131 | --------------------------- 132 | */ 133 | 134 | void FX_DisruptorHitWall( vec3_t origin, vec3_t normal ) 135 | { 136 | trap_FX_PlayEffectID( cgs.effects.disruptorWallImpactEffect, origin, normal ); 137 | } 138 | 139 | /* 140 | --------------------------- 141 | FX_DisruptorHitPlayer 142 | --------------------------- 143 | */ 144 | 145 | void FX_DisruptorHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 146 | { 147 | trap_FX_PlayEffectID( cgs.effects.disruptorFleshImpactEffect, origin, normal ); 148 | } 149 | -------------------------------------------------------------------------------- /code/cgame/fx_flechette.c: -------------------------------------------------------------------------------- 1 | // Golan Arms Flechette Weapon 2 | 3 | #include "cg_local.h" 4 | 5 | /* 6 | ------------------------- 7 | FX_FlechetteProjectileThink 8 | ------------------------- 9 | */ 10 | 11 | void FX_FlechetteProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 12 | { 13 | vec3_t forward; 14 | 15 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 16 | { 17 | forward[2] = 1.0f; 18 | } 19 | 20 | trap_FX_PlayEffectID( cgs.effects.flechetteShotEffect, cent->lerpOrigin, forward ); 21 | } 22 | 23 | /* 24 | ------------------------- 25 | FX_FlechetteWeaponHitWall 26 | ------------------------- 27 | */ 28 | void FX_FlechetteWeaponHitWall( vec3_t origin, vec3_t normal ) 29 | { 30 | trap_FX_PlayEffectID( cgs.effects.flechetteWallImpactEffect, origin, normal ); 31 | } 32 | 33 | /* 34 | ------------------------- 35 | FX_FlechetteWeaponHitPlayer 36 | ------------------------- 37 | */ 38 | void FX_FlechetteWeaponHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 39 | { 40 | // if ( humanoid ) 41 | // { 42 | trap_FX_PlayEffectID( cgs.effects.flechetteFleshImpactEffect, origin, normal ); 43 | // } 44 | // else 45 | // { 46 | // trap_FX_PlayEffect( "blaster/droid_impact", origin, normal ); 47 | // } 48 | } 49 | 50 | 51 | /* 52 | ------------------------- 53 | FX_FlechetteProjectileThink 54 | ------------------------- 55 | */ 56 | 57 | void FX_FlechetteAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 58 | { 59 | vec3_t forward; 60 | 61 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 62 | { 63 | forward[2] = 1.0f; 64 | } 65 | 66 | trap_FX_PlayEffectID( cgs.effects.flechetteAltShotEffect, cent->lerpOrigin, forward ); 67 | } 68 | -------------------------------------------------------------------------------- /code/cgame/fx_force.c: -------------------------------------------------------------------------------- 1 | // Any dedicated force oriented effects 2 | 3 | #include "cg_local.h" 4 | 5 | /* 6 | ------------------------- 7 | FX_ForceDrained 8 | ------------------------- 9 | */ 10 | // This effect is not generic because of possible enhancements 11 | void FX_ForceDrained(vec3_t origin, vec3_t dir) 12 | { 13 | VectorScale(dir, -1.0, dir); 14 | trap_FX_PlayEffectID(cgs.effects.forceDrained, origin, dir); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /code/cgame/fx_heavyrepeater.c: -------------------------------------------------------------------------------- 1 | // Heavy Repeater Weapon 2 | 3 | #include "cg_local.h" 4 | 5 | /* 6 | --------------------------- 7 | FX_RepeaterProjectileThink 8 | --------------------------- 9 | */ 10 | 11 | void FX_RepeaterProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 12 | { 13 | vec3_t forward; 14 | 15 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 16 | { 17 | forward[2] = 1.0f; 18 | } 19 | 20 | trap_FX_PlayEffectID( cgs.effects.repeaterProjectileEffect, cent->lerpOrigin, forward ); 21 | } 22 | 23 | /* 24 | ------------------------ 25 | FX_RepeaterHitWall 26 | ------------------------ 27 | */ 28 | 29 | void FX_RepeaterHitWall( vec3_t origin, vec3_t normal ) 30 | { 31 | trap_FX_PlayEffectID( cgs.effects.repeaterWallImpactEffect, origin, normal ); 32 | } 33 | 34 | /* 35 | ------------------------ 36 | FX_RepeaterHitPlayer 37 | ------------------------ 38 | */ 39 | 40 | void FX_RepeaterHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 41 | { 42 | trap_FX_PlayEffectID( cgs.effects.repeaterFleshImpactEffect, origin, normal ); 43 | } 44 | 45 | /* 46 | ------------------------------ 47 | FX_RepeaterAltProjectileThink 48 | ----------------------------- 49 | */ 50 | 51 | void FX_RepeaterAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 52 | { 53 | vec3_t forward; 54 | 55 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 56 | { 57 | forward[2] = 1.0f; 58 | } 59 | 60 | trap_FX_PlayEffectID( cgs.effects.repeaterAltProjectileEffect, cent->lerpOrigin, forward ); 61 | } 62 | 63 | /* 64 | ------------------------ 65 | FX_RepeaterAltHitWall 66 | ------------------------ 67 | */ 68 | 69 | void FX_RepeaterAltHitWall( vec3_t origin, vec3_t normal ) 70 | { 71 | trap_FX_PlayEffectID( cgs.effects.repeaterAltWallImpactEffect, origin, normal ); 72 | } 73 | 74 | /* 75 | ------------------------ 76 | FX_RepeaterAltHitPlayer 77 | ------------------------ 78 | */ 79 | 80 | void FX_RepeaterAltHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 81 | { 82 | trap_FX_PlayEffectID( cgs.effects.repeaterAltWallImpactEffect, origin, normal ); 83 | } 84 | -------------------------------------------------------------------------------- /code/cgame/fx_local.h: -------------------------------------------------------------------------------- 1 | // 2 | // fx_*.c 3 | // 4 | 5 | // NOTENOTE This is not the best, DO NOT CHANGE THESE! 6 | #define FX_ALPHA_LINEAR 0x00000001 7 | #define FX_SIZE_LINEAR 0x00000100 8 | 9 | 10 | 11 | // Bryar 12 | void FX_BryarProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 13 | void FX_BryarAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 14 | void FX_BryarHitWall( vec3_t origin, vec3_t normal ); 15 | void FX_BryarAltHitWall( vec3_t origin, vec3_t normal, int power ); 16 | void FX_BryarHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 17 | void FX_BryarAltHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 18 | 19 | // Blaster 20 | void FX_BlasterProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 21 | void FX_BlasterAltFireThink( centity_t *cent, const struct weaponInfo_s *weapon ); 22 | void FX_BlasterWeaponHitWall( vec3_t origin, vec3_t normal ); 23 | void FX_BlasterWeaponHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 24 | 25 | // Disruptor 26 | void FX_DisruptorMainShot( vec3_t start, vec3_t end ); 27 | void FX_DisruptorAltShot( vec3_t start, vec3_t end, qboolean fullCharge ); 28 | void FX_DisruptorAltMiss( vec3_t origin, vec3_t normal ); 29 | void FX_DisruptorAltHit( vec3_t origin, vec3_t normal ); 30 | void FX_DisruptorHitWall( vec3_t origin, vec3_t normal ); 31 | void FX_DisruptorHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 32 | 33 | // Bowcaster 34 | void FX_BowcasterProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 35 | void FX_BowcasterAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 36 | void FX_BowcasterHitWall( vec3_t origin, vec3_t normal ); 37 | void FX_BowcasterHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 38 | 39 | // Heavy Repeater 40 | void FX_RepeaterProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 41 | void FX_RepeaterAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 42 | void FX_RepeaterHitWall( vec3_t origin, vec3_t normal ); 43 | void FX_RepeaterAltHitWall( vec3_t origin, vec3_t normal ); 44 | void FX_RepeaterHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 45 | void FX_RepeaterAltHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 46 | 47 | // DEMP2 48 | void FX_DEMP2_ProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 49 | void FX_DEMP2_HitWall( vec3_t origin, vec3_t normal ); 50 | void FX_DEMP2_HitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 51 | void FX_DEMP2_AltDetonate( vec3_t org, float size ); 52 | 53 | // Golan Arms Flechette 54 | void FX_FlechetteProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 55 | void FX_FlechetteWeaponHitWall( vec3_t origin, vec3_t normal ); 56 | void FX_FlechetteWeaponHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 57 | void FX_FlechetteAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 58 | 59 | // Personal Rocket Launcher 60 | void FX_RocketProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 61 | void FX_RocketAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ); 62 | void FX_RocketHitWall( vec3_t origin, vec3_t normal ); 63 | void FX_RocketHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ); 64 | -------------------------------------------------------------------------------- /code/cgame/fx_rocketlauncher.c: -------------------------------------------------------------------------------- 1 | // Rocket Launcher Weapon 2 | 3 | #include "cg_local.h" 4 | 5 | /* 6 | --------------------------- 7 | FX_RocketProjectileThink 8 | --------------------------- 9 | */ 10 | 11 | void FX_RocketProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 12 | { 13 | vec3_t forward; 14 | 15 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 16 | { 17 | forward[2] = 1.0f; 18 | } 19 | 20 | trap_FX_PlayEffectID( cgs.effects.rocketShotEffect, cent->lerpOrigin, forward ); 21 | } 22 | 23 | /* 24 | --------------------------- 25 | FX_RocketHitWall 26 | --------------------------- 27 | */ 28 | 29 | void FX_RocketHitWall( vec3_t origin, vec3_t normal ) 30 | { 31 | trap_FX_PlayEffectID( cgs.effects.rocketExplosionEffect, origin, normal ); 32 | } 33 | 34 | /* 35 | --------------------------- 36 | FX_RocketHitPlayer 37 | --------------------------- 38 | */ 39 | 40 | void FX_RocketHitPlayer( vec3_t origin, vec3_t normal, qboolean humanoid ) 41 | { 42 | trap_FX_PlayEffectID( cgs.effects.rocketExplosionEffect, origin, normal ); 43 | } 44 | 45 | /* 46 | --------------------------- 47 | FX_RocketAltProjectileThink 48 | --------------------------- 49 | */ 50 | 51 | void FX_RocketAltProjectileThink( centity_t *cent, const struct weaponInfo_s *weapon ) 52 | { 53 | vec3_t forward; 54 | 55 | if ( VectorNormalize2( cent->currentState.pos.trDelta, forward ) == 0.0f ) 56 | { 57 | forward[2] = 1.0f; 58 | } 59 | 60 | trap_FX_PlayEffectID( cgs.effects.rocketShotEffect, cent->lerpOrigin, forward ); 61 | } 62 | -------------------------------------------------------------------------------- /code/game/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | set(MVGAMEHEADERS 7 | "${SRCDir}/game/ai_main.h" 8 | "${SRCDir}/game/anims.h" 9 | "${SRCDir}/game/be_aas.h" 10 | "${SRCDir}/game/be_ai_char.h" 11 | "${SRCDir}/game/be_ai_chat.h" 12 | "${SRCDir}/game/be_ai_gen.h" 13 | "${SRCDir}/game/be_ai_goal.h" 14 | "${SRCDir}/game/be_ai_move.h" 15 | "${SRCDir}/game/be_ai_weap.h" 16 | "${SRCDir}/game/be_ea.h" 17 | "${SRCDir}/game/bg_local.h" 18 | "${SRCDir}/game/bg_public.h" 19 | "${SRCDir}/game/bg_saga.h" 20 | "${SRCDir}/game/bg_weapons.h" 21 | "${SRCDir}/game/botlib.h" 22 | "${SRCDir}/game/chars.h" 23 | "${SRCDir}/game/g_local.h" 24 | "${SRCDir}/game/g_public.h" 25 | "${SRCDir}/game/g_team.h" 26 | "${SRCDir}/game/inv.h" 27 | "${SRCDir}/game/match.h" 28 | "${SRCDir}/game/q_shared.h" 29 | "${SRCDir}/game/surfaceflags.h" 30 | "${SRCDir}/game/syn.h" 31 | "${SRCDir}/game/w_saber.h" 32 | "${SRCDir}/game/g_multiversion.h" 33 | "${SRCDir}/game/g_multiversion_syscalls.h" 34 | "${SRCDir}/game/bg_multiversion.h" 35 | 36 | "${SRCDir}/cgame/animtable.h" 37 | "${SRCDir}/cgame/cg_local.h" 38 | "${SRCDir}/cgame/cg_public.h" 39 | "${SRCDir}/cgame/tr_types.h" 40 | 41 | "${SRCDir}/qcommon/tags.h" 42 | 43 | "${SRCDir}/ghoul2/g2.h" 44 | 45 | "${SRCDir}/api/mvapi.h" 46 | ) 47 | 48 | set(MVGAMESOURCES 49 | "${SRCDir}/game/g_main.c" # keep this on top (qvm compiler needs VM_Main as the first compiled function) 50 | "${SRCDir}/game/ai_main.c" 51 | "${SRCDir}/game/ai_util.c" 52 | "${SRCDir}/game/ai_wpnav.c" 53 | "${SRCDir}/game/bg_misc.c" 54 | "${SRCDir}/game/bg_panimate.c" 55 | "${SRCDir}/game/bg_pmove.c" 56 | "${SRCDir}/game/bg_saber.c" 57 | "${SRCDir}/game/bg_slidemove.c" 58 | "${SRCDir}/game/bg_weapons.c" 59 | "${SRCDir}/game/g_active.c" 60 | "${SRCDir}/game/g_arenas.c" 61 | "${SRCDir}/game/g_bot.c" 62 | "${SRCDir}/game/g_client.c" 63 | "${SRCDir}/game/g_cmds.c" 64 | "${SRCDir}/game/g_combat.c" 65 | "${SRCDir}/game/g_items.c" 66 | "${SRCDir}/game/g_log.c" 67 | "${SRCDir}/game/g_mem.c" 68 | "${SRCDir}/game/g_misc.c" 69 | "${SRCDir}/game/g_missile.c" 70 | "${SRCDir}/game/g_mover.c" 71 | "${SRCDir}/game/g_object.c" 72 | "${SRCDir}/game/g_saga.c" 73 | "${SRCDir}/game/g_session.c" 74 | "${SRCDir}/game/g_spawn.c" 75 | "${SRCDir}/game/g_svcmds.c" 76 | "${SRCDir}/game/g_target.c" 77 | "${SRCDir}/game/g_team.c" 78 | "${SRCDir}/game/g_trigger.c" 79 | "${SRCDir}/game/g_utils.c" 80 | "${SRCDir}/game/g_weapon.c" 81 | "${SRCDir}/game/q_math.c" 82 | "${SRCDir}/game/q_shared.c" 83 | "${SRCDir}/game/w_force.c" 84 | "${SRCDir}/game/w_saber.c" 85 | "${SRCDir}/game/g_multiversion.c" 86 | "${SRCDir}/game/g_multiversion_syscalls.c" 87 | "${SRCDir}/game/bg_multiversion.c" 88 | "${SRCDir}/game/animMappingTable.c" 89 | ) 90 | 91 | set(MVGAMEASM 92 | "${SRCDir}/game/g_syscalls.asm" 93 | PARENT_SCOPE 94 | ) 95 | 96 | set(MVGAMEFILES 97 | ${MVGAMEHEADERS} 98 | ${MVGAMESOURCES} 99 | "${SRCDir}/game/g_syscalls.c" 100 | ) 101 | 102 | set(MVGAMEVMSOURCES ${MVGAMESOURCES} 103 | "${SRCDir}/game/bg_lib.c" 104 | PARENT_SCOPE 105 | ) 106 | 107 | add_library(${MVGAME} SHARED ${MVGAMEFILES}) 108 | 109 | # Defines 110 | set(MVGAMEDefines ${MVGAMEDefines} "QAGAME") 111 | set(MVGAMEDefines ${MVGAMEDefines} "JK2_GAME") 112 | set(MVGAMEIncludeDirs ${MVGLOBALIncludeDirs}) 113 | 114 | set_target_properties(${MVGAME} PROPERTIES PREFIX "") # remove "lib" prefix for .so/.dylib files 115 | 116 | set_property(TARGET ${MVGAME} APPEND PROPERTY COMPILE_DEFINITIONS 117 | $<$:${GlobalDefines} ${MVGAMEDefines} ${DebugDefines}> 118 | $<$:${GlobalDefines} ${MVGAMEDefines} ${ReleaseDefines}> 119 | $<$:${GlobalDefines} ${MVGAMEDefines} ${ReleaseDefines}> 120 | ) 121 | 122 | set_target_properties(${MVGAME} PROPERTIES INCLUDE_DIRECTORIES "${MVGAMEIncludeDirs}") 123 | set_target_properties(${MVGAME} PROPERTIES PROJECT_LABEL "Game Module") 124 | if(InMV) 125 | set_property(TARGET ${MVGAME} PROPERTY FOLDER "Modules") 126 | endif() 127 | -------------------------------------------------------------------------------- /code/game/be_ai_char.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | 4 | /***************************************************************************** 5 | * name: be_ai_char.h 6 | * 7 | * desc: bot characters 8 | * 9 | * $Archive: /source/code/botlib/be_ai_char.h $ 10 | * $Author: Mrelusive $ 11 | * $Revision: 2 $ 12 | * $Modtime: 10/05/99 3:32p $ 13 | * $Date: 10/05/99 3:42p $ 14 | * 15 | *****************************************************************************/ 16 | 17 | //loads a bot character from a file 18 | int BotLoadCharacter(char *charfile, float skill); 19 | //frees a bot character 20 | void BotFreeCharacter(int character); 21 | //returns a float characteristic 22 | float Characteristic_Float(int character, int index); 23 | //returns a bounded float characteristic 24 | float Characteristic_BFloat(int character, int index, float min, float max); 25 | //returns an integer characteristic 26 | int Characteristic_Integer(int character, int index); 27 | //returns a bounded integer characteristic 28 | int Characteristic_BInteger(int character, int index, int min, int max); 29 | //returns a string characteristic 30 | void Characteristic_String(int character, int index, char *buf, int size); 31 | //free cached bot characters 32 | void BotShutdownCharacters(void); 33 | -------------------------------------------------------------------------------- /code/game/be_ai_chat.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | /***************************************************************************** 4 | * name: be_ai_chat.h 5 | * 6 | * desc: char AI 7 | * 8 | * $Archive: /source/code/botlib/be_ai_chat.h $ 9 | * $Author: Mrelusive $ 10 | * $Revision: 2 $ 11 | * $Modtime: 10/05/99 3:32p $ 12 | * $Date: 10/05/99 3:42p $ 13 | * 14 | *****************************************************************************/ 15 | 16 | #define MAX_MESSAGE_SIZE 256 17 | #define MAX_CHATTYPE_NAME 32 18 | #define MAX_MATCHVARIABLES 8 19 | 20 | #define CHAT_GENDERLESS 0 21 | #define CHAT_GENDERFEMALE 1 22 | #define CHAT_GENDERMALE 2 23 | 24 | #define CHAT_ALL 0 25 | #define CHAT_TEAM 1 26 | #define CHAT_TELL 2 27 | 28 | //a console message 29 | typedef struct bot_consolemessage_s 30 | { 31 | int handle; 32 | float time; //message time 33 | int type; //message type 34 | char message[MAX_MESSAGE_SIZE]; //message 35 | struct bot_consolemessage_s *prev, *next; //prev and next in list 36 | } bot_consolemessage_t; 37 | 38 | //match variable 39 | typedef struct bot_matchvariable_s 40 | { 41 | char offset; 42 | int length; 43 | } bot_matchvariable_t; 44 | //returned to AI when a match is found 45 | typedef struct bot_match_s 46 | { 47 | char string[MAX_MESSAGE_SIZE]; 48 | int type; 49 | int subtype; 50 | bot_matchvariable_t variables[MAX_MATCHVARIABLES]; 51 | } bot_match_t; 52 | 53 | //setup the chat AI 54 | int BotSetupChatAI(void); 55 | //shutdown the chat AI 56 | void BotShutdownChatAI(void); 57 | //returns the handle to a newly allocated chat state 58 | int BotAllocChatState(void); 59 | //frees the chatstate 60 | void BotFreeChatState(int handle); 61 | //adds a console message to the chat state 62 | void BotQueueConsoleMessage(int chatstate, int type, char *message); 63 | //removes the console message from the chat state 64 | void BotRemoveConsoleMessage(int chatstate, int handle); 65 | //returns the next console message from the state 66 | int BotNextConsoleMessage(int chatstate, bot_consolemessage_t *cm); 67 | //returns the number of console messages currently stored in the state 68 | int BotNumConsoleMessages(int chatstate); 69 | //selects a chat message of the given type 70 | void BotInitialChat(int chatstate, char *type, int mcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7); 71 | //returns the number of initial chat messages of the given type 72 | int BotNumInitialChats(int chatstate, char *type); 73 | //find and select a reply for the given message 74 | int BotReplyChat(int chatstate, char *message, int mcontext, int vcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7); 75 | //returns the length of the currently selected chat message 76 | int BotChatLength(int chatstate); 77 | //enters the selected chat message 78 | void BotEnterChat(int chatstate, int clientto, int sendto); 79 | //get the chat message ready to be output 80 | void BotGetChatMessage(int chatstate, char *buf, int size); 81 | //checks if the first string contains the second one, returns index into first string or -1 if not found 82 | int StringContains(char *str1, char *str2, int casesensitive); 83 | //finds a match for the given string using the match templates 84 | int BotFindMatch(char *str, bot_match_t *match, unsigned long int context); 85 | //returns a variable from a match 86 | void BotMatchVariable(bot_match_t *match, int variable, char *buf, int size); 87 | //unify all the white spaces in the string 88 | void UnifyWhiteSpaces(char *string); 89 | //replace all the context related synonyms in the string 90 | void BotReplaceSynonyms(char *string, unsigned long int context); 91 | //loads a chat file for the chat state 92 | int BotLoadChatFile(int chatstate, char *chatfile, char *chatname); 93 | //store the gender of the bot in the chat state 94 | void BotSetChatGender(int chatstate, int gender); 95 | //store the bot name in the chat state 96 | void BotSetChatName(int chatstate, char *name, int client); 97 | 98 | -------------------------------------------------------------------------------- /code/game/be_ai_gen.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | 4 | /***************************************************************************** 5 | * name: be_ai_gen.h 6 | * 7 | * desc: genetic selection 8 | * 9 | * $Archive: /source/code/botlib/be_ai_gen.h $ 10 | * $Author: Mrelusive $ 11 | * $Revision: 2 $ 12 | * $Modtime: 10/05/99 3:32p $ 13 | * $Date: 10/05/99 3:42p $ 14 | * 15 | *****************************************************************************/ 16 | 17 | int GeneticParentsAndChildSelection(int numranks, float *ranks, int *parent1, int *parent2, int *child); 18 | -------------------------------------------------------------------------------- /code/game/be_ai_goal.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | /***************************************************************************** 4 | * name: be_ai_goal.h 5 | * 6 | * desc: goal AI 7 | * 8 | * $Archive: /source/code/botlib/be_ai_goal.h $ 9 | * $Author: Mrelusive $ 10 | * $Revision: 2 $ 11 | * $Modtime: 10/05/99 3:32p $ 12 | * $Date: 10/05/99 3:42p $ 13 | * 14 | *****************************************************************************/ 15 | 16 | #define MAX_AVOIDGOALS 256 17 | #define MAX_GOALSTACK 8 18 | 19 | #define GFL_NONE 0 20 | #define GFL_ITEM 1 21 | #define GFL_ROAM 2 22 | #define GFL_DROPPED 4 23 | 24 | //a bot goal 25 | typedef struct bot_goal_s 26 | { 27 | vec3_t origin; //origin of the goal 28 | int areanum; //area number of the goal 29 | vec3_t mins, maxs; //mins and maxs of the goal 30 | int entitynum; //number of the goal entity 31 | int number; //goal number 32 | int flags; //goal flags 33 | int iteminfo; //item information 34 | } bot_goal_t; 35 | 36 | //reset the whole goal state, but keep the item weights 37 | void BotResetGoalState(int goalstate); 38 | //reset avoid goals 39 | void BotResetAvoidGoals(int goalstate); 40 | //remove the goal with the given number from the avoid goals 41 | void BotRemoveFromAvoidGoals(int goalstate, int number); 42 | //push a goal onto the goal stack 43 | void BotPushGoal(int goalstate, bot_goal_t *goal); 44 | //pop a goal from the goal stack 45 | void BotPopGoal(int goalstate); 46 | //empty the bot's goal stack 47 | void BotEmptyGoalStack(int goalstate); 48 | //dump the avoid goals 49 | void BotDumpAvoidGoals(int goalstate); 50 | //dump the goal stack 51 | void BotDumpGoalStack(int goalstate); 52 | //get the name name of the goal with the given number 53 | void BotGoalName(int number, char *name, int size); 54 | //get the top goal from the stack 55 | int BotGetTopGoal(int goalstate, bot_goal_t *goal); 56 | //get the second goal on the stack 57 | int BotGetSecondGoal(int goalstate, bot_goal_t *goal); 58 | //choose the best long term goal item for the bot 59 | int BotChooseLTGItem(int goalstate, vec3_t origin, int *inventory, int travelflags); 60 | //choose the best nearby goal item for the bot 61 | //the item may not be further away from the current bot position than maxtime 62 | //also the travel time from the nearby goal towards the long term goal may not 63 | //be larger than the travel time towards the long term goal from the current bot position 64 | int BotChooseNBGItem(int goalstate, vec3_t origin, int *inventory, int travelflags, 65 | bot_goal_t *ltg, float maxtime); 66 | //returns true if the bot touches the goal 67 | int BotTouchingGoal(vec3_t origin, bot_goal_t *goal); 68 | //returns true if the goal should be visible but isn't 69 | int BotItemGoalInVisButNotVisible(int viewer, vec3_t eye, vec3_t viewangles, bot_goal_t *goal); 70 | //search for a goal for the given classname, the index can be used 71 | //as a start point for the search when multiple goals are available with that same classname 72 | int BotGetLevelItemGoal(int index, char *classname, bot_goal_t *goal); 73 | //get the next camp spot in the map 74 | int BotGetNextCampSpotGoal(int num, bot_goal_t *goal); 75 | //get the map location with the given name 76 | int BotGetMapLocationGoal(char *name, bot_goal_t *goal); 77 | //returns the avoid goal time 78 | float BotAvoidGoalTime(int goalstate, int number); 79 | //set the avoid goal time 80 | void BotSetAvoidGoalTime(int goalstate, int number, float avoidtime); 81 | //initializes the items in the level 82 | void BotInitLevelItems(void); 83 | //regularly update dynamic entity items (dropped weapons, flags etc.) 84 | void BotUpdateEntityItems(void); 85 | //interbreed the goal fuzzy logic 86 | void BotInterbreedGoalFuzzyLogic(int parent1, int parent2, int child); 87 | //save the goal fuzzy logic to disk 88 | void BotSaveGoalFuzzyLogic(int goalstate, char *filename); 89 | //mutate the goal fuzzy logic 90 | void BotMutateGoalFuzzyLogic(int goalstate, float range); 91 | //loads item weights for the bot 92 | int BotLoadItemWeights(int goalstate, char *filename); 93 | //frees the item weights of the bot 94 | void BotFreeItemWeights(int goalstate); 95 | //returns the handle of a newly allocated goal state 96 | int BotAllocGoalState(int client); 97 | //free the given goal state 98 | void BotFreeGoalState(int handle); 99 | //setup the goal AI 100 | int BotSetupGoalAI(void); 101 | //shut down the goal AI 102 | void BotShutdownGoalAI(void); 103 | -------------------------------------------------------------------------------- /code/game/be_ai_move.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | 4 | /***************************************************************************** 5 | * name: be_ai_move.h 6 | * 7 | * desc: movement AI 8 | * 9 | * $Archive: /source/code/botlib/be_ai_move.h $ 10 | * $Author: Mrelusive $ 11 | * $Revision: 2 $ 12 | * $Modtime: 10/05/99 3:32p $ 13 | * $Date: 10/05/99 3:42p $ 14 | * 15 | *****************************************************************************/ 16 | 17 | //movement types 18 | #define MOVE_WALK 1 19 | #define MOVE_CROUCH 2 20 | #define MOVE_JUMP 4 21 | #define MOVE_GRAPPLE 8 22 | #define MOVE_ROCKETJUMP 16 23 | #define MOVE_BFGJUMP 32 24 | //move flags 25 | #define MFL_BARRIERJUMP 1 //bot is performing a barrier jump 26 | #define MFL_ONGROUND 2 //bot is in the ground 27 | #define MFL_SWIMMING 4 //bot is swimming 28 | #define MFL_AGAINSTLADDER 8 //bot is against a ladder 29 | #define MFL_WATERJUMP 16 //bot is waterjumping 30 | #define MFL_TELEPORTED 32 //bot is being teleported 31 | #define MFL_GRAPPLEPULL 64 //bot is being pulled by the grapple 32 | #define MFL_ACTIVEGRAPPLE 128 //bot is using the grapple hook 33 | #define MFL_GRAPPLERESET 256 //bot has reset the grapple 34 | #define MFL_WALK 512 //bot should walk slowly 35 | // move result flags 36 | #define MOVERESULT_MOVEMENTVIEW 1 //bot uses view for movement 37 | #define MOVERESULT_SWIMVIEW 2 //bot uses view for swimming 38 | #define MOVERESULT_WAITING 4 //bot is waiting for something 39 | #define MOVERESULT_MOVEMENTVIEWSET 8 //bot has set the view in movement code 40 | #define MOVERESULT_MOVEMENTWEAPON 16 //bot uses weapon for movement 41 | #define MOVERESULT_ONTOPOFOBSTACLE 32 //bot is ontop of obstacle 42 | #define MOVERESULT_ONTOPOF_FUNCBOB 64 //bot is ontop of a func_bobbing 43 | #define MOVERESULT_ONTOPOF_ELEVATOR 128 //bot is ontop of an elevator (func_plat) 44 | #define MOVERESULT_BLOCKEDBYAVOIDSPOT 256 //bot is blocked by an avoid spot 45 | // 46 | #define MAX_AVOIDREACH 1 47 | #define MAX_AVOIDSPOTS 32 48 | // avoid spot types 49 | #define AVOID_CLEAR 0 //clear all avoid spots 50 | #define AVOID_ALWAYS 1 //avoid always 51 | #define AVOID_DONTBLOCK 2 //never totally block 52 | // restult types 53 | #define RESULTTYPE_ELEVATORUP 1 //elevator is up 54 | #define RESULTTYPE_WAITFORFUNCBOBBING 2 //waiting for func bobbing to arrive 55 | #define RESULTTYPE_BADGRAPPLEPATH 4 //grapple path is obstructed 56 | #define RESULTTYPE_INSOLIDAREA 8 //stuck in solid area, this is bad 57 | 58 | //structure used to initialize the movement state 59 | //the or_moveflags MFL_ONGROUND, MFL_TELEPORTED and MFL_WATERJUMP come from the playerstate 60 | typedef struct bot_initmove_s 61 | { 62 | vec3_t origin; //origin of the bot 63 | vec3_t velocity; //velocity of the bot 64 | vec3_t viewoffset; //view offset 65 | int entitynum; //entity number of the bot 66 | int client; //client number of the bot 67 | float thinktime; //time the bot thinks 68 | int presencetype; //presencetype of the bot 69 | vec3_t viewangles; //view angles of the bot 70 | int or_moveflags; //values ored to the movement flags 71 | } bot_initmove_t; 72 | 73 | //NOTE: the ideal_viewangles are only valid if MFL_MOVEMENTVIEW is set 74 | typedef struct bot_moveresult_s 75 | { 76 | int failure; //true if movement failed all together 77 | int type; //failure or blocked type 78 | int blocked; //true if blocked by an entity 79 | int blockentity; //entity blocking the bot 80 | int traveltype; //last executed travel type 81 | int flags; //result flags 82 | int weapon; //weapon used for movement 83 | vec3_t movedir; //movement direction 84 | vec3_t ideal_viewangles; //ideal viewangles for the movement 85 | } bot_moveresult_t; 86 | 87 | // bk001204: from code/botlib/be_ai_move.c 88 | // TTimo 04/12/2001 was moved here to avoid dup defines 89 | typedef struct bot_avoidspot_s 90 | { 91 | vec3_t origin; 92 | float radius; 93 | int type; 94 | } bot_avoidspot_t; 95 | 96 | //resets the whole move state 97 | void BotResetMoveState(int movestate); 98 | //moves the bot to the given goal 99 | void BotMoveToGoal(bot_moveresult_t *result, int movestate, bot_goal_t *goal, int travelflags); 100 | //moves the bot in the specified direction using the specified type of movement 101 | int BotMoveInDirection(int movestate, vec3_t dir, float speed, int type); 102 | //reset avoid reachability 103 | void BotResetAvoidReach(int movestate); 104 | //resets the last avoid reachability 105 | void BotResetLastAvoidReach(int movestate); 106 | //returns a reachability area if the origin is in one 107 | int BotReachabilityArea(vec3_t origin, int client); 108 | //view target based on movement 109 | int BotMovementViewTarget(int movestate, bot_goal_t *goal, int travelflags, float lookahead, vec3_t target); 110 | //predict the position of a player based on movement towards a goal 111 | int BotPredictVisiblePosition(vec3_t origin, int areanum, bot_goal_t *goal, int travelflags, vec3_t target); 112 | //returns the handle of a newly allocated movestate 113 | int BotAllocMoveState(void); 114 | //frees the movestate with the given handle 115 | void BotFreeMoveState(int handle); 116 | //initialize movement state before performing any movement 117 | void BotInitMoveState(int handle, bot_initmove_t *initmove); 118 | //add a spot to avoid (if type == AVOID_CLEAR all spots are removed) 119 | void BotAddAvoidSpot(int movestate, vec3_t origin, float radius, int type); 120 | //must be called every map change 121 | void BotSetBrushModelTypes(void); 122 | //setup movement AI 123 | int BotSetupMoveAI(void); 124 | //shutdown movement AI 125 | void BotShutdownMoveAI(void); 126 | 127 | -------------------------------------------------------------------------------- /code/game/be_ai_weap.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | 4 | /***************************************************************************** 5 | * name: be_ai_weap.h 6 | * 7 | * desc: weapon AI 8 | * 9 | * $Archive: /source/code/botlib/be_ai_weap.h $ 10 | * $Author: Mrelusive $ 11 | * $Revision: 2 $ 12 | * $Modtime: 10/05/99 3:32p $ 13 | * $Date: 10/05/99 3:42p $ 14 | * 15 | *****************************************************************************/ 16 | 17 | //projectile flags 18 | #define PFL_WINDOWDAMAGE 1 //projectile damages through window 19 | #define PFL_RETURN 2 //set when projectile returns to owner 20 | //weapon flags 21 | #define WFL_FIRERELEASED 1 //set when projectile is fired with key-up event 22 | //damage types 23 | #define DAMAGETYPE_IMPACT 1 //damage on impact 24 | #define DAMAGETYPE_RADIAL 2 //radial damage 25 | #define DAMAGETYPE_VISIBLE 4 //damage to all entities visible to the projectile 26 | 27 | typedef struct projectileinfo_s 28 | { 29 | char name[MAX_STRINGFIELD]; 30 | char model[MAX_STRINGFIELD]; 31 | int flags; 32 | float gravity; 33 | int damage; 34 | float radius; 35 | int visdamage; 36 | int damagetype; 37 | int healthinc; 38 | float push; 39 | float detonation; 40 | float bounce; 41 | float bouncefric; 42 | float bouncestop; 43 | } projectileinfo_t; 44 | 45 | typedef struct weaponinfo_s 46 | { 47 | int valid; //true if the weapon info is valid 48 | int number; //number of the weapon 49 | char name[MAX_STRINGFIELD]; 50 | char model[MAX_STRINGFIELD]; 51 | int level; 52 | int weaponindex; 53 | int flags; 54 | char projectile[MAX_STRINGFIELD]; 55 | int numprojectiles; 56 | float hspread; 57 | float vspread; 58 | float speed; 59 | float acceleration; 60 | vec3_t recoil; 61 | vec3_t offset; 62 | vec3_t angleoffset; 63 | float extrazvelocity; 64 | int ammoamount; 65 | int ammoindex; 66 | float activate; 67 | float reload; 68 | float spinup; 69 | float spindown; 70 | projectileinfo_t proj; //pointer to the used projectile 71 | } weaponinfo_t; 72 | 73 | //setup the weapon AI 74 | int BotSetupWeaponAI(void); 75 | //shut down the weapon AI 76 | void BotShutdownWeaponAI(void); 77 | //returns the best weapon to fight with 78 | int BotChooseBestFightWeapon(int weaponstate, int *inventory); 79 | //returns the information of the current weapon 80 | void BotGetWeaponInfo(int weaponstate, int weapon, weaponinfo_t *weaponinfo); 81 | //loads the weapon weights 82 | int BotLoadWeaponWeights(int weaponstate, char *filename); 83 | //returns a handle to a newly allocated weapon state 84 | int BotAllocWeaponState(void); 85 | //frees the weapon state 86 | void BotFreeWeaponState(int weaponstate); 87 | //resets the whole weapon state 88 | void BotResetWeaponState(int weaponstate); 89 | -------------------------------------------------------------------------------- /code/game/be_ea.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | 4 | /***************************************************************************** 5 | * name: be_ea.h 6 | * 7 | * desc: elementary actions 8 | * 9 | * $Archive: /source/code/botlib/be_ea.h $ 10 | * $Author: Mrelusive $ 11 | * $Revision: 2 $ 12 | * $Modtime: 10/05/99 3:32p $ 13 | * $Date: 10/05/99 3:42p $ 14 | * 15 | *****************************************************************************/ 16 | 17 | //ClientCommand elementary actions 18 | void EA_Say(int client, char *str); 19 | void EA_SayTeam(int client, char *str); 20 | void EA_Command(int client, char *command ); 21 | 22 | void EA_Action(int client, int action); 23 | void EA_Crouch(int client); 24 | void EA_Walk(int client); 25 | void EA_MoveUp(int client); 26 | void EA_MoveDown(int client); 27 | void EA_MoveForward(int client); 28 | void EA_MoveBack(int client); 29 | void EA_MoveLeft(int client); 30 | void EA_MoveRight(int client); 31 | void EA_Attack(int client); 32 | void EA_Alt_Attack(int client); 33 | void EA_ForcePower(int client); 34 | void EA_Respawn(int client); 35 | void EA_Talk(int client); 36 | void EA_Gesture(int client); 37 | void EA_Use(int client); 38 | 39 | //regular elementary actions 40 | void EA_SelectWeapon(int client, int weapon); 41 | void EA_Jump(int client); 42 | void EA_DelayedJump(int client); 43 | void EA_Move(int client, vec3_t dir, float speed); 44 | void EA_View(int client, vec3_t viewangles); 45 | 46 | //send regular input to the server 47 | void EA_EndRegular(int client, float thinktime); 48 | void EA_GetInput(int client, float thinktime, bot_input_t *input); 49 | void EA_ResetInput(int client); 50 | //setup and shutdown routines 51 | int EA_Setup(void); 52 | void EA_Shutdown(void); 53 | -------------------------------------------------------------------------------- /code/game/bg_lib.h: -------------------------------------------------------------------------------- 1 | // bg_lib.h -- standard C library replacement routines used by code 2 | // compiled for the virtual machine 3 | 4 | // This file is NOT included on native builds 5 | 6 | typedef int intptr_t; 7 | 8 | typedef unsigned int size_t; 9 | 10 | typedef char * va_list; 11 | #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) ) 12 | #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) ) 13 | #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) 14 | #define va_end(ap) ( ap = (va_list)0 ) 15 | 16 | #define CHAR_BIT 8 /* number of bits in a char */ 17 | #define SCHAR_MIN (-128) /* minimum signed char value */ 18 | #define SCHAR_MAX 127 /* maximum signed char value */ 19 | #define UCHAR_MAX 0xff /* maximum unsigned char value */ 20 | 21 | #define SHRT_MIN (-32768) /* minimum (signed) short value */ 22 | #define SHRT_MAX 32767 /* maximum (signed) short value */ 23 | #define USHRT_MAX 0xffff /* maximum unsigned short value */ 24 | #define INT_MIN (-2147483647 - 1) /* minimum (signed) int value */ 25 | #define INT_MAX 2147483647 /* maximum (signed) int value */ 26 | #define UINT_MAX 0xffffffff /* maximum unsigned int value */ 27 | #define LONG_MIN (-2147483647L - 1) /* minimum (signed) long value */ 28 | #define LONG_MAX 2147483647L /* maximum (signed) long value */ 29 | #define ULONG_MAX 0xffffffffUL /* maximum unsigned long value */ 30 | 31 | #define FLT_MAX 3.40282346638528859812e+38f 32 | #define HUGE_VALF (FLT_MAX + 1.0f) 33 | 34 | #define M_E 2.7182818284590452354 /* e */ 35 | #define M_LOG2E 1.4426950408889634074 /* log_2 e */ 36 | #define M_LOG10E 0.43429448190325182765 /* log_10 e */ 37 | #define M_LN2 0.69314718055994530942 /* log_e 2 */ 38 | #define M_LN10 2.30258509299404568402 /* log_e 10 */ 39 | #define M_PI 3.14159265358979323846 /* pi */ 40 | #define M_PI_2 1.57079632679489661923 /* pi/2 */ 41 | #define M_PI_4 0.78539816339744830962 /* pi/4 */ 42 | #define M_1_PI 0.31830988618379067154 /* 1/pi */ 43 | #define M_2_PI 0.63661977236758134308 /* 2/pi */ 44 | #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 45 | #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 46 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 47 | 48 | // Misc functions 49 | typedef int cmp_t(const void *, const void *); 50 | void qsort(void *a, size_t n, size_t es, cmp_t *cmp); 51 | void srand( unsigned seed ); 52 | int rand( void ); 53 | 54 | // String functions 55 | size_t strlen( const char *string ); 56 | char *strcat( char *strDestination, const char *strSource ); 57 | char *strcpy( char *strDestination, const char *strSource ); 58 | int strcmp( const char *string1, const char *string2 ); 59 | char *strchr( const char *string, int c ); 60 | char *strstr( const char *string, const char *strCharSet ); 61 | char *strncpy( char *strDest, const char *strSource, size_t count ); 62 | int tolower( int c ); 63 | int toupper( int c ); 64 | 65 | double atof( const char *string ); 66 | double _atof( const char **stringPtr ); 67 | int atoi( const char *string ); 68 | int _atoi( const char **stringPtr ); 69 | 70 | int vsnprintf( char *buffer, size_t size, const char *fmt, va_list argptr ) __attribute__ ((format (printf, 3, 4))); 71 | int sscanf( const char *buffer, const char *fmt, ... ) __attribute__ ((format (scanf, 2, 3))); 72 | 73 | // Memory functions 74 | void *memmove( void *dest, const void *src, size_t count ); 75 | void *memset( void *dest, int c, size_t count ); 76 | void *memcpy( void *dest, const void *src, size_t count ); 77 | 78 | // Math functions 79 | double ceil( double x ); 80 | double floor( double x ); 81 | double sqrt( double x ); 82 | double sin( double x ); 83 | double cos( double x ); 84 | double atan2( double y, double x ); 85 | double tan( double x ); 86 | int abs( int n ); 87 | double fabs( double x ); 88 | double acos( double x ); 89 | float roundf( float x ); 90 | float frexpf( float x, int *exp ); 91 | float expf( float x ); 92 | float logf( float a ); 93 | float powf( float x, float y ); 94 | 95 | -------------------------------------------------------------------------------- /code/game/bg_local.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | // bg_local.h -- local definitions for the bg (both games) files 4 | 5 | #define MIN_WALK_NORMAL 0.7f // can't walk on very steep slopes 6 | 7 | #define STEPSIZE 18 8 | 9 | #define TIMER_LAND 130 10 | #define TIMER_GESTURE (34*66+50) 11 | 12 | #define OVERCLIP 1.001f 13 | 14 | // all of the locals will be zeroed before each 15 | // pmove, just to make damn sure we don't have 16 | // any differences when running on client or server 17 | typedef struct 18 | { 19 | vec3_t forward, right, up; 20 | float frametime; 21 | 22 | int msec; 23 | 24 | qboolean walking; 25 | qboolean groundPlane; 26 | trace_t groundTrace; 27 | 28 | float impactSpeed; 29 | 30 | vec3_t previous_origin; 31 | vec3_t previous_velocity; 32 | int previous_waterlevel; 33 | 34 | int seed; 35 | } pml_t; 36 | 37 | extern pml_t pml; 38 | 39 | // movement parameters 40 | extern float pm_stopspeed; 41 | extern float pm_duckScale; 42 | extern float pm_swimScale; 43 | extern float pm_wadeScale; 44 | 45 | extern float pm_accelerate; 46 | extern float pm_airaccelerate; 47 | extern float pm_wateraccelerate; 48 | extern float pm_flyaccelerate; 49 | 50 | extern float pm_friction; 51 | extern float pm_waterfriction; 52 | extern float pm_flightfriction; 53 | 54 | extern int c_pmove; 55 | 56 | extern int forcePowerNeeded_1_02[NUM_FORCE_POWER_LEVELS][NUM_FORCE_POWERS]; 57 | extern int forcePowerNeeded_1_04[NUM_FORCE_POWER_LEVELS][NUM_FORCE_POWERS]; 58 | extern int (*forcePowerNeeded)[NUM_FORCE_POWERS]; 59 | 60 | // Had to add these here because there was no file access within the BG right now. 61 | int trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode ); 62 | void trap_FS_Read( void *buffer, int len, fileHandle_t f ); 63 | void trap_FS_Write( const void *buffer, int len, fileHandle_t f ); 64 | void trap_FS_FCloseFile( fileHandle_t f ); 65 | 66 | //PM anim utility functions: 67 | qboolean PM_SaberInParry( int move ); 68 | qboolean PM_SaberInKnockaway( int move ); 69 | qboolean PM_SaberInReflect( int move ); 70 | qboolean PM_SaberInStart( int move ); 71 | qboolean PM_InSaberAnim( int anim ); 72 | qboolean PM_InKnockDown( playerState_t *ps ); 73 | qboolean PM_PainAnim( int anim ); 74 | qboolean PM_JumpingAnim( int anim ); 75 | qboolean PM_LandingAnim( int anim ); 76 | qboolean PM_SpinningAnim( int anim ); 77 | qboolean PM_InOnGroundAnim ( int anim ); 78 | qboolean PM_InRollComplete( playerState_t *ps, int anim ); 79 | int PM_AnimLength( int index, animNumber_t anim ); 80 | 81 | int PM_GetSaberStance(void); 82 | float PM_GroundDistance(void); 83 | qboolean PM_SomeoneInFront(trace_t *tr); 84 | saberMoveName_t PM_SaberFlipOverAttackMove(trace_t *tr); 85 | saberMoveName_t PM_SaberJumpAttackMove( void ); 86 | 87 | void PM_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce ); 88 | void PM_AddTouchEnt( int entityNum ); 89 | void PM_AddEvent( int newEvent ); 90 | 91 | qboolean PM_SlideMove( qboolean gravity ); 92 | void PM_StepSlideMove( qboolean gravity ); 93 | 94 | void BG_CycleInven(playerState_t *ps, int direction); 95 | 96 | void PM_StartTorsoAnim( int anim ); 97 | void PM_ContinueLegsAnim( int anim ); 98 | void PM_ForceLegsAnim( int anim ); 99 | 100 | void PM_BeginWeaponChange( int weapon ); 101 | void PM_FinishWeaponChange( void ); 102 | 103 | void PM_SetAnim(int setAnimParts,int anim,int setAnimFlags, int blendTime); 104 | 105 | void PM_WeaponLightsaber(void); 106 | void PM_SetSaberMove(short newMove); 107 | 108 | void PM_SetForceJumpZStart(float value); 109 | -------------------------------------------------------------------------------- /code/game/bg_multiversion.h: -------------------------------------------------------------------------------- 1 | //bg_multiversion.h - This file contains multiversion variables and functions that are shared accross all modules... 2 | #include "../api/mvapi.h" 3 | #include "../game/q_shared.h" 4 | #include "../game/anims.h" 5 | 6 | /* Variables */ 7 | extern mvversion_t jk2version; 8 | extern mvversion_t jk2gameplay; 9 | extern mvversion_t jk2startversion; 10 | 11 | #ifndef JK2_UI // Not defined for UI, but still in bg_* for game and cgame 12 | extern animNumber_1_02_t animMappingTable_1_04_to_1_02[MAX_TOTALANIMATIONS]; 13 | extern animNumber_t animMappingTable_1_02_to_1_04[MAX_TOTALANIMATIONS_1_02]; 14 | #endif // #ifndef JK2_UI 15 | 16 | /* Functions */ 17 | #ifndef JK2_UI // Not defined for UI, but still in bg_* for game and cgame 18 | #ifdef MV_GENERATE_ANIMATION_MAPPING_TABLE 19 | extern void MV_DumpAnimationMappingTable( void ); 20 | #endif // #ifdef MV_GENERATE_ANIMATION_MAPPING_TABLE 21 | extern void MV_BuildAnimationMappingTable( void ); 22 | extern void MV_SetGamePlay( mvversion_t version ); 23 | 24 | /* Macros */ 25 | #define MV_MapAnimation104(anim) (animMappingTable_1_02_to_1_04[(anim)&~ANIM_TOGGLEBIT] | ((anim)&ANIM_TOGGLEBIT)) 26 | #define MV_MapAnimation102(anim) (animMappingTable_1_04_to_1_02[(anim)&~ANIM_TOGGLEBIT] | ((anim)&ANIM_TOGGLEBIT)) 27 | 28 | 29 | //extern int MV_VersionMagic_g2ModelParts( int limbType ); 30 | #ifndef MV_VersionMagic_g2ModelParts 31 | #ifdef JK2_GAME 32 | #define MV_VersionMagic_g2ModelParts( limbType ) ( jk2startversion != VERSION_1_02 ? limbType : (limbType >= G2_MODELPART_RHAND ? limbType-1 : limbType) ) 33 | #elif JK2_CGAME 34 | #define MV_VersionMagic_g2ModelParts( limbType ) ( jk2startversion != VERSION_1_02 ? limbType : (limbType >= G2_MODELPART_RHAND ? limbType+1 : limbType) ) 35 | #endif // #ifdef JK2_GAME 36 | #endif // #ifndef MV_VersionMagic_g2ModelParts 37 | 38 | #endif // #ifndef JK2_UI 39 | 40 | #ifndef JK2_GAME 41 | extern int Key_GetProtocolKey(mvversion_t version, int key16); 42 | extern int Key_GetProtocolKey15(mvversion_t version, int key15); 43 | #endif // #ifndef JK2_GAME 44 | 45 | -------------------------------------------------------------------------------- /code/game/bg_saga.h: -------------------------------------------------------------------------------- 1 | #define MAX_SAGA_INFO_SIZE 8192 //128000 2 | 3 | #define SAGATEAM_IMPERIAL 1 //e.g. TEAM_RED 4 | #define SAGATEAM_REBEL 2 //e.g. TEAM_BLUE 5 | 6 | #define SAGA_POINTS_OBJECTIVECOMPLETED 3 7 | #define SAGA_POINTS_FINALOBJECTIVECOMPLETED 5 8 | #define SAGA_POINTS_TEAMWONROUND 5 9 | -------------------------------------------------------------------------------- /code/game/bg_weapons.h: -------------------------------------------------------------------------------- 1 | // Filename:- bg_weapons.h 2 | // 3 | // This crosses both client and server. It could all be crammed into bg_public, but isolation of this type of data is best. 4 | 5 | #ifndef __WEAPONS_H__ 6 | #define __WEAPONS_H__ 7 | 8 | typedef enum { 9 | WP_NONE, 10 | 11 | WP_STUN_BATON, 12 | WP_SABER, // NOTE: lots of code assumes this is the first weapon (... which is crap) so be careful -Ste. 13 | WP_BRYAR_PISTOL, 14 | WP_BLASTER, 15 | WP_DISRUPTOR, 16 | WP_BOWCASTER, 17 | WP_REPEATER, 18 | WP_DEMP2, 19 | WP_FLECHETTE, 20 | WP_ROCKET_LAUNCHER, 21 | WP_THERMAL, 22 | WP_TRIP_MINE, 23 | WP_DET_PACK, 24 | WP_EMPLACED_GUN, 25 | WP_TURRET, 26 | 27 | // WP_GAUNTLET, 28 | // WP_MACHINEGUN, // Bryar 29 | // WP_SHOTGUN, // Blaster 30 | // WP_GRENADE_LAUNCHER, // Thermal 31 | // WP_LIGHTNING, // 32 | // WP_RAILGUN, // 33 | // WP_GRAPPLING_HOOK, 34 | 35 | WP_NUM_WEAPONS 36 | } weapon_t; 37 | 38 | 39 | typedef enum //# ammo_e 40 | { 41 | AMMO_NONE, 42 | AMMO_FORCE, // AMMO_PHASER 43 | AMMO_BLASTER, // AMMO_STARFLEET, 44 | AMMO_POWERCELL, // AMMO_ALIEN, 45 | AMMO_METAL_BOLTS, 46 | AMMO_ROCKETS, 47 | AMMO_EMPLACED, 48 | AMMO_THERMAL, 49 | AMMO_TRIPMINE, 50 | AMMO_DETPACK, 51 | AMMO_MAX 52 | } ammo_t; 53 | 54 | 55 | typedef struct weaponData_s 56 | { 57 | // char classname[32]; // Spawning name 58 | 59 | int ammoIndex; // Index to proper ammo slot 60 | int ammoLow; // Count when ammo is low 61 | 62 | int energyPerShot; // Amount of energy used per shot 63 | int fireTime; // Amount of time between firings 64 | int range; // Range of weapon 65 | 66 | int altEnergyPerShot; // Amount of energy used for alt-fire 67 | int altFireTime; // Amount of time between alt-firings 68 | int altRange; // Range of alt-fire 69 | 70 | int chargeSubTime; // ms interval for subtracting ammo during charge 71 | int altChargeSubTime; // above for secondary 72 | 73 | int chargeSub; // amount to subtract during charge on each interval 74 | int altChargeSub; // above for secondary 75 | 76 | int maxCharge; // stop subtracting once charged for this many ms 77 | int altMaxCharge; // above for secondary 78 | } weaponData_t; 79 | 80 | 81 | typedef struct ammoData_s 82 | { 83 | // char icon[32]; // Name of ammo icon file 84 | int max; // Max amount player can hold of ammo 85 | } ammoData_t; 86 | 87 | 88 | // MVSDK:: weaponData is now a pointer to the weaponData of the currently played version (gameplay-wise) 89 | extern weaponData_t weaponData_1_02[WP_NUM_WEAPONS]; 90 | extern weaponData_t weaponData_1_03[WP_NUM_WEAPONS]; 91 | extern weaponData_t weaponData_1_04[WP_NUM_WEAPONS]; 92 | extern weaponData_t *weaponData; 93 | extern ammoData_t ammoData[AMMO_MAX]; 94 | 95 | 96 | // Specific weapon information 97 | 98 | #define FIRST_WEAPON WP_BRYAR_PISTOL // this is the first weapon for next and prev weapon switching 99 | #define MAX_PLAYER_WEAPONS WP_NUM_WEAPONS-1 // this is the max you can switch to and get with the give all. 100 | 101 | 102 | #define DEFAULT_SHOTGUN_SPREAD 700 103 | #define DEFAULT_SHOTGUN_COUNT 11 104 | 105 | #define LIGHTNING_RANGE 768 106 | 107 | 108 | 109 | 110 | 111 | #endif//#ifndef __WEAPONS_H__ 112 | -------------------------------------------------------------------------------- /code/game/chars.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | //=========================================================================== 4 | // 5 | // Name: chars.h 6 | // Function: bot characteristics 7 | // Programmer: Mr Elusive (MrElusive@idsoftware.com) 8 | // Last update: 1999-09-08 9 | // Tab Size: 4 (real tabs) 10 | //=========================================================================== 11 | 12 | 13 | //======================================================== 14 | //======================================================== 15 | //name 16 | #define CHARACTERISTIC_NAME 0 //string 17 | //gender of the bot 18 | #define CHARACTERISTIC_GENDER 1 //string ("male", "female", "it") 19 | //attack skill 20 | // > 0.0 && < 0.2 = don't move 21 | // > 0.3 && < 1.0 = aim at enemy during retreat 22 | // > 0.0 && < 0.4 = only move forward/backward 23 | // >= 0.4 && < 1.0 = circle strafing 24 | // > 0.7 && < 1.0 = random strafe direction change 25 | #define CHARACTERISTIC_ATTACK_SKILL 2 //float [0, 1] 26 | //weapon weight file 27 | #define CHARACTERISTIC_WEAPONWEIGHTS 3 //string 28 | //view angle difference to angle change factor 29 | #define CHARACTERISTIC_VIEW_FACTOR 4 //float <0, 1] 30 | //maximum view angle change 31 | #define CHARACTERISTIC_VIEW_MAXCHANGE 5 //float [1, 360] 32 | //reaction time in seconds 33 | #define CHARACTERISTIC_REACTIONTIME 6 //float [0, 5] 34 | //accuracy when aiming 35 | #define CHARACTERISTIC_AIM_ACCURACY 7 //float [0, 1] 36 | //weapon specific aim accuracy 37 | #define CHARACTERISTIC_AIM_ACCURACY_MACHINEGUN 8 //float [0, 1] 38 | #define CHARACTERISTIC_AIM_ACCURACY_SHOTGUN 9 //float [0, 1] 39 | #define CHARACTERISTIC_AIM_ACCURACY_ROCKETLAUNCHER 10 //float [0, 1] 40 | #define CHARACTERISTIC_AIM_ACCURACY_GRENADELAUNCHER 11 //float [0, 1] 41 | #define CHARACTERISTIC_AIM_ACCURACY_LIGHTNING 12 42 | #define CHARACTERISTIC_AIM_ACCURACY_PLASMAGUN 13 //float [0, 1] 43 | #define CHARACTERISTIC_AIM_ACCURACY_RAILGUN 14 44 | #define CHARACTERISTIC_AIM_ACCURACY_BFG10K 15 //float [0, 1] 45 | //skill when aiming 46 | // > 0.0 && < 0.9 = aim is affected by enemy movement 47 | // > 0.4 && <= 0.8 = enemy linear leading 48 | // > 0.8 && <= 1.0 = enemy exact movement leading 49 | // > 0.5 && <= 1.0 = prediction shots when enemy is not visible 50 | // > 0.6 && <= 1.0 = splash damage by shooting nearby geometry 51 | #define CHARACTERISTIC_AIM_SKILL 16 //float [0, 1] 52 | //weapon specific aim skill 53 | #define CHARACTERISTIC_AIM_SKILL_ROCKETLAUNCHER 17 //float [0, 1] 54 | #define CHARACTERISTIC_AIM_SKILL_GRENADELAUNCHER 18 //float [0, 1] 55 | #define CHARACTERISTIC_AIM_SKILL_PLASMAGUN 19 //float [0, 1] 56 | #define CHARACTERISTIC_AIM_SKILL_BFG10K 20 //float [0, 1] 57 | //======================================================== 58 | //chat 59 | //======================================================== 60 | //file with chats 61 | #define CHARACTERISTIC_CHAT_FILE 21 //string 62 | //name of the chat character 63 | #define CHARACTERISTIC_CHAT_NAME 22 //string 64 | //characters per minute type speed 65 | #define CHARACTERISTIC_CHAT_CPM 23 //integer [1, 4000] 66 | //tendency to insult/praise 67 | #define CHARACTERISTIC_CHAT_INSULT 24 //float [0, 1] 68 | //tendency to chat misc 69 | #define CHARACTERISTIC_CHAT_MISC 25 //float [0, 1] 70 | //tendency to chat at start or end of level 71 | #define CHARACTERISTIC_CHAT_STARTENDLEVEL 26 //float [0, 1] 72 | //tendency to chat entering or exiting the game 73 | #define CHARACTERISTIC_CHAT_ENTEREXITGAME 27 //float [0, 1] 74 | //tendency to chat when killed someone 75 | #define CHARACTERISTIC_CHAT_KILL 28 //float [0, 1] 76 | //tendency to chat when died 77 | #define CHARACTERISTIC_CHAT_DEATH 29 //float [0, 1] 78 | //tendency to chat when enemy suicides 79 | #define CHARACTERISTIC_CHAT_ENEMYSUICIDE 30 //float [0, 1] 80 | //tendency to chat when hit while talking 81 | #define CHARACTERISTIC_CHAT_HITTALKING 31 //float [0, 1] 82 | //tendency to chat when bot was hit but didn't dye 83 | #define CHARACTERISTIC_CHAT_HITNODEATH 32 //float [0, 1] 84 | //tendency to chat when bot hit the enemy but enemy didn't dye 85 | #define CHARACTERISTIC_CHAT_HITNOKILL 33 //float [0, 1] 86 | //tendency to randomly chat 87 | #define CHARACTERISTIC_CHAT_RANDOM 34 //float [0, 1] 88 | //tendency to reply 89 | #define CHARACTERISTIC_CHAT_REPLY 35 //float [0, 1] 90 | //======================================================== 91 | //movement 92 | //======================================================== 93 | //tendency to crouch 94 | #define CHARACTERISTIC_CROUCHER 36 //float [0, 1] 95 | //tendency to jump 96 | #define CHARACTERISTIC_JUMPER 37 //float [0, 1] 97 | //tendency to walk 98 | #define CHARACTERISTIC_WALKER 48 //float [0, 1] 99 | //tendency to jump using a weapon 100 | #define CHARACTERISTIC_WEAPONJUMPING 38 //float [0, 1] 101 | //tendency to use the grapple hook when available 102 | #define CHARACTERISTIC_GRAPPLE_USER 39 //float [0, 1] //use this!! 103 | //======================================================== 104 | //goal 105 | //======================================================== 106 | //item weight file 107 | #define CHARACTERISTIC_ITEMWEIGHTS 40 //string 108 | //the aggression of the bot 109 | #define CHARACTERISTIC_AGGRESSION 41 //float [0, 1] 110 | //the self preservation of the bot (rockets near walls etc.) 111 | #define CHARACTERISTIC_SELFPRESERVATION 42 //float [0, 1] 112 | //how likely the bot is to take revenge 113 | #define CHARACTERISTIC_VENGEFULNESS 43 //float [0, 1] //use this!! 114 | //tendency to camp 115 | #define CHARACTERISTIC_CAMPER 44 //float [0, 1] 116 | //======================================================== 117 | //======================================================== 118 | //tendency to get easy frags 119 | #define CHARACTERISTIC_EASY_FRAGGER 45 //float [0, 1] 120 | //how alert the bot is (view distance) 121 | #define CHARACTERISTIC_ALERTNESS 46 //float [0, 1] 122 | //how much the bot fires it's weapon 123 | #define CHARACTERISTIC_FIRETHROTTLE 47 //float [0, 1] 124 | 125 | -------------------------------------------------------------------------------- /code/game/g_mem.c: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | // 4 | // g_mem.c 5 | // 6 | 7 | 8 | #include "g_local.h" 9 | 10 | 11 | #define POOLSIZE (256 * 1024) 12 | 13 | static char memoryPool[POOLSIZE]; 14 | static int allocPoint; 15 | 16 | void *G_Alloc( int size ) { 17 | char *p; 18 | 19 | if ( g_debugAlloc.integer ) { 20 | G_Printf( "G_Alloc of %i bytes (%i left)\n", size, POOLSIZE - allocPoint - ( ( size + 31 ) & ~31 ) ); 21 | } 22 | 23 | if ( allocPoint + size > POOLSIZE ) { 24 | G_Error( "G_Alloc: failed on allocation of %i bytes", size ); // bk010103 - was %u, but is signed 25 | } 26 | 27 | p = &memoryPool[allocPoint]; 28 | 29 | allocPoint += ( size + 31 ) & ~31; 30 | 31 | return p; 32 | } 33 | 34 | void G_InitMemory( void ) { 35 | allocPoint = 0; 36 | } 37 | 38 | void Svcmd_GameMem_f( void ) { 39 | G_Printf( "Game memory status: %i out of %i bytes allocated\n", allocPoint, POOLSIZE ); 40 | } 41 | -------------------------------------------------------------------------------- /code/game/g_multiversion.h: -------------------------------------------------------------------------------- 1 | //g_multiversion.h 2 | #ifndef __G_MULTIVERSION_H_INCLUDED___ 3 | #define __G_MULTIVERSION_H_INCLUDED___ 4 | 5 | /* Enums */ 6 | /* 7 | typedef enum 8 | { 9 | VERSION_UNDEF = 0, 10 | VERSION_1_02 = 2, 11 | VERSION_1_03 = 3, 12 | VERSION_1_04 = 4, 13 | } mvversion_t; 14 | */ 15 | #include "../api/mvapi.h" 16 | 17 | /* Variables */ 18 | extern playerState_1_02_t g_ps[MAX_CLIENTS]; 19 | 20 | /* Functions */ 21 | extern void MV_SetGameVersion( mvversion_t version, qboolean setGameplay ); 22 | extern void MV_VersionMagic( qboolean revert ); 23 | 24 | /* Function pointers */ 25 | extern qboolean (*trap_G2API_GetBoltMatrix_NoRecNoRot) (void *ghoul2, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles, const vec3_t position, const int frameNum, qhandle_t *modelList, vec3_t scale); 26 | extern int (*trap_G2API_InitGhoul2Model) (void **ghoul2Ptr, const char *fileName, int modelIndex, qhandle_t customSkin, qhandle_t customShader, int modelFlags, int lodBias); 27 | extern int (*trap_G2API_AddBolt) (void *ghoul2, int modelIndex, const char *boneName); 28 | extern void (*trap_G2API_SetBoltInfo) (void *ghoul2, int modelIndex, int boltInfo); 29 | extern int (*trap_G2API_CopyGhoul2Instance) (void *g2From, void *g2To, int modelIndex); 30 | extern void (*trap_G2API_CopySpecificGhoul2Model) (void *g2From, int modelFrom, void *g2To, int modelTo); 31 | extern void (*trap_G2API_DuplicateGhoul2Instance) (void *g2From, void **g2To); 32 | extern qboolean (*trap_G2API_HasGhoul2ModelOnIndex) (void *ghlInfo, int modelIndex); 33 | extern qboolean (*trap_G2API_RemoveGhoul2Model) (void *ghlInfo, int modelIndex); 34 | extern void (*trap_G2API_CleanGhoul2Models) (void **ghoul2Ptr); 35 | extern void (*trap_G2API_CollisionDetect) (CollisionRecord_t *collRecMap, void* ghoul2, const vec3_t angles, const vec3_t position, int frameNumber, int entNum, vec3_t rayStart, vec3_t rayEnd, vec3_t scale, int traceFlags, int useLod, float fRadius); 36 | extern qboolean (*trap_G2API_SetBoneAngles) (void *ghoul2, int modelIndex, const char *boneName, const vec3_t angles, const int flags, const int up, const int right, const int forward, qhandle_t *modelList, int blendTime , int currentTime); 37 | extern void (*trap_G2API_GetGLAName) (void *ghoul2, int modelIndex, char *fillBuf); 38 | extern qboolean (*trap_G2API_SetBoneAnim) (void *ghoul2, const int modelIndex, const char *boneName, const int startFrame, const int endFrame, const int flags, const float animSpeed, const int currentTime, const float setFrame , const int blendTime); 39 | 40 | #endif //__G_MULTIVERSION_H_INCLUDED___ 41 | -------------------------------------------------------------------------------- /code/game/g_multiversion_syscalls.c: -------------------------------------------------------------------------------- 1 | //g_multiversion_syscalls.c 2 | 3 | #include "g_local.h" 4 | #include "g_multiversion_syscalls.h" 5 | -------------------------------------------------------------------------------- /code/game/g_multiversion_syscalls.h: -------------------------------------------------------------------------------- 1 | //g_multiversion_syscalls.h 2 | -------------------------------------------------------------------------------- /code/game/g_team.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | 4 | #define CTF_CAPTURE_BONUS 100 // what you get for capture 5 | #define CTF_TEAM_BONUS 25 // what your team gets for capture 6 | #define CTF_RECOVERY_BONUS 10 // what you get for recovery 7 | #define CTF_FLAG_BONUS 10 // what you get for picking up enemy flag 8 | #define CTF_FRAG_CARRIER_BONUS 20 // what you get for fragging enemy flag carrier 9 | #define CTF_FLAG_RETURN_TIME 40000 // seconds until auto return 10 | 11 | #define CTF_CARRIER_DANGER_PROTECT_BONUS 5 // bonus for fraggin someone who has recently hurt your flag carrier 12 | #define CTF_CARRIER_PROTECT_BONUS 2 // bonus for fraggin someone while either you or your target are near your flag carrier 13 | #define CTF_FLAG_DEFENSE_BONUS 10 // bonus for fraggin someone while either you or your target are near your flag 14 | #define CTF_RETURN_FLAG_ASSIST_BONUS 10 // awarded for returning a flag that causes a capture to happen almost immediately 15 | #define CTF_FRAG_CARRIER_ASSIST_BONUS 10 // award for fragging a flag carrier if a capture happens almost immediately 16 | 17 | #define CTF_TARGET_PROTECT_RADIUS 1000 // the radius around an object being defended where a target will be worth extra frags 18 | #define CTF_ATTACKER_PROTECT_RADIUS 1000 // the radius around an object being defended where an attacker will get extra frags when making kills 19 | 20 | #define CTF_CARRIER_DANGER_PROTECT_TIMEOUT 8000 21 | #define CTF_FRAG_CARRIER_ASSIST_TIMEOUT 10000 22 | #define CTF_RETURN_FLAG_ASSIST_TIMEOUT 10000 23 | 24 | #define CTF_GRAPPLE_SPEED 750 // speed of grapple in flight 25 | #define CTF_GRAPPLE_PULL_SPEED 750 // speed player is pulled at 26 | 27 | #define OVERLOAD_ATTACK_BASE_SOUND_TIME 20000 28 | 29 | // Prototypes 30 | 31 | team_t OtherTeam(team_t team); 32 | const char *TeamName(team_t team); 33 | const char *OtherTeamName(team_t team); 34 | const char *TeamColorString(team_t team); 35 | void AddTeamScore(vec3_t origin, int team, int score); 36 | 37 | void Team_DroppedFlagThink(gentity_t *ent); 38 | void Team_FragBonuses(gentity_t *targ, gentity_t *inflictor, gentity_t *attacker); 39 | void Team_CheckHurtCarrier(gentity_t *targ, gentity_t *attacker); 40 | void Team_InitGame(void); 41 | void Team_ReturnFlag(int team); 42 | void Team_FreeEntity(gentity_t *ent); 43 | gentity_t *SelectCTFSpawnPoint ( team_t team, int teamstate, vec3_t origin, vec3_t angles ); 44 | gentity_t *SelectSagaSpawnPoint ( team_t team, int teamstate, vec3_t origin, vec3_t angles ); 45 | gentity_t *Team_GetLocation(gentity_t *ent); 46 | qboolean Team_GetLocationMsg(gentity_t *ent, char *loc, int loclen); 47 | void TeamplayInfoMessage( gentity_t *ent ); 48 | void CheckTeamStatus(void); 49 | 50 | int Pickup_Team( gentity_t *ent, gentity_t *other ); 51 | -------------------------------------------------------------------------------- /code/game/inv.h: -------------------------------------------------------------------------------- 1 | 2 | #define INVENTORY_NONE 0 3 | //pickups 4 | #define INVENTORY_ARMOR 1 5 | #define INVENTORY_HEALTH 2 6 | //items 7 | #define INVENTORY_SEEKER 3 8 | #define INVENTORY_MEDPAC 4 9 | #define INVENTORY_DATAPAD 5 10 | #define INVENTORY_BINOCULARS 6 11 | #define INVENTORY_SENTRY_GUN 7 12 | #define INVENTORY_GOGGLES 8 13 | //weapons 14 | #define INVENTORY_STUN_BATON 9 15 | #define INVENTORY_SABER 10 16 | #define INVENTORY_BRYAR_PISTOL 11 17 | #define INVENTORY_BLASTER 12 18 | #define INVENTORY_DISRUPTOR 13 19 | #define INVENTORY_BOWCASTER 14 20 | #define INVENTORY_REPEATER 15 21 | #define INVENTORY_DEMP2 16 22 | #define INVENTORY_FLECHETTE 17 23 | #define INVENTORY_ROCKET_LAUNCHER 18 24 | #define INVENTORY_THERMAL 19 25 | #define INVENTORY_TRIP_MINE 20 26 | #define INVENTORY_DET_PACK 21 27 | //ammo 28 | #define INVENTORY_AMMO_FORCE 22 29 | #define INVENTORY_AMMO_BLASTER 23 30 | #define INVENTORY_AMMO_BOLTS 24 31 | #define INVENTORY_AMMO_ROCKETS 25 32 | //powerups 33 | #define INVENTORY_REDFLAG 26 34 | #define INVENTORY_BLUEFLAG 27 35 | #define INVENTORY_SCOUT 28 36 | #define INVENTORY_GUARD 29 37 | #define INVENTORY_DOUBLER 30 38 | #define INVENTORY_AMMOREGEN 31 39 | #define INVENTORY_NEUTRALFLAG 32 40 | #define INVENTORY_REDCUBE 33 41 | #define INVENTORY_BLUECUBE 34 42 | 43 | //enemy stuff 44 | #define ENEMY_HORIZONTAL_DIST 200 45 | #define ENEMY_HEIGHT 201 46 | #define NUM_VISIBLE_ENEMIES 202 47 | #define NUM_VISIBLE_TEAMMATES 203 48 | 49 | // NOTENOTE Update this so that it is in sync. 50 | //item numbers (make sure they are in sync with bg_itemlist in bg_misc.c) 51 | //pickups 52 | #define MODELINDEX_ARMOR 1 53 | #define MODELINDEX_HEALTH 2 54 | //items 55 | #define MODELINDEX_SEEKER 3 56 | #define MODELINDEX_MEDPAC 4 57 | #define MODELINDEX_DATAPAD 5 58 | #define MODELINDEX_BINOCULARS 6 59 | #define MODELINDEX_SENTRY_GUN 7 60 | #define MODELINDEX_GOGGLES 8 61 | //weapons 62 | #define MODELINDEX_STUN_BATON 9 63 | #define MODELINDEX_SABER 10 64 | #define MODELINDEX_BRYAR_PISTOL 11 65 | #define MODELINDEX_BLASTER 12 66 | #define MODELINDEX_DISRUPTOR 13 67 | #define MODELINDEX_BOWCASTER 14 68 | #define MODELINDEX_REPEATER 15 69 | #define MODELINDEX_DEMP2 16 70 | #define MODELINDEX_FLECHETTE 17 71 | #define MODELINDEX_ROCKET_LAUNCHER 18 72 | #define MODELINDEX_THERMAL 19 73 | #define MODELINDEX_TRIP_MINE 20 74 | #define MODELINDEX_DET_PACK 21 75 | //ammo 76 | #define MODELINDEX_AMMO_FORCE 22 77 | #define MODELINDEX_AMMO_BLASTER 23 78 | #define MODELINDEX_AMMO_BOLTS 24 79 | #define MODELINDEX_AMMO_ROCKETS 25 80 | //powerups 81 | #define MODELINDEX_REDFLAG 26 82 | #define MODELINDEX_BLUEFLAG 27 83 | #define MODELINDEX_SCOUT 28 84 | #define MODELINDEX_GUARD 29 85 | #define MODELINDEX_DOUBLER 30 86 | #define MODELINDEX_AMMOREGEN 31 87 | #define MODELINDEX_NEUTRALFLAG 32 88 | #define MODELINDEX_REDCUBE 33 89 | #define MODELINDEX_BLUECUBE 34 90 | 91 | // 92 | #define WEAPONINDEX_STUN_BATON 1 93 | #define WEAPONINDEX_SABER 2 94 | #define WEAPONINDEX_BRYAR_PISTOL 3 95 | #define WEAPONINDEX_BLASTER 4 96 | #define WEAPONINDEX_DISRUPTOR 5 97 | #define WEAPONINDEX_BOWCASTER 6 98 | #define WEAPONINDEX_REPEATER 7 99 | #define WEAPONINDEX_DEMP2 8 100 | #define WEAPONINDEX_FLECHETTE 9 101 | #define WEAPONINDEX_ROCKET_LAUNCHER 10 102 | #define WEAPONINDEX_THERMAL 11 103 | #define WEAPONINDEX_TRIP_MINE 12 104 | #define WEAPONINDEX_DET_PACK 13 105 | -------------------------------------------------------------------------------- /code/game/match.h: -------------------------------------------------------------------------------- 1 | //=========================================================================== 2 | // 3 | // Name: match.h 4 | // Function: match template defines 5 | // Programmer: Mr Elusive 6 | // Last update: 7 | // Tab Size: 4 (real tabs) 8 | // 9 | //=========================================================================== 10 | 11 | // make sure this is the same character as we use in chats in g_cmd.c 12 | #define EC "\x19" 13 | 14 | //match template contexts 15 | #define MTCONTEXT_MISC 2 16 | #define MTCONTEXT_INITIALTEAMCHAT 4 17 | #define MTCONTEXT_TIME 8 18 | #define MTCONTEXT_TEAMMATE 16 19 | #define MTCONTEXT_ADDRESSEE 32 20 | #define MTCONTEXT_PATROLKEYAREA 64 21 | #define MTCONTEXT_REPLYCHAT 128 22 | #define MTCONTEXT_CTF 256 23 | 24 | //message types 25 | #define MSG_NEWLEADER 1 //new leader 26 | #define MSG_ENTERGAME 2 //enter game message 27 | #define MSG_HELP 3 //help someone 28 | #define MSG_ACCOMPANY 4 //accompany someone 29 | #define MSG_DEFENDKEYAREA 5 //defend a key area 30 | #define MSG_RUSHBASE 6 //everyone rush to base 31 | #define MSG_GETFLAG 7 //get the enemy flag 32 | #define MSG_STARTTEAMLEADERSHIP 8 //someone wants to become the team leader 33 | #define MSG_STOPTEAMLEADERSHIP 9 //someone wants to stop being the team leader 34 | #define MSG_WHOISTEAMLAEDER 10 //who is the team leader 35 | #define MSG_WAIT 11 //wait for someone 36 | #define MSG_WHATAREYOUDOING 12 //what are you doing? 37 | #define MSG_JOINSUBTEAM 13 //join a sub-team 38 | #define MSG_LEAVESUBTEAM 14 //leave a sub-team 39 | #define MSG_CREATENEWFORMATION 15 //create a new formation 40 | #define MSG_FORMATIONPOSITION 16 //tell someone his/her position in a formation 41 | #define MSG_FORMATIONSPACE 17 //set the formation intervening space 42 | #define MSG_DOFORMATION 18 //form a known formation 43 | #define MSG_DISMISS 19 //dismiss commanded team mates 44 | #define MSG_CAMP 20 //camp somewhere 45 | #define MSG_CHECKPOINT 21 //remember a check point 46 | #define MSG_PATROL 22 //patrol between certain keypoints 47 | #define MSG_LEADTHEWAY 23 //lead the way 48 | #define MSG_GETITEM 24 //get an item 49 | #define MSG_KILL 25 //kill someone 50 | #define MSG_WHEREAREYOU 26 //where is someone 51 | #define MSG_RETURNFLAG 27 //return the flag 52 | #define MSG_WHATISMYCOMMAND 28 //ask the team leader what to do 53 | #define MSG_WHICHTEAM 29 //ask which team a bot is in 54 | #define MSG_TASKPREFERENCE 30 //tell your teamplay task preference 55 | #define MSG_ATTACKENEMYBASE 31 //attack the enemy base 56 | #define MSG_HARVEST 32 //go harvest 57 | #define MSG_SUICIDE 33 //order to suicide 58 | // 59 | #define MSG_ME 100 60 | #define MSG_EVERYONE 101 61 | #define MSG_MULTIPLENAMES 102 62 | #define MSG_NAME 103 63 | #define MSG_PATROLKEYAREA 104 64 | #define MSG_MINUTES 105 65 | #define MSG_SECONDS 106 66 | #define MSG_FOREVER 107 67 | #define MSG_FORALONGTIME 108 68 | #define MSG_FORAWHILE 109 69 | // 70 | #define MSG_CHATALL 200 71 | #define MSG_CHATTEAM 201 72 | #define MSG_CHATTELL 202 73 | // 74 | #define MSG_CTF 300 //ctf message 75 | 76 | //command sub types 77 | #define ST_SOMEWHERE 0 78 | #define ST_NEARITEM 1 79 | #define ST_ADDRESSED 2 80 | #define ST_METER 4 81 | #define ST_FEET 8 82 | #define ST_TIME 16 83 | #define ST_HERE 32 84 | #define ST_THERE 64 85 | #define ST_I 128 86 | #define ST_MORE 256 87 | #define ST_BACK 512 88 | #define ST_REVERSE 1024 89 | #define ST_SOMEONE 2048 90 | #define ST_GOTFLAG 4096 91 | #define ST_CAPTUREDFLAG 8192 92 | #define ST_RETURNEDFLAG 16384 93 | #define ST_TEAM 32768 94 | #define ST_1FCTFGOTFLAG 65535 95 | //ctf task preferences 96 | #define ST_DEFENDER 1 97 | #define ST_ATTACKER 2 98 | #define ST_ROAMER 4 99 | 100 | 101 | //word replacement variables 102 | #define THE_ENEMY 7 103 | #define THE_TEAM 7 104 | //team message variables 105 | #define NETNAME 0 106 | #define PLACE 1 107 | #define FLAG 1 108 | #define MESSAGE 2 109 | #define ADDRESSEE 2 110 | #define ITEM 3 111 | #define TEAMMATE 4 112 | #define TEAMNAME 4 113 | #define ENEMY 4 114 | #define KEYAREA 5 115 | #define FORMATION 5 116 | #define POSITION 5 117 | #define NUMBER 5 118 | #define TIME 6 119 | #define NAME 6 120 | #define MORE 6 121 | 122 | 123 | -------------------------------------------------------------------------------- /code/game/surfaceflags.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 1999-2000 Id Software, Inc. 2 | // 3 | // This file must be identical in the quake and utils directories 4 | 5 | // contents flags are seperate bits 6 | // a given brush can contribute multiple content bits 7 | 8 | // these definitions also need to be in q_shared.h! 9 | 10 | #define CONTENTS_SOLID 0x00000001 // Default setting. An eye is never valid in a solid 11 | #define CONTENTS_LAVA 0x00000002 12 | #define CONTENTS_WATER 0x00000004 13 | #define CONTENTS_FOG 0x00000008 14 | #define CONTENTS_PLAYERCLIP 0x00000010 15 | #define CONTENTS_MONSTERCLIP 0x00000020 // Physically block bots 16 | #define CONTENTS_BOTCLIP 0x00000040 // A hint for bots - do not enter this brush by navigation (if possible) 17 | #define CONTENTS_SHOTCLIP 0x00000080 18 | #define CONTENTS_BODY 0x00000100 // should never be on a brush, only in game 19 | #define CONTENTS_CORPSE 0x00000200 // should never be on a brush, only in game 20 | #define CONTENTS_TRIGGER 0x00000400 21 | #define CONTENTS_NODROP 0x00000800 // don't leave bodies or items (death fog, lava) 22 | #define CONTENTS_TERRAIN 0x00001000 // volume contains terrain data 23 | #define CONTENTS_LADDER 0x00002000 24 | #define CONTENTS_ABSEIL 0x00004000 // (SOF2) used like ladder to define where an NPC can abseil 25 | #define CONTENTS_OPAQUE 0x00008000 // defaults to on, when off, solid can be seen through 26 | #define CONTENTS_OUTSIDE 0x00010000 // volume is considered to be in the outside (i.e. not indoors) 27 | #define CONTENTS_SLIME 0x00020000 // CHC needs this since we use same tools 28 | #define CONTENTS_LIGHTSABER 0x00040000 // "" 29 | #define CONTENTS_TELEPORTER 0x00080000 // "" 30 | #define CONTENTS_ITEM 0x00100000 // "" 31 | #define CONTENTS_NOSHOT 0x00200000 // shots pass through me 32 | #define CONTENTS_DETAIL 0x08000000 // brushes not used for the bsp 33 | #define CONTENTS_TRANSLUCENT 0x80000000 // don't consume surface fragments inside 34 | 35 | #define SURF_SKY 0x00002000 // lighting from environment map 36 | #define SURF_SLICK 0x00004000 // affects game physics 37 | #define SURF_METALSTEPS 0x00008000 // CHC needs this since we use same tools (though this flag is temp?) 38 | #define SURF_FORCEFIELD 0x00010000 // CHC "" (but not temp) 39 | #define SURF_NODAMAGE 0x00040000 // never give falling damage 40 | #define SURF_NOIMPACT 0x00080000 // don't make missile explosions 41 | #define SURF_NOMARKS 0x00100000 // don't leave missile marks 42 | #define SURF_NODRAW 0x00200000 // don't generate a drawsurface at all 43 | #define SURF_NOSTEPS 0x00400000 // no footstep sounds 44 | #define SURF_NODLIGHT 0x00800000 // don't dlight even if solid (solid lava, skies) 45 | #define SURF_NOMISCENTS 0x01000000 // no client models allowed on this surface 46 | 47 | 48 | #define MATERIAL_BITS 5 49 | #define MATERIAL_MASK 0x1f // mask to get the material type 50 | 51 | #define MATERIAL_NONE 0 // for when the artist hasn't set anything up =) 52 | #define MATERIAL_SOLIDWOOD 1 // freshly cut timber 53 | #define MATERIAL_HOLLOWWOOD 2 // termite infested creaky wood 54 | #define MATERIAL_SOLIDMETAL 3 // solid girders 55 | #define MATERIAL_HOLLOWMETAL 4 // hollow metal machines 56 | #define MATERIAL_SHORTGRASS 5 // manicured lawn 57 | #define MATERIAL_LONGGRASS 6 // long jungle grass 58 | #define MATERIAL_DIRT 7 // hard mud 59 | #define MATERIAL_SAND 8 // sandy beach 60 | #define MATERIAL_GRAVEL 9 // lots of small stones 61 | #define MATERIAL_GLASS 10 // 62 | #define MATERIAL_CONCRETE 11 // hardened concrete pavement 63 | #define MATERIAL_MARBLE 12 // marble floors 64 | #define MATERIAL_WATER 13 // light covering of water on a surface 65 | #define MATERIAL_SNOW 14 // freshly laid snow 66 | #define MATERIAL_ICE 15 // packed snow/solid ice 67 | #define MATERIAL_FLESH 16 // hung meat, corpses in the world 68 | #define MATERIAL_MUD 17 // wet soil 69 | #define MATERIAL_BPGLASS 18 // bulletproof glass 70 | #define MATERIAL_DRYLEAVES 19 // dried up leaves on the floor 71 | #define MATERIAL_GREENLEAVES 20 // fresh leaves still on a tree 72 | #define MATERIAL_FABRIC 21 // Cotton sheets 73 | #define MATERIAL_CANVAS 22 // tent material 74 | #define MATERIAL_ROCK 23 // 75 | #define MATERIAL_RUBBER 24 // hard tire like rubber 76 | #define MATERIAL_PLASTIC 25 // 77 | #define MATERIAL_TILES 26 // tiled floor 78 | #define MATERIAL_CARPET 27 // lush carpet 79 | #define MATERIAL_PLASTER 28 // drywall style plaster 80 | #define MATERIAL_SHATTERGLASS 29 // glass with the Crisis Zone style shattering 81 | #define MATERIAL_ARMOR 30 // body armor 82 | #define MATERIAL_LAST 31 // number of materials 83 | 84 | // Defined as a macro here so one change will affect all the relevant files 85 | 86 | #define MATERIALS \ 87 | "none", \ 88 | "solidwood", \ 89 | "hollowwood", \ 90 | "solidmetal", \ 91 | "hollowmetal", \ 92 | "shortgrass", \ 93 | "longgrass", \ 94 | "dirt", \ 95 | "sand", \ 96 | "gravel", \ 97 | "glass", \ 98 | "concrete", \ 99 | "marble", \ 100 | "water", \ 101 | "snow", \ 102 | "ice", \ 103 | "flesh", \ 104 | "mud", \ 105 | "bpglass", \ 106 | "dryleaves", \ 107 | "greenleaves", \ 108 | "fabric", \ 109 | "canvas", \ 110 | "rock", \ 111 | "rubber", \ 112 | "plastic", \ 113 | "tiles", \ 114 | "carpet", \ 115 | "plaster", \ 116 | "shatterglass", \ 117 | "armor" 118 | -------------------------------------------------------------------------------- /code/game/syn.h: -------------------------------------------------------------------------------- 1 | //=========================================================================== 2 | // 3 | // Name: syn.h 4 | // Function: synonyms 5 | // Programmer: Mr Elusive 6 | // Last update: - 7 | // Tab Size: 4 (real tabs) 8 | // Notes: - 9 | //=========================================================================== 10 | 11 | #define CONTEXT_ALL 0xFFFFFFFF 12 | #define CONTEXT_NORMAL 1 13 | #define CONTEXT_NEARBYITEM 2 14 | #define CONTEXT_CTFREDTEAM 4 15 | #define CONTEXT_CTFBLUETEAM 8 16 | #define CONTEXT_REPLY 16 17 | #define CONTEXT_HARVESTERREDTEAM 128 18 | #define CONTEXT_HARVESTERBLUETEAM 256 19 | 20 | #define CONTEXT_NAMES 1024 21 | -------------------------------------------------------------------------------- /code/game/w_saber.h: -------------------------------------------------------------------------------- 1 | #define FORCE_POWER_MAX 100 2 | #define MAX_GRIP_DISTANCE 256 3 | #define MAX_TRICK_DISTANCE 512 4 | #define FORCE_JUMP_CHARGE_TIME 6400//3000.0f 5 | #define GRIP_DRAIN_AMOUNT 30 6 | #define FORCE_LIGHTNING_RADIUS 300 7 | #define MAX_DRAIN_DISTANCE 512 8 | 9 | typedef enum 10 | { 11 | FJ_FORWARD, 12 | FJ_BACKWARD, 13 | FJ_RIGHT, 14 | FJ_LEFT, 15 | FJ_UP 16 | } FJ_t; 17 | 18 | extern vmCvar_t g_MaxHolocronCarry; 19 | extern int forcePowerNeeded_1_02[NUM_FORCE_POWER_LEVELS][NUM_FORCE_POWERS]; 20 | extern int forcePowerNeeded_1_04[NUM_FORCE_POWER_LEVELS][NUM_FORCE_POWERS]; 21 | extern int (*forcePowerNeeded)[NUM_FORCE_POWERS]; 22 | extern float forceJumpHeight[NUM_FORCE_POWER_LEVELS]; 23 | extern float forceJumpStrength[NUM_FORCE_POWER_LEVELS]; 24 | 25 | -------------------------------------------------------------------------------- /code/ghoul2/g2.h: -------------------------------------------------------------------------------- 1 | #if defined (_MSC_VER) && (_MSC_VER >= 1020) 2 | #pragma once 3 | #endif 4 | #if !defined(G2_H_INC) 5 | #define G2_H_INC 6 | 7 | 8 | #define BONE_ANGLES_PREMULT 0x0001 9 | #define BONE_ANGLES_POSTMULT 0x0002 10 | #define BONE_ANGLES_REPLACE 0x0004 11 | 12 | #define BONE_ANGLES_TOTAL ( BONE_ANGLES_PREMULT | BONE_ANGLES_POSTMULT | BONE_ANGLES_REPLACE ) 13 | #define BONE_ANIM_OVERRIDE 0x0008 14 | #define BONE_ANIM_OVERRIDE_LOOP 0x0010 15 | #define BONE_ANIM_OVERRIDE_FREEZE ( 0x0040 + BONE_ANIM_OVERRIDE ) 16 | #define BONE_ANIM_BLEND 0x0080 17 | #define BONE_ANIM_TOTAL ( BONE_ANIM_OVERRIDE | BONE_ANIM_OVERRIDE_LOOP | BONE_ANIM_OVERRIDE_FREEZE | BONE_ANIM_BLEND) 18 | 19 | 20 | // defines to setup the 21 | #define ENTITY_WIDTH 12 22 | #define MODEL_WIDTH 10 23 | #define BOLT_WIDTH 10 24 | 25 | #define MODEL_AND ((1<:${GlobalDefines} ${MVUIDefines} ${DebugDefines}> 65 | $<$:${GlobalDefines} ${MVUIDefines} ${ReleaseDefines}> 66 | $<$:${GlobalDefines} ${MVUIDefines} ${ReleaseDefines}> 67 | ) 68 | 69 | set_target_properties(${MVUI} PROPERTIES INCLUDE_DIRECTORIES "${MVUIIncludeDirs}") 70 | set_target_properties(${MVUI} PROPERTIES PROJECT_LABEL "UI Module") 71 | if(InMV) 72 | set_property(TARGET ${MVUI} PROPERTY FOLDER "Modules") 73 | endif() 74 | -------------------------------------------------------------------------------- /code/ui/ui_force.h: -------------------------------------------------------------------------------- 1 | #include "../qcommon/qfiles.h" 2 | 3 | #define NUM_FORCE_STAR_IMAGES 9 4 | #define FORCE_NONJEDI 0 5 | #define FORCE_JEDI 1 6 | 7 | extern int uiForceSide; 8 | extern int uiJediNonJedi; 9 | extern int uiForceRank; 10 | extern int uiServerForceRank; 11 | extern int uiMaxRank; 12 | extern int uiForceUsed; 13 | extern int uiForceAvailable; 14 | extern qboolean gTouchedForce; 15 | extern qboolean uiForcePowersDisabled[NUM_FORCE_POWERS]; 16 | extern int uiForcePowersRank[NUM_FORCE_POWERS]; 17 | extern const int uiForcePowerDarkLight[NUM_FORCE_POWERS]; 18 | extern int uiSaberColorShaders[NUM_SABER_COLORS]; 19 | // Dots above or equal to a given rank carry a certain color. 20 | extern vmCvar_t ui_freeSaber, ui_forcePowerDisable; 21 | 22 | void UI_InitForceShaders(void); 23 | void UI_ReadLegalForce(void); 24 | void UI_DrawTotalForceStars(rectDef_t *rect, float scale, vec4_t color, int textStyle); 25 | void UI_DrawForceStars(rectDef_t *rect, float scale, vec4_t color, int textStyle, int findex, int val, int min, int max) ; 26 | void UI_UpdateClientForcePowers(const char *teamArg); 27 | void UI_SaveForceTemplate(); 28 | void UI_UpdateForcePowers(); 29 | qboolean UI_SkinColor_HandleKey(int flags, float *special, int key, int num, int min, int max, int type); 30 | qboolean UI_ForceSide_HandleKey(int flags, float *special, int key, int num, int min, int max, int type); 31 | qboolean UI_JediNonJedi_HandleKey(int flags, float *special, int key, int num, int min, int max, int type); 32 | qboolean UI_ForceMaxRank_HandleKey(int flags, float *special, int key, int num, int min, int max, int type); 33 | qboolean UI_ForcePowerRank_HandleKey(int flags, float *special, int key, int num, int min, int max, int type); 34 | extern void UI_ForceConfigHandle( int oldindex, int newindex ); 35 | -------------------------------------------------------------------------------- /code/ui/ui_multiversion.h: -------------------------------------------------------------------------------- 1 | //ui_multiversion.h 2 | #ifndef __UI_MULTIVERSION_H_INCLUDED___ 3 | #define __UI_MULTIVERSION_H_INCLUDED___ 4 | 5 | /* Enums */ 6 | /* 7 | typedef enum 8 | { 9 | VERSION_UNDEF = 0, 10 | VERSION_1_02 = 2, 11 | VERSION_1_03 = 3, 12 | VERSION_1_04 = 4, 13 | } mvversion_t; 14 | */ 15 | 16 | /* Variables */ 17 | /* */ 18 | 19 | /* Functions */ 20 | extern void MV_SetGameVersion( mvversion_t version, qboolean setGameplay ); 21 | extern void MV_SetGamePlay( mvversion_t version ); 22 | 23 | /* Function pointers */ 24 | extern qboolean (*trap_Language_IsAsian) (void); 25 | extern qboolean (*trap_Language_UsesSpaces) (void); 26 | //extern unsigned int (*trap_AnyLanguage_ReadCharFromString) (const char *psText, int *piAdvanceCount, qboolean *pbIsTrailingPunctuation); 27 | 28 | extern void (*trap_R_ModelBounds) (clipHandle_t model, vec3_t mins, vec3_t maxs); 29 | extern int (*trap_LAN_GetServerCount) (int source); 30 | extern void (*trap_LAN_GetServerAddressString) (int source, int n, char *buf, int buflen); 31 | extern void (*trap_LAN_GetServerInfo) (int source, int n, char *buf, int buflen); 32 | extern int (*trap_LAN_GetServerPing) (int source, int n); 33 | extern int (*trap_LAN_ServerStatus) (const char *serverAddress, char *serverStatus, int maxLen); 34 | extern void (*trap_LAN_SaveCachedServers) (); 35 | extern void (*trap_LAN_LoadCachedServers) (); 36 | extern void (*trap_LAN_ResetPings) (int n); 37 | extern void (*trap_LAN_MarkServerVisible) (int source, int n, qboolean visible); 38 | extern int (*trap_LAN_ServerIsVisible) (int source, int n); 39 | extern qboolean (*trap_LAN_UpdateVisiblePings) (int source); 40 | extern int (*trap_LAN_AddServer) (int source, const char *name, const char *addr); 41 | extern void (*trap_LAN_RemoveServer) (int source, const char *addr); 42 | extern int (*trap_LAN_CompareServers) (int source, int sortKey, int sortDir, int s1, int s2); 43 | extern int (*trap_PC_AddGlobalDefine) (char *define); 44 | extern int (*trap_PC_LoadSource) (const char *filename); 45 | extern int (*trap_PC_FreeSource) (int handle); 46 | extern int (*trap_PC_ReadToken) (int handle, pc_token_t *pc_token); 47 | extern int (*trap_PC_SourceFileAndLine) (int handle, char *filename, int *line); 48 | extern int (*trap_PC_LoadGlobalDefines) (const char* filename); 49 | 50 | extern void (*trap_PC_RemoveAllGlobalDefines) (void); 51 | 52 | extern void (*trap_S_StopBackgroundTrack) (void); 53 | extern void (*trap_S_StartBackgroundTrack) (const char *intro, const char *loop, qboolean bReturnWithoutStarting); 54 | extern int (*trap_RealTime) (qtime_t *qtime); 55 | extern int (*trap_CIN_PlayCinematic) (const char *arg0, int xpos, int ypos, int width, int height, int bits); 56 | extern e_status (*trap_CIN_StopCinematic) (int handle); 57 | extern e_status (*trap_CIN_RunCinematic) (int handle); 58 | extern void (*trap_CIN_DrawCinematic) (int handle); 59 | extern void (*trap_CIN_SetExtents) (int handle, int x, int y, int w, int h); 60 | extern void (*trap_R_RemapShader) (const char *oldShader, const char *newShader, const char *timeOffset); 61 | 62 | extern unsigned int trap_AnyLanguage_ReadCharFromString_1_04( const char *psText, int *piAdvanceCount, qboolean *pbIsTrailingPunctuation ); 63 | extern unsigned int trap_AnyLanguage_ReadCharFromString_1_02( const char **ppText ); 64 | 65 | #endif //__UI_MULTIVERSION_H_INCLUDED___ 66 | -------------------------------------------------------------------------------- /code/ui/ui_multiversion_syscalls.c: -------------------------------------------------------------------------------- 1 | //ui_multiversion_syscalls.c 2 | 3 | #include "ui_local.h" 4 | #include "ui_multiversion_syscalls.h" 5 | 6 | void trap_Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) 7 | { 8 | trap_Key_KeynumToStringBuf_real( Key_GetProtocolKey(jk2version, keynum), buf, buflen ); 9 | } 10 | 11 | void trap_Key_GetBindingBuf( int keynum, char *buf, int buflen ) 12 | { 13 | trap_Key_GetBindingBuf_real( Key_GetProtocolKey(jk2version, keynum), buf, buflen ); 14 | } 15 | 16 | void trap_Key_SetBinding( int keynum, const char *binding ) 17 | { 18 | trap_Key_SetBinding_real( Key_GetProtocolKey(jk2version, keynum), binding ); 19 | } 20 | 21 | qboolean trap_Key_IsDown( int keynum ) 22 | { 23 | return trap_Key_IsDown_real( Key_GetProtocolKey(jk2version, keynum) ); 24 | } 25 | -------------------------------------------------------------------------------- /code/ui/ui_multiversion_syscalls.h: -------------------------------------------------------------------------------- 1 | //ui_multiversion_syscalls.h 2 | 3 | void trap_Key_KeynumToStringBuf_real( int keynum, char *buf, int buflen ); 4 | void trap_Key_GetBindingBuf_real( int keynum, char *buf, int buflen ); 5 | void trap_Key_SetBinding_real( int keynum, const char *binding ); 6 | qboolean trap_Key_IsDown_real( int keynum ); 7 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | if(${CMAKE_C_COMPILER_ID} MATCHES GNU|Clang|AppleClang) 7 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare") 8 | endif() 9 | 10 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools) 11 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools) 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools) 13 | set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/tools) 14 | 15 | add_subdirectory("lcc") 16 | add_subdirectory("cpp") 17 | add_subdirectory("rcc") 18 | add_subdirectory("asm") 19 | -------------------------------------------------------------------------------- /tools/COPYRIGHT: -------------------------------------------------------------------------------- 1 | The authors of this software are Christopher W. Fraser and 2 | David R. Hanson. 3 | 4 | Copyright (c) 1991,1992,1993,1994,1995,1996,1997,1998 by AT&T, 5 | Christopher W. Fraser, and David R. Hanson. All Rights Reserved. 6 | 7 | Permission to use, copy, modify, and distribute this software for any 8 | purpose, subject to the provisions described below, without fee is 9 | hereby granted, provided that this entire notice is included in all 10 | copies of any software that is or includes a copy or modification of 11 | this software and in all copies of the supporting documentation for 12 | such software. 13 | 14 | THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 15 | WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY 16 | REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 17 | OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 18 | 19 | 20 | lcc is not public-domain software, shareware, and it is not protected 21 | by a `copyleft' agreement, like the code from the Free Software 22 | Foundation. 23 | 24 | lcc is available free for your personal research and instructional use 25 | under the `fair use' provisions of the copyright law. You may, however, 26 | redistribute lcc in whole or in part provided you acknowledge its 27 | source and include this CPYRIGHT file. You may, for example, include 28 | the distribution in a CDROM of free software, provided you charge only 29 | for the media, or mirror the distribution files at your site. 30 | 31 | You may not sell lcc or any product derived from it in which it is a 32 | significant part of the value of the product. Using the lcc front end 33 | to build a C syntax checker is an example of this kind of product. 34 | 35 | You may use parts of lcc in products as long as you charge for only 36 | those components that are entirely your own and you acknowledge the use 37 | of lcc clearly in all product documentation and distribution media. You 38 | must state clearly that your product uses or is based on parts of lcc 39 | and that lcc is available free of charge. You must also request that 40 | bug reports on your product be reported to you. Using the lcc front 41 | end to build a C compiler for the Motorola 88000 chip and charging for 42 | and distributing only the 88000 code generator is an example of this 43 | kind of product. 44 | 45 | Using parts of lcc in other products is more problematic. For example, 46 | using parts of lcc in a C++ compiler could save substantial time and 47 | effort and therefore contribute significantly to the profitability of 48 | the product. This kind of use, or any use where others stand to make a 49 | profit from what is primarily our work, requires a license agreement 50 | with Addison-Wesley. Per-copy and unlimited use licenses are 51 | available; for more information, contact 52 | 53 | J. Carter Shanklin 54 | Addison Wesley Longman, Inc. 55 | 2725 Sand Hill Rd. 56 | Menlo Park, CA 94025 57 | 650/854-0300 x2478 FAX: 650/614-2930 jcs@awl.com 58 | ----- 59 | Chris Fraser / cwfraser@microsoft.com 60 | David Hanson / drh@microsoft.com 61 | $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $ 62 | -------------------------------------------------------------------------------- /tools/README: -------------------------------------------------------------------------------- 1 | This hierarchy is the distribution for lcc version 4.1. 2 | 3 | lcc version 3.x is described in the book "A Retargetable C Compiler: 4 | Design and Implementation" (Addison-Wesley, 1995, ISBN 0-8053-1670-1). 5 | There are significant differences between 3.x and 4.x, most notably in 6 | the intermediate code. doc/4.html summarizes the differences. 7 | 8 | VERSION 4.1 IS INCOMPATIBLE WITH EARLIER VERSIONS OF LCC. DO NOT 9 | UNLOAD THIS DISTRIBUTION ON TOP OF A 3.X DISTRIBUTION. 10 | 11 | LOG describes the changes since the last release. 12 | 13 | CPYRIGHT describes the conditions under you can use, copy, modify, and 14 | distribute lcc or works derived from lcc. 15 | 16 | doc/install.html is an HTML file that gives a complete description of 17 | the distribution and installation instructions. 18 | 19 | Chris Fraser / cwfraser@microsoft.com 20 | David Hanson / drh@microsoft.com 21 | $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $ 22 | -------------------------------------------------------------------------------- /tools/README.id: -------------------------------------------------------------------------------- 1 | 2001-10-31 Timothee Besset 2 | updated from the $/source/lcc code 3 | modified for portability and use with >= 1.31 mod source release 4 | -------------------------------------------------------------------------------- /tools/asm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | set(ASMFiles 7 | "cmdlib.h" 8 | "mathlib.h" 9 | "opstrings.h" 10 | 11 | "cmdlib.c" 12 | "q3asm.c" 13 | ) 14 | 15 | add_executable(${ASM} ${ASMFiles}) 16 | set_target_properties(${ASM} PROPERTIES PROJECT_LABEL "q3asm") 17 | set_property(TARGET ${ASM} PROPERTY FOLDER "Tools") 18 | -------------------------------------------------------------------------------- /tools/asm/README.Id: -------------------------------------------------------------------------------- 1 | 2002-10-25 Timothee Besset 2 | If you are looking for a faster version of the q3asm tool, try: 3 | http://www.icculus.org/~phaethon/q3/q3asm-turbo/q3asm-turbo.html 4 | 5 | 2001-10-31 Timothee Besset 6 | updated from the $/source/q3asm code 7 | modified for portability and use with >= 1.31 mod source release 8 | 9 | the cmdlib.c cmdlib.h mathlib.h qfiles.h have been copied from 10 | $/source/common 11 | -------------------------------------------------------------------------------- /tools/asm/cmdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (C) 1999-2005 Id Software, Inc. 4 | 5 | This file is part of Quake III Arena source code. 6 | 7 | Quake III Arena source code is free software; you can redistribute it 8 | and/or modify it under the terms of the GNU General Public License as 9 | published by the Free Software Foundation; either version 2 of the License, 10 | or (at your option) any later version. 11 | 12 | Quake III Arena source code is distributed in the hope that it will be 13 | useful, 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 Quake III Arena source code; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | =========================================================================== 21 | */ 22 | // cmdlib.h 23 | 24 | #ifndef __CMDLIB__ 25 | #define __CMDLIB__ 26 | 27 | #ifdef _MSC_VER 28 | #pragma warning(disable : 4244) // MIPS 29 | #pragma warning(disable : 4136) // X86 30 | #pragma warning(disable : 4051) // ALPHA 31 | 32 | #pragma warning(disable : 4018) // signed/unsigned mismatch 33 | #pragma warning(disable : 4305) // truncate from double to float 34 | 35 | #pragma check_stack(off) 36 | 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #ifdef _MSC_VER 48 | 49 | #pragma intrinsic( memset, memcpy ) 50 | 51 | #endif 52 | 53 | #ifndef __BYTEBOOL__ 54 | #define __BYTEBOOL__ 55 | typedef enum { qfalse, qtrue } qboolean; 56 | typedef unsigned char byte; 57 | #endif 58 | 59 | #define MAX_OS_PATH 1024 60 | #define MEM_BLOCKSIZE 4096 61 | 62 | // the dec offsetof macro doesnt work very well... 63 | #define myoffsetof(type,identifier) ((size_t)&((type *)0)->identifier) 64 | 65 | 66 | // set these before calling CheckParm 67 | extern int myargc; 68 | extern char **myargv; 69 | 70 | char *strupr (char *in); 71 | char *strlower (char *in); 72 | int Q_strncasecmp( const char *s1, const char *s2, int n ); 73 | int Q_stricmp( const char *s1, const char *s2 ); 74 | void Q_getwd( char *out ); 75 | 76 | int Q_filelength (FILE *f); 77 | int FileTime( const char *path ); 78 | 79 | void Q_mkdir( const char *path ); 80 | 81 | extern char qdir[1024]; 82 | extern char gamedir[1024]; 83 | extern char writedir[1024]; 84 | void SetQdirFromPath( const char *path ); 85 | char *ExpandArg( const char *path ); // from cmd line 86 | char *ExpandPath( const char *path ); // from scripts 87 | char *ExpandGamePath (const char *path); 88 | char *ExpandPathAndArchive( const char *path ); 89 | 90 | 91 | double I_FloatTime( void ); 92 | 93 | void Error( const char *error, ... ); 94 | int CheckParm( const char *check ); 95 | 96 | FILE *SafeOpenWrite( const char *filename ); 97 | FILE *SafeOpenRead( const char *filename ); 98 | void SafeRead (FILE *f, void *buffer, int count); 99 | void SafeWrite (FILE *f, const void *buffer, int count); 100 | 101 | int LoadFile( const char *filename, void **bufferptr ); 102 | int LoadFileBlock( const char *filename, void **bufferptr ); 103 | int TryLoadFile( const char *filename, void **bufferptr ); 104 | void SaveFile( const char *filename, const void *buffer, int count ); 105 | qboolean FileExists( const char *filename ); 106 | 107 | void DefaultExtension( char *path, const char *extension ); 108 | void DefaultPath( char *path, const char *basepath ); 109 | void StripFilename( char *path ); 110 | void StripExtension( char *path ); 111 | 112 | void ExtractFilePath( const char *path, char *dest ); 113 | void ExtractFileBase( const char *path, char *dest ); 114 | void ExtractFileExtension( const char *path, char *dest ); 115 | 116 | int ParseNum (const char *str); 117 | 118 | char *COM_Parse (char *data); 119 | 120 | extern char com_token[1024]; 121 | extern qboolean com_eof; 122 | 123 | char *copystring(const char *s); 124 | 125 | 126 | void CRC_Init(unsigned short *crcvalue); 127 | void CRC_ProcessByte(unsigned short *crcvalue, byte data); 128 | unsigned short CRC_Value(unsigned short crcvalue); 129 | 130 | void CreatePath( const char *path ); 131 | void QCopyFile( const char *from, const char *to ); 132 | 133 | extern qboolean archive; 134 | extern char archivedir[1024]; 135 | 136 | 137 | extern qboolean verbose; 138 | void qprintf( const char *format, ... ); 139 | void _printf( const char *format, ... ); 140 | 141 | void ExpandWildcards( int *argc, char ***argv ); 142 | 143 | 144 | // for compression routines 145 | typedef struct 146 | { 147 | void *data; 148 | int count, width, height; 149 | } cblock_t; 150 | 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /tools/asm/lib.txt: -------------------------------------------------------------------------------- 1 | 2 | strlen 3 | strcasecmp 4 | tolower 5 | strcat 6 | strncpy 7 | strcmp 8 | strcpy 9 | strchr 10 | 11 | vsprintf 12 | 13 | memcpy 14 | memset 15 | rand 16 | 17 | atoi 18 | atof 19 | 20 | abs 21 | 22 | floor 23 | fabs 24 | tan 25 | atan 26 | sqrt 27 | log 28 | cos 29 | sin 30 | atan2 31 | 32 | -------------------------------------------------------------------------------- /tools/asm/mathlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (C) 1999-2005 Id Software, Inc. 4 | 5 | This file is part of Quake III Arena source code. 6 | 7 | Quake III Arena source code is free software; you can redistribute it 8 | and/or modify it under the terms of the GNU General Public License as 9 | published by the Free Software Foundation; either version 2 of the License, 10 | or (at your option) any later version. 11 | 12 | Quake III Arena source code is distributed in the hope that it will be 13 | useful, 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 Quake III Arena source code; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | =========================================================================== 21 | */ 22 | #ifndef __MATHLIB__ 23 | #define __MATHLIB__ 24 | 25 | // mathlib.h 26 | 27 | #include 28 | 29 | #ifdef DOUBLEVEC_T 30 | typedef double vec_t; 31 | #else 32 | typedef float vec_t; 33 | #endif 34 | typedef vec_t vec2_t[3]; 35 | typedef vec_t vec3_t[3]; 36 | typedef vec_t vec4_t[4]; 37 | 38 | #define SIDE_FRONT 0 39 | #define SIDE_ON 2 40 | #define SIDE_BACK 1 41 | #define SIDE_CROSS -2 42 | 43 | #define Q_PI 3.14159265358979323846 44 | #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0F ) 45 | #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI ) 46 | 47 | extern vec3_t vec3_origin; 48 | 49 | #define EQUAL_EPSILON 0.001 50 | 51 | // plane types are used to speed some tests 52 | // 0-2 are axial planes 53 | #define PLANE_X 0 54 | #define PLANE_Y 1 55 | #define PLANE_Z 2 56 | #define PLANE_NON_AXIAL 3 57 | 58 | qboolean VectorCompare( const vec3_t v1, const vec3_t v2 ); 59 | 60 | #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2]) 61 | #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];} 62 | #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];} 63 | #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];} 64 | #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];} 65 | #define VectorClear(x) {x[0] = x[1] = x[2] = 0;} 66 | #define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];} 67 | void Vec10Copy( vec_t *in, vec_t *out ); 68 | 69 | vec_t Q_rint (vec_t in); 70 | vec_t _DotProduct (vec3_t v1, vec3_t v2); 71 | void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out); 72 | void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out); 73 | void _VectorCopy (vec3_t in, vec3_t out); 74 | void _VectorScale (vec3_t v, vec_t scale, vec3_t out); 75 | 76 | double VectorLength( const vec3_t v ); 77 | 78 | void VectorMA( const vec3_t va, double scale, const vec3_t vb, vec3_t vc ); 79 | 80 | void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ); 81 | vec_t VectorNormalize( const vec3_t in, vec3_t out ); 82 | vec_t ColorNormalize( const vec3_t in, vec3_t out ); 83 | void VectorInverse (vec3_t v); 84 | 85 | void ClearBounds (vec3_t mins, vec3_t maxs); 86 | void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); 87 | 88 | qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c ); 89 | 90 | void NormalToLatLong( const vec3_t normal, byte bytes[2] ); 91 | 92 | int PlaneTypeForNormal (vec3_t normal); 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /tools/asm/notes.txt: -------------------------------------------------------------------------------- 1 | 2 | don't do any paramter conversion (double to float, etc) 3 | 4 | 5 | 6 | Why? 7 | 8 | Security. 9 | Portability. 10 | 11 | It may be more aproachable. 12 | 13 | can still use regular dlls for development purposes 14 | 15 | lcc 16 | q3asm 17 | -------------------------------------------------------------------------------- /tools/asm/ops.txt: -------------------------------------------------------------------------------- 1 | CNSTF, 2 | CNSTI, 3 | CNSTP, 4 | CNSTU, 5 | 6 | ARGB, 7 | ARGF, 8 | ARGI, 9 | ARGP, 10 | ARGU, 11 | 12 | ASGNB, 13 | ASGNF, 14 | ASGNI, 15 | ASGNP, 16 | ASGNU, 17 | 18 | INDIRB, 19 | INDIRF, 20 | INDIRI, 21 | INDIRP, 22 | INDIRU, 23 | 24 | CVFF, 25 | CVFI, 26 | 27 | CVIF, 28 | CVII, 29 | CVIU, 30 | 31 | CVPU, 32 | 33 | CVUI, 34 | CVUP, 35 | CVUU, 36 | 37 | NEGF, 38 | NEGI, 39 | 40 | CALLB, 41 | CALLF, 42 | CALLI, 43 | CALLP, 44 | CALLU, 45 | CALLV, 46 | 47 | RETF, 48 | RETI, 49 | RETP, 50 | RETU, 51 | RETV, 52 | 53 | ADDRGP, 54 | 55 | ADDRFP, 56 | 57 | ADDRLP, 58 | 59 | ADDF, 60 | ADDI, 61 | ADDP, 62 | ADDU, 63 | 64 | SUBF, 65 | SUBI, 66 | SUBP, 67 | SUBU, 68 | 69 | LSHI, 70 | LSHU, 71 | 72 | MODI, 73 | MODU, 74 | 75 | RSHI, 76 | RSHU, 77 | 78 | BANDI, 79 | BANDU, 80 | 81 | BCOMI, 82 | BCOMU, 83 | 84 | BORI, 85 | BORU, 86 | 87 | BXORI, 88 | BXORU, 89 | 90 | DIVF, 91 | DIVI, 92 | DIVU, 93 | 94 | MULF, 95 | MULI, 96 | MULU, 97 | 98 | EQF, 99 | EQI, 100 | EQU, 101 | 102 | GEF, 103 | GEI, 104 | GEU, 105 | 106 | GTF, 107 | GTI, 108 | GTU, 109 | 110 | LEF, 111 | LEI, 112 | LEU, 113 | 114 | LTF, 115 | LTI, 116 | LTU, 117 | 118 | NEF, 119 | NEI, 120 | NEU, 121 | 122 | JUMPV, 123 | 124 | LABELV, 125 | 126 | LOADB, 127 | LOADF, 128 | LOADI, 129 | LOADP, 130 | LOADU, 131 | 132 | 133 | -------------------------------------------------------------------------------- /tools/asm/opstrings.h: -------------------------------------------------------------------------------- 1 | /* 2 | =========================================================================== 3 | Copyright (C) 1999-2005 Id Software, Inc. 4 | 5 | This file is part of Quake III Arena source code. 6 | 7 | Quake III Arena source code is free software; you can redistribute it 8 | and/or modify it under the terms of the GNU General Public License as 9 | published by the Free Software Foundation; either version 2 of the License, 10 | or (at your option) any later version. 11 | 12 | Quake III Arena source code is distributed in the hope that it will be 13 | useful, 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 Quake III Arena source code; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | =========================================================================== 21 | */ 22 | { "BREAK", OP_BREAK }, 23 | 24 | { "CNSTF4", OP_CONST }, 25 | { "CNSTI4", OP_CONST }, 26 | { "CNSTP4", OP_CONST }, 27 | { "CNSTU4", OP_CONST }, 28 | 29 | { "CNSTI2", OP_CONST }, 30 | { "CNSTU2", OP_CONST }, 31 | 32 | { "CNSTI1", OP_CONST }, 33 | { "CNSTU1", OP_CONST }, 34 | 35 | //{ "ARGB", OP_ARG }, 36 | //{ "ARGF", OP_ARG }, 37 | //{ "ARGI", OP_ARG }, 38 | //{ "ARGP", OP_ARG }, 39 | //{ "ARGU", OP_ARG }, 40 | 41 | { "ASGNB", OP_BLOCK_COPY }, 42 | { "ASGNF4", OP_STORE4 }, 43 | { "ASGNI4", OP_STORE4 }, 44 | { "ASGNP4", OP_STORE4 }, 45 | { "ASGNU4", OP_STORE4 }, 46 | 47 | { "ASGNI2", OP_STORE2 }, 48 | { "ASGNU2", OP_STORE2 }, 49 | 50 | { "ASGNI1", OP_STORE1 }, 51 | { "ASGNU1", OP_STORE1 }, 52 | 53 | { "INDIRB", OP_IGNORE }, // block copy deals with this 54 | { "INDIRF4", OP_LOAD4 }, 55 | { "INDIRI4", OP_LOAD4 }, 56 | { "INDIRP4", OP_LOAD4 }, 57 | { "INDIRU4", OP_LOAD4 }, 58 | 59 | { "INDIRI2", OP_LOAD2 }, 60 | { "INDIRU2", OP_LOAD2 }, 61 | 62 | { "INDIRI1", OP_LOAD1 }, 63 | { "INDIRU1", OP_LOAD1 }, 64 | 65 | { "CVFF4", OP_UNDEF }, 66 | { "CVFI4", OP_CVFI }, 67 | 68 | { "CVIF4", OP_CVIF }, 69 | { "CVII4", OP_SEX8 }, // will be either SEX8 or SEX16 70 | { "CVII1", OP_IGNORE }, 71 | { "CVII2", OP_IGNORE }, 72 | { "CVIU4", OP_IGNORE }, 73 | 74 | { "CVPU4", OP_IGNORE }, 75 | 76 | { "CVUI4", OP_IGNORE }, 77 | { "CVUP4", OP_IGNORE }, 78 | { "CVUU4", OP_IGNORE }, 79 | 80 | { "CVUU1", OP_IGNORE }, 81 | 82 | { "NEGF4", OP_NEGF }, 83 | { "NEGI4", OP_NEGI }, 84 | 85 | //{ "CALLB", OP_UNDEF }, 86 | //{ "CALLF", OP_UNDEF }, 87 | //{ "CALLI", OP_UNDEF }, 88 | //{ "CALLP", OP_UNDEF }, 89 | //{ "CALLU", OP_UNDEF }, 90 | //{ "CALLV", OP_CALL }, 91 | 92 | //{ "RETF", OP_UNDEF }, 93 | //{ "RETI", OP_UNDEF }, 94 | //{ "RETP", OP_UNDEF }, 95 | //{ "RETU", OP_UNDEF }, 96 | //{ "RETV", OP_UNDEF }, 97 | 98 | { "ADDRGP4", OP_CONST }, 99 | 100 | //{ "ADDRFP", OP_PARM }, 101 | //{ "ADDRLP", OP_LOCAL }, 102 | 103 | { "ADDF4", OP_ADDF }, 104 | { "ADDI4", OP_ADD }, 105 | { "ADDP4", OP_ADD }, 106 | { "ADDP", OP_ADD }, 107 | { "ADDU4", OP_ADD }, 108 | 109 | { "SUBF4", OP_SUBF }, 110 | { "SUBI4", OP_SUB }, 111 | { "SUBP4", OP_SUB }, 112 | { "SUBU4", OP_SUB }, 113 | 114 | { "LSHI4", OP_LSH }, 115 | { "LSHU4", OP_LSH }, 116 | 117 | { "MODI4", OP_MODI }, 118 | { "MODU4", OP_MODU }, 119 | 120 | { "RSHI4", OP_RSHI }, 121 | { "RSHU4", OP_RSHU }, 122 | 123 | { "BANDI4", OP_BAND }, 124 | { "BANDU4", OP_BAND }, 125 | 126 | { "BCOMI4", OP_BCOM }, 127 | { "BCOMU4", OP_BCOM }, 128 | 129 | { "BORI4", OP_BOR }, 130 | { "BORU4", OP_BOR }, 131 | 132 | { "BXORI4", OP_BXOR }, 133 | { "BXORU4", OP_BXOR }, 134 | 135 | { "DIVF4", OP_DIVF }, 136 | { "DIVI4", OP_DIVI }, 137 | { "DIVU4", OP_DIVU }, 138 | 139 | { "MULF4", OP_MULF }, 140 | { "MULI4", OP_MULI }, 141 | { "MULU4", OP_MULU }, 142 | 143 | { "EQF4", OP_EQF }, 144 | { "EQI4", OP_EQ }, 145 | { "EQU4", OP_EQ }, 146 | 147 | { "GEF4", OP_GEF }, 148 | { "GEI4", OP_GEI }, 149 | { "GEU4", OP_GEU }, 150 | 151 | { "GTF4", OP_GTF }, 152 | { "GTI4", OP_GTI }, 153 | { "GTU4", OP_GTU }, 154 | 155 | { "LEF4", OP_LEF }, 156 | { "LEI4", OP_LEI }, 157 | { "LEU4", OP_LEU }, 158 | 159 | { "LTF4", OP_LTF }, 160 | { "LTI4", OP_LTI }, 161 | { "LTU4", OP_LTU }, 162 | 163 | { "NEF4", OP_NEF }, 164 | { "NEI4", OP_NE }, 165 | { "NEU4", OP_NE }, 166 | 167 | { "JUMPV", OP_JUMP }, 168 | 169 | { "LOADB4", OP_UNDEF }, 170 | { "LOADF4", OP_UNDEF }, 171 | { "LOADI4", OP_UNDEF }, 172 | { "LOADP4", OP_UNDEF }, 173 | { "LOADU4", OP_UNDEF }, 174 | 175 | 176 | -------------------------------------------------------------------------------- /tools/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | set(CPPFiles 7 | "cpp.h" 8 | 9 | "cpp.c" 10 | "eval.c" 11 | "getopt.c" 12 | "hideset.c" 13 | "include.c" 14 | "lex.c" 15 | "macro.c" 16 | "nlist.c" 17 | "tokens.c" 18 | "unix.c" 19 | ) 20 | 21 | add_executable(${CPP} ${CPPFiles}) 22 | set_target_properties(${CPP} PROPERTIES PROJECT_LABEL "q3cpp") 23 | set_property(TARGET ${CPP} PROPERTY FOLDER "Tools") 24 | -------------------------------------------------------------------------------- /tools/cpp/cpp.h: -------------------------------------------------------------------------------- 1 | #define INS 32768 /* input buffer */ 2 | #define OBS 4096 /* outbut buffer */ 3 | #define NARG 32 /* Max number arguments to a macro */ 4 | #define NINCLUDE 32 /* Max number of include directories (-I) */ 5 | #define NIF 32 /* depth of nesting of #if */ 6 | #ifndef EOF 7 | #define EOF (-1) 8 | #endif 9 | #ifndef NULL 10 | #define NULL 0 11 | #endif 12 | 13 | #ifndef __alpha 14 | typedef unsigned char uchar; 15 | #endif 16 | 17 | enum toktype { END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP, 18 | EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS, 19 | ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS, 20 | TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST, 21 | COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET, 22 | ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH, 23 | ASRSH, ASOR, ASAND, ELLIPS, 24 | DSHARP1, NAME1, DEFINED, UMINUS }; 25 | 26 | enum kwtype { KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KDEFINE, 27 | KUNDEF, KLINE, KWARNING, KERROR, KPRAGMA, KDEFINED, 28 | KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL }; 29 | 30 | #define ISDEFINED 01 /* has #defined value */ 31 | #define ISKW 02 /* is PP keyword */ 32 | #define ISUNCHANGE 04 /* can't be #defined in PP */ 33 | #define ISMAC 010 /* builtin macro, e.g. __LINE__ */ 34 | 35 | #define EOB 0xFE /* sentinel for end of input buffer */ 36 | #define EOFC 0xFD /* sentinel for end of input file */ 37 | #define XPWS 1 /* token flag: white space to assure token sep. */ 38 | 39 | typedef struct token { 40 | unsigned char type; 41 | unsigned char flag; 42 | unsigned short hideset; 43 | unsigned int wslen; 44 | unsigned int len; 45 | uchar *t; 46 | } Token; 47 | 48 | typedef struct tokenrow { 49 | Token *tp; /* current one to scan */ 50 | Token *bp; /* base (allocated value) */ 51 | Token *lp; /* last+1 token used */ 52 | int max; /* number allocated */ 53 | } Tokenrow; 54 | 55 | typedef struct source { 56 | char *filename; /* name of file of the source */ 57 | int line; /* current line number */ 58 | int lineinc; /* adjustment for \\n lines */ 59 | uchar *inb; /* input buffer */ 60 | uchar *inp; /* input pointer */ 61 | uchar *inl; /* end of input */ 62 | int fd; /* input source */ 63 | int ifdepth; /* conditional nesting in include */ 64 | struct source *next; /* stack for #include */ 65 | } Source; 66 | 67 | typedef struct nlist { 68 | struct nlist *next; 69 | uchar *name; 70 | int len; 71 | Tokenrow *vp; /* value as macro */ 72 | Tokenrow *ap; /* list of argument names, if any */ 73 | char val; /* value as preprocessor name */ 74 | char flag; /* is defined, is pp name */ 75 | } Nlist; 76 | 77 | typedef struct includelist { 78 | char deleted; 79 | char always; 80 | char *file; 81 | } Includelist; 82 | 83 | #define new(t) (t *)domalloc(sizeof(t)) 84 | #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037))) 85 | #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037)) 86 | extern unsigned long namebit[077+1]; 87 | 88 | enum errtype { WARNING, ERROR, FATAL }; 89 | 90 | void expandlex(void); 91 | void fixlex(void); 92 | void setup(int, char **); 93 | int gettokens(Tokenrow *, int); 94 | int comparetokens(Tokenrow *, Tokenrow *); 95 | Source *setsource(char *, int, char *); 96 | void unsetsource(void); 97 | void puttokens(Tokenrow *); 98 | void process(Tokenrow *); 99 | void *domalloc(int); 100 | void dofree(void *); 101 | void error(enum errtype, char *, ...); 102 | void flushout(void); 103 | int fillbuf(Source *); 104 | int trigraph(Source *); 105 | int foldline(Source *); 106 | Nlist *lookup(Token *, int); 107 | void control(Tokenrow *); 108 | void dodefine(Tokenrow *); 109 | void doadefine(Tokenrow *, int); 110 | void doinclude(Tokenrow *); 111 | void appendDirToIncludeList( char *dir ); 112 | void doif(Tokenrow *, enum kwtype); 113 | void expand(Tokenrow *, Nlist *); 114 | void builtin(Tokenrow *, int); 115 | int gatherargs(Tokenrow *, Tokenrow **, int *); 116 | void substargs(Nlist *, Tokenrow *, Tokenrow **); 117 | void expandrow(Tokenrow *, char *); 118 | void maketokenrow(int, Tokenrow *); 119 | Tokenrow *copytokenrow(Tokenrow *, Tokenrow *); 120 | Token *growtokenrow(Tokenrow *); 121 | Tokenrow *normtokenrow(Tokenrow *); 122 | void adjustrow(Tokenrow *, int); 123 | void movetokenrow(Tokenrow *, Tokenrow *); 124 | void insertrow(Tokenrow *, int, Tokenrow *); 125 | void peektokens(Tokenrow *, char *); 126 | void doconcat(Tokenrow *); 127 | Tokenrow *stringify(Tokenrow *); 128 | int lookuparg(Nlist *, Token *); 129 | long eval(Tokenrow *, int); 130 | void genline(void); 131 | void setempty(Tokenrow *); 132 | void makespace(Tokenrow *); 133 | char *outnum(char *, int); 134 | int digit(int); 135 | uchar *newstring(uchar *, int, int); 136 | int checkhideset(int, Nlist *); 137 | void prhideset(int); 138 | int newhideset(int, Nlist *); 139 | int unionhideset(int, int); 140 | void iniths(void); 141 | void setobjname(char *); 142 | #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp) 143 | 144 | char *basepath( char *fname ); 145 | 146 | extern char *outbufp; 147 | extern Token nltoken; 148 | extern Source *cursource; 149 | extern char *curtime; 150 | extern int incdepth; 151 | extern int ifdepth; 152 | extern int ifsatisfied[NIF]; 153 | extern int Mflag; 154 | extern int skipping; 155 | extern int verbose; 156 | extern int Cplusplus; 157 | extern Nlist *kwdefined; 158 | extern Includelist includelist[NINCLUDE]; 159 | extern char wd[]; 160 | 161 | #ifndef _WIN32 162 | #include 163 | #else 164 | #include 165 | #endif 166 | #include 167 | -------------------------------------------------------------------------------- /tools/cpp/getopt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define EPR fprintf(stderr, 4 | #define ERR(str, chr) if(opterr){EPR "%s%c\n", str, chr);} 5 | int opterr = 1; 6 | int optind = 1; 7 | int optopt; 8 | char *optarg; 9 | 10 | int 11 | lcc_getopt (int argc, char *const argv[], const char *opts) 12 | { 13 | static int sp = 1; 14 | int c; 15 | char *cp; 16 | 17 | if (sp == 1) { 18 | if (optind >= argc || 19 | argv[optind][0] != '-' || argv[optind][1] == '\0') 20 | return -1; 21 | else if (strcmp(argv[optind], "--") == 0) { 22 | optind++; 23 | return -1; 24 | } 25 | } 26 | optopt = c = argv[optind][sp]; 27 | if (c == ':' || (cp=strchr(opts, c)) == 0) { 28 | ERR (": illegal option -- ", c); 29 | if (argv[optind][++sp] == '\0') { 30 | optind++; 31 | sp = 1; 32 | } 33 | return '?'; 34 | } 35 | if (*++cp == ':') { 36 | if (argv[optind][sp+1] != '\0') 37 | optarg = &argv[optind++][sp+1]; 38 | else if (++optind >= argc) { 39 | ERR (": option requires an argument -- ", c); 40 | sp = 1; 41 | return '?'; 42 | } else 43 | optarg = argv[optind++]; 44 | sp = 1; 45 | } else { 46 | if (argv[optind][++sp] == '\0') { 47 | sp = 1; 48 | optind++; 49 | } 50 | optarg = 0; 51 | } 52 | return c; 53 | } 54 | -------------------------------------------------------------------------------- /tools/cpp/hideset.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpp.h" 5 | 6 | /* 7 | * A hideset is a null-terminated array of Nlist pointers. 8 | * They are referred to by indices in the hidesets array. 9 | * Hideset 0 is empty. 10 | */ 11 | 12 | #define HSSIZ 32 13 | typedef Nlist **Hideset; 14 | Hideset *hidesets; 15 | int nhidesets = 0; 16 | int maxhidesets = 3; 17 | int inserths(Hideset, Hideset, Nlist *); 18 | 19 | /* 20 | * Test for membership in a hideset 21 | */ 22 | int 23 | checkhideset(int hs, Nlist *np) 24 | { 25 | Hideset hsp; 26 | 27 | if (hs>=nhidesets) 28 | abort(); 29 | for (hsp = hidesets[hs]; *hsp; hsp++) { 30 | if (*hsp == np) 31 | return 1; 32 | } 33 | return 0; 34 | } 35 | 36 | /* 37 | * Return the (possibly new) hideset obtained by adding np to hs. 38 | */ 39 | int 40 | newhideset(int hs, Nlist *np) 41 | { 42 | int i, len; 43 | Nlist *nhs[HSSIZ+3]; 44 | Hideset hs1, hs2; 45 | 46 | len = inserths(nhs, hidesets[hs], np); 47 | for (i=0; i=HSSIZ) 53 | return hs; 54 | if (nhidesets >= maxhidesets) { 55 | maxhidesets = 3*maxhidesets/2+1; 56 | hidesets = (Hideset *)realloc(hidesets, (sizeof (Hideset *))*maxhidesets); 57 | if (hidesets == NULL) 58 | error(FATAL, "Out of memory from realloc"); 59 | } 60 | hs1 = (Hideset)domalloc(len*sizeof(Hideset)); 61 | memmove(hs1, nhs, len*sizeof(Hideset)); 62 | hidesets[nhidesets] = hs1; 63 | return nhidesets++; 64 | } 65 | 66 | int 67 | inserths(Hideset dhs, Hideset shs, Nlist *np) 68 | { 69 | Hideset odhs = dhs; 70 | 71 | while (*shs && *shs < np) 72 | *dhs++ = *shs++; 73 | if (*shs != np) 74 | *dhs++ = np; 75 | do { 76 | *dhs++ = *shs; 77 | } while (*shs++); 78 | return dhs - odhs; 79 | } 80 | 81 | /* 82 | * Hideset union 83 | */ 84 | int 85 | unionhideset(int hs1, int hs2) 86 | { 87 | Hideset hp; 88 | 89 | for (hp = hidesets[hs2]; *hp; hp++) 90 | hs1 = newhideset(hs1, *hp); 91 | return hs1; 92 | } 93 | 94 | void 95 | iniths(void) 96 | { 97 | hidesets = (Hideset *)domalloc(maxhidesets*sizeof(Hideset *)); 98 | hidesets[0] = (Hideset)domalloc(sizeof(Hideset)); 99 | *hidesets[0] = NULL; 100 | nhidesets++; 101 | } 102 | 103 | void 104 | prhideset(int hs) 105 | { 106 | Hideset np; 107 | 108 | for (np = hidesets[hs]; *np; np++) { 109 | fprintf(stderr, (char*)(*np)->name, (*np)->len); 110 | fprintf(stderr, " "); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /tools/cpp/include.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpp.h" 5 | 6 | Includelist includelist[NINCLUDE]; 7 | 8 | extern char *objname; 9 | 10 | void appendDirToIncludeList( char *dir ) 11 | { 12 | int i; 13 | char *fqdir; 14 | 15 | fqdir = (char *)newstring( (uchar *)includelist[NINCLUDE-1].file, 256, 0 ); 16 | strcat( fqdir, "/" ); 17 | strcat( fqdir, dir ); 18 | 19 | //avoid adding it more than once 20 | for (i=NINCLUDE-2; i>=0; i--) { 21 | if (includelist[i].file && 22 | !strcmp (includelist[i].file, fqdir)) { 23 | return; 24 | } 25 | } 26 | 27 | for (i=NINCLUDE-2; i>=0; i--) { 28 | if (includelist[i].file==NULL) { 29 | includelist[i].always = 1; 30 | includelist[i].file = fqdir; 31 | break; 32 | } 33 | } 34 | if (i<0) 35 | error(FATAL, "Too many -I directives"); 36 | } 37 | 38 | void 39 | doinclude(Tokenrow *trp) 40 | { 41 | char fname[256], iname[256]; 42 | Includelist *ip; 43 | int angled, len, fd, i; 44 | 45 | trp->tp += 1; 46 | if (trp->tp>=trp->lp) 47 | goto syntax; 48 | if (trp->tp->type!=STRING && trp->tp->type!=LT) { 49 | len = trp->tp - trp->bp; 50 | expandrow(trp, ""); 51 | trp->tp = trp->bp+len; 52 | } 53 | if (trp->tp->type==STRING) { 54 | len = trp->tp->len-2; 55 | if (len > sizeof(fname) - 1) 56 | len = sizeof(fname) - 1; 57 | strncpy(fname, (char*)trp->tp->t+1, len); 58 | angled = 0; 59 | } else if (trp->tp->type==LT) { 60 | len = 0; 61 | trp->tp++; 62 | while (trp->tp->type!=GT) { 63 | if (trp->tp>trp->lp || len+trp->tp->len+2 >= sizeof(fname)) 64 | goto syntax; 65 | strncpy(fname+len, (char*)trp->tp->t, trp->tp->len); 66 | len += trp->tp->len; 67 | trp->tp++; 68 | } 69 | angled = 1; 70 | } else 71 | goto syntax; 72 | trp->tp += 2; 73 | if (trp->tp < trp->lp || len==0) 74 | goto syntax; 75 | fname[len] = '\0'; 76 | 77 | appendDirToIncludeList( basepath( fname ) ); 78 | 79 | if (fname[0]=='/') { 80 | fd = open(fname, 0); 81 | strcpy(iname, fname); 82 | } else for (fd = -1,i=NINCLUDE-1; i>=0; i--) { 83 | ip = &includelist[i]; 84 | if (ip->file==NULL || ip->deleted || (angled && ip->always==0)) 85 | continue; 86 | if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname)) 87 | continue; 88 | strcpy(iname, ip->file); 89 | strcat(iname, "/"); 90 | strcat(iname, fname); 91 | if ((fd = open(iname, 0)) >= 0) 92 | break; 93 | } 94 | if ( Mflag>1 || (!angled&&Mflag==1) ) { 95 | write(1,objname,strlen(objname)); 96 | write(1,iname,strlen(iname)); 97 | write(1,"\n",1); 98 | } 99 | if (fd >= 0) { 100 | if (++incdepth > 10) 101 | error(FATAL, "#include too deeply nested"); 102 | setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL); 103 | genline(); 104 | } else { 105 | trp->tp = trp->bp+2; 106 | error(ERROR, "Could not find include file %r", trp); 107 | } 108 | return; 109 | syntax: 110 | error(ERROR, "Syntax error in #include"); 111 | } 112 | 113 | /* 114 | * Generate a line directive for cursource 115 | */ 116 | void 117 | genline(void) 118 | { 119 | static Token ta = { UNCLASS }; 120 | static Tokenrow tr = { &ta, &ta, &ta+1, 1 }; 121 | uchar *p; 122 | 123 | ta.t = p = (uchar*)outbufp; 124 | strcpy((char*)p, "#line "); 125 | p += sizeof("#line ")-1; 126 | p = (uchar*)outnum((char*)p, cursource->line); 127 | *p++ = ' '; *p++ = '"'; 128 | if (cursource->filename[0]!='/' && wd[0]) { 129 | strcpy((char*)p, wd); 130 | p += strlen(wd); 131 | *p++ = '/'; 132 | } 133 | strcpy((char*)p, cursource->filename); 134 | p += strlen((char*)p); 135 | *p++ = '"'; *p++ = '\n'; 136 | ta.len = (char*)p-outbufp; 137 | outbufp = (char*)p; 138 | tr.tp = tr.bp; 139 | puttokens(&tr); 140 | } 141 | 142 | void 143 | setobjname(char *f) 144 | { 145 | int n = strlen(f); 146 | objname = (char*)domalloc(n+5); 147 | strcpy(objname,f); 148 | if(objname[n-2]=='.'){ 149 | strcpy(objname+n-1,"$O: "); 150 | }else{ 151 | strcpy(objname+n,"$O: "); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /tools/cpp/nlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpp.h" 5 | 6 | extern char *optarg; 7 | extern int optind; 8 | extern int verbose; 9 | extern int Cplusplus; 10 | Nlist *kwdefined; 11 | char wd[128]; 12 | 13 | #define NLSIZE 128 14 | 15 | static Nlist *nlist[NLSIZE]; 16 | 17 | struct kwtab { 18 | char *kw; 19 | int val; 20 | int flag; 21 | } kwtab[] = { 22 | {"if", KIF, ISKW}, 23 | {"ifdef", KIFDEF, ISKW}, 24 | {"ifndef", KIFNDEF, ISKW}, 25 | {"elif", KELIF, ISKW}, 26 | {"else", KELSE, ISKW}, 27 | {"endif", KENDIF, ISKW}, 28 | {"include", KINCLUDE, ISKW}, 29 | {"define", KDEFINE, ISKW}, 30 | {"undef", KUNDEF, ISKW}, 31 | {"line", KLINE, ISKW}, 32 | {"warning", KWARNING, ISKW}, 33 | {"error", KERROR, ISKW}, 34 | {"pragma", KPRAGMA, ISKW}, 35 | {"eval", KEVAL, ISKW}, 36 | {"defined", KDEFINED, ISDEFINED+ISUNCHANGE}, 37 | {"__LINE__", KLINENO, ISMAC+ISUNCHANGE}, 38 | {"__FILE__", KFILE, ISMAC+ISUNCHANGE}, 39 | {"__DATE__", KDATE, ISMAC+ISUNCHANGE}, 40 | {"__TIME__", KTIME, ISMAC+ISUNCHANGE}, 41 | {"__STDC__", KSTDC, ISUNCHANGE}, 42 | {NULL} 43 | }; 44 | 45 | unsigned long namebit[077+1]; 46 | Nlist *np; 47 | 48 | void 49 | setup_kwtab(void) 50 | { 51 | struct kwtab *kp; 52 | Nlist *np; 53 | Token t; 54 | static Token deftoken[1] = {{ NAME, 0, 0, 0, 7, (uchar*)"defined" }}; 55 | static Tokenrow deftr = { deftoken, deftoken, deftoken+1, 1 }; 56 | 57 | for (kp=kwtab; kp->kw; kp++) { 58 | t.t = (uchar*)kp->kw; 59 | t.len = strlen(kp->kw); 60 | np = lookup(&t, 1); 61 | np->flag = kp->flag; 62 | np->val = kp->val; 63 | if (np->val == KDEFINED) { 64 | kwdefined = np; 65 | np->val = NAME; 66 | np->vp = &deftr; 67 | np->ap = 0; 68 | } 69 | } 70 | } 71 | 72 | Nlist * 73 | lookup(Token *tp, int install) 74 | { 75 | unsigned int h; 76 | Nlist *np; 77 | uchar *cp, *cpe; 78 | 79 | h = 0; 80 | for (cp=tp->t, cpe=cp+tp->len; cpt==*np->name && tp->len==np->len 86 | && strncmp((char*)tp->t, (char*)np->name, tp->len)==0) 87 | return np; 88 | np = np->next; 89 | } 90 | if (install) { 91 | np = new(Nlist); 92 | np->vp = NULL; 93 | np->ap = NULL; 94 | np->flag = 0; 95 | np->val = 0; 96 | np->len = tp->len; 97 | np->name = newstring(tp->t, tp->len, 0); 98 | np->next = nlist[h]; 99 | nlist[h] = np; 100 | quickset(tp->t[0], tp->len>1? tp->t[1]:0); 101 | return np; 102 | } 103 | return NULL; 104 | } 105 | -------------------------------------------------------------------------------- /tools/cpp/unix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "cpp.h" 7 | 8 | extern int lcc_getopt(int, char *const *, const char *); 9 | extern char *optarg, rcsid[]; 10 | extern int optind; 11 | int verbose; 12 | int Mflag; /* only print active include files */ 13 | char *objname; /* "src.$O: " */ 14 | int Cplusplus = 1; 15 | 16 | void 17 | setup(int argc, char **argv) 18 | { 19 | int c, fd, i; 20 | char *fp, *dp; 21 | Tokenrow tr; 22 | extern void setup_kwtab(void); 23 | uchar *includeDirs[ NINCLUDE ] = { 0 }; 24 | int numIncludeDirs = 0; 25 | 26 | setup_kwtab(); 27 | while ((c = lcc_getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1) 28 | switch (c) { 29 | case 'N': 30 | for (i=0; i", -1, optarg); 40 | maketokenrow(3, &tr); 41 | gettokens(&tr, 1); 42 | doadefine(&tr, c); 43 | unsetsource(); 44 | break; 45 | case 'M': 46 | Mflag++; 47 | break; 48 | case 'v': 49 | fprintf(stderr, "%s %s\n", argv[0], rcsid); 50 | break; 51 | case 'V': 52 | verbose++; 53 | break; 54 | case '+': 55 | Cplusplus++; 56 | break; 57 | default: 58 | break; 59 | } 60 | dp = "."; 61 | fp = ""; 62 | fd = 0; 63 | if (optind 4 | #include 5 | #include "../qcommon/q_platform.h" 6 | 7 | #ifdef _WIN32 8 | #define BINEXT ".exe" 9 | #else 10 | #define BINEXT "" 11 | #endif 12 | 13 | char *suffixes[] = { ".c", ".i", ".asm", ".o", ".out", 0 }; 14 | char inputs[256] = ""; 15 | char *cpp[] = { "q3cpp" BINEXT, 16 | "-D__STDC__=1", "-D__STRICT_ANSI__", "-D__signed__=signed", "-DQ3_VM", 17 | "$1", "$2", "$3", 0 }; 18 | char *include[] = { 0 }; 19 | char *com[] = { "q3rcc" BINEXT, "-target=bytecode", "$1", "$2", "$3", 0 }; 20 | char *ld[] = { 0 }; 21 | char *as[] = { 0 }; 22 | 23 | extern char *concat(char *, char *); 24 | 25 | /* 26 | =============== 27 | UpdatePaths 28 | 29 | Updates the paths to q3cpp and q3rcc based on 30 | the directory that contains q3lcc 31 | =============== 32 | */ 33 | void UpdatePaths( const char *lccBinary ) 34 | { 35 | char basepath[ 1024 ]; 36 | char *p; 37 | size_t basepathsz = sizeof( basepath ) - 1; 38 | 39 | strncpy( basepath, lccBinary, basepathsz ); 40 | basepath[basepathsz] = 0; 41 | p = strrchr( basepath, PATH_SEP ); 42 | 43 | if( p ) 44 | { 45 | *( p + 1 ) = '\0'; 46 | 47 | cpp[ 0 ] = concat( basepath, "q3cpp" BINEXT ); 48 | com[ 0 ] = concat( basepath, "q3rcc" BINEXT ); 49 | } 50 | } 51 | 52 | int option(char *arg) { 53 | if (strncmp(arg, "-lccdir=", 8) == 0) { 54 | cpp[0] = concat(&arg[8], "/q3cpp" BINEXT); 55 | include[0] = concat("-I", concat(&arg[8], "/include")); 56 | com[0] = concat(&arg[8], "/q3rcc" BINEXT); 57 | } else if (strncmp(arg, "-lcppdir=", 9) == 0) { 58 | cpp[0] = concat(&arg[9], "/q3cpp" BINEXT); 59 | } else if (strncmp(arg, "-lrccdir=", 9) == 0) { 60 | com[0] = concat(&arg[9], "/q3rcc" BINEXT); 61 | } else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-pg") == 0) { 62 | fprintf( stderr, "no profiling supported, %s ignored.\n", arg); 63 | } else if (strcmp(arg, "-b") == 0) 64 | ; 65 | else if (strcmp(arg, "-g") == 0) 66 | fprintf( stderr, "no debugging supported, %s ignored.\n", arg); 67 | else if (strncmp(arg, "-ld=", 4) == 0 || strcmp(arg, "-static") == 0) { 68 | fprintf( stderr, "no linking supported, %s ignored.\n", arg); 69 | } else 70 | return 0; 71 | return 1; 72 | } 73 | -------------------------------------------------------------------------------- /tools/rcc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Make sure the user is not executing this script directly 2 | if(NOT InMVSDK) 3 | message(FATAL_ERROR "Use the top-level cmake script!") 4 | endif(NOT InMVSDK) 5 | 6 | set(RCCFiles 7 | "c.h" 8 | "config.h" 9 | "token.h" 10 | 11 | "alloc.c" 12 | "bytecode.c" 13 | "decl.c" 14 | "error.c" 15 | "expr.c" 16 | "init.c" 17 | "input.c" 18 | "list.c" 19 | "null.c" 20 | "prof.c" 21 | "simp.c" 22 | "string.c" 23 | "symbolic.c" 24 | "tree.c" 25 | "bind.c" 26 | "dag.c" 27 | "dagcheck.c" 28 | "enode.c" 29 | "event.c" 30 | "gen.c" 31 | "inits.c" 32 | "lex.c" 33 | "main.c" 34 | "output.c" 35 | "profio.c" 36 | "stmt.c" 37 | "sym.c" 38 | "trace.c" 39 | "types.c" 40 | ) 41 | 42 | add_executable(${RCC} ${RCCFiles}) 43 | set_target_properties(${RCC} PROPERTIES PROJECT_LABEL "q3rcc") 44 | set_property(TARGET ${RCC} PROPERTY FOLDER "Tools") 45 | -------------------------------------------------------------------------------- /tools/rcc/alloc.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | struct block { 3 | struct block *next; 4 | char *limit; 5 | char *avail; 6 | }; 7 | union align { 8 | long l; 9 | char *p; 10 | double d; 11 | int (*f)(void); 12 | }; 13 | union header { 14 | struct block b; 15 | union align a; 16 | }; 17 | #ifdef PURIFY 18 | union header *arena[3]; 19 | 20 | void *allocate(unsigned long n, unsigned a) { 21 | union header *new = malloc(sizeof *new + n); 22 | 23 | assert(a < NELEMS(arena)); 24 | if (new == NULL) { 25 | error("insufficient memory\n"); 26 | exit(1); 27 | } 28 | new->b.next = (void *)arena[a]; 29 | arena[a] = new; 30 | return new + 1; 31 | } 32 | 33 | void deallocate(unsigned a) { 34 | union header *p, *q; 35 | 36 | assert(a < NELEMS(arena)); 37 | for (p = arena[a]; p; p = q) { 38 | q = (void *)p->b.next; 39 | free(p); 40 | } 41 | arena[a] = NULL; 42 | } 43 | 44 | void *newarray(unsigned long m, unsigned long n, unsigned a) { 45 | return allocate(m*n, a); 46 | } 47 | #else 48 | static struct block 49 | first[] = { { NULL }, { NULL }, { NULL } }, 50 | *arena[] = { &first[0], &first[1], &first[2] }; 51 | static struct block *freeblocks; 52 | 53 | void *allocate(unsigned long n, unsigned a) { 54 | struct block *ap; 55 | 56 | assert(a < NELEMS(arena)); 57 | assert(n > 0); 58 | ap = arena[a]; 59 | n = roundup(n, sizeof (union align)); 60 | while (n > ap->limit - ap->avail) { 61 | if ((ap->next = freeblocks) != NULL) { 62 | freeblocks = freeblocks->next; 63 | ap = ap->next; 64 | } else 65 | { 66 | unsigned m = sizeof (union header) + n + roundup(10*1024, sizeof (union align)); 67 | ap->next = malloc(m); 68 | ap = ap->next; 69 | if (ap == NULL) { 70 | error("insufficient memory\n"); 71 | exit(1); 72 | } 73 | ap->limit = (char *)ap + m; 74 | } 75 | ap->avail = (char *)((union header *)ap + 1); 76 | ap->next = NULL; 77 | arena[a] = ap; 78 | 79 | } 80 | ap->avail += n; 81 | return ap->avail - n; 82 | } 83 | 84 | void *newarray(unsigned long m, unsigned long n, unsigned a) { 85 | return allocate(m*n, a); 86 | } 87 | void deallocate(unsigned a) { 88 | assert(a < NELEMS(arena)); 89 | arena[a]->next = freeblocks; 90 | freeblocks = first[a].next; 91 | first[a].next = NULL; 92 | arena[a] = &first[a]; 93 | } 94 | #endif 95 | -------------------------------------------------------------------------------- /tools/rcc/bind.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | extern Interface nullIR; 3 | extern Interface bytecodeIR; 4 | Binding bindings[] = { 5 | { "null", &nullIR }, 6 | { "bytecode", &bytecodeIR }, 7 | { NULL, NULL }, 8 | }; 9 | -------------------------------------------------------------------------------- /tools/rcc/config.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | unsigned char max_unaligned_load; 3 | Symbol (*rmap)(int); 4 | 5 | void (*blkfetch)(int size, int off, int reg, int tmp); 6 | void (*blkstore)(int size, int off, int reg, int tmp); 7 | void (*blkloop)(int dreg, int doff, 8 | int sreg, int soff, 9 | int size, int tmps[]); 10 | void (*_label)(Node); 11 | int (*_rule)(void*, int); 12 | short **_nts; 13 | void (*_kids)(Node, int, Node*); 14 | char **_string; 15 | char **_templates; 16 | char *_isinstruction; 17 | char **_ntname; 18 | void (*emit2)(Node); 19 | void (*doarg)(Node); 20 | void (*target)(Node); 21 | void (*clobber)(Node); 22 | } Xinterface; 23 | extern int askregvar(Symbol, Symbol); 24 | extern void blkcopy(int, int, int, int, int, int[]); 25 | extern int getregnum(Node); 26 | extern int mayrecalc(Node); 27 | extern int mkactual(int, int); 28 | extern void mkauto(Symbol); 29 | extern Symbol mkreg(char *, int, int, int); 30 | extern Symbol mkwildcard(Symbol *); 31 | extern int move(Node); 32 | extern int notarget(Node); 33 | extern void parseflags(int, char **); 34 | extern int range(Node, int, int); 35 | extern unsigned regloc(Symbol); /* omit */ 36 | extern void rtarget(Node, int, Symbol); 37 | extern void setreg(Node, Symbol); 38 | extern void spill(unsigned, int, Node); 39 | extern int widens(Node); 40 | 41 | extern int argoffset, maxargoffset; 42 | extern int bflag, dflag; 43 | extern int dalign, salign; 44 | extern int framesize; 45 | extern unsigned freemask[], usedmask[]; 46 | extern int offset, maxoffset; 47 | extern int swap; 48 | extern unsigned tmask[], vmask[]; 49 | typedef struct { 50 | unsigned listed:1; 51 | unsigned registered:1; 52 | unsigned emitted:1; 53 | unsigned copy:1; 54 | unsigned equatable:1; 55 | unsigned spills:1; 56 | unsigned mayrecalc:1; 57 | void *state; 58 | short inst; 59 | Node kids[3]; 60 | Node prev, next; 61 | Node prevuse; 62 | short argno; 63 | } Xnode; 64 | typedef struct { 65 | Symbol vbl; 66 | short set; 67 | short number; 68 | unsigned mask; 69 | } *Regnode; 70 | enum { IREG=0, FREG=1 }; 71 | typedef struct { 72 | char *name; 73 | unsigned int eaddr; /* omit */ 74 | int offset; 75 | Node lastuse; 76 | int usecount; 77 | Regnode regnode; 78 | Symbol *wildcard; 79 | } Xsymbol; 80 | enum { RX=2 }; 81 | typedef struct { 82 | int offset; 83 | unsigned freemask[2]; 84 | } Env; 85 | 86 | #define LBURG_MAX SHRT_MAX 87 | 88 | enum { VREG=(44<<4) }; 89 | 90 | /* Exported for the front end */ 91 | extern void blockbeg(Env *); 92 | extern void blockend(Env *); 93 | extern void emit(Node); 94 | extern Node gen(Node); 95 | 96 | extern unsigned emitbin(Node, int); 97 | 98 | #ifdef NDEBUG 99 | #define debug(x) (void)0 100 | #else 101 | #define debug(x) (void)(dflag&&((x),0)) 102 | #endif 103 | -------------------------------------------------------------------------------- /tools/rcc/error.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | static void printtoken(void); 5 | int errcnt = 0; 6 | int errlimit = 20; 7 | char kind[] = { 8 | #define xx(a,b,c,d,e,f,g) f, 9 | #define yy(a,b,c,d,e,f,g) f, 10 | #include "token.h" 11 | }; 12 | int wflag; /* != 0 to suppress warning messages */ 13 | 14 | void test(int tok, char set[]) { 15 | if (t == tok) 16 | t = gettok(); 17 | else { 18 | expect(tok); 19 | skipto(tok, set); 20 | if (t == tok) 21 | t = gettok(); 22 | } 23 | } 24 | void expect(int tok) { 25 | if (t == tok) 26 | t = gettok(); 27 | else { 28 | error("syntax error; found"); 29 | printtoken(); 30 | fprint(stderr, " expecting `%k'\n", tok); 31 | } 32 | } 33 | void error(const char *fmt, ...) { 34 | va_list ap; 35 | 36 | if (errcnt++ >= errlimit) { 37 | errcnt = -1; 38 | error("too many errors\n"); 39 | exit(1); 40 | } 41 | va_start(ap, fmt); 42 | if (firstfile != file && firstfile && *firstfile) 43 | fprint(stderr, "%s: ", firstfile); 44 | fprint(stderr, "%w: ", &src); 45 | vfprint(stderr, NULL, fmt, ap); 46 | va_end(ap); 47 | } 48 | 49 | void skipto(int tok, char set[]) { 50 | int n; 51 | char *s; 52 | 53 | assert(set); 54 | for (n = 0; t != EOI && t != tok; t = gettok()) { 55 | for (s = set; *s && kind[t] != *s; s++) 56 | ; 57 | if (kind[t] == *s) 58 | break; 59 | if (n++ == 0) 60 | error("skipping"); 61 | if (n <= 8) 62 | printtoken(); 63 | else if (n == 9) 64 | fprint(stderr, " ..."); 65 | } 66 | if (n > 8) { 67 | fprint(stderr, " up to"); 68 | printtoken(); 69 | } 70 | if (n > 0) 71 | fprint(stderr, "\n"); 72 | } 73 | /* fatal - issue fatal error message and exit */ 74 | int fatal(const char *name, const char *fmt, int n) { 75 | print("\n"); 76 | errcnt = -1; 77 | error("compiler error in %s--", name); 78 | fprint(stderr, fmt, n); 79 | exit(EXIT_FAILURE); 80 | return 0; 81 | } 82 | 83 | /* printtoken - print current token preceeded by a space */ 84 | static void printtoken(void) { 85 | switch (t) { 86 | case ID: fprint(stderr, " `%s'", token); break; 87 | case ICON: 88 | fprint(stderr, " `%s'", vtoa(tsym->type, tsym->u.c.v)); 89 | break; 90 | case SCON: { 91 | int i, n; 92 | if (ischar(tsym->type->type)) { 93 | char *s = tsym->u.c.v.p; 94 | n = tsym->type->size; 95 | fprint(stderr, " \""); 96 | for (i = 0; i < 20 && i < n && *s; s++, i++) 97 | if (*s < ' ' || *s >= 0177) 98 | fprint(stderr, "\\%o", *s); 99 | else 100 | fprint(stderr, "%c", *s); 101 | } else { /* wchar_t string */ 102 | unsigned int *s = tsym->u.c.v.p; 103 | assert(tsym->type->type->size == widechar->size); 104 | n = tsym->type->size/widechar->size; 105 | fprint(stderr, " L\""); 106 | for (i = 0; i < 20 && i < n && *s; s++, i++) 107 | if (*s < ' ' || *s >= 0177) 108 | fprint(stderr, "\\x%x", *s); 109 | else 110 | fprint(stderr, "%c", *s); 111 | } 112 | if (i < n) 113 | fprint(stderr, " ..."); 114 | else 115 | fprint(stderr, "\""); 116 | break; 117 | } 118 | case FCON: 119 | fprint(stderr, " `%S'", token, (char*)cp - token); 120 | break; 121 | case '`': case '\'': fprint(stderr, " \"%k\"", t); break; 122 | default: fprint(stderr, " `%k'", t); 123 | } 124 | } 125 | 126 | /* warning - issue warning error message */ 127 | void warning(const char *fmt, ...) { 128 | va_list ap; 129 | 130 | va_start(ap, fmt); 131 | if (wflag == 0) { 132 | errcnt--; 133 | error("warning: "); 134 | vfprint(stderr, NULL, fmt, ap); 135 | } 136 | va_end(ap); 137 | } 138 | -------------------------------------------------------------------------------- /tools/rcc/event.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | struct entry { 5 | Apply func; 6 | void *cl; 7 | }; 8 | 9 | Events events; 10 | void attach(Apply func, void *cl, List *list) { 11 | struct entry *p; 12 | 13 | NEW(p, PERM); 14 | p->func = func; 15 | p->cl = cl; 16 | *list = append(p, *list); 17 | } 18 | void apply(List event, void *arg1, void *arg2) { 19 | if (event) { 20 | List lp = event; 21 | do { 22 | struct entry *p = lp->x; 23 | (*p->func)(p->cl, arg1, arg2); 24 | lp = lp->link; 25 | } while (lp != event); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tools/rcc/inits.c: -------------------------------------------------------------------------------- 1 | void init(int argc, char *argv[]) { 2 | {extern void input_init(int, char *[]); input_init(argc, argv);} 3 | {extern void main_init(int, char *[]); main_init(argc, argv);} 4 | {extern void prof_init(int, char *[]); prof_init(argc, argv);} 5 | {extern void trace_init(int, char *[]); trace_init(argc, argv);} 6 | {extern void type_init(int, char *[]); type_init(argc, argv);} 7 | } 8 | -------------------------------------------------------------------------------- /tools/rcc/input.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | static void pragma(void); 5 | static void resynch(void); 6 | 7 | static int bsize; 8 | static unsigned char buffer[MAXLINE+1 + BUFSIZE+1]; 9 | unsigned char *cp; /* current input character */ 10 | char *file; /* current input file name */ 11 | char *firstfile; /* first input file */ 12 | unsigned char *limit; /* points to last character + 1 */ 13 | char *line; /* current line */ 14 | int lineno; /* line number of current line */ 15 | 16 | void nextline(void) { 17 | do { 18 | if (cp >= limit) { 19 | fillbuf(); 20 | if (cp >= limit) 21 | cp = limit; 22 | if (cp == limit) 23 | return; 24 | } else { 25 | lineno++; 26 | for (line = (char *)cp; *cp==' ' || *cp=='\t'; cp++) 27 | ; 28 | if (*cp == '#') { 29 | resynch(); 30 | nextline(); 31 | } 32 | } 33 | } while (*cp == '\n' && cp == limit); 34 | } 35 | void fillbuf(void) { 36 | if (bsize == 0) 37 | return; 38 | if (cp >= limit) 39 | cp = &buffer[MAXLINE+1]; 40 | else 41 | { 42 | int n = limit - cp; 43 | unsigned char *s = &buffer[MAXLINE+1] - n; 44 | assert(s >= buffer); 45 | line = (char *)s - ((char *)cp - line); 46 | while (cp < limit) 47 | *s++ = *cp++; 48 | cp = &buffer[MAXLINE+1] - n; 49 | } 50 | if (feof(stdin)) 51 | bsize = 0; 52 | else 53 | bsize = fread(&buffer[MAXLINE+1], 1, BUFSIZE, stdin); 54 | if (bsize < 0) { 55 | error("read error\n"); 56 | exit(EXIT_FAILURE); 57 | } 58 | limit = &buffer[MAXLINE+1+bsize]; 59 | *limit = '\n'; 60 | } 61 | void input_init(int argc, char *argv[]) { 62 | static int inited; 63 | 64 | if (inited) 65 | return; 66 | inited = 1; 67 | main_init(argc, argv); 68 | limit = cp = &buffer[MAXLINE+1]; 69 | bsize = -1; 70 | lineno = 0; 71 | file = NULL; 72 | fillbuf(); 73 | if (cp >= limit) 74 | cp = limit; 75 | nextline(); 76 | } 77 | 78 | /* pragma - handle #pragma ref id... */ 79 | static void pragma(void) { 80 | if ((t = gettok()) == ID && strcmp(token, "ref") == 0) 81 | for (;;) { 82 | while (*cp == ' ' || *cp == '\t') 83 | cp++; 84 | if (*cp == '\n' || *cp == 0) 85 | break; 86 | if ((t = gettok()) == ID && tsym) { 87 | tsym->ref++; 88 | use(tsym, src); 89 | } 90 | } 91 | } 92 | 93 | /* resynch - set line number/file name in # n [ "file" ] and #pragma ... */ 94 | static void resynch(void) { 95 | for (cp++; *cp == ' ' || *cp == '\t'; ) 96 | cp++; 97 | if (limit - cp < MAXLINE) 98 | fillbuf(); 99 | if (strncmp((char *)cp, "pragma", 6) == 0) { 100 | cp += 6; 101 | pragma(); 102 | } else if (*cp >= '0' && *cp <= '9') { 103 | line: for (lineno = 0; *cp >= '0' && *cp <= '9'; ) 104 | lineno = 10*lineno + *cp++ - '0'; 105 | lineno--; 106 | while (*cp == ' ' || *cp == '\t') 107 | cp++; 108 | if (*cp == '"') { 109 | file = (char *)++cp; 110 | while (*cp && *cp != '"' && *cp != '\n') 111 | cp++; 112 | file = stringn(file, (char *)cp - file); 113 | if (*cp == '\n') 114 | warning("missing \" in preprocessor line\n"); 115 | if (firstfile == 0) 116 | firstfile = file; 117 | } 118 | } else if (strncmp((char *)cp, "line", 4) == 0) { 119 | for (cp += 4; *cp == ' ' || *cp == '\t'; ) 120 | cp++; 121 | if (*cp >= '0' && *cp <= '9') 122 | goto line; 123 | if (Aflag >= 2) 124 | warning("unrecognized control line\n"); 125 | } else if (Aflag >= 2 && *cp != '\n') 126 | warning("unrecognized control line\n"); 127 | while (*cp) 128 | if (*cp++ == '\n') { 129 | if (cp == limit + 1) 130 | nextline(); 131 | else 132 | break; 133 | } 134 | } 135 | 136 | -------------------------------------------------------------------------------- /tools/rcc/list.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | static List freenodes; /* free list nodes */ 5 | 6 | /* append - append x to list, return new list */ 7 | List append(void *x, List list) { 8 | List new; 9 | 10 | if ((new = freenodes) != NULL) 11 | freenodes = freenodes->link; 12 | else 13 | NEW(new, PERM); 14 | if (list) { 15 | new->link = list->link; 16 | list->link = new; 17 | } else 18 | new->link = new; 19 | new->x = x; 20 | return new; 21 | } 22 | 23 | /* length - # elements in list */ 24 | int length(List list) { 25 | int n = 0; 26 | 27 | if (list) { 28 | List lp = list; 29 | do 30 | n++; 31 | while ((lp = lp->link) != list); 32 | } 33 | return n; 34 | } 35 | 36 | /* ltov - convert list to a NULL-terminated vector allocated in arena */ 37 | void *ltov(List *list, unsigned arena) { 38 | int i = 0; 39 | void **array = newarray(length(*list) + 1, sizeof array[0], arena); 40 | 41 | if (*list) { 42 | List lp = *list; 43 | do { 44 | lp = lp->link; 45 | array[i++] = lp->x; 46 | } while (lp != *list); 47 | #ifndef PURIFY 48 | lp = (*list)->link; 49 | (*list)->link = freenodes; 50 | freenodes = lp; 51 | #endif 52 | } 53 | *list = NULL; 54 | array[i] = NULL; 55 | return array; 56 | } 57 | -------------------------------------------------------------------------------- /tools/rcc/null.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | #define I(f) null_##f 3 | 4 | static Node I(gen)(Node p) { return p; } 5 | static void I(address)(Symbol q, Symbol p, long n) {} 6 | static void I(blockbeg)(Env *e) {} 7 | static void I(blockend)(Env *e) {} 8 | static void I(defaddress)(Symbol p) {} 9 | static void I(defconst)(int suffix, int size, Value v) {} 10 | static void I(defstring)(int len, char *s) {} 11 | static void I(defsymbol)(Symbol p) {} 12 | static void I(emit)(Node p) {} 13 | static void I(export)(Symbol p) {} 14 | static void I(function)(Symbol f, Symbol caller[], Symbol callee[], int ncalls) {} 15 | static void I(global)(Symbol p) {} 16 | static void I(import)(Symbol p) {} 17 | static void I(local)(Symbol p) {} 18 | static void I(progbeg)(int argc, char *argv[]) {} 19 | static void I(progend)(void) {} 20 | static void I(segment)(int s) {} 21 | static void I(space)(int n) {} 22 | static void I(stabblock)(int brace, int lev, Symbol *p) {} 23 | static void I(stabend)(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {} 24 | static void I(stabfend)(Symbol p, int lineno) {} 25 | static void I(stabinit)(char *file, int argc, char *argv[]) {} 26 | static void I(stabline)(Coordinate *cp) {} 27 | static void I(stabsym)(Symbol p) {} 28 | static void I(stabtype)(Symbol p) {} 29 | 30 | 31 | Interface nullIR = { 32 | {1, 1, 0}, /* char */ 33 | {2, 2, 0}, /* short */ 34 | {4, 4, 0}, /* int */ 35 | {8, 8, 1}, /* long */ 36 | {8 ,8, 1}, /* long long */ 37 | {4, 4, 1}, /* float */ 38 | {8, 8, 1}, /* double */ 39 | {16,16,1}, /* long double */ 40 | {4, 4, 0}, /* T* */ 41 | {0, 4, 0}, /* struct */ 42 | 1, /* little_endian */ 43 | 0, /* mulops_calls */ 44 | 0, /* wants_callb */ 45 | 0, /* wants_argb */ 46 | 1, /* left_to_right */ 47 | 0, /* wants_dag */ 48 | 0, /* unsigned_char */ 49 | I(address), 50 | I(blockbeg), 51 | I(blockend), 52 | I(defaddress), 53 | I(defconst), 54 | I(defstring), 55 | I(defsymbol), 56 | I(emit), 57 | I(export), 58 | I(function), 59 | I(gen), 60 | I(global), 61 | I(import), 62 | I(local), 63 | I(progbeg), 64 | I(progend), 65 | I(segment), 66 | I(space), 67 | I(stabblock), 68 | I(stabend), 69 | I(stabfend), 70 | I(stabinit), 71 | I(stabline), 72 | I(stabsym), 73 | I(stabtype) 74 | }; 75 | -------------------------------------------------------------------------------- /tools/rcc/output.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | static char *outs(const char *str, FILE *f, char *bp) { 5 | if (f) 6 | fputs(str, f); 7 | else 8 | while ((*bp = *str++)) 9 | bp++; 10 | return bp; 11 | } 12 | 13 | static char *outd(long n, FILE *f, char *bp) { 14 | unsigned long m; 15 | char buf[25], *s = buf + sizeof buf; 16 | 17 | *--s = '\0'; 18 | if (n < 0) 19 | m = -n; 20 | else 21 | m = n; 22 | do 23 | *--s = m%10 + '0'; 24 | while ((m /= 10) != 0); 25 | if (n < 0) 26 | *--s = '-'; 27 | return outs(s, f, bp); 28 | } 29 | 30 | static char *outu(unsigned long n, int base, FILE *f, char *bp) { 31 | char buf[25], *s = buf + sizeof buf; 32 | 33 | *--s = '\0'; 34 | do 35 | *--s = "0123456789abcdef"[n%base]; 36 | while ((n /= base) != 0); 37 | return outs(s, f, bp); 38 | } 39 | void print(const char *fmt, ...) { 40 | va_list ap; 41 | 42 | va_start(ap, fmt); 43 | vfprint(stdout, NULL, fmt, ap); 44 | va_end(ap); 45 | } 46 | /* fprint - formatted output to f */ 47 | void fprint(FILE *f, const char *fmt, ...) { 48 | va_list ap; 49 | 50 | va_start(ap, fmt); 51 | vfprint(f, NULL, fmt, ap); 52 | va_end(ap); 53 | } 54 | 55 | /* stringf - formatted output to a saved string */ 56 | char *stringf(const char *fmt, ...) { 57 | char buf[1024]; 58 | va_list ap; 59 | 60 | va_start(ap, fmt); 61 | vfprint(NULL, buf, fmt, ap); 62 | va_end(ap); 63 | return string(buf); 64 | } 65 | 66 | /* vfprint - formatted output to f or string bp */ 67 | void vfprint(FILE *f, char *bp, const char *fmt, va_list ap) { 68 | for (; *fmt; fmt++) 69 | if (*fmt == '%') 70 | switch (*++fmt) { 71 | case 'd': bp = outd(va_arg(ap, int), f, bp); break; 72 | case 'D': bp = outd(va_arg(ap, long), f, bp); break; 73 | case 'U': bp = outu(va_arg(ap, unsigned long), 10, f, bp); break; 74 | case 'u': bp = outu(va_arg(ap, unsigned), 10, f, bp); break; 75 | case 'o': bp = outu(va_arg(ap, unsigned), 8, f, bp); break; 76 | case 'X': bp = outu(va_arg(ap, unsigned long), 16, f, bp); break; 77 | case 'x': bp = outu(va_arg(ap, unsigned), 16, f, bp); break; 78 | case 'f': case 'e': 79 | case 'g': { 80 | static char format[] = "%f"; 81 | char buf[128]; 82 | format[1] = *fmt; 83 | sprintf(buf, format, va_arg(ap, double)); 84 | bp = outs(buf, f, bp); 85 | } 86 | ; break; 87 | case 's': bp = outs(va_arg(ap, char *), f, bp); break; 88 | case 'p': { 89 | void *p = va_arg(ap, void *); 90 | if (p) 91 | bp = outs("0x", f, bp); 92 | bp = outu((unsigned long)p, 16, f, bp); 93 | break; 94 | } 95 | case 'c': if (f) fputc(va_arg(ap, int), f); else *bp++ = va_arg(ap, int); break; 96 | case 'S': { char *s = va_arg(ap, char *); 97 | int n = va_arg(ap, int); 98 | if (s) { 99 | for ( ; n-- > 0; s++) 100 | if (f) (void)putc(*s, f); else *bp++ = *s; 101 | } 102 | } break; 103 | case 'k': { int t = va_arg(ap, int); 104 | static char *tokens[] = { 105 | #define xx(a,b,c,d,e,f,g) g, 106 | #define yy(a,b,c,d,e,f,g) g, 107 | #include "token.h" 108 | }; 109 | assert(tokens[t&0177]); 110 | bp = outs(tokens[t&0177], f, bp); 111 | } break; 112 | case 't': { Type ty = va_arg(ap, Type); 113 | assert(f); 114 | outtype(ty ? ty : voidtype, f); 115 | } break; 116 | case 'w': { Coordinate *p = va_arg(ap, Coordinate *); 117 | if (p->file && *p->file) { 118 | bp = outs(p->file, f, bp); 119 | bp = outs(":", f, bp); 120 | } 121 | bp = outd(p->y, f, bp); 122 | } break; 123 | case 'I': { int n = va_arg(ap, int); 124 | while (--n >= 0) 125 | if (f) (void)putc(' ', f); else *bp++ = ' '; 126 | } break; 127 | default: if (f) (void)putc(*fmt, f); else *bp++ = *fmt; break; 128 | } 129 | else if (f) 130 | (void)putc(*fmt, f); 131 | else 132 | *bp++ = *fmt; 133 | if (!f) 134 | *bp = '\0'; 135 | } 136 | -------------------------------------------------------------------------------- /tools/rcc/string.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | static struct string { 5 | char *str; 6 | int len; 7 | struct string *link; 8 | } *buckets[1024]; 9 | static int scatter[] = { /* map characters to random values */ 10 | 2078917053, 143302914, 1027100827, 1953210302, 755253631, 11 | 2002600785, 1405390230, 45248011, 1099951567, 433832350, 12 | 2018585307, 438263339, 813528929, 1703199216, 618906479, 13 | 573714703, 766270699, 275680090, 1510320440, 1583583926, 14 | 1723401032, 1965443329, 1098183682, 1636505764, 980071615, 15 | 1011597961, 643279273, 1315461275, 157584038, 1069844923, 16 | 471560540, 89017443, 1213147837, 1498661368, 2042227746, 17 | 1968401469, 1353778505, 1300134328, 2013649480, 306246424, 18 | 1733966678, 1884751139, 744509763, 400011959, 1440466707, 19 | 1363416242, 973726663, 59253759, 1639096332, 336563455, 20 | 1642837685, 1215013716, 154523136, 593537720, 704035832, 21 | 1134594751, 1605135681, 1347315106, 302572379, 1762719719, 22 | 269676381, 774132919, 1851737163, 1482824219, 125310639, 23 | 1746481261, 1303742040, 1479089144, 899131941, 1169907872, 24 | 1785335569, 485614972, 907175364, 382361684, 885626931, 25 | 200158423, 1745777927, 1859353594, 259412182, 1237390611, 26 | 48433401, 1902249868, 304920680, 202956538, 348303940, 27 | 1008956512, 1337551289, 1953439621, 208787970, 1640123668, 28 | 1568675693, 478464352, 266772940, 1272929208, 1961288571, 29 | 392083579, 871926821, 1117546963, 1871172724, 1771058762, 30 | 139971187, 1509024645, 109190086, 1047146551, 1891386329, 31 | 994817018, 1247304975, 1489680608, 706686964, 1506717157, 32 | 579587572, 755120366, 1261483377, 884508252, 958076904, 33 | 1609787317, 1893464764, 148144545, 1415743291, 2102252735, 34 | 1788268214, 836935336, 433233439, 2055041154, 2109864544, 35 | 247038362, 299641085, 834307717, 1364585325, 23330161, 36 | 457882831, 1504556512, 1532354806, 567072918, 404219416, 37 | 1276257488, 1561889936, 1651524391, 618454448, 121093252, 38 | 1010757900, 1198042020, 876213618, 124757630, 2082550272, 39 | 1834290522, 1734544947, 1828531389, 1982435068, 1002804590, 40 | 1783300476, 1623219634, 1839739926, 69050267, 1530777140, 41 | 1802120822, 316088629, 1830418225, 488944891, 1680673954, 42 | 1853748387, 946827723, 1037746818, 1238619545, 1513900641, 43 | 1441966234, 367393385, 928306929, 946006977, 985847834, 44 | 1049400181, 1956764878, 36406206, 1925613800, 2081522508, 45 | 2118956479, 1612420674, 1668583807, 1800004220, 1447372094, 46 | 523904750, 1435821048, 923108080, 216161028, 1504871315, 47 | 306401572, 2018281851, 1820959944, 2136819798, 359743094, 48 | 1354150250, 1843084537, 1306570817, 244413420, 934220434, 49 | 672987810, 1686379655, 1301613820, 1601294739, 484902984, 50 | 139978006, 503211273, 294184214, 176384212, 281341425, 51 | 228223074, 147857043, 1893762099, 1896806882, 1947861263, 52 | 1193650546, 273227984, 1236198663, 2116758626, 489389012, 53 | 593586330, 275676551, 360187215, 267062626, 265012701, 54 | 719930310, 1621212876, 2108097238, 2026501127, 1865626297, 55 | 894834024, 552005290, 1404522304, 48964196, 5816381, 56 | 1889425288, 188942202, 509027654, 36125855, 365326415, 57 | 790369079, 264348929, 513183458, 536647531, 13672163, 58 | 313561074, 1730298077, 286900147, 1549759737, 1699573055, 59 | 776289160, 2143346068, 1975249606, 1136476375, 262925046, 60 | 92778659, 1856406685, 1884137923, 53392249, 1735424165, 61 | 1602280572 62 | }; 63 | char *string(const char *str) { 64 | const char *s; 65 | 66 | for (s = str; *s; s++) 67 | ; 68 | return stringn(str, s - str); 69 | } 70 | char *stringd(long n) { 71 | char str[25], *s = str + sizeof (str); 72 | unsigned long m; 73 | 74 | if (n == LONG_MIN) 75 | m = (unsigned long)LONG_MAX + 1; 76 | else if (n < 0) 77 | m = -n; 78 | else 79 | m = n; 80 | do 81 | *--s = m%10 + '0'; 82 | while ((m /= 10) != 0); 83 | if (n < 0) 84 | *--s = '-'; 85 | return stringn(s, str + sizeof (str) - s); 86 | } 87 | char *stringn(const char *str, int len) { 88 | int i; 89 | unsigned int h; 90 | const char *end; 91 | struct string *p; 92 | 93 | assert(str); 94 | for (h = 0, i = len, end = str; i > 0; i--) 95 | h = (h<<1) + scatter[*(unsigned char *)end++]; 96 | h &= NELEMS(buckets)-1; 97 | for (p = buckets[h]; p; p = p->link) 98 | if (len == p->len) { 99 | const char *s1 = str; 100 | char *s2 = p->str; 101 | do { 102 | if (s1 == end) 103 | return p->str; 104 | } while (*s1++ == *s2++); 105 | } 106 | { 107 | static char *next, *strlimit; 108 | if (len + 1 >= strlimit - next) { 109 | int n = len + 4*1024; 110 | next = allocate(n, PERM); 111 | strlimit = next + n; 112 | } 113 | NEW(p, PERM); 114 | p->len = len; 115 | for (p->str = next; str < end; ) 116 | *next++ = *str++; 117 | *next++ = 0; 118 | p->link = buckets[h]; 119 | buckets[h] = p; 120 | return p->str; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /tools/rcc/trace.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | 4 | static char *fmt, *fp, *fmtend; /* format string, current & limit pointer */ 5 | static Tree args; /* printf arguments */ 6 | static Symbol frameno; /* local holding frame number */ 7 | 8 | /* appendstr - append str to the evolving format string, expanding it if necessary */ 9 | static void appendstr(char *str) { 10 | do 11 | if (fp == fmtend) { 12 | if (fp) { 13 | char *s = allocate(2*(fmtend - fmt), FUNC); 14 | strncpy(s, fmt, fmtend - fmt); 15 | fp = s + (fmtend - fmt); 16 | fmtend = s + 2*(fmtend - fmt); 17 | fmt = s; 18 | } else { 19 | fp = fmt = allocate(80, FUNC); 20 | fmtend = fmt + 80; 21 | } 22 | } 23 | while ((*fp++ = *str++) != 0); 24 | fp--; 25 | } 26 | 27 | /* tracevalue - append format and argument to print the value of e */ 28 | static void tracevalue(Tree e, int lev) { 29 | Type ty = unqual(e->type); 30 | 31 | switch (ty->op) { 32 | case INT: 33 | if (ty == chartype || ty == signedchar) 34 | appendstr("'\\x%02x'"); 35 | else if (ty == longtype) 36 | appendstr("0x%ld"); 37 | else 38 | appendstr("0x%d"); 39 | break; 40 | case UNSIGNED: 41 | if (ty == chartype || ty == unsignedchar) 42 | appendstr("'\\x%02x'"); 43 | else if (ty == unsignedlong) 44 | appendstr("0x%lx"); 45 | else 46 | appendstr("0x%x"); 47 | break; 48 | case FLOAT: 49 | if (ty == longdouble) 50 | appendstr("%Lg"); 51 | else 52 | appendstr("%g"); 53 | break; 54 | case POINTER: 55 | if (unqual(ty->type) == chartype 56 | || unqual(ty->type) == signedchar 57 | || unqual(ty->type) == unsignedchar) { 58 | static Symbol null; 59 | if (null == NULL) 60 | null = mkstr("(null)"); 61 | tracevalue(cast(e, unsignedtype), lev + 1); 62 | appendstr(" \"%.30s\""); 63 | e = condtree(e, e, pointer(idtree(null->u.c.loc))); 64 | } else { 65 | appendstr("("); appendstr(typestring(ty, "")); appendstr(")0x%x"); 66 | } 67 | break; 68 | case STRUCT: { 69 | Field q; 70 | appendstr("("); appendstr(typestring(ty, "")); appendstr("){"); 71 | for (q = ty->u.sym->u.s.flist; q; q = q->link) { 72 | appendstr(q->name); appendstr("="); 73 | tracevalue(field(addrof(e), q->name), lev + 1); 74 | if (q->link) 75 | appendstr(","); 76 | } 77 | appendstr("}"); 78 | return; 79 | } 80 | case UNION: 81 | appendstr("("); appendstr(typestring(ty, "")); appendstr("){...}"); 82 | return; 83 | case ARRAY: 84 | if (lev && ty->type->size > 0) { 85 | int i; 86 | e = pointer(e); 87 | appendstr("{"); 88 | for (i = 0; i < ty->size/ty->type->size; i++) { 89 | Tree p = (*optree['+'])(ADD, e, consttree(i, inttype)); 90 | if (isptr(p->type) && isarray(p->type->type)) 91 | p = retype(p, p->type->type); 92 | else 93 | p = rvalue(p); 94 | if (i) 95 | appendstr(","); 96 | tracevalue(p, lev + 1); 97 | } 98 | appendstr("}"); 99 | } else 100 | appendstr(typestring(ty, "")); 101 | return; 102 | default: 103 | assert(0); 104 | } 105 | e = cast(e, promote(ty)); 106 | args = tree(mkop(ARG,e->type), e->type, e, args); 107 | } 108 | 109 | /* tracefinis - complete & generate the trace call to print */ 110 | static void tracefinis(Symbol printer) { 111 | Tree *ap; 112 | Symbol p; 113 | 114 | *fp = 0; 115 | p = mkstr(string(fmt)); 116 | for (ap = &args; *ap; ap = &(*ap)->kids[1]) 117 | ; 118 | *ap = tree(ARG+P, charptype, pointer(idtree(p->u.c.loc)), 0); 119 | walk(calltree(pointer(idtree(printer)), freturn(printer->type), args, NULL), 0, 0); 120 | args = 0; 121 | fp = fmtend = 0; 122 | } 123 | 124 | /* tracecall - generate code to trace entry to f */ 125 | static void tracecall(Symbol printer, Symbol f) { 126 | int i; 127 | Symbol counter = genident(STATIC, inttype, GLOBAL); 128 | 129 | defglobal(counter, BSS); 130 | (*IR->space)(counter->type->size); 131 | frameno = genident(AUTO, inttype, level); 132 | addlocal(frameno); 133 | appendstr(f->name); appendstr("#"); 134 | tracevalue(asgn(frameno, incr(INCR, idtree(counter), consttree(1, inttype))), 0); 135 | appendstr("("); 136 | for (i = 0; f->u.f.callee[i]; i++) { 137 | if (i) 138 | appendstr(","); 139 | appendstr(f->u.f.callee[i]->name); appendstr("="); 140 | tracevalue(idtree(f->u.f.callee[i]), 0); 141 | } 142 | if (variadic(f->type)) 143 | appendstr(",..."); 144 | appendstr(") called\n"); 145 | tracefinis(printer); 146 | } 147 | 148 | /* tracereturn - generate code to trace return e */ 149 | static void tracereturn(Symbol printer, Symbol f, Tree e) { 150 | appendstr(f->name); appendstr("#"); 151 | tracevalue(idtree(frameno), 0); 152 | appendstr(" returned"); 153 | if (freturn(f->type) != voidtype && e) { 154 | appendstr(" "); 155 | tracevalue(e, 0); 156 | } 157 | appendstr("\n"); 158 | tracefinis(printer); 159 | } 160 | 161 | /* trace_init - initialize for tracing */ 162 | void trace_init(int argc, char *argv[]) { 163 | int i; 164 | static int inited; 165 | 166 | if (inited) 167 | return; 168 | inited = 1; 169 | type_init(argc, argv); 170 | if (IR) 171 | for (i = 1; i < argc; i++) 172 | if (strncmp(argv[i], "-t", 2) == 0 && strchr(argv[i], '=') == NULL) { 173 | Symbol printer = mksymbol(EXTERN, 174 | argv[i][2] ? &argv[i][2] : "printf", 175 | ftype(inttype, ptr(qual(CONST, chartype)))); 176 | printer->defined = 0; 177 | attach((Apply)tracecall, printer, &events.entry); 178 | attach((Apply)tracereturn, printer, &events.returns); 179 | break; 180 | } 181 | } 182 | --------------------------------------------------------------------------------