diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 8639401c7..58b8f75e4 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -176,7 +176,7 @@ void checkavailweapon(struct player_struct* player) SetGameVarID(g_iWeaponVarID, player->curr_weapon, player->GetActor(), snum); // snum is player index! if (player->curr_weapon >= 0) { - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[player->curr_weapon][snum], player->GetActor(), snum); + SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(player->curr_weapon, snum), player->GetActor(), snum); } else { diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index a960bf072..4ff5822ca 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -240,31 +240,7 @@ void addweapon_d(struct player_struct *p, int weapon) } p->okickback_pic = p->kickback_pic = 0; -#ifdef EDUKE - if(p->curr_weapon != weapon) - { - int snum; - snum = p->GetPlayerNum(); - - SetGameVarID(g_iWeaponVarID,weapon, snum, p->GetActor()); - if (p->curr_weapon >= 0) - { - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[weapon][snum], snum, p->GetActor()); - } - else - { - SetGameVarID(g_iWorksLikeVarID, -1, snum, p->GetActor()); - } - SetGameVarID(g_iReturnVarID, 0, snum, -1); - OnEvent(EVENT_CHANGEWEAPON, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, nullptr, snum) == 0) - { - p->curr_weapon = weapon; - } - } -#else p->curr_weapon = weapon; -#endif p->wantweaponfire = -1; switch (weapon) diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index 6aa53b794..ee03db55a 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -197,7 +197,7 @@ const char* GameInterface::GenericCheat(int player, int cheat) case CHT_RHETT: ud.god = 0; - memset(ps[player].gotweapon, 0, MAX_WEAPONS); + memset(ps[player].gotweapon, 0, sizeof(ps[player].gotweapon)); ps[player].curr_weapon = KNEE_WEAPON; ps[player].nocheat = 1; ps[player].GetActor()->s->extra = 1; diff --git a/source/games/duke/src/gamedef.cpp b/source/games/duke/src/gamedef.cpp index ef84b2977..3c8e6c31f 100644 --- a/source/games/duke/src/gamedef.cpp +++ b/source/games/duke/src/gamedef.cpp @@ -3235,8 +3235,7 @@ void loadcons() } // These can only be retrieved AFTER loading the scripts. - InitGameVarPointers(); - ResetSystemDefaults(); + FinalizeGameVars(); S_WorldTourMappingsForOldSounds(); // create a sound mapping for World Tour. S_CacheAllSounds(); comp.setmusic(); diff --git a/source/games/duke/src/gamevar.cpp b/source/games/duke/src/gamevar.cpp index b83a3ec72..7c3778729 100644 --- a/source/games/duke/src/gamevar.cpp +++ b/source/games/duke/src/gamevar.cpp @@ -48,6 +48,7 @@ BEGIN_DUKE_NS MATTGAMEVAR aGameVars[MAXGAMEVARS]; int iGameVarCount; +int numActorVars; extern int errorcount, warningcount, line_count; @@ -71,12 +72,9 @@ void SerializeGameVars(FSerializer &arc) { if (arc.BeginObject(gv.szLabel)) { - arc("value", gv.lValue); - if (gv.dwFlags & (GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_PERACTOR)) - { - arc("array", gv.plArray); - } - arc.EndObject(); + arc("value", gv.lValue) + ("initvalue", gv.initValue) + .EndObject(); } } } @@ -92,13 +90,10 @@ void SerializeGameVars(FSerializer &arc) int AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) { - - int i; - int j; - if (dwFlags & (GAMEVAR_FLAG_PLONG | GAMEVAR_FLAG_PFUNC)) dwFlags |= GAMEVAR_FLAG_SYSTEM; // force system if PLONG + int i; for (i = 0; i < iGameVarCount; i++) { if (strcmp(pszLabel, aGameVars[i].szLabel) == 0) @@ -143,33 +138,12 @@ int AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) aGameVars[i].defaultValue = (int)lValue; } } - + aGameVars[i].initValue = (int)lValue; if (i == iGameVarCount) { // we're adding a new one. iGameVarCount++; } - if (!(aGameVars[i].dwFlags & GAMEVAR_FLAG_SYSTEM)) - { - // only free if not system - aGameVars[i].plArray.Reset(); - } - if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERPLAYER) - { - aGameVars[i].plArray.Resize(MAXPLAYERS); - for (j = 0; j < MAXPLAYERS; j++) - { - aGameVars[i].plArray[j] = (int)lValue; - } - } - else if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR) - { - aGameVars[i].plArray.Resize(MAXSPRITES); - for (j = 0; j < MAXSPRITES; j++) - { - aGameVars[i].plArray[j] = (int)lValue; - } - } return 1; } else @@ -254,17 +228,22 @@ void ResetGameVars(void) { if (!(aGameVars[i].dwFlags & (GAMEVAR_FLAG_PLONG | GAMEVAR_FLAG_PFUNC))) { - if (aGameVars[i].dwFlags & (GAMEVAR_FLAG_PERPLAYER | GAMEVAR_FLAG_PERACTOR)) + if (aGameVars[i].dwFlags & (GAMEVAR_FLAG_PERPLAYER)) { - for (auto& v : aGameVars[i].plArray) + for (auto &pl : ps) { - v = aGameVars[i].defaultValue; + pl.uservars[aGameVars[i].lValue] = aGameVars[i].defaultValue; } } - else if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR) + else if (!(aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR)) { aGameVars[i].lValue = aGameVars[i].defaultValue; } + else + { + // actor vars get set when an actor gets spawned and use initValue as their initial value. + aGameVars[i].initValue = aGameVars[i].defaultValue; + } } } } @@ -289,25 +268,21 @@ int GetGameVarID(int id, DDukeActor* sActor, int sPlayer) if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER ) { // for the current player - if(sPlayer >=0 && sPlayer < MAXPLAYERS) - { - return aGameVars[id].plArray[sPlayer]; - } - else - { - return aGameVars[id].lValue; - } + if (sPlayer >= 0 && sPlayer < MAXPLAYERS) + return ps[sPlayer].uservars[aGameVars[id].lValue]; + + return aGameVars[id].initValue; } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR ) { // for the current actor if(sActor != nullptr) { - return aGameVars[id].plArray[sActor->GetSpriteIndex()]; + return sActor->uservars[aGameVars[id].lValue]; } else { - return aGameVars[id].lValue; + return aGameVars[id].initValue; } } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG ) @@ -351,14 +326,30 @@ void SetGameVarID(int id, int lValue, DDukeActor* sActor, int sPlayer) if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER ) { // for the current player - if (sPlayer >= 0) aGameVars[id].plArray[sPlayer] = lValue; - else for (auto& i : aGameVars[id].plArray) i = lValue; // -1 sets all players - was undefined OOB access in WW2GI. + if (sPlayer >= 0) + { + if (sPlayer < MAXPLAYERS) + ps[sPlayer].uservars[aGameVars[id].lValue] = lValue; + } + else + { + for (int i = connecthead; i >= 0; i = connectpoint2[i]) + ps[i].uservars[aGameVars[id].lValue] = lValue; // set for all players + aGameVars[id].initValue = lValue; + } } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR ) { // for the current actor - if (sActor != nullptr) aGameVars[id].plArray[sActor->GetSpriteIndex()]=lValue; - else for (auto& i : aGameVars[id].plArray) i = lValue; // -1 sets all actors - was undefined OOB access in WW2GI. + if (sActor != nullptr) sActor->uservars[aGameVars[id].lValue] = lValue; + else + { + DukeSpriteIterator it; + while (auto actor = it.Next()) + actor->uservars[aGameVars[id].lValue] = lValue; + aGameVars[id].initValue = lValue; + } + } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG ) { @@ -392,29 +383,25 @@ int GetGameVar(const char *szGameLabel, int lDefault, DDukeActor* sActor, int sP //--------------------------------------------------------------------------- // -// +// only used for the aplWeapon stuff // //--------------------------------------------------------------------------- -int *GetGameValuePtr(char *szGameLabel) +int GetGameValuePtr(char *szGameLabel) { - int i; - for(i=0;iuservars.Resize(numActorVars); + for (int i = 0; i < iGameVarCount; i++) + { + if (aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR) + { + actor->uservars[aGameVars[i].lValue] = aGameVars[i].initValue; + } + } +} END_DUKE_NS diff --git a/source/games/duke/src/gamevar.h b/source/games/duke/src/gamevar.h index 9fb32adc3..c378b493a 100644 --- a/source/games/duke/src/gamevar.h +++ b/source/games/duke/src/gamevar.h @@ -37,21 +37,23 @@ enum NAM_GRENADE_LIFETIME_VAR = 30, }; -extern int* aplWeaponClip[MAX_WEAPONS]; // number of items in clip -extern int* aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire) -extern int* aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire -extern int* aplWeaponHoldDelay[MAX_WEAPONS]; // delay after release fire button to fire (0 for none) -extern int* aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire. -extern int* aplWeaponFlags[MAX_WEAPONS]; // Flags for weapon -extern int* aplWeaponShoots[MAX_WEAPONS]; // what the weapon shoots -extern int* aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn an item -extern int* aplWeaponSpawn[MAX_WEAPONS]; // the item to spawn -extern int* aplWeaponShotsPerBurst[MAX_WEAPONS]; // number of shots per 'burst' (one ammo per 'burst' -extern int* aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like -extern int* aplWeaponInitialSound[MAX_WEAPONS]; // Sound made when initialy firing. zero for no sound -extern int* aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for automatic) -extern int* aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time -extern int* aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID +// Keep the gory details away from the main game code. + +int aplWeaponClip(int weapon, int player); // number of items in clip +int aplWeaponReload(int weapon, int player); // delay to reload (include fire) +int aplWeaponFireDelay(int weapon, int player); // delay to fire +int aplWeaponHoldDelay(int weapon, int player); // delay after release fire button to fire (0 for none) +int aplWeaponTotalTime(int weapon, int player); // The total time the weapon is cycling before next fire. +int aplWeaponFlags(int weapon, int player); // Flags for weapon +int aplWeaponShoots(int weapon, int player); // what the weapon shoots +int aplWeaponSpawnTime(int weapon, int player); // the frame at which to spawn an item +int aplWeaponSpawn(int weapon, int player); // the item to spawn +int aplWeaponShotsPerBurst(int weapon, int player); // number of shots per 'burst' (one ammo per 'burst' +int aplWeaponWorksLike(int weapon, int player); // What original the weapon works like +int aplWeaponInitialSound(int weapon, int player); // Sound made when initialy firing. zero for no sound +int aplWeaponFireSound(int weapon, int player); // Sound made when firing (each time for automatic) +int aplWeaponSound2Time(int weapon, int player); // Alternate sound time +int aplWeaponSound2Sound(int weapon, int player); // Alternate sound sound ID enum @@ -98,9 +100,9 @@ typedef struct int (*getter)(); }; int defaultValue; + int initValue; // this is what gets copied to players/actors upon spawn. This is not the same as the default! unsigned int dwFlags; char szLabel[MAXVARLABEL]; - TArray plArray; } MATTGAMEVAR; extern MATTGAMEVAR aGameVars[MAXGAMEVARS]; @@ -132,7 +134,8 @@ int GetGameVar(const char* szGameLabel, int lDefault, DDukeActor* sActor, int sP void ClearGameEvents(); bool IsGameEvent(int i); void InitGameVarPointers(void); -void ResetSystemDefaults(void); +void FinalizeGameVars(void); +void SetupGameVarsForActor(DDukeActor* actor); diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index f93835a70..7650fc375 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -269,11 +269,11 @@ void displayweapon_d(int snum, double smoothratio) { if (p->last_weapon >= 0) { - cw = aplWeaponWorksLike[p->last_weapon][snum]; + cw = aplWeaponWorksLike(p->last_weapon, snum); } else { - cw = aplWeaponWorksLike[p->curr_weapon][snum]; + cw = aplWeaponWorksLike(p->curr_weapon, snum); } } else @@ -388,7 +388,7 @@ void displayweapon_d(int snum, double smoothratio) if (*kb > 0) { - if (*kb < (isWW2GI() ? aplWeaponTotalTime[RPG_WEAPON][snum] : 8)) + if (*kb < (isWW2GI() ? aplWeaponTotalTime(RPG_WEAPON, snum) : 8)) { hud_drawpal(weapon_xoffset + 164, (looking_arc * 2.) + 176 - gun_pos, RPGGUN + (*kb >> 1), shade, o | pin, pal); @@ -398,20 +398,20 @@ void displayweapon_d(int snum, double smoothratio) // else we are in 'reload time' if (*kb < ( - (aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]) / 2 - + aplWeaponTotalTime[p->curr_weapon][snum] + (aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum)) / 2 + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // down - gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime[p->curr_weapon][snum]); //D + gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime(p->curr_weapon, snum)); //D } else { // move back down // up and left - gun_pos -= 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); //U + gun_pos -= 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); //U } } } @@ -443,21 +443,20 @@ void displayweapon_d(int snum, double smoothratio) { hud_drawpal(weapon_xoffset + 146 - look_anghalf, looking_arc + 202 - gun_pos, SHOTGUN, shade, o, pal); } - else if (*kb <= aplWeaponTotalTime[SHOTGUN_WEAPON][snum]) + else if (*kb <= aplWeaponTotalTime(SHOTGUN_WEAPON, snum)) { hud_drawpal(weapon_xoffset + 146 - look_anghalf, looking_arc + 202 - gun_pos, SHOTGUN + 1, shade, o, pal); } // else we are in 'reload time' else if (*kb < ( - (aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]) / 2 - + aplWeaponTotalTime[p->curr_weapon][snum] + (aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum)) / 2 + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // down - gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime[p->curr_weapon][snum]); //D -// weapon_xoffset+=80*(*kb-aplWeaponTotalTime[cw][snum]); + gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime(p->curr_weapon, snum)); //D hud_drawpal(weapon_xoffset + 146 - look_anghalf, looking_arc + 202 - gun_pos, SHOTGUN, shade, o, pal); } else @@ -465,8 +464,7 @@ void displayweapon_d(int snum, double smoothratio) // move back down // up and left - gun_pos -= 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); //U -// weapon_xoffset+=80*(*kb-aplWeaponTotalTime[cw][snum]); + gun_pos -= 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); //U hud_drawpal(weapon_xoffset + 146 - look_anghalf, looking_arc + 202 - gun_pos, SHOTGUN, shade, o, pal); } }; @@ -561,7 +559,7 @@ void displayweapon_d(int snum, double smoothratio) // CHAINGUN,gs,o,pal); hud_drawpal(weapon_xoffset + 178 - look_anghalf, looking_arc + 233 - gun_pos, CHAINGUN + 1, shade, o, pal); } - else if (*kb <= aplWeaponTotalTime[CHAINGUN_WEAPON][snum]) + else if (*kb <= aplWeaponTotalTime(CHAINGUN_WEAPON, snum)) { hud_drawpal(weapon_xoffset + 188 - look_anghalf, looking_arc + 243 - gun_pos, CHAINGUN + 2, shade, o, pal); } @@ -575,57 +573,57 @@ void displayweapon_d(int snum, double smoothratio) else { - int iFifths = (aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]) / 5; + int iFifths = (aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum)) / 5; if (iFifths < 1) { iFifths = 1; } if (*kb < (iFifths - + aplWeaponTotalTime[p->curr_weapon][snum] + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // first segment // - gun_pos += 80 - (10 * (aplWeaponTotalTime[p->curr_weapon][snum] + iFifths - kickback_pic)); - weapon_xoffset += 80 - (10 * (aplWeaponTotalTime[p->curr_weapon][snum] + iFifths - kickback_pic)); + gun_pos += 80 - (10 * (aplWeaponTotalTime(p->curr_weapon, snum) + iFifths - kickback_pic)); + weapon_xoffset += 80 - (10 * (aplWeaponTotalTime(p->curr_weapon, snum) + iFifths - kickback_pic)); hud_drawpal(weapon_xoffset + 168 - look_anghalf, looking_arc + 260 - gun_pos, 2519, shade, o, pal); } else if (*kb < (iFifths * 2 - + aplWeaponTotalTime[p->curr_weapon][snum] + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // second segment // down - gun_pos += 80; //5*(iFifthsp->kickback_pic-aplWeaponTotalTime[p->curr_weapon][snum]); //D - weapon_xoffset += 80; //80*(*kb-aplWeaponTotalTime[p->curr_weapon][snum]); + gun_pos += 80; //5*(iFifthsp->kickback_pic-aplWeaponTotalTime(p->curr_weapon, snum)); //D + weapon_xoffset += 80; //80*(*kb-aplWeaponTotalTime(p->curr_weapon, snum)); hud_drawpal(weapon_xoffset + 168 - look_anghalf, looking_arc + 260 - gun_pos, 2518, shade, o, pal); } else if (*kb < (iFifths * 3 - + aplWeaponTotalTime[p->curr_weapon][snum] + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // third segment // up gun_pos += 80;//5*(iFifths*2); - weapon_xoffset += 80; //80*(*kb-aplWeaponTotalTime[p->curr_weapon][snum]); + weapon_xoffset += 80; //80*(*kb-aplWeaponTotalTime(p->curr_weapon, snum)); hud_drawpal(weapon_xoffset + 168 - look_anghalf, looking_arc + 260 - gun_pos, 2517, shade, o, pal); } else if (*kb < (iFifths * 4 - + aplWeaponTotalTime[p->curr_weapon][snum] + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // fourth segment // down - gun_pos += 80; //5*(aplWeaponTotalTime[p->curr_weapon][snum]- p->kickback_pic); //D - weapon_xoffset += 80; //80*(*kb-aplWeaponTotalTime[p->curr_weapon][snum]); + gun_pos += 80; //5*(aplWeaponTotalTime(p->curr_weapon, snum)- p->kickback_pic); //D + weapon_xoffset += 80; //80*(*kb-aplWeaponTotalTime(p->curr_weapon, snum)); hud_drawpal(weapon_xoffset + 168 - look_anghalf, looking_arc + 260 - gun_pos, 2518, shade, o, pal); } else @@ -633,10 +631,8 @@ void displayweapon_d(int snum, double smoothratio) // move back down // up and left - gun_pos += 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); - //5*(aplWeaponReload[p->curr_weapon][snum]- p->kickback_pic); //U - weapon_xoffset += 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); - //80*(*kb-aplWeaponTotalTime[cw][snum]); + gun_pos += 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); + weapon_xoffset += 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); hud_drawpal(weapon_xoffset + 168 - look_anghalf, looking_arc + 260 - gun_pos, 2519, shade, o, pal); } } @@ -712,7 +708,7 @@ void displayweapon_d(int snum, double smoothratio) auto pic_5 = FIRSTGUN+5; const int WEAPON2_RELOAD_TIME = 50; - auto reload_time = isWW2GI() ? aplWeaponReload[PISTOL_WEAPON][snum] : WEAPON2_RELOAD_TIME; + auto reload_time = isWW2GI() ? aplWeaponReload(PISTOL_WEAPON, snum) : WEAPON2_RELOAD_TIME; if (*kb < 10) hud_drawpal(194 - look_anghalf, looking_arc + 230 - gun_pos, FIRSTGUN + 4, shade, o|pin, pal); else if (*kb < 15) @@ -755,28 +751,28 @@ void displayweapon_d(int snum, double smoothratio) if (isWW2GI()) { - if (*kb <= aplWeaponFireDelay[HANDBOMB_WEAPON][snum]) + if (*kb <= aplWeaponFireDelay(HANDBOMB_WEAPON, snum)) { // it holds here gun_pos -= 5 * kickback_pic; //D } else if (*kb < ( - (aplWeaponTotalTime[HANDBOMB_WEAPON][snum] - aplWeaponFireDelay[HANDBOMB_WEAPON][snum]) / 2 - + aplWeaponFireDelay[HANDBOMB_WEAPON][snum] + (aplWeaponTotalTime(HANDBOMB_WEAPON, snum) - aplWeaponFireDelay(HANDBOMB_WEAPON, snum)) / 2 + + aplWeaponFireDelay(HANDBOMB_WEAPON, snum) ) ) { // up and left - gun_pos += 10 * (kickback_pic - aplWeaponFireDelay[HANDBOMB_WEAPON][snum]); //U - weapon_xoffset += 80 * (kickback_pic - aplWeaponFireDelay[HANDBOMB_WEAPON][snum]); + gun_pos += 10 * (kickback_pic - aplWeaponFireDelay(HANDBOMB_WEAPON, snum)); //U + weapon_xoffset += 80 * (kickback_pic - aplWeaponFireDelay(HANDBOMB_WEAPON, snum)); } - else if (*kb < aplWeaponTotalTime[HANDBOMB_WEAPON][snum]) + else if (*kb < aplWeaponTotalTime(HANDBOMB_WEAPON, snum)) { gun_pos += 240; // start high - gun_pos -= 12 * (kickback_pic - aplWeaponFireDelay[HANDBOMB_WEAPON][snum]); //D + gun_pos -= 12 * (kickback_pic - aplWeaponFireDelay(HANDBOMB_WEAPON, snum)); //D // move left - weapon_xoffset += 90 - (5 * (aplWeaponTotalTime[HANDBOMB_WEAPON][snum] - kickback_pic)); + weapon_xoffset += 90 - (5 * (aplWeaponTotalTime(HANDBOMB_WEAPON, snum) - kickback_pic)); } } else @@ -822,7 +818,7 @@ void displayweapon_d(int snum, double smoothratio) { if (*kb) { - if (*kb < aplWeaponTotalTime[p->curr_weapon][snum]) + if (*kb < aplWeaponTotalTime(p->curr_weapon, snum)) { i = Sgn(*kb >> 2); if (p->ammo_amount[p->curr_weapon] & 1) @@ -839,13 +835,13 @@ void displayweapon_d(int snum, double smoothratio) // else we are in 'reload time' else if (*kb < ( - (aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]) / 2 - + aplWeaponTotalTime[p->curr_weapon][snum] + (aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum)) / 2 + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // down - gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime[p->curr_weapon][snum]); //D + gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime(p->curr_weapon, snum)); //D // weapon_xoffset+=80*(*kb-aplWeaponTotalTime[cw][snum]); hud_drawpal(weapon_xoffset + 268 - look_anghalf, looking_arc + 238 - gun_pos, DEVISTATOR, shade, o, pal); hud_drawpal(weapon_xoffset + 30 - look_anghalf, looking_arc + 240 - gun_pos, DEVISTATOR, shade, o | 4, pal); @@ -855,7 +851,7 @@ void displayweapon_d(int snum, double smoothratio) // move back down // up and left - gun_pos -= 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); //U + gun_pos -= 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); //U // weapon_xoffset+=80*(*kb-aplWeaponTotalTime[cw][snum]); hud_drawpal(weapon_xoffset + 268 - look_anghalf, looking_arc + 238 - gun_pos, DEVISTATOR, shade, o, pal); hud_drawpal(weapon_xoffset + 30 - look_anghalf, looking_arc + 240 - gun_pos, DEVISTATOR, shade, o | 4, pal); @@ -972,9 +968,9 @@ void displayweapon_d(int snum, double smoothratio) } - if (*kb < aplWeaponTotalTime[p->curr_weapon][snum]) + if (*kb < aplWeaponTotalTime(p->curr_weapon, snum)) { - if (*kb < aplWeaponFireDelay[p->curr_weapon][snum]) + if (*kb < aplWeaponFireDelay(p->curr_weapon, snum)) { // before fire time. // nothing to modify @@ -985,24 +981,24 @@ void displayweapon_d(int snum, double smoothratio) // after fire time. // lower weapon to reload cartridge (not clip) - gun_pos -= 10 * (aplWeaponTotalTime[p->curr_weapon][snum] - kickback_pic); + gun_pos -= 10 * (aplWeaponTotalTime(p->curr_weapon, snum) - kickback_pic); } } // else we are in 'reload time' else if (*kb < ( - (aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]) / 2 - + aplWeaponTotalTime[p->curr_weapon][snum] + (aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum)) / 2 + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // down - gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime[p->curr_weapon][snum]); //D + gun_pos -= 10 * (kickback_pic - aplWeaponTotalTime(p->curr_weapon, snum)); //D } else { // up - gun_pos -= 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); //U + gun_pos -= 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); //U } // draw weapon @@ -1043,9 +1039,9 @@ void displayweapon_d(int snum, double smoothratio) gun_pos += (rand() & 3); } - if (*kb < aplWeaponTotalTime[p->curr_weapon][snum]) + if (*kb < aplWeaponTotalTime(p->curr_weapon, snum)) { - if (*kb < aplWeaponFireDelay[p->curr_weapon][snum]) + if (*kb < aplWeaponFireDelay(p->curr_weapon, snum)) { // before fire time. // nothing to modify @@ -1056,24 +1052,24 @@ void displayweapon_d(int snum, double smoothratio) // after fire time. // lower weapon to reload cartridge (not clip) - gun_pos -= 15 * (aplWeaponTotalTime[p->curr_weapon][snum] - kickback_pic); + gun_pos -= 15 * (aplWeaponTotalTime(p->curr_weapon, snum) - kickback_pic); } } // else we are in 'reload time' else if (*kb < ( - (aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]) / 2 - + aplWeaponTotalTime[p->curr_weapon][snum] + (aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum)) / 2 + + aplWeaponTotalTime(p->curr_weapon, snum) ) ) { // down - gun_pos -= 5 * (kickback_pic - aplWeaponTotalTime[p->curr_weapon][snum]); //D + gun_pos -= 5 * (kickback_pic - aplWeaponTotalTime(p->curr_weapon, snum)); //D } else { // up - gun_pos -= 10 * (aplWeaponReload[p->curr_weapon][snum] - kickback_pic); //U + gun_pos -= 10 * (aplWeaponReload(p->curr_weapon, snum) - kickback_pic); //U } // display weapon diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 32f03cfc9..8dcdc03a4 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -258,7 +258,7 @@ DDukeActor* aim(DDukeActor* actor, int aang) } else { - weap = aplWeaponWorksLike[ps[s->yvel].curr_weapon][s->yvel]; + weap = aplWeaponWorksLike(ps[s->yvel].curr_weapon, s->yvel); } if (weap > CHAINGUN_WEAPON || weap == KNEE_WEAPON) { @@ -277,8 +277,8 @@ DDukeActor* aim(DDukeActor* actor, int aang) } else if (isWW2GI()) { - gotshrinker = s->picnum == TILE_APLAYER && aplWeaponWorksLike[ps[s->yvel].curr_weapon][s->yvel] == SHRINKER_WEAPON; - gotfreezer = s->picnum == TILE_APLAYER && aplWeaponWorksLike[ps[s->yvel].curr_weapon][s->yvel] == FREEZE_WEAPON; + gotshrinker = s->picnum == TILE_APLAYER && aplWeaponWorksLike(ps[s->yvel].curr_weapon, s->yvel) == SHRINKER_WEAPON; + gotfreezer = s->picnum == TILE_APLAYER && aplWeaponWorksLike(ps[s->yvel].curr_weapon, s->yvel) == FREEZE_WEAPON; } else { @@ -937,13 +937,13 @@ bool movementBlocked(player_struct *p) auto blockingweapon = [=]() { if (isRR()) return false; - if (isWW2GI()) return aplWeaponWorksLike[p->curr_weapon][p->GetPlayerNum()] == TRIPBOMB_WEAPON; + if (isWW2GI()) return aplWeaponWorksLike(p->curr_weapon, p->GetPlayerNum()) == TRIPBOMB_WEAPON; else return p->curr_weapon == TRIPBOMB_WEAPON; }; auto weapondelay = [=]() { - if (isWW2GI()) return aplWeaponFireDelay[p->curr_weapon][p->GetPlayerNum()]; + if (isWW2GI()) return aplWeaponFireDelay(p->curr_weapon, p->GetPlayerNum()); else return 4; }; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 20c0d8f2a..9510fe13a 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -814,7 +814,7 @@ static void shootrpg(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, i spj->extra >>= 2; } } - else if ((isWW2GI() && aplWeaponWorksLike[ps[p].curr_weapon][p] == DEVISTATOR_WEAPON) || (!isWW2GI() && ps[p].curr_weapon == DEVISTATOR_WEAPON)) + else if ((isWW2GI() && aplWeaponWorksLike(ps[p].curr_weapon, p) == DEVISTATOR_WEAPON) || (!isWW2GI() && ps[p].curr_weapon == DEVISTATOR_WEAPON)) { spj->extra >>= 2; spj->ang += 16 - (krand() & 31); @@ -1653,7 +1653,7 @@ void checkweapons_d(struct player_struct* p) if (isWW2GI()) { int snum = p->GetActor()->s->yvel; - cw = aplWeaponWorksLike[p->curr_weapon][snum]; + cw = aplWeaponWorksLike(p->curr_weapon, snum); } else cw = p->curr_weapon; @@ -2449,7 +2449,7 @@ static void operateweapon(int snum, ESyncBits actions) //#ifdef NAM //#else - if (!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_NOVISIBLE)) + if (!(aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_NOVISIBLE)) { // make them visible if not set... p->visibility = 0; @@ -2459,11 +2459,11 @@ static void operateweapon(int snum, ESyncBits actions) //#endif } else if (!isNam()) p->kickback_pic++; - if (isNam() && p->kickback_pic > aplWeaponReload[p->curr_weapon][snum]) // 30) + if (isNam() && p->kickback_pic > aplWeaponReload(p->curr_weapon, snum)) // 30) { // reload now... p->okickback_pic = p->kickback_pic = 0; - if (!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_NOVISIBLE)) + if (!(aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_NOVISIBLE)) { // make them visible if not set... p->visibility = 0; @@ -2655,21 +2655,21 @@ static void processweapon(int snum, ESyncBits actions) { SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->GetActor(), snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->GetActor(), snum); + SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(p->curr_weapon, snum), p->GetActor(), snum); OnEvent(EVENT_HOLSTER, snum, p->GetActor(), -1); if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { // now it uses the game definitions... - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_HOLSTER_CLEARS_CLIP) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_HOLSTER_CLEARS_CLIP) { - if (p->ammo_amount[p->curr_weapon] > aplWeaponClip[p->curr_weapon][snum] - && (p->ammo_amount[p->curr_weapon] % aplWeaponClip[p->curr_weapon][snum]) != 0) + if (p->ammo_amount[p->curr_weapon] > aplWeaponClip(p->curr_weapon, snum) + && (p->ammo_amount[p->curr_weapon] % aplWeaponClip(p->curr_weapon, snum)) != 0) { // throw away the remaining clip p->ammo_amount[p->curr_weapon] -= - p->ammo_amount[p->curr_weapon] % aplWeaponClip[p->curr_weapon][snum]; - // p->kickback_pic = aplWeaponFireDelay[p->curr_weapon][snum]+1; // animate, but don't shoot... - p->kickback_pic = aplWeaponTotalTime[p->curr_weapon][snum] + 1; // animate, but don't shoot... + p->ammo_amount[p->curr_weapon] % aplWeaponClip(p->curr_weapon, snum); + // p->kickback_pic = aplWeaponFireDelay(p->curr_weapon, snum)+1; // animate, but don't shoot... + p->kickback_pic = aplWeaponTotalTime(p->curr_weapon, snum) + 1; // animate, but don't shoot... actions &= ~SB_FIRE; // not firing... } return; @@ -2690,7 +2690,7 @@ static void processweapon(int snum, ESyncBits actions) } - if (isWW2GI() && (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_GLOWS)) + if (isWW2GI() && (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_GLOWS)) p->random_club_frame += 64; // Glowing if (!isWW2GI() && (p->curr_weapon == SHRINKER_WEAPON || p->curr_weapon == GROW_WEAPON)) @@ -2849,7 +2849,7 @@ void processinput_d(int snum) fi.doincrements(p); - if (isWW2GI() && aplWeaponWorksLike[p->curr_weapon][snum] == HANDREMOTE_WEAPON) processweapon(snum, actions); + if (isWW2GI() && aplWeaponWorksLike(p->curr_weapon, snum) == HANDREMOTE_WEAPON) processweapon(snum, actions); if (!isWW2GI() && p->curr_weapon == HANDREMOTE_WEAPON) processweapon(snum, actions); return; } @@ -2992,7 +2992,7 @@ void processinput_d(int snum) bool check; if (!isWW2GI()) check = ((p->curr_weapon == KNEE_WEAPON && p->kickback_pic > 10 && p->on_ground) || (p->on_ground && (actions & SB_CROUCH))); - else check = ((aplWeaponWorksLike[p->curr_weapon][snum] == KNEE_WEAPON && p->kickback_pic > 10 && p->on_ground) || (p->on_ground && (actions & SB_CROUCH))); + else check = ((aplWeaponWorksLike(p->curr_weapon, snum) == KNEE_WEAPON && p->kickback_pic > 10 && p->on_ground) || (p->on_ground && (actions & SB_CROUCH))); if (check) { p->posxv = MulScale(p->posxv, gs.playerfriction - 0x2000, 16); diff --git a/source/games/duke/src/player_w.cpp b/source/games/duke/src/player_w.cpp index 4d35c5302..975fc61ca 100644 --- a/source/games/duke/src/player_w.cpp +++ b/source/games/duke/src/player_w.cpp @@ -53,48 +53,48 @@ void DoFire(struct player_struct* p, int snum) { int i; - if (aplWeaponWorksLike[p->curr_weapon][snum] != KNEE_WEAPON) + if (aplWeaponWorksLike(p->curr_weapon, snum) != KNEE_WEAPON) { p->ammo_amount[p->curr_weapon]--; } - if (aplWeaponFireSound[p->curr_weapon][snum]) + if (aplWeaponFireSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponFireSound[p->curr_weapon][snum], p->GetActor()); + S_PlayActorSound(aplWeaponFireSound(p->curr_weapon, snum), p->GetActor()); } SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->GetActor(), snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->GetActor(), snum); - fi.shoot(p->GetActor(), aplWeaponShoots[p->curr_weapon][snum]); - for (i = 1; i < aplWeaponShotsPerBurst[p->curr_weapon][snum]; i++) + SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(p->curr_weapon, snum), p->GetActor(), snum); + fi.shoot(p->GetActor(), aplWeaponShoots(p->curr_weapon, snum)); + for (i = 1; i < aplWeaponShotsPerBurst(p->curr_weapon, snum); i++) { - fi.shoot(p->GetActor(), aplWeaponShoots[p->curr_weapon][snum]); - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_AMMOPERSHOT) + fi.shoot(p->GetActor(), aplWeaponShoots(p->curr_weapon, snum)); + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_AMMOPERSHOT) { p->ammo_amount[p->curr_weapon]--; } } - if (!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_NOVISIBLE)) + if (!(aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_NOVISIBLE)) { // make them visible if not set... lastvisinc = PlayClock + 32; p->visibility = 0; } - if ( //!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_CHECKATRELOAD) && - aplWeaponReload[p->curr_weapon][snum] > aplWeaponTotalTime[p->curr_weapon][snum] + if ( //!(aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_CHECKATRELOAD) && + aplWeaponReload(p->curr_weapon, snum) > aplWeaponTotalTime(p->curr_weapon, snum) && p->ammo_amount[p->curr_weapon] > 0 - && (aplWeaponClip[p->curr_weapon][snum]) - && ((p->ammo_amount[p->curr_weapon] % (aplWeaponClip[p->curr_weapon][snum])) == 0) + && (aplWeaponClip(p->curr_weapon, snum)) + && ((p->ammo_amount[p->curr_weapon] % (aplWeaponClip(p->curr_weapon, snum))) == 0) ) { // do clip check... - p->kickback_pic = aplWeaponTotalTime[p->curr_weapon][snum]; + p->kickback_pic = aplWeaponTotalTime(p->curr_weapon, snum); // is same as p->kickback_pic.... } - if (aplWeaponWorksLike[p->curr_weapon][snum] != KNEE_WEAPON) + if (aplWeaponWorksLike(p->curr_weapon, snum) != KNEE_WEAPON) { checkavailweapon(p); } @@ -108,13 +108,13 @@ void DoFire(struct player_struct* p, int snum) void DoSpawn(struct player_struct *p, int snum) { - if(!aplWeaponSpawn[p->curr_weapon][snum]) + if(!aplWeaponSpawn(p->curr_weapon, snum)) return; - auto j = spawn(p->GetActor(), aplWeaponSpawn[p->curr_weapon][snum]); + auto j = spawn(p->GetActor(), aplWeaponSpawn(p->curr_weapon, snum)); if (!j) return; - if((aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_SPAWNTYPE2 ) ) + if((aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_SPAWNTYPE2 ) ) { // like shotgun shells j->s->ang += 1024; @@ -122,7 +122,7 @@ void DoSpawn(struct player_struct *p, int snum) j->s->ang += 1024; // p->kickback_pic++; } - else if((aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_SPAWNTYPE3 ) ) + else if((aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_SPAWNTYPE3 ) ) { // like chaingun shells j->s->ang += 1024; @@ -160,29 +160,29 @@ void fireweapon_ww(int snum) { SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->GetActor(), snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->GetActor(), snum); + SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(p->curr_weapon, snum), p->GetActor(), snum); OnEvent(EVENT_FIRE, snum, p->GetActor(), -1); if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { - switch (aplWeaponWorksLike[p->curr_weapon][snum]) + switch (aplWeaponWorksLike(p->curr_weapon, snum)) { case HANDBOMB_WEAPON: p->hbomb_hold_delay = 0; if (p->ammo_amount[p->curr_weapon] > 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; case HANDREMOTE_WEAPON: p->hbomb_hold_delay = 0; p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } break; @@ -191,9 +191,9 @@ void fireweapon_ww(int snum) { //p->ammo_amount[p->curr_weapon]--; p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -203,9 +203,9 @@ void fireweapon_ww(int snum) if (p->ammo_amount[p->curr_weapon] > 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -214,9 +214,9 @@ void fireweapon_ww(int snum) if (p->ammo_amount[p->curr_weapon] > 0 && p->random_club_frame == 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -224,9 +224,9 @@ void fireweapon_ww(int snum) if (operateTripbomb(snum)) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -235,9 +235,9 @@ void fireweapon_ww(int snum) if (p->ammo_amount[p->curr_weapon] > 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -246,9 +246,9 @@ void fireweapon_ww(int snum) if (p->ammo_amount[p->curr_weapon] > 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -257,9 +257,9 @@ void fireweapon_ww(int snum) if (p->ammo_amount[p->curr_weapon] > 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -268,9 +268,9 @@ void fireweapon_ww(int snum) { p->kickback_pic = 1; p->hbomb_hold_delay = !p->hbomb_hold_delay; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -279,9 +279,9 @@ void fireweapon_ww(int snum) if (p->ammo_amount[RPG_WEAPON] > 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -290,9 +290,9 @@ void fireweapon_ww(int snum) if (p->quick_kick == 0) { p->kickback_pic = 1; - if (aplWeaponInitialSound[p->curr_weapon][snum]) + if (aplWeaponInitialSound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponInitialSound(p->curr_weapon, snum), pact); } } break; @@ -314,10 +314,10 @@ void operateweapon_ww(int snum, ESyncBits actions) int i, k; // already firing... - if (aplWeaponWorksLike[p->curr_weapon][snum] == HANDBOMB_WEAPON) + if (aplWeaponWorksLike(p->curr_weapon, snum) == HANDBOMB_WEAPON) { - if (aplWeaponHoldDelay[p->curr_weapon][snum] // there is a hold delay - && (p->kickback_pic == aplWeaponFireDelay[p->curr_weapon][snum]) // and we are 'at' hold + if (aplWeaponHoldDelay(p->curr_weapon, snum) // there is a hold delay + && (p->kickback_pic == aplWeaponFireDelay(p->curr_weapon, snum)) // and we are 'at' hold && (actions & SB_FIRE) // and 'fire' button is still down ) // just hold here... @@ -326,7 +326,7 @@ void operateweapon_ww(int snum, ESyncBits actions) return; } p->kickback_pic++; - if (p->kickback_pic == aplWeaponHoldDelay[p->curr_weapon][snum]) + if (p->kickback_pic == aplWeaponHoldDelay(p->curr_weapon, snum)) { p->ammo_amount[p->curr_weapon]--; @@ -376,43 +376,43 @@ void operateweapon_ww(int snum, ESyncBits actions) } } - else if (p->kickback_pic < aplWeaponHoldDelay[p->curr_weapon][snum] && + else if (p->kickback_pic < aplWeaponHoldDelay(p->curr_weapon, snum) && (actions & SB_CROUCH)) { p->hbomb_hold_delay++; } - else if (p->kickback_pic > aplWeaponTotalTime[p->curr_weapon][snum]) + else if (p->kickback_pic > aplWeaponTotalTime(p->curr_weapon, snum)) { p->okickback_pic = p->kickback_pic = 0; // don't change to remote when in NAM: grenades are timed checkavailweapon(p); } } - else if (aplWeaponWorksLike[p->curr_weapon][snum] == HANDREMOTE_WEAPON) + else if (aplWeaponWorksLike(p->curr_weapon, snum) == HANDREMOTE_WEAPON) { p->kickback_pic++; - if (p->kickback_pic == aplWeaponFireDelay[p->curr_weapon][snum]) + if (p->kickback_pic == aplWeaponFireDelay(p->curr_weapon, snum)) { - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_BOMB_TRIGGER) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_BOMB_TRIGGER) { p->hbomb_on = 0; } - if (aplWeaponShoots[p->curr_weapon][snum] != 0) + if (aplWeaponShoots(p->curr_weapon, snum) != 0) { - if (!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_NOVISIBLE)) + if (!(aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_NOVISIBLE)) { // make them visible if not set... lastvisinc = PlayClock + 32; p->visibility = 0; } SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->GetActor(), snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->GetActor(), snum); - fi.shoot(p->GetActor(), aplWeaponShoots[p->curr_weapon][snum]); + SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(p->curr_weapon, snum), p->GetActor(), snum); + fi.shoot(p->GetActor(), aplWeaponShoots(p->curr_weapon, snum)); } } - if (p->kickback_pic >= aplWeaponTotalTime[p->curr_weapon][snum]) + if (p->kickback_pic >= aplWeaponTotalTime(p->curr_weapon, snum)) { p->okickback_pic = p->kickback_pic = 0; /// WHAT THE HELL DOES THIS DO....????????????? @@ -429,47 +429,47 @@ void operateweapon_ww(int snum, ESyncBits actions) // the basic weapon... p->kickback_pic++; - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_CHECKATRELOAD) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_CHECKATRELOAD) { - if (p->kickback_pic == aplWeaponReload[p->curr_weapon][snum]) + if (p->kickback_pic == aplWeaponReload(p->curr_weapon, snum)) { checkavailweapon(p); } } - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_STANDSTILL - && p->kickback_pic < (aplWeaponFireDelay[p->curr_weapon][snum] + 1)) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_STANDSTILL + && p->kickback_pic < (aplWeaponFireDelay(p->curr_weapon, snum) + 1)) { p->pos.z = p->oposz; p->poszv = 0; } - if (p->kickback_pic == aplWeaponSound2Time[p->curr_weapon][snum]) + if (p->kickback_pic == aplWeaponSound2Time(p->curr_weapon, snum)) { - if (aplWeaponSound2Sound[p->curr_weapon][snum]) + if (aplWeaponSound2Sound(p->curr_weapon, snum)) { - S_PlayActorSound(aplWeaponSound2Sound[p->curr_weapon][snum], pact); + S_PlayActorSound(aplWeaponSound2Sound(p->curr_weapon, snum), pact); } } - if (p->kickback_pic == aplWeaponSpawnTime[p->curr_weapon][snum]) + if (p->kickback_pic == aplWeaponSpawnTime(p->curr_weapon, snum)) { DoSpawn(p, snum); } - if (p->kickback_pic == aplWeaponFireDelay[p->curr_weapon][snum]) + if (p->kickback_pic == aplWeaponFireDelay(p->curr_weapon, snum)) { DoFire(p, snum); } - if (p->kickback_pic > aplWeaponFireDelay[p->curr_weapon][snum] - && p->kickback_pic < aplWeaponTotalTime[p->curr_weapon][snum]) + if (p->kickback_pic > aplWeaponFireDelay(p->curr_weapon, snum) + && p->kickback_pic < aplWeaponTotalTime(p->curr_weapon, snum)) { - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_AUTOMATIC) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_AUTOMATIC) { // an 'automatic' if ((actions & SB_FIRE) == 0) { - p->kickback_pic = aplWeaponTotalTime[p->curr_weapon][snum]; + p->kickback_pic = aplWeaponTotalTime(p->curr_weapon, snum); } - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_FIREEVERYTHIRD) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_FIREEVERYTHIRD) { if (((p->kickback_pic) % 3) == 0) { @@ -478,7 +478,7 @@ void operateweapon_ww(int snum, ESyncBits actions) } } - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_FIREEVERYOTHER) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_FIREEVERYOTHER) { // fire every other... DoFire(p, snum); @@ -487,31 +487,31 @@ void operateweapon_ww(int snum, ESyncBits actions) } // 'automatic } - else if (p->kickback_pic >= aplWeaponTotalTime[p->curr_weapon][snum]) + else if (p->kickback_pic >= aplWeaponTotalTime(p->curr_weapon, snum)) { - if ( //!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_CHECKATRELOAD) && - aplWeaponReload[p->curr_weapon][snum] > aplWeaponTotalTime[p->curr_weapon][snum] + if ( //!(aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_CHECKATRELOAD) && + aplWeaponReload(p->curr_weapon, snum) > aplWeaponTotalTime(p->curr_weapon, snum) && p->ammo_amount[p->curr_weapon] > 0 - && (aplWeaponClip[p->curr_weapon][snum]) - && ((p->ammo_amount[p->curr_weapon] % (aplWeaponClip[p->curr_weapon][snum])) == 0) + && (aplWeaponClip(p->curr_weapon, snum)) + && ((p->ammo_amount[p->curr_weapon] % (aplWeaponClip(p->curr_weapon, snum))) == 0) ) { // reload in progress... int i; - i = aplWeaponReload[p->curr_weapon][snum] - aplWeaponTotalTime[p->curr_weapon][snum]; + i = aplWeaponReload(p->curr_weapon, snum) - aplWeaponTotalTime(p->curr_weapon, snum); // time for 'reload' - if (p->kickback_pic == (aplWeaponTotalTime[p->curr_weapon][snum] + 1)) + if (p->kickback_pic == (aplWeaponTotalTime(p->curr_weapon, snum) + 1)) { // eject shortly after 'total time' S_PlayActorSound(EJECT_CLIP, pact); } - else if (p->kickback_pic == (aplWeaponReload[p->curr_weapon][snum] - (i / 3))) + else if (p->kickback_pic == (aplWeaponReload(p->curr_weapon, snum) - (i / 3))) { // insert occurs 2/3 of way through reload delay S_PlayActorSound(INSERT_CLIP, pact); } - if (p->kickback_pic >= (aplWeaponReload[p->curr_weapon][snum])) + if (p->kickback_pic >= (aplWeaponReload(p->curr_weapon, snum))) { p->okickback_pic = p->kickback_pic = 0; } @@ -519,12 +519,12 @@ void operateweapon_ww(int snum, ESyncBits actions) } else { - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_AUTOMATIC) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_AUTOMATIC) { // an 'automatic' if (actions & SB_FIRE) { // we are an AUTOMATIC. Fire again... - if (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_RANDOMRESTART) + if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_RANDOMRESTART) { p->kickback_pic = 1 + (krand() & 3); } diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index d30577894..e39baaf4b 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -539,7 +539,7 @@ void resetpspritevars(int g) resetplayerstats(0); for (i = 1; i < MAXPLAYERS; i++) - memcpy(&ps[i], &ps[0], sizeof(ps[0])); + ps[i] = ps[0]; if (ud.recstat != 2) for (i = 0; i < MAXPLAYERS; i++) { @@ -766,13 +766,13 @@ void donewgame(MapRecord* map, int sk) { for (int i = 0; i < 12/*MAX_WEAPONS*/; i++) // aboive 12 have no data defined and would crash. { - if (aplWeaponWorksLike[i][0] == PISTOL_WEAPON) + if (aplWeaponWorksLike(i, 0) == PISTOL_WEAPON) { p->curr_weapon = i; p->gotweapon[i] = true; p->ammo_amount[i] = 48; } - else if (aplWeaponWorksLike[i][0] == KNEE_WEAPON || aplWeaponWorksLike[i][0] == HANDREMOTE_WEAPON) + else if (aplWeaponWorksLike(i, 0) == KNEE_WEAPON || aplWeaponWorksLike(i, 0) == HANDREMOTE_WEAPON) { p->gotweapon[i] = true; } diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 6bce52a0d..448036340 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -265,6 +265,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, // new stuff ("actions", w.sync.actions) .Array("frags", w.frags, MAXPLAYERS) + ("uservars", w.uservars) .EndObject(); w.invdisptime = 0; @@ -311,7 +312,8 @@ void DDukeActor::Serialize(FSerializer& arc) ("seek_actor", seek_actor) .Array("temp_data", temp_data, 6) .Array("temo_wall", temp_walls, 2) - ("temp_sect", temp_sect); + ("temp_sect", temp_sect) + ("uservars", uservars); } diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index ea259d613..f6480d971 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -56,6 +56,8 @@ DDukeActor* EGS(sectortype* whatsectp, int s_x, int s_y, int s_z, int s_pn, int8 auto act = static_cast(::InsertActor(whatsectp, s_ss)); if (act == nullptr) return nullptr; + SetupGameVarsForActor(act); + auto s = act->s; diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 4bf9002c2..cbe583304 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -45,6 +45,8 @@ struct DDukeActor : public DCoreActor DDukeActor* temp_actor, *seek_actor; spritetype* s; // direct reference to the corresponding sprite. + TArray uservars; + static DDukeActor* array(); // this is necessary to allow define inline functions referencing the global array inside the definition itself. DDukeActor() @@ -302,6 +304,9 @@ struct player_struct double vehForwardScale, vehReverseScale, MotoSpeed; bool vehTurnLeft, vehTurnRight, vehBraking; + TArray uservars; + + // input stuff. InputPacket sync;