From f67f93580790e5047322c3b261615dcb051cabe8 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 7 Oct 2018 05:23:05 +0000 Subject: [PATCH] Fix some weirdness in osdcmd_setactorvar() and remove an unused counter var from osdcmd_map() git-svn-id: https://svn.eduke32.com/eduke32@7037 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/osdcmds.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/source/duke3d/src/osdcmds.cpp b/source/duke3d/src/osdcmds.cpp index bd0b9d747..88e9a3a16 100644 --- a/source/duke3d/src/osdcmds.cpp +++ b/source/duke3d/src/osdcmds.cpp @@ -185,14 +185,13 @@ static int32_t osdcmd_map(osdfuncparm_t const * const parm) if (maxwidth > 0) { - int32_t x = 0, count = 0; + int32_t x = 0; maxwidth += 3; OSD_Printf(OSDTEXT_RED "Map listing:\n"); for (r=fnlist.findfiles; r; r=r->next) { OSD_Printf("%-*s",maxwidth,r->name); x += maxwidth; - count++; if (x > OSD_GetCols() - maxwidth) { x = 0; @@ -641,9 +640,6 @@ static int32_t osdcmd_addlogvar(osdfuncparm_t const * const parm) static int32_t osdcmd_setactorvar(osdfuncparm_t const * const parm) { - int32_t i, varval, ID; - char varname[256]; - if (parm->numparms != 3) return OSDCMD_SHOWHELP; if (numplayers > 1) @@ -652,24 +648,26 @@ static int32_t osdcmd_setactorvar(osdfuncparm_t const * const parm) return OSDCMD_OK; } - ID=Batol(parm->parms[0]); - if (ID>=MAXSPRITES) + int32_t spriteNum = Batol(parm->parms[0]); + + if ((unsigned)spriteNum >= MAXSPRITES) { OSD_Printf("Invalid sprite ID\n"); return OSDCMD_OK; } - varval = Batol(parm->parms[2]); - strcpy(varname,parm->parms[2]); - varval = Batol(varname); - i = hash_find(&h_gamevars,varname); - if (i >= 0) - varval=Gv_GetVar(i, g_player[screenpeek].ps->i, screenpeek); + // get value to set + char varname[MAXVARLABEL]; + strcpy(varname, parm->parms[2]); - strcpy(varname,parm->parms[1]); - i = hash_find(&h_gamevars,varname); + int32_t i = hash_find(&h_gamevars, varname); + int32_t const newValue = (i >= 0) ? Gv_GetVar(i, g_player[screenpeek].ps->i, screenpeek) : Batol(varname); + + strcpy(varname, parm->parms[1]); + i = hash_find(&h_gamevars, varname); if (i >= 0) - Gv_SetVar(i, varval, ID, -1); + Gv_SetVar(i, newValue, spriteNum, -1); + return OSDCMD_OK; } #else