From 3f2c54d9e83e93dbb09be66fb9a778fa50b4d2c7 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 9 Feb 2012 22:43:40 +0000 Subject: [PATCH] Factor out identical (except for params) pieces of code of G_CheatGetInv(). git-svn-id: https://svn.eduke32.com/eduke32@2324 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 82 ++++++++--------------------------- 1 file changed, 19 insertions(+), 63 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 4153012d9..d411e46e1 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -6809,71 +6809,27 @@ enum cheatindex_t CHEAT_COMEGETSOME, }; +static void doinvcheat(int32_t invidx, int32_t defaultnum, int32_t event) +{ + Gv_SetVar(g_iReturnVarID, defaultnum, g_player[myconnectindex].ps->i, myconnectindex); + VM_OnEvent(event, g_player[myconnectindex].ps->i, myconnectindex, -1); + if (aGameVars[g_iReturnVarID].val.lValue >=0) + { + g_player[myconnectindex].ps->inv_amount[invidx] = + aGameVars[g_iReturnVarID].val.lValue; + } +} + static void G_CheatGetInv(void) { - Gv_SetVar(g_iReturnVarID, 400, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETSTEROIDS, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_STEROIDS] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, 1200, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETHEAT, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_HEATS] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, 200, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETBOOT, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_BOOTS] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, 100, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETSHIELD, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_SHIELD] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, 6400, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETSCUBA, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_SCUBA] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, 2400, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETHOLODUKE, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_HOLODUKE] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, 1600, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETJETPACK, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_JETPACK] = - aGameVars[g_iReturnVarID].val.lValue; - } - - Gv_SetVar(g_iReturnVarID, g_player[myconnectindex].ps->max_player_health, g_player[myconnectindex].ps->i, myconnectindex); - VM_OnEvent(EVENT_CHEATGETFIRSTAID, g_player[myconnectindex].ps->i, myconnectindex, -1); - if (aGameVars[g_iReturnVarID].val.lValue >=0) - { - g_player[myconnectindex].ps->inv_amount[GET_FIRSTAID] = - aGameVars[g_iReturnVarID].val.lValue; - } + doinvcheat(GET_STEROIDS, 400, EVENT_CHEATGETSTEROIDS); + doinvcheat(GET_HEATS, 1200, EVENT_CHEATGETHEAT); + doinvcheat(GET_BOOTS, 200, EVENT_CHEATGETBOOT); + doinvcheat(GET_SHIELD, 100, EVENT_CHEATGETSHIELD); + doinvcheat(GET_SCUBA, 6400, EVENT_CHEATGETSCUBA); + doinvcheat(GET_HOLODUKE, 2400, EVENT_CHEATGETHOLODUKE); + doinvcheat(GET_JETPACK, 1600, EVENT_CHEATGETJETPACK); + doinvcheat(GET_FIRSTAID, g_player[myconnectindex].ps->max_player_health, EVENT_CHEATGETFIRSTAID); } static int8_t cheatbuf[MAXCHEATLEN], cheatbuflen;