From ed38f0a75d8eb56c5cf0c92a8da22dea1cfb286d Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Thu, 15 Mar 2018 01:19:27 +0000 Subject: [PATCH] CON: Add gettiledata/settiledata. Same members as tiledata[] quick access struct. Not all fields writable. Patch from Striker. git-svn-id: https://svn.eduke32.com/eduke32@6766 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gamedef.cpp | 17 +++++++++++++++++ source/duke3d/src/gamedef.h | 2 ++ source/duke3d/src/gameexec.cpp | 20 ++++++++++++++++++++ source/duke3d/src/gamestructures.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 8459510ac..4df2a1229 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -236,6 +236,7 @@ static tokenmap_t const vm_keywords[] = { "gettexturefloor", CON_GETTEXTUREFLOOR }, { "getthisprojectile", CON_GETTHISPROJECTILE }, { "getticks", CON_GETTICKS }, + { "gettiledata", CON_GETTILEDATA }, // OldMP compat. { "gettimedate", CON_GETTIMEDATE }, { "gettspr", CON_GETTSPR }, { "getuserdef", CON_GETUSERDEF }, @@ -441,6 +442,7 @@ static tokenmap_t const vm_keywords[] = { "setsector", CON_SETSECTOR }, { "setsprite", CON_SETSPRITE }, { "setthisprojectile", CON_SETTHISPROJECTILE }, + { "settiledata", CON_SETTILEDATA }, { "settspr", CON_SETTSPR }, { "setuserdef", CON_SETUSERDEF }, { "setvar", CON_SETVAR }, @@ -3952,6 +3954,21 @@ DO_DEFSTATE: continue; } + case CON_SETTILEDATA: + case CON_GETTILEDATA: + { + int32_t const labelNum = C_GetStructureIndexes(0, &h_tiledata); + + if (labelNum == -1) + continue; + + BITPTR_CLEAR(g_scriptPtr - apScript); + *g_scriptPtr++ = TileDataLabels[labelNum].lId; + + C_GetNextVarType((tw == CON_GETTILEDATA) ? GAMEVAR_READONLY : 0); + continue; + } + case CON_SETUSERDEF: case CON_GETUSERDEF: { diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index 4e210cdf2..900e94b08 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -1245,6 +1245,8 @@ enum ScriptKeywords_t CON_UNDEFINECHEAT, // 424 CON_SHOWVIEWQ16, // 425 CON_SHOWVIEWQ16UNBIASED,// 426 + CON_GETTILEDATA, // 427 + CON_SETTILEDATA, // 428 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 502146428..210768984 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -4244,6 +4244,26 @@ finish_qsprintf: continue; } + case CON_GETTILEDATA: + insptr++; + { + int const tileNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(*(insptr - 1)) : vm.pSprite->picnum; + int const labelNum = *insptr++; + + Gv_SetVarX(*insptr++, VM_GetTileData(tileNum, labelNum)); + continue; + } + + case CON_SETTILEDATA: + insptr++; + { + int const tileNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(*(insptr - 1)) : vm.pSprite->picnum; + int const labelNum = *insptr++; + + VM_SetTileData(tileNum, labelNum, Gv_GetVarX(*insptr++)); + continue; + } + case CON_SETUSERDEF: insptr++; { diff --git a/source/duke3d/src/gamestructures.cpp b/source/duke3d/src/gamestructures.cpp index adf7bcb5a..0b59252a4 100644 --- a/source/duke3d/src/gamestructures.cpp +++ b/source/duke3d/src/gamestructures.cpp @@ -43,6 +43,7 @@ void __fastcall VM_SetTsprite(int32_t const spriteNum, int32_t const labelNum, i int32_t __fastcall VM_GetProjectile(int32_t const tileNum, int32_t labelNum); void __fastcall VM_SetProjectile(int32_t const tileNum, int32_t const labelNum, int32_t const iSet); int32_t __fastcall VM_GetTileData(int32_t const tileNum, int32_t labelNum); +void __fastcall VM_SetTileData(int32_t const tileNum, int32_t labelNum, int32_t const iSet); int32_t __fastcall VM_GetPalData(int32_t const palNum, int32_t labelNum); #else int32_t __fastcall VM_GetUserdef(int32_t labelNum, int32_t const lParm2) @@ -1517,6 +1518,29 @@ int32_t __fastcall VM_GetTileData(int32_t const tileNum, int32_t labelNum) return labelNum; } +void __fastcall VM_SetTileData(int32_t const tileNum, int32_t labelNum, int32_t iSet) +{ + if (EDUKE32_PREDICT_FALSE((unsigned)tileNum >= MAXTILES)) + { + CON_ERRPRINTF("invalid tile %d\n", tileNum); + return; + } + + switch (labelNum) + { + //case TILEDATA_XSIZE: tilesiz[tileNum].x = iSet; break; + //case TILEDATA_YSIZE: tilesiz[tileNum].y = iSet; break; + + case TILEDATA_ANIMFRAMES: picanm[tileNum].num = iSet; break; + case TILEDATA_XOFFSET: picanm[tileNum].xofs = iSet; break; + case TILEDATA_YOFFSET: picanm[tileNum].yofs = iSet; break; + case TILEDATA_ANIMSPEED: picanm[tileNum].sf = (picanm[tileNum].sf & ~PICANM_ANIMSPEED_MASK) | (iSet & PICANM_ANIMSPEED_MASK); break; + case TILEDATA_ANIMTYPE: picanm[tileNum].sf = (picanm[tileNum].sf & ~PICANM_ANIMTYPE_MASK) | ((iSet << PICANM_ANIMTYPE_SHIFT) & PICANM_ANIMTYPE_MASK); break; + + case TILEDATA_GAMEFLAGS: g_tile[tileNum].flags = iSet; break; + } +} + int32_t __fastcall VM_GetPalData(int32_t const palNum, int32_t labelNum) { if (EDUKE32_PREDICT_FALSE((unsigned)palNum >= MAXPALOOKUPS))