From 517517a1bb6afb0e4740aa8748cb11a288c73b5c Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sat, 24 Jun 2017 09:20:54 +0000 Subject: [PATCH] CON: Add getclosestcol command, which finds the closest palette index given getclosestcol is encoded the same as PROJ_FLASH_COLOR. is the index of the last palette color that should be considered. Use 255 for the whole palette, 254 to exclude the transparent color, 239 to exclude Duke 3D's fullbrights, etc. git-svn-id: https://svn.eduke32.com/eduke32@6259 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gamedef.cpp | 2 ++ source/duke3d/src/gamedef.h | 1 + source/duke3d/src/gameexec.cpp | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 51f3215f6..93a0ecaf9 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -574,6 +574,7 @@ const char *keyw[] = "divscale", // 400 "scalevar", // 401 "undefinegamefunc", // 402 + "getclosestcol", // 403 "" }; #endif @@ -4078,6 +4079,7 @@ DO_DEFSTATE: continue; case CON_CLAMP: + case CON_GETCLOSESTCOL: C_GetNextVarType(GAMEVAR_READONLY); C_GetManyVars(2); continue; diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index 565c8761f..ebc46cf0f 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -1136,6 +1136,7 @@ enum ScriptKeywords_t CON_DIVSCALE, // 400 CON_SCALEVAR, // 401 CON_UNDEFINEGAMEFUNC, // 402 + CON_GETCLOSESTCOL, // 403 CON_END }; // KEEPINSYNC with the keyword list in lunatic/con_lang.lua diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 8b8beb4b0..4287a96d9 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -4890,6 +4890,15 @@ finish_qsprintf: } continue; + case CON_GETCLOSESTCOL: + insptr++; + { + tw = *insptr++; + int32_t const rgb = Gv_GetVarX(*insptr++); + Gv_SetVarX(tw, getclosestcol_lim(rgb & 0xFF, (rgb >> 8) & 0xFF, (rgb >> 16) & 0xFF, Gv_GetVarX(*insptr++))); + } + continue; + case CON_INV: if ((aGameVars[*(insptr + 1)].flags & (GAMEVAR_USER_MASK | GAMEVAR_PTR_MASK)) == 0) aGameVars[*(insptr + 1)].global = -aGameVars[*(insptr + 1)].global;