diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 14c70fbdf..63c17f3f6 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -450,6 +450,8 @@ if( VPX_FOUND ) add_definitions( "-DUSE_LIBVPX=1" ) include_directories( "${VPX_INCLUDE_DIR}" ) set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} ${VPX_LIBRARIES} ) +else() + message( SEND_ERROR "Could not find libvpx" ) endif() diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 0030fb304..6888bbba4 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -42,6 +42,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) return; } + PLAYER* pPlayer = &gPlayer[myconnectindex]; double const scaleAdjust = InputScale(); InputPacket input {}; @@ -50,12 +51,10 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) if (!cl_syncinput && gamestate == GS_LEVEL) { - PLAYER* pPlayer = &gPlayer[myconnectindex]; - // Perform unsynchronised angle/horizon if not dead. if (gView->pXSprite->health != 0) { - applylook(&pPlayer->angle, input.avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0); + applylook(&pPlayer->angle, input.avel, &pPlayer->input.actions, scaleAdjust); sethorizon(&pPlayer->horizon.horiz, input.horz, &pPlayer->input.actions, scaleAdjust); } diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 644246522..d024b2a0f 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -1445,7 +1445,7 @@ void ProcessInput(PLAYER *pPlayer) if (cl_syncinput) { - applylook(&pPlayer->angle, pInput->avel, &pInput->actions, 1, pPlayer->posture != 0); + applylook(&pPlayer->angle, pInput->avel, &pInput->actions); UpdatePlayerSpriteAngle(pPlayer); } @@ -1493,14 +1493,20 @@ void ProcessInput(PLAYER *pPlayer) if (pXSector->locked && pPlayer == gMe) { viewSetMessage(GStrings("TXTB_LOCKED")); - sndStartSample(3062, 255, 2, 0); + auto snd = 3062; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } if (!key || pPlayer->hasKey[key]) trTriggerSector(a2, pXSector, kCmdSpritePush); else if (pPlayer == gMe) { viewSetMessage(GStrings("TXTB_KEY")); - sndStartSample(3063, 255, 2, 0); + auto snd = 3063; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } } break; @@ -1511,14 +1517,20 @@ void ProcessInput(PLAYER *pPlayer) if (pXWall->locked && pPlayer == gMe) { viewSetMessage(GStrings("TXTB_LOCKED")); - sndStartSample(3062, 255, 2, 0); + auto snd = 3062; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } if (!key || pPlayer->hasKey[key]) trTriggerWall(a2, pXWall, kCmdWallPush); else if (pPlayer == gMe) { viewSetMessage(GStrings("TXTB_KEY")); - sndStartSample(3063, 255, 2, 0); + auto snd = 3063; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } break; } @@ -1557,7 +1569,7 @@ void ProcessInput(PLAYER *pPlayer) if (cl_syncinput) { - sethorizon(&pPlayer->horizon.horiz, pInput->horz, &pInput->actions, 1); + sethorizon(&pPlayer->horizon.horiz, pInput->horz, &pInput->actions); } int nSector = pSprite->sectnum; diff --git a/source/blood/src/sound.cpp b/source/blood/src/sound.cpp index 56f6282f5..eb70241d1 100644 --- a/source/blood/src/sound.cpp +++ b/source/blood/src/sound.cpp @@ -144,6 +144,22 @@ void SoundCallback(intptr_t val) pChannel->TotalKills = 0; } +bool sndCheckPlaying(unsigned int nSound) +{ + auto snd = soundEngine->FindSoundByResID(nSound); + return snd > 0 ? soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, snd) : false; +} + +void sndStopSample(unsigned int nSound) +{ + auto snd = soundEngine->FindSoundByResID(nSound); + + if (snd > 0) + { + soundEngine->StopSoundID(snd); + } +} + void sndStartSample(const char *pzSound, int nVolume, int nChannel) { if (!SoundEnabled()) diff --git a/source/blood/src/sound.h b/source/blood/src/sound.h index b3dd7085a..5fe03882d 100644 --- a/source/blood/src/sound.h +++ b/source/blood/src/sound.h @@ -45,6 +45,8 @@ struct SFX }; int sndGetRate(int format); +bool sndCheckPlaying(unsigned int nSound); +void sndStopSample(unsigned int nSound); void sndStartSample(const char *pzSound, int nVolume, int nChannel = -1); void sndStartSample(unsigned int nSound, int nVolume, int nChannel = -1, bool bLoop = false, EChanFlags soundflags = CHANF_NONE); void sndStartWavID(unsigned int nSound, int nVolume, int nChannel = -1); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index a714f249b..53ba2c2c6 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -69,8 +69,6 @@ int32_t voxscale[MAXVOXELS]; static int32_t beforedrawrooms = 1; -static int32_t oxdimen = -1, oviewingrange = -1, oxyaspect = -1; - int32_t globalflags; static int8_t tempbuf[MAXWALLS]; @@ -399,49 +397,6 @@ static inline void initksqrt(void) } } - -// -// dosetaspect -// -static void dosetaspect(void) -{ - int32_t i, j; - - if (xyaspect != oxyaspect) - { - oxyaspect = xyaspect; - j = xyaspect*320; - } - - if (xdimen != oxdimen || viewingrange != oviewingrange) - { - int32_t k, x, xinc; - - no_radarang2 = 0; - oviewingrange = viewingrange; - - xinc = mulscale32(viewingrange*2560,xdimenrecip); - x = IntToFixed(5120)-mulscale1(xinc,xdimen); - - for (i=0; i= (int32_t)countof(qradarang)-1) - { - no_radarang2 = 1; - break; - } - - if (j != 0) - j = mulscale16(qradarang[k+1]-qradarang[k], j); - } - - oxdimen = xdimen; - } -} - - static int32_t engineLoadTables(void) { static char tablesloaded = 0; @@ -1092,9 +1047,6 @@ int32_t renderDrawRoomsQ16(int32_t daposx, int32_t daposy, int32_t daposz, globalcursectnum = dacursectnum; - if ((xyaspect != oxyaspect) || (xdimen != oxdimen) || (viewingrange != oviewingrange)) - dosetaspect(); - memset(gotsector, 0, sizeof(gotsector)); i = xdimen-1; @@ -2183,9 +2135,6 @@ void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang) renderFillPolygon(npoints); } } - - - renderSetAspect(oviewingrange, oyxaspect); } // @@ -2219,9 +2168,6 @@ int32_t videoSetGameMode(char davidoption, int32_t daupscaledxdim, int32_t daups j = ydim*4; //Leave room for horizlookup&horizlookup2 - //Force drawrooms to call dosetaspect & recalculate stuff - oxyaspect = oxdimen = oviewingrange = -1; - videoSetViewableArea(0L,0L,xdim-1,ydim-1); videoClearScreen(0L); diff --git a/source/common/fonts/v_text.cpp b/source/common/fonts/v_text.cpp index 59d843496..54dfbf290 100644 --- a/source/common/fonts/v_text.cpp +++ b/source/common/fonts/v_text.cpp @@ -242,6 +242,27 @@ DEFINE_ACTION_FUNCTION(FFont, BreakLines) ACTION_RETURN_OBJECT(Create(broken)); } +DEFINE_ACTION_FUNCTION(FFont, BreakLines2) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + PARAM_STRING(text); + PARAM_INT(maxwidth); + + auto broken = V_BreakLines(self, maxwidth, text, true); + ACTION_RETURN_OBJECT(Create(broken)); +} + +DEFINE_ACTION_FUNCTION(_Hugohaft, BreakLines) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + PARAM_STRING(text); + PARAM_INT(maxwidth); + + auto broken = V_BreakLines(self, maxwidth, text, true); + ACTION_RETURN_OBJECT(Create(broken)); +} + + bool generic_ui; EXTERN_CVAR(String, language) diff --git a/source/common/objects/dobject.h b/source/common/objects/dobject.h index f9c0c0b0a..a866a4ca5 100644 --- a/source/common/objects/dobject.h +++ b/source/common/objects/dobject.h @@ -266,7 +266,7 @@ private: void *operator new(size_t len, nonew&) { - return M_Malloc(len); + return M_Calloc(len, 1); } public: diff --git a/source/common/scripting/vm/vmframe.cpp b/source/common/scripting/vm/vmframe.cpp index bc6b344e5..4b50f9b21 100644 --- a/source/common/scripting/vm/vmframe.cpp +++ b/source/common/scripting/vm/vmframe.cpp @@ -79,8 +79,8 @@ void VMFunction::CreateRegUse() int count = 0; if (!Proto) { - if (RegTypes) return; - Printf(TEXTCOLOR_ORANGE "Function without prototype needs register info manually set: %s\n", PrintableName.GetChars()); + //if (RegTypes) return; + //Printf(TEXTCOLOR_ORANGE "Function without prototype needs register info manually set: %s\n", PrintableName.GetChars()); return; } assert(Proto->isPrototype()); diff --git a/source/core/console/c_notifybuffer.cpp b/source/core/console/c_notifybuffer.cpp index 542ec5306..ff1c8869f 100644 --- a/source/core/console/c_notifybuffer.cpp +++ b/source/core/console/c_notifybuffer.cpp @@ -110,8 +110,8 @@ void FNotifyBuffer::DrawNative() // * top left for Exhumed // * 4 lines with the tiny font for Blood. (same mechanic as the regular one, just a different font and scale.) - bool center = g_gameType & (GAMEFLAG_DUKE | GAMEFLAG_NAM | GAMEFLAG_WW2GI | GAMEFLAG_RR | GAMEFLAG_SW); - bool pulse = g_gameType & (GAMEFLAG_DUKE | GAMEFLAG_NAM | GAMEFLAG_WW2GI | GAMEFLAG_RR); + bool center = g_gameType & (GAMEFLAG_DUKE | GAMEFLAG_NAM | GAMEFLAG_WW2GI | GAMEFLAG_RRALL | GAMEFLAG_SW); + bool pulse = g_gameType & (GAMEFLAG_DUKE | GAMEFLAG_NAM | GAMEFLAG_WW2GI | GAMEFLAG_RRALL); unsigned topline = g_gameType & GAMEFLAG_BLOOD ? 0 : Text.Size() - 1; FFont* font = g_gameType & GAMEFLAG_BLOOD ? SmallFont2 : SmallFont; diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index e027ad190..aaec5e095 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -21,6 +21,7 @@ extern bool GUICapture; extern bool AppActive; extern cycle_t drawtime, actortime, thinktime, gameupdatetime; extern bool r_NoInterpolate; +extern bool crouch_toggle; struct MapRecord; extern MapRecord* g_nextmap; diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index aba636e72..0e771b16e 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -133,8 +133,8 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn // process remaining controller input. currInput->horz -= scaleAdjust * hidInput->dpitch * hidspeed; - currInput->svel -= xs_CRoundToInt(scaleAdjust * hidInput->dx * keymove * cntrlvelscale); - currInput->fvel -= xs_CRoundToInt(scaleAdjust * hidInput->dz * keymove * cntrlvelscale); + currInput->svel += xs_CRoundToInt(scaleAdjust * hidInput->dx * keymove * cntrlvelscale); + currInput->fvel += xs_CRoundToInt(scaleAdjust * hidInput->dz * keymove * cntrlvelscale); // process keyboard turning keys. if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe) @@ -298,7 +298,7 @@ void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double // //--------------------------------------------------------------------------- -void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching) +void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust) { // return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->rotscrnang.asbam() * (15. / GameTicRate))); @@ -335,7 +335,7 @@ void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double if (angle->spin.asbam() < 0) { // return spin to 0 - lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate) * BAMUNIT)); + lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate) * BAMUNIT)); angle->spin += add; if (angle->spin.asbam() > 0) { diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 097db9406..f6e186665 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -199,6 +199,5 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, Pl FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def); void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1); -void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust); -void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching); - +void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust = 1); +void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust = 1); diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index ce88497f4..ca660482f 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -46,7 +46,7 @@ static int WeaponToSend = 0; ESyncBits ActionsToSend = 0; static int dpad_lock = 0; bool sendPause; - +bool crouch_toggle; static double lastCheck; CVAR(Float, m_pitch, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) // Mouse speeds @@ -120,6 +120,7 @@ void InputState::ClearAllInput() WeaponToSend = 0; dpad_lock = 0; lastCheck = 0; + crouch_toggle = false; buttonMap.ResetButtonStates(); // this is important. If all input is cleared, the buttons must be cleared as well. gi->clearlocalinputstate(); // also clear game local input state. } @@ -182,8 +183,8 @@ ControlInfo CONTROL_GetInput() I_GetAxes(joyaxes); hidInput.dyaw += -joyaxes[JOYAXIS_Yaw]; - hidInput.dx += -joyaxes[JOYAXIS_Side] * .5f; - hidInput.dz += -joyaxes[JOYAXIS_Forward] * .5f; + hidInput.dx += joyaxes[JOYAXIS_Side] * .5f; + hidInput.dz += joyaxes[JOYAXIS_Forward] * .5f; hidInput.dpitch += -joyaxes[JOYAXIS_Pitch]; } @@ -327,8 +328,7 @@ CCMD(pause) } - -void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput) +void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput, bool const crouchable, bool const disableToggle) { if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend); WeaponToSend = 0; @@ -366,9 +366,18 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput) if (buttonMap.ButtonDown(gamefunc_Jump)) input.actions |= SB_JUMP; - if (buttonMap.ButtonDown(gamefunc_Crouch)) + if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || crouch_toggle) input.actions |= SB_CROUCH; + if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) + { + crouch_toggle = !crouch_toggle && crouchable; + if (crouchable) buttonMap.ClearButton(gamefunc_Toggle_Crouch); + } + + if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || disableToggle) + crouch_toggle = false; + if (buttonMap.ButtonDown(gamefunc_Fire)) input.actions |= SB_FIRE; diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 028ac7a70..e37eb447e 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -102,6 +102,6 @@ enum GameFunction_t }; void SetupGameButtons(); -void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput); +void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput, bool const crouchable = true, bool const disableToggle = false); extern ESyncBits ActionsToSend; double InputScale(); diff --git a/source/core/menu/razemenu.cpp b/source/core/menu/razemenu.cpp index 71f02aa97..7c236694d 100644 --- a/source/core/menu/razemenu.cpp +++ b/source/core/menu/razemenu.cpp @@ -399,7 +399,8 @@ static void BuildEpisodeMenu() addedVolumes++; if (gVolumeSubtitles[i].IsNotEmpty()) { - auto it = CreateListMenuItemStaticText(ld->mXpos, y, gVolumeSubtitles[i], SmallFont, CR_GRAY, false); + auto it = CreateCustomListMenuItemText(ld->mXpos, y, ld->mLinespacing * 6 / 10, 1, + gVolumeSubtitles[i], SmallFont, CR_GRAY, false, NAME_None, i); y += ld->mLinespacing * 6 / 10; ld->mItems.Push(it); } diff --git a/source/core/packet.h b/source/core/packet.h index 2c169ee53..af295a503 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -25,8 +25,7 @@ enum ESyncBits_ : uint32_t SB_OPEN = 1 << 17, SB_AIMMODE = 1 << 18, - SB_QUICK_KICK = 1 << 19, // Duke only. - SB_CROUCH_LOCK = 1 << 19, // SW only. + SB_QUICK_KICK = 1 << 19, SB_FLYDOWN = 1 << 19, // WH only. SB_ESCAPE = 1 << 20, // Duke only SB_SPELL = 1 << 20, // WH only diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 75b5b2f4a..66694dc1d 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -75,6 +75,21 @@ CVAR(String, cl_savedir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // //============================================================================= +static void SerializeGlobals(FSerializer& arc) +{ + if (arc.BeginObject("globals")) + { + arc("crouch_toggle", crouch_toggle) + .EndObject(); + } +} + +//============================================================================= +// +// +// +//============================================================================= + static void SerializeSession(FSerializer& arc) { SerializeMap(arc); @@ -85,6 +100,7 @@ static void SerializeSession(FSerializer& arc) S_SerializeSounds(arc); SerializeAutomap(arc); SerializeHud(arc); + SerializeGlobals(arc); } //============================================================================= diff --git a/source/exhumed/src/bullet.cpp b/source/exhumed/src/bullet.cpp index 03188dbf3..ab85f85bf 100644 --- a/source/exhumed/src/bullet.cpp +++ b/source/exhumed/src/bullet.cpp @@ -496,7 +496,7 @@ HITWALL: } // draws bullet puff on walls when they're shot - BuildAnim(-1, pBulletInfo->field_C, 0, x2, y2, z2 + zOffset, hitsect, 40, pBulletInfo->nFlags); + BuildAnim(-1, pBulletInfo->field_C, 0, x2, y2, z2 + zOffset + -4096, hitsect, 40, pBulletInfo->nFlags); } } else diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 212e67010..83f721232 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -403,7 +403,7 @@ void GameInterface::Ticker() if (weap2 == WeaponSel_Next) { auto newWeap = currWeap == 6 ? 0 : currWeap + 1; - while (!(nPlayerWeapons[nLocalPlayer] & (1 << newWeap))) + while (!(nPlayerWeapons[nLocalPlayer] & (1 << newWeap)) || (nPlayerWeapons[nLocalPlayer] & (1 << newWeap) && PlayerList[nLocalPlayer].nAmmo[newWeap] == 0)) { newWeap++; } @@ -412,7 +412,7 @@ void GameInterface::Ticker() else if (weap2 == WeaponSel_Prev) { auto newWeap = currWeap == 0 ? 6 : currWeap - 1; - while (!(nPlayerWeapons[nLocalPlayer] & (1 << newWeap))) + while (!(nPlayerWeapons[nLocalPlayer] & (1 << newWeap)) || (nPlayerWeapons[nLocalPlayer] & (1 << newWeap) && PlayerList[nLocalPlayer].nAmmo[newWeap] == 0)) { newWeap--; } diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index e803281a3..2158f9c35 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -106,6 +106,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN; } + Player* pPlayer = &PlayerList[nLocalPlayer]; double const scaleAdjust = InputScale(); InputPacket input {}; @@ -121,11 +122,9 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) if (!cl_syncinput) { - Player* pPlayer = &PlayerList[nLocalPlayer]; - if (!nFreeze) { - applylook(&pPlayer->angle, input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080); + applylook(&pPlayer->angle, input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); sethorizon(&pPlayer->horizon.horiz, input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); } diff --git a/source/exhumed/src/menu.cpp b/source/exhumed/src/menu.cpp index 140087c71..d943c4855 100644 --- a/source/exhumed/src/menu.cpp +++ b/source/exhumed/src/menu.cpp @@ -85,7 +85,7 @@ void DoEnergyTile() auto energy1 = TileFiles.tileMakeWritable(kEnergy1); auto energy2 = TileFiles.tileMakeWritable(kEnergy2); uint8_t* ptr1 = energy1 + 1984; - uint8_t* ptr2 = energy2 + 2048; + uint8_t* ptr2 = energy1 + 2048; short nColor = nButtonColor + 161; diff --git a/source/exhumed/src/object.cpp b/source/exhumed/src/object.cpp index 4beda230f..a8017346b 100644 --- a/source/exhumed/src/object.cpp +++ b/source/exhumed/src/object.cpp @@ -1347,7 +1347,7 @@ int BuildSpark(int nSprite, int nVal) if (var_14 < 0) { return -1; } - auto spr = &sprite[nSprite]; + auto spr = &sprite[var_14]; assert(var_14 < kMaxSprites); diff --git a/source/exhumed/src/player.cpp b/source/exhumed/src/player.cpp index 632d46a59..f3725f8e0 100644 --- a/source/exhumed/src/player.cpp +++ b/source/exhumed/src/player.cpp @@ -921,7 +921,7 @@ void FuncPlayer(int a, int nDamage, int nRun) if (cl_syncinput) { Player* pPlayer = &PlayerList[nPlayer]; - applylook(&pPlayer->angle, sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions, 1, eyelevel[nLocalPlayer] > -14080); + applylook(&pPlayer->angle, sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions); UpdatePlayerSpriteAngle(pPlayer); } @@ -2640,7 +2640,7 @@ loc_1BD2E: if (cl_syncinput) { Player* pPlayer = &PlayerList[nPlayer]; - sethorizon(&pPlayer->horizon.horiz, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions, 1); + sethorizon(&pPlayer->horizon.horiz, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions); } } else // else, player's health is less than 0 diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 92631ed26..a23eb31fd 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -48,7 +48,7 @@ This file is a combination of code from the following sources: BEGIN_DUKE_NS -int adjustfall(spritetype* s, int c); +int adjustfall(DDukeActor* s, int c); //--------------------------------------------------------------------------- @@ -182,7 +182,7 @@ void checkavailweapon(struct player_struct* player) { SetGameVarID(g_iWorksLikeVarID, -1, player->GetActor(), snum); } - OnEvent(EVENT_CHANGEWEAPON, snum, player->i, -1); + OnEvent(EVENT_CHANGEWEAPON, snum, player->GetActor(), -1); } player->okickback_pic = player->kickback_pic = 0; @@ -202,13 +202,12 @@ void checkavailweapon(struct player_struct* player) void clearcamera(player_struct* ps) { - ps->newowner = -1; + ps->newOwner = nullptr; ps->posx = ps->oposx; ps->posy = ps->oposy; ps->posz = ps->oposz; ps->angle.restore(); updatesector(ps->posx, ps->posy, &ps->cursectnum); - setpal(ps); DukeStatIterator it(STAT_ACTOR); while (auto k = it.Next()) @@ -371,7 +370,7 @@ void movedummyplayers(void) if ((!isRR() && ps[p].on_crane != nullptr) || sector[ps[p].cursectnum].lotag != 1 || ps->GetActor()->s.extra <= 0) { - ps[p].dummyplayersprite = -1; + ps[p].dummyplayersprite = nullptr; deletesprite(act); continue; } @@ -417,7 +416,7 @@ void moveplayers(void) auto spri = &act->s; if (act->GetOwner()) { - if (p->newowner >= 0) //Looking thru the camera + if (p->newOwner != nullptr) //Looking thru the camera { spri->x = p->oposx; spri->y = p->oposy; @@ -482,7 +481,7 @@ void moveplayers(void) p->posy = spri->y; p->posz = spri->z - (20 << 8); - p->newowner = -1; + p->newOwner = nullptr; if (p->wackedbyactor != nullptr && p->wackedbyactor->s.statnum < MAXSTATUS) { @@ -715,7 +714,7 @@ void movecrane(DDukeActor *actor, int crane) ps[p].on_crane = nullptr; } t[0]++; - actor->SetOwner(nullptr); + actor->SetActiveCrane(false); } } } @@ -778,7 +777,6 @@ void movecrane(DDukeActor *actor, int crane) if (spri->xvel < 192) spri->xvel += 8; spri->ang = getangle(msx[t[4]] - spri->x, msy[t[4]] - spri->y); - //IFMOVING; // JBF 20040825: see my rant above about this ssp(actor, CLIPMASK0); if (((spri->x - msx[t[4]]) * (spri->x - msx[t[4]]) + (spri->y - msy[t[4]]) * (spri->y - msy[t[4]])) < (128 * 128)) t[0]++; @@ -787,10 +785,10 @@ void movecrane(DDukeActor *actor, int crane) else if (t[0] == 9) t[0] = 0; - setsprite(msy[t[4] + 2], spri->x, spri->y, spri->z - (34 << 8)); + setsprite(ScriptIndexToActor(msy[t[4] + 2]), spri->x, spri->y, spri->z - (34 << 8)); auto Owner = actor->GetOwner(); - if (Owner != nullptr) + if (Owner != nullptr || actor->IsActiveCrane()) { int p = findplayer(actor, &x); @@ -805,14 +803,13 @@ void movecrane(DDukeActor *actor, int crane) return; } - auto a_owner = actor->GetOwner(); - if (a_owner != nullptr) + if (Owner != nullptr) { - setsprite(a_owner, spri->pos); + setsprite(Owner, spri->pos); - a_owner->bposx = spri->x; - a_owner->bposy = spri->y; - a_owner->bposz = spri->z; + Owner->bposx = spri->x; + Owner->bposy = spri->y; + Owner->bposz = spri->z; spri->zvel = 0; } @@ -837,10 +834,9 @@ void movecrane(DDukeActor *actor, int crane) // //--------------------------------------------------------------------------- -void movefountain(int i, int fountain) +void movefountain(DDukeActor *actor, int fountain) { - auto t = &hittype[i].temp_data[0]; - auto s = &sprite[i]; + int* t = &actor->temp_data[0]; int x; if (t[0] > 0) { @@ -848,19 +844,19 @@ void movefountain(int i, int fountain) { t[0]++; - s->picnum++; + actor->s.picnum++; - if (s->picnum == fountain + 3) - s->picnum = fountain + 1; + if (actor->s.picnum == fountain + 3) + actor->s.picnum = fountain + 1; } else { - findplayer(s, &x); + findplayer(actor, &x); if (x > 512) { t[0] = 0; - s->picnum = fountain; + actor->s.picnum = fountain; } else t[0] = 1; } @@ -872,53 +868,52 @@ void movefountain(int i, int fountain) // //--------------------------------------------------------------------------- -void moveflammable(int i, int tire, int box, int pool) +void moveflammable(DDukeActor* actor, int tire, int box, int pool) { - auto s = &sprite[i]; - auto ht = &hittype[i]; + auto spri = &actor->s; int j; - if (ht->temp_data[0] == 1) + if (actor->temp_data[0] == 1) { - ht->temp_data[1]++; - if ((ht->temp_data[1] & 3) > 0) return; + actor->temp_data[1]++; + if ((actor->temp_data[1] & 3) > 0) return; - if (!isRR() && s->picnum == tire && ht->temp_data[1] == 32) + if (!isRR() && spri->picnum == tire && actor->temp_data[1] == 32) { - s->cstat = 0; - j = fi.spawn(i, pool); - sprite[j].shade = 127; + spri->cstat = 0; + auto spawned = spawn(actor, pool); + spawned->s.shade = 127; } else { - if (s->shade < 64) s->shade++; + if (spri->shade < 64) spri->shade++; else { - deletesprite(i); + deletesprite(actor); return; } } - j = s->xrepeat - (krand() & 7); + j = spri->xrepeat - (krand() & 7); if (j < 10) { - deletesprite(i); + deletesprite(actor); return; } - s->xrepeat = j; + spri->xrepeat = j; - j = s->yrepeat - (krand() & 7); + j = spri->yrepeat - (krand() & 7); if (j < 4) { - deletesprite(i); + deletesprite(actor); return; } - s->yrepeat = j; + spri->yrepeat = j; } - if (box >= 0 && s->picnum == box) + if (box >= 0 && spri->picnum == box) { - makeitfall(i); - ht->ceilingz = sector[s->sectnum].ceilingz; + makeitfall(actor); + actor->ceilingz = sector[spri->sectnum].ceilingz; } } @@ -929,52 +924,49 @@ void moveflammable(int i, int tire, int box, int pool) // //--------------------------------------------------------------------------- -void detonate(int i, int explosion) +void detonate(DDukeActor *actor, int explosion) { - auto s = &sprite[i]; - auto ht = &hittype[i]; - auto t = &hittype[i].temp_data[0]; + auto spri = &actor->s; + int* t = &actor->temp_data[0]; earthquaketime = 16; - int j; - StatIterator itj(STAT_EFFECTOR); - while ((j = itj.NextIndex()) >= 0) + DukeStatIterator itj(STAT_EFFECTOR); + while (auto effector = itj.Next()) { - auto sj = &sprite[j]; - auto htj = &hittype[j]; - if (s->hitag == sj->hitag) + auto sj = &effector->s; + if (actor->s.hitag == sj->hitag) { if (sj->lotag == SE_13_EXPLOSIVE) { - if (htj->temp_data[2] == 0) - htj->temp_data[2] = 1; + if (effector->temp_data[2] == 0) + effector->temp_data[2] = 1; } else if (sj->lotag == SE_8_UP_OPEN_DOOR_LIGHTS) - htj->temp_data[4] = 1; + effector->temp_data[4] = 1; else if (sj->lotag == SE_18_INCREMENTAL_SECTOR_RISE_FALL) { - if (htj->temp_data[0] == 0) - htj->temp_data[0] = 1; + if (effector->temp_data[0] == 0) + effector->temp_data[0] = 1; } else if (sj->lotag == SE_21_DROP_FLOOR) - htj->temp_data[0] = 1; + effector->temp_data[0] = 1; } } - s->z -= (32 << 8); + spri->z -= (32 << 8); - if ((t[3] == 1 && s->xrepeat) || s->lotag == -99) + if ((t[3] == 1 && spri->xrepeat) || spri->lotag == -99) { - int x = s->extra; - fi.spawn(i, explosion); - fi.hitradius(i, seenineblastradius, x >> 2, x - (x >> 1), x - (x >> 2), x); - S_PlayActorSound(PIPEBOMB_EXPLODE, i); + int x = spri->extra; + spawn(actor, explosion); + fi.hitradius(actor, seenineblastradius, x >> 2, x - (x >> 1), x - (x >> 2), x); + S_PlayActorSound(PIPEBOMB_EXPLODE, actor); } - if (s->xrepeat) - for (int x = 0; x < 8; x++) RANDOMSCRAP(s, i); + if (spri->xrepeat) + for (int x = 0; x < 8; x++) RANDOMSCRAP(actor); - deletesprite(i); + deletesprite(actor); } @@ -984,23 +976,21 @@ void detonate(int i, int explosion) // //--------------------------------------------------------------------------- -void movemasterswitch(int i, int spectype1, int spectype2) +void movemasterswitch(DDukeActor *actor, int spectype1, int spectype2) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - if (s->yvel == 1) + auto spri = &actor->s; + if (spri->yvel == 1) { - s->hitag--; - if (s->hitag <= 0) + spri->hitag--; + if (spri->hitag <= 0) { - operatesectors(s->sectnum, i); + operatesectors(spri->sectnum, actor); - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(spri->sectnum); + while (auto effector = it.Next()) { - auto sj = &sprite[j]; - if (sj->statnum == 3) + auto sj = &effector->s; + if (sj->statnum == STAT_EFFECTOR) { switch (sj->lotag) { @@ -1009,10 +999,10 @@ void movemasterswitch(int i, int spectype1, int spectype2) case SE_31_FLOOR_RISE_FALL: case SE_32_CEILING_RISE_FALL: case SE_36_PROJ_SHOOTER: - hittype[j].temp_data[0] = 1; + effector->temp_data[0] = 1; break; case SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT: - hittype[j].temp_data[4] = 1; + effector->temp_data[4] = 1; break; } } @@ -1024,7 +1014,7 @@ void movemasterswitch(int i, int spectype1, int spectype2) } } } - deletesprite(i); + deletesprite(actor); } } } @@ -1035,18 +1025,18 @@ void movemasterswitch(int i, int spectype1, int spectype2) // //--------------------------------------------------------------------------- -void movetrash(int i) +void movetrash(DDukeActor *actor) { - auto s = &sprite[i]; + auto s = &actor->s; if (s->xvel == 0) s->xvel = 1; - if (ssp(i, CLIPMASK0)) + if (ssp(actor, CLIPMASK0)) { - makeitfall(i); + makeitfall(actor); if (krand() & 1) s->zvel -= 256; if (abs(s->xvel) < 48) s->xvel += (krand() & 3); } - else deletesprite(i); + else deletesprite(actor); } //--------------------------------------------------------------------------- @@ -1055,10 +1045,10 @@ void movetrash(int i) // //--------------------------------------------------------------------------- -void movewaterdrip(int i, int drip) +void movewaterdrip(DDukeActor *actor, int drip) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int sect = s->sectnum; if (t[1]) @@ -1069,8 +1059,8 @@ void movewaterdrip(int i, int drip) } else { - makeitfall(i); - ssp(i, CLIPMASK0); + makeitfall(actor); + ssp(actor, CLIPMASK0); if (s->xvel > 0) s->xvel -= 2; if (s->zvel == 0) @@ -1078,15 +1068,16 @@ void movewaterdrip(int i, int drip) s->cstat |= 32768; if (s->pal != 2 && (isRR() || s->hitag == 0)) - S_PlayActorSound(SOMETHING_DRIPPING, i); + S_PlayActorSound(SOMETHING_DRIPPING, actor); - if (sprite[s->owner].picnum != drip) + auto Owner = actor->GetOwner(); + if (!Owner || Owner->s.picnum != drip) { - deletesprite(i); + deletesprite(actor); } else { - hittype[i].bposz = s->z = t[0]; + actor->bposz = s->z = t[0]; t[1] = 48 + (krand() & 31); } } @@ -1099,9 +1090,9 @@ void movewaterdrip(int i, int drip) // //--------------------------------------------------------------------------- -void movedoorshock(int i) +void movedoorshock(DDukeActor* actor) { - auto s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int j = abs(sector[sect].ceilingz - sector[sect].floorz) >> 9; s->yrepeat = j + 4; @@ -1115,10 +1106,10 @@ void movedoorshock(int i) // //--------------------------------------------------------------------------- -void movetouchplate(int i, int plate) +void movetouchplate(DDukeActor* actor, int plate) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int sect = s->sectnum; int x; int p; @@ -1182,14 +1173,13 @@ void movetouchplate(int i, int plate) if (t[1] == 1) { - StatIterator it(STAT_STANDABLE); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto act2 = it.Next()) { - if (j != i && sprite[j].picnum == plate && sprite[j].lotag == s->lotag) + if (act2 != actor && act2->s.picnum == plate && act2->s.lotag == s->lotag) { - hittype[j].temp_data[1] = 1; - hittype[j].temp_data[3] = t[3]; + act2->temp_data[1] = 1; + act2->temp_data[3] = t[3]; } } } @@ -1201,15 +1191,15 @@ void movetouchplate(int i, int plate) // //--------------------------------------------------------------------------- -void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion) +void moveooz(DDukeActor* actor, int seenine, int seeninedead, int ooz, int explosion) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int j; if (s->shade != -32 && s->shade != -33) { if (s->xrepeat) - j = (fi.ifhitbyweapon(&hittype[i]) >= 0); + j = (fi.ifhitbyweapon(actor) >= 0); else j = 0; @@ -1219,11 +1209,10 @@ void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion) t[3] = 1; - StatIterator it(STAT_STANDABLE); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto act2 = it.Next()) { - auto ss = &sprite[j]; + auto ss = &act2->s; if (s->hitag == ss->hitag && (ss->picnum == seenine || ss->picnum == ooz)) ss->shade = -32; } @@ -1245,18 +1234,18 @@ void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion) { if (s->xrepeat > 0) { - hittype[i].temp_data[2]++; - if (hittype[i].temp_data[2] == 3) + actor->temp_data[2]++; + if (actor->temp_data[2] == 3) { if (s->picnum == ooz) { - hittype[i].temp_data[2] = 0; - detonate(i, explosion); + actor->temp_data[2] = 0; + detonate(actor, explosion); return; } if (s->picnum != (seeninedead + 1)) { - hittype[i].temp_data[2] = 0; + actor->temp_data[2] = 0; if (s->picnum == seeninedead) s->picnum++; else if (s->picnum == seenine) @@ -1264,13 +1253,13 @@ void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion) } else { - detonate(i, explosion); + detonate(actor, explosion); return; } } return; } - detonate(i, explosion); + detonate(actor, explosion); return; } } @@ -1282,20 +1271,18 @@ void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion) // //--------------------------------------------------------------------------- -void movecanwithsomething(int i) +void movecanwithsomething(DDukeActor* actor) { - auto s = &sprite[i]; - makeitfall(i); - int j = fi.ifhitbyweapon(&hittype[i]); + makeitfall(actor); + int j = fi.ifhitbyweapon(actor); if (j >= 0) { - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, actor); for (j = 0; j < 10; j++) - RANDOMSCRAP(s, i); + RANDOMSCRAP(actor); - if (s->lotag) fi.spawn(i, s->lotag); - - deletesprite(i); + if (actor->s.lotag) spawn(actor, actor->s.lotag); + deletesprite(actor); } } @@ -1305,29 +1292,27 @@ void movecanwithsomething(int i) // //--------------------------------------------------------------------------- -void bounce(int i) +void bounce(DDukeActor* actor) { - int k, l, daang, dax, day, daz, xvect, yvect, zvect; - int hitsect; - spritetype* s = &sprite[i]; + auto s = &actor->s; + int xvect = mulscale10(s->xvel, sintable[(s->ang + 512) & 2047]); + int yvect = mulscale10(s->xvel, sintable[s->ang & 2047]); + int zvect = s->zvel; - xvect = mulscale10(s->xvel, sintable[(s->ang + 512) & 2047]); - yvect = mulscale10(s->xvel, sintable[s->ang & 2047]); - zvect = s->zvel; + int hitsect = s->sectnum; - hitsect = s->sectnum; + int k = sector[hitsect].wallptr; + int l = wall[k].point2; + int daang = getangle(wall[l].x - wall[k].x, wall[l].y - wall[k].y); - k = sector[hitsect].wallptr; l = wall[k].point2; - daang = getangle(wall[l].x - wall[k].x, wall[l].y - wall[k].y); - - if (s->z < (hittype[i].floorz + hittype[i].ceilingz) >> 1) + if (s->z < (actor->floorz + actor->ceilingz) >> 1) k = sector[hitsect].ceilingheinum; else k = sector[hitsect].floorheinum; - dax = mulscale14(k, sintable[(daang) & 2047]); - day = mulscale14(k, sintable[(daang + 1536) & 2047]); - daz = 4096; + int dax = mulscale14(k, sintable[(daang) & 2047]); + int day = mulscale14(k, sintable[(daang + 1536) & 2047]); + int daz = 4096; k = xvect * dax + yvect * day + zvect * daz; l = dax * dax + day * day + daz * daz; @@ -1350,49 +1335,57 @@ void bounce(int i) // //--------------------------------------------------------------------------- -void movetongue(int i, int tongue, int jaw) +void movetongue(DDukeActor *actor, int tongue, int jaw) { - spritetype* s = &sprite[i]; - - hittype[i].temp_data[0] = sintable[(hittype[i].temp_data[1]) & 2047] >> 9; - hittype[i].temp_data[1] += 32; - if (hittype[i].temp_data[1] > 2047) + auto s = &actor->s; + actor->temp_data[0] = sintable[(actor->temp_data[1]) & 2047] >> 9; + actor->temp_data[1] += 32; + if (actor->temp_data[1] > 2047) { - deletesprite(i); + deletesprite(actor); return; } - if (sprite[s->owner].statnum == MAXSTATUS) - if (badguy(&sprite[s->owner]) == 0) + auto Owner = actor->GetOwner(); + if (!Owner) return; + + if (Owner->s.statnum == MAXSTATUS) + if (badguy(Owner) == 0) { - deletesprite(i); + deletesprite(actor); return; } - s->ang = sprite[s->owner].ang; - s->x = sprite[s->owner].x; - s->y = sprite[s->owner].y; - if (sprite[s->owner].picnum == TILE_APLAYER) - s->z = sprite[s->owner].z - (34 << 8); - for (int k = 0; k < hittype[i].temp_data[0]; k++) + s->ang = Owner->s.ang; + s->x = Owner->s.x; + s->y = Owner->s.y; + if (Owner->s.picnum == TILE_APLAYER) + s->z = Owner->s.z - (34 << 8); + for (int k = 0; k < actor->temp_data[0]; k++) { - int q = EGS(s->sectnum, + auto q = EGS(s->sectnum, s->x + ((k * sintable[(s->ang + 512) & 2047]) >> 9), s->y + ((k * sintable[s->ang & 2047]) >> 9), s->z + ((k * ksgn(s->zvel)) * abs(s->zvel / 12)), tongue, -40 + (k << 1), - 8, 8, 0, 0, 0, i, 5); - sprite[q].cstat = 128; - sprite[q].pal = 8; + 8, 8, 0, 0, 0, actor, 5); + if (q) + { + q->s.cstat = 128; + q->s.pal = 8; } - int k = hittype[i].temp_data[0]; // do not depend on the above loop counter. - int q = EGS(s->sectnum, + } + int k = actor->temp_data[0]; // do not depend on the above loop counter. + auto spawned = EGS(s->sectnum, s->x + ((k * sintable[(s->ang + 512) & 2047]) >> 9), s->y + ((k * sintable[s->ang & 2047]) >> 9), s->z + ((k * ksgn(s->zvel)) * abs(s->zvel / 12)), jaw, -40, - 32, 32, 0, 0, 0, i, 5); - sprite[q].cstat = 128; - if (hittype[i].temp_data[1] > 512 && hittype[i].temp_data[1] < (1024)) - sprite[q].picnum = jaw + 1; + 32, 32, 0, 0, 0, actor, 5); + if (spawned) + { + spawned->s.cstat = 128; + if (actor->temp_data[1] > 512 && actor->temp_data[1] < (1024)) + spawned->s.picnum = jaw + 1; + } } //--------------------------------------------------------------------------- @@ -1401,40 +1394,39 @@ void movetongue(int i, int tongue, int jaw) // //--------------------------------------------------------------------------- -void rpgexplode(int i, int j, const vec3_t &pos, int EXPLOSION2, int EXPLOSION2BOT, int newextra, int playsound) +void rpgexplode(DDukeActor *actor, int hit, const vec3_t &pos, int EXPLOSION2, int EXPLOSION2BOT, int newextra, int playsound) { - auto act = &hittype[i]; - auto s = &act->s; - auto k = spawn(act, EXPLOSION2); - k->s.pos = pos; + auto s = &actor->s; + auto explosion = spawn(actor, EXPLOSION2); + explosion->s.pos = pos; if (s->xrepeat < 10) { - k->s.xrepeat = 6; - k->s.yrepeat = 6; + explosion->s.xrepeat = 6; + explosion->s.yrepeat = 6; } - else if ((j & kHitTypeMask) == kHitSector) + else if (hit == kHitSector) { if (s->zvel > 0 && EXPLOSION2BOT >= 0) - fi.spawn(i, EXPLOSION2BOT); + spawn(actor, EXPLOSION2BOT); else { - k->s.cstat |= 8; - k->s.z += (48 << 8); + explosion->s.cstat |= 8; + explosion->s.z += (48 << 8); } } if (newextra > 0) s->extra = newextra; - S_PlayActorSound(playsound, i); + S_PlayActorSound(playsound, actor); if (s->xrepeat >= 10) { int x = s->extra; - fi.hitradius(i, rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x); + fi.hitradius(actor, rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x); } else { int x = s->extra + (global_random & 3); - fi.hitradius(i, (rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x); + fi.hitradius(actor, (rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x); } } @@ -1444,19 +1436,19 @@ void rpgexplode(int i, int j, const vec3_t &pos, int EXPLOSION2, int EXPLOSION2B // //--------------------------------------------------------------------------- -bool respawnmarker(int i, int yellow, int green) +bool respawnmarker(DDukeActor *actor, int yellow, int green) { - hittype[i].temp_data[0]++; - if (hittype[i].temp_data[0] > respawnitemtime) + actor->temp_data[0]++; + if (actor->temp_data[0] > respawnitemtime) { - deletesprite(i); + deletesprite(actor); return false; } - if (hittype[i].temp_data[0] >= (respawnitemtime >> 1) && hittype[i].temp_data[0] < ((respawnitemtime >> 1) + (respawnitemtime >> 2))) - sprite[i].picnum = yellow; - else if (hittype[i].temp_data[0] > ((respawnitemtime >> 1) + (respawnitemtime >> 2))) - sprite[i].picnum = green; - makeitfall(i); + if (actor->temp_data[0] >= (respawnitemtime >> 1) && actor->temp_data[0] < ((respawnitemtime >> 1) + (respawnitemtime >> 2))) + actor->s.picnum = yellow; + else if (actor->temp_data[0] > ((respawnitemtime >> 1) + (respawnitemtime >> 2))) + actor->s.picnum = green; + makeitfall(actor); return true; } @@ -1466,21 +1458,21 @@ bool respawnmarker(int i, int yellow, int green) // //--------------------------------------------------------------------------- -bool rat(int i, bool makesound) +bool rat(DDukeActor* actor, bool makesound) { - spritetype* s = &sprite[i]; - makeitfall(i); - if (ssp(i, CLIPMASK0)) + auto s = &actor->s; + makeitfall(actor); + if (ssp(actor, CLIPMASK0)) { - if (makesound && (krand() & 255) == 0) S_PlayActorSound(RATTY, i); - s->ang += (krand() & 31) - 15 + (sintable[(hittype[i].temp_data[0] << 8) & 2047] >> 11); + if (makesound && (krand() & 255) == 0) S_PlayActorSound(RATTY, actor); + s->ang += (krand() & 31) - 15 + (sintable[(actor->temp_data[0] << 8) & 2047] >> 11); } else { - hittype[i].temp_data[0]++; - if (hittype[i].temp_data[0] > 1) + actor->temp_data[0]++; + if (actor->temp_data[0] > 1) { - deletesprite(i); + deletesprite(actor); return false; } else s->ang = (krand() & 2047); @@ -1497,43 +1489,40 @@ bool rat(int i, bool makesound) // //--------------------------------------------------------------------------- -bool queball(int i, int pocket, int queball, int stripeball) +bool queball(DDukeActor *actor, int pocket, int queball, int stripeball) { - spritetype* s = &sprite[i]; + auto s = &actor->s; if (s->xvel) { - StatIterator it(STAT_DEFAULT); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DEFAULT); + while (auto aa = it.Next()) { - if (sprite[j].picnum == pocket && ldist(&sprite[j], s) < 52) + if (aa->s.picnum == pocket && ldist(aa, actor) < 52) { - deletesprite(i); + deletesprite(actor); return false; } } - j = clipmove(&s->x, &s->y, &s->z, &s->sectnum, + Collision coll; + int j = clipmove_ex(&s->x, &s->y, &s->z, &s->sectnum, (((s->xvel * (sintable[(s->ang + 512) & 2047])) >> 14) * TICSPERFRAME) << 11, (((s->xvel * (sintable[s->ang & 2047])) >> 14) * TICSPERFRAME) << 11, - 24L, (4 << 8), (4 << 8), CLIPMASK1); + 24L, (4 << 8), (4 << 8), CLIPMASK1, coll); - if (j & 49152) + if (j == kHitWall) { - if ((j & 49152) == 32768) - { - j &= (MAXWALLS - 1); + j = coll.index; int k = getangle( wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y); s->ang = ((k << 1) - s->ang) & 2047; } - else if ((j & 49152) == 49152) - { - j &= (MAXSPRITES - 1); - fi.checkhitsprite(i, j); - } + else if (j == kHitSprite) + { + fi.checkhitsprite(actor, coll.actor); } + s->xvel--; if (s->xvel < 0) s->xvel = 0; if (s->picnum == stripeball) @@ -1546,34 +1535,33 @@ bool queball(int i, int pocket, int queball, int stripeball) else { int x; - int p = findplayer(s, &x); + int p = findplayer(actor, &x); if (x < 1596) { - // if(s->pal == 12) { int j = getincangle(ps[p].angle.ang.asbuild(), getangle(s->x - ps[p].posx, s->y - ps[p].posy)); if (j > -64 && j < 64 && PlayerInput(p, SB_OPEN)) if (ps[p].toggle_key_flag == 1) { - StatIterator it(STAT_ACTOR); - int a; - while ((a = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + DDukeActor *act2; + while ((act2 = it.Next())) { - auto sa = &sprite[a]; + auto sa = &act2->s; if (sa->picnum == queball || sa->picnum == stripeball) { j = getincangle(ps[p].angle.ang.asbuild(), getangle(sa->x - ps[p].posx, sa->y - ps[p].posy)); if (j > -64 && j < 64) { int l; - findplayer(sa, &l); + findplayer(act2, &l); if (x > l) break; } } } - if (a == -1) + if (act2 == nullptr) { if (s->pal == 12) s->xvel = 164; @@ -1599,11 +1587,10 @@ bool queball(int i, int pocket, int queball, int stripeball) // //--------------------------------------------------------------------------- -void forcesphere(int i, int forcesphere) +void forcesphere(DDukeActor* actor, int forcesphere) { - auto act = &hittype[i]; - auto s = &act->s; - auto t = &act->temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int sect = s->sectnum; if (s->yvel == 0) { @@ -1612,13 +1599,13 @@ void forcesphere(int i, int forcesphere) for (int l = 512; l < (2048 - 512); l += 128) for (int j = 0; j < 2048; j += 128) { - auto k = spawn(act, forcesphere); + auto k = spawn(actor, forcesphere); k->s.cstat = 257 + 128; k->s.clipdist = 64; k->s.ang = j; k->s.zvel = sintable[l & 2047] >> 5; k->s.xvel = sintable[(l + 512) & 2047] >> 9; - k->s.owner = i; + k->SetOwner(actor); } } @@ -1632,17 +1619,16 @@ void forcesphere(int i, int forcesphere) t[3]--; if (t[3] == 0) { - deletesprite(i); + deletesprite(actor); return; } else if (t[2] > 10) { - StatIterator it(STAT_MISC); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto aa = it.Next()) { - if (sprite[j].owner == i && sprite[j].picnum == forcesphere) - hittype[j].temp_data[1] = 1 + (krand() & 63); + if (aa->GetOwner() == actor && aa->s.picnum == forcesphere) + aa->temp_data[1] = 1 + (krand() & 63); } t[3] = 64; } @@ -1655,14 +1641,14 @@ void forcesphere(int i, int forcesphere) // //--------------------------------------------------------------------------- -void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int roamsnd, int shift, int (*getspawn)(int i)) +void recon(DDukeActor *actor, int explosion, int firelaser, int attacksnd, int painsnd, int roamsnd, int shift, int (*getspawn)(DDukeActor* i)) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int sect = s->sectnum; - int j, a; + int a; - getglobalz(i); + getglobalz(actor); if (sector[s->sectnum].ceilingstat & 1) s->shade += (sector[s->sectnum].ceilingshade - s->shade) >> 1; @@ -1680,47 +1666,47 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int } else if (actor_tog == 2) s->cstat = 257; } - j = fi.ifhitbyweapon(&hittype[i]); if (j >= 0) + if (fi.ifhitbyweapon(actor) >= 0) { if (s->extra < 0 && t[0] != -1) { t[0] = -1; s->extra = 0; } - if (painsnd >= 0) S_PlayActorSound(painsnd, i); - RANDOMSCRAP(s, i); + if (painsnd >= 0) S_PlayActorSound(painsnd, actor); + RANDOMSCRAP(actor); } if (t[0] == -1) { s->z += 1024; t[2]++; - if ((t[2] & 3) == 0) fi.spawn(i, explosion); - getglobalz(i); + if ((t[2] & 3) == 0) spawn(actor, explosion); + getglobalz(actor); s->ang += 96; s->xvel = 128; - j = ssp(i, CLIPMASK0); - if (j != 1 || s->z > hittype[i].floorz) + int j = ssp(actor, CLIPMASK0); + if (j != 1 || s->z > actor->floorz) { for (int l = 0; l < 16; l++) - RANDOMSCRAP(s, i); - S_PlayActorSound(LASERTRIP_EXPLODE, i); - int sp = getspawn(i); - if (sp >= 0) fi.spawn(i, sp); + RANDOMSCRAP(actor); + S_PlayActorSound(LASERTRIP_EXPLODE, actor); + int sp = getspawn(actor); + if (sp >= 0) spawn(actor, sp); ps[myconnectindex].actors_killed++; - deletesprite(i); + deletesprite(actor); } return; } else { - if (s->z > hittype[i].floorz - (48 << 8)) - s->z = hittype[i].floorz - (48 << 8); + if (s->z > actor->floorz - (48 << 8)) + s->z = actor->floorz - (48 << 8); } int x; - int p = findplayer(s, &x); - j = s->owner; + int p = findplayer(actor, &x); + auto Owner = actor->GetOwner(); // 3 = findplayerz, 4 = shoot @@ -1730,9 +1716,9 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int if ((t[2] & 15) == 0) { a = s->ang; - s->ang = hittype[i].tempang; - if (attacksnd >= 0) S_PlayActorSound(attacksnd, i); - fi.shoot(i, firelaser); + s->ang = actor->tempang; + if (attacksnd >= 0) S_PlayActorSound(attacksnd, actor); + fi.shoot(actor, firelaser); s->ang = a; } if (t[2] > (26 * 3) || !cansee(s->x, s->y, s->z - (16 << 8), s->sectnum, ps[p].posx, ps[p].posy, ps[p].posz, ps[p].cursectnum)) @@ -1740,8 +1726,8 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int t[0] = 0; t[2] = 0; } - else hittype[i].tempang += - getincangle(hittype[i].tempang, getangle(ps[p].posx - s->x, ps[p].posy - s->y)) / 3; + else actor->tempang += + getincangle(actor->tempang, getangle(ps[p].posx - s->x, ps[p].posy - s->y)) / 3; } else if (t[0] == 2 || t[0] == 3) { @@ -1765,26 +1751,26 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int } else if ((t[2] & 15) == 0 && attacksnd >= 0) { - S_PlayActorSound(attacksnd, i); - fi.shoot(i, firelaser); + S_PlayActorSound(attacksnd, actor); + fi.shoot(actor, firelaser); } } s->ang += getincangle(s->ang, getangle(ps[p].posx - s->x, ps[p].posy - s->y)) >> 2; } - if (t[0] != 2 && t[0] != 3) + if (t[0] != 2 && t[0] != 3 && Owner) { - int l = ldist(&sprite[j], s); + int l = ldist(Owner, actor); if (l <= 1524) { a = s->ang; s->xvel >>= 1; } - else a = getangle(sprite[j].x - s->x, sprite[j].y - s->y); + else a = getangle(Owner->s.x - s->x, Owner->s.y - s->y); if (t[0] == 1 || t[0] == 4) // Found a locator and going with it { - l = dist(&sprite[j], s); + l = dist(Owner, actor); if (l <= 1524) { if (t[0] == 1) t[0] = 0; else t[0] = 5; } else @@ -1804,7 +1790,7 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int { t[0] = 2 + (krand() & 2); t[2] = 0; - hittype[i].tempang = s->ang; + actor->tempang = s->ang; } } @@ -1813,33 +1799,33 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int if (t[0] == 0) t[0] = 1; else t[0] = 4; - j = s->owner = LocateTheLocator(s->hitag, -1); - if (j == -1) + auto NewOwner = LocateTheLocator(s->hitag, -1); + if (!NewOwner) { - s->hitag = j = hittype[i].temp_data[5]; - s->owner = LocateTheLocator(j, -1); - j = s->owner; - if (j == -1) + s->hitag = actor->temp_data[5]; + NewOwner = LocateTheLocator(s->hitag, -1); + if (!NewOwner) { - deletesprite(i); + deletesprite(actor); return; } } else s->hitag++; + actor->SetOwner(NewOwner); } t[3] = getincangle(s->ang, a); s->ang += t[3] >> 3; - if (s->z < sprite[j].z) + if (s->z < Owner->s.z) s->z += 1024; else s->z -= 1024; } - if (roamsnd >= 0 && S_CheckSoundPlaying(i, roamsnd) < 1) - S_PlayActorSound(roamsnd, i); + if (roamsnd >= 0 && S_CheckActorSoundPlaying(actor, roamsnd) < 1) + S_PlayActorSound(roamsnd, actor); - ssp(i, CLIPMASK0); + ssp(actor, CLIPMASK0); } //--------------------------------------------------------------------------- @@ -1848,21 +1834,20 @@ void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int // //--------------------------------------------------------------------------- -void ooz(int i) +void ooz(DDukeActor *actor) { - getglobalz(i); + getglobalz(actor); - int j = (hittype[i].floorz - hittype[i].ceilingz) >> 9; + int j = (actor->floorz - actor->ceilingz) >> 9; if (j > 255) j = 255; int x = 25 - (j >> 1); if (x < 8) x = 8; else if (x > 48) x = 48; - spritetype* s = &sprite[i]; - s->yrepeat = j; - s->xrepeat = x; - s->z = hittype[i].floorz; + actor->s.yrepeat = j; + actor->s.xrepeat = x; + actor->s.z = actor->floorz; } //--------------------------------------------------------------------------- @@ -1871,19 +1856,18 @@ void ooz(int i) // //--------------------------------------------------------------------------- -void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BURNT, int REACTORSPARK, int REACTOR2SPARK) +void reactor(DDukeActor* actor, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BURNT, int REACTORSPARK, int REACTOR2SPARK) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - int sect = s->sectnum; + spritetype* s = &actor->s; + int* t = &actor->temp_data[0]; + int sect = actor->s.sectnum; if (t[4] == 1) { - SectIterator it(sect); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto act2 = it.Next()) { - auto sprj = &sprite[j]; + auto sprj = &act2->s; if (sprj->picnum == SECTOREFFECTOR) { if (sprj->lotag == 1) @@ -1904,7 +1888,8 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR { sprj->cstat = (short)32768; } - } return; + } + return; } if (t[1] >= 20) @@ -1914,7 +1899,7 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR } int x; - int p = findplayer(s, &x); + int p = findplayer(actor, &x); t[2]++; if (t[2] == 4) t[2] = 0; @@ -1924,11 +1909,11 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR if ((krand() & 255) < 16) { if (!S_CheckSoundPlaying(DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor()); - S_PlayActorSound(SHORT_CIRCUIT, i); + S_PlayActorSound(SHORT_CIRCUIT, actor); - sprite[ps[p].i].extra--; + ps[p].GetActor()->s.extra--; SetPlayerPal(&ps[p], PalEntry(32, 32, 0, 0)); } t[0] += 128; @@ -1939,7 +1924,6 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR if (t[1]) { - int j; t[1]++; t[4] = s->z; @@ -1950,16 +1934,15 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR case 3: { //Turn on all of those flashing sectoreffector. - fi.hitradius(i, 4096, + fi.hitradius(actor, 4096, impact_damage << 2, impact_damage << 2, impact_damage << 2, impact_damage << 2); - StatIterator it(STAT_STANDABLE); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto act2 = it.Next()) { - auto sj = &sprite[j]; + auto sj = &act2->s; if (sj->picnum == MASTERSWITCH) if (sj->hitag == s->hitag) if (sj->yvel == 0) @@ -1972,12 +1955,12 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR case 10: case 15: { - SectIterator it(sect); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto a2 = it.Next()) { - if (j != i) + if (a2 != actor) { - deletesprite(j); + deletesprite(a2); break; } } @@ -1985,7 +1968,7 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR } } for (x = 0; x < 16; x++) - RANDOMSCRAP(s, i); + RANDOMSCRAP(actor); s->z = t[4]; t[4] = 0; @@ -1993,11 +1976,11 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR } else { - int j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j >= 0) { for (x = 0; x < 32; x++) - RANDOMSCRAP(s, i); + RANDOMSCRAP(actor); if (s->extra < 0) t[1] = 1; } @@ -2010,27 +1993,27 @@ void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BUR // //--------------------------------------------------------------------------- -void camera(int i) +void camera(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + spritetype* s = &actor->s; + int* t = &actor->temp_data[0]; if (t[0] == 0) { if (camerashitable) { - int j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j >= 0) { t[0] = 1; // static s->cstat = (short)32768; for (int x = 0; x < 5; x++) - RANDOMSCRAP(s, i); + RANDOMSCRAP(actor); return; } } // backup current angle for interpolating camera angle. - hittype[i].tempang = s->ang; + actor->tempang = s->ang; if (s->hitag > 0) { @@ -2077,21 +2060,22 @@ void camera(int i) // //--------------------------------------------------------------------------- -void forcesphere(int i) +void forcesphereexplode(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - int l = s->xrepeat; + int* t = &actor->temp_data[0]; + int l = actor->s.xrepeat; if (t[1] > 0) { t[1]--; if (t[1] == 0) { - deletesprite(i); + deletesprite(actor); return; } } - if (hittype[s->owner].temp_data[1] == 0) + auto Owner = actor->GetOwner(); + if (!Owner) return; + if (Owner->temp_data[1] == 0) { if (t[0] < 64) { @@ -2106,20 +2090,20 @@ void forcesphere(int i) l -= 3; } - s->x = sprite[s->owner].x; - s->y = sprite[s->owner].y; - s->z = sprite[s->owner].z; - s->ang += hittype[s->owner].temp_data[0]; + actor->s.x = Owner->s.x; + actor->s.y = Owner->s.y; + actor->s.z = Owner->s.z; + actor->s.ang += Owner->temp_data[0]; if (l > 64) l = 64; else if (l < 1) l = 1; - s->xrepeat = l; - s->yrepeat = l; - s->shade = (l >> 1) - 48; + actor->s.xrepeat = l; + actor->s.yrepeat = l; + actor->s.shade = (l >> 1) - 48; for (int j = t[0]; j > 0; j--) - ssp(i, CLIPMASK0); + ssp(actor, CLIPMASK0); } //--------------------------------------------------------------------------- @@ -2128,21 +2112,20 @@ void forcesphere(int i) // //--------------------------------------------------------------------------- -void watersplash2(int i) +void watersplash2(DDukeActor* actor) { - spritetype* s = &sprite[i]; - int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int sect = actor->s.sectnum; + int* t = &actor->temp_data[0]; t[0]++; if (t[0] == 1) { if (sector[sect].lotag != 1 && sector[sect].lotag != 2) { - deletesprite(i); + deletesprite(actor); return; } if (!S_CheckSoundPlaying(ITEM_SPLASH)) - S_PlayActorSound(ITEM_SPLASH, i); + S_PlayActorSound(ITEM_SPLASH, actor); } if (t[0] == 3) { @@ -2150,7 +2133,7 @@ void watersplash2(int i) t[1]++; } if (t[1] == 5) - deletesprite(i); + deletesprite(actor); } //--------------------------------------------------------------------------- @@ -2159,25 +2142,23 @@ void watersplash2(int i) // //--------------------------------------------------------------------------- -void frameeffect1(int i) +void frameeffect1(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - if (s->owner >= 0) + int* t = &actor->temp_data[0]; + auto Owner = actor->GetOwner(); + if (Owner) { t[0]++; if (t[0] > 7) { - deletesprite(i); + deletesprite(actor); return; } - else if (t[0] > 4) - s->cstat |= 512 + 2; - else if (t[0] > 2) - s->cstat |= 2; - s->xoffset = sprite[s->owner].xoffset; - s->yoffset = sprite[s->owner].yoffset; + else if (t[0] > 4) actor->s.cstat |= 512 + 2; + else if (t[0] > 2) actor->s.cstat |= 2; + actor->s.xoffset = Owner->s.xoffset; + actor->s.yoffset = Owner->s.yoffset; } } @@ -2187,15 +2168,15 @@ void frameeffect1(int i) // //--------------------------------------------------------------------------- -bool money(int i, int BLOODPOOL) +bool money(DDukeActor* actor, int BLOODPOOL) { - spritetype* s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; - s->xvel = (krand() & 7) + (sintable[hittype[i].temp_data[0] & 2047] >> 9); - hittype[i].temp_data[0] += (krand() & 63); - if ((hittype[i].temp_data[0] & 2047) > 512 && (hittype[i].temp_data[0] & 2047) < 1596) + s->xvel = (krand() & 7) + (sintable[actor->temp_data[0] & 2047] >> 9); + actor->temp_data[0] += (krand() & 63); + if ((actor->temp_data[0] & 2047) > 512 && (actor->temp_data[0] & 2047) < 1596) { if (sector[sect].lotag == 2) { @@ -2207,14 +2188,14 @@ bool money(int i, int BLOODPOOL) s->zvel += (gc >> 5) + (krand() & 7); } - ssp(i, CLIPMASK0); + ssp(actor, CLIPMASK0); if ((krand() & 3) == 0) - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->pos); if (s->sectnum == -1) { - deletesprite(i); + deletesprite(actor); return false; } int l = getflorzofslope(s->sectnum, s->x, s->y); @@ -2223,15 +2204,14 @@ bool money(int i, int BLOODPOOL) { s->z = l; - insertspriteq(&hittype[i]); - sprite[i].picnum++; + insertspriteq(actor); + s->picnum++; - StatIterator it(STAT_MISC); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto aa = it.Next()) { - if (sprite[j].picnum == BLOODPOOL) - if (ldist(s, &sprite[j]) < 348) + if (aa->s.picnum == BLOODPOOL) + if (ldist(actor, aa) < 348) { s->pal = 2; break; @@ -2247,11 +2227,11 @@ bool money(int i, int BLOODPOOL) // //--------------------------------------------------------------------------- -bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, bool zcheck1, bool zcheck2) +bool jibs(DDukeActor *actor, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, bool zcheck1, bool zcheck2) { - spritetype* s = &sprite[i]; + spritetype* s = &actor->s; int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; if (s->xvel > 0) s->xvel--; else s->xvel = 0; @@ -2262,24 +2242,24 @@ bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, b t[5]++; else { - deletesprite(i); + deletesprite(actor); return false; } } if (s->zvel > 1024 && s->zvel < 1280) { - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->pos); sect = s->sectnum; } - if (callsetsprite) setsprite(i, s->x, s->y, s->z); + if (callsetsprite) setsprite(actor, s->pos); int l = getflorzofslope(sect, s->x, s->y); int x = getceilzofslope(sect, s->x, s->y); if (x == l || sect < 0 || sect >= MAXSECTORS) { - deletesprite(i); + deletesprite(actor); return false; } @@ -2319,7 +2299,7 @@ bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, b if (floorcheck && s->z >= sector[s->sectnum].floorz) { - deletesprite(i); + deletesprite(actor); return false; } } @@ -2327,19 +2307,19 @@ bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, b { if (zcheck2) { - deletesprite(i); + deletesprite(actor); return false; } if (t[2] == 0) { if (s->sectnum == -1) { - deletesprite(i); + deletesprite(actor); return false; } if ((sector[s->sectnum].floorstat & 2)) { - deletesprite(i); + deletesprite(actor); return false; } t[2]++; @@ -2356,7 +2336,7 @@ bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, b t[0]++; if (t[1] > 20) { - deletesprite(i); + deletesprite(actor); return false; } } @@ -2371,34 +2351,34 @@ bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, b // //--------------------------------------------------------------------------- -bool bloodpool(int i, bool puke, int TIRE) +bool bloodpool(DDukeActor* actor, bool puke, int TIRE) { - spritetype* s = &sprite[i]; + spritetype* s = &actor->s; int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; if (t[0] == 0) { t[0] = 1; if (sector[sect].floorstat & 2) { - deletesprite(i); + deletesprite(actor); return false; } - else insertspriteq(&hittype[i]); + else insertspriteq(actor); } - makeitfall(i); + makeitfall(actor); int x; - int p = findplayer(s, &x); + int p = findplayer(actor, &x); - s->z = hittype[i].floorz - (FOURSLEIGHT); + s->z = actor->floorz - (FOURSLEIGHT); if (t[2] < 32) { t[2]++; - if (hittype[i].picnum == TIRE) + if (actor->picnum == TIRE) { if (s->xrepeat < 64 && s->yrepeat < 64) { @@ -2425,8 +2405,8 @@ bool bloodpool(int i, bool puke, int TIRE) else { if (!S_CheckSoundPlaying(DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); - sprite[ps[p].i].extra--; + S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor()); + ps[p].GetActor()->s.extra--; SetPlayerPal(&ps[p], PalEntry(32, 16, 0, 0)); } } @@ -2434,7 +2414,7 @@ bool bloodpool(int i, bool puke, int TIRE) if (t[1] == 1) return false; t[1] = 1; - if (hittype[i].picnum == TIRE) + if (actor->picnum == TIRE) ps[p].footprintcount = 10; else ps[p].footprintcount = 3; @@ -2457,17 +2437,17 @@ bool bloodpool(int i, bool puke, int TIRE) // //--------------------------------------------------------------------------- -void shell(int i, bool morecheck) +void shell(DDukeActor* actor, bool morecheck) { - spritetype* s = &sprite[i]; + spritetype* s = &actor->s; int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; - ssp(i, CLIPMASK0); + ssp(actor, CLIPMASK0); if (sect < 0 || morecheck) { - deletesprite(i); + deletesprite(actor); return; } @@ -2500,7 +2480,7 @@ void shell(int i, bool morecheck) s->xvel--; else { - deletesprite(i); + deletesprite(actor); } } } @@ -2511,22 +2491,22 @@ void shell(int i, bool morecheck) // //--------------------------------------------------------------------------- -void glasspieces(int i) +void glasspieces(DDukeActor* actor) { - spritetype* s = &sprite[i]; + spritetype* s = &actor->s; int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; - makeitfall(i); + makeitfall(actor); if (s->zvel > 4096) s->zvel = 4096; if (sect < 0) { - deletesprite(i); + deletesprite(actor); return; } - if (s->z == hittype[i].floorz - (FOURSLEIGHT) && t[0] < 3) + if (s->z == actor->floorz - (FOURSLEIGHT) && t[0] < 3) { s->zvel = -((3 - t[0]) << 8) - (krand() & 511); if (sector[sect].lotag == 2) @@ -2534,12 +2514,12 @@ void glasspieces(int i) s->xrepeat >>= 1; s->yrepeat >>= 1; if (rnd(96)) - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->pos); t[0]++;//Number of bounces } else if (t[0] == 3) { - deletesprite(i); + deletesprite(actor); return; } @@ -2550,7 +2530,7 @@ void glasspieces(int i) } else s->xvel = 0; - ssp(i, CLIPMASK0); + ssp(actor, CLIPMASK0); } //--------------------------------------------------------------------------- @@ -2559,11 +2539,11 @@ void glasspieces(int i) // //--------------------------------------------------------------------------- -void scrap(int i, int SCRAP1, int SCRAP6) +void scrap(DDukeActor* actor, int SCRAP1, int SCRAP6) { - spritetype* s = &sprite[i]; + spritetype* s = &actor->s; int sect = s->sectnum; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; if (s->xvel > 0) s->xvel--; @@ -2571,7 +2551,7 @@ void scrap(int i, int SCRAP1, int SCRAP6) if (s->zvel > 1024 && s->zvel < 1280) { - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->pos); sect = s->sectnum; } @@ -2604,12 +2584,44 @@ void scrap(int i, int SCRAP1, int SCRAP6) { if (s->picnum == SCRAP1 && s->yvel > 0) { - int j = fi.spawn(i, s->yvel); - setsprite(j, s->x, s->y, s->z); - getglobalz(j); - sprite[j].hitag = sprite[j].lotag = 0; + auto spawned = spawn(actor, s->yvel); + setsprite(spawned, s->pos); + getglobalz(spawned); + spawned->s.hitag = spawned->s.lotag = 0; } - deletesprite(i); + deletesprite(actor); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void gutsdir(DDukeActor* actor, short gtype, short n, short p) +{ + int sx, sy; + + if (badguy(actor) && actor->s.xrepeat < 16) + sx = sy = 8; + else sx = sy = 32; + + int gutz = actor->s.z - (8 << 8); + int floorz = getflorzofslope(actor->s.sectnum, actor->s.x, actor->s.y); + + if (gutz > (floorz - (8 << 8))) + gutz = floorz - (8 << 8); + + gutz += actorinfo[actor->s.picnum].gutsoffset; + + for (int j = 0; j < n; j++) + { + int a = krand() & 2047; + int r1 = krand(); + int r2 = krand(); + // TRANSITIONAL: owned by a player??? + EGS(actor->s.sectnum, actor->s.x, actor->s.y, gutz, gtype, -32, sx, sy, a, 256 + (r2 & 127), -512 - (r1 & 2047), ps[p].GetActor(), 5); } } @@ -2619,88 +2631,85 @@ void scrap(int i, int SCRAP1, int SCRAP6) // //--------------------------------------------------------------------------- -void handle_se00(int i, int LASERLINE) +void handle_se00(DDukeActor* actor, int LASERLINE) { - auto s = &sprite[i]; - auto ht = &hittype[i]; - int sect = s->sectnum; - auto t = &ht->temp_data[0]; - sectortype *sc = §or[s->sectnum]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; + sectortype *sect = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; int zchange = 0; - int j = s->owner; - auto sprowner = &sprite[j]; + auto Owner = actor->GetOwner(); - if (sprowner->lotag == (short)65535) + if (!Owner || Owner->s.lotag == (short)65535) { - deletesprite(i); + deletesprite(actor); return; } - int q = sc->extra >> 3; + int q = sect->extra >> 3; int l = 0; - if (sc->lotag == 30) + if (sect->lotag == 30) { q >>= 2; - if (sprite[i].extra == 1) + if (s->extra == 1) { - if (ht->tempang < 256) + if (actor->tempang < 256) { - ht->tempang += 4; - if (ht->tempang >= 256) - callsound(s->sectnum, i); + actor->tempang += 4; + if (actor->tempang >= 256) + callsound(s->sectnum, actor); if (s->clipdist) l = 1; else l = -1; } - else ht->tempang = 256; + else actor->tempang = 256; - if (sc->floorz > s->z) //z's are touching + if (sect->floorz > s->z) //z's are touching { - sc->floorz -= 512; + sect->floorz -= 512; zchange = -512; - if (sc->floorz < s->z) - sc->floorz = s->z; + if (sect->floorz < s->z) + sect->floorz = s->z; } - else if (sc->floorz < s->z) //z's are touching + else if (sect->floorz < s->z) //z's are touching { - sc->floorz += 512; + sect->floorz += 512; zchange = 512; - if (sc->floorz > s->z) - sc->floorz = s->z; + if (sect->floorz > s->z) + sect->floorz = s->z; } } - else if (sprite[i].extra == 3) + else if (s->extra == 3) { - if (ht->tempang > 0) + if (actor->tempang > 0) { - ht->tempang -= 4; - if (ht->tempang <= 0) - callsound(s->sectnum, i); + actor->tempang -= 4; + if (actor->tempang <= 0) + callsound(s->sectnum, actor); if (s->clipdist) l = -1; else l = 1; } - else ht->tempang = 0; + else actor->tempang = 0; - if (sc->floorz > ht->temp_data[3]) //z's are touching + if (sect->floorz > actor->temp_data[3]) //z's are touching { - sc->floorz -= 512; + sect->floorz -= 512; zchange = -512; - if (sc->floorz < ht->temp_data[3]) - sc->floorz = ht->temp_data[3]; + if (sect->floorz < actor->temp_data[3]) + sect->floorz = actor->temp_data[3]; } - else if (sc->floorz < ht->temp_data[3]) //z's are touching + else if (sect->floorz < actor->temp_data[3]) //z's are touching { - sc->floorz += 512; + sect->floorz += 512; zchange = 512; - if (sc->floorz > ht->temp_data[3]) - sc->floorz = ht->temp_data[3]; + if (sect->floorz > actor->temp_data[3]) + sect->floorz = actor->temp_data[3]; } } @@ -2709,26 +2718,26 @@ void handle_se00(int i, int LASERLINE) } else { - if (hittype[j].temp_data[0] == 0) return; - if (hittype[j].temp_data[0] == 2) + if (Owner->temp_data[0] == 0) return; + if (Owner->temp_data[0] == 2) { - deletesprite(i); + deletesprite(actor); return; } - if (sprowner->ang > 1024) + if (Owner->s.ang > 1024) l = -1; else l = 1; if (t[3] == 0) - t[3] = ldist(s, &sprite[j]); + t[3] = ldist(actor, Owner); s->xvel = t[3]; - s->x = sprowner->x; - s->y = sprowner->y; + s->x = Owner->s.x; + s->y = Owner->s.y; s->ang += (l * q); t[2] += (l * q); } - if (l && (sc->floorstat & 64)) + if (l && (sect->floorstat & 64)) { int p; for (p = connecthead; p >= 0; p = connectpoint2[p]) @@ -2740,9 +2749,7 @@ void handle_se00(int i, int LASERLINE) ps[p].posz += zchange; int m, x; - rotatepoint(sprowner->x, sprowner->y, - ps[p].posx, ps[p].posy, (q * l), - &m, &x); + rotatepoint(Owner->s.x, Owner->s.y, ps[p].posx, ps[p].posy, (q * l), &m, &x); ps[p].bobposx += m - ps[p].posx; ps[p].bobposy += x - ps[p].posy; @@ -2750,21 +2757,22 @@ void handle_se00(int i, int LASERLINE) ps[p].posx = m; ps[p].posy = x; - if (sprite[ps[p].i].extra <= 0) + auto psp = ps[p].GetActor(); + if (psp->s.extra <= 0) { - sprite[ps[p].i].x = m; - sprite[ps[p].i].y = x; + psp->s.x = m; + psp->s.y = x; } } } - SectIterator itp(s->sectnum); - while ((p = itp.NextIndex()) >= 0) + DukeSectIterator itp(s->sectnum); + while (auto ap = itp.Next()) { - auto sprp = &sprite[p]; + auto sprp = &ap->s; if (sprp->statnum != 3 && sprp->statnum != 4) if (LASERLINE < 0 || sprp->picnum != LASERLINE) { - if (sprp->picnum == TILE_APLAYER && sprp->owner >= 0) + if (sprp->picnum == TILE_APLAYER && ap->GetOwner()) { continue; } @@ -2773,16 +2781,12 @@ void handle_se00(int i, int LASERLINE) sprp->ang &= 2047; sprp->z += zchange; - - rotatepoint(sprowner->x, sprowner->y, - sprp->x, sprp->y, (q * l), - &sprp->x, &sprp->y); - + rotatepoint(Owner->s.x, Owner->s.y, ap->s.x, ap->s.y, (q* l), &ap->s.x, &ap->s.y); } } } - ms(i); + ms(actor); } //--------------------------------------------------------------------------- @@ -2791,21 +2795,18 @@ void handle_se00(int i, int LASERLINE) // //--------------------------------------------------------------------------- -void handle_se01(int i) +void handle_se01(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - int sh = s->hitag; - if (s->owner == -1) //Init + int* t = &actor->temp_data[0]; + int sh = actor->s.hitag; + if (actor->GetOwner() == nullptr) //Init { - s->owner = i; + actor->SetOwner(actor); - StatIterator it(STAT_EFFECTOR); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto ac = it.Next()) { - auto ss = &sprite[j]; - if (ss->lotag == 19 && ss->hitag == sh) + if (ac->s.lotag == 19 && ac->s.hitag == sh) { t[0] = 0; break; @@ -2820,41 +2821,47 @@ void handle_se01(int i) // //--------------------------------------------------------------------------- -void handle_se14(int i, bool checkstat, int RPG, int JIBS6) +void handle_se14(DDukeActor* actor, bool checkstat, int RPG, int JIBS6) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; - if (s->owner == -1) - s->owner = LocateTheLocator(t[3], t[0]); - - if (s->owner == -1) + if (actor->GetOwner() == nullptr) { - I_Error("Could not find any locators for SE# 6 and 14 with a hitag of %d.", t[3]); + auto NewOwner = LocateTheLocator(t[3], t[0]); + + if (NewOwner == nullptr) + { + I_Error("Could not find any locators for SE# 6 and 14 with a hitag of %d.", t[3]); + } + actor->SetOwner(NewOwner); } - int j = ldist(&sprite[s->owner], s); + auto Owner = actor->GetOwner(); + int j = ldist(Owner, actor); - if (j < 1024L) + if (j < 1024) { if (st == 6) - if (sprite[s->owner].hitag & 1) + if (Owner->s.hitag & 1) t[4] = sc->extra; //Slow it down t[3]++; - s->owner = LocateTheLocator(t[3], t[0]); - if (s->owner == -1) + auto NewOwner = LocateTheLocator(t[3], t[0]); + if (NewOwner == nullptr) { t[3] = 0; - s->owner = LocateTheLocator(0, t[0]); + NewOwner = LocateTheLocator(0, t[0]); } + if (NewOwner) actor->SetOwner(NewOwner); } + Owner = actor->GetOwner(); if (s->xvel) { - int x = getangle(sprite[s->owner].x - s->x, sprite[s->owner].y - s->y); + int x = getangle(Owner->s.x - s->x, Owner->s.y - s->y); int q = getincangle(s->ang, x) >> 3; t[2] += q; @@ -2865,30 +2872,32 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) { if (statstate) { - if (!S_CheckSoundPlaying(hittype[i].lastvx)) - S_PlayActorSound(hittype[i].lastvx, i); + if (!S_CheckSoundPlaying(actor->lastvx)) + S_PlayActorSound(actor->lastvx, actor); } if ((!checkstat || !statstate) && (ud.monsters_off == 0 && sc->floorpal == 0 && (sc->floorstat & 1) && rnd(8))) { - int p = findplayer(s, &x); + int p = findplayer(actor, &x); if (x < 20480) { j = s->ang; s->ang = getangle(s->x - ps[p].posx, s->y - ps[p].posy); - fi.shoot(i, RPG); + fi.shoot(actor, RPG); s->ang = j; } } } if (s->xvel <= 64 && statstate) - S_StopSound(hittype[i].lastvx, i); + S_StopSound(actor->lastvx, actor); if ((sc->floorz - sc->ceilingz) < (108 << 8)) { if (ud.clipping == 0 && s->xvel >= 192) for (int p = connecthead; p >= 0; p = connectpoint2[p]) - if (sprite[ps[p].i].extra > 0) + { + auto psp = ps[p].GetActor(); + if (psp->s.extra > 0) { short k = ps[p].cursectnum; updatesector(ps[p].posx, ps[p].posy, &k); @@ -2898,16 +2907,19 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].posy = s->y; ps[p].cursectnum = s->sectnum; - setsprite(ps[p].i, s->x, s->y, s->z); + setsprite(ps[p].GetActor(), s->pos); quickkill(&ps[p]); } } + } } int m = (s->xvel * sintable[(s->ang + 512) & 2047]) >> 14; x = (s->xvel * sintable[s->ang & 2047]) >> 14; for (int p = connecthead; p >= 0; p = connectpoint2[p]) + { + auto psp = ps[p].GetActor(); if (sector[ps[p].cursectnum].lotag != 2) { if (po[p].os == s->sectnum) @@ -2916,7 +2928,7 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) po[p].oy += x; } - if (s->sectnum == sprite[ps[p].i].sectnum) + if (s->sectnum == psp->s.sectnum) { rotatepoint(s->x, s->y, ps[p].posx, ps[p].posy, q, &ps[p].posx, &ps[p].posy); @@ -2933,22 +2945,21 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].oposx = ps[p].posx; ps[p].oposy = ps[p].posy; } - if (sprite[ps[p].i].extra <= 0) + if (psp->s.extra <= 0) { - sprite[ps[p].i].x = ps[p].posx; - sprite[ps[p].i].y = ps[p].posy; + psp->s.x = ps[p].posx; + psp->s.y = ps[p].posy; } } } - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) + } + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; + auto sj = &a2->s; if (sj->statnum != 10 && sector[sj->sectnum].lotag != 2 && sj->picnum != SECTOREFFECTOR && sj->picnum != LOCATORS) { - rotatepoint(s->x, s->y, - sj->x, sj->y, q, - &sj->x, &sj->y); + rotatepoint(s->x, s->y, sj->x, sj->y, q, &sj->x, &sj->y); sj->x += m; sj->y += x; @@ -2957,20 +2968,21 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) if (numplayers > 1) { - hittype[j].bposx = sj->x; - hittype[j].bposy = sj->y; + a2->bposx = sj->x; + a2->bposy = sj->y; } } } - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); if ((sc->floorz - sc->ceilingz) < (108 << 8)) { if (ud.clipping == 0 && s->xvel >= 192) for (int p = connecthead; p >= 0; p = connectpoint2[p]) - if (sprite[ps[p].i].extra > 0) + { + if (ps[p].GetActor()->s.extra > 0) { short k = ps[p].cursectnum; updatesector(ps[p].posx, ps[p].posy, &k); @@ -2980,25 +2992,28 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].oposy = ps[p].posy = s->y; ps[p].cursectnum = s->sectnum; - setsprite(ps[p].i, s->x, s->y, s->z); + setsprite(ps[p].GetActor(), s->pos); quickkill(&ps[p]); } } + } - SectIterator itr(sprite[s->owner].sectnum); - while ((j = itr.NextIndex()) >= 0) + auto Owner = actor->GetOwner(); + if (Owner) { - auto spj = &sprite[j]; - - if (spj->statnum == 1 && badguy(spj) && spj->picnum != SECTOREFFECTOR && spj->picnum != LOCATORS) + DukeSectIterator itr(Owner->s.sectnum); + while (auto a2 = itr.Next()) { - short k = spj->sectnum; - updatesector(spj->x, spj->y, &k); - if (spj->extra >= 0 && k == s->sectnum) + if (a2->s.statnum == 1 && badguy(a2) && a2->s.picnum != SECTOREFFECTOR && a2->s.picnum != LOCATORS) { - fi.gutsdir(&sprite[j], JIBS6, 72, myconnectindex); - S_PlayActorSound(SQUISHED, i); - deletesprite(j); + short k = a2->s.sectnum; + updatesector(a2->s.x, a2->s.y, &k); + if (a2->s.extra >= 0 && k == s->sectnum) + { + gutsdir(a2, JIBS6, 72, myconnectindex); + S_PlayActorSound(SQUISHED, actor); + deletesprite(a2); + } } } } @@ -3012,25 +3027,26 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) // //--------------------------------------------------------------------------- -void handle_se30(int i, int JIBS6) +void handle_se30(DDukeActor *actor, int JIBS6) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; - if (s->owner == -1) + auto Owner = actor->GetOwner(); + if (Owner == nullptr) { t[3] = !t[3]; - s->owner = LocateTheLocator(t[3], t[0]); + Owner = LocateTheLocator(t[3], t[0]); + actor->SetOwner(Owner); } else { - if (t[4] == 1) // Starting to go { - if (ldist(&sprite[s->owner], s) < (2048 - 128)) + if (ldist(Owner, actor) < (2048 - 128)) t[4] = 2; else { @@ -3042,7 +3058,7 @@ void handle_se30(int i, int JIBS6) } if (t[4] == 2) { - int l = FindDistance2D(sprite[s->owner].x - s->x, sprite[s->owner].y - s->y); + int l = FindDistance2D(Owner->s.x - s->x, Owner->s.y - s->y); if (l <= 128) s->xvel = 0; @@ -3053,20 +3069,18 @@ void handle_se30(int i, int JIBS6) { s->xvel = 0; operateactivators(s->hitag + (short)t[3], -1); - s->owner = -1; + actor->SetOwner(nullptr); s->ang += 1024; t[4] = 0; - fi.operateforcefields(i, s->hitag); + fi.operateforcefields(actor, s->hitag); - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->picnum != SECTOREFFECTOR && sj->picnum != LOCATORS) + if (a2->s.picnum != SECTOREFFECTOR && a2->s.picnum != LOCATORS) { - hittype[j].bposx = sj->x; - hittype[j].bposy = sj->y; + a2->bposx = a2->s.x; + a2->bposy = a2->s.y; } } @@ -3082,7 +3096,9 @@ void handle_se30(int i, int JIBS6) if ((sc->floorz - sc->ceilingz) < (108 << 8)) if (ud.clipping == 0) for (int p = connecthead; p >= 0; p = connectpoint2[p]) - if (sprite[ps[p].i].extra > 0) + { + auto psp = ps[p].GetActor(); + if (psp->s.extra > 0) { short k = ps[p].cursectnum; updatesector(ps[p].posx, ps[p].posy, &k); @@ -3092,14 +3108,15 @@ void handle_se30(int i, int JIBS6) ps[p].posy = s->y; ps[p].cursectnum = s->sectnum; - setsprite(ps[p].i, s->x, s->y, s->z); + setsprite(ps[p].GetActor(), s->pos); quickkill(&ps[p]); } } - + } for (int p = connecthead; p >= 0; p = connectpoint2[p]) { - if (sprite[ps[p].i].sectnum == s->sectnum) + auto psp = ps[p].GetActor(); + if (psp->s.sectnum == s->sectnum) { ps[p].posx += l; ps[p].posy += x; @@ -3121,39 +3138,37 @@ void handle_se30(int i, int JIBS6) } } - SectIterator its(s->sectnum); - int j; - while ((j = its.NextIndex()) >= 0) + DukeSectIterator its(s->sectnum); + while (auto a2 = its.Next()) { - auto sprj = &sprite[j]; - auto htj = &hittype[j]; - if (sprj->picnum != SECTOREFFECTOR && sprj->picnum != LOCATORS) + auto spa2 = &a2->s; + if (spa2->picnum != SECTOREFFECTOR && spa2->picnum != LOCATORS) { if (numplayers < 2) { - htj->bposx = sprj->x; - htj->bposy = sprj->y; + a2->bposx = spa2->x; + a2->bposy = spa2->y; } - sprj->x += l; - sprj->y += x; + spa2->x += l; + spa2->y += x; if (numplayers > 1) { - htj->bposx = sprj->x; - htj->bposy = sprj->y; + a2->bposx = spa2->x; + a2->bposy = spa2->y; } } } - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); if ((sc->floorz - sc->ceilingz) < (108 << 8)) { if (ud.clipping == 0) for (int p = connecthead; p >= 0; p = connectpoint2[p]) - if (sprite[ps[p].i].extra > 0) + if (ps[p].GetActor()->s.extra > 0) { short k = ps[p].cursectnum; updatesector(ps[p].posx, ps[p].posy, &k); @@ -3167,33 +3182,34 @@ void handle_se30(int i, int JIBS6) ps[p].cursectnum = s->sectnum; - setsprite(ps[p].i, s->x, s->y, s->z); + setsprite(ps[p].GetActor(), s->pos); quickkill(&ps[p]); } } - SectIterator it(sprite[sprite[i].owner].sectnum); - while ((j = it.NextIndex()) >= 0) + if (Owner) { - auto sj = &sprite[j]; - if (sj->statnum == 1 && badguy(&sprite[j]) && sj->picnum != SECTOREFFECTOR && sj->picnum != LOCATORS) + DukeSectIterator it(Owner->s.sectnum); + while (auto a2 = it.Next()) { - // if(sj->sectnum != s->sectnum) + if (a2->s.statnum == 1 && badguy(a2) && a2->s.picnum != SECTOREFFECTOR && a2->s.picnum != LOCATORS) { - short k = sj->sectnum; - updatesector(sj->x, sj->y, &k); - if (sj->extra >= 0 && k == s->sectnum) + // if(a2->s.sectnum != s->sectnum) { - fi.gutsdir(&sprite[j], JIBS6, 24, myconnectindex); - S_PlayActorSound(SQUISHED, j); - deletesprite(j); + short k = a2->s.sectnum; + updatesector(a2->s.x, a2->s.y, &k); + if (a2->s.extra >= 0 && k == s->sectnum) + { + gutsdir(a2, JIBS6, 24, myconnectindex); + S_PlayActorSound(SQUISHED, a2); + deletesprite(a2); } } - } } } } + } } //--------------------------------------------------------------------------- @@ -3202,10 +3218,10 @@ void handle_se30(int i, int JIBS6) // //--------------------------------------------------------------------------- -void handle_se02(int i) +void handle_se02(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -3227,7 +3243,7 @@ void handle_se02(int i) { t[0] = -1; //Stop the quake t[4] = -1; - deletesprite(i); + deletesprite(actor); return; } else @@ -3235,7 +3251,7 @@ void handle_se02(int i) if ((t[0] & 31) == 8) { earthquaketime = 48; - S_PlayActorSound(EARTHQUAKE, ps[screenpeek].i); + S_PlayActorSound(EARTHQUAKE, ps[screenpeek].GetActor()); } if (abs(sc->floorheinum - t[5]) < 8) @@ -3257,20 +3273,19 @@ void handle_se02(int i) ps[p].bobposy += x; } - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; + auto sj = &a2->s; if (sj->picnum != SECTOREFFECTOR) { sj->x += m; sj->y += x; - setsprite(j, sj->x, sj->y, sj->z); + setsprite(a2, sj->pos); } } - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); } } @@ -3280,24 +3295,26 @@ void handle_se02(int i) // //--------------------------------------------------------------------------- -void handle_se03(int i) +void handle_se03(DDukeActor *actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; if (t[4] == 0) return; - int x, p = findplayer(s, &x); + int x, p = findplayer(actor, &x); + + int palvals = actor->palvals; // if(t[5] > 0) { t[5]--; break; } if ((global_random / (sh + 1) & 31) < 4 && !t[2]) { // t[5] = 4+(global_random&7); - sc->ceilingpal = s->owner >> 8; - sc->floorpal = s->owner & 0xff; + sc->ceilingpal = palvals >> 8; + sc->floorpal = palvals & 0xff; t[0] = s->shade + (global_random & 15); } else @@ -3332,21 +3349,23 @@ void handle_se03(int i) // //--------------------------------------------------------------------------- -void handle_se04(int i) +void handle_se04(DDukeActor *actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; int j; + int palvals = actor->palvals; + if ((global_random / (sh + 1) & 31) < 4) { t[1] = s->shade + (global_random & 15);//Got really bright t[0] = s->shade + (global_random & 15); - sc->ceilingpal = s->owner >> 8; - sc->floorpal = s->owner & 0xff; + sc->ceilingpal = palvals >> 8; + sc->floorpal = palvals & 0xff; j = 1; } else @@ -3367,7 +3386,7 @@ void handle_se04(int i) for (int x = sc->wallnum; x > 0; x--, wal++) { - if (j) wal->pal = (s->owner & 0xff); + if (j) wal->pal = (palvals & 0xff); else wal->pal = s->pal; if (wal->hitag != 1) @@ -3378,10 +3397,10 @@ void handle_se04(int i) } } - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; + auto sj = &a2->s; if (sj->cstat & 16) { if (sc->ceilingstat & 1) @@ -3391,7 +3410,7 @@ void handle_se04(int i) } if (t[4]) - deletesprite(i); + deletesprite(actor); } @@ -3401,63 +3420,64 @@ void handle_se04(int i) // //--------------------------------------------------------------------------- -void handle_se05(int i, int FIRELASER) +void handle_se05(DDukeActor* actor, int FIRELASER) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; - int j, l, q, m; + int j, l, m; - int x, p = findplayer(s, &x); + int x, p = findplayer(actor, &x); if (x < 8192) { j = s->ang; s->ang = getangle(s->x - ps[p].posx, s->y - ps[p].posy); - fi.shoot(i, FIRELASER); + fi.shoot(actor, FIRELASER); s->ang = j; } - if (s->owner == -1) //Start search + auto Owner = actor->GetOwner(); + if (Owner == nullptr) //Start search { t[4] = 0; l = 0x7fffffff; while (1) //Find the shortest dist { - s->owner = LocateTheLocator((short)t[4], -1); //t[0] hold sectnum + auto NewOwner = LocateTheLocator(t[4], -1); //t[0] hold sectnum + if (NewOwner == nullptr) break; - if (s->owner == -1) break; - - m = ldist(&sprite[ps[p].i], &sprite[s->owner]); + m = ldist(ps[p].GetActor(), NewOwner); if (l > m) { - q = s->owner; + Owner = NewOwner; l = m; } t[4]++; } - s->owner = q; - s->zvel = ksgn(sprite[q].z - s->z) << 4; + actor->SetOwner(Owner); + if (!Owner) return; // Undefined case - was not checked. + s->zvel = ksgn(Owner->s.z - s->z) << 4; } - if (ldist(&sprite[s->owner], s) < 1024) + if (ldist(Owner, actor) < 1024) { short ta; ta = s->ang; s->ang = getangle(ps[p].posx - s->x, ps[p].posy - s->y); s->ang = ta; - s->owner = -1; + actor->SetOwner(nullptr); return; } else s->xvel = 256; - x = getangle(sprite[s->owner].x - s->x, sprite[s->owner].y - s->y); - q = getincangle(s->ang, x) >> 3; + x = getangle(Owner->s.x - s->x, Owner->s.y - s->y); + int q = getincangle(s->ang, x) >> 3; s->ang += q; if (rnd(32)) @@ -3471,7 +3491,7 @@ void handle_se05(int i, int FIRELASER) getincangle(t[2] + 512, getangle(ps[p].posx - s->x, ps[p].posy - s->y)) >> 2; sc->ceilingshade = 0; } - j = fi.ifhitbyweapon(&hittype[i]); + j = fi.ifhitbyweapon(actor); if (j >= 0) { t[3]++; @@ -3485,8 +3505,8 @@ void handle_se05(int i, int FIRELASER) s->z += s->zvel; sc->ceilingz += s->zvel; sector[t[0]].ceilingz += s->zvel; - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); } //--------------------------------------------------------------------------- @@ -3495,23 +3515,23 @@ void handle_se05(int i, int FIRELASER) // //--------------------------------------------------------------------------- -void handle_se08(int i, bool checkhitag1) +void handle_se08(DDukeActor *actor, bool checkhitag1) { // work only if its moving - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; int x, j = -1; - if (hittype[i].temp_data[4]) + if (actor->temp_data[4]) { - hittype[i].temp_data[4]++; - if (hittype[i].temp_data[4] > 8) + actor->temp_data[4]++; + if (actor->temp_data[4] > 8) { - deletesprite(i); + deletesprite(actor); return; } j = 1; @@ -3522,22 +3542,21 @@ void handle_se08(int i, bool checkhitag1) { short sn; - if ((sc->lotag & 0x8000) || hittype[i].temp_data[4]) + if ((sc->lotag & 0x8000) || actor->temp_data[4]) x = -t[3]; else x = t[3]; if (st == 9) x = -x; - StatIterator it(STAT_EFFECTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto ac = it.Next()) { - auto sj = &sprite[j]; - if (((sj->lotag) == st) && (sj->hitag) == sh) + if (((ac->s.lotag) == st) && (ac->s.hitag) == sh) { - sn = sj->sectnum; + sn = ac->s.sectnum; auto sect = §or[sn]; - int m = sj->shade; + int m = ac->s.shade; auto wal = &wall[sect->wallptr]; @@ -3549,8 +3568,8 @@ void handle_se08(int i, bool checkhitag1) if (wal->shade < m) wal->shade = m; - else if (wal->shade > hittype[j].temp_data[2]) - wal->shade = hittype[j].temp_data[2]; + else if (wal->shade > ac->temp_data[2]) + wal->shade = ac->temp_data[2]; if (wal->nextwall >= 0) if (wall[wal->nextwall].hitag != 1) @@ -3563,16 +3582,16 @@ void handle_se08(int i, bool checkhitag1) if (sect->floorshade < m) sect->floorshade = m; - else if (sect->floorshade > hittype[j].temp_data[0]) - sect->floorshade = hittype[j].temp_data[0]; + else if (sect->floorshade > ac->temp_data[0]) + sect->floorshade = ac->temp_data[0]; if (sect->ceilingshade < m) sect->ceilingshade = m; - else if (sect->ceilingshade > hittype[j].temp_data[1]) - sect->ceilingshade = hittype[j].temp_data[1]; + else if (sect->ceilingshade > ac->temp_data[1]) + sect->ceilingshade = ac->temp_data[1]; if (checkhitag1 && sect->hitag == 1) - sect->ceilingshade = hittype[j].temp_data[1]; + sect->ceilingshade = ac->temp_data[1]; } } @@ -3585,10 +3604,10 @@ void handle_se08(int i, bool checkhitag1) // //--------------------------------------------------------------------------- -void handle_se10(int i, const int* specialtags) +void handle_se10(DDukeActor* actor, const int* specialtags) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -3600,7 +3619,7 @@ void handle_se10(int i, const int* specialtags) if ((sc->lotag & 0xff) != 27) for (int p = connecthead; p >= 0; p = connectpoint2[p]) if (sc->lotag != 30 && sc->lotag != 31 && sc->lotag != 0) - if (s->sectnum == sprite[ps[p].i].sectnum) + if (s->sectnum == ps[p].GetActor()->s.sectnum) j = 0; if (j == 1) @@ -3614,7 +3633,7 @@ void handle_se10(int i, const int* specialtags) return; } } - fi.activatebysector(s->sectnum, i); + fi.activatebysector(s->sectnum, actor); t[0] = 0; } else t[0]++; @@ -3629,10 +3648,10 @@ void handle_se10(int i, const int* specialtags) // //--------------------------------------------------------------------------- -void handle_se11(int i) +void handle_se11(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -3651,27 +3670,26 @@ void handle_se11(int i) for (int j = startwall; j < endwall; j++) { - StatIterator it(STAT_ACTOR); - int k; - while ((k = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto ac = it.Next()) { - auto sk = &sprite[k]; - if (sk->extra > 0 && badguy(&sprite[k]) && clipinsidebox(sk->x, sk->y, j, 256L) == 1) + auto sk = &ac->s; + if (sk->extra > 0 && badguy(ac) && clipinsidebox(sk->x, sk->y, j, 256L) == 1) return; } it.Reset(STAT_PLAYER); - while ((k = it.NextIndex()) >= 0) + while (auto ac = it.Next()) { - auto sk = &sprite[k]; - if (sk->owner >= 0 && clipinsidebox(sk->x, sk->y, j, 144L) == 1) + auto sk = &ac->s; + if (ac->GetOwner() && clipinsidebox(sk->x, sk->y, j, 144L) == 1) { t[5] = 8; // Delay - k = (s->yvel >> 3) * t[3]; + int k = (s->yvel >> 3) * t[3]; t[2] -= k; t[4] -= k; - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); return; } } @@ -3680,15 +3698,15 @@ void handle_se11(int i) int k = (s->yvel >> 3) * t[3]; t[2] += k; t[4] += k; - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); if (t[4] <= -511 || t[4] >= 512) { t[4] = 0; t[2] &= 0xffffff00; - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); } } } @@ -3699,10 +3717,10 @@ void handle_se11(int i) // //--------------------------------------------------------------------------- -void handle_se12(int i, int planeonly) +void handle_se12(DDukeActor *actor, int planeonly) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -3723,22 +3741,20 @@ void handle_se12(int i, int planeonly) sc->ceilingshade = t[2]; t[0] = 0; - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->cstat & 16) + if (a2->s.cstat & 16) { if (sc->ceilingstat & 1) - sj->shade = sc->ceilingshade; - else sj->shade = sc->floorshade; + a2->s.shade = sc->ceilingshade; + else a2->s.shade = sc->floorshade; } } if (t[3] == 1) { - deletesprite(i); + deletesprite(actor); return; } } @@ -3764,16 +3780,14 @@ void handle_se12(int i, int planeonly) } else t[0] = 2; - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->cstat & 16) + if (a2->s.cstat & 16) { if (sc->ceilingstat & 1) - sj->shade = sc->ceilingshade; - else sj->shade = sc->floorshade; + a2->s.shade = sc->ceilingshade; + else a2->s.shade = sc->floorshade; } } } @@ -3785,20 +3799,20 @@ void handle_se12(int i, int planeonly) // //--------------------------------------------------------------------------- -void handle_se13(int i) +void handle_se13(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; if (t[2]) { - int j = (sprite[i].yvel << 5) | 1; + int j = (s->yvel << 5) | 1; if (s->ang == 512) { - if (s->owner) + if (actor->spriteextra) { if (abs(t[0] - sc->ceilingz) >= j) sc->ceilingz += sgn(t[0] - sc->ceilingz) * j; @@ -3838,24 +3852,22 @@ void handle_se13(int i) if (ps[0].one_parallax_sectnum >= 0) { - sc->ceilingpicnum = - sector[ps[0].one_parallax_sectnum].ceilingpicnum; - sc->ceilingshade = - sector[ps[0].one_parallax_sectnum].ceilingshade; + sc->ceilingpicnum = sector[ps[0].one_parallax_sectnum].ceilingpicnum; + sc->ceilingshade = sector[ps[0].one_parallax_sectnum].ceilingshade; } } } t[2]++; if (t[2] > 256) { - deletesprite(i); + deletesprite(actor); return; } } if (t[2] == 4 && s->ang != 512) - for (int x = 0; x < 7; x++) RANDOMSCRAP(s, i); + for (int x = 0; x < 7; x++) RANDOMSCRAP(actor); } //--------------------------------------------------------------------------- @@ -3864,20 +3876,20 @@ void handle_se13(int i) // //--------------------------------------------------------------------------- -void handle_se15(int i) +void handle_se15(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; if (t[4]) { s->xvel = 16; if (t[4] == 1) //Opening { - if (t[3] >= (sprite[i].yvel >> 3)) + if (t[3] >= (s->yvel >> 3)) { t[4] = 0; //Turn off the sliders - callsound(s->sectnum, i); + callsound(s->sectnum, actor); return; } t[3]++; @@ -3887,14 +3899,14 @@ void handle_se15(int i) if (t[3] < 1) { t[4] = 0; - callsound(s->sectnum, i); + callsound(s->sectnum, actor); return; } t[3]--; } - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); } } @@ -3904,10 +3916,10 @@ void handle_se15(int i) // //--------------------------------------------------------------------------- -void handle_se16(int i, int REACTOR, int REACTOR2) +void handle_se16(DDukeActor* actor, int REACTOR, int REACTOR2) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; t[2] += 32; @@ -3921,17 +3933,16 @@ void handle_se16(int i, int REACTOR, int REACTOR2) //If there isn't, then kill this sectoreffector //itself..... - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + DDukeActor* a2; + while ((a2 = it.Next())) { - auto sj = &sprite[j]; - if (sj->picnum == REACTOR || sj->picnum == REACTOR2) + if (a2->s.picnum == REACTOR || a2->s.picnum == REACTOR2) return; } - if (j == -1) + if (a2 == nullptr) { - deletesprite(i); + deletesprite(actor); return; } else s->shade = 1; @@ -3940,8 +3951,8 @@ void handle_se16(int i, int REACTOR, int REACTOR2) if (s->shade) sc->ceilingz += 1024; else sc->ceilingz -= 512; - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); } //--------------------------------------------------------------------------- @@ -3950,50 +3961,46 @@ void handle_se16(int i, int REACTOR, int REACTOR2) // //--------------------------------------------------------------------------- -void handle_se17(int i) +void handle_se17(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; - int q = t[0] * (sprite[i].yvel << 2); + int q = t[0] * (s->yvel << 2); sc->ceilingz += q; sc->floorz += q; - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto act1 = it.Next()) { - auto sj = &sprite[j]; - if (sj->statnum == 10 && sj->owner >= 0) + if (act1->s.statnum == STAT_PLAYER && act1->GetOwner()) { - int p = sj->yvel; - if (numplayers < 2) - ps[p].oposz = ps[p].posz; + int p = act1->s.yvel; + if (numplayers < 2) ps[p].oposz = ps[p].posz; ps[p].posz += q; ps[p].truefz += q; ps[p].truecz += q; - if (numplayers > 1) - ps[p].oposz = ps[p].posz; + if (numplayers > 1) ps[p].oposz = ps[p].posz; } - if (sj->statnum != 3) + if (act1->s.statnum != 3) { - hittype[j].bposz = sj->z; - sj->z += q; + act1->bposz = act1->s.z; + act1->s.z += q; } - hittype[j].floorz = sc->floorz; - hittype[j].ceilingz = sc->ceilingz; + act1->floorz = sc->floorz; + act1->ceilingz = sc->ceilingz; } if (t[0]) //If in motion { - if (abs(sc->floorz - t[2]) <= sprite[i].yvel) + if (abs(sc->floorz - t[2]) <= s->yvel) { - activatewarpelevators(i, 0); + activatewarpelevators(actor, 0); return; } @@ -4007,65 +4014,59 @@ void handle_se17(int i) if (t[1] == 0) return; t[1] = 0; - StatIterator it(STAT_EFFECTOR); - int j; - while ((j = it.NextIndex()) >= 0) + DDukeActor* act2; + DukeStatIterator it(STAT_EFFECTOR); + while ((act2 = it.Next())) { - if (i != j && (sprite[j].lotag) == 17) - if ((sc->hitag - t[0]) == - (sector[sprite[j].sectnum].hitag) - && sh == (sprite[j].hitag)) + if (actor != act2 && (act2->s.lotag) == 17) + if ((sc->hitag - t[0]) == (sector[act2->s.sectnum].hitag) && sh == (act2->s.hitag)) break; } - if (j == -1) return; + if (act2 == nullptr) return; + auto spr2 = &act2->s; - SectIterator its(s->sectnum); - int k; - while ((k = its.NextIndex()) >= 0) + DukeSectIterator its(s->sectnum); + while (auto act3 = its.Next()) { - auto sk = &sprite[k]; - auto htk = &hittype[k]; - if (sk->statnum == 10 && sk->owner >= 0) + auto spr3 = &act3->s; + if (spr3->statnum == STAT_PLAYER && act3->GetOwner()) { - int p = sk->yvel; + int p = spr3->yvel; - ps[p].posx += sprite[j].x - s->x; - ps[p].posy += sprite[j].y - s->y; - ps[p].posz = sector[sprite[j].sectnum].floorz - (sc->floorz - ps[p].posz); + ps[p].posx += spr2->x - s->x; + ps[p].posy += spr2->y - s->y; + ps[p].posz = sector[spr2->sectnum].floorz - (sc->floorz - ps[p].posz); - htk->floorz = sector[sprite[j].sectnum].floorz; - htk->ceilingz = sector[sprite[j].sectnum].ceilingz; + act3->floorz = sector[spr2->sectnum].floorz; + act3->ceilingz = sector[spr2->sectnum].ceilingz; ps[p].bobposx = ps[p].oposx = ps[p].posx; ps[p].bobposy = ps[p].oposy = ps[p].posy; ps[p].oposz = ps[p].posz; - ps[p].truefz = htk->floorz; - ps[p].truecz = htk->ceilingz; + ps[p].truefz = act3->floorz; + ps[p].truecz = act3->ceilingz; ps[p].bobcounter = 0; - changespritesect(k, sprite[j].sectnum); - ps[p].cursectnum = sprite[j].sectnum; + changespritesect(act3, spr2->sectnum); + ps[p].cursectnum = spr2->sectnum; } - else if (sk->statnum != 3) + else if (spr3->statnum != 3) { - sk->x += - sprite[j].x - s->x; - sk->y += - sprite[j].y - s->y; - sk->z = sector[sprite[j].sectnum].floorz - - (sc->floorz - sk->z); + spr3->x += spr2->x - s->x; + spr3->y += spr2->y - s->y; + spr3->z = sector[spr2->sectnum].floorz - (sc->floorz - spr3->z); - htk->bposx = sk->x; - htk->bposy = sk->y; - htk->bposz = sk->z; + act3->bposx = spr3->x; + act3->bposy = spr3->y; + act3->bposz = spr3->z; - changespritesect(k, sprite[j].sectnum); - setsprite(k, sk->x, sk->y, sk->z); + changespritesect(act3, spr2->sectnum); + setsprite(act3, spr3->pos); - htk->floorz = sector[sprite[j].sectnum].floorz; - htk->ceilingz = sector[sprite[j].sectnum].ceilingz; + act3->floorz = sector[spr2->sectnum].floorz; + act3->ceilingz = sector[spr2->sectnum].ceilingz; } } @@ -4078,25 +4079,24 @@ void handle_se17(int i) // //--------------------------------------------------------------------------- -void handle_se18(int i, bool morecheck) +void handle_se18(DDukeActor *actor, bool morecheck) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - auto sc = §or[s->sectnum]; - int st = s->lotag; - int sh = s->hitag; + int* t = &actor->temp_data[0]; + auto sc = §or[actor->s.sectnum]; + int st = actor->s.lotag; + int sh = actor->s.hitag; if (t[0]) { - if (s->pal) + if (actor->s.pal) { - if (s->ang == 512) + if (actor->s.ang == 512) { sc->ceilingz -= sc->extra; if (sc->ceilingz <= t[1]) { sc->ceilingz = t[1]; - deletesprite(i); + deletesprite(actor); return; } } @@ -4105,38 +4105,35 @@ void handle_se18(int i, bool morecheck) sc->floorz += sc->extra; if (morecheck) { - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(actor->s.sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->picnum == TILE_APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += sc->extra; - if (sj->zvel == 0 && sj->statnum != STAT_EFFECTOR && sj->statnum != STAT_PROJECTILE) + if (a2->s.picnum == TILE_APLAYER && a2->GetOwner()) + if (ps[a2->PlayerIndex()].on_ground == 1) ps[a2->PlayerIndex()].posz += sc->extra; + if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && a2->s.statnum != STAT_PROJECTILE) { - hittype[j].bposz = sj->z += sc->extra; - hittype[j].floorz = sc->floorz; + a2->bposz = a2->s.z += sc->extra; + a2->floorz = sc->floorz; } } } if (sc->floorz >= t[1]) { sc->floorz = t[1]; - deletesprite(i); + deletesprite(actor); return; } } } else { - if (s->ang == 512) + if (actor->s.ang == 512) { sc->ceilingz += sc->extra; - if (sc->ceilingz >= s->z) + if (sc->ceilingz >= actor->s.z) { - sc->ceilingz = s->z; - deletesprite(i); + sc->ceilingz = actor->s.z; + deletesprite(actor); return; } } @@ -4145,32 +4142,29 @@ void handle_se18(int i, bool morecheck) sc->floorz -= sc->extra; if (morecheck) { - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(actor->s.sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->picnum == TILE_APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz -= sc->extra; - if (sj->zvel == 0 && sj->statnum != STAT_EFFECTOR && sj->statnum != STAT_PROJECTILE) + if (a2->s.picnum == TILE_APLAYER && a2->GetOwner()) + if (ps[a2->PlayerIndex()].on_ground == 1) ps[a2->PlayerIndex()].posz -= sc->extra; + if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && a2->s.statnum != STAT_PROJECTILE) { - hittype[j].bposz = sj->z -= sc->extra; - hittype[j].floorz = sc->floorz; + a2->bposz = a2->s.z -= sc->extra; + a2->floorz = sc->floorz; } } } - if (sc->floorz <= s->z) + if (sc->floorz <= actor->s.z) { - sc->floorz = s->z; - deletesprite(i); + sc->floorz = actor->s.z; + deletesprite(actor); return; } } } t[2]++; - if (t[2] >= s->hitag) + if (t[2] >= actor->s.hitag) { t[2] = 0; t[0] = 0; @@ -4184,13 +4178,12 @@ void handle_se18(int i, bool morecheck) // //--------------------------------------------------------------------------- -void handle_se19(int i, int BIGFORCE) +void handle_se19(DDukeActor *actor, int BIGFORCE) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - auto sc = §or[s->sectnum]; - int st = s->lotag; - int sh = s->hitag; + int* t = &actor->temp_data[0]; + auto sc = §or[actor->s.sectnum]; + int st = actor->s.lotag; + int sh = actor->s.hitag; int j, x, q; if (t[0]) @@ -4214,56 +4207,46 @@ void handle_se19(int i, int BIGFORCE) } if (sc->ceilingz < sc->floorz) - sc->ceilingz += sprite[i].yvel; + sc->ceilingz += actor->s.yvel; else { sc->ceilingz = sc->floorz; - StatIterator it(STAT_EFFECTOR); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->lotag == 0 && sj->hitag == sh) + auto a2Owner = a2->GetOwner(); + if (a2->s.lotag == 0 && a2->s.hitag == sh && a2Owner) { - q = sprite[sj->owner].sectnum; - sector[sj->sectnum].floorpal = sector[sj->sectnum].ceilingpal = - sector[q].floorpal; - sector[sj->sectnum].floorshade = sector[sj->sectnum].ceilingshade = - sector[q].floorshade; - - hittype[sj->owner].temp_data[0] = 2; + q = a2Owner->s.sectnum; + sector[a2->s.sectnum].floorpal = sector[a2->s.sectnum].ceilingpal = sector[q].floorpal; + sector[a2->s.sectnum].floorshade = sector[a2->s.sectnum].ceilingshade = sector[q].floorshade; + a2Owner->temp_data[0] = 2; } } - deletesprite(i); + deletesprite(actor); return; } } else //Not hit yet { - j = fi.ifhitsectors(s->sectnum); - if (j >= 0) + auto hitter = fi.ifhitsectors(actor->s.sectnum); + if (hitter) { FTA(8, &ps[myconnectindex]); - StatIterator it(STAT_EFFECTOR); - int l; - while ((l = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto ac = it.Next()) { - auto sl = &sprite[l]; - x = sl->lotag & 0x7fff; + x = ac->s.lotag & 0x7fff; switch (x) { case 0: - if (sl->hitag == sh) + if (ac->s.hitag == sh && ac->GetOwner()) { - q = sl->sectnum; - sector[q].floorshade = - sector[q].ceilingshade = - sprite[sl->owner].shade; - sector[q].floorpal = - sector[q].ceilingpal = - sprite[sl->owner].pal; + q = ac->s.sectnum; + sector[q].floorshade = sector[q].ceilingshade = ac->GetOwner()->s.shade; + sector[q].floorpal = sector[q].ceilingpal = ac->GetOwner()->s.pal; } break; @@ -4272,11 +4255,11 @@ void handle_se19(int i, int BIGFORCE) //case 18: case 19: - if (sh == sl->hitag) - if (hittype[l].temp_data[0] == 0) + if (sh == ac->s.hitag) + if (ac->temp_data[0] == 0) { - hittype[l].temp_data[0] = 1; //Shut them all on - sl->owner = i; + ac->temp_data[0] = 1; //Shut them all on + ac->SetOwner(actor); } break; @@ -4292,10 +4275,10 @@ void handle_se19(int i, int BIGFORCE) // //--------------------------------------------------------------------------- -void handle_se20(int i) +void handle_se20(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -4314,28 +4297,26 @@ void handle_se20(int i) s->x += x; s->y += l; - if (t[3] <= 0 || (t[3] >> 6) >= (sprite[i].yvel >> 6)) + if (t[3] <= 0 || (t[3] >> 6) >= (s->yvel >> 6)) { s->x -= x; s->y -= l; t[0] = 0; - callsound(s->sectnum, i); + callsound(s->sectnum, actor); return; } - SectIterator it(s->sectnum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->statnum != 3 && sj->zvel == 0) + if (a2->s.statnum != 3 && a2->s.zvel == 0) { - sj->x += x; - sj->y += l; - setsprite(j, sj->x, sj->y, sj->z); - if (sector[sj->sectnum].floorstat & 2) - if (sj->statnum == 2) - makeitfall(j); + a2->s.x += x; + a2->s.y += l; + setsprite(a2, a2->s.pos); + if (sector[a2->s.sectnum].floorstat & 2) + if (a2->s.statnum == 2) + makeitfall(a2); } } @@ -4351,7 +4332,7 @@ void handle_se20(int i) ps[p].oposx = ps[p].posx; ps[p].oposy = ps[p].posy; - setsprite(ps[p].i, ps[p].posx, ps[p].posy, ps[p].posz + PHEIGHT); + setsprite(ps[p].GetActor(), ps[p].posx, ps[p].posy, ps[p].posz + PHEIGHT); } sc->floorxpanning -= x >> 3; @@ -4368,10 +4349,10 @@ void handle_se20(int i) // //--------------------------------------------------------------------------- -void handle_se21(int i) +void handle_se21(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -4386,7 +4367,7 @@ void handle_se21(int i) if (t[0] == 1) //Decide if the s->sectnum should go up or down { - s->zvel = ksgn(s->z - *lp) * (sprite[i].yvel << 4); + s->zvel = ksgn(s->z - *lp) * (s->yvel << 4); t[0]++; } @@ -4397,7 +4378,7 @@ void handle_se21(int i) if (abs(*lp - s->z) < 1024) { *lp = s->z; - deletesprite(i); + deletesprite(actor); } } else sc->extra--; @@ -4409,11 +4390,10 @@ void handle_se21(int i) // //--------------------------------------------------------------------------- -void handle_se22(int i) +void handle_se22(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - auto sc = §or[s->sectnum]; + int* t = &actor->temp_data[0]; + auto sc = §or[actor->s.sectnum]; if (t[1]) { if (getanimationgoal(anim_ceilingz, t[0]) >= 0) @@ -4428,12 +4408,12 @@ void handle_se22(int i) // //--------------------------------------------------------------------------- -void handle_se26(int i) +void handle_se26(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; - int x, j, l; + int x, l; s->xvel = 32; l = (s->xvel * sintable[(s->ang + 512) & 2047]) >> 14; @@ -4450,33 +4430,32 @@ void handle_se26(int i) else sc->floorz += s->zvel; - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->statnum != 3 && sj->statnum != 10) + if (a2->s.statnum != 3 && a2->s.statnum != 10) { - hittype[j].bposx = sj->x; - hittype[j].bposy = sj->y; + a2->bposx = a2->s.x; + a2->bposy = a2->s.y; - sj->x += l; - sj->y += x; + a2->s.x += l; + a2->s.y += x; - sj->z += s->zvel; - setsprite(j, sj->x, sj->y, sj->z); + a2->s.z += s->zvel; + setsprite(a2, a2->s.pos); } } for (int p = connecthead; p >= 0; p = connectpoint2[p]) - if (sprite[ps[p].i].sectnum == s->sectnum && ps[p].on_ground) + if (ps[p].GetActor()->s.sectnum == s->sectnum && ps[p].on_ground) { ps[p].fric.x += l << 5; ps[p].fric.y += x << 5; ps[p].posz += s->zvel; } - ms(i); - setsprite(i, s->x, s->y, s->z); + ms(actor); + setsprite(actor, s->pos); } //--------------------------------------------------------------------------- @@ -4485,10 +4464,10 @@ void handle_se26(int i) // //--------------------------------------------------------------------------- -void handle_se27(int i) +void handle_se27(DDukeActor* actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; int st = s->lotag; int sh = s->hitag; @@ -4496,34 +4475,34 @@ void handle_se27(int i) if (ud.recstat == 0) return; - hittype[i].tempang = s->ang; + actor->tempang = s->ang; - p = findplayer(s, &x); - if (sprite[ps[p].i].extra > 0 && myconnectindex == screenpeek) + p = findplayer(actor, &x); + if (ps[p].GetActor()->s.extra > 0 && myconnectindex == screenpeek) { if (t[0] < 0) { - ud.camerasprite = i; + ud.cameraactor = actor; t[0]++; } - else if (ud.recstat == 2 && ps[p].newowner == -1) + else if (ud.recstat == 2 && ps[p].newOwner == nullptr) { - if (cansee(s->x, s->y, s->z, sprite[i].sectnum, ps[p].posx, ps[p].posy, ps[p].posz, ps[p].cursectnum)) + if (cansee(s->x, s->y, s->z, s->sectnum, ps[p].posx, ps[p].posy, ps[p].posz, ps[p].cursectnum)) { if (x < (unsigned)sh) { - ud.camerasprite = i; + ud.cameraactor = actor; t[0] = 999; s->ang += getincangle(s->ang, getangle(ps[p].posx - s->x, ps[p].posy - s->y)) >> 3; - sprite[i].yvel = 100 + ((s->z - ps[p].posz) / 257); + s->yvel = 100 + ((s->z - ps[p].posz) / 257); } else if (t[0] == 999) { - if (ud.camerasprite == i) + if (ud.cameraactor == actor) t[0] = 0; else t[0] = -10; - ud.camerasprite = i; + ud.cameraactor = actor; } } @@ -4533,10 +4512,10 @@ void handle_se27(int i) if (t[0] == 999) { - if (ud.camerasprite == i) + if (ud.cameraactor == actor) t[0] = 0; else t[0] = -20; - ud.camerasprite = i; + ud.cameraactor = actor; } } } @@ -4549,10 +4528,130 @@ void handle_se27(int i) // //--------------------------------------------------------------------------- -void handle_se32(int i) +void handle_se24(DDukeActor *actor, int16_t *list1, int16_t *list2, int TRIPBOMB, int LASERLINE, int CRANE, int shift) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; + + auto testlist = [](int16_t* list, int val) { for (int i = 0; list[i] > 0; i++) if (list[i] == val) return true; return false; }; + + if (t[4]) return; + + int x = (actor->s.yvel * sintable[(actor->s.ang + 512) & 2047]) >> 18; + int l = (actor->s.yvel * sintable[actor->s.ang & 2047]) >> 18; + + DukeSectIterator it(actor->s.sectnum); + while (auto a2 = it.Next()) + { + auto s2 = &a2->s; + if (s2->zvel >= 0) + { + switch (s2->statnum) + { + case 5: + if (testlist(list1, s2->picnum)) + { + s2->xrepeat = s2->yrepeat = 0; + continue; + } + if (s2->picnum == LASERLINE) + { + continue; + } + + //[[fallthrough]] + case 6: + if (s2->picnum == TRIPBOMB) break; + //[[fallthrough]] + case 1: + case 0: + if (testlist(list2, s2->picnum) || + wallswitchcheck(a2)) + break; + + if (!(s2->picnum >= CRANE && s2->picnum <= (CRANE + 3))) + { + if (s2->z > (a2->floorz - (16 << 8))) + { + a2->bposx = s2->x; + a2->bposy = s2->y; + + s2->x += x >> shift; + s2->y += l >> shift; + + setsprite(a2, s2->pos); + + if (sector[s2->sectnum].floorstat & 2) + if (s2->statnum == 2) + makeitfall(a2); + } + } + break; + } + } + } + + for (auto p = connecthead; p >= 0; p = connectpoint2[p]) + { + if (ps[p].cursectnum == actor->s.sectnum && ps[p].on_ground) + { + if (abs(ps[p].pos.z - ps[p].truefz) < PHEIGHT + (9 << 8)) + { + ps[p].fric.x += x << 3; + ps[p].fric.y += l << 3; + } + } + } + sector[actor->s.sectnum].floorxpanning += actor->s.yvel >> 7; +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void handle_se25(DDukeActor* actor, int t_index, int snd1, int snd2) +{ + int* t = &actor->temp_data[0]; + auto sec = §or[actor->s.sectnum]; + + if (sec->floorz <= sec->ceilingz) + actor->s.shade = 0; + else if (sec->ceilingz <= t[t_index]) + actor->s.shade = 1; + + if (actor->s.shade) + { + sec->ceilingz += actor->s.yvel << 4; + if (sec->ceilingz > sec->floorz) + { + sec->ceilingz = sec->floorz; + if (pistonsound && snd1 >= 0) + S_PlayActorSound(snd1, actor); + } + } + else + { + sec->ceilingz -= actor->s.yvel << 4; + if (sec->ceilingz < t[t_index]) + { + sec->ceilingz = t[t_index]; + if (pistonsound && snd2 >= 0) + S_PlayActorSound(snd2, actor); + } + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void handle_se32(DDukeActor *actor) +{ + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; if (t[0] == 1) @@ -4561,57 +4660,51 @@ void handle_se32(int i) if (t[2] == 1) // Retract { - if (sprite[i].ang != 1536) + if (s->ang != 1536) { - if (abs(sc->ceilingz - s->z) < - (sprite[i].yvel << 1)) + if (abs(sc->ceilingz - s->z) < (s->yvel << 1)) { sc->ceilingz = s->z; - callsound(s->sectnum, i); + callsound(s->sectnum, actor); t[2] = 0; t[0] = 0; } - else sc->ceilingz += - sgn(s->z - sc->ceilingz) * sprite[i].yvel; + else sc->ceilingz += sgn(s->z - sc->ceilingz) * s->yvel; } else { - if (abs(sc->ceilingz - t[1]) < - (sprite[i].yvel << 1)) + if (abs(sc->ceilingz - t[1]) < (s->yvel << 1)) { sc->ceilingz = t[1]; - callsound(s->sectnum, i); + callsound(s->sectnum, actor); t[2] = 0; t[0] = 0; } - else sc->ceilingz += - sgn(t[1] - sc->ceilingz) * sprite[i].yvel; + else sc->ceilingz += sgn(t[1] - sc->ceilingz) * s->yvel; } return; } if ((s->ang & 2047) == 1536) { - if (abs(sc->ceilingz - s->z) < - (sprite[i].yvel << 1)) + if (abs(sc->ceilingz - s->z) < (s->yvel << 1)) { t[0] = 0; t[2] = !t[2]; - callsound(s->sectnum, i); + callsound(s->sectnum, actor); sc->ceilingz = s->z; } - else sc->ceilingz += - sgn(s->z - sc->ceilingz) * sprite[i].yvel; + else sc->ceilingz += sgn(s->z - sc->ceilingz) * s->yvel; } else { - if (abs(sc->ceilingz - t[1]) < (sprite[i].yvel << 1)) + if (abs(sc->ceilingz - t[1]) < (s->yvel << 1)) { t[0] = 0; t[2] = !t[2]; - callsound(s->sectnum, i); + callsound(s->sectnum, actor); } - else sc->ceilingz -= sgn(s->z - t[1]) * sprite[i].yvel; + else sc->ceilingz -= sgn(s->z - t[1]) * s->yvel; } } @@ -4623,22 +4716,22 @@ void handle_se32(int i) // //--------------------------------------------------------------------------- -void handle_se35(int i, int SMALLSMOKE, int EXPLOSION2) +void handle_se35(DDukeActor *actor, int SMALLSMOKE, int EXPLOSION2) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; auto sc = §or[s->sectnum]; if (sc->ceilingz > s->z) for (int j = 0; j < 8; j++) { s->ang += krand() & 511; - int k = fi.spawn(i, SMALLSMOKE); - sprite[k].xvel = 96 + (krand() & 127); - ssp(k, CLIPMASK0); - setsprite(k, sprite[k].x, sprite[k].y, sprite[k].z); + auto spawned = spawn(actor, SMALLSMOKE); + spawned->s.xvel = 96 + (krand() & 127); + ssp(spawned, CLIPMASK0); + setsprite(spawned, spawned->s.pos); if (rnd(16)) - fi.spawn(i, EXPLOSION2); + spawn(actor, EXPLOSION2); } switch (t[0]) @@ -4667,11 +4760,10 @@ void handle_se35(int i, int SMALLSMOKE, int EXPLOSION2) // //--------------------------------------------------------------------------- -void handle_se128(int i) +void handle_se128(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - auto sc = §or[s->sectnum]; + int* t = &actor->temp_data[0]; + auto sc = §or[actor->s.sectnum]; auto wal = &wall[t[2]]; @@ -4697,7 +4789,7 @@ void handle_se128(int i) wal->cstat &= (128 + 32 + 8 + 4 + 2); if (wal->nextwall >= 0) wall[wal->nextwall].cstat &= (128 + 32 + 8 + 4 + 2); - deletesprite(i); + deletesprite(actor); } } @@ -4707,16 +4799,14 @@ void handle_se128(int i) // //--------------------------------------------------------------------------- -void handle_se130(int i, int countmax, int EXPLOSION2) +void handle_se130(DDukeActor *actor, int countmax, int EXPLOSION2) { - auto act = &hittype[i]; - spritetype* s = &act->s; - auto t = &act->temp_data[0]; - auto sc = §or[s->sectnum]; + int* t = &actor->temp_data[0]; + auto sc = §or[actor->s.sectnum]; if (t[0] > countmax) { - deletesprite(i); + deletesprite(actor); return; } else t[0]++; @@ -4725,7 +4815,7 @@ void handle_se130(int i, int countmax, int EXPLOSION2) if (rnd(64)) { - auto k = spawn(act, EXPLOSION2); + auto k = spawn(actor, EXPLOSION2); k->s.xrepeat = k->s.yrepeat = 2 + (krand() & 7); k->s.z = sc->floorz - (krand() % x); k->s.ang += 256 - (krand() % 511); @@ -4740,52 +4830,141 @@ void handle_se130(int i, int countmax, int EXPLOSION2) // //--------------------------------------------------------------------------- -void getglobalz(int i) +void handle_se31(DDukeActor* actor, bool choosedir) { - int hz,lz,zr; + auto s = &actor->s; + int* t = &actor->temp_data[0]; + auto sec = §or[s->sectnum]; - spritetype *s = &sprite[i]; - - if( s->statnum == STAT_PLAYER || s->statnum == STAT_STANDABLE || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_ACTOR || s->statnum == STAT_PROJECTILE) + if (t[0] == 1) { - if(s->statnum == STAT_PROJECTILE) - zr = 4; - else zr = 127; + // Choose dir - getzrange(s->x,s->y,s->z-(FOURSLEIGHT),s->sectnum,&hittype[i].ceilingz,&hz,&hittype[i].floorz,&lz,zr,CLIPMASK0); - - if( (lz&49152) == 49152 && (sprite[lz&(MAXSPRITES-1)].cstat&48) == 0 ) + if (choosedir && t[3] > 0) { - lz &= (MAXSPRITES-1); - if( badguy(&sprite[lz]) && sprite[lz].pal != 1) + t[3]--; + return; + } + + if (t[2] == 1) // Retract + { + if (s->ang != 1536) { - if( s->statnum != 4 ) + if (abs(sec->floorz - s->z) < s->yvel) { - hittype[i].aflags |= SFLAG_NOFLOORSHADOW; - //hittype[i].dispicnum = -4; // No shadows on actors - s->xvel = -256; - ssp(i,CLIPMASK0); + sec->floorz = s->z; + t[2] = 0; + t[0] = 0; + if (choosedir) t[3] = s->hitag; + callsound(s->sectnum, actor); + } + else + { + int l = sgn(s->z - sec->floorz) * s->yvel; + sec->floorz += l; + + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) + { + if (a2->s.picnum == TILE_APLAYER && a2->GetOwner()) + if (ps[a2->PlayerIndex()].on_ground == 1) + ps[a2->PlayerIndex()].posz += l; + if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && (!choosedir || a2->s.statnum != STAT_PROJECTILE)) + { + a2->bposz = a2->s.z += l; + a2->floorz = sec->floorz; + } + } } } - else if(sprite[lz].picnum == TILE_APLAYER && badguy(s) ) + else { - hittype[i].aflags |= SFLAG_NOFLOORSHADOW; - //hittype[i].dispicnum = -4; // No shadows on actors - s->xvel = -256; - ssp(i,CLIPMASK0); + if (abs(sec->floorz - t[1]) < s->yvel) + { + sec->floorz = t[1]; + callsound(s->sectnum, actor); + t[2] = 0; + t[0] = 0; + if (choosedir) t[3] = s->hitag; + } + else + { + int l = sgn(t[1] - sec->floorz) * s->yvel; + sec->floorz += l; + + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) + { + if (a2->s.picnum == TILE_APLAYER && a2->GetOwner()) + if (ps[a2->PlayerIndex()].on_ground == 1) + ps[a2->PlayerIndex()].posz += l; + if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && (!choosedir || a2->s.statnum != STAT_PROJECTILE)) + { + a2->bposz = a2->s.z += l; + a2->floorz = sec->floorz; + } + } + } } - else if(s->statnum == 4 && sprite[lz].picnum == TILE_APLAYER) - if(s->owner == lz) + return; + } + + if ((s->ang & 2047) == 1536) + { + if (abs(s->z - sec->floorz) < s->yvel) { - hittype[i].ceilingz = sector[s->sectnum].ceilingz; - hittype[i].floorz = sector[s->sectnum].floorz; + callsound(s->sectnum, actor); + t[0] = 0; + t[2] = 1; + if (choosedir) t[3] = s->hitag; + } + else + { + int l = sgn(s->z - sec->floorz) * s->yvel; + sec->floorz += l; + + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) + { + if (a2->s.picnum == TILE_APLAYER && a2->GetOwner()) + if (ps[a2->PlayerIndex()].on_ground == 1) + ps[a2->PlayerIndex()].posz += l; + if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && (!choosedir || a2->s.statnum != STAT_PROJECTILE)) + { + a2->bposz = a2->s.z += l; + a2->floorz = sec->floorz; + } + } + } + } + else + { + if (abs(sec->floorz - t[1]) < s->yvel) + { + t[0] = 0; + callsound(s->sectnum, actor); + t[2] = 1; + t[3] = s->hitag; + } + else + { + int l = sgn(s->z - t[1]) * s->yvel; + sec->floorz -= l; + + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) + { + if (a2->s.picnum ==TILE_APLAYER && a2->GetOwner()) + if (ps[a2->PlayerIndex()].on_ground == 1) + ps[a2->PlayerIndex()].posz -= l; + if (a2->s.zvel == 0 && a2->s.statnum != STAT_EFFECTOR && (!choosedir || a2->s.statnum != STAT_PROJECTILE)) + { + a2->bposz = a2->s.z -= l; + a2->floorz = sec->floorz; + } + } } } - } - else - { - hittype[i].ceilingz = sector[s->sectnum].ceilingz; - hittype[i].floorz = sector[s->sectnum].floorz; } } @@ -4795,10 +4974,63 @@ void getglobalz(int i) // //--------------------------------------------------------------------------- -void makeitfall(int i) +void getglobalz(DDukeActor* actor) { - spritetype *s = &sprite[i]; - int hz,lz,c; + auto s = &actor->s; + int zr; + Collision hz, lz; + + if( s->statnum == STAT_PLAYER || s->statnum == STAT_STANDABLE || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_ACTOR || s->statnum == STAT_PROJECTILE) + { + if(s->statnum == STAT_PROJECTILE) + zr = 4; + else zr = 127; + + getzrange_ex(s->x, s->y, s->z - (FOURSLEIGHT), s->sectnum, &actor->ceilingz, hz, &actor->floorz, lz, zr, CLIPMASK0); + + if( lz.type == kHitSprite && (lz.actor->s.cstat&48) == 0 ) + { + if( badguy(lz.actor) && lz.actor->s.pal != 1) + { + if( s->statnum != STAT_PROJECTILE) + { + actor->aflags |= SFLAG_NOFLOORSHADOW; + //actor->dispicnum = -4; // No shadows on actors + s->xvel = -256; + ssp(actor, CLIPMASK0); + } + } + else if(lz.actor->s.picnum == TILE_APLAYER && badguy(actor) ) + { + actor->aflags |= SFLAG_NOFLOORSHADOW; + //actor->dispicnum = -4; // No shadows on actors + s->xvel = -256; + ssp(actor, CLIPMASK0); + } + else if(s->statnum == STAT_PROJECTILE && lz.actor->s.picnum == TILE_APLAYER && actor->GetOwner() == actor) + { + actor->ceilingz = sector[s->sectnum].ceilingz; + actor->floorz = sector[s->sectnum].floorz; + } + } + } + else + { + actor->ceilingz = sector[s->sectnum].ceilingz; + actor->floorz = sector[s->sectnum].floorz; + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void makeitfall(DDukeActor* actor) +{ + auto s = &actor->s; + int c; if( fi.floorspace(s->sectnum) ) c = 0; @@ -4811,18 +5043,21 @@ void makeitfall(int i) if (isRRRA()) { - c = adjustfall(s, c); // this accesses sprite indices and cannot be in shared code. Should be done better. + c = adjustfall(actor, c); // this accesses sprite indices and cannot be in shared code. Should be done better. } - if( ( s->statnum == STAT_ACTOR || s->statnum == STAT_PLAYER || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_STANDABLE ) ) - getzrange(s->x,s->y,s->z-(FOURSLEIGHT),s->sectnum,&hittype[i].ceilingz,&hz,&hittype[i].floorz,&lz,127L,CLIPMASK0); + if ((s->statnum == STAT_ACTOR || s->statnum == STAT_PLAYER || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_STANDABLE)) + { + Collision c; + getzrange_ex(s->x, s->y, s->z - (FOURSLEIGHT), s->sectnum, &actor->ceilingz, c, &actor->floorz, c, 127, CLIPMASK0); + } else { - hittype[i].ceilingz = sector[s->sectnum].ceilingz; - hittype[i].floorz = sector[s->sectnum].floorz; + actor->ceilingz = sector[s->sectnum].ceilingz; + actor->floorz = sector[s->sectnum].floorz; } - if( s->z < hittype[i].floorz-(FOURSLEIGHT) ) + if( s->z < actor->floorz-(FOURSLEIGHT) ) { if( sector[s->sectnum].lotag == 2 && s->zvel > 3122 ) s->zvel = 3144; @@ -4831,9 +5066,9 @@ void makeitfall(int i) else s->zvel = 6144; s->z += s->zvel; } - if( s->z >= hittype[i].floorz-(FOURSLEIGHT) ) + if( s->z >= actor->floorz-(FOURSLEIGHT) ) { - s->z = hittype[i].floorz - FOURSLEIGHT; + s->z = actor->floorz - FOURSLEIGHT; s->zvel = 0; } } @@ -4844,20 +5079,20 @@ void makeitfall(int i) // //--------------------------------------------------------------------------- -int dodge(spritetype* s) +int dodge(DDukeActor* actor) { - int i; + auto s = &actor->s; int bx, by, mx, my, bxvect, byvect, mxvect, myvect, d; mx = s->x; my = s->y; mxvect = sintable[(s->ang + 512) & 2047]; myvect = sintable[s->ang & 2047]; - StatIterator it(STAT_PROJECTILE); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_PROJECTILE); + while (auto ac = it.Next()) { - auto si = &sprite[i]; - if (si->owner == i || si->sectnum != s->sectnum) + auto si = &ac->s; + if (ac->GetOwner() == ac || si->sectnum != s->sectnum) continue; bx = si->x - mx; @@ -4884,24 +5119,22 @@ int dodge(spritetype* s) // //--------------------------------------------------------------------------- -int furthestangle(int i, int angs) +int furthestangle(DDukeActor *actor, int angs) { - short j, hitsect, hitwall, hitspr, furthest_angle, angincs; + auto s = &actor->s; + short j, hitsect, hitwall, furthest_angle, angincs; int hx, hy, hz, d, greatestd; - spritetype* s = &sprite[i]; + DDukeActor* dd; greatestd = -(1 << 30); angincs = 2048 / angs; if (s->picnum != TILE_APLAYER) - if ((hittype[i].temp_data[0] & 63) > 2) return(s->ang + 1024); + if ((actor->temp_data[0] & 63) > 2) return(s->ang + 1024); for (j = s->ang; j < (2048 + s->ang); j += angincs) { - hitscan(s->x, s->y, s->z - (8 << 8), s->sectnum, - sintable[(j + 512) & 2047], - sintable[j & 2047], 0, - &hitsect, &hitwall, &hitspr, &hx, &hy, &hz, CLIPMASK1); + hitscan(s->x, s->y, s->z - (8 << 8), s->sectnum, sintable[(j + 512) & 2047], sintable[j & 2047], 0, &hitsect, &hitwall, &dd, &hx, &hy, &hz, CLIPMASK1); d = abs(hx - s->x) + abs(hy - s->y); @@ -4920,24 +5153,24 @@ int furthestangle(int i, int angs) // //--------------------------------------------------------------------------- -int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day) +int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, int* dax, int* day) { - short j, hitsect, hitwall, hitspr, angincs; + auto s = &actor->s; + short j, hitsect, hitwall, angincs; int hx, hy, hz, d, da;//, d, cd, ca,tempx,tempy,cx,cy; - spritetype* s = &sprite[i]; + DDukeActor* dd; - if ((hittype[i].temp_data[0] & 63)) return -1; + if ((actor->temp_data[0] & 63)) return -1; if (ud.multimode < 2 && ud.player_skill < 3) angincs = 2048 / 2; else angincs = 2048 / (1 + (krand() & 1)); + auto ts = &tosee->s; for (j = ts->ang; j < (2048 + ts->ang); j += (angincs - (krand() & 511))) { - hitscan(ts->x, ts->y, ts->z - (16 << 8), ts->sectnum, - sintable[(j + 512) & 2047], - sintable[j & 2047], 16384 - (krand() & 32767), - &hitsect, &hitwall, &hitspr, &hx, &hy, &hz, CLIPMASK1); + hitscan(ts->x, ts->y, ts->z - (16 << 8), ts->sectnum, sintable[(j + 512) & 2047], sintable[j & 2047], 16384 - (krand() & 32767), + &hitsect, &hitwall, &dd, &hx, &hy, &hz, CLIPMASK1); d = abs(hx - ts->x) + abs(hy - ts->y); da = abs(hx - s->x) + abs(hy - s->y); @@ -4959,40 +5192,41 @@ int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day) // //--------------------------------------------------------------------------- -void alterang(int a, int g_i, int g_p) +void alterang(int ang, DDukeActor* actor, int playernum) { + auto s = &actor->s; short aang, angdif, goalang, j; int ticselapsed; - int* g_t = hittype[g_i].temp_data; - auto* g_sp = &sprite[g_i]; + int* t = actor->temp_data; - auto moveptr = &ScriptCode[g_t[1]]; + auto moveptr = &ScriptCode[t[1]]; - ticselapsed = (g_t[0]) & 31; + ticselapsed = (t[0]) & 31; - aang = g_sp->ang; + aang = s->ang; - g_sp->xvel += (*moveptr - g_sp->xvel) / 5; - if (g_sp->zvel < 648) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) / 5; + s->xvel += (*moveptr - s->xvel) / 5; + if (s->zvel < 648) s->zvel += ((*(moveptr + 1) << 4) - s->zvel) / 5; - if (isRRRA() && (a & windang)) - g_sp->ang = WindDir; - else if (a & seekplayer) + if (isRRRA() && (ang & windang)) + s->ang = WindDir; + else if (ang & seekplayer) { - j = !isRR()? ps[g_p].holoduke_on->GetIndex() : -1; + auto holoduke = !isRR()? ps[playernum].holoduke_on : nullptr; - // NOTE: looks like 'owner' is set to target sprite ID... + // NOTE: looks like 'Owner' is set to target sprite ID... - if (j >= 0 && cansee(sprite[j].x, sprite[j].y, sprite[j].z, sprite[j].sectnum, g_sp->x, g_sp->y, g_sp->z, g_sp->sectnum)) - g_sp->owner = j; - else g_sp->owner = ps[g_p].i; + if (holoduke && cansee(holoduke->s.x, holoduke->s.y, holoduke->s.z, holoduke->s.sectnum, s->x, s->y, s->z, s->sectnum)) + actor->SetOwner(holoduke); + else actor->SetOwner(ps[playernum].GetActor()); - if (sprite[g_sp->owner].picnum == TILE_APLAYER) - goalang = getangle(hittype[g_i].lastvx - g_sp->x, hittype[g_i].lastvy - g_sp->y); + auto Owner = actor->GetOwner(); + if (Owner->s.picnum == TILE_APLAYER) + goalang = getangle(actor->lastvx - s->x, actor->lastvy - s->y); else - goalang = getangle(sprite[g_sp->owner].x - g_sp->x, sprite[g_sp->owner].y - g_sp->y); + goalang = getangle(Owner->s.x - s->x, Owner->s.y - s->y); - if (g_sp->xvel && g_sp->picnum != TILE_DRONE) + if (s->xvel && s->picnum != TILE_DRONE) { angdif = getincangle(aang, goalang); @@ -5001,34 +5235,34 @@ void alterang(int a, int g_i, int g_p) if (abs(angdif) < 256) { j = 128 - (krand() & 256); - g_sp->ang += j; - if (hits(g_i) < 844) - g_sp->ang -= j; + s->ang += j; + if (hits(actor) < 844) + s->ang -= j; } } else if (ticselapsed > 18 && ticselapsed < 26) // choose { - if (abs(angdif >> 2) < 128) g_sp->ang = goalang; - else g_sp->ang += angdif >> 2; + if (abs(angdif >> 2) < 128) s->ang = goalang; + else s->ang += angdif >> 2; } } - else g_sp->ang = goalang; + else s->ang = goalang; } if (ticselapsed < 1) { j = 2; - if (a & furthestdir) + if (ang & furthestdir) { - goalang = furthestangle(g_i, j); - g_sp->ang = goalang; - g_sp->owner = ps[g_p].i; + goalang = furthestangle(actor, j); + s->ang = goalang; + actor->SetOwner(ps[playernum].GetActor()); } - if (a & fleeenemy) + if (ang & fleeenemy) { - goalang = furthestangle(g_i, j); - g_sp->ang = goalang; // += angdif; // = getincangle(aang,goalang)>>1; + goalang = furthestangle(actor, j); + s->ang = goalang; // += angdif; // = getincangle(aang,goalang)>>1; } } } @@ -5039,87 +5273,87 @@ void alterang(int a, int g_i, int g_p) // //--------------------------------------------------------------------------- -void fall_common(int g_i, int g_p, int JIBS6, int DRONE, int BLOODPOOL, int SHOTSPARK1, int squished, int thud, int(*fallspecial)(int, int), void (*falladjustz)(spritetype*)) +void fall_common(DDukeActor *actor, int playernum, int JIBS6, int DRONE, int BLOODPOOL, int SHOTSPARK1, int squished, int thud, int(*fallspecial)(DDukeActor*, int)) { - auto g_sp = &sprite[g_i]; - g_sp->xoffset = 0; - g_sp->yoffset = 0; + auto s = &actor->s; + s->xoffset = 0; + s->yoffset = 0; // if(!gotz) { int c; - int sphit = fallspecial? fallspecial(g_i, g_p) : 0; - if (fi.floorspace(g_sp->sectnum)) + int sphit = fallspecial? fallspecial(actor, playernum) : 0; + if (fi.floorspace(s->sectnum)) c = 0; else { - if (fi.ceilingspace(g_sp->sectnum) || sector[g_sp->sectnum].lotag == 2) + if (fi.ceilingspace(s->sectnum) || sector[s->sectnum].lotag == 2) c = gc / 6; else c = gc; } - if (hittype[g_i].cgg <= 0 || (sector[g_sp->sectnum].floorstat & 2)) + if (actor->cgg <= 0 || (sector[s->sectnum].floorstat & 2)) { - getglobalz(g_i); - hittype[g_i].cgg = 6; + getglobalz(actor); + actor->cgg = 6; } - else hittype[g_i].cgg--; + else actor->cgg--; - if (g_sp->z < (hittype[g_i].floorz - FOURSLEIGHT)) + if (s->z < (actor->floorz - FOURSLEIGHT)) { - g_sp->zvel += c; - g_sp->z += g_sp->zvel; + s->zvel += c; + s->z += s->zvel; - if (g_sp->zvel > 6144) g_sp->zvel = 6144; + if (s->zvel > 6144) s->zvel = 6144; } else { - g_sp->z = hittype[g_i].floorz - FOURSLEIGHT; + s->z = actor->floorz - FOURSLEIGHT; - if (badguy(g_sp) || (g_sp->picnum == TILE_APLAYER && g_sp->owner >= 0)) + if (badguy(actor) || (s->picnum == TILE_APLAYER && actor->GetOwner())) { - if (g_sp->zvel > 3084 && g_sp->extra <= 1) + if (s->zvel > 3084 && s->extra <= 1) { - if (g_sp->pal != 1 && g_sp->picnum != DRONE) + if (s->pal != 1 && s->picnum != DRONE) { - if (g_sp->picnum == TILE_APLAYER && g_sp->extra > 0) + if (s->picnum == TILE_APLAYER && s->extra > 0) goto SKIPJIBS; if (sphit) { - fi.guts(g_sp, JIBS6, 5, g_p); - S_PlayActorSound(squished, g_i); + fi.guts(actor, JIBS6, 5, playernum); + S_PlayActorSound(squished, actor); } else { - fi.guts(g_sp, JIBS6, 15, g_p); - S_PlayActorSound(squished, g_i); - fi.spawn(g_i, BLOODPOOL); + fi.guts(actor, JIBS6, 15, playernum); + S_PlayActorSound(squished, actor); + spawn(actor, BLOODPOOL); } } SKIPJIBS: - hittype[g_i].picnum = SHOTSPARK1; - hittype[g_i].extra = 1; - g_sp->zvel = 0; + actor->picnum = SHOTSPARK1; + actor->extra = 1; + s->zvel = 0; } - else if (g_sp->zvel > 2048 && sector[g_sp->sectnum].lotag != 1) + else if (s->zvel > 2048 && sector[s->sectnum].lotag != 1) { - short j = g_sp->sectnum; - int x = g_sp->x, y = g_sp->y, z = g_sp->z; + short j = s->sectnum; + int x = s->x, y = s->y, z = s->z; pushmove(&x, &y, &z, &j, 128, (4 << 8), (4 << 8), CLIPMASK0); - setspritepos(g_i, x, y, z); // wrap this for safety. The renderer may need processing of the new position. - if (j != g_sp->sectnum && j >= 0 && j < MAXSECTORS) - changespritesect(g_i, j); + setspritepos(actor->GetIndex(), x, y, z); // wrap this for safety. The renderer may need processing of the new position. + if (j != s->sectnum && j >= 0 && j < MAXSECTORS) + changespritesect(actor, j); - S_PlayActorSound(thud, g_i); + S_PlayActorSound(thud, actor); } } - if (sector[g_sp->sectnum].lotag == 1) - falladjustz(g_sp); - else g_sp->zvel = 0; + if (sector[s->sectnum].lotag == 1) + s->z += actorinfo[s->picnum].falladjustz; + else s->zvel = 0; } } } @@ -5130,17 +5364,15 @@ void fall_common(int g_i, int g_p, int JIBS6, int DRONE, int BLOODPOOL, int SHOT // //--------------------------------------------------------------------------- -int LocateTheLocator(int n, int sn) +DDukeActor *LocateTheLocator(int n, int sectnum) { - int i; - - StatIterator it(STAT_LOCATOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_LOCATOR); + while (auto ac = it.Next()) { - if ((sn == -1 || sn == sprite[i].sectnum) && n == sprite[i].lotag) - return i; + if ((sectnum == -1 || sectnum == ac->s.sectnum) && n == ac->s.lotag) + return ac; } - return -1; + return nullptr; } //--------------------------------------------------------------------------- @@ -5153,15 +5385,12 @@ void recordoldspritepos() { for (int statNum = 0; statNum < MAXSTATUS; statNum++) { - StatIterator it(statNum); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(statNum); + while (auto ac = it.Next()) { - auto s = &sprite[j]; - auto h = &hittype[j]; - h->bposx = s->x; - h->bposy = s->y; - h->bposz = s->z; + ac->bposx = ac->s.x; + ac->bposy = ac->s.y; + ac->bposz = ac->s.z; } } } diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index c0da755f2..4844edc05 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -73,13 +73,13 @@ void SerializeActorGlobals(FSerializer& arc) { fire.Clear(); if (!res) return; - auto length = arc.ArraySize() / 2; + int length = arc.ArraySize() / 2; int key; FireProj value; for (int i = 0; i < length; i++) { - Serialize(arc, nullptr, key, nullptr); + arc(nullptr, key); Serialize(arc, nullptr, value, nullptr); fire.Insert(key, value); } @@ -144,10 +144,9 @@ bool floorspace_d(int sectnum) // //--------------------------------------------------------------------------- -void check_fta_sounds_d(int i) +void check_fta_sounds_d(DDukeActor* actor) { - auto spri = &sprite[i]; - if (spri->extra > 0) switch (spri->picnum) + if (actor->s.extra > 0) switch (actor->s.picnum) { case LIZTROOPONTOILET: case LIZTROOPJUSTSIT: @@ -156,56 +155,56 @@ void check_fta_sounds_d(int i) case LIZTROOPDUCKING: case LIZTROOPRUNNING: case LIZTROOP: - S_PlayActorSound(PRED_RECOG, i); + S_PlayActorSound(PRED_RECOG, actor); break; case LIZMAN: case LIZMANSPITTING: case LIZMANFEEDING: case LIZMANJUMP: - S_PlayActorSound(CAPT_RECOG, i); + S_PlayActorSound(CAPT_RECOG, actor); break; case PIGCOP: case PIGCOPDIVE: - S_PlayActorSound(PIG_RECOG, i); + S_PlayActorSound(PIG_RECOG, actor); break; case RECON: - S_PlayActorSound(RECO_RECOG, i); + S_PlayActorSound(RECO_RECOG, actor); break; case DRONE: - S_PlayActorSound(DRON_RECOG, i); + S_PlayActorSound(DRON_RECOG, actor); break; case COMMANDER: case COMMANDERSTAYPUT: - S_PlayActorSound(COMM_RECOG, i); + S_PlayActorSound(COMM_RECOG, actor); break; case ORGANTIC: - S_PlayActorSound(TURR_RECOG, i); + S_PlayActorSound(TURR_RECOG, actor); break; case OCTABRAIN: case OCTABRAINSTAYPUT: - S_PlayActorSound(OCTA_RECOG, i); + S_PlayActorSound(OCTA_RECOG, actor); break; case BOSS1: S_PlaySound(BOS1_RECOG); break; case BOSS2: - if (spri->pal == 1) + if (actor->s.pal == 1) S_PlaySound(BOS2_RECOG); else S_PlaySound(WHIPYOURASS); break; case BOSS3: - if (spri->pal == 1) + if (actor->s.pal == 1) S_PlaySound(BOS3_RECOG); else S_PlaySound(RIPHEADNECK); break; case BOSS4: case BOSS4STAYPUT: - if (spri->pal == 1) + if (actor->s.pal == 1) S_PlaySound(BOS4_RECOG); S_PlaySound(BOSS4_FIRSTSEE); break; case GREENSLIME: - S_PlayActorSound(SLIM_RECOG, i); + S_PlayActorSound(SLIM_RECOG, actor); break; } } @@ -245,20 +244,20 @@ void addweapon_d(struct player_struct *p, int weapon) if(p->curr_weapon != weapon) { int snum; - snum = sprite[p->i].yvel; + snum = p->GetPlayerNum(); - SetGameVarID(g_iWeaponVarID,weapon, snum, p->i); + SetGameVarID(g_iWeaponVarID,weapon, snum, p->GetActor()); if (p->curr_weapon >= 0) { - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[weapon][snum], snum, p->i); + SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[weapon][snum], snum, p->GetActor()); } else { - SetGameVarID(g_iWorksLikeVarID, -1, snum, p->i); + SetGameVarID(g_iWorksLikeVarID, -1, snum, p->GetActor()); } SetGameVarID(g_iReturnVarID, 0, snum, -1); - OnEvent(EVENT_CHANGEWEAPON, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + OnEvent(EVENT_CHANGEWEAPON, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, nullptr, snum) == 0) { p->curr_weapon = weapon; } @@ -275,13 +274,13 @@ void addweapon_d(struct player_struct *p, int weapon) case HANDBOMB_WEAPON: break; case SHOTGUN_WEAPON: - S_PlayActorSound(SHOTGUN_COCK, p->i); + S_PlayActorSound(SHOTGUN_COCK, p->GetActor()); break; case PISTOL_WEAPON: - S_PlayActorSound(INSERT_CLIP, p->i); + S_PlayActorSound(INSERT_CLIP, p->GetActor()); break; default: - S_PlayActorSound(SELECT_WEAPON, p->i); + S_PlayActorSound(SELECT_WEAPON, p->GetActor()); break; } } @@ -292,12 +291,11 @@ void addweapon_d(struct player_struct *p, int weapon) // //--------------------------------------------------------------------------- -bool ifsquished(int i, int p) +bool ifsquished(DDukeActor* actor, int p) { if (isRR()) return false; // this function is a no-op in RR's source. - auto spri = &sprite[i]; - auto ht = &hittype[i]; + auto spri = &actor->s; bool squishme = false; if (spri->picnum == APLAYER && ud.clipping) return false; @@ -317,13 +315,13 @@ bool ifsquished(int i, int p) { FTA(QUOTE_SQUISHED, &ps[p]); - if (badguy(&sprite[i])) + if (badguy(actor)) spri->xvel = 0; if (spri->pal == 1) { - ht->picnum = SHOTSPARK1; - ht->extra = 1; + actor->picnum = SHOTSPARK1; + actor->extra = 1; return false; } @@ -338,37 +336,37 @@ bool ifsquished(int i, int p) // //--------------------------------------------------------------------------- -void hitradius_d(short i, int r, int hp1, int hp2, int hp3, int hp4) +void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int hp4) { walltype* wal; int d, q, x1, y1; int sectcnt, sectend, dasect, startwall, endwall, nextsect; - short j, p, x, sect; + short p, x, sect; static const uint8_t statlist[] = { STAT_DEFAULT, STAT_ACTOR, STAT_STANDABLE, STAT_PLAYER, STAT_FALLER, STAT_ZOMBIEACTOR, STAT_MISC }; short tempshort[MAXSECTORS]; // originally hijacked a global buffer which is bad. Q: How many do we really need? RedNukem says 64. - auto s = &sprite[i]; + auto spri = &actor->s; - if(s->picnum == RPG && s->xrepeat < 11) goto SKIPWALLCHECK; + if(spri->picnum == RPG && spri->xrepeat < 11) goto SKIPWALLCHECK; - if(s->picnum != SHRINKSPARK) + if(spri->picnum != SHRINKSPARK) { - tempshort[0] = s->sectnum; - dasect = s->sectnum; + tempshort[0] = spri->sectnum; + dasect = spri->sectnum; sectcnt = 0; sectend = 1; do { dasect = tempshort[sectcnt++]; - if (((sector[dasect].ceilingz - s->z) >> 8) < r) + if (((sector[dasect].ceilingz - spri->z) >> 8) < r) { - d = abs(wall[sector[dasect].wallptr].x - s->x) + abs(wall[sector[dasect].wallptr].y - s->y); + d = abs(wall[sector[dasect].wallptr].x - spri->x) + abs(wall[sector[dasect].wallptr].y - spri->y); if (d < r) fi.checkhitceiling(dasect); else { // ouch... - d = abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x - s->x) + abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].y - s->y); + d = abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x - spri->x) + abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].y - spri->y); if (d < r) fi.checkhitceiling(dasect); } @@ -377,7 +375,7 @@ void hitradius_d(short i, int r, int hp1, int hp2, int hp3, int hp4) startwall = sector[dasect].wallptr; endwall = startwall + sector[dasect].wallnum; for (x = startwall, wal = &wall[startwall]; x < endwall; x++, wal++) - if ((abs(wal->x - s->x) + abs(wal->y - s->y)) < r) + if ((abs(wal->x - spri->x) + abs(wal->y - spri->y)) < r) { nextsect = wal->nextsector; if (nextsect >= 0) @@ -386,11 +384,11 @@ void hitradius_d(short i, int r, int hp1, int hp2, int hp3, int hp4) if (tempshort[dasect] == nextsect) break; if (dasect < 0) tempshort[sectend++] = nextsect; } - x1 = (((wal->x + wall[wal->point2].x) >> 1) + s->x) >> 1; - y1 = (((wal->y + wall[wal->point2].y) >> 1) + s->y) >> 1; + x1 = (((wal->x + wall[wal->point2].x) >> 1) + spri->x) >> 1; + y1 = (((wal->y + wall[wal->point2].y) >> 1) + spri->y) >> 1; updatesector(x1, y1, §); - if (sect >= 0 && cansee(x1, y1, s->z, sect, s->x, s->y, s->z, s->sectnum)) - fi.checkhitwall(i, x, wal->x, wal->y, s->z, s->picnum); + if (sect >= 0 && cansee(x1, y1, spri->z, sect, spri->x, spri->y, spri->z, spri->sectnum)) + fi.checkhitwall(actor, x, wal->x, wal->y, spri->z, spri->picnum); } } while (sectcnt < sectend); } @@ -399,132 +397,130 @@ SKIPWALLCHECK: q = -(16 << 8) + (krand() & ((32 << 8) - 1)); + auto Owner = actor->GetOwner(); for (x = 0; x < 7; x++) { - StatIterator itj(statlist[x]); - while ((j = itj.NextIndex()) >= 0) + DukeStatIterator itj(statlist[x]); + while (auto act2 = itj.Next()) { - auto sj = &sprite[j]; - auto ht = &hittype[j]; - - if (isWorldTour()) + auto spri2 = &act2->s; + if (isWorldTour() && Owner) { - if (sprite[s->owner].picnum == APLAYER && sj->picnum == APLAYER && ud.coop != 0 && ud.ffire == 0 && s->owner != j) + if (Owner->s.picnum == APLAYER && spri2->picnum == APLAYER && ud.coop != 0 && ud.ffire == 0 && Owner != act2) { continue; } - if (s->picnum == FLAMETHROWERFLAME && ((sprite[s->owner].picnum == FIREFLY && sj->picnum == FIREFLY) || (sprite[s->owner].picnum == BOSS5 && sj->picnum == BOSS5))) + if (spri->picnum == FLAMETHROWERFLAME && ((Owner->s.picnum == FIREFLY && spri2->picnum == FIREFLY) || (Owner->s.picnum == BOSS5 && spri2->picnum == BOSS5))) { continue; } } - if (x == 0 || x >= 5 || AFLAMABLE(sj->picnum)) + if (x == 0 || x >= 5 || AFLAMABLE(spri2->picnum)) { - if (s->picnum != SHRINKSPARK || (sj->cstat & 257)) - if (dist(s, sj) < r) + if (spri->picnum != SHRINKSPARK || (spri2->cstat & 257)) + if (dist(actor, act2) < r) { - if (badguy(sj) && !cansee(sj->x, sj->y, sj->z + q, sj->sectnum, s->x, s->y, s->z + q, s->sectnum)) + if (badguy(act2) && !cansee(spri2->x, spri2->y, spri2->z + q, spri2->sectnum, spri->x, spri->y, spri->z + q, spri->sectnum)) continue; - fi.checkhitsprite(j, i); + fi.checkhitsprite(act2, actor); } } - else if (sj->extra >= 0 && sj != s && (sj->picnum == TRIPBOMB || badguy(sj) || sj->picnum == QUEBALL || sj->picnum == STRIPEBALL || (sj->cstat & 257) || sj->picnum == DUKELYINGDEAD)) + else if (spri2->extra >= 0 && act2 != actor && (spri2->picnum == TRIPBOMB || badguy(act2) || spri2->picnum == QUEBALL || spri2->picnum == STRIPEBALL || (spri2->cstat & 257) || spri2->picnum == DUKELYINGDEAD)) { - if (s->picnum == SHRINKSPARK && sj->picnum != SHARK && (j == s->owner || sj->xrepeat < 24)) + if (spri->picnum == SHRINKSPARK && spri2->picnum != SHARK && (act2 == Owner || spri2->xrepeat < 24)) { continue; } - if (s->picnum == MORTER && j == s->owner) + if (spri->picnum == MORTER && act2 == Owner) { continue; } - if (sj->picnum == APLAYER) sj->z -= PHEIGHT; - d = dist(s, sj); - if (sj->picnum == APLAYER) sj->z += PHEIGHT; + if (spri2->picnum == APLAYER) spri2->z -= PHEIGHT; + d = dist(actor, act2); + if (spri2->picnum == APLAYER) spri2->z += PHEIGHT; - if (d < r && cansee(sj->x, sj->y, sj->z - (8 << 8), sj->sectnum, s->x, s->y, s->z - (12 << 8), s->sectnum)) + if (d < r && cansee(spri2->x, spri2->y, spri2->z - (8 << 8), spri2->sectnum, spri->x, spri->y, spri->z - (12 << 8), spri->sectnum)) { - ht->ang = getangle(sj->x - s->x, sj->y - s->y); + act2->ang = getangle(spri2->x - spri->x, spri2->y - spri->y); - if (s->picnum == RPG && sj->extra > 0) - ht->picnum = RPG; + if (spri->picnum == RPG && spri2->extra > 0) + act2->picnum = RPG; else if (!isWorldTour()) { - if (s->picnum == SHRINKSPARK) - ht->picnum = SHRINKSPARK; - else ht->picnum = RADIUSEXPLOSION; + if (spri->picnum == SHRINKSPARK) + act2->picnum = SHRINKSPARK; + else act2->picnum = RADIUSEXPLOSION; } else { - if (s->picnum == SHRINKSPARK || s->picnum == FLAMETHROWERFLAME) - ht->picnum = s->picnum; - else if (s->picnum != FIREBALL || sprite[s->owner].picnum != APLAYER) + if (spri->picnum == SHRINKSPARK || spri->picnum == FLAMETHROWERFLAME) + act2->picnum = spri->picnum; + else if (spri->picnum != FIREBALL || !Owner || Owner->s.picnum != APLAYER) { - if (s->picnum == LAVAPOOL) - ht->picnum = FLAMETHROWERFLAME; + if (spri->picnum == LAVAPOOL) + act2->picnum = FLAMETHROWERFLAME; else - ht->picnum = RADIUSEXPLOSION; + act2->picnum = RADIUSEXPLOSION; } else - ht->picnum = FLAMETHROWERFLAME; + act2->picnum = FLAMETHROWERFLAME; } - if (s->picnum != SHRINKSPARK && (!isWorldTour() || s->picnum != LAVAPOOL)) + if (spri->picnum != SHRINKSPARK && (!isWorldTour() || spri->picnum != LAVAPOOL)) { if (d < r / 3) { if (hp4 == hp3) hp4++; - ht->extra = hp3 + (krand() % (hp4 - hp3)); + act2->extra = hp3 + (krand() % (hp4 - hp3)); } else if (d < 2 * r / 3) { if (hp3 == hp2) hp3++; - ht->extra = hp2 + (krand() % (hp3 - hp2)); + act2->extra = hp2 + (krand() % (hp3 - hp2)); } else if (d < r) { if (hp2 == hp1) hp2++; - ht->extra = hp1 + (krand() % (hp2 - hp1)); + act2->extra = hp1 + (krand() % (hp2 - hp1)); } - if (sj->picnum != TANK && sj->picnum != ROTATEGUN && sj->picnum != RECON && !bossguy(sj)) + if (spri2->picnum != TANK && spri2->picnum != ROTATEGUN && spri2->picnum != RECON && !bossguy(act2)) { - if (sj->xvel < 0) sj->xvel = 0; - sj->xvel += (s->extra << 2); + if (spri2->xvel < 0) spri2->xvel = 0; + spri2->xvel += (spri->extra << 2); } - if (sj->picnum == PODFEM1 || sj->picnum == FEM1 || - sj->picnum == FEM2 || sj->picnum == FEM3 || - sj->picnum == FEM4 || sj->picnum == FEM5 || - sj->picnum == FEM6 || sj->picnum == FEM7 || - sj->picnum == FEM8 || sj->picnum == FEM9 || - sj->picnum == FEM10 || sj->picnum == STATUE || - sj->picnum == STATUEFLASH || sj->picnum == SPACEMARINE || sj->picnum == QUEBALL || sj->picnum == STRIPEBALL) - fi.checkhitsprite(j, i); + if (spri2->picnum == PODFEM1 || spri2->picnum == FEM1 || + spri2->picnum == FEM2 || spri2->picnum == FEM3 || + spri2->picnum == FEM4 || spri2->picnum == FEM5 || + spri2->picnum == FEM6 || spri2->picnum == FEM7 || + spri2->picnum == FEM8 || spri2->picnum == FEM9 || + spri2->picnum == FEM10 || spri2->picnum == STATUE || + spri2->picnum == STATUEFLASH || spri2->picnum == SPACEMARINE || spri2->picnum == QUEBALL || spri2->picnum == STRIPEBALL) + fi.checkhitsprite(act2, actor); } - else if (s->extra == 0) ht->extra = 0; + else if (spri->extra == 0) act2->extra = 0; - if (sj->picnum != RADIUSEXPLOSION && - s->owner >= 0 && sprite[s->owner].statnum < MAXSTATUS) + if (spri2->picnum != RADIUSEXPLOSION && Owner && Owner->s.statnum < MAXSTATUS) { - if (sj->picnum == APLAYER) + if (spri2->picnum == APLAYER) { - p = sj->yvel; + p = spri2->yvel; - if (isWorldTour() && ht->picnum == FLAMETHROWERFLAME && sprite[s->owner].picnum == APLAYER) + if (isWorldTour() && act2->picnum == FLAMETHROWERFLAME && Owner->s.picnum == APLAYER) { - ps[p].numloogs = -1 - s->yvel; + ps[p].numloogs = -1 - spri->yvel; } - if (ps[p].newowner >= 0) + if (ps[p].newOwner != nullptr) { clearcamera(&ps[p]); } } - ht->owner = s->owner; + act2->SetHitOwner(actor->GetOwner()); } } } @@ -574,7 +570,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un { if (spri->picnum == LIZMAN) cd = 292; - else if (actorflag(actor->GetIndex(), SFLAG_BADGUY)) + else if (actorflag(actor, SFLAG_BADGUY)) cd = spri->clipdist << 2; else cd = 192; @@ -607,10 +603,10 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un { if (spri->statnum == STAT_PROJECTILE) retval = - clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype, result); else retval = - clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), (int)(spri->clipdist << 2), (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), (int)(spri->clipdist << 2), (4 << 8), (4 << 8), cliptype, result); } if (dasectnum >= 0) @@ -619,10 +615,10 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un daz = spri->z + ((zchange * TICSPERFRAME) >> 3); if ((daz > actor->ceilingz) && (daz <= actor->floorz)) spri->z = daz; - else if (retval == 0) + else if (retval == kHitNone) return result.setSector(dasectnum); - return result.setFromEngine(retval); + return retval; } //--------------------------------------------------------------------------- // @@ -651,14 +647,15 @@ void lotsofpaper_d(DDukeActor *actor, short n) // //--------------------------------------------------------------------------- -void guts_d(spritetype* s, short gtype, short n, short p) +void guts_d(DDukeActor* actor, short gtype, short n, short p) { + auto s = &actor->s; int gutz, floorz; int i=0, j; int sx, sy; uint8_t pal; - if (badguy(s) && s->xrepeat < 16) + if (badguy(actor) && s->xrepeat < 16) sx = sy = 8; else sx = sy = 32; @@ -668,10 +665,9 @@ void guts_d(spritetype* s, short gtype, short n, short p) if (gutz > (floorz - (8 << 8))) gutz = floorz - (8 << 8); - if (s->picnum == COMMANDER) - gutz -= (24 << 8); + gutz += actorinfo[s->picnum].gutsoffset; - if (badguy(s) && s->pal == 6) + if (badguy(actor) && s->pal == 6) pal = 6; else if (s->picnum != LIZTROOP) // EDuke32 transfers the palette unconditionally, I'm not sure that's such a good idea. pal = 0; @@ -688,48 +684,14 @@ void guts_d(spritetype* s, short gtype, short n, short p) int r4 = krand(); int r5 = krand(); // TRANSITIONAL: owned by a player??? - i = EGS(s->sectnum, s->x + (r5 & 255) - 128, s->y + (r4 & 255) - 128, gutz - (r3 & 8191), gtype, -32, sx, sy, a, 48 + (r2 & 31), -512 - (r1 & 2047), ps[p].i, 5); - auto si = &sprite[i]; - if (si->picnum == JIBS2) + auto spawned = EGS(s->sectnum, s->x + (r5 & 255) - 128, s->y + (r4 & 255) - 128, gutz - (r3 & 8191), gtype, -32, sx, sy, a, 48 + (r2 & 31), -512 - (r1 & 2047), ps[p].GetActor(), 5); + if (spawned->s.picnum == JIBS2) { - si->xrepeat >>= 2; - si->yrepeat >>= 2; + spawned->s.xrepeat >>= 2; + spawned->s.yrepeat >>= 2; } if (pal != 0) - si->pal = pal; - } -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -void gutsdir_d(spritetype* s, short gtype, short n, short p) -{ - int sx, sy; - - if (badguy(s) && s->xrepeat < 16) - sx = sy = 8; - else sx = sy = 32; - - int gutz = s->z - (8 << 8); - int floorz = getflorzofslope(s->sectnum, s->x, s->y); - - if (gutz > (floorz - (8 << 8))) - gutz = floorz - (8 << 8); - - if (s->picnum == COMMANDER) - gutz -= (24 << 8); - - for (int j = 0; j < n; j++) - { - int a = krand() & 2047; - int r1 = krand(); - int r2 = krand(); - // TRANSITIONAL: owned by a player??? - EGS(s->sectnum, s->x, s->y, gutz, gtype, -32, sx, sy, a, 256 + (r2 & 127), -512 - (r1 & 2047), ps[p].i, 5); + spawned->s.pal = pal; } } @@ -743,26 +705,26 @@ void movefta_d(void) { int x, px, py, sx, sy; short p, psect, ssect; - int i, j; + int j; - StatIterator iti(STAT_ZOMBIEACTOR); + DukeStatIterator iti(STAT_ZOMBIEACTOR); - while ((i = iti.NextIndex()) >= 0) + while (auto act = iti.Next()) { - auto s = &sprite[i]; - auto ht = &hittype[i]; - p = findplayer(s, &x); + auto s = &act->s; + p = findplayer(act, &x); ssect = psect = s->sectnum; - if (sprite[ps[p].i].extra > 0) + auto pa = ps[p].GetActor(); + if (pa->s.extra > 0) { if (x < 30000) { - ht->timetosleep++; - if (ht->timetosleep >= (x >> 8)) + act->timetosleep++; + if (act->timetosleep >= (x >> 8)) { - if (badguy(s)) + if (badguy(act)) { px = ps[p].oposx + 64 - (krand() & 127); py = ps[p].oposy + 64 - (krand() & 127); @@ -811,20 +773,20 @@ void movefta_d(void) s->shade = sector[s->sectnum].ceilingshade; else s->shade = sector[s->sectnum].floorshade; - ht->timetosleep = 0; - changespritestat(i, STAT_STANDABLE); + act->timetosleep = 0; + changespritestat(act, STAT_STANDABLE); break; default: - ht->timetosleep = 0; - fi.check_fta_sounds(i); - changespritestat(i, STAT_ACTOR); + act->timetosleep = 0; + check_fta_sounds_d(act); + changespritestat(act, STAT_ACTOR); break; } - else ht->timetosleep = 0; + else act->timetosleep = 0; } } - if (badguy(s)) + if (badguy(act)) { if (sector[s->sectnum].ceilingstat & 1) s->shade = sector[s->sectnum].ceilingshade; @@ -840,17 +802,15 @@ void movefta_d(void) // //--------------------------------------------------------------------------- -int ifhitsectors_d(int sectnum) +DDukeActor* ifhitsectors_d(int sectnum) { - StatIterator it(STAT_MISC); - int i; - while((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto a1 = it.Next()) { - auto s = &sprite[i]; - if (s->picnum == EXPLOSION2 && sectnum == s->sectnum) - return i; + if (a1->s.picnum == EXPLOSION2 && sectnum == a1->s.sectnum) + return a1; } - return -1; + return nullptr; } //--------------------------------------------------------------------------- @@ -982,53 +942,50 @@ int ifhitbyweapon_d(DDukeActor *actor) void movefallers_d(void) { short sect; - int i, j, x; + int j, x; - StatIterator iti(STAT_FALLER); - while ((i = iti.NextIndex()) >= 0) + DukeStatIterator iti(STAT_FALLER); + while (auto act = iti.Next()) { - auto s = &sprite[i]; - auto ht = &hittype[i]; - + auto s = &act->s; sect = s->sectnum; - if (ht->temp_data[0] == 0) + if (act->temp_data[0] == 0) { s->z -= (16 << 8); - ht->temp_data[1] = s->ang; + act->temp_data[1] = s->ang; x = s->extra; - j = fi.ifhitbyweapon(&hittype[i]); + j = fi.ifhitbyweapon(act); if (j >= 0) { if (j == FIREEXT || j == RPG || j == RADIUSEXPLOSION || j == SEENINE || j == OOZFILTER) { if (s->extra <= 0) { - ht->temp_data[0] = 1; - StatIterator itj(STAT_FALLER); - while ((j = itj.NextIndex()) >= 0) + act->temp_data[0] = 1; + DukeStatIterator itj(STAT_FALLER); + while (auto a2 = itj.Next()) { - auto sj = &sprite[j]; - if (sj->hitag == s->hitag) + if (a2->s.hitag == s->hitag) { - hittype[j].temp_data[0] = 1; - sj->cstat &= (65535 - 64); - if (sj->picnum == CEILINGSTEAM || sj->picnum == STEAM) - sj->cstat |= 32768; + a2->temp_data[0] = 1; + a2->s.cstat &= (65535 - 64); + if (a2->s.picnum == CEILINGSTEAM || a2->s.picnum == STEAM) + a2->s.cstat |= 32768; } } } } else { - ht->extra = 0; + act->extra = 0; s->extra = x; } } - s->ang = ht->temp_data[1]; + s->ang = act->temp_data[1]; s->z += (16 << 8); } - else if (ht->temp_data[0] == 1) + else if (act->temp_data[0] == 1) { if (s->lotag > 0) { @@ -1044,7 +1001,7 @@ void movefallers_d(void) if (s->xvel > 0) { s->xvel -= 8; - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); } if (fi.floorspace(s->sectnum)) x = 0; @@ -1066,8 +1023,8 @@ void movefallers_d(void) if ((sector[sect].floorz - s->z) < (16 << 8)) { j = 1 + (krand() & 7); - for (x = 0; x < j; x++) RANDOMSCRAP(s, i); - deletesprite(i); + for (x = 0; x < j; x++) RANDOMSCRAP(act); + deletesprite(act); } } } @@ -1087,11 +1044,11 @@ void movefallers_d(void) // //--------------------------------------------------------------------------- -static void movetripbomb(int i) +static void movetripbomb(DDukeActor *actor) { - auto s = &sprite[i]; + auto s = &actor->s; int j, x; - int lTripBombControl = GetGameVar("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, -1, -1); + int lTripBombControl = GetGameVar("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, nullptr, -1); if (lTripBombControl & TRIPBOMB_TIMER) { // we're on a timer.... @@ -1100,33 +1057,33 @@ static void movetripbomb(int i) s->extra--; if (s->extra == 0) { - hittype[i].temp_data[2] = 16; - S_PlayActorSound(LASERTRIP_ARMING, i); + actor->temp_data[2] = 16; + S_PlayActorSound(LASERTRIP_ARMING, actor); } } } - if (hittype[i].temp_data[2] > 0) + if (actor->temp_data[2] > 0) { - hittype[i].temp_data[2]--; - if (hittype[i].temp_data[2] == 8) + actor->temp_data[2]--; + if (actor->temp_data[2] == 8) { - S_PlayActorSound(LASERTRIP_EXPLODE, i); - for (j = 0; j < 5; j++) RANDOMSCRAP(s, i); + S_PlayActorSound(LASERTRIP_EXPLODE, actor); + for (j = 0; j < 5; j++) RANDOMSCRAP(actor); x = s->extra; - fi.hitradius(i, tripbombblastradius, x >> 2, x >> 1, x - (x >> 2), x); + fi.hitradius(actor, tripbombblastradius, x >> 2, x >> 1, x - (x >> 2), x); - j = fi.spawn(i, EXPLOSION2); - sprite[j].ang = s->ang; - sprite[j].xvel = 348; - ssp(j, CLIPMASK0); + auto spawned = spawn(actor, EXPLOSION2); + spawned->s.ang = s->ang; + spawned->s.xvel = 348; + ssp(spawned, CLIPMASK0); - StatIterator it(STAT_MISC); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto a1 = it.Next()) { - if (sprite[j].picnum == LASERLINE && s->hitag == sprite[j].hitag) - sprite[j].xrepeat = sprite[j].yrepeat = 0; + if (a1->s.picnum == LASERLINE && s->hitag == a1->s.hitag) + a1->s.xrepeat = a1->s.yrepeat = 0; } - deletesprite(i); + deletesprite(actor); } return; } @@ -1135,29 +1092,29 @@ static void movetripbomb(int i) x = s->extra; s->extra = 1; int16_t l = s->ang; - j = fi.ifhitbyweapon(&hittype[i]); + j = fi.ifhitbyweapon(actor); if (j >= 0) { - hittype[i].temp_data[2] = 16; + actor->temp_data[2] = 16; } s->extra = x; s->ang = l; } - if (hittype[i].temp_data[0] < 32) + if (actor->temp_data[0] < 32) { - findplayer(s, &x); - if (x > 768) hittype[i].temp_data[0]++; - else if (hittype[i].temp_data[0] > 16) hittype[i].temp_data[0]++; + findplayer(actor, &x); + if (x > 768) actor->temp_data[0]++; + else if (actor->temp_data[0] > 16) actor->temp_data[0]++; } - if (hittype[i].temp_data[0] == 32) + if (actor->temp_data[0] == 32) { int16_t l = s->ang; - s->ang = hittype[i].temp_data[5]; + s->ang = actor->temp_data[5]; - hittype[i].temp_data[3] = s->x; hittype[i].temp_data[4] = s->y; - s->x += sintable[(hittype[i].temp_data[5] + 512) & 2047] >> 9; - s->y += sintable[(hittype[i].temp_data[5]) & 2047] >> 9; + actor->temp_data[3] = s->x; actor->temp_data[4] = s->y; + s->x += sintable[(actor->temp_data[5] + 512) & 2047] >> 9; + s->y += sintable[(actor->temp_data[5]) & 2047] >> 9; s->z -= (3 << 8); // Laser fix from EDuke32. @@ -1165,12 +1122,12 @@ static void movetripbomb(int i) int16_t curSectNum = s->sectnum; updatesectorneighbor(s->x, s->y, &curSectNum, 1024, 2048); - changespritesect(i, curSectNum); + changespritesect(actor, curSectNum); - int16_t m; - x = hitasprite(i, &m); + DDukeActor* hit; + x = hitasprite(actor, &hit); - hittype[i].lastvx = x; + actor->lastvx = x; s->ang = l; @@ -1181,67 +1138,66 @@ static void movetripbomb(int i) // we're on a trip wire while (x > 0) { - j = fi.spawn(i, LASERLINE); - setsprite(j, sprite[j].x, sprite[j].y, sprite[j].z); - sprite[j].hitag = s->hitag; - hittype[j].temp_data[1] = sprite[j].z; + auto spawned = spawn(actor, LASERLINE); + setsprite(spawned, spawned->s.pos); + spawned->s.hitag = s->hitag; + spawned->temp_data[1] = spawned->s.z; if (x < 1024) { - sprite[j].xrepeat = x >> 5; + spawned->s.xrepeat = x >> 5; break; } x -= 1024; - s->x += sintable[(hittype[i].temp_data[5] + 512) & 2047] >> 4; - s->y += sintable[(hittype[i].temp_data[5]) & 2047] >> 4; + s->x += sintable[(actor->temp_data[5] + 512) & 2047] >> 4; + s->y += sintable[(actor->temp_data[5]) & 2047] >> 4; updatesectorneighbor(s->x, s->y, &curSectNum, 1024, 2048); if (curSectNum == -1) break; - changespritesect(i, curSectNum); + changespritesect(actor, curSectNum); // this is a hack to work around the LASERLINE sprite's art tile offset - changespritesect(j, curSectNum); + changespritesect(spawned, curSectNum); } } - hittype[i].temp_data[0]++; - s->x = hittype[i].temp_data[3]; s->y = hittype[i].temp_data[4]; + actor->temp_data[0]++; + s->x = actor->temp_data[3]; s->y = actor->temp_data[4]; s->z += (3 << 8); - changespritesect(i, oldSectNum); - hittype[i].temp_data[3] = 0; - if (m >= 0 && lTripBombControl & TRIPBOMB_TRIPWIRE) + changespritesect(actor, oldSectNum); + actor->temp_data[3] = 0; + if (hit && lTripBombControl & TRIPBOMB_TRIPWIRE) { - hittype[i].temp_data[2] = 13; - S_PlayActorSound(LASERTRIP_ARMING, i); + actor->temp_data[2] = 13; + S_PlayActorSound(LASERTRIP_ARMING, actor); } - else hittype[i].temp_data[2] = 0; + else actor->temp_data[2] = 0; } - if (hittype[i].temp_data[0] == 33) + if (actor->temp_data[0] == 33) { - hittype[i].temp_data[1]++; + actor->temp_data[1]++; - hittype[i].temp_data[3] = s->x; hittype[i].temp_data[4] = s->y; - s->x += sintable[(hittype[i].temp_data[5] + 512) & 2047] >> 9; - s->y += sintable[(hittype[i].temp_data[5]) & 2047] >> 9; + actor->temp_data[3] = s->x; actor->temp_data[4] = s->y; + s->x += sintable[(actor->temp_data[5] + 512) & 2047] >> 9; + s->y += sintable[(actor->temp_data[5]) & 2047] >> 9; s->z -= (3 << 8); - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->pos); - int16_t m; - x = hitasprite(i, &m); + x = hitasprite(actor, nullptr); - s->x = hittype[i].temp_data[3]; s->y = hittype[i].temp_data[4]; + s->x = actor->temp_data[3]; s->y = actor->temp_data[4]; s->z += (3 << 8); - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->x, s->y, s->z); - if (hittype[i].lastvx != x && lTripBombControl & TRIPBOMB_TRIPWIRE) + if (actor->lastvx != x && lTripBombControl & TRIPBOMB_TRIPWIRE) { - hittype[i].temp_data[2] = 13; - S_PlayActorSound(LASERTRIP_ARMING, i); + actor->temp_data[2] = 13; + S_PlayActorSound(LASERTRIP_ARMING, actor); } } } @@ -1252,26 +1208,25 @@ static void movetripbomb(int i) // //--------------------------------------------------------------------------- -static void movecrack(int i) +static void movecrack(DDukeActor* actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; if (s->hitag > 0) { t[0] = s->cstat; t[1] = s->ang; - int j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j == FIREEXT || j == RPG || j == RADIUSEXPLOSION || j == SEENINE || j == OOZFILTER) { - StatIterator it(STAT_STANDABLE); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto a1 = it.Next()) { - auto sj = &sprite[j]; - if (s->hitag == sj->hitag && (sj->picnum == OOZFILTER || sj->picnum == SEENINE)) - if (sj->shade != -32) - sj->shade = -32; + if (s->hitag == a1->s.hitag && (a1->s.picnum == OOZFILTER || a1->s.picnum == SEENINE)) + if (a1->s.shade != -32) + a1->s.shade = -32; } - detonate(i, EXPLOSION2); + detonate(actor, EXPLOSION2); } else { @@ -1288,46 +1243,43 @@ static void movecrack(int i) // //--------------------------------------------------------------------------- -static void movefireext(int i) +static void movefireext(DDukeActor* actor) { - int j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j == -1) return; - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + int* t = &actor->temp_data[0]; for (int k = 0; k < 16; k++) { - j = EGS(sprite[i].sectnum, sprite[i].x, sprite[i].y, sprite[i].z - (krand() % (48 << 8)), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (sprite[i].zvel >> 2), i, 5); - sprite[j].pal = 2; + auto spawned = EGS(actor->s.sectnum, actor->s.x, actor->s.y, actor->s.z - (krand() % (48 << 8)), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (actor->s.zvel >> 2), actor, 5); + spawned->s.pal = 2; } - fi.spawn(i, EXPLOSION2); - S_PlayActorSound(PIPEBOMB_EXPLODE, i); - S_PlayActorSound(GLASS_HEAVYBREAK, i); + spawn(actor, EXPLOSION2); + S_PlayActorSound(PIPEBOMB_EXPLODE, actor); + S_PlayActorSound(GLASS_HEAVYBREAK, actor); - if (s->hitag > 0) + if (actor->s.hitag > 0) { - StatIterator it(STAT_STANDABLE); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto a1 = it.Next()) { - auto sj = &sprite[j]; - if (s->hitag == sj->hitag && (sj->picnum == OOZFILTER || sj->picnum == SEENINE)) - if (sj->shade != -32) - sj->shade = -32; + if (actor->s.hitag == a1->s.hitag && (a1->s.picnum == OOZFILTER || a1->s.picnum == SEENINE)) + if (a1->s.shade != -32) + a1->s.shade = -32; } - int x = s->extra; - fi.spawn(i, EXPLOSION2); - fi.hitradius(i, pipebombblastradius, x >> 2, x - (x >> 1), x - (x >> 2), x); - S_PlayActorSound(PIPEBOMB_EXPLODE, i); - detonate(i, EXPLOSION2); + int x = actor->s.extra; + spawn(actor, EXPLOSION2); + fi.hitradius(actor, pipebombblastradius, x >> 2, x - (x >> 1), x - (x >> 2), x); + S_PlayActorSound(PIPEBOMB_EXPLODE, actor); + detonate(actor, EXPLOSION2); } else { - fi.hitradius(i, seenineblastradius, 10, 15, 20, 25); - deletesprite(i); + fi.hitradius(actor, seenineblastradius, 10, 15, 20, 25); + deletesprite(actor); } } @@ -1337,27 +1289,26 @@ static void movefireext(int i) // //--------------------------------------------------------------------------- -static void moveviewscreen(int i) +static void moveviewscreen(DDukeActor* actor) { - auto s = &sprite[i]; - if (s->xrepeat == 0) deletesprite(i); + if (actor->s.xrepeat == 0) deletesprite(actor); else { int x; - findplayer(s, &x); + findplayer(actor, &x); if (x < 2048) { #if 0 - if (sprite[i].yvel == 1) - camsprite = i; + if (actor->s.yvel == 1) + camsprite = actor; #endif } - else if (camsprite != -1 && hittype[i].temp_data[0] == 1) + else if (camsprite != nullptr && actor->temp_data[0] == 1) { - camsprite = -1; - s->yvel = 0; - hittype[i].temp_data[0] = 0; + camsprite = nullptr; + actor->s.yvel = 0; + actor->temp_data[0] = 0; } } } @@ -1368,14 +1319,14 @@ static void moveviewscreen(int i) // //--------------------------------------------------------------------------- -static void movesidebolt(int i) +static void movesidebolt(DDukeActor* actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int x; int sect = s->sectnum; - auto p = findplayer(s, &x); + auto p = findplayer(actor, &x); if (x > 20480) return; CLEAR_THE_BOLT2: @@ -1399,13 +1350,8 @@ CLEAR_THE_BOLT2: } s->picnum++; -#if 0 - // content of l was undefined. - if (l & 1) s->cstat ^= 2; -#endif - if ((krand() & 1) && sector[sect].floorpicnum == HURTRAIL) - S_PlayActorSound(SHORT_CIRCUIT, i); + S_PlayActorSound(SHORT_CIRCUIT, actor); if (s->picnum == SIDEBOLT1 + 4) s->picnum = SIDEBOLT1; } @@ -1416,14 +1362,14 @@ CLEAR_THE_BOLT2: // //--------------------------------------------------------------------------- -static void movebolt(int i) +static void movebolt(DDukeActor *actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int x; int sect = s->sectnum; - auto p = findplayer(s, &x); + auto p = findplayer(actor, &x); if (x > 20480) return; if (t[3] == 0) @@ -1458,7 +1404,7 @@ CLEAR_THE_BOLT: if (l & 1) s->cstat ^= 2; if (s->picnum == (BOLT1+1) && (krand()&7) == 0 && sector[sect].floorpicnum == HURTRAIL) - S_PlayActorSound(SHORT_CIRCUIT,i); + S_PlayActorSound(SHORT_CIRCUIT,actor); if (s->picnum==BOLT1+4) s->picnum=BOLT1; @@ -1482,102 +1428,100 @@ CLEAR_THE_BOLT: void movestandables_d(void) { - StatIterator it(STAT_STANDABLE); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto act = it.Next()) { - auto s = &sprite[i]; - int picnum = s->picnum; + int picnum = act->s.picnum; - if (s->sectnum < 0) + if (act->s.sectnum < 0) { - deletesprite(i); + deletesprite(act); continue; } - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = act->s.x; + act->bposy = act->s.y; + act->bposz = act->s.z; if (picnum >= CRANE && picnum <= CRANE +3) { - movecrane(&hittype[i], CRANE); + movecrane(act, CRANE); } else if (picnum >= WATERFOUNTAIN && picnum <= WATERFOUNTAIN + 3) { - movefountain(i, WATERFOUNTAIN); + movefountain(act, WATERFOUNTAIN); } else if (AFLAMABLE(picnum)) { - moveflammable(i, TIRE, BOX, BLOODPOOL); + moveflammable(act, TIRE, BOX, BLOODPOOL); } else if (picnum == TRIPBOMB) { - movetripbomb(i); + movetripbomb(act); } else if (picnum >= CRACK1 && picnum <= CRACK1 + 3) { - movecrack(i); + movecrack(act); } else if (picnum == FIREEXT) { - movefireext(i); + movefireext(act); } else if (picnum == OOZFILTER || picnum == SEENINE || picnum == SEENINEDEAD || picnum == (SEENINEDEAD + 1)) { - moveooz(i, SEENINE, SEENINEDEAD, OOZFILTER, EXPLOSION2); + moveooz(act, SEENINE, SEENINEDEAD, OOZFILTER, EXPLOSION2); } else if (picnum == MASTERSWITCH) { - movemasterswitch(i, SEENINE, OOZFILTER); + movemasterswitch(act, SEENINE, OOZFILTER); } else if (picnum == VIEWSCREEN || picnum == VIEWSCREEN2) { - moveviewscreen(i); + moveviewscreen(act); } else if (picnum == TRASH) { - movetrash(i); + movetrash(act); } else if (picnum >= SIDEBOLT1 && picnum <= SIDEBOLT1 + 3) { - movesidebolt(i); + movesidebolt(act); } else if (picnum >= BOLT1 && picnum <= BOLT1 + 3) { - movebolt(i); + movebolt(act); } else if (picnum == WATERDRIP) { - movewaterdrip(i, WATERDRIP); + movewaterdrip(act, WATERDRIP); } else if (picnum == DOORSHOCK) { - movedoorshock(i); + movedoorshock(act); } else if (picnum == TOUCHPLATE) { - movetouchplate(i, TOUCHPLATE); + movetouchplate(act, TOUCHPLATE); } else if (isIn(picnum, CANWITHSOMETHING, CANWITHSOMETHING2, CANWITHSOMETHING3, CANWITHSOMETHING4)) { - movecanwithsomething(i); + movecanwithsomething(act); } else if (isIn(picnum, @@ -1597,8 +1541,8 @@ void movestandables_d(void) WATERBUBBLEMAKER)) { int x; - int p = findplayer(s, &x); - execute(i, p, x); + int p = findplayer(act, &x); + execute(act, p, x); } } } @@ -1609,30 +1553,32 @@ void movestandables_d(void) // //--------------------------------------------------------------------------- -static bool movefireball(int i) +static bool movefireball(DDukeActor* actor) { - auto s = &sprite[i]; - auto ht = &hittype[i]; + auto s = &actor->s; + auto Owner = actor->GetOwner(); if (sector[s->sectnum].lotag == 2) { - deletesprite(i); + deletesprite(actor); return true; } - if (sprite[s->owner].picnum != FIREBALL) + if (!Owner || Owner->s.picnum != FIREBALL) { - if (ht->temp_data[0] >= 1 && ht->temp_data[0] < 6) + if (actor->temp_data[0] >= 1 && actor->temp_data[0] < 6) { - float siz = 1.0f - (ht->temp_data[0] * 0.2f); - int trail = ht->temp_data[1]; - int j = ht->temp_data[1] = fi.spawn(i, FIREBALL); - - auto spr = &sprite[j]; + float siz = 1.0f - (actor->temp_data[0] * 0.2f); + // This still needs work- it stores an actor reference in a general purpose integer field. + int trail = actor->temp_data[1]; + auto ball = spawn(actor, FIREBALL); + auto spr = &ball->s; + actor->temp_data[1] = ball->GetIndex(); + spr->xvel = s->xvel; spr->yvel = s->yvel; spr->zvel = s->zvel; - if (ht->temp_data[0] > 1) + if (actor->temp_data[0] > 1) { FireProj* proj = fire.CheckKey(trail); if (proj != nullptr) @@ -1645,15 +1591,16 @@ static bool movefireball(int i) spr->zvel = proj->zv; } } - spr->yrepeat = spr->xrepeat = (short)(sprite[i].xrepeat * siz); - spr->cstat = sprite[i].cstat; + spr->yrepeat = spr->xrepeat = (short)(s->xrepeat * siz); + spr->cstat = s->cstat; spr->extra = 0; FireProj proj = { spr->x, spr->y, spr->z, spr->xvel, spr->yvel, spr->zvel }; - fire.Insert(j, proj); - changespritestat((short)j, (short)4); + + fire.Insert(ball->GetIndex(), proj); + changespritestat(ball, STAT_PROJECTILE); } - ht->temp_data[0]++; + actor->temp_data[0]++; } if (s->zvel < 15000) s->zvel += 200; @@ -1666,35 +1613,35 @@ static bool movefireball(int i) // //--------------------------------------------------------------------------- -static bool weaponhitsprite(int i, int j, bool fireball) +static bool weaponhitsprite(DDukeActor* proj, DDukeActor *targ, bool fireball) { - auto s = &sprite[i]; - - if (s->picnum == FREEZEBLAST && sprite[j].pal == 1) - if (badguy(&sprite[j]) || sprite[j].picnum == APLAYER) + auto s = &proj->s; + if (s->picnum == FREEZEBLAST && targ->s.pal == 1) + if (badguy(targ) || targ->s.picnum == APLAYER) { - j = fi.spawn(i, TRANSPORTERSTAR); - sprite[j].pal = 1; - sprite[j].xrepeat = 32; - sprite[j].yrepeat = 32; + auto spawned = spawn(targ, TRANSPORTERSTAR); + spawned->s.pal = 1; + spawned->s.xrepeat = 32; + spawned->s.yrepeat = 32; - deletesprite(i); + deletesprite(proj); return true; } if (!isWorldTour() || s->picnum != FIREBALL || fireball) - fi.checkhitsprite(j, i); + fi.checkhitsprite(targ, proj); - if (sprite[j].picnum == APLAYER) + if (targ->s.picnum == APLAYER) { - int p = sprite[j].yvel; + int p = targ->s.yvel; + auto Owner = proj->GetOwner(); - if (ud.multimode >= 2 && fireball && sprite[s->owner].picnum == APLAYER) + if (ud.multimode >= 2 && fireball && Owner && Owner->s.picnum == APLAYER) { - ps[p].numloogs = -1 - sprite[i].yvel; + ps[p].numloogs = -1 - s->yvel; } - S_PlayActorSound(PISTOL_BODYHIT, j); + S_PlayActorSound(PISTOL_BODYHIT, targ); if (s->picnum == SPIT) { @@ -1703,10 +1650,10 @@ static bool weaponhitsprite(int i, int j, bool fireball) if (ps[p].loogcnt == 0) { - if (!S_CheckActorSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); + if (!S_CheckActorSoundPlaying(ps[p].GetActor(), DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor()); - j = 3 + (krand() & 3); + int j = 3 + (krand() & 3); ps[p].numloogs = j; ps[p].loogcnt = 24 * 4; for (int x = 0; x < j; x++) @@ -1726,10 +1673,9 @@ static bool weaponhitsprite(int i, int j, bool fireball) // //--------------------------------------------------------------------------- -static bool weaponhitwall(int i, int j, const vec3_t &oldpos) +static bool weaponhitwall(DDukeActor *proj, int j, const vec3_t &oldpos) { - auto s = &sprite[i]; - + auto s = &proj->s; if (s->picnum != RPG && s->picnum != FREEZEBLAST && s->picnum != SPIT && (!isWorldTour() || s->picnum != FIREBALL) && (wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR)) @@ -1738,14 +1684,14 @@ static bool weaponhitwall(int i, int j, const vec3_t &oldpos) wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y); s->ang = ((k << 1) - s->ang) & 2047; - s->owner = i; - fi.spawn(i, TRANSPORTERSTAR); + proj->SetOwner(proj); + spawn(proj, TRANSPORTERSTAR); return true; } else { - setsprite(i, &oldpos); - fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); + setsprite(proj, oldpos); + fi.checkhitwall(proj, j, s->x, s->y, s->z, s->picnum); if (s->picnum == FREEZEBLAST) { @@ -1771,18 +1717,17 @@ static bool weaponhitwall(int i, int j, const vec3_t &oldpos) // //--------------------------------------------------------------------------- -static bool weaponhitsector(int i, const vec3_t& oldpos, bool fireball) +static bool weaponhitsector(DDukeActor* proj, const vec3_t& oldpos, bool fireball) { - auto s = &sprite[i]; - - setsprite(i, &oldpos); + auto s = &proj->s; + setsprite(proj, oldpos); if (s->zvel < 0) { if (sector[s->sectnum].ceilingstat & 1) if (sector[s->sectnum].ceilingpal == 0) { - deletesprite(i); + deletesprite(proj); return true; } @@ -1790,18 +1735,18 @@ static bool weaponhitsector(int i, const vec3_t& oldpos, bool fireball) } else if (fireball) { - int j = fi.spawn(i, LAVAPOOL); - sprite[j].owner = sprite[i].owner; - sprite[j].yvel = sprite[i].yvel; - hittype[j].owner = sprite[i].owner; - deletesprite(i); + auto spawned = spawn(proj, LAVAPOOL); + spawned->SetOwner(proj); + spawned->SetHitOwner(proj); + spawned->s.yvel = s->yvel; + deletesprite(proj); return true; } if (s->picnum == FREEZEBLAST) { - bounce(i); - ssp(i, CLIPMASK1); + bounce(proj); + ssp(proj, CLIPMASK1); s->extra >>= 1; if (s->xrepeat > 8) s->xrepeat -= 2; @@ -1819,17 +1764,16 @@ static bool weaponhitsector(int i, const vec3_t& oldpos, bool fireball) // //--------------------------------------------------------------------------- -static void weaponcommon_d(int i) +static void weaponcommon_d(DDukeActor* proj) { - auto s = &sprite[i]; - + auto s = &proj->s; if (s->picnum == COOLEXPLOSION1) - if (!S_CheckSoundPlaying(i, WIERDSHOT_FLY)) - S_PlayActorSound(WIERDSHOT_FLY, i); + if (!S_CheckActorSoundPlaying(proj, WIERDSHOT_FLY)) + S_PlayActorSound(WIERDSHOT_FLY, proj); int p = -1; int k, ll; - auto oldpos = s->pos; + vec3_t oldpos = s->pos; if (s->picnum == RPG && sector[s->sectnum].lotag == 2) { @@ -1842,49 +1786,50 @@ static void weaponcommon_d(int i) ll = s->zvel; } - getglobalz(i); + getglobalz(proj); switch (s->picnum) { case RPG: - if (hittype[i].picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) + if (proj->picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) { - int j = fi.spawn(i, SMALLSMOKE); - sprite[j].z += (1 << 8); + auto spawned = spawn(proj, SMALLSMOKE); + spawned->s.z += (1 << 8); } break; case FIREBALL: - if (movefireball(i)) return; + if (movefireball(proj)) return; break; } - int j = fi.movesprite(i, + Collision coll; + movesprite_ex(proj, (k * (sintable[(s->ang + 512) & 2047])) >> 14, - (k * (sintable[s->ang & 2047])) >> 14, ll, CLIPMASK1); + (k * (sintable[s->ang & 2047])) >> 14, ll, CLIPMASK1, coll); - if (s->picnum == RPG && s->yvel >= 0) - if (FindDistance2D(s->x - sprite[s->yvel].x, s->y - sprite[s->yvel].y) < 256) - j = kHitSprite | s->yvel; + if (s->picnum == RPG && proj->temp_actor != nullptr) + if (FindDistance2D(s->x - proj->temp_actor->s.x, s->y - proj->temp_actor->s.y) < 256) + coll.setSprite(proj->temp_actor); if (s->sectnum < 0) { - deletesprite(i); + deletesprite(proj); return; } - if ((j & kHitTypeMask) != kHitSprite && s->picnum != FREEZEBLAST) + if (coll.type != kHitSprite && s->picnum != FREEZEBLAST) { - if (s->z < hittype[i].ceilingz) + if (s->z < proj->ceilingz) { - j = kHitSector | (s->sectnum); + coll.setSector(s->sectnum); s->zvel = -1; } else - if ((s->z > hittype[i].floorz && sector[s->sectnum].lotag != 1) || - (s->z > hittype[i].floorz + (16 << 8) && sector[s->sectnum].lotag == 1)) + if ((s->z > proj->floorz && sector[s->sectnum].lotag != 1) || + (s->z > proj->floorz + (16 << 8) && sector[s->sectnum].lotag == 1)) { - j = kHitSector | (s->sectnum); + coll.setSector(s->sectnum); if (sector[s->sectnum].lotag != 1) s->zvel = 1; } @@ -1894,24 +1839,24 @@ static void weaponcommon_d(int i) { for (k = -3; k < 2; k++) { - int x = EGS(s->sectnum, + auto spawned = EGS(s->sectnum, s->x + ((k * sintable[(s->ang + 512) & 2047]) >> 9), s->y + ((k * sintable[s->ang & 2047]) >> 9), s->z + ((k * ksgn(s->zvel)) * abs(s->zvel / 24)), FIRELASER, -40 + (k << 2), - s->xrepeat, s->yrepeat, 0, 0, 0, s->owner, 5); + s->xrepeat, s->yrepeat, 0, 0, 0, proj->GetOwner(), 5); - sprite[x].cstat = 128; - sprite[x].pal = s->pal; + spawned->s.cstat = 128; + spawned->s.pal = s->pal; } } else if (s->picnum == SPIT) if (s->zvel < 6144) s->zvel += gc - 112; - if (j != 0) + if (coll.type != 0) { if (s->picnum == COOLEXPLOSION1) { - if ((j & kHitTypeMask) == kHitSprite && sprite[j & kHitIndexMask].picnum != APLAYER) + if (coll.type == kHitSprite && coll.actor->s.picnum != APLAYER) { return; } @@ -1919,21 +1864,19 @@ static void weaponcommon_d(int i) s->zvel = 0; } - bool fireball = (isWorldTour() && s->picnum == FIREBALL && sprite[s->owner].picnum != FIREBALL); + bool fireball = (isWorldTour() && s->picnum == FIREBALL && (!proj->GetOwner() || proj->GetOwner()->s.picnum != FIREBALL)); - if ((j & kHitTypeMask) == kHitSprite) + if (coll.type == kHitSprite) { - j &= kHitIndexMask; - if (weaponhitsprite(i, j, fireball)) return; + if (weaponhitsprite(proj, coll.actor, fireball)) return; } - else if ((j & kHitTypeMask) == kHitWall) + else if (coll.type == kHitWall) { - j &= kHitIndexMask; - if (weaponhitwall(i, j, oldpos)) return; + if (weaponhitwall(proj, coll.index, oldpos)) return; } - else if ((j & kHitTypeMask) == kHitSector) + else if (coll.type == kHitSector) { - if (weaponhitsector(i, oldpos, fireball)) return; + if (weaponhitsector(proj, oldpos, fireball)) return; } if (s->picnum != SPIT) @@ -1941,35 +1884,35 @@ static void weaponcommon_d(int i) if (s->picnum == RPG) { // j is only needed for the hit type mask. - rpgexplode(i, j, oldpos, EXPLOSION2, EXPLOSION2BOT, -1, RPG_EXPLODE); + rpgexplode(proj, coll.type, oldpos, EXPLOSION2, EXPLOSION2BOT, -1, RPG_EXPLODE); } else if (s->picnum == SHRINKSPARK) { - fi.spawn(i, SHRINKEREXPLOSION); - S_PlayActorSound(SHRINKER_HIT, i); - fi.hitradius(i, shrinkerblastradius, 0, 0, 0, 0); + spawn(proj, SHRINKEREXPLOSION); + S_PlayActorSound(SHRINKER_HIT, proj); + fi.hitradius(proj, shrinkerblastradius, 0, 0, 0, 0); } else if (s->picnum != COOLEXPLOSION1 && s->picnum != FREEZEBLAST && s->picnum != FIRELASER && (!isWorldTour() || s->picnum != FIREBALL)) { - k = fi.spawn(i, EXPLOSION2); - sprite[k].xrepeat = sprite[k].yrepeat = s->xrepeat >> 1; - if ((j & kHitTypeMask) == kHitSector) + auto k = spawn(proj, EXPLOSION2); + k->s.xrepeat = k->s.yrepeat = s->xrepeat >> 1; + if (coll.type == kHitSector) { if (s->zvel < 0) { - sprite[k].cstat |= 8; sprite[k].z += (72 << 8); + k->s.cstat |= 8; k->s.z += (72 << 8); } } } if (fireball) { - j = fi.spawn(i, EXPLOSION2); - sprite[j].xrepeat = sprite[j].yrepeat = (short)(s->xrepeat >> 1); + auto spawned = spawn(proj, EXPLOSION2); + spawned->s.xrepeat = spawned->s.yrepeat = (short)(s->xrepeat >> 1); } } if (s->picnum != COOLEXPLOSION1) { - deletesprite(i); + deletesprite(proj); return; } } @@ -1978,12 +1921,12 @@ static void weaponcommon_d(int i) s->shade++; if (s->shade >= 40) { - deletesprite(i); + deletesprite(proj); return; } } else if (s->picnum == RPG && sector[s->sectnum].lotag == 2 && s->xrepeat >= 10 && rnd(140)) - fi.spawn(i, WATERBUBBLE); + spawn(proj, WATERBUBBLE); } //--------------------------------------------------------------------------- @@ -1994,58 +1937,55 @@ static void weaponcommon_d(int i) void moveweapons_d(void) { - StatIterator it(STAT_PROJECTILE); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_PROJECTILE); + while (auto act = it.Next()) { - auto s = &sprite[i]; - - if (s->sectnum < 0) + if (act->s.sectnum < 0) { - deletesprite(i); + deletesprite(act); continue; } - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = act->s.x; + act->bposy = act->s.y; + act->bposz = act->s.z; - switch(s->picnum) + switch(act->s.picnum) { case RADIUSEXPLOSION: case KNEE: - deletesprite(i); + deletesprite(act); continue; case TONGUE: - movetongue(i, TONGUE, INNERJAW); + movetongue(act, TONGUE, INNERJAW); continue; case FREEZEBLAST: - if (s->yvel < 1 || s->extra < 2 || (s->xvel|s->zvel) == 0) + if (act->s.yvel < 1 || act->s.extra < 2 || (act->s.xvel|act->s.zvel) == 0) { - int j = fi.spawn(i,TRANSPORTERSTAR); - sprite[j].pal = 1; - sprite[j].xrepeat = 32; - sprite[j].yrepeat = 32; - deletesprite(i); + auto spawned = spawn(act,TRANSPORTERSTAR); + spawned->s.pal = 1; + spawned->s.xrepeat = 32; + spawned->s.yrepeat = 32; + deletesprite(act); continue; } case FIREBALL: // Twentieth Anniversary World Tour - if (s->picnum == FIREBALL && !isWorldTour()) break; + if (act->s.picnum == FIREBALL && !isWorldTour()) break; case SHRINKSPARK: case RPG: case FIRELASER: case SPIT: case COOLEXPLOSION1: - weaponcommon_d(i); + weaponcommon_d(act); break; case SHOTSPARK1: { int x; - int p = findplayer(s, &x); - execute(i, p, x); + int p = findplayer(act, &x); + execute(act, p, x); break; } } @@ -2061,42 +2001,36 @@ void moveweapons_d(void) void movetransports_d(void) { int warpspriteto; - int ll, onfloorz, q; - int i, j; + int ll; - StatIterator iti(STAT_TRANSPORT); - while ((i = iti.NextIndex()) >= 0) + DukeStatIterator iti(STAT_TRANSPORT); + while (auto act = iti.Next()) { - auto spri = &sprite[i]; - auto hiti = &hittype[i]; - auto spriowner = spri->owner < 0? nullptr : &sprite[spri->owner]; + auto spr = &act->s; + auto Owner = act->GetOwner(); - int sect = spri->sectnum; - int sectlotag = sector[sect].lotag; - - - if (spri->owner == i) + if (Owner == act) { continue; } + + int sect = spr->sectnum; + int sectlotag = sector[sect].lotag; + int onfloorz = act->temp_data[4]; - onfloorz = hiti->temp_data[4]; + if (act->temp_data[0] > 0) act->temp_data[0]--; - if (hiti->temp_data[0] > 0) hiti->temp_data[0]--; - - SectIterator itj(sect); - while ((j = itj.NextIndex()) >= 0) + DukeSectIterator itj(sect); + while (auto act2 = itj.Next()) { - auto sprj = &sprite[j]; - auto hitj = &hittype[j]; - - switch (sprj->statnum) + auto spr2 = &act2->s; + switch (spr2->statnum) { case STAT_PLAYER: // Player - if (sprj->owner != -1) + if (act2->GetOwner()) { - int p = sprj->yvel; + int p = act2->PlayerIndex(); ps[p].on_warping_sector = 1; @@ -2104,38 +2038,38 @@ void movetransports_d(void) { if (ps[p].on_ground && sectlotag == 0 && onfloorz && ps[p].jetpack_on == 0) { - if (spri->pal == 0) + if (spr->pal == 0) { - fi.spawn(i, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, i); + spawn(act, TRANSPORTERBEAM); + S_PlayActorSound(TELEPORTER, act); } for (int k = connecthead; k >= 0; k = connectpoint2[k]) - if (ps[k].cursectnum == spriowner->sectnum) + if (ps[k].cursectnum == Owner->s.sectnum) { ps[k].frag_ps = p; - sprite[ps[k].i].extra = 0; + ps[k].GetActor()->s.extra = 0; } - ps[p].angle.ang = buildang(spriowner->ang); + ps[p].angle.ang = buildang(Owner->s.ang); - if (spriowner->owner != spri->owner) + if (Owner->GetOwner() != Owner) { - hiti->temp_data[0] = 13; - hittype[spri->owner].temp_data[0] = 13; + act->temp_data[0] = 13; + Owner->temp_data[0] = 13; ps[p].transporter_hold = 13; } - ps[p].bobposx = ps[p].oposx = ps[p].posx = spriowner->x; - ps[p].bobposy = ps[p].oposy = ps[p].posy = spriowner->y; - ps[p].oposz = ps[p].posz = spriowner->z - PHEIGHT; + ps[p].bobposx = ps[p].oposx = ps[p].posx = Owner->s.x; + ps[p].bobposy = ps[p].oposy = ps[p].posy = Owner->s.y; + ps[p].oposz = ps[p].posz = Owner->s.z - PHEIGHT; - changespritesect(j, spriowner->sectnum); - ps[p].cursectnum = sprj->sectnum; + changespritesect(act2, Owner->s.sectnum); + ps[p].cursectnum = spr2->sectnum; - if (spri->pal == 0) + if (spr->pal == 0) { - int k = fi.spawn(spri->owner, TRANSPORTERBEAM); + auto k = spawn(Owner, TRANSPORTERBEAM); S_PlayActorSound(TELEPORTER, k); } @@ -2144,24 +2078,25 @@ void movetransports_d(void) } else if (!(sectlotag == 1 && ps[p].on_ground == 1)) break; - if (onfloorz == 0 && abs(spri->z - ps[p].posz) < 6144) + if (onfloorz == 0 && abs(spr->z - ps[p].posz) < 6144) if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP))) || - (ps[p].jetpack_on && (PlayerInput(p, SB_CROUCH) ^ !!ps[p].crouch_toggle))) + (ps[p].jetpack_on && PlayerInput(p, SB_CROUCH))) { - ps[p].oposx = ps[p].posx += spriowner->x - spri->x; - ps[p].oposy = ps[p].posy += spriowner->y - spri->y; + ps[p].oposx = ps[p].posx += Owner->s.x - spr->x; + ps[p].oposy = ps[p].posy += Owner->s.y - spr->y; if (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP) || ps[p].jetpack_on < 11)) - ps[p].posz = spriowner->z - 6144; - else ps[p].posz = spriowner->z + 6144; + ps[p].posz = Owner->s.z - 6144; + else ps[p].posz = Owner->s.z + 6144; ps[p].oposz = ps[p].posz; - hittype[ps[p].i].bposx = ps[p].posx; - hittype[ps[p].i].bposy = ps[p].posy; - hittype[ps[p].i].bposz = ps[p].posz; + auto pa = ps[p].GetActor(); + pa->bposx = ps[p].posx; + pa->bposy = ps[p].posy; + pa->bposz = ps[p].posz; - changespritesect(j, spriowner->sectnum); - ps[p].cursectnum = spriowner->sectnum; + changespritesect(act2, Owner->s.sectnum); + ps[p].cursectnum = Owner->s.sectnum; break; } @@ -2176,10 +2111,10 @@ void movetransports_d(void) { FX_StopAllSounds(); } - if (sprite[ps[p].i].extra > 0) - S_PlayActorSound(DUKE_UNDERWATER, j); + if (ps[p].GetActor()->s.extra > 0) + S_PlayActorSound(DUKE_UNDERWATER, act2); ps[p].oposz = ps[p].posz = - sector[spriowner->sectnum].ceilingz + (7 << 8); + sector[Owner->s.sectnum].ceilingz + (7 << 8); ps[p].posxv = 4096 - (krand() & 8192); ps[p].posyv = 4096 - (krand() & 8192); @@ -2189,15 +2124,15 @@ void movetransports_d(void) if (onfloorz && sectlotag == ST_2_UNDERWATER && ps[p].posz < (sector[sect].ceilingz + (6 << 8))) { k = 1; - // if( sprj->extra <= 0) break; + // if( spr2->extra <= 0) break; if (screenpeek == p) { FX_StopAllSounds(); } - S_PlayActorSound(DUKE_GASP, j); + S_PlayActorSound(DUKE_GASP, act2); ps[p].oposz = ps[p].posz = - sector[spriowner->sectnum].floorz - (7 << 8); + sector[Owner->s.sectnum].floorz - (7 << 8); ps[p].jumping_toggle = 1; ps[p].jumping_counter = 0; @@ -2205,33 +2140,31 @@ void movetransports_d(void) if (k == 1) { - ps[p].oposx = ps[p].posx += spriowner->x - spri->x; - ps[p].oposy = ps[p].posy += spriowner->y - spri->y; + ps[p].oposx = ps[p].posx += Owner->s.x - spr->x; + ps[p].oposy = ps[p].posy += Owner->s.y - spr->y; - if (spriowner->owner != spri->owner) + if (!Owner || Owner->GetOwner() != Owner) ps[p].transporter_hold = -2; - ps[p].cursectnum = spriowner->sectnum; + ps[p].cursectnum = Owner->s.sectnum; - changespritesect(j, spriowner->sectnum); - setsprite(ps[p].i, ps[p].posx, ps[p].posy, ps[p].posz + PHEIGHT); - - setpal(&ps[p]); + changespritesect(act2, Owner->s.sectnum); + setsprite(ps[p].GetActor(), ps[p].posx, ps[p].posy, ps[p].posz + PHEIGHT); if ((krand() & 255) < 32) - fi.spawn(j, WATERSPLASH2); + spawn(act2, WATERSPLASH2); if (sectlotag == 1) for (int l = 0; l < 9; l++) { - q = fi.spawn(ps[p].i, WATERBUBBLE); - sprite[q].z += krand() & 16383; + auto q = spawn(ps[p].GetActor(), WATERBUBBLE); + q->s.z += krand() & 16383; } } } break; case STAT_ACTOR: - switch (sprj->picnum) + switch (spr2->picnum) { case SHARK: case COMMANDER: @@ -2244,7 +2177,7 @@ void movetransports_d(void) case GREENSLIME + 5: case GREENSLIME + 6: case GREENSLIME + 7: - if (sprj->extra > 0) + if (spr2->extra > 0) continue; } case STAT_PROJECTILE: @@ -2252,27 +2185,27 @@ void movetransports_d(void) case STAT_FALLER: case STAT_DUMMYPLAYER: - ll = abs(sprj->zvel); + ll = abs(spr2->zvel); { warpspriteto = 0; - if (ll && sectlotag == 2 && sprj->z < (sector[sect].ceilingz + ll)) + if (ll && sectlotag == 2 && spr2->z < (sector[sect].ceilingz + ll)) warpspriteto = 1; - if (ll && sectlotag == 1 && sprj->z > (sector[sect].floorz - ll)) + if (ll && sectlotag == 1 && spr2->z > (sector[sect].floorz - ll)) warpspriteto = 1; - if (sectlotag == 0 && (onfloorz || abs(sprj->z - spri->z) < 4096)) + if (sectlotag == 0 && (onfloorz || abs(spr2->z - spr->z) < 4096)) { - if (spriowner->owner != spri->owner && onfloorz && hiti->temp_data[0] > 0 && sprj->statnum != 5) + if ((!Owner || Owner->GetOwner() != Owner) && onfloorz && act->temp_data[0] > 0 && spr2->statnum != STAT_MISC) { - hiti->temp_data[0]++; + act->temp_data[0]++; goto BOLT; } warpspriteto = 1; } - if (warpspriteto) switch (sprj->picnum) + if (warpspriteto) switch (spr2->picnum) { case TRANSPORTERSTAR: case TRANSPORTERBEAM: @@ -2289,24 +2222,24 @@ void movetransports_d(void) case PLAYERONWATER: if (sectlotag == 2) { - sprj->cstat &= 32767; + spr2->cstat &= 32767; break; } default: - if (sprj->statnum == 5 && !(sectlotag == 1 || sectlotag == 2)) + if (spr2->statnum == 5 && !(sectlotag == 1 || sectlotag == 2)) break; case WATERBUBBLE: - //if( rnd(192) && sprj->picnum == WATERBUBBLE) + //if( rnd(192) && a2->s.picnum == WATERBUBBLE) // break; if (sectlotag > 0) { - int k = fi.spawn(j, WATERSPLASH2); - if (sectlotag == 1 && sprj->statnum == 4) + auto k = spawn(act2, WATERSPLASH2); + if (sectlotag == 1 && spr2->statnum == 4) { - sprite[k].xvel = sprj->xvel >> 1; - sprite[k].ang = sprj->ang; + k->s.xvel = spr2->xvel >> 1; + k->s.ang = spr2->ang; ssp(k, CLIPMASK0); } } @@ -2316,70 +2249,70 @@ void movetransports_d(void) case 0: if (onfloorz) { - if (sprj->statnum == 4 || (checkcursectnums(sect) == -1 && checkcursectnums(spriowner->sectnum) == -1)) + if (spr2->statnum == STAT_PROJECTILE || (checkcursectnums(sect) == -1 && checkcursectnums(Owner->s.sectnum) == -1)) { - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z -= spri->z - sector[spriowner->sectnum].floorz; - sprj->ang = spriowner->ang; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z -= spr->z - sector[Owner->s.sectnum].floorz; + spr2->ang = Owner->s.ang; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - if (spri->pal == 0) + if (spr->pal == 0) { - int k = fi.spawn(i, TRANSPORTERBEAM); + auto k = spawn(act, TRANSPORTERBEAM); S_PlayActorSound(TELEPORTER, k); - k = fi.spawn(spri->owner, TRANSPORTERBEAM); + k = spawn(Owner, TRANSPORTERBEAM); S_PlayActorSound(TELEPORTER, k); } - if (spriowner->owner != spri->owner) + if (Owner && Owner->GetOwner() == Owner) { - hiti->temp_data[0] = 13; - hittype[spri->owner].temp_data[0] = 13; + act->temp_data[0] = 13; + Owner->temp_data[0] = 13; } - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); } } else { - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = spriowner->z + 4096; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = Owner->s.z + 4096; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); } break; case 1: - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = sector[spriowner->sectnum].ceilingz + ll; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = sector[Owner->s.sectnum].ceilingz + ll; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); break; case 2: - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = sector[spriowner->sectnum].floorz - ll; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = sector[Owner->s.sectnum].floorz - ll; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); break; } @@ -2401,10 +2334,10 @@ void movetransports_d(void) // //--------------------------------------------------------------------------- -static void greenslime(int i) +static void greenslime(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int sect = s->sectnum; int j; @@ -2424,20 +2357,20 @@ static void greenslime(int i) if (sector[sect].floorstat & 1) { - deletesprite(i); + deletesprite(actor); return; } int x; - int p = findplayer(s, &x); + int p = findplayer(actor, &x); if (x > 20480) { - hittype[i].timetosleep++; - if (hittype[i].timetosleep > SLEEPTIME) + actor->timetosleep++; + if (actor->timetosleep > SLEEPTIME) { - hittype[i].timetosleep = 0; - changespritestat(i, 2); + actor->timetosleep = 0; + changespritestat(actor, 2); return; } } @@ -2451,27 +2384,28 @@ static void greenslime(int i) t[0] = 0; return; } - makeitfall(i); + makeitfall(actor); s->cstat = 257; s->picnum = GREENSLIME + 2; s->extra = 1; s->pal = 1; - j = fi.ifhitbyweapon(&hittype[i]); if (j >= 0) + j = fi.ifhitbyweapon(actor); + if (j >= 0) { if (j == FREEZEBLAST) return; for (j = 16; j >= 0; j--) { - int k = EGS(sprite[i].sectnum, sprite[i].x, sprite[i].y, sprite[i].z, GLASSPIECES + (j % 3), -32, 36, 36, krand() & 2047, 32 + (krand() & 63), 1024 - (krand() & 1023), i, 5); - sprite[k].pal = 1; + auto k = EGS(s->sectnum, s->x, s->y, s->z, GLASSPIECES + (j % 3), -32, 36, 36, krand() & 2047, 32 + (krand() & 63), 1024 - (krand() & 1023), actor, 5); + k->s.pal = 1; } ps[p].actors_killed++; - S_PlayActorSound(GLASS_BREAKING, i); - deletesprite(i); + S_PlayActorSound(GLASS_BREAKING, actor); + deletesprite(actor); } else if (x < 1024 && ps[p].quick_kick == 0) { - j = getincangle(ps[p].angle.ang.asbuild(), getangle(sprite[i].x - ps[p].posx, sprite[i].y - ps[p].posy)); + j = getincangle(ps[p].angle.ang.asbuild(), getangle(s->x - ps[p].posx, s->y - ps[p].posy)); if (j > -128 && j < 128) ps[p].quick_kick = 14; } @@ -2485,37 +2419,37 @@ static void greenslime(int i) if (t[0] == -4) //On the player { - if (sprite[ps[p].i].extra < 1) + if (ps[p].GetActor()->s.extra < 1) { t[0] = 0; return; } - setsprite(i, s->x, s->y, s->z); + setsprite(actor, s->pos); s->ang = ps[p].angle.ang.asbuild(); - if ((PlayerInput(p, SB_FIRE) || (ps[p].quick_kick > 0)) && sprite[ps[p].i].extra > 0) + if ((PlayerInput(p, SB_FIRE) || (ps[p].quick_kick > 0)) && ps[p].GetActor()->s.extra > 0) if (ps[p].quick_kick > 0 || (ps[p].curr_weapon != HANDREMOTE_WEAPON && ps[p].curr_weapon != HANDBOMB_WEAPON && ps[p].curr_weapon != TRIPBOMB_WEAPON && ps[p].ammo_amount[ps[p].curr_weapon] >= 0)) { for (x = 0; x < 8; x++) { - j = EGS(sect, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), i, 5); - sprite[j].pal = 6; + auto j = EGS(sect, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5); + j->s.pal = 6; } - S_PlayActorSound(SLIM_DYING, i); - S_PlayActorSound(SQUISHED, i); + S_PlayActorSound(SLIM_DYING, actor); + S_PlayActorSound(SQUISHED, actor); if ((krand() & 255) < 32) { - j = fi.spawn(i, BLOODPOOL); - sprite[j].pal = 0; + auto j = spawn(actor, BLOODPOOL); + j->s.pal = 0; } ps[p].actors_killed++; t[0] = -3; - if (ps[p].somethingonplayer == &hittype[i]) + if (ps[p].somethingonplayer == actor) ps[p].somethingonplayer = nullptr; - deletesprite(i); + deletesprite(actor); return; } @@ -2529,21 +2463,20 @@ static void greenslime(int i) if (t[2] < 348) t[2] += 128; - if (ps[p].newowner >= 0) + if (ps[p].newOwner != nullptr) { - ps[p].newowner = -1; + ps[p].newOwner = nullptr; ps[p].posx = ps[p].oposx; ps[p].posy = ps[p].oposy; ps[p].posz = ps[p].oposz; ps[p].angle.restore(); updatesector(ps[p].posx, ps[p].posy, &ps[p].cursectnum); - setpal(&ps[p]); - StatIterator it(STAT_ACTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto ac = it.Next()) { - if (sprite[j].picnum == CAMERA1) sprite[j].yvel = 0; + if (ac->s.picnum == CAMERA1) ac->s.yvel = 0; } } @@ -2555,8 +2488,9 @@ static void greenslime(int i) if (t[3] == 5) { - sprite[ps[p].i].extra += -(5 + (krand() & 3)); - S_PlayActorSound(SLIM_ATTACK, i); + auto psp = ps[p].GetActor(); + psp->s.extra += -(5 + (krand() & 3)); + S_PlayActorSound(SLIM_ATTACK, actor); } if (t[3] < 7) t[3]++; @@ -2583,7 +2517,7 @@ static void greenslime(int i) { if (ps[p].somethingonplayer == nullptr) { - ps[p].somethingonplayer = &hittype[i]; + ps[p].somethingonplayer = actor; if (t[0] == 3 || t[0] == 2) //Falling downward t[2] = (12 << 8); else t[2] = -(13 << 8); //Climbing up duke @@ -2591,70 +2525,70 @@ static void greenslime(int i) } } - j = fi.ifhitbyweapon(&hittype[i]); if (j >= 0) + j = fi.ifhitbyweapon(actor); + if (j >= 0) { - S_PlayActorSound(SLIM_DYING, i); + S_PlayActorSound(SLIM_DYING, actor); - if (ps[p].somethingonplayer == &hittype[i]) + if (ps[p].somethingonplayer == actor) ps[p].somethingonplayer = nullptr; if (j == FREEZEBLAST) { - S_PlayActorSound(SOMETHINGFROZE, i); t[0] = -5; t[3] = 0; + S_PlayActorSound(SOMETHINGFROZE, actor); + t[0] = -5; t[3] = 0; return; } ps[p].actors_killed++; if ((krand() & 255) < 32) { - j = fi.spawn(i, BLOODPOOL); - sprite[j].pal = 0; + auto j = spawn(actor, BLOODPOOL); + j->s.pal = 0; } for (x = 0; x < 8; x++) { - j = EGS(sect, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), i, 5); - sprite[j].pal = 6; + auto j = EGS(sect, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5); + j->s.pal = 6; } t[0] = -3; - deletesprite(i); + deletesprite(actor); return; } // All weap if (t[0] == -1) //Shrinking down { - makeitfall(i); + makeitfall(actor); s->cstat &= 65535 - 8; s->picnum = GREENSLIME + 4; - // if(s->yrepeat > 62) - // fi.guts(s,JIBS6,5,myconnectindex); - if (s->xrepeat > 32) s->xrepeat -= krand() & 7; if (s->yrepeat > 16) s->yrepeat -= krand() & 7; else { s->xrepeat = 40; s->yrepeat = 16; - t[5] = -1; + actor->temp_actor = nullptr; t[0] = 0; } return; } - else if (t[0] != -2) getglobalz(i); + else if (t[0] != -2) getglobalz(actor); if (t[0] == -2) //On top of somebody (an enemy) { - makeitfall(i); - sprite[t[5]].xvel = 0; + auto s5 = actor->temp_actor; + makeitfall(actor); + s5->s.xvel = 0; - int l = sprite[t[5]].ang; + int l = s5->s.ang; - s->z = sprite[t[5]].z; - s->x = sprite[t[5]].x + (sintable[(l + 512) & 2047] >> 11); - s->y = sprite[t[5]].y + (sintable[l & 2047] >> 11); + s->z = s5->s.z; + s->x = s5->s.x + (sintable[(l + 512) & 2047] >> 11); + s->y = s5->s.y + (sintable[l & 2047] >> 11); s->picnum = GREENSLIME + 2 + (global_random & 1); @@ -2665,9 +2599,9 @@ static void greenslime(int i) else { t[0] = -1; - x = ldist(s, &sprite[t[5]]); + x = ldist(actor, s5); if (x < 768) { - sprite[t[5]].xrepeat = 0; + s5->s.xrepeat = 0; } } } @@ -2677,18 +2611,14 @@ static void greenslime(int i) //Check randomly to see of there is an actor near if (rnd(32)) { - SectIterator it(sect); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto a2 = it.Next()) { - switch (sprite[j].picnum) + if (actorinfo[a2->s.picnum].flags & SFLAG_GREENSLIMEFOOD) { - case LIZTROOP: - case LIZMAN: - case PIGCOP: - case NEWBEAST: - if (ldist(s, &sprite[j]) < 768 && (abs(s->z - sprite[j].z) < 8192)) //Gulp them + if (ldist(actor, a2) < 768 && (abs(s->z - a2->s.z) < 8192)) //Gulp them { - t[5] = j; + actor->temp_actor = a2; t[0] = -2; t[1] = 0; return; @@ -2704,14 +2634,14 @@ static void greenslime(int i) s->picnum = GREENSLIME; if ((krand() & 511) == 0) - S_PlayActorSound(SLIM_ROAM, i); + S_PlayActorSound(SLIM_ROAM, actor); if (t[0] == 2) { s->zvel = 0; s->cstat &= (65535 - 8); - if ((sector[sect].ceilingstat & 1) || (hittype[i].ceilingz + 6144) < s->z) + if ((sector[sect].ceilingstat & 1) || (actor->ceilingz + 6144) < s->z) { s->z += 2048; t[0] = 3; @@ -2721,10 +2651,10 @@ static void greenslime(int i) else { s->cstat |= 8; - makeitfall(i); + makeitfall(actor); } - if (everyothertime & 1) ssp(i, CLIPMASK0); + if (everyothertime & 1) ssp(actor, CLIPMASK0); if (s->xvel > 96) { @@ -2745,7 +2675,7 @@ static void greenslime(int i) s->yrepeat = 16 + (sintable[t[1] & 2047] >> 13); if (rnd(4) && (sector[sect].ceilingstat & 1) == 0 && - abs(hittype[i].floorz - hittype[i].ceilingz) + abs(actor->floorz - actor->ceilingz) < (192 << 8)) { s->zvel = 0; @@ -2762,9 +2692,9 @@ static void greenslime(int i) if (s->zvel > -(2048 + 1024)) s->zvel -= 348; s->z += s->zvel; - if (s->z < hittype[i].ceilingz + 4096) + if (s->z < actor->ceilingz + 4096) { - s->z = hittype[i].ceilingz + 4096; + s->z = actor->ceilingz + 4096; s->xvel = 0; t[0] = 2; } @@ -2774,9 +2704,9 @@ static void greenslime(int i) { s->picnum = GREENSLIME + 1; - makeitfall(i); + makeitfall(actor); - if (s->z > hittype[i].floorz - (8 << 8)) + if (s->z > actor->floorz - (8 << 8)) { s->yrepeat -= 4; s->xrepeat += 2; @@ -2787,9 +2717,9 @@ static void greenslime(int i) if (s->xrepeat > 8) s->xrepeat -= 4; } - if (s->z > hittype[i].floorz - 2048) + if (s->z > actor->floorz - 2048) { - s->z = hittype[i].floorz - 2048; + s->z = actor->floorz - 2048; t[0] = 0; s->xvel = 0; } @@ -2802,19 +2732,19 @@ static void greenslime(int i) // //--------------------------------------------------------------------------- -static void flamethrowerflame(int i) +static void flamethrowerflame(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int sect = s->sectnum; - int x, j; - int p = findplayer(s, &x); - execute(i, p, x); + int x; + int p = findplayer(actor, &x); + execute(actor, p, x); t[0]++; if (sector[sect].lotag == 2) { - sprite[fi.spawn(i, EXPLOSION2)].shade = 127; - deletesprite(i); + spawn(actor, EXPLOSION2)->s.shade = 127; + deletesprite(actor); return; } @@ -2824,7 +2754,7 @@ static void flamethrowerflame(int i) int xvel = s->xvel; int zvel = s->zvel; - getglobalz(i); + getglobalz(actor); int ds = t[0] / 6; if (s->xrepeat < 80) @@ -2834,54 +2764,53 @@ static void flamethrowerflame(int i) t[3] = krand() % 10; if (t[0] > 30) { - sprite[fi.spawn(i, EXPLOSION2)].shade = 127; - deletesprite(i); + spawn(actor, EXPLOSION2)->s.shade = 127; + deletesprite(actor); return; } - j = fi.movesprite(i, (xvel * (sintable[(s->ang + 512) & 2047])) >> 14, - (xvel * (sintable[s->ang & 2047])) >> 14, s->zvel, CLIPMASK1); + Collision coll; + movesprite_ex(actor, (xvel * (sintable[(s->ang + 512) & 2047])) >> 14, + (xvel * (sintable[s->ang & 2047])) >> 14, s->zvel, CLIPMASK1, coll); if (s->sectnum < 0) { - deletesprite(i); + deletesprite(actor); return; } - if ((j & kHitTypeMask) != kHitSprite) + if (coll.type != kHitSprite) { - if (s->z < hittype[i].ceilingz) + if (s->z < actor->ceilingz) { - j = kHitSector | (s->sectnum); + coll.setSector(s->sectnum); s->zvel = -1; } - else if ((s->z > hittype[i].floorz && sector[s->sectnum].lotag != 1) - || (s->z > hittype[i].floorz + (16 << 8) && sector[s->sectnum].lotag == 1)) + else if ((s->z > actor->floorz && sector[s->sectnum].lotag != 1) + || (s->z > actor->floorz + (16 << 8) && sector[s->sectnum].lotag == 1)) { - j = kHitSector | (s->sectnum); + coll.setSector(s->sectnum); if (sector[s->sectnum].lotag != 1) s->zvel = 1; } } - if (j != 0) { + if (coll.type != 0) { s->xvel = s->yvel = s->zvel = 0; - if ((j & kHitTypeMask) == kHitSprite) + if (coll.type == kHitSprite) { - j &= (MAXSPRITES - 1); - fi.checkhitsprite((short)j, i); - if (sprite[j].picnum == APLAYER) - S_PlayActorSound(j, PISTOL_BODYHIT); + fi.checkhitsprite(coll.actor, actor); + if (coll.actor->s.picnum == APLAYER) + S_PlayActorSound(PISTOL_BODYHIT, coll.actor); } - else if ((j & kHitTypeMask) == kHitWall) + else if (coll.type == kHitWall) { - j &= (MAXWALLS - 1); - setsprite(i, dax, day, daz); - fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); + setsprite(actor, dax, day, daz); + fi.checkhitwall(actor, coll.index, s->x, s->y, s->z, s->picnum); } - else if ((j & kHitTypeMask) == kHitSector) + else if (coll.type == kHitSector) { - setsprite(i, dax, day, daz); + setsprite(actor, dax, day, daz); if (s->zvel < 0) fi.checkhitceiling(s->sectnum); } @@ -2889,12 +2818,12 @@ static void flamethrowerflame(int i) if (s->xrepeat >= 10) { x = s->extra; - fi.hitradius(i, rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x); + fi.hitradius(actor, rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x); } else { x = s->extra + (global_random & 3); - fi.hitradius(i, (rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x); + fi.hitradius(actor, (rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x); } } } @@ -2905,33 +2834,34 @@ static void flamethrowerflame(int i) // //--------------------------------------------------------------------------- -static void heavyhbomb(int i) +static void heavyhbomb(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + auto t = &actor->temp_data[0]; + auto Owner = actor->GetOwner(); int sect = s->sectnum; - int x, j, l; + int x, l; if ((s->cstat & 32768)) { t[2]--; if (t[2] <= 0) { - S_PlayActorSound(TELEPORTER, i); - fi.spawn(i, TRANSPORTERSTAR); + S_PlayActorSound(TELEPORTER, actor); + spawn(actor, TRANSPORTERSTAR); s->cstat = 257; } return; } - int p = findplayer(s, &x); + int p = findplayer(actor, &x); if (x < 1220) s->cstat &= ~257; else s->cstat |= 257; if (t[3] == 0) { - j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j >= 0) { t[3] = 1; @@ -2944,41 +2874,42 @@ static void heavyhbomb(int i) if (s->picnum != BOUNCEMINE) { - makeitfall(i); + makeitfall(actor); - if (sector[sect].lotag != 1 && s->z >= hittype[i].floorz - (FOURSLEIGHT) && s->yvel < 3) + if (sector[sect].lotag != 1 && s->z >= actor->floorz - (FOURSLEIGHT) && s->yvel < 3) { - if (s->yvel > 0 || (s->yvel == 0 && hittype[i].floorz == sector[sect].floorz)) - S_PlayActorSound(PIPEBOMB_BOUNCE, i); + if (s->yvel > 0 || (s->yvel == 0 && actor->floorz == sector[sect].floorz)) + S_PlayActorSound(PIPEBOMB_BOUNCE, actor); s->zvel = -((4 - s->yvel) << 8); if (sector[s->sectnum].lotag == 2) s->zvel >>= 2; s->yvel++; } - if (s->z < hittype[i].ceilingz) // && sector[sect].lotag != 2 ) + if (s->z < actor->ceilingz) // && sector[sect].lotag != 2 ) { - s->z = hittype[i].ceilingz + (3 << 8); + s->z = actor->ceilingz + (3 << 8); s->zvel = 0; } } - j = fi.movesprite(i, + Collision coll; + movesprite_ex(actor, (s->xvel * (sintable[(s->ang + 512) & 2047])) >> 14, (s->xvel * (sintable[s->ang & 2047])) >> 14, - s->zvel, CLIPMASK0); + s->zvel, CLIPMASK0, coll); - if (sector[sprite[i].sectnum].lotag == 1 && s->zvel == 0) + if (sector[s->sectnum].lotag == 1 && s->zvel == 0) { s->z += (32 << 8); if (t[5] == 0) { t[5] = 1; - fi.spawn(i, WATERSPLASH2); + spawn(actor, WATERSPLASH2); } } else t[5] = 0; - if (t[3] == 0 && (s->picnum == BOUNCEMINE || s->picnum == MORTER) && (j || x < 844)) + if (t[3] == 0 && (s->picnum == BOUNCEMINE || s->picnum == MORTER) && (coll.type || x < 844)) { t[3] = 1; t[4] = 0; @@ -2987,8 +2918,8 @@ static void heavyhbomb(int i) goto DETONATEB; } - if (sprite[s->owner].picnum == APLAYER) - l = sprite[s->owner].yvel; + if ( Owner && Owner->s.picnum == APLAYER) + l = Owner->PlayerIndex(); else l = -1; if (s->xvel > 0) @@ -3002,11 +2933,10 @@ static void heavyhbomb(int i) if (s->xvel & 8) s->cstat ^= 4; } - if ((j & 49152) == 32768) + if (coll.type== kHitWall) { - j &= (MAXWALLS - 1); - - fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); + int j = coll.index; + fi.checkhitwall(actor, j, s->x, s->y, s->z, s->picnum); int k = getangle( wall[wall[j].point2].x - wall[j].x, @@ -3042,13 +2972,12 @@ DETONATEB: case BOUNCEMINE: m = bouncemineblastradius; break; } - fi.hitradius(i, m, x >> 2, x >> 1, x - (x >> 2), x); - fi.spawn(i, EXPLOSION2); - if (s->zvel == 0) - fi.spawn(i, EXPLOSION2BOT); - S_PlayActorSound(PIPEBOMB_EXPLODE, i); + fi.hitradius(actor, m, x >> 2, x >> 1, x - (x >> 2), x); + spawn(actor, EXPLOSION2); + if (s->zvel == 0) spawn(actor, EXPLOSION2BOT); + S_PlayActorSound(PIPEBOMB_EXPLODE, actor); for (x = 0; x < 8; x++) - RANDOMSCRAP(s, i); + RANDOMSCRAP(actor); } if (s->yrepeat) @@ -3059,15 +2988,15 @@ DETONATEB: if (t[4] > 20) { - if (s->owner != i || ud.respawn_items == 0) + if (Owner != actor || ud.respawn_items == 0) { - deletesprite(i); + deletesprite(actor); return; } else { t[2] = respawnitemtime; - fi.spawn(i, RESPAWNMARKERRED); + spawn(actor, RESPAWNMARKERRED); s->cstat = (short)32768; s->yrepeat = 9; return; @@ -3078,9 +3007,9 @@ DETONATEB: if (cansee(s->x, s->y, s->z - (8 << 8), s->sectnum, ps[p].posx, ps[p].posy, ps[p].posz, ps[p].cursectnum)) if (ps[p].ammo_amount[HANDBOMB_WEAPON] < max_ammo_amount[HANDBOMB_WEAPON]) { - if (ud.coop >= 1 && s->owner == i) + if (ud.coop >= 1 && Owner == actor) { - for (j = 0; j < ps[p].weapreccnt; j++) + for (int j = 0; j < ps[p].weapreccnt; j++) if (ps[p].weaprecs[j] == s->picnum) continue; @@ -3089,28 +3018,28 @@ DETONATEB: } addammo(HANDBOMB_WEAPON, &ps[p], 1); - S_PlayActorSound(DUKE_GET, ps[p].i); + S_PlayActorSound(DUKE_GET, ps[p].GetActor()); - if (ps[p].gotweapon[HANDBOMB_WEAPON] == 0 || s->owner == ps[p].i) + if (ps[p].gotweapon[HANDBOMB_WEAPON] == 0 || Owner == ps[p].GetActor()) fi.addweapon(&ps[p], HANDBOMB_WEAPON); - if (sprite[s->owner].picnum != APLAYER) + if (!Owner || Owner->s.picnum != APLAYER) { SetPlayerPal(&ps[p], PalEntry(32, 0, 32, 0)); } - if (s->owner != i || ud.respawn_items == 0) + if (Owner != actor || ud.respawn_items == 0) { - if (s->owner == i && ud.coop >= 1) + if (Owner == actor && ud.coop >= 1) return; - deletesprite(i); + deletesprite(actor); return; } else { t[2] = respawnitemtime; - fi.spawn(i, RESPAWNMARKERRED); + spawn(actor, RESPAWNMARKERRED); s->cstat = (short)32768; } } @@ -3126,36 +3055,33 @@ DETONATEB: void moveactors_d(void) { - int x, * t; - short j, sect, p; - spritetype* s; - unsigned short k; + int x; + int sect, p; + unsigned int k; - StatIterator it(STAT_ACTOR); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { - s = &sprite[i]; - + auto s = &act->s; sect = s->sectnum; if (s->xrepeat == 0 || sect < 0 || sect >= MAXSECTORS) { - deletesprite(i); + deletesprite(act); continue; } - t = &hittype[i].temp_data[0]; + int *t = &act->temp_data[0]; - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = s->x; + act->bposy = s->y; + act->bposz = s->z; switch (s->picnum) { case FLAMETHROWERFLAME: - if (isWorldTour()) flamethrowerflame(i); + if (isWorldTour()) flamethrowerflame(act); continue; case DUCK: @@ -3172,22 +3098,20 @@ void moveactors_d(void) } else { - j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(act); if (j >= 0) { s->cstat = 32 + 128; k = 1; - StatIterator it(STAT_ACTOR); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->lotag == s->lotag && - sj->picnum == s->picnum) + if (act2->s.lotag == s->lotag && + act2->s.picnum == s->picnum) { - if ((sj->hitag && !(sj->cstat & 32)) || - (!sj->hitag && (sj->cstat & 32)) + if ((act2->s.hitag && !(act2->s.cstat & 32)) || + (!act2->s.hitag && (act2->s.cstat & 32)) ) { k = 0; @@ -3199,7 +3123,7 @@ void moveactors_d(void) if (k == 1) { operateactivators(s->lotag, -1); - fi.operateforcefields(i, s->lotag); + fi.operateforcefields(act, s->lotag); operatemasterswitches(s->lotag); } } @@ -3209,7 +3133,7 @@ void moveactors_d(void) case RESPAWNMARKERRED: case RESPAWNMARKERYELLOW: case RESPAWNMARKERGREEN: - if (!respawnmarker(i, RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; + if (!respawnmarker(act, RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; break; case HELECOPT: @@ -3218,39 +3142,39 @@ void moveactors_d(void) s->z += s->zvel; t[0]++; - if (t[0] == 4) S_PlayActorSound(WAR_AMBIENCE2, i); + if (t[0] == 4) S_PlayActorSound(WAR_AMBIENCE2, act); if (t[0] > (26 * 8)) { S_PlaySound(RPG_EXPLODE); - for (j = 0; j < 32; j++) - RANDOMSCRAP(s, i); + for (int j = 0; j < 32; j++) + RANDOMSCRAP(act); earthquaketime = 16; - deletesprite(i); + deletesprite(act); continue; } else if ((t[0] & 3) == 0) - fi.spawn(i, EXPLOSION2); - ssp(i, CLIPMASK0); + spawn(act, EXPLOSION2); + ssp(act, CLIPMASK0); break; case RAT: - if (!rat(i, true)) continue; + if (!rat(act, true)) continue; break; case QUEBALL: case STRIPEBALL: - if (!queball(i, POCKET, QUEBALL, STRIPEBALL)) continue; + if (!queball(act, POCKET, QUEBALL, STRIPEBALL)) continue; break; case FORCESPHERE: - forcesphere(i, FORCESPHERE); + forcesphere(act, FORCESPHERE); continue; case RECON: - recon(i, EXPLOSION2, FIRELASER, RECO_ATTACK, RECO_PAIN, RECO_ROAM, 10, [](int i)->int { return PIGCOP; }); + recon(act, EXPLOSION2, FIRELASER, RECO_ATTACK, RECO_PAIN, RECO_ROAM, 10, [](DDukeActor* i)->int { return PIGCOP; }); continue; case OOZ: case OOZ2: - ooz(i); + ooz(act); continue; case GREENSLIME: @@ -3261,16 +3185,15 @@ void moveactors_d(void) case GREENSLIME + 5: case GREENSLIME + 6: case GREENSLIME + 7: - greenslime(i); + greenslime(act); continue; case BOUNCEMINE: case MORTER: - j = fi.spawn(i, FRAMEEFFECT1); - hittype[j].temp_data[0] = 3; + spawn(act, FRAMEEFFECT1)->temp_data[0] = 3; case HEAVYHBOMB: - heavyhbomb(i); + heavyhbomb(act); continue; case REACTORBURNT: @@ -3279,17 +3202,17 @@ void moveactors_d(void) case REACTOR: case REACTOR2: - reactor(i, REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); + reactor(act, REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); continue; case CAMERA1: - camera(i); + camera(act); continue; } // #ifndef VOLOMEONE - if (ud.multimode < 2 && badguy(s)) + if (ud.multimode < 2 && badguy(act)) { if (actor_tog == 1) { @@ -3300,9 +3223,9 @@ void moveactors_d(void) } // #endif - p = findplayer(s, &x); + p = findplayer(act, &x); - execute(i, p, x); + execute(act, p, x); } } @@ -3313,27 +3236,26 @@ void moveactors_d(void) // //--------------------------------------------------------------------------- -static void fireflyflyingeffect(int i) +static void fireflyflyingeffect(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; - int x, p = findplayer(s, &x); - execute(i, p, x); + auto t = &actor->temp_data[0]; + int x, p = findplayer(actor, &x); + execute(actor, p, x); - auto owner = &sprite[s->owner]; - if (owner->picnum != FIREFLY) + auto Owner = actor->GetOwner(); + if (!Owner || Owner->s.picnum != FIREFLY) { - deletesprite(i); + deletesprite(actor); return; } - if (owner->xrepeat >= 24 || owner->pal == 1) - s->cstat |= 0x8000; + if (Owner->s.xrepeat >= 24 || Owner->s.pal == 1) + actor->s.cstat |= 0x8000; else - s->cstat &= ~0x8000; + actor->s.cstat &= ~0x8000; - double dx = owner->x - sprite[ps[p].i].x; - double dy = owner->y - sprite[ps[p].i].y; + double dx = Owner->s.x - ps[p].GetActor()->s.x; + double dy = Owner->s.y - ps[p].GetActor()->s.y; double dist = sqrt(dx * dx + dy * dy); if (dist != 0.0) { @@ -3341,13 +3263,13 @@ static void fireflyflyingeffect(int i) dy /= dist; } - s->x = (int) (owner->x - (dx * -10.0)); - s->y = (int) (owner->y - (dy * -10.0)); - s->z = owner->z + 2048; + actor->s.x = (int) (Owner->s.x - (dx * -10.0)); + actor->s.y = (int) (Owner->s.y - (dy * -10.0)); + actor->s.z = Owner->s.z + 2048; - if (owner->extra <= 0) + if (Owner->s.extra <= 0) { - deletesprite(i); + deletesprite(actor); } } @@ -3360,32 +3282,29 @@ static void fireflyflyingeffect(int i) void moveexplosions_d(void) // STATNUM 5 { int sect, p; - int x, * t; - spritetype* s; - + int x; - StatIterator it(STAT_MISC); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto act = it.Next()) { - t = &hittype[i].temp_data[0]; - s = &sprite[i]; + auto s = &act->s; + int* t = &act->temp_data[0]; sect = s->sectnum; if (sect < 0 || s->xrepeat == 0) { - deletesprite(i); + deletesprite(act); continue; } - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = s->x; + act->bposy = s->y; + act->bposz = s->z; switch (s->picnum) { case FIREFLYFLYINGEFFECT: - if (isWorldTour()) fireflyflyingeffect(i); + if (isWorldTour()) fireflyflyingeffect(act); continue; case NEON1: @@ -3418,35 +3337,36 @@ void moveexplosions_d(void) // STATNUM 5 if (t[0]) { t[0]++; + auto Owner = act->GetOwner(); if (t[0] == 8) s->picnum = NUKEBUTTON + 1; - else if (t[0] == 16) + else if (t[0] == 16 && Owner) { s->picnum = NUKEBUTTON + 2; - ps[sprite[s->owner].yvel].fist_incs = 1; + ps[Owner->PlayerIndex()].fist_incs = 1; } - if (ps[sprite[s->owner].yvel].fist_incs == 26) + if (Owner && ps[Owner->PlayerIndex()].fist_incs == 26) s->picnum = NUKEBUTTON + 3; } continue; case FORCESPHERE: - forcesphere(i); + forcesphereexplode(act); continue; case WATERSPLASH2: - watersplash2(i); + watersplash2(act); continue; case FRAMEEFFECT1: - frameeffect1(i); + frameeffect1(act); continue; case INNERJAW: case INNERJAW + 1: - p = findplayer(s, &x); + p = findplayer(act, &x); if (x < 512) { SetPlayerPal(&ps[p], PalEntry(32, 32, 0, 0)); - sprite[ps[p].i].extra -= 4; + ps[p].GetActor()->s.extra -= 4; } case FIRELASER: @@ -3454,23 +3374,22 @@ void moveexplosions_d(void) // STATNUM 5 s->extra = 999; else { - deletesprite(i); + deletesprite(act); continue; } break; case TONGUE: - deletesprite(i); + deletesprite(act); continue; case MONEY + 1: case MAIL + 1: case PAPER + 1: - hittype[i].floorz = s->z = getflorzofslope(s->sectnum, s->x, s->y); + act->floorz = s->z = getflorzofslope(s->sectnum, s->x, s->y); break; case MONEY: case MAIL: case PAPER: - money(i, BLOODPOOL); - + money(act, BLOODPOOL); break; case JIBS1: @@ -3488,12 +3407,12 @@ void moveexplosions_d(void) // STATNUM 5 case DUKETORSO: case DUKEGUN: case DUKELEG: - jibs(i, JIBS6, true, false, false, s->picnum == DUKELEG || s->picnum == DUKETORSO || s->picnum == DUKEGUN, false); + jibs(act, JIBS6, true, false, false, s->picnum == DUKELEG || s->picnum == DUKETORSO || s->picnum == DUKEGUN, false); continue; case BLOODPOOL: case PUKE: - bloodpool(i, s->picnum == PUKE, TIRE); + bloodpool(act, s->picnum == PUKE, TIRE); continue; @@ -3519,25 +3438,174 @@ void moveexplosions_d(void) // STATNUM 5 case FORCERIPPLE: case TRANSPORTERSTAR: case TRANSPORTERBEAM: - p = findplayer(s, &x); - execute(i, p, x); + p = findplayer(act, &x); + execute(act, p, x); continue; case SHELL: case SHOTGUNSHELL: - shell(i, (sector[sect].floorz + (24 << 8)) < s->z); + shell(act, (sector[sect].floorz + (24 << 8)) < s->z); continue; case GLASSPIECES: case GLASSPIECES + 1: case GLASSPIECES + 2: - glasspieces(i); + glasspieces(act); continue; } if (s->picnum >= SCRAP6 && s->picnum <= SCRAP5 + 3) { - scrap(i, SCRAP1, SCRAP6); + scrap(act, SCRAP1, SCRAP6); + } + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void handle_se06_d(DDukeActor* actor) +{ + auto s = &actor->s; + auto t = &actor->temp_data[0]; + + auto sc = §or[s->sectnum]; + int st = s->lotag; + int sh = s->hitag; + + int k = sc->extra; + + if (t[4] > 0) + { + t[4]--; + if (t[4] >= (k - (k >> 3))) + s->xvel -= (k >> 5); + if (t[4] > ((k >> 1) - 1) && t[4] < (k - (k >> 3))) + s->xvel = 0; + if (t[4] < (k >> 1)) + s->xvel += (k >> 5); + if (t[4] < ((k >> 1) - (k >> 3))) + { + t[4] = 0; + s->xvel = k; + } + } + else s->xvel = k; + + DukeStatIterator it(STAT_EFFECTOR); + while (auto act2 = it.Next()) + { + if ((act2->s.lotag == 14) && (sh == act2->s.hitag) && (act2->temp_data[0] == t[0])) + { + act2->s.xvel = s->xvel; + //if( t[4] == 1 ) + { + if (act2->temp_data[5] == 0) + act2->temp_data[5] = dist(act2, actor); + int x = sgn(dist(act2, actor) - act2->temp_data[5]); + if (act2->s.extra) + x = -x; + s->xvel += x; + } + act2->temp_data[4] = t[4]; + } + } + handle_se14(actor, true, RPG, JIBS6); +} + + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_se28(DDukeActor* actor) +{ + auto s = &actor->s; + auto sc = §or[s->sectnum]; + int st = s->lotag; + int sh = s->hitag; + int* t = &actor->temp_data[0]; + + if (t[5] > 0) + { + t[5]--; + return; + } + + if (t[0] == 0) + { + int x; + int p = findplayer(actor, &x); + if (x > 15500) + return; + t[0] = 1; + t[1] = 64 + (krand() & 511); + t[2] = 0; + } + else + { + t[2]++; + if (t[2] > t[1]) + { + t[0] = 0; + ps[screenpeek].visibility = ud.const_visibility; + return; + } + else if (t[2] == (t[1] >> 1)) + S_PlayActorSound(THUNDER, actor); + else if (t[2] == (t[1] >> 3)) + S_PlayActorSound(LIGHTNING_SLAP, actor); + else if (t[2] == (t[1] >> 2)) + { + DukeStatIterator it(STAT_DEFAULT); + while (auto act2 = it.Next()) + { + if (act2->s.picnum == NATURALLIGHTNING && act2->s.hitag == s->hitag) + act2->s.cstat |= 32768; + } + } + else if (t[2] > (t[1] >> 3) && t[2] < (t[1] >> 2)) + { + int j = !!cansee(s->x, s->y, s->z, s->sectnum, ps[screenpeek].posx, ps[screenpeek].posy, ps[screenpeek].posz, ps[screenpeek].cursectnum); + + if (rnd(192) && (t[2] & 1)) + { + if (j) ps[screenpeek].visibility = 0; + } + else if (j) ps[screenpeek].visibility = ud.const_visibility; + + DukeStatIterator it(STAT_DEFAULT); + while (auto act2 = it.Next()) + { + if (act2->s.picnum == NATURALLIGHTNING && act2->s.hitag == s->hitag) + { + if (rnd(32) && (t[2] & 1)) + { + act2->s.cstat &= 32767; + spawn(act2, SMALLSMOKE); + + int x; + int p = findplayer(actor, &x); + auto psa = ps[p].GetActor(); + x = ldist(psa, act2); + if (x < 768) + { + if (S_CheckActorSoundPlaying(psa, DUKE_LONGTERM_PAIN) < 1) + S_PlayActorSound(DUKE_LONGTERM_PAIN, psa); + S_PlayActorSound(SHORT_CIRCUIT, psa); + psa->s.extra -= 8 + (krand() & 7); + SetPlayerPal(&ps[p], PalEntry(32, 16, 0, 0)); + } + return; + } + else act2->s.cstat |= 32768; + } + } } } } @@ -3550,786 +3618,408 @@ void moveexplosions_d(void) // STATNUM 5 void moveeffectors_d(void) //STATNUM 3 { - int q = 0, l, x, st, j, * t; - int p, sh; - short k; - spritetype* s; - sectortype* sc; - walltype* wal; + int l; clearfriction(); - - StatIterator it(STAT_EFFECTOR); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act = it.Next()) { - s = &sprite[i]; - - sc = §or[s->sectnum]; - st = s->lotag; - sh = s->hitag; - - t = &hittype[i].temp_data[0]; - - switch (st) + auto sc = §or[act->s.sectnum]; + switch (act->s.lotag) { case SE_0_ROTATING_SECTOR: - handle_se00(i, LASERLINE); + handle_se00(act, LASERLINE); break; case SE_1_PIVOT: //Nothing for now used as the pivot - handle_se01(i); + handle_se01(act); break; case SE_6_SUBWAY: - { - k = sc->extra; + handle_se06_d(act); + break; - if (t[4] > 0) - { - t[4]--; - if (t[4] >= (k - (k >> 3))) - s->xvel -= (k >> 5); - if (t[4] > ((k >> 1) - 1) && t[4] < (k - (k >> 3))) - s->xvel = 0; - if (t[4] < (k >> 1)) - s->xvel += (k >> 5); - if (t[4] < ((k >> 1) - (k >> 3))) - { - t[4] = 0; - s->xvel = k; - } - } - else s->xvel = k; - - StatIterator it(STAT_EFFECTOR); - int j; - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if ((sj->lotag == 14) && (sh == sj->hitag) && (hittype[j].temp_data[0] == t[0])) - { - sj->xvel = s->xvel; - // if( t[4] == 1 ) - { - if (hittype[j].temp_data[5] == 0) - hittype[j].temp_data[5] = dist(sj, s); - x = sgn(dist(sj, s) - hittype[j].temp_data[5]); - if (sj->extra) - x = -x; - s->xvel += x; - } - hittype[j].temp_data[4] = t[4]; - } - } - x = 0; - } case SE_14_SUBWAY_CAR: - handle_se14(i, true, RPG, JIBS6); + handle_se14(act, true, RPG, JIBS6); break; case SE_30_TWO_WAY_TRAIN: - handle_se30(i, JIBS6); + handle_se30(act, JIBS6); break; - case SE_2_EARTHQUAKE: - handle_se02(i); + handle_se02(act); break; //Flashing sector lights after reactor EXPLOSION2 case SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT: - handle_se03(i); + handle_se03(act); break; case SE_4_RANDOM_LIGHTS: - handle_se04(i); + handle_se04(act); break; //BOSS case SE_5_BOSS: - handle_se05(i, FIRELASER); + handle_se05(act, FIRELASER); break; case SE_8_UP_OPEN_DOOR_LIGHTS: case SE_9_DOWN_OPEN_DOOR_LIGHTS: - handle_se08(i, false); + handle_se08(act, false); break; case SE_10_DOOR_AUTO_CLOSE: { static const int tags[] = { 20, 21, 22, 26, 0}; - handle_se10(i, tags); + handle_se10(act, tags); break; } case SE_11_SWINGING_DOOR: - handle_se11(i); + handle_se11(act); break; case SE_12_LIGHT_SWITCH: - handle_se12(i); + handle_se12(act); break; case SE_13_EXPLOSIVE: - handle_se13(i); + handle_se13(act); break; case SE_15_SLIDING_DOOR: - handle_se15(i); + handle_se15(act); break; case SE_16_REACTOR: - handle_se16(i, REACTOR, REACTOR2); + handle_se16(act, REACTOR, REACTOR2); break; case SE_17_WARP_ELEVATOR: - handle_se17(i); + handle_se17(act); break; case SE_18_INCREMENTAL_SECTOR_RISE_FALL: - handle_se18(i, true); + handle_se18(act, true); break; case SE_19_EXPLOSION_LOWERS_CEILING: - handle_se19(i, BIGFORCE); + handle_se19(act, BIGFORCE); break; case SE_20_STRETCH_BRIDGE: - handle_se20(i); + handle_se20(act); break; case SE_21_DROP_FLOOR: - handle_se21(i); + handle_se21(act); break; case SE_22_TEETH_DOOR: - handle_se22(i); + handle_se22(act); break; case SE_24_CONVEYOR: case 34: { - if (t[4]) break; - - x = (sprite[i].yvel * sintable[(s->ang + 512) & 2047]) >> 18; - l = (sprite[i].yvel * sintable[s->ang & 2047]) >> 18; - - k = 0; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sprj = &sprite[j]; - if (sprj->zvel >= 0) - switch (sprj->statnum) - { - case 5: - switch (sprj->picnum) - { - case BLOODPOOL: - case PUKE: - case FOOTPRINTS: - case FOOTPRINTS2: - case FOOTPRINTS3: - case FOOTPRINTS4: - case BULLETHOLE: - case BLOODSPLAT1: - case BLOODSPLAT2: - case BLOODSPLAT3: - case BLOODSPLAT4: - sprj->xrepeat = sprj->yrepeat = 0; - continue; - case LASERLINE: - continue; - } - case 6: - if (sprj->picnum == TRIPBOMB) break; - case 1: - case 0: - if ( - sprj->picnum == BOLT1 || - sprj->picnum == BOLT1 + 1 || - sprj->picnum == BOLT1 + 2 || - sprj->picnum == BOLT1 + 3 || - sprj->picnum == SIDEBOLT1 || - sprj->picnum == SIDEBOLT1 + 1 || - sprj->picnum == SIDEBOLT1 + 2 || - sprj->picnum == SIDEBOLT1 + 3 || - wallswitchcheck(j) - ) - break; - - if (!(sprj->picnum >= CRANE && sprj->picnum <= (CRANE + 3))) - { - if (sprj->z > (hittype[j].floorz - (16 << 8))) - { - hittype[j].bposx = sprj->x; - hittype[j].bposy = sprj->y; - - sprj->x += x >> 2; - sprj->y += l >> 2; - - setsprite(j, sprj->x, sprj->y, sprj->z); - - if (sector[sprj->sectnum].floorstat & 2) - if (sprj->statnum == 2) - makeitfall(j); - } - } - break; - } - } - - for (p = connecthead; p >= 0; p = connectpoint2[p]) - { - if (ps[p].cursectnum == s->sectnum && ps[p].on_ground) - { - if (abs(ps[p].pos.z - ps[p].truefz) < PHEIGHT + (9 << 8)) - { - ps[p].fric.x += x << 3; - ps[p].fric.y += l << 3; - } - } - } - - sc->floorxpanning += sprite[i].yvel >> 7; - + static int16_t list1[] = { BLOODPOOL, PUKE, FOOTPRINTS, FOOTPRINTS2, FOOTPRINTS3, FOOTPRINTS4, BULLETHOLE, BLOODSPLAT1, BLOODSPLAT2, BLOODSPLAT3, BLOODSPLAT4, -1 }; + static int16_t list2[] = { BOLT1, BOLT1 + 1,BOLT1 + 2, BOLT1 + 3, SIDEBOLT1, SIDEBOLT1 + 1, SIDEBOLT1 + 2, SIDEBOLT1 + 3, -1 }; + handle_se24(act, list1, list2, TRIPBOMB, LASERLINE, CRANE, 2); break; } case 35: - handle_se35(i, SMALLSMOKE, EXPLOSION2); + handle_se35(act, SMALLSMOKE, EXPLOSION2); break; case 25: //PISTONS - - if (t[4] == 0) break; - - if (sc->floorz <= sc->ceilingz) - s->shade = 0; - else if (sc->ceilingz <= t[3]) - s->shade = 1; - - if (s->shade) - { - sc->ceilingz += sprite[i].yvel << 4; - if (sc->ceilingz > sc->floorz) - sc->ceilingz = sc->floorz; - } - else - { - sc->ceilingz -= sprite[i].yvel << 4; - if (sc->ceilingz < t[3]) - sc->ceilingz = t[3]; - } - + if (act->temp_data[4] == 0) break; + handle_se25(act, 3, -1, -1); break; case 26: - handle_se26(i); + handle_se26(act); break; case SE_27_DEMO_CAM: - handle_se27(i); + handle_se27(act); break; case 28: - if (t[5] > 0) - { - t[5]--; - break; - } - - if (hittype[i].temp_data[0] == 0) - { - p = findplayer(s, &x); - if (x > 15500) - break; - hittype[i].temp_data[0] = 1; - hittype[i].temp_data[1] = 64 + (krand() & 511); - hittype[i].temp_data[2] = 0; - } - else - { - hittype[i].temp_data[2]++; - if (hittype[i].temp_data[2] > hittype[i].temp_data[1]) - { - hittype[i].temp_data[0] = 0; - ps[screenpeek].visibility = ud.const_visibility; - break; - } - else if (hittype[i].temp_data[2] == (hittype[i].temp_data[1] >> 1)) - S_PlayActorSound(THUNDER, i); - else if (hittype[i].temp_data[2] == (hittype[i].temp_data[1] >> 3)) - S_PlayActorSound(LIGHTNING_SLAP, i); - else if (hittype[i].temp_data[2] == (hittype[i].temp_data[1] >> 2)) - { - StatIterator it(STAT_DEFAULT); - while ((j = it.NextIndex()) >= 0) - { - if (sprite[j].picnum == NATURALLIGHTNING && sprite[j].hitag == s->hitag) - sprite[j].cstat |= 32768; - } - } - else if (hittype[i].temp_data[2] > (hittype[i].temp_data[1] >> 3) && hittype[i].temp_data[2] < (hittype[i].temp_data[1] >> 2)) - { - if (cansee(s->x, s->y, s->z, s->sectnum, ps[screenpeek].posx, ps[screenpeek].posy, ps[screenpeek].posz, ps[screenpeek].cursectnum)) - j = 1; - else j = 0; - - if (rnd(192) && (hittype[i].temp_data[2] & 1)) - { - if (j) - ps[screenpeek].visibility = 0; - } - else if (j) - ps[screenpeek].visibility = ud.const_visibility; - - StatIterator it(STAT_DEFAULT); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == NATURALLIGHTNING && sj->hitag == s->hitag) - { - if (rnd(32) && (hittype[i].temp_data[2] & 1)) - { - sj->cstat &= 32767; - fi.spawn(j, SMALLSMOKE); - - p = findplayer(s, &x); - x = ldist(&sprite[ps[p].i], sj); - if (x < 768) - { - if (S_CheckSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN) < 1) - S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); - S_PlayActorSound(SHORT_CIRCUIT, ps[p].i); - sprite[ps[p].i].extra -= 8 + (krand() & 7); - SetPlayerPal(&ps[p], PalEntry(32, 16, 0, 0)); - } - break; - } - else sj->cstat |= 32768; - } - } - } - } + handle_se28(act); break; + case 29: - s->hitag += 64; - l = mulscale12((int)s->yvel, sintable[s->hitag & 2047]); - sc->floorz = s->z + l; + act->s.hitag += 64; + l = mulscale12((int)act->s.yvel, sintable[act->s.hitag & 2047]); + sc->floorz = act->s.z + l; break; case 31: // True Drop Floor - if (t[0] == 1) - { - // Choose dir - - if (t[3] > 0) - { - t[3]--; - break; - } - - if (t[2] == 1) // Retract - { - if (sprite[i].ang != 1536) - { - if (abs(sc->floorz - s->z) < sprite[i].yvel ) - { - sc->floorz = s->z; - t[2] = 0; - t[0] = 0; - t[3] = s->hitag; - callsound(s->sectnum, i); - } - else - { - l = sgn(s->z - sc->floorz) * sprite[i].yvel ; - sc->floorz += l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += l; - if (sj->zvel == 0 && sj->statnum != 3 && sj->statnum != 4) - { - hittype[j].bposz = sj->z += l; - hittype[j].floorz = sc->floorz; - } - } - } - } - else - { - if (abs(sc->floorz - t[1]) < sprite[i].yvel ) - { - sc->floorz = t[1]; - callsound(s->sectnum, i); - t[2] = 0; - t[0] = 0; - t[3] = s->hitag; - } - else - { - l = sgn(t[1] - sc->floorz) * sprite[i].yvel ; - sc->floorz += l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += l; - if (sj->zvel == 0 && sj->statnum != 3 && sj->statnum != 4) - { - hittype[j].bposz = sj->z += l; - hittype[j].floorz = sc->floorz; - } - } - } - } - break; - } - - if ((s->ang & 2047) == 1536) - { - if (abs(s->z - sc->floorz) < sprite[i].yvel ) - { - callsound(s->sectnum, i); - t[0] = 0; - t[2] = 1; - t[3] = s->hitag; - } - else - { - l = sgn(s->z - sc->floorz) * sprite[i].yvel ; - sc->floorz += l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += l; - if (sj->zvel == 0 && sj->statnum != 3 && sj->statnum != 4) - { - hittype[j].bposz = sj->z += l; - hittype[j].floorz = sc->floorz; - } - } - } - } - else - { - if (abs(sc->floorz - t[1]) < sprite[i].yvel ) - { - t[0] = 0; - callsound(s->sectnum, i); - t[2] = 1; - t[3] = s->hitag; - } - else - { - l = sgn(s->z - t[1]) * sprite[i].yvel ; - sc->floorz -= l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz -= l; - if (sj->zvel == 0 && sj->statnum != 3 && sj->statnum != 4) - { - hittype[j].bposz = sj->z -= l; - hittype[j].floorz = sc->floorz; - } - } - } - } - } + handle_se31(act, true); break; case 32: // True Drop Ceiling - handle_se32(i); + handle_se32(act); break; case 33: if (earthquaketime > 0 && (krand() & 7) == 0) - RANDOMSCRAP(s, i); + RANDOMSCRAP(act); break; case 36: - if (t[0]) + if (act->temp_data[0]) { - if (t[0] == 1) - fi.shoot(i, sc->extra); - else if (t[0] == 26 * 5) - t[0] = 0; - t[0]++; + if (act->temp_data[0] == 1) + fi.shoot(act, sc->extra); + else if (act->temp_data[0] == 26 * 5) + act->temp_data[0] = 0; + act->temp_data[0]++; } break; case 128: //SE to control glass breakage - handle_se128(i); + handle_se128(act); break; case 130: - handle_se130(i, 80, EXPLOSION2); + handle_se130(act, 80, EXPLOSION2); break; case 131: - handle_se130(i, 40, EXPLOSION2); + handle_se130(act, 40, EXPLOSION2); break; } } //Sloped sin-wave floors! it.Reset(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - s = &sprite[i]; - if (s->lotag != 29) continue; - sc = §or[s->sectnum]; + if (act->s.lotag != 29) continue; + auto sc = §or[act->s.sectnum]; if (sc->wallnum != 4) continue; - wal = &wall[sc->wallptr + 2]; - alignflorslope(s->sectnum, wal->x, wal->y, sector[wal->nextsector].floorz); + auto wal = &wall[sc->wallptr + 2]; + alignflorslope(act->s.sectnum, wal->x, wal->y, sector[wal->nextsector].floorz); } } //--------------------------------------------------------------------------- // -// +// // //--------------------------------------------------------------------------- -void move_d(int g_i, int g_p, int g_x) +void move_d(DDukeActor *actor, int playernum, int xvel) { - auto g_sp = &sprite[g_i]; - auto g_t = hittype[g_i].temp_data; + auto spr = &actor->s; + auto t = actor->temp_data; int l; short goalang, angdif; int daxvel; - int a = g_sp->hitag; + int a = spr->hitag; if (a == -1) a = 0; - g_t[0]++; + t[0]++; if (a & face_player) { - if (ps[g_p].newowner >= 0) - goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); - else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); - angdif = getincangle(g_sp->ang, goalang) >> 2; + if (ps[playernum].newOwner != nullptr) + goalang = getangle(ps[playernum].oposx - spr->x, ps[playernum].oposy - spr->y); + else goalang = getangle(ps[playernum].posx - spr->x, ps[playernum].posy - spr->y); + angdif = getincangle(spr->ang, goalang) >> 2; if (angdif > -8 && angdif < 0) angdif = 0; - g_sp->ang += angdif; + spr->ang += angdif; } if (a & spin) - g_sp->ang += sintable[((g_t[0] << 3) & 2047)] >> 6; + spr->ang += sintable[((t[0] << 3) & 2047)] >> 6; if (a & face_player_slow) { - if (ps[g_p].newowner >= 0) - goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); - else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); - angdif = ksgn(getincangle(g_sp->ang, goalang)) << 5; + if (ps[playernum].newOwner != nullptr) + goalang = getangle(ps[playernum].oposx - spr->x, ps[playernum].oposy - spr->y); + else goalang = getangle(ps[playernum].posx - spr->x, ps[playernum].posy - spr->y); + angdif = ksgn(getincangle(spr->ang, goalang)) << 5; if (angdif > -32 && angdif < 0) { angdif = 0; - g_sp->ang = goalang; + spr->ang = goalang; } - g_sp->ang += angdif; + spr->ang += angdif; } if ((a & jumptoplayer) == jumptoplayer) { - if (g_t[0] < 16) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] >> 5); + if (t[0] < 16) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] >> 5); } if (a & face_player_smart) { int newx, newy; - newx = ps[g_p].posx + (ps[g_p].posxv / 768); - newy = ps[g_p].posy + (ps[g_p].posyv / 768); - goalang = getangle(newx - g_sp->x, newy - g_sp->y); - angdif = getincangle(g_sp->ang, goalang) >> 2; + newx = ps[playernum].posx + (ps[playernum].posxv / 768); + newy = ps[playernum].posy + (ps[playernum].posyv / 768); + goalang = getangle(newx - spr->x, newy - spr->y); + angdif = getincangle(spr->ang, goalang) >> 2; if (angdif > -8 && angdif < 0) angdif = 0; - g_sp->ang += angdif; + spr->ang += angdif; } - if (g_t[1] == 0 || a == 0) + if (t[1] == 0 || a == 0) { - if ((badguy(g_sp) && g_sp->extra <= 0) || (hittype[g_i].bposx != g_sp->x) || (hittype[g_i].bposy != g_sp->y)) + if ((badguy(actor) && spr->extra <= 0) || (actor->bposx != spr->x) || (actor->bposy != spr->y)) { - hittype[g_i].bposx = g_sp->x; - hittype[g_i].bposy = g_sp->y; - setsprite(g_i, g_sp->x, g_sp->y, g_sp->z); + actor->bposx = spr->x; + actor->bposy = spr->y; + setsprite(actor, spr->pos); } return; } - auto moveptr = &ScriptCode[g_t[1]]; + auto moveptr = &ScriptCode[t[1]]; - if (a & geth) g_sp->xvel += (*moveptr - g_sp->xvel) >> 1; - if (a & getv) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) >> 1; + if (a & geth) spr->xvel += (*moveptr - spr->xvel) >> 1; + if (a & getv) spr->zvel += ((*(moveptr + 1) << 4) - spr->zvel) >> 1; if (a & dodgebullet) - dodge(g_sp); + dodge(actor); - if (g_sp->picnum != APLAYER) - alterang(a, g_i, g_p); + if (spr->picnum != APLAYER) + alterang(a, actor, playernum); - if (g_sp->xvel > -6 && g_sp->xvel < 6) g_sp->xvel = 0; + if (spr->xvel > -6 && spr->xvel < 6) spr->xvel = 0; - a = badguy(g_sp); + a = badguy(actor); - if (g_sp->xvel || g_sp->zvel) + if (spr->xvel || spr->zvel) { - if (a && g_sp->picnum != ROTATEGUN) + if (a && spr->picnum != ROTATEGUN) { - if ((g_sp->picnum == DRONE || g_sp->picnum == COMMANDER) && g_sp->extra > 0) + if ((spr->picnum == DRONE || spr->picnum == COMMANDER) && spr->extra > 0) { - if (g_sp->picnum == COMMANDER) + if (spr->picnum == COMMANDER) { - hittype[g_i].floorz = l = getflorzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if (g_sp->z > (l - (8 << 8))) + actor->floorz = l = getflorzofslope(spr->sectnum, spr->x, spr->y); + if (spr->z > (l - (8 << 8))) { - if (g_sp->z > (l - (8 << 8))) g_sp->z = l - (8 << 8); - g_sp->zvel = 0; + if (spr->z > (l - (8 << 8))) spr->z = l - (8 << 8); + spr->zvel = 0; } - hittype[g_i].ceilingz = l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if ((g_sp->z - l) < (80 << 8)) + actor->ceilingz = l = getceilzofslope(spr->sectnum, spr->x, spr->y); + if ((spr->z - l) < (80 << 8)) { - g_sp->z = l + (80 << 8); - g_sp->zvel = 0; + spr->z = l + (80 << 8); + spr->zvel = 0; } } else { - if (g_sp->zvel > 0) + if (spr->zvel > 0) { - hittype[g_i].floorz = l = getflorzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if (g_sp->z > (l - (30 << 8))) - g_sp->z = l - (30 << 8); + actor->floorz = l = getflorzofslope(spr->sectnum, spr->x, spr->y); + if (spr->z > (l - (30 << 8))) + spr->z = l - (30 << 8); } else { - hittype[g_i].ceilingz = l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if ((g_sp->z - l) < (50 << 8)) + actor->ceilingz = l = getceilzofslope(spr->sectnum, spr->x, spr->y); + if ((spr->z - l) < (50 << 8)) { - g_sp->z = l + (50 << 8); - g_sp->zvel = 0; + spr->z = l + (50 << 8); + spr->zvel = 0; } } } } - else if (g_sp->picnum != ORGANTIC) + else if (spr->picnum != ORGANTIC) { - if (g_sp->zvel > 0 && hittype[g_i].floorz < g_sp->z) - g_sp->z = hittype[g_i].floorz; - if (g_sp->zvel < 0) + if (spr->zvel > 0 && actor->floorz < spr->z) + spr->z = actor->floorz; + if (spr->zvel < 0) { - l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if ((g_sp->z - l) < (66 << 8)) + l = getceilzofslope(spr->sectnum, spr->x, spr->y); + if ((spr->z - l) < (66 << 8)) { - g_sp->z = l + (66 << 8); - g_sp->zvel >>= 1; + spr->z = l + (66 << 8); + spr->zvel >>= 1; } } } } - else if (g_sp->picnum == APLAYER) - if ((g_sp->z - hittype[g_i].ceilingz) < (32 << 8)) - g_sp->z = hittype[g_i].ceilingz + (32 << 8); + else if (spr->picnum == APLAYER) + if ((spr->z - actor->ceilingz) < (32 << 8)) + spr->z = actor->ceilingz + (32 << 8); - daxvel = g_sp->xvel; - angdif = g_sp->ang; + daxvel = spr->xvel; + angdif = spr->ang; - if (a && g_sp->picnum != ROTATEGUN) + if (a && spr->picnum != ROTATEGUN) { - if (g_x < 960 && g_sp->xrepeat > 16) + if (xvel < 960 && spr->xrepeat > 16) { - daxvel = -(1024 - g_x); - angdif = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + daxvel = -(1024 - xvel); + angdif = getangle(ps[playernum].posx - spr->x, ps[playernum].posy - spr->y); - if (g_x < 512) + if (xvel < 512) { - ps[g_p].posxv = 0; - ps[g_p].posyv = 0; + ps[playernum].posxv = 0; + ps[playernum].posyv = 0; } else { - ps[g_p].posxv = mulscale(ps[g_p].posxv, dukefriction - 0x2000, 16); - ps[g_p].posyv = mulscale(ps[g_p].posyv, dukefriction - 0x2000, 16); + ps[playernum].posxv = mulscale(ps[playernum].posxv, dukefriction - 0x2000, 16); + ps[playernum].posyv = mulscale(ps[playernum].posyv, dukefriction - 0x2000, 16); } } - else if (g_sp->picnum != DRONE && g_sp->picnum != SHARK && g_sp->picnum != COMMANDER) + else if (spr->picnum != DRONE && spr->picnum != SHARK && spr->picnum != COMMANDER) { - if (hittype[g_i].bposz != g_sp->z || (ud.multimode < 2 && ud.player_skill < 2)) + if (actor->bposz != spr->z || (ud.multimode < 2 && ud.player_skill < 2)) { - if ((g_t[0] & 1) || ps[g_p].actorsqu == &hittype[g_i]) return; + if ((t[0] & 1) || ps[playernum].actorsqu == actor) return; else daxvel <<= 1; } else { - if ((g_t[0] & 3) || ps[g_p].actorsqu == &hittype[g_i]) return; + if ((t[0] & 3) || ps[playernum].actorsqu == actor) return; else daxvel <<= 2; } } } - hittype[g_i].movflag = fi.movesprite(g_i, + Collision coll; + actor->movflag = movesprite_ex(actor, (daxvel * (sintable[(angdif + 512) & 2047])) >> 14, - (daxvel * (sintable[angdif & 2047])) >> 14, g_sp->zvel, CLIPMASK0); + (daxvel * (sintable[angdif & 2047])) >> 14, spr->zvel, CLIPMASK0, coll); } if (a) { - if (sector[g_sp->sectnum].ceilingstat & 1) - g_sp->shade += (sector[g_sp->sectnum].ceilingshade - g_sp->shade) >> 1; - else g_sp->shade += (sector[g_sp->sectnum].floorshade - g_sp->shade) >> 1; + if (sector[spr->sectnum].ceilingstat & 1) + spr->shade += (sector[spr->sectnum].ceilingshade - spr->shade) >> 1; + else spr->shade += (sector[spr->sectnum].floorshade - spr->shade) >> 1; - if (sector[g_sp->sectnum].floorpicnum == MIRROR) - deletesprite(g_i); + if (sector[spr->sectnum].floorpicnum == MIRROR) + deletesprite(actor); } } + //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- -static void falladjustz(spritetype* g_sp) +void fall_d(DDukeActor *actor, int g_p) { - switch (g_sp->picnum) - { - case OCTABRAIN: - case COMMANDER: - case DRONE: - break; - default: - g_sp->z += (24 << 8); - break; - } -} - -void fall_d(int g_i, int g_p) -{ - fall_common(g_i, g_p, JIBS6, DRONE, BLOODPOOL, SHOTSPARK1, SQUISHED, THUD, nullptr, falladjustz); + fall_common(actor, g_p, JIBS6, DRONE, BLOODPOOL, SHOTSPARK1, SQUISHED, THUD, nullptr); } bool spawnweapondebris_d(int picnum, int dnum) @@ -4337,9 +4027,9 @@ bool spawnweapondebris_d(int picnum, int dnum) return picnum == BLIMP && dnum == SCRAP1; } -void respawnhitag_d(spritetype* g_sp) +void respawnhitag_d(DDukeActor* actor) { - switch (g_sp->picnum) + switch (actor->s.picnum) { case FEM1: case FEM2: @@ -4354,20 +4044,19 @@ void respawnhitag_d(spritetype* g_sp) case PODFEM1: case NAKED1: case STATUE: - if (g_sp->yvel) fi.operaterespawns(g_sp->yvel); + if (actor->s.yvel) fi.operaterespawns(actor->s.yvel); break; default: - if (g_sp->hitag >= 0) fi.operaterespawns(g_sp->hitag); + if (actor->s.hitag >= 0) fi.operaterespawns(actor->s.hitag); break; } } -void checktimetosleep_d(int g_i) +void checktimetosleep_d(DDukeActor *actor) { - auto g_sp = &sprite[g_i]; - if (g_sp->statnum == 6) + if (actor->s.statnum == STAT_STANDABLE) { - switch (g_sp->picnum) + switch (actor->s.picnum) { case RUBBERCAN: case EXPLODINGBARREL: @@ -4380,10 +4069,10 @@ void checktimetosleep_d(int g_i) case NUKEBARRELLEAKED: case TRIPBOMB: case EGG: - if (hittype[g_i].timetosleep > 1) - hittype[g_i].timetosleep--; - else if (hittype[g_i].timetosleep == 1) - changespritestat(g_i, 2); + if (actor->timetosleep > 1) + actor->timetosleep--; + else if (actor->timetosleep == 1) + changespritestat(actor, STAT_ZOMBIEACTOR); break; } } diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp index 1aef39f80..dc228c485 100644 --- a/source/games/duke/src/actors_lava.cpp +++ b/source/games/duke/src/actors_lava.cpp @@ -29,6 +29,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "global.h" #include "names_r.h" #include "serializer.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -121,24 +122,24 @@ void lava_serialize(FSerializer& arc) ("windertime", windertime); } -void addtorch(int i) +void addtorch(spritetype* s) { if (torchcnt >= 64) I_Error("Too many torch effects"); - torchsector[torchcnt] = sprite[i].sectnum; - torchsectorshade[torchcnt] = sector[sprite[i].sectnum].floorshade; - torchtype[torchcnt] = sprite[i].lotag; + torchsector[torchcnt] = s->sectnum; + torchsectorshade[torchcnt] = sector[s->sectnum].floorshade; + torchtype[torchcnt] = s->lotag; torchcnt++; } -void addlightning(int i) +void addlightning(spritetype* s) { if (lightnincnt >= 64) I_Error("Too many lightnin effects"); - lightninsector[lightnincnt] = sprite[i].sectnum; - lightninsectorshade[lightnincnt] = sector[sprite[i].sectnum].floorshade; + lightninsector[lightnincnt] = s->sectnum; + lightninsectorshade[lightnincnt] = sector[s->sectnum].floorshade; lightnincnt++; } @@ -149,7 +150,7 @@ void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int j) if (jlt != 10 && jlt != 20 && jlt != 30 && jlt != 40) { - Printf(PRINT_HIGH, "Bad direction %d for jail door with tag %d\n", iht); + Printf(PRINT_HIGH, "Bad direction %d for jail door with tag %d\n", jlt, iht); return; // wouldn't work so let's skip it. } @@ -517,12 +518,12 @@ void moveminecart(void) } cx = (max_x + min_x) >> 1; cy = (max_y + min_y) >> 1; - SectIterator it(csect); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(csect); + while (auto a2 = it.Next()) { - auto sj = &sprite[j]; - if (badguy(&sprite[j])) - setsprite(j,cx,cy,sprite[j].z); + auto sj = &a2->s; + if (badguy(sj)) + setsprite(a2, cx, cy, sj->z); } } } @@ -538,14 +539,14 @@ void operatejaildoors(int hitag) jaildooropen[i] = 1; jaildoordrag[i] = jaildoordist[i]; if (!isRRRA() || jaildoorsound[i] != 0) - S_PlayActorSound(jaildoorsound[i], ps[screenpeek].i); + S_PlayActorSound(jaildoorsound[i], ps[screenpeek].GetActor()); } if (jaildooropen[i] == 2) { jaildooropen[i] = 3; jaildoordrag[i] = jaildoordist[i]; if (!isRRRA() || jaildoorsound[i] != 0) - S_PlayActorSound(jaildoorsound[i], ps[screenpeek].i); + S_PlayActorSound(jaildoorsound[i], ps[screenpeek].GetActor()); } } } diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index e5d338628..86ddadfcf 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -38,7 +38,7 @@ BEGIN_DUKE_NS void dojaildoor(); void moveminecart(); -void ballreturn(short spr); +void ballreturn(DDukeActor* spr); short pinsectorresetdown(short sect); short pinsectorresetup(short sect); short checkpins(short sect); @@ -92,18 +92,18 @@ bool floorspace_r(int sectnum) // //--------------------------------------------------------------------------- -void check_fta_sounds_r(int i) +void check_fta_sounds_r(DDukeActor* actor) { - if (sprite[i].extra > 0) switch (sprite[i].picnum) + if (actor->s.extra > 0) switch (actor->s.picnum) { case COOT: // LIZTROOP if (!isRRRA() && (krand() & 3) == 2) - S_PlayActorSound(PRED_RECOG, i); + S_PlayActorSound(PRED_RECOG, actor); break; case BILLYCOCK: case BILLYRAY: case BRAYSNIPER: // PIGCOP - S_PlayActorSound(PIG_RECOG, i); + S_PlayActorSound(PIG_RECOG, actor); break; } } @@ -197,13 +197,13 @@ void addweapon_r(struct player_struct* p, int weapon) case THROWINGDYNAMITE_WEAPON: break; case SHOTGUN_WEAPON: - S_PlayActorSound(SHOTGUN_COCK, p->i); + S_PlayActorSound(SHOTGUN_COCK, p->GetActor()); break; case PISTOL_WEAPON: - S_PlayActorSound(INSERT_CLIP, p->i); + S_PlayActorSound(INSERT_CLIP, p->GetActor()); break; default: - S_PlayActorSound(EJECT_CLIP, p->i); + S_PlayActorSound(EJECT_CLIP, p->GetActor()); break; } } @@ -214,39 +214,38 @@ void addweapon_r(struct player_struct* p, int weapon) // //--------------------------------------------------------------------------- -void hitradius_r(short i, int r, int hp1, int hp2, int hp3, int hp4) +void hitradius_r(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int hp4) { - spritetype* s, * sj; walltype* wal; int d, q, x1, y1; int sectcnt, sectend, dasect, startwall, endwall, nextsect; - short j, p, x, sect; + short p, x, sect; static const uint8_t statlist[] = { STAT_DEFAULT, STAT_ACTOR, STAT_STANDABLE, STAT_PLAYER, STAT_FALLER, STAT_ZOMBIEACTOR, STAT_MISC }; short tempshort[MAXSECTORS]; // originally hijacked a global buffer which is bad. Q: How many do we really need? RedNukem says 64. - s = &sprite[i]; + auto spri = &actor->s; - if (s->xrepeat < 11) + if (spri->xrepeat < 11) { - if (s->picnum == RPG || ((isRRRA()) && s->picnum == RPG2)) goto SKIPWALLCHECK; + if (spri->picnum == RPG || ((isRRRA()) && spri->picnum == RPG2)) goto SKIPWALLCHECK; } - tempshort[0] = s->sectnum; - dasect = s->sectnum; + tempshort[0] = spri->sectnum; + dasect = spri->sectnum; sectcnt = 0; sectend = 1; do { dasect = tempshort[sectcnt++]; - if (((sector[dasect].ceilingz - s->z) >> 8) < r) + if (((sector[dasect].ceilingz - spri->z) >> 8) < r) { - d = abs(wall[sector[dasect].wallptr].x - s->x) + abs(wall[sector[dasect].wallptr].y - s->y); + d = abs(wall[sector[dasect].wallptr].x - spri->x) + abs(wall[sector[dasect].wallptr].y - spri->y); if (d < r) fi.checkhitceiling(dasect); else { // ouch... - d = abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x - s->x) + abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].y - s->y); + d = abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x - spri->x) + abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].y - spri->y); if (d < r) fi.checkhitceiling(dasect); } @@ -255,7 +254,7 @@ void hitradius_r(short i, int r, int hp1, int hp2, int hp3, int hp4) startwall = sector[dasect].wallptr; endwall = startwall + sector[dasect].wallnum; for (x = startwall, wal = &wall[startwall]; x < endwall; x++, wal++) - if ((abs(wal->x - s->x) + abs(wal->y - s->y)) < r) + if ((abs(wal->x - spri->x) + abs(wal->y - spri->y)) < r) { nextsect = wal->nextsector; if (nextsect >= 0) @@ -264,11 +263,11 @@ void hitradius_r(short i, int r, int hp1, int hp2, int hp3, int hp4) if (tempshort[dasect] == nextsect) break; if (dasect < 0) tempshort[sectend++] = nextsect; } - x1 = (((wal->x + wall[wal->point2].x) >> 1) + s->x) >> 1; - y1 = (((wal->y + wall[wal->point2].y) >> 1) + s->y) >> 1; + x1 = (((wal->x + wall[wal->point2].x) >> 1) + spri->x) >> 1; + y1 = (((wal->y + wall[wal->point2].y) >> 1) + spri->y) >> 1; updatesector(x1, y1, §); - if (sect >= 0 && cansee(x1, y1, s->z, sect, s->x, s->y, s->z, s->sectnum)) - fi.checkhitwall(i, x, wal->x, wal->y, s->z, s->picnum); + if (sect >= 0 && cansee(x1, y1, spri->z, sect, spri->x, spri->y, spri->z, spri->sectnum)) + fi.checkhitwall(actor, x, wal->x, wal->y, spri->z, spri->picnum); } } while (sectcnt < sectend); @@ -276,97 +275,97 @@ SKIPWALLCHECK: q = -(24 << 8) + (krand() & ((32 << 8) - 1)); + auto Owner = actor->GetOwner(); for (x = 0; x < 7; x++) { - StatIterator it1(statlist[x]); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(statlist[x]); + while (auto act2 = it1.Next()) { - sj = &sprite[j]; - - if (x == 0 || x >= 5 || AFLAMABLE(sj->picnum)) + auto spri2 = &act2->s; + if (x == 0 || x >= 5 || AFLAMABLE(spri2->picnum)) { - if (sj->cstat & 257) - if (dist(s, sj) < r) + if (spri2->cstat & 257) + if (dist(actor, act2) < r) { - if (badguy(sj) && !cansee(sj->x, sj->y, sj->z + q, sj->sectnum, s->x, s->y, s->z + q, s->sectnum)) + if (badguy(act2) && !cansee(spri2->x, spri2->y, spri2->z + q, spri2->sectnum, spri->x, spri->y, spri->z + q, spri->sectnum)) { continue; } - fi.checkhitsprite(j, i); + fi.checkhitsprite(act2, actor); } } - else if (sj->extra >= 0 && sj != s && (badguy(sj) || sj->picnum == QUEBALL || sj->picnum == RRTILE3440 || sj->picnum == STRIPEBALL || (sj->cstat & 257) || sj->picnum == DUKELYINGDEAD)) + else if (spri2->extra >= 0 && act2 != actor && (badguy(act2) || spri2->picnum == QUEBALL || spri2->picnum == RRTILE3440 || spri2->picnum == STRIPEBALL || (spri2->cstat & 257) || spri2->picnum == DUKELYINGDEAD)) { - if (s->picnum == MORTER && j == s->owner) + if (spri->picnum == MORTER && act2 == Owner) { continue; } - if ((isRRRA()) && s->picnum == CHEERBOMB && j == s->owner) + if ((isRRRA()) && spri->picnum == CHEERBOMB && act2 == Owner) { continue; } - if (sj->picnum == APLAYER) sj->z -= PHEIGHT; - d = dist(s, sj); - if (sj->picnum == APLAYER) sj->z += PHEIGHT; + if (spri2->picnum == APLAYER) spri2->z -= PHEIGHT; + d = dist(actor, act2); + if (spri2->picnum == APLAYER) spri2->z += PHEIGHT; - if (d < r && cansee(sj->x, sj->y, sj->z - (8 << 8), sj->sectnum, s->x, s->y, s->z - (12 << 8), s->sectnum)) + if (d < r && cansee(spri2->x, spri2->y, spri2->z - (8 << 8), spri2->sectnum, spri->x, spri->y, spri->z - (12 << 8), spri->sectnum)) { - if ((isRRRA()) && sprite[j].picnum == MINION && sprite[j].pal == 19) + if ((isRRRA()) && spri2->picnum == MINION && spri2->pal == 19) { continue; } - hittype[j].ang = getangle(sj->x - s->x, sj->y - s->y); + act2->ang = getangle(spri2->x - spri->x, spri2->y - spri->y); - if (s->picnum == RPG && sj->extra > 0) - hittype[j].picnum = RPG; - else if ((isRRRA()) && s->picnum == RPG2 && sj->extra > 0) - hittype[j].picnum = RPG; + if (spri->picnum == RPG && spri2->extra > 0) + act2->picnum = RPG; + else if ((isRRRA()) && spri->picnum == RPG2 && spri2->extra > 0) + act2->picnum = RPG; else - hittype[j].picnum = RADIUSEXPLOSION; + act2->picnum = RADIUSEXPLOSION; if (d < r / 3) { if (hp4 == hp3) hp4++; - hittype[j].extra = hp3 + (krand() % (hp4 - hp3)); + act2->extra = hp3 + (krand() % (hp4 - hp3)); } else if (d < 2 * r / 3) { if (hp3 == hp2) hp3++; - hittype[j].extra = hp2 + (krand() % (hp3 - hp2)); + act2->extra = hp2 + (krand() % (hp3 - hp2)); } else if (d < r) { if (hp2 == hp1) hp2++; - hittype[j].extra = hp1 + (krand() % (hp2 - hp1)); + act2->extra = hp1 + (krand() % (hp2 - hp1)); } - int pic = sprite[j].picnum; + int pic = spri2->picnum; if ((isRRRA())? (pic != HULK && pic != MAMA && pic != BILLYPLAY && pic != COOTPLAY && pic != MAMACLOUD) : (pic != HULK && pic != SBMOVE)) { - if (sprite[j].xvel < 0) sprite[j].xvel = 0; - sprite[j].xvel += (sprite[j].extra << 2); + if (spri2->xvel < 0) spri2->xvel = 0; + spri2->xvel += (spri2->extra << 2); } - if (sj->picnum == STATUEFLASH || sj->picnum == QUEBALL || - sj->picnum == STRIPEBALL || sj->picnum == RRTILE3440) - fi.checkhitsprite(j, i); + if (spri2->picnum == STATUEFLASH || spri2->picnum == QUEBALL || + spri2->picnum == STRIPEBALL || spri2->picnum == RRTILE3440) + fi.checkhitsprite(act2, actor); - if (sprite[j].picnum != RADIUSEXPLOSION && - s->owner >= 0 && sprite[s->owner].statnum < MAXSTATUS) + if (spri2->picnum != RADIUSEXPLOSION && + Owner && Owner->s.statnum < MAXSTATUS) { - if (sprite[j].picnum == APLAYER) + if (spri2->picnum == APLAYER) { - p = sprite[j].yvel; - if (ps[p].newowner >= 0) + p = act2->PlayerIndex(); + if (ps[p].newOwner != nullptr) { clearcamera(&ps[p]); } } - hittype[j].owner = s->owner; + act2->SetHitOwner(actor->GetOwner()); } } } @@ -434,10 +433,10 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un { if (spri->statnum == STAT_PROJECTILE) retval = - clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 8L, (4 << 8), (4 << 8), cliptype, result); else retval = - clipmove(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 128, (4 << 8), (4 << 8), cliptype); + clipmove_ex(&spri->x, &spri->y, &daz, &dasectnum, ((xchange * TICSPERFRAME) << 11), ((ychange * TICSPERFRAME) << 11), 128, (4 << 8), (4 << 8), cliptype, result); } if (dasectnum >= 0) @@ -449,7 +448,7 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un else if (retval == 0) return result.setSector(dasectnum); - return result.setFromEngine(retval); + return retval; } //--------------------------------------------------------------------------- @@ -470,14 +469,15 @@ void lotsoffeathers_r(DDukeActor *actor, short n) // //--------------------------------------------------------------------------- -void guts_r(spritetype* s, short gtype, short n, short p) +void guts_r(DDukeActor* actor, short gtype, short n, short p) { + auto s = &actor->s; int gutz, floorz; int i=0, j; int sx, sy; uint8_t pal; - if (badguy(s) && s->xrepeat < 16) + if (badguy(actor) && s->xrepeat < 16) sx = sy = 8; else sx = sy = 32; @@ -487,7 +487,9 @@ void guts_r(spritetype* s, short gtype, short n, short p) if (gutz > (floorz - (8 << 8))) gutz = floorz - (8 << 8); - if (badguy(s) && s->pal == 6) + gutz += actorinfo[s->picnum].gutsoffset; + + if (badguy(actor) && s->pal == 6) pal = 6; else { @@ -508,9 +510,9 @@ void guts_r(spritetype* s, short gtype, short n, short p) int r4 = krand(); int r5 = krand(); // TRANSITIONAL: owned by a player??? - i = EGS(s->sectnum, s->x + (r5 & 255) - 128, s->y + (r4 & 255) - 128, gutz - (r3 & 8191), gtype, -32, sx >> 1, sy >> 1, a, 48 + (r2 & 31), -512 - (r1 & 2047), ps[p].i, 5); + auto spawned = EGS(s->sectnum, s->x + (r5 & 255) - 128, s->y + (r4 & 255) - 128, gutz - (r3 & 8191), gtype, -32, sx >> 1, sy >> 1, a, 48 + (r2 & 31), -512 - (r1 & 2047), ps[p].GetActor(), 5); if (pal != 0) - sprite[i].pal = pal; + spawned->s.pal = pal; } } @@ -520,63 +522,29 @@ void guts_r(spritetype* s, short gtype, short n, short p) // //--------------------------------------------------------------------------- -void gutsdir_r(spritetype* s, short gtype, short n, short p) -{ - int gutz, floorz; - short i, j; - char sx, sy; - - if (badguy(s) && s->xrepeat < 16) - sx = sy = 8; - else sx = sy = 32; - - gutz = s->z - (8 << 8); - floorz = getflorzofslope(s->sectnum, s->x, s->y); - - if (gutz > (floorz - (8 << 8))) - gutz = floorz - (8 << 8); - - for (j = 0; j < n; j++) - { - int a = krand() & 2047; - int r1 = krand(); - int r2 = krand(); - // TRANSITIONAL: owned by a player??? - i = EGS(s->sectnum, s->x, s->y, gutz, gtype, -32, sx, sy, a, 256 + (r2 & 127), -512 - (r1 & 2047), ps[p].i, 5); - } -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- void movefta_r(void) { int x, px, py, sx, sy; short j, p, psect, ssect; - spritetype* s; - - StatIterator it(STAT_ZOMBIEACTOR); - int i; - while((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ZOMBIEACTOR); + while(auto act = it.Next()) { - s = &sprite[i]; - p = findplayer(s, &x); + auto s = &act->s; + p = findplayer(act, &x); j = 0; ssect = psect = s->sectnum; - if (sprite[ps[p].i].extra > 0) + if (ps[p].GetActor()->s.extra > 0) { if (x < 30000) { - hittype[i].timetosleep++; - if (hittype[i].timetosleep >= (x >> 8)) + act->timetosleep++; + if (act->timetosleep >= (x >> 8)) { - if (badguy(s)) + if (badguy(act)) { px = ps[p].oposx + 64 - (krand() & 127); py = ps[p].oposy + 64 - (krand() & 127); @@ -628,23 +596,23 @@ void movefta_r(void) s->shade = sector[s->sectnum].ceilingshade; else s->shade = sector[s->sectnum].floorshade; - hittype[i].timetosleep = 0; - changespritestat(i, STAT_STANDABLE); + act->timetosleep = 0; + changespritestat(act, STAT_STANDABLE); break; default: #if 0 // TRANSITIONAL: RedNukem has this here. Needed? - if (actorflag(spriteNum, SFLAG_USEACTIVATOR) && sector[sprite[spriteNum].sectnum].lotag & 16384) break; + if (actorflag(act, SFLAG_USEACTIVATOR) && sector[act->s.lotag & 16384) break; #endif - hittype[i].timetosleep = 0; - fi.check_fta_sounds(i); - changespritestat(i, STAT_ACTOR); + act->timetosleep = 0; + check_fta_sounds_r(act); + changespritestat(act, STAT_ACTOR); break; } - else hittype[i].timetosleep = 0; + else act->timetosleep = 0; } } - if (/*!j &&*/ badguy(s)) // this is like RedneckGDX. j is uninitialized here, i.e. most likely not 0. + if (/*!j &&*/ badguy(act)) // this is like RedneckGDX. j is uninitialized here, i.e. most likely not 0. { if (sector[s->sectnum].ceilingstat & 1) s->shade = sector[s->sectnum].ceilingshade; @@ -652,11 +620,11 @@ void movefta_r(void) if (s->picnum != HEN || s->picnum != COW || s->picnum != PIG || s->picnum != DOGRUN || ((isRRRA()) && s->picnum != RABBIT)) { - if (wakeup(i, p)) + if (wakeup(act, p)) { - hittype[i].timetosleep = 0; - fi.check_fta_sounds(i); - changespritestat(i, STAT_ACTOR); + act->timetosleep = 0; + check_fta_sounds_r(act); + changespritestat(act, STAT_ACTOR); } } } @@ -670,16 +638,15 @@ void movefta_r(void) // //--------------------------------------------------------------------------- -int ifhitsectors_r(int sectnum) +DDukeActor* ifhitsectors_r(int sectnum) { - StatIterator it(STAT_MISC); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto a1 = it.Next()) { - if (sprite[i].picnum == EXPLOSION2 || (sprite[i].picnum == EXPLOSION3 && sectnum == sprite[i].sectnum)) - return i; + if (a1->s.picnum == EXPLOSION2 || (a1->s.picnum == EXPLOSION3 && sectnum == a1->s.sectnum)) + return a1; } - return -1; + return nullptr; } //--------------------------------------------------------------------------- @@ -834,55 +801,48 @@ void respawn_rrra(DDukeActor* oldact, DDukeActor* newact) void movefallers_r(void) { - short sect, j; - spritetype* s; - int x; - - StatIterator it(STAT_FALLER); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_FALLER); + while (auto act = it.Next()) { - s = &sprite[i]; + auto s = &act->s; + int sect = s->sectnum; - sect = s->sectnum; - - if (hittype[i].temp_data[0] == 0) + if (act->temp_data[0] == 0) { s->z -= (16 << 8); - hittype[i].temp_data[1] = s->ang; - x = s->extra; - j = fi.ifhitbyweapon(&hittype[i]); - if (j >= 0) + act->temp_data[1] = s->ang; + int x = s->extra; + int j = fi.ifhitbyweapon(act); + if (j >= 0) { if (j == RPG || (isRRRA() && j == RPG2) || j == RADIUSEXPLOSION || j == SEENINE || j == OOZFILTER) { if (s->extra <= 0) { - hittype[i].temp_data[0] = 1; - StatIterator it(STAT_FALLER); - while ((j = it.NextIndex()) >= 0) + act->temp_data[0] = 1; + DukeStatIterator it(STAT_FALLER); + while (auto ac2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->hitag == sprite[i].hitag) + if (ac2->s.hitag == s->hitag) { - hittype[j].temp_data[0] = 1; - sj->cstat &= (65535 - 64); - if (sj->picnum == CEILINGSTEAM || sj->picnum == STEAM) - sj->cstat |= 32768; + ac2->temp_data[0] = 1; + ac2->s.cstat &= (65535 - 64); + if (ac2->s.picnum == CEILINGSTEAM || ac2->s.picnum == STEAM) + ac2->s.cstat |= 32768; } } } } else { - hittype[i].extra = 0; + act->extra = 0; s->extra = x; } } - s->ang = hittype[i].temp_data[1]; + s->ang = act->temp_data[1]; s->z += (16 << 8); } - else if (hittype[i].temp_data[0] == 1) + else if (act->temp_data[0] == 1) { if (s->lotag > 0) { @@ -895,9 +855,10 @@ void movefallers_r(void) if (s->xvel > 0) { s->xvel -= 2; - ssp(i, CLIPMASK0); + ssp(act, CLIPMASK0); } + int x; if (fi.floorspace(s->sectnum)) x = 0; else { @@ -916,9 +877,9 @@ void movefallers_r(void) } if ((sector[sect].floorz - s->z) < (16 << 8)) { - j = 1 + (krand() & 7); - for (x = 0; x < j; x++) RANDOMSCRAP(s, i); - deletesprite(i); + int j = 1 + (krand() & 7); + for (x = 0; x < j; x++) RANDOMSCRAP(act); + deletesprite(act); } } } @@ -937,26 +898,25 @@ void movefallers_r(void) // //--------------------------------------------------------------------------- -static void movecrack(int i) +static void movecrack(DDukeActor* actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; if (s->hitag > 0) { t[0] = s->cstat; t[1] = s->ang; - int j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j == RPG || (isRRRA() && j == RPG2) || j == RADIUSEXPLOSION || j == SEENINE || j == OOZFILTER) { - StatIterator it(STAT_STANDABLE); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto a1 = it.Next()) { - auto sj = &sprite[j]; - if (s->hitag == sj->hitag && (sj->picnum == OOZFILTER || sj->picnum == SEENINE)) - if (sj->shade != -32) - sj->shade = -32; + if (s->hitag == a1->s.hitag && (a1->s.picnum == OOZFILTER || a1->s.picnum == SEENINE)) + if (a1->s.shade != -32) + a1->s.shade = -32; } - detonate(i, EXPLOSION2); + detonate(actor, EXPLOSION2); } else { @@ -973,14 +933,14 @@ static void movecrack(int i) // //--------------------------------------------------------------------------- -static void movebolt(int i) +static void movebolt(DDukeActor* actor) { - auto s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + int* t = &actor->temp_data[0]; int x; int sect = s->sectnum; - auto p = findplayer(s, &x); + auto p = findplayer(actor, &x); if (x > 20480) return; if (t[3] == 0) @@ -1015,7 +975,7 @@ CLEAR_THE_BOLT: if (l & 1) s->cstat ^= 2; if (s->picnum == (BOLT1 + 1) && (krand() & 1) && sector[sect].floorpicnum == HURTRAIL) - S_PlayActorSound(SHORT_CIRCUIT, i); + S_PlayActorSound(SHORT_CIRCUIT, actor); if (s->picnum == BOLT1 + 4) s->picnum = BOLT1; @@ -1039,83 +999,81 @@ CLEAR_THE_BOLT: void movestandables_r(void) { - StatIterator it(STAT_STANDABLE); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto act = it.Next()) { - auto s = &sprite[i]; - int picnum = s->picnum; + int picnum = act->s.picnum; - if (s->sectnum < 0) + if (act->s.sectnum < 0) { - deletesprite(i); + deletesprite(act); continue; } - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = act->s.x; + act->bposy = act->s.y; + act->bposz = act->s.z; if (picnum >= CRANE && picnum <= CRANE +3) { - movecrane(&hittype[i], CRANE); + movecrane(act, CRANE); } else if (picnum >= WATERFOUNTAIN && picnum <= WATERFOUNTAIN + 3) { - movefountain(i, WATERFOUNTAIN); + movefountain(act, WATERFOUNTAIN); } else if (AFLAMABLE(picnum)) { - moveflammable(i, TIRE, BOX, BLOODPOOL); + moveflammable(act, TIRE, BOX, BLOODPOOL); } else if (picnum >= CRACK1 && picnum <= CRACK1 + 3) { - movecrack(i); + movecrack(act); } else if (picnum == OOZFILTER || picnum == SEENINE || picnum == SEENINEDEAD || picnum == (SEENINEDEAD + 1)) { - moveooz(i, SEENINE, SEENINEDEAD, OOZFILTER, EXPLOSION2); + moveooz(act, SEENINE, SEENINEDEAD, OOZFILTER, EXPLOSION2); } else if (picnum == MASTERSWITCH) { - movemasterswitch(i, SEENINE, OOZFILTER); + movemasterswitch(act, SEENINE, OOZFILTER); } else if (picnum == TRASH) { - movetrash(i); + movetrash(act); } else if (picnum >= BOLT1 && picnum <= BOLT1 + 3) { - movebolt(i); + movebolt(act); } else if (picnum == WATERDRIP) { - movewaterdrip(i, WATERDRIP); + movewaterdrip(act, WATERDRIP); } else if (picnum == DOORSHOCK) { - movedoorshock(i); + movedoorshock(act); } else if (picnum == TOUCHPLATE) { - movetouchplate(i, TOUCHPLATE); + movetouchplate(act, TOUCHPLATE); } else if (picnum == CANWITHSOMETHING) { - movecanwithsomething(i); + movecanwithsomething(act); } else if (isIn(picnum, @@ -1133,8 +1091,8 @@ void movestandables_r(void) CEILINGSTEAM)) { int x; - int p = findplayer(s, &x); - execute(i, p, x); + int p = findplayer(act, &x); + execute(act, p, x); } } } @@ -1145,27 +1103,28 @@ void movestandables_r(void) // //--------------------------------------------------------------------------- -static void chickenarrow(int i) +static void chickenarrow(DDukeActor* actor) { - auto s = &sprite[i]; + auto s = &actor->s; s->hitag++; - if (hittype[i].picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) + if (actor->picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) { - int j = fi.spawn(i, SMALLSMOKE); - sprite[j].z += (1 << 8); + auto spawned = spawn(actor, SMALLSMOKE); + spawned->s.z += (1 << 8); if ((krand() & 15) == 2) { - j = fi.spawn(i, 1310); + spawn(actor, MONEY); } } - if (sprite[s->lotag].extra <= 0) - s->lotag = 0; - if (s->lotag != 0 && s->hitag > 5) + auto ts = actor->seek_actor; + if (!ts) return; + + if (ts->s.extra <= 0) + actor->seek_actor = nullptr; + if (actor->seek_actor && s->hitag > 5) { - spritetype* ts; int ang, ang2, ang3; - ts = &sprite[s->lotag]; - ang = getangle(ts->x - s->x, ts->y - s->y); + ang = getangle(ts->s.x - s->x, ts->s.y - s->y); ang2 = ang - s->ang; ang3 = abs(ang2); if (ang2 < 100) @@ -1197,48 +1156,46 @@ static void chickenarrow(int i) // //--------------------------------------------------------------------------- -static bool weaponhitsprite(int i, int j, const vec3_t &oldpos) +static bool weaponhitsprite(DDukeActor *proj, DDukeActor *targ, const vec3_t &oldpos) { - auto s = &sprite[i]; - + auto s = &proj->s; if (isRRRA()) { - if (sprite[j].picnum == MINION + if (targ->s.picnum == MINION && (s->picnum == RPG || s->picnum == RPG2) - && sprite[j].pal == 19) + && targ->s.pal == 19) { - S_PlayActorSound(RPG_EXPLODE, i); - int k = fi.spawn(i, EXPLOSION2); - sprite[k].pos = oldpos; + S_PlayActorSound(RPG_EXPLODE, proj); + spawn(proj, EXPLOSION2)->s.pos = oldpos; return true; } } - else if (s->picnum == FREEZEBLAST && sprite[j].pal == 1) - if (badguy(&sprite[j]) || sprite[j].picnum == APLAYER) + else if (s->picnum == FREEZEBLAST && targ->s.pal == 1) + if (badguy(targ) || targ->s.picnum == APLAYER) { - j = fi.spawn(i, TRANSPORTERSTAR); - sprite[j].pal = 1; - sprite[j].xrepeat = 32; - sprite[j].yrepeat = 32; + auto star = spawn(proj, TRANSPORTERSTAR); + star->s.pal = 1; + star->s.xrepeat = 32; + star->s.yrepeat = 32; - deletesprite(i); + deletesprite(proj); return true; } - fi.checkhitsprite(j, i); + fi.checkhitsprite(targ, proj); - if (sprite[j].picnum == APLAYER) + if (targ->s.picnum == APLAYER) { - int p = sprite[j].yvel; - S_PlayActorSound(PISTOL_BODYHIT, j); + int p = targ->s.yvel; + S_PlayActorSound(PISTOL_BODYHIT, targ); if (s->picnum == SPIT) { - if (isRRRA() && sprite[s->owner].picnum == MAMA) + if (isRRRA() && proj->GetOwner() && proj->GetOwner()->s.picnum == MAMA) { - guts_r(s, RABBITJIBA, 2, myconnectindex); - guts_r(s, RABBITJIBB, 2, myconnectindex); - guts_r(s, RABBITJIBC, 2, myconnectindex); + guts_r(proj, RABBITJIBA, 2, myconnectindex); + guts_r(proj, RABBITJIBB, 2, myconnectindex); + guts_r(proj, RABBITJIBC, 2, myconnectindex); } ps[p].horizon.addadjustment(32); @@ -1246,10 +1203,10 @@ static bool weaponhitsprite(int i, int j, const vec3_t &oldpos) if (ps[p].loogcnt == 0) { - if (!S_CheckActorSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); + if (!S_CheckActorSoundPlaying(ps[p].GetActor(), DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor()); - j = 3 + (krand() & 3); + int j = 3 + (krand() & 3); ps[p].numloogs = j; ps[p].loogcnt = 24 * 4; for (int x = 0; x < j; x++) @@ -1269,36 +1226,34 @@ static bool weaponhitsprite(int i, int j, const vec3_t &oldpos) // //--------------------------------------------------------------------------- -static bool weaponhitwall(int i, int j, const vec3_t& oldpos) +static bool weaponhitwall(DDukeActor *proj, int wal, const vec3_t& oldpos) { - auto act = &hittype[i]; - auto s = &act->s; - - if (isRRRA() && sprite[s->owner].picnum == MAMA) + auto s = &proj->s; + if (isRRRA() && proj->GetOwner() && proj->GetOwner()->s.picnum == MAMA) { - guts_r(s, RABBITJIBA, 2, myconnectindex); - guts_r(s, RABBITJIBB, 2, myconnectindex); - guts_r(s, RABBITJIBC, 2, myconnectindex); + guts_r(proj, RABBITJIBA, 2, myconnectindex); + guts_r(proj, RABBITJIBB, 2, myconnectindex); + guts_r(proj, RABBITJIBC, 2, myconnectindex); } - if (s->picnum != RPG && (!isRRRA() || s->picnum != RPG2) && s->picnum != FREEZEBLAST && s->picnum != SPIT && s->picnum != SHRINKSPARK && (wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR)) + if (s->picnum != RPG && (!isRRRA() || s->picnum != RPG2) && s->picnum != FREEZEBLAST && s->picnum != SPIT && s->picnum != SHRINKSPARK && (wall[wal].overpicnum == MIRROR || wall[wal].picnum == MIRROR)) { int k = getangle( - wall[wall[j].point2].x - wall[j].x, - wall[wall[j].point2].y - wall[j].y); + wall[wall[wal].point2].x - wall[wal].x, + wall[wall[wal].point2].y - wall[wal].y); s->ang = ((k << 1) - s->ang) & 2047; - s->owner = i; - fi.spawn(i, TRANSPORTERSTAR); + proj->SetOwner(proj); + spawn(proj, TRANSPORTERSTAR); return true; } else { - setsprite(i, &oldpos); - fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); + setsprite(proj, oldpos); + fi.checkhitwall(proj, wal, s->x, s->y, s->z, s->picnum); if (!isRRRA() && s->picnum == FREEZEBLAST) { - if (wall[j].overpicnum != MIRROR && wall[j].picnum != MIRROR) + if (wall[wal].overpicnum != MIRROR && wall[wal].picnum != MIRROR) { s->extra >>= 1; if (s->xrepeat > 8) @@ -1309,42 +1264,43 @@ static bool weaponhitwall(int i, int j, const vec3_t& oldpos) } int k = getangle( - wall[wall[j].point2].x - wall[j].x, - wall[wall[j].point2].y - wall[j].y); + wall[wall[wal].point2].x - wall[wal].x, + wall[wall[wal].point2].y - wall[wal].y); s->ang = ((k << 1) - s->ang) & 2047; return true; } if (s->picnum == SHRINKSPARK) { - if (wall[j].picnum >= RRTILE3643 && wall[j].picnum < RRTILE3643 + 3) + if (wall[wal].picnum >= RRTILE3643 && wall[wal].picnum < RRTILE3643 + 3) { - deletesprite(i); + deletesprite(proj); } if (s->extra <= 0) { s->x += sintable[(s->ang + 512) & 2047] >> 7; s->y += sintable[s->ang & 2047] >> 7; - if (!isRRRA() || (sprite[s->owner].picnum != CHEER && sprite[s->owner].picnum != CHEERSTAYPUT)) + auto Owner = proj->GetOwner(); + if (!isRRRA() || !Owner || (Owner->s.picnum != CHEER && Owner->s.picnum != CHEERSTAYPUT)) { - auto j = spawn(act, CIRCLESTUCK); + auto j = spawn(proj, CIRCLESTUCK); j->s.xrepeat = 8; j->s.yrepeat = 8; j->s.cstat = 16; j->s.ang = (j->s.ang + 512) & 2047; j->s.clipdist = mulscale7(s->xrepeat, tilesiz[s->picnum].x); } - deletesprite(i); + deletesprite(proj); return true; } - if (wall[j].overpicnum != MIRROR && wall[j].picnum != MIRROR) + if (wall[wal].overpicnum != MIRROR && wall[wal].picnum != MIRROR) { s->extra -= 20; s->yvel--; } int k = getangle( - wall[wall[j].point2].x - wall[j].x, - wall[wall[j].point2].y - wall[j].y); + wall[wall[wal].point2].x - wall[wal].x, + wall[wall[wal].point2].y - wall[wal].y); s->ang = ((k << 1) - s->ang) & 2047; return true; } @@ -1352,23 +1308,23 @@ static bool weaponhitwall(int i, int j, const vec3_t& oldpos) return false; } + //--------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- -bool weaponhitsector(int i, const vec3_t& oldpos) +bool weaponhitsector(DDukeActor *proj, const vec3_t& oldpos) { - auto s = &sprite[i]; + auto s = &proj->s; + setsprite(proj, oldpos); - setsprite(i, &oldpos); - - if (isRRRA() && sprite[s->owner].picnum == MAMA) + if (isRRRA() && proj->GetOwner() && proj->GetOwner()->s.picnum == MAMA) { - guts_r(s, RABBITJIBA, 2, myconnectindex); - guts_r(s, RABBITJIBB, 2, myconnectindex); - guts_r(s, RABBITJIBC, 2, myconnectindex); + guts_r(proj, RABBITJIBA, 2, myconnectindex); + guts_r(proj, RABBITJIBB, 2, myconnectindex); + guts_r(proj, RABBITJIBC, 2, myconnectindex); } if (s->zvel < 0) @@ -1376,7 +1332,7 @@ bool weaponhitsector(int i, const vec3_t& oldpos) if (sector[s->sectnum].ceilingstat & 1) if (sector[s->sectnum].ceilingpal == 0) { - deletesprite(i); + deletesprite(proj); return true; } @@ -1385,8 +1341,8 @@ bool weaponhitsector(int i, const vec3_t& oldpos) if (!isRRRA() && s->picnum == FREEZEBLAST) { - bounce(i); - ssp(i, CLIPMASK1); + bounce(proj); + ssp(proj, CLIPMASK1); s->extra >>= 1; if (s->xrepeat > 8) s->xrepeat -= 2; @@ -1404,12 +1360,12 @@ bool weaponhitsector(int i, const vec3_t& oldpos) // //--------------------------------------------------------------------------- -static void weaponcommon_r(int i) +static void weaponcommon_r(DDukeActor *proj) { - int j, k, p; - int x, ll; + auto s = &proj->s; + int k, p; + int ll; - auto s = &sprite[i]; p = -1; if (s->picnum == RPG && sector[s->sectnum].lotag == 2) @@ -1430,20 +1386,19 @@ static void weaponcommon_r(int i) auto oldpos = s->pos; - getglobalz(i); + getglobalz(proj); switch (s->picnum) { case RPG: - if (hittype[i].picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) + if (proj->picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) { - j = fi.spawn(i, SMALLSMOKE); - sprite[j].z += (1 << 8); + spawn(proj, SMALLSMOKE)->s.z += (1 << 8); } break; case RPG2: if (!isRRRA()) break; - chickenarrow(i); + chickenarrow(proj); break; case RRTILE1790: @@ -1454,40 +1409,40 @@ static void weaponcommon_r(int i) s->extra--; } else - makeitfall(i); + makeitfall(proj); if (s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) { - j = fi.spawn(i, SMALLSMOKE); - sprite[j].z += (1 << 8); + spawn(proj, SMALLSMOKE)->s.z += (1 << 8); } break; } - j = movesprite_r(i, + Collision coll; + movesprite_ex(proj, (k * (sintable[(s->ang + 512) & 2047])) >> 14, - (k * (sintable[s->ang & 2047])) >> 14, ll, CLIPMASK1); + (k * (sintable[s->ang & 2047])) >> 14, ll, CLIPMASK1, coll); - if ((s->picnum == RPG || (isRRRA() && isIn(s->picnum, RPG2, RRTILE1790))) && s->yvel >= 0) - if (FindDistance2D(s->x - sprite[s->yvel].x, s->y - sprite[s->yvel].y) < 256) - j = 49152 | s->yvel; + if ((s->picnum == RPG || (isRRRA() && isIn(s->picnum, RPG2, RRTILE1790))) && proj->temp_actor != nullptr) + if (FindDistance2D(s->x - proj->temp_actor->s.x, s->y - proj->temp_actor->s.y) < 256) + coll.setSprite(proj->temp_actor); if (s->sectnum < 0) // || (isRR() && sector[s->sectnum].filler == 800)) { - deletesprite(i); + deletesprite(proj); return; } - if ((j & kHitTypeMask) != kHitSprite && s->picnum != FREEZEBLAST) + if (coll.type != kHitSprite && s->picnum != FREEZEBLAST) { - if (s->z < hittype[i].ceilingz) + if (s->z < proj->ceilingz) { - j = kHitSector | (s->sectnum); + coll.setSector(s->sectnum); s->zvel = -1; } else - if (s->z > hittype[i].floorz) + if (s->z > proj->floorz) { - j = kHitSector | (s->sectnum); + coll.setSector(s->sectnum); if (sector[s->sectnum].lotag != 1) s->zvel = 1; } @@ -1497,59 +1452,58 @@ static void weaponcommon_r(int i) { for (k = -3; k < 2; k++) { - x = EGS(s->sectnum, + auto x = EGS(s->sectnum, s->x + ((k * sintable[(s->ang + 512) & 2047]) >> 9), s->y + ((k * sintable[s->ang & 2047]) >> 9), s->z + ((k * ksgn(s->zvel)) * abs(s->zvel / 24)), FIRELASER, -40 + (k << 2), - s->xrepeat, s->yrepeat, 0, 0, 0, s->owner, 5); + s->xrepeat, s->yrepeat, 0, 0, 0, proj->GetOwner(), 5); - sprite[x].cstat = 128; - sprite[x].pal = s->pal; + x->s.cstat = 128; + x->s.pal = s->pal; } } else if (s->picnum == SPIT) if (s->zvel < 6144) s->zvel += gc - 112; - if (j != 0) + if (coll.type != 0) { - if ((j & kHitTypeMask) == kHitSprite) + if (coll.type == kHitSprite) { - j &= kHitIndexMask; - if (weaponhitsprite(i, j, oldpos)) return; + if (weaponhitsprite(proj, coll.actor, oldpos)) return; } - else if ((j & kHitTypeMask) == kHitWall) + else if (coll.type == kHitWall) { - j &= kHitIndexMask; - if (weaponhitwall(i, j, oldpos)) return; + if (weaponhitwall(proj, coll.index, oldpos)) return; } - else if ((j & 49152) == 16384) + else if (coll.type == kHitSector) { - if (weaponhitsector(i, oldpos)) return; + if (weaponhitsector(proj, oldpos)) return; } if (s->picnum != SPIT) { - if (s->picnum == RPG) rpgexplode(i, j, oldpos, EXPLOSION2, -1, -1, RPG_EXPLODE); - else if (isRRRA() && s->picnum == RPG2) rpgexplode(i, j, oldpos, EXPLOSION2, -1, 150, 247); - else if (isRRRA() && s->picnum == RRTILE1790) rpgexplode(i, j, oldpos, EXPLOSION2, -1, 160, RPG_EXPLODE); + if (s->picnum == RPG) rpgexplode(proj, coll.type, oldpos, EXPLOSION2, -1, -1, RPG_EXPLODE); + else if (isRRRA() && s->picnum == RPG2) rpgexplode(proj, coll.type, oldpos, EXPLOSION2, -1, 150, 247); + else if (isRRRA() && s->picnum == RRTILE1790) rpgexplode(proj, coll.type, oldpos, EXPLOSION2, -1, 160, RPG_EXPLODE); else if (s->picnum != FREEZEBLAST && s->picnum != FIRELASER && s->picnum != SHRINKSPARK) { - k = fi.spawn(i, 1441); - sprite[k].xrepeat = sprite[k].yrepeat = s->xrepeat >> 1; - if ((j & kHitTypeMask) == kHitSector) + auto k = spawn(proj, 1441); + k->s.xrepeat = k->s.yrepeat = s->xrepeat >> 1; + if (coll.type == kHitSector) { if (s->zvel < 0) { - sprite[k].cstat |= 8; sprite[k].z += (72 << 8); + k->s.cstat |= 8; + k->s.z += (72 << 8); } } } } - deletesprite(i); + deletesprite(proj); return; } if ((s->picnum == RPG || (isRRRA() && s->picnum == RPG2)) && sector[s->sectnum].lotag == 2 && s->xrepeat >= 10 && rnd(184)) - fi.spawn(i, WATERBUBBLE); + spawn(proj, WATERBUBBLE); } @@ -1561,39 +1515,36 @@ static void weaponcommon_r(int i) void moveweapons_r(void) { - StatIterator it(STAT_PROJECTILE); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_PROJECTILE); + while (auto proj = it.Next()) { - auto s = &sprite[i]; - - if (s->sectnum < 0) + if (proj->s.sectnum < 0) { - deletesprite(i); + deletesprite(proj); continue; } - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + proj->bposx = proj->s.x; + proj->bposy = proj->s.y; + proj->bposz = proj->s.z; - switch (s->picnum) + switch (proj->s.picnum) { case RADIUSEXPLOSION: - deletesprite(i); + deletesprite(proj); continue; case TONGUE: - movetongue(i, TONGUE, INNERJAW); + movetongue(proj, TONGUE, INNERJAW); continue; case FREEZEBLAST: - if (s->yvel < 1 || s->extra < 2 || (s->xvel | s->zvel) == 0) + if (proj->s.yvel < 1 || proj->s.extra < 2 || (proj->s.xvel | proj->s.zvel) == 0) { - int j = fi.spawn(i, TRANSPORTERSTAR); - sprite[j].pal = 1; - sprite[j].xrepeat = 32; - sprite[j].yrepeat = 32; - deletesprite(i); + auto star = spawn(proj, TRANSPORTERSTAR); + star->s.pal = 1; + star->s.xrepeat = 32; + star->s.yrepeat = 32; + deletesprite(proj); continue; } case RPG2: @@ -1606,15 +1557,15 @@ void moveweapons_r(void) case COOLEXPLOSION1: case OWHIP: case UWHIP: - weaponcommon_r(i); + weaponcommon_r(proj); continue; case SHOTSPARK1: { int x; - int p = findplayer(s, &x); - execute(i, p, x); + int p = findplayer(proj, &x); + execute(proj, p, x); continue; } } @@ -1631,44 +1582,39 @@ void movetransports_r(void) { char warpdir, warpspriteto; short k, p, sect, sectlotag; - int i, j, ll2, ll, onfloorz; + int ll2, ll, onfloorz; + Collision coll; //Transporters - StatIterator iti(STAT_TRANSPORT); - while ((i = iti.NextIndex()) >= 0) + DukeStatIterator iti(STAT_TRANSPORT); + while (auto act = iti.Next()) { - auto spri = &sprite[i]; - auto hiti = &hittype[i]; - auto spriowner = spri->owner < 0? nullptr : &sprite[spri->owner]; - - sect = spri->sectnum; + auto spr = &act->s; + sect = spr->sectnum; sectlotag = sector[sect].lotag; - auto& OW = spri->owner; - auto PN = spri->picnum; - if (OW == i) + auto Owner = act->GetOwner(); + if (Owner == act || Owner == nullptr) { continue; } - onfloorz = hiti->temp_data[4]; + onfloorz = act->temp_data[4]; - if (hiti->temp_data[0] > 0) hiti->temp_data[0]--; + if (act->temp_data[0] > 0) act->temp_data[0]--; - SectIterator itj(sect); - while ((j = itj.NextIndex()) >= 0) + DukeSectIterator itj(sect); + while (auto act2 = itj.Next()) { - auto sprj = &sprite[j]; - auto hitj = &hittype[j]; - - switch (sprj->statnum) + auto spr2 = &act2->s; + switch (spr2->statnum) { case STAT_PLAYER: // Player - if (sprj->owner != -1) + if (act2->GetOwner()) { - p = sprj->yvel; + p = spr2->yvel; ps[p].on_warping_sector = 1; @@ -1676,54 +1622,54 @@ void movetransports_r(void) { if (ps[p].on_ground && sectlotag == 0 && onfloorz && ps[p].jetpack_on == 0) { - fi.spawn(i, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, i); + spawn(act, TRANSPORTERBEAM); + S_PlayActorSound(TELEPORTER, act); - for (k = connecthead; k >= 0; k = connectpoint2[k])// connectpoinhittype[i].temp_data[1][k]) - if (ps[k].cursectnum == spriowner->sectnum) + for (k = connecthead; k >= 0; k = connectpoint2[k]) + if (ps[k].cursectnum == Owner->s.sectnum) { ps[k].frag_ps = p; - sprite[ps[k].i].extra = 0; + ps[k].GetActor()->s.extra = 0; } - ps[p].angle.ang = buildang(spriowner->ang); + ps[p].angle.ang = buildang(Owner->s.ang); - if (spriowner->owner != OW) + if (Owner->GetOwner() != Owner) { - hiti->temp_data[0] = 13; - hittype[OW].temp_data[0] = 13; + act->temp_data[0] = 13; + Owner->temp_data[0] = 13; ps[p].transporter_hold = 13; } - ps[p].bobposx = ps[p].oposx = ps[p].posx = spriowner->x; - ps[p].bobposy = ps[p].oposy = ps[p].posy = spriowner->y; - ps[p].oposz = ps[p].posz = spriowner->z - (PHEIGHT - (4 << 8)); + ps[p].bobposx = ps[p].oposx = ps[p].posx = Owner->s.x; + ps[p].bobposy = ps[p].oposy = ps[p].posy = Owner->s.y; + ps[p].oposz = ps[p].posz = Owner->s.z - (PHEIGHT - (4 << 8)); - changespritesect(j, spriowner->sectnum); - ps[p].cursectnum = sprj->sectnum; + changespritesect(act2, Owner->s.sectnum); + ps[p].cursectnum = spr2->sectnum; - k = fi.spawn(OW, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, k); + auto beam = spawn(Owner, TRANSPORTERBEAM); + S_PlayActorSound(TELEPORTER, beam); break; } } else break; - if (onfloorz == 0 && abs(spri->z - ps[p].posz) < 6144) + if (onfloorz == 0 && abs(spr->z - ps[p].posz) < 6144) if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && PlayerInput(p, SB_JUMP)) || (ps[p].jetpack_on && PlayerInput(p, SB_CROUCH))) { - ps[p].oposx = ps[p].posx += spriowner->x - spri->x; - ps[p].oposy = ps[p].posy += spriowner->y - spri->y; + ps[p].oposx = ps[p].posx += Owner->s.x - spr->x; + ps[p].oposy = ps[p].posy += Owner->s.y - spr->y; if (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP) || ps[p].jetpack_on < 11)) - ps[p].posz = spriowner->z - 6144; - else ps[p].posz = spriowner->z + 6144; + ps[p].posz = Owner->s.z - 6144; + else ps[p].posz = Owner->s.z + 6144; ps[p].oposz = ps[p].posz; - changespritesect(j, spriowner->sectnum); - ps[p].cursectnum = spriowner->sectnum; + changespritesect(act2, Owner->s.sectnum); + ps[p].cursectnum = Owner->s.sectnum; break; } @@ -1736,15 +1682,15 @@ void movetransports_r(void) { k = 2; ps[p].oposz = ps[p].posz = - sector[spriowner->sectnum].ceilingz + (7 << 8); + sector[Owner->s.sectnum].ceilingz + (7 << 8); } if (onfloorz && sectlotag == 161 && ps[p].posz < (sector[sect].ceilingz + (6 << 8))) { k = 2; - if (sprite[ps[p].i].extra <= 0) break; + if (ps[p].GetActor()->s.extra <= 0) break; ps[p].oposz = ps[p].posz = - sector[spriowner->sectnum].floorz - (49 << 8); + sector[Owner->s.sectnum].floorz - (49 << 8); } } @@ -1757,9 +1703,9 @@ void movetransports_r(void) { FX_StopAllSounds(); } - S_PlayActorSound(DUKE_UNDERWATER, ps[p].i); + S_PlayActorSound(DUKE_UNDERWATER, ps[p].GetActor()); ps[p].oposz = ps[p].posz = - sector[spriowner->sectnum].ceilingz + (7 << 8); + sector[Owner->s.sectnum].ceilingz + (7 << 8); if (ps[p].OnMotorcycle) ps[p].moto_underwater = 1; } @@ -1767,59 +1713,57 @@ void movetransports_r(void) if (onfloorz && sectlotag == ST_2_UNDERWATER && ps[p].posz < (sector[sect].ceilingz + (6 << 8))) { k = 1; - if (sprite[ps[p].i].extra <= 0) break; + if (ps[p].GetActor()->s.extra <= 0) break; if (screenpeek == p) { FX_StopAllSounds(); } - S_PlayActorSound(DUKE_GASP, ps[p].i); + S_PlayActorSound(DUKE_GASP, ps[p].GetActor()); ps[p].oposz = ps[p].posz = - sector[spriowner->sectnum].floorz - (7 << 8); + sector[Owner->s.sectnum].floorz - (7 << 8); } if (k == 1) { - ps[p].oposx = ps[p].posx += spriowner->x - spri->x; - ps[p].oposy = ps[p].posy += spriowner->y - spri->y; + ps[p].oposx = ps[p].posx += Owner->s.x - spr->x; + ps[p].oposy = ps[p].posy += Owner->s.y - spr->y; - if (spriowner->owner != OW) + if (Owner->GetOwner() != Owner) ps[p].transporter_hold = -2; - ps[p].cursectnum = spriowner->sectnum; + ps[p].cursectnum = Owner->s.sectnum; - changespritesect(j, spriowner->sectnum); - - setpal(&ps[p]); + changespritesect(act2, Owner->s.sectnum); if ((krand() & 255) < 32) - fi.spawn(ps[p].i, WATERSPLASH2); + spawn(ps[p].GetActor(), WATERSPLASH2); } else if (isRRRA() && k == 2) { - ps[p].oposx = ps[p].posx += spriowner->x - spri->x; - ps[p].oposy = ps[p].posy += spriowner->y - spri->y; + ps[p].oposx = ps[p].posx += Owner->s.x - spr->x; + ps[p].oposy = ps[p].posy += Owner->s.y - spr->y; - if (spriowner->owner != OW) + if (Owner->GetOwner() != Owner) ps[p].transporter_hold = -2; - ps[p].cursectnum = spriowner->sectnum; + ps[p].cursectnum = Owner->s.sectnum; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); } } break; case STAT_ACTOR: - if (PN == SHARK || - (isRRRA() && (PN == CHEERBOAT || PN == HULKBOAT || PN == MINIONBOAT || PN == UFO1_RRRA)) || - (!isRRRA() && (PN == UFO1_RR || PN == UFO2 || PN == UFO3 || PN == UFO4 || PN == UFO5))) continue; + if (spr->picnum == SHARK || + (isRRRA() && (spr->picnum == CHEERBOAT || spr->picnum == HULKBOAT || spr->picnum == MINIONBOAT || spr->picnum == UFO1_RRRA)) || + (!isRRRA() && (spr->picnum == UFO1_RR || spr->picnum == UFO2 || spr->picnum == UFO3 || spr->picnum == UFO4 || spr->picnum == UFO5))) continue; case STAT_PROJECTILE: case STAT_MISC: case STAT_DUMMYPLAYER: - ll = abs(sprj->zvel); + ll = abs(spr2->zvel); if (isRRRA()) { - if (sprj->zvel >= 0) + if (spr2->zvel >= 0) warpdir = 2; else warpdir = 1; @@ -1827,48 +1771,48 @@ void movetransports_r(void) { warpspriteto = 0; - if (ll && sectlotag == ST_2_UNDERWATER && sprj->z < (sector[sect].ceilingz + ll)) + if (ll && sectlotag == ST_2_UNDERWATER && spr2->z < (sector[sect].ceilingz + ll)) warpspriteto = 1; - if (ll && sectlotag == ST_1_ABOVE_WATER && sprj->z > (sector[sect].floorz - ll)) - if (!isRRRA() || (sprj->picnum != CHEERBOAT && sprj->picnum != HULKBOAT && sprj->picnum != MINIONBOAT)) + if (ll && sectlotag == ST_1_ABOVE_WATER && spr2->z > (sector[sect].floorz - ll)) + if (!isRRRA() || (spr2->picnum != CHEERBOAT && spr2->picnum != HULKBOAT && spr2->picnum != MINIONBOAT)) warpspriteto = 1; if (isRRRA()) { - if (ll && sectlotag == 161 && sprj->z < (sector[sect].ceilingz + ll) && warpdir == 1) + if (ll && sectlotag == 161 && spr2->z < (sector[sect].ceilingz + ll) && warpdir == 1) { warpspriteto = 1; - ll2 = ll - abs(sprj->z - sector[sect].ceilingz); + ll2 = ll - abs(spr2->z - sector[sect].ceilingz); } - else if (sectlotag == 161 && sprj->z < (sector[sect].ceilingz + 1000) && warpdir == 1) + else if (sectlotag == 161 && spr2->z < (sector[sect].ceilingz + 1000) && warpdir == 1) { warpspriteto = 1; ll2 = 1; } - if (ll && sectlotag == 160 && sprj->z > (sector[sect].floorz - ll) && warpdir == 2) + if (ll && sectlotag == 160 && spr2->z > (sector[sect].floorz - ll) && warpdir == 2) { warpspriteto = 1; - ll2 = ll - abs(sector[sect].floorz - sprj->z); + ll2 = ll - abs(sector[sect].floorz - spr2->z); } - else if (sectlotag == 160 && sprj->z > (sector[sect].floorz - 1000) && warpdir == 2) + else if (sectlotag == 160 && spr2->z > (sector[sect].floorz - 1000) && warpdir == 2) { warpspriteto = 1; ll2 = 1; } } - if (sectlotag == 0 && (onfloorz || abs(sprj->z - spri->z) < 4096)) + if (sectlotag == 0 && (onfloorz || abs(spr2->z - spr->z) < 4096)) { - if (spriowner->owner != OW && onfloorz && hiti->temp_data[0] > 0 && sprj->statnum != 5) + if (Owner->GetOwner() != Owner && onfloorz && act->temp_data[0] > 0 && spr2->statnum != 5) { - hiti->temp_data[0]++; + act->temp_data[0]++; continue; } warpspriteto = 1; } - if (warpspriteto) switch (sprj->picnum) + if (warpspriteto) switch (spr2->picnum) { case TRANSPORTERSTAR: case TRANSPORTERBEAM: @@ -1881,24 +1825,24 @@ void movetransports_r(void) case PLAYERONWATER: if (sectlotag == ST_2_UNDERWATER) { - sprj->cstat &= 32767; + spr2->cstat &= 32767; break; } default: - if (sprj->statnum == 5 && !(sectlotag == ST_1_ABOVE_WATER || sectlotag == ST_2_UNDERWATER || (isRRRA() && (sectlotag == 160 || sectlotag == 161)))) + if (spr2->statnum == 5 && !(sectlotag == ST_1_ABOVE_WATER || sectlotag == ST_2_UNDERWATER || (isRRRA() && (sectlotag == 160 || sectlotag == 161)))) break; case WATERBUBBLE: - if (rnd(192) && sprj->picnum == WATERBUBBLE) + if (rnd(192) && spr2->picnum == WATERBUBBLE) break; if (sectlotag > 0) { - k = fi.spawn(j, WATERSPLASH2); - if (sectlotag == 1 && sprj->statnum == 4) + auto k = spawn(act2, WATERSPLASH2); + if (sectlotag == 1 && spr2->statnum == 4) { - sprite[k].xvel = sprj->xvel >> 1; - sprite[k].ang = sprj->ang; + k->s.xvel = spr2->xvel >> 1; + k->s.ang = spr2->ang; ssp(k, CLIPMASK0); } } @@ -1908,100 +1852,100 @@ void movetransports_r(void) case ST_0_NO_EFFECT: if (onfloorz) { - if (checkcursectnums(sect) == -1 && checkcursectnums(spriowner->sectnum) == -1) + if (checkcursectnums(sect) == -1 && checkcursectnums(Owner->s.sectnum) == -1) { - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z -= spri->z - sector[spriowner->sectnum].floorz; - sprj->ang = spriowner->ang; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z -= spr->z - sector[Owner->s.sectnum].floorz; + spr2->ang = Owner->s.ang; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - k = fi.spawn(i, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, k); + auto beam = spawn(act, TRANSPORTERBEAM); + S_PlayActorSound(TELEPORTER, beam); - k = fi.spawn(OW, TRANSPORTERBEAM); - S_PlayActorSound(TELEPORTER, k); + beam = spawn(Owner, TRANSPORTERBEAM); + S_PlayActorSound(TELEPORTER, beam); - if (spriowner->owner != OW) + if (Owner->GetOwner() != Owner) { - hiti->temp_data[0] = 13; - hittype[OW].temp_data[0] = 13; + act->temp_data[0] = 13; + Owner->temp_data[0] = 13; } - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); } } else { - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = spriowner->z + 4096; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = Owner->s.z + 4096; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); } break; case ST_1_ABOVE_WATER: - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = sector[spriowner->sectnum].ceilingz + ll; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = sector[Owner->s.sectnum].ceilingz + ll; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); break; case ST_2_UNDERWATER: - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = sector[spriowner->sectnum].floorz - ll; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = sector[Owner->s.sectnum].floorz - ll; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); break; case 160: if (!isRRRA()) break; - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = sector[spriowner->sectnum].ceilingz + ll2; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = sector[Owner->s.sectnum].ceilingz + ll2; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); - fi.movesprite(j, (sprj->xvel * sintable[(sprj->ang + 512) & 2047]) >> 14, - (sprj->xvel * sintable[sprj->ang & 2047]) >> 14, 0, CLIPMASK1); + movesprite_ex(act2, (spr2->xvel * sintable[(spr2->ang + 512) & 2047]) >> 14, + (spr2->xvel * sintable[spr2->ang & 2047]) >> 14, 0, CLIPMASK1, coll); break; case 161: if (!isRRRA()) break; - sprj->x += (spriowner->x - spri->x); - sprj->y += (spriowner->y - spri->y); - sprj->z = sector[spriowner->sectnum].floorz - ll2; + spr2->x += (Owner->s.x - spr->x); + spr2->y += (Owner->s.y - spr->y); + spr2->z = sector[Owner->s.sectnum].floorz - ll2; - hitj->bposx = sprj->x; - hitj->bposy = sprj->y; - hitj->bposz = sprj->z; + act2->bposx = spr2->x; + act2->bposy = spr2->y; + act2->bposz = spr2->z; - changespritesect(j, spriowner->sectnum); + changespritesect(act2, Owner->s.sectnum); - fi.movesprite(j, (sprj->xvel * sintable[(sprj->ang + 512) & 2047]) >> 14, - (sprj->xvel * sintable[sprj->ang & 2047]) >> 14, 0, CLIPMASK1); + movesprite_ex(act2, (spr2->xvel * sintable[(spr2->ang + 512) & 2047]) >> 14, + (spr2->xvel * sintable[spr2->ang & 2047]) >> 14, 0, CLIPMASK1, coll); break; } @@ -2024,12 +1968,11 @@ void movetransports_r(void) static void rrra_specialstats() { - int i, j; - - StatIterator it(117); - while ((i = it.NextIndex()) >= 0) + Collision coll; + DukeStatIterator it(117); + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->hitag > 2) s->hitag = 0; if ((s->picnum == RRTILE8488 || s->picnum == RRTILE8490) && s->hitag != 2) @@ -2054,17 +1997,17 @@ static void rrra_specialstats() s->extra--; if (s->extra <= -104) { - fi.spawn(i, s->lotag); - deletesprite(i); + spawn(act, s->lotag); + deletesprite(act); } } - j = fi.movesprite(i, 0, 0, s->extra * 2, CLIPMASK0); + movesprite_ex(act, 0, 0, s->extra * 2, CLIPMASK0, coll); } it.Reset(118); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->hitag > 1) s->hitag = 0; if (s->hitag == 0) @@ -2079,7 +2022,7 @@ static void rrra_specialstats() if (s->extra <= -20) s->hitag = 0; } - j = fi.movesprite(i, 0, 0, s->extra, CLIPMASK0); + movesprite_ex(act, 0, 0, s->extra, CLIPMASK0, coll); } if (ps[screenpeek].MamaEnd > 0) @@ -2093,11 +2036,11 @@ static void rrra_specialstats() if (enemysizecheat > 0) { - short ti; - for (ti = 0; ti < MAXSPRITES; ti++) + DukeSpriteIterator it; + while (auto act = it.Next()) { - auto tispr = &sprite[ti]; - switch (tispr->picnum) + auto s = &act->s; + switch (s->picnum) { //case 4049: //case 4050: @@ -2139,15 +2082,15 @@ static void rrra_specialstats() case MAMA: if (enemysizecheat == 3) { - tispr->xrepeat = tispr->xrepeat << 1; - tispr->yrepeat = tispr->yrepeat << 1; - tispr->clipdist = mulscale7(tispr->xrepeat, tilesiz[tispr->picnum].x); + s->xrepeat <<= 1; + s->yrepeat <<= 1; + s->clipdist = mulscale7(s->xrepeat, tilesiz[s->picnum].x); } else if (enemysizecheat == 2) { - tispr->xrepeat = tispr->xrepeat >> 1; - tispr->yrepeat = tispr->yrepeat >> 1; - tispr->clipdist = mulscale7(tispr->xrepeat, tilesiz[tispr->picnum].y); + s->xrepeat >>= 1; + s->yrepeat >>= 1; + s->clipdist = mulscale7(s->xrepeat, tilesiz[s->picnum].y); } break; } @@ -2157,9 +2100,9 @@ static void rrra_specialstats() } it.Reset(121); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; s->extra++; if (s->extra < 100) { @@ -2170,7 +2113,7 @@ static void rrra_specialstats() s->picnum = PIG + 7; s->extra = 1; } - fi.movesprite(i, 0, 0, -300, CLIPMASK0); + movesprite_ex(act, 0, 0, -300, CLIPMASK0, coll); if (sector[s->sectnum].ceilingz + (4 << 8) > s->z) { s->picnum = 0; @@ -2179,51 +2122,51 @@ static void rrra_specialstats() } else if (s->extra == 200) { - setsprite(i, s->x, s->y, sector[s->sectnum].floorz - 10); + setsprite(act, s->x, s->y, sector[s->sectnum].floorz - 10); s->extra = 1; s->picnum = PIG + 11; - fi.spawn(i, TRANSPORTERSTAR); + spawn(act, TRANSPORTERSTAR); } } it.Reset(119); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->hitag > 0) { if (s->extra == 0) { s->hitag--; s->extra = 150; - fi.spawn(i, RABBIT); + spawn(act, RABBIT); } else s->extra--; } } it.Reset(116); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->extra) { if (s->extra == s->lotag) S_PlaySound(183); s->extra--; - j = fi.movesprite(i, + int j = movesprite_ex(act, (s->hitag * sintable[(s->ang + 512) & 2047]) >> 14, (s->hitag * sintable[s->ang & 2047]) >> 14, - s->hitag << 1, CLIPMASK0); + s->hitag << 1, CLIPMASK0, coll); if (j > 0) { - S_PlayActorSound(PIPEBOMB_EXPLODE, i); - deletesprite(i); + S_PlayActorSound(PIPEBOMB_EXPLODE, act); + deletesprite(act); } if (s->extra == 0) { S_PlaySound(215); - deletesprite(i); + deletesprite(act); earthquaketime = 32; SetPlayerPal(&ps[myconnectindex], PalEntry(32, 32, 32, 48)); } @@ -2231,9 +2174,9 @@ static void rrra_specialstats() } it.Reset(115); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->extra) { if (s->picnum != RRTILE8162) @@ -2256,9 +2199,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8162 + 2; - fi.spawn(i, BATTERYAMMO); + spawn(act, BATTERYAMMO); ps[screenpeek].SlotWin |= 1; - S_PlayActorSound(52, i); + S_PlayActorSound(52, act); } } else if (rvar < 120) @@ -2270,9 +2213,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8162 + 6; - fi.spawn(i, HEAVYHBOMB); + spawn(act, HEAVYHBOMB); ps[screenpeek].SlotWin |= 2; - S_PlayActorSound(52, i); + S_PlayActorSound(52, act); } } else if (rvar < 126) @@ -2284,9 +2227,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8162 + 5; - fi.spawn(i, SIXPAK); + spawn(act, SIXPAK); ps[screenpeek].SlotWin |= 4; - S_PlayActorSound(52, i); + S_PlayActorSound(52, act); } } else @@ -2298,9 +2241,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8162 + 4; - fi.spawn(i, ATOMICHEALTH); + spawn(act, ATOMICHEALTH); ps[screenpeek].SlotWin |= 8; - S_PlayActorSound(52, i); + S_PlayActorSound(52, act); } } } @@ -2308,9 +2251,9 @@ static void rrra_specialstats() } it.Reset(122); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->extra) { if (s->picnum != RRTILE8589) @@ -2333,9 +2276,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8589 + 5; - fi.spawn(i, BATTERYAMMO); + spawn(act, BATTERYAMMO); ps[screenpeek].SlotWin |= 1; - S_PlayActorSound(342, i); + S_PlayActorSound(342, act); } } else if (rvar < 120) @@ -2347,9 +2290,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8589 + 6; - fi.spawn(i, HEAVYHBOMB); + spawn(act, HEAVYHBOMB); ps[screenpeek].SlotWin |= 2; - S_PlayActorSound(342, i); + S_PlayActorSound(342, act); } } else if (rvar < 126) @@ -2361,9 +2304,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8589 + 2; - fi.spawn(i, SIXPAK); + spawn(act, SIXPAK); ps[screenpeek].SlotWin |= 4; - S_PlayActorSound(342, i); + S_PlayActorSound(342, act); } } else @@ -2375,9 +2318,9 @@ static void rrra_specialstats() else { s->picnum = RRTILE8589 + 3; - fi.spawn(i, ATOMICHEALTH); + spawn(act, ATOMICHEALTH); ps[screenpeek].SlotWin |= 8; - S_PlayActorSound(342, i); + S_PlayActorSound(342, act); } } } @@ -2385,12 +2328,11 @@ static void rrra_specialstats() } it.Reset(123); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; - if (s->lotag == 5) + if (act->s.lotag == 5) if (!S_CheckSoundPlaying(330)) - S_PlayActorSound(330, i); + S_PlayActorSound(330, act); } } @@ -2402,15 +2344,10 @@ static void rrra_specialstats() void rr_specialstats() { - int x; - int i, j, p, pi; - unsigned short pst; - - StatIterator it(107); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(107); + while (auto act = it.Next()) { - auto s = &sprite[i]; - + auto s = &act->s; if (s->hitag == 100) { s->z += (4 << 8); @@ -2427,13 +2364,12 @@ void rr_specialstats() s->z = sector[s->sectnum].floorz - 15168; s->extra = 0; s->picnum = RRTILE3410; - StatIterator itj(STAT_DEFAULT); - while ((j = itj.NextIndex()) >= 0) + DukeStatIterator it2(STAT_DEFAULT); + while (auto act2 = it2.Next()) { - auto sprj = &sprite[j]; - if (sprj->picnum == 128) - if (sprj->hitag == 999) - sprj->picnum = 127; + if (act2->s.picnum == 128) + if (act2->s.hitag == 999) + act2->s.picnum = 127; } } } @@ -2442,17 +2378,16 @@ void rr_specialstats() if (chickenplant) { it.Reset(106); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; switch (s->picnum) { case RRTILE285: s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3190); - sprite[j].ang = s->ang; + spawn(act, RRTILE3190)->s.ang = s->ang; s->lotag = 128; } break; @@ -2460,8 +2395,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3192); - sprite[j].ang = s->ang; + spawn(act, RRTILE3192)->s.ang = s->ang; s->lotag = 256; } break; @@ -2469,7 +2403,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - lotsoffeathers_r(&hittype[i], (krand() & 3) + 4); + lotsoffeathers_r(act, (krand() & 3) + 4); s->lotag = 84; } break; @@ -2477,7 +2411,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3132); + auto j = spawn(act, RRTILE3132); s->lotag = 96; if (!isRRRA()) S_PlayActorSound(472, j); } @@ -2486,8 +2420,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3120); - sprite[j].ang = s->ang; + spawn(act, RRTILE3120)->s.ang = s->ang; s->lotag = 448; } break; @@ -2495,8 +2428,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3122); - sprite[j].ang = s->ang; + spawn(act, RRTILE3122)->s.ang = s->ang; s->lotag = 64; } break; @@ -2504,8 +2436,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3123); - sprite[j].ang = s->ang; + spawn(act, RRTILE3123)->s.ang = s->ang; s->lotag = 512; } break; @@ -2513,8 +2444,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - j = fi.spawn(i, RRTILE3124); - sprite[j].ang = s->ang; + spawn(act, RRTILE3124)->s.ang = s->ang; s->lotag = 224; } break; @@ -2522,10 +2452,10 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - guts_r(s, JIBS1, 1, myconnectindex); - guts_r(s, JIBS2, 1, myconnectindex); - guts_r(s, JIBS3, 1, myconnectindex); - guts_r(s, JIBS4, 1, myconnectindex); + fi.guts(act, JIBS1, 1, myconnectindex); + fi.guts(act, JIBS2, 1, myconnectindex); + fi.guts(act, JIBS3, 1, myconnectindex); + fi.guts(act, JIBS4, 1, myconnectindex); s->lotag = 256; } break; @@ -2534,13 +2464,13 @@ void rr_specialstats() } it.Reset(STAT_BOWLING); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->picnum == RRTILE280) if (s->lotag == 100) { - pst = pinsectorresetup(s->sectnum); + auto pst = pinsectorresetup(s->sectnum); if (pst) { s->lotag = 0; @@ -2562,29 +2492,29 @@ void rr_specialstats() } it.Reset(108); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - auto s = &sprite[i]; + auto s = &act->s; if (s->picnum == RRTILE296) { - p = findplayer(s, &x); + int x; + int p = findplayer(act, &x); if (x < 2047) { - StatIterator itj(108); - while ((j = itj.NextIndex()) >= 0) + DukeStatIterator it2(108); + while (auto act2 = it2.Next()) { - auto sprj = &sprite[j]; - if (sprj->picnum == RRTILE297) + if (act2->s.picnum == RRTILE297) { - ps[p].angle.ang = buildang(sprj->ang); - ps[p].bobposx = ps[p].oposx = ps[p].posx = sprj->x; - ps[p].bobposy = ps[p].oposy = ps[p].posy = sprj->y; - ps[p].oposz = ps[p].posz = sprj->z - (36 << 8); - pi = ps[p].i; - changespritesect(pi, sprj->sectnum); - ps[p].cursectnum = sprite[pi].sectnum; - S_PlayActorSound(70, j); - deletesprite(j); + ps[p].angle.ang = buildang(act2->s.ang); + ps[p].bobposx = ps[p].oposx = ps[p].posx = act2->s.x; + ps[p].bobposy = ps[p].oposy = ps[p].posy = act2->s.y; + ps[p].oposz = ps[p].posz = act2->s.z - (36 << 8); + auto pact = ps[p].GetActor(); + changespritesect(pact, act2->s.sectnum); + ps[p].cursectnum = pact->s.sectnum; + S_PlayActorSound(70, act2); + deletesprite(act2); } } } @@ -2598,33 +2528,34 @@ void rr_specialstats() // //--------------------------------------------------------------------------- -static void heavyhbomb(int i) +static void heavyhbomb(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + auto t = &actor->temp_data[0]; int sect = s->sectnum; - int x, j, l; + int x, l; + auto Owner = actor->GetOwner(); if ((s->cstat & 32768)) { t[2]--; if (t[2] <= 0) { - S_PlayActorSound(TELEPORTER, i); - fi.spawn(i, TRANSPORTERSTAR); + S_PlayActorSound(TELEPORTER, actor); + spawn(actor, TRANSPORTERSTAR); s->cstat = 257; } return; } - int p = findplayer(s, &x); + int p = findplayer(actor, &x); if (x < 1220) s->cstat &= ~257; else s->cstat |= 257; if (t[3] == 0) { - j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(actor); if (j >= 0) { t[3] = 1; @@ -2635,14 +2566,14 @@ static void heavyhbomb(int i) } } - makeitfall(i); + makeitfall(actor); - if (sector[sect].lotag != 1 && (!isRRRA() || sector[sect].lotag != 160) && s->z >= hittype[i].floorz - (FOURSLEIGHT) && s->yvel < 3) + if (sector[sect].lotag != 1 && (!isRRRA() || sector[sect].lotag != 160) && s->z >= actor->floorz - (FOURSLEIGHT) && s->yvel < 3) { - if (s->yvel > 0 || (s->yvel == 0 && hittype[i].floorz == sector[sect].floorz)) + if (s->yvel > 0 || (s->yvel == 0 && actor->floorz == sector[sect].floorz)) { if (s->picnum != CHEERBOMB) - S_PlayActorSound(PIPEBOMB_BOUNCE, i); + S_PlayActorSound(PIPEBOMB_BOUNCE, actor); else { t[3] = 1; @@ -2656,31 +2587,32 @@ static void heavyhbomb(int i) s->zvel >>= 2; s->yvel++; } - if (s->picnum != CHEERBOMB && s->z < hittype[i].ceilingz + (16 << 8) && sector[sect].lotag != 2) + if (s->picnum != CHEERBOMB && s->z < actor->ceilingz + (16 << 8) && sector[sect].lotag != 2) { - s->z = hittype[i].ceilingz + (16 << 8); + s->z = actor->ceilingz + (16 << 8); s->zvel = 0; } - j = fi.movesprite(i, + Collision coll; + movesprite_ex(actor, (s->xvel * (sintable[(s->ang + 512) & 2047])) >> 14, (s->xvel * (sintable[s->ang & 2047])) >> 14, - s->zvel, CLIPMASK0); + s->zvel, CLIPMASK0, coll); - if (sector[sprite[i].sectnum].lotag == 1 && s->zvel == 0) + if (sector[s->sectnum].lotag == 1 && s->zvel == 0) { s->z += (32 << 8); if (t[5] == 0) { t[5] = 1; - fi.spawn(i, WATERSPLASH2); + spawn(actor, WATERSPLASH2); if (isRRRA() && s->picnum == MORTER) s->xvel = 0; } } else t[5] = 0; - if (t[3] == 0 && s->picnum == MORTER && (j || x < 844)) + if (t[3] == 0 && s->picnum == MORTER && (coll.type || x < 844)) { t[3] = 1; t[4] = 0; @@ -2689,7 +2621,7 @@ static void heavyhbomb(int i) goto DETONATEB; } - if (t[3] == 0 && s->picnum == CHEERBOMB && (j || x < 844)) + if (t[3] == 0 && s->picnum == CHEERBOMB && (coll.type || x < 844)) { t[3] = 1; t[4] = 0; @@ -2698,8 +2630,8 @@ static void heavyhbomb(int i) goto DETONATEB; } - if (sprite[s->owner].picnum == APLAYER) - l = sprite[s->owner].yvel; + if (Owner && Owner->s.picnum == APLAYER) + l = Owner->PlayerIndex(); else l = -1; if (s->xvel > 0) @@ -2713,11 +2645,10 @@ static void heavyhbomb(int i) if (s->xvel & 8) s->cstat ^= 4; } - if ((j & 49152) == 32768) + if (coll.type == kHitWall) { - j &= (MAXWALLS - 1); - - fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); + int j = coll.index; + fi.checkhitwall(actor, j, s->x, s->y, s->z, s->picnum); int k = getangle( wall[wall[j].point2].x - wall[j].x, @@ -2756,13 +2687,13 @@ DETONATEB: if (sector[s->sectnum].lotag != 800) { - fi.hitradius(i, m, x >> 2, x >> 1, x - (x >> 2), x); - fi.spawn(i, EXPLOSION2); + fi.hitradius(actor, m, x >> 2, x >> 1, x - (x >> 2), x); + spawn(actor, EXPLOSION2); if (s->picnum == CHEERBOMB) - fi.spawn(i, BURNING); - S_PlayActorSound(PIPEBOMB_EXPLODE, i); + spawn(actor, BURNING); + S_PlayActorSound(PIPEBOMB_EXPLODE, actor); for (x = 0; x < 8; x++) - RANDOMSCRAP(s, i); + RANDOMSCRAP(actor); } } @@ -2774,13 +2705,13 @@ DETONATEB: if (t[4] > 20) { - deletesprite(i); + deletesprite(actor); return; } if (s->picnum == CHEERBOMB) { - fi.spawn(i, BURNING); - deletesprite(i); + spawn(actor, BURNING); + deletesprite(actor); return; } } @@ -2791,38 +2722,37 @@ DETONATEB: { if (ud.coop >= 1) { - for (j = 0; j < ps[p].weapreccnt; j++) - if (ps[p].weaprecs[j] == i) + for (int j = 0; j < ps[p].weapreccnt; j++) + if (ps[p].weaprecs[j] == s->picnum) return; if (ps[p].weapreccnt < 255) - ps[p].weaprecs[ps[p].weapreccnt++] = i; + ps[p].weaprecs[ps[p].weapreccnt++] = s->picnum; } addammo(DYNAMITE_WEAPON, &ps[p], 1); addammo(CROSSBOW_WEAPON, &ps[p], 1); - S_PlayActorSound(DUKE_GET, ps[p].i); + S_PlayActorSound(DUKE_GET, ps[p].GetActor()); - if (ps[p].gotweapon[DYNAMITE_WEAPON] == 0 || s->owner == ps[p].i) + if (ps[p].gotweapon[DYNAMITE_WEAPON] == 0 || Owner == ps[p].GetActor()) fi.addweapon(&ps[p], DYNAMITE_WEAPON); - if (sprite[s->owner].picnum != APLAYER) + if (!Owner || Owner->s.picnum != APLAYER) { SetPlayerPal(&ps[p], PalEntry(32, 0, 32, 0)); } - if (hittype[s->owner].picnum != HEAVYHBOMB || ud.respawn_items == 0 || sprite[s->owner].picnum == APLAYER) + if (Owner && (Owner->picnum != HEAVYHBOMB || ud.respawn_items == 0 || Owner->s.picnum == APLAYER)) { - if (s->picnum == HEAVYHBOMB && - sprite[s->owner].picnum != APLAYER && ud.coop) + if (s->picnum == HEAVYHBOMB && Owner->s.picnum != APLAYER && ud.coop) return; - deletesprite(i); + deletesprite(actor); return; } else { t[2] = respawnitemtime; - fi.spawn(i, RESPAWNMARKERRED); + spawn(actor, RESPAWNMARKERRED); s->cstat = (short)32768; } } @@ -2836,20 +2766,19 @@ DETONATEB: // //--------------------------------------------------------------------------- -static int henstand(int i) +static int henstand(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + auto t = &actor->temp_data[0]; int sect = s->sectnum; - int j; if (s->picnum == HENSTAND || s->picnum == HENSTAND + 1) { s->lotag--; if (s->lotag == 0) { - fi.spawn(i, HEN); - deletesprite(i); + spawn(actor, HEN); + deletesprite(actor); return 1; } } @@ -2857,32 +2786,33 @@ static int henstand(int i) s->xvel = 0; if (s->xvel) { - makeitfall(i); - j = fi.movesprite(i, + makeitfall(actor); + Collision coll; + movesprite_ex(actor, (sintable[(s->ang + 512) & 2047] * s->xvel) >> 14, (sintable[s->ang & 2047] * s->xvel) >> 14, - s->zvel, CLIPMASK0); - if (j & 49152) + s->zvel, CLIPMASK0, coll); + if (coll.type) { - if ((j & 49152) == 32768) + if (coll.type == kHitWall) { - j &= (MAXWALLS - 1); + int j = coll.index; int k = getangle( wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y); s->ang = ((k << 1) - s->ang) & 2047; } - else if ((j & 49152) == 49152) + else if (coll.type == kHitSprite) { - j &= (MAXSPRITES - 1); - fi.checkhitsprite(i, j); - if (sprite[j].picnum == HEN) + auto hitact = coll.actor; + fi.checkhitsprite(actor, hitact); + if (hitact->s.picnum == HEN) { - int ns = fi.spawn(j, HENSTAND); - deletesprite(j); - sprite[ns].xvel = 32; - sprite[ns].lotag = 40; - sprite[ns].ang = s->ang; + auto ns = spawn(hitact, HENSTAND); + deletesprite(hitact); + ns->s.xvel = 32; + ns->s.lotag = 40; + ns->s.ang = s->ang; } } } @@ -2903,18 +2833,18 @@ static int henstand(int i) if (krand() & 1) s->picnum = HENSTAND + 1; if (!s->xvel) - return 2;//deletesprite(i); still needs to run a script but should not do on a deleted object + return 2;//deletesprite(actor); still needs to run a script but should not do on a deleted object } if (s->picnum == RRTILE3440 || (s->picnum == RRTILE3440 + 1 && !s->xvel)) { - return 2;//deletesprite(i); still needs to run a script but should not do on a deleted object + return 2;//deletesprite(actor); still needs to run a script but should not do on a deleted object } } else if (sector[s->sectnum].lotag == 900) { if (s->picnum == BOWLINGBALL) - ballreturn(i); - deletesprite(i); + ballreturn(actor); + deletesprite(actor); return 1; } return 0; @@ -2929,8 +2859,8 @@ static int henstand(int i) void moveactors_r(void) { int x; - int j, sect, p; - spritetype *s; + int p; + Collision coll; dojaildoor(); moveminecart(); @@ -2941,27 +2871,24 @@ void moveactors_r(void) } rr_specialstats(); - StatIterator it(STAT_ACTOR); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { + auto s = &act->s; bool deleteafterexecute = false; // taking a cue here from RedNukem to not run scripts on deleted sprites. - - s = &sprite[i]; - - sect = s->sectnum; + auto sect = s->sectnum; if( s->xrepeat == 0 || sect < 0 || sect >= MAXSECTORS) { - deletesprite(i); + deletesprite(act); continue; } - auto t = &hittype[i].temp_data[0]; + auto t = &act->temp_data[0]; - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = s->x; + act->bposy = s->y; + act->bposz = s->z; switch(s->picnum) @@ -2969,48 +2896,48 @@ void moveactors_r(void) case RESPAWNMARKERRED: case RESPAWNMARKERYELLOW: case RESPAWNMARKERGREEN: - if (!respawnmarker(i, RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; + if (!respawnmarker(act, RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; break; case RAT: - if (!rat(i, !isRRRA())) continue; + if (!rat(act, !isRRRA())) continue; break; case RRTILE3190: case RRTILE3191: case RRTILE3192: - if (!chickenplant) + if (!chickenplant) { - deletesprite(i); + deletesprite(act); continue; } - if (sector[sprite[i].sectnum].lotag == 903) - makeitfall(i); - j = fi.movesprite(i, + if (sector[sect].lotag == 903) + makeitfall(act); + movesprite_ex(act, (s->xvel*sintable[(s->ang+512)&2047])>>14, (s->xvel*sintable[s->ang&2047])>>14, - s->zvel,CLIPMASK0); - switch (sector[sprite[i].sectnum].lotag) + s->zvel,CLIPMASK0, coll); + switch (sector[sect].lotag) { case 901: - sprite[i].picnum = RRTILE3191; + s->picnum = RRTILE3191; break; case 902: - sprite[i].picnum = RRTILE3192; + s->picnum = RRTILE3192; break; case 903: - if (sprite[i].z >= sector[sprite[i].sectnum].floorz - (8<<8)) + if (s->z >= sector[sect].floorz - (8<<8)) { - deletesprite(i); + deletesprite(act); continue; } break; case 904: - deletesprite(i); + deletesprite(act); continue; break; } - if ((j & 32768) == 32768) + if (coll.type > kHitSector) { - deletesprite(i); + deletesprite(act); continue; } break; @@ -3019,55 +2946,55 @@ void moveactors_r(void) case RRTILE3122: case RRTILE3123: case RRTILE3124: - if (!chickenplant) + if (!chickenplant) { - deletesprite(i); + deletesprite(act); continue; } - makeitfall(i); - j = fi.movesprite(i, + makeitfall(act); + movesprite_ex(act, (s->xvel*(sintable[(s->ang+512)&2047]))>>14, (s->xvel*(sintable[s->ang&2047]))>>14, - s->zvel,CLIPMASK0); - if ((j & 32768) == 32768) + s->zvel,CLIPMASK0, coll); + if (coll.type > kHitSector) { - deletesprite(i); + deletesprite(act); continue; } - if (sector[s->sectnum].lotag == 903) + if (sector[sect].lotag == 903) { - if (sprite[i].z >= sector[sprite[i].sectnum].floorz - (4<<8)) + if (s->z >= sector[sect].floorz - (4<<8)) { - deletesprite(i); + deletesprite(act); continue; } } - else if (sector[s->sectnum].lotag == 904) + else if (sector[sect].lotag == 904) { - deletesprite(i); + deletesprite(act); continue; } break; case RRTILE3132: - if (!chickenplant) + if (!chickenplant) { - deletesprite(i); + deletesprite(act); continue; } - makeitfall(i); - j = fi.movesprite(i, + makeitfall(act); + movesprite_ex(act, (s->xvel*sintable[(s->ang+512)&2047])>>14, (s->xvel*sintable[s->ang&2047])>>14, - s->zvel,CLIPMASK0); - if (s->z >= sector[s->sectnum].floorz - (8<<8)) + s->zvel,CLIPMASK0, coll); + if (s->z >= sector[sect].floorz - (8<<8)) { - if (sector[s->sectnum].lotag == 1) + if (sector[sect].lotag == 1) { - j = fi.spawn(i,WATERSPLASH2); - sprite[j].z = sector[sprite[j].sectnum].floorz; + auto j = spawn(act, WATERSPLASH2); + j->s.z = sector[j->s.sectnum].floorz; } - deletesprite(i); + deletesprite(act); continue; } break; @@ -3075,24 +3002,24 @@ void moveactors_r(void) if (s->xvel) { if(!S_CheckSoundPlaying(356)) - S_PlayActorSound(356,i); + S_PlayActorSound(356,act); } else { - fi.spawn(i,BOWLINGBALLSPRITE); - deletesprite(i); + spawn(act,BOWLINGBALLSPRITE); + deletesprite(act); continue; } if (sector[s->sectnum].lotag == 900) { - S_StopSound(356, -1); + S_StopSound(356, nullptr); } case RRTILE3440: case RRTILE3440+1: case HENSTAND: case HENSTAND+1: { - int todo = henstand(i); + int todo = henstand(act); if (todo == 2) deleteafterexecute = true; if (todo == 1) continue; break; @@ -3100,10 +3027,10 @@ void moveactors_r(void) case QUEBALL: case STRIPEBALL: - if (!queball(i, POCKET, QUEBALL, STRIPEBALL)) continue; + if (!queball(act, POCKET, QUEBALL, STRIPEBALL)) continue; break; case FORCESPHERE: - forcesphere(i, FORCESPHERE); + forcesphere(act, FORCESPHERE); continue; case RECON: @@ -3112,9 +3039,9 @@ void moveactors_r(void) case UFO3: case UFO4: case UFO5: - recon(i, EXPLOSION2, FIRELASER, -1, -1, 457, 8, [](int i) ->int + recon(act, EXPLOSION2, FIRELASER, -1, -1, 457, 8, [](DDukeActor* act) ->int { - auto s = &sprite[i]; + auto s = &act->s; if (isRRRA() && ufospawnsminion) return MINION; else if (s->picnum == UFO1_RR) @@ -3132,33 +3059,33 @@ void moveactors_r(void) continue; case OOZ: - ooz(i); + ooz(act); continue; case EMPTYBIKE: if (!isRRRA()) break; - makeitfall(i); - getglobalz(i); + makeitfall(act); + getglobalz(act); if (sector[sect].lotag == 1) { - setsprite(i,s->x,s->y,hittype[i].floorz+(16<<8)); + setsprite(act,s->x,s->y,act->floorz+(16<<8)); } break; case EMPTYBOAT: if (!isRRRA()) break; - makeitfall(i); - getglobalz(i); + makeitfall(act); + getglobalz(act); break; case TRIPBOMBSPRITE: if (!isRRRA() || (sector[sect].lotag != 1 && sector[sect].lotag != 160)) if (s->xvel) { - j = fi.movesprite(i, + movesprite_ex(act, (s->xvel*sintable[(s->ang+512)&2047])>>14, (s->xvel*sintable[s->ang&2047])>>14, - s->zvel,CLIPMASK0); + s->zvel,CLIPMASK0, coll); s->xvel--; } break; @@ -3167,7 +3094,7 @@ void moveactors_r(void) if (!isRRRA()) break; case MORTER: case HEAVYHBOMB: - heavyhbomb(i); + heavyhbomb(act); continue; case REACTORBURNT: @@ -3176,17 +3103,17 @@ void moveactors_r(void) case REACTOR: case REACTOR2: - reactor(i, REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); + reactor(act, REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); continue; case CAMERA1: - camera(i); + camera(act); continue; } // #ifndef VOLOMEONE - if( ud.multimode < 2 && badguy(s) ) + if( ud.multimode < 2 && badguy(act) ) { if( actor_tog == 1) { @@ -3197,10 +3124,10 @@ void moveactors_r(void) } // #endif - p = findplayer(s,&x); + p = findplayer(act,&x); - execute(i,p,x); - if (deleteafterexecute) deletesprite(i); + execute(act,p,x); + if (deleteafterexecute) deletesprite(act); } } @@ -3215,26 +3142,24 @@ void moveexplosions_r(void) // STATNUM 5 { int sect, p; int x, * t; - spritetype* s; - StatIterator it(STAT_MISC); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto act = it.Next()) { - t = &hittype[i].temp_data[0]; - s = &sprite[i]; + auto s = &act->s; + t = &act->temp_data[0]; sect = s->sectnum; if (sect < 0 || s->xrepeat == 0) { - deletesprite(i); + deletesprite(act); continue; } - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = s->x; + act->bposy = s->y; + act->bposz = s->z; switch (s->picnum) { @@ -3242,7 +3167,7 @@ void moveexplosions_r(void) // STATNUM 5 if (sector[s->sectnum].lotag == 800) if (s->z >= sector[s->sectnum].floorz - (8 << 8)) { - deletesprite(i); + deletesprite(act); continue; } break; @@ -3270,7 +3195,7 @@ void moveexplosions_r(void) // STATNUM 5 case FORCESPHERE: - forcesphere(i); + forcesphereexplode(act); continue; case MUD: @@ -3280,11 +3205,11 @@ void moveexplosions_r(void) // STATNUM 5 { if (sector[sect].floorpicnum != 3073) { - deletesprite(i); + deletesprite(act); continue; } if (S_CheckSoundPlaying(22)) - S_PlayActorSound(22, i); + S_PlayActorSound(22, act); } if (t[0] == 3) { @@ -3292,24 +3217,24 @@ void moveexplosions_r(void) // STATNUM 5 t[1]++; } if (t[1] == 5) - deletesprite(i); + deletesprite(act); continue; case WATERSPLASH2: - watersplash2(i); + watersplash2(act); continue; case FRAMEEFFECT1: - frameeffect1(i); + frameeffect1(act); continue; case INNERJAW: case INNERJAW + 1: - p = findplayer(s, &x); + p = findplayer(act, &x); if (x < 512) { SetPlayerPal(&ps[p], PalEntry(32, 32, 0, 0)); - sprite[ps[p].i].extra -= 4; + ps[p].GetActor()->s.extra -= 4; } case COOLEXPLOSION1: @@ -3320,28 +3245,28 @@ void moveexplosions_r(void) // STATNUM 5 s->extra = 999; else { - deletesprite(i); + deletesprite(act); continue; } break; case TONGUE: - deletesprite(i); + deletesprite(act); continue; - case MONEY + 1: - hittype[i].floorz = s->z = getflorzofslope(s->sectnum, s->x, s->y); + case FEATHER + 1: // feather + act->floorz = s->z = getflorzofslope(s->sectnum, s->x, s->y); if (sector[s->sectnum].lotag == 800) { - deletesprite(i); + deletesprite(act); continue; } break; - case MONEY: - if (!money(i, BLOODPOOL)) continue; + case FEATHER: + if (!money(act, BLOODPOOL)) continue; if (sector[s->sectnum].lotag == 800) if (s->z >= sector[s->sectnum].floorz - (8 << 8)) { - deletesprite(i); + deletesprite(act); continue; } @@ -3389,25 +3314,25 @@ void moveexplosions_r(void) // STATNUM 5 case DUKETORSO: case DUKEGUN: case DUKELEG: - if (!jibs(i, JIBS6, false, true, true, s->picnum == DUKELEG || s->picnum == DUKETORSO || s->picnum == DUKEGUN, + if (!jibs(act, JIBS6, false, true, true, s->picnum == DUKELEG || s->picnum == DUKETORSO || s->picnum == DUKEGUN, isRRRA() && (s->picnum == RRTILE2465 || s->picnum == RRTILE2560))) continue; if (sector[s->sectnum].lotag == 800) if (s->z >= sector[s->sectnum].floorz - (8 << 8)) { - deletesprite(i); + deletesprite(act); continue; } continue; case BLOODPOOL: - if (!bloodpool(i, false, TIRE)) continue; + if (!bloodpool(act, false, TIRE)) continue; if (sector[s->sectnum].lotag == 800) if (s->z >= sector[s->sectnum].floorz - (8 << 8)) { - deletesprite(i); + deletesprite(act); } continue; @@ -3420,26 +3345,26 @@ void moveexplosions_r(void) // STATNUM 5 case FORCERIPPLE: case TRANSPORTERSTAR: case TRANSPORTERBEAM: - p = findplayer(s, &x); - execute(i, p, x); + p = findplayer(act, &x); + execute(act, p, x); continue; case SHELL: case SHOTGUNSHELL: - shell(i, false); + shell(act, false); continue; case GLASSPIECES: case GLASSPIECES + 1: case GLASSPIECES + 2: case POPCORN: - glasspieces(i); + glasspieces(act); continue; } if (s->picnum >= SCRAP6 && s->picnum <= SCRAP5 + 3) { - scrap(i, SCRAP1, SCRAP6); + scrap(act, SCRAP1, SCRAP6); } } } @@ -3450,229 +3375,232 @@ void moveexplosions_r(void) // STATNUM 5 // //--------------------------------------------------------------------------- +void handle_se06_r(DDukeActor *actor) +{ + auto s = &actor->s; + auto t = &actor->temp_data[0]; + + auto sc = §or[s->sectnum]; + int st = s->lotag; + int sh = s->hitag; + + int k = sc->extra; + + if (t[4] > 0) + { + t[4]--; + if (t[4] >= (k - (k >> 3))) + s->xvel -= (k >> 5); + if (t[4] > ((k >> 1) - 1) && t[4] < (k - (k >> 3))) + s->xvel = 0; + if (t[4] < (k >> 1)) + s->xvel += (k >> 5); + if (t[4] < ((k >> 1) - (k >> 3))) + { + t[4] = 0; + s->xvel = k; + if ((!isRRRA() || lastlevel) && hulkspawn) + { + hulkspawn--; + auto ns = spawn(actor, HULK); + ns->s.z = sector[ns->s.sectnum].ceilingz; + ns->s.pal = 33; + if (!hulkspawn) + { + ns = EGS(s->sectnum, s->x, s->y, sector[s->sectnum].ceilingz + 119428, 3677, -8, 16, 16, 0, 0, 0, actor, 5); + ns->s.cstat = 514; + ns->s.pal = 7; + ns->s.xrepeat = 80; + ns->s.yrepeat = 255; + ns = spawn(actor, 296); + ns->s.cstat = 0; + ns->s.cstat |= 32768; + ns->s.z = sector[s->sectnum].floorz - 6144; + deletesprite(actor); + return; + } + } + } + } + else + { + s->xvel = k; + DukeSectIterator it(s->sectnum); + while (auto a2 = it.Next()) + { + if (a2->s.picnum == UFOBEAM && ufospawn && ++ufocnt == 64) + { + int pn; + ufocnt = 0; + ufospawn--; + if (!isRRRA()) + { + switch (krand() & 3) + { + default: + case 0: + pn = UFO1_RR; + break; + case 1: + pn = UFO2; + break; + case 2: + pn = UFO3; + break; + case 3: + pn = UFO4; + break; + } + } + else pn = UFO1_RRRA; + auto ns = spawn(actor, pn); + ns->s.z = sector[ns->s.sectnum].ceilingz; + } + } + } + + DukeStatIterator it(STAT_EFFECTOR); + while (auto act2 = it.Next()) + { + if ((act2->s.lotag == 14) && (sh == act2->s.hitag) && (act2->temp_data[0] == t[0])) + { + act2->s.xvel = s->xvel; + // if( t[4] == 1 ) + { + if (act2->temp_data[5] == 0) + act2->temp_data[5] = dist(act2, actor); + int x = sgn(dist(act2, actor) - act2->temp_data[5]); + if (act2->s.extra) x = -x; + s->xvel += x; + } + act2->temp_data[4] = t[4]; + } + } + handle_se14(actor, false, RPG, JIBS6); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void moveeffectors_r(void) //STATNUM 3 { - int l, x, st, j, * t; - int p, sh, ns, pn; - short k; - spritetype* s; - sectortype* sc; - walltype* wal; + int l; clearfriction(); - - StatIterator it(STAT_EFFECTOR); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act = it.Next()) { - s = &sprite[i]; + auto sc = §or[act->s.sectnum]; + int st = act->s.lotag; + int sh = act->s.hitag; - sc = §or[s->sectnum]; - st = s->lotag; - sh = s->hitag; - - t = &hittype[i].temp_data[0]; + auto t = &act->temp_data[0]; switch (st) { case SE_0_ROTATING_SECTOR: - handle_se00(i, -1); + handle_se00(act, -1); break; case SE_1_PIVOT: //Nothing for now used as the pivot - handle_se01(i); + handle_se01(act); break; case SE_6_SUBWAY: - { - k = sc->extra; - - if (t[4] > 0) - { - t[4]--; - if (t[4] >= (k - (k >> 3))) - s->xvel -= (k >> 5); - if (t[4] > ((k >> 1) - 1) && t[4] < (k - (k >> 3))) - s->xvel = 0; - if (t[4] < (k >> 1)) - s->xvel += (k >> 5); - if (t[4] < ((k >> 1) - (k >> 3))) - { - t[4] = 0; - s->xvel = k; - if ((!isRRRA() || lastlevel) && hulkspawn) - { - hulkspawn--; - ns = fi.spawn(i, HULK); - sprite[ns].z = sector[sprite[ns].sectnum].ceilingz; - sprite[ns].pal = 33; - if (!hulkspawn) - { - ns = EGS(s->sectnum, s->x, s->y, sector[s->sectnum].ceilingz + 119428, 3677, -8, 16, 16, 0, 0, 0, i, 5); - sprite[ns].cstat = 514; - sprite[ns].pal = 7; - sprite[ns].xrepeat = 80; - sprite[ns].yrepeat = 255; - ns = fi.spawn(i, 296); - sprite[ns].cstat = 0; - sprite[ns].cstat |= 32768; - sprite[ns].z = sector[s->sectnum].floorz - 6144; - deletesprite(i); - break; - } - } - } - } - else - { - s->xvel = k; - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - if (sprite[j].picnum == UFOBEAM) - if (ufospawn) - if (++ufocnt == 64) - { - ufocnt = 0; - ufospawn--; - if (!isRRRA()) - { - switch (krand() & 3) - { - default: - case 0: - pn = UFO1_RR; - break; - case 1: - pn = UFO2; - break; - case 2: - pn = UFO3; - break; - case 3: - pn = UFO4; - break; - } - } - else pn = UFO1_RRRA; - ns = fi.spawn(i, pn); - sprite[ns].z = sector[sprite[ns].sectnum].ceilingz; - } - } - } - - StatIterator it(STAT_EFFECTOR); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - auto htj = &hittype[j]; - if ((sj->lotag == 14) && (sh == sj->hitag) && (htj->temp_data[0] == t[0])) - { - sj->xvel = s->xvel; - // if( t[4] == 1 ) - { - if (htj->temp_data[5] == 0) - htj->temp_data[5] = dist(&sprite[j], s); - x = sgn(dist(&sprite[j], s) - htj->temp_data[5]); - if (sj->extra) - x = -x; - s->xvel += x; - } - htj->temp_data[4] = t[4]; - } - } - x = 0; - } + handle_se06_r(act); + break; case SE_14_SUBWAY_CAR: - handle_se14(i, false, RPG, JIBS6); + handle_se14(act, false, RPG, JIBS6); break; case SE_30_TWO_WAY_TRAIN: - handle_se30(i, JIBS6); + handle_se30(act, JIBS6); break; case SE_2_EARTHQUAKE: - handle_se02(i); + handle_se02(act); break; //Flashing sector lights after reactor EXPLOSION2 case SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT: - handle_se03(i); + handle_se03(act); break; case SE_4_RANDOM_LIGHTS: - handle_se04(i); + handle_se04(act); break; //BOSS case SE_5_BOSS: - handle_se05(i, FIRELASER); + handle_se05(act, FIRELASER); break; case SE_8_UP_OPEN_DOOR_LIGHTS: case SE_9_DOWN_OPEN_DOOR_LIGHTS: - handle_se08(i, true); + handle_se08(act, true); break; case SE_10_DOOR_AUTO_CLOSE: - - handle_se10(i, nullptr); + handle_se10(act, nullptr); break; + case SE_11_SWINGING_DOOR: - handle_se11(i); + handle_se11(act); break; case SE_12_LIGHT_SWITCH: - handle_se12(i); + handle_se12(act); break; case SE_47_LIGHT_SWITCH: - if (isRRRA()) handle_se12(i, 1); + if (isRRRA()) handle_se12(act, 1); break; case SE_48_LIGHT_SWITCH: - if (isRRRA()) handle_se12(i, 2); + if (isRRRA()) handle_se12(act, 2); break; case SE_13_EXPLOSIVE: - handle_se13(i); + handle_se13(act); break; case SE_15_SLIDING_DOOR: - handle_se15(i); + handle_se15(act); break; case SE_16_REACTOR: - handle_se16(i, REACTOR, REACTOR2); + handle_se16(act, REACTOR, REACTOR2); break; case SE_17_WARP_ELEVATOR: - handle_se17(i); + handle_se17(act); break; case SE_18_INCREMENTAL_SECTOR_RISE_FALL: - handle_se18(i, true); + handle_se18(act, true); break; case SE_19_EXPLOSION_LOWERS_CEILING: - handle_se19(i, BIGFORCE); + handle_se19(act, BIGFORCE); break; case SE_20_STRETCH_BRIDGE: - handle_se20(i); + handle_se20(act); break; case SE_21_DROP_FLOOR: - handle_se21(i); + handle_se21(act); break; case SE_22_TEETH_DOOR: - handle_se22(i); - + handle_se22(act); break; case 156: @@ -3680,271 +3608,53 @@ void moveeffectors_r(void) //STATNUM 3 case SE_24_CONVEYOR: case 34: { - if (t[4]) break; - - x = (sprite[i].yvel * sintable[(s->ang + 512) & 2047]) >> 18; - l = (sprite[i].yvel * sintable[s->ang & 2047]) >> 18; - - k = 0; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->zvel >= 0) - switch (sj->statnum) - { - case 5: - switch (sj->picnum) - { - case BLOODPOOL: - case FOOTPRINTS: - case FOOTPRINTS2: - case FOOTPRINTS3: - sj->xrepeat = sj->yrepeat = 0; - k = 1; - break; - case BULLETHOLE: - continue; - } - case 6: - case 1: - case 0: - if ( - sj->picnum == BOLT1 || - sj->picnum == BOLT1 + 1 || - sj->picnum == BOLT1 + 2 || - sj->picnum == BOLT1 + 3 || - wallswitchcheck(j) - ) - break; - - if (!(sj->picnum >= CRANE && sj->picnum <= (CRANE + 3))) - { - if (sj->z > (hittype[j].floorz - (16 << 8))) - { - hittype[j].bposx = sj->x; - hittype[j].bposy = sj->y; - - sj->x += x >> 1; - sj->y += l >> 1; - - setsprite(j, sj->x, sj->y, sj->z); - - if (sector[sj->sectnum].floorstat & 2) - if (sj->statnum == 2) - makeitfall(j); - } - } - break; - } - } - - for (p = connecthead; p >= 0; p = connectpoint2[p]) - { - if (ps[p].cursectnum == s->sectnum && ps[p].on_ground) - { - if (abs(ps[p].pos.z - ps[p].truefz) < PHEIGHT + (9 << 8)) - { - ps[p].fric.x += x << 3; - ps[p].fric.y += l << 3; - } - } - } - - sc->floorxpanning += sprite[i].yvel >> 7; - + static int16_t list1[] = { BLOODPOOL, PUKE, FOOTPRINTS, FOOTPRINTS2, FOOTPRINTS3, -1 }; + static int16_t list2[] = { BOLT1, BOLT1 + 1,BOLT1 + 2, BOLT1 + 3, -1 }; + handle_se24(act, list1, list2, BULLETHOLE, -1, CRANE, 1); break; } + case 35: - handle_se35(i, SMALLSMOKE, EXPLOSION2); + handle_se35(act, SMALLSMOKE, EXPLOSION2); break; case 25: //PISTONS - if (t[4] == 0) break; - - if (sc->floorz <= sc->ceilingz) - s->shade = 0; - else if (sc->ceilingz <= t[4]) - s->shade = 1; - - if (s->shade) - { - sc->ceilingz += sprite[i].yvel << 4; - if (sc->ceilingz > sc->floorz) - { - sc->ceilingz = sc->floorz; - if (isRRRA() && pistonsound) - S_PlayActorSound(371, i); - } - } - else - { - sc->ceilingz -= sprite[i].yvel << 4; - if (sc->ceilingz < t[4]) - { - sc->ceilingz = t[4]; - if (isRRRA() && pistonsound) - S_PlayActorSound(167, i); - } - } - + handle_se25(act, 4, isRRRA() ? 371 : -1, isRRRA() ? 167 : -1); break; case 26: - handle_se26(i); + handle_se26(act); break; case SE_27_DEMO_CAM: - handle_se27(i); + handle_se27(act); break; case 29: - s->hitag += 64; - l = mulscale12((int)s->yvel, sintable[s->hitag & 2047]); - sc->floorz = s->z + l; + act->s.hitag += 64; + l = mulscale12((int)act->s.yvel, sintable[act->s.hitag & 2047]); + sc->floorz = act->s.z + l; break; case 31: // True Drop Floor - if (t[0] == 1) - { - if (t[2] == 1) // Retract - { - if (sprite[i].ang != 1536) - { - if (abs(sc->floorz - s->z) < sprite[i].yvel ) - { - sc->floorz = s->z; - t[2] = 0; - t[0] = 0; - callsound(s->sectnum, i); - } - else - { - l = sgn(s->z - sc->floorz) * sprite[i].yvel ; - sc->floorz += l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += l; - if (sj->zvel == 0 && sj->statnum != 3) - { - hittype[j].bposz = sj->z += l; - hittype[j].floorz = sc->floorz; - } - } - } - } - else - { - if (abs(sc->floorz - t[1]) < sprite[i].yvel ) - { - sc->floorz = t[1]; - callsound(s->sectnum, i); - t[2] = 0; - t[0] = 0; - } - else - { - l = sgn(t[1] - sc->floorz) * sprite[i].yvel ; - sc->floorz += l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += l; - if (sj->zvel == 0 && sj->statnum != 3) - { - hittype[j].bposz = sj->z += l; - hittype[j].floorz = sc->floorz; - } - } - } - } - break; - } - - if ((s->ang & 2047) == 1536) - { - if (abs(s->z - sc->floorz) < sprite[i].yvel ) - { - callsound(s->sectnum, i); - t[0] = 0; - t[2] = 1; - } - else - { - l = sgn(s->z - sc->floorz) * sprite[i].yvel ; - sc->floorz += l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz += l; - if (sj->zvel == 0 && sj->statnum != 3) - { - hittype[j].bposz = sj->z += l; - hittype[j].floorz = sc->floorz; - } - } - } - } - else - { - if (abs(sc->floorz - t[1]) < sprite[i].yvel ) - { - t[0] = 0; - callsound(s->sectnum, i); - t[2] = 1; - } - else - { - l = sgn(s->z - t[1]) * sprite[i].yvel ; - sc->floorz -= l; - - SectIterator it(s->sectnum); - while ((j = it.NextIndex()) >= 0) - { - auto sj = &sprite[j]; - if (sj->picnum == APLAYER && sj->owner >= 0) - if (ps[sj->yvel].on_ground == 1) - ps[sj->yvel].posz -= l; - if (sj->zvel == 0 && sj->statnum != 3) - { - hittype[j].bposz = sj->z -= l; - hittype[j].floorz = sc->floorz; - } - } - } - } - } + handle_se31(act, false); break; case 32: // True Drop Ceiling - handle_se32(i); + handle_se32(act); break; case 33: if (earthquaketime > 0 && (krand() & 7) == 0) - RANDOMSCRAP(s, i); + RANDOMSCRAP(act); break; case 36: if (t[0]) { if (t[0] == 1) - fi.shoot(i, sc->extra); + fi.shoot(act, sc->extra); else if (t[0] == 26 * 5) t[0] = 0; t[0]++; @@ -3952,28 +3662,28 @@ void moveeffectors_r(void) //STATNUM 3 break; case 128: //SE to control glass breakage - handle_se128(i); + handle_se128(act); break; case 130: - handle_se130(i, 80, EXPLOSION2); + handle_se130(act, 80, EXPLOSION2); break; case 131: - handle_se130(i, 40, EXPLOSION2); + handle_se130(act, 40, EXPLOSION2); break; } } //Sloped sin-wave floors! it.Reset(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + while (auto act = it.Next()) { - s = &sprite[i]; - if (s->lotag != 29) continue; - sc = §or[s->sectnum]; + auto s = &act->s; + if (act->s.lotag != 29) continue; + auto sc = §or[act->s.sectnum]; if (sc->wallnum != 4) continue; - wal = &wall[sc->wallptr + 2]; - alignflorslope(s->sectnum, wal->x, wal->y, sector[wal->nextsector].floorz); + auto wal = &wall[sc->wallptr + 2]; + alignflorslope(act->s.sectnum, wal->x, wal->y, sector[wal->nextsector].floorz); } } @@ -3984,11 +3694,11 @@ void moveeffectors_r(void) //STATNUM 3 // //--------------------------------------------------------------------------- -int adjustfall(spritetype *s, int c) +int adjustfall(DDukeActor *actor, int c) { - if ((s->picnum == BIKERB || s->picnum == CHEERB) && c == gc) + if ((actor->s.picnum == BIKERB || actor->s.picnum == CHEERB) && c == gc) c = gc>>2; - else if (s->picnum == BIKERBV2 && c == gc) + else if (actor->s.picnum == BIKERBV2 && c == gc) c = gc>>3; return c; } @@ -3999,112 +3709,112 @@ int adjustfall(spritetype *s, int c) // //--------------------------------------------------------------------------- -void move_r(int g_i, int g_p, int g_x) +void move_r(DDukeActor *actor, int pnum, int xvel) { - auto g_sp = &sprite[g_i]; - auto g_t = hittype[g_i].temp_data; + auto spr = &actor->s; + auto t = actor->temp_data; int l; - short a, goalang, angdif; + short goalang, angdif; int daxvel; - a = g_sp->hitag; + int a = spr->hitag; if (a == -1) a = 0; - g_t[0]++; + t[0]++; if (a & face_player) { - if (ps[g_p].newowner >= 0) - goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); - else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); - angdif = getincangle(g_sp->ang, goalang) >> 2; + if (ps[pnum].newOwner != nullptr) + goalang = getangle(ps[pnum].oposx - spr->x, ps[pnum].oposy - spr->y); + else goalang = getangle(ps[pnum].posx - spr->x, ps[pnum].posy - spr->y); + angdif = getincangle(spr->ang, goalang) >> 2; if (angdif > -8 && angdif < 0) angdif = 0; - g_sp->ang += angdif; + spr->ang += angdif; } if (a & spin) - g_sp->ang += sintable[((g_t[0] << 3) & 2047)] >> 6; + spr->ang += sintable[((t[0] << 3) & 2047)] >> 6; if (a & face_player_slow) { - if (ps[g_p].newowner >= 0) - goalang = getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y); - else goalang = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); - angdif = ksgn(getincangle(g_sp->ang, goalang)) << 5; + if (ps[pnum].newOwner != nullptr) + goalang = getangle(ps[pnum].oposx - spr->x, ps[pnum].oposy - spr->y); + else goalang = getangle(ps[pnum].posx - spr->x, ps[pnum].posy - spr->y); + angdif = ksgn(getincangle(spr->ang, goalang)) << 5; if (angdif > -32 && angdif < 0) { angdif = 0; - g_sp->ang = goalang; + spr->ang = goalang; } - g_sp->ang += angdif; + spr->ang += angdif; } if (isRRRA()) { if (a & antifaceplayerslow) { - if (ps[g_p].newowner >= 0) - goalang = (getangle(ps[g_p].oposx - g_sp->x, ps[g_p].oposy - g_sp->y) + 1024) & 2047; - else goalang = (getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y) + 1024) & 2047; - angdif = ksgn(getincangle(g_sp->ang, goalang)) << 5; + if (ps[pnum].newOwner != nullptr) + goalang = (getangle(ps[pnum].oposx - spr->x, ps[pnum].oposy - spr->y) + 1024) & 2047; + else goalang = (getangle(ps[pnum].posx - spr->x, ps[pnum].posy - spr->y) + 1024) & 2047; + angdif = ksgn(getincangle(spr->ang, goalang)) << 5; if (angdif > -32 && angdif < 0) { angdif = 0; - g_sp->ang = goalang; + spr->ang = goalang; } - g_sp->ang += angdif; + spr->ang += angdif; } if ((a & jumptoplayer) == jumptoplayer) { - if (g_sp->picnum == CHEER) + if (spr->picnum == CHEER) { - if (g_t[0] < 16) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 40); + if (t[0] < 16) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] / 40); } else { - if (g_t[0] < 16) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] >> 5); + if (t[0] < 16) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] >> 5); } } if (a & justjump1) { - if (g_sp->picnum == RABBIT) + if (spr->picnum == RABBIT) { - if (g_t[0] < 8) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 30); + if (t[0] < 8) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] / 30); } - else if (g_sp->picnum == MAMA) + else if (spr->picnum == MAMA) { - if (g_t[0] < 8) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 35); + if (t[0] < 8) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] / 35); } } if (a & justjump2) { - if (g_sp->picnum == RABBIT) + if (spr->picnum == RABBIT) { - if (g_t[0] < 8) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 24); + if (t[0] < 8) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] / 24); } - else if (g_sp->picnum == MAMA) + else if (spr->picnum == MAMA) { - if (g_t[0] < 8) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 28); + if (t[0] < 8) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] / 28); } } if (a & windang) { - if (g_t[0] < 8) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] / 24); + if (t[0] < 8) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] / 24); } } else if ((a & jumptoplayer) == jumptoplayer) { - if (g_t[0] < 16) - g_sp->zvel -= (sintable[(512 + (g_t[0] << 4)) & 2047] >> 5); + if (t[0] < 16) + spr->zvel -= (sintable[(512 + (t[0] << 4)) & 2047] >> 5); } @@ -4112,147 +3822,147 @@ void move_r(int g_i, int g_p, int g_x) { int newx, newy; - newx = ps[g_p].posx + (ps[g_p].posxv / 768); - newy = ps[g_p].posy + (ps[g_p].posyv / 768); - goalang = getangle(newx - g_sp->x, newy - g_sp->y); - angdif = getincangle(g_sp->ang, goalang) >> 2; + newx = ps[pnum].posx + (ps[pnum].posxv / 768); + newy = ps[pnum].posy + (ps[pnum].posyv / 768); + goalang = getangle(newx - spr->x, newy - spr->y); + angdif = getincangle(spr->ang, goalang) >> 2; if (angdif > -8 && angdif < 0) angdif = 0; - g_sp->ang += angdif; + spr->ang += angdif; } - if (g_t[1] == 0 || a == 0) + if (t[1] == 0 || a == 0) { - if ((badguy(g_sp) && g_sp->extra <= 0) || (hittype[g_i].bposx != g_sp->x) || (hittype[g_i].bposy != g_sp->y)) + if ((badguy(actor) && spr->extra <= 0) || (actor->bposx != spr->x) || (actor->bposy != spr->y)) { - hittype[g_i].bposx = g_sp->x; - hittype[g_i].bposy = g_sp->y; - setsprite(g_i, g_sp->x, g_sp->y, g_sp->z); + actor->bposx = spr->x; + actor->bposy = spr->y; + setsprite(actor, spr->pos); } - if (badguy(g_sp) && g_sp->extra <= 0) + if (badguy(actor) && spr->extra <= 0) { - if (sector[g_sp->sectnum].ceilingstat & 1) + if (sector[spr->sectnum].ceilingstat & 1) { - if (shadedsector[g_sp->sectnum] == 1) + if (shadedsector[spr->sectnum] == 1) { - g_sp->shade += (16 - g_sp->shade) >> 1; + spr->shade += (16 - spr->shade) >> 1; } else { - g_sp->shade += (sector[g_sp->sectnum].ceilingshade - g_sp->shade) >> 1; + spr->shade += (sector[spr->sectnum].ceilingshade - spr->shade) >> 1; } } else { - g_sp->shade += (sector[g_sp->sectnum].floorshade - g_sp->shade) >> 1; + spr->shade += (sector[spr->sectnum].floorshade - spr->shade) >> 1; } } return; } - auto moveptr = &ScriptCode[g_t[1]]; + auto moveptr = &ScriptCode[t[1]]; - if (a & geth) g_sp->xvel += (*moveptr - g_sp->xvel) >> 1; - if (a & getv) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) >> 1; + if (a & geth) spr->xvel += (*moveptr - spr->xvel) >> 1; + if (a & getv) spr->zvel += ((*(moveptr + 1) << 4) - spr->zvel) >> 1; if (a & dodgebullet) - dodge(g_sp); + dodge(actor); - if (g_sp->picnum != APLAYER) - alterang(a, g_i, g_p); + if (spr->picnum != APLAYER) + alterang(a, actor, pnum); - if (g_sp->xvel > -6 && g_sp->xvel < 6) g_sp->xvel = 0; + if (spr->xvel > -6 && spr->xvel < 6) spr->xvel = 0; - a = badguy(g_sp); + a = badguy(actor); - if (g_sp->xvel || g_sp->zvel) + if (spr->xvel || spr->zvel) { if (a) { - if (g_sp->picnum == DRONE && g_sp->extra > 0) + if (spr->picnum == DRONE && spr->extra > 0) { - if (g_sp->zvel > 0) + if (spr->zvel > 0) { - hittype[g_i].floorz = l = getflorzofslope(g_sp->sectnum, g_sp->x, g_sp->y); + actor->floorz = l = getflorzofslope(spr->sectnum, spr->x, spr->y); if (isRRRA()) { - if (g_sp->z > (l - (28 << 8))) - g_sp->z = l - (28 << 8); + if (spr->z > (l - (28 << 8))) + spr->z = l - (28 << 8); } else { - if (g_sp->z > (l - (30 << 8))) - g_sp->z = l - (30 << 8); + if (spr->z > (l - (30 << 8))) + spr->z = l - (30 << 8); } } else { - hittype[g_i].ceilingz = l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if ((g_sp->z - l) < (50 << 8)) + actor->ceilingz = l = getceilzofslope(spr->sectnum, spr->x, spr->y); + if ((spr->z - l) < (50 << 8)) { - g_sp->z = l + (50 << 8); - g_sp->zvel = 0; + spr->z = l + (50 << 8); + spr->zvel = 0; } } } - if (g_sp->zvel > 0 && hittype[g_i].floorz < g_sp->z) - g_sp->z = hittype[g_i].floorz; - if (g_sp->zvel < 0) + if (spr->zvel > 0 && actor->floorz < spr->z) + spr->z = actor->floorz; + if (spr->zvel < 0) { - l = getceilzofslope(g_sp->sectnum, g_sp->x, g_sp->y); - if ((g_sp->z - l) < (66 << 8)) + l = getceilzofslope(spr->sectnum, spr->x, spr->y); + if ((spr->z - l) < (66 << 8)) { - g_sp->z = l + (66 << 8); - g_sp->zvel >>= 1; + spr->z = l + (66 << 8); + spr->zvel >>= 1; } } } - else if (g_sp->picnum == APLAYER) - if ((g_sp->z - hittype[g_i].ceilingz) < (32 << 8)) - g_sp->z = hittype[g_i].ceilingz + (32 << 8); + else if (spr->picnum == APLAYER) + if ((spr->z - actor->ceilingz) < (32 << 8)) + spr->z = actor->ceilingz + (32 << 8); - daxvel = g_sp->xvel; - angdif = g_sp->ang; + daxvel = spr->xvel; + angdif = spr->ang; if (a) { - if (g_x < 960 && g_sp->xrepeat > 16) + if (xvel < 960 && spr->xrepeat > 16) { - daxvel = -(1024 - g_x); - angdif = getangle(ps[g_p].posx - g_sp->x, ps[g_p].posy - g_sp->y); + daxvel = -(1024 - xvel); + angdif = getangle(ps[pnum].posx - spr->x, ps[pnum].posy - spr->y); - if (g_x < 512) + if (xvel < 512) { - ps[g_p].posxv = 0; - ps[g_p].posyv = 0; + ps[pnum].posxv = 0; + ps[pnum].posyv = 0; } else { - ps[g_p].posxv = mulscale(ps[g_p].posxv, dukefriction - 0x2000, 16); - ps[g_p].posyv = mulscale(ps[g_p].posyv, dukefriction - 0x2000, 16); + ps[pnum].posxv = mulscale(ps[pnum].posxv, dukefriction - 0x2000, 16); + ps[pnum].posyv = mulscale(ps[pnum].posyv, dukefriction - 0x2000, 16); } } - else if ((isRRRA() && g_sp->picnum != DRONE && g_sp->picnum != SHARK && g_sp->picnum != UFO1_RRRA) || - (!isRRRA() && g_sp->picnum != DRONE && g_sp->picnum != SHARK && g_sp->picnum != UFO1_RR - && g_sp->picnum != UFO2 && g_sp->picnum != UFO3 && g_sp->picnum != UFO4 && g_sp->picnum != UFO5)) + else if ((isRRRA() && spr->picnum != DRONE && spr->picnum != SHARK && spr->picnum != UFO1_RRRA) || + (!isRRRA() && spr->picnum != DRONE && spr->picnum != SHARK && spr->picnum != UFO1_RR + && spr->picnum != UFO2 && spr->picnum != UFO3 && spr->picnum != UFO4 && spr->picnum != UFO5)) { - if (hittype[g_i].bposz != g_sp->z || (ud.multimode < 2 && ud.player_skill < 2)) + if (actor->bposz != spr->z || (ud.multimode < 2 && ud.player_skill < 2)) { - if ((g_t[0] & 1) || ps[g_p].actorsqu == &hittype[g_i]) return; + if ((t[0] & 1) || ps[pnum].actorsqu == actor) return; else daxvel <<= 1; } else { - if ((g_t[0] & 3) || ps[g_p].actorsqu == &hittype[g_i]) return; + if ((t[0] & 3) || ps[pnum].actorsqu == actor) return; else daxvel <<= 2; } } } if (isRRRA()) { - if (sector[g_sp->sectnum].lotag != 1) + if (sector[spr->sectnum].lotag != 1) { - switch (g_sp->picnum) + switch (spr->picnum) { case MINIONBOAT: case HULKBOAT: @@ -4261,9 +3971,9 @@ void move_r(int g_i, int g_p, int g_x) break; } } - else if (sector[g_sp->sectnum].lotag == 1) + else if (sector[spr->sectnum].lotag == 1) { - switch (g_sp->picnum) + switch (spr->picnum) { case BIKERB: case BIKERBV2: @@ -4274,32 +3984,33 @@ void move_r(int g_i, int g_p, int g_x) } } - hittype[g_i].movflag = fi.movesprite(g_i, + Collision coll; + actor->movflag = movesprite_ex(actor, (daxvel * (sintable[(angdif + 512) & 2047])) >> 14, - (daxvel * (sintable[angdif & 2047])) >> 14, g_sp->zvel, CLIPMASK0); + (daxvel * (sintable[angdif & 2047])) >> 14, spr->zvel, CLIPMASK0, coll); } if (a) { - if (sector[g_sp->sectnum].ceilingstat & 1) + if (sector[spr->sectnum].ceilingstat & 1) { - if (shadedsector[g_sp->sectnum] == 1) + if (shadedsector[spr->sectnum] == 1) { - g_sp->shade += (16 - g_sp->shade) >> 1; + spr->shade += (16 - spr->shade) >> 1; } else { - g_sp->shade += (sector[g_sp->sectnum].ceilingshade - g_sp->shade) >> 1; + spr->shade += (sector[spr->sectnum].ceilingshade - spr->shade) >> 1; } } - else g_sp->shade += (sector[g_sp->sectnum].floorshade - g_sp->shade) >> 1; + else spr->shade += (sector[spr->sectnum].floorshade - spr->shade) >> 1; - if (sector[g_sp->sectnum].floorpicnum == MIRROR) - deletesprite(g_i); + if (sector[spr->sectnum].floorpicnum == MIRROR) + deletesprite(actor); } } -void fakebubbaspawn(int g_i, int g_p) +void fakebubbaspawn(DDukeActor *actor, int g_p) { fakebubba_spawn++; switch (fakebubba_spawn) @@ -4307,17 +4018,17 @@ void fakebubbaspawn(int g_i, int g_p) default: break; case 1: - fi.spawn(g_i, PIG); + spawn(actor, PIG); break; case 2: - fi.spawn(g_i, MINION); + spawn(actor, MINION); break; case 3: - fi.spawn(g_i, CHEER); + spawn(actor, CHEER); break; case 4: - fi.spawn(g_i, VIXEN); - operateactivators(666, ps[g_p].i); + spawn(actor, VIXEN); + operateactivators(666, g_p); break; } } @@ -4328,71 +4039,71 @@ void fakebubbaspawn(int g_i, int g_p) // //--------------------------------------------------------------------------- -static int fallspecial(int g_i, int g_p) +static int fallspecial(DDukeActor *actor, int playernum) { + auto s = &actor->s; int sphit = 0; - auto g_sp = &sprite[g_i]; if (isRRRA()) { - if (sector[g_sp->sectnum].lotag == 801) + if (sector[s->sectnum].lotag == 801) { - if (g_sp->picnum == ROCK) + if (s->picnum == ROCK) { - fi.spawn(g_i, ROCK2); - fi.spawn(g_i, ROCK2); - addspritetodelete(g_i); + spawn(actor, ROCK2); + spawn(actor, ROCK2); + addspritetodelete(); } return 0; } - else if (sector[g_sp->sectnum].lotag == 802) + else if (sector[s->sectnum].lotag == 802) { - if (g_sp->picnum != APLAYER && badguy(g_sp) && g_sp->z == hittype[g_i].floorz - FOURSLEIGHT) + if (s->picnum != APLAYER && badguy(actor) && s->z == actor->floorz - FOURSLEIGHT) { - fi.guts(g_sp, JIBS6, 5, g_p); - S_PlayActorSound(SQUISHED, g_i); - addspritetodelete(g_i); + fi.guts(actor, JIBS6, 5, playernum); + S_PlayActorSound(SQUISHED, actor); + addspritetodelete(); } return 0; } - else if (sector[g_sp->sectnum].lotag == 803) + else if (sector[s->sectnum].lotag == 803) { - if (g_sp->picnum == ROCK2) - addspritetodelete(g_i); + if (s->picnum == ROCK2) + addspritetodelete(); return 0; } } - if (sector[g_sp->sectnum].lotag == 800) + if (sector[s->sectnum].lotag == 800) { - if (g_sp->picnum == 40) + if (s->picnum == 40) { - addspritetodelete(g_i); + addspritetodelete(); return 0; } - if (g_sp->picnum != APLAYER && (badguy(g_sp) || g_sp->picnum == HEN || g_sp->picnum == COW || g_sp->picnum == PIG || g_sp->picnum == DOGRUN || g_sp->picnum == RABBIT) && (!isRRRA() || hittype[g_i].spriteextra < 128)) + if (s->picnum != APLAYER && (badguy(actor) || s->picnum == HEN || s->picnum == COW || s->picnum == PIG || s->picnum == DOGRUN || s->picnum == RABBIT) && (!isRRRA() || actor->spriteextra < 128)) { - g_sp->z = hittype[g_i].floorz - FOURSLEIGHT; - g_sp->zvel = 8000; - g_sp->extra = 0; - hittype[g_i].spriteextra++; + s->z = actor->floorz - FOURSLEIGHT; + s->zvel = 8000; + s->extra = 0; + actor->spriteextra++; sphit = 1; } - else if (g_sp->picnum != APLAYER) + else if (s->picnum != APLAYER) { - if (!hittype[g_i].spriteextra) - addspritetodelete(g_i); + if (!actor->spriteextra) + addspritetodelete(); return 0; } - hittype[g_i].picnum = SHOTSPARK1; - hittype[g_i].extra = 1; + actor->picnum = SHOTSPARK1; + actor->extra = 1; } - else if (isRRRA() && (sector[g_sp->sectnum].floorpicnum == RRTILE7820 || sector[g_sp->sectnum].floorpicnum == RRTILE7768)) + else if (isRRRA() && (sector[s->sectnum].floorpicnum == RRTILE7820 || sector[s->sectnum].floorpicnum == RRTILE7768)) { - if (g_sp->picnum != MINION && g_sp->pal != 19) + if (s->picnum != MINION && s->pal != 19) { if ((krand() & 3) == 1) { - hittype[g_i].picnum = SHOTSPARK1; - hittype[g_i].extra = 5; + actor->picnum = SHOTSPARK1; + actor->extra = 5; } } } @@ -4405,28 +4116,9 @@ static int fallspecial(int g_i, int g_p) // //--------------------------------------------------------------------------- -static void falladjustz(spritetype* g_sp) +void fall_r(DDukeActor* ac, int g_p) { - if (isRRRA()) switch (g_sp->picnum) - { - case HULKBOAT: - g_sp->z += (12 << 8); - return; - case MINIONBOAT: - g_sp->z += (3 << 8); - return; - case CHEERBOAT: - case EMPTYBOAT: - g_sp->z += (6 << 8); - return; - } - if (g_sp->picnum != DRONE) - g_sp->z += (24 << 8); -} - -void fall_r(int g_i, int g_p) -{ - fall_common(g_i, g_p, JIBS6, DRONE, BLOODPOOL, SHOTSPARK1, 69, 158, fallspecial, falladjustz); + fall_common(ac, g_p, JIBS6, DRONE, BLOODPOOL, SHOTSPARK1, 69, 158, fallspecial); } //--------------------------------------------------------------------------- @@ -4435,56 +4127,51 @@ void fall_r(int g_i, int g_p) // //--------------------------------------------------------------------------- -void destroyit(int g_i) +void destroyit(DDukeActor *actor) { - auto g_sp = &sprite[g_i]; - spritetype* js; int lotag, hitag; - int k, jj; int wi, wj; - int spr; + DDukeActor* spr; int wallstart2, wallend2; int sectnum; int wallstart, wallend; hitag = 0; - SectIterator it1(g_sp->sectnum); - while ((k = it1.NextIndex()) >= 0) + DukeSectIterator it1(actor->s.sectnum); + while (auto a2 = it1.Next()) { - auto sj = &sprite[k]; - if (sj->picnum == RRTILE63) + if (a2->s.picnum == RRTILE63) { - lotag = sj->lotag; - spr = k; - if (sj->hitag) - hitag = sj->hitag; + lotag = a2->s.lotag; + spr = a2; + if (a2->s.hitag) + hitag = a2->s.hitag; } } - StatIterator it(STAT_DESTRUCT); - while ((jj = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DESTRUCT); + while (auto a2 = it.Next()) { - js = &sprite[jj]; - if (hitag) - if (hitag == js->hitag) + int it_sect = a2->s.sectnum; + if (hitag && hitag == a2->s.hitag) + { + DukeSectIterator its(it_sect); + while (auto a3 = its.Next()) { - SectIterator it(js->sectnum); - while ((k = it.NextIndex()) >= 0) + if (a3->s.picnum == DESTRUCTO) { - if (sprite[k].picnum == DESTRUCTO) - { - hittype[k].picnum = SHOTSPARK1; - hittype[k].extra = 1; - } + a3->picnum = SHOTSPARK1; + a3->extra = 1; } } - if (sprite[spr].sectnum != js->sectnum) - if (lotag == js->lotag) + } + if (spr->s.sectnum != it_sect) + if (lotag == a2->s.lotag) { - sectnum = sprite[spr].sectnum; + sectnum = spr->s.sectnum; wallstart = sector[sectnum].wallptr; wallend = wallstart + sector[sectnum].wallnum; - wallstart2 = sector[js->sectnum].wallptr; - wallend2 = wallstart2 + sector[js->sectnum].wallnum; + wallstart2 = sector[it_sect].wallptr; + wallend2 = wallstart2 + sector[it_sect].wallnum; for (wi = wallstart, wj = wallstart2; wi < wallend; wi++, wj++) { wall[wi].picnum = wall[wj].picnum; @@ -4500,33 +4187,33 @@ void destroyit(int g_i) wall[wall[wi].nextwall].cstat = 0; } } - sector[sectnum].floorz = sector[js->sectnum].floorz; - sector[sectnum].ceilingz = sector[js->sectnum].ceilingz; - sector[sectnum].ceilingstat = sector[js->sectnum].ceilingstat; - sector[sectnum].floorstat = sector[js->sectnum].floorstat; - sector[sectnum].ceilingpicnum = sector[js->sectnum].ceilingpicnum; - sector[sectnum].ceilingheinum = sector[js->sectnum].ceilingheinum; - sector[sectnum].ceilingshade = sector[js->sectnum].ceilingshade; - sector[sectnum].ceilingpal = sector[js->sectnum].ceilingpal; - sector[sectnum].ceilingxpanning = sector[js->sectnum].ceilingxpanning; - sector[sectnum].ceilingypanning = sector[js->sectnum].ceilingypanning; - sector[sectnum].floorpicnum = sector[js->sectnum].floorpicnum; - sector[sectnum].floorheinum = sector[js->sectnum].floorheinum; - sector[sectnum].floorshade = sector[js->sectnum].floorshade; - sector[sectnum].floorpal = sector[js->sectnum].floorpal; - sector[sectnum].floorxpanning = sector[js->sectnum].floorxpanning; - sector[sectnum].floorypanning = sector[js->sectnum].floorypanning; - sector[sectnum].visibility = sector[js->sectnum].visibility; - sectorextra[sectnum] = sectorextra[js->sectnum]; // TRANSITIONAL: at least rename this. - sector[sectnum].lotag = sector[js->sectnum].lotag; - sector[sectnum].hitag = sector[js->sectnum].hitag; - sector[sectnum].extra = sector[js->sectnum].extra; + sector[sectnum].floorz = sector[it_sect].floorz; + sector[sectnum].ceilingz = sector[it_sect].ceilingz; + sector[sectnum].ceilingstat = sector[it_sect].ceilingstat; + sector[sectnum].floorstat = sector[it_sect].floorstat; + sector[sectnum].ceilingpicnum = sector[it_sect].ceilingpicnum; + sector[sectnum].ceilingheinum = sector[it_sect].ceilingheinum; + sector[sectnum].ceilingshade = sector[it_sect].ceilingshade; + sector[sectnum].ceilingpal = sector[it_sect].ceilingpal; + sector[sectnum].ceilingxpanning = sector[it_sect].ceilingxpanning; + sector[sectnum].ceilingypanning = sector[it_sect].ceilingypanning; + sector[sectnum].floorpicnum = sector[it_sect].floorpicnum; + sector[sectnum].floorheinum = sector[it_sect].floorheinum; + sector[sectnum].floorshade = sector[it_sect].floorshade; + sector[sectnum].floorpal = sector[it_sect].floorpal; + sector[sectnum].floorxpanning = sector[it_sect].floorxpanning; + sector[sectnum].floorypanning = sector[it_sect].floorypanning; + sector[sectnum].visibility = sector[it_sect].visibility; + sectorextra[sectnum] = sectorextra[it_sect]; // TRANSITIONAL: at least rename this. + sector[sectnum].lotag = sector[it_sect].lotag; + sector[sectnum].hitag = sector[it_sect].hitag; + sector[sectnum].extra = sector[it_sect].extra; } } - it1.Reset(g_sp->sectnum); - while ((k = it.NextIndex()) >= 0) + it1.Reset(actor->s.sectnum); + while (auto a2 = it1.Next()) { - switch (sprite[k].picnum) + switch (a2->s.picnum) { case DESTRUCTO: case RRTILE63: @@ -4535,7 +4222,7 @@ void destroyit(int g_i) case COOT: break; default: - deletesprite(k); + deletesprite(a2); break; } } @@ -4547,12 +4234,12 @@ void destroyit(int g_i) // //--------------------------------------------------------------------------- -void mamaspawn(int g_i) +void mamaspawn(DDukeActor *actor) { if (mamaspawn_count) { mamaspawn_count--; - fi.spawn(g_i, RABBIT); + spawn(actor, RABBIT); } } @@ -4561,27 +4248,26 @@ bool spawnweapondebris_r(int picnum, int dnum) return dnum == SCRAP1; } -void respawnhitag_r(spritetype* g_sp) +void respawnhitag_r(DDukeActor *actor) { - switch (g_sp->picnum) + switch (actor->s.picnum) { case FEM10: case NAKED1: case STATUE: - if (g_sp->yvel) fi.operaterespawns(g_sp->yvel); + if (actor->s.yvel) fi.operaterespawns(actor->s.yvel); break; default: - if (g_sp->hitag >= 0) fi.operaterespawns(g_sp->hitag); + if (actor->s.hitag >= 0) fi.operaterespawns(actor->s.hitag); break; } } -void checktimetosleep_r(int g_i) +void checktimetosleep_r(DDukeActor *actor) { - auto g_sp = &sprite[g_i]; - if (g_sp->statnum == 6) + if (actor->s.statnum == STAT_STANDABLE) { - switch (g_sp->picnum) + switch (actor->s.picnum) { case RUBBERCAN: case EXPLODINGBARREL: @@ -4594,10 +4280,10 @@ void checktimetosleep_r(int g_i) case NUKEBARRELLEAKED: case TRIPBOMB: case EGG: - if (hittype[g_i].timetosleep > 1) - hittype[g_i].timetosleep--; - else if (hittype[g_i].timetosleep == 1) - changespritestat(g_i, 2); + if (actor->timetosleep > 1) + actor->timetosleep--; + else if (actor->timetosleep == 1) + changespritestat(actor, STAT_ZOMBIEACTOR); break; } } diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index 431af1b5a..f822c0718 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -37,6 +37,7 @@ source as it is released. #include "global.h" #include "prediction.h" #include "names_d.h" +#include "dukeactor.h" EXTERN_CVAR(Bool, wt_commentary) @@ -49,12 +50,14 @@ void animatesprites_d(int x, int y, int a, int smoothratio) int l, t1, t3, t4; spritetype* s; tspritetype* t; + weaponhit* h; for (j = 0; j < spritesortcnt; j++) { t = &tsprite[j]; i = t->owner; - s = &sprite[t->owner]; + h = &hittype[i]; + s = &h->s; switch (t->picnum) { @@ -146,7 +149,10 @@ void animatesprites_d(int x, int y, int a, int smoothratio) { //is the perfect time to animate sprites t = &tsprite[j]; i = t->owner; - s = &sprite[i]; + h = &hittype[i]; + s = &h->s; + auto OwnerAc = h->GetOwner(); + auto Owner = OwnerAc ? &OwnerAc->s : nullptr; switch (s->picnum) { @@ -168,7 +174,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) } if (t->statnum == 99) continue; - if (s->statnum != STAT_ACTOR && s->picnum == APLAYER && ps[s->yvel].newowner == -1 && s->owner >= 0) + if (s->statnum != STAT_ACTOR && s->picnum == APLAYER && ps[s->yvel].newOwner == nullptr && h->GetOwner()) { t->x -= mulscale16(MaxSmoothRatio - smoothratio, ps[s->yvel].posx - ps[s->yvel].oposx); t->y -= mulscale16(MaxSmoothRatio - smoothratio, ps[s->yvel].posy - ps[s->yvel].oposy); @@ -177,15 +183,15 @@ void animatesprites_d(int x, int y, int a, int smoothratio) } else if (s->picnum != CRANEPOLE) { - t->x -= mulscale16(MaxSmoothRatio - smoothratio, s->x - hittype[i].bposx); - t->y -= mulscale16(MaxSmoothRatio - smoothratio, s->y - hittype[i].bposy); - t->z -= mulscale16(MaxSmoothRatio - smoothratio, s->z - hittype[i].bposz); + t->x -= mulscale16(MaxSmoothRatio - smoothratio, s->x - h->bposx); + t->y -= mulscale16(MaxSmoothRatio - smoothratio, s->y - h->bposy); + t->z -= mulscale16(MaxSmoothRatio - smoothratio, s->z - h->bposz); } sect = s->sectnum; - t1 = hittype[i].temp_data[1]; - t3 = hittype[i].temp_data[3]; - t4 = hittype[i].temp_data[4]; + t1 = h->temp_data[1]; + t3 = h->temp_data[3]; + t4 = h->temp_data[4]; switch (s->picnum) { @@ -210,35 +216,35 @@ void animatesprites_d(int x, int y, int a, int smoothratio) case TRIPBOMB: continue; case FORCESPHERE: - if (t->statnum == 5) + if (t->statnum == STAT_MISC && Owner) { short sqa, sqb; sqa = getangle( - sprite[s->owner].x - ps[screenpeek].posx, - sprite[s->owner].y - ps[screenpeek].posy); + Owner->x - ps[screenpeek].posx, + Owner->y - ps[screenpeek].posy); sqb = getangle( - sprite[s->owner].x - t->x, - sprite[s->owner].y - t->y); + Owner->x - t->x, + Owner->y - t->y); if (abs(getincangle(sqa, sqb)) > 512) - if (ldist(&sprite[s->owner], t) < ldist(&sprite[ps[screenpeek].i], &sprite[s->owner])) + if (ldist(Owner, t) < ldist(&ps[screenpeek].GetActor()->s, Owner)) t->xrepeat = t->yrepeat = 0; } continue; case BURNING: case BURNING2: - if (sprite[s->owner].statnum == 10) + if (Owner && Owner->statnum == STAT_PLAYER) { - if (display_mirror == 0 && sprite[s->owner].yvel == screenpeek && ps[sprite[s->owner].yvel].over_shoulder_on == 0) + if (display_mirror == 0 && Owner->yvel == screenpeek && ps[screenpeek].over_shoulder_on == 0) t->xrepeat = 0; else { t->ang = getangle(x - t->x, y - t->y); - t->x = sprite[s->owner].x; - t->y = sprite[s->owner].y; + t->x = Owner->x; + t->y = Owner->y; t->x += sintable[(t->ang + 512) & 2047] >> 10; t->y += sintable[t->ang & 2047] >> 10; } @@ -253,14 +259,14 @@ void animatesprites_d(int x, int y, int a, int smoothratio) continue; case VIEWSCREEN: case VIEWSCREEN2: - if (camsprite >= 0 && hittype[sprite[i].owner].temp_data[0] == 1) + if (camsprite != nullptr && h->GetOwner()->temp_data[0] == 1) { t->picnum = STATIC; t->cstat |= (rand() & 12); t->xrepeat += 8; t->yrepeat += 8; } - else if (camsprite >= 0) + else if (camsprite != nullptr) { t->picnum = TILE_VIEWSCR; } @@ -296,7 +302,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) }*/ k = getangle(s->x - x, s->y - y); - if (hittype[i].temp_data[0] < 4) + if (h->temp_data[0] < 4) k = (((s->ang + 3072 + 128 - k) & 2047) / 170); else k = (((s->ang + 3072 + 128 - k) & 2047) / 170); @@ -318,7 +324,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) if (t->pal == 1) t->z -= (18 << 8); - if (ps[p].over_shoulder_on > 0 && ps[p].newowner < 0) + if (ps[p].over_shoulder_on > 0 && ps[p].newOwner == nullptr) { t->cstat |= 2; if (screenpeek == myconnectindex && numplayers >= 2) @@ -331,7 +337,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) } } - if ((display_mirror == 1 || screenpeek != p || s->owner == -1) && ud.multimode > 1 && ud.showweapons && sprite[ps[p].i].extra > 0 && ps[p].curr_weapon > 0) + if ((display_mirror == 1 || screenpeek != p || !h->GetOwner()) && ud.multimode > 1 && ud.showweapons && ps[p].GetActor()->s.extra > 0 && ps[p].curr_weapon > 0) { auto newtspr = &tsprite[spritesortcnt]; memcpy(newtspr, t, sizeof(spritetype)); @@ -362,7 +368,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) case DEVISTATOR_WEAPON: newtspr->picnum = DEVISTATORSPRITE; break; } - if (s->owner >= 0) + if (h->GetOwner()) newtspr->z = ps[p].posz - (12 << 8); else newtspr->z = s->z - (51 << 8); if (ps[p].curr_weapon == HANDBOMB_WEAPON) @@ -379,7 +385,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) spritesortcnt++; } - if (s->owner == -1) + if (!h->GetOwner()) { /*if (bpp > 8 && usemodels && md_tilehasmodel(s->picnum) >= 0) { k = 0; @@ -395,7 +401,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) } if (sector[t->sectnum].lotag == 2) k += 1795 - 1405; - else if ((hittype[i].floorz - s->z) > (64 << 8)) k += 60; + else if ((h->floorz - s->z) > (64 << 8)) k += 60; t->picnum += k; t->pal = ps[p].palookup; @@ -405,21 +411,21 @@ void animatesprites_d(int x, int y, int a, int smoothratio) if (ps[p].on_crane == nullptr && (sector[s->sectnum].lotag & 0x7ff) != 1) { - l = s->z - hittype[ps[p].i].floorz + (3 << 8); + l = s->z - ps[p].GetActor()->floorz + (3 << 8); if (l > 1024 && s->yrepeat > 32 && s->extra > 0) s->yoffset = (signed char)(l / (s->yrepeat << 2)); else s->yoffset = 0; } - if (ps[p].newowner > -1) + if (ps[p].newOwner != nullptr) { t4 = ScriptCode[actorinfo[APLAYER].scriptaddress + 1]; t3 = 0; t1 = ScriptCode[actorinfo[APLAYER].scriptaddress + 2]; } - if (ud.camerasprite == -1 && ps[p].newowner == -1) - if (s->owner >= 0 && display_mirror == 0 && ps[p].over_shoulder_on == 0) + if (ud.cameraactor == nullptr && ps[p].newOwner == nullptr) + if (h->GetOwner() && display_mirror == 0 && ps[p].over_shoulder_on == 0) if (ud.multimode < 2 || (ud.multimode > 1 && p == screenpeek)) { t->owner = -1; @@ -432,10 +438,10 @@ void animatesprites_d(int x, int y, int a, int smoothratio) if (sector[sect].floorpal) t->pal = sector[sect].floorpal; - if (s->owner == -1) continue; + if (!h->GetOwner()) continue; - if (t->z > hittype[i].floorz && t->xrepeat < 32) - t->z = hittype[i].floorz; + if (t->z > h->floorz && t->xrepeat < 32) + t->z = h->floorz; break; @@ -470,9 +476,9 @@ void animatesprites_d(int x, int y, int a, int smoothratio) case SCRAP6 + 6: case SCRAP6 + 7: - if (hittype[i].picnum == BLIMP && t->picnum == SCRAP1 && s->yvel >= 0) + if (h->picnum == BLIMP && t->picnum == SCRAP1 && s->yvel >= 0) t->picnum = s->yvel; - else t->picnum += hittype[i].temp_data[0]; + else t->picnum += h->temp_data[0]; t->shade -= 6; if (sector[sect].floorpal) @@ -552,20 +558,20 @@ void animatesprites_d(int x, int y, int a, int smoothratio) while (!tileGetTexture(t->picnum)->isValid() && t->picnum > 0) t->picnum -= l; //Hack, for actors - if (hittype[i].dispicnum >= 0) - hittype[i].dispicnum = t->picnum; + if (h->dispicnum >= 0) + h->dispicnum = t->picnum; } else if (display_mirror == 1) t->cstat |= 4; } - if (s->statnum == STAT_DUMMYPLAYER || badguy(s) || (s->picnum == APLAYER && s->owner >= 0)) + if (s->statnum == STAT_DUMMYPLAYER || badguy(s) || (s->picnum == APLAYER && h->GetOwner())) if (t->statnum != 99 && s->picnum != EXPLOSION2 && s->picnum != HANGLIGHT && s->picnum != DOMELITE) if (s->picnum != HOTMEAT) { - if (hittype[i].dispicnum < 0) + if (h->dispicnum < 0) { - hittype[i].dispicnum++; + h->dispicnum++; continue; } else if (r_shadows && spritesortcnt < (MAXSPRITESONSCREEN - 2)) @@ -575,7 +581,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) if ((sector[sect].lotag & 0xff) > 2 || s->statnum == 4 || s->statnum == 5 || s->picnum == DRONE || s->picnum == COMMANDER) daz = sector[sect].floorz; else - daz = hittype[i].floorz; + daz = h->floorz; if ((s->z - daz) < (8 << 8) && ps[screenpeek].posz < daz) @@ -628,8 +634,9 @@ void animatesprites_d(int x, int y, int a, int smoothratio) switch (s->picnum) { case LASERLINE: + if (!Owner) break; if (sector[t->sectnum].lotag == 2) t->pal = 8; - t->z = sprite[s->owner].z - (3 << 8); + t->z = Owner->z - (3 << 8); if (lasermode == 2 && ps[screenpeek].heat_on == 0) t->yrepeat = 0; case EXPLOSION2: @@ -655,7 +662,8 @@ void animatesprites_d(int x, int y, int a, int smoothratio) t->cstat |= 128; case BURNING: case BURNING2: - if (sprite[s->owner].picnum != TREE1 && sprite[s->owner].picnum != TREE2) + if (!Owner) break; + if (Owner->picnum != TREE1 && Owner->picnum != TREE2) t->z = sector[t->sectnum].floorz; t->shade = -127; break; @@ -677,8 +685,8 @@ void animatesprites_d(int x, int y, int a, int smoothratio) else t->cstat &= ~4; } - t->picnum = s->picnum + k + ((hittype[i].temp_data[0] < 4) * 5); - t->shade = sprite[s->owner].shade; + t->picnum = s->picnum + k + ((h->temp_data[0] < 4) * 5); + if (Owner) t->shade = Owner->shade; break; @@ -686,32 +694,32 @@ void animatesprites_d(int x, int y, int a, int smoothratio) t->picnum = WATERSPLASH2 + t1; break; case REACTOR2: - t->picnum = s->picnum + hittype[i].temp_data[2]; + t->picnum = s->picnum + h->temp_data[2]; break; case SHELL: - t->picnum = s->picnum + (hittype[i].temp_data[0] & 1); + t->picnum = s->picnum + (h->temp_data[0] & 1); case SHOTGUNSHELL: t->cstat |= 12; - if (hittype[i].temp_data[0] > 1) t->cstat &= ~4; - if (hittype[i].temp_data[0] > 2) t->cstat &= ~12; + if (h->temp_data[0] > 1) t->cstat &= ~4; + if (h->temp_data[0] > 2) t->cstat &= ~12; break; case FRAMEEFFECT1: - if (s->owner >= 0 && sprite[s->owner].statnum < MAXSTATUS) + if (Owner && Owner->statnum < MAXSTATUS) { - if (sprite[s->owner].picnum == APLAYER) - if (ud.camerasprite == -1) - if (screenpeek == sprite[s->owner].yvel && display_mirror == 0) + if (Owner->picnum == APLAYER) + if (ud.cameraactor == nullptr) + if (screenpeek == Owner->yvel && display_mirror == 0) { t->owner = -1; break; } - if ((sprite[s->owner].cstat & 32768) == 0) + if ((Owner->cstat & 32768) == 0) { - t->picnum = hittype[s->owner].dispicnum; - t->pal = sprite[s->owner].pal; - t->shade = sprite[s->owner].shade; - t->ang = sprite[s->owner].ang; - t->cstat = 2 | sprite[s->owner].cstat; + t->picnum = OwnerAc->dispicnum; + t->pal = Owner->pal; + t->shade = Owner->shade; + t->ang = Owner->ang; + t->cstat = 2 | Owner->cstat; } } break; @@ -734,7 +742,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) break; } - hittype[i].dispicnum = t->picnum; + h->dispicnum = t->picnum; if (sector[t->sectnum].floorpicnum == MIRROR) t->xrepeat = t->yrepeat = 0; } diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index 74cad6842..ab403510f 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -31,6 +31,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "global.h" #include "names_r.h" #include "prediction.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -42,6 +43,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) int l, t1, t3, t4; spritetype* s; tspritetype* t; + weaponhit* h; int bg = 0; @@ -49,7 +51,8 @@ void animatesprites_r(int x, int y, int a, int smoothratio) { t = &tsprite[j]; i = t->owner; - s = &sprite[t->owner]; + h = &hittype[i]; + s = &h->s; switch (t->picnum) { @@ -135,7 +138,10 @@ void animatesprites_r(int x, int y, int a, int smoothratio) { //is the perfect time to animate sprites t = &tsprite[j]; i = t->owner; - s = &sprite[i]; + h = &hittype[i]; + s = &h->s; + auto OwnerAc = h->GetOwner(); + auto Owner = OwnerAc ? &OwnerAc->s : nullptr; switch (s->picnum) { @@ -153,7 +159,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) } if (t->statnum == 99) continue; - if (s->statnum != STAT_ACTOR && s->picnum == APLAYER && ps[s->yvel].newowner == -1 && s->owner >= 0) + if (s->statnum != STAT_ACTOR && s->picnum == APLAYER && ps[s->yvel].newOwner == nullptr && h->GetOwner()) { t->x -= mulscale16(MaxSmoothRatio - smoothratio, ps[s->yvel].posx - ps[s->yvel].oposx); t->y -= mulscale16(MaxSmoothRatio - smoothratio, ps[s->yvel].posy - ps[s->yvel].oposy); @@ -164,15 +170,15 @@ void animatesprites_r(int x, int y, int a, int smoothratio) } else if (s->picnum != CRANEPOLE) { - t->x -= mulscale16(MaxSmoothRatio - smoothratio, s->x - hittype[i].bposx); - t->y -= mulscale16(MaxSmoothRatio - smoothratio, s->y - hittype[i].bposy); - t->z -= mulscale16(MaxSmoothRatio - smoothratio, s->z - hittype[i].bposz); + t->x -= mulscale16(MaxSmoothRatio - smoothratio, s->x - h->bposx); + t->y -= mulscale16(MaxSmoothRatio - smoothratio, s->y - h->bposy); + t->z -= mulscale16(MaxSmoothRatio - smoothratio, s->z - h->bposz); } sect = s->sectnum; - t1 = hittype[i].temp_data[1]; - t3 = hittype[i].temp_data[3]; - t4 = hittype[i].temp_data[4]; + t1 = h->temp_data[1]; + t3 = h->temp_data[3]; + t4 = h->temp_data[4]; switch (s->picnum) { @@ -208,34 +214,34 @@ void animatesprites_r(int x, int y, int a, int smoothratio) case TRIPBOMBSPRITE: continue; case FORCESPHERE: - if (t->statnum == 5) + if (t->statnum == STAT_MISC && Owner) { short sqa, sqb; sqa = getangle( - sprite[s->owner].x - ps[screenpeek].posx, - sprite[s->owner].y - ps[screenpeek].posy); + Owner->x - ps[screenpeek].posx, + Owner->y - ps[screenpeek].posy); sqb = getangle( - sprite[s->owner].x - t->x, - sprite[s->owner].y - t->y); + Owner->x - t->x, + Owner->y - t->y); if (abs(getincangle(sqa, sqb)) > 512) - if (ldist(&sprite[s->owner], t) < ldist(&sprite[ps[screenpeek].i], &sprite[s->owner])) + if (ldist(Owner, t) < ldist(&ps[screenpeek].GetActor()->s, Owner)) t->xrepeat = t->yrepeat = 0; } continue; case BURNING: - if (sprite[s->owner].statnum == 10) + if (Owner && Owner->statnum == STAT_PLAYER) { - if (display_mirror == 0 && sprite[s->owner].yvel == screenpeek && ps[sprite[s->owner].yvel].over_shoulder_on == 0) + if (display_mirror == 0 && Owner->yvel == screenpeek && ps[Owner->yvel].over_shoulder_on == 0) t->xrepeat = 0; else { t->ang = getangle(x - t->x, y - t->y); - t->x = sprite[s->owner].x; - t->y = sprite[s->owner].y; + t->x = Owner->x; + t->y = Owner->y; t->x += sintable[(t->ang + 512) & 2047] >> 10; t->y += sintable[t->ang & 2047] >> 10; } @@ -249,7 +255,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) t->shade = (sintable[(ud.levelclock << 4) & 2047] >> 10); break; case SHRINKSPARK: - if ((sprite[s->owner].picnum == CHEER || sprite[s->owner].picnum == CHEERSTAYPUT) && isRRRA()) + if (Owner && (Owner->picnum == CHEER || Owner->picnum == CHEERSTAYPUT) && isRRRA()) { t->picnum = CHEERBLADE + ((ud.levelclock >> 4) & 3); t->shade = -127; @@ -265,16 +271,16 @@ void animatesprites_r(int x, int y, int a, int smoothratio) } else goto default_case; case SPIT: - if (isRRRA()) + if (isRRRA() && Owner) { - if (sprite[s->owner].picnum == MINION && sprite[s->owner].pal == 8) + if (Owner->picnum == MINION && Owner->pal == 8) t->picnum = RRTILE3500 + ((ud.levelclock >> 4) % 6); - else if (sprite[s->owner].picnum == MINION && sprite[s->owner].pal == 19) + else if (Owner->picnum == MINION && Owner->pal == 19) { t->picnum = RRTILE5090 + ((ud.levelclock >> 4) & 3); t->shade = -127; } - else if (sprite[s->owner].picnum == MAMA) + else if (Owner->picnum == MAMA) { k = getangle(s->x - x, s->y - y); k = (((s->ang + 3072 + 128 - k) & 2047) >> 8) & 7; @@ -343,7 +349,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) case RECON: k = getangle(s->x - x, s->y - y); - if (hittype[i].temp_data[0] < 4) + if (h->temp_data[0] < 4) k = (((s->ang + 3072 + 128 - k) & 2047) / 170); else k = (((s->ang + 3072 + 128 - k) & 2047) / 170); @@ -365,7 +371,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if (t->pal == 1) t->z -= (18 << 8); - if (ps[p].over_shoulder_on > 0 && ps[p].newowner < 0) + if (ps[p].over_shoulder_on > 0 && ps[p].newOwner == nullptr) { t->cstat |= 2; if (screenpeek == myconnectindex && numplayers >= 2) @@ -378,7 +384,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) } } - if ((display_mirror == 1 || screenpeek != p || s->owner == -1) && ud.multimode > 1 && ud.showweapons && sprite[ps[p].i].extra > 0 && ps[p].curr_weapon > 0) + if ((display_mirror == 1 || screenpeek != p || !h->GetOwner()) && ud.multimode > 1 && ud.showweapons && ps[p].GetActor()->s.extra > 0 && ps[p].curr_weapon > 0) { auto newtspr = &tsprite[spritesortcnt]; memcpy(newtspr, t, sizeof(spritetype)); @@ -408,7 +414,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) case TIT_WEAPON: newtspr->picnum = FREEZESPRITE; break; } - if (s->owner >= 0) + if (h->GetOwner()) newtspr->z = ps[p].posz - (12 << 8); else newtspr->z = s->z - (51 << 8); if (ps[p].curr_weapon == HANDBOMB_WEAPON) @@ -430,7 +436,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) spritesortcnt++; } - if (s->owner == -1) + if (!h->GetOwner()) { /*if (bpp > 8 && usemodels && md_tilehasmodel(s->picnum) >= 0) { k = 0; @@ -446,7 +452,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) } if (sector[t->sectnum].lotag == 2) k += 1795 - 1405; - else if ((hittype[i].floorz - s->z) > (64 << 8)) k += 60; + else if ((h->floorz - s->z) > (64 << 8)) k += 60; t->picnum += k; t->pal = ps[p].palookup; @@ -456,21 +462,21 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if (ps[p].on_crane == nullptr && (sector[s->sectnum].lotag & 0x7ff) != 1) { - l = s->z - hittype[ps[p].i].floorz + (3 << 8); + l = s->z - ps[p].GetActor()->floorz + (3 << 8); if (l > 1024 && s->yrepeat > 32 && s->extra > 0) s->yoffset = (signed char)(l / (s->yrepeat << 2)); else s->yoffset = 0; } - if (ps[p].newowner > -1) + if (ps[p].newOwner != nullptr) { t4 = ScriptCode[actorinfo[APLAYER].scriptaddress + 1]; t3 = 0; t1 = ScriptCode[actorinfo[APLAYER].scriptaddress + 2]; } - if (ud.camerasprite == -1 && ps[p].newowner == -1) - if (s->owner >= 0 && display_mirror == 0 && ps[p].over_shoulder_on == 0) + if (ud.cameraactor == nullptr && ps[p].newOwner == nullptr) + if (h->GetOwner() && display_mirror == 0 && ps[p].over_shoulder_on == 0) if (ud.multimode < 2 || (ud.multimode > 1 && p == screenpeek)) { t->owner = -1; @@ -483,10 +489,10 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if (sector[sect].floorpal) t->pal = sector[sect].floorpal; - if (s->owner == -1) continue; + if (!h->GetOwner()) continue; - if (t->z > hittype[i].floorz && t->xrepeat < 32) - t->z = hittype[i].floorz; + if (t->z > h->floorz && t->xrepeat < 32) + t->z = h->floorz; if (ps[p].OnMotorcycle && p == screenpeek) { @@ -610,7 +616,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if (t->picnum == SCRAP1 && s->yvel >= 0) t->picnum = s->yvel; - else t->picnum += hittype[i].temp_data[0]; + else t->picnum += h->temp_data[0]; if (sector[sect].floorpal) t->pal = sector[sect].floorpal; @@ -704,8 +710,8 @@ void animatesprites_r(int x, int y, int a, int smoothratio) while (!tileGetTexture(t->picnum)->isValid() && t->picnum > 0) t->picnum -= l; //Hack, for actors - if (hittype[i].dispicnum >= 0) - hittype[i].dispicnum = t->picnum; + if (h->dispicnum >= 0) + h->dispicnum = t->picnum; } else if (display_mirror == 1) t->cstat |= 4; @@ -714,13 +720,13 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if (!isRRRA() && s->picnum == SBMOVE) t->shade = -127; - if (s->statnum == 13 || badguy(s) || (s->picnum == APLAYER && s->owner >= 0)) + if (s->statnum == 13 || badguy(s) || (s->picnum == APLAYER && h->GetOwner())) if ((s->cstat & 48) == 0 && t->statnum != 99) if (s->picnum != EXPLOSION2 && s->picnum != DOMELITE && s->picnum != TORNADO && s->picnum != EXPLOSION3 && (s->picnum != SBMOVE || isRRRA())) { - if (hittype[i].dispicnum < 0) + if (h->dispicnum < 0) { - hittype[i].dispicnum++; + h->dispicnum++; continue; } else if (r_shadows && spritesortcnt < (MAXSPRITESONSCREEN - 2)) @@ -731,7 +737,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if ((sector[sect].lotag & 0xff) > 2 || s->statnum == 4 || s->statnum == 5 || s->picnum == DRONE) daz = sector[sect].floorz; else - daz = hittype[i].floorz; + daz = h->floorz; if ((s->z - daz) < (8 << 8)) if (ps[screenpeek].posz < daz) @@ -814,7 +820,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) break; case FIRE: case BURNING: - if (sprite[s->owner].picnum != TREE1 && sprite[s->owner].picnum != TREE2) + if (Owner && Owner->picnum != TREE1 && Owner->picnum != TREE2) t->z = sector[t->sectnum].floorz; t->shade = -127; break; @@ -911,8 +917,8 @@ void animatesprites_r(int x, int y, int a, int smoothratio) } else t->cstat &= ~4; - t->picnum = s->picnum + k + ((hittype[i].temp_data[0] < 4) * 5); - t->shade = sprite[s->owner].shade; + t->picnum = s->picnum + k + ((h->temp_data[0] < 4) * 5); + if (Owner) t->shade = Owner->shade; break; case MUD: t->picnum = MUD + t1; @@ -921,35 +927,35 @@ void animatesprites_r(int x, int y, int a, int smoothratio) t->picnum = WATERSPLASH2 + t1; break; case REACTOR2: - t->picnum = s->picnum + hittype[i].temp_data[2]; + t->picnum = s->picnum + h->temp_data[2]; break; case SHELL: - t->picnum = s->picnum + (hittype[i].temp_data[0] & 1); + t->picnum = s->picnum + (h->temp_data[0] & 1); case SHOTGUNSHELL: t->cstat |= 12; - if (hittype[i].temp_data[0] > 1) t->cstat &= ~4; - if (hittype[i].temp_data[0] > 2) t->cstat &= ~12; + if (h->temp_data[0] > 1) t->cstat &= ~4; + if (h->temp_data[0] > 2) t->cstat &= ~12; break; case FRAMEEFFECT1: - if (s->owner >= 0 && sprite[s->owner].statnum < MAXSTATUS) + if (Owner && Owner->statnum < MAXSTATUS) { - if (sprite[s->owner].picnum == APLAYER) - if (ud.camerasprite == -1) - if (screenpeek == sprite[s->owner].yvel && display_mirror == 0) + if (Owner->picnum == APLAYER) + if (ud.cameraactor == nullptr) + if (screenpeek == Owner->yvel && display_mirror == 0) { t->owner = -1; break; } - if ((sprite[s->owner].cstat & 32768) == 0) + if ((Owner->cstat & 32768) == 0) { - if (sprite[s->owner].picnum == APLAYER) + if (Owner->picnum == APLAYER) t->picnum = 1554; else - t->picnum = hittype[s->owner].dispicnum; - t->pal = sprite[s->owner].pal; - t->shade = sprite[s->owner].shade; - t->ang = sprite[s->owner].ang; - t->cstat = 2 | sprite[s->owner].cstat; + t->picnum = OwnerAc->dispicnum; + t->pal = Owner->pal; + t->shade = Owner->shade; + t->ang = Owner->ang; + t->cstat = 2 | Owner->cstat; } } break; @@ -967,7 +973,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) break; } - hittype[i].dispicnum = t->picnum; + h->dispicnum = t->picnum; if (sector[t->sectnum].floorpicnum == MIRROR) t->xrepeat = t->yrepeat = 0; } diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index bb9579b8c..70283953b 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -36,25 +36,22 @@ BEGIN_DUKE_NS short pinsectorresetdown(short sect); -void ballreturn(short spr) +void ballreturn(DDukeActor *ball) { - int j, i; - StatIterator it(STAT_BOWLING); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_BOWLING); + while (auto act = it.Next()) { - auto si = &sprite[i]; - if (si->picnum == RRTILE281 && sprite[spr].sectnum == si->sectnum) + if (act->s.picnum == RRTILE281 && ball->s.sectnum == act->s.sectnum) { - StatIterator it2(STAT_BOWLING); - while ((j = it2.NextIndex()) >= 0) + DukeStatIterator it2(STAT_BOWLING); + while (auto act2 = it2.Next()) { - auto sj = &sprite[j]; - if (sj->picnum == RRTILE282 && si->hitag == sj->hitag) - fi.spawn(j, BOWLINGBALLSPRITE); - if (sj->picnum == RRTILE280 && si->hitag == sj->hitag && sj->lotag == 0) + if (act2->s.picnum == RRTILE282 && act->s.hitag == act2->s.hitag) + spawn(act2, BOWLINGBALLSPRITE); + if (act2->s.picnum == RRTILE280 && act->s.hitag == act2->s.hitag && act2->s.lotag == 0) { - sj->lotag = 100; - sj->extra++; + act2->s.lotag = 100; + act2->s.extra++; } } } @@ -63,15 +60,12 @@ void ballreturn(short spr) short pinsectorresetdown(short sect) { - int vel, j; - - j = getanimationgoal(anim_ceilingz, sect); + int j = getanimationgoal(anim_ceilingz, sect); if (j == -1) { j = sector[sect].floorz; - vel = 64; - setanimation(sect, anim_ceilingz, sect, j, vel); + setanimation(sect, anim_ceilingz, sect, j, 64); return 1; } return 0; @@ -79,15 +73,12 @@ short pinsectorresetdown(short sect) short pinsectorresetup(short sect) { - int vel, j; - - j = getanimationgoal(anim_ceilingz, sect); + int j = getanimationgoal(anim_ceilingz, sect); if (j == -1) { j = sector[nextsectorneighborz(sect, sector[sect].ceilingz, -1, -1)].ceilingz; - vel = 64; - setanimation(sect, anim_ceilingz, sect, j, vel); + setanimation(sect, anim_ceilingz, sect, j, 64); return 1; } return 0; @@ -99,76 +90,76 @@ short checkpins(short sect) int x, y; short pins[10]; short tag; - - pin = 0; - for(i=0;i<10;i++) pins[i] = 0; - SectIterator it(sect); - while ((i = it.NextIndex()) >= 0) + pin = 0; + for (i = 0; i < 10; i++) pins[i] = 0; + + DukeSectIterator it(sect); + while (auto a2 = it.Next()) { - if (sprite[i].picnum == RRTILE3440) + if (a2->s.picnum == RRTILE3440) { pin++; - pins[sprite[i].lotag] = 1; + pins[a2->s.lotag] = 1; } - if (sprite[i].picnum == RRTILE280) + if (a2->s.picnum == RRTILE280) { - tag = sprite[i].hitag; + tag = a2->s.hitag; } } if (tag) { tag += 2024; - tileCopySection(2024,0,0,128,64,tag,0,0); - for(i=0;i<10;i++) + tileCopySection(2024, 0, 0, 128, 64, tag, 0, 0); + for (i = 0; i < 10; i++) { if (pins[i] == 1) { switch (i) { - case 0: - x = 64; - y = 48; - break; - case 1: - x = 56; - y = 40; - break; - case 2: - x = 72; - y = 40; - break; - case 3: - x = 48; - y = 32; - break; - case 4: - x = 64; - y = 32; - break; - case 5: - x = 80; - y = 32; - break; - case 6: - x = 40; - y = 24; - break; - case 7: - x = 56; - y = 24; - break; - case 8: - x = 72; - y = 24; - break; - case 9: - x = 88; - y = 24; - break; + case 0: + x = 64; + y = 48; + break; + case 1: + x = 56; + y = 40; + break; + case 2: + x = 72; + y = 40; + break; + case 3: + x = 48; + y = 32; + break; + case 4: + x = 64; + y = 32; + break; + case 5: + x = 80; + y = 32; + break; + case 6: + x = 40; + y = 24; + break; + case 7: + x = 56; + y = 24; + break; + case 8: + x = 72; + y = 24; + break; + case 9: + x = 88; + y = 24; + break; } - tileCopySection(2023,0,0,8,8,tag,x-4,y-10); + tileCopySection(2023, 0, 0, 8, 8, tag, x - 4, y - 10); } } } @@ -178,84 +169,84 @@ short checkpins(short sect) void resetpins(short sect) { - short i, j, tag; + int i, tag; int x, y; - SectIterator it(sect); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto a2 = it.Next()) { - if (sprite[i].picnum == 3440) - deletesprite(i); + if (a2->s.picnum == RRTILE3440) + deletesprite(a2); } it.Reset(sect); - while ((i = it.NextIndex()) >= 0) + while (auto a2 = it.Next()) { - if (sprite[i].picnum == 283) + if (a2->s.picnum == 283) { - j = fi.spawn(i,3440); - sprite[j].lotag = sprite[i].lotag; - if (sprite[j].lotag == 3 || sprite[j].lotag == 5) + auto spawned = spawn(a2, RRTILE3440); + spawned->s.lotag = a2->s.lotag; + if (spawned->s.lotag == 3 || spawned->s.lotag == 5) { - sprite[j].clipdist = (1+(krand()%1))*16+32; + spawned->s.clipdist = (1 + (krand() % 1)) * 16 + 32; } else { - sprite[j].clipdist = (1+(krand()%1))*16+32; + spawned->s.clipdist = (1 + (krand() % 1)) * 16 + 32; } - sprite[j].ang -= ((krand()&32)-(krand()&64))&2047; + spawned->s.ang -= ((krand() & 32) - (krand() & 64)) & 2047; } - if (sprite[i].picnum == 280) - tag = sprite[i].hitag; + if (a2->s.picnum == 280) + tag = a2->s.hitag; } if (tag) { - tag += LANEPICS+1; - tileCopySection(LANEPICS+1,0,0,128,64,tag,0,0); - for(i=0;i<10;i++) + tag += LANEPICS + 1; + tileCopySection(LANEPICS + 1, 0, 0, 128, 64, tag, 0, 0); + for (i = 0; i < 10; i++) { switch (i) { - case 0: - x = 64; - y = 48; - break; - case 1: - x = 56; - y = 40; - break; - case 2: - x = 72; - y = 40; - break; - case 3: - x = 48; - y = 32; - break; - case 4: - x = 64; - y = 32; - break; - case 5: - x = 80; - y = 32; - break; - case 6: - x = 40; - y = 24; - break; - case 7: - x = 56; - y = 24; - break; - case 8: - x = 72; - y = 24; - break; - case 9: - x = 88; - y = 24; - break; + case 0: + x = 64; + y = 48; + break; + case 1: + x = 56; + y = 40; + break; + case 2: + x = 72; + y = 40; + break; + case 3: + x = 48; + y = 32; + break; + case 4: + x = 64; + y = 32; + break; + case 5: + x = 80; + y = 32; + break; + case 6: + x = 40; + y = 24; + break; + case 7: + x = 56; + y = 24; + break; + case 8: + x = 72; + y = 24; + break; + case 9: + x = 88; + y = 24; + break; } - tileCopySection(LANEPICS,0,0,8,8,tag,x-4,y-10); + tileCopySection(LANEPICS, 0, 0, 8, 8, tag, x - 4, y - 10); } } } @@ -265,58 +256,58 @@ void resetlanepics(void) int x, y; short i; short tag, pic; - for(tag=0;tag<4;tag++) + for (tag = 0; tag < 4; tag++) { pic = tag + 1; if (pic == 0) continue; - pic += LANEPICS+1; - tileCopySection(LANEPICS+1,0,0,128,64, pic,0,0); - for(i=0;i<10;i++) + pic += LANEPICS + 1; + tileCopySection(LANEPICS + 1, 0, 0, 128, 64, pic, 0, 0); + for (i = 0; i < 10; i++) { switch (i) { - case 0: - x = 64; - y = 48; - break; - case 1: - x = 56; - y = 40; - break; - case 2: - x = 72; - y = 40; - break; - case 3: - x = 48; - y = 32; - break; - case 4: - x = 64; - y = 32; - break; - case 5: - x = 80; - y = 32; - break; - case 6: - x = 40; - y = 24; - break; - case 7: - x = 56; - y = 24; - break; - case 8: - x = 72; - y = 24; - break; - case 9: - x = 88; - y = 24; - break; + case 0: + x = 64; + y = 48; + break; + case 1: + x = 56; + y = 40; + break; + case 2: + x = 72; + y = 40; + break; + case 3: + x = 48; + y = 32; + break; + case 4: + x = 64; + y = 32; + break; + case 5: + x = 80; + y = 32; + break; + case 6: + x = 40; + y = 24; + break; + case 7: + x = 56; + y = 24; + break; + case 8: + x = 72; + y = 24; + break; + case 9: + x = 88; + y = 24; + break; } - tileCopySection(LANEPICS,0,0,8,8,pic,x-4,y-10); + tileCopySection(LANEPICS, 0, 0, 8, 8, pic, x - 4, y - 10); } } } diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 07a98bd6e..f082ec62e 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -46,7 +46,7 @@ static int ccmd_spawn(CCmdFuncPtr parm) unsigned int cstat = 0, picnum = 0; unsigned int pal = 0; int ang = 0; - int set = 0, idx; + int set = 0; #if 0 // fixme - route through the network and this limitation becomes irrelevant if (netgame || numplayers > 1 || !(ps[myconnectindex].gm & MODE_GAME)) { @@ -88,14 +88,15 @@ static int ccmd_spawn(CCmdFuncPtr parm) return CCMD_SHOWHELP; } - idx = fi.spawn(ps[myconnectindex].i, (short)picnum); - if (set & 1) sprite[idx].pal = (char)pal; - if (set & 2) sprite[idx].cstat = (short)cstat; - if (set & 4) sprite[idx].ang = ang; + auto spawned = spawn(ps[myconnectindex].GetActor(), picnum); + if (set & 1) spawned->s.pal = (char)pal; + if (set & 2) spawned->s.cstat = (short)cstat; + if (set & 4) spawned->s.ang = ang; if (set & 8) { - if (setsprite(idx, x, y, z) < 0) { + if (setsprite(spawned, x, y, z) < 0) + { Printf("spawn: Sprite can't be spawned into null space\n"); - deletesprite(idx); + deletesprite(spawned); } } diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index 81eab90bf..c6ca45431 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -107,10 +107,10 @@ static const char* cheatUnlock() { if (j & (0xffff - 16384)) sector[i].lotag &= (0xffff - 16384); - operatesectors(i, ps[myconnectindex].i); + operatesectors(i, ps[myconnectindex].GetActor()); } } - fi.operateforcefields(ps[myconnectindex].i, -1); + fi.operateforcefields(ps[myconnectindex].GetActor(), -1); return quoteMgr.GetQuote(QUOTE_CHEAT_UNLOCK); } @@ -118,10 +118,10 @@ static const char *cheatKfc(int player) { for (int i = 0; i < 7; i++) { - int spr = fi.spawn(ps[player].i, TILE_HEN); - sprite[spr].pal = 1; - sprite[spr].xrepeat = sprite[spr].xrepeat << 2; - sprite[spr].yrepeat = sprite[spr].yrepeat << 2; + auto spr = spawn(ps[player].GetActor(), TILE_HEN); + spr->s.pal = 1; + spr->s.xrepeat = spr->s.xrepeat << 2; + spr->s.yrepeat = spr->s.yrepeat << 2; } return quoteMgr.GetQuote(QUOTE_CHEAT_KFC); } @@ -173,7 +173,7 @@ const char* GameInterface::GenericCheat(int player, int cheat) return cheatMonsters(); case CHT_BIKE: - OnMotorcycle(&ps[player], 0); + OnMotorcycle(&ps[player], nullptr); ps[player].ammo_amount[MOTORCYCLE_WEAPON] = max_ammo_amount[MOTORCYCLE_WEAPON]; return quoteMgr.GetQuote(QUOTE_ON_BIKE); @@ -195,7 +195,7 @@ const char* GameInterface::GenericCheat(int player, int cheat) ps[player].gotweapon.Zero(); ps[player].curr_weapon = KNEE_WEAPON; ps[player].nocheat = 1; - sprite[ps[player].i].extra = 1; + ps[player].GetActor()->s.extra = 1; return quoteMgr.GetQuote(QUOTE_YERFUCKED); case CHT_AARON: @@ -241,11 +241,11 @@ static bool cheatInventory(int player) { auto invGet = [=](int defvalue, int evtype, int16_t &dest) { - SetGameVarID(g_iReturnVarID, defvalue, -1, player); - OnEvent(evtype, -1, player, -1); - if (GetGameVarID(g_iReturnVarID, -1, player) >= 0) + SetGameVarID(g_iReturnVarID, defvalue, nullptr, player); + OnEvent(evtype, player, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, player) >= 0) { - dest = GetGameVarID(g_iReturnVarID, -1, player); + dest = GetGameVarID(g_iReturnVarID, nullptr, player); } }; @@ -472,7 +472,7 @@ static void cmd_Give(int player, uint8_t** stream, bool skip) int type = ReadByte(stream); if (skip) return; - if (numplayers != 1 || gamestate != GS_LEVEL || sprite[ps[player].i].extra <= 0) + if (numplayers != 1 || gamestate != GS_LEVEL || ps[player].GetActor()->s.extra <= 0) { Printf("give: Cannot give while dead or not in a single-player game.\n"); return; @@ -486,7 +486,7 @@ static void cmd_Give(int player, uint8_t** stream, bool skip) break; case GIVE_HEALTH: - sprite[ps[player].i].extra = max_player_health << 1; + ps[player].GetActor()->s.extra = max_player_health << 1; break; case GIVE_WEAPONS: diff --git a/source/games/duke/src/constants.h b/source/games/duke/src/constants.h index 9b6673540..638806f6f 100644 --- a/source/games/duke/src/constants.h +++ b/source/games/duke/src/constants.h @@ -288,12 +288,6 @@ enum amoveflags_t antifaceplayerslow = 32768 }; -enum -{ - SWITCH_WALL, - SWITCH_SPRITE -}; - enum sflags_t { SFLAG_SHADOW = 0x00000001, diff --git a/source/games/duke/src/d_menu.cpp b/source/games/duke/src/d_menu.cpp index 96aa69fcb..30bcbc469 100644 --- a/source/games/duke/src/d_menu.cpp +++ b/source/games/duke/src/d_menu.cpp @@ -93,7 +93,7 @@ bool GameInterface::CanSave() { if (ud.recstat == 2 || gamestate != GS_LEVEL) return false; auto &myplayer = ps[myconnectindex]; - return (sprite[myplayer.i].extra > 0); + return (myplayer.GetActor()->s.extra > 0); } bool GameInterface::StartGame(FNewGameStartup& gs) diff --git a/source/games/duke/src/dispatch.cpp b/source/games/duke/src/dispatch.cpp index adc0e1bc6..b19a80e46 100644 --- a/source/games/duke/src/dispatch.cpp +++ b/source/games/duke/src/dispatch.cpp @@ -41,20 +41,18 @@ void animatewalls_d(void); void animatewalls_r(void); void operaterespawns_d(int low); void operaterespawns_r(int low); -void operateforcefields_r(int s, int low); -void operateforcefields_d(int s, int low); -bool checkhitswitch_d(int snum, int w, int switchtype); -bool checkhitswitch_r(int snum, int w, int switchtype); -void activatebysector_d(int sect, int j); -void activatebysector_r(int sect, int j); -void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith); -void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith); -void checkplayerhurt_d(struct player_struct* p, int j); -void checkplayerhurt_r(struct player_struct* p, int j); +void operateforcefields_r(DDukeActor* act, int low); +void operateforcefields_d(DDukeActor* act, int low); +bool checkhitswitch_d(int snum, int w, DDukeActor *act); +bool checkhitswitch_r(int snum, int w, DDukeActor* act); +void activatebysector_d(int sect, DDukeActor* j); +void activatebysector_r(int sect, DDukeActor* j); +void checkhitwall_d(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith); +void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith); bool checkhitceiling_d(int sn); bool checkhitceiling_r(int sn); -void checkhitsprite_d(int i, int sn); -void checkhitsprite_r(int i, int sn); +void checkhitsprite_d(DDukeActor* i, DDukeActor* sn); +void checkhitsprite_r(DDukeActor* i, DDukeActor* sn); void checksectors_d(int snum); void checksectors_r(int snum); @@ -64,38 +62,32 @@ bool floorspace_d(int sectnum); bool floorspace_r(int sectnum); void addweapon_d(struct player_struct* p, int weapon); void addweapon_r(struct player_struct* p, int weapon); -void hitradius_d(short i, int r, int hp1, int hp2, int hp3, int hp4); -void hitradius_r(short i, int r, int hp1, int hp2, int hp3, int hp4); +void hitradius_d(DDukeActor* i, int r, int hp1, int hp2, int hp3, int hp4); +void hitradius_r(DDukeActor* i, int r, int hp1, int hp2, int hp3, int hp4); void lotsofmoney_d(DDukeActor* s, short n); void lotsofmail_d(DDukeActor* s, short n); void lotsofpaper_d(DDukeActor* s, short n); void lotsoffeathers_r(DDukeActor* s, short n); -void guts_d(spritetype* s, short gtype, short n, short p); -void guts_r(spritetype* s, short gtype, short n, short p); -void gutsdir_d(spritetype* s, short gtype, short n, short p); -void gutsdir_r(spritetype* s, short gtype, short n, short p); -int ifhitsectors_d(int sectnum); -int ifhitsectors_r(int sectnum); +void guts_d(DDukeActor* s, short gtype, short n, short p); +void guts_r(DDukeActor* s, short gtype, short n, short p); +DDukeActor* ifhitsectors_d(int sectnum); +DDukeActor* ifhitsectors_r(int sectnum); int ifhitbyweapon_r(DDukeActor* sn); int ifhitbyweapon_d(DDukeActor* sn); -void fall_d(int g_i, int g_p); -void fall_r(int g_i, int g_p); +void fall_d(DDukeActor* i, int g_p); +void fall_r(DDukeActor* i, int g_p); bool spawnweapondebris_d(int picnum, int dnum); bool spawnweapondebris_r(int picnum, int dnum); -void respawnhitag_d(spritetype* g_sp); -void respawnhitag_r(spritetype* g_sp); -void checktimetosleep_d(int g_i); -void checktimetosleep_r(int g_i); -void move_d(int g_i, int g_p, int g_x); -void move_r(int g_i, int g_p, int g_x); -int spawn_d(int j, int pn); -int spawn_r(int j, int pn); -void check_fta_sounds_d(int i); -void check_fta_sounds_r(int i); +void respawnhitag_d(DDukeActor* g_sp); +void respawnhitag_r(DDukeActor* g_sp); +void checktimetosleep_d(DDukeActor* actor); +void checktimetosleep_r(DDukeActor* actor); +void move_d(DDukeActor* i, int g_p, int g_x); +void move_r(DDukeActor* i, int g_p, int g_x); void incur_damage_d(struct player_struct* p); void incur_damage_r(struct player_struct* p); -void shoot_d(int i, int atwith); -void shoot_r(int i, int atwith); +void shoot_d(DDukeActor* i, int atwith); +void shoot_r(DDukeActor* i, int atwith); void selectweapon_d(int snum, int j); void selectweapon_r(int snum, int j); int doincrements_d(struct player_struct* p); @@ -141,7 +133,6 @@ void SetDispatcher() checkhitswitch_d, activatebysector_d, checkhitwall_d, - checkplayerhurt_d, checkhitceiling_d, checkhitsprite_d, checksectors_d, @@ -150,12 +141,10 @@ void SetDispatcher() floorspace_d, addweapon_d, hitradius_d, - movesprite_d, lotsofmoney_d, lotsofmail_d, lotsofpaper_d, guts_d, - gutsdir_d, ifhitsectors_d, ifhitbyweapon_d, fall_d, @@ -163,8 +152,6 @@ void SetDispatcher() respawnhitag_d, checktimetosleep_d, move_d, - spawn_d, - check_fta_sounds_d, incur_damage_d, shoot_d, @@ -193,7 +180,6 @@ void SetDispatcher() checkhitswitch_r, activatebysector_r, checkhitwall_r, - checkplayerhurt_r, checkhitceiling_r, checkhitsprite_r, checksectors_r, @@ -202,12 +188,10 @@ void SetDispatcher() floorspace_r, addweapon_r, hitradius_r, - movesprite_r, lotsoffeathers_r, lotsoffeathers_r, lotsoffeathers_r, guts_r, - gutsdir_r, ifhitsectors_r, ifhitbyweapon_r, fall_r, @@ -215,8 +199,6 @@ void SetDispatcher() respawnhitag_r, checktimetosleep_r, move_r, - spawn_r, - check_fta_sounds_r, incur_damage_r, shoot_r, diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index c6c3bd9bb..17a513a12 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -75,38 +75,33 @@ struct Dispatcher bool (*isadoorwall)(int dapic); void (*animatewalls)(); void (*operaterespawns)(int low); - void (*operateforcefields)(int s, int low); - bool (*checkhitswitch)(int snum, int w, int switchtype); - void (*activatebysector)(int sect, int j); - void (*checkhitwall)(int spr, int dawallnum, int x, int y, int z, int atwith); - void (*checkplayerhurt)(struct player_struct* p, int j); + void (*operateforcefields)(DDukeActor* act, int low); + bool (*checkhitswitch)(int snum, int w, DDukeActor* act); + void (*activatebysector)(int sect, DDukeActor* j); + void (*checkhitwall)(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith); bool (*checkhitceiling)(int sn); - void (*checkhitsprite)(int i, int sn); + void (*checkhitsprite)(DDukeActor* i, DDukeActor* sn); void (*checksectors)(int low); bool (*ceilingspace)(int sectnum); bool (*floorspace)(int sectnum); void (*addweapon)(struct player_struct *p, int weapon); - void (*hitradius)(short i, int r, int hp1, int hp2, int hp3, int hp4); - int (*movesprite)(int spritenum, int xchange, int ychange, int zchange, unsigned int cliptype); + void (*hitradius)(DDukeActor* i, int r, int hp1, int hp2, int hp3, int hp4); void (*lotsofmoney)(DDukeActor *s, short n); void (*lotsofmail)(DDukeActor *s, short n); void (*lotsofpaper)(DDukeActor *s, short n); - void (*guts)(spritetype* s, short gtype, short n, short p); - void (*gutsdir)(spritetype* s, short gtype, short n, short p); - int (*ifhitsectors)(int sectnum); + void (*guts)(DDukeActor* s, short gtype, short n, short p); + DDukeActor* (*ifhitsectors)(int sectnum); int (*ifhitbyweapon)(DDukeActor* sectnum); - void (*fall)(int g_i, int g_p); + void (*fall)(DDukeActor* actor, int g_p); bool (*spawnweapondebris)(int picnum, int dnum); - void (*respawnhitag)(spritetype* g_sp); - void (*checktimetosleep)(int g_i); - void (*move)(int g_i, int g_p, int g_x); - int (*spawn)(int j, int pn); - void (*check_fta_sounds)(int i); + void (*respawnhitag)(DDukeActor* g_sp); + void (*checktimetosleep)(DDukeActor* actor); + void (*move)(DDukeActor* i, int g_p, int g_x); // player void (*incur_damage)(struct player_struct* p); - void (*shoot)(int, int); + void (*shoot)(DDukeActor*, int); void (*selectweapon)(int snum, int j); int (*doincrements)(struct player_struct* p); void (*checkweapons)(struct player_struct* p); diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index a6f3ea951..611269542 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -68,6 +68,22 @@ public: } }; +class DukeLinearSpriteIterator +{ + int index = 0; +public: + + DDukeActor* Next() + { + while (index < MAXSPRITES) + { + auto p = &hittype[index++]; + if (p->s.statnum != MAXSTATUS) return p; + } + return nullptr; + } +}; + inline DDukeActor* player_struct::GetActor() { return &hittype[i]; @@ -116,31 +132,6 @@ inline int setsprite(int i, int x, int y, int z) return ::setsprite(i, x, y, z); } -inline int S_PlayActorSound(int soundNum, DDukeActor* spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0) -{ - return S_PlayActorSound(soundNum, spriteNum ? spriteNum->GetIndex() : -1, channel, flags); -} - -inline void S_StopSound(int sndNum, DDukeActor* actor, int flags = -1) -{ - S_StopSound(sndNum, actor ? actor->GetIndex() : -1, flags); -} - -inline void S_RelinkActorSound(DDukeActor* from, DDukeActor* to) -{ - S_RelinkActorSound(from ? from->GetIndex() : -1, to ? to->GetIndex() : -1); -} - -inline int S_CheckActorSoundPlaying(DDukeActor* a, int soundNum, int channel = 0) -{ - return S_CheckActorSoundPlaying(a->GetIndex(), soundNum, channel); -} - -inline DDukeActor* EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, DDukeActor* Owner, signed char s_ss) -{ - return &hittype[EGS(whatsect, s_x, s_y, s_z, s_pn, s_s, s_xr, s_yr, s_a, s_ve, s_zv, Owner ? Owner->GetIndex() : -1, s_ss)]; -} - inline int ActorToScriptIndex(DDukeActor* a) { if (!a) return -1; @@ -154,14 +145,12 @@ inline DDukeActor* ScriptIndexToActor(int index) return &hittype[index]; } -inline bool wallswitchcheck(DDukeActor* s) -{ - return !!(tileinfo[s->s.picnum].flags & TFLAG_WALLSWITCH); -} +int spawn_d(int j, int pn); +int spawn_r(int j, int pn); inline DDukeActor* spawn(DDukeActor* spawner, int type) { - int i = fi.spawn(spawner ? spawner->GetIndex() : -1, type); + int i = (isRR()? spawn_r : spawn_d)(spawner ? spawner->GetIndex() : -1, type); return i == -1 ? nullptr : &hittype[i]; } @@ -185,79 +174,52 @@ inline int bossguy(DDukeActor* pSprite) return bossguypic(pSprite->s.picnum); } -inline int GetGameVarID(int id, DDukeActor* sActor, int sPlayer) -{ - return GetGameVarID(id, sActor->GetIndex(), sPlayer); -} - -inline void SetGameVarID(int id, int lValue, DDukeActor* sActor, int sPlayer) -{ - SetGameVarID(id, lValue, sActor->GetIndex(), sPlayer); -} - // old interface versions of already changed functions -inline void RANDOMSCRAP(spritetype* s, int i) -{ - return RANDOMSCRAP(&hittype[s - sprite]); -} - inline void deletesprite(int num) { deletesprite(&hittype[num]); } -inline int ssp(int i, unsigned int cliptype) //The set sprite function -{ - return ssp(&hittype[i], cliptype); -} - int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result); int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result); -inline int movesprite_d(int actor, int xchange, int ychange, int zchange, unsigned int cliptype) -{ - Collision c; - movesprite_ex_d(&hittype[actor], xchange, ychange, zchange, cliptype, c); - return c.legacyVal; -} - -inline int movesprite_r(int actor, int xchange, int ychange, int zchange, unsigned int cliptype) -{ - Collision c; - movesprite_ex_r(&hittype[actor], xchange, ychange, zchange, cliptype, c); - return c.legacyVal; -} - inline int movesprite_ex(DDukeActor* actor, int xchange, int ychange, int zchange, unsigned int cliptype, Collision& result) { auto f = isRR() ? movesprite_ex_r : movesprite_ex_d; return f(actor, xchange, ychange, zchange, cliptype, result); } -inline void ms(short i) +inline int clipmove_ex(int* x, int* y, int* z, short* sect, int xv, int yv, int wal, int ceil, int flor, int ct, Collision& result) { - ms(&hittype[i]); + int res = clipmove(x, y, z, sect, xv, yv, wal, ceil, flor, ct); + return result.setFromEngine(res); } -inline void execute(DDukeActor* act, int a, int b) +inline void getzrange_ex(int x, int y, int z, int16_t sectnum, int32_t* ceilz, Collision& ceilhit, int32_t* florz, Collision& florhit, int32_t walldist, uint32_t cliptype) { - execute(act->GetIndex(), a, b); + int ch, fh; + getzrange(x, y, z, sectnum, ceilz, &ch, florz, &fh, walldist, cliptype); + ceilhit.setFromEngine(ch); + florhit.setFromEngine(fh); } -inline void makeitfall(DDukeActor* act) +inline int hitscan(int x, int y, int z, int16_t sectnum, int32_t vx, int32_t vy, int32_t vz, + short* hitsect, short* hitwall, DDukeActor** hitspr, int* hitx, int* hity, int* hitz, uint32_t cliptype) { - makeitfall(act->GetIndex()); + short hitsprt; + int res = ::hitscan(x, y, z, sectnum, vx, vy, vz, hitsect, hitwall, &hitsprt, hitx, hity, hitz, cliptype); + if (hitspr) *hitspr = hitsprt == -1 ? nullptr : &hittype[hitsprt]; + return res; } -inline void getglobalz(DDukeActor* act) +inline void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange, + int16_t* neartagsector, int16_t* neartagwall, DDukeActor** neartagsprite, + int32_t* neartaghitdist, int32_t neartagrange, uint8_t tagsearch) { - getglobalz(act->GetIndex()); -} - -inline int findplayer(DDukeActor* act, int* x) -{ - return findplayer(&act->s, x); + int16_t nts; + ::neartag(xs, ys, zs, sectnum, ange, neartagsector, neartagwall, &nts, neartaghitdist, neartagrange, tagsearch); + *neartagsprite = nts == -1 ? nullptr : &hittype[nts]; } END_DUKE_NS diff --git a/source/games/duke/src/flags_d.cpp b/source/games/duke/src/flags_d.cpp index 11f2dec90..81656ac3c 100644 --- a/source/games/duke/src/flags_d.cpp +++ b/source/games/duke/src/flags_d.cpp @@ -40,6 +40,14 @@ BEGIN_DUKE_NS void initactorflags_d() { + actorinfo[COMMANDER].gutsoffset = -(24 << 8); + + for (auto &fa : actorinfo) + { + fa.falladjustz = 24 << 8; + } + actorinfo[OCTABRAIN].falladjustz = actorinfo[COMMANDER].falladjustz = actorinfo[DRONE].falladjustz = 0; + setflag(SFLAG_INTERNAL_BADGUY, { SHARK, RECON, diff --git a/source/games/duke/src/flags_r.cpp b/source/games/duke/src/flags_r.cpp index 900dc7ac7..8319b9d06 100644 --- a/source/games/duke/src/flags_r.cpp +++ b/source/games/duke/src/flags_r.cpp @@ -34,6 +34,19 @@ BEGIN_DUKE_NS void initactorflags_r() { + for (auto &fa : actorinfo) + { + fa.falladjustz = 24 << 8; + } + if (isRRRA()) + { + actorinfo[HULKBOAT].falladjustz = 12 << 8; + actorinfo[MINIONBOAT].falladjustz = 3 << 8; + actorinfo[CHEERBOAT].falladjustz = actorinfo[EMPTYBOAT].falladjustz = 6 << 8; + } + actorinfo[DRONE].falladjustz = 0; + + setflag(SFLAG_INTERNAL_BADGUY|SFLAG_KILLCOUNT, { BOULDER, BOULDER1, diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 148b06e1a..6212c3aea 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -17,8 +17,8 @@ BEGIN_DUKE_NS void lava_cleararrays(); void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int h); void addminecart(int p1, int p2, int i, int iht, int p3, int childsectnum); -void addtorch(int i); -void addlightning(int i); +void addtorch(spritetype* i); +void addlightning(spritetype* i); void movecyclers(void); void movedummyplayers(void); @@ -31,82 +31,88 @@ void moveclouds(double smoothratio); void RANDOMSCRAP(DDukeActor* i); void ms(DDukeActor* i); void movecrane(DDukeActor* i, int crane); -void movefountain(int i, int fountain); -void moveflammable(int i, int tire, int box, int pool); -void detonate(int i, int explosion); -void movemasterswitch(int i, int spectype1, int spectype2); -void movetrash(int i); -void movewaterdrip(int i, int drip); -void movedoorshock(int i); -void movetouchplate(int i, int plate); -void movecanwithsomething(int i); -void bounce(int i); -void movetongue(int i, int tongue, int jaw); -void rpgexplode(int i, int j, const vec3_t& pos, int EXPLOSION2, int EXPLOSION2BOT, int newextra, int playsound); -void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion); +void movefountain(DDukeActor* i, int fountain); +void moveflammable(DDukeActor* i, int tire, int box, int pool); +void detonate(DDukeActor* i, int explosion); +void movemasterswitch(DDukeActor* i, int spectype1, int spectype2); +void movetrash(DDukeActor* i); +void movewaterdrip(DDukeActor* i, int drip); +void movedoorshock(DDukeActor* i); +void movetouchplate(DDukeActor* i, int plate); +void movecanwithsomething(DDukeActor* i); +void bounce(DDukeActor* i); +void movetongue(DDukeActor* i, int tongue, int jaw); +void rpgexplode(DDukeActor* i, int j, const vec3_t& pos, int EXPLOSION2, int EXPLOSIONBOT2, int newextra, int playsound); +void moveooz(DDukeActor* i, int seenine, int seeninedead, int ooz, int explosion); void lotsofstuff(DDukeActor* s, int n, int spawntype); -bool respawnmarker(int i, int yellow, int green); -bool rat(int i, bool makesound); -bool queball(int i, int pocket, int queball, int stripeball); -void forcesphere(int i, int forcesphere); -void recon(int i, int explosion, int firelaser, int attacksnd, int painsnd, int roamsnd, int shift, int (*getspawn)(int i)); -void ooz(int i); -void reactor(int i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BURNT, int REACTORSPARK, int REACTOR2SPARK); -void camera(int i); -void forcesphere(int i); -void watersplash2(int i); -void frameeffect1(int i); -bool money(int i, int BLOODPOOL); -bool jibs(int i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, bool zcheck1, bool zcheck2); -bool bloodpool(int i, bool puke, int TIRE); -void shell(int i, bool morecheck); -void glasspieces(int i); -void scrap(int i, int SCRAP1, int SCRAP6); +bool respawnmarker(DDukeActor* i, int yellow, int green); +bool rat(DDukeActor* i, bool makesound); +bool queball(DDukeActor* i, int pocket, int queball, int stripeball); +void forcesphere(DDukeActor* i, int forcesphere); +void recon(DDukeActor* i, int explosion, int firelaser, int attacksnd, int painsnd, int roamsnd, int shift, int (*getspawn)(DDukeActor* i)); +void ooz(DDukeActor* i); +void reactor(DDukeActor* i, int REACTOR, int REACTOR2, int REACTORBURNT, int REACTOR2BURNT, int REACTORSPARK, int REACTOR2SPARK); +void camera(DDukeActor* i); +void forcesphereexplode(DDukeActor* i); +void watersplash2(DDukeActor* i); +void frameeffect1(DDukeActor* i); +bool money(DDukeActor* i, int BLOODPOOL); +bool jibs(DDukeActor* i, int JIBS6, bool timeout, bool callsetsprite, bool floorcheck, bool zcheck1, bool zcheck2); +bool bloodpool(DDukeActor* i, bool puke, int TIRE); +void shell(DDukeActor* i, bool morecheck); +void glasspieces(DDukeActor* i); +void scrap(DDukeActor* i, int SCRAP1, int SCRAP6); -void handle_se00(int i, int LASERLINE); -void handle_se01(int i); -void handle_se14(int i, bool checkstat, int RPG, int JIBS6); -void handle_se30(int i, int JIBS6); -void handle_se02(int i); -void handle_se03(int i); -void handle_se04(int i); -void handle_se05(int i, int FIRELASER); -void handle_se08(int i, bool checkhitag1); -void handle_se10(int i, const int *); -void handle_se11(int i); -void handle_se12(int i, int planeonly = 0); -void handle_se13(int i); -void handle_se15(int i); -void handle_se16(int i, int REACTOR, int REACTOR2); -void handle_se17(int i); -void handle_se18(int i, bool morecheck); -void handle_se19(int i, int BIGFORCE); -void handle_se20(int i); -void handle_se21(int i); -void handle_se22(int i); -void handle_se26(int i); -void handle_se27(int i); -void handle_se32(int i); -void handle_se35(int i, int SMALLSMOKE, int EXPLOSION2); -void handle_se128(int i); -void handle_se130(int i, int countmax, int EXPLOSION2); +void handle_se00(DDukeActor* i, int LASERLINE); +void handle_se01(DDukeActor* i); +void handle_se14(DDukeActor* i, bool checkstat, int RPG, int JIBS6); +void handle_se30(DDukeActor* i, int JIBS6); +void handle_se02(DDukeActor* i); +void handle_se03(DDukeActor* i); +void handle_se04(DDukeActor* i); +void handle_se05(DDukeActor* i, int FIRELASER); +void handle_se08(DDukeActor* i, bool checkhitag1); +void handle_se10(DDukeActor* i, const int *); +void handle_se11(DDukeActor* i); +void handle_se12(DDukeActor* i, int planeonly = 0); +void handle_se13(DDukeActor* i); +void handle_se15(DDukeActor* i); +void handle_se16(DDukeActor* i, int REACTOR, int REACTOR2); +void handle_se17(DDukeActor* i); +void handle_se18(DDukeActor* i, bool morecheck); +void handle_se19(DDukeActor* i, int BIGFORCE); +void handle_se20(DDukeActor* i); +void handle_se21(DDukeActor* i); +void handle_se22(DDukeActor* i); +void handle_se24(DDukeActor* actor, int16_t* list1, int16_t* list2, int TRIPBOMB, int LASERLINE, int CRANE, int shift); +void handle_se25(DDukeActor* a, int t_index, int snd1, int snd2); +void handle_se26(DDukeActor* i); +void handle_se27(DDukeActor* i); +void handle_se31(DDukeActor* a, bool choosedir); +void handle_se32(DDukeActor* i); +void handle_se35(DDukeActor* i, int SMALLSMOKE, int EXPLOSION2); +void handle_se128(DDukeActor* i); +void handle_se130(DDukeActor* i, int countmax, int EXPLOSION2); void respawn_rrra(DDukeActor* oldact, DDukeActor* newact); +// This is only called from game specific code so it does not need an indirection. +void check_fta_sounds_d(DDukeActor* i); +void check_fta_sounds_r(DDukeActor* i); -int dodge(spritetype*); -void alterang(int a, int g_i, int g_p); -void fall_common(int g_i, int g_p, int JIBS6, int DRONE, int BLOODPOOL, int SHOTSPARK1, int squished, int thud, int(*fallspecial)(int, int), void (*falladjustz)(spritetype*)); +int dodge(DDukeActor*); +void alterang(int ang, DDukeActor* actor, int g_p); +void fall_common(DDukeActor* actor, int g_p, int JIBS6, int DRONE, int BLOODPOOL, int SHOTSPARK1, int squished, int thud, int(*fallspecial)(DDukeActor*, int)); void checkavailweapon(struct player_struct* p); void deletesprite(DDukeActor* num); void addammo(int weapon, struct player_struct* p, int amount); int ssp(DDukeActor* i, unsigned int cliptype); //The set sprite function void insertspriteq(DDukeActor *i); -int wakeup(int sn, int pn); +int wakeup(DDukeActor* sn, int pn); int timedexit(int snum); -void dokneeattack(int snum, int pi, const std::initializer_list& respawnlist); +void dokneeattack(int snum, const std::initializer_list& respawnlist); int endoflevel(int snum); void playerisdead(int snum, int psectlotag, int fz, int cz); void footprints(int snum); @@ -122,31 +128,28 @@ void playerAimUp(int snum, ESyncBits actions); void playerAimDown(int snum, ESyncBits actions); bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, fixed_t q16horiz, double smoothratio); void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n); -int hits(int i); -int hitasprite(int i, short* hitsp); -int aim(spritetype* s, int aang); +DDukeActor* aim(DDukeActor* s, int aang); void checkweapons(struct player_struct* const p); int findotherplayer(int p, int* d); void quickkill(struct player_struct* p); -void setpal(struct player_struct* p); +int setpal(struct player_struct* p); int madenoise(int playerNum); int haskey(int sect, int snum); -void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST); +void shootbloodsplat(DDukeActor* i, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST); -void breakwall(short newpn, short spr, short dawallnum); -void callsound2(int soundNum, int playerNum); -int callsound(int sectnum,int snum); -int hitasprite(int snum,short *hitSprite); -int findplayer(const spritetype* s, int* dist); +void breakwall(short newpn, DDukeActor* spr, short dawallnum); +int callsound(int sectnum,DDukeActor* snum); +int hitasprite(DDukeActor* snum,DDukeActor **hitSprite); +int findplayer(const DDukeActor* s, int* dist); void operatejaildoors(int hitag); void allignwarpelevators(void); bool isablockdoor(int tileNum); -bool activatewarpelevators(int s, int w); +bool activatewarpelevators(DDukeActor* s, int w); int check_activator_motion(int lotag); void operateactivators(int l, int w); -void operateforcefields_common(int s, int low, const std::initializer_list& tiles); +void operateforcefields_common(DDukeActor* s, int low, const std::initializer_list& tiles); void operatemasterswitches(int lotag); -void operatesectors(int s, int i); +void operatesectors(int s, DDukeActor* i); void hud_input(int playerNum); int getanimationgoal(int animtype, int animindex); bool isanearoperator(int lotag); @@ -155,41 +158,43 @@ int setanimation(short animsect, int animtype, int animindex, int thegoal, int t void dofurniture(int wallNum, int sectnum, int playerNum); void dotorch(); int hitawall(struct player_struct* pl, int* hitWall); -int hits(int snum); +int hits(DDukeActor* snum); void clearsectinterpolate(int sprnum); -void setsectinterpolate(int sprnum); -int LocateTheLocator(int const tag, int const sectnum); +void setsectinterpolate(int sectnum); +DDukeActor* LocateTheLocator(int n, int sectnum); void clearcamera(player_struct* ps); void showtwoscreens(const CompletionFunc& func); void doorders(const CompletionFunc& func); -void LoadActor(int i, int p, int x); -void execute(int s, int p, int d); -void makeitfall(int s); -int furthestangle(int snum, int angDiv); -void getglobalz(int s); -void OnEvent(int id, int pnum = -1, int snum = -1, int dist = -1); +void LoadActor(DDukeActor* i, int p, int x); +void execute(DDukeActor* s, int p, int d); +void makeitfall(DDukeActor* s); +int furthestangle(DDukeActor* snum, int angDiv); +void getglobalz(DDukeActor* s); +void OnEvent(int id, int pnum = -1, DDukeActor* snum = nullptr, int dist = -1); -short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, short s_ow, signed char s_ss); -void ceilingglass(int snum, int sectnum, int cnt); -void spriteglass(int snum, int cnt); -void lotsofcolourglass(int snum, int wallNum, int cnt); -void lotsofglass(int snum, int wallnum, int cnt); +DDukeActor* EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, DDukeActor* s_ow, signed char s_ss); +void ceilingglass(DDukeActor* snum, int sectnum, int cnt); +void spriteglass(DDukeActor* snum, int cnt); +void lotsofcolourglass(DDukeActor* snum, int wallNum, int cnt); +void lotsofglass(DDukeActor* snum, int wallnum, int cnt); +void checkplayerhurt_d(struct player_struct* p, const Collision& coll); +void checkplayerhurt_r(struct player_struct* p, const Collision& coll); -void addspritetodelete(int spnum); +void addspritetodelete(int spnum=0); void checkavailinven(struct player_struct* p); -int initspriteforspawn(int j, int pn, const std::initializer_list &excludes); -void spawninitdefault(int j, int i); -void spawntransporter(int j, int i, bool beam); -int spawnbloodpoolpart1(int j, int i); -void initfootprint(int j, int i); -void initshell(int j, int i, bool isshell); -void initcrane(int j, int i, int CRANEPOLE); -void initwaterdrip(int j, int i); -int initreactor(int j, int i, bool isrecon); -void spawneffector(int i); +int initspriteforspawn(DDukeActor* j, int pn, const std::initializer_list &excludes); +void spawninitdefault(DDukeActor* actj, DDukeActor* act); +void spawntransporter(DDukeActor* actj, DDukeActor* acti, bool beam); +int spawnbloodpoolpart1(DDukeActor* actj, DDukeActor* acti); +void initfootprint(DDukeActor* actj, DDukeActor* acti); +void initshell(DDukeActor* actj, DDukeActor* acti, bool isshell); +void initcrane(DDukeActor* actj, DDukeActor* acti, int CRANEPOLE); +void initwaterdrip(DDukeActor* actj, DDukeActor* acti); +int initreactor(DDukeActor* actj, DDukeActor* acti, bool isrecon); +void spawneffector(DDukeActor* actor); void gameexitfrommenu(); int startrts(int lumpNum, int localPlayer); @@ -203,12 +208,12 @@ void cacheit_d(); void cacheit_r(); void FTA(int q, struct player_struct* p); -void OnMotorcycle(player_struct *pl, int snum); +void OnMotorcycle(player_struct *pl, DDukeActor* snum); void OffMotorcycle(player_struct *pl); -void OnBoat(player_struct *pl, int snum); +void OnBoat(player_struct *pl, DDukeActor* snum); void OffBoat(player_struct *pl); -void cameratext(int i); +void cameratext(DDukeActor* i); void dobonus(int bonusonly, const CompletionFunc& completion); void dobonus_d(int bonusonly, const CompletionFunc& completion); void dobonus_r(int bonusonly, const CompletionFunc& completion); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 08a282fff..efbd1425c 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -291,7 +291,7 @@ void GameInterface::app_init() ud.multimode = 1; ud.m_monsters_off = userConfig.nomonsters; ps[0].aim_mode = 1; - ud.camerasprite = -1; + ud.cameraactor = nullptr; if (fileSystem.FileExists("DUKESW.BIN")) g_gameType |= GAMEFLAG_SHAREWARE; @@ -325,7 +325,6 @@ void GameInterface::app_init() registerosdcommands(); screenpeek = myconnectindex; - ps[myconnectindex].palette = BASEPAL; for (int j = numplayers; j < ud.multimode; j++) { diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 6cefab2ec..6e0b78491 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -43,6 +43,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "sbar.h" #include "glbackend/glbackend.h" #include "gamestate.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -248,12 +249,12 @@ void drawoverlays(double smoothratio) MarkSectorSeen(pp->cursectnum); - if (ud.camerasprite == -1) + if (ud.cameraactor == nullptr) { if (automapMode != am_full) { - if (!isRR() && pp->newowner >= 0) - cameratext(pp->newowner); + if (!isRR() && pp->newOwner != nullptr) + cameratext(pp->newOwner); else { fi.displayweapon(screenpeek, smoothratio); @@ -268,7 +269,7 @@ void drawoverlays(double smoothratio) { dointerpolations(smoothratio); - if (pp->newowner == -1 && playrunning()) + if (pp->newOwner == nullptr && playrunning()) { if (screenpeek == myconnectindex && numplayers > 1) { @@ -298,7 +299,7 @@ void drawoverlays(double smoothratio) StatusBar->UpdateStatusBar(); - if (ps[myconnectindex].newowner == -1 && ud.camerasprite == -1) + if (ps[myconnectindex].newOwner == nullptr && ud.cameraactor == nullptr) { DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -getHalfLookAng(pp->angle.olook_ang.asq16(), pp->angle.look_ang.asq16(), cl_syncinput, smoothratio), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1); } @@ -316,14 +317,14 @@ void drawoverlays(double smoothratio) // //--------------------------------------------------------------------------- -void cameratext(int i) +void cameratext(DDukeActor *cam) { auto drawitem = [=](int tile, double x, double y, bool flipx, bool flipy) { DrawTexture(twod, tileGetTexture(tile), x, y, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_CenterOffsetRel, true, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1, DTA_FlipX, flipx, DTA_FlipY, flipy, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE); }; - if (!hittype[i].temp_data[0]) + if (!cam->temp_data[0]) { drawitem(TILE_CAMCORNER, 24, 33, false, false); drawitem(TILE_CAMCORNER + 1, 320 - 26, 33, false, false); @@ -416,16 +417,16 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang) yvect2 = mulscale16(yvect, yxaspect); //Draw sprites - k = ps[screenpeek].i; + auto pactor = ps[screenpeek].GetActor(); for (i = 0; i < numsectors; i++) { if (!gFullMap || !show2dsector[i]) continue; - SectIterator it(i); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(i); + while (auto act = it.Next()) { - spr = &sprite[j]; + spr = &act->s; - if (j == k || (spr->cstat & 0x8000) || spr->cstat == 257 || spr->xrepeat == 0) continue; + if (act == pactor || (spr->cstat & 0x8000) || spr->cstat == 257 || spr->xrepeat == 0) continue; col = PalEntry(0, 170, 170); if (spr->cstat & 1) col = PalEntry(170, 0, 170); @@ -563,9 +564,10 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang) for (p = connecthead; p >= 0; p = connectpoint2[p]) { - ox = sprite[ps[p].i].x - cposx; - oy = sprite[ps[p].i].y - cposy; - daang = (sprite[ps[p].i].ang - cang) & 2047; + auto pspr = &ps[p].GetActor()->s; + ox = pspr->x - cposx; + oy = pspr->y - cposy; + daang = (pspr->ang - cang) & 2047; x1 = mulscale(ox, xvect, 16) - mulscale(oy, yvect, 16); y1 = mulscale(oy, xvect2, 16) + mulscale(ox, yvect2, 16); @@ -573,19 +575,19 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang) if (p == screenpeek || ud.coop == 1) { auto& pp = ps[p]; - if (sprite[pp.i].xvel > 16 && pp.on_ground) + if (pspr->xvel > 16 && pp.on_ground) i = TILE_APLAYERTOP + ((ud.levelclock >> 4) & 3); else i = TILE_APLAYERTOP; j = klabs(pp.truefz - pp.posz) >> 8; - j = mulscale(czoom * (sprite[pp.i].yrepeat + j), yxaspect, 16); + j = mulscale(czoom * (pspr->yrepeat + j), yxaspect, 16); if (j < 22000) j = 22000; else if (j > (65536 << 1)) j = (65536 << 1); - DrawTexture(twod, tileGetTexture(i), xdim / 2. + x1 / 4096., ydim / 2. + y1 / 4096., DTA_TranslationIndex, TRANSLATION(Translation_Remap + pp.palette, sprite[pp.i].pal), DTA_CenterOffset, true, - DTA_Rotate, daang * (-360./2048), DTA_Color, shadeToLight(sprite[pp.i].shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); + DrawTexture(twod, tileGetTexture(i), xdim / 2. + x1 / 4096., ydim / 2. + y1 / 4096., DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), pspr->pal), DTA_CenterOffset, true, + DTA_Rotate, daang * (-360./2048), DTA_Color, shadeToLight(pspr->shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); } } return true; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index a4213bb9a..d0b9edcdc 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -68,24 +68,24 @@ enum playeraction_t { struct ParseState { - int g_i, g_p; + int g_p; int g_x; int* g_t; uint8_t killit_flag; - spritetype* g_sp; DDukeActor *g_ac; int* insptr; + Collision coll; int parse(void); void parseifelse(int condition); }; -int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day); -bool ifsquished(int i, int p); -void fakebubbaspawn(int g_i, int g_p); +int furthestcanseepoint(DDukeActor* i, DDukeActor* ts, int* dax, int* day); +bool ifsquished(DDukeActor* i, int p); +void fakebubbaspawn(DDukeActor* actor, int g_p); void tearitup(int sect); -void destroyit(int g_i); -void mamaspawn(int g_i); +void destroyit(DDukeActor* actor); +void mamaspawn(DDukeActor* actor); void forceplayerangle(int snum); bool killthesprite = false; @@ -95,7 +95,7 @@ void addspritetodelete(int spnum) killthesprite = true; } -static void DoUserDef(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPlayer, int lParm2) +static void DoUserDef(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, int sPlayer, int lParm2) { int lValue; @@ -136,8 +136,8 @@ static void DoUserDef(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, break; case USERDEFS_CAMERASPRITE: - if (bSet) ud.camerasprite = lValue; - else SetGameVarID((int)lVar2, ud.camerasprite, sActor, sPlayer); + if (bSet) ud.cameraactor = ScriptIndexToActor(lValue); + else SetGameVarID((int)lVar2, ActorToScriptIndex(ud.cameraactor), sActor, sPlayer); break; case USERDEFS_LAST_CAMSPRITE: @@ -262,7 +262,7 @@ static void DoUserDef(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, } /////////////////////////////////////////// -void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPlayer, int lParm2) +void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, int sPlayer, int lParm2) { int iPlayer; int lValue; @@ -538,8 +538,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; case PLAYER_NEWOWNER: - if (bSet) ps[iPlayer].newowner = lValue; - else SetGameVarID((int)lVar2, ps[iPlayer].newowner, sActor, sPlayer); + if (bSet) ps[iPlayer].newOwner = ScriptIndexToActor(lValue); + else SetGameVarID((int)lVar2, ActorToScriptIndex(ps[iPlayer].newOwner), sActor, sPlayer); break; case PLAYER_HURT_DELAY: @@ -578,8 +578,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; case PLAYER_ACCESS_SPRITENUM: - if (bSet) ps[iPlayer].access_spritenum = lValue; - else SetGameVarID((int)lVar2, ps[iPlayer].access_spritenum, sActor, sPlayer); + if (bSet) ps[iPlayer].access_spritenum = ScriptIndexToActor(lValue); + else SetGameVarID((int)lVar2, ActorToScriptIndex(ps[iPlayer].access_spritenum), sActor, sPlayer); break; case PLAYER_KICKBACK_PIC: @@ -648,8 +648,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; case PLAYER_DUMMYPLAYERSPRITE: - if (bSet) ps[iPlayer].dummyplayersprite = lValue; - else SetGameVarID((int)lVar2, ps[iPlayer].dummyplayersprite, sActor, sPlayer); + if (bSet) ps[iPlayer].dummyplayersprite = ScriptIndexToActor(lValue); + else SetGameVarID((int)lVar2, ActorToScriptIndex(ps[iPlayer].dummyplayersprite), sActor, sPlayer); break; case PLAYER_EXTRA_EXTRA8: @@ -931,7 +931,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl } //////////////////// -void DoWall(char bSet, int lVar1, int lLabelID, int lVar2, short sActor, short sPlayer, int lParm2) +void DoWall(char bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, short sPlayer, int lParm2) { int iWall; int lValue; @@ -1018,16 +1018,15 @@ void DoWall(char bSet, int lVar1, int lLabelID, int lVar2, short sActor, short s return; } -void DoSector(char bSet, int lVar1, int lLabelID, int lVar2, short sActor, short sPlayer, int lParm2) +void DoSector(char bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, short sPlayer, int lParm2) { int iSector; int lValue; - if (lVar1 == g_iThisActorID) { // if they've asked for 'this', then use 'this'... - iSector = sprite[sActor].sectnum; + iSector = sActor->s.sectnum; } else { @@ -1133,23 +1132,24 @@ void DoSector(char bSet, int lVar1, int lLabelID, int lVar2, short sActor, short } return; } -void DoActor(char bSet, int lVar1, int lLabelID, int lVar2, short sActor, short sPlayer, int lParm2) +void DoActor(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, int sPlayer, int lParm2) { int iActor; int lValue; lValue = GetGameVarID((int)lVar2, sActor, sPlayer); + DDukeActor* act; if (lVar1 == g_iThisActorID) { // if they've asked for 'this', then use 'this'... - iActor = sActor; + act = sActor; } else { iActor = GetGameVarID((int)lVar1, sActor, sPlayer); + act = ScriptIndexToActor(iActor); } - auto act = &hittype[iActor]; auto spr = &act->s; if (iActor < 0 || iActor >= MAXSPRITES || spr->statnum == MAXSTATUS) @@ -1386,15 +1386,14 @@ void ParseState::parseifelse(int condition) // //--------------------------------------------------------------------------- -static int ifcanshoottarget(int g_i, int g_p, int g_x) +static int ifcanshoottarget(DDukeActor *actor, int g_p, int g_x) { int j; - auto g_sp = &sprite[g_i]; if (g_x > 1024) { - short temphit, sclip, angdif; + short sclip, angdif; - if (badguy(g_sp) && g_sp->xrepeat > 56) + if (badguy(actor) && actor->s.xrepeat > 56) { sclip = 3084; angdif = 48; @@ -1405,28 +1404,29 @@ static int ifcanshoottarget(int g_i, int g_p, int g_x) angdif = 16; } - j = hitasprite(g_i, &temphit); + DDukeActor* hit; + j = hitasprite(actor, &hit); if (j == (1 << 30)) { return 1; } if (j > sclip) { - if (temphit >= 0 && sprite[temphit].picnum == g_sp->picnum) + if (hit != nullptr && hit->s.picnum == actor->s.picnum) j = 0; else { - g_sp->ang += angdif; j = hitasprite(g_i, &temphit); g_sp->ang -= angdif; + actor->s.ang += angdif; j = hitasprite(actor, &hit); actor->s.ang -= angdif; if (j > sclip) { - if (temphit >= 0 && sprite[temphit].picnum == g_sp->picnum) + if (hit != nullptr && hit->s.picnum == actor->s.picnum) j = 0; else { - g_sp->ang -= angdif; j = hitasprite(g_i, &temphit); g_sp->ang += angdif; + actor->s.ang -= angdif; j = hitasprite(actor, &hit); actor->s.ang += angdif; if (j > 768) { - if (temphit >= 0 && sprite[temphit].picnum == g_sp->picnum) + if (hit != nullptr && hit->s.picnum == actor->s.picnum) j = 0; else j = 1; } @@ -1448,67 +1448,48 @@ static int ifcanshoottarget(int g_i, int g_p, int g_x) // //--------------------------------------------------------------------------- -static bool ifcansee(int g_i, int g_p) +static bool ifcansee(DDukeActor* actor, int pnum) { - auto g_sp = &sprite[g_i]; - spritetype* s; int j; + DDukeActor* tosee; + auto spr = &actor->s; // select sprite for monster to target // if holoduke is on, let them target holoduke first. // - if (ps[g_p].holoduke_on != nullptr && !isRR()) + if (ps[pnum].holoduke_on != nullptr && !isRR()) { - s = &ps[g_p].holoduke_on->s; - j = cansee(g_sp->x, g_sp->y, g_sp->z - (krand() & ((32 << 8) - 1)), g_sp->sectnum, - s->x, s->y, s->z, s->sectnum); + tosee = ps[pnum].holoduke_on; + j = cansee(spr->x, spr->y, spr->z - (krand() & ((32 << 8) - 1)), spr->sectnum, tosee->s.x, tosee->s.y, tosee->s.z, tosee->s.sectnum); if (j == 0) { // they can't see player's holoduke - // check for player... - s = &sprite[ps[g_p].i]; + // check for player.. + tosee = ps[pnum].GetActor(); } } - else s = &sprite[ps[g_p].i]; // holoduke not on. look for player + else tosee = ps[pnum].GetActor(); // holoduke not on. look for player // can they see player, (or player's holoduke) - j = cansee(g_sp->x, g_sp->y, g_sp->z - (krand() & ((47 << 8))), g_sp->sectnum, - s->x, s->y, s->z - ((isRR()? 28 : 24) << 8), s->sectnum); + j = cansee(spr->x, spr->y, spr->z - (krand() & ((47 << 8))), spr->sectnum, tosee->s.x, tosee->s.y, tosee->s.z - ((isRR()? 28 : 24) << 8), tosee->s.sectnum); if (j == 0) { - // they can't see it. - - // Huh?. This does nothing.... - // (the result is always j==0....) - if ((abs(hittype[g_i].lastvx - g_sp->x) + abs(hittype[g_i].lastvy - g_sp->y)) < - (abs(hittype[g_i].lastvx - s->x) + abs(hittype[g_i].lastvy - s->y))) - j = 0; - - // um yeah, this if() will always fire.... - if (j == 0) - { - // search around for target player - - // also modifies 'target' x&y if found.. - - j = furthestcanseepoint(g_i, s, &hittype[g_i].lastvx, &hittype[g_i].lastvy); - - if (j == -1) j = 0; - else j = 1; - } + // search around for target player + // also modifies 'target' x&y if found. + j = furthestcanseepoint(actor, tosee, &actor->lastvx, &actor->lastvy) != -1; } else { // else, they did see it. - // save where we were looking... - hittype[g_i].lastvx = s->x; - hittype[g_i].lastvy = s->y; + // save where we were looking.. + actor->lastvx = tosee->s.x; + actor->lastvy = tosee->s.y; } - if (j == 1 && (g_sp->statnum == 1 || g_sp->statnum == 6)) - hittype[g_i].timetosleep = SLEEPTIME; + if (j == 1 && (spr->statnum == STAT_ACTOR || spr->statnum == STAT_STANDABLE)) + actor->timetosleep = SLEEPTIME; return j == 1; } @@ -1519,6 +1500,7 @@ static bool ifcansee(int g_i, int g_p) int ParseState::parse(void) { int j, l, s; + auto g_sp = g_ac? &g_ac->s : nullptr; if(killit_flag) return 1; @@ -1529,7 +1511,7 @@ int ParseState::parse(void) insptr++; // HACK ALERT! The fire animation uses a broken ifrnd setup to delay its start because original CON has no variables. // But the chosen random value of 16/255 is too low and can cause delays of a second or more. - int spnum = sprite[g_i].picnum; + int spnum = g_sp->picnum; if (spnum == TILE_FIRE && g_t[4] == 0 && *insptr == 16) { parseifelse(rnd(64)); @@ -1539,31 +1521,31 @@ int ParseState::parse(void) break; } case concmd_ifcanshoottarget: - parseifelse(ifcanshoottarget(g_i, g_p, g_x)); + parseifelse(ifcanshoottarget(g_ac, g_p, g_x)); break; case concmd_ifcanseetarget: - j = cansee(g_sp->x, g_sp->y, g_sp->z - ((krand() & 41) << 8), g_sp->sectnum, ps[g_p].posx, ps[g_p].posy, ps[g_p].posz/*-((krand()&41)<<8)*/, sprite[ps[g_p].i].sectnum); + j = cansee(g_sp->x, g_sp->y, g_sp->z - ((krand() & 41) << 8), g_sp->sectnum, ps[g_p].posx, ps[g_p].posy, ps[g_p].posz/*-((krand()&41)<<8)*/, ps[g_p].GetActor()->s.sectnum); parseifelse(j); - if (j) hittype[g_i].timetosleep = SLEEPTIME; + if (j) g_ac->timetosleep = SLEEPTIME; break; case concmd_ifnocover: - j = cansee(g_sp->x, g_sp->y, g_sp->z, g_sp->sectnum, ps[g_p].posx, ps[g_p].posy, ps[g_p].posz, sprite[ps[g_p].i].sectnum); + j = cansee(g_sp->x, g_sp->y, g_sp->z, g_sp->sectnum, ps[g_p].posx, ps[g_p].posy, ps[g_p].posz, ps[g_p].GetActor()->s.sectnum); parseifelse(j); - if (j) hittype[g_i].timetosleep = SLEEPTIME; + if (j) g_ac->timetosleep = SLEEPTIME; break; case concmd_ifactornotstayput: - parseifelse(hittype[g_i].actorstayput == -1); + parseifelse(g_ac->actorstayput == -1); break; case concmd_ifcansee: - parseifelse(ifcansee(g_i, g_p)); + parseifelse(ifcansee(g_ac, g_p)); break; case concmd_ifhitweapon: parseifelse(fi.ifhitbyweapon(g_ac) >= 0); break; case concmd_ifsquished: - parseifelse(ifsquished(g_i, g_p) == 1); + parseifelse(ifsquished(g_ac, g_p) == 1); break; case concmd_ifdead: { @@ -1595,14 +1577,14 @@ int ParseState::parse(void) case concmd_ifpdistl: insptr++; parseifelse(g_x < *insptr); - if (g_x > MAXSLEEPDIST && hittype[g_i].timetosleep == 0) - hittype[g_i].timetosleep = SLEEPTIME; + if (g_x > MAXSLEEPDIST && g_ac->timetosleep == 0) + g_ac->timetosleep = SLEEPTIME; break; case concmd_ifpdistg: insptr++; parseifelse(g_x > * insptr); - if (g_x > MAXSLEEPDIST && hittype[g_i].timetosleep == 0) - hittype[g_i].timetosleep = SLEEPTIME; + if (g_x > MAXSLEEPDIST && g_ac->timetosleep == 0) + g_ac->timetosleep = SLEEPTIME; break; case concmd_else: insptr = &ScriptCode[*(insptr + 1)]; @@ -1631,7 +1613,7 @@ int ParseState::parse(void) break; case concmd_fakebubba: insptr++; - fakebubbaspawn(g_i, g_p); + fakebubbaspawn(g_ac, g_p); break; case concmd_rndmove: @@ -1640,11 +1622,11 @@ int ParseState::parse(void) insptr++; break; case concmd_mamatrigger: - operateactivators(667, ps[g_p].i); + operateactivators(667, g_p); insptr++; break; case concmd_mamaspawn: - mamaspawn(g_i); + mamaspawn(g_ac); insptr++; break; case concmd_mamaquake: @@ -1674,15 +1656,15 @@ int ParseState::parse(void) { banjosound = 273; } - S_PlayActorSound(banjosound, g_i, CHAN_WEAPON); + S_PlayActorSound(banjosound, g_ac, CHAN_WEAPON); } - else if (!S_CheckSoundPlaying(g_i, banjosound)) - S_PlayActorSound(banjosound, g_i, CHAN_WEAPON); + else if (!S_CheckActorSoundPlaying(g_ac, banjosound)) + S_PlayActorSound(banjosound, g_ac, CHAN_WEAPON); insptr++; break; case concmd_motoloopsnd: - if (!S_CheckSoundPlaying(g_i, 411)) - S_PlayActorSound(411, g_i, CHAN_VOICE); + if (!S_CheckActorSoundPlaying(g_ac, 411)) + S_PlayActorSound(411, g_ac, CHAN_VOICE); insptr++; break; case concmd_ifgotweaponce: @@ -1696,12 +1678,12 @@ int ParseState::parse(void) if (ps[g_p].weaprecs[j] == g_sp->picnum) break; - parseifelse(j < ps[g_p].weapreccnt&& g_sp->owner == g_i); + parseifelse(j < ps[g_p].weapreccnt&& g_ac->GetOwner() == g_ac); } else if (ps[g_p].weapreccnt < 16) { ps[g_p].weaprecs[ps[g_p].weapreccnt++] = g_sp->picnum; - parseifelse(g_sp->owner == g_i); + parseifelse(g_ac->GetOwner() == g_ac); } } else parseifelse(0); @@ -1713,14 +1695,14 @@ int ParseState::parse(void) else { // Copied from DukeGDX. - if (g_sp->picnum == TILE_EGG && hittype[g_i].temp_data[5] == TILE_EGG + 2 && g_sp->pal == 1) + if (g_sp->picnum == TILE_EGG && g_ac->temp_data[5] == TILE_EGG + 2 && g_sp->pal == 1) { ps[connecthead].max_actors_killed++; //revive the egg - hittype[g_i].temp_data[5] = 0; + g_ac->temp_data[5] = 0; } - g_sp->pal = hittype[g_i].tempang; + g_sp->pal = g_ac->tempang; } - hittype[g_i].tempang = 0; + g_ac->tempang = 0; break; case concmd_tossweapon: insptr++; @@ -1731,8 +1713,8 @@ int ParseState::parse(void) break; case concmd_mikesnd: insptr++; - if (!S_CheckSoundPlaying(g_i, g_sp->yvel)) - S_PlayActorSound(g_sp->yvel, g_i, CHAN_VOICE); + if (!S_CheckActorSoundPlaying(g_ac, g_sp->yvel)) + S_PlayActorSound(g_sp->yvel, g_ac, CHAN_VOICE); break; case concmd_pkick: insptr++; @@ -1758,7 +1740,7 @@ int ParseState::parse(void) insptr++; - if ((g_sp->picnum == TILE_APLAYER && g_sp->yrepeat < 36) || *insptr < g_sp->yrepeat || ((g_sp->yrepeat * (tilesiz[g_sp->picnum].y + 8)) << 2) < (hittype[g_i].floorz - hittype[g_i].ceilingz)) + if ((g_sp->picnum == TILE_APLAYER && g_sp->yrepeat < 36) || *insptr < g_sp->yrepeat || ((g_sp->yrepeat * (tilesiz[g_sp->picnum].y + 8)) << 2) < (g_ac->floorz - g_ac->ceilingz)) { j = ((*insptr) - g_sp->yrepeat) << 1; if (abs(j)) g_sp->yrepeat += ksgn(j); @@ -1776,7 +1758,7 @@ int ParseState::parse(void) break; case concmd_shoot: insptr++; - fi.shoot(g_i, (short)*insptr); + fi.shoot(g_ac, (short)*insptr); insptr++; break; case concmd_ifsoundid: @@ -1792,28 +1774,28 @@ int ParseState::parse(void) break; case concmd_soundtag: insptr++; - S_PlayActorSound(ambientlotag[g_sp->ang], g_i); + S_PlayActorSound(ambientlotag[g_sp->ang], g_ac); break; case concmd_soundtagonce: insptr++; - if (!S_CheckSoundPlaying(g_i, ambientlotag[g_sp->ang])) - S_PlayActorSound(ambientlotag[g_sp->ang], g_i); + if (!S_CheckActorSoundPlaying(g_ac, ambientlotag[g_sp->ang])) + S_PlayActorSound(ambientlotag[g_sp->ang], g_ac); break; case concmd_soundonce: insptr++; - if (!S_CheckSoundPlaying(g_i, *insptr++)) - S_PlayActorSound(*(insptr - 1), g_i); + if (!S_CheckSoundPlaying(*insptr++)) + S_PlayActorSound(*(insptr - 1), g_ac); break; case concmd_stopsound: insptr++; - if (S_CheckSoundPlaying(g_i, *insptr)) + if (S_CheckSoundPlaying(*insptr)) S_StopSound((int)*insptr); insptr++; break; case concmd_globalsound: insptr++; if (g_p == screenpeek || ud.coop == 1) - S_PlayActorSound((int)*insptr, ps[screenpeek].i); + S_PlayActorSound((int)*insptr, ps[screenpeek].GetActor()); insptr++; break; case concmd_smackbubba: @@ -1838,7 +1820,7 @@ int ParseState::parse(void) break; case concmd_sound: insptr++; - S_PlayActorSound((short) *insptr,g_i); + S_PlayActorSound((short) *insptr,g_ac); insptr++; break; case concmd_tip: @@ -1847,10 +1829,10 @@ int ParseState::parse(void) break; case concmd_iftipcow: case concmd_ifhittruck: // both have the same code. - if (hittype[g_i].spriteextra == 1) // + if (g_ac->spriteextra == 1) // { j = 1; - hittype[g_i].spriteextra++; + g_ac->spriteextra++; } else j = 0; @@ -1864,7 +1846,7 @@ int ParseState::parse(void) insptr++; g_sp->xoffset = 0; g_sp->yoffset = 0; - fi.fall(g_i, g_p); + fi.fall(g_ac, g_p); break; case concmd_enda: case concmd_break: @@ -1899,7 +1881,7 @@ int ParseState::parse(void) break; case concmd_sleeptime: insptr++; - hittype[g_i].timetosleep = (short)*insptr; + g_ac->timetosleep = (short)*insptr; insptr++; break; case concmd_paper: @@ -1911,19 +1893,19 @@ int ParseState::parse(void) insptr++; if (isRR()) { - if (hittype[g_i].spriteextra < 1 || hittype[g_i].spriteextra == 128) + if (g_ac->spriteextra < 1 || g_ac->spriteextra == 128) { - if (actorfella(g_i)) + if (actorfella(g_ac)) ps[g_p].actors_killed += *insptr; } } else ps[g_p].actors_killed += *insptr; - hittype[g_i].actorstayput = -1; + g_ac->actorstayput = -1; insptr++; break; case concmd_lotsofglass: insptr++; - spriteglass(g_i,*insptr); + spriteglass(g_ac, *insptr); insptr++; break; case concmd_killit: @@ -1960,7 +1942,7 @@ int ParseState::parse(void) case concmd_isdrunk: // todo: move out to player_r. insptr++; ps[g_p].drink_amt += *insptr; - j = sprite[ps[g_p].i].extra; + j = ps[g_p].GetActor()->s.extra; if (j > 0) j += *insptr; if (j > max_player_health * 2) @@ -1974,39 +1956,39 @@ int ParseState::parse(void) { if ((j - *insptr) < (max_player_health >> 2) && j >= (max_player_health >> 2)) - S_PlayActorSound(DUKE_GOTHEALTHATLOW, ps[g_p].i); + S_PlayActorSound(DUKE_GOTHEALTHATLOW, ps[g_p].GetActor()); ps[g_p].last_extra = j; } - sprite[ps[g_p].i].extra = j; + ps[g_p].GetActor()->s.extra = j; } if (ps[g_p].drink_amt > 100) ps[g_p].drink_amt = 100; - if (sprite[ps[g_p].i].extra >= max_player_health) + if (ps[g_p].GetActor()->s.extra >= max_player_health) { - sprite[ps[g_p].i].extra = max_player_health; + ps[g_p].GetActor()->s.extra = max_player_health; ps[g_p].last_extra = max_player_health; } insptr++; break; case concmd_strafeleft: insptr++; - fi.movesprite(g_i, sintable[(g_sp->ang + 1024) & 2047] >> 10, sintable[(g_sp->ang + 512) & 2047] >> 10, g_sp->zvel, CLIPMASK0); + movesprite_ex(g_ac, sintable[(g_sp->ang + 1024) & 2047] >> 10, sintable[(g_sp->ang + 512) & 2047] >> 10, g_sp->zvel, CLIPMASK0, coll); break; case concmd_straferight: insptr++; - fi.movesprite(g_i, sintable[(g_sp->ang - 0) & 2047] >> 10, sintable[(g_sp->ang - 512) & 2047] >> 10, g_sp->zvel, CLIPMASK0); + movesprite_ex(g_ac, sintable[(g_sp->ang - 0) & 2047] >> 10, sintable[(g_sp->ang - 512) & 2047] >> 10, g_sp->zvel, CLIPMASK0, coll); break; case concmd_larrybird: insptr++; - ps[g_p].posz = sector[sprite[ps[g_p].i].sectnum].ceilingz; - sprite[ps[g_p].i].z = ps[g_p].posz; + ps[g_p].posz = sector[ps[g_p].GetActor()->s.sectnum].ceilingz; + ps[g_p].GetActor()->s.z = ps[g_p].posz; break; case concmd_destroyit: insptr++; - destroyit(g_i); + destroyit(g_ac); break; case concmd_iseat: // move out to player_r. insptr++; @@ -2018,7 +2000,7 @@ int ParseState::parse(void) ps[g_p].drink_amt -= *insptr; if (ps[g_p].drink_amt < 0) ps[g_p].drink_amt = 0; - j = sprite[ps[g_p].i].extra; + j = ps[g_p].GetActor()->s.extra; if (g_sp->picnum != TILE_ATOMICHEALTH) { if (j > max_player_health && *insptr > 0) @@ -2050,12 +2032,12 @@ int ParseState::parse(void) { if ((j - *insptr) < (max_player_health >> 2) && j >= (max_player_health >> 2)) - S_PlayActorSound(229, ps[g_p].i); + S_PlayActorSound(229, ps[g_p].GetActor()); ps[g_p].last_extra = j; } - sprite[ps[g_p].i].extra = j; + ps[g_p].GetActor()->s.extra = j; } insptr++; @@ -2064,25 +2046,24 @@ int ParseState::parse(void) case concmd_addphealth: // todo: move out to player. insptr++; - if(!isRR() && ps[g_p].newowner >= 0) + if(!isRR() && ps[g_p].newOwner != nullptr) { - ps[g_p].newowner = -1; + ps[g_p].newOwner = nullptr; ps[g_p].posx = ps[g_p].oposx; ps[g_p].posy = ps[g_p].oposy; ps[g_p].posz = ps[g_p].oposz; ps[g_p].angle.restore(); updatesector(ps[g_p].posx,ps[g_p].posy,&ps[g_p].cursectnum); - setpal(&ps[g_p]); - StatIterator it(STAT_ACTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto j = it.Next()) { - if (sprite[j].picnum == TILE_CAMERA1) - sprite[j].yvel = 0; + if (j->s.picnum == TILE_CAMERA1) + j->s.yvel = 0; } } - j = sprite[ps[g_p].i].extra; + j = ps[g_p].GetActor()->s.extra; if(g_sp->picnum != TILE_ATOMICHEALTH) { @@ -2115,12 +2096,12 @@ int ParseState::parse(void) { if( ( j - *insptr ) < (max_player_health>>2) && j >= (max_player_health>>2) ) - S_PlayActorSound(isRR()? 229 : DUKE_GOTHEALTHATLOW,ps[g_p].i); + S_PlayActorSound(isRR()? 229 : DUKE_GOTHEALTHATLOW,ps[g_p].GetActor()); ps[g_p].last_extra = j; } - sprite[ps[g_p].i].extra = j; + ps[g_p].GetActor()->s.extra = j; } insptr++; @@ -2151,13 +2132,13 @@ int ParseState::parse(void) case concmd_spawn: insptr++; if(g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) - fi.spawn(g_i,*insptr); + spawn(g_ac,*insptr); insptr++; break; case concmd_ifwasweapon: case concmd_ifspawnedby: // these two are the same insptr++; - parseifelse( hittype[g_i].picnum == *insptr); + parseifelse( g_ac->picnum == *insptr); break; case concmd_ifai: insptr++; @@ -2191,14 +2172,14 @@ int ParseState::parse(void) s = 0; else s = (krand()%3); - l = EGS(g_sp->sectnum, + auto l = EGS(g_sp->sectnum, g_sp->x + (krand() & 255) - 128, g_sp->y + (krand() & 255) - 128, g_sp->z - (8 << 8) - (krand() & 8191), dnum + s, g_sp->shade, 32 + (krand() & 15), 32 + (krand() & 15), - krand() & 2047, (krand() & 127) + 32, -(krand() & 2047), g_i, 5); + krand() & 2047, (krand() & 127) + 32, -(krand() & 2047), g_ac, 5); if(weap) - sprite[l].yvel = weaponsandammosprites[j%14]; - else sprite[l].yvel = -1; - sprite[l].pal = g_sp->pal; + l->s.yvel = weaponsandammosprites[j%14]; + else l->s.yvel = -1; + l->s.pal = g_sp->pal; } insptr++; } @@ -2242,20 +2223,20 @@ int ParseState::parse(void) } else { - // I am not convinced this is even remotely smart to be executed from here... + // I am not convinced this is even remotely smart to be executed from here.. pickrandomspot(g_p); - g_sp->x = hittype[g_i].bposx = ps[g_p].bobposx = ps[g_p].oposx = ps[g_p].posx; - g_sp->y = hittype[g_i].bposy = ps[g_p].bobposy = ps[g_p].oposy = ps[g_p].posy; - g_sp->z = hittype[g_i].bposy = ps[g_p].oposz = ps[g_p].posz; + g_sp->x = g_ac->bposx = ps[g_p].bobposx = ps[g_p].oposx = ps[g_p].posx; + g_sp->y = g_ac->bposy = ps[g_p].bobposy = ps[g_p].oposy = ps[g_p].posy; + g_sp->z = g_ac->bposy = ps[g_p].oposz = ps[g_p].posz; updatesector(ps[g_p].posx, ps[g_p].posy, &ps[g_p].cursectnum); - setsprite(ps[g_p].i, ps[g_p].posx, ps[g_p].posy, ps[g_p].posz + PHEIGHT); + setsprite(ps[g_p].GetActor(), ps[g_p].posx, ps[g_p].posy, ps[g_p].posz + PHEIGHT); g_sp->cstat = 257; g_sp->shade = -12; g_sp->clipdist = 64; g_sp->xrepeat = 42; g_sp->yrepeat = 36; - g_sp->owner = g_i; + g_ac->SetOwner(g_ac); g_sp->xoffset = 0; g_sp->pal = ps[g_p].palookup; @@ -2278,27 +2259,25 @@ int ParseState::parse(void) ps[g_p].falling_counter = 0; - hittype[g_i].extra = -1; - hittype[g_i].owner = g_i; + g_ac->extra = -1; - hittype[g_i].cgg = 0; - hittype[g_i].movflag = 0; - hittype[g_i].tempang = 0; - hittype[g_i].actorstayput = -1; - hittype[g_i].dispicnum = 0; - hittype[g_i].owner = ps[g_p].i; - hittype[g_i].temp_data[4] = 0; + g_ac->cgg = 0; + g_ac->movflag = 0; + g_ac->tempang = 0; + g_ac->actorstayput = -1; + g_ac->dispicnum = 0; + g_ac->SetHitOwner(ps[g_p].GetActor()); + g_ac->temp_data[4] = 0; resetinventory(g_p); resetweapons(g_p); } - setpal(&ps[g_p]); break; case concmd_ifcoop: parseifelse(ud.coop || numplayers > 2); break; case concmd_ifonmud: - parseifelse(abs(g_sp->z - sector[g_sp->sectnum].floorz) < (32 << 8) && sector[g_sp->sectnum].floorpicnum == 3073); // eew, hard coded tile numbers... :? + parseifelse(abs(g_sp->z - sector[g_sp->sectnum].floorz) < (32 << 8) && sector[g_sp->sectnum].floorpicnum == 3073); // eew, hard coded tile numbers.. :? break; case concmd_ifonwater: parseifelse( abs(g_sp->z-sector[g_sp->sectnum].floorz) < (32<<8) && sector[g_sp->sectnum].lotag == ST_1_ABOVE_WATER); @@ -2398,7 +2377,7 @@ int ParseState::parse(void) insptr++; break; case concmd_hitradius: - fi.hitradius(g_i,*(insptr+1),*(insptr+2),*(insptr+3),*(insptr+4),*(insptr+5)); + fi.hitradius(g_ac, *(insptr + 1), *(insptr + 2), *(insptr + 3), *(insptr + 4), *(insptr + 5)); insptr+=6; break; case concmd_ifp: @@ -2410,8 +2389,8 @@ int ParseState::parse(void) s = g_sp->xvel; - // sigh... this was yet another place where number literals were used as bit masks for every single value, making the code totally unreadable. - if( (l& pducking) && ps[g_p].on_ground && (PlayerInput(g_p, SB_CROUCH) ^ !!(ps[g_p].crouch_toggle) )) + // sigh.. this was yet another place where number literals were used as bit masks for every single value, making the code totally unreadable. + if( (l& pducking) && ps[g_p].on_ground && PlayerInput(g_p, SB_CROUCH)) j = 1; else if( (l& pfalling) && ps[g_p].jumping_counter == 0 && !ps[g_p].on_ground && ps[g_p].poszv > 2048 ) j = 1; @@ -2431,7 +2410,7 @@ int ParseState::parse(void) j = 1; else if( (l& pkicking) && ( ps[g_p].quick_kick > 0 || ( ps[g_p].curr_weapon == KNEE_WEAPON && ps[g_p].kickback_pic > 0 ) ) ) j = 1; - else if( (l& pshrunk) && sprite[ps[g_p].i].xrepeat < (isRR() ? 8 : 32)) + else if( (l& pshrunk) && ps[g_p].GetActor()->s.xrepeat < (isRR() ? 8 : 32)) j = 1; else if( (l& pjetpack) && ps[g_p].jetpack_on ) j = 1; @@ -2439,9 +2418,9 @@ int ParseState::parse(void) j = 1; else if( (l& ponground) && ps[g_p].on_ground) j = 1; - else if( (l& palive) && sprite[ps[g_p].i].xrepeat > (isRR() ? 8 : 32) && sprite[ps[g_p].i].extra > 0 && ps[g_p].timebeforeexit == 0 ) + else if( (l& palive) && ps[g_p].GetActor()->s.xrepeat > (isRR() ? 8 : 32) && ps[g_p].GetActor()->s.extra > 0 && ps[g_p].timebeforeexit == 0 ) j = 1; - else if( (l& pdead) && sprite[ps[g_p].i].extra <= 0) + else if( (l& pdead) && ps[g_p].GetActor()->s.extra <= 0) j = 1; else if( (l& pfacing) ) { @@ -2466,7 +2445,7 @@ int ParseState::parse(void) break; case concmd_guts: insptr += 2; - fi.guts(g_sp,*(insptr-1),*insptr,g_p); + fi.guts(g_ac,*(insptr-1),*insptr,g_p); insptr++; break; case concmd_slapplayer: @@ -2489,7 +2468,7 @@ int ParseState::parse(void) return 0; case concmd_ifgapzl: insptr++; - parseifelse( (( hittype[g_i].floorz - hittype[g_i].ceilingz ) >> 8 ) < *insptr); + parseifelse( (( g_ac->floorz - g_ac->ceilingz ) >> 8 ) < *insptr); break; case concmd_ifhitspace: parseifelse(PlayerInput(g_p, SB_OPEN)); @@ -2504,22 +2483,25 @@ int ParseState::parse(void) insptr++; if( sector[g_sp->sectnum].lotag == 0 ) { - int16_t neartagsector, neartagwall, neartagsprite; + int16_t neartagsector, neartagwall; + DDukeActor* neartagsprite; int32_t neartaghitdist; - neartag(g_sp->x,g_sp->y,g_sp->z-(32<<8),g_sp->sectnum,g_sp->ang,&neartagsector,&neartagwall,&neartagsprite,&neartaghitdist,768L,1); + neartag(g_sp->x, g_sp->y, g_sp->z - (32 << 8), g_sp->sectnum, g_sp->ang, &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 768L, 1); if( neartagsector >= 0 && isanearoperator(sector[neartagsector].lotag) ) if( (sector[neartagsector].lotag&0xff) == ST_23_SWINGING_DOOR || sector[neartagsector].floorz == sector[neartagsector].ceilingz ) if( (sector[neartagsector].lotag&16384) == 0 ) if ((sector[neartagsector].lotag & 32768) == 0) { - SectIterator it(neartagsector); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(neartagsector); + DDukeActor* a2; + while ((a2 = it.Next())) { - if (sprite[j].picnum == ACTIVATOR) + auto sj = &a2->s; + if (sj->picnum == ACTIVATOR) break; } - if (j == -1) - operatesectors(neartagsector, g_i); + if (a2 == nullptr) + operatesectors(neartagsector, g_ac); } } break; @@ -2530,7 +2512,7 @@ int ParseState::parse(void) case concmd_spritepal: insptr++; if(g_sp->picnum != TILE_APLAYER) - hittype[g_i].tempang = g_sp->pal; + g_ac->tempang = g_sp->pal; g_sp->pal = *insptr; insptr++; break; @@ -2542,23 +2524,23 @@ int ParseState::parse(void) break; case concmd_ifbulletnear: - parseifelse( dodge(g_sp) == 1); + parseifelse( dodge(g_ac) == 1); break; case concmd_ifrespawn: - if( badguy(g_sp) ) + if( badguy(g_ac) ) parseifelse( ud.respawn_monsters ); - else if( inventory(g_sp) ) + else if( inventory(&g_ac->s) ) parseifelse( ud.respawn_inventory ); else parseifelse( ud.respawn_items ); break; case concmd_iffloordistl: insptr++; - parseifelse( (hittype[g_i].floorz - g_sp->z) <= ((*insptr)<<8)); + parseifelse( (g_ac->floorz - g_sp->z) <= ((*insptr)<<8)); break; case concmd_ifceilingdistl: insptr++; - parseifelse( ( g_sp->z - hittype[g_i].ceilingz ) <= ((*insptr)<<8)); + parseifelse( ( g_sp->z - g_ac->ceilingz ) <= ((*insptr)<<8)); break; case concmd_palfrom: insptr++; @@ -2568,8 +2550,8 @@ int ParseState::parse(void) /* case 74: insptr++; - getglobalz(g_i); - parseifelse( (( hittype[g_i].floorz - hittype[g_i].ceilingz ) >> 8 ) >= *insptr); + getglobalz(g_ac); + parseifelse( (( g_ac->floorz - g_ac->ceilingz ) >> 8 ) >= *insptr); break; */ case concmd_addlog: @@ -2607,13 +2589,13 @@ int ParseState::parse(void) } else if( aGameVars[*insptr].dwFlags & GAMEVAR_FLAG_PERACTOR) { - DPrintf(DMSG_NOTIFY, " (Per Actor. Actor=%d)",g_i); + DPrintf(DMSG_NOTIFY, " (Per Actor. Actor=%p)",g_ac); } else { DPrintf(DMSG_NOTIFY, " (Global)"); } - DPrintf(DMSG_NOTIFY, " =%d", GetGameVarID(*insptr, g_i, g_p)); + DPrintf(DMSG_NOTIFY, " =%d", GetGameVarID(*insptr, g_ac, g_p)); insptr++; break; } @@ -2621,7 +2603,7 @@ int ParseState::parse(void) { int i; insptr++; i=*(insptr++); // ID of def - SetGameVarID(i, *insptr, g_i, g_p ); + SetGameVarID(i, *insptr, g_ac, g_p ); insptr++; break; } @@ -2629,7 +2611,7 @@ int ParseState::parse(void) { int i; insptr++; i=*(insptr++); // ID of def - SetGameVarID(i, GetGameVarID(*insptr, g_i, g_p), g_i, g_p ); + SetGameVarID(i, GetGameVarID(*insptr, g_ac, g_p), g_ac, g_p ); // aGameVars[i].lValue = aGameVars[*insptr].lValue; insptr++; break; @@ -2638,9 +2620,7 @@ int ParseState::parse(void) { int i; insptr++; i=*(insptr++); // ID of def -//sprintf(g_szBuf,"AddVar %d to Var ID=%d, g_i=%d, g_p=%d\n",*insptr, i, g_i, g_p); -//AddLog(g_szBuf); - SetGameVarID(i, GetGameVarID(i, g_i, g_p) + *insptr, g_i, g_p ); + SetGameVarID(i, GetGameVarID(i, g_ac, g_p) + *insptr, g_ac, g_p ); insptr++; break; } @@ -2649,7 +2629,7 @@ int ParseState::parse(void) { int i; insptr++; i=*(insptr++); // ID of def - SetGameVarID(i, GetGameVarID(i, g_i, g_p) + GetGameVarID(*insptr, g_i, g_p), g_i, g_p ); + SetGameVarID(i, GetGameVarID(i, g_ac, g_p) + GetGameVarID(*insptr, g_ac, g_p), g_ac, g_p ); insptr++; break; } @@ -2659,7 +2639,7 @@ int ParseState::parse(void) insptr++; i=*(insptr++); // ID of def j=0; - if(GetGameVarID(i, g_i, g_p) == GetGameVarID(*(insptr), g_i, g_p) ) + if(GetGameVarID(i, g_ac, g_p) == GetGameVarID(*(insptr), g_ac, g_p) ) { j=1; } @@ -2672,7 +2652,7 @@ int ParseState::parse(void) insptr++; i=*(insptr++); // ID of def j=0; - if(GetGameVarID(i, g_i, g_p) > GetGameVarID(*(insptr), g_i, g_p) ) + if(GetGameVarID(i, g_ac, g_p) > GetGameVarID(*(insptr), g_ac, g_p) ) { j=1; } @@ -2685,7 +2665,7 @@ int ParseState::parse(void) insptr++; i=*(insptr++); // ID of def j=0; - if(GetGameVarID(i, g_i, g_p) < GetGameVarID(*(insptr), g_i, g_p) ) + if(GetGameVarID(i, g_ac, g_p) < GetGameVarID(*(insptr), g_ac, g_p) ) { j=1; } @@ -2698,7 +2678,7 @@ int ParseState::parse(void) insptr++; i=*(insptr++); // ID of def j=0; - if(GetGameVarID(i, g_i, g_p) == *insptr) + if(GetGameVarID(i, g_ac, g_p) == *insptr) { j=1; } @@ -2711,7 +2691,7 @@ int ParseState::parse(void) insptr++; i=*(insptr++); // ID of def j=0; - if(GetGameVarID(i, g_i, g_p) > *insptr) + if(GetGameVarID(i, g_ac, g_p) > *insptr) { j=1; } @@ -2724,7 +2704,7 @@ int ParseState::parse(void) insptr++; i=*(insptr++); // ID of def j=0; - if(GetGameVarID(i, g_i, g_p) < *insptr) + if(GetGameVarID(i, g_ac, g_p) < *insptr) { j=1; } @@ -2733,7 +2713,7 @@ int ParseState::parse(void) } case concmd_ifphealthl: insptr++; - parseifelse( sprite[ps[g_p].i].extra < *insptr); + parseifelse( ps[g_p].GetActor()->s.extra < *insptr); break; case concmd_ifpinventory: @@ -2784,13 +2764,13 @@ int ParseState::parse(void) } case concmd_pstomp: insptr++; - if( ps[g_p].knee_incs == 0 && sprite[ps[g_p].i].xrepeat >= (isRR()? 9: 40) ) - if( cansee(g_sp->x,g_sp->y,g_sp->z-(4<<8),g_sp->sectnum,ps[g_p].posx,ps[g_p].posy,ps[g_p].posz+(16<<8),sprite[ps[g_p].i].sectnum) ) + if( ps[g_p].knee_incs == 0 && ps[g_p].GetActor()->s.xrepeat >= (isRR()? 9: 40) ) + if( cansee(g_sp->x,g_sp->y,g_sp->z-(4<<8),g_sp->sectnum,ps[g_p].posx,ps[g_p].posy,ps[g_p].posz+(16<<8),ps[g_p].GetActor()->s.sectnum) ) { ps[g_p].knee_incs = 1; if(ps[g_p].weapon_pos == 0) ps[g_p].weapon_pos = -1; - ps[g_p].actorsqu = &hittype[g_i]; + ps[g_p].actorsqu = g_ac; } break; case concmd_ifawayfromwall: @@ -2829,11 +2809,11 @@ int ParseState::parse(void) parseifelse( fi.floorspace(g_sp->sectnum)); break; case concmd_ifnotmoving: - parseifelse( (hittype[g_i].movflag&49152) > 16384 ); + parseifelse( (g_ac->movflag&kHitTypeMask) > kHitSprite ); break; case concmd_respawnhitag: insptr++; - fi.respawnhitag(g_sp); + fi.respawnhitag(g_ac); break; case concmd_ifspritepal: insptr++; @@ -2847,7 +2827,7 @@ int ParseState::parse(void) break; case concmd_ifnosounds: - parseifelse(!S_CheckAnyActorSoundPlaying(g_i) ); + parseifelse(!S_CheckAnyActorSoundPlaying(g_ac)); break; case concmd_ifplaybackon: //Twentieth Anniversary World Tour @@ -2856,28 +2836,26 @@ int ParseState::parse(void) case concmd_espawnvar: { - int lReturn; + DDukeActor* lReturn = nullptr; int lIn; - lReturn = -1; insptr++; lIn = *insptr++; - lIn = GetGameVarID(lIn, g_i, g_p); + lIn = GetGameVarID(lIn, g_ac, g_p); if (g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) - lReturn = fi.spawn(g_i, lIn); + lReturn = spawn(g_ac, lIn); - SetGameVarID(g_iReturnVarID, lReturn, g_i, g_p); + SetGameVarID(g_iReturnVarID, ActorToScriptIndex(lReturn), g_ac, g_p); break; } case concmd_espawn: { - int lReturn; - lReturn = -1; + DDukeActor* lReturn = nullptr; insptr++; if (g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) - lReturn = fi.spawn(g_i, *insptr); + lReturn = spawn(g_ac, *insptr); insptr++; - SetGameVarID(g_iReturnVarID, lReturn, g_i, g_p); + SetGameVarID(g_iReturnVarID, ActorToScriptIndex(lReturn), g_ac, g_p); break; } case concmd_setsector: @@ -2895,7 +2873,7 @@ int ParseState::parse(void) lLabelID = *(insptr++); lParm2 = *(insptr++); lVar2 = *(insptr++); - DoSector(lWhat == concmd_setsector, lVar1, lLabelID, lVar2, g_i, g_p, lParm2); + DoSector(lWhat == concmd_setsector, lVar1, lLabelID, lVar2, g_ac, g_p, lParm2); break; } case concmd_sqrt: @@ -2909,8 +2887,8 @@ int ParseState::parse(void) insptr++; lInVarID = *(insptr++); lOutVarID = *(insptr++); - lIn = GetGameVarID(lInVarID, g_i, g_p); - SetGameVarID(lOutVarID, ksqrt(lIn), g_i, g_p); + lIn = GetGameVarID(lInVarID, g_ac, g_p); + SetGameVarID(lOutVarID, ksqrt(lIn), g_ac, g_p); break; } case concmd_findnearactor: @@ -2924,9 +2902,7 @@ int ParseState::parse(void) int lMaxDist; int lVarID; int lTemp; - int lFound; int lDist; - short j; insptr++; @@ -2934,15 +2910,15 @@ int ParseState::parse(void) lMaxDist = *(insptr++); lVarID = *(insptr++); - lFound = -1; + DDukeActor* lFound = nullptr; lDist = 32767; // big number - StatIterator it(STAT_ACTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto j = it.Next()) { - if (sprite[j].picnum == lType) + if (j->s.picnum == lType) { - lTemp = ldist(&sprite[g_i], &sprite[j]); + lTemp = ldist(g_ac, j); if (lTemp < lMaxDist) { if (lTemp < lDist) @@ -2953,7 +2929,7 @@ int ParseState::parse(void) } } - SetGameVarID(lVarID, lFound, g_i, g_p); + SetGameVarID(lVarID, ActorToScriptIndex(lFound), g_ac, g_p); break; } @@ -2969,25 +2945,23 @@ int ParseState::parse(void) int lMaxDist; int lVarID; int lTemp; - int lFound; int lDist; - short j; insptr++; lType = *(insptr++); lMaxDistVar = *(insptr++); lVarID = *(insptr++); - lMaxDist = GetGameVarID(lMaxDistVar, g_i, g_p); - lFound = -1; + lMaxDist = GetGameVarID(lMaxDistVar, g_ac, g_p); + DDukeActor* lFound; lDist = 32767; // big number - StatIterator it(STAT_ACTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto j = it.Next()) { - if (sprite[j].picnum == lType) + if (j->s.picnum == lType) { - lTemp = ldist(&sprite[g_i], &sprite[j]); + lTemp = ldist(g_ac, j); if (lTemp < lMaxDist) { if (lTemp < lDist) @@ -2998,7 +2972,7 @@ int ParseState::parse(void) } } - SetGameVarID(lVarID, lFound, g_i, g_p); + SetGameVarID(lVarID, ActorToScriptIndex(lFound), g_ac, g_p); break; } @@ -3018,7 +2992,7 @@ int ParseState::parse(void) lParm2 = *(insptr++); lVar2 = *(insptr++); - DoPlayer(lWhat == concmd_setplayer, lVar1, lLabelID, lVar2, g_i, g_p, lParm2); + DoPlayer(lWhat == concmd_setplayer, lVar1, lLabelID, lVar2, g_ac, g_p, lParm2); break; } case concmd_getuserdef: @@ -3037,7 +3011,7 @@ int ParseState::parse(void) lParm2 = *(insptr++); lVar2 = *(insptr++); - DoUserDef(lWhat == concmd_setuserdef, lVar1, lLabelID, lVar2, g_i, g_p, lParm2); + DoUserDef(lWhat == concmd_setuserdef, lVar1, lLabelID, lVar2, g_ac, g_p, lParm2); break; } case concmd_setwall: @@ -3056,7 +3030,7 @@ int ParseState::parse(void) lParm2 = *(insptr++); lVar2 = *(insptr++); - DoWall(lWhat == concmd_setwall, lVar1, lLabelID, lVar2, g_i, g_p, lParm2); + DoWall(lWhat == concmd_setwall, lVar1, lLabelID, lVar2, g_ac, g_p, lParm2); break; } case concmd_setactorvar: @@ -3073,11 +3047,11 @@ int ParseState::parse(void) lVar2 = *(insptr++); lVar3 = *(insptr++); - lSprite = GetGameVarID(lVar1, g_i, g_p); + lSprite = GetGameVarID(lVar1, g_ac, g_p); if (lSprite >= 0) { - lTemp = GetGameVarID(lVar3, g_i, g_p); - SetGameVarID(lVar2, lTemp, lSprite, g_p); + lTemp = GetGameVarID(lVar3, g_ac, g_p); + SetGameVarID(lVar2, lTemp, ScriptIndexToActor(lSprite), g_p); } break; @@ -3096,11 +3070,11 @@ int ParseState::parse(void) lVar2 = *(insptr++); lVar3 = *(insptr++); - lSprite = GetGameVarID(lVar1, g_i, g_p); + lSprite = GetGameVarID(lVar1, g_ac, g_p); if (lSprite >= 0) { - lTemp = GetGameVarID(lVar2, lSprite, g_p); - SetGameVarID(lVar3, lTemp, g_i, g_p); + lTemp = GetGameVarID(lVar2, ScriptIndexToActor(lSprite), g_p); + SetGameVarID(lVar3, lTemp, g_ac, g_p); } break; @@ -3121,7 +3095,7 @@ int ParseState::parse(void) lParm2 = *(insptr++); lVar2 = *(insptr++); - DoActor(lWhat == concmd_setactor, lVar1, lLabelID, lVar2, g_i, g_p, lParm2); + DoActor(lWhat == concmd_setactor, lVar1, lLabelID, lVar2, g_ac, g_p, lParm2); break; } case concmd_getangletotarget: @@ -3132,9 +3106,9 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def - // hittype[g_i].lastvx and lastvy are last known location of target. - ang = getangle(hittype[g_i].lastvx - g_sp->x, hittype[g_i].lastvy - g_sp->y); - SetGameVarID(i, ang, g_i, g_p); + // g_ac->lastvx and lastvy are last known location of target. + ang = getangle(g_ac->lastvx - g_sp->x, g_ac->lastvy - g_sp->y); + SetGameVarID(i, ang, g_ac, g_p); break; } case concmd_lockplayer: @@ -3142,7 +3116,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - ps[g_p].transporter_hold = GetGameVarID(i, g_i, g_p); + ps[g_p].transporter_hold = GetGameVarID(i, g_ac, g_p); break; } case concmd_getplayerangle: @@ -3150,7 +3124,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, ps[g_p].angle.ang.asbuild(), g_i, g_p); + SetGameVarID(i, ps[g_p].angle.ang.asbuild(), g_ac, g_p); break; } case concmd_setplayerangle: @@ -3158,7 +3132,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - ps[g_p].angle.ang = buildang(GetGameVarID(i, g_i, g_p) & 2047); + ps[g_p].angle.ang = buildang(GetGameVarID(i, g_ac, g_p) & 2047); break; } case concmd_getactorangle: @@ -3166,7 +3140,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, g_sp->ang, g_i, g_p); + SetGameVarID(i, g_sp->ang, g_ac, g_p); break; } case concmd_setactorangle: @@ -3174,7 +3148,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - g_sp->ang = GetGameVarID(i, g_i, g_p); + g_sp->ang = GetGameVarID(i, g_ac, g_p); g_sp->ang &= 2047; break; } @@ -3183,7 +3157,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, mulscale(rand(), *insptr, 15), g_i, g_p); + SetGameVarID(i, mulscale(rand(), *insptr, 15), g_ac, g_p); insptr++; break; } @@ -3192,7 +3166,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, GetGameVarID(i, g_i, g_p) * (*insptr), g_i, g_p); + SetGameVarID(i, GetGameVarID(i, g_ac, g_p) * (*insptr), g_ac, g_p); insptr++; break; } @@ -3205,7 +3179,7 @@ int ParseState::parse(void) { I_Error("Divide by Zero in CON."); } - SetGameVarID(i, GetGameVarID(i, g_i, g_p) / (*insptr), g_i, g_p); + SetGameVarID(i, GetGameVarID(i, g_ac, g_p) / (*insptr), g_ac, g_p); insptr++; break; } @@ -3221,8 +3195,8 @@ int ParseState::parse(void) { I_Error("Divide by Zero in CON"); } - lResult = GetGameVarID(i, g_i, g_p) % l; - SetGameVarID(i, lResult, g_i, g_p); + lResult = GetGameVarID(i, g_ac, g_p) % l; + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3234,8 +3208,8 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def l = (*insptr); - lResult = GetGameVarID(i, g_i, g_p) & l; - SetGameVarID(i, lResult, g_i, g_p); + lResult = GetGameVarID(i, g_ac, g_p) & l; + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3247,8 +3221,8 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def l = (*insptr); - lResult = GetGameVarID(i, g_i, g_p) ^ l; - SetGameVarID(i, lResult, g_i, g_p); + lResult = GetGameVarID(i, g_ac, g_p) ^ l; + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3260,8 +3234,8 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def l = (*insptr); - lResult = GetGameVarID(i, g_i, g_p) | l; - SetGameVarID(i, lResult, g_i, g_p); + lResult = GetGameVarID(i, g_ac, g_p) | l; + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3272,10 +3246,10 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); // not used for this command - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); // not used for this command + l2 = GetGameVarID(*insptr, g_ac, g_p); lResult = mulscale(rand(), l2, 15); - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3286,10 +3260,10 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); // l2 not used in this one + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); // l2 not used in this one lResult = max_ammo_amount[l1]; - SetGameVarID(*insptr, lResult, g_i, g_p); + SetGameVarID(*insptr, lResult, g_ac, g_p); insptr++; break; } @@ -3299,8 +3273,8 @@ int ParseState::parse(void) int l1, l2; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); max_ammo_amount[l1] = l2; insptr++; @@ -3313,10 +3287,10 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); lResult = l1 * l2; - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3327,14 +3301,14 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); if (l2 == 0) { I_Error("Divide by Zero in CON"); } lResult = l1 / l2; - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3345,14 +3319,14 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); if (l2 == 0) { I_Error("Mod by Zero in CON"); } lResult = l1 % l2; - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3363,10 +3337,10 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); lResult = l1 & l2; - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3377,10 +3351,10 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); lResult = l1 ^ l2; - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3391,10 +3365,10 @@ int ParseState::parse(void) int lResult; insptr++; i = *(insptr++); // ID of def - l1 = GetGameVarID(i, g_i, g_p); - l2 = GetGameVarID(*insptr, g_i, g_p); + l1 = GetGameVarID(i, g_ac, g_p); + l2 = GetGameVarID(*insptr, g_ac, g_p); lResult = l1 | l2; - SetGameVarID(i, lResult, g_i, g_p); + SetGameVarID(i, lResult, g_ac, g_p); insptr++; break; } @@ -3403,7 +3377,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, GetGameVarID(i, g_i, g_p) - *insptr, g_i, g_p); + SetGameVarID(i, GetGameVarID(i, g_ac, g_p) - *insptr, g_ac, g_p); insptr++; break; } @@ -3412,7 +3386,7 @@ int ParseState::parse(void) int i; insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, GetGameVarID(i, g_i, g_p) - GetGameVarID(*insptr, g_i, g_p), g_i, g_p); + SetGameVarID(i, GetGameVarID(i, g_ac, g_p) - GetGameVarID(*insptr, g_ac, g_p), g_ac, g_p); insptr++; break; } @@ -3422,9 +3396,9 @@ int ParseState::parse(void) int lValue; insptr++; i = *(insptr++); // ID of def - lValue = GetGameVarID(*insptr, g_i, g_p); + lValue = GetGameVarID(*insptr, g_ac, g_p); lValue = sintable[lValue & 2047]; - SetGameVarID(i, lValue, g_i, g_p); + SetGameVarID(i, lValue, g_ac, g_p); insptr++; break; } @@ -3432,31 +3406,31 @@ int ParseState::parse(void) case concmd_spgetlotag: { insptr++; - SetGameVarID(g_iLoTagID, g_sp->lotag, g_i, g_p); + SetGameVarID(g_iLoTagID, g_sp->lotag, g_ac, g_p); break; } case concmd_spgethitag: { insptr++; - SetGameVarID(g_iHiTagID, g_sp->hitag, g_i, g_p); + SetGameVarID(g_iHiTagID, g_sp->hitag, g_ac, g_p); break; } case concmd_sectgetlotag: { insptr++; - SetGameVarID(g_iLoTagID, sector[g_sp->sectnum].lotag, g_i, g_p); + SetGameVarID(g_iLoTagID, sector[g_sp->sectnum].lotag, g_ac, g_p); break; } case concmd_sectgethitag: { insptr++; - SetGameVarID(g_iHiTagID, sector[g_sp->sectnum].hitag, g_i, g_p); + SetGameVarID(g_iHiTagID, sector[g_sp->sectnum].hitag, g_ac, g_p); break; } case concmd_gettexturefloor: { insptr++; - SetGameVarID(g_iTextureID, sector[g_sp->sectnum].floorpicnum, g_i, g_p); + SetGameVarID(g_iTextureID, sector[g_sp->sectnum].floorpicnum, g_ac, g_p); break; } @@ -3467,8 +3441,8 @@ int ParseState::parse(void) int levnume; insptr++; // skip command - volnume = GetGameVarID(*(insptr++), g_i, g_p); - levnume = GetGameVarID(*(insptr++), g_i, g_p); + volnume = GetGameVarID(*insptr++, g_ac, g_p); + levnume = GetGameVarID(*insptr++, g_ac, g_p); auto level = FindMapByLevelNum(levelnum(volnume - 1, levnume - 1)); if (level != nullptr) ChangeLevel(level, -1); @@ -3486,14 +3460,14 @@ int ParseState::parse(void) int orientation; int pal; int tw = *insptr++; - x = GetGameVarID(*insptr++, g_i, g_p); - y = GetGameVarID(*insptr++, g_i, g_p); - tilenum = GetGameVarID(*insptr++, g_i, g_p); - shade = GetGameVarID(*insptr++, g_i, g_p); - orientation = GetGameVarID(*insptr++, g_i, g_p); + x = GetGameVarID(*insptr++, g_ac, g_p); + y = GetGameVarID(*insptr++, g_ac, g_p); + tilenum = GetGameVarID(*insptr++, g_ac, g_p); + shade = GetGameVarID(*insptr++, g_ac, g_p); + orientation = GetGameVarID(*insptr++, g_ac, g_p); if (tw == concmd_myospal) { - pal = GetGameVarID(*insptr++, g_i, g_p); + pal = GetGameVarID(*insptr++, g_ac, g_p); //myospal(x, y, tilenum, shade, orientation, pal); } else if (tw == concmd_myos) @@ -3506,7 +3480,7 @@ int ParseState::parse(void) } else if (tw == concmd_myospalx) { - pal = GetGameVarID(*insptr++, g_i, g_p); + pal = GetGameVarID(*insptr++, g_ac, g_p); //myospal640(x, y, tilenum, shade, orientation, pal); } break; @@ -3518,7 +3492,7 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def - SetGameVarID(i, rand(), g_i, g_p); + SetGameVarID(i, rand(), g_ac, g_p); break; } case concmd_switch: @@ -3541,7 +3515,7 @@ int ParseState::parse(void) // For each case: value, ptr to code insptr++; // p-code lVarID = *insptr++; - lValue = GetGameVarID(lVarID, g_i, g_p); + lValue = GetGameVarID(lVarID, g_ac, g_p); lEnd = *insptr++; lCases = *insptr++; lpDefault = insptr++; @@ -3593,7 +3567,7 @@ int ParseState::parse(void) case concmd_gettextureceiling: { insptr++; - SetGameVarID(g_iTextureID, sector[g_sp->sectnum].ceilingpicnum, g_i, g_p); + SetGameVarID(g_iTextureID, sector[g_sp->sectnum].ceilingpicnum, g_ac, g_p); break; } case concmd_ifvarvarand: @@ -3602,7 +3576,7 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def j = 0; - if (GetGameVarID(i, g_i, g_p) & GetGameVarID(*(insptr), g_i, g_p)) + if (GetGameVarID(i, g_ac, g_p) & GetGameVarID(*(insptr), g_ac, g_p)) { j = 1; } @@ -3615,7 +3589,7 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def j = 0; - if (GetGameVarID(i, g_i, g_p) != GetGameVarID(*(insptr), g_i, g_p)) + if (GetGameVarID(i, g_ac, g_p) != GetGameVarID(*(insptr), g_ac, g_p)) { j = 1; } @@ -3628,7 +3602,7 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def j = 0; - if (GetGameVarID(i, g_i, g_p) != *insptr) + if (GetGameVarID(i, g_ac, g_p) != *insptr) { j = 1; } @@ -3641,7 +3615,7 @@ int ParseState::parse(void) insptr++; i = *(insptr++); // ID of def j = 0; - if (GetGameVarID(i, g_i, g_p) & *insptr) + if (GetGameVarID(i, g_ac, g_p) & *insptr) { j = 1; } @@ -3664,29 +3638,26 @@ int ParseState::parse(void) // //--------------------------------------------------------------------------- -void LoadActor(int i, int p, int x) +void LoadActor(DDukeActor *actor, int p, int x) { char done; - spritetype* g_sp; ParseState s; - s.g_i = i; // Sprite ID s.g_p = p; // Player ID s.g_x = x; // ?? - g_sp = s.g_sp = &sprite[i]; // Pointer to sprite structure - s.g_t = &hittype[i].temp_data[0]; // Sprite's 'extra' data - s.g_ac = &hittype[i]; + s.g_ac = actor; + s.g_t = &s.g_ac->temp_data[0]; // Sprite's 'extra' data - auto addr = tileinfo[s.g_sp->picnum].loadeventscriptptr; + auto addr = tileinfo[actor->s.picnum].loadeventscriptptr; if (addr == 0) return; int *insptr = &ScriptCode[addr + 1]; s.killit_flag = 0; - if (g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) + if (actor->s.sectnum < 0 || actor->s.sectnum >= MAXSECTORS) { - deletesprite(i); + deletesprite(actor); return; } do @@ -3695,37 +3666,37 @@ void LoadActor(int i, int p, int x) if (s.killit_flag == 1) { - // if player was set to squish, first stop that... + // if player was set to squish, first stop that.. if (p >= 0) { - if (ps[p].actorsqu == &hittype[i]) + if (ps[p].actorsqu == actor) ps[p].actorsqu = nullptr; } - deletesprite(i); + deletesprite(actor); } else { - fi.move(i, p, x); + fi.move(actor, p, x); - if (g_sp->statnum == 1) + if (actor->s.statnum == STAT_ACTOR) { - if (badguy(g_sp)) + if (badguy(actor)) { - if (g_sp->xrepeat > 60) return; - if (ud.respawn_monsters == 1 && g_sp->extra <= 0) return; + if (actor->s.xrepeat > 60) return; + if (ud.respawn_monsters == 1 && actor->s.extra <= 0) return; } - else if (ud.respawn_items == 1 && (g_sp->cstat & 32768)) return; + else if (ud.respawn_items == 1 && (actor->s.cstat & 32768)) return; - if (hittype[i].timetosleep > 1) - hittype[i].timetosleep--; - else if (hittype[i].timetosleep == 1) - changespritestat(i, 2); + if (actor->timetosleep > 1) + actor->timetosleep--; + else if (actor->timetosleep == 1) + changespritestat(actor, STAT_ZOMBIEACTOR); } - else if (g_sp->statnum == 6) + else if (actor->s.statnum == 6) { #if 0 - switch (g_sp->picnum) + switch (actor->s.picnum) { case RUBBERCAN: case EXPLODINGBARREL: @@ -3738,9 +3709,9 @@ void LoadActor(int i, int p, int x) case NUKEBARRELLEAKED: case TRIPBOMB: case EGG: - if (hittype[i].timetosleep > 1) - hittype[i].timetosleep--; - else if (hittype[i].timetosleep == 1) + if (actor->timetosleep > 1) + actor->timetosleep--; + else if (actor->timetosleep == 1) changespritestat(i, 2); break; } @@ -3756,31 +3727,28 @@ void LoadActor(int i, int p, int x) // //--------------------------------------------------------------------------- -void execute(int i,int p,int x) +void execute(DDukeActor *actor,int p,int x) { - if (actorinfo[sprite[i].picnum].scriptaddress == 0) return; + if (actorinfo[actor->s.picnum].scriptaddress == 0) return; int done; - spritetype* g_sp; ParseState s; - s.g_i = i; // Sprite ID s.g_p = p; // Player ID s.g_x = x; // ?? - g_sp = s.g_sp = &sprite[i]; // Pointer to sprite structure - s.g_t = &hittype[i].temp_data[0]; // Sprite's 'extra' data - s.g_ac = &hittype[i]; + s.g_ac = actor; + s.g_t = &actor->temp_data[0]; // Sprite's 'extra' data - if (actorinfo[g_sp->picnum].scriptaddress == 0) return; - s.insptr = &ScriptCode[4 + (actorinfo[g_sp->picnum].scriptaddress)]; + if (actorinfo[actor->s.picnum].scriptaddress == 0) return; + s.insptr = &ScriptCode[4 + (actorinfo[actor->s.picnum].scriptaddress)]; s.killit_flag = 0; - if(g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) + if(actor->s.sectnum < 0 || actor->s.sectnum >= MAXSECTORS) { - if(badguy(g_sp)) + if(badguy(actor)) ps[p].actors_killed++; - deletesprite(i); + deletesprite(actor); return; } @@ -3792,11 +3760,11 @@ void execute(int i,int p,int x) int increment = ptr[3]; int delay = ptr[4]; - g_sp->lotag += TICSPERFRAME; - if (g_sp->lotag > delay) + actor->s.lotag += TICSPERFRAME; + if (actor->s.lotag > delay) { s.g_t[2]++; - g_sp->lotag = 0; + actor->s.lotag = 0; s.g_t[3] += increment; } if (abs(s.g_t[3]) >= abs(numframes * increment)) @@ -3809,35 +3777,35 @@ void execute(int i,int p,int x) if(s.killit_flag == 1) { - // if player was set to squish, first stop that... - if(ps[p].actorsqu == &hittype[i]) + // if player was set to squish, first stop that.. + if(ps[p].actorsqu == actor) ps[p].actorsqu = nullptr; killthesprite = true; } else { - fi.move(i, p, x); + fi.move(actor, p, x); - if (g_sp->statnum == STAT_ACTOR) + if (actor->s.statnum == STAT_ACTOR) { - if (badguy(g_sp)) + if (badguy(actor)) { - if (g_sp->xrepeat > 60) goto quit; - if (ud.respawn_monsters == 1 && g_sp->extra <= 0) goto quit; + if (actor->s.xrepeat > 60) goto quit; + if (ud.respawn_monsters == 1 && actor->s.extra <= 0) goto quit; } - else if (ud.respawn_items == 1 && (g_sp->cstat & 32768)) goto quit; + else if (ud.respawn_items == 1 && (actor->s.cstat & 32768)) goto quit; - if (hittype[i].timetosleep > 1) - hittype[i].timetosleep--; - else if (hittype[i].timetosleep == 1) - changespritestat(i, STAT_ZOMBIEACTOR); + if (actor->timetosleep > 1) + actor->timetosleep--; + else if (actor->timetosleep == 1) + changespritestat(actor, STAT_ZOMBIEACTOR); } - else if (g_sp->statnum == STAT_STANDABLE) - fi.checktimetosleep(i); + else if (actor->s.statnum == STAT_STANDABLE) + fi.checktimetosleep(actor); } quit: - if (killthesprite) deletesprite(i); + if (killthesprite) deletesprite(actor); killthesprite = false; } @@ -3848,7 +3816,7 @@ quit: // //--------------------------------------------------------------------------- -void OnEvent(int iEventID, int p, int i, int x) +void OnEvent(int iEventID, int p, DDukeActor *actor, int x) { char done; @@ -3863,12 +3831,10 @@ void OnEvent(int iEventID, int p, int i, int x) } ParseState s; - s.g_i = i; // current sprite ID s.g_p = p; /// current player ID s.g_x = x; // ? - s.g_sp = &sprite[i]; - s.g_ac = &hittype[i]; - s.g_t = &hittype[i].temp_data[0]; + s.g_ac = actor; + s.g_t = actor->temp_data; s.insptr = &ScriptCode[apScriptGameEvent[iEventID]]; diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 5f460686b..d3e625825 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -66,7 +66,7 @@ void GameInterface::Ticker() { if (earthquaketime > 0) earthquaketime--; - ud.camerasprite = -1; + ud.cameraactor = nullptr; everyothertime++; global_random = krand(); diff --git a/source/games/duke/src/gamevar.cpp b/source/games/duke/src/gamevar.cpp index 4746e4d46..839092c33 100644 --- a/source/games/duke/src/gamevar.cpp +++ b/source/games/duke/src/gamevar.cpp @@ -278,7 +278,7 @@ void ResetGameVars(void) // //--------------------------------------------------------------------------- -int GetGameVarID(int id, int sActor, int sPlayer) +int GetGameVarID(int id, DDukeActor* sActor, int sPlayer) { if(id<0 || id >= iGameVarCount) { @@ -287,7 +287,7 @@ int GetGameVarID(int id, int sActor, int sPlayer) } if (id == g_iThisActorID) { - return sActor; + return sActor->GetIndex(); } if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER ) { @@ -304,9 +304,9 @@ int GetGameVarID(int id, int sActor, int sPlayer) else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR ) { // for the current actor - if(sActor >= 0 && sActor <=MAXSPRITES) + if(sActor != nullptr) { - return aGameVars[id].plArray[sActor]; + return aGameVars[id].plArray[sActor->GetIndex()]; } else { @@ -344,7 +344,7 @@ int GetGameVarID(int id, int sActor, int sPlayer) // //--------------------------------------------------------------------------- -void SetGameVarID(int id, int lValue, int sActor, int sPlayer) +void SetGameVarID(int id, int lValue, DDukeActor* sActor, int sPlayer) { if(id<0 || id >= iGameVarCount) { @@ -360,7 +360,7 @@ void SetGameVarID(int id, int lValue, int sActor, int sPlayer) else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR ) { // for the current actor - if (sActor >= 0) aGameVars[id].plArray[sActor]=lValue; + if (sActor != nullptr) aGameVars[id].plArray[sActor->GetIndex()]=lValue; else for (auto& i : aGameVars[id].plArray) i = lValue; // -1 sets all actors - was undefined OOB access in WW2GI. } else if( aGameVars[id].dwFlags & GAMEVAR_FLAG_PLONG ) @@ -381,7 +381,7 @@ void SetGameVarID(int id, int lValue, int sActor, int sPlayer) // //--------------------------------------------------------------------------- -int GetGameVar(const char *szGameLabel, int lDefault, int sActor, int sPlayer) +int GetGameVar(const char *szGameLabel, int lDefault, DDukeActor* sActor, int sPlayer) { for (int i = 0; i < iGameVarCount; i++) { @@ -1171,49 +1171,49 @@ void ResetSystemDefaults(void) for(i=0;i<12/*MAX_WEAPONS*/;i++) { sprintf(aszBuf,"WEAPON%d_CLIP",i); - aplWeaponClip[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponClip[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_RELOAD",i); - aplWeaponReload[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponReload[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_FIREDELAY",i); - aplWeaponFireDelay[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponFireDelay[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_TOTALTIME",i); - aplWeaponTotalTime[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponTotalTime[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_HOLDDELAY",i); - aplWeaponHoldDelay[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponHoldDelay[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_FLAGS",i); - aplWeaponFlags[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponFlags[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_SHOOTS",i); - aplWeaponShoots[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponShoots[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_SPAWNTIME",i); - aplWeaponSpawnTime[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponSpawnTime[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_SPAWN",i); - aplWeaponSpawn[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponSpawn[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_SHOTSPERBURST",i); - aplWeaponShotsPerBurst[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponShotsPerBurst[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_WORKSLIKE",i); - aplWeaponWorksLike[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponWorksLike[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_INITIALSOUND",i); - aplWeaponInitialSound[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponInitialSound[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_FIRESOUND",i); - aplWeaponFireSound[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponFireSound[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_SOUND2TIME",i); - aplWeaponSound2Time[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponSound2Time[i][j]=GetGameVar(aszBuf,0, nullptr, j); sprintf(aszBuf,"WEAPON%d_SOUND2SOUND",i); - aplWeaponSound2Sound[i][j]=GetGameVar(aszBuf,0, -1, j); + aplWeaponSound2Sound[i][j]=GetGameVar(aszBuf,0, nullptr, j); } } diff --git a/source/games/duke/src/gamevar.h b/source/games/duke/src/gamevar.h index 712f079af..ca383a25b 100644 --- a/source/games/duke/src/gamevar.h +++ b/source/games/duke/src/gamevar.h @@ -124,9 +124,11 @@ int GetDefID(const char *szGameLabel); void ClearGameVars(void); void AddSystemVars(); void ResetGameVars(void); -int GetGameVarID(int id, int sActor, int sPlayer); -void SetGameVarID(int id, int lValue, int sActor, int sPlayer); -int GetGameVar(const char* szGameLabel, int lDefault, int sActor, int sPlayer); +struct weaponhit; +using DDukeActor = weaponhit; +int GetGameVarID(int id, DDukeActor* sActor, int sPlayer); +void SetGameVarID(int id, int lValue, DDukeActor* sActor, int sPlayer); +int GetGameVar(const char* szGameLabel, int lDefault, DDukeActor* sActor, int sPlayer); void ClearGameEvents(); bool IsGameEvent(int i); diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index 8d049f2ee..1c45fb361 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -84,7 +84,7 @@ animwalltype animwall[MAXANIMWALLS]; int numanimwalls; int animatecnt; int numclouds; -int camsprite; +DDukeActor* camsprite; int numcyclers; int earthquaketime; int freezerhurtowner; @@ -135,7 +135,8 @@ unsigned ambientfx; int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS]; int WindTime, WindDir; short fakebubba_spawn, mamaspawn_count, banjosound; -short BellTime, BellSprite /* word_119BE0*/; +short BellTime; +DDukeActor* BellSprite /* word_119BE0*/; uint8_t enemysizecheat /*raat607*/, ufospawnsminion, pistonsound, chickenphase /* raat605*/, RRRA_ExitedLevel, fogactive; uint32_t everyothertime; player_orig po[MAXPLAYERS]; diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 92138011e..78799afdf 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -70,7 +70,7 @@ extern animwalltype animwall[MAXANIMWALLS]; extern int numanimwalls; extern int animatecnt; extern int numclouds; -extern int camsprite; +extern DDukeActor* camsprite; extern int numcyclers; extern int earthquaketime; extern int freezerhurtowner; @@ -127,7 +127,8 @@ extern unsigned ambientfx; extern int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS]; extern int WindTime, WindDir; extern short fakebubba_spawn, mamaspawn_count, banjosound; -extern short BellTime, BellSprite /* word_119BE0*/; +extern short BellTime; +extern DDukeActor* BellSprite /* word_119BE0*/; extern uint8_t enemysizecheat /*raat607*/, ufospawnsminion, pistonsound, chickenphase /* raat605*/, RRRA_ExitedLevel, fogactive; extern uint32_t everyothertime; extern player_orig po[MAXPLAYERS]; diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index 5ec059087..f3afb3d63 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -35,6 +35,7 @@ source as it is released. #include "ns.h" #include "global.h" #include "names_d.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -105,7 +106,7 @@ int animatefist(int gs, int snum, double look_anghalf) fistzoom = 40290; fistz = 194 + (calcSinTableValue(((6 + fisti) << 7) & 2047) / 512.); - if (sprite[ps[snum].i].pal == 1) + if (ps[snum].GetActor()->s.pal == 1) fistpal = 1; else fistpal = sector[ps[snum].cursectnum].floorpal; @@ -130,13 +131,13 @@ int animateknee(int gs, int snum, double hard_landing, double look_anghalf, doub short pal; double looking_arc; - if (ps[snum].knee_incs > 11 || ps[snum].knee_incs == 0 || sprite[ps[snum].i].extra <= 0) return 0; + if (ps[snum].knee_incs > 11 || ps[snum].knee_incs == 0 || ps[snum].GetActor()->s.extra <= 0) return 0; looking_arc = knee_y[ps[snum].knee_incs] + (fabs(look_anghalf) / 4.5); looking_arc -= hard_landing * 8.; - if (sprite[ps[snum].i].pal == 1) + if (ps[snum].GetActor()->s.pal == 1) pal = 1; else { @@ -162,13 +163,13 @@ int animateknuckles(int gs, int snum, double hard_landing, double look_anghalf, short pal; double looking_arc; - if (isWW2GI() || ps[snum].over_shoulder_on != 0 || ps[snum].knuckle_incs == 0 || sprite[ps[snum].i].extra <= 0) return 0; + if (isWW2GI() || ps[snum].over_shoulder_on != 0 || ps[snum].knuckle_incs == 0 || ps[snum].GetActor()->s.extra <= 0) return 0; looking_arc = fabs(look_anghalf) / 4.5; looking_arc -= hard_landing * 8.; - if (sprite[ps[snum].i].pal == 1) + if (ps[snum].GetActor()->s.pal == 1) pal = 1; else pal = sector[ps[snum].cursectnum].floorpal; @@ -189,7 +190,7 @@ void displaymasks_d(int snum, double) { int p; - if (sprite[ps[snum].i].pal == 1) + if (ps[snum].GetActor()->s.pal == 1) p = 1; else p = sector[ps[snum].cursectnum].floorpal; @@ -218,16 +219,11 @@ static int animatetip(int gs, int snum, double hard_landing, double look_anghalf looking_arc = fabs(look_anghalf) / 4.5; looking_arc -= hard_landing * 8.; - if (sprite[ps[snum].i].pal == 1) + if (ps[snum].GetActor()->s.pal == 1) p = 1; else p = sector[ps[snum].cursectnum].floorpal; - /* if(ps[snum].access_spritenum >= 0) - p = sprite[ps[snum].access_spritenum].pal; - else - p = wall[ps[snum].access_wallnum].pal; - */ hud_drawpal(170 + (getavel(snum) / 16.) - look_anghalf, (tip_y[ps[snum].tipincs] >> 1) + looking_arc + 240 - horiz16th, TIP + ((26 - ps[snum].tipincs) >> 4), gs, 0, p); @@ -246,16 +242,14 @@ int animateaccess(int gs,int snum,double hard_landing,double look_anghalf,double double looking_arc; char p; - if(ps[snum].access_incs == 0 || sprite[ps[snum].i].extra <= 0) return 0; + if(ps[snum].access_incs == 0 || ps[snum].GetActor()->s.extra <= 0) return 0; looking_arc = access_y[ps[snum].access_incs] + (fabs(look_anghalf) / 4.5); looking_arc -= hard_landing * 8.; - if(ps[snum].access_spritenum >= 0) - p = sprite[ps[snum].access_spritenum].pal; + if(ps[snum].access_spritenum != nullptr) + p = ps[snum].access_spritenum->s.pal; else p = 0; -// else -// p = wall[ps[snum].access_wallnum].pal; if((ps[snum].access_incs-3) > 0 && (ps[snum].access_incs-3)>>3) hud_drawpal(170+(getavel(snum)/16.)-look_anghalf+(access_y[ps[snum].access_incs]>>2),looking_arc+266-horiz16th,HANDHOLDINGLASER+(ps[snum].access_incs>>3),gs,0,p); @@ -294,10 +288,10 @@ void displayweapon_d(int snum, double smoothratio) random_club_frame = p->orandom_club_frame + fmulscale16(p->random_club_frame - p->orandom_club_frame, smoothratio); hard_landing = p->ohard_landing + fmulscale16(p->hard_landing - p->ohard_landing, smoothratio); - gs = sprite[p->i].shade; + gs = p->GetActor()->s.shade; if(gs > 24) gs = 24; - bool playerVars = p->newowner >= 0 || ud.camerasprite >= 0 || p->over_shoulder_on > 0 || (sprite[p->i].pal != 1 && sprite[p->i].extra <= 0); + bool playerVars = p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (p->GetActor()->s.pal != 1 && p->GetActor()->s.extra <= 0); bool playerAnims = animatefist(gs,snum,look_anghalf) || animateknuckles(gs,snum,hard_landing,look_anghalf,horiz16th) || animatetip(gs,snum,hard_landing,look_anghalf,horiz16th) || animateaccess(gs,snum,hard_landing,look_anghalf,horiz16th); @@ -313,7 +307,7 @@ void displayweapon_d(int snum, double smoothratio) weapon_xoffset = (160)-90; weapon_xoffset -= calcSinTableValue((weapon_sway / 2.) + 512) / (1024. + 512.); weapon_xoffset -= 58 + p->weapon_ang; - if( sprite[p->i].xrepeat < 32 ) + if( p->GetActor()->s.xrepeat < 32 ) gun_pos -= fabs(calcSinTableValue(weapon_sway * 4.) / 512.); else gun_pos -= fabs(calcSinTableValue(weapon_sway / 2.) / 1024.); @@ -344,7 +338,7 @@ void displayweapon_d(int snum, double smoothratio) j = 14-p->quick_kick; if (j != 14 || p->last_quick_kick) { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else { @@ -364,13 +358,13 @@ void displayweapon_d(int snum, double smoothratio) } } - if (sprite[p->i].xrepeat < 40) + if (p->GetActor()->s.xrepeat < 40) { static int fistsign; //shrunken.. if (p->jetpack_on == 0) { - i = sprite[p->i].xvel; + i = p->GetActor()->s.xvel; looking_arc += 32 - (i >> 1); fistsign += i >> 1; } @@ -398,7 +392,7 @@ void displayweapon_d(int snum, double smoothratio) { if (*kb > 0) { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else { @@ -429,7 +423,7 @@ void displayweapon_d(int snum, double smoothratio) auto displaytripbomb = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -462,7 +456,7 @@ void displayweapon_d(int snum, double smoothratio) //pin = (isWorldTour() || (duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) ? 0 : RS_ALIGN_R; auto rpgpic = /*isWorldTour() ? RPGGUNWIDE :*/ RPGGUN; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -510,7 +504,7 @@ void displayweapon_d(int snum, double smoothratio) auto displayshotgun_ww = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -521,7 +515,7 @@ void displayweapon_d(int snum, double smoothratio) gun_pos -= calcSinTableValue(kickback_pic * 128.) / 4096.; } - if (*kb > 0 && sprite[p->i].pal != 1) + if (*kb > 0 && p->GetActor()->s.pal != 1) { weapon_xoffset += 1 - (rand() & 3); } @@ -572,7 +566,7 @@ void displayweapon_d(int snum, double smoothratio) auto displayshotgun = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -657,7 +651,7 @@ void displayweapon_d(int snum, double smoothratio) auto displaychaingun_ww = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -665,7 +659,7 @@ void displayweapon_d(int snum, double smoothratio) if (*kb > 0) gun_pos -= calcSinTableValue(kickback_pic * 128.) / 4096.; - if (*kb > 0 && sprite[p->i].pal != 1) weapon_xoffset += 1 - (rand() & 3); + if (*kb > 0 && p->GetActor()->s.pal != 1) weapon_xoffset += 1 - (rand() & 3); if (*kb == 0) { @@ -770,7 +764,7 @@ void displayweapon_d(int snum, double smoothratio) auto displaychaingun = [&] { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -778,7 +772,7 @@ void displayweapon_d(int snum, double smoothratio) if (*kb > 0) gun_pos -= calcSinTableValue(kickback_pic * 128.) / 4096.; - if (*kb > 0 && sprite[p->i].pal != 1) weapon_xoffset += 1 - (rand() & 3); + if (*kb > 0 && p->GetActor()->s.pal != 1) weapon_xoffset += 1 - (rand() & 3); hud_drawpal(weapon_xoffset + 168 - look_anghalf, looking_arc + 260 - gun_pos, CHAINGUN, gs, o, pal); switch(*kb) @@ -790,9 +784,9 @@ void displayweapon_d(int snum, double smoothratio) if (*kb > 4 && *kb < 12) { i = 0; - if (sprite[p->i].pal != 1) i = rand() & 7; + if (p->GetActor()->s.pal != 1) i = rand() & 7; hud_drawpal(i + weapon_xoffset - 4 + 140 - look_anghalf,i + looking_arc - (kickback_pic / 2.) + 208 - gun_pos, CHAINGUN + 5 + ((*kb - 4) / 5),gs,o,pal); - if (sprite[p->i].pal != 1) i = rand() & 7; + if (p->GetActor()->s.pal != 1) i = rand() & 7; hud_drawpal(i + weapon_xoffset - 4 + 184 - look_anghalf,i + looking_arc - (kickback_pic / 2.) + 208 - gun_pos, CHAINGUN + 5 + ((*kb - 4) / 5),gs,o,pal); } if (*kb < 8) @@ -814,7 +808,7 @@ void displayweapon_d(int snum, double smoothratio) auto displaypistol = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -877,7 +871,7 @@ void displayweapon_d(int snum, double smoothratio) auto displayhandbomb = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -937,7 +931,7 @@ void displayweapon_d(int snum, double smoothratio) auto displayhandremote = [&]() { signed char remote_frames[] = { 0,1,1,2,1,1,0,0,0,0,0 }; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -958,7 +952,7 @@ void displayweapon_d(int snum, double smoothratio) auto displaydevastator_ww = [&] { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -1019,7 +1013,7 @@ void displayweapon_d(int snum, double smoothratio) auto displaydevastator = [&] { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -1059,7 +1053,7 @@ void displayweapon_d(int snum, double smoothratio) //pin = (isWW2GI() || isWorldTour() || (duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) ? 0 : RS_ALIGN_R; auto pic = /*isWorldTour() ? FREEZEWIDE :*/ FREEZE; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -1068,7 +1062,7 @@ void displayweapon_d(int snum, double smoothratio) { char cat_frames[] = { 0,0,1,1,2,2 }; - if (sprite[p->i].pal != 1) + if (p->GetActor()->s.pal != 1) { weapon_xoffset += rand() & 3; looking_arc += rand() & 3; @@ -1090,7 +1084,7 @@ void displayweapon_d(int snum, double smoothratio) { weapon_xoffset += 28; looking_arc += 18; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -1121,7 +1115,7 @@ void displayweapon_d(int snum, double smoothratio) else { // the 'active' display. - if (sprite[p->i].pal != 1) + if (p->GetActor()->s.pal != 1) { weapon_xoffset += rand() & 3; gun_pos += (rand() & 3); @@ -1183,7 +1177,7 @@ void displayweapon_d(int snum, double smoothratio) { weapon_xoffset += 28; looking_arc += 18; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -1196,7 +1190,7 @@ void displayweapon_d(int snum, double smoothratio) } else { - if (sprite[p->i].pal != 1) + if (p->GetActor()->s.pal != 1) { weapon_xoffset += rand() & 3; gun_pos += (rand() & 3); @@ -1259,7 +1253,7 @@ void displayweapon_d(int snum, double smoothratio) auto shrinker = /*isWorldTour() ? SHRINKERWIDE :*/ SHRINKER; weapon_xoffset += 28; looking_arc += 18; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -1288,7 +1282,7 @@ void displayweapon_d(int snum, double smoothratio) } else { - if (sprite[p->i].pal != 1) + if (p->GetActor()->s.pal != 1) { weapon_xoffset += rand() & 3; gun_pos += (rand() & 3); @@ -1324,7 +1318,7 @@ void displayweapon_d(int snum, double smoothratio) auto displayflamethrower = [&]() { - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else { @@ -1342,7 +1336,7 @@ void displayweapon_d(int snum, double smoothratio) else { static const uint8_t cat_frames[] = { 0, 0, 1, 1, 2, 2 }; - if (sprite[p->i].pal != 1) + if (p->GetActor()->s.pal != 1) { weapon_xoffset += krand() & 1; looking_arc += krand() & 1; diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 39558a0fd..c202843a2 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -29,6 +29,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "ns.h" #include "global.h" #include "names_r.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -68,7 +69,7 @@ void displaymasks_r(int snum, double smoothratio) { short p; - if (sprite[ps[snum].i].pal == 1) + if (ps[snum].GetActor()->s.pal == 1) p = 1; else p = sector[ps[snum].cursectnum].floorpal; @@ -132,10 +133,10 @@ void displayweapon_r(int snum, double smoothratio) if (shadedsector[p->cursectnum] == 1) gs = 16; else - gs = sprite[p->i].shade; + gs = p->GetActor()->s.shade; if(gs > 24) gs = 24; - if(p->newowner >= 0 || ud.camerasprite >= 0 || p->over_shoulder_on > 0 || (sprite[p->i].pal != 1 && sprite[p->i].extra <= 0)) + if(p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (p->GetActor()->s.pal != 1 && p->GetActor()->s.extra <= 0)) return; int opos = p->oweapon_pos * p->oweapon_pos; @@ -145,7 +146,7 @@ void displayweapon_r(int snum, double smoothratio) weapon_xoffset = (160)-90; weapon_xoffset -= calcSinTableValue((weapon_sway / 2.) + 512) / (1024. + 512.); weapon_xoffset -= 58 + p->weapon_ang; - if( sprite[p->i].xrepeat < 8 ) + if( p->GetActor()->s.xrepeat < 8 ) gun_pos -= fabs(calcSinTableValue(weapon_sway * 4.) / 512.); else gun_pos -= fabs(calcSinTableValue(weapon_sway / 2.) / 1024.); @@ -158,7 +159,7 @@ void displayweapon_r(int snum, double smoothratio) j = 14-p->quick_kick; if(j != 14) { - if(sprite[p->i].pal == 1) + if(p->GetActor()->s.pal == 1) pal = 1; else pal = p->palookup; @@ -213,7 +214,7 @@ void displayweapon_r(int snum, double smoothratio) else temp_kb = MOTOHIT; } - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -280,7 +281,7 @@ void displayweapon_r(int snum, double smoothratio) temp_kb = BOATHIT; } - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -300,12 +301,12 @@ void displayweapon_r(int snum, double smoothratio) return; } - if( sprite[p->i].xrepeat < 8 ) + if( p->GetActor()->s.xrepeat < 8 ) { static int fistsign; if(p->jetpack_on == 0 ) { - i = sprite[p->i].xvel; + i = p->GetActor()->s.xvel; looking_arc += 32-(i>>1); fistsign += i>>1; } @@ -324,7 +325,7 @@ void displayweapon_r(int snum, double smoothratio) { int pin = 0; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -480,7 +481,7 @@ void displayweapon_r(int snum, double smoothratio) } else if ((krand() & 15) == 5) { - S_PlayActorSound(327, p->i); + S_PlayActorSound(327, p->GetActor()); rdmyospal((weapon_xoffset + 210) - look_anghalf, looking_arc + 222 - gun_pos, RPGGUN2 + 7, gs, o | pin, pal); chickenphase = 6; @@ -509,7 +510,7 @@ void displayweapon_r(int snum, double smoothratio) { weapon_xoffset -= 8; - if (sprite[p->i].pal == 1) + if (p->GetActor()->s.pal == 1) pal = 1; else pal = sector[p->cursectnum].floorpal; @@ -624,7 +625,7 @@ void displayweapon_r(int snum, double smoothratio) if (*kb > 0) gun_pos -= calcSinTableValue((*kb) << 7) / 4096.; - if (*kb > 0 && sprite[p->i].pal != 1) weapon_xoffset += 1 - (rand() & 3); + if (*kb > 0 && p->GetActor()->s.pal != 1) weapon_xoffset += 1 - (rand() & 3); switch (*kb) { @@ -837,7 +838,7 @@ void displayweapon_r(int snum, double smoothratio) } else { - if (sprite[p->i].pal != 1) + if (p->GetActor()->s.pal != 1) { weapon_xoffset += rand() & 3; gun_pos += (rand() & 3); diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index cbc53b7dc..38340035c 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -37,14 +37,14 @@ inline int bossguy(spritetype const* const pSprite) return bossguypic(pSprite->picnum); } -inline int actorflag(int spritenum, int mask) +inline int actorflag(DDukeActor * actor, int mask) { - return (((actorinfo[sprite[spritenum].picnum].flags/* ^ hittype[spritenum].flags*/) & mask) != 0); + return (((actorinfo[actor->s.picnum].flags) & mask) != 0); } -inline int actorfella(int spnum) +inline int actorfella(DDukeActor* actor) { - return actorflag(spnum, SFLAG_KILLCOUNT); + return actorflag(actor, SFLAG_KILLCOUNT); } inline void setflag(int flag, const std::initializer_list& types) @@ -68,16 +68,16 @@ inline void settileflag(int flag, const std::initializer_list& types) } } -inline bool wallswitchcheck(int s) +inline bool wallswitchcheck(DDukeActor* s) { - return !!(tileinfo[sprite[s].picnum].flags & TFLAG_WALLSWITCH); + return !!(tileinfo[s->s.picnum].flags & TFLAG_WALLSWITCH); } inline int checkcursectnums(int se) { int i; for(i=connecthead;i>=0;i=connectpoint2[i]) - if((unsigned)ps[i].i < MAXSPRITES && sprite[ps[i].i].sectnum == se ) return i; + if(ps[i].GetActor() && ps[i].GetActor()->s.sectnum == se ) return i; return -1; } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index a09895050..20ab0129f 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -55,7 +55,7 @@ static InputPacket loc; // input accumulation buffer. // //--------------------------------------------------------------------------- -void hud_input(int snum) +void hud_input(int plnum) { int i, k; uint8_t dainv; @@ -63,10 +63,11 @@ void hud_input(int snum) short unk; unk = 0; - p = &ps[snum]; + p = &ps[plnum]; + auto pact = p->GetActor(); i = p->aim_mode; - p->aim_mode = !PlayerInput(snum, SB_AIMMODE); + p->aim_mode = !PlayerInput(plnum, SB_AIMMODE); if (p->aim_mode < i) p->sync.actions |= SB_CENTERVIEW; @@ -75,39 +76,39 @@ void hud_input(int snum) if (isRR()) { - if (PlayerInput(snum, SB_QUICK_KICK) && p->last_pissed_time == 0) + if (PlayerInput(plnum, SB_QUICK_KICK) && p->last_pissed_time == 0) { - if (!isRRRA() || sprite[p->i].extra > 0) + if (!isRRRA() || p->GetActor()->s.extra > 0) { p->last_pissed_time = 4000; - S_PlayActorSound(437, p->i); - if (sprite[p->i].extra <= max_player_health - max_player_health / 10) + S_PlayActorSound(437, pact); + if (p->GetActor()->s.extra <= max_player_health - max_player_health / 10) { - sprite[p->i].extra += 2; - p->last_extra = sprite[p->i].extra; + p->GetActor()->s.extra += 2; + p->last_extra = p->GetActor()->s.extra; } - else if (sprite[p->i].extra < max_player_health) - sprite[p->i].extra = max_player_health; + else if (p->GetActor()->s.extra < max_player_health) + p->GetActor()->s.extra = max_player_health; } } } else { - if (PlayerInput(snum, SB_QUICK_KICK) && p->quick_kick == 0 && (p->curr_weapon != KNEE_WEAPON || p->kickback_pic == 0)) + if (PlayerInput(plnum, SB_QUICK_KICK) && p->quick_kick == 0 && (p->curr_weapon != KNEE_WEAPON || p->kickback_pic == 0)) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_QUICKKICK, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_QUICKKICK, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { p->quick_kick = 14; - if (!p->quick_kick_msg && snum == screenpeek) FTA(QUOTE_MIGHTY_FOOT, p); + if (!p->quick_kick_msg && plnum == screenpeek) FTA(QUOTE_MIGHTY_FOOT, p); p->quick_kick_msg = true; } } } - if (!PlayerInput(snum, SB_QUICK_KICK)) p->quick_kick_msg = false; + if (!PlayerInput(plnum, SB_QUICK_KICK)) p->quick_kick_msg = false; - if (!PlayerInputBits(snum, SB_INTERFACE_BITS)) + if (!PlayerInputBits(plnum, SB_INTERFACE_BITS)) p->interface_toggle_flag = 0; else if (p->interface_toggle_flag == 0) { @@ -115,43 +116,42 @@ void hud_input(int snum) // Don't go on if paused or dead. if (paused) return; - if (sprite[p->i].extra <= 0) return; + if (p->GetActor()->s.extra <= 0) return; // Activate an inventory item. This just forwards to the other inventory bits. If the inventory selector was taken out of the playsim this could be removed. - if (PlayerInput(snum, SB_INVUSE) && p->newowner == -1) + if (PlayerInput(plnum, SB_INVUSE) && p->newOwner == nullptr) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_INVENTORY, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_INVENTORY, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { - if (p->inven_icon > ICON_NONE && p->inven_icon <= ICON_HEATS) PlayerSetItemUsed(snum, p->inven_icon); + if (p->inven_icon > ICON_NONE && p->inven_icon <= ICON_HEATS) PlayerSetItemUsed(plnum, p->inven_icon); } } - if (!isRR() && PlayerUseItem(snum, ICON_HEATS)) + if (!isRR() && PlayerUseItem(plnum, ICON_HEATS)) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_USENIGHTVISION, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0 && p->heat_amount > 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_USENIGHTVISION, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0 && p->heat_amount > 0) { p->heat_on = !p->heat_on; - setpal(p); p->inven_icon = 5; - S_PlayActorSound(NITEVISION_ONOFF, p->i); + S_PlayActorSound(NITEVISION_ONOFF, pact); FTA(106 + (!p->heat_on), p); } } - if (PlayerUseItem(snum, ICON_STEROIDS)) + if (PlayerUseItem(plnum, ICON_STEROIDS)) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_USESTEROIDS, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_USESTEROIDS, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { if (p->steroids_amount == 400) { p->steroids_amount--; - S_PlayActorSound(DUKE_TAKEPILLS, p->i); + S_PlayActorSound(DUKE_TAKEPILLS, pact); p->inven_icon = ICON_STEROIDS; FTA(12, p); } @@ -159,11 +159,11 @@ void hud_input(int snum) return; } - if (PlayerInput(snum, SB_INVPREV) || PlayerInput(snum, SB_INVNEXT)) + if (PlayerInput(plnum, SB_INVPREV) || PlayerInput(plnum, SB_INVNEXT)) { p->invdisptime = 26 * 2; - if (PlayerInput(snum, SB_INVNEXT)) k = 1; + if (PlayerInput(plnum, SB_INVNEXT)) k = 1; else k = 0; dainv = p->inven_icon; @@ -225,17 +225,17 @@ void hud_input(int snum) else dainv = 0; // These events force us to keep the inventory selector in the playsim as opposed to the UI where it really belongs. - if (PlayerInput(snum, SB_INVPREV)) + if (PlayerInput(plnum, SB_INVPREV)) { - SetGameVarID(g_iReturnVarID, dainv, -1, snum); - OnEvent(EVENT_INVENTORYLEFT, -1, snum, -1); - dainv = GetGameVarID(g_iReturnVarID, -1, snum); + SetGameVarID(g_iReturnVarID, dainv, nullptr, plnum); + OnEvent(EVENT_INVENTORYLEFT, plnum, nullptr, -1); + dainv = GetGameVarID(g_iReturnVarID, nullptr, plnum); } - if (PlayerInput(snum, SB_INVNEXT)) + if (PlayerInput(plnum, SB_INVNEXT)) { - SetGameVarID(g_iReturnVarID, dainv, -1, snum); - OnEvent(EVENT_INVENTORYRIGHT, -1, snum, -1); - dainv = GetGameVarID(g_iReturnVarID, -1, snum); + SetGameVarID(g_iReturnVarID, dainv, nullptr, plnum); + OnEvent(EVENT_INVENTORYRIGHT, plnum, nullptr, -1); + dainv = GetGameVarID(g_iReturnVarID, nullptr, plnum); } p->inven_icon = dainv; // Someone must have really hated constant data, doing this with a switch/case (and of course also with literal numbers...) @@ -243,14 +243,14 @@ void hud_input(int snum) if (dainv >= 1 && dainv < 8) FTA(invquotes[dainv - 1], p); } - int weap = PlayerNewWeapon(snum); + int weap = PlayerNewWeapon(plnum); if (weap > 1 && p->kickback_pic > 0) p->wantweaponfire = weap - 1; // Here we have to be extra careful that the weapons do not get mixed up, so let's keep the code for Duke and RR completely separate. - fi.selectweapon(snum, weap); + fi.selectweapon(plnum, weap); - if (PlayerInput(snum, SB_HOLSTER)) + if (PlayerInput(plnum, SB_HOLSTER)) { if (p->curr_weapon > KNEE_WEAPON) { @@ -269,11 +269,11 @@ void hud_input(int snum) } } - if (PlayerUseItem(snum, ICON_HOLODUKE) && (isRR() || p->newowner == -1)) + if (PlayerUseItem(plnum, ICON_HOLODUKE) && (isRR() || p->newOwner == nullptr)) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_HOLODUKEON, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_HOLODUKEON, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { if (!isRR()) { @@ -283,15 +283,15 @@ void hud_input(int snum) { p->inven_icon = 3; - i = + auto pactor = EGS(p->cursectnum, p->posx, p->posy, - p->posz + (30 << 8), TILE_APLAYER, -64, 0, 0, p->angle.ang.asbuild(), 0, 0, -1, 10); - hittype[i].temp_data[3] = hittype[i].temp_data[4] = 0; - p->holoduke_on = &hittype[i]; - sprite[i].yvel = snum; - sprite[i].extra = 0; + p->posz + (30 << 8), TILE_APLAYER, -64, 0, 0, p->angle.ang.asbuild(), 0, 0, nullptr, 10); + pactor->temp_data[3] = pactor->temp_data[4] = 0; + p->holoduke_on = pactor; + pactor->s.yvel = plnum; + pactor->s.extra = 0; FTA(QUOTE_HOLODUKE_ON, p); S_PlayActorSound(TELEPORTER, p->holoduke_on); } @@ -307,82 +307,82 @@ void hud_input(int snum) } else // In RR this means drinking whiskey. { - if (p->holoduke_amount > 0 && sprite[p->i].extra < max_player_health) + if (p->holoduke_amount > 0 && p->GetActor()->s.extra < max_player_health) { p->holoduke_amount -= 400; - sprite[p->i].extra += 5; - if (sprite[p->i].extra > max_player_health) - sprite[p->i].extra = max_player_health; + p->GetActor()->s.extra += 5; + if (p->GetActor()->s.extra > max_player_health) + p->GetActor()->s.extra = max_player_health; p->drink_amt += 5; p->inven_icon = 3; if (p->holoduke_amount == 0) checkavailinven(p); - if (p->drink_amt < 99 && !S_CheckActorSoundPlaying(p->i, 425)) - S_PlayActorSound(425, p->i); + if (p->drink_amt < 99 && !S_CheckActorSoundPlaying(pact, 425)) + S_PlayActorSound(425, pact); } } } } - if (isRR() && PlayerUseItem(snum, ICON_HEATS) && p->newowner == -1) + if (isRR() && PlayerUseItem(plnum, ICON_HEATS) && p->newOwner == nullptr) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_USENIGHTVISION, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_USENIGHTVISION, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { if (p->yehaa_timer == 0) { p->yehaa_timer = 126; - S_PlayActorSound(390, p->i); + S_PlayActorSound(390, pact); p->noise_radius = 16384; - madenoise(snum); + madenoise(plnum); if (sector[p->cursectnum].lotag == 857) { - if (sprite[p->i].extra <= max_player_health) + if (p->GetActor()->s.extra <= max_player_health) { - sprite[p->i].extra += 10; - if (sprite[p->i].extra >= max_player_health) - sprite[p->i].extra = max_player_health; + p->GetActor()->s.extra += 10; + if (p->GetActor()->s.extra >= max_player_health) + p->GetActor()->s.extra = max_player_health; } } else { - if (sprite[p->i].extra + 1 <= max_player_health) + if (p->GetActor()->s.extra + 1 <= max_player_health) { - sprite[p->i].extra++; + p->GetActor()->s.extra++; } } } } } - if (PlayerUseItem(snum, ICON_FIRSTAID)) + if (PlayerUseItem(plnum, ICON_FIRSTAID)) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_USEMEDKIT, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_USEMEDKIT, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { - if (p->firstaid_amount > 0 && sprite[p->i].extra < max_player_health) + if (p->firstaid_amount > 0 && p->GetActor()->s.extra < max_player_health) { if (!isRR()) { - int j = max_player_health - sprite[p->i].extra; + int j = max_player_health - p->GetActor()->s.extra; if ((unsigned int)p->firstaid_amount > j) { p->firstaid_amount -= j; - sprite[p->i].extra = max_player_health; + p->GetActor()->s.extra = max_player_health; p->inven_icon = 1; } else { - sprite[p->i].extra += p->firstaid_amount; + p->GetActor()->s.extra += p->firstaid_amount; p->firstaid_amount = 0; checkavailinven(p); } - S_PlayActorSound(DUKE_USEMEDKIT, p->i); + S_PlayActorSound(DUKE_USEMEDKIT, pact); } else { @@ -390,32 +390,32 @@ void hud_input(int snum) if (p->firstaid_amount > j) { p->firstaid_amount -= j; - sprite[p->i].extra += j; - if (sprite[p->i].extra > max_player_health) - sprite[p->i].extra = max_player_health; + p->GetActor()->s.extra += j; + if (p->GetActor()->s.extra > max_player_health) + p->GetActor()->s.extra = max_player_health; p->inven_icon = 1; } else { - sprite[p->i].extra += p->firstaid_amount; + p->GetActor()->s.extra += p->firstaid_amount; p->firstaid_amount = 0; checkavailinven(p); } - if (sprite[p->i].extra > max_player_health) - sprite[p->i].extra = max_player_health; + if (p->GetActor()->s.extra > max_player_health) + p->GetActor()->s.extra = max_player_health; p->drink_amt += 10; - if (p->drink_amt <= 100 && !S_CheckActorSoundPlaying(p->i, DUKE_USEMEDKIT)) - S_PlayActorSound(DUKE_USEMEDKIT, p->i); + if (p->drink_amt <= 100 && !S_CheckActorSoundPlaying(pact, DUKE_USEMEDKIT)) + S_PlayActorSound(DUKE_USEMEDKIT, pact); } } } } - if (PlayerUseItem(snum, ICON_JETPACK) && (isRR() || p->newowner == -1)) + if (PlayerUseItem(plnum, ICON_JETPACK) && (isRR() || p->newOwner == nullptr)) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_USEJETPACK, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_USEJETPACK, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) == 0) { if (!isRR()) { @@ -426,17 +426,17 @@ void hud_input(int snum) { p->inven_icon = 4; - S_StopSound(-1, p->i, CHAN_VOICE); // this will stop the falling scream - S_PlayActorSound(DUKE_JETPACK_ON, p->i); + S_StopSound(-1, pact, CHAN_VOICE); // this will stop the falling scream + S_PlayActorSound(DUKE_JETPACK_ON, pact); FTA(QUOTE_JETPACK_ON, p); } else { p->hard_landing = 0; p->poszv = 0; - S_PlayActorSound(DUKE_JETPACK_OFF, p->i); - S_StopSound(DUKE_JETPACK_IDLE, p->i); - S_StopSound(DUKE_JETPACK_ON, p->i); + S_PlayActorSound(DUKE_JETPACK_OFF, pact); + S_StopSound(DUKE_JETPACK_IDLE, pact); + S_StopSound(DUKE_JETPACK_ON, pact); FTA(QUOTE_JETPACK_OFF, p); } } @@ -445,10 +445,10 @@ void hud_input(int snum) else { // eat cow pie - if (p->jetpack_amount > 0 && sprite[p->i].extra < max_player_health) + if (p->jetpack_amount > 0 && p->GetActor()->s.extra < max_player_health) { - if (!S_CheckActorSoundPlaying(p->i, 429)) - S_PlayActorSound(429, p->i); + if (!S_CheckActorSoundPlaying(pact, 429)) + S_PlayActorSound(429, pact); p->jetpack_amount -= 100; if (p->drink_amt > 0) @@ -465,12 +465,12 @@ void hud_input(int snum) p->eat = 100; } - sprite[p->i].extra += 5; + p->GetActor()->s.extra += 5; p->inven_icon = 4; - if (sprite[p->i].extra > max_player_health) - sprite[p->i].extra = max_player_health; + if (p->GetActor()->s.extra > max_player_health) + p->GetActor()->s.extra = max_player_health; if (p->jetpack_amount <= 0) checkavailinven(p); @@ -479,11 +479,11 @@ void hud_input(int snum) } } - if (PlayerInput(snum, SB_TURNAROUND) && p->angle.spin.asbam() == 0 && p->on_crane == nullptr) + if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin.asbam() == 0 && p->on_crane == nullptr) { - SetGameVarID(g_iReturnVarID, 0, -1, snum); - OnEvent(EVENT_TURNAROUND, -1, snum, -1); - if (GetGameVarID(g_iReturnVarID, -1, snum) != 0) + SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); + OnEvent(EVENT_TURNAROUND, plnum, nullptr, -1); + if (GetGameVarID(g_iReturnVarID, nullptr, plnum) != 0) { p->sync.actions &= ~SB_TURNAROUND; } @@ -510,7 +510,8 @@ enum MAXANGVEL = 1024, // 127 MAXHORIZVEL = 256, // 127 - MAXVELMOTO = 120 + MAXVELMOTO = 120, + VEHICLETURN = 20 }; //--------------------------------------------------------------------------- @@ -521,7 +522,12 @@ enum static void processInputBits(player_struct *p, ControlInfo* const hidInput) { - ApplyGlobalInput(loc, hidInput); + // Set-up crouch bools. + int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0; + bool const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); + bool const disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat)); + + ApplyGlobalInput(loc, hidInput, crouchable, disableToggle); if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; if (p->OnMotorcycle || p->OnBoat) @@ -535,38 +541,11 @@ static void processInputBits(player_struct *p, ControlInfo* const hidInput) if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) // this shares a bit with another function so cannot be in the common code. loc.actions |= SB_QUICK_KICK; - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || p->crouch_toggle) - { - loc.actions |= SB_CROUCH; - } if ((isRR() && p->drink_amt > 88)) loc.actions |= SB_LOOK_LEFT; if ((isRR() && p->drink_amt > 99)) loc.actions |= SB_LOOK_DOWN; } } -//--------------------------------------------------------------------------- -// -// split off so that it can later be integrated into the other games more easily. -// -//--------------------------------------------------------------------------- - -static void checkCrouchToggle(player_struct* p) -{ - int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0; - int const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); - - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) - { - p->crouch_toggle = !p->crouch_toggle && crouchable; - - if (crouchable) - buttonMap.ClearButton(gamefunc_Toggle_Crouch); - } - - if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || p->jetpack_on || (!crouchable && p->on_ground)) - p->crouch_toggle = 0; -} - //--------------------------------------------------------------------------- // // @@ -586,67 +565,70 @@ int getticssincelastupdate() // //--------------------------------------------------------------------------- -static double motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, bool goback, double factor) +static double motoApplyTurn(player_struct* p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, double const factor) { - int turnvel = 0; + double turnvel = 0; p->oTiltStatus = p->TiltStatus; if (p->MotoSpeed == 0 || !p->on_ground) { turnheldtime = 0; lastcontroltime = 0; - if (turnl) + + if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) { - p->TiltStatus -= (float)factor; + p->TiltStatus -= factor; if (p->TiltStatus < -10) p->TiltStatus = -10; } - else if (turnr) + else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw > 0) { - p->TiltStatus += (float)factor; + p->TiltStatus += factor; if (p->TiltStatus > 10) p->TiltStatus = 10; } } else { - int tics = getticssincelastupdate(); - if (turnl || turnr || p->moto_drink != 0) + if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) { - if (turnl || p->moto_drink < 0) + auto const baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dz < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + int tics = getticssincelastupdate(); + + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) { turnheldtime += tics; - p->TiltStatus -= (float)factor; + p->TiltStatus -= factor; + if (p->TiltStatus < -10) p->TiltStatus = -10; - if (turnheldtime >= TURBOTURNTIME && p->MotoSpeed > 0) - { - if (goback) turnvel += bike_turn ? 40 : 20; - else turnvel += bike_turn ? -40 : -20; - } - else - { - if (goback) turnvel += bike_turn ? 20 : 6; - else turnvel += bike_turn ? -20 : -6; - } + + if (kbdLeft) + turnvel -= turnheldtime >= TURBOTURNTIME && p->MotoSpeed > 0 ? baseVel : baseVel * (3. / 10.); + + if (hidInput->mouseturnx < 0) + turnvel -= sqrt((p->MotoSpeed > 0 ? baseVel : baseVel * (3. / 10.)) * -(hidInput->mouseturnx / factor) * 2.); + + if (hidInput->dyaw < 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * (3. / 10.)) * hidInput->dyaw; } - if (turnr || p->moto_drink > 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw > 0) { turnheldtime += tics; - p->TiltStatus += (float)factor; + p->TiltStatus += factor; + if (p->TiltStatus > 10) p->TiltStatus = 10; - if (turnheldtime >= TURBOTURNTIME && p->MotoSpeed > 0) - { - if (goback) turnvel += bike_turn ? -40 : -20; - else turnvel += bike_turn ? 40 : 20; - } - else - { - if (goback) turnvel += bike_turn ? -20 : -6; - else turnvel += bike_turn ? 20 : 6; - } + + if (kbdRight) + turnvel += turnheldtime >= TURBOTURNTIME && p->MotoSpeed > 0 ? baseVel : baseVel * (3. / 10.); + + if (hidInput->mouseturnx > 0) + turnvel += sqrt((p->MotoSpeed > 0 ? baseVel : baseVel * (3. / 10.)) * (hidInput->mouseturnx / factor) * 2.); + + if (hidInput->dyaw > 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * (3. / 10.)) * hidInput->dyaw; } } else @@ -655,9 +637,9 @@ static double motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_tur lastcontroltime = 0; if (p->TiltStatus > 0) - p->TiltStatus -= (float)factor; + p->TiltStatus -= factor; else if (p->TiltStatus < 0) - p->TiltStatus += (float)factor; + p->TiltStatus += factor; } } @@ -673,55 +655,59 @@ static double motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_tur // //--------------------------------------------------------------------------- -static double boatApplyTurn(player_struct *p, int turnl, int turnr, int boat_turn, double factor) +static double boatApplyTurn(player_struct *p, ControlInfo* const hidInput, bool const kbdLeft, bool const kbdRight, double const factor) { - int turnvel = 0; - int tics = getticssincelastupdate(); + double turnvel = 0; + p->oTiltStatus = p->TiltStatus; if (p->MotoSpeed) { - if (turnl || turnr || p->moto_drink != 0) + if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) { - if (turnl || p->moto_drink < 0) + double const velScale = 6. / 19.; + auto const baseVel = !p->NotOnWater ? VEHICLETURN : VEHICLETURN * velScale; + int tics = getticssincelastupdate(); + + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw < 0) { turnheldtime += tics; + if (!p->NotOnWater) { - p->TiltStatus -= (float)factor; + p->TiltStatus -= factor; if (p->TiltStatus < -10) p->TiltStatus = -10; } - if (turnheldtime >= TURBOTURNTIME) - { - if (p->NotOnWater) turnvel += boat_turn ? -12 : -6; - else turnvel += boat_turn ? -40 : -20; - } - else - { - if (p->NotOnWater) turnvel += boat_turn ? -4 : -2; - else turnvel += boat_turn ? -12 : -6; - } + + if (kbdLeft) + turnvel -= turnheldtime >= TURBOTURNTIME ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx < 0) + turnvel -= sqrt(baseVel * -(hidInput->mouseturnx / factor) * 2.); + + if (hidInput->dyaw < 0) + turnvel += baseVel * hidInput->dyaw; } - if (turnr || p->moto_drink > 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw > 0) { turnheldtime += tics; + if (!p->NotOnWater) { - p->TiltStatus += (float)factor; + p->TiltStatus += factor; if (p->TiltStatus > 10) p->TiltStatus = 10; } - if (turnheldtime >= TURBOTURNTIME) - { - if (p->NotOnWater) turnvel += boat_turn ? 12 : 6; - else turnvel += boat_turn ? 40 : 20; - } - else - { - if (p->NotOnWater) turnvel += boat_turn ? 4 : 2; - else turnvel += boat_turn ? 12 : 6; - } + + if (kbdRight) + turnvel += turnheldtime >= TURBOTURNTIME ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx > 0) + turnvel += sqrt(baseVel * (hidInput->mouseturnx / factor) * 2.); + + if (hidInput->dyaw > 0) + turnvel += baseVel * hidInput->dyaw; } } else if (!p->NotOnWater) @@ -730,9 +716,9 @@ static double boatApplyTurn(player_struct *p, int turnl, int turnr, int boat_tur lastcontroltime = 0; if (p->TiltStatus > 0) - p->TiltStatus -= (float)factor; + p->TiltStatus -= factor; else if (p->TiltStatus < 0) - p->TiltStatus += (float)factor; + p->TiltStatus += factor; } } else if (!p->NotOnWater) @@ -741,9 +727,9 @@ static double boatApplyTurn(player_struct *p, int turnl, int turnr, int boat_tur lastcontroltime = 0; if (p->TiltStatus > 0) - p->TiltStatus -= (float)factor; + p->TiltStatus -= factor; else if (p->TiltStatus < 0) - p->TiltStatus += (float)factor; + p->TiltStatus += factor; } if (fabs(p->TiltStatus) < factor) @@ -758,55 +744,35 @@ static double boatApplyTurn(player_struct *p, int turnl, int turnr, int boat_tur // //--------------------------------------------------------------------------- -static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, InputPacket& input, double scaleAdjust) +static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, InputPacket& input, double const scaleAdjust) { - auto turnspeed = hidInput->mouseturnx + scaleAdjust * hidInput->dyaw * (1. / 32); // originally this was 64, not 32. Why the change? - int turnl = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); - int turnr = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); - - // Cancel out micro-movement - const double turn_threshold = 1 / 65536.; - if (turnspeed < -turn_threshold) - turnl = 1; - else if (turnspeed > turn_threshold) - turnr = 1; - else - turnspeed = 0; + bool const kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); + bool const kbdRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); + p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw < 0; + p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw > 0; if (p->OnBoat || !p->moto_underwater) { - if (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) - loc.actions |= SB_JUMP; - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - p->vehicle_backwards = true; + p->vehForwardScale = std::min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->dz, 1.f); + p->vehReverseScale = std::min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->dz, 1.f); + if (loc.actions & SB_RUN) loc.actions |= SB_CROUCH; } - if (turnl) p->vehicle_turnl = true; - if (turnr) p->vehicle_turnr = true; - - double turnvel; - if (p->OnMotorcycle) { - bool backward = buttonMap.ButtonDown(gamefunc_Move_Backward) && p->MotoSpeed <= 0; - - turnvel = motoApplyTurn(p, turnl, turnr, turnspeed, backward, scaleAdjust); + input.avel = motoApplyTurn(p, hidInput, kbdLeft, kbdRight, scaleAdjust); if (p->moto_underwater) p->MotoSpeed = 0; } else { - turnvel = boatApplyTurn(p, turnl, turnr, turnspeed != 0, scaleAdjust); + input.avel = boatApplyTurn(p, hidInput, kbdLeft, kbdRight, scaleAdjust); } - // What is this? Optimization for playing with a mouse which the original did not have? - if (turnspeed) - turnvel *= clamp(turnspeed * turnspeed, 0., 1.); - - input.fvel = p->MotoSpeed; - input.avel = turnvel * (45. / 256.); - loc.avel = clamp(loc.avel + input.avel, -MAXANGVEL, MAXANGVEL); + input.fvel = xs_CRoundToInt(p->MotoSpeed); + input.avel *= (45. / 256.); + loc.avel += input.avel; } //--------------------------------------------------------------------------- @@ -818,9 +784,9 @@ static void processVehicleInput(player_struct *p, ControlInfo* const hidInput, I static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) { auto p = &ps[playerNum]; - bool blocked = movementBlocked(playerNum) || sprite[p->i].extra <= 0 || (p->dead_flag && !ud.god); + bool blocked = movementBlocked(playerNum) || p->GetActor()->s.extra <= 0 || (p->dead_flag && !ud.god); - if (blocked && ps[playerNum].newowner < 0) + if (blocked && ps[playerNum].newOwner == nullptr) { // neutralize all movement when blocked or in automap follow mode loc.fvel = loc.svel = 0; @@ -845,7 +811,7 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) loc.svel = input.svel = 0; } - if (p->on_crane == nullptr && p->newowner == -1) + if (p->on_crane == nullptr && p->newOwner == nullptr) { // input.avel already added to loc in processMovement() loc.avel = clamp(loc.avel, -MAXANGVEL, MAXANGVEL); @@ -859,7 +825,7 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) loc.avel = input.avel = 0; } - if (p->newowner == -1 && !(p->sync.actions & SB_CENTERVIEW)) + if (p->newOwner == nullptr && !(p->sync.actions & SB_CENTERVIEW)) { // input.horz already added to loc in processMovement() loc.horz = clamp(loc.horz, -MAXHORIZVEL, MAXHORIZVEL); @@ -898,12 +864,11 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { - p->crouch_toggle = 0; processInputBits(p, hidInput); processVehicleInput(p, hidInput, input, scaleAdjust); FinalizeInput(myconnectindex, input, true); - if (!cl_syncinput && sprite[p->i].extra > 0) + if (!cl_syncinput && p->GetActor()->s.extra > 0) { apply_seasick(p, scaleAdjust); } @@ -912,18 +877,17 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { processInputBits(p, hidInput); processMovement(&input, &loc, hidInput, scaleAdjust, p->drink_amt); - checkCrouchToggle(p); FinalizeInput(myconnectindex, input, false); } if (!cl_syncinput) { - if (sprite[p->i].extra > 0) + if (p->GetActor()->s.extra > 0) { // Do these in the same order as the old code. calcviewpitch(p, scaleAdjust); processavel(p, &input.avel); - applylook(&p->angle, input.avel, &p->sync.actions, scaleAdjust, p->crouch_toggle || p->sync.actions & SB_CROUCH); + applylook(&p->angle, input.avel, &p->sync.actions, scaleAdjust); sethorizon(&p->horizon.horiz, input.horz, &p->sync.actions, scaleAdjust); } diff --git a/source/games/duke/src/interpolate.cpp b/source/games/duke/src/interpolate.cpp index c5368bb2f..ecd8aa254 100644 --- a/source/games/duke/src/interpolate.cpp +++ b/source/games/duke/src/interpolate.cpp @@ -100,10 +100,10 @@ void restoreinterpolations() //Stick at end of drawscreen } -void setsectinterpolate(int i) +void setsectinterpolate(int sectnum) { int j, k, startwall,endwall; - auto sect = §or[sprite[i].sectnum]; + auto sect = §or[sectnum]; startwall = sect->wallptr; endwall = startwall+sect->wallnum; @@ -124,10 +124,10 @@ void setsectinterpolate(int i) } } -void clearsectinterpolate(short i) +void clearsectinterpolate(int sectnum) { short j,startwall,endwall; - auto sect = §or[sprite[i].sectnum]; + auto sect = §or[sectnum]; startwall = sect->wallptr; endwall = startwall + sect->wallnum; diff --git a/source/games/duke/src/namelist_r.h b/source/games/duke/src/namelist_r.h index ea59ca1a5..9429bf35c 100644 --- a/source/games/duke/src/namelist_r.h +++ b/source/games/duke/src/namelist_r.h @@ -387,6 +387,7 @@ x(NUKEBARRELDENTED, 1305) x(NUKEBARRELLEAKED, 1306) x(CANWITHSOMETHING, 1309) x(MONEY, 1310) +x(FEATHER, 1310) x(BANNER, 1313) x(EXPLODINGBARREL, 1315) x(EXPLODINGBARREL2, 1316) diff --git a/source/games/duke/src/noise.cpp b/source/games/duke/src/noise.cpp index 4b9fbe642..8f3bf8487 100644 --- a/source/games/duke/src/noise.cpp +++ b/source/games/duke/src/noise.cpp @@ -26,6 +26,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms //------------------------------------------------------------------------- #include "ns.h" #include "duke3d.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -39,20 +40,21 @@ int madenoise(int snum) return 1; } -int wakeup(int i, int snum) +int wakeup(DDukeActor* ac, int snum) { player_struct *p; int radius; p = &ps[snum]; + auto spr = &ac->s; if (!p->donoise) return 0; - if (sprite[i].pal == 30 || sprite[i].pal == 32 || sprite[i].pal == 33 || (isRRRA() && sprite[i].pal == 8)) + if (spr->pal == 30 || spr->pal == 32 || spr->pal == 33 || (isRRRA() && spr->pal == 8)) return 0; radius = p->noise_radius; - if (p->noise_x - radius < sprite[i].x && p->noise_x + radius > sprite[i].x - && p->noise_y - radius < sprite[i].y && p->noise_y + radius > sprite[i].y) + if (p->noise_x - radius < spr->x && p->noise_x + radius > spr->x + && p->noise_y - radius < spr->y && p->noise_y + radius > spr->y) return 1; return 0; } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index bd9cff4ec..a391ea62b 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -58,16 +58,17 @@ void PlayerColorChanged(void) if (ud.recstat != 0) return; + auto& pp = ps[myconnectindex]; if (ud.multimode > 1) { //Net_SendClientInfo(); } else { - ps[myconnectindex].palookup = ud.user_pals[myconnectindex] = playercolor2lookup(playercolor); + pp.palookup = ud.user_pals[myconnectindex] = playercolor2lookup(playercolor); } - if (sprite[ps[myconnectindex].i].picnum == TILE_APLAYER && sprite[ps[myconnectindex].i].pal != 1) - sprite[ps[myconnectindex].i].pal = ud.user_pals[myconnectindex]; + if (pp.GetActor()->s.picnum == TILE_APLAYER && pp.GetActor()->s.pal != 1) + pp.GetActor()->s.pal = ud.user_pals[myconnectindex]; } //--------------------------------------------------------------------------- @@ -124,7 +125,7 @@ void calcviewpitch(player_struct *p, double factor) // //--------------------------------------------------------------------------- -void setpal(struct player_struct* p) +int setpal(struct player_struct* p) { int palette; if (p->DrugMode) palette = DRUGPAL; @@ -133,7 +134,7 @@ void setpal(struct player_struct* p) else if (sector[p->cursectnum].ceilingpicnum >= TILE_FLOORSLIME && sector[p->cursectnum].ceilingpicnum <= TILE_FLOORSLIME + 2) palette = SLIMEPAL; else if (sector[p->cursectnum].lotag == ST_2_UNDERWATER) palette = WATERPAL; else palette = BASEPAL; - p->palette = palette; + return palette; } //--------------------------------------------------------------------------- @@ -146,9 +147,10 @@ void quickkill(struct player_struct* p) { SetPlayerPal(p, PalEntry(48, 48, 48, 48)); - sprite[p->i].extra = 0; - sprite[p->i].cstat |= 32768; - if (ud.god == 0) fi.guts(&sprite[p->i], TILE_JIBS6, 8, myconnectindex); + auto pa = p->GetActor(); + pa->s.extra = 0; + pa->s.cstat |= 32768; + if (ud.god == 0) fi.guts(pa, TILE_JIBS6, 8, myconnectindex); return; } @@ -198,9 +200,9 @@ void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n) if (sect >= 0) { if (sector[sect].lotag == 2) - EGS(sect, x1, y1, z1, TILE_WATERBUBBLE, -32, 4 + (krand() & 3), 4 + (krand() & 3), krand() & 2047, 0, 0, ps[0].i, 5); + EGS(sect, x1, y1, z1, TILE_WATERBUBBLE, -32, 4 + (krand() & 3), 4 + (krand() & 3), krand() & 2047, 0, 0, ps[0].GetActor(), 5); else - EGS(sect, x1, y1, z1, TILE_SMALLSMOKE, -32, 14, 14, 0, 0, 0, ps[0].i, 5); + EGS(sect, x1, y1, z1, TILE_SMALLSMOKE, -32, 14, 14, 0, 0, 0, ps[0].GetActor(), 5); } } } @@ -211,18 +213,19 @@ void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n) // //--------------------------------------------------------------------------- -int hits(int i) +int hits(DDukeActor* actor) { - auto sp = &sprite[i]; + auto sp = &actor->s; int sx, sy, sz; short sect; - short hw, hs; + short hw; int zoff; + DDukeActor* d; if (sp->picnum == TILE_APLAYER) zoff = (40 << 8); else zoff = 0; - hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, sintable[(sp->ang + 512) & 2047], sintable[sp->ang & 2047], 0, §, &hw, &hs, &sx, &sy, &sz, CLIPMASK1); + hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, sintable[(sp->ang + 512) & 2047], sintable[sp->ang & 2047], 0, §, &hw, &d, &sx, &sy, &sz, CLIPMASK1); return (FindDistance2D(sx - sp->x, sy - sp->y)); } @@ -233,20 +236,20 @@ int hits(int i) // //--------------------------------------------------------------------------- -int hitasprite(int i, short* hitsp) +int hitasprite(DDukeActor* actor, DDukeActor** hitsp) { - auto sp = &sprite[i]; + auto sp = &actor->s; int sx, sy, sz, zoff; short sect, hw; - if (badguy(&sprite[i])) + if (badguy(actor)) zoff = (42 << 8); else if (sp->picnum == TILE_APLAYER) zoff = (39 << 8); else zoff = 0; hitscan(sp->x, sp->y, sp->z - zoff, sp->sectnum, sintable[(sp->ang + 512) & 2047], sintable[sp->ang & 2047], 0, §, &hw, hitsp, &sx, &sy, &sz, CLIPMASK1); - if (hw >= 0 && (wall[hw].cstat & 16) && badguy(&sprite[i])) + if (hw >= 0 && (wall[hw].cstat & 16) && badguy(actor)) return((1 << 30)); return (FindDistance2D(sx - sp->x, sy - sp->y)); @@ -261,10 +264,11 @@ int hitasprite(int i, short* hitsp) int hitawall(struct player_struct* p, int* hitw) { int sx, sy, sz; - short sect, hs, hitw1; + short sect, hitw1; + DDukeActor* d; hitscan(p->posx, p->posy, p->posz, p->cursectnum, - sintable[(p->angle.ang.asbuild() + 512) & 2047], sintable[p->angle.ang.asbuild() & 2047], 0, §, &hitw1, &hs, &sx, &sy, &sz, CLIPMASK0); + sintable[(p->angle.ang.asbuild() + 512) & 2047], sintable[p->angle.ang.asbuild() & 2047], 0, §, &hitw1, &d, &sx, &sy, &sz, CLIPMASK0); *hitw = hitw1; return (FindDistance2D(sx - p->posx, sy - p->posy)); @@ -277,13 +281,14 @@ int hitawall(struct player_struct* p, int* hitw) // //--------------------------------------------------------------------------- -int aim(spritetype* s, int aang) +DDukeActor* aim(DDukeActor* actor, int aang) { char gotshrinker, gotfreezer; - int i, j, a, k, cans; + int a, k, cans; int aimstats[] = { STAT_PLAYER, STAT_DUMMYPLAYER, STAT_ACTOR, STAT_ZOMBIEACTOR }; int dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist; int xv, yv; + auto s = &actor->s; a = s->ang; @@ -294,7 +299,7 @@ int aim(spritetype* s, int aang) { // The chickens in RRRA are homing and must always autoaim. if (!isRRRA() || ps[s->yvel].curr_weapon != CHICKEN_WEAPON) - return -1; + return nullptr; } else if (ps[s->yvel].auto_aim == 2) { @@ -309,12 +314,12 @@ int aim(spritetype* s, int aang) } if (weap > CHAINGUN_WEAPON || weap == KNEE_WEAPON) { - return -1; + return nullptr; } } } - j = -1; + DDukeActor* aimed = nullptr; // if(s->picnum == TILE_APLAYER && ps[s->yvel].aim_mode) return -1; if (isRR()) @@ -345,13 +350,13 @@ int aim(spritetype* s, int aang) for (k = 0; k < 4; k++) { - if (j >= 0) + if (aimed) break; - StatIterator it(aimstats[k]); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(aimstats[k]); + while (auto act = it.Next()) { - auto sp = &sprite[i]; + auto sp = &act->s; if (sp->xrepeat > 0 && sp->extra >= 0 && (sp->cstat & (257 + 32768)) == 257) if (badguy(sp) || k < 2) { @@ -386,7 +391,7 @@ int aim(spritetype* s, int aang) if (a && cans) { smax = sdist; - j = i; + aimed = act; } } } @@ -394,7 +399,7 @@ int aim(spritetype* s, int aang) } } - return j; + return aimed; } //--------------------------------------------------------------------------- @@ -403,7 +408,7 @@ int aim(spritetype* s, int aang) // //--------------------------------------------------------------------------- -void dokneeattack(int snum, int pi, const std::initializer_list & respawnlist) +void dokneeattack(int snum, const std::initializer_list & respawnlist) { auto p = &ps[snum]; @@ -418,10 +423,10 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli p->holster_weapon = 0; if (p->weapon_pos < 0) p->weapon_pos = -p->weapon_pos; - if (p->actorsqu != nullptr && dist(&sprite[pi], &p->actorsqu->s) < 1400) + if (p->actorsqu != nullptr && dist(p->GetActor(), p->actorsqu) < 1400) { - fi.guts(&p->actorsqu->s, TILE_JIBS6, 7, myconnectindex); - fi.spawn(p->actorsqu->GetIndex(), TILE_BLOODPOOL); + fi.guts(p->actorsqu, TILE_JIBS6, 7, myconnectindex); + spawn(p->actorsqu, TILE_BLOODPOOL); S_PlayActorSound(SQUISHED, p->actorsqu); if (isIn(p->actorsqu->s.picnum, respawnlist)) { @@ -456,8 +461,8 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli int makepainsounds(int snum, int type) { auto p = &ps[snum]; - auto pi = p->i; - auto s = &sprite[pi]; + auto actor = p->GetActor(); + auto s = &actor->s; int k = 0; switch (type) @@ -469,12 +474,12 @@ int makepainsounds(int snum, int type) k = 1; else { - if (!S_CheckActorSoundPlaying(pi, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); + if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, actor); SetPlayerPal(p, PalEntry(32, 64, 64, 64)); s->extra -= 1 + (krand() & 3); - if (!S_CheckActorSoundPlaying(pi, SHORT_CIRCUIT)) - S_PlayActorSound(SHORT_CIRCUIT, pi); + if (!S_CheckActorSoundPlaying(actor, SHORT_CIRCUIT)) + S_PlayActorSound(SHORT_CIRCUIT, actor); } } break; @@ -485,8 +490,8 @@ int makepainsounds(int snum, int type) k = 1; else { - if (!S_CheckActorSoundPlaying(pi, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); + if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, actor); SetPlayerPal(p, PalEntry(32, 0, 8, 0)); s->extra -= 1 + (krand() & 3); } @@ -499,8 +504,8 @@ int makepainsounds(int snum, int type) k = 1; else { - if (!S_CheckActorSoundPlaying(pi, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); + if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, actor); SetPlayerPal(p, PalEntry(32, 8, 0, 0)); s->extra -= 1 + (krand() & 3); } @@ -514,7 +519,7 @@ int makepainsounds(int snum, int type) s->extra -= 2; else s->extra -= 4; - S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); + S_PlayActorSound(DUKE_LONGTERM_PAIN, actor); } break; } @@ -530,36 +535,40 @@ int makepainsounds(int snum, int type) void footprints(int snum) { auto p = &ps[snum]; - auto pi = p->i; - auto s = &sprite[pi]; + auto actor = p->GetActor(); + auto s = &actor->s; auto psect = s->sectnum; if (p->footprintcount > 0 && p->on_ground) if ((sector[p->cursectnum].floorstat & 2) != 2) { - int j; - SectIterator it(psect); - while ((j = it.NextIndex()) >= 0) + int j = -1; + DukeSectIterator it(psect); + while (auto act = it.Next()) { - if (sprite[j].picnum == TILE_FOOTPRINTS || sprite[j].picnum == TILE_FOOTPRINTS2 || sprite[j].picnum == TILE_FOOTPRINTS3 || sprite[j].picnum == TILE_FOOTPRINTS4) - if (abs(sprite[j].x - p->posx) < 384) - if (abs(sprite[j].y - p->posy) < 384) + if (act->s.picnum == TILE_FOOTPRINTS || act->s.picnum == TILE_FOOTPRINTS2 || act->s.picnum == TILE_FOOTPRINTS3 || act->s.picnum == TILE_FOOTPRINTS4) + if (abs(act->s.x - p->posx) < 384) + if (abs(act->s.y - p->posy) < 384) + { + j = 1; break; + } } if (j < 0) { p->footprintcount--; if (sector[p->cursectnum].lotag == 0 && sector[p->cursectnum].hitag == 0) { + DDukeActor* fprint; switch (krand() & 3) { - case 0: j = fi.spawn(pi, TILE_FOOTPRINTS); break; - case 1: j = fi.spawn(pi, TILE_FOOTPRINTS2); break; - case 2: j = fi.spawn(pi, TILE_FOOTPRINTS3); break; - default: j = fi.spawn(pi, TILE_FOOTPRINTS4); break; + case 0: fprint = spawn(actor, TILE_FOOTPRINTS); break; + case 1: fprint = spawn(actor, TILE_FOOTPRINTS2); break; + case 2: fprint = spawn(actor, TILE_FOOTPRINTS3); break; + default: fprint = spawn(actor, TILE_FOOTPRINTS4); break; } - sprite[j].pal = p->footprintpal; - sprite[j].shade = p->footprintshade; + fprint->s.pal = p->footprintpal; + fprint->s.shade = p->footprintshade; } } } @@ -581,8 +590,8 @@ inline void backupplayer(player_struct* p) void playerisdead(int snum, int psectlotag, int fz, int cz) { auto p = &ps[snum]; - auto pi = p->i; - auto s = &sprite[pi]; + auto actor = p->GetActor(); + auto s = &actor->s; if (p->dead_flag == 0) { @@ -603,8 +612,8 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) p->jetpack_on = 0; p->holoduke_on = nullptr; - if (!isRR())S_StopSound(DUKE_JETPACK_IDLE, pi); - S_StopSound(-1, pi, CHAN_VOICE); + if (!isRR())S_StopSound(DUKE_JETPACK_IDLE, actor); + S_StopSound(-1, actor, CHAN_VOICE); if (s->pal != 1 && (s->cstat & 32768) == 0) s->cstat = 0; @@ -655,9 +664,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) s->zvel = -348; } - clipmove(&p->posx, &p->posy, - &p->posz, &p->cursectnum, - 0, 0, 164L, (4L << 8), (4L << 8), CLIPMASK0); + clipmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0); // p->bobcounter += 32; } @@ -667,7 +674,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) updatesector(p->posx, p->posy, &p->cursectnum); - pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4L << 8), (20L << 8), CLIPMASK0); + pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4 << 8), (20 << 8), CLIPMASK0); if (fz > cz + (16 << 8) && s->pal != 1) p->angle.rotscrnang = buildlook(p->dead_flag + ((fz + p->posz) >> 7)); @@ -741,9 +748,9 @@ void playerCrouch(int snum) { auto p = &ps[snum]; // crouching - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_CROUCH, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_CROUCH, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->posz += (2048 + 768); p->crack_time = CRACK_TIME; @@ -757,9 +764,9 @@ void playerJump(int snum, int fz, int cz) { if ((fz - cz) > (56 << 8)) { - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_JUMP, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_JUMP, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->jumping_counter = 1; p->jumping_toggle = 1; @@ -904,9 +911,9 @@ void checklook(int snum, ESyncBits actions) if ((actions & SB_LOOK_LEFT) && !p->OnMotorcycle) { - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_LOOKLEFT, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_LOOKLEFT, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) != 0) { actions &= ~SB_LOOK_LEFT; } @@ -914,9 +921,9 @@ void checklook(int snum, ESyncBits actions) if ((actions & SB_LOOK_RIGHT) && !p->OnMotorcycle) { - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_LOOKRIGHT, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_LOOKRIGHT, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) != 0) { actions &= ~SB_LOOK_RIGHT; } @@ -933,9 +940,9 @@ void checklook(int snum, ESyncBits actions) void playerCenterView(int snum) { auto p = &ps[snum]; - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_RETURNTOCENTER, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_RETURNTOCENTER, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->sync.actions |= SB_CENTERVIEW; } @@ -948,9 +955,9 @@ void playerCenterView(int snum) void playerLookUp(int snum, ESyncBits actions) { auto p = &ps[snum]; - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_LOOKUP, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_LOOKUP, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->sync.actions |= SB_CENTERVIEW; } @@ -963,9 +970,9 @@ void playerLookUp(int snum, ESyncBits actions) void playerLookDown(int snum, ESyncBits actions) { auto p = &ps[snum]; - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_LOOKDOWN, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_LOOKDOWN, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->sync.actions |= SB_CENTERVIEW; } @@ -978,9 +985,9 @@ void playerLookDown(int snum, ESyncBits actions) void playerAimUp(int snum, ESyncBits actions) { auto p = &ps[snum]; - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_AIMUP, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_AIMUP, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) != 0) { p->sync.actions &= ~SB_AIM_UP; } @@ -989,9 +996,9 @@ void playerAimUp(int snum, ESyncBits actions) void playerAimDown(int snum, ESyncBits actions) { auto p = &ps[snum]; - SetGameVarID(g_iReturnVarID, 0, p->i, snum); - OnEvent(EVENT_AIMDOWN, p->i, snum, -1); - if (GetGameVarID(g_iReturnVarID, p->i, snum) != 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_AIMDOWN, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) != 0) { p->sync.actions &= ~SB_AIM_DOWN; } @@ -1025,7 +1032,7 @@ bool movementBlocked(int snum) p->hard_landing || p->access_incs > 0 || p->knee_incs > 0 || - p->newowner >= 0 || + p->newOwner != nullptr || (blockingweapon() && p->kickback_pic > 1 && p->kickback_pic < weapondelay())); } @@ -1062,13 +1069,14 @@ int haskey(int sect, int snum) // //--------------------------------------------------------------------------- -void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST) +void shootbloodsplat(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST) { - spritetype* const s = &sprite[i]; + spritetype* const s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, k; + short hitsect, hitwall; int hitx, hity, hitz; + DDukeActor* d; if (p >= 0) sa += 64 - (krand() & 127); @@ -1079,7 +1087,7 @@ void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, i hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], zvel << 6, - &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + &hitsect, &hitwall, &d, &hitx, &hity, &hitz, CLIPMASK1); // oh my... if (FindDistance2D(sx - hitx, sy - hity) < 1024 && @@ -1095,10 +1103,10 @@ void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, i { if (wall[hitwall].nextsector >= 0) { - SectIterator it(wall[hitwall].nextsector); - while ((k = it.NextIndex()) >= 0) + DukeSectIterator it(wall[hitwall].nextsector); + while (auto act2 = it.Next()) { - if (sprite[k].statnum == 3 && sprite[k].lotag == 13) + if (act2->s.statnum == STAT_EFFECTOR && act2->s.lotag == SE_13_EXPLOSIVE) return; } } @@ -1109,17 +1117,17 @@ void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, i if (wall[hitwall].hitag == 0) { - k = fi.spawn(i, atwith); - sprite[k].xvel = -12; - sprite[k].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) + 512; - sprite[k].x = hitx; - sprite[k].y = hity; - sprite[k].z = hitz; - sprite[k].cstat |= (krand() & 4); - ssp(k, CLIPMASK0); - setsprite(k, sprite[k].x, sprite[k].y, sprite[k].z); + auto spawned = spawn(actor, atwith); + spawned->s.xvel = -12; + spawned->s.ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) + 512; + spawned->s.x = hitx; + spawned->s.y = hity; + spawned->s.z = hitz; + spawned->s.cstat |= (krand() & 4); + ssp(spawned, CLIPMASK0); + setsprite(spawned, spawned->s.pos); if (s->picnum == OOZFILTER || s->picnum == NEWBEAST) - sprite[k].pal = 6; + spawned->s.pal = 6; } } } @@ -1136,19 +1144,20 @@ bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, { spritetype* sp; int i, nx, ny, nz, hx, hy, hitx, hity, hitz; - short bakcstat, hitsect, hitwall, hitsprite, daang; + short bakcstat, hitsect, hitwall, daang; + DDukeActor* hitsprt; nx = (sintable[(ang + 1536) & 2047] >> 4); ny = (sintable[(ang + 1024) & 2047] >> 4); nz = q16horiz >> 9; - sp = &sprite[pp->i]; + sp = &pp->GetActor()->s; bakcstat = sp->cstat; sp->cstat &= (short)~0x101; updatesectorz(*vx, *vy, *vz, vsectnum); - hitscan(*vx, *vy, *vz, *vsectnum, nx, ny, nz, &hitsect, &hitwall, &hitsprite, &hitx, &hity, &hitz, CLIPMASK1); + hitscan(*vx, *vy, *vz, *vsectnum, nx, ny, nz, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); if (*vsectnum < 0) { @@ -1169,7 +1178,7 @@ bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, if (abs(nx) > abs(ny)) hx -= mulscale28(nx, i); else hy -= mulscale28(ny, i); } - else if (hitsprite < 0) + else if (!hitsprt) { if (abs(nx) > abs(ny)) hx -= (nx >> 5); else hy -= (ny >> 5); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 53c9012cd..4d721ed50 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -54,9 +54,9 @@ void incur_damage_d(struct player_struct* p) { int damage = 0L, shield_damage = 0L; - sprite[p->i].extra -= p->extra_extra8 >> 8; + p->GetActor()->s.extra -= p->extra_extra8 >> 8; - damage = sprite[p->i].extra - p->last_extra; + damage = p->GetActor()->s.extra - p->last_extra; if (damage < 0) { @@ -76,7 +76,7 @@ void incur_damage_d(struct player_struct* p) } } - sprite[p->i].extra = p->last_extra + damage; + p->GetActor()->s.extra = p->last_extra + damage; } } @@ -87,16 +87,16 @@ void incur_damage_d(struct player_struct* p) // //--------------------------------------------------------------------------- -static void shootfireball(int i, int p, int sx, int sy, int sz, int sa) +static void shootfireball(DDukeActor *actor, int p, int sx, int sy, int sz, int sa) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int vel, zvel; if (s->extra >= 0) s->shade = -96; sz -= (4 << 7); - if (sprite[i].picnum != BOSS5) + if (s->picnum != BOSS5) vel = 840; else { vel = 968; @@ -107,8 +107,8 @@ static void shootfireball(int i, int p, int sx, int sy, int sz, int sa) { sa += 16 - (krand() & 31); int scratch; - int j = findplayer(s, &scratch); - zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s); + int j = findplayer(actor, &scratch); + zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(ps[j].GetActor(), actor); } else { @@ -126,10 +126,10 @@ static void shootfireball(int i, int p, int sx, int sy, int sz, int sa) sizy = 7; } - int j = EGS(s->sectnum, sx, sy, sz, FIREBALL, -127, sizx, sizy, sa, vel, zvel, i, (short)4); - auto spr = &sprite[j]; + auto spawned = EGS(s->sectnum, sx, sy, sz, FIREBALL, -127, sizx, sizy, sa, vel, zvel, actor, (short)4); + auto spr = &spawned->s; spr->extra += (krand() & 7); - if (sprite[i].picnum == BOSS5 || p >= 0) + if (s->picnum == BOSS5 || p >= 0) { spr->xrepeat = 40; spr->yrepeat = 40; @@ -145,78 +145,78 @@ static void shootfireball(int i, int p, int sx, int sy, int sz, int sa) // //--------------------------------------------------------------------------- -static void shootflamethrowerflame(int i, int p, int sx, int sy, int sz, int sa) +static void shootflamethrowerflame(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int vel, zvel; if (s->extra >= 0) s->shade = -96; vel = 400; - int k = -1; + DDukeActor* spawned = nullptr; if (p < 0) { int x; - int j = findplayer(s, &x); + int j = findplayer(actor, &x); sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy); - if (sprite[i].picnum == BOSS5) + if (s->picnum == BOSS5) { vel = 528; sz += 6144; } - else if (sprite[i].picnum == BOSS3) + else if (s->picnum == BOSS3) sz -= 8192; - int l = ldist(&sprite[ps[j].i], s); + int l = ldist(ps[j].GetActor(), actor); if (l != 0) zvel = ((ps[j].oposz - sz) * vel) / l; - if (badguy(s) && (s->hitag & face_player_smart) != 0) + if (badguy(actor) && (s->hitag & face_player_smart) != 0) sa = (short)(s->ang + (krand() & 31) - 16); if (sector[s->sectnum].lotag == 2 && (krand() % 5) == 0) - k = fi.spawn(i, WATERBUBBLE); + spawned = spawn(actor, WATERBUBBLE); } else { zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81); - if (sprite[ps[p].i].xvel != 0) + if (ps[p].GetActor()->s.xvel != 0) vel = (int)((((512 - (1024 - abs(abs(getangle(sx - ps[p].oposx, sy - ps[p].oposy) - sa) - 1024))) - * 0.001953125f) * sprite[ps[p].i].xvel) + 400); + * 0.001953125f) * ps[p].GetActor()->s.xvel) + 400); if (sector[s->sectnum].lotag == 2 && (krand() % 5) == 0) - k = fi.spawn(i, WATERBUBBLE); + spawned = spawn(actor, WATERBUBBLE); } - if (k == -1) + if (spawned == nullptr) { - k = fi.spawn(i, FLAMETHROWERFLAME); - sprite[k].xvel = (short)vel; - sprite[k].zvel = (short)zvel; + spawned = spawn(actor, FLAMETHROWERFLAME); + spawned->s.xvel = (short)vel; + spawned->s.zvel = (short)zvel; } - sprite[k].x = sx + sintable[(sa + 630) & 0x7FF] / 448; - sprite[k].y = sy + sintable[(sa + 112) & 0x7FF] / 448; - sprite[k].z = sz - 256; - sprite[k].sectnum = s->sectnum; - sprite[k].cstat = 0x80; - sprite[k].ang = sa; - sprite[k].xrepeat = 2; - sprite[k].yrepeat = 2; - sprite[k].clipdist = 40; - sprite[k].yvel = p; - sprite[k].owner = (short)i; + spawned->s.x = sx + sintable[(sa + 630) & 0x7FF] / 448; + spawned->s.y = sy + sintable[(sa + 112) & 0x7FF] / 448; + spawned->s.z = sz - 256; + spawned->s.sectnum = s->sectnum; + spawned->s.cstat = 0x80; + spawned->s.ang = sa; + spawned->s.xrepeat = 2; + spawned->s.yrepeat = 2; + spawned->s.clipdist = 40; + spawned->s.yvel = p; + spawned->SetOwner(actor); if (p == -1) { - if (sprite[i].picnum == BOSS5) + if (s->picnum == BOSS5) { - sprite[k].x -= sintable[sa & 2047] / 56; - sprite[k].y -= sintable[(sa + 1024 + 512) & 2047] / 56; - sprite[k].xrepeat = 10; - sprite[k].yrepeat = 10; + spawned->s.x -= sintable[sa & 2047] / 56; + spawned->s.y -= sintable[(sa + 1024 + 512) & 2047] / 56; + spawned->s.xrepeat = 10; + spawned->s.yrepeat = 10; } } } @@ -227,13 +227,14 @@ static void shootflamethrowerflame(int i, int p, int sx, int sy, int sz, int sa) // //--------------------------------------------------------------------------- -static void shootknee(int i, int p, int sx, int sy, int sz, int sa) +static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, j, k; + short hitsect, hitwall; int hitx, hity, hitz; + DDukeActor* hitsprt; if (p >= 0) { @@ -244,39 +245,39 @@ static void shootknee(int i, int p, int sx, int sy, int sz, int sa) else { int x; - j = ps[findplayer(s, &x)].i; - zvel = ((sprite[j].z - sz) << 8) / (x + 1); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + auto pactor = ps[findplayer(actor, &x)].GetActor(); + zvel = ((pactor->s.z - sz) << 8) / (x + 1); + sa = getangle(pactor->s.x - sx, pactor->s.y - sy); } hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], zvel << 6, - &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); if (hitsect < 0) return; if ((abs(sx - hitx) + abs(sy - hity)) < 1024) { - if (hitwall >= 0 || hitspr >= 0) + if (hitwall >= 0 || hitsprt) { - j = EGS(hitsect, hitx, hity, hitz, KNEE, -15, 0, 0, sa, 32, 0, i, 4); - sprite[j].extra += (krand() & 7); + auto knee = EGS(hitsect, hitx, hity, hitz, KNEE, -15, 0, 0, sa, 32, 0, actor, 4); + knee->s.extra += (krand() & 7); if (p >= 0) { - k = fi.spawn(j, SMALLSMOKE); - sprite[k].z -= (8 << 8); - S_PlayActorSound(KICK_HIT, j); + auto k = spawn(knee, SMALLSMOKE); + k->s.z -= (8 << 8); + S_PlayActorSound(KICK_HIT, knee); } if (p >= 0 && ps[p].steroids_amount > 0 && ps[p].steroids_amount < 400) - sprite[j].extra += (max_player_health >> 2); + knee->s.extra += (max_player_health >> 2); - if (hitspr >= 0 && sprite[hitspr].picnum != ACCESSSWITCH && sprite[hitspr].picnum != ACCESSSWITCH2) + if (hitsprt && hitsprt->s.picnum != ACCESSSWITCH && hitsprt->s.picnum != ACCESSSWITCH2) { - fi.checkhitsprite(hitspr, j); - if (p >= 0) fi.checkhitswitch(p, hitspr, 1); + fi.checkhitsprite(hitsprt, knee); + if (p >= 0) fi.checkhitswitch(p, -1, hitsprt); } else if (hitwall >= 0) @@ -288,20 +289,20 @@ static void shootknee(int i, int p, int sx, int sy, int sz, int sa) if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2) { - fi.checkhitwall(j, hitwall, hitx, hity, hitz, KNEE); - if (p >= 0) fi.checkhitswitch(p, hitwall, 0); + fi.checkhitwall(knee, hitwall, hitx, hity, hitz, KNEE); + if (p >= 0) fi.checkhitswitch(p, hitwall, nullptr); } } } else if (p >= 0 && zvel > 0 && sector[hitsect].lotag == 1) { - j = fi.spawn(ps[p].i, WATERSPLASH2); - sprite[j].x = hitx; - sprite[j].y = hity; - sprite[j].ang = ps[p].angle.ang.asbuild(); // Total tweek - sprite[j].xvel = 32; - ssp(i, CLIPMASK0); - sprite[j].xvel = 0; + auto splash = spawn(ps[p].GetActor(), WATERSPLASH2); + splash->s.x = hitx; + splash->s.y = hity; + splash->s.ang = ps[p].angle.ang.asbuild(); // Total tweek + splash->s.xvel = 32; + ssp(actor, CLIPMASK0); + splash->s.xvel = 0; } } @@ -313,30 +314,32 @@ static void shootknee(int i, int p, int sx, int sy, int sz, int sa) // //--------------------------------------------------------------------------- -static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, l, j, k; + short hitsect, hitwall; int hitx, hity, hitz; + DDukeActor* hitact; if (s->extra >= 0) s->shade = -96; if (p >= 0) { - SetGameVarID(g_iAimAngleVarID, AUTO_AIM_ANGLE, i, p); - OnEvent(EVENT_GETAUTOAIMANGLE, i, p, -1); - j = -1; - if (GetGameVarID(g_iAimAngleVarID, i, p) > 0) + SetGameVarID(g_iAimAngleVarID, AUTO_AIM_ANGLE, actor, p); + OnEvent(EVENT_GETAUTOAIMANGLE, p, ps[p].GetActor(), -1); + int varval = GetGameVarID(g_iAimAngleVarID, actor, p); + DDukeActor* aimed = nullptr; + if (varval > 0) { - j = aim(s, GetGameVarID(g_iAimAngleVarID, i, p)); + aimed = aim(actor, varval); } - if (j >= 0) + if (aimed) { - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8); - switch (sprite[j].picnum) + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (5 << 8); + switch (aimed->s.picnum) { case GREENSLIME: case GREENSLIME + 1: @@ -350,29 +353,29 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith dal -= (8 << 8); break; } - zvel = ((sprite[j].z - sz - dal) << 8) / ldist(&sprite[ps[p].i], &sprite[j]); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + zvel = ((aimed->s.z - sz - dal) << 8) / ldist(ps[p].GetActor(), aimed); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } if (isWW2GI()) { int angRange = 32; int zRange = 256; - SetGameVarID(g_iAngRangeVarID, 32, i, p); - SetGameVarID(g_iZRangeVarID, 256, i, p); - OnEvent(EVENT_GETSHOTRANGE, i, p, -1); - angRange = GetGameVarID(g_iAngRangeVarID, i, p); - zRange = GetGameVarID(g_iZRangeVarID, i, p); + SetGameVarID(g_iAngRangeVarID, 32, actor, p); + SetGameVarID(g_iZRangeVarID, 256, actor, p); + OnEvent(EVENT_GETSHOTRANGE, p, ps[p].GetActor(), -1); + angRange = GetGameVarID(g_iAngRangeVarID, actor, p); + zRange = GetGameVarID(g_iZRangeVarID, actor, p); sa += (angRange / 2) - (krand() & (angRange - 1)); - if (j == -1) + if (aimed == nullptr) { // no target zvel = -ps[p].horizon.sum().asq16() >> 11; } zvel += (zRange / 2) - (krand() & (zRange - 1)); } - else if (j == -1) + else if (aimed == nullptr) { sa += 16 - (krand() & 31); zvel = -ps[p].horizon.sum().asq16() >> 11; @@ -384,9 +387,9 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); sz -= (4 << 8); - zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s)); + zvel = ((ps[j].posz - sz) << 8) / (ldist(ps[j].GetActor(), actor)); if (s->picnum != BOSS1) { zvel += 128 - (krand() & 255); @@ -403,67 +406,69 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], - zvel << 6, &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + zvel << 6, &hitsect, &hitwall, &hitact, &hitx, &hity, &hitz, CLIPMASK1); s->cstat |= 257; + if (hitsect < 0) return; if ((krand() & 15) == 0 && sector[hitsect].lotag == 2) tracers(hitx, hity, hitz, sx, sy, sz, 8 - (ud.multimode >> 1)); + DDukeActor* spark; if (p >= 0) { - k = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, i, 4); - sprite[k].extra = ScriptCode[actorinfo[atwith].scriptaddress]; - sprite[k].extra += (krand() % 6); + spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, actor, 4); + spark->s.extra = ScriptCode[actorinfo[atwith].scriptaddress]; + spark->s.extra += (krand() % 6); - if (hitwall == -1 && hitspr == -1) + if (hitwall == -1 && hitact == nullptr) { if (zvel < 0) { if (sector[hitsect].ceilingstat & 1) { - sprite[k].xrepeat = 0; - sprite[k].yrepeat = 0; + spark->s.xrepeat = 0; + spark->s.yrepeat = 0; return; } else fi.checkhitceiling(hitsect); } - fi.spawn(k, SMALLSMOKE); + spawn(spark, SMALLSMOKE); } - if (hitspr >= 0) + if (hitact) { - fi.checkhitsprite(hitspr, k); - if (sprite[hitspr].picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1)) + fi.checkhitsprite(hitact, spark); + if (hitact->s.picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1)) { - l = fi.spawn(k, JIBS6); - sprite[k].xrepeat = sprite[k].yrepeat = 0; - sprite[l].z += (4 << 8); - sprite[l].xvel = 16; - sprite[l].xrepeat = sprite[l].yrepeat = 24; - sprite[l].ang += 64 - (krand() & 127); + auto jib = spawn(spark, JIBS6); + spark->s.xrepeat = spark->s.yrepeat = 0; + jib->s.z += (4 << 8); + jib->s.xvel = 16; + jib->s.xrepeat = jib->s.yrepeat = 24; + jib->s.ang += 64 - (krand() & 127); } - else fi.spawn(k, SMALLSMOKE); + else spawn(spark, SMALLSMOKE); if (p >= 0 && ( - sprite[hitspr].picnum == DIPSWITCH || - sprite[hitspr].picnum == DIPSWITCH + 1 || - sprite[hitspr].picnum == DIPSWITCH2 || - sprite[hitspr].picnum == DIPSWITCH2 + 1 || - sprite[hitspr].picnum == DIPSWITCH3 || - sprite[hitspr].picnum == DIPSWITCH3 + 1 || - sprite[hitspr].picnum == HANDSWITCH || - sprite[hitspr].picnum == HANDSWITCH + 1)) + hitact->s.picnum == DIPSWITCH || + hitact->s.picnum == DIPSWITCH + 1 || + hitact->s.picnum == DIPSWITCH2 || + hitact->s.picnum == DIPSWITCH2 + 1 || + hitact->s.picnum == DIPSWITCH3 || + hitact->s.picnum == DIPSWITCH3 + 1 || + hitact->s.picnum == HANDSWITCH || + hitact->s.picnum == HANDSWITCH + 1)) { - fi.checkhitswitch(p, hitspr, 1); + fi.checkhitswitch(p, -1, hitact); return; } } else if (hitwall >= 0) { - fi.spawn(k, SMALLSMOKE); + spawn(spark, SMALLSMOKE); if (fi.isadoorwall(wall[hitwall].picnum) == 1) goto SKIPBULLETHOLE; @@ -477,7 +482,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith wall[hitwall].picnum == HANDSWITCH || wall[hitwall].picnum == HANDSWITCH + 1)) { - fi.checkhitswitch(p, hitwall, 0); + fi.checkhitswitch(p, hitwall, nullptr); return; } @@ -492,26 +497,26 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith { if (wall[hitwall].nextsector >= 0) { - SectIterator it(wall[hitwall].nextsector); - while ((l = it.NextIndex()) >= 0) + DukeSectIterator it(wall[hitwall].nextsector); + while (auto l = it.Next()) { - if (sprite[l].statnum == 3 && sprite[l].lotag == 13) + if (l->s.statnum == 3 && l->s.lotag == 13) goto SKIPBULLETHOLE; } } - StatIterator it(STAT_MISC); - while ((l = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto l = it.Next()) { - if (sprite[l].picnum == BULLETHOLE) - if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) + if (l->s.picnum == BULLETHOLE) + if (dist(l, spark) < (12 + (krand() & 7))) goto SKIPBULLETHOLE; } - l = fi.spawn(k, BULLETHOLE); - sprite[l].xvel = -1; - sprite[l].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, + auto hole = spawn(spark, BULLETHOLE); + hole->s.xvel = -1; + hole->s.ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) + 512; - ssp(l, CLIPMASK0); + ssp(hole, CLIPMASK0); } SKIPBULLETHOLE: @@ -521,29 +526,29 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith if (hitz >= (sector[wall[hitwall].nextsector].floorz)) hitwall = wall[hitwall].nextwall; - fi.checkhitwall(k, hitwall, hitx, hity, hitz, SHOTSPARK1); + fi.checkhitwall(spark, hitwall, hitx, hity, hitz, SHOTSPARK1); } } else { - k = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, i, 4); - sprite[k].extra = ScriptCode[actorinfo[atwith].scriptaddress]; + spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, actor, 4); + spark->s.extra = ScriptCode[actorinfo[atwith].scriptaddress]; - if (hitspr >= 0) + if (hitact) { - fi.checkhitsprite(hitspr, k); - if (sprite[hitspr].picnum != TILE_APLAYER) - fi.spawn(k, SMALLSMOKE); - else sprite[k].xrepeat = sprite[k].yrepeat = 0; + fi.checkhitsprite(hitact, spark); + if (hitact->s.picnum != TILE_APLAYER) + spawn(spark, SMALLSMOKE); + else spark->s.xrepeat = spark->s.yrepeat = 0; } else if (hitwall >= 0) - fi.checkhitwall(k, hitwall, hitx, hity, hitz, SHOTSPARK1); + fi.checkhitwall(spark, hitwall, hitx, hity, hitz, SHOTSPARK1); } if ((krand() & 255) < 4) { vec3_t v{ hitx, hity, hitz }; - S_PlaySound3D(PISTOL_RICOCHET, k, &v); + S_PlaySound3D(PISTOL_RICOCHET, spark, &v); } } @@ -553,12 +558,12 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith // //--------------------------------------------------------------------------- -static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootstuff(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + spritetype* const s = &actor->s; int sect = s->sectnum; int vel, zvel; - short l, j, scount; + short l, scount; if (s->extra >= 0) s->shade = -96; @@ -581,13 +586,13 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) if (p >= 0) { - j = aim(s, AUTO_AIM_ANGLE); + auto aimed = aim(actor, AUTO_AIM_ANGLE); - if (j >= 0) + if (aimed) { - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8); - zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) - (12 << 8); + zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98); @@ -595,10 +600,10 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); // sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy); sa += 16 - (krand() & 31); - zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s); + zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(ps[p].GetActor(), actor); } int oldzvel = zvel; @@ -632,24 +637,24 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) while (scount > 0) { - j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4); - sprite[j].extra += (krand() & 7); + auto spawned = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, actor, 4); + spawned->s.extra += (krand() & 7); if (atwith == COOLEXPLOSION1) { - sprite[j].shade = 0; + spawned->s.shade = 0; if (s->picnum == BOSS2) { - l = sprite[j].xvel; - sprite[j].xvel = 1024; - ssp(j, CLIPMASK0); - sprite[j].xvel = l; - sprite[j].ang += 128 - (krand() & 255); + l = spawned->s.xvel; + spawned->s.xvel = 1024; + ssp(spawned, CLIPMASK0); + spawned->s.xvel = l; + spawned->s.ang += 128 - (krand() & 255); } } - sprite[j].cstat = 128; - sprite[j].clipdist = 4; + spawned->s.cstat = 128; + spawned->s.clipdist = 4; sa = s->ang + 32 - (krand() & 63); zvel = oldzvel + 512 - (krand() & 1023); @@ -664,45 +669,45 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) // //--------------------------------------------------------------------------- -static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootrpg(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int vel, zvel; - short l, j, scount; + short l, scount; if (s->extra >= 0) s->shade = -96; scount = 1; vel = 644; - j = -1; + DDukeActor* aimed = nullptr; if (p >= 0) { - j = aim(s, 48); - if (j >= 0) + aimed = aim(actor, 48); + if (aimed) { - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (8 << 8); - zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); - if (sprite[j].picnum != RECON) - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (8 << 8); + zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed); + if (aimed->s.picnum != RECON) + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81); if (atwith == RPG) - S_PlayActorSound(RPG_SHOOT, i); + S_PlayActorSound(RPG_SHOOT, actor); } else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy); if (s->picnum == BOSS3) { int zoffs = (32 << 8); if (isWorldTour()) // Twentieth Anniversary World Tour - zoffs = (int)((sprite[i].yrepeat / 80.0f) * zoffs); + zoffs = (int)((actor->s.yrepeat / 80.0f) * zoffs); sz -= zoffs; } else if (s->picnum == BOSS2) @@ -710,30 +715,27 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) vel += 128; int zoffs = 24 << 8; if (isWorldTour()) // Twentieth Anniversary World Tour - zoffs = (int)((sprite[i].yrepeat / 80.0f) * zoffs); + zoffs = (int)((actor->s.yrepeat / 80.0f) * zoffs); sz += zoffs; } - l = ldist(&sprite[ps[j].i], s); + l = ldist(ps[j].GetActor(), actor); zvel = ((ps[j].oposz - sz) * vel) / l; - if (badguy(s) && (s->hitag & face_player_smart)) + if (badguy(actor) && (s->hitag & face_player_smart)) sa = s->ang + (krand() & 31) - 16; } + if (p < 0) aimed = nullptr; - if (p >= 0 && j >= 0) - l = j; - else l = -1; - - j = EGS(sect, + auto spawned = EGS(sect, sx + (sintable[(348 + sa + 512) & 2047] / 448), sy + (sintable[(sa + 348) & 2047] / 448), - sz - (1 << 8), atwith, 0, 14, 14, sa, vel, zvel, i, 4); + sz - (1 << 8), atwith, 0, 14, 14, sa, vel, zvel, actor, 4); - auto spj = &sprite[j]; + auto spj = &spawned->s; spj->extra += (krand() & 7); if (atwith != FREEZEBLAST) - spj->yvel = l; + spawned->temp_actor = aimed; else { spj->yvel = numfreezebounces; @@ -759,7 +761,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) if (isWorldTour()) // Twentieth Anniversary World Tour { - float siz = sprite[i].yrepeat / 80.0f; + float siz = actor->s.yrepeat / 80.0f; xoffs *= siz; yoffs *= siz; aoffs *= siz; @@ -779,7 +781,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) int aoffs = 8 + (krand() & 255) - 128; if (isWorldTour()) { // Twentieth Anniversary World Tour - int siz = sprite[i].yrepeat; + int siz = actor->s.yrepeat; xoffs = Scale(xoffs, siz, 80); yoffs = Scale(yoffs, siz, 80); aoffs = Scale(aoffs, siz, 80); @@ -838,13 +840,14 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) // //--------------------------------------------------------------------------- -static void shootlaser(int i, int p, int sx, int sy, int sz, int sa) +static void shootlaser(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) { - spritetype* const s = &sprite[i]; + spritetype* const s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, j, k; + short hitsect, hitwall, j; int hitx, hity, hitz; + DDukeActor* hitsprt; if (p >= 0) zvel = -ps[p].horizon.sum().asq16() >> 11; @@ -853,10 +856,10 @@ static void shootlaser(int i, int p, int sx, int sy, int sz, int sa) hitscan(sx, sy, sz - ps[p].pyoff, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], - zvel << 6, &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); j = 0; - if (hitspr >= 0) return; + if (hitsprt) return; if (hitwall >= 0 && hitsect >= 0) if (((hitx - sx) * (hitx - sx) + (hity - sy) * (hity - sy)) < (290 * 290)) @@ -872,27 +875,30 @@ static void shootlaser(int i, int p, int sx, int sy, int sz, int sa) if (j == 1) { - k = EGS(hitsect, hitx, hity, hitz, TRIPBOMB, -16, 4, 5, sa, 0, 0, i, 6); + auto bomb = EGS(hitsect, hitx, hity, hitz, TRIPBOMB, -16, 4, 5, sa, 0, 0, actor, 6); if (isWW2GI()) { - int lTripBombControl = GetGameVar("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, -1, -1); + int lTripBombControl = GetGameVar("TRIPBOMB_CONTROL", TRIPBOMB_TRIPWIRE, nullptr, -1); if (lTripBombControl & TRIPBOMB_TIMER) { - int lLifetime = GetGameVar("STICKYBOMB_LIFETIME", NAM_GRENADE_LIFETIME, -1, p); - int lLifetimeVar = GetGameVar("STICKYBOMB_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, -1, p); + int lLifetime = GetGameVar("STICKYBOMB_LIFETIME", NAM_GRENADE_LIFETIME, nullptr, p); + int lLifetimeVar = GetGameVar("STICKYBOMB_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, nullptr, p); // set timer. blows up when at zero.... - sprite[k].extra = lLifetime + bomb->s.extra = lLifetime + mulscale(krand(), lLifetimeVar, 14) - lLifetimeVar; } } - sprite[k].hitag = k; - S_PlayActorSound(LASERTRIP_ONWALL, k); - sprite[k].xvel = -20; - ssp(k, CLIPMASK0); - sprite[k].cstat = 16; - hittype[k].temp_data[5] = sprite[k].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) - 512; + // this originally used the sprite index as tag to link the laser segments. + // This value is never used again to reference an actor by index. Decouple this for robustness. + ud.bomb_tag = (ud.bomb_tag + 1) & 32767; + bomb->s.hitag = ud.bomb_tag; + S_PlayActorSound(LASERTRIP_ONWALL, bomb); + bomb->s.xvel = -20; + ssp(bomb, CLIPMASK0); + bomb->s.cstat = 16; + bomb->temp_data[5] = bomb->s.ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) - 512; if (p >= 0) ps[p].ammo_amount[TRIPBOMB_WEAPON]--; @@ -905,21 +911,22 @@ static void shootlaser(int i, int p, int sx, int sy, int sz, int sa) // //--------------------------------------------------------------------------- -static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa) +static void shootgrowspark(DDukeActor* actor, int p, int sx, int sy, int sz, int sa) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, j, k; + short hitsect, hitwall, k; int hitx, hity, hitz; + DDukeActor* hitsprt; if (p >= 0) { - j = aim(s, AUTO_AIM_ANGLE); - if (j >= 0) + auto aimed = aim(actor, AUTO_AIM_ANGLE); + if (aimed) { - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8); - switch (sprite[j].picnum) + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (5 << 8); + switch (aimed->s.picnum) { case GREENSLIME: case GREENSLIME + 1: @@ -933,8 +940,8 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa) dal -= (8 << 8); break; } - zvel = ((sprite[j].z - sz - dal) << 8) / (ldist(&sprite[ps[p].i], &sprite[j])); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + zvel = ((aimed->s.z - sz - dal) << 8) / (ldist(ps[p].GetActor(), aimed)); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else { @@ -948,9 +955,9 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa) else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); sz -= (4 << 8); - zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s)); + zvel = ((ps[j].posz - sz) << 8) / (ldist(ps[p].GetActor(), actor)); zvel += 128 - (krand() & 255); sa += 32 - (krand() & 63); } @@ -960,28 +967,26 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa) // RESHOOTGROW: s->cstat &= ~257; - hitscan(sx, sy, sz, sect, - sintable[(sa + 512) & 2047], - sintable[sa & 2047], - zvel << 6, &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], + zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); s->cstat |= 257; - j = EGS(sect, hitx, hity, hitz, GROWSPARK, -16, 28, 28, sa, 0, 0, i, 1); + auto spark = EGS(sect, hitx, hity, hitz, GROWSPARK, -16, 28, 28, sa, 0, 0, actor, 1); - sprite[j].pal = 2; - sprite[j].cstat |= 130; - sprite[j].xrepeat = sprite[j].yrepeat = 1; + spark->s.pal = 2; + spark->s.cstat |= 130; + spark->s.xrepeat = spark->s.yrepeat = 1; - if (hitwall == -1 && hitspr == -1 && hitsect >= 0) + if (hitwall == -1 && hitsprt == nullptr && hitsect >= 0) { if (zvel < 0 && (sector[hitsect].ceilingstat & 1) == 0) fi.checkhitceiling(hitsect); } - else if (hitspr >= 0) fi.checkhitsprite(hitspr, j); + else if (hitsprt != nullptr) fi.checkhitsprite(hitsprt, spark); else if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2) { - fi.checkhitwall(j, hitwall, hitx, hity, hitz, GROWSPARK); + fi.checkhitwall(spark, hitwall, hitx, hity, hitz, GROWSPARK); } } @@ -991,11 +996,12 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa) // //--------------------------------------------------------------------------- -void shoot_d(int i, int atwith) +void shoot_d(DDukeActor* actor, int atwith) { - short sect, l, j, k; + spritetype* const s = &actor->s; + + short sect, l, j; int sx, sy, sz, sa, p, vel, zvel, x, dal; - spritetype* const s = &sprite[i]; if (s->picnum == TILE_APLAYER) { p = s->yvel; @@ -1005,10 +1011,10 @@ void shoot_d(int i, int atwith) p = -1; } - SetGameVarID(g_iAtWithVarID, 0, p, atwith); - SetGameVarID(g_iReturnVarID, 0, p, i); - OnEvent(EVENT_SHOOT, i, p, -1); - if (GetGameVarID(g_iReturnVarID, p, i) != 0) + SetGameVarID(g_iAtWithVarID, atwith, actor, p); + SetGameVarID(g_iReturnVarID, 0, actor, p); + OnEvent(EVENT_SHOOT, p, ps[p].GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, actor, p) != 0) { return; } @@ -1049,24 +1055,26 @@ void shoot_d(int i, int atwith) switch (atwith) { case FIREBALL: - shootfireball(i, p, sx, sy, sz, sa); + shootfireball(actor, p, sx, sy, sz, sa); return; case FLAMETHROWERFLAME: - shootflamethrowerflame(i, p, sx, sy, sz, sa); + shootflamethrowerflame(actor, p, sx, sy, sz, sa); return; case FIREFLY: // BOSS5 shot - k = fi.spawn(i, atwith); - sprite[k].sectnum = sect; - sprite[k].x = sx; - sprite[k].y = sy; - sprite[k].z = sz; - sprite[k].ang = sa; - sprite[k].xvel = 500; - sprite[k].zvel = 0; + { + auto k = spawn(actor, atwith); + k->s.sectnum = sect; + k->s.x = sx; + k->s.y = sy; + k->s.z = sz; + k->s.ang = sa; + k->s.xvel = 500; + k->s.zvel = 0; return; } + } } switch (atwith) @@ -1075,43 +1083,43 @@ void shoot_d(int i, int atwith) case BLOODSPLAT2: case BLOODSPLAT3: case BLOODSPLAT4: - shootbloodsplat(i, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, NEWBEAST); + shootbloodsplat(actor, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, NEWBEAST); break; case KNEE: - shootknee(i, p, sx, sy, sz, sa); + shootknee(actor, p, sx, sy, sz, sa); break; case SHOTSPARK1: case SHOTGUN: case CHAINGUN: - shootweapon(i, p, sx, sy, sz, sa, atwith); + shootweapon(actor, p, sx, sy, sz, sa, atwith); return; case FIRELASER: case SPIT: case COOLEXPLOSION1: - shootstuff(i, p, sx, sy, sz, sa, atwith); + shootstuff(actor, p, sx, sy, sz, sa, atwith); return; case FREEZEBLAST: sz += (3 << 8); case RPG: - shootrpg(i, p, sx, sy, sz, sa, atwith); + shootrpg(actor, p, sx, sy, sz, sa, atwith); break; case HANDHOLDINGLASER: - shootlaser(i, p, sx, sy, sz, sa); + shootlaser(actor, p, sx, sy, sz, sa); return; case BOUNCEMINE: case MORTER: - + { if (s->extra >= 0) s->shade = -96; - j = ps[findplayer(s, &x)].i; - x = ldist(&sprite[j], s); + auto j = ps[findplayer(actor, &x)].GetActor(); + x = ldist(j, actor); zvel = -x >> 1; @@ -1122,45 +1130,47 @@ void shoot_d(int i, int atwith) EGS(sect, sx + (sintable[(512 + sa + 512) & 2047] >> 8), sy + (sintable[(sa + 512) & 2047] >> 8), - sz + (6 << 8), atwith, -64, 32, 32, sa, vel, zvel, i, 1); + sz + (6 << 8), atwith, -64, 32, 32, sa, vel, zvel, actor, 1); break; - + } case GROWSPARK: - shootgrowspark(i, p, sx, sy, sz, sa); + shootgrowspark(actor, p, sx, sy, sz, sa); break; case SHRINKER: + { if (s->extra >= 0) s->shade = -96; if (p >= 0) { - j = isNamWW2GI()? -1 : aim(s, AUTO_AIM_ANGLE); - if (j >= 0) + auto aimed = isNamWW2GI() ? nullptr : aim(actor, AUTO_AIM_ANGLE); + if (aimed) { - dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1); - zvel = ((sprite[j].z - sz - dal - (4 << 8)) * 768) / (ldist(&sprite[ps[p].i], &sprite[j])); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1); + zvel = ((aimed->s.z - sz - dal - (4 << 8)) * 768) / (ldist(ps[p].GetActor(), aimed)); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98); } else if (s->statnum != 3) { - j = findplayer(s, &x); - l = ldist(&sprite[ps[j].i], s); + j = findplayer(actor, &x); + l = ldist(ps[j].GetActor(), actor); zvel = ((ps[j].oposz - sz) * 512) / l; } else zvel = 0; - j = EGS(sect, + auto j = EGS(sect, sx + (sintable[(512 + sa + 512) & 2047] >> 12), sy + (sintable[(sa + 512) & 2047] >> 12), - sz + (2 << 8), SHRINKSPARK, -16, 28, 28, sa, 768, zvel, i, 4); + sz + (2 << 8), SHRINKSPARK, -16, 28, 28, sa, 768, zvel, actor, 4); - sprite[j].cstat = 128; - sprite[j].clipdist = 32; + j->s.cstat = 128; + j->s.clipdist = 32; return; } + } return; } @@ -1174,7 +1184,7 @@ void selectweapon_d(int snum, int weap) // playernum, weaponnum { int i, j, k; auto p = &ps[snum]; - if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && sprite[p->i].xrepeat > 32 && p->access_incs == 0 && p->knee_incs == 0) + if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && p->GetActor()->s.xrepeat > 32 && p->access_incs == 0 && p->knee_incs == 0) { if ((p->weapon_pos == 0 || (p->holster_weapon && p->weapon_pos == -9))) { @@ -1284,10 +1294,10 @@ void selectweapon_d(int snum, int weap) // playernum, weaponnum if (j == HANDBOMB_WEAPON && p->ammo_amount[HANDBOMB_WEAPON] == 0) { - StatIterator it(STAT_ACTOR); - while ((k = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { - if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i) + if (act->s.picnum == HEAVYHBOMB && act->GetOwner() == p->GetActor()) { p->gotweapon.Set(HANDBOMB_WEAPON); j = HANDREMOTE_WEAPON; @@ -1408,7 +1418,8 @@ int doincrements_d(struct player_struct* p) { int snum; - snum = sprite[p->i].yvel; + auto pact = p->GetActor(); + snum = pact->s.yvel; p->player_par++; @@ -1423,9 +1434,9 @@ int doincrements_d(struct player_struct* p) if (p->last_pissed_time == (26 * 219)) { - S_PlayActorSound(FLUSH_TOILET, p->i); + S_PlayActorSound(FLUSH_TOILET, pact); if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(DUKE_PISSRELIEF, p->i); + S_PlayActorSound(DUKE_PISSRELIEF, pact); } if (p->last_pissed_time == (26 * 218)) @@ -1452,7 +1463,7 @@ int doincrements_d(struct player_struct* p) checkavailinven(p); if (!(p->steroids_amount & 7)) if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(DUKE_HARTBEAT, p->i); + S_PlayActorSound(DUKE_HARTBEAT, pact); } if (p->heat_on && p->heat_amount > 0) @@ -1462,8 +1473,7 @@ int doincrements_d(struct player_struct* p) { p->heat_on = 0; checkavailinven(p); - S_PlayActorSound(NITEVISION_ONOFF, p->i); - setpal(p); + S_PlayActorSound(NITEVISION_ONOFF, pact); } } @@ -1472,7 +1482,7 @@ int doincrements_d(struct player_struct* p) p->holoduke_amount--; if (p->holoduke_amount <= 0) { - S_PlayActorSound(TELEPORTER, p->i); + S_PlayActorSound(TELEPORTER, pact); p->holoduke_on = nullptr; checkavailinven(p); } @@ -1485,43 +1495,43 @@ int doincrements_d(struct player_struct* p) { p->jetpack_on = 0; checkavailinven(p); - S_PlayActorSound(DUKE_JETPACK_OFF, p->i); - S_StopSound(DUKE_JETPACK_IDLE, p->i); - S_StopSound(DUKE_JETPACK_ON, p->i); + S_PlayActorSound(DUKE_JETPACK_OFF, pact); + S_StopSound(DUKE_JETPACK_IDLE, pact); + S_StopSound(DUKE_JETPACK_ON, pact); } } - if (p->quick_kick > 0 && sprite[p->i].pal != 1) + if (p->quick_kick > 0 && p->GetActor()->s.pal != 1) { p->last_quick_kick = p->quick_kick + 1; p->quick_kick--; if (p->quick_kick == 8) - fi.shoot(p->i, KNEE); + fi.shoot(p->GetActor(), KNEE); } else if (p->last_quick_kick > 0) p->last_quick_kick--; - if (p->access_incs && sprite[p->i].pal != 1) + if (p->access_incs && p->GetActor()->s.pal != 1) { p->access_incs++; - if (sprite[p->i].extra <= 0) + if (p->GetActor()->s.extra <= 0) p->access_incs = 12; if (p->access_incs == 12) { - if (p->access_spritenum >= 0) + if (p->access_spritenum != nullptr) { - fi.checkhitswitch(snum, p->access_spritenum, 1); - switch (sprite[p->access_spritenum].pal) + fi.checkhitswitch(snum, -1, p->access_spritenum); + switch (p->access_spritenum->s.pal) { case 0:p->got_access &= (0xffff - 0x1); break; case 21:p->got_access &= (0xffff - 0x2); break; case 23:p->got_access &= (0xffff - 0x4); break; } - p->access_spritenum = -1; + p->access_spritenum = nullptr; } else { - fi.checkhitswitch(snum, p->access_wallnum, 0); + fi.checkhitswitch(snum, p->access_wallnum, nullptr); switch (wall[p->access_wallnum].pal) { case 0:p->got_access &= (0xffff - 0x1); break; @@ -1555,7 +1565,7 @@ int doincrements_d(struct player_struct* p) { p->extra_extra8 += 32; if (p->last_extra < (max_player_health >> 1) && (p->last_extra & 3) == 0) - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, pact); } } } @@ -1578,10 +1588,10 @@ int doincrements_d(struct player_struct* p) if (snum == screenpeek || ud.coop == 1) { if (rand() & 1) - S_PlayActorSound(DUKE_CRACK, p->i); - else S_PlayActorSound(DUKE_CRACK2, p->i); + S_PlayActorSound(DUKE_CRACK, pact); + else S_PlayActorSound(DUKE_CRACK2, pact); } - S_PlayActorSound(DUKE_CRACK_FIRST, p->i); + S_PlayActorSound(DUKE_CRACK_FIRST, pact); } else if (p->knuckle_incs == 22 || PlayerInput(snum, SB_FIRE)) p->knuckle_incs = 0; @@ -1608,7 +1618,7 @@ void checkweapons_d(struct player_struct* p) if (isWW2GI()) { - int snum = sprite[p->i].yvel; + int snum = p->GetActor()->s.yvel; cw = aplWeaponWorksLike[p->curr_weapon][snum]; } else @@ -1620,12 +1630,12 @@ void checkweapons_d(struct player_struct* p) if (cw) { if (krand() & 1) - fi.spawn(p->i, weapon_sprites[cw]); + spawn(p->GetActor(), weapon_sprites[cw]); else switch (cw) { case RPG_WEAPON: case HANDBOMB_WEAPON: - fi.spawn(p->i, EXPLOSION2); + spawn(p->GetActor(), EXPLOSION2); break; } } @@ -1641,7 +1651,7 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, { int j; auto p = &ps[snum]; - int pi = p->i; + auto pact = p->GetActor(); p->on_ground = 0; p->jumping_counter = 0; p->hard_landing = 0; @@ -1651,9 +1661,9 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, p->pycount &= 2047; p->pyoff = sintable[p->pycount] >> 7; - if (p->jetpack_on && S_CheckActorSoundPlaying(pi, DUKE_SCREAM)) + if (p->jetpack_on && S_CheckActorSoundPlaying(pact, DUKE_SCREAM)) { - S_StopSound(DUKE_SCREAM, pi); + S_StopSound(DUKE_SCREAM, pact); } if (p->jetpack_on < 11) @@ -1661,8 +1671,8 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, p->jetpack_on++; p->posz -= (p->jetpack_on << 7); //Goin up } - else if (p->jetpack_on == 11 && !S_CheckActorSoundPlaying(pi, DUKE_JETPACK_IDLE)) - S_PlayActorSound(DUKE_JETPACK_IDLE, pi); + else if (p->jetpack_on == 11 && !S_CheckActorSoundPlaying(pact, DUKE_JETPACK_IDLE)) + S_PlayActorSound(DUKE_JETPACK_IDLE, pact); if (shrunk) j = 512; else j = 2048; @@ -1670,9 +1680,9 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, if (actions & SB_JUMP) //A (soar high) { // jump - SetGameVarID(g_iReturnVarID, 0, pi, snum); - OnEvent(EVENT_SOARUP, pi, snum, -1); - if (GetGameVarID(g_iReturnVarID, pi, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_SOARUP, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->posz -= j; p->crack_time = CRACK_TIME; @@ -1682,9 +1692,9 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, if (actions & SB_CROUCH) //Z (soar low) { // crouch - SetGameVarID(g_iReturnVarID, 0, pi, snum); - OnEvent(EVENT_SOARDOWN, pi, snum, -1); - if (GetGameVarID(g_iReturnVarID, pi, snum) == 0) + SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); + OnEvent(EVENT_SOARDOWN, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { p->posz += j; p->crack_time = CRACK_TIME; @@ -1700,8 +1710,8 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, int fz, if (p->posz > (fz - (k << 8))) p->posz += ((fz - (k << 8)) - p->posz) >> 1; - if (p->posz < (hittype[pi].ceilingz + (18 << 8))) - p->posz = hittype[pi].ceilingz + (18 << 8); + if (p->posz < (pact->ceilingz + (18 << 8))) + p->posz = pact->ceilingz + (18 << 8); } @@ -1715,7 +1725,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int { int j; auto p = &ps[snum]; - int pi = p->i; + auto pact = p->GetActor(); if (p->airleft != 15 * 26) p->airleft = 15 * 26; //Aprox twenty seconds. @@ -1739,9 +1749,8 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int { if (p->on_ground == 1) { - if (p->dummyplayersprite == -1) - p->dummyplayersprite = - fi.spawn(pi, PLAYERONWATER); + if (p->dummyplayersprite == nullptr) + p->dummyplayersprite = spawn(pact, PLAYERONWATER); p->footprintcount = 6; if (sector[p->cursectnum].floorpicnum == FLOORSLIME) @@ -1770,13 +1779,13 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int if (p->poszv > 2400 && p->falling_counter < 255) { p->falling_counter++; - if (p->falling_counter == 38 && !S_CheckActorSoundPlaying(pi, DUKE_SCREAM)) - S_PlayActorSound(DUKE_SCREAM, pi); + if (p->falling_counter == 38 && !S_CheckActorSoundPlaying(pact, DUKE_SCREAM)) + S_PlayActorSound(DUKE_SCREAM, pact); } if ((p->posz + p->poszv) >= (fz - (i << 8))) // hit the ground { - S_StopSound(DUKE_SCREAM, pi); + S_StopSound(DUKE_SCREAM, pact); if (sector[p->cursectnum].lotag != 1) { if (p->falling_counter > 62) quickkill(p); @@ -1784,21 +1793,21 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int else if (p->falling_counter > 9) { j = p->falling_counter; - sprite[pi].extra -= j - (krand() & 3); - if (sprite[pi].extra <= 0) + pact->s.extra -= j - (krand() & 3); + if (pact->s.extra <= 0) { - S_PlayActorSound(SQUISHED, pi); + S_PlayActorSound(SQUISHED, pact); SetPlayerPal(p, PalEntry(63, 63, 0, 0)); } else { - S_PlayActorSound(DUKE_LAND, pi); - S_PlayActorSound(DUKE_LAND_HURT, pi); + S_PlayActorSound(DUKE_LAND, pact); + S_PlayActorSound(DUKE_LAND_HURT, pact); } SetPlayerPal(p, PalEntry(32, 16, 0, 0)); } - else if (p->poszv > 2048) S_PlayActorSound(DUKE_LAND, pi); + else if (p->poszv > 2048) S_PlayActorSound(DUKE_LAND, pact); } } } @@ -1807,7 +1816,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int else { p->falling_counter = 0; - S_StopSound(-1, pi, CHAN_VOICE); + S_StopSound(-1, pact, CHAN_VOICE); if (psectlotag != ST_1_ABOVE_WATER && psectlotag != ST_2_UNDERWATER && p->on_ground == 0 && p->poszv > (6144 >> 1)) p->hard_landing = p->poszv >> 10; @@ -1900,9 +1909,8 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) { - int j; auto p = &ps[snum]; - int pi = p->i; + auto pact = p->GetActor(); int psectlotag = sector[psect].lotag; // under water @@ -1912,8 +1920,8 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) p->pycount &= 2047; p->pyoff = sintable[p->pycount] >> 7; - if (!S_CheckActorSoundPlaying(pi, DUKE_UNDERWATER)) - S_PlayActorSound(DUKE_UNDERWATER, pi); + if (!S_CheckActorSoundPlaying(pact, DUKE_UNDERWATER)) + S_PlayActorSound(DUKE_UNDERWATER, pact); if (actions & SB_JUMP) { @@ -1962,14 +1970,14 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) if (p->scuba_on && (krand() & 255) < 8) { - j = fi.spawn(pi, WATERBUBBLE); - sprite[j].x += + auto j = spawn(pact, WATERBUBBLE); + j->s.x += sintable[(p->angle.ang.asbuild() + 512 + 64 - (global_random & 128)) & 2047] >> 6; - sprite[j].y += + j->s.y += sintable[(p->angle.ang.asbuild() + 64 - (global_random & 128)) & 2047] >> 6; - sprite[j].xrepeat = 3; - sprite[j].yrepeat = 2; - sprite[j].z = p->posz + (8 << 8); + j->s.xrepeat = 3; + j->s.yrepeat = 2; + j->s.z = p->posz + (8 << 8); } } @@ -1982,17 +1990,17 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) int operateTripbomb(int snum) { auto p = &ps[snum]; - int pi = p->i; int sx, sy, sz; - short sect, hw, hitsp; + short sect, hw; + DDukeActor* hitsprt; hitscan(p->posx, p->posy, p->posz, p->cursectnum, sintable[(p->angle.ang.asbuild() + 512) & 2047], sintable[p->angle.ang.asbuild() & 2047], -p->horizon.sum().asq16() >> 11, - §, &hw, &hitsp, &sx, &sy, &sz, CLIPMASK1); + §, &hw, &hitsprt, &sx, &sy, &sz, CLIPMASK1); - if (sect < 0 || hitsp >= 0) + if (sect < 0 || hitsprt) return 0; if (hw >= 0 && sector[sect].lotag > 2) @@ -2002,17 +2010,17 @@ int operateTripbomb(int snum) if (wall[hw].overpicnum == BIGFORCE) return 0; - int j; - SectIterator it(sect); - while ((j = it.NextIndex()) >= 0) + DDukeActor* j; + DukeSectIterator it(sect); + while (j = it.Next()) { - auto sj = &sprite[j]; + auto sj = &j->s; if (sj->picnum == TRIPBOMB && abs(sj->z - sz) < (12 << 8) && ((sj->x - sx) * (sj->x - sx) + (sj->y - sy) * (sj->y - sy)) < (290 * 290)) return 0; } - if (j == -1 && hw >= 0 && (wall[hw].cstat & 16) == 0) + if (j == nullptr && hw >= 0 && (wall[hw].cstat & 16) == 0) if ((wall[hw].nextsector >= 0 && sector[wall[hw].nextsector].lotag <= 2) || (wall[hw].nextsector == -1 && sector[sect].lotag <= 2)) if (((sx - p->posx) * (sx - p->posx) + (sy - p->posy) * (sy - p->posy)) < (290 * 290)) { @@ -2033,7 +2041,7 @@ int operateTripbomb(int snum) static void fireweapon(int snum) { auto p = &ps[snum]; - int pi = p->i; + auto pact = p->GetActor(); p->crack_time = CRACK_TIME; @@ -2091,13 +2099,13 @@ static void fireweapon(int snum) if (p->ammo_amount[GROW_WEAPON] > 0) { p->kickback_pic = 1; - S_PlayActorSound(EXPANDERSHOOT, pi); + S_PlayActorSound(EXPANDERSHOOT, pact); } } else if (p->ammo_amount[SHRINKER_WEAPON] > 0) { p->kickback_pic = 1; - S_PlayActorSound(SHRINKER_FIRE, pi); + S_PlayActorSound(SHRINKER_FIRE, pact); } break; @@ -2105,7 +2113,7 @@ static void fireweapon(int snum) if (p->ammo_amount[FREEZE_WEAPON] > 0) { p->kickback_pic = 1; - S_PlayActorSound(CAT_FIRE, pi); + S_PlayActorSound(CAT_FIRE, pact); } break; case DEVISTATOR_WEAPON: @@ -2113,7 +2121,7 @@ static void fireweapon(int snum) { p->kickback_pic = 1; p->hbomb_hold_delay = !p->hbomb_hold_delay; - S_PlayActorSound(CAT_FIRE, pi); + S_PlayActorSound(CAT_FIRE, pact); } break; @@ -2129,7 +2137,7 @@ static void fireweapon(int snum) { p->kickback_pic = 1; if (sector[p->cursectnum].lotag != 2) - S_PlayActorSound(FLAMETHROWER_INTRO, pi); + S_PlayActorSound(FLAMETHROWER_INTRO, pact); } break; @@ -2151,8 +2159,8 @@ static void fireweapon(int snum) static void operateweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; - int pi = p->i; - int i, j, k; + auto pact = p->GetActor(); + int i, k; // already firing... @@ -2180,29 +2188,29 @@ static void operateweapon(int snum, ESyncBits actions, int psect) i = -512 - mulscale16(p->horizon.sum().asq16(), 20); } - j = EGS(p->cursectnum, + auto spawned = EGS(p->cursectnum, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 6), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 6), p->posz, HEAVYHBOMB, -16, 9, 9, - p->angle.ang.asbuild(), (k + (p->hbomb_hold_delay << 5)), i, pi, 1); + p->angle.ang.asbuild(), (k + (p->hbomb_hold_delay << 5)), i, pact, 1); if (isNam()) { - sprite[j].extra = mulscale(krand(), NAM_GRENADE_LIFETIME_VAR, 14); + spawned->s.extra = mulscale(krand(), NAM_GRENADE_LIFETIME_VAR, 14); } if (k == 15) { - sprite[j].yvel = 3; - sprite[j].z += (8 << 8); + spawned->s.yvel = 3; + spawned->s.z += (8 << 8); } - k = hits(pi); + k = hits(pact); if (k < 512) { - sprite[j].ang += 1024; - sprite[j].zvel /= 3; - sprite[j].xvel /= 3; + spawned->s.ang += 1024; + spawned->s.zvel /= 3; + spawned->s.xvel /= 3; } p->hbomb_on = 1; @@ -2250,14 +2258,14 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case PISTOL_WEAPON: // m-16 in NAM if (p->kickback_pic == 1) { - fi.shoot(pi, SHOTSPARK1); - S_PlayActorSound(PISTOL_FIRE, pi); + fi.shoot(pact, SHOTSPARK1); + S_PlayActorSound(PISTOL_FIRE, pact); lastvisinc = ud.levelclock + 32; p->visibility = 0; } else if (p->kickback_pic == 2) - fi.spawn(pi, SHELL); + spawn(pact, SHELL); p->kickback_pic++; @@ -2273,14 +2281,14 @@ static void operateweapon(int snum, ESyncBits actions, int psect) switch (p->kickback_pic) { case 5: - S_PlayActorSound(EJECT_CLIP, pi); + S_PlayActorSound(EJECT_CLIP, pact); break; //#ifdef NAM // case WEAPON2_RELOAD_TIME - 15: //#else case 8: //#endif - S_PlayActorSound(INSERT_CLIP, pi); + S_PlayActorSound(INSERT_CLIP, pact); break; } } @@ -2300,16 +2308,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if (p->kickback_pic == 4) { - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); + for(int i = 0; i < 7; i++) + fi.shoot(pact, SHOTGUN); p->ammo_amount[SHOTGUN_WEAPON]--; - S_PlayActorSound(SHOTGUN_FIRE, pi); + S_PlayActorSound(SHOTGUN_FIRE, pact); lastvisinc = ud.levelclock + 32; p->visibility = 0; @@ -2322,19 +2325,21 @@ static void operateweapon(int snum, ESyncBits actions, int psect) checkavailweapon(p); break; case 15: - S_PlayActorSound(SHOTGUN_COCK, pi); + S_PlayActorSound(SHOTGUN_COCK, pact); break; case 17: case 20: p->kickback_pic++; break; case 24: - j = fi.spawn(pi, SHOTGUNSHELL); - sprite[j].ang += 1024; + { + auto j = spawn(pact, SHOTGUNSHELL); + j->s.ang += 1024; ssp(j, CLIPMASK0); - sprite[j].ang += 1024; + j->s.ang += 1024; p->kickback_pic++; break; + } case 31: p->okickback_pic = p->kickback_pic = 0; return; @@ -2353,17 +2358,17 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if ((p->kickback_pic % 3) == 0) { - j = fi.spawn(pi, SHELL); + auto j = spawn(pact, SHELL); - sprite[j].ang += 1024; - sprite[j].ang &= 2047; - sprite[j].xvel += 32; - sprite[j].z += (3 << 8); + j->s.ang += 1024; + j->s.ang &= 2047; + j->s.xvel += 32; + j->s.z += (3 << 8); ssp(j, CLIPMASK0); } - S_PlayActorSound(CHAINGUN_FIRE, pi); - fi.shoot(pi, CHAINGUN); + S_PlayActorSound(CHAINGUN_FIRE, pact); + fi.shoot(pact, CHAINGUN); lastvisinc = ud.levelclock + 32; p->visibility = 0; checkavailweapon(p); @@ -2407,7 +2412,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) else p->okickback_pic = p->kickback_pic = 0; p->ammo_amount[p->curr_weapon]--; - fi.shoot(pi, GROWSPARK); + fi.shoot(pact, GROWSPARK); //#ifdef NAM //#else @@ -2442,7 +2447,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) else p->okickback_pic = p->kickback_pic = 0; p->ammo_amount[SHRINKER_WEAPON]--; - fi.shoot(pi, SHRINKER); + fi.shoot(pact, SHRINKER); if (!isNam()) { @@ -2475,7 +2480,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { p->visibility = 0; lastvisinc = ud.levelclock + 32; - fi.shoot(pi, RPG); + fi.shoot(pact, RPG); p->ammo_amount[DEVISTATOR_WEAPON]--; checkavailweapon(p); } @@ -2485,7 +2490,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { p->visibility = 0; lastvisinc = ud.levelclock + 32; - fi.shoot(pi, RPG); + fi.shoot(pact, RPG); p->ammo_amount[DEVISTATOR_WEAPON]--; checkavailweapon(p); if (p->ammo_amount[DEVISTATOR_WEAPON] <= 0) p->okickback_pic = p->kickback_pic = 0; @@ -2505,10 +2510,10 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->visibility = 0; lastvisinc = ud.levelclock + 32; - fi.shoot(pi, FREEZEBLAST); + fi.shoot(pact, FREEZEBLAST); checkavailweapon(p); } - if (sprite[p->i].xrepeat < 32) + if (pact->s.xrepeat < 32) { p->okickback_pic = p->kickback_pic = 0; break; } @@ -2518,7 +2523,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if (actions & SB_FIRE) { p->okickback_pic = p->kickback_pic = 1; - S_PlayActorSound(CAT_FIRE, pi); + S_PlayActorSound(CAT_FIRE, pact); } else p->okickback_pic = p->kickback_pic = 0; } @@ -2535,7 +2540,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->ammo_amount[FLAMETHROWER_WEAPON]--; if (snum == screenpeek) g_visibility = 0; - fi.shoot(pi, FIREBALL); + fi.shoot(pact, FIREBALL); } checkavailweapon(p); } @@ -2544,7 +2549,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if ((actions & SB_FIRE) != 0) { p->okickback_pic = p->kickback_pic = 1; - S_PlayActorSound(FLAMETHROWER_INTRO, pi); + S_PlayActorSound(FLAMETHROWER_INTRO, pact); } else p->okickback_pic = p->kickback_pic = 0; @@ -2557,7 +2562,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->posz = p->oposz; p->poszv = 0; if (p->kickback_pic == 3) - fi.shoot(pi, HANDHOLDINGLASER); + fi.shoot(pact, HANDHOLDINGLASER); } if (p->kickback_pic == 16) { @@ -2570,7 +2575,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case KNEE_WEAPON: p->kickback_pic++; - if (p->kickback_pic == 7) fi.shoot(pi, KNEE); + if (p->kickback_pic == 7) fi.shoot(pact, KNEE); else if (p->kickback_pic == 14) { if (actions & SB_FIRE) @@ -2589,7 +2594,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->ammo_amount[RPG_WEAPON]--; lastvisinc = ud.levelclock + 32; p->visibility = 0; - fi.shoot(pi, RPG); + fi.shoot(pact, RPG); checkavailweapon(p); } else if (p->kickback_pic == (cl_dukefixrpgrecoil ? 13 : 20)) @@ -2607,8 +2612,8 @@ static void operateweapon(int snum, ESyncBits actions, int psect) static void processweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; - int pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); + auto s = &pact->s; int shrunk = (s->yrepeat < 32); // Set maximum for pistol slightly higher if playing with `cl_showmagamount 1`. @@ -2636,11 +2641,11 @@ static void processweapon(int snum, ESyncBits actions, int psect) { if (isWW2GI()) { - SetGameVarID(g_iReturnVarID, 0, pi, snum); - SetGameVarID(g_iWeaponVarID, p->curr_weapon, pi, snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], pi, snum); - OnEvent(EVENT_HOLSTER, pi, snum, -1); - if (GetGameVarID(g_iReturnVarID, pi, snum) == 0) + 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); + 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) @@ -2707,16 +2712,17 @@ static void processweapon(int snum, ESyncBits actions, int psect) void processinput_d(int snum) { - int j, i, k, doubvel, fz, cz, hz, lz, truefdist; - char shrunk; + int j, k, doubvel, fz, cz, truefdist; + Collision chz, clz; + bool shrunk; ESyncBits actions; - short psect, psectlotag, pi; + short psect, psectlotag; struct player_struct* p; spritetype* s; p = &ps[snum]; - pi = p->i; - s = &sprite[pi]; + auto pact = p->GetActor(); + s = &pact->s; p->horizon.resetadjustment(); p->angle.resetadjustment(); @@ -2733,7 +2739,7 @@ void processinput_d(int snum) if (s->extra > 0 && ud.clipping == 0) { quickkill(p); - S_PlayActorSound(SQUISHED, pi); + S_PlayActorSound(SQUISHED, pact); } psect = 0; } @@ -2742,7 +2748,7 @@ void processinput_d(int snum) p->spritebridge = 0; shrunk = (s->yrepeat < 32); - getzrange(p->posx, p->posy, p->posz, psect, &cz, &hz, &fz, &lz, 163L, CLIPMASK0); + getzrange_ex(p->posx, p->posy, p->posz, psect, &cz, chz, &fz, clz, 163L, CLIPMASK0); j = getflorzofslope(psect, p->posx, p->posy); @@ -2750,11 +2756,11 @@ void processinput_d(int snum) p->truecz = getceilzofslope(psect, p->posx, p->posy); truefdist = abs(p->posz - j); - if ((lz & 49152) == 16384 && psectlotag == 1 && truefdist > PHEIGHT + (16 << 8)) + if (clz.type == kHitSector && psectlotag == 1 && truefdist > PHEIGHT + (16 << 8)) psectlotag = 0; - hittype[pi].floorz = fz; - hittype[pi].ceilingz = cz; + pact->floorz = fz; + pact->ceilingz = cz; if (cl_syncinput) { @@ -2762,30 +2768,27 @@ void processinput_d(int snum) calcviewpitch(p, 1); } - if (hz >= 0 && (hz & 49152) == 49152) + if (chz.type == kHitSprite) { - hz &= (MAXSPRITES - 1); - - if (sprite[hz].statnum == 1 && sprite[hz].extra >= 0) + if (chz.actor->s.statnum == 1 && chz.actor->s.extra >= 0) { - hz = 0; + chz.type = kHitNone; + chz.actor = nullptr; cz = p->truecz; } } - if (lz >= 0 && (lz & 49152) == 49152) + if (clz.type == kHitSprite) { - j = lz & (MAXSPRITES - 1); - - if ((sprite[j].cstat & 33) == 33) + if ((clz.actor->s.cstat & 33) == 33) { psectlotag = 0; p->footprintcount = 0; p->spritebridge = 1; } - else if (badguy(&sprite[j]) && sprite[j].xrepeat > 24 && abs(s->z - sprite[j].z) < (84 << 8)) + else if (badguy(clz.actor) && clz.actor->s.xrepeat > 24 && abs(s->z - clz.actor->s.z) < (84 << 8)) { - j = getangle(sprite[j].x - p->posx, sprite[j].y - p->posy); + j = getangle(clz.actor->s.x - p->posx, clz.actor->s.y - p->posy); p->posxv -= sintable[(j + 512) & 2047] << 4; p->posyv -= sintable[j & 2047] << 4; } @@ -2830,9 +2833,8 @@ void processinput_d(int snum) if (p->transporter_hold < 0) p->transporter_hold++; - if (p->newowner >= 0) + if (p->newOwner != nullptr) { - i = p->newowner; p->posxv = p->posyv = s->xvel = 0; fi.doincrements(p); @@ -2845,6 +2847,7 @@ void processinput_d(int snum) doubvel = TICSPERFRAME; checklook(snum,actions); + int ii = 40; if (p->on_crane != nullptr) goto HORIZONLY; @@ -2852,14 +2855,12 @@ void processinput_d(int snum) playerweaponsway(p, s); s->xvel = clamp(ksqrt((p->posx - p->bobposx) * (p->posx - p->bobposx) + (p->posy - p->bobposy) * (p->posy - p->bobposy)), 0, 512); - if (p->on_ground) p->bobcounter += sprite[p->i].xvel >> 1; + if (p->on_ground) p->bobcounter += p->GetActor()->s.xvel >> 1; backuppos(p, ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); // Shrinking code - i = 40; - if (psectlotag == ST_2_UNDERWATER) { underwater(snum, actions, psect, fz, cz); @@ -2891,7 +2892,7 @@ void processinput_d(int snum) // may still be needed later for demo recording processavel(p, &sb_avel); - applylook(&p->angle, sb_avel, &p->sync.actions, 1, p->crouch_toggle || actions & SB_CROUCH); + applylook(&p->angle, sb_avel, &p->sync.actions); } if (p->spritebridge == 0) @@ -2909,8 +2910,8 @@ void processinput_d(int snum) } else { - if (!S_CheckActorSoundPlaying(p->i, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + if (!S_CheckActorSoundPlaying(pact, DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, pact); SetPlayerPal(p, PalEntry(32, 0, 8, 0)); s->extra--; } @@ -2947,22 +2948,23 @@ void processinput_d(int snum) { case 0: - if (lz >= 0 && (lz & (MAXSPRITES - 1)) == 49152) - j = sprite[lz & (MAXSPRITES - 1)].picnum; - else j = sector[psect].floorpicnum; + if (clz.type == kHitSprite) + j = clz.actor->s.picnum; + else + j = sector[psect].floorpicnum; switch (j) { case PANNEL1: case PANNEL2: - S_PlayActorSound(DUKE_WALKINDUCTS, pi); + S_PlayActorSound(DUKE_WALKINDUCTS, pact); p->walking_snd_toggle = 1; break; } break; case 1: if ((krand() & 1) == 0) - S_PlayActorSound(DUKE_ONWATER, pi); + S_PlayActorSound(DUKE_ONWATER, pact); p->walking_snd_toggle = 1; break; } @@ -3014,30 +3016,30 @@ void processinput_d(int snum) HORIZONLY: - if (psectlotag == 1 || p->spritebridge == 1) i = (4L << 8); - else i = (20L << 8); + if (psectlotag == 1 || p->spritebridge == 1) ii = (4L << 8); + else ii = (20L << 8); if (sector[p->cursectnum].lotag == 2) k = 0; else k = 1; + Collision clip{}; if (ud.clipping) { - j = 0; p->posx += p->posxv >> 14; p->posy += p->posyv >> 14; updatesector(p->posx, p->posy, &p->cursectnum); - changespritesect(pi, p->cursectnum); + changespritesect(pact, p->cursectnum); } else - j = clipmove(&p->posx, &p->posy, + clipmove_ex(&p->posx, &p->posy, &p->posz, &p->cursectnum, - p->posxv, p->posyv, 164L, (4L << 8), i, CLIPMASK0); + p->posxv, p->posyv, 164L, (4L << 8), ii, CLIPMASK0, clip); if (p->jetpack_on == 0 && psectlotag != 2 && psectlotag != 1 && shrunk) p->posz += 32 << 8; - if (j) - fi.checkplayerhurt(p, j); + if (clip.type != kHitNone) + checkplayerhurt_d(p, clip); if (p->jetpack_on == 0) { @@ -3056,14 +3058,15 @@ HORIZONLY: } // RBG*** - setsprite(pi, p->posx, p->posy, p->posz + PHEIGHT); + setsprite(pact, p->posx, p->posy, p->posz + PHEIGHT); if (psectlotag < 3) { psect = s->sectnum; if (ud.clipping == 0 && sector[psect].lotag == 31) { - if (sprite[sector[psect].hitag].xvel && hittype[sector[psect].hitag].temp_data[0] == 0) + auto secact = ScriptIndexToActor(sector[psect].hitag); + if (secact && secact->s.xvel && secact->temp_data[0] == 0) { quickkill(p); return; @@ -3072,23 +3075,23 @@ HORIZONLY: } if (truefdist < PHEIGHT && p->on_ground && psectlotag != 1 && shrunk == 0 && sector[p->cursectnum].lotag == 1) - if (!S_CheckActorSoundPlaying(pi, DUKE_ONWATER)) - S_PlayActorSound(DUKE_ONWATER, pi); + if (!S_CheckActorSoundPlaying(pact, DUKE_ONWATER)) + S_PlayActorSound(DUKE_ONWATER, pact); if (p->cursectnum != s->sectnum) - changespritesect(pi, p->cursectnum); + changespritesect(pact, p->cursectnum); if (ud.clipping == 0) - j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 164L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(pi, 8) < 512); + j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 164L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512); else j = 0; if (ud.clipping == 0) { - if (abs(hittype[pi].floorz - hittype[pi].ceilingz) < (48 << 8) || j) + if (abs(pact->floorz - pact->ceilingz) < (48 << 8) || j) { if (!(sector[s->sectnum].lotag & 0x8000) && (isanunderoperator(sector[s->sectnum].lotag) || isanearoperator(sector[s->sectnum].lotag))) - fi.activatebysector(s->sectnum, pi); + fi.activatebysector(s->sectnum, pact); if (j) { quickkill(p); @@ -3096,7 +3099,7 @@ HORIZONLY: } } else if (abs(fz - cz) < (32 << 8) && isanunderoperator(sector[psect].lotag)) - fi.activatebysector(psect, pi); + fi.activatebysector(psect, pact); } // center_view @@ -3123,7 +3126,7 @@ HORIZONLY: if (cl_syncinput) { - sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions, 1); + sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); } checkhardlanding(p); @@ -3144,7 +3147,7 @@ HORIZONLY: } } - dokneeattack(snum, pi, { FEM1, FEM2, FEM3, FEM4, FEM5, FEM6, FEM7, FEM8, FEM9, FEM10, PODFEM1, NAKED1, STATUE }); + dokneeattack(snum, { FEM1, FEM2, FEM3, FEM4, FEM5, FEM6, FEM7, FEM8, FEM9, FEM10, PODFEM1, NAKED1, STATUE }); if (fi.doincrements(p)) return; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index dbd4773b9..ba97ad276 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -46,9 +46,9 @@ void incur_damage_r(struct player_struct* p) int damage = 0, unk = 0, shield_damage = 0; short gut = 0; - sprite[p->i].extra -= p->extra_extra8 >> 8; + p->GetActor()->s.extra -= p->extra_extra8 >> 8; - damage = sprite[p->i].extra - p->last_extra; + damage = p->GetActor()->s.extra - p->last_extra; if (damage < 0) { p->extra_extra8 = 0; @@ -78,7 +78,7 @@ void incur_damage_r(struct player_struct* p) break; } - sprite[p->i].extra = p->last_extra + damage; + p->GetActor()->s.extra = p->last_extra + damage; } } @@ -88,13 +88,14 @@ void incur_damage_r(struct player_struct* p) // //--------------------------------------------------------------------------- -static void shootmelee(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + spritetype* const s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, j, k; + short hitsect, hitwall; int hitx, hity, hitz; + DDukeActor* hitsprt; if (p >= 0) { @@ -105,40 +106,39 @@ static void shootmelee(int i, int p, int sx, int sy, int sz, int sa, int atwith) else { int x; - j = ps[findplayer(s, &x)].i; - zvel = ((sprite[j].z - sz) << 8) / (x + 1); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + auto pspr = ps[findplayer(actor, &x)].GetActor(); + zvel = ((pspr->s.z - sz) << 8) / (x + 1); + sa = getangle(pspr->s.x - sx, pspr->s.y - sy); } hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], zvel << 6, - &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); if (isRRRA() && ((sector[hitsect].lotag == 160 && zvel > 0) || (sector[hitsect].lotag == 161 && zvel < 0)) - && hitspr == -1 && hitwall == -1) + && hitsprt == nullptr && hitwall == -1) { - short ii; - for (ii = 0; ii < MAXSPRITES; ii++) + DukeSpriteIterator its; + while (auto effector = its.Next()) { - if (sprite[ii].sectnum == hitsect && sprite[ii].picnum == SECTOREFFECTOR - && sprite[ii].lotag == 7) + // shouldn't this only check STAT_EFFECTOR? + if (effector->s.sectnum == hitsect && effector->s.picnum == SECTOREFFECTOR && effector->GetOwner() + && effector->s.lotag == 7) { int nx, ny, nz; - nx = hitx + (sprite[sprite[ii].owner].x - sprite[ii].x); - ny = hity + (sprite[sprite[ii].owner].y - sprite[ii].y); + nx = hitx + (effector->GetOwner()->s.x - effector->s.x); + ny = hity + (effector->GetOwner()->s.y - effector->s.y); if (sector[hitsect].lotag == 161) { - nz = sector[sprite[sprite[ii].owner].sectnum].floorz; + nz = sector[effector->GetOwner()->s.sectnum].floorz; } else { - nz = sector[sprite[sprite[ii].owner].sectnum].ceilingz; + nz = sector[effector->GetOwner()->s.sectnum].ceilingz; } - hitscan(nx, ny, nz, sprite[sprite[ii].owner].sectnum, - sintable[(sa + 512) & 2047], - sintable[sa & 2047], zvel << 6, - &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + hitscan(nx, ny, nz, effector->GetOwner()->s.sectnum, sintable[(sa + 512) & 2047], sintable[sa & 2047], zvel << 6, + &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); break; } } @@ -148,35 +148,34 @@ static void shootmelee(int i, int p, int sx, int sy, int sz, int sa, int atwith) if ((abs(sx - hitx) + abs(sy - hity)) < 1024) { - if (hitwall >= 0 || hitspr >= 0) + if (hitwall >= 0 || hitsprt) { + DDukeActor* wpn; if (isRRRA() && atwith == SLINGBLADE) { - j = EGS(hitsect, hitx, hity, hitz, SLINGBLADE, -15, 0, 0, sa, 32, 0, i, 4); - sprite[j].extra += 50; + wpn = EGS(hitsect, hitx, hity, hitz, SLINGBLADE, -15, 0, 0, sa, 32, 0, actor, 4); + wpn->s.extra += 50; } else { - j = EGS(hitsect, hitx, hity, hitz, KNEE, -15, 0, 0, sa, 32, 0, i, 4); - sprite[j].extra += (krand() & 7); + wpn = EGS(hitsect, hitx, hity, hitz, KNEE, -15, 0, 0, sa, 32, 0, actor, 4); + wpn->s.extra += (krand() & 7); } if (p >= 0) { - k = fi.spawn(j, SMALLSMOKE); - sprite[k].z -= (8 << 8); - if (atwith == KNEE) - S_PlayActorSound(KICK_HIT, j); - else if (isRRRA() && atwith == SLINGBLADE) - S_PlayActorSound(260, j); + auto k = spawn(wpn, SMALLSMOKE); + k->s.z -= (8 << 8); + if (atwith == KNEE) S_PlayActorSound(KICK_HIT, wpn); + else if (isRRRA() && atwith == SLINGBLADE) S_PlayActorSound(260, wpn); } if (p >= 0 && ps[p].steroids_amount > 0 && ps[p].steroids_amount < 400) - sprite[j].extra += (max_player_health >> 2); + wpn->s.extra += (max_player_health >> 2); - if (hitspr >= 0 && sprite[hitspr].picnum != ACCESSSWITCH && sprite[hitspr].picnum != ACCESSSWITCH2) + if (hitsprt && hitsprt->s.picnum != ACCESSSWITCH && hitsprt->s.picnum != ACCESSSWITCH2) { - fi.checkhitsprite(hitspr, j); - if (p >= 0) fi.checkhitswitch(p, hitspr, 1); + fi.checkhitsprite(hitsprt, wpn); + if (p >= 0) fi.checkhitswitch(p, -1, hitsprt); } else if (hitwall >= 0) { @@ -187,20 +186,20 @@ static void shootmelee(int i, int p, int sx, int sy, int sz, int sa, int atwith) if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2) { - fi.checkhitwall(j, hitwall, hitx, hity, hitz, atwith); - if (p >= 0) fi.checkhitswitch(p, hitwall, 0); + fi.checkhitwall(wpn, hitwall, hitx, hity, hitz, atwith); + if (p >= 0) fi.checkhitswitch(p, hitwall, nullptr); } } } else if (p >= 0 && zvel > 0 && sector[hitsect].lotag == 1) { - j = fi.spawn(ps[p].i, WATERSPLASH2); - sprite[j].x = hitx; - sprite[j].y = hity; - sprite[j].ang = ps[p].angle.ang.asbuild(); // Total tweek - sprite[j].xvel = 32; - ssp(i, 0); - sprite[j].xvel = 0; + auto splash = spawn(ps[p].GetActor(), WATERSPLASH2); + splash->s.x = hitx; + splash->s.y = hity; + splash->s.ang = ps[p].angle.ang.asbuild(); // Total tweek + splash->s.xvel = 32; + ssp(actor, 0); + splash->s.xvel = 0; } } } @@ -211,29 +210,30 @@ static void shootmelee(int i, int p, int sx, int sy, int sz, int sa, int atwith) // //--------------------------------------------------------------------------- -static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int zvel; - short hitsect, hitspr, hitwall, l, j, k; + short hitsect, hitwall; int hitx, hity, hitz; + DDukeActor* hitsprt; if (s->extra >= 0) s->shade = -96; if (p >= 0) { - j = aim(s, AUTO_AIM_ANGLE); - if (j >= 0) + auto aimed = aim(actor, AUTO_AIM_ANGLE); + if (aimed) { - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8); - zvel = ((sprite[j].z - sz - dal) << 8) / ldist(&sprite[ps[p].i], &sprite[j]); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (5 << 8); + zvel = ((aimed->s.z - sz - dal) << 8) / ldist(ps[p].GetActor(), aimed); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } if (atwith == SHOTSPARK1) { - if (j == -1) + if (aimed == nullptr) { sa += 16 - (krand() & 31); zvel = -ps[p].horizon.sum().asq16() >> 11; @@ -246,7 +246,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith sa += 64 - (krand() & 127); else sa += 16 - (krand() & 31); - if (j == -1) zvel = -ps[p].horizon.sum().asq16() >> 11; + if (aimed == nullptr) zvel = -ps[p].horizon.sum().asq16() >> 11; zvel += 128 - (krand() & 255); } sz -= (2 << 8); @@ -254,9 +254,9 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); sz -= (4 << 8); - zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s)); + zvel = ((ps[j].posz - sz) << 8) / (ldist(ps[j].GetActor(), actor)); if (s->picnum != BOSS1) { zvel += 128 - (krand() & 255); @@ -270,35 +270,32 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith } s->cstat &= ~257; - hitscan(sx, sy, sz, sect, - sintable[(sa + 512) & 2047], - sintable[sa & 2047], - zvel << 6, &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047], + zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); if (isRRRA() && (((sector[hitsect].lotag == 160 && zvel > 0) || (sector[hitsect].lotag == 161 && zvel < 0)) - && hitspr == -1 && hitwall == -1)) + && hitsprt == nullptr && hitwall == -1)) { - short ii; - for (ii = 0; ii < MAXSPRITES; ii++) + DukeSpriteIterator its; + while (auto effector = its.Next()) { - if (sprite[ii].sectnum == hitsect && sprite[ii].picnum == SECTOREFFECTOR - && sprite[ii].lotag == 7) + // shouldn't this only check STAT_EFFECTOR? + if (effector->s.sectnum == hitsect && effector->s.picnum == SECTOREFFECTOR && effector->GetOwner() + && effector->s.lotag == 7) { int nx, ny, nz; - nx = hitx + (sprite[sprite[ii].owner].x - sprite[ii].x); - ny = hity + (sprite[sprite[ii].owner].y - sprite[ii].y); + nx = hitx + (effector->GetOwner()->s.x - effector->s.x); + ny = hity + (effector->GetOwner()->s.y - effector->s.y); if (sector[hitsect].lotag == 161) { - nz = sector[sprite[sprite[ii].owner].sectnum].floorz; + nz = sector[effector->GetOwner()->s.sectnum].floorz; } else { - nz = sector[sprite[sprite[ii].owner].sectnum].ceilingz; + nz = sector[effector->GetOwner()->s.sectnum].ceilingz; } - hitscan(nx, ny, nz, sprite[sprite[ii].owner].sectnum, - sintable[(sa + 512) & 2047], - sintable[sa & 2047], zvel << 6, - &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1); + hitscan(nx, ny, nz, effector->GetOwner()->s.sectnum, sintable[(sa + 512) & 2047], sintable[sa & 2047], zvel << 6, + &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); break; } } @@ -316,63 +313,64 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith if ((krand() & 15) == 0 && sector[hitsect].lotag == 2) tracers(hitx, hity, hitz, sx, sy, sz, 8 - (ud.multimode >> 1)); + DDukeActor* spark; if (p >= 0) { - k = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, i, 4); - sprite[k].extra = ScriptCode[actorinfo[atwith].scriptaddress]; - sprite[k].extra += (krand() % 6); + spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, actor, 4); + spark->s.extra = ScriptCode[actorinfo[atwith].scriptaddress]; + spark->s.extra += (krand() % 6); - if (hitwall == -1 && hitspr == -1) + if (hitwall == -1 && hitsprt == nullptr) { if (zvel < 0) { if (sector[hitsect].ceilingstat & 1) { - sprite[k].xrepeat = 0; - sprite[k].yrepeat = 0; + spark->s.xrepeat = 0; + spark->s.yrepeat = 0; return; } else fi.checkhitceiling(hitsect); } if (sector[hitsect].lotag != 1) - fi.spawn(k, SMALLSMOKE); + spawn(spark, SMALLSMOKE); } - if (hitspr >= 0) + if (hitsprt) { - if (sprite[hitspr].picnum == 1930) + if (hitsprt->s.picnum == 1930) return; - fi.checkhitsprite(hitspr, k); - if (sprite[hitspr].picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1)) + fi.checkhitsprite(hitsprt, spark); + if (hitsprt->s.picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1)) { - l = fi.spawn(k, JIBS6); - sprite[k].xrepeat = sprite[k].yrepeat = 0; - sprite[l].z += (4 << 8); - sprite[l].xvel = 16; - sprite[l].xrepeat = sprite[l].yrepeat = 24; - sprite[l].ang += 64 - (krand() & 127); + auto l = spawn(spark, JIBS6); + spark->s.xrepeat = spark->s.yrepeat = 0; + l->s.z += (4 << 8); + l->s.xvel = 16; + l->s.xrepeat = l->s.yrepeat = 24; + l->s.ang += 64 - (krand() & 127); } - else fi.spawn(k, SMALLSMOKE); + else spawn(spark, SMALLSMOKE); if (p >= 0 && ( - sprite[hitspr].picnum == DIPSWITCH || - sprite[hitspr].picnum == DIPSWITCH + 1 || - sprite[hitspr].picnum == DIPSWITCH2 || - sprite[hitspr].picnum == DIPSWITCH2 + 1 || - sprite[hitspr].picnum == DIPSWITCH3 || - sprite[hitspr].picnum == DIPSWITCH3 + 1 || - (isRRRA() && sprite[hitspr].picnum == RRTILE8660) || - sprite[hitspr].picnum == HANDSWITCH || - sprite[hitspr].picnum == HANDSWITCH + 1)) + hitsprt->s.picnum == DIPSWITCH || + hitsprt->s.picnum == DIPSWITCH + 1 || + hitsprt->s.picnum == DIPSWITCH2 || + hitsprt->s.picnum == DIPSWITCH2 + 1 || + hitsprt->s.picnum == DIPSWITCH3 || + hitsprt->s.picnum == DIPSWITCH3 + 1 || + (isRRRA() && hitsprt->s.picnum == RRTILE8660) || + hitsprt->s.picnum == HANDSWITCH || + hitsprt->s.picnum == HANDSWITCH + 1)) { - fi.checkhitswitch(p, hitspr, 1); + fi.checkhitswitch(p, -1, hitsprt); return; } } else if (hitwall >= 0) { - fi.spawn(k, SMALLSMOKE); + spawn(spark, SMALLSMOKE); if (fi.isadoorwall(wall[hitwall].picnum) == 1) goto SKIPBULLETHOLE; @@ -389,7 +387,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith wall[hitwall].picnum == HANDSWITCH || wall[hitwall].picnum == HANDSWITCH + 1)) { - fi.checkhitswitch(p, hitwall, 0); + fi.checkhitswitch(p, hitwall, nullptr); return; } @@ -404,24 +402,24 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith { if (wall[hitwall].nextsector >= 0) { - SectIterator it(wall[hitwall].nextsector); - while ((l = it.NextIndex()) >= 0) + DukeSectIterator it(wall[hitwall].nextsector); + while (auto l = it.Next()) { - if (sprite[l].statnum == 3 && sprite[l].lotag == 13) + if (l->s.statnum == 3 && l->s.lotag == 13) goto SKIPBULLETHOLE; } } - StatIterator it(STAT_MISC); - while ((l = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_MISC); + while (auto l = it.Next()) { - if (sprite[l].picnum == BULLETHOLE) - if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) + if (l->s.picnum == BULLETHOLE) + if (dist(l, spark) < (12 + (krand() & 7))) goto SKIPBULLETHOLE; } - l = fi.spawn(k, BULLETHOLE); - sprite[l].xvel = -1; - sprite[l].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, + auto l = spawn(spark, BULLETHOLE); + l->s.xvel = -1; + l->s.ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) + 512; ssp(l, CLIPMASK0); } @@ -433,29 +431,29 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith if (hitz >= (sector[wall[hitwall].nextsector].floorz)) hitwall = wall[hitwall].nextwall; - fi.checkhitwall(k, hitwall, hitx, hity, hitz, SHOTSPARK1); + fi.checkhitwall(spark, hitwall, hitx, hity, hitz, SHOTSPARK1); } } else { - k = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, i, 4); - sprite[k].extra = ScriptCode[actorinfo[atwith].scriptaddress]; + spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, actor, 4); + spark->s.extra = ScriptCode[actorinfo[atwith].scriptaddress]; - if (hitspr >= 0) + if (hitsprt) { - fi.checkhitsprite(hitspr, k); - if (sprite[hitspr].picnum != TILE_APLAYER) - fi.spawn(k, SMALLSMOKE); - else sprite[k].xrepeat = sprite[k].yrepeat = 0; + fi.checkhitsprite(hitsprt, spark); + if (hitsprt->s.picnum != TILE_APLAYER) + spawn(spark, SMALLSMOKE); + else spark->s.xrepeat = spark->s.yrepeat = 0; } else if (hitwall >= 0) - fi.checkhitwall(k, hitwall, hitx, hity, hitz, SHOTSPARK1); + fi.checkhitwall(spark, hitwall, hitx, hity, hitz, SHOTSPARK1); } if ((krand() & 255) < 10) { vec3_t v{ hitx, hity, hitz }; - S_PlaySound3D(PISTOL_RICOCHET, k, &v); + S_PlaySound3D(PISTOL_RICOCHET, spark, &v); } } @@ -465,12 +463,12 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith // //--------------------------------------------------------------------------- -static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootstuff(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int vel, zvel; - short j, scount; + short scount; if (isRRRA()) { @@ -510,15 +508,15 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) if (p >= 0) { - j = aim(s, AUTO_AIM_ANGLE); + auto aimed = aim(actor, AUTO_AIM_ANGLE); - if (j >= 0) + if (aimed) { sx += sintable[(s->ang + 512 + 160) & 2047] >> 7; sy += sintable[(s->ang + 160) & 2047] >> 7; - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8); - zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) - (12 << 8); + zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else { @@ -530,7 +528,7 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); // sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy); if (s->picnum == HULK) sa -= (krand() & 31); @@ -539,7 +537,7 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) else if (s->picnum != UFOBEAM) sa += 16 - (krand() & 31); - zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s); + zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(ps[j].GetActor(), actor); } int oldzvel = zvel; @@ -582,18 +580,18 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) while (scount > 0) { - j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4); - sprite[j].extra += (krand() & 7); - sprite[j].cstat = 128; - sprite[j].clipdist = 4; + auto j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, actor, 4); + j->s.extra += (krand() & 7); + j->s.cstat = 128; + j->s.clipdist = 4; sa = s->ang + 32 - (krand() & 63); zvel = oldzvel + 512 - (krand() & 1023); if (atwith == FIRELASER) { - sprite[j].xrepeat = 8; - sprite[j].yrepeat = 8; + j->s.xrepeat = 8; + j->s.yrepeat = 8; } scount--; @@ -606,54 +604,54 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) // //--------------------------------------------------------------------------- -static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootrpg(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int vel, zvel; - short l, j, scount; + short l, scount; - short var90 = 0; + DDukeActor* act90 = nullptr; if (s->extra >= 0) s->shade = -96; scount = 1; vel = 644; - j = -1; + DDukeActor* aimed = nullptr; if (p >= 0) { - j = aim(s, 48); - if (j >= 0) + aimed = aim(actor, 48); + if (aimed) { if (isRRRA() && atwith == RPG2) { - if (sprite[j].picnum == HEN || sprite[j].picnum == HENSTAYPUT) - var90 = ps[screenpeek].i; + if (aimed->s.picnum == HEN || aimed->s.picnum == HENSTAYPUT) + act90 = ps[screenpeek].GetActor(); else - var90 = j; + act90 = aimed; } - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (8 << 8); - zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); - if (sprite[j].picnum != RECON) - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (8 << 8); + zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed); + if (aimed->s.picnum != RECON) + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81); if (atwith == RPG) - S_PlayActorSound(RPG_SHOOT, i); + S_PlayActorSound(RPG_SHOOT, actor); else if (isRRRA()) { if (atwith == RPG2) - S_PlayActorSound(244, i); + S_PlayActorSound(244, actor); else if (atwith == RRTILE1790) - S_PlayActorSound(94, i); + S_PlayActorSound(94, actor); } } else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy); if (s->picnum == BOSS3) sz -= (32 << 8); @@ -663,16 +661,14 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) sz += 24 << 8; } - l = ldist(&sprite[ps[j].i], s); + l = ldist(ps[j].GetActor(), actor); zvel = ((ps[j].oposz - sz) * vel) / l; if (badguy(s) && (s->hitag & face_player_smart)) sa = s->ang + (krand() & 31) - 16; } - if (p >= 0 && j >= 0) - l = j; - else l = -1; + if (p < 0) aimed = nullptr; if (isRRRA() && atwith == RRTILE1790) { @@ -680,76 +676,76 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) vel <<= 1; } - j = EGS(sect, + auto spawned = EGS(sect, sx + (sintable[(348 + sa + 512) & 2047] / 448), sy + (sintable[(sa + 348) & 2047] / 448), - sz - (1 << 8), atwith, 0, 14, 14, sa, vel, zvel, i, 4); + sz - (1 << 8), atwith, 0, 14, 14, sa, vel, zvel, actor, 4); if (isRRRA()) { if (atwith == RRTILE1790) { - sprite[j].extra = 10; - sprite[j].zvel = -(10 << 8); + spawned->s.extra = 10; + spawned->s.zvel = -(10 << 8); } else if (atwith == RPG2) { - sprite[j].lotag = var90; - sprite[j].hitag = 0; - fi.lotsofmoney(&hittype[j], (krand() & 3) + 1); + spawned->seek_actor = act90; + spawned->s.hitag = 0; + fi.lotsofmoney(spawned, (krand() & 3) + 1); } } - sprite[j].extra += (krand() & 7); + spawned->s.extra += (krand() & 7); if (atwith != FREEZEBLAST) - sprite[j].yvel = l; + spawned->temp_actor = aimed; else { - sprite[j].yvel = numfreezebounces; - sprite[j].xrepeat >>= 1; - sprite[j].yrepeat >>= 1; - sprite[j].zvel -= (2 << 4); + spawned->s.yvel = numfreezebounces; + spawned->s.xrepeat >>= 1; + spawned->s.yrepeat >>= 1; + spawned->s.zvel -= (2 << 4); } if (p == -1) { if (s->picnum == HULK) { - sprite[j].xrepeat = 8; - sprite[j].yrepeat = 8; + spawned->s.xrepeat = 8; + spawned->s.yrepeat = 8; } else if (atwith != FREEZEBLAST) { - sprite[j].xrepeat = 30; - sprite[j].yrepeat = 30; - sprite[j].extra >>= 2; + spawned->s.xrepeat = 30; + spawned->s.yrepeat = 30; + spawned->s.extra >>= 2; } } else if (ps[p].curr_weapon == TIT_WEAPON) { - sprite[j].extra >>= 2; - sprite[j].ang += 16 - (krand() & 31); - sprite[j].zvel += 256 - (krand() & 511); + spawned->s.extra >>= 2; + spawned->s.ang += 16 - (krand() & 31); + spawned->s.zvel += 256 - (krand() & 511); if (ps[p].hbomb_hold_delay) { - sprite[j].x -= sintable[sa & 2047] / 644; - sprite[j].y -= sintable[(sa + 1024 + 512) & 2047] / 644; + spawned->s.x -= sintable[sa & 2047] / 644; + spawned->s.y -= sintable[(sa + 1024 + 512) & 2047] / 644; } else { - sprite[j].x += sintable[sa & 2047] >> 8; - sprite[j].y += sintable[(sa + 1024 + 512) & 2047] >> 8; + spawned->s.x += sintable[sa & 2047] >> 8; + spawned->s.y += sintable[(sa + 1024 + 512) & 2047] >> 8; } - sprite[j].xrepeat >>= 1; - sprite[j].yrepeat >>= 1; + spawned->s.xrepeat >>= 1; + spawned->s.yrepeat >>= 1; } - sprite[j].cstat = 128; + spawned->s.cstat = 128; if (atwith == RPG || (atwith == RPG2 && isRRRA())) - sprite[j].clipdist = 4; + spawned->s.clipdist = 4; else - sprite[j].clipdist = 40; + spawned->s.clipdist = 40; } @@ -760,12 +756,12 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) // //--------------------------------------------------------------------------- -static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith) +static void shootwhip(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith) { - spritetype* const s = &sprite[i]; + auto s = &actor->s; int sect = s->sectnum; int vel, zvel; - short j, scount; + short scount; if (s->extra >= 0) s->shade = -96; @@ -785,13 +781,13 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith) if (p >= 0) { - j = aim(s, AUTO_AIM_ANGLE); + auto aimed = aim(actor, AUTO_AIM_ANGLE); - if (j >= 0) + if (aimed) { - int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8); - zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); - sa = getangle(sprite[j].x - sx, sprite[j].y - sy); + int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) - (12 << 8); + zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed); + sa = getangle(aimed->s.x - sx, aimed->s.y - sy); } else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98); @@ -799,13 +795,13 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith) else { int x; - j = findplayer(s, &x); + int j = findplayer(actor, &x); // sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy); if (s->picnum == VIXEN) sa -= (krand() & 16); else sa += 16 - (krand() & 31); - zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s); + zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(ps[j].GetActor(), actor); } int oldzvel = zvel; @@ -817,11 +813,10 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith) while (scount > 0) { - j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4); - sprite[j].extra += (krand() & 7); - - sprite[j].cstat = 128; - sprite[j].clipdist = 4; + auto j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, actor, 4); + j->s.extra += (krand() & 7); + j->s.cstat = 128; + j->s.clipdist = 4; sa = s->ang + 32 - (krand() & 63); zvel = oldzvel + 512 - (krand() & 1023); @@ -836,13 +831,14 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith) // //--------------------------------------------------------------------------- -void shoot_r(int i, int atwith) +void shoot_r(DDukeActor* actor, int atwith) { - short sect, sa, p, j; - int sx, sy, sz, vel, zvel, x; - spritetype* s; + spritetype* const s = &actor->s; + + short sect, sa, p; + int sx, sy, sz, vel, zvel, x; + - s = &sprite[i]; sect = s->sectnum; zvel = 0; @@ -872,10 +868,10 @@ void shoot_r(int i, int atwith) } } - SetGameVarID(g_iAtWithVarID, 0, p, atwith); - SetGameVarID(g_iReturnVarID, 0, p, i); - OnEvent(EVENT_SHOOT, i, p, -1); - if (GetGameVarID(g_iReturnVarID, p, i) != 0) + SetGameVarID(g_iAtWithVarID, atwith, actor, p); + SetGameVarID(g_iReturnVarID, 0, actor, p); + OnEvent(EVENT_SHOOT, p, ps[p].GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, actor, p) != 0) { return; } @@ -886,45 +882,47 @@ void shoot_r(int i, int atwith) case BLOODSPLAT2: case BLOODSPLAT3: case BLOODSPLAT4: - shootbloodsplat(i, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, -1); + shootbloodsplat(actor, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, -1); return; case SLINGBLADE: if (!isRRRA()) break; case KNEE: case GROWSPARK: - shootmelee(i, p, sx, sy, sz, sa, atwith); + shootmelee(actor, p, sx, sy, sz, sa, atwith); return; case SHOTSPARK1: case SHOTGUN: case CHAINGUN: - shootweapon(i, p, sx, sy, sz, sa, atwith); + shootweapon(actor, p, sx, sy, sz, sa, atwith); return; case TRIPBOMBSPRITE: - j = fi.spawn(i, atwith); - sprite[j].xvel = 32; - sprite[j].ang = sprite[i].ang; - sprite[j].z -= (5 << 8); + { + auto j = spawn(actor, atwith); + j->s.xvel = 32; + j->s.ang = s->ang; + j->s.z -= (5 << 8); break; - + } case BOWLINGBALL: - j = fi.spawn(i, atwith); - sprite[j].xvel = 250; - sprite[j].ang = sprite[i].ang; - sprite[j].z -= (15 << 8); + { + auto j = spawn(actor, atwith); + j->s.xvel = 250; + j->s.ang = s->ang; + j->s.z -= (15 << 8); break; - + } case OWHIP: case UWHIP: - shootwhip(i, p, sx, sy, sz, sa, atwith); + shootwhip(actor, p, sx, sy, sz, sa, atwith); return; case FIRELASER: case SPIT: case COOLEXPLOSION1: - shootstuff(i, p, sx, sy, sz, sa, atwith); + shootstuff(actor, p, sx, sy, sz, sa, atwith); return; case RPG2: @@ -937,17 +935,17 @@ void shoot_r(int i, int atwith) case RPG: case SHRINKSPARK: rrra_rpg2: - shootrpg(i, p, sx, sy, sz, sa, atwith); + shootrpg(actor, p, sx, sy, sz, sa, atwith); break; case CHEERBOMB: if (!isRRRA()) break; case MORTER: - + { if (s->extra >= 0) s->shade = -96; - j = ps[findplayer(s, &x)].i; - x = ldist(&sprite[j], s); + auto j = ps[findplayer(actor, &x)].GetActor(); + x = ldist(j, actor); zvel = -x >> 1; @@ -959,14 +957,15 @@ void shoot_r(int i, int atwith) EGS(sect, sx + (sintable[(512 + sa + 512) & 2047] >> 8), sy + (sintable[(sa + 512) & 2047] >> 8), - sz + (6 << 8), atwith, -64, 16, 16, sa, vel, zvel, i, 1); + sz + (6 << 8), atwith, -64, 16, 16, sa, vel, zvel, actor, 1); else EGS(sect, sx + (sintable[(512 + sa + 512) & 2047] >> 8), sy + (sintable[(sa + 512) & 2047] >> 8), - sz + (6 << 8), atwith, -64, 32, 32, sa, vel, zvel, i, 1); + sz + (6 << 8), atwith, -64, 32, 32, sa, vel, zvel, actor, 1); break; } + } return; } @@ -980,7 +979,7 @@ void selectweapon_r(int snum, int weap) { int i, j, k; auto p = &ps[snum]; - if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && sprite[p->i].xrepeat > 8 && p->access_incs == 0 && p->knee_incs == 0) + if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && p->GetActor()->s.xrepeat > 8 && p->access_incs == 0 && p->knee_incs == 0) { if ((p->weapon_pos == 0 || (p->holster_weapon && p->weapon_pos == -9))) { @@ -1055,10 +1054,10 @@ void selectweapon_r(int snum, int weap) if (j == DYNAMITE_WEAPON && p->ammo_amount[DYNAMITE_WEAPON] == 0) { - StatIterator it(STAT_ACTOR); - while ((k = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { - if (sprite[k].picnum == HEAVYHBOMB && sprite[k].owner == p->i) + if (act->s.picnum == HEAVYHBOMB && act->GetOwner() == p->GetActor()) { p->gotweapon.Set(DYNAMITE_WEAPON); j = THROWINGDYNAMITE_WEAPON; @@ -1135,7 +1134,7 @@ void selectweapon_r(int snum, int weap) case SLINGBLADE_WEAPON: if (isRRRA()) { - S_PlayActorSound(496, ps[screenpeek].i); + S_PlayActorSound(496, ps[screenpeek].GetActor()); fi.addweapon(p, j); } break; @@ -1207,6 +1206,7 @@ void selectweapon_r(int snum, int weap) int doincrements_r(struct player_struct* p) { int snum; + auto pact = p->GetActor(); if (isRRRA()) { @@ -1221,8 +1221,8 @@ int doincrements_r(struct player_struct* p) if (BellTime > 0) { BellTime--; - if (BellTime == 0) - sprite[BellSprite].picnum++; + if (BellTime == 0 && BellSprite) + BellSprite->s.picnum++; } if (chickenphase > 0) chickenphase--; @@ -1234,7 +1234,7 @@ int doincrements_r(struct player_struct* p) } } - snum = sprite[p->i].yvel; + snum = p->GetActor()->s.yvel; p->player_par++; if (p->yehaa_timer) @@ -1264,8 +1264,8 @@ int doincrements_r(struct player_struct* p) } if (p->drink_amt >= 100) { - if (!S_CheckActorSoundPlaying(p->i, 420)) - S_PlayActorSound(420, p->i); + if (!S_CheckActorSoundPlaying(pact, 420)) + S_PlayActorSound(420, pact); p->drink_amt -= 9; p->eat >>= 1; } @@ -1279,16 +1279,16 @@ int doincrements_r(struct player_struct* p) switch (krand() & 3) { case 0: - S_PlayActorSound(404, p->i); + S_PlayActorSound(404, pact); break; case 1: - S_PlayActorSound(422, p->i); + S_PlayActorSound(422, pact); break; case 2: - S_PlayActorSound(423, p->i); + S_PlayActorSound(423, pact); break; case 3: - S_PlayActorSound(424, p->i); + S_PlayActorSound(424, pact); break; } if (numplayers < 2) @@ -1317,17 +1317,17 @@ int doincrements_r(struct player_struct* p) { if (p->last_pissed_time == 5662) - S_PlayActorSound(434, p->i); + S_PlayActorSound(434, pact); else if (p->last_pissed_time == 5567) - S_PlayActorSound(434, p->i); + S_PlayActorSound(434, pact); else if (p->last_pissed_time == 5472) - S_PlayActorSound(433, p->i); + S_PlayActorSound(433, pact); else if (p->last_pissed_time == 5072) - S_PlayActorSound(435, p->i); + S_PlayActorSound(435, pact); else if (p->last_pissed_time == 5014) - S_PlayActorSound(434, p->i); + S_PlayActorSound(434, pact); else if (p->last_pissed_time == 4919) - S_PlayActorSound(433, p->i); + S_PlayActorSound(433, pact); } if (p->last_pissed_time == 5668) @@ -1358,30 +1358,30 @@ int doincrements_r(struct player_struct* p) } if (!(p->steroids_amount & 14)) if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(DUKE_TAKEPILLS, p->i); + S_PlayActorSound(DUKE_TAKEPILLS, pact); } - if (p->access_incs && sprite[p->i].pal != 1) + if (p->access_incs && p->GetActor()->s.pal != 1) { p->access_incs++; - if (sprite[p->i].extra <= 0) + if (p->GetActor()->s.extra <= 0) p->access_incs = 12; if (p->access_incs == 12) { - if (p->access_spritenum >= 0) + if (p->access_spritenum != nullptr) { - fi.checkhitswitch(snum, p->access_spritenum, 1); - switch (sprite[p->access_spritenum].pal) + fi.checkhitswitch(snum, -1, p->access_spritenum); + switch (p->access_spritenum->s.pal) { case 0:p->keys[1] = 1; break; case 21:p->keys[2] = 1; break; case 23:p->keys[3] = 1; break; } - p->access_spritenum = -1; + p->access_spritenum = nullptr; } else { - fi.checkhitswitch(snum, p->access_wallnum, 0); + fi.checkhitswitch(snum, p->access_wallnum, nullptr); switch (wall[p->access_wallnum].pal) { case 0:p->keys[1] = 1; break; @@ -1415,7 +1415,7 @@ int doincrements_r(struct player_struct* p) { p->extra_extra8 += 32; if (p->last_extra < (max_player_health >> 1) && (p->last_extra & 3) == 0) - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, pact); } } } @@ -1456,14 +1456,14 @@ int doincrements_r(struct player_struct* p) case levelnum(1, 5): snd = 255; break; case levelnum(1, 6): snd = 283; break; } - S_PlayActorSound(snd, p->i); + S_PlayActorSound(snd, pact); } else if (ud.levelclock > 1024) if (snum == screenpeek || ud.coop == 1) { if (rand() & 1) - S_PlayActorSound(DUKE_CRACK, p->i); - else S_PlayActorSound(DUKE_CRACK2, p->i); + S_PlayActorSound(DUKE_CRACK, pact); + else S_PlayActorSound(DUKE_CRACK2, pact); } } else if (p->knuckle_incs == 22 || PlayerInput(snum, SB_FIRE)) @@ -1485,15 +1485,14 @@ void checkweapons_r(struct player_struct* p) static const short weapon_sprites[MAX_WEAPONS] = { KNEE, FIRSTGUNSPRITE, SHOTGUNSPRITE, CHAINGUNSPRITE, RPGSPRITE, HEAVYHBOMB, SHRINKERSPRITE, DEVISTATORSPRITE, TRIPBOMBSPRITE, BOWLINGBALLSPRITE, FREEZEBLAST, HEAVYHBOMB }; - short i, j; if (isRRRA()) { if (p->OnMotorcycle && numplayers > 1) { - j = fi.spawn(p->i, 7220); - sprite[j].ang = p->angle.ang.asbuild(); - sprite[j].owner = p->ammo_amount[MOTORCYCLE_WEAPON]; + auto j = spawn(p->GetActor(), 7220); + j->s.ang = p->angle.ang.asbuild(); + j->saved_ammo = p->ammo_amount[MOTORCYCLE_WEAPON]; p->OnMotorcycle = 0; p->gotweapon.Clear(MOTORCYCLE_WEAPON); p->horizon.horiz = q16horiz(0); @@ -1507,9 +1506,9 @@ void checkweapons_r(struct player_struct* p) } else if (p->OnBoat && numplayers > 1) { - j = fi.spawn(p->i, 7233); - sprite[j].ang = p->angle.ang.asbuild(); - sprite[j].owner = p->ammo_amount[BOAT_WEAPON]; + auto j = spawn(p->GetActor(), 7233); + j->s.ang = p->angle.ang.asbuild(); + j->saved_ammo = p->ammo_amount[BOAT_WEAPON]; p->OnBoat = 0; p->gotweapon.Clear(BOAT_WEAPON); p->horizon.horiz = q16horiz(0); @@ -1526,36 +1525,36 @@ void checkweapons_r(struct player_struct* p) if (p->curr_weapon > 0) { if (krand() & 1) - fi.spawn(p->i, weapon_sprites[p->curr_weapon]); + spawn(p->GetActor(), weapon_sprites[p->curr_weapon]); else switch (p->curr_weapon) { case CHICKEN_WEAPON: if (!isRRRA()) break; case DYNAMITE_WEAPON: case CROSSBOW_WEAPON: - fi.spawn(p->i, EXPLOSION2); + spawn(p->GetActor(), EXPLOSION2); break; } } - for (i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) { if (p->keys[i] == 1) { - j = fi.spawn(p->i, ACCESSCARD); + auto j = spawn(p->GetActor(), ACCESSCARD); switch (i) { case 1: - sprite[j].lotag = 100; + j->s.lotag = 100; break; case 2: - sprite[j].lotag = 101; + j->s.lotag = 101; break; case 3: - sprite[j].lotag = 102; + j->s.lotag = 102; break; case 4: - sprite[j].lotag = 103; + j->s.lotag = 103; break; } } @@ -1571,167 +1570,138 @@ void checkweapons_r(struct player_struct* p) static void onMotorcycle(int snum, ESyncBits &actions) { auto p = &ps[snum]; - auto pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); + + bool braking; + short rng; - int var64, var68, var6c, var70, var74, var78, var7c, var80; - short var84; if (p->MotoSpeed < 0) p->MotoSpeed = 0; + if (actions & SB_CROUCH) { - var64 = 1; + braking = true; actions &= ~SB_CROUCH; } else - var64 = 0; + braking = false; - if (actions & SB_JUMP) + if (p->vehForwardScale != 0) { - var68 = 1; - actions &= ~SB_JUMP; if (p->on_ground) { - if (p->MotoSpeed == 0 && var64) + if (p->MotoSpeed == 0 && braking) { - if (!S_CheckActorSoundPlaying(pi, 187)) - S_PlayActorSound(187, pi); + if (!S_CheckActorSoundPlaying(pact, 187)) + S_PlayActorSound(187, pact); } - else if (p->MotoSpeed == 0 && !S_CheckActorSoundPlaying(pi, 214)) + else if (p->MotoSpeed == 0 && !S_CheckActorSoundPlaying(pact, 214)) { - if (S_CheckActorSoundPlaying(pi, 187)) - S_StopSound(187, pi); - S_PlayActorSound(214, pi); + if (S_CheckActorSoundPlaying(pact, 187)) + S_StopSound(187, pact); + S_PlayActorSound(214, pact); } - else if (p->MotoSpeed >= 50 && !S_CheckActorSoundPlaying(pi, 188)) + else if (p->MotoSpeed >= 50 && !S_CheckActorSoundPlaying(pact, 188)) { - S_PlayActorSound(188, pi); + S_PlayActorSound(188, pact); } - else if (!S_CheckActorSoundPlaying(pi, 188) && !S_CheckActorSoundPlaying(pi, 214)) + else if (!S_CheckActorSoundPlaying(pact, 188) && !S_CheckActorSoundPlaying(pact, 214)) { - S_PlayActorSound(188, pi); + S_PlayActorSound(188, pact); } } } else { - var68 = 0; - if (S_CheckActorSoundPlaying(pi, 214)) + if (S_CheckActorSoundPlaying(pact, 214)) { - S_StopSound(214, pi); - if (!S_CheckActorSoundPlaying(pi, 189)) - S_PlayActorSound(189, pi); + S_StopSound(214, pact); + if (!S_CheckActorSoundPlaying(pact, 189)) + S_PlayActorSound(189, pact); } - if (S_CheckActorSoundPlaying(pi, 188)) + if (S_CheckActorSoundPlaying(pact, 188)) { - S_StopSound(188, pi); - if (!S_CheckActorSoundPlaying(pi, 189)) - S_PlayActorSound(189, pi); + S_StopSound(188, pact); + if (!S_CheckActorSoundPlaying(pact, 189)) + S_PlayActorSound(189, pact); } - if (!S_CheckActorSoundPlaying(pi, 189) && !S_CheckActorSoundPlaying(pi, 187)) - S_PlayActorSound(187, pi); + if (!S_CheckActorSoundPlaying(pact, 189) && !S_CheckActorSoundPlaying(pact, 187)) + S_PlayActorSound(187, pact); } - if (p->vehicle_backwards) - { - var6c = 1; - p->vehicle_backwards = false; - } - else - var6c = 0; - if (p->vehicle_turnl) - { - var70 = 1; - var74 = 1; - p->vehicle_turnl = false; - } - else - { - var70 = 0; - var74 = 0; - } - if (p->vehicle_turnr) - { - var78 = 1; - var7c = 1; - p->vehicle_turnr = false; - } - else - { - var78 = 0; - var7c = 0; - } - var80 = 0; + if (p->drink_amt > 88 && p->moto_drink == 0) { - var84 = krand() & 63; - if (var84 == 1) + rng = krand() & 63; + if (rng == 1) p->moto_drink = -10; - else if (var84 == 2) + else if (rng == 2) p->moto_drink = 10; } else if (p->drink_amt > 99 && p->moto_drink == 0) { - var84 = krand() & 31; - if (var84 == 1) + rng = krand() & 31; + if (rng == 1) p->moto_drink = -20; - else if (var84 == 2) + else if (rng == 2) p->moto_drink = 20; } + if (p->on_ground == 1) { - if (var64 && p->MotoSpeed > 0) + if (braking && p->MotoSpeed > 0) { - if (p->moto_on_oil) - p->MotoSpeed -= 2; - else - p->MotoSpeed -= 4; + p->MotoSpeed -= p->moto_on_oil ? 2 : 4; if (p->MotoSpeed < 0) p->MotoSpeed = 0; p->VBumpTarget = -30; p->moto_do_bump = 1; } - else if (var68 && !var64) + else if (p->vehForwardScale != 0 && !braking) { if (p->MotoSpeed < 40) { p->VBumpTarget = 70; p->moto_bump_fast = 1; } - p->MotoSpeed += 2; + + p->MotoSpeed += 2 * p->vehForwardScale; + p->vehForwardScale = 0; + if (p->MotoSpeed > 120) p->MotoSpeed = 120; - if (!p->NotOnWater) - if (p->MotoSpeed > 80) - p->MotoSpeed = 80; + + if (!p->NotOnWater && p->MotoSpeed > 80) + p->MotoSpeed = 80; } else if (p->MotoSpeed > 0) p->MotoSpeed--; - if (p->moto_do_bump && (!var64 || p->MotoSpeed == 0)) + + if (p->moto_do_bump && (!braking || p->MotoSpeed == 0)) { p->VBumpTarget = 0; p->moto_do_bump = 0; } - if (var6c && p->MotoSpeed <= 0 && !var64) + + if (p->vehReverseScale != 0 && p->MotoSpeed <= 0 && !braking) { - int var88; - p->MotoSpeed = -15; - var88 = var7c; - var7c = var74; - var74 = var88; - var80 = 1; + bool temp = p->vehTurnRight; + p->vehTurnRight = p->vehTurnLeft; + p->vehTurnLeft = temp; + p->MotoSpeed = -15 * p->vehReverseScale; + p->vehReverseScale = 0; } } if (p->MotoSpeed != 0 && p->on_ground == 1) { - if (!p->VBumpNow) - if ((krand() & 3) == 2) - p->VBumpTarget = (p->MotoSpeed >> 4) * ((krand() & 7) - 4); - if (var74 || p->moto_drink < 0) + if (!p->VBumpNow && (krand() & 3) == 2) + p->VBumpTarget = (p->MotoSpeed / 16.) * ((krand() & 7) - 4); + + if (p->vehTurnLeft || p->moto_drink < 0) { if (p->moto_drink < 0) p->moto_drink++; } - else if (var7c || p->moto_drink > 0) + else if (p->vehTurnRight || p->moto_drink > 0) { if (p->moto_drink > 0) p->moto_drink--; @@ -1757,20 +1727,14 @@ static void onMotorcycle(int snum, ESyncBits &actions) } else if (p->VBumpTarget > p->VBumpNow) { - if (p->moto_bump_fast) - p->VBumpNow += 6; - else - p->VBumpNow++; + p->VBumpNow += p->moto_bump_fast ? 6 : 1; if (p->VBumpTarget < p->VBumpNow) p->VBumpNow = p->VBumpTarget; horiz = p->VBumpNow / 3.; } else if (p->VBumpTarget < p->VBumpNow) { - if (p->moto_bump_fast) - p->VBumpNow -= 6; - else - p->VBumpNow--; + p->VBumpNow -= p->moto_bump_fast ? 6 : 1; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; horiz = p->VBumpNow / 3.; @@ -1785,38 +1749,28 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->horizon.addadjustment(horiz - FixedToFloat(p->horizon.horiz.asq16())); } - if (p->MotoSpeed >= 20 && p->on_ground == 1 && (var74 || var7c)) + int currSpeed = p->MotoSpeed; + short currAngle = p->angle.ang.asbuild(), velAdjustment; + if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) { - short var8c, var90, var94, var98; - var8c = p->MotoSpeed; - var90 = p->angle.ang.asbuild(); - if (var74) - var94 = -10; - else - var94 = 10; - if (var94 < 0) - var98 = 350; - else - var98 = -350; - int ang; + velAdjustment = p->vehTurnLeft ? -10 : 10; + short angAdjustment = velAdjustment < 0 ? 350 : -350; + if (p->moto_on_mud || p->moto_on_oil || !p->NotOnWater) { - if (p->moto_on_oil) - var8c <<= 3; - else - var8c <<= 2; + currSpeed <<= p->moto_on_oil ? 3 : 2; + if (p->moto_do_bump) { - p->posxv += (var8c >> 5) * (sintable[(var94 * -51 + var90 + 512) & 2047] << 4); - p->posyv += (var8c >> 5) * (sintable[(var94 * -51 + var90) & 2047] << 4); - ang = var98 >> 2; + currSpeed >>= 5; + angAdjustment >>= 2; } else { - p->posxv += (var8c >> 7) * (sintable[(var94 * -51 + var90 + 512) & 2047] << 4); - p->posyv += (var8c >> 7) * (sintable[(var94 * -51 + var90) & 2047] << 4); - ang = var98 >> 6; + currSpeed >>= 7; + angAdjustment >>= 6; } + p->moto_on_mud = 0; p->moto_on_oil = 0; } @@ -1824,40 +1778,35 @@ static void onMotorcycle(int snum, ESyncBits &actions) { if (p->moto_do_bump) { - p->posxv += (var8c >> 5) * (sintable[(var94 * -51 + var90 + 512) & 2047] << 4); - p->posyv += (var8c >> 5) * (sintable[(var94 * -51 + var90) & 2047] << 4); - ang = var98 >> 4; - if (!S_CheckActorSoundPlaying(pi, 220)) - S_PlayActorSound(220, pi); + currSpeed >>= 5; + angAdjustment >>= 4; + if (!S_CheckActorSoundPlaying(pact, 220)) + S_PlayActorSound(220, pact); } else { - p->posxv += (var8c >> 7) * (sintable[(var94 * -51 + var90 + 512) & 2047] << 4); - p->posyv += (var8c >> 7) * (sintable[(var94 * -51 + var90) & 2047] << 4); - ang = var98 >> 7; + currSpeed >>= 7; + angAdjustment >>= 7; } } - p->angle.addadjustment(FixedToFloat(getincangleq16(p->angle.ang.asq16(), IntToFixed(var90 - ang)))); + + p->posxv += currSpeed * (sintable[(velAdjustment * -51 + currAngle + 512) & 2047] << 4); + p->posyv += currSpeed * (sintable[(velAdjustment * -51 + currAngle) & 2047] << 4); + p->angle.addadjustment(FixedToFloat(getincangleq16(p->angle.ang.asq16(), IntToFixed(currAngle - angAdjustment)))); } else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil)) { - short var9c, vara0, vara4=0; - var9c = p->MotoSpeed; - vara0 = p->angle.ang.asbuild(); - var84 = krand() & 1; - if (var84 == 0) - vara4 = -10; - else if (var84 == 1) - vara4 = 10; - if (p->moto_on_oil) - var9c *= 10; - else - var9c *= 5; - p->posxv += (var9c >> 7) * (sintable[(vara4 * -51 + vara0 + 512) & 2047] << 4); - p->posyv += (var9c >> 7) * (sintable[(vara4 * -51 + vara0) & 2047] << 4); + rng = krand() & 1; + velAdjustment = rng == 0 ? -10 : 10; + currSpeed = mulscale7(currSpeed, p->moto_on_oil ? 10 : 5); + p->posxv += currSpeed * (sintable[(velAdjustment * -51 + currAngle + 512) & 2047] << 4); + p->posyv += currSpeed * (sintable[(velAdjustment * -51 + currAngle) & 2047] << 4); } + p->moto_on_mud = 0; p->moto_on_oil = 0; + p->vehTurnLeft = false; + p->vehTurnRight = false; } //--------------------------------------------------------------------------- @@ -1869,137 +1818,112 @@ static void onMotorcycle(int snum, ESyncBits &actions) static void onBoat(int snum, ESyncBits &actions) { auto p = &ps[snum]; - auto pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); + + bool heeltoe, braking; + short rng; - int vara8, varac, varb0, varb4, varb8, varbc, varc0, varc4, varc8; - short varcc; if (p->NotOnWater) { if (p->MotoSpeed > 0) { - if (!S_CheckActorSoundPlaying(pi, 88)) - S_PlayActorSound(88, pi); + if (!S_CheckActorSoundPlaying(pact, 88)) + S_PlayActorSound(88, pact); } else { - if (!S_CheckActorSoundPlaying(pi, 87)) - S_PlayActorSound(87, pi); + if (!S_CheckActorSoundPlaying(pact, 87)) + S_PlayActorSound(87, pact); } } + if (p->MotoSpeed < 0) p->MotoSpeed = 0; - if ((actions & SB_CROUCH) && (actions & SB_JUMP)) + + if ((actions & SB_CROUCH) && (p->vehForwardScale != 0)) { - vara8 = 1; - varac = 0; - varb0 = 0; - actions &= ~(SB_JUMP|SB_CROUCH); + heeltoe = true; + braking = false; + p->vehForwardScale = 0; + actions &= ~SB_CROUCH; } else - vara8 = 0; - if (actions & SB_JUMP) + heeltoe = false; + + if (p->vehForwardScale != 0) { - varac = 1; - actions &= ~SB_JUMP; - if (p->MotoSpeed == 0 && !S_CheckActorSoundPlaying(pi, 89)) + if (p->MotoSpeed == 0 && !S_CheckActorSoundPlaying(pact, 89)) { - if (S_CheckActorSoundPlaying(pi, 87)) - S_StopSound(pi, 87); - S_PlayActorSound(89, pi); + if (S_CheckActorSoundPlaying(pact, 87)) + S_StopSound(87, pact); + S_PlayActorSound(89, pact); } - else if (p->MotoSpeed >= 50 && !S_CheckActorSoundPlaying(pi, 88)) - S_PlayActorSound(88, pi); - else if (!S_CheckActorSoundPlaying(pi, 88) && !S_CheckActorSoundPlaying(pi, 89)) - S_PlayActorSound(88, pi); + else if (p->MotoSpeed >= 50 && !S_CheckActorSoundPlaying(pact, 88)) + S_PlayActorSound(88, pact); + else if (!S_CheckActorSoundPlaying(pact, 88) && !S_CheckActorSoundPlaying(pact, 89)) + S_PlayActorSound(88, pact); } else { - varac = 0; - if (S_CheckActorSoundPlaying(pi, 89)) + if (S_CheckActorSoundPlaying(pact, 89)) { - S_StopSound(pi, 89); - if (!S_CheckActorSoundPlaying(pi, 90)) - S_PlayActorSound(90, pi); + S_StopSound(89, pact); + if (!S_CheckActorSoundPlaying(pact, 90)) + S_PlayActorSound(90, pact); } - if (S_CheckActorSoundPlaying(pi, 88)) + if (S_CheckActorSoundPlaying(pact, 88)) { - S_StopSound(pi, 88); - if (!S_CheckActorSoundPlaying(pi, 90)) - S_PlayActorSound(90, pi); + S_StopSound(88, pact); + if (!S_CheckActorSoundPlaying(pact, 90)) + S_PlayActorSound(90, pact); } - if (!S_CheckActorSoundPlaying(pi, 90) && !S_CheckActorSoundPlaying(pi, 87)) - S_PlayActorSound(87, pi); + if (!S_CheckActorSoundPlaying(pact, 90) && !S_CheckActorSoundPlaying(pact, 87)) + S_PlayActorSound(87, pact); } if (actions & SB_CROUCH) { - varb0 = 1; + braking = true; actions &= ~SB_CROUCH; } else - varb0 = 0; - if (p->vehicle_backwards) - { - varb4 = 1; - p->vehicle_backwards = false; - } - else varb4 = 0; - if (p->vehicle_turnl) - { - varb8 = 1; - varbc = 1; - p->vehicle_turnl = false; - if (!S_CheckActorSoundPlaying(pi, 91) && p->MotoSpeed > 30 && !p->NotOnWater) - S_PlayActorSound(91, pi); - } - else - { - varb8 = 0; - varbc = 0; - } - if (p->vehicle_turnr) - { - varc0 = 1; - varc4 = 1; - p->vehicle_turnr = false; - if (!S_CheckActorSoundPlaying(pi, 91) && p->MotoSpeed > 30 && !p->NotOnWater) - S_PlayActorSound(91, pi); - } - else - { - varc0 = 0; - varc4 = 0; - } - varc8 = 0; + braking = false; + + if (p->vehTurnLeft && !S_CheckActorSoundPlaying(pact, 91) && p->MotoSpeed > 30 && !p->NotOnWater) + S_PlayActorSound(91, pact); + + if (p->vehTurnRight && !S_CheckActorSoundPlaying(pact, 91) && p->MotoSpeed > 30 && !p->NotOnWater) + S_PlayActorSound(91, pact); + if (!p->NotOnWater) { if (p->drink_amt > 88 && p->moto_drink == 0) { - varcc = krand() & 63; - if (varcc == 1) + rng = krand() & 63; + if (rng == 1) p->moto_drink = -10; - else if (varcc == 2) + else if (rng == 2) p->moto_drink = 10; } else if (p->drink_amt > 99 && p->moto_drink == 0) { - varcc = krand() & 31; - if (varcc == 1) + rng = krand() & 31; + if (rng == 1) p->moto_drink = -20; - else if (varcc == 2) + else if (rng == 2) p->moto_drink = 20; } } + if (p->on_ground == 1) { - if (vara8) + if (heeltoe) { if (p->MotoSpeed <= 25) { p->MotoSpeed++; - if (!S_CheckActorSoundPlaying(pi, 182)) - S_PlayActorSound(182, pi); + if (!S_CheckActorSoundPlaying(pact, 182)) + S_PlayActorSound(182, pact); } else { @@ -2010,7 +1934,7 @@ static void onBoat(int snum, ESyncBits &actions) p->moto_do_bump = 1; } } - else if (varb0 && p->MotoSpeed > 0) + else if (braking && p->MotoSpeed > 0) { p->MotoSpeed -= 2; if (p->MotoSpeed < 0) @@ -2018,52 +1942,48 @@ static void onBoat(int snum, ESyncBits &actions) p->VBumpTarget = 30; p->moto_do_bump = 1; } - else if (varac) + else if (p->vehForwardScale != 0) { - if (p->MotoSpeed < 40) - if (!p->NotOnWater) - { - p->VBumpTarget = -30; - p->moto_bump_fast = 1; - } - p->MotoSpeed++; + if (p->MotoSpeed < 40 && !p->NotOnWater) + { + p->VBumpTarget = -30; + p->moto_bump_fast = 1; + } + p->MotoSpeed += 1 * p->vehForwardScale; + p->vehForwardScale = 0; if (p->MotoSpeed > 120) p->MotoSpeed = 120; } else if (p->MotoSpeed > 0) p->MotoSpeed--; - if (p->moto_do_bump && (!varb0 || p->MotoSpeed == 0)) + + if (p->moto_do_bump && (!braking || p->MotoSpeed == 0)) { p->VBumpTarget = 0; p->moto_do_bump = 0; } - if (varb4 && p->MotoSpeed == 0 && !varb0) + + if (p->vehReverseScale != 0 && p->MotoSpeed == 0 && !braking) { - int vard0; - if (!p->NotOnWater) - p->MotoSpeed = -25; - else - p->MotoSpeed = -20; - vard0 = varc4; - varc4 = varbc; - varbc = vard0; - varc8 = 1; + bool temp = p->vehTurnRight; + p->vehTurnRight = p->vehTurnLeft; + p->vehTurnLeft = temp; + p->MotoSpeed = -(!p->NotOnWater ? 25 : 20) * p->vehReverseScale; + p->vehReverseScale = 0; } } if (p->MotoSpeed != 0 && p->on_ground == 1) { - if (!p->VBumpNow) - if ((krand() & 15) == 14) - p->VBumpTarget = (p->MotoSpeed >> 4) * ((krand() & 3) - 2); - if (varbc || p->moto_drink < 0) + if (!p->VBumpNow && (krand() & 15) == 14) + p->VBumpTarget = (p->MotoSpeed / 16.) * ((krand() & 3) - 2); + + if (p->vehTurnLeft && p->moto_drink < 0) { - if (p->moto_drink < 0) - p->moto_drink++; + p->moto_drink++; } - else if (varc4 || p->moto_drink > 0) + else if (p->vehTurnRight && p->moto_drink > 0) { - if (p->moto_drink > 0) - p->moto_drink--; + p->moto_drink--; } } @@ -2086,20 +2006,14 @@ static void onBoat(int snum, ESyncBits &actions) } else if (p->VBumpTarget > p->VBumpNow) { - if (p->moto_bump_fast) - p->VBumpNow += 6; - else - p->VBumpNow++; + p->VBumpNow += p->moto_bump_fast ? 6 : 1; if (p->VBumpTarget < p->VBumpNow) p->VBumpNow = p->VBumpTarget; horiz = p->VBumpNow / 3.; } else if (p->VBumpTarget < p->VBumpNow) { - if (p->moto_bump_fast) - p->VBumpNow -= 6; - else - p->VBumpNow--; + p->VBumpNow -= p->moto_bump_fast ? 6 : 1; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; horiz = p->VBumpNow / 3.; @@ -2114,39 +2028,33 @@ static void onBoat(int snum, ESyncBits &actions) p->horizon.addadjustment(horiz - FixedToFloat(p->horizon.horiz.asq16())); } - if (p->MotoSpeed > 0 && p->on_ground == 1 && (varbc || varc4)) + if (p->MotoSpeed > 0 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) { - short vard4, vard8, vardc, vare0; - vard4 = p->MotoSpeed; - vard8 = p->angle.ang.asbuild(); - if (varbc) - vardc = -10; - else - vardc = 10; - if (vardc < 0) - vare0 = 350; - else - vare0 = -350; - vard4 <<= 2; - int ang; + int currSpeed = p->MotoSpeed * 4.; + short currAngle = p->angle.ang.asbuild(); + short velAdjustment = p->vehTurnLeft ? -10 : 10; + short angAdjustment = velAdjustment < 0 ? 350 : -350; + if (p->moto_do_bump) { - p->posxv += (vard4 >> 6) * (sintable[(vardc * -51 + vard8 + 512) & 2047] << 4); - p->posyv += (vard4 >> 6) * (sintable[(vardc * -51 + vard8) & 2047] << 4); - ang = vare0 >> 5; + currSpeed >>= 6; + angAdjustment >>= 5; } else { - p->posxv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8 + 512) & 2047] << 4); - p->posyv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8) & 2047] << 4); - ang = vare0 >> 6; + currSpeed >>= 7; + angAdjustment >>= 6; } - p->angle.addadjustment(FixedToFloat(getincangleq16(p->angle.ang.asq16(), IntToFixed(vard8 - ang)))); - } - if (p->NotOnWater) - if (p->MotoSpeed > 50) - p->MotoSpeed -= (p->MotoSpeed >> 1); + p->posxv += currSpeed * (sintable[(velAdjustment * -51 + currAngle + 512) & 2047] << 4); + p->posyv += currSpeed * (sintable[(velAdjustment * -51 + currAngle) & 2047] << 4); + p->angle.addadjustment(FixedToFloat(getincangleq16(p->angle.ang.asq16(), IntToFixed(currAngle - angAdjustment)))); + } + if (p->NotOnWater && p->MotoSpeed > 50) + p->MotoSpeed -= (p->MotoSpeed / 2.); + + p->vehTurnLeft = false; + p->vehTurnRight = false; } //--------------------------------------------------------------------------- @@ -2158,8 +2066,8 @@ static void onBoat(int snum, ESyncBits &actions) static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int shrunk, int truefdist, int psectlotag) { auto p = &ps[snum]; - auto pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); + auto s = &pact->s; if (p->airleft != 15 * 26) p->airleft = 15 * 26; //Aprox twenty seconds. @@ -2183,9 +2091,8 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int { if (p->on_ground == 1) { - if (p->dummyplayersprite == -1) - p->dummyplayersprite = - fi.spawn(pi, PLAYERONWATER); + if (p->dummyplayersprite == nullptr) + p->dummyplayersprite = spawn(pact, PLAYERONWATER); p->footprintcount = 6; if (sector[p->cursectnum].floorpicnum == FLOORSLIME) @@ -2225,17 +2132,17 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int { p->VBumpTarget = 80; p->moto_bump_fast = 1; - p->poszv -= gc * (p->MotoSpeed >> 4); + p->poszv -= xs_CRoundToInt(gc * (p->MotoSpeed / 16.)); p->MotoOnGround = 0; - if (S_CheckActorSoundPlaying(pi, 188)) - S_StopSound(188, pi); - S_PlayActorSound(189, pi); + if (S_CheckActorSoundPlaying(pact, 188)) + S_StopSound(188, pact); + S_PlayActorSound(189, pact); } else { p->poszv += gc - 80 + (120 - p->MotoSpeed); - if (!S_CheckActorSoundPlaying(pi, 189) && !S_CheckActorSoundPlaying(pi, 190)) - S_PlayActorSound(190, pi); + if (!S_CheckActorSoundPlaying(pact, 189) && !S_CheckActorSoundPlaying(pact, 190)) + S_PlayActorSound(190, pact); } } else @@ -2245,13 +2152,13 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int if (p->poszv > 2400 && p->falling_counter < 255) { p->falling_counter++; - if (p->falling_counter == 38 && !S_CheckActorSoundPlaying(pi, DUKE_SCREAM)) - S_PlayActorSound(DUKE_SCREAM, pi); + if (p->falling_counter == 38 && !S_CheckActorSoundPlaying(pact, DUKE_SCREAM)) + S_PlayActorSound(DUKE_SCREAM, pact); } if ((p->posz + p->poszv) >= (fz - (i << 8))) // hit the ground { - S_StopSound(DUKE_SCREAM, pi); + S_StopSound(DUKE_SCREAM, pact); if (sector[p->cursectnum].lotag != 1) { if (isRRRA()) p->MotoOnGround = 1; @@ -2264,12 +2171,12 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int s->extra -= j - (krand() & 3); if (s->extra <= 0) { - S_PlayActorSound(SQUISHED, pi); + S_PlayActorSound(SQUISHED, pact); } else { - S_PlayActorSound(DUKE_LAND, pi); - S_PlayActorSound(DUKE_LAND_HURT, pi); + S_PlayActorSound(DUKE_LAND, pact); + S_PlayActorSound(DUKE_LAND_HURT, pact); } SetPlayerPal(p, PalEntry(32, 16, 0, 0)); @@ -2278,16 +2185,16 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int { if (p->OnMotorcycle) { - if (S_CheckActorSoundPlaying(pi, 190)) - S_StopSound(pi, 190); - S_PlayActorSound(191, pi); + if (S_CheckActorSoundPlaying(pact, 190)) + S_StopSound(190, pact); + S_PlayActorSound(191, pact); p->TurbCount = 12; } - else S_PlayActorSound(DUKE_LAND, pi); + else S_PlayActorSound(DUKE_LAND, pact); } else if (p->poszv > 1024 && p->OnMotorcycle) { - S_PlayActorSound(DUKE_LAND, pi); + S_PlayActorSound(DUKE_LAND, pact); p->TurbCount = 12; } } @@ -2298,7 +2205,7 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int else { p->falling_counter = 0; - S_StopSound(-1, pi, CHAN_VOICE); + S_StopSound(-1, pact, CHAN_VOICE); if (psectlotag != ST_1_ABOVE_WATER && psectlotag != ST_2_UNDERWATER && p->on_ground == 0 && p->poszv > (6144 >> 1)) p->hard_landing = p->poszv >> 10; @@ -2387,9 +2294,8 @@ static void movement(int snum, ESyncBits actions, int psect, int fz, int cz, int static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) { - int j; auto p = &ps[snum]; - int pi = p->i; + auto pact = p->GetActor(); int psectlotag = sector[psect].lotag; p->jumping_counter = 0; @@ -2398,8 +2304,8 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) p->pycount &= 2047; p->pyoff = sintable[p->pycount] >> 7; - if (!S_CheckActorSoundPlaying(pi, DUKE_UNDERWATER)) - S_PlayActorSound(DUKE_UNDERWATER, pi); + if (!S_CheckActorSoundPlaying(pact, DUKE_UNDERWATER)) + S_PlayActorSound(DUKE_UNDERWATER, pact); if ((actions & SB_JUMP) && !p->OnMotorcycle) { @@ -2445,15 +2351,13 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) if (p->scuba_on && (krand() & 255) < 8) { - j = fi.spawn(pi, WATERBUBBLE); - sprite[j].x += - sintable[(p->angle.ang.asbuild() + 512 + 64 - (global_random & 128) + 128) & 2047] >> 6; - sprite[j].y += - sintable[(p->angle.ang.asbuild() + 64 - (global_random & 128) + 128) & 2047] >> 6; - sprite[j].xrepeat = 3; - sprite[j].yrepeat = 2; - sprite[j].z = p->posz + (8 << 8); - sprite[j].cstat = 514; + auto j = spawn(pact, WATERBUBBLE); + j->s.x += sintable[(p->angle.ang.asbuild() + 512 + 64 - (global_random & 128) + 128) & 2047] >> 6; + j->s.y += sintable[(p->angle.ang.asbuild() + 64 - (global_random & 128) + 128) & 2047] >> 6; + j->s.xrepeat = 3; + j->s.yrepeat = 2; + j->s.z = p->posz + (8 << 8); + j->s.cstat = 514; } } @@ -2466,62 +2370,50 @@ static void underwater(int snum, ESyncBits actions, int psect, int fz, int cz) void onMotorcycleMove(int snum, int psect, int j) { auto p = &ps[snum]; - int pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); + auto s = &pact->s; int psectlotag = sector[psect].lotag; + short angleDelta = abs(p->angle.ang.asbuild() - getangle(wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y)); + short damageAmount; - short var104, var108, var10c; - var104 = 0; - j &= (MAXWALLS - 1); - var108 = getangle(wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y); - var10c = abs(p->angle.ang.asbuild() - var108); - int ang; - switch (krand() & 1) + p->angle.addadjustment(p->MotoSpeed / (krand() & 1 ? -2 : 2)); + + if (angleDelta >= 441 && angleDelta <= 581) { - case 0: - ang = p->MotoSpeed >> 1; - break; - case 1: - ang = -(p->MotoSpeed >> 1); - break; - } - p->angle.addadjustment(ang); - if (var10c >= 441 && var10c <= 581) - { - var104 = (p->MotoSpeed * p->MotoSpeed) >> 8; + damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 256.); p->MotoSpeed = 0; - if (S_CheckActorSoundPlaying(pi, 238) == 0) - S_PlayActorSound(238, pi); + if (S_CheckActorSoundPlaying(pact, 238) == 0) + S_PlayActorSound(238, pact); } - else if (var10c >= 311 && var10c <= 711) + else if (angleDelta >= 311 && angleDelta <= 711) { - var104 = (p->MotoSpeed * p->MotoSpeed) >> 11; - p->MotoSpeed -= (p->MotoSpeed >> 1) + (p->MotoSpeed >> 2); - if (S_CheckActorSoundPlaying(pi, 238) == 0) - S_PlayActorSound(238, pi); + damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 2048.); + p->MotoSpeed -= (p->MotoSpeed / 2.) + (p->MotoSpeed / 4.); + if (S_CheckActorSoundPlaying(pact, 238) == 0) + S_PlayActorSound(238, pact); } - else if (var10c >= 111 && var10c <= 911) + else if (angleDelta >= 111 && angleDelta <= 911) { - var104 = (p->MotoSpeed * p->MotoSpeed) >> 14; - p->MotoSpeed -= (p->MotoSpeed >> 1); - if (S_CheckActorSoundPlaying(pi, 239) == 0) - S_PlayActorSound(239, pi); + damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 16384.); + p->MotoSpeed -= p->MotoSpeed / 2.; + if (S_CheckActorSoundPlaying(pact, 239) == 0) + S_PlayActorSound(239, pact); } else { - var104 = (p->MotoSpeed * p->MotoSpeed) >> 15; - p->MotoSpeed -= (p->MotoSpeed >> 3); - if (S_CheckActorSoundPlaying(pi, 240) == 0) - S_PlayActorSound(240, pi); + damageAmount = xs_CRoundToInt((p->MotoSpeed * p->MotoSpeed) / 32768.); + p->MotoSpeed -= p->MotoSpeed / 8.; + if (S_CheckActorSoundPlaying(pact, 240) == 0) + S_PlayActorSound(240, pact); } - s->extra -= var104; + s->extra -= damageAmount; if (s->extra <= 0) { - S_PlayActorSound(SQUISHED, pi); + S_PlayActorSound(SQUISHED, pact); SetPlayerPal(p, PalEntry(63, 63, 0, 0)); } - else if (var104) - S_PlayActorSound(DUKE_LAND_HURT, pi); + else if (damageAmount) + S_PlayActorSound(DUKE_LAND_HURT, pact); } @@ -2534,52 +2426,35 @@ void onMotorcycleMove(int snum, int psect, int j) void onBoatMove(int snum, int psect, int j) { auto p = &ps[snum]; - int pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); int psectlotag = sector[psect].lotag; + short angleDelta = abs(p->angle.ang.asbuild() - getangle(wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y)); - short var114, var118; - j &= (MAXWALLS - 1); - var114 = getangle(wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y); - var118 = abs(p->angle.ang.asbuild() - var114); - int ang; - switch (krand() & 1) + p->angle.addadjustment(p->MotoSpeed / (krand() & 1 ? -4 : 4)); + + if (angleDelta >= 441 && angleDelta <= 581) { - case 0: - ang = p->MotoSpeed >> 2; - break; - case 1: - ang = -(p->MotoSpeed >> 2); - break; + p->MotoSpeed = ((p->MotoSpeed / 2.) + (p->MotoSpeed / 4.)) / 4.; + if (psectlotag == 1 && S_CheckActorSoundPlaying(pact, 178) == 0) + S_PlayActorSound(178, pact); } - p->angle.addadjustment(ang); - if (var118 >= 441 && var118 <= 581) + else if (angleDelta >= 311 && angleDelta <= 711) { - p->MotoSpeed = ((p->MotoSpeed >> 1) + (p->MotoSpeed >> 2)) >> 2; - if (psectlotag == 1) - if (S_CheckActorSoundPlaying(pi, 178) == 0) - S_PlayActorSound(178, pi); + p->MotoSpeed -= ((p->MotoSpeed / 2.) + (p->MotoSpeed / 4.)) / 8.; + if (psectlotag == 1 && S_CheckActorSoundPlaying(pact, 179) == 0) + S_PlayActorSound(179, pact); } - else if (var118 >= 311 && var118 <= 711) + else if (angleDelta >= 111 && angleDelta <= 911) { - p->MotoSpeed -= ((p->MotoSpeed >> 1) + (p->MotoSpeed >> 2)) >> 3; - if (psectlotag == 1) - if (S_CheckActorSoundPlaying(pi, 179) == 0) - S_PlayActorSound(179, pi); - } - else if (var118 >= 111 && var118 <= 911) - { - p->MotoSpeed -= (p->MotoSpeed >> 4); - if (psectlotag == 1) - if (S_CheckActorSoundPlaying(pi, 180) == 0) - S_PlayActorSound(180, pi); + p->MotoSpeed -= p->MotoSpeed / 16.; + if (psectlotag == 1 && S_CheckActorSoundPlaying(pact, 180) == 0) + S_PlayActorSound(180, pact); } else { - p->MotoSpeed -= (p->MotoSpeed >> 6); - if (psectlotag == 1) - if (S_CheckActorSoundPlaying(pi, 181) == 0) - S_PlayActorSound(181, pi); + p->MotoSpeed -= p->MotoSpeed / 64.; + if (psectlotag == 1 && S_CheckActorSoundPlaying(pact, 181) == 0) + S_PlayActorSound(181, pact); } } @@ -2590,39 +2465,40 @@ void onBoatMove(int snum, int psect, int j) // //--------------------------------------------------------------------------- -void onMotorcycleHit(int snum, int var60) +void onMotorcycleHit(int snum, DDukeActor* victim) { auto p = &ps[snum]; - auto s = &sprite[var60]; - auto ht = &hittype[var60]; + auto s = &victim->s; if (badguy(s) || s->picnum == APLAYER) { if (s->picnum != APLAYER) { if (numplayers == 1) { - fi.movesprite(var60, sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild() + 512) & 2047] >> 8, - sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild()) & 2047] >> 8, s->zvel, CLIPMASK0); + Collision coll; + movesprite_ex(victim, sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild() + 512) & 2047] >> 8, + sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild()) & 2047] >> 8, s->zvel, CLIPMASK0, coll); } } else - ht->owner = p->i; - ht->picnum = MOTOHIT; - ht->extra = p->MotoSpeed >> 1; - p->MotoSpeed -= p->MotoSpeed >> 2; + victim->SetHitOwner(p->GetActor()); + victim->picnum = MOTOHIT; + victim->extra = xs_CRoundToInt(p->MotoSpeed / 2.); + p->MotoSpeed -= p->MotoSpeed / 4.; p->TurbCount = 6; } else if ((s->picnum == RRTILE2431 || s->picnum == RRTILE2443 || s->picnum == RRTILE2451 || s->picnum == RRTILE2455) && s->picnum != ACTIVATORLOCKED && p->MotoSpeed > 45) { - S_PlayActorSound(SQUISHED, var60); + S_PlayActorSound(SQUISHED, victim); if (s->picnum == RRTILE2431 || s->picnum == RRTILE2451) { if (s->lotag != 0) { - for (int j = 0; j < MAXSPRITES; j++) + DukeSpriteIterator it; + while (auto act2 = it.Next()) { - auto sprj = &sprite[j]; + auto sprj = &act2->s; if ((sprj->picnum == RRTILE2431 || sprj->picnum == RRTILE2451) && sprj->pal == 4) { if (s->lotag == sprj->lotag) @@ -2633,12 +2509,12 @@ void onMotorcycleHit(int snum, int var60) } } } - fi.guts(&sprite[var60], RRTILE2460, 12, myconnectindex); - fi.guts(&sprite[var60], RRTILE2465, 3, myconnectindex); + fi.guts(victim, RRTILE2460, 12, myconnectindex); + fi.guts(victim, RRTILE2465, 3, myconnectindex); } else - fi.guts(&sprite[var60], RRTILE2465, 3, myconnectindex); - fi.guts(&sprite[var60], RRTILE2465, 3, myconnectindex); + fi.guts(victim, RRTILE2465, 3, myconnectindex); + fi.guts(victim, RRTILE2465, 3, myconnectindex); s->xrepeat = 0; s->yrepeat = 0; } @@ -2650,11 +2526,10 @@ void onMotorcycleHit(int snum, int var60) // //--------------------------------------------------------------------------- -void onBoatHit(int snum, int var60) +void onBoatHit(int snum, DDukeActor* victim) { auto p = &ps[snum]; - auto s = &sprite[var60]; - auto ht = &hittype[var60]; + auto s = &victim->s; if (badguy(s) || s->picnum == APLAYER) { @@ -2662,15 +2537,16 @@ void onBoatHit(int snum, int var60) { if (numplayers == 1) { - fi.movesprite(var60, sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild() + 512) & 2047] >> 9, - sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild()) & 2047] >> 9, s->zvel, CLIPMASK0); + Collision coll; + movesprite_ex(victim, sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild() + 512) & 2047] >> 9, + sintable[int(p->TiltStatus * 20 + p->angle.ang.asbuild()) & 2047] >> 9, s->zvel, CLIPMASK0, coll); } } else - ht->owner = p->i; - ht->picnum = MOTOHIT; - ht->extra = p->MotoSpeed >> 2; - p->MotoSpeed -= p->MotoSpeed >> 2; + victim->SetHitOwner(p->GetActor()); + victim->picnum = MOTOHIT; + victim->extra = xs_CRoundToInt(p->MotoSpeed / 4.); + p->MotoSpeed -= p->MotoSpeed / 4.; p->TurbCount = 6; } } @@ -2684,7 +2560,6 @@ void onBoatHit(int snum, int var60) static void fireweapon(int snum) { auto p = &ps[snum]; - int pi = p->i; p->crack_time = CRACK_TIME; @@ -2746,13 +2621,13 @@ static void fireweapon(int snum) if (p->ammo_amount[BUZZSAW_WEAPON] > 0) { p->kickback_pic = 1; - S_PlayActorSound(431, pi); + S_PlayActorSound(431, p->GetActor()); } } else if (p->ammo_amount[THROWSAW_WEAPON] > 0) { p->kickback_pic = 1; - S_PlayActorSound(SHRINKER_FIRE, pi); + S_PlayActorSound(SHRINKER_FIRE, p->GetActor()); } break; @@ -2817,8 +2692,8 @@ static void fireweapon(int snum) static void operateweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; - int pi = p->i; - int i, j, k; + auto pact = p->GetActor(); + int i, k; int psectlotag = sector[psect].lotag; if (!isRRRA() && p->curr_weapon >= MOTORCYCLE_WEAPON) return; @@ -2876,24 +2751,24 @@ static void operateweapon(int snum, ESyncBits actions, int psect) i = -512 - -mulscale16(p->horizon.sum().asq16(), 20); } - j = EGS(p->cursectnum, + auto spawned = EGS(p->cursectnum, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 6), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 6), p->posz, HEAVYHBOMB, -16, 9, 9, - p->angle.ang.asbuild(), (k + (p->hbomb_hold_delay << 5)) * 2, i, pi, 1); + p->angle.ang.asbuild(), (k + (p->hbomb_hold_delay << 5)) * 2, i, pact, 1); if (k == 15) { - sprite[j].yvel = 3; - sprite[j].z += (8 << 8); + spawned->s.yvel = 3; + spawned->s.z += (8 << 8); } - k = hits(pi); + k = hits(p->GetActor()); if (k < 512) { - sprite[j].ang += 1024; - sprite[j].zvel /= 3; - sprite[j].xvel /= 3; + spawned->s.ang += 1024; + spawned->s.zvel /= 3; + spawned->s.xvel /= 3; } p->hbomb_on = 1; @@ -2920,8 +2795,8 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case PISTOL_WEAPON: if (p->kickback_pic == 1) { - fi.shoot(pi, SHOTSPARK1); - S_PlayActorSound(PISTOL_FIRE, pi); + fi.shoot(pact, SHOTSPARK1); + S_PlayActorSound(PISTOL_FIRE, pact); p->noise_radius = 8192; madenoise(snum); @@ -2955,10 +2830,10 @@ static void operateweapon(int snum, ESyncBits actions, int psect) switch (p->kickback_pic) { case 24: - S_PlayActorSound(EJECT_CLIP, pi); + S_PlayActorSound(EJECT_CLIP, pact); break; case 30: - S_PlayActorSound(INSERT_CLIP, pi); + S_PlayActorSound(INSERT_CLIP, pact); break; } } @@ -2986,20 +2861,20 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if (p->kickback_pic == 4) { - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); p->ammo_amount[SHOTGUN_WEAPON]--; - S_PlayActorSound(SHOTGUN_FIRE, pi); + S_PlayActorSound(SHOTGUN_FIRE, pact); p->noise_radius = 8192; madenoise(snum); @@ -3012,20 +2887,20 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { if (p->shotgun_state[1]) { - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); - fi.shoot(pi, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); + fi.shoot(pact, SHOTGUN); p->ammo_amount[SHOTGUN_WEAPON]--; - S_PlayActorSound(SHOTGUN_FIRE, pi); + S_PlayActorSound(SHOTGUN_FIRE, pact); if (psectlotag != 857) { @@ -3048,7 +2923,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) checkavailweapon(p); break; case 17: - S_PlayActorSound(SHOTGUN_COCK, pi); + S_PlayActorSound(SHOTGUN_COCK, pact); break; case 28: p->okickback_pic = p->kickback_pic = 0; @@ -3065,7 +2940,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) checkavailweapon(p); break; case 27: - S_PlayActorSound(SHOTGUN_COCK, pi); + S_PlayActorSound(SHOTGUN_COCK, pact); break; case 38: p->okickback_pic = p->kickback_pic = 0; @@ -3102,17 +2977,17 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if ((p->kickback_pic % 3) == 0) { - j = fi.spawn(pi, SHELL); + auto j = spawn(pact, SHELL); - sprite[j].ang += 1024; - sprite[j].ang &= 2047; - sprite[j].xvel += 32; - sprite[j].z += (3 << 8); + j->s.ang += 1024; + j->s.ang &= 2047; + j->s.xvel += 32; + j->s.z += (3 << 8); ssp(j, CLIPMASK0); } - S_PlayActorSound(CHAINGUN_FIRE, pi); - fi.shoot(pi, CHAINGUN); + S_PlayActorSound(CHAINGUN_FIRE, pact); + fi.shoot(pact, CHAINGUN); p->noise_radius = 8192; madenoise(snum); lastvisinc = ud.levelclock + 32; @@ -3145,7 +3020,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if (p->kickback_pic > 3) { p->okickback_pic = p->kickback_pic = 0; - fi.shoot(pi, GROWSPARK); + fi.shoot(pact, GROWSPARK); p->noise_radius = 1024; madenoise(snum); checkavailweapon(p); @@ -3158,7 +3033,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if (p->kickback_pic == 1) { p->ammo_amount[THROWSAW_WEAPON]--; - fi.shoot(pi, SHRINKSPARK); + fi.shoot(pact, SHRINKSPARK); checkavailweapon(p); } p->kickback_pic++; @@ -3172,8 +3047,8 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { p->visibility = 0; lastvisinc = ud.levelclock + 32; - S_PlayActorSound(CHAINGUN_FIRE, pi); - fi.shoot(pi, SHOTSPARK1); + S_PlayActorSound(CHAINGUN_FIRE, pact); + fi.shoot(pact, SHOTSPARK1); p->noise_radius = 16384; madenoise(snum); p->ammo_amount[TIT_WEAPON]--; @@ -3199,8 +3074,8 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { p->visibility = 0; lastvisinc = ud.levelclock + 32; - S_PlayActorSound(CHAINGUN_FIRE, pi); - fi.shoot(pi, CHAINGUN); + S_PlayActorSound(CHAINGUN_FIRE, pact); + fi.shoot(pact, CHAINGUN); p->noise_radius = 16384; madenoise(snum); p->ammo_amount[MOTORCYCLE_WEAPON]--; @@ -3227,7 +3102,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect) { p->MotoSpeed -= 20; p->ammo_amount[BOAT_WEAPON]--; - fi.shoot(pi, RRTILE1790); + fi.shoot(pact, RRTILE1790); } p->kickback_pic++; if (p->kickback_pic > 20) @@ -3244,11 +3119,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case ALIENBLASTER_WEAPON: p->kickback_pic++; if (p->kickback_pic >= 7 && p->kickback_pic <= 11) - fi.shoot(pi, FIRELASER); + fi.shoot(pact, FIRELASER); if (p->kickback_pic == 5) { - S_PlayActorSound(CAT_FIRE, pi); + S_PlayActorSound(CAT_FIRE, pact); p->noise_radius = 2048; madenoise(snum); } @@ -3286,11 +3161,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) i = -512 - mulscale16(p->horizon.sum().asq16(), 20); } - j = EGS(p->cursectnum, + EGS(p->cursectnum, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 6), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 6), p->posz, TRIPBOMBSPRITE, -16, 9, 9, - p->angle.ang.asbuild(), k * 2, i, pi, 1); + p->angle.ang.asbuild(), k * 2, i, pact, 1); } p->kickback_pic++; if (p->kickback_pic > 20) @@ -3304,8 +3179,8 @@ static void operateweapon(int snum, ESyncBits actions, int psect) if (p->kickback_pic == 30) { p->ammo_amount[BOWLING_WEAPON]--; - S_PlayActorSound(354, pi); - fi.shoot(pi, BOWLINGBALL); + S_PlayActorSound(354, pact); + fi.shoot(pact, BOWLINGBALL); p->noise_radius = 1024; madenoise(snum); } @@ -3326,10 +3201,10 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case KNEE_WEAPON: p->kickback_pic++; if (p->kickback_pic == 3) - S_PlayActorSound(426, pi); + S_PlayActorSound(426, pact); if (p->kickback_pic == 12) { - fi.shoot(pi, KNEE); + fi.shoot(pact, KNEE); p->noise_radius = 1024; madenoise(snum); } @@ -3344,10 +3219,10 @@ static void operateweapon(int snum, ESyncBits actions, int psect) case SLINGBLADE_WEAPON: p->kickback_pic++; if (p->kickback_pic == 3) - S_PlayActorSound(252, pi); + S_PlayActorSound(252, pact); if (p->kickback_pic == 8) { - fi.shoot(pi, SLINGBLADE); + fi.shoot(pact, SLINGBLADE); p->noise_radius = 1024; madenoise(snum); } @@ -3367,13 +3242,13 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->ammo_amount[DYNAMITE_WEAPON]--; lastvisinc = ud.levelclock + 32; p->visibility = 0; - fi.shoot(pi, RPG); + fi.shoot(pact, RPG); p->noise_radius = 32768; madenoise(snum); checkavailweapon(p); } else if (p->kickback_pic == 16) - S_PlayActorSound(450, pi); + S_PlayActorSound(450, pact); else if (p->kickback_pic == 34) p->okickback_pic = p->kickback_pic = 0; break; @@ -3385,13 +3260,13 @@ static void operateweapon(int snum, ESyncBits actions, int psect) p->ammo_amount[CHICKEN_WEAPON]--; lastvisinc = ud.levelclock + 32; p->visibility = 0; - fi.shoot(pi, RPG2); + fi.shoot(pact, RPG2); p->noise_radius = 32768; madenoise(snum); checkavailweapon(p); } else if (p->kickback_pic == 16) - S_PlayActorSound(450, pi); + S_PlayActorSound(450, pact); else if (p->kickback_pic == 34) p->okickback_pic = p->kickback_pic = 0; break; @@ -3409,8 +3284,8 @@ static void operateweapon(int snum, ESyncBits actions, int psect) static void processweapon(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; - int pi = p->i; - auto s = &sprite[pi]; + auto pact = p->GetActor(); + auto s = &pact->s; int shrunk = (s->yrepeat < 8); if (actions & SB_FIRE) @@ -3469,16 +3344,15 @@ static void processweapon(int snum, ESyncBits actions, int psect) void processinput_r(int snum) { - int j, i, k, doubvel, fz, cz, hz, lz, truefdist, var60; + int i, k, doubvel, fz, cz, truefdist; + Collision chz, clz; char shrunk; ESyncBits actions; - short psect, psectlotag, pi; - struct player_struct* p; - spritetype* s; + short psect, psectlotag; - p = &ps[snum]; - pi = p->i; - s = &sprite[pi]; + auto p = &ps[snum]; + auto pact = p->GetActor(); + auto s = &pact->s; p->horizon.resetadjustment(); p->angle.resetadjustment(); @@ -3503,7 +3377,7 @@ void processinput_r(int snum) if (s->extra > 0 && ud.clipping == 0) { quickkill(p); - S_PlayActorSound(SQUISHED, pi); + S_PlayActorSound(SQUISHED, pact); } psect = 0; } @@ -3512,11 +3386,11 @@ void processinput_r(int snum) if (psectlotag == 867) { - SectIterator it(psect); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(psect); + while (auto act2 = it.Next()) { - if (sprite[j].picnum == RRTILE380) - if (sprite[j].z - (8 << 8) < p->posz) + if (act2->s.picnum == RRTILE380) + if (act2->s.z - (8 << 8) < p->posz) psectlotag = 2; } } @@ -3535,26 +3409,27 @@ void processinput_r(int snum) p->spritebridge = 0; shrunk = (s->yrepeat < 8); + int tempfz; if (s->clipdist == 64) { - getzrange(p->posx, p->posy, p->posz, psect, &cz, &hz, &fz, &lz, 163L, CLIPMASK0); - j = getflorzofslope(psect, p->posx, p->posy); + getzrange_ex(p->posx, p->posy, p->posz, psect, &cz, chz, &fz, clz, 163L, CLIPMASK0); + tempfz = getflorzofslope(psect, p->posx, p->posy); } else { - getzrange(p->posx, p->posy, p->posz, psect, &cz, &hz, &fz, &lz, 4L, CLIPMASK0); - j = getflorzofslope(psect, p->posx, p->posy); + getzrange_ex(p->posx, p->posy, p->posz, psect, &cz, chz, &fz, clz, 4L, CLIPMASK0); + tempfz = getflorzofslope(psect, p->posx, p->posy); } - p->truefz = j; + p->truefz = tempfz; p->truecz = getceilzofslope(psect, p->posx, p->posy); - truefdist = abs(p->posz - j); - if ((lz & 49152) == 16384 && psectlotag == 1 && truefdist > PHEIGHT + (16 << 8)) + truefdist = abs(p->posz - tempfz); + if (clz.type == kHitSector && psectlotag == 1 && truefdist > PHEIGHT + (16 << 8)) psectlotag = 0; - hittype[pi].floorz = fz; - hittype[pi].ceilingz = cz; + pact->floorz = fz; + pact->ceilingz = cz; if (cl_syncinput) { @@ -3562,23 +3437,23 @@ void processinput_r(int snum) calcviewpitch(p, 1); } - if (hz >= 0 && (hz & 49152) == 49152) + if (chz.type == kHitSprite) { - hz &= (MAXSPRITES - 1); - - if (sprite[hz].statnum == 1 && sprite[hz].extra >= 0) + if (chz.actor->s.statnum == 1 && chz.actor->s.extra >= 0) { - hz = 0; + chz.type = kHitNone; + chz.actor = nullptr; cz = p->truecz; } - if (sprite[hz].picnum == RRTILE3587) + else if (chz.actor->s.picnum == RRTILE3587) { if (!p->stairs) { p->stairs = 10; if ((actions & SB_JUMP) && !p->OnMotorcycle) { - hz = 0; + chz.type = kHitNone; + chz.actor = nullptr; cz = p->truecz; } } @@ -3587,61 +3462,58 @@ void processinput_r(int snum) } } - if (lz >= 0 && (lz & 49152) == 49152) + if (clz.type == kHitSprite) { - j = lz & (MAXSPRITES - 1); - - if (isRRRA()) var60 = j & (MAXSPRITES - 1); - - if ((sprite[j].cstat & 33) == 33) + if ((clz.actor->s.cstat & 33) == 33) { psectlotag = 0; p->footprintcount = 0; p->spritebridge = 1; } if (p->OnMotorcycle) - if (badguy(&sprite[var60])) + if (badguy(clz.actor)) { - hittype[var60].picnum = MOTOHIT; - hittype[var60].extra = 2 + (p->MotoSpeed >> 1); - p->MotoSpeed -= p->MotoSpeed >> 4; + clz.actor->picnum = MOTOHIT; + clz.actor->extra = xs_CRoundToInt(2 + (p->MotoSpeed / 2.)); + p->MotoSpeed -= p->MotoSpeed / 16.; } if (p->OnBoat) { - if (badguy(&sprite[var60])) + if (badguy(clz.actor)) { - hittype[var60].picnum = MOTOHIT; - hittype[var60].extra = 2 + (p->MotoSpeed >> 1); - p->MotoSpeed -= p->MotoSpeed >> 4; + clz.actor->picnum = MOTOHIT; + clz.actor->extra = xs_CRoundToInt(2 + (p->MotoSpeed / 2.)); + p->MotoSpeed -= p->MotoSpeed / 16.; } } - else if (badguy(&sprite[j]) && sprite[j].xrepeat > 24 && abs(s->z - sprite[j].z) < (84 << 8)) + else if (badguy(clz.actor) && clz.actor->s.xrepeat > 24 && abs(s->z - clz.actor->s.z) < (84 << 8)) { - j = getangle(sprite[j].x - p->posx, sprite[j].y - p->posy); + int j = getangle(clz.actor->s.x - p->posx, clz.actor->s.y - p->posy); p->posxv -= sintable[(j + 512) & 2047] << 4; p->posyv -= sintable[j & 2047] << 4; } - if (sprite[j].picnum == RRTILE3587) + if (clz.actor->s.picnum == RRTILE3587) { if (!p->stairs) { p->stairs = 10; if ((actions & SB_CROUCH) && !p->OnMotorcycle) { - cz = sprite[j].z; - hz = 0; - fz = sprite[j].z + (4 << 8); + cz = clz.actor->s.z; + chz.type = kHitNone; + chz.actor = nullptr; + fz = clz.actor->s.z + (4 << 8); } } else p->stairs--; } - else if (sprite[j].picnum == TOILET || sprite[j].picnum == RRTILE2121) + else if (clz.actor->s.picnum == TOILET || clz.actor->s.picnum == RRTILE2121) { if ((actions & SB_CROUCH) && !p->OnMotorcycle) //if (Sound[436].num == 0) { - S_PlayActorSound(436, p->i); + S_PlayActorSound(436, pact); p->last_pissed_time = 4000; p->eat = 0; } @@ -3687,9 +3559,8 @@ void processinput_r(int snum) if (p->transporter_hold < 0) p->transporter_hold++; - if (p->newowner >= 0) + if (p->newOwner != nullptr) { - i = p->newowner; p->posxv = p->posyv = s->xvel = 0; fi.doincrements(p); @@ -3708,7 +3579,7 @@ void processinput_r(int snum) playerweaponsway(p, s); s->xvel = clamp(ksqrt((p->posx - p->bobposx) * (p->posx - p->bobposx) + (p->posy - p->bobposy) * (p->posy - p->bobposy)), 0, 512); - if (p->on_ground) p->bobcounter += sprite[p->i].xvel >> 1; + if (p->on_ground) p->bobcounter += p->GetActor()->s.xvel >> 1; backuppos(p, ud.clipping == 0 && (sector[p->cursectnum].floorpicnum == MIRROR || p->cursectnum < 0 || p->cursectnum >= MAXSECTORS)); @@ -3722,8 +3593,8 @@ void processinput_r(int snum) tmp = getanimationgoal(anim_floorz, p->cursectnum); if (tmp >= 0) { - if (!S_CheckSoundPlaying(p->i, 432)) - S_PlayActorSound(432, pi); + if (!S_CheckActorSoundPlaying(pact, 432)) + S_PlayActorSound(432, pact); } else S_StopSound(432); @@ -3764,13 +3635,13 @@ void processinput_r(int snum) // may still be needed later for demo recording processavel(p, &sb_avel); - applylook(&p->angle, sb_avel, &p->sync.actions, 1, p->crouch_toggle || actions & SB_CROUCH); + applylook(&p->angle, sb_avel, &p->sync.actions); apply_seasick(p, 1); } if (p->spritebridge == 0) { - j = sector[s->sectnum].floorpicnum; + int j = sector[s->sectnum].floorpicnum; k = 0; if (p->on_ground && truefdist <= PHEIGHT + (16 << 8)) @@ -3814,18 +3685,19 @@ void processinput_r(int snum) { if (p->spritebridge == 0 && p->walking_snd_toggle == 0 && p->on_ground) { + int j; switch (psectlotag) { case 0: - if (lz >= 0 && (lz & (MAXSPRITES - 1)) == 49152) - j = sprite[lz & (MAXSPRITES - 1)].picnum; + if (clz.type == kHitSprite) + j = clz.actor->s.picnum; else j = sector[psect].floorpicnum; break; case 1: if ((krand() & 1) == 0) if (!isRRRA() || (!p->OnBoat && !p->OnMotorcycle && sector[p->cursectnum].hitag != 321)) - S_PlayActorSound(DUKE_ONWATER, pi); + S_PlayActorSound(DUKE_ONWATER, pact); p->walking_snd_toggle = 1; break; } @@ -3922,47 +3794,47 @@ HORIZONLY: if (sector[p->cursectnum].lotag == 2) k = 0; else k = 1; + Collision clip{}; if (ud.clipping) { - j = 0; p->posx += p->posxv >> 14; p->posy += p->posyv >> 14; updatesector(p->posx, p->posy, &p->cursectnum); - changespritesect(pi, p->cursectnum); + changespritesect(pact, p->cursectnum); } else - j = clipmove(&p->posx, &p->posy, + clipmove_ex(&p->posx, &p->posy, &p->posz, &p->cursectnum, - p->posxv, p->posyv, 164L, (4L << 8), i, CLIPMASK0); + p->posxv, p->posyv, 164L, (4L << 8), i, CLIPMASK0, clip); if (p->jetpack_on == 0 && psectlotag != 2 && psectlotag != 1 && shrunk) p->posz += 32 << 8; - if (j) - fi.checkplayerhurt(p, j); + if (clip.type != kHitNone) + checkplayerhurt_r(p, clip); else if (isRRRA() && p->hurt_delay2 > 0) p->hurt_delay2--; - var60 = j & (MAXWALLS - 1); - var60 = wall[j & (MAXWALLS - 1)].lotag; - if ((j & 49152) == 32768) + if (clip.type == kHitWall) { + int var60 = wall[clip.index].lotag; + if (p->OnMotorcycle) { - onMotorcycleMove(snum, psect, j); + onMotorcycleMove(snum, psect, clip.index); } else if (p->OnBoat) { - onBoatMove(snum, psect, j); + onBoatMove(snum, psect, clip.index); } else { - if (wall[j & (MAXWALLS - 1)].lotag >= 40 && wall[j & (MAXWALLS - 1)].lotag <= 44) + if (wall[clip.index].lotag >= 40 && wall[clip.index].lotag <= 44) { - if (wall[j & (MAXWALLS - 1)].lotag < 44) + if (wall[clip.index].lotag < 44) { - dofurniture(j & (MAXWALLS - 1), p->cursectnum, snum); + dofurniture(clip.index, p->cursectnum, snum); pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 172L, (4L << 8), (4L << 8), CLIPMASK0); } else @@ -3971,45 +3843,49 @@ HORIZONLY: } } - if ((j & 49152) == 49152) + if (clip.type == kHitSprite) { - var60 = j & (MAXSPRITES - 1); if (p->OnMotorcycle) { - onMotorcycleHit(snum, var60); + onMotorcycleHit(snum, clip.actor); } else if (p->OnBoat) { - onBoatHit(snum, var60); + onBoatHit(snum, clip.actor); } - else - if (badguy(&sprite[var60])) + else if (badguy(clip.actor)) + { + if (clip.actor->s.statnum != 1) { - if (sprite[var60].statnum != 1) - { - hittype[var60].timetosleep = 0; - if (sprite[var60].picnum == BILLYRAY) - S_PlayActorSound(404, var60); - else - fi.check_fta_sounds(var60); - changespritestat(var60, 1); - } + clip.actor->timetosleep = 0; + if (clip.actor->s.picnum == BILLYRAY) + S_PlayActorSound(404, clip.actor); + else + check_fta_sounds_r(clip.actor); + changespritestat(clip.actor, 1); } - else - if (sprite[var60].picnum == RRTILE3410) - { - quickkill(p); - S_PlayActorSound(446, pi); - } - else if (isRRRA() && sprite[var60].picnum == RRTILE2443 && sprite[var60].pal == 19) - { - sprite[var60].pal = 0; - p->DrugMode = 5; - sprite[ps[snum].i].extra = max_player_health; - } + } + else if (!isRRRA() && clip.actor->s.picnum == RRTILE3410) + { + quickkill(p); + S_PlayActorSound(446, pact); + } + if (isRRRA()) + { + if (clip.actor->s.picnum == RRTILE3410) + { + quickkill(p); + S_PlayActorSound(446, pact); + } + else if (clip.actor->s.picnum == RRTILE2443 && clip.actor->s.pal == 19) + { + clip.actor->s.pal = 0; + p->DrugMode = 5; + ps[snum].GetActor()->s.extra = max_player_health; + } + } } - if (p->jetpack_on == 0) { if (s->xvel > 16) @@ -4027,7 +3903,7 @@ HORIZONLY: } // RBG*** - setsprite(pi, p->posx, p->posy, p->posz + PHEIGHT); + setsprite(pact, p->posx, p->posy, p->posz + PHEIGHT); if (psectlotag == 800 && (!isRRRA() || !p->lotag800kill)) { @@ -4039,9 +3915,10 @@ HORIZONLY: if (psectlotag < 3) { psect = s->sectnum; - if (ud.clipping == 0 && sector[psect].lotag == 31) + if (ud.clipping == 0 && sector[psect].lotag == ST_31_TWO_WAY_TRAIN) { - if (sprite[sector[psect].hitag].xvel && hittype[sector[psect].hitag].temp_data[0] == 0) + auto act = ScriptIndexToActor(sector[psect].hitag); + if (act && act->s.xvel && act->temp_data[0] == 0) { quickkill(p); return; @@ -4050,29 +3927,30 @@ HORIZONLY: } if (truefdist < PHEIGHT && p->on_ground && psectlotag != 1 && shrunk == 0 && sector[p->cursectnum].lotag == 1) - if (!S_CheckActorSoundPlaying(pi, DUKE_ONWATER)) + if (!S_CheckActorSoundPlaying(pact, DUKE_ONWATER)) if (!isRRRA() || (!p->OnBoat && !p->OnMotorcycle && sector[p->cursectnum].hitag != 321)) - S_PlayActorSound(DUKE_ONWATER, pi); + S_PlayActorSound(DUKE_ONWATER, pact); if (p->cursectnum != s->sectnum) - changespritesect(pi, p->cursectnum); + changespritesect(pact, p->cursectnum); + int j; if (ud.clipping == 0) { if (s->clipdist == 64) - j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(pi, 8) < 512); + j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512); else - j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 16L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(pi, 8) < 512); + j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 16L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512); } else j = 0; if (ud.clipping == 0) { - if (abs(hittype[pi].floorz - hittype[pi].ceilingz) < (48 << 8) || j) + if (abs(pact->floorz - pact->ceilingz) < (48 << 8) || j) { if (!(sector[s->sectnum].lotag & 0x8000) && (isanunderoperator(sector[s->sectnum].lotag) || isanearoperator(sector[s->sectnum].lotag))) - fi.activatebysector(s->sectnum, pi); + fi.activatebysector(s->sectnum, pact); if (j) { quickkill(p); @@ -4080,7 +3958,7 @@ HORIZONLY: } } else if (abs(fz - cz) < (32 << 8) && isanunderoperator(sector[psect].lotag)) - fi.activatebysector(psect, pi); + fi.activatebysector(psect, pact); } if (ud.clipping == 0 && sector[p->cursectnum].ceilingz > (sector[p->cursectnum].floorz - (12 << 8))) @@ -4120,7 +3998,7 @@ HORIZONLY: if (cl_syncinput) { - sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions, 1); + sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); } checkhardlanding(p); @@ -4135,7 +4013,7 @@ HORIZONLY: fi.addweapon(p, p->last_full_weapon); return; } - dokneeattack(snum, pi, { FEM10, NAKED1, STATUE }); + dokneeattack(snum, { FEM10, NAKED1, STATUE }); if (fi.doincrements(p)) return; @@ -4185,16 +4063,16 @@ void processmove_r(int snum, ESyncBits actions, int psect, int fz, int cz, int s // //--------------------------------------------------------------------------- -void OnMotorcycle(struct player_struct *p, int motosprite) +void OnMotorcycle(struct player_struct *p, DDukeActor* motosprite) { if (!p->OnMotorcycle && !(sector[p->cursectnum].lotag == 2)) { if (motosprite) { - p->posx = sprite[motosprite].x; - p->posy = sprite[motosprite].y; - p->angle.ang = buildang(sprite[motosprite].ang); - p->ammo_amount[MOTORCYCLE_WEAPON] = sprite[motosprite].owner; + p->posx = motosprite->s.x; + p->posy = motosprite->s.y; + p->angle.ang = buildang(motosprite->s.ang); + p->ammo_amount[MOTORCYCLE_WEAPON] = motosprite->saved_ammo; deletesprite(motosprite); } p->over_shoulder_on = 0; @@ -4206,8 +4084,8 @@ void OnMotorcycle(struct player_struct *p, int motosprite) p->posyv = 0; p->horizon.horiz = q16horiz(0); } - if (!S_CheckActorSoundPlaying(p->i,186)) - S_PlayActorSound(186, p->i); + if (!S_CheckActorSoundPlaying(p->GetActor(),186)) + S_PlayActorSound(186, p->GetActor()); } //--------------------------------------------------------------------------- @@ -4218,19 +4096,19 @@ void OnMotorcycle(struct player_struct *p, int motosprite) void OffMotorcycle(struct player_struct *p) { - short j; + auto pact = p->GetActor(); if (p->OnMotorcycle) { - if (S_CheckActorSoundPlaying(p->i,188)) - S_StopSound(188,p->i); - if (S_CheckActorSoundPlaying(p->i,187)) - S_StopSound(187,p->i); - if (S_CheckActorSoundPlaying(p->i,186)) - S_StopSound(186,p->i); - if (S_CheckActorSoundPlaying(p->i,214)) - S_StopSound(214,p->i); - if (!S_CheckActorSoundPlaying(p->i,42)) - S_PlayActorSound(42, p->i); + if (S_CheckActorSoundPlaying(pact,188)) + S_StopSound(188,pact); + if (S_CheckActorSoundPlaying(pact,187)) + S_StopSound(187,pact); + if (S_CheckActorSoundPlaying(pact,186)) + S_StopSound(186,pact); + if (S_CheckActorSoundPlaying(pact,214)) + S_StopSound(214,pact); + if (!S_CheckActorSoundPlaying(pact,42)) + S_PlayActorSound(42, pact); p->OnMotorcycle = 0; p->gotweapon.Clear(MOTORCYCLE_WEAPON); p->curr_weapon = p->last_full_weapon; @@ -4248,11 +4126,11 @@ void OffMotorcycle(struct player_struct *p) p->posxv -= sintable[(p->angle.ang.asbuild()+512)&2047]<<7; p->posyv -= sintable[p->angle.ang.asbuild()&2047]<<7; p->moto_underwater = 0; - j = fi.spawn(p->i, EMPTYBIKE); - sprite[j].ang = p->angle.ang.asbuild(); - sprite[j].xvel += sintable[(p->angle.ang.asbuild()+512)&2047]<<7; - sprite[j].yvel += sintable[p->angle.ang.asbuild()&2047]<<7; - sprite[j].owner = p->ammo_amount[MOTORCYCLE_WEAPON]; + auto spawned = spawn(p->GetActor(), EMPTYBIKE); + spawned->s.ang = p->angle.ang.asbuild(); + spawned->s.xvel += sintable[(p->angle.ang.asbuild()+512)&2047]<<7; + spawned->s.yvel += sintable[p->angle.ang.asbuild()&2047]<<7; + spawned->saved_ammo = p->ammo_amount[MOTORCYCLE_WEAPON]; } } @@ -4262,17 +4140,17 @@ void OffMotorcycle(struct player_struct *p) // //--------------------------------------------------------------------------- -void OnBoat(struct player_struct *p, int boatsprite) +void OnBoat(struct player_struct *p, DDukeActor* boat) { if (!p->OnBoat) { - if (boatsprite) + if (boat) { - p->posx = sprite[boatsprite].x; - p->posy = sprite[boatsprite].y; - p->angle.ang = buildang(sprite[boatsprite].ang); - p->ammo_amount[BOAT_WEAPON] = sprite[boatsprite].owner; - deletesprite(boatsprite); + p->posx = boat->s.x; + p->posy = boat->s.y; + p->angle.ang = buildang(boat->s.ang); + p->ammo_amount[BOAT_WEAPON] = boat->saved_ammo; + deletesprite(boat); } p->over_shoulder_on = 0; p->OnBoat = 1; @@ -4293,7 +4171,6 @@ void OnBoat(struct player_struct *p, int boatsprite) void OffBoat(struct player_struct *p) { - short j; if (p->OnBoat) { p->OnBoat = 0; @@ -4313,11 +4190,11 @@ void OffBoat(struct player_struct *p) p->posxv -= sintable[(p->angle.ang.asbuild()+512)&2047]<<7; p->posyv -= sintable[p->angle.ang.asbuild()&2047]<<7; p->moto_underwater = 0; - j = fi.spawn(p->i, EMPTYBOAT); - sprite[j].ang = p->angle.ang.asbuild(); - sprite[j].xvel += sintable[(p->angle.ang.asbuild()+512)&2047]<<7; - sprite[j].yvel += sintable[p->angle.ang.asbuild()&2047]<<7; - sprite[j].owner = p->ammo_amount[BOAT_WEAPON]; + auto spawned = spawn(p->GetActor(), EMPTYBOAT); + spawned->s.ang = p->angle.ang.asbuild(); + spawned->s.xvel += sintable[(p->angle.ang.asbuild()+512)&2047]<<7; + spawned->s.yvel += sintable[p->angle.ang.asbuild()&2047]<<7; + spawned->saved_ammo = p->ammo_amount[BOAT_WEAPON]; } } diff --git a/source/games/duke/src/player_w.cpp b/source/games/duke/src/player_w.cpp index cb170a77c..78f7f3c37 100644 --- a/source/games/duke/src/player_w.cpp +++ b/source/games/duke/src/player_w.cpp @@ -49,52 +49,52 @@ int operateTripbomb(int snum); // //--------------------------------------------------------------------------- -void DoFire(struct player_struct *p, short snum) +void DoFire(struct player_struct* p, short 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->i); + S_PlayActorSound(aplWeaponFireSound[p->curr_weapon][snum], p->GetActor()); } - - SetGameVarID(g_iWeaponVarID,p->curr_weapon,p->i,snum); - SetGameVarID(g_iWorksLikeVarID,aplWeaponWorksLike[p->curr_weapon][snum], p->i, snum); - fi.shoot(p->i,aplWeaponShoots[p->curr_weapon][snum]); - for(i=1;icurr_weapon][snum];i++) + + 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++) { - fi.shoot(p->i,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 = ud.levelclock+32; + lastvisinc = ud.levelclock + 32; p->visibility = 0; } - - 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) - ) + + 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) + ) { // 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,27 +108,26 @@ void DoFire(struct player_struct *p, short snum) void DoSpawn(struct player_struct *p, short snum) { - int j; if(!aplWeaponSpawn[p->curr_weapon][snum]) return; - j = fi.spawn(p->i, aplWeaponSpawn[p->curr_weapon][snum]); + auto j = spawn(p->GetActor(), aplWeaponSpawn[p->curr_weapon][snum]); if((aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_SPAWNTYPE2 ) ) { // like shotgun shells - sprite[j].ang += 1024; + j->s.ang += 1024; ssp(j,CLIPMASK0); - sprite[j].ang += 1024; + j->s.ang += 1024; // p->kickback_pic++; } else if((aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_SPAWNTYPE3 ) ) { // like chaingun shells - sprite[j].ang += 1024; - sprite[j].ang &= 2047; - sprite[j].xvel += 32; - sprite[j].z += (3<<8); + j->s.ang += 1024; + j->s.ang &= 2047; + j->s.xvel += 32; + j->s.z += (3<<8); ssp(j,CLIPMASK0); } @@ -143,7 +142,7 @@ void DoSpawn(struct player_struct *p, short snum) void fireweapon_ww(int snum) { auto p = &ps[snum]; - int pi = p->i; + auto pact = p->GetActor(); p->crack_time = CRACK_TIME; @@ -158,11 +157,11 @@ void fireweapon_ww(int snum) } else { - SetGameVarID(g_iReturnVarID, 0, pi, snum); - SetGameVarID(g_iWeaponVarID, p->curr_weapon, pi, snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], pi, snum); - OnEvent(EVENT_FIRE, pi, snum, -1); - if (GetGameVarID(g_iReturnVarID, pi, snum) == 0) + 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); + OnEvent(EVENT_FIRE, snum, p->GetActor(), -1); + if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum) == 0) { switch (aplWeaponWorksLike[p->curr_weapon][snum]) { @@ -173,7 +172,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -182,7 +181,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } break; @@ -193,7 +192,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -205,7 +204,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -216,7 +215,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -226,7 +225,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -237,7 +236,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -248,7 +247,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -259,7 +258,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -270,7 +269,7 @@ void fireweapon_ww(int snum) p->hbomb_hold_delay = !p->hbomb_hold_delay; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -281,7 +280,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -292,7 +291,7 @@ void fireweapon_ww(int snum) p->kickback_pic = 1; if (aplWeaponInitialSound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponInitialSound[p->curr_weapon][snum], pact); } } break; @@ -310,8 +309,8 @@ void fireweapon_ww(int snum) void operateweapon_ww(int snum, ESyncBits actions, int psect) { auto p = &ps[snum]; - int pi = p->i; - int i, j, k; + auto pact = p->GetActor(); + int i, k; int psectlotag = sector[psect].lotag; // already firing... @@ -342,33 +341,33 @@ void operateweapon_ww(int snum, ESyncBits actions, int psect) i = -512 - mulscale16(p->horizon.sum().asq16(), 20); } - j = EGS(p->cursectnum, + auto j = EGS(p->cursectnum, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 6), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 6), p->posz, HEAVYHBOMB, -16, 9, 9, - p->angle.ang.asbuild(), (k + (p->hbomb_hold_delay << 5)), i, pi, 1); + p->angle.ang.asbuild(), (k + (p->hbomb_hold_delay << 5)), i, p->GetActor(), 1); { - int lGrenadeLifetime = GetGameVar("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, -1, snum); - int lGrenadeLifetimeVar = GetGameVar("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, -1, snum); + int lGrenadeLifetime = GetGameVar("GRENADE_LIFETIME", NAM_GRENADE_LIFETIME, nullptr, snum); + int lGrenadeLifetimeVar = GetGameVar("GRENADE_LIFETIME_VAR", NAM_GRENADE_LIFETIME_VAR, nullptr, snum); // set timer. blows up when at zero.... - sprite[j].extra = lGrenadeLifetime + j->s.extra = lGrenadeLifetime + mulscale(krand(), lGrenadeLifetimeVar, 14) - lGrenadeLifetimeVar; } if (k == 15) { - sprite[j].yvel = 3; - sprite[j].z += (8 << 8); + j->s.yvel = 3; + j->s.z += (8 << 8); } - k = hits(pi); + k = hits(p->GetActor()); if (k < 512) { - sprite[j].ang += 1024; - sprite[j].zvel /= 3; - sprite[j].xvel /= 3; + j->s.ang += 1024; + j->s.zvel /= 3; + j->s.xvel /= 3; } p->hbomb_on = 1; @@ -404,9 +403,9 @@ void operateweapon_ww(int snum, ESyncBits actions, int psect) lastvisinc = ud.levelclock + 32; p->visibility = 0; } - SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->i, snum); - SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike[p->curr_weapon][snum], p->i, snum); - fi.shoot(pi, aplWeaponShoots[p->curr_weapon][snum]); + 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]); } } @@ -444,7 +443,7 @@ void operateweapon_ww(int snum, ESyncBits actions, int psect) { if (aplWeaponSound2Sound[p->curr_weapon][snum]) { - S_PlayActorSound(aplWeaponSound2Sound[p->curr_weapon][snum], pi); + S_PlayActorSound(aplWeaponSound2Sound[p->curr_weapon][snum], pact); } } if (p->kickback_pic == aplWeaponSpawnTime[p->curr_weapon][snum]) @@ -501,12 +500,12 @@ void operateweapon_ww(int snum, ESyncBits actions, int psect) if (p->kickback_pic == (aplWeaponTotalTime[p->curr_weapon][snum] + 1)) { // eject shortly after 'total time' - S_PlayActorSound(EJECT_CLIP, pi); + S_PlayActorSound(EJECT_CLIP, pact); } 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, pi); + S_PlayActorSound(INSERT_CLIP, pact); } if (p->kickback_pic >= (aplWeaponReload[p->curr_weapon][snum])) diff --git a/source/games/duke/src/prediction.cpp b/source/games/duke/src/prediction.cpp index 7829a1da9..97dc9cb29 100644 --- a/source/games/duke/src/prediction.cpp +++ b/source/games/duke/src/prediction.cpp @@ -102,7 +102,8 @@ void fakedomovethings(void) { input *syn; struct player_struct *p; - int i, j, k, doubvel, fz, cz, hz, lz, x, y; + int i, j, k, doubvel, fz, cz, x, y; + Collision clz, chz; short psect, psectlotag, tempsect, backcstat; uint8_t shrunk, spritebridge; ESyncBits actions; @@ -111,8 +112,8 @@ void fakedomovethings(void) p = &ps[myconnectindex]; - backcstat = sprite[p->i].cstat; - sprite[p->i].cstat &= ~257; + backcstat = p->GetActor()->s.cstat; + p->GetActor()->s.cstat &= ~257; actions = syn->actions; @@ -120,7 +121,7 @@ void fakedomovethings(void) psectlotag = sector[psect].lotag; spritebridge = 0; - shrunk = (sprite[p->i].yrepeat < (isRR()? 8 : 32)); + shrunk = (p->GetActor()->s.yrepeat < (isRR()? 8 : 32)); if( ud.clipping == 0 && ( sector[psect].floorpicnum == MIRROR || psect < 0 || psect >= MAXSECTORS) ) { @@ -138,11 +139,11 @@ void fakedomovethings(void) omyz = myz; omyang = myang; - getzrange(myx,myy,myz,psect,&cz,&hz,&fz,&lz,163L,CLIPMASK0); + getzrange(myx,myy,myz,psect,&cz,chz,&fz,clz,163L,CLIPMASK0); j = getflorzofslope(psect,myx,myy); - if( (lz&49152) == 16384 && psectlotag == 1 && klabs(myz-j) > PHEIGHT+(16<<8) ) + if(clz.type == kHitSector && psectlotag == 1 && klabs(myz-j) > PHEIGHT+(16<<8) ) psectlotag = 0; if( p->aim_mode == 0 && myonground && psectlotag != 2 && (sector[psect].floorstat&2) ) @@ -163,33 +164,31 @@ void fakedomovethings(void) if (myhorizoff > 0) myhorizoff -= ((myhorizoff>>3)+1); else if (myhorizoff < 0) myhorizoff += (((-myhorizoff)>>3)+1); - if(hz >= 0 && (hz&49152) == 49152) + if(chz.type == kHitSprite) { - hz &= (MAXSPRITES-1); - if (sprite[hz].statnum == 1 && sprite[hz].extra >= 0) + if (chz.actor->s.statnum == 1 && chz.actor->s.extra >= 0) { - hz = 0; + chz.type = kHitNone; cz = getceilzofslope(psect,myx,myy); } } - if(lz >= 0 && (lz&49152) == 49152) + if (clz.type == kHitSprite) { - j = lz&(MAXSPRITES-1); - if ((sprite[j].cstat&33) == 33) + if ((clz.actor->s.cstat&33) == 33) { psectlotag = 0; spritebridge = 1; } - if(badguy(&sprite[j]) && sprite[j].xrepeat > 24 && klabs(sprite[p->i].z-sprite[j].z) < (84<<8) ) + if(badguy(chz.actor) && chz.actor->s.xrepeat > 24 && klabs(p->GetActor()->s.z- chz.actor->s.z) < (84<<8) ) { - j = getangle( sprite[j].x-myx,sprite[j].y-myy); + j = getangle(chz.actor->s.x-myx, chz.actor->s.y-myy); myxvel -= sintable[(j+512)&2047]<<4; myyvel -= sintable[j&2047]<<4; } } - if( sprite[p->i].extra <= 0 ) + if( p->GetActor()->s.extra <= 0 ) { if( psectlotag == 2 ) { @@ -525,7 +524,7 @@ ENDFAKEPROCESSINPUT: myhorizbak[fakemovefifoplc&(MOVEFIFOSIZ-1)] = myhoriz; fakemovefifoplc++; - sprite[p->i].cstat = backcstat; + p->GetActor()->s.cstat = backcstat; } #endif diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 98f6b3530..934283b46 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -101,7 +101,7 @@ void resetplayerstats(int snum) // p->select_dir = 0; p->extra_extra8 = 0; p->show_empty_weapon= 0; - p->dummyplayersprite=-1; + p->dummyplayersprite=nullptr; p->crack_time = 0; p->hbomb_hold_delay = 0; p->transporter_hold = 0; @@ -121,14 +121,13 @@ void resetplayerstats(int snum) p->airleft = 15*26; p->rapid_fire_hold = 0; p->toggle_key_flag = 0; - p->access_spritenum = -1; + p->access_spritenum = nullptr; if(ud.multimode > 1 && ud.coop != 1 ) p->got_access = 7; else p->got_access = 0; p->random_club_frame= 0; p->on_warping_sector = 0; p->spritebridge = 0; - p->palette = 0; if(p->steroids_amount < 400 ) { @@ -142,7 +141,7 @@ void resetplayerstats(int snum) p->angle.olook_ang = p->angle.look_ang = buildlook(512 - ((currentLevel->levelNumber & 1) << 10)); p->angle.orotscrnang = p->angle.rotscrnang = buildlook(0); - p->newowner =-1; + p->newOwner =nullptr; p->jumping_counter = 0; p->hard_landing = 0; p->posxv = 0; //!! @@ -166,7 +165,6 @@ void resetplayerstats(int snum) p->knuckle_incs = 1; p->fist_incs = 0; p->knee_incs = 0; - setpal(p); p->stairs = 0; p->noise_x = 0; p->noise_y = 0; @@ -297,7 +295,7 @@ void resetweapons(int snum) p->gotweapon.Set(SLINGBLADE_WEAPON); p->ammo_amount[SLINGBLADE_WEAPON] = 1; } - OnEvent(EVENT_RESETWEAPONS, -1, snum, -1); + OnEvent(EVENT_RESETWEAPONS, snum, nullptr, -1); } //--------------------------------------------------------------------------- @@ -370,7 +368,7 @@ void resetinventory(int snum) ufocnt = 0; hulkspawn = 2; } - OnEvent(EVENT_RESETINVENTORY, snum, p->i); + OnEvent(EVENT_RESETINVENTORY, snum, p->GetActor()); } @@ -416,9 +414,9 @@ void resetprestat(int snum,int g) parallaxtype = 0; randomseed = 17L; paused = 0; - ud.camerasprite =-1; + ud.cameraactor =nullptr; tempwallptr = 0; - camsprite =-1; + camsprite =nullptr; earthquaketime = 0; WindTime = 0; @@ -426,7 +424,7 @@ void resetprestat(int snum,int g) fakebubba_spawn = 0; RRRA_ExitedLevel = 0; BellTime = 0; - BellSprite = 0; + BellSprite = nullptr; numinterpolations = 0; //startofdynamicinterpolations = 0; @@ -572,10 +570,10 @@ void resetpspritevars(int g) which_palookup = 9; j = connecthead; - StatIterator it(STAT_PLAYER); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_PLAYER); + while (auto act = it.Next()) { - s = &sprite[i]; + s = &act->s; if (numplayersprites == MAXPLAYERS) I_Error("Too many player sprites (max 16.)"); @@ -595,7 +593,7 @@ void resetpspritevars(int g) numplayersprites++; if (j >= 0) { - s->owner = i; + act->SetOwner(act); s->shade = 0; s->xrepeat = isRR() ? 24 : 42; s->yrepeat = isRR() ? 17 : 36; @@ -626,13 +624,13 @@ void resetpspritevars(int g) else s->pal = ps[j].palookup = ud.user_pals[j]; - ps[j].i = i; + ps[j].i = act->GetIndex(); ps[j].frag_ps = j; - hittype[i].owner = i; + act->SetOwner(act); - hittype[i].bposx = ps[j].bobposx = ps[j].oposx = ps[j].posx = s->x; - hittype[i].bposy = ps[j].bobposy = ps[j].oposy = ps[j].posy = s->y; - hittype[i].bposz = ps[j].oposz = ps[j].posz = s->z; + act->bposx = ps[j].bobposx = ps[j].oposx = ps[j].posx = s->x; + act->bposy = ps[j].bobposy = ps[j].oposy = ps[j].posy = s->y; + act->bposz = ps[j].oposz = ps[j].posz = s->z; ps[j].angle.oang = ps[j].angle.ang = buildang(s->ang); updatesector(s->x, s->y, &ps[j].cursectnum); @@ -640,7 +638,7 @@ void resetpspritevars(int g) j = connectpoint2[j]; } - else deletesprite(i); + else deletesprite(act); } } @@ -677,7 +675,7 @@ void prelevel_common(int g) RRRA_ExitedLevel = 0; mamaspawn_count = 15; BellTime = 0; - BellSprite = 0; + BellSprite = nullptr; // RRRA E2L1 fog handling. fogactive = 0; @@ -742,8 +740,8 @@ void resettimevars(void) { cloudclock = 0; ud.levelclock = 0; - if (camsprite >= 0) - hittype[camsprite].temp_data[0] = 0; + if (camsprite != nullptr) + camsprite->temp_data[0] = 0; } //--------------------------------------------------------------------------- @@ -950,7 +948,7 @@ void enterlevel(MapRecord *mi, int gamemode) for (int i = connecthead; i >= 0; i = connectpoint2[i]) { - int pn = sector[sprite[ps[i].i].sectnum].floorpicnum; + int pn = sector[ps[i].GetActor()->s.sectnum].floorpicnum; if (pn == TILE_HURTRAIL || pn == TILE_FLOORSLIME || pn == TILE_FLOORPLASMA) { resetweapons(i); @@ -962,7 +960,6 @@ void enterlevel(MapRecord *mi, int gamemode) } } resetmys(); - setpal(&ps[myconnectindex]); everyothertime = 0; global_random = 0; @@ -1063,7 +1060,6 @@ void exitlevel(MapRecord *nextlevel) { bool endofgame = nextlevel == nullptr; STAT_Update(endofgame); - setpal(&ps[myconnectindex]); StopCommentary(); dobonus(endofgame? -1 : 0, [=](bool) diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index 305996333..e07263069 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -52,17 +52,17 @@ inline void tloadtile(int tilenum, int palnum = 0) // //--------------------------------------------------------------------------- -static void cachespritenum(int i) +static void cachespritenum(spritetype *spr) { int maxc; int j; - int pal = sprite[i].pal; + int pal = spr->pal; - if(ud.monsters_off && badguy(&sprite[i])) return; + if(ud.monsters_off && badguy(spr)) return; maxc = 1; - switch(sprite[i].picnum) + switch(spr->picnum) { case HYDRENT: tloadtile(BROKEFIREHYDRENT); @@ -164,7 +164,7 @@ static void cachespritenum(int i) break; } - for(j = sprite[i].picnum; j < (sprite[i].picnum+maxc); j++) + for(j = spr->picnum; j < (spr->picnum+maxc); j++) tloadtile(j, pal); } @@ -231,7 +231,7 @@ static void cachegoodsprites(void) void cacheit_d(void) { - int i, j; + int i; cachegoodsprites(); @@ -251,13 +251,13 @@ void cacheit_d(void) tloadtile(LA + 1); tloadtile(LA + 2); } - } - SectIterator it(i); - while ((j = it.NextIndex()) >= 0) - { - if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat & 32768) == 0) - cachespritenum(j); + DukeSectIterator it(i); + while (auto j = it.Next()) + { + if (j->s.xrepeat != 0 && j->s.yrepeat != 0 && (j->s.cstat & 32768) == 0) + cachespritenum(&j->s); + } } precacheMarkedTiles(); @@ -276,11 +276,11 @@ void prelevel_d(int g) prelevel_common(g); - StatIterator it(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DEFAULT); + while (auto ac = it.Next()) { - auto si = &sprite[i]; - LoadActor(i, -1, -1); + auto si = &ac->s; + LoadActor(ac, -1, -1); if (si->lotag == -1 && (si->cstat & 16)) { @@ -291,7 +291,7 @@ void prelevel_d(int g) { case GPSPEED: sector[si->sectnum].extra = si->lotag; - deletesprite(i); + deletesprite(ac); break; case CYCLER: @@ -304,34 +304,39 @@ void prelevel_d(int g) cyclers[numcyclers][4] = si->hitag; cyclers[numcyclers][5] = (si->ang == 1536); numcyclers++; - deletesprite(i); + deletesprite(ac); break; } } + + for (i = 0; i < MAXSPRITES; i++) + { + auto spr = &sprite[i]; + if (spr->statnum < MAXSTATUS) + { + if (spr->picnum == SECTOREFFECTOR && spr->lotag == SE_14_SUBWAY_CAR) + continue; + spawn(nullptr, i); + } + } + for (i = 0; i < MAXSPRITES; i++) { - if (sprite[i].statnum < MAXSTATUS) + auto spr = &sprite[i]; + if (spr->statnum < MAXSTATUS) { - if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == SE_14_SUBWAY_CAR) - continue; - fi.spawn(-1, i); + if (spr->picnum == SECTOREFFECTOR && spr->lotag == SE_14_SUBWAY_CAR) + spawn(nullptr, i); } } - - for (i = 0; i < MAXSPRITES; i++) - if (sprite[i].statnum < MAXSTATUS) - { - if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == SE_14_SUBWAY_CAR) - fi.spawn(-1, i); - } - lotaglist = 0; it.Reset(STAT_DEFAULT); while ((i = it.NextIndex()) >= 0) { - switch (sprite[i].picnum) + auto spr = &sprite[i]; + switch (spr->picnum) { case DIPSWITCH + 1: case DIPSWITCH2 + 1: @@ -347,21 +352,21 @@ void prelevel_d(int g) case LOCKSWITCH1 + 1: case POWERSWITCH2 + 1: for (j = 0; j < lotaglist; j++) - if (sprite[i].lotag == lotags[j]) + if (spr->lotag == lotags[j]) break; if (j == lotaglist) { - lotags[lotaglist] = sprite[i].lotag; + lotags[lotaglist] = spr->lotag; lotaglist++; if (lotaglist > 64) I_Error("Too many switches (64 max)."); - StatIterator it1(STAT_EFFECTOR); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(STAT_EFFECTOR); + while (auto ac = it1.Next()) { - if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag) - hittype[j].temp_data[0] = 1; + if (ac->s.lotag == 12 && ac->s.hitag == spr->lotag) + ac->temp_data[0] = 1; } } break; diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index a47fb42d9..196d6d052 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -51,17 +51,17 @@ static inline void tloadtile(int tilenum, int palnum = 0) // //--------------------------------------------------------------------------- -static void cachespritenum(short i) +static void cachespritenum(spritetype *spr) { char maxc; short j; - int pal = sprite[i].pal; + int pal = spr->pal; - if (ud.monsters_off && badguy(&sprite[i])) return; + if (ud.monsters_off && badguy(spr)) return; maxc = 1; - switch (sprite[i].picnum) + switch (spr->picnum) { case HYDRENT: tloadtile(BROKEFIREHYDRENT); @@ -70,7 +70,7 @@ static void cachespritenum(short i) break; case RRTILE2121: case RRTILE2122: - tloadtile(sprite[i].picnum, pal); + tloadtile(spr->picnum, pal); break; case TOILET: tloadtile(TOILETBROKE); @@ -126,7 +126,7 @@ static void cachespritenum(short i) break; case COW: maxc = 56; - for (j = sprite[i].picnum; j < (sprite[i].picnum + maxc); j++) + for (j = spr->picnum; j < (spr->picnum + maxc); j++) tloadtile(j, pal); maxc = 0; break; @@ -278,7 +278,7 @@ static void cachespritenum(short i) break; case VIXEN: maxc = 214; - for (j = sprite[i].picnum; j < sprite[i].picnum + maxc; j++) + for (j = spr->picnum; j < spr->picnum + maxc; j++) tloadtile(j, pal); maxc = 0; break; @@ -287,7 +287,7 @@ static void cachespritenum(short i) { maxc = 54; - for (j = sprite[i].picnum; j < sprite[i].picnum + maxc; j++) + for (j = spr->picnum; j < spr->picnum + maxc; j++) tloadtile(j, pal); maxc = 100; for (j = SBMOVE; j < SBMOVE + maxc; j++) @@ -297,7 +297,7 @@ static void cachespritenum(short i) break; case HULK: maxc = 40; - for (j = sprite[i].picnum - 41; j < sprite[i].picnum + maxc - 41; j++) + for (j = spr->picnum - 41; j < spr->picnum + maxc - 41; j++) tloadtile(j, pal); for (j = HULKJIBA; j <= HULKJIBC + 4; j++) tloadtile(j, pal); @@ -305,7 +305,7 @@ static void cachespritenum(short i) break; case MINION: maxc = 141; - for (j = sprite[i].picnum; j < sprite[i].picnum + maxc; j++) + for (j = spr->picnum; j < spr->picnum + maxc; j++) tloadtile(j, pal); for (j = MINJIBA; j <= MINJIBC + 4; j++) tloadtile(j, pal); @@ -315,7 +315,7 @@ static void cachespritenum(short i) } - for (j = sprite[i].picnum; j < (sprite[i].picnum + maxc); j++) + for (j = spr->picnum; j < (spr->picnum + maxc); j++) tloadtile(j, pal); } @@ -406,7 +406,7 @@ static void cachegoodsprites(void) void cacheit_r(void) { - short i,j; + int i; cachegoodsprites(); @@ -426,13 +426,13 @@ void cacheit_r(void) tloadtile(LA + 1); tloadtile(LA + 2); } - } - SectIterator it(i); - while ((j = it.NextIndex()) >= 0) - { - if(sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0) - cachespritenum(j); + DukeSectIterator it(i); + while (auto j = it.Next()) + { + if(j->s.xrepeat != 0 && j->s.yrepeat != 0 && (j->s.cstat&32768) == 0) + cachespritenum(&j->s); + } } precacheMarkedTiles(); } @@ -451,7 +451,6 @@ void prelevel_r(int g) short startwall; short endwall; short lotaglist; - short k; short lotags[65]; int speed; int dist; @@ -469,18 +468,19 @@ void prelevel_r(int g) for (j = 0; j < MAXSPRITES; j++) { - if (sprite[j].pal == 100) + auto spr = &sprite[j]; + if (spr->pal == 100) { if (numplayers > 1) deletesprite(j); else - sprite[j].pal = 0; + spr->pal = 0; } - else if (sprite[j].pal == 101) + else if (spr->pal == 101) { - sprite[j].extra = 0; - sprite[j].hitag = 1; - sprite[j].pal = 0; + spr->extra = 0; + spr->hitag = 1; + spr->pal = 0; changespritestat(j, 118); } } @@ -495,19 +495,20 @@ void prelevel_r(int g) { case 41: { - SectIterator it(i); - while ((k = it.NextIndex()) >= 0) + DukeSectIterator it(i); + while (auto act = it.Next()) { - if (sprite[k].picnum == RRTILE11) + auto spr = &act->s; + if (spr->picnum == RRTILE11) { - dist = sprite[k].lotag << 4; - speed = sprite[k].hitag; - deletesprite(k); + dist = spr->lotag << 4; + speed = spr->hitag; + deletesprite(act); } - if (sprite[k].picnum == RRTILE38) + if (spr->picnum == RRTILE38) { - sound = sprite[k].lotag; - deletesprite(k); + sound = spr->lotag; + deletesprite(act); } } for (j = 0; j < numsectors; j++) @@ -525,29 +526,30 @@ void prelevel_r(int g) { short ii; int childsectnum = -1; - SectIterator it(i); - while ((k = it.NextIndex()) >= 0) + DukeSectIterator it(i); + while (auto act = it.Next()) { - auto sj = &sprite[k]; + auto sj = &act->s; if (sj->picnum == RRTILE64) { dist = sj->lotag << 4; speed = sj->hitag; for (ii = 0; ii < MAXSPRITES; ii++) { - if (sprite[ii].picnum == RRTILE66) - if (sprite[ii].lotag == sj->sectnum) + auto spr = &sprite[ii]; + if (spr->picnum == RRTILE66) + if (spr->lotag == sj->sectnum) { - childsectnum = sprite[ii].sectnum; + childsectnum = spr->sectnum; deletesprite(ii); } } - deletesprite(k); + deletesprite(act); } if (sj->picnum == RRTILE65) { sound = sj->lotag; - deletesprite(k); + deletesprite(act); } } addminecart(dist, speed, i, sector[i].hitag, sound, childsectnum); @@ -556,11 +558,11 @@ void prelevel_r(int g) } } - StatIterator it(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DEFAULT); + while (auto ac = it.Next()) { - auto si = &sprite[i]; - LoadActor(i, -1, -1); + auto si = &ac->s; + LoadActor(ac, -1, -1); if (si->lotag == -1 && (si->cstat & 16)) { @@ -575,7 +577,7 @@ void prelevel_r(int g) case GPSPEED: sector[si->sectnum].extra = si->lotag; - deletesprite(i); + deletesprite(ac); break; case CYCLER: @@ -588,22 +590,22 @@ void prelevel_r(int g) cyclers[numcyclers][4] = si->hitag; cyclers[numcyclers][5] = (si->ang == 1536); numcyclers++; - deletesprite(i); + deletesprite(ac); break; case RRTILE18: - addtorch(i); - deletesprite(i); + addtorch(si); + deletesprite(ac); break; case RRTILE35: - addlightning(i); - deletesprite(i); + addlightning(si); + deletesprite(ac); break; case RRTILE68: shadedsector[si->sectnum] = 1; - deletesprite(i); + deletesprite(ac); break; case RRTILE67: @@ -628,30 +630,32 @@ void prelevel_r(int g) for (i = 0; i < MAXSPRITES; i++) { - if (sprite[i].picnum == RRTILE19) + auto spr = &sprite[i]; + if (spr->picnum == RRTILE19) { if (geocnt > 64) I_Error("Too many geometry effects"); - if (sprite[i].hitag == 0) + if (spr->hitag == 0) { - geosector[geocnt] = sprite[i].sectnum; + geosector[geocnt] = spr->sectnum; for (j = 0; j < MAXSPRITES; j++) { - if (sprite[i].lotag == sprite[j].lotag && j != i && sprite[j].picnum == RRTILE19) + auto spj = &sprite[j]; + if (spr->lotag == spj->lotag && j != i && spj->picnum == RRTILE19) { - if (sprite[j].hitag == 1) + if (spj->hitag == 1) { - geosectorwarp[geocnt] = sprite[j].sectnum; - geox[geocnt] = sprite[i].x - sprite[j].x; - geoy[geocnt] = sprite[i].y - sprite[j].y; - //geoz[geocnt] = sprite[i].z - sprite[j].z; + geosectorwarp[geocnt] = spj->sectnum; + geox[geocnt] = spr->x - spj->x; + geoy[geocnt] = spr->y - spj->y; + //geoz[geocnt] = spr->z - spj->z; } - if (sprite[j].hitag == 2) + if (spj->hitag == 2) { - geosectorwarp2[geocnt] = sprite[j].sectnum; - geox2[geocnt] = sprite[i].x - sprite[j].x; - geoy2[geocnt] = sprite[i].y - sprite[j].y; - //geoz2[geocnt] = sprite[i].z - sprite[j].z; + geosectorwarp2[geocnt] = spj->sectnum; + geox2[geocnt] = spr->x - spj->x; + geoy2[geocnt] = spr->y - spj->y; + //geoz2[geocnt] = spr->z - spj->z; } } } @@ -662,26 +666,28 @@ void prelevel_r(int g) for (i = 0; i < MAXSPRITES; i++) { - if (sprite[i].statnum < MAXSTATUS) + auto spr = &sprite[i]; + if (spr->statnum < MAXSTATUS) { - if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == 14) + if (spr->picnum == SECTOREFFECTOR && spr->lotag == 14) continue; - fi.spawn(-1, i); + spawn(nullptr, i); } } for (i = 0; i < MAXSPRITES; i++) { - if (sprite[i].statnum < MAXSTATUS) + auto spr = &sprite[i]; + if (spr->statnum < MAXSTATUS) { - if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == 14) - fi.spawn(-1, i); + if (spr->picnum == SECTOREFFECTOR && spr->lotag == 14) + spawn(nullptr, i); } - if (sprite[i].picnum == RRTILE19) + if (spr->picnum == RRTILE19) deletesprite(i); - if (sprite[i].picnum == RRTILE34) + if (spr->picnum == RRTILE34) { - sectorextra[sprite[i].sectnum] = sprite[i].lotag; + sectorextra[spr->sectnum] = spr->lotag; deletesprite(i); } } @@ -689,9 +695,10 @@ void prelevel_r(int g) lotaglist = 0; it.Reset(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + while (auto ac = it.Next()) { - switch (sprite[i].picnum) + auto spr = &ac->s; + switch (spr->picnum) { case RRTILE8464 + 1: if (!isRRRA()) break; @@ -712,21 +719,21 @@ void prelevel_r(int g) case NUKEBUTTON + 1: for (j = 0; j < lotaglist; j++) - if (sprite[i].lotag == lotags[j]) + if (spr->lotag == lotags[j]) break; if (j == lotaglist) { - lotags[lotaglist] = sprite[i].lotag; + lotags[lotaglist] = spr->lotag; lotaglist++; if (lotaglist > 64) I_Error("Too many switches (64 max)."); - StatIterator it1(STAT_EFFECTOR); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(STAT_EFFECTOR); + while (auto j = it1.Next()) { - if (sprite[j].lotag == 12 && sprite[j].hitag == sprite[i].lotag) - hittype[j].temp_data[0] = 1; + if (j->s.lotag == 12 && j->s.hitag == spr->lotag) + j->temp_data[0] = 1; } } break; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 8ac659a6a..d832529c5 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -31,6 +31,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "v_video.h" #include "prediction.h" #include "automap.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -57,104 +58,118 @@ static int tempsectorz[MAXSECTORS]; static int tempsectorpicnum[MAXSECTORS]; //short tempcursectnum; -void SE40_Draw(int tag, int spnum, int x, int y, int z, binangle a, fixedhoriz h, int smoothratio) +void SE40_Draw(int tag, spritetype *spr, int x, int y, int z, binangle a, fixedhoriz h, int smoothratio) { int i, j = 0, k = 0; - int floor1, floor2 = 0, ok = 0, fofmode = 0; + int ok = 0, fofmode = 0; int offx, offy; + spritetype* floor1, *floor2 = nullptr; - if (sprite[spnum].ang != 512) return; + if (spr->ang != 512) return; i = FOF; //Effect TILE tileDelete(FOF); if (!(gotpic[i >> 3] & (1 << (i & 7)))) return; gotpic[i >> 3] &= ~(1 << (i & 7)); - floor1 = spnum; + floor1 = spr; - if (sprite[spnum].lotag == tag + 2) fofmode = tag + 0; - if (sprite[spnum].lotag == tag + 3) fofmode = tag + 1; - if (sprite[spnum].lotag == tag + 4) fofmode = tag + 0; - if (sprite[spnum].lotag == tag + 5) fofmode = tag + 1; + if (spr->lotag == tag + 2) fofmode = tag + 0; + if (spr->lotag == tag + 3) fofmode = tag + 1; + if (spr->lotag == tag + 4) fofmode = tag + 0; + if (spr->lotag == tag + 5) fofmode = tag + 1; ok++; - for (j = 0; j < MAXSPRITES; j++) + DukeStatIterator it(STAT_RAROR); + while (auto act = it.Next()) { + auto spr = &act->s; if ( - sprite[j].picnum == 1 && - sprite[j].lotag == fofmode && - sprite[j].hitag == sprite[floor1].hitag - ) { - floor1 = j; fofmode = sprite[j].lotag; ok++; break; + spr->picnum == SECTOREFFECTOR && + spr->lotag == fofmode && + spr->hitag == floor1->hitag + ) + { + floor1 = spr; + fofmode = spr->lotag; + ok++; + break; } } // if(ok==1) { Message("no floor1",RED); return; } if (fofmode == tag + 0) k = tag + 1; else k = tag + 0; - for (j = 0; j < MAXSPRITES; j++) + it.Reset(STAT_RAROR); + while (auto act = it.Next()) { + auto spr = &act->s; if ( - sprite[j].picnum == 1 && - sprite[j].lotag == k && - sprite[j].hitag == sprite[floor1].hitag - ) { - floor2 = j; ok++; break; + spr->picnum == SECTOREFFECTOR && + spr->lotag == k && + spr->hitag == floor1->hitag + ) + { + floor2 = spr; + ok++; + break; } } // if(ok==2) { Message("no floor2",RED); return; } - for (j = 0; j < MAXSPRITES; j++) // raise ceiling or floor + it.Reset(STAT_RAROR); + while (auto act = it.Next()) { - if (sprite[j].picnum == 1 && - sprite[j].lotag == k + 2 && - sprite[j].hitag == sprite[floor1].hitag + auto spr = &act->s; + if (spr->picnum == SECTOREFFECTOR && + spr->lotag == k + 2 && + spr->hitag == floor1->hitag ) { if (k == tag + 0) { - tempsectorz[sprite[j].sectnum] = sector[sprite[j].sectnum].floorz; - sector[sprite[j].sectnum].floorz += (((z - sector[sprite[j].sectnum].floorz) / 32768) + 1) * 32768; - tempsectorpicnum[sprite[j].sectnum] = sector[sprite[j].sectnum].floorpicnum; - sector[sprite[j].sectnum].floorpicnum = 13; + tempsectorz[spr->sectnum] = sector[spr->sectnum].floorz; + sector[spr->sectnum].floorz += (((z - sector[spr->sectnum].floorz) / 32768) + 1) * 32768; + tempsectorpicnum[spr->sectnum] = sector[spr->sectnum].floorpicnum; + sector[spr->sectnum].floorpicnum = 13; } if (k == tag + 1) { - tempsectorz[sprite[j].sectnum] = sector[sprite[j].sectnum].ceilingz; - sector[sprite[j].sectnum].ceilingz += (((z - sector[sprite[j].sectnum].ceilingz) / 32768) - 1) * 32768; - tempsectorpicnum[sprite[j].sectnum] = sector[sprite[j].sectnum].ceilingpicnum; - sector[sprite[j].sectnum].ceilingpicnum = 13; + tempsectorz[spr->sectnum] = sector[spr->sectnum].ceilingz; + sector[spr->sectnum].ceilingz += (((z - sector[spr->sectnum].ceilingz) / 32768) - 1) * 32768; + tempsectorpicnum[spr->sectnum] = sector[spr->sectnum].ceilingpicnum; + sector[spr->sectnum].ceilingpicnum = 13; } } } - i = floor1; - offx = x - sprite[i].x; - offy = y - sprite[i].y; - i = floor2; + offx = x - floor1->x; + offy = y - floor1->y; - renderDrawRoomsQ16(sprite[i].x + offx, sprite[i].y + offy, z, a.asq16(), h.asq16(), sprite[i].sectnum); - fi.animatesprites(offx + sprite[i].x, offy + sprite[i].y, a.asbuild(), smoothratio); + renderDrawRoomsQ16(floor2->x + offx, floor2->y + offy, z, a.asq16(), h.asq16(), floor2->sectnum); + fi.animatesprites(offx + floor2->x, offy + floor2->y, a.asbuild(), smoothratio); renderDrawMasks(); - for (j = 0; j < MAXSPRITES; j++) // restore ceiling or floor + it.Reset(STAT_RAROR); + while (auto act = it.Next()) { - if (sprite[j].picnum == 1 && - sprite[j].lotag == k + 2 && - sprite[j].hitag == sprite[floor1].hitag + auto spr = &act->s; + if (spr->picnum == 1 && + spr->lotag == k + 2 && + spr->hitag == floor1->hitag ) { if (k == tag + 0) { - sector[sprite[j].sectnum].floorz = tempsectorz[sprite[j].sectnum]; - sector[sprite[j].sectnum].floorpicnum = tempsectorpicnum[sprite[j].sectnum]; + sector[spr->sectnum].floorz = tempsectorz[spr->sectnum]; + sector[spr->sectnum].floorpicnum = tempsectorpicnum[spr->sectnum]; } if (k == tag + 1) { - sector[sprite[j].sectnum].ceilingz = tempsectorz[sprite[j].sectnum]; - sector[sprite[j].sectnum].ceilingpicnum = tempsectorpicnum[sprite[j].sectnum]; + sector[spr->sectnum].ceilingz = tempsectorz[spr->sectnum]; + sector[spr->sectnum].ceilingpicnum = tempsectorpicnum[spr->sectnum]; } }// end if }// end for @@ -170,15 +185,15 @@ void SE40_Draw(int tag, int spnum, int x, int y, int z, binangle a, fixedhoriz h void se40code(int x, int y, int z, binangle a, fixedhoriz h, int smoothratio) { - int i, tag; + int tag; if (!isRR()) tag = 40; else if (isRRRA()) tag = 150; else return; - StatIterator it(STAT_RAROR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_RAROR); + while (auto act = it.Next()) { - switch (sprite[i].lotag - tag + 40) + switch (act->s.lotag - tag + 40) { // case 40: // case 41: @@ -188,8 +203,8 @@ void se40code(int x, int y, int z, binangle a, fixedhoriz h, int smoothratio) case 43: case 44: case 45: - if (ps[screenpeek].cursectnum == sprite[i].sectnum) - SE40_Draw(tag, i, x, y, z, a, h, smoothratio); + if (ps[screenpeek].cursectnum == act->s.sectnum) + SE40_Draw(tag, &act->s, x, y, z, a, h, smoothratio); break; } } @@ -243,9 +258,9 @@ void renderMirror(int cposx, int cposy, int cposz, binangle cang, fixedhoriz cho // //--------------------------------------------------------------------------- -static inline int16_t getcamspriteang(short const newowner, double const smoothratio) +static inline int16_t getcamspriteang(DDukeActor* newOwner, double const smoothratio) { - return hittype[newowner].tempang + xs_CRoundToInt(fmulscale16(((sprite[newowner].ang - hittype[newowner].tempang + 1024) & 2047) - 1024, smoothratio)); + return newOwner->tempang + xs_CRoundToInt(fmulscale16(((newOwner->s.ang - newOwner->tempang + 1024) & 2047) - 1024, smoothratio)); } //--------------------------------------------------------------------------- @@ -258,17 +273,15 @@ void animatecamsprite(double smoothratio) { const int VIEWSCREEN_ACTIVE_DISTANCE = 8192; - if (camsprite < 0) + if (camsprite == nullptr) return; - int spriteNum = camsprite; - auto p = &ps[screenpeek]; - auto sp = &sprite[spriteNum]; + auto sp = &camsprite->s; - if (p->newowner >= 0) sp->owner = p->newowner; + if (p->newOwner != nullptr) camsprite->SetOwner(p->newOwner); - if (sp->owner >= 0 && dist(&sprite[p->i], sp) < VIEWSCREEN_ACTIVE_DISTANCE) + if (camsprite->GetOwner() && dist(p->GetActor(), camsprite) < VIEWSCREEN_ACTIVE_DISTANCE) { auto tex = tileGetTexture(sp->picnum); TileFiles.MakeCanvas(TILE_VIEWSCR, tex->GetDisplayWidth(), tex->GetDisplayHeight()); @@ -278,8 +291,8 @@ void animatecamsprite(double smoothratio) screen->RenderTextureView(canvas, [=](IntRect& rect) { - auto camera = &sprite[sp->owner]; - auto ang = getcamspriteang(sp->owner, smoothratio); + auto camera = &camsprite->GetOwner()->s; + auto ang = getcamspriteang(camsprite->GetOwner(), smoothratio); // Note: no ROR or camera here for now - the current setup has no means to detect these things before rendering the scene itself. drawrooms(camera->x, camera->y, camera->z, ang, 100 + camera->shade, camera->sectnum); // why 'shade'...? display_mirror = 1; // should really be 'display external view'. @@ -296,13 +309,17 @@ void animatecamsprite(double smoothratio) // RRRA's drug distortion effect // //--------------------------------------------------------------------------- +int DrugTimer; -void setdrugmode(player_struct *p, int oyrepeat) +static int getdrugmode(player_struct *p, int oyrepeat) { - if (playrunning()) + int now = I_GetBuildTime() >> 1; // this function works on a 60 fps setup. + if (playrunning() && p->DrugMode > 0) { - if (p->DrugMode > 0) + if (now - DrugTimer > 4 || now - DrugTimer < 0) DrugTimer = now - 1; + while (DrugTimer < now) { + DrugTimer++; int var_8c; if (p->drug_stat[0] == 0) { @@ -310,16 +327,13 @@ void setdrugmode(player_struct *p, int oyrepeat) var_8c = oyrepeat + p->drug_stat[1] * 5000; if (oyrepeat * 3 < var_8c) { - renderSetAspect(oyrepeat * 3, yxaspect); p->drug_aspect = oyrepeat * 3; p->drug_stat[0] = 2; } else { - renderSetAspect(var_8c, yxaspect); p->drug_aspect = var_8c; } - setpal(p); } else if (p->drug_stat[0] == 3) { @@ -327,18 +341,16 @@ void setdrugmode(player_struct *p, int oyrepeat) var_8c = oyrepeat + p->drug_stat[1] * 5000; if (var_8c < oyrepeat) { - renderSetAspect(oyrepeat, yxaspect); p->DrugMode = 0; p->drug_stat[0] = 0; p->drug_stat[2] = 0; p->drug_stat[1] = 0; + p->drug_aspect = oyrepeat; } else { - renderSetAspect(var_8c, yxaspect); p->drug_aspect = var_8c; } - setpal(p); } else if (p->drug_stat[0] == 2) { @@ -349,9 +361,7 @@ void setdrugmode(player_struct *p, int oyrepeat) else { p->drug_stat[2]++; - renderSetAspect(p->drug_stat[2] * 500 + oyrepeat * 3, yxaspect); p->drug_aspect = oyrepeat * 3 + p->drug_stat[2] * 500; - setpal(p); } } else @@ -366,17 +376,16 @@ void setdrugmode(player_struct *p, int oyrepeat) else { p->drug_stat[2]--; - renderSetAspect(p->drug_stat[2] * 500 + oyrepeat * 3, yxaspect); p->drug_aspect = oyrepeat * 3 + p->drug_stat[2] * 500; - setpal(p); } } } + return p->drug_aspect; } - else if (p->DrugMode > 0) + else { - renderSetAspect(p->drug_aspect, yxaspect); - setpal(p); + DrugTimer = now; + return oyrepeat; } } @@ -389,7 +398,6 @@ void setdrugmode(player_struct *p, int oyrepeat) static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixedhoriz choriz, int sect, int smoothratio) { short gs, tgsect, geosect, geoid = 0; - int spr; renderDrawRoomsQ16(cposx, cposy, cposz, cang.asq16(), choriz.asq16(), sect); fi.animatesprites(cposx, cposy, cang.asbuild(), smoothratio); renderDrawMasks(); @@ -397,11 +405,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed { tgsect = geosector[gs]; - SectIterator it(tgsect); - while ((spr = it.NextIndex()) >= 0) + DukeSectIterator it(tgsect); + while (auto act = it.Next()) { - changespritesect((short)spr, geosectorwarp[gs]); - setsprite((short)spr, sprite[spr].x -= geox[gs], sprite[spr].y -= geoy[gs], sprite[spr].z); + changespritesect(act, geosectorwarp[gs]); + setsprite(act, act->s.x -= geox[gs], act->s.y -= geoy[gs], act->s.z); } if (geosector[gs] == sect) { @@ -417,11 +425,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosectorwarp[gs]; - SectIterator it(tgsect); - while ((spr = it.NextIndex()) >= 0) + DukeSectIterator it(tgsect); + while (auto act = it.Next()) { - changespritesect((short)spr, geosector[gs]); - setsprite((short)spr, sprite[spr].x += geox[gs], sprite[spr].y += geoy[gs], sprite[spr].z); + changespritesect(act, geosector[gs]); + setsprite(act, act->s.x += geox[gs], act->s.y += geoy[gs], act->s.z); } } fi.animatesprites(cposx, cposy, cang.asbuild(), smoothratio); @@ -429,11 +437,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosector[gs]; - SectIterator it(tgsect); - while ((spr = it.NextIndex()) >= 0) + DukeSectIterator it(tgsect); + while (auto act = it.Next()) { - changespritesect((short)spr, geosectorwarp2[gs]); - setsprite((short)spr, sprite[spr].x -= geox2[gs], sprite[spr].y -= geoy2[gs], sprite[spr].z); + changespritesect(act, geosectorwarp2[gs]); + setsprite(act, act->s.x -= geox2[gs], act->s.y -= geoy2[gs], act->s.z); } if (geosector[gs] == sect) { @@ -449,11 +457,11 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed for (gs = 0; gs < geocnt; gs++) { tgsect = geosectorwarp2[gs]; - SectIterator it(tgsect); - while ((spr = it.NextIndex()) >= 0) + DukeSectIterator it(tgsect); + while (auto act = it.Next()) { - changespritesect((short)spr, geosector[gs]); - setsprite((short)spr, sprite[spr].x += geox2[gs], sprite[spr].y += geoy2[gs], sprite[spr].z); + changespritesect(act, geosector[gs]); + setsprite(act, act->s.x += geox2[gs], act->s.y += geoy2[gs], act->s.z); } } fi.animatesprites(cposx, cposy, cang.asbuild(), smoothratio); @@ -500,19 +508,16 @@ void displayrooms(int snum, double smoothratio) setgamepalette(BASEPAL); animatecamsprite(smoothratio); - // The camera texture must be rendered with the base palette, so this is the only place where the current global palette can be set. - // The setting here will be carried over to the rendering of the weapon sprites, but other 2D content will always default to the main palette. - setgamepalette(p->palette); - if (ud.camerasprite >= 0) + if (ud.cameraactor) { spritetype* s; - s = &sprite[ud.camerasprite]; + s = &ud.cameraactor->s; if (s->yvel < 0) s->yvel = -100; else if (s->yvel > 199) s->yvel = 300; - cang = buildang(hittype[ud.camerasprite].tempang + xs_CRoundToInt(fmulscale16(((s->ang + 1024 - hittype[ud.camerasprite].tempang) & 2047) - 1024, smoothratio))); + cang = buildang(ud.cameraactor->tempang + xs_CRoundToInt(fmulscale16(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio))); auto bh = buildhoriz(s->yvel); se40code(s->x, s->y, s->z, cang, bh, smoothratio); @@ -523,18 +528,14 @@ void displayrooms(int snum, double smoothratio) } else { - int i = divscale22(1, isRR() ? 64 : sprite[p->i].yrepeat + 28); - fixed_t dang = IntToFixed(1024); - if (!isRRRA() || !p->DrugMode) - { - // Fixme: This should get the aspect ratio from the backend, not the current viewport size. - int viewingRange = xs_CRoundToInt(double(i) * tan(r_fov * (pi::pi() / 360.))); - renderSetAspect(mulscale16(viewingRange, viewingrange), yxaspect); - } - else - { - setdrugmode(p, i); - } + // Fixme: This should get the aspect ratio from the backend, not the current viewport size. + int i = divscale22(1, isRR() ? 64 : p->GetActor()->s.yrepeat + 28); + int viewingaspect = !isRRRA() || !p->DrugMode ? xs_CRoundToInt(double(i) * tan(r_fov * (pi::pi() / 360.))) : getdrugmode(p, i); + renderSetAspect(mulscale16(viewingaspect, viewingrange), yxaspect); + + // The camera texture must be rendered with the base palette, so this is the only place where the current global palette can be set. + // The setting here will be carried over to the rendering of the weapon sprites, but other 2D content will always default to the main palette. + setgamepalette(setpal(p)); // set screen rotation. rotscrnang = !cl_syncinput ? p->angle.rotscrnang : p->angle.interpolatedrotscrn(smoothratio); @@ -577,14 +578,15 @@ void displayrooms(int snum, double smoothratio) } } - if (p->newowner >= 0) + if (p->newOwner != nullptr) { - cang = buildang(getcamspriteang(p->newowner, smoothratio)); - choriz = buildhoriz(sprite[p->newowner].shade); - cposx = sprite[p->newowner].pos.x; - cposy = sprite[p->newowner].pos.y; - cposz = sprite[p->newowner].pos.z; - sect = sprite[p->newowner].sectnum; + auto spr = &p->newOwner->s; + cang = buildang(getcamspriteang(p->newOwner, smoothratio)); + choriz = buildhoriz(spr->shade); + cposx = spr->pos.x; + cposy = spr->pos.y; + cposz = spr->pos.z; + sect = spr->sectnum; rotscrnang = buildlook(0); smoothratio = MaxSmoothRatio; } @@ -606,8 +608,8 @@ void displayrooms(int snum, double smoothratio) // do screen rotation. renderSetRollAngle(rotscrnang.asbam() / (double)(BAMUNIT)); - cz = hittype[p->i].ceilingz; - fz = hittype[p->i].floorz; + cz = p->GetActor()->ceilingz; + fz = p->GetActor()->floorz; if (earthquaketime > 0 && p->on_ground == 1) { @@ -615,9 +617,9 @@ void displayrooms(int snum, double smoothratio) cang += buildang((2 - ((earthquaketime) & 2)) << 2); } - if (sprite[p->i].pal == 1) cposz -= (18 << 8); + if (p->GetActor()->s.pal == 1) cposz -= (18 << 8); - else if (p->spritebridge == 0 && p->newowner < 0) + else if (p->spritebridge == 0 && p->newOwner == nullptr) { if (cposz < (p->truecz + (4 << 8))) cposz = cz + (4 << 8); else if (cposz > (p->truefz - (4 << 8))) cposz = fz - (4 << 8); diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 284e190a4..c456fadf0 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -30,6 +30,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "mapinfo.h" #include "duke3d.h" #include "gamestate.h" +#include "dukeactor.h" extern FixedBitArray activeSprites; @@ -60,22 +61,22 @@ static void recreateinterpolations() { numinterpolations = 0; - int k; - StatIterator it(STAT_EFFECTOR); - while ((k = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto k = it.Next()) { - switch (sprite[k].lotag) + auto sectnum = k->s.sectnum; + switch (k->s.lotag) { case SE_31_FLOOR_RISE_FALL: - setinterpolation(§or[sprite[k].sectnum].floorz); + setinterpolation(§or[sectnum].floorz); break; case SE_32_CEILING_RISE_FALL: - setinterpolation(§or[sprite[k].sectnum].ceilingz); + setinterpolation(§or[sectnum].ceilingz); break; case SE_17_WARP_ELEVATOR: case SE_25_PISTON: - setinterpolation(§or[sprite[k].sectnum].floorz); - setinterpolation(§or[sprite[k].sectnum].ceilingz); + setinterpolation(§or[sectnum].floorz); + setinterpolation(§or[sectnum].ceilingz); break; case SE_0_ROTATING_SECTOR: case SE_5_BOSS: @@ -86,7 +87,7 @@ static void recreateinterpolations() case SE_16_REACTOR: case SE_26: case SE_30_TWO_WAY_TRAIN: - setsectinterpolate(k); + setsectinterpolate(sectnum); break; } } @@ -132,7 +133,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, ("angle", w.angle) ("horizon", w.horizon) ("gotweapon", w.gotweapon) - ("palette", w.palette) ("pals", w.pals) ("fricx", w.fric.x) ("fricy", w.fric.y) @@ -172,7 +172,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, ("tipincs", w.tipincs) ("wantweaponfire", w.wantweaponfire) ("holoduke_amount", w.holoduke_amount) - ("newowner", w.newowner) + ("newowner", w.newOwner) ("hurt_delay", w.hurt_delay) ("hbomb_hold_delay", w.hbomb_hold_delay) ("jumping_counter", w.jumping_counter) @@ -291,7 +291,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, ("moto_on_oil", w.moto_on_oil) ("moto_on_mud", w.moto_on_mud) // new stuff - ("crouch_toggle", w.crouch_toggle) ("actions", w.sync.actions) .EndObject(); @@ -305,7 +304,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, w.okickback_pic = w.kickback_pic; w.orandom_club_frame = w.random_club_frame; w.ohard_landing = w.hard_landing; - w.sync.actions &= SB_CENTERVIEW; // this is the only bit we need to preserve. + w.sync.actions &= SB_CENTERVIEW|SB_CROUCH; // these are the only bits we need to preserve. } return arc; } @@ -335,6 +334,9 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, weaponhit& w, weap ("bposy", w.bposy, def->bposy) ("bposz", w.bposz, def->bposz) ("aflags", w.aflags, def->aflags) + ("saved_ammo", w.saved_ammo, def->saved_ammo) + ("temp_actor", w.temp_actor, def->temp_actor) + ("seek_actor", w.seek_actor, def->seek_actor) .Array("temp_data", w.temp_data, def->temp_data, 6) .EndObject(); } @@ -375,6 +377,7 @@ void GameInterface::SerializeGameState(FSerializer& arc) ("marker", ud.marker) ("ffire", ud.ffire) ("levelclock", ud.levelclock) + ("bomb_tag", ud.bomb_tag) .Array("sectorextra", sectorextra, numsectors) ("rtsplaying", rtsplaying) @@ -471,7 +474,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) cameraclock = 0; ps[myconnectindex].over_shoulder_on = 1; } - setpal(&ps[myconnectindex]); memset(gotpic, 0, sizeof(gotpic)); if (isRR()) cacheit_r(); else cacheit_d(); diff --git a/source/games/duke/src/sbar.cpp b/source/games/duke/src/sbar.cpp index 8f8ad3ff5..40d509d9a 100644 --- a/source/games/duke/src/sbar.cpp +++ b/source/games/duke/src/sbar.cpp @@ -86,9 +86,9 @@ void DDukeCommonStatusBar::displayfragbar(void) for (i = connecthead; i >= 0; i = connectpoint2[i]) { - m initext(21 + (73 * (i & 3)), 2 + ((i & 28) << 1), &ud.user_name[i][0], sprite[ps[i].i].pal, 2 + 8 + 16 + 128); + m initext(21 + (73 * (i & 3)), 2 + ((i & 28) << 1), &ud.user_name[i][0], ps[i].GetActor()->s.pal, 2 + 8 + 16 + 128); sprintf(tempbuf, "%d", ps[i].frag - ps[i].fraggedself); - m initext(17 + 50 + (73 * (i & 3)), 2 + ((i & 28) << 1), tempbuf, sprite[ps[i].i].pal, 2 + 8 + 16 + 128); + m initext(17 + 50 + (73 * (i & 3)), 2 + ((i & 28) << 1), tempbuf, ps[i].GetActor()->s.pal, 2 + 8 + 16 + 128); } } #endif diff --git a/source/games/duke/src/sbar_d.cpp b/source/games/duke/src/sbar_d.cpp index 284c8cd3e..1129c80d7 100644 --- a/source/games/duke/src/sbar_d.cpp +++ b/source/games/duke/src/sbar_d.cpp @@ -42,6 +42,7 @@ source as it is released. #include "v_draw.h" #include "names_d.h" #include "texturemanager.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -68,7 +69,7 @@ public: SetSize(tilesiz[TILE_BOTTOMSTATUSBAR].y); scale = 1; - ammo_sprites = { -1, AMMO, SHOTGUNAMMO, BATTERYAMMO, RPGAMMO, HBOMBAMMO, CRYSTALAMMO, DEVISTATORAMMO, TRIPBOMBSPRITE, FREEZEAMMO + 1, HBOMBAMMO, GROWAMMO/*, FLAMETHROWERAMMO + 1*/ }; + ammo_sprites = { -1, AMMO, SHOTGUNAMMO, BATTERYAMMO, RPGAMMO, HBOMBAMMO, CRYSTALAMMO, DEVISTATORAMMO, TRIPBOMBSPRITE, FREEZEAMMO + 1, HBOMBAMMO, GROWAMMO, FLAMETHROWERAMMO + 1 }; item_icons = { 0, FIRSTAID_ICON, STEROIDS_ICON, HOLODUKE_ICON, JETPACK_ICON, HEAT_ICON, AIRTANK_ICON, BOOT_ICON }; } @@ -104,7 +105,7 @@ public: int GetMoraleOrShield(struct player_struct *p, int snum) { // special handling for WW2GI - int lAmount = GetGameVar("PLR_MORALE", -1, p->i, snum); + int lAmount = GetGameVar("PLR_MORALE", -1, p->GetActor(), snum); if (lAmount == -1) lAmount = p->shield_amount; return lAmount; } @@ -131,7 +132,7 @@ public: imgScale = baseScale / img->GetDisplayHeight(); DrawGraphic(img, 2, -1.5, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, imgScale, imgScale); - if (!althud_flashing || p->last_extra > (max_player_health >> 2) || (ud.levelclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) + if (!althud_flashing || p->last_extra > (max_player_health >> 2) || (ud.levelclock & 32) || (p->GetActor()->s.pal == 1 && p->last_extra < 2)) { int s = -8; if (althud_flashing && p->last_extra > max_player_health) @@ -233,7 +234,7 @@ public: // health // DrawGraphic(tileGetTexture(HEALTHBOX), 5, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); - int health = (sprite[p->i].pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; + int health = (p->GetActor()->s.pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; FStringf format("%d", health); SBar_DrawString(this, digiFont, format, 20, -digiFont->mFont->GetHeight() * scale - 3, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale); @@ -409,7 +410,7 @@ public: } DrawWeaponAmounts(p, 96, top + 15.5); - int num = (sprite[p->i].pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; + int num = (p->GetActor()->s.pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; format.Format("%d", num); SBar_DrawString(this, digiFont, format, 31, top + 17, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, 1, 1); format.Format("%d", GetMoraleOrShield(p, snum)); diff --git a/source/games/duke/src/sbar_r.cpp b/source/games/duke/src/sbar_r.cpp index 54ac99f41..24bc5417c 100644 --- a/source/games/duke/src/sbar_r.cpp +++ b/source/games/duke/src/sbar_r.cpp @@ -34,6 +34,7 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms #include "v_draw.h" #include "names_r.h" #include "texturemanager.h" +#include "dukeactor.h" BEGIN_DUKE_NS @@ -107,7 +108,7 @@ public: imgScale = baseScale / img->GetDisplayHeight(); DrawGraphic(img, 2, -2, DI_ITEM_LEFT_BOTTOM, 1, 0, 0, imgScale, imgScale); - if (!althud_flashing || p->last_extra > (max_player_health >> 2) || (ud.levelclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) + if (!althud_flashing || p->last_extra > (max_player_health >> 2) || (ud.levelclock & 32) || (p->GetActor()->s.pal == 1 && p->last_extra < 2)) { int s = -8; if (althud_flashing && p->last_extra > max_player_health) @@ -227,7 +228,7 @@ public: // health // DrawGraphic(tileGetTexture(HEALTHBOX), 2, -2, DI_ITEM_LEFT_BOTTOM, 1, -1, -1, scale, scale); - int health = (sprite[p->i].pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; + int health = (p->GetActor()->s.pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; FStringf format("%d", health); SBar_DrawString(this, digiFont, format, 21.5, -digiFont->mFont->GetHeight() * scale - 5.5, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale); @@ -376,7 +377,7 @@ public: if (p->keys[1]) DrawGraphic(key, 145, top + 21, DI_ITEM_OFFSETS, 1, -1, -1, scale, scale, 0xffffffff, TRANSLATION(Translation_Remap, 0)); } - int num = (sprite[p->i].pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; + int num = (p->GetActor()->s.pal == 1 && p->last_extra < 2) ? 1 : p->last_extra; format.Format("%d", num); SBar_DrawString(this, digiFont, format, 66.5, top + 16, DI_TEXT_ALIGN_CENTER, CR_UNTRANSLATED, 1, 0, 0, scale, scale); diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index f262f7b1c..2bf2f8903 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -50,7 +50,7 @@ BEGIN_DUKE_NS //--------------------------------------------------------------------------- static bool haltsoundhack; -int callsound(int sn, int whatsprite) +int callsound(int sn, DDukeActor* whatsprite) { if (!isRRRA() && haltsoundhack) { @@ -58,49 +58,48 @@ int callsound(int sn, int whatsprite) return -1; } - int i; - SectIterator it(sn); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sn); + while (auto act = it.Next()) { - auto si = &sprite[i]; + auto si = &act->s; if (si->picnum == MUSICANDSFX && si->lotag < 1000) { - if (whatsprite == -1) whatsprite = i; + if (whatsprite == nullptr) whatsprite = act; int snum = si->lotag; auto flags = S_GetUserFlags(snum); // Reset if the desired actor isn't playing anything. bool hival = S_IsSoundValid(si->hitag); - if (hittype[i].temp_data[0] == 1 && !hival) + if (act->temp_data[0] == 1 && !hival) { - if (!S_CheckActorSoundPlaying(hittype[i].temp_data[5], snum)) - hittype[i].temp_data[0] = 0; + if (!S_CheckActorSoundPlaying(act->temp_actor, snum)) + act->temp_data[0] = 0; } - if (hittype[i].temp_data[0] == 0) + if (act->temp_data[0] == 0) { if ((flags & (SF_GLOBAL | SF_DTAG)) != SF_GLOBAL) { if (snum) { if (si->hitag && snum != si->hitag) - S_StopSound(si->hitag, hittype[i].temp_data[5]); + S_StopSound(si->hitag, act->temp_actor); S_PlayActorSound(snum, whatsprite); - hittype[i].temp_data[5] = whatsprite; + act->temp_actor = whatsprite; } if ((sector[si->sectnum].lotag & 0xff) != ST_22_SPLITTING_DOOR) - hittype[i].temp_data[0] = 1; + act->temp_data[0] = 1; } } else if (si->hitag < 1000) { if ((flags & SF_LOOP) || (si->hitag && si->hitag != si->lotag)) - S_StopSound(si->lotag, hittype[i].temp_data[5]); + S_StopSound(si->lotag, act->temp_actor); if (si->hitag) S_PlayActorSound(si->hitag, whatsprite); - hittype[i].temp_data[0] = 0; - hittype[i].temp_data[5] = whatsprite; + act->temp_data[0] = 0; + act->temp_actor = whatsprite; } return si->lotag; } @@ -117,29 +116,24 @@ int callsound(int sn, int whatsprite) int check_activator_motion(int lotag) { - int i, j; - spritetype* s; - - StatIterator it(STAT_ACTIVATOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTIVATOR); + while (auto act = it.Next()) { - if (sprite[i].lotag == lotag) + if (act->s.lotag == lotag) { - s = &sprite[i]; - - for (j = animatecnt - 1; j >= 0; j--) - if (s->sectnum == animatesect[j]) + for (int j = animatecnt - 1; j >= 0; j--) + if (act->s.sectnum == animatesect[j]) return(1); - StatIterator it1(STAT_EFFECTOR); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(STAT_EFFECTOR); + while (auto act2 = it1.Next()) { - if (s->sectnum == sprite[j].sectnum) - switch (sprite[j].lotag) + if (act->s.sectnum == act2->s.sectnum) + switch (act2->s.lotag) { case SE_11_SWINGING_DOOR: case SE_30_TWO_WAY_TRAIN: - if (hittype[j].temp_data[4]) + if (act2->temp_data[4]) return(1); break; case SE_18_INCREMENTAL_SECTOR_RISE_FALL: @@ -147,7 +141,7 @@ int check_activator_motion(int lotag) case SE_20_STRETCH_BRIDGE: case SE_31_FLOOR_RISE_FALL: case SE_32_CEILING_RISE_FALL: - if (hittype[j].temp_data[0]) + if (act2->temp_data[0]) return(1); break; } @@ -217,10 +211,11 @@ bool isanearoperator(int lotag) // //--------------------------------------------------------------------------- -int findplayer(const spritetype* s, int* d) +int findplayer(const DDukeActor* actor, int* d) { short j, closest_player; int x, closest; + auto s = &actor->s.pos; if (ud.multimode < 2) { @@ -234,7 +229,7 @@ int findplayer(const spritetype* s, int* d) for (j = connecthead; j >= 0; j = connectpoint2[j]) { x = abs(ps[j].oposx - s->x) + abs(ps[j].oposy - s->y) + ((abs(ps[j].oposz - s->z + (28 << 8))) >> 4); - if (x < closest && sprite[ps[j].i].extra > 0) + if (x < closest && ps[j].GetActor()->s.extra > 0) { closest_player = j; closest = x; @@ -260,7 +255,7 @@ int findotherplayer(int p, int* d) closest_player = p; for (j = connecthead; j >= 0; j = connectpoint2[j]) - if (p != j && sprite[ps[j].i].extra > 0) + if (p != j && ps[j].GetActor()->s.extra > 0) { x = abs(ps[j].oposx - ps[p].posx) + abs(ps[j].oposy - ps[p].posy) + (abs(ps[j].oposz - ps[p].posz) >> 4); @@ -313,7 +308,7 @@ int* animateptr(int i) void doanimations(void) { - int i, j, a, p, v, dasect; + int i, a, p, v, dasect; for (i = animatecnt - 1; i >= 0; i--) { @@ -336,7 +331,7 @@ void doanimations(void) continue; if ((sector[dasect].lotag & 0xff) != ST_22_SPLITTING_DOOR) - callsound(dasect, -1); + callsound(dasect, nullptr); continue; } @@ -349,20 +344,20 @@ void doanimations(void) for (p = connecthead; p >= 0; p = connectpoint2[p]) if (ps[p].cursectnum == dasect) if ((sector[dasect].floorz - ps[p].posz) < (64 << 8)) - if (sprite[ps[p].i].owner >= 0) + if (ps[p].GetActor()->GetOwner() != nullptr) { ps[p].posz += v; ps[p].poszv = 0; } - SectIterator it(dasect); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(dasect); + while (auto act = it.Next()) { - if (sprite[j].statnum != STAT_EFFECTOR) + if (act->s.statnum != STAT_EFFECTOR) { - hittype[j].bposz = sprite[j].z; - sprite[j].z += v; - hittype[j].floorz = sector[dasect].floorz + v; + act->bposz = act->s.z; + act->s.z += v; + act->floorz = sector[dasect].floorz + v; } } } @@ -436,25 +431,24 @@ int setanimation(short animsect, int animtype, int animtarget, int thegoal, int // //--------------------------------------------------------------------------- -bool activatewarpelevators(int s, int d) //Parm = sectoreffectornum +bool activatewarpelevators(DDukeActor* actor, int d) //Parm = sectoreffectornum { - int i, sn; - - sn = sprite[s].sectnum; + int sn = actor->s.sectnum; // See if the sector exists - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + DDukeActor *act2; + while ((act2 = it.Next())) { - if (sprite[i].lotag == SE_17_WARP_ELEVATOR || (isRRRA() && sprite[i].lotag == SE_18_INCREMENTAL_SECTOR_RISE_FALL)) - if (sprite[i].hitag == sprite[s].hitag) - if ((abs(sector[sn].floorz - hittype[s].temp_data[2]) > sprite[i].yvel) || - (sector[sprite[i].sectnum].hitag == (sector[sn].hitag - d))) + if (act2->s.lotag == SE_17_WARP_ELEVATOR || (isRRRA() && act2->s.lotag == SE_18_INCREMENTAL_SECTOR_RISE_FALL)) + if (act2->s.hitag == actor->s.hitag) + if ((abs(sector[sn].floorz - actor->temp_data[2]) > act2->s.yvel) || + (sector[act2->s.sectnum].hitag == (sector[sn].hitag - d))) break; } - if (i == -1) + if (act2 == nullptr) { d = 0; return 1; // No find @@ -462,19 +456,19 @@ bool activatewarpelevators(int s, int d) //Parm = sectoreffectornum else { if (d == 0) - S_PlayActorSound(ELEVATOR_OFF, s); - else S_PlayActorSound(ELEVATOR_ON, s); + S_PlayActorSound(ELEVATOR_OFF, actor); + else S_PlayActorSound(ELEVATOR_ON, actor); } it.Reset(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + while ((act2 = it.Next())) { - if (sprite[i].lotag == SE_17_WARP_ELEVATOR || (isRRRA() && sprite[i].lotag == SE_18_INCREMENTAL_SECTOR_RISE_FALL)) - if (sprite[i].hitag == sprite[s].hitag) + if (act2->s.lotag == SE_17_WARP_ELEVATOR || (isRRRA() && act2->s.lotag == SE_18_INCREMENTAL_SECTOR_RISE_FALL)) + if (act2->s.hitag == actor->s.hitag) { - hittype[i].temp_data[0] = d; - hittype[i].temp_data[1] = d; //Make all check warp + act2->temp_data[0] = d; + act2->temp_data[1] = d; //Make all check warp } } return 0; @@ -486,17 +480,478 @@ bool activatewarpelevators(int s, int d) //Parm = sectoreffectornum // //--------------------------------------------------------------------------- -void operatesectors(int sn, int ii) +static void handle_st09(int sn, DDukeActor* actor) { - int j=0, l, q, startwall, endwall; + int dax, day, dax2, day2, sp; + int wallfind[2]; + sectortype* sptr = §or[sn]; + + int startwall = sptr->wallptr; + int endwall = startwall + sptr->wallnum - 1; + + sp = sptr->extra >> 4; + + //first find center point by averaging all points + dax = 0L, day = 0L; + for (int i = startwall; i <= endwall; i++) + { + dax += wall[i].x; + day += wall[i].y; + } + dax /= (endwall - startwall + 1); + day /= (endwall - startwall + 1); + + //find any points with either same x or same y coordinate + // as center (dax, day) - should be 2 points found. + wallfind[0] = -1; + wallfind[1] = -1; + for (int i = startwall; i <= endwall; i++) + if ((wall[i].x == dax) || (wall[i].y == day)) + { + if (wallfind[0] == -1) + wallfind[0] = i; + else wallfind[1] = i; + } + + for (int j = 0; j < 2; j++) + { + if ((wall[wallfind[j]].x == dax) && (wall[wallfind[j]].y == day)) + { + //find what direction door should open by averaging the + // 2 neighboring points of wallfind[0] & wallfind[1]. + int i = wallfind[j] - 1; if (i < startwall) i = endwall; + dax2 = ((wall[i].x + wall[wall[wallfind[j]].point2].x) >> 1) - wall[wallfind[j]].x; + day2 = ((wall[i].y + wall[wall[wallfind[j]].point2].y) >> 1) - wall[wallfind[j]].y; + if (dax2 != 0) + { + dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; + dax2 -= wall[wall[wallfind[j]].point2].x; + setanimation(sn, anim_vertexx, wallfind[j], wall[wallfind[j]].x + dax2, sp); + setanimation(sn, anim_vertexx, i, wall[i].x + dax2, sp); + setanimation(sn, anim_vertexx, wall[wallfind[j]].point2, wall[wall[wallfind[j]].point2].x + dax2, sp); + callsound(sn, actor); + } + else if (day2 != 0) + { + day2 = wall[wall[wall[wallfind[j]].point2].point2].y; + day2 -= wall[wall[wallfind[j]].point2].y; + setanimation(sn, anim_vertexy, wallfind[j], wall[wallfind[j]].y + day2, sp); + setanimation(sn, anim_vertexy, i, wall[i].y + day2, sp); + setanimation(sn, anim_vertexy, wall[wallfind[j]].point2, wall[wall[wallfind[j]].point2].y + day2, sp); + callsound(sn, actor); + } + } + else + { + int i = wallfind[j] - 1; if (i < startwall) i = endwall; + dax2 = ((wall[i].x + wall[wall[wallfind[j]].point2].x) >> 1) - wall[wallfind[j]].x; + day2 = ((wall[i].y + wall[wall[wallfind[j]].point2].y) >> 1) - wall[wallfind[j]].y; + if (dax2 != 0) + { + setanimation(sn, anim_vertexx, wallfind[j], dax, sp); + setanimation(sn, anim_vertexx, i, dax + dax2, sp); + setanimation(sn, anim_vertexx, wall[wallfind[j]].point2, dax + dax2, sp); + callsound(sn, actor); + } + else if (day2 != 0) + { + setanimation(sn, anim_vertexy, wallfind[j], day, sp); + setanimation(sn, anim_vertexy, i, day + day2, sp); + setanimation(sn, anim_vertexy, wall[wallfind[j]].point2, day + day2, sp); + callsound(sn, actor); + } + } + } + +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st15(int sn, DDukeActor* actor) +{ + if (actor->s.picnum != TILE_APLAYER) return; + + sectortype* sptr = §or[sn]; + DukeSectIterator it(sn); + DDukeActor* a2; + while ((a2 = it.Next())) + { + if (a2->s.picnum == SECTOREFFECTOR && a2->s.lotag == ST_17_PLATFORM_UP) break; + } + if (!a2) return; + + if (actor->s.sectnum == sn) + { + if (activatewarpelevators(a2, -1)) + activatewarpelevators(a2, 1); + else if (activatewarpelevators(a2, 1)) + activatewarpelevators(a2, -1); + return; + } + else + { + if (sptr->floorz > a2->s.z) + activatewarpelevators(a2, -1); + else + activatewarpelevators(a2, 1); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st16(int sn, DDukeActor* actor) +{ + sectortype* sptr = §or[sn]; + int i = getanimationgoal(anim_floorz, sn); + int j; + + if (i == -1) + { + i = nextsectorneighborz(sn, sptr->floorz, 1, 1); + if (i == -1) + { + i = nextsectorneighborz(sn, sptr->floorz, 1, -1); + if (i == -1) return; + j = sector[i].floorz; + setanimation(sn, anim_floorz, sn, j, sptr->extra); + } + else + { + j = sector[i].floorz; + setanimation(sn, anim_floorz, sn, j, sptr->extra); + } + callsound(sn, actor); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st18(int sn, DDukeActor* actor) +{ + sectortype* sptr = §or[sn]; + int i = getanimationgoal(anim_floorz, sn); + + if (i == -1) + { + i = nextsectorneighborz(sn, sptr->floorz, 1, -1); + if (i == -1) i = nextsectorneighborz(sn, sptr->floorz, 1, 1); + if (i == -1) return; + int j = sector[i].floorz; + int q = sptr->extra; + int l = sptr->ceilingz - sptr->floorz; + setanimation(sn, anim_floorz, sn, j, q); + setanimation(sn, anim_ceilingz, sn, j + l, q); + callsound(sn, actor); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st29(int sn, DDukeActor* actor) +{ + sectortype* sptr = §or[sn]; + int j; + + if (sptr->lotag & 0x8000) + j = sector[nextsectorneighborz(sn, sptr->ceilingz, 1, 1)].floorz; + else + j = sector[nextsectorneighborz(sn, sptr->ceilingz, -1, -1)].ceilingz; + + DukeStatIterator it(STAT_EFFECTOR); + while (auto act2 = it.Next()) + { + if ((act2->s.lotag == 22) && + (act2->s.hitag == sptr->hitag)) + { + sector[act2->s.sectnum].extra = -sector[act2->s.sectnum].extra; + + act2->temp_data[0] = sn; + act2->temp_data[1] = 1; + } + } + + sptr->lotag ^= 0x8000; + + setanimation(sn, anim_ceilingz, sn, j, sptr->extra); + + callsound(sn, actor); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st20(int sn, DDukeActor* actor) +{ + sectortype* sptr = §or[sn]; + int j; +REDODOOR: + + if (sptr->lotag & 0x8000) + { + DDukeActor* a2; + DukeSectIterator it(sn); + while ((a2 = it.Next())) + { + if (a2->s.statnum == 3 && a2->s.lotag == 9) + { + j = a2->s.z; + break; + } + } + if (a2 == nullptr) + j = sptr->floorz; + } + else + { + j = nextsectorneighborz(sn, sptr->ceilingz, -1, -1); + + if (j >= 0) j = sector[j].ceilingz; + else + { + sptr->lotag |= 32768; + goto REDODOOR; + } + } + + sptr->lotag ^= 0x8000; + + setanimation(sn, anim_ceilingz, sn, j, sptr->extra); + callsound(sn, actor); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st21(int sn, DDukeActor* actor) +{ + sectortype* sptr = §or[sn]; + int i = getanimationgoal(anim_floorz, sn); + int j; + if (i >= 0) + { + if (animategoal[sn] == sptr->ceilingz) + animategoal[i] = sector[nextsectorneighborz(sn, sptr->ceilingz, 1, 1)].floorz; + else animategoal[i] = sptr->ceilingz; + j = animategoal[i]; + } + else + { + if (sptr->ceilingz == sptr->floorz) + j = sector[nextsectorneighborz(sn, sptr->ceilingz, 1, 1)].floorz; + else j = sptr->ceilingz; + + sptr->lotag ^= 0x8000; + + if (setanimation(sn, anim_floorz, sn, j, sptr->extra) >= 0) + callsound(sn, actor); + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st22(int sn, DDukeActor* actor) +{ + sectortype* sptr = §or[sn]; + int j, q; + if ((sptr->lotag & 0x8000)) + { + q = (sptr->ceilingz + sptr->floorz) >> 1; + j = setanimation(sn, anim_floorz, sn, q, sptr->extra); + j = setanimation(sn, anim_ceilingz, sn, q, sptr->extra); + } + else + { + q = sector[nextsectorneighborz(sn, sptr->floorz, 1, 1)].floorz; + j = setanimation(sn, anim_floorz, sn, q, sptr->extra); + q = sector[nextsectorneighborz(sn, sptr->ceilingz, -1, -1)].ceilingz; + j = setanimation(sn, anim_ceilingz, sn, q, sptr->extra); + } + + sptr->lotag ^= 0x8000; + + callsound(sn, actor); + +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st23(int sn, DDukeActor* actor) +{ + int q = 0; + + DukeStatIterator it(STAT_EFFECTOR); + DDukeActor* act2; + while ((act2 = it.Next())) + { + if (act2->s.lotag == 11 && act2->s.sectnum == sn && !act2->temp_data[4]) + { + break; + } + } + if (!act2) return; + + int l = sector[act2->s.sectnum].lotag & 0x8000; + + if (act2) + { + DukeStatIterator it(STAT_EFFECTOR); + while (auto act3 = it.Next()) + { + if (l == (sector[act3->s.sectnum].lotag & 0x8000) && act3->s.lotag == 11 && act2->s.hitag == act3->s.hitag && !act3->temp_data[4]) + { + if (sector[act3->s.sectnum].lotag & 0x8000) sector[act3->s.sectnum].lotag &= 0x7fff; + else sector[act3->s.sectnum].lotag |= 0x8000; + act3->temp_data[4] = 1; + act3->temp_data[3] = -act3->temp_data[3]; + if (q == 0) + { + callsound(sn, act3); + q = 1; + } + } + } + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st25(int sn, DDukeActor* actor) +{ + DukeStatIterator it(STAT_EFFECTOR); + DDukeActor* act2; + while ((act2 = it.Next())) + { + if (act2->s.lotag == 15 && act2->s.sectnum == sn) + { + break; + } + } + + if (act2 == nullptr) + return; + + it.Reset(STAT_EFFECTOR); + while (auto act3 = it.Next()) + { + if (act3->s.hitag == act2->s.hitag) + { + if (act3->s.lotag == 15) + { + sector[act3->s.sectnum].lotag ^= 0x8000; // Toggle the open or close + act3->s.ang += 1024; + if (act3->temp_data[4]) callsound(act3->s.sectnum, act3); + callsound(act3->s.sectnum, act3); + if (sector[act3->s.sectnum].lotag & 0x8000) act3->temp_data[4] = 1; + else act3->temp_data[4] = 2; + } + } + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st27(int sn, DDukeActor* actor) +{ + DukeStatIterator it(STAT_EFFECTOR); + while (auto act2 = it.Next()) + { + if ((act2->s.lotag & 0xff) == 20 && act2->s.sectnum == sn) //Bridge + { + + sector[sn].lotag ^= 0x8000; + if (sector[sn].lotag & 0x8000) //OPENING + act2->temp_data[0] = 1; + else act2->temp_data[0] = 2; + callsound(sn, actor); + break; + } + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +static void handle_st28(int sn, DDukeActor* actor) +{ + //activate the rest of them + int j = -1; + DukeSectIterator it(sn); + while (auto a2 = it.Next()) + { + if (a2->s.statnum == 3 && (a2->s.lotag & 0xff) == 21) + { + j = a2->s.hitag; + break; //Found it + } + } + + if (j == -1) return; + DukeStatIterator it1(STAT_EFFECTOR); + while (auto act3 = it.Next()) + { + if ((act3->s.lotag & 0xff) == 21 && !act3->temp_data[0] && + (act3->s.hitag) == j) + act3->temp_data[0] = 1; + } + callsound(sn, actor); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void operatesectors(int sn, DDukeActor *actor) +{ + int j=0, startwall, endwall; int i; - char sect_error; sectortype* sptr; - sect_error = 0; sptr = §or[sn]; - switch (sptr->lotag & (0xffff - 49152)) + switch (sptr->lotag & (0x3fff)) { case 41: @@ -515,24 +970,25 @@ void operatesectors(int sn, int ii) break; case ST_30_ROTATE_RISE_BRIDGE: - j = sector[sn].hitag; - if (hittype[j].tempang == 0 || - hittype[j].tempang == 256) - callsound(sn, ii); - if (sprite[j].extra == 1) - sprite[j].extra = 3; - else sprite[j].extra = 1; + { + auto act = ScriptIndexToActor(sector[sn].hitag); + if (!act) break; + if (act->tempang == 0 || act->tempang == 256) callsound(sn, actor); + if (act->s.extra == 1) act->s.extra = 3; + else act->s.extra = 1; break; + } case ST_31_TWO_WAY_TRAIN: + { + auto act = ScriptIndexToActor(sector[sn].hitag); + if (!act) break; + if (act->temp_data[4] == 0) + act->temp_data[4] = 1; - j = sector[sn].hitag; - if (hittype[j].temp_data[4] == 0) - hittype[j].temp_data[4] = 1; - - callsound(sn, ii); + callsound(sn, actor); break; - + } case ST_26_SPLITTING_ST_DOOR: //The split doors i = getanimationgoal(anim_ceilingz, sn); if (i == -1) //if the door has stopped @@ -540,393 +996,65 @@ void operatesectors(int sn, int ii) haltsoundhack = 1; sptr->lotag &= 0xff00; sptr->lotag |= ST_22_SPLITTING_DOOR; - operatesectors(sn, ii); + operatesectors(sn, actor); sptr->lotag &= 0xff00; sptr->lotag |= ST_9_SLIDING_ST_DOOR; - operatesectors(sn, ii); + operatesectors(sn, actor); sptr->lotag &= 0xff00; sptr->lotag |= ST_26_SPLITTING_ST_DOOR; } return; case ST_9_SLIDING_ST_DOOR: - { - int dax, day, dax2, day2, sp; - int wallfind[2]; - - startwall = sptr->wallptr; - endwall = startwall + sptr->wallnum - 1; - - sp = sptr->extra >> 4; - - //first find center point by averaging all points - dax = 0L, day = 0L; - for (i = startwall; i <= endwall; i++) - { - dax += wall[i].x; - day += wall[i].y; - } - dax /= (endwall - startwall + 1); - day /= (endwall - startwall + 1); - - //find any points with either same x or same y coordinate - // as center (dax, day) - should be 2 points found. - wallfind[0] = -1; - wallfind[1] = -1; - for (i = startwall; i <= endwall; i++) - if ((wall[i].x == dax) || (wall[i].y == day)) - { - if (wallfind[0] == -1) - wallfind[0] = i; - else wallfind[1] = i; - } - - for (j = 0; j < 2; j++) - { - if ((wall[wallfind[j]].x == dax) && (wall[wallfind[j]].y == day)) - { - //find what direction door should open by averaging the - // 2 neighboring points of wallfind[0] & wallfind[1]. - i = wallfind[j] - 1; if (i < startwall) i = endwall; - dax2 = ((wall[i].x + wall[wall[wallfind[j]].point2].x) >> 1) - wall[wallfind[j]].x; - day2 = ((wall[i].y + wall[wall[wallfind[j]].point2].y) >> 1) - wall[wallfind[j]].y; - if (dax2 != 0) - { - dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; - dax2 -= wall[wall[wallfind[j]].point2].x; - setanimation(sn, anim_vertexx, wallfind[j], wall[wallfind[j]].x + dax2, sp); - setanimation(sn, anim_vertexx, i, wall[i].x + dax2, sp); - setanimation(sn, anim_vertexx, wall[wallfind[j]].point2, wall[wall[wallfind[j]].point2].x + dax2, sp); - callsound(sn, ii); - } - else if (day2 != 0) - { - day2 = wall[wall[wall[wallfind[j]].point2].point2].y; - day2 -= wall[wall[wallfind[j]].point2].y; - setanimation(sn, anim_vertexy, wallfind[j], wall[wallfind[j]].y + day2, sp); - setanimation(sn, anim_vertexy, i, wall[i].y + day2, sp); - setanimation(sn, anim_vertexy, wall[wallfind[j]].point2, wall[wall[wallfind[j]].point2].y + day2, sp); - callsound(sn, ii); - } - } - else - { - i = wallfind[j] - 1; if (i < startwall) i = endwall; - dax2 = ((wall[i].x + wall[wall[wallfind[j]].point2].x) >> 1) - wall[wallfind[j]].x; - day2 = ((wall[i].y + wall[wall[wallfind[j]].point2].y) >> 1) - wall[wallfind[j]].y; - if (dax2 != 0) - { - setanimation(sn, anim_vertexx, wallfind[j], dax, sp); - setanimation(sn, anim_vertexx, i, dax + dax2, sp); - setanimation(sn, anim_vertexx, wall[wallfind[j]].point2, dax + dax2, sp); - callsound(sn, ii); - } - else if (day2 != 0) - { - setanimation(sn, anim_vertexy, wallfind[j], day, sp); - setanimation(sn, anim_vertexy, i, day + day2, sp); - setanimation(sn, anim_vertexy, wall[wallfind[j]].point2, day + day2, sp); - callsound(sn, ii); - } - } - } - - } - return; + handle_st09(sn, actor); + return; case ST_15_WARP_ELEVATOR://Warping elevators - { - if (sprite[ii].picnum != TILE_APLAYER) return; - // if(ps[sprite[ii].yvel].select_dir == 1) return; - - SectIterator it(sn); - while ((i = it.NextIndex()) >= 0) - { - if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == 17) break; - } - - if (sprite[ii].sectnum == sn) - { - if (activatewarpelevators(i, -1)) - activatewarpelevators(i, 1); - else if (activatewarpelevators(i, 1)) - activatewarpelevators(i, -1); - return; - } - else - { - if (sptr->floorz > sprite[i].z) - activatewarpelevators(i, -1); - else - activatewarpelevators(i, 1); - } - + handle_st15(sn, actor); return; - } + case ST_16_PLATFORM_DOWN: case ST_17_PLATFORM_UP: - - i = getanimationgoal(anim_floorz, sn); - - if (i == -1) - { - i = nextsectorneighborz(sn, sptr->floorz, 1, 1); - if (i == -1) - { - i = nextsectorneighborz(sn, sptr->floorz, 1, -1); - if (i == -1) return; - j = sector[i].floorz; - setanimation(sn, anim_floorz, sn, j, sptr->extra); - } - else - { - j = sector[i].floorz; - setanimation(sn, anim_floorz, sn, j, sptr->extra); - } - callsound(sn, ii); - } - + handle_st16(sn, actor); return; case ST_18_ELEVATOR_DOWN: case ST_19_ELEVATOR_UP: - - i = getanimationgoal(anim_floorz, sn); - - if (i == -1) - { - i = nextsectorneighborz(sn, sptr->floorz, 1, -1); - if (i == -1) i = nextsectorneighborz(sn, sptr->floorz, 1, 1); - if (i == -1) return; - j = sector[i].floorz; - q = sptr->extra; - l = sptr->ceilingz - sptr->floorz; - setanimation(sn, anim_floorz, sn, j, q); - setanimation(sn, anim_ceilingz, sn, j + l, q); - callsound(sn, ii); - } + handle_st18(sn, actor); return; case ST_29_TEETH_DOOR: - { - if (sptr->lotag & 0x8000) - j = sector[nextsectorneighborz(sn, sptr->ceilingz, 1, 1)].floorz; - else - j = sector[nextsectorneighborz(sn, sptr->ceilingz, -1, -1)].ceilingz; - - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) - { - if ((sprite[i].lotag == 22) && - (sprite[i].hitag == sptr->hitag)) - { - sector[sprite[i].sectnum].extra = -sector[sprite[i].sectnum].extra; - - hittype[i].temp_data[0] = sn; - hittype[i].temp_data[1] = 1; - } - } - - sptr->lotag ^= 0x8000; - - setanimation(sn, anim_ceilingz, sn, j, sptr->extra); - - callsound(sn, ii); - + handle_st29(sn, actor); return; - } case ST_20_CEILING_DOOR: - REDODOOR: - - if (sptr->lotag & 0x8000) - { - SectIterator it(sn); - while ((i = it.NextIndex()) >= 0) - { - if (sprite[i].statnum == 3 && sprite[i].lotag == 9) - { - j = sprite[i].z; - break; - } - } - if (i == -1) - j = sptr->floorz; - } - else - { - j = nextsectorneighborz(sn, sptr->ceilingz, -1, -1); - - if (j >= 0) j = sector[j].ceilingz; - else - { - sptr->lotag |= 32768; - goto REDODOOR; - } - } - - sptr->lotag ^= 0x8000; - - setanimation(sn, anim_ceilingz, sn, j, sptr->extra); - callsound(sn, ii); - + handle_st20(sn, actor); return; case ST_21_FLOOR_DOOR: - i = getanimationgoal(anim_floorz, sn); - if (i >= 0) - { - if (animategoal[sn] == sptr->ceilingz) - animategoal[i] = sector[nextsectorneighborz(sn, sptr->ceilingz, 1, 1)].floorz; - else animategoal[i] = sptr->ceilingz; - j = animategoal[i]; - } - else - { - if (sptr->ceilingz == sptr->floorz) - j = sector[nextsectorneighborz(sn, sptr->ceilingz, 1, 1)].floorz; - else j = sptr->ceilingz; - - sptr->lotag ^= 0x8000; - - if (setanimation(sn, anim_floorz, sn, j, sptr->extra) >= 0) - callsound(sn, ii); - } + handle_st21(sn, actor); return; case ST_22_SPLITTING_DOOR: - - if ((sptr->lotag & 0x8000)) - { - q = (sptr->ceilingz + sptr->floorz) >> 1; - j = setanimation(sn, anim_floorz, sn, q, sptr->extra); - j = setanimation(sn, anim_ceilingz, sn, q, sptr->extra); - } - else - { - q = sector[nextsectorneighborz(sn, sptr->floorz, 1, 1)].floorz; - j = setanimation(sn, anim_floorz, sn, q, sptr->extra); - q = sector[nextsectorneighborz(sn, sptr->ceilingz, -1, -1)].ceilingz; - j = setanimation(sn, anim_ceilingz, sn, q, sptr->extra); - } - - sptr->lotag ^= 0x8000; - - callsound(sn, ii); - + handle_st22(sn, actor); return; case ST_23_SWINGING_DOOR: //Swingdoor - { - j = -1; - q = 0; - - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) - { - if (sprite[i].lotag == 11 && sprite[i].sectnum == sn && !hittype[i].temp_data[4]) - { - j = i; - break; - } - } - - l = sector[sprite[i].sectnum].lotag & 0x8000; - - if (j >= 0) - { - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) - { - if (l == (sector[sprite[i].sectnum].lotag & 0x8000) && sprite[i].lotag == 11 && sprite[j].hitag == sprite[i].hitag && !hittype[i].temp_data[4]) - { - if (sector[sprite[i].sectnum].lotag & 0x8000) sector[sprite[i].sectnum].lotag &= 0x7fff; - else sector[sprite[i].sectnum].lotag |= 0x8000; - hittype[i].temp_data[4] = 1; - hittype[i].temp_data[3] = -hittype[i].temp_data[3]; - if (q == 0) - { - callsound(sn, i); - q = 1; - } - } - } - } + handle_st23(sn, actor); return; - } + case ST_25_SLIDING_DOOR: //Subway type sliding doors { - StatIterator it(STAT_EFFECTOR); - while ((j = it.NextIndex()) >= 0) - { - if ((sprite[j].lotag) == 15 && sprite[j].sectnum == sn) - break; //Found the sectoreffector. - } - - if (j < 0) - return; - - it.Reset(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) - { - if (sprite[i].hitag == sprite[j].hitag) - { - if (sprite[i].lotag == 15) - { - sector[sprite[i].sectnum].lotag ^= 0x8000; // Toggle the open or close - sprite[i].ang += 1024; - if (hittype[i].temp_data[4]) callsound(sprite[i].sectnum, i); - callsound(sprite[i].sectnum, i); - if (sector[sprite[i].sectnum].lotag & 0x8000) hittype[i].temp_data[4] = 1; - else hittype[i].temp_data[4] = 2; - } - } - } + handle_st25(sn, actor); return; } case ST_27_STRETCH_BRIDGE: //Extended bridge - { - StatIterator it(STAT_EFFECTOR); - while ((j = it.NextIndex()) >= 0) - { - if ((sprite[j].lotag & 0xff) == 20 && sprite[j].sectnum == sn) //Bridge - { - - sector[sn].lotag ^= 0x8000; - if (sector[sn].lotag & 0x8000) //OPENING - hittype[j].temp_data[0] = 1; - else hittype[j].temp_data[0] = 2; - callsound(sn, ii); - break; - } - } + handle_st27(sn, actor); return; - } case ST_28_DROP_FLOOR: - { - //activate the rest of them - - SectIterator it(sn); - while ((j = it.NextIndex()) >= 0) - { - if (sprite[j].statnum == 3 && (sprite[j].lotag & 0xff) == 21) - break; //Found it - } - - j = sprite[j].hitag; - - StatIterator it1(STAT_EFFECTOR); - while ((l = it1.NextIndex()) >= 0) - { - if ((sprite[l].lotag & 0xff) == 21 && !hittype[l].temp_data[0] && - (sprite[l].hitag) == j) - hittype[l].temp_data[0] = 1; - } - callsound(sn, ii); - + handle_st28(sn, actor); return; } - } } @@ -936,7 +1064,7 @@ void operatesectors(int sn, int ii) // //--------------------------------------------------------------------------- -void operateactivators(int low, int snum) +void operateactivators(int low, int plnum) { int i, j, k; short * p; @@ -958,66 +1086,65 @@ void operateactivators(int low, int snum) } k = -1; - StatIterator it(STAT_ACTIVATOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTIVATOR); + while (auto act = it.Next()) { - auto si = &sprite[i]; - if (si->lotag == low) + if (act->s.lotag == low) { - if (si->picnum == ACTIVATORLOCKED) + if (act->s.picnum == ACTIVATORLOCKED) { - sector[si->sectnum].lotag ^= 16384; + sector[act->s.sectnum].lotag ^= 16384; - if (snum >= 0) + if (plnum >= 0) { - if (sector[si->sectnum].lotag & 16384) - FTA(4, &ps[snum]); - else FTA(8, &ps[snum]); + if (sector[act->s.sectnum].lotag & 16384) + FTA(4, &ps[plnum]); + else FTA(8, &ps[plnum]); } } else { - switch (si->hitag) + switch (act->s.hitag) { case 0: break; case 1: - if (sector[si->sectnum].floorz != sector[si->sectnum].ceilingz) + if (sector[act->s.sectnum].floorz != sector[act->s.sectnum].ceilingz) { continue; } break; case 2: - if (sector[si->sectnum].floorz == sector[si->sectnum].ceilingz) + if (sector[act->s.sectnum].floorz == sector[act->s.sectnum].ceilingz) { continue; } break; } - if (sector[si->sectnum].lotag < 3) + if (sector[act->s.sectnum].lotag < 3) { - SectIterator it(si->sectnum); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(act->s.sectnum); + while (auto a2 = it.Next()) { - if (sprite[j].statnum == 3) switch (sprite[j].lotag) + if (a2->s.statnum == 3) switch (a2->s.lotag) { case SE_18_INCREMENTAL_SECTOR_RISE_FALL: if (isRRRA()) break; case SE_36_PROJ_SHOOTER: case SE_31_FLOOR_RISE_FALL: case SE_32_CEILING_RISE_FALL: - hittype[j].temp_data[0] = 1 - hittype[j].temp_data[0]; - callsound(si->sectnum, j); + a2->temp_data[0] = 1 - a2->temp_data[0]; + callsound(act->s.sectnum, a2); break; } } } - if (k == -1 && (sector[si->sectnum].lotag & 0xff) == 22) - k = callsound(si->sectnum, i); + if (k == -1 && (sector[act->s.sectnum].lotag & 0xff) == 22) + k = callsound(act->s.sectnum, act); - operatesectors(si->sectnum, i); + operatesectors(act->s.sectnum, act); } } } @@ -1033,13 +1160,11 @@ void operateactivators(int low, int snum) void operatemasterswitches(int low) { - int i; - - StatIterator it(STAT_STANDABLE); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_STANDABLE); + while (auto act2 = it.Next()) { - if (sprite[i].picnum == MASTERSWITCH && sprite[i].lotag == low && sprite[i].yvel == 0) - sprite[i].yvel = 1; + if (act2->s.picnum == MASTERSWITCH && act2->s.lotag == low && act2->s.yvel == 0) + act2->s.yvel = 1; } } @@ -1049,7 +1174,7 @@ void operatemasterswitches(int low) // //--------------------------------------------------------------------------- -void operateforcefields_common(int s, int low, const std::initializer_list &tiles) +void operateforcefields_common(DDukeActor *effector, int low, const std::initializer_list &tiles) { int i, p; @@ -1066,8 +1191,7 @@ void operateforcefields_common(int s, int low, const std::initializer_list { wall[i].cstat = 0; - if (s >= 0 && sprite[s].picnum == SECTOREFFECTOR && - sprite[s].lotag == 30) + if (effector && effector->s.picnum == SECTOREFFECTOR && effector->s.lotag == 30) wall[i].lotag = 0; } else @@ -1082,7 +1206,7 @@ void operateforcefields_common(int s, int low, const std::initializer_list // //--------------------------------------------------------------------------- -void breakwall(short newpn, short spr, short dawallnum) +void breakwall(short newpn, DDukeActor* spr, short dawallnum) { wall[dawallnum].picnum = newpn; S_PlayActorSound(VENT_BUST, spr); @@ -1098,22 +1222,18 @@ void breakwall(short newpn, short spr, short dawallnum) void allignwarpelevators(void) { - int i, j; - - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act = it.Next()) { - auto si = &sprite[i]; - if (si->lotag == SE_17_WARP_ELEVATOR && si->shade > 16) + if (act->s.lotag == SE_17_WARP_ELEVATOR && act->s.shade > 16) { - StatIterator it1(STAT_EFFECTOR); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(STAT_EFFECTOR); + while (auto act2 = it1.Next()) { - if ((sprite[j].lotag) == SE_17_WARP_ELEVATOR && i != j && - (si->hitag) == (sprite[j].hitag)) + if ((act2->s.lotag) == SE_17_WARP_ELEVATOR && act != act2 && act->s.hitag == act2->s.hitag) { - sector[sprite[j].sectnum].floorz = sector[si->sectnum].floorz; - sector[sprite[j].sectnum].ceilingz = sector[si->sectnum].ceilingz; + sector[act2->s.sectnum].floorz = sector[act->s.sectnum].floorz; + sector[act2->s.sectnum].ceilingz = sector[act->s.sectnum].ceilingz; } } } @@ -1128,7 +1248,7 @@ void allignwarpelevators(void) void moveclouds(double smoothratio) { - // The math here is very messy... :( + // The math here is very messy.. :( int myclock = smoothratio < 32768? ud.levelclock-2 : ud.levelclock; if (myclock > cloudclock || myclock < (cloudclock - 7)) { diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 7bbf5bcde..50b30ba21 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -187,20 +187,18 @@ void animatewalls_d(void) void operaterespawns_d(int low) { - int i, j; - - StatIterator it(STAT_FX); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_FX); + while (auto act = it.Next()) { - if (sprite[i].lotag == low) switch (sprite[i].picnum) + if (act->s.lotag == low) switch (act->s.picnum) { case RESPAWN: - if (badguypic(sprite[i].hitag) && ud.monsters_off) break; + if (badguypic(act->s.hitag) && ud.monsters_off) break; - j = fi.spawn(i, TRANSPORTERSTAR); - sprite[j].z -= (32 << 8); + auto star = spawn(act, TRANSPORTERSTAR); + star->s.z -= (32 << 8); - sprite[i].extra = 66 - 12; // Just a way to killit + act->s.extra = 66 - 12; // Just a way to killit break; } } @@ -212,9 +210,9 @@ void operaterespawns_d(int low) // //--------------------------------------------------------------------------- -void operateforcefields_d(int s, int low) +void operateforcefields_d(DDukeActor* act, int low) { - operateforcefields_common(s, low, { W_FORCEFIELD, W_FORCEFIELD + 1, W_FORCEFIELD + 2, BIGFORCE }); + operateforcefields_common(act, low, { W_FORCEFIELD, W_FORCEFIELD + 1, W_FORCEFIELD + 2, BIGFORCE }); } //--------------------------------------------------------------------------- @@ -223,35 +221,36 @@ void operateforcefields_d(int s, int low) // //--------------------------------------------------------------------------- -bool checkhitswitch_d(int snum, int w, int switchtype) +bool checkhitswitch_d(int snum, int ww, DDukeActor *act) { uint8_t switchpal; int i, x, lotag, hitag, picnum, correctdips, numdips; int sx, sy; - if (w < 0) return 0; + if (ww < 0 && act == nullptr) return 0; correctdips = 1; numdips = 0; - - if (switchtype == SWITCH_SPRITE) // A wall sprite + + if (act) { - lotag = sprite[w].lotag; + lotag = act->s.lotag; if (lotag == 0) return 0; - hitag = sprite[w].hitag; - sx = sprite[w].x; - sy = sprite[w].y; - picnum = sprite[w].picnum; - switchpal = sprite[w].pal; + hitag = act->s.hitag; + sx = act->s.x; + sy = act->s.y; + picnum = act->s.picnum; + switchpal = act->s.pal; } else { - lotag = wall[w].lotag; + auto wal = &wall[ww]; + lotag = wal->lotag; if (lotag == 0) return 0; - hitag = wall[w].hitag; - sx = wall[w].x; - sy = wall[w].y; - picnum = wall[w].picnum; - switchpal = wall[w].pal; + hitag = wal->hitag; + sx = wal->x; + sy = wal->y; + picnum = wal->picnum; + switchpal = wal->pal; } switch (picnum) @@ -264,18 +263,18 @@ bool checkhitswitch_d(int snum, int w, int switchtype) case ALIENSWITCH + 1: break; case DEVELOPERCOMMENTARY + 1: //Twentieth Anniversary World Tour - if (switchtype == 1) + if (act) { StopCommentary(); - sprite[w].picnum = DEVELOPERCOMMENTARY; + act->s.picnum = DEVELOPERCOMMENTARY; return true; } return false; case DEVELOPERCOMMENTARY: //Twentieth Anniversary World Tour - if (switchtype == 1) + if (act) { - if (StartCommentary(lotag, w)) - sprite[w].picnum = DEVELOPERCOMMENTARY+1; + if (StartCommentary(lotag, act)) + act->s.picnum = DEVELOPERCOMMENTARY+1; return true; } return false; @@ -306,10 +305,10 @@ bool checkhitswitch_d(int snum, int w, int switchtype) if (ps[snum].access_incs == 1) { - if (switchtype == SWITCH_WALL) - ps[snum].access_wallnum = w; + if (!act) + ps[snum].access_wallnum = ww; else - ps[snum].access_spritenum = w; + ps[snum].access_spritenum = act; } return 0; @@ -351,23 +350,23 @@ bool checkhitswitch_d(int snum, int w, int switchtype) break; } - StatIterator it(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DEFAULT); + while (auto other = it.Next()) { - auto si = &sprite[i]; + auto si = &other->s; if (lotag == si->lotag) switch (si->picnum) { case DIPSWITCH: case TECHSWITCH: case ALIENSWITCH: - if (switchtype == SWITCH_SPRITE && w == i) si->picnum++; + if (act && act == other) si->picnum++; else if (si->hitag == 0) correctdips++; numdips++; break; case TECHSWITCH + 1: case DIPSWITCH + 1: case ALIENSWITCH + 1: - if (switchtype == SWITCH_SPRITE && w == i) si->picnum--; + if (act && act == other) si->picnum--; else if (si->hitag == 1) correctdips++; numdips++; break; @@ -423,14 +422,14 @@ bool checkhitswitch_d(int snum, int w, int switchtype) case DIPSWITCH: case TECHSWITCH: case ALIENSWITCH: - if (switchtype == SWITCH_WALL && i == w) wall[x].picnum++; + if (!act && i == ww) wall[x].picnum++; else if (wall[x].hitag == 0) correctdips++; numdips++; break; case DIPSWITCH + 1: case TECHSWITCH + 1: case ALIENSWITCH + 1: - if (switchtype == SWITCH_WALL && i == w) wall[x].picnum--; + if (!act && i == ww) wall[x].picnum--; else if (wall[x].hitag == 1) correctdips++; numdips++; break; @@ -498,18 +497,18 @@ bool checkhitswitch_d(int snum, int w, int switchtype) { if (picnum == ALIENSWITCH || picnum == ALIENSWITCH + 1) { - if (switchtype == SWITCH_SPRITE) - S_PlaySound3D(ALIEN_SWITCH1, w, &v); - else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].i, &v); + if (act) + S_PlaySound3D(ALIEN_SWITCH1, act, &v); + else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), &v); } else { - if (switchtype == SWITCH_SPRITE) - S_PlaySound3D(SWITCH_ON, w, &v); - else S_PlaySound3D(SWITCH_ON, ps[snum].i, &v); + if (act) + S_PlaySound3D(SWITCH_ON, act, &v); + else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v); } if (numdips != correctdips) break; - S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].i, &v); + S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].GetActor(), &v); } case DIPSWITCH2: case DIPSWITCH2 + 1: @@ -548,25 +547,25 @@ bool checkhitswitch_d(int snum, int w, int switchtype) picnum == (MULTISWITCH + 2) || picnum == (MULTISWITCH + 3)) lotag += picnum - MULTISWITCH; - StatIterator it(STAT_EFFECTOR); - while ((x = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto other = it.Next()) { - if (sprite[x].hitag == lotag) + if (other->s.hitag == lotag) { - switch (sprite[x].lotag) + switch (other->s.lotag) { case SE_12_LIGHT_SWITCH: - sector[sprite[x].sectnum].floorpal = 0; - hittype[x].temp_data[0]++; - if (hittype[x].temp_data[0] == 2) - hittype[x].temp_data[0]++; + sector[other->s.sectnum].floorpal = 0; + other->temp_data[0]++; + if (other->temp_data[0] == 2) + other->temp_data[0]++; break; case SE_24_CONVEYOR: case SE_34: case SE_25_PISTON: - hittype[x].temp_data[4] = !hittype[x].temp_data[4]; - if (hittype[x].temp_data[4]) + other->temp_data[4] = !other->temp_data[4]; + if (other->temp_data[4]) FTA(15, &ps[snum]); else FTA(2, &ps[snum]); break; @@ -578,7 +577,7 @@ bool checkhitswitch_d(int snum, int w, int switchtype) } operateactivators(lotag, snum); - fi.operateforcefields(ps[snum].i, lotag); + fi.operateforcefields(ps[snum].GetActor(), lotag); operatemasterswitches(lotag); if (picnum == DIPSWITCH || picnum == DIPSWITCH + 1 || @@ -587,18 +586,18 @@ bool checkhitswitch_d(int snum, int w, int switchtype) if (hitag == 0 && fi.isadoorwall(picnum) == 0) { - if (switchtype == SWITCH_SPRITE) - S_PlaySound3D(SWITCH_ON, w, &v); - else S_PlaySound3D(SWITCH_ON, ps[snum].i, &v); + if (act) + S_PlaySound3D(SWITCH_ON, act, &v); + else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v); } else if (hitag != 0) { auto flags = S_GetUserFlags(hitag); - if (switchtype == SWITCH_SPRITE && (flags & SF_TALK) == 0) - S_PlaySound3D(hitag, w, &v); + if (act && (flags & SF_TALK) == 0) + S_PlaySound3D(hitag, act, &v); else - S_PlayActorSound(hitag, ps[snum].i); + S_PlayActorSound(hitag, ps[snum].GetActor()); } return 1; @@ -612,25 +611,25 @@ bool checkhitswitch_d(int snum, int w, int switchtype) // //--------------------------------------------------------------------------- -void activatebysector_d(int sect, int j) +void activatebysector_d(int sect, DDukeActor* activator) { - short i, didit; + short didit; didit = 0; - SectIterator it(sect); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto act = it.Next()) { - if (sprite[i].picnum == ACTIVATOR) + if (act->s.picnum == ACTIVATOR) { - operateactivators(sprite[i].lotag, -1); + operateactivators(act->s.lotag, -1); didit = 1; // return; } } if (didit == 0) - operatesectors(sect, j); + operatesectors(sect, activator); } //--------------------------------------------------------------------------- @@ -639,9 +638,9 @@ void activatebysector_d(int sect, int j) // //--------------------------------------------------------------------------- -void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) +void checkhitwall_d(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith) { - short j, i, sn = -1, darkestwall; + short j, sn = -1, darkestwall; walltype* wal; wal = &wall[dawallnum]; @@ -675,26 +674,26 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) case W_FORCEFIELD + 2: wal->extra = 1; // tell the forces to animate case BIGFORCE: + { updatesector(x, y, &sn); if (sn < 0) return; - + DDukeActor* spawned; if (atwith == -1) - i = EGS(sn, x, y, z, FORCERIPPLE, -127, 8, 8, 0, 0, 0, spr, 5); + spawned = EGS(sn, x, y, z, FORCERIPPLE, -127, 8, 8, 0, 0, 0, spr, 5); else { if (atwith == CHAINGUN) - i = EGS(sn, x, y, z, FORCERIPPLE, -127, 16 + sprite[spr].xrepeat, 16 + sprite[spr].yrepeat, 0, 0, 0, spr, 5); - else i = EGS(sn, x, y, z, FORCERIPPLE, -127, 32, 32, 0, 0, 0, spr, 5); + spawned = EGS(sn, x, y, z, FORCERIPPLE, -127, 16 + spr->s.xrepeat, 16 + spr->s.yrepeat, 0, 0, 0, spr, 5); + else spawned = EGS(sn, x, y, z, FORCERIPPLE, -127, 32, 32, 0, 0, 0, spr, 5); } - sprite[i].cstat |= 18 + 128; - sprite[i].ang = getangle(wal->x - wall[wal->point2].x, - wal->y - wall[wal->point2].y) - 512; + spawned->s.cstat |= 18 + 128; + spawned->s.ang = getangle(wal->x - wall[wal->point2].x, wal->y - wall[wal->point2].y) - 512; - S_PlayActorSound(SOMETHINGHITFORCE, i); + S_PlayActorSound(SOMETHINGHITFORCE, spawned); return; - + } case FANSPRITE: wal->overpicnum = FANSPRITEBROKE; wal->cstat &= 65535 - 65; @@ -708,6 +707,7 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) return; case GLASS: + { updatesector(x, y, &sn); if (sn < 0) return; wal->overpicnum = GLASS2; lotsofglass(spr, dawallnum, 10); @@ -716,10 +716,13 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) if (wal->nextwall >= 0) wall[wal->nextwall].cstat = 0; - i = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3); - sprite[i].lotag = 128; hittype[i].temp_data[1] = 5; hittype[i].temp_data[2] = dawallnum; - S_PlayActorSound(GLASS_BREAKING, i); + auto spawned = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3); + spawned->s.lotag = 128; + spawned->temp_data[1] = 5; + spawned->temp_data[2] = dawallnum; + S_PlayActorSound(GLASS_BREAKING, spawned); return; + } case STAINGLASS1: updatesector(x, y, &sn); if (sn < 0) return; lotsofcolourglass(spr, dawallnum, 80); @@ -816,7 +819,7 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) case ATM: wal->picnum = ATMBROKE; - fi.lotsofmoney(&hittype[spr], 1 + (krand() & 7)); + fi.lotsofmoney(spr, 1 + (krand() & 7)); S_PlayActorSound(GLASS_HEAVYBREAK, spr); break; @@ -857,19 +860,19 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) darkestwall = 0; wal = &wall[sector[sn].wallptr]; - for (i = sector[sn].wallnum; i > 0; i--, wal++) + for (int i = sector[sn].wallnum; i > 0; i--, wal++) if (wal->shade > darkestwall) darkestwall = wal->shade; j = krand() & 1; - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto effector = it.Next()) { - if (sprite[i].hitag == wall[dawallnum].lotag && sprite[i].lotag == 3) + if (effector->s.hitag == wall[dawallnum].lotag && effector->s.lotag == 3) { - hittype[i].temp_data[2] = j; - hittype[i].temp_data[3] = darkestwall; - hittype[i].temp_data[4] = 1; + effector->temp_data[2] = j; + effector->temp_data[3] = darkestwall; + effector->temp_data[4] = 1; } } break; @@ -882,29 +885,27 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) // //--------------------------------------------------------------------------- -void checkplayerhurt_d(struct player_struct* p, int j) +void checkplayerhurt_d(struct player_struct* p, const Collision& coll) { - if ((j & 49152) == 49152) + if (coll.type == kHitSprite) { - j &= (MAXSPRITES - 1); - - switch (sprite[j].picnum) + switch (coll.actor->s.picnum) { case CACTUS: if (p->hurt_delay < 8) { - sprite[p->i].extra -= 5; + p->GetActor()->s.extra -= 5; p->hurt_delay = 16; SetPlayerPal(p, PalEntry(32, 32, 0, 0)); - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, p->GetActor()); } break; } return; } - if ((j & 49152) != 32768) return; - j &= (MAXWALLS - 1); + if (coll.type != kHitWall) return; + int j = coll.index; if (p->hurt_delay > 0) p->hurt_delay--; else if (wall[j].cstat & 85) switch (wall[j].overpicnum) @@ -912,16 +913,16 @@ void checkplayerhurt_d(struct player_struct* p, int j) case W_FORCEFIELD: case W_FORCEFIELD + 1: case W_FORCEFIELD + 2: - sprite[p->i].extra -= 5; + p->GetActor()->s.extra -= 5; p->hurt_delay = 16; SetPlayerPal(p, PalEntry(32, 32, 0, 0)); p->posxv = -(sintable[(p->angle.ang.asbuild() + 512) & 2047] << 8); p->posyv = -(sintable[(p->angle.ang.asbuild()) & 2047] << 8); - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, p->GetActor()); - fi.checkhitwall(p->i, j, + fi.checkhitwall(p->GetActor(), j, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 9), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 9), p->posz, -1); @@ -930,7 +931,7 @@ void checkplayerhurt_d(struct player_struct* p, int j) case BIGFORCE: p->hurt_delay = 26; - fi.checkhitwall(p->i, j, + fi.checkhitwall(p->GetActor(), j, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 9), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 9), p->posz, -1); @@ -947,7 +948,7 @@ void checkplayerhurt_d(struct player_struct* p, int j) bool checkhitceiling_d(int sn) { - int i, j; + int j; switch (sector[sn].ceilingpicnum) { @@ -958,8 +959,8 @@ bool checkhitceiling_d(int sn) case TECHLIGHT2: case TECHLIGHT4: - ceilingglass(ps[myconnectindex].i, sn, 10); - S_PlayActorSound(GLASS_BREAKING, ps[screenpeek].i); + ceilingglass(ps[myconnectindex].GetActor(), sn, 10); + S_PlayActorSound(GLASS_BREAKING, ps[screenpeek].GetActor()); if (sector[sn].ceilingpicnum == WALLLIGHT1) sector[sn].ceilingpicnum = WALLLIGHTBUST1; @@ -982,16 +983,16 @@ bool checkhitceiling_d(int sn) if (!sector[sn].hitag) { - SectIterator it(sn); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sn); + while (auto act = it.Next()) { - if (sprite[i].picnum == SECTOREFFECTOR && sprite[i].lotag == 12) + if (act->s.picnum == SECTOREFFECTOR && act->s.lotag == 12) { - StatIterator it1(STAT_EFFECTOR); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(STAT_EFFECTOR); + while (auto act2 = it1.Next()) { - if (sprite[j].hitag == sprite[i].hitag) - hittype[j].temp_data[3] = 1; + if (act2->s.hitag == act->s.hitag) + act2->temp_data[3] = 1; } break; } @@ -999,13 +1000,13 @@ bool checkhitceiling_d(int sn) } j = krand() & 1; - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act = it.Next()) { - if (sprite[i].hitag == (sector[sn].hitag) && sprite[i].lotag == 3) + if (act->s.hitag == (sector[sn].hitag) && act->s.lotag == 3) { - hittype[i].temp_data[2] = j; - hittype[i].temp_data[4] = 1; + act->temp_data[2] = j; + act->temp_data[4] = 1; } } @@ -1021,12 +1022,11 @@ bool checkhitceiling_d(int sn) // //--------------------------------------------------------------------------- -void checkhitsprite_d(int i, int sn) +void checkhitsprite_d(DDukeActor* targ, DDukeActor* proj) { int j, k, p; - - i &= (MAXSPRITES - 1); - spritetype* s = &sprite[i]; + spritetype* s = &targ->s; + auto pspr = &proj->s; switch (s->picnum) { @@ -1034,9 +1034,9 @@ void checkhitsprite_d(int i, int sn) case WTGLASS2: if (!isWorldTour()) break; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); - deletesprite(i); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); + deletesprite(targ); return; case OCEANSPRITE1: @@ -1044,30 +1044,30 @@ void checkhitsprite_d(int i, int sn) case OCEANSPRITE3: case OCEANSPRITE4: case OCEANSPRITE5: - fi.spawn(i, SMALLSMOKE); - deletesprite(i); + spawn(targ, SMALLSMOKE); + deletesprite(targ); break; case QUEBALL: case STRIPEBALL: - if (sprite[sn].picnum == QUEBALL || sprite[sn].picnum == STRIPEBALL) + if (pspr->picnum == QUEBALL || pspr->picnum == STRIPEBALL) { - sprite[sn].xvel = (s->xvel >> 1) + (s->xvel >> 2); - sprite[sn].ang -= (s->ang << 1) + 1024; - s->ang = getangle(s->x - sprite[sn].x, s->y - sprite[sn].y) - 512; + pspr->xvel = (s->xvel >> 1) + (s->xvel >> 2); + pspr->ang -= (s->ang << 1) + 1024; + s->ang = getangle(s->x - pspr->x, s->y - pspr->y) - 512; if (S_CheckSoundPlaying(POOLBALLHIT) < 2) - S_PlayActorSound(POOLBALLHIT, i); + S_PlayActorSound(POOLBALLHIT, targ); } else { if (krand() & 3) { s->xvel = 164; - s->ang = sprite[sn].ang; + s->ang = pspr->ang; } else { - lotsofglass(i, -1, 3); - deletesprite(i); + lotsofglass(targ, -1, 3); + deletesprite(targ); } } break; @@ -1076,25 +1076,25 @@ void checkhitsprite_d(int i, int sn) case TIRE: case CONE: case BOX: - switch (sprite[sn].picnum) + switch (pspr->picnum) { case RADIUSEXPLOSION: case RPG: case FIRELASER: case HYDRENT: case HEAVYHBOMB: - if (hittype[i].temp_data[0] == 0) + if (targ->temp_data[0] == 0) { s->cstat &= ~257; - hittype[i].temp_data[0] = 1; - fi.spawn(i, BURNING); + targ->temp_data[0] = 1; + spawn(targ, BURNING); } break; } break; case CACTUS: // case CACTUSBROKE: - switch (sprite[sn].picnum) + switch (pspr->picnum) { case RADIUSEXPLOSION: case RPG: @@ -1103,8 +1103,8 @@ void checkhitsprite_d(int i, int sn) case HEAVYHBOMB: for (k = 0; k < 64; k++) { - j = EGS(s->sectnum, s->x, s->y, s->z - (krand() % (48 << 8)), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), i, 5); - sprite[j].pal = 8; + auto j = EGS(s->sectnum, s->x, s->y, s->z - (krand() % (48 << 8)), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), targ, 5); + j->s.pal = 8; } if (s->picnum == CACTUS) @@ -1118,9 +1118,9 @@ void checkhitsprite_d(int i, int sn) case HANGLIGHT: case GENERICPOLE2: for (k = 0; k < 6; k++) - EGS(s->sectnum, s->x, s->y, s->z - (8 << 8), SCRAP1 + (krand() & 15), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), i, 5); - S_PlayActorSound(GLASS_HEAVYBREAK, i); - deletesprite(i); + EGS(s->sectnum, s->x, s->y, s->z - (8 << 8), SCRAP1 + (krand() & 15), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), targ, 5); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + deletesprite(targ); break; @@ -1130,8 +1130,8 @@ void checkhitsprite_d(int i, int sn) if (sector[s->sectnum].floorpicnum == FANSHADOW) sector[s->sectnum].floorpicnum = FANSHADOWBROKE; - S_PlayActorSound(GLASS_HEAVYBREAK, i); - for (j = 0; j < 16; j++) RANDOMSCRAP(s, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + for (j = 0; j < 16; j++) RANDOMSCRAP(targ); break; case WATERFOUNTAIN: @@ -1139,19 +1139,19 @@ void checkhitsprite_d(int i, int sn) case WATERFOUNTAIN + 2: case WATERFOUNTAIN + 3: s->picnum = WATERFOUNTAINBROKE; - fi.spawn(i, TOILETWATER); + spawn(targ, TOILETWATER); break; case SATELITE: case FUELPOD: case SOLARPANNEL: case ANTENNA: - if (actorinfo[SHOTSPARK1].scriptaddress && sprite[sn].extra != ScriptCode[actorinfo[SHOTSPARK1].scriptaddress]) + if (actorinfo[SHOTSPARK1].scriptaddress && pspr->extra != ScriptCode[actorinfo[SHOTSPARK1].scriptaddress]) { for (j = 0; j < 15; j++) EGS(s->sectnum, s->x, s->y, sector[s->sectnum].floorz - (12 << 8) - (j << 9), SCRAP1 + (krand() & 15), -8, 64, 64, - krand() & 2047, (krand() & 127) + 64, -(krand() & 511) - 256, i, 5); - fi.spawn(i, EXPLOSION2); - deletesprite(i); + krand() & 2047, (krand() & 127) + 64, -(krand() & 511) - 256, targ, 5); + spawn(targ, EXPLOSION2); + deletesprite(targ); } break; case BOTTLE1: @@ -1183,59 +1183,62 @@ void checkhitsprite_d(int i, int sn) case STATUEFLASH: case STATUE: if (s->picnum == BOTTLE10) - fi.lotsofmoney(&hittype[i], 4 + (krand() & 3)); + fi.lotsofmoney(targ, 4 + (krand() & 3)); else if (s->picnum == STATUE || s->picnum == STATUEFLASH) { - lotsofcolourglass(i, -1, 40); - S_PlayActorSound(GLASS_HEAVYBREAK, i); + lotsofcolourglass(targ, -1, 40); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); } else if (s->picnum == VASE) - lotsofglass(i, -1, 40); + lotsofglass(targ, -1, 40); - S_PlayActorSound(GLASS_BREAKING, i); + S_PlayActorSound(GLASS_BREAKING, targ); s->ang = krand() & 2047; - lotsofglass(i, -1, 8); - deletesprite(i); + lotsofglass(targ, -1, 8); + deletesprite(targ); break; case FETUS: s->picnum = FETUSBROKE; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case FETUSBROKE: for (j = 0; j < 48; j++) { - fi.shoot(i, BLOODSPLAT1); + fi.shoot(targ, BLOODSPLAT1); s->ang += 333; } - S_PlayActorSound(GLASS_HEAVYBREAK, i); - S_PlayActorSound(SQUISHED, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + S_PlayActorSound(SQUISHED, targ); case BOTTLE7: - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); - deletesprite(i); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); + deletesprite(targ); break; case HYDROPLANT: s->picnum = BROKEHYDROPLANT; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case FORCESPHERE: s->xrepeat = 0; - hittype[s->owner].temp_data[0] = 32; - hittype[s->owner].temp_data[1] = !hittype[s->owner].temp_data[1]; - hittype[s->owner].temp_data[2] ++; - fi.spawn(i, EXPLOSION2); + if (targ->GetOwner()) + { + targ->GetOwner()->temp_data[0] = 32; + targ->GetOwner()->temp_data[1] = !targ->GetOwner()->temp_data[1]; + targ->GetOwner()->temp_data[2] ++; + } + spawn(targ, EXPLOSION2); break; case BROKEHYDROPLANT: if (s->cstat & 1) { - S_PlayActorSound(GLASS_BREAKING, i); + S_PlayActorSound(GLASS_BREAKING, targ); s->z += 16 << 8; s->cstat = 0; - lotsofglass(i, -1, 5); + lotsofglass(targ, -1, 5); } break; @@ -1243,51 +1246,45 @@ void checkhitsprite_d(int i, int sn) s->picnum = TOILETBROKE; s->cstat |= (krand() & 1) << 2; s->cstat &= ~257; - fi.spawn(i, TOILETWATER); - S_PlayActorSound(GLASS_BREAKING, i); + spawn(targ, TOILETWATER); + S_PlayActorSound(GLASS_BREAKING, targ); break; case STALL: s->picnum = STALLBROKE; s->cstat |= (krand() & 1) << 2; s->cstat &= ~257; - fi.spawn(i, TOILETWATER); - S_PlayActorSound(GLASS_HEAVYBREAK, i); + spawn(targ, TOILETWATER); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case HYDRENT: s->picnum = BROKEFIREHYDRENT; - fi.spawn(i, TOILETWATER); - - // for(k=0;k<5;k++) - // { - // j = EGS(s->sectnum,s->x,s->y,s->z-(krand()%(48<<8)),SCRAP3+(krand()&3),-8,48,48,krand()&2047,(krand()&63)+64,-(krand()&4095)-(s->zvel>>2),i,5); - // sprite[j].pal = 2; - // } - S_PlayActorSound(GLASS_HEAVYBREAK, i); + spawn(targ, TOILETWATER); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case GRATE1: s->picnum = BGRATE1; s->cstat &= (65535 - 256 - 1); - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case CIRCLEPANNEL: s->picnum = CIRCLEPANNELBROKE; s->cstat &= (65535 - 256 - 1); - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case PANNEL1: case PANNEL2: s->picnum = BPANNEL1; s->cstat &= (65535 - 256 - 1); - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case PANNEL3: s->picnum = BPANNEL3; s->cstat &= (65535 - 256 - 1); - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case PIPE1: case PIPE2: @@ -1304,45 +1301,48 @@ void checkhitsprite_d(int i, int sn) case PIPE5:s->picnum = PIPE5B; break; case PIPE6:s->picnum = PIPE6B; break; } - - j = fi.spawn(i, STEAM); - sprite[j].z = sector[s->sectnum].floorz - (32 << 8); + { + auto j = spawn(targ, STEAM); + j->s.z = sector[s->sectnum].floorz - (32 << 8); + } break; case MONK: case LUKE: case INDY: case JURYGUY: - S_PlayActorSound(s->lotag, i); - fi.spawn(i, s->hitag); + S_PlayActorSound(s->lotag, targ); + spawn(targ, s->hitag); case SPACEMARINE: - s->extra -= sprite[sn].extra; + { + s->extra -= pspr->extra; if (s->extra > 0) break; s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT1); + fi.shoot(targ, BLOODSPLAT1); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT2); + fi.shoot(targ, BLOODSPLAT2); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT3); + fi.shoot(targ, BLOODSPLAT3); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT4); + fi.shoot(targ, BLOODSPLAT4); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT1); + fi.shoot(targ, BLOODSPLAT1); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT2); + fi.shoot(targ, BLOODSPLAT2); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT3); + fi.shoot(targ, BLOODSPLAT3); s->ang = krand() & 2047; - fi.shoot(i, BLOODSPLAT4); - fi.guts(s, JIBS1, 1, myconnectindex); - fi.guts(s, JIBS2, 2, myconnectindex); - fi.guts(s, JIBS3, 3, myconnectindex); - fi.guts(s, JIBS4, 4, myconnectindex); - fi.guts(s, JIBS5, 1, myconnectindex); - fi.guts(s, JIBS3, 6, myconnectindex); + fi.shoot(targ, BLOODSPLAT4); + fi.guts(targ, JIBS1, 1, myconnectindex); + fi.guts(targ, JIBS2, 2, myconnectindex); + fi.guts(targ, JIBS3, 3, myconnectindex); + fi.guts(targ, JIBS4, 4, myconnectindex); + fi.guts(targ, JIBS5, 1, myconnectindex); + fi.guts(targ, JIBS3, 6, myconnectindex); S_PlaySound(SQUISHED); - deletesprite(i); + deletesprite(targ); break; + } case CHAIR1: case CHAIR2: s->picnum = BROKENCHAIR; @@ -1358,118 +1358,121 @@ void checkhitsprite_d(int i, int sn) case POT2: case POT3: case TRIPODCAMERA: - S_PlayActorSound(GLASS_HEAVYBREAK, i); - for (j = 0; j < 16; j++) RANDOMSCRAP(s, i); - deletesprite(i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + for (j = 0; j < 16; j++) RANDOMSCRAP(targ); + deletesprite(targ); break; case PLAYERONWATER: - i = s->owner; - s = &sprite[i]; + targ = targ->GetOwner(); + if (!targ) break; + s = &targ->s; default: if ((s->cstat & 16) && s->hitag == 0 && s->lotag == 0 && s->statnum == 0) break; - if ((sprite[sn].picnum == FREEZEBLAST || sprite[sn].owner != i) && s->statnum != 4) + if ((pspr->picnum == FREEZEBLAST || proj->GetOwner() != targ) && s->statnum != 4) { - if (badguy(&sprite[i]) == 1) + if (badguy(targ) == 1) { if (isWorldTour() && s->picnum == FIREFLY && s->xrepeat < 48) break; - if (sprite[sn].picnum == RPG) sprite[sn].extra <<= 1; + if (pspr->picnum == RPG) pspr->extra <<= 1; if ((s->picnum != DRONE) && (s->picnum != ROTATEGUN) && (s->picnum != COMMANDER) && (s->picnum < GREENSLIME || s->picnum > GREENSLIME + 7)) - if (sprite[sn].picnum != FREEZEBLAST) + if (pspr->picnum != FREEZEBLAST) //if (actortype[s->picnum] == 0) //TRANSITIONAL. Cannot be done right with EDuke mess backing the engine. { - j = fi.spawn(sn, JIBS6); - if (sprite[sn].pal == 6) - sprite[j].pal = 6; - sprite[j].z += (4 << 8); - sprite[j].xvel = 16; - sprite[j].xrepeat = sprite[j].yrepeat = 24; - sprite[j].ang += 32 - (krand() & 63); + auto spawned = spawn(proj, JIBS6); + if (pspr->pal == 6) + spawned->s.pal = 6; + spawned->s.z += (4 << 8); + spawned->s.xvel = 16; + spawned->s.xrepeat = spawned->s.yrepeat = 24; + spawned->s.ang += 32 - (krand() & 63); } - j = sprite[sn].owner; + auto Owner = proj->GetOwner(); - if (j >= 0 && sprite[j].picnum == APLAYER && s->picnum != ROTATEGUN && s->picnum != DRONE) - if (ps[sprite[j].yvel].curr_weapon == SHOTGUN_WEAPON) + if (Owner && Owner->s.picnum == APLAYER && s->picnum != ROTATEGUN && s->picnum != DRONE) + if (ps[Owner->PlayerIndex()].curr_weapon == SHOTGUN_WEAPON) { - fi.shoot(i, BLOODSPLAT3); - fi.shoot(i, BLOODSPLAT1); - fi.shoot(i, BLOODSPLAT2); - fi.shoot(i, BLOODSPLAT4); + fi.shoot(targ, BLOODSPLAT3); + fi.shoot(targ, BLOODSPLAT1); + fi.shoot(targ, BLOODSPLAT2); + fi.shoot(targ, BLOODSPLAT4); } - if (s->picnum != TANK && !bossguy(&sprite[i]) && s->picnum != RECON && s->picnum != ROTATEGUN) + if (s->picnum != TANK && !bossguy(targ) && s->picnum != RECON && s->picnum != ROTATEGUN) { if ((s->cstat & 48) == 0) - s->ang = (sprite[sn].ang + 1024) & 2047; - s->xvel = -(sprite[sn].extra << 2); + s->ang = (pspr->ang + 1024) & 2047; + s->xvel = -(pspr->extra << 2); short j = s->sectnum; - pushmove(&s->x, &s->y, &s->z, &j, 128L, (4L << 8), (4L << 8), CLIPMASK0); + pushmove(&s->x, &s->y, &s->z, &j, 128L, (4 << 8), (4 << 8), CLIPMASK0); if (j != s->sectnum && j >= 0 && j < MAXSECTORS) - changespritesect(i, j); + changespritesect(targ, j); } if (s->statnum == 2) { - changespritestat(i, 1); - hittype[i].timetosleep = SLEEPTIME; + changespritestat(targ, 1); + targ->timetosleep = SLEEPTIME; } - if ((s->xrepeat < 24 || s->picnum == SHARK) && sprite[sn].picnum == SHRINKSPARK) return; + if ((s->xrepeat < 24 || s->picnum == SHARK) && pspr->picnum == SHRINKSPARK) return; } if (s->statnum != 2) { - if (sprite[sn].picnum == FREEZEBLAST && ((s->picnum == APLAYER && s->pal == 1) || (freezerhurtowner == 0 && sprite[sn].owner == i))) + if (pspr->picnum == FREEZEBLAST && ((s->picnum == APLAYER && s->pal == 1) || (freezerhurtowner == 0 && proj->GetOwner() == targ))) return; - int hitpic = sprite[sn].picnum; - if (sprite[sprite[sn].owner].picnum == APLAYER) + int hitpic = pspr->picnum; + auto Owner = proj->GetOwner(); + if (Owner && Owner->s.picnum == APLAYER) { if (s->picnum == APLAYER && ud.coop != 0 && ud.ffire == 0) return; - if (isWorldTour() && hitpic == FIREBALL && sprite[s->owner].picnum != FIREBALL) + auto tOwner = targ->GetOwner(); + if (isWorldTour() && hitpic == FIREBALL && tOwner && tOwner->s.picnum != FIREBALL) hitpic = FLAMETHROWERFLAME; } - hittype[i].picnum = hitpic; - hittype[i].extra += sprite[sn].extra; - hittype[i].ang = sprite[sn].ang; - hittype[i].owner = sprite[sn].owner; + targ->picnum = hitpic; + targ->extra += pspr->extra; + targ->ang = pspr->ang; + targ->SetHitOwner(Owner); } if (s->statnum == 10) { p = s->yvel; - if (ps[p].newowner >= 0) + if (ps[p].newOwner != nullptr) { - ps[p].newowner = -1; + ps[p].newOwner = nullptr; ps[p].posx = ps[p].oposx; ps[p].posy = ps[p].oposy; ps[p].posz = ps[p].oposz; ps[p].angle.restore(); updatesector(ps[p].posx, ps[p].posy, &ps[p].cursectnum); - setpal(&ps[p]); - StatIterator it(STAT_ACTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto j = it.Next()) { - if (sprite[j].picnum == CAMERA1) sprite[j].yvel = 0; + if (j->s.picnum == CAMERA1) j->s.yvel = 0; } } - if (s->xrepeat < 24 && sprite[sn].picnum == SHRINKSPARK) + if (s->xrepeat < 24 && pspr->picnum == SHRINKSPARK) return; - if (sprite[hittype[i].owner].picnum != APLAYER) + auto hitowner = targ->GetHitOwner(); + if (!hitowner || hitowner->s.picnum != APLAYER) if (ud.player_skill >= 3) - sprite[sn].extra += (sprite[sn].extra >> 1); + pspr->extra += (pspr->extra >> 1); } } @@ -1488,10 +1491,12 @@ void checksectors_d(int snum) int i = -1, oldz; struct player_struct* p; int j, hitscanwall; - short neartagsector, neartagwall, neartagsprite; + short neartagsector, neartagwall; + DDukeActor* neartagsprite; int neartaghitdist; p = &ps[snum]; + auto pact = p->GetActor(); switch (sector[p->cursectnum].lotag) { @@ -1514,7 +1519,7 @@ void checksectors_d(int snum) if (sector[p->cursectnum].lotag >= 10000 && sector[p->cursectnum].lotag < 16383) { if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(sector[p->cursectnum].lotag - 10000, p->i); + S_PlayActorSound(sector[p->cursectnum].lotag - 10000, pact); sector[p->cursectnum].lotag = 0; } break; @@ -1523,12 +1528,12 @@ void checksectors_d(int snum) //After this point the the player effects the map with space - if (chatmodeon || sprite[p->i].extra <= 0) return; + if (chatmodeon || p->GetActor()->s.extra <= 0) return; if (ud.cashman && PlayerInput(snum, SB_OPEN)) - fi.lotsofmoney(&hittype[p->i], 2); + fi.lotsofmoney(p->GetActor(), 2); - if (p->newowner >= 0) + if (p->newOwner != nullptr) { if (abs(PlayerInputSideVel(snum)) > 768 || abs(PlayerInputForwardVel(snum)) > 768) { @@ -1545,7 +1550,7 @@ void checksectors_d(int snum) if (PlayerInput(snum, SB_ESCAPE)) { - if (p->newowner >= 0) + if (p->newOwner != nullptr) { i = -1; goto CLEARCAMERAS; @@ -1553,7 +1558,7 @@ void checksectors_d(int snum) return; } - neartagsprite = -1; + neartagsprite = nullptr; p->toggle_key_flag = 1; hitscanwall = -1; @@ -1562,7 +1567,7 @@ void checksectors_d(int snum) if (i < 1280 && hitscanwall >= 0 && wall[hitscanwall].overpicnum == MIRROR) if (wall[hitscanwall].lotag > 0 && S_CheckSoundPlaying(wall[hitscanwall].lotag) == 0 && snum == screenpeek) { - S_PlayActorSound(wall[hitscanwall].lotag, p->i); + S_PlayActorSound(wall[hitscanwall].lotag, pact); return; } @@ -1570,21 +1575,21 @@ void checksectors_d(int snum) if (wall[hitscanwall].lotag) return; - if (p->newowner >= 0) - neartag(p->oposx, p->oposy, p->oposz, sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (p->newOwner != nullptr) + neartag(p->oposx, p->oposy, p->oposz, p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); else { - neartag(p->posx, p->posy, p->posz, sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); - if (neartagsprite == -1 && neartagwall == -1 && neartagsector == -1) - neartag(p->posx, p->posy, p->posz + (8 << 8), sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); - if (neartagsprite == -1 && neartagwall == -1 && neartagsector == -1) - neartag(p->posx, p->posy, p->posz + (16 << 8), sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); - if (neartagsprite == -1 && neartagwall == -1 && neartagsector == -1) + neartag(p->posx, p->posy, p->posz, p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (neartagsprite == nullptr && neartagwall == -1 && neartagsector == -1) + neartag(p->posx, p->posy, p->posz + (8 << 8), p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (neartagsprite == nullptr && neartagwall == -1 && neartagsector == -1) + neartag(p->posx, p->posy, p->posz + (16 << 8), p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (neartagsprite == nullptr && neartagwall == -1 && neartagsector == -1) { - neartag(p->posx, p->posy, p->posz + (16 << 8), sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 3); - if (neartagsprite >= 0) + neartag(p->posx, p->posy, p->posz + (16 << 8), p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 3); + if (neartagsprite != nullptr) { - switch (sprite[neartagsprite].picnum) + switch (neartagsprite->s.picnum) { case FEM1: case FEM2: @@ -1604,37 +1609,40 @@ void checksectors_d(int snum) } } - neartagsprite = -1; + neartagsprite = nullptr; neartagwall = -1; neartagsector = -1; } } - if (p->newowner == -1 && neartagsprite == -1 && neartagsector == -1 && neartagwall == -1) - if (isanunderoperator(sector[sprite[p->i].sectnum].lotag)) - neartagsector = sprite[p->i].sectnum; + if (p->newOwner == nullptr && neartagsprite == nullptr && neartagsector == -1 && neartagwall == -1) + if (isanunderoperator(sector[p->GetActor()->s.sectnum].lotag)) + neartagsector = p->GetActor()->s.sectnum; if (neartagsector >= 0 && (sector[neartagsector].lotag & 16384)) return; - if (neartagsprite == -1 && neartagwall == -1) + if (neartagsprite == nullptr && neartagwall == -1) if (sector[p->cursectnum].lotag == 2) { - oldz = hitasprite(p->i, &neartagsprite); - if (oldz > 1280) neartagsprite = -1; + DDukeActor* hit; + oldz = hitasprite(p->GetActor(), &hit); + if (hit) neartagsprite = hit; + if (oldz > 1280) neartagsprite = nullptr; + } - if (neartagsprite >= 0) + if (neartagsprite != nullptr) { - if (fi.checkhitswitch(snum, neartagsprite, 1)) return; + if (fi.checkhitswitch(snum, -1, neartagsprite)) return; - switch (sprite[neartagsprite].picnum) + switch (neartagsprite->s.picnum) { case TOILET: case STALL: if (p->last_pissed_time == 0) { - S_PlayActorSound(DUKE_URINATE, p->i); + S_PlayActorSound(DUKE_URINATE, p->GetActor()); p->last_pissed_time = 26 * 220; p->transporter_hold = 29 * 2; @@ -1643,15 +1651,15 @@ void checksectors_d(int snum) p->holster_weapon = 1; p->weapon_pos = -1; } - if (sprite[p->i].extra <= (max_player_health - (max_player_health / 10))) + if (p->GetActor()->s.extra <= (max_player_health - (max_player_health / 10))) { - sprite[p->i].extra += max_player_health / 10; - p->last_extra = sprite[p->i].extra; + p->GetActor()->s.extra += max_player_health / 10; + p->last_extra = p->GetActor()->s.extra; } - else if (sprite[p->i].extra < max_player_health) - sprite[p->i].extra = max_player_health; + else if (p->GetActor()->s.extra < max_player_health) + p->GetActor()->s.extra = max_player_health; } - else if (S_CheckSoundPlaying(neartagsprite, FLUSH_TOILET) == 0) + else if (S_CheckActorSoundPlaying(neartagsprite, FLUSH_TOILET) == 0) S_PlayActorSound(FLUSH_TOILET, neartagsprite); return; @@ -1659,60 +1667,61 @@ void checksectors_d(int snum) hitawall(p, &j); if (j >= 0 && wall[j].overpicnum == 0) - if (hittype[neartagsprite].temp_data[0] == 0) + if (neartagsprite->temp_data[0] == 0) { - hittype[neartagsprite].temp_data[0] = 1; - sprite[neartagsprite].owner = p->i; - p->buttonpalette = sprite[neartagsprite].pal; + neartagsprite->temp_data[0] = 1; + neartagsprite->SetOwner(p->GetActor()); + p->buttonpalette = neartagsprite->s.pal; if (p->buttonpalette) - ud.secretlevel = sprite[neartagsprite].lotag; + ud.secretlevel = neartagsprite->s.lotag; else ud.secretlevel = 0; } return; case WATERFOUNTAIN: - if (hittype[neartagsprite].temp_data[0] != 1) + if (neartagsprite->temp_data[0] != 1) { - hittype[neartagsprite].temp_data[0] = 1; - sprite[neartagsprite].owner = p->i; + neartagsprite->temp_data[0] = 1; + neartagsprite->SetOwner(p->GetActor()); - if (sprite[p->i].extra < max_player_health) + if (p->GetActor()->s.extra < max_player_health) { - sprite[p->i].extra++; - S_PlayActorSound(DUKE_DRINKING, p->i); + p->GetActor()->s.extra++; + S_PlayActorSound(DUKE_DRINKING, p->GetActor()); } } return; case PLUG: - S_PlayActorSound(SHORT_CIRCUIT, p->i); - sprite[p->i].extra -= 2 + (krand() & 3); + S_PlayActorSound(SHORT_CIRCUIT, pact); + p->GetActor()->s.extra -= 2 + (krand() & 3); SetPlayerPal(p, PalEntry(32, 48, 48, 64)); break; case VIEWSCREEN: case VIEWSCREEN2: { - StatIterator it(STAT_ACTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto acti = it.Next()) { - if (sprite[i].picnum == CAMERA1 && sprite[i].yvel == 0 && sprite[neartagsprite].hitag == sprite[i].lotag) + auto spr = &acti->s; + if (spr->picnum == CAMERA1 && spr->yvel == 0 && neartagsprite->s.hitag == spr->lotag) { - sprite[i].yvel = 1; //Using this camera + spr->yvel = 1; //Using this camera if (snum == screenpeek) S_PlaySound(MONITOR_ACTIVE); - sprite[neartagsprite].owner = i; - sprite[neartagsprite].yvel = 1; + neartagsprite->SetOwner(acti); + neartagsprite->s.yvel = 1; camsprite = neartagsprite; j = p->cursectnum; - p->cursectnum = sprite[i].sectnum; - setpal(p); + p->cursectnum = spr->sectnum; p->cursectnum = j; // parallaxtype = 2; - p->newowner = i; + p->newOwner = acti; return; } } + i = -1; } CLEARCAMERAS: @@ -1722,33 +1731,32 @@ void checksectors_d(int snum) p->posx = p->oposx; p->posy = p->oposy; p->posz = p->oposz; - p->newowner = -1; + p->newOwner = nullptr; updatesector(p->posx, p->posy, &p->cursectnum); - setpal(p); - StatIterator it(STAT_ACTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { - if (sprite[i].picnum == CAMERA1) sprite[i].yvel = 0; + if (act->s.picnum == CAMERA1) act->s.yvel = 0; } } - else if (p->newowner >= 0) - p->newowner = -1; + else if (p->newOwner != nullptr) + p->newOwner = nullptr; return; } } if (!PlayerInput(snum, SB_OPEN)) return; - else if (p->newowner >= 0) { i = -1; goto CLEARCAMERAS; } + else if (p->newOwner != nullptr) { i = -1; goto CLEARCAMERAS; } - if (neartagwall == -1 && neartagsector == -1 && neartagsprite == -1) - if (abs(hits(p->i)) < 512) + if (neartagwall == -1 && neartagsector == -1 && neartagsprite == nullptr) + if (abs(hits(p->GetActor())) < 512) { if ((krand() & 255) < 16) - S_PlayActorSound(DUKE_SEARCH2, p->i); - else S_PlayActorSound(DUKE_SEARCH, p->i); + S_PlayActorSound(DUKE_SEARCH2, pact); + else S_PlayActorSound(DUKE_SEARCH, pact); return; } @@ -1757,10 +1765,10 @@ void checksectors_d(int snum) if (wall[neartagwall].lotag > 0 && fi.isadoorwall(wall[neartagwall].picnum)) { if (hitscanwall == neartagwall || hitscanwall == -1) - fi.checkhitswitch(snum, neartagwall, 0); + fi.checkhitswitch(snum, neartagwall, nullptr); return; } - else if (p->newowner >= 0) + else if (p->newOwner != nullptr) { i = -1; goto CLEARCAMERAS; @@ -1769,26 +1777,26 @@ void checksectors_d(int snum) if (neartagsector >= 0 && (sector[neartagsector].lotag & 16384) == 0 && isanearoperator(sector[neartagsector].lotag)) { - SectIterator it(neartagsector); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(neartagsector); + while (auto act = it.Next()) { - if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) + if (act->s.picnum == ACTIVATOR || act->s.picnum == MASTERSWITCH) return; } - operatesectors(neartagsector, p->i); + operatesectors(neartagsector, p->GetActor()); } - else if ((sector[sprite[p->i].sectnum].lotag & 16384) == 0) + else if ((sector[p->GetActor()->s.sectnum].lotag & 16384) == 0) { - if (isanunderoperator(sector[sprite[p->i].sectnum].lotag)) + if (isanunderoperator(sector[p->GetActor()->s.sectnum].lotag)) { - SectIterator it(sprite[p->i].sectnum); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(p->GetActor()->s.sectnum); + while (auto act = it.Next()) { - if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) return; + if (act->s.picnum == ACTIVATOR || act->s.picnum == MASTERSWITCH) return; } - operatesectors(sprite[p->i].sectnum, p->i); + operatesectors(p->GetActor()->s.sectnum, p->GetActor()); } - else fi.checkhitswitch(snum, neartagwall, 0); + else fi.checkhitswitch(snum, neartagwall, nullptr); } } } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index a931108dd..6c7303777 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -302,24 +302,24 @@ void animatewalls_r(void) void operaterespawns_r(int low) { - int i, j; - - StatIterator it(STAT_FX); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_FX); + while (auto act = it.Next()) { - if (sprite[i].lotag == low) switch (sprite[i].picnum) + if (act->s.lotag == low) switch (act->s.picnum) { case RESPAWN: - if (badguypic(sprite[i].hitag) && ud.monsters_off) break; + { + if (badguypic(act->s.hitag) && ud.monsters_off) break; - j = fi.spawn(i, TRANSPORTERSTAR); - sprite[j].z -= (32 << 8); + auto star = spawn(act, TRANSPORTERSTAR); + star->s.z -= (32 << 8); - sprite[i].extra = 66 - 12; // Just a way to killit + act->s.extra = 66 - 12; // Just a way to killit break; + } case RRTILE7424: if (isRRRA() && !ud.monsters_off) - changespritestat(i, 119); + changespritestat(act, 119); break; } @@ -332,9 +332,9 @@ void operaterespawns_r(int low) // //--------------------------------------------------------------------------- -void operateforcefields_r(int s, int low) +void operateforcefields_r(DDukeActor* act, int low) { - operateforcefields_common(s, low, { BIGFORCE }); + operateforcefields_common(act, low, { BIGFORCE }); } //--------------------------------------------------------------------------- @@ -343,33 +343,36 @@ void operateforcefields_r(int s, int low) // //--------------------------------------------------------------------------- -bool checkhitswitch_r(int snum, int w, int switchtype) +bool checkhitswitch_r(int snum, int ww, DDukeActor* act) { uint8_t switchpal; int i, x, lotag, hitag, picnum, correctdips, numdips; int sx, sy; - if (w < 0) return 0; + if (ww < 0 && act == nullptr) return 0; correctdips = 1; numdips = 0; - if (switchtype == 1) // A wall sprite + if (act) { - lotag = sprite[w].lotag; if (lotag == 0) return 0; - hitag = sprite[w].hitag; - sx = sprite[w].x; - sy = sprite[w].y; - picnum = sprite[w].picnum; - switchpal = sprite[w].pal; + lotag = act->s.lotag; + if (lotag == 0) return 0; + hitag = act->s.hitag; + sx = act->s.x; + sy = act->s.y; + picnum = act->s.picnum; + switchpal = act->s.pal; } else { - lotag = wall[w].lotag; if (lotag == 0) return 0; - hitag = wall[w].hitag; - sx = wall[w].x; - sy = wall[w].y; - picnum = wall[w].picnum; - switchpal = wall[w].pal; + auto wal = &wall[ww]; + lotag = wal->lotag; + if (lotag == 0) return 0; + hitag = wal->hitag; + sx = wal->x; + sy = wal->y; + picnum = wal->picnum; + switchpal = wal->pal; } switch (picnum) @@ -392,7 +395,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype) else { FTA(70, &ps[snum]); - if (isRRRA()) S_PlayActorSound(99, w); + if (isRRRA()) S_PlayActorSound(99, act? act : ps[snum].GetActor()); } } @@ -403,7 +406,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype) else { FTA(71, &ps[snum]); - if (isRRRA()) S_PlayActorSound(99, w); + if (isRRRA()) S_PlayActorSound(99, act ? act : ps[snum].GetActor()); } } @@ -414,16 +417,16 @@ bool checkhitswitch_r(int snum, int w, int switchtype) else { FTA(72, &ps[snum]); - if (isRRRA()) S_PlayActorSound(99, w); + if (isRRRA()) S_PlayActorSound(99, act ? act : ps[snum].GetActor()); } } if (ps[snum].access_incs == 1) { - if (switchtype == 0) - ps[snum].access_wallnum = w; + if (!act) + ps[snum].access_wallnum = ww; else - ps[snum].access_spritenum = w; + ps[snum].access_spritenum = act; } return 0; @@ -482,23 +485,23 @@ bool checkhitswitch_r(int snum, int w, int switchtype) break; } - StatIterator it(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DEFAULT); + while (auto other = it.Next()) { - auto si = &sprite[i]; + auto si = &other->s; if (lotag == si->lotag) switch (si->picnum) { case DIPSWITCH: case TECHSWITCH: case ALIENSWITCH: - if (switchtype == 1 && w == i) si->picnum++; + if (act && act == other) si->picnum++; else if (si->hitag == 0) correctdips++; numdips++; break; case TECHSWITCH + 1: case DIPSWITCH + 1: case ALIENSWITCH + 1: - if (switchtype == 1 && w == i) si->picnum--; + if (act && act == other) si->picnum--; else if (si->hitag == 1) correctdips++; numdips++; break; @@ -547,19 +550,18 @@ bool checkhitswitch_r(int snum, int w, int switchtype) if (si->picnum == DIPSWITCH3) if (si->hitag == 999) { - int j; - StatIterator it1(107); - while ((j = it1.NextIndex()) >= 0) + DukeStatIterator it1(107); + while (auto other2 = it1.Next()) { - if (sprite[j].picnum == RRTILE3410) + if (other2->s.picnum == RRTILE3410) { - sprite[j].picnum++; - sprite[j].hitag = 100; - sprite[j].extra = 0; - S_PlayActorSound(474, j); + other2->s.picnum++; + other2->s.hitag = 100; + other2->s.extra = 0; + S_PlayActorSound(474, other2); } - else if (sprite[j].picnum == RRTILE295) - deletesprite(j); + else if (other2->s.picnum == RRTILE295) + deletesprite(other2); } si->picnum++; break; @@ -569,7 +571,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype) if (si->picnum == RRTILE8660) { BellTime = 132; - BellSprite = i; + BellSprite = other; } si->picnum++; break; @@ -606,14 +608,14 @@ bool checkhitswitch_r(int snum, int w, int switchtype) case DIPSWITCH: case TECHSWITCH: case ALIENSWITCH: - if (switchtype == 0 && i == w) wall[x].picnum++; + if (!act && i == ww) wall[x].picnum++; else if (wall[x].hitag == 0) correctdips++; numdips++; break; case DIPSWITCH + 1: case TECHSWITCH + 1: case ALIENSWITCH + 1: - if (switchtype == 0 && i == w) wall[x].picnum--; + if (!act && i == ww) wall[x].picnum--; else if (wall[x].hitag == 1) correctdips++; numdips++; break; @@ -695,18 +697,18 @@ bool checkhitswitch_r(int snum, int w, int switchtype) { if (picnum == ALIENSWITCH || picnum == ALIENSWITCH + 1) { - if (switchtype == SWITCH_SPRITE) - S_PlaySound3D(ALIEN_SWITCH1, w, &v); - else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].i, &v); + if (act) + S_PlaySound3D(ALIEN_SWITCH1, act, &v); + else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), &v); } else { - if (switchtype == SWITCH_SPRITE) - S_PlaySound3D(SWITCH_ON, w, &v); - else S_PlaySound3D(SWITCH_ON, ps[snum].i, &v); + if (act) + S_PlaySound3D(SWITCH_ON, act, &v); + else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v); } if (numdips != correctdips) break; - S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].i, &v); + S_PlaySound3D(END_OF_LEVEL_WARN, ps[snum].GetActor(), &v); } goto goOn2; case MULTISWITCH2: @@ -755,22 +757,22 @@ bool checkhitswitch_r(int snum, int w, int switchtype) goOn2: if (isRRRA()) { - if (picnum == RRTILE8660) + if (picnum == RRTILE8660 && act) { BellTime = 132; - BellSprite = w; - sprite[w].picnum++; + BellSprite = act; + act->s.picnum++; } else if (picnum == RRTILE8464) { - sprite[w].picnum = sprite[w].picnum + 1; + act->s.picnum = act->s.picnum + 1; if (hitag == 10001) { if (ps[snum].SeaSick == 0) ps[snum].SeaSick = 350; - operateactivators(668, ps[snum].i); + operateactivators(668, snum); operatemasterswitches(668); - S_PlayActorSound(328, ps[snum].i); + S_PlayActorSound(328, ps[snum].GetActor()); return 1; } } @@ -781,32 +783,34 @@ bool checkhitswitch_r(int snum, int w, int switchtype) picnum == MULTISWITCH2 || picnum == (MULTISWITCH2 + 1) || picnum == (MULTISWITCH2 + 2) || picnum == (MULTISWITCH2 + 3)) { - int switches[3], switchcount = 0, j; - S_PlaySound3D(SWITCH_ON, w, &v); - for (j = 0; j < MAXSPRITES; j++) + DDukeActor* switches[3]; + int switchcount = 0, j; + S_PlaySound3D(SWITCH_ON, act, &v); + DukeSpriteIterator it; + while (auto actt = it.Next()) { - int jpn = sprite[j].picnum; - int jht = sprite[j].hitag; + int jpn = actt->s.picnum; + int jht = actt->s.hitag; if ((jpn == MULTISWITCH || jpn == MULTISWITCH2) && jht == 10000) { if (switchcount < 3) { - switches[switchcount] = j; + switches[switchcount] = actt; switchcount++; } } } if (switchcount == 3) { - S_PlaySound3D(78, w, &v); + S_PlaySound3D(78, act, &v); for (j = 0; j < switchcount; j++) { - sprite[switches[j]].hitag = 0; + switches[j]->s.hitag = 0; if (picnum >= MULTISWITCH2) - sprite[switches[j]].picnum = MULTISWITCH2 + 3; + switches[j]->s.picnum = MULTISWITCH2 + 3; else - sprite[switches[j]].picnum = MULTISWITCH + 3; - checkhitswitch_r(snum, switches[j], 1); + switches[j]->s.picnum = MULTISWITCH + 3; + checkhitswitch_r(snum, -1, switches[j]); } } return 1; @@ -823,29 +827,29 @@ bool checkhitswitch_r(int snum, int w, int switchtype) lotag += picnum - MULTISWITCH2; } - StatIterator itx(STAT_EFFECTOR); - while ((x = itx.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto other = it.Next()) { - if (sprite[x].hitag == lotag) + if (other->s.hitag == lotag) { - switch (sprite[x].lotag) + switch (other->s.lotag) { case 46: case SE_47_LIGHT_SWITCH: case SE_48_LIGHT_SWITCH: if (!isRRRA()) break; case SE_12_LIGHT_SWITCH: - sector[sprite[x].sectnum].floorpal = 0; - hittype[x].temp_data[0]++; - if (hittype[x].temp_data[0] == 2) - hittype[x].temp_data[0]++; + sector[other->s.sectnum].floorpal = 0; + other->temp_data[0]++; + if (other->temp_data[0] == 2) + other->temp_data[0]++; break; case SE_24_CONVEYOR: case SE_34: case SE_25_PISTON: - hittype[x].temp_data[4] = !hittype[x].temp_data[4]; - if (hittype[x].temp_data[4]) + other->temp_data[4] = !other->temp_data[4]; + if (other->temp_data[4]) FTA(15, &ps[snum]); else FTA(2, &ps[snum]); break; @@ -857,7 +861,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype) } operateactivators(lotag, snum); - fi.operateforcefields(ps[snum].i, lotag); + fi.operateforcefields(ps[snum].GetActor(), lotag); operatemasterswitches(lotag); if (picnum == DIPSWITCH || picnum == DIPSWITCH + 1 || @@ -866,18 +870,18 @@ bool checkhitswitch_r(int snum, int w, int switchtype) if (hitag == 0 && fi.isadoorwall(picnum) == 0) { - if (switchtype == SWITCH_SPRITE) - S_PlaySound3D(SWITCH_ON, w, &v); - else S_PlaySound3D(SWITCH_ON, ps[snum].i, &v); + if (act) + S_PlaySound3D(SWITCH_ON, act, &v); + else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v); } else if (hitag != 0) { auto flags = S_GetUserFlags(hitag); - if (switchtype == SWITCH_SPRITE && (flags & SF_TALK) == 0) - S_PlaySound3D(hitag, w, &v); + if (act && (flags & SF_TALK) == 0) + S_PlaySound3D(hitag, act, &v); else - S_PlayActorSound(hitag, ps[snum].i); + S_PlayActorSound(hitag, ps[snum].GetActor()); } return 1; @@ -891,22 +895,20 @@ bool checkhitswitch_r(int snum, int w, int switchtype) // //--------------------------------------------------------------------------- -void activatebysector_r(int sect, int j) +void activatebysector_r(int sect, DDukeActor* activator) { - short i; - - SectIterator it(sect); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto act = it.Next()) { - if (sprite[i].picnum == ACTIVATOR) + if (act->s.picnum == ACTIVATOR) { - operateactivators(sprite[i].lotag, -1); + operateactivators(act->s.lotag, -1); // return; } } if (sector[sect].lotag != 22) - operatesectors(sect, j); + operatesectors(sect, activator); } @@ -916,20 +918,20 @@ void activatebysector_r(int sect, int j) // //--------------------------------------------------------------------------- -static void lotsofpopcorn(short i, short wallnum, short n) +static void lotsofpopcorn(DDukeActor *actor, short wallnum, short n) { int j, xv, yv, z, x1, y1; short sect, a; sect = -1; - auto sp = &sprite[i]; + auto sp = &actor->s; if (wallnum < 0) { for (j = n - 1; j >= 0; j--) { a = sp->ang - 256 + (krand() & 511) + 1024; - EGS(sp->sectnum, sp->x, sp->y, sp->z, POPCORN, -32, 36, 36, a, 32 + (krand() & 63), 1024 - (krand() & 1023), i, 5); + EGS(sp->sectnum, sp->x, sp->y, sp->z, POPCORN, -32, 36, 36, a, 32 + (krand() & 63), 1024 - (krand() & 1023), actor, 5); } return; } @@ -960,7 +962,7 @@ static void lotsofpopcorn(short i, short wallnum, short n) if (z < -(32 << 8) || z >(32 << 8)) z = sp->z - (32 << 8) + (krand() & ((64 << 8) - 1)); a = sp->ang - 1024; - EGS(sp->sectnum, x1, y1, z, POPCORN, -32, 36, 36, a, 32 + (krand() & 63), -(krand() & 1023), i, 5); + EGS(sp->sectnum, x1, y1, z, POPCORN, -32, 36, 36, a, 32 + (krand() & 63), -(krand() & 1023), actor, 5); } } } @@ -971,7 +973,7 @@ static void lotsofpopcorn(short i, short wallnum, short n) // //--------------------------------------------------------------------------- -void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) +void checkhitwall_r(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith) { short j, i, sn = -1, darkestwall; walltype* wal; @@ -1018,6 +1020,7 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) return; case RRTILE1973: + { updatesector(x, y, &sn); if (sn < 0) return; wal->overpicnum = GLASS2; lotsofpopcorn(spr, dawallnum, 64); @@ -1026,12 +1029,15 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) if (wal->nextwall >= 0) wall[wal->nextwall].cstat = 0; - i = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3); - sprite[i].lotag = 128; hittype[i].temp_data[1] = 2; hittype[i].temp_data[2] = dawallnum; - S_PlayActorSound(GLASS_BREAKING, i); + auto spawned = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3); + spawned->s.lotag = 128; + spawned->temp_data[1] = 2; + spawned->temp_data[2] = dawallnum; + S_PlayActorSound(GLASS_BREAKING, spawned); return; - + } case GLASS: + { updatesector(x, y, &sn); if (sn < 0) return; wal->overpicnum = GLASS2; lotsofglass(spr, dawallnum, 10); @@ -1040,10 +1046,13 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) if (wal->nextwall >= 0) wall[wal->nextwall].cstat = 0; - i = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3); - sprite[i].lotag = 128; hittype[i].temp_data[1] = 2; hittype[i].temp_data[2] = dawallnum; - S_PlayActorSound(GLASS_BREAKING, i); + auto spawned = EGS(sn, x, y, z, SECTOREFFECTOR, 0, 0, 0, ps[0].angle.ang.asbuild(), 0, 0, spr, 3); + spawned->s.lotag = 128; + spawned->temp_data[1] = 2; + spawned->temp_data[2] = dawallnum; + S_PlayActorSound(GLASS_BREAKING, spawned); return; + } case STAINGLASS1: updatesector(x, y, &sn); if (sn < 0) return; lotsofcolourglass(spr, dawallnum, 80); @@ -1067,27 +1076,26 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) { int sect; int unk = 0; - int jj; int startwall, endwall; sect = wall[wal->nextwall].nextsector; - SectIterator it(sect); - while ((jj = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto act = it.Next()) { - s = &sprite[jj]; + s = &act->s; if (s->lotag == 6) { //for (j = 0; j < 16; j++) RANDOMSCRAP(s, -1); This never spawned anything due to the -1. - hittype[jj].spriteextra++; - if (hittype[jj].spriteextra == 25) + act->spriteextra++; + if (act->spriteextra == 25) { startwall = sector[s->sectnum].wallptr; endwall = startwall + sector[s->sectnum].wallnum; for (i = startwall; i < endwall; i++) sector[wall[i].nextsector].lotag = 0; sector[s->sectnum].lotag = 0; - S_StopSound(sprite[jj].lotag); - S_PlayActorSound(400, jj); - deletesprite(jj); + S_StopSound(act->s.lotag); + S_PlayActorSound(400, act); + deletesprite(act); } } } @@ -1245,7 +1253,7 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) case ATM: wal->picnum = ATMBROKE; - fi.lotsofmoney(&hittype[spr], 1 + (krand() & 7)); + fi.lotsofmoney(spr, 1 + (krand() & 7)); S_PlayActorSound(GLASS_HEAVYBREAK, spr); break; @@ -1343,14 +1351,14 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) darkestwall = wal->shade; j = krand() & 1; - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act = it.Next()) { - if (sprite[i].hitag == wall[dawallnum].lotag && sprite[i].lotag == 3) + if (act->s.hitag == wall[dawallnum].lotag && act->s.lotag == 3) { - hittype[i].temp_data[2] = j; - hittype[i].temp_data[3] = darkestwall; - hittype[i].temp_data[4] = 1; + act->temp_data[2] = j; + act->temp_data[3] = darkestwall; + act->temp_data[4] = 1; } } break; @@ -1363,13 +1371,11 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) // //--------------------------------------------------------------------------- -void checkplayerhurt_r(struct player_struct* p, int j) +void checkplayerhurt_r(struct player_struct* p, const Collision &coll) { - if ((j & 49152) == 49152) + if (coll.type == kHitSprite) { - j &= (MAXSPRITES - 1); - - switch (sprite[j].picnum) + switch (coll.actor->s.picnum) { case RRTILE2430: case RRTILE2431: @@ -1380,34 +1386,34 @@ void checkplayerhurt_r(struct player_struct* p, int j) case RRTILE2455: if (isRRRA() && p->hurt_delay2 < 8) { - sprite[p->i].extra -= 2; + p->GetActor()->s.extra -= 2; p->hurt_delay2 = 16; SetPlayerPal(p, PalEntry(32, 32, 0, 0)); - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, p->GetActor()); } break; case CACTUS: if (!isRRRA() && p->hurt_delay < 8) { - sprite[p->i].extra -= 5; + p->GetActor()->s.extra -= 5; p->hurt_delay = 16; SetPlayerPal(p, PalEntry(32, 32, 0, 0)); - S_PlayActorSound(DUKE_LONGTERM_PAIN, p->i); + S_PlayActorSound(DUKE_LONGTERM_PAIN, p->GetActor()); } break; } return; } - if ((j & 49152) != 32768) return; - j &= (MAXWALLS - 1); + if (coll.type != kHitWall) return; + int j = coll.index; if (p->hurt_delay > 0) p->hurt_delay--; else if (wall[j].cstat & 85) switch (wall[j].overpicnum) { case BIGFORCE: p->hurt_delay = 26; - fi.checkhitwall(p->i, j, + fi.checkhitwall(p->GetActor(), j, p->posx + (sintable[(p->angle.ang.asbuild() + 512) & 2047] >> 9), p->posy + (sintable[p->angle.ang.asbuild() & 2047] >> 9), p->posz, -1); @@ -1424,7 +1430,7 @@ void checkplayerhurt_r(struct player_struct* p, int j) bool checkhitceiling_r(int sn) { - short i, j; + short j; switch (sector[sn].ceilingpicnum) { @@ -1442,8 +1448,8 @@ bool checkhitceiling_r(int sn) case RRTILE2898: - ceilingglass(ps[myconnectindex].i, sn, 10); - S_PlayActorSound(GLASS_BREAKING, ps[screenpeek].i); + ceilingglass(ps[myconnectindex].GetActor(), sn, 10); + S_PlayActorSound(GLASS_BREAKING, ps[screenpeek].GetActor()); if (sector[sn].ceilingpicnum == WALLLIGHT1) sector[sn].ceilingpicnum = WALLLIGHTBUST1; @@ -1484,16 +1490,17 @@ bool checkhitceiling_r(int sn) if (!sector[sn].hitag) { - SectIterator it(sn); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sn); + while (auto act1 = it.Next()) { - if (sprite[i].picnum == SECTOREFFECTOR && (sprite[i].lotag == 12 || (isRRRA() && (sprite[i].lotag == 47 || sprite[i].lotag == 48)))) + auto spr1 = &act1->s; + if (spr1->picnum == SECTOREFFECTOR && (spr1->lotag == 12 || (isRRRA() && (spr1->lotag == 47 || spr1->lotag == 48)))) { - StatIterator it(STAT_EFFECTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act2 = it.Next()) { - if (sprite[j].hitag == sprite[i].hitag) - hittype[j].temp_data[3] = 1; + if (act2->s.hitag == spr1->hitag) + act2->temp_data[3] = 1; } break; } @@ -1501,13 +1508,14 @@ bool checkhitceiling_r(int sn) } j = krand() & 1; - StatIterator it(STAT_EFFECTOR); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act1 = it.Next()) { - if (sprite[i].hitag == (sector[sn].hitag) && sprite[i].lotag == 3) + auto spr1 = &act1->s; + if (spr1->hitag == (sector[sn].hitag) && spr1->lotag == 3) { - hittype[i].temp_data[2] = j; - hittype[i].temp_data[4] = 1; + act1->temp_data[2] = j; + act1->temp_data[4] = 1; } } @@ -1523,12 +1531,11 @@ bool checkhitceiling_r(int sn) // //--------------------------------------------------------------------------- -void checkhitsprite_r(int i, int sn) +void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj) { int j, k, p; - - i &= (MAXSPRITES - 1); - spritetype* s = &sprite[i]; + spritetype* s = &targ->s; + auto pspr = &proj->s; if (isRRRA()) switch (s->picnum) { @@ -1536,7 +1543,7 @@ void checkhitsprite_r(int i, int sn) break; case RRTILE8487: case RRTILE8489: - S_PlayActorSound(471, i); + S_PlayActorSound(471, targ); s->picnum++; break; case RRTILE7638: @@ -1550,12 +1557,12 @@ void checkhitsprite_r(int i, int sn) case RRTILE7881: case RRTILE7883: s->picnum++; - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case RRTILE7879: s->picnum++; - S_PlayActorSound(495, i); - fi.hitradius(i, 10, 0, 0, 1, 1); + S_PlayActorSound(495, targ); + fi.hitradius(targ, 10, 0, 0, 1, 1); break; case RRTILE7648: case RRTILE7694: @@ -1563,120 +1570,120 @@ void checkhitsprite_r(int i, int sn) case RRTILE7702: case RRTILE7711: s->picnum++; - S_PlayActorSound(47, i); + S_PlayActorSound(47, targ); break; case RRTILE7636: s->picnum += 3; - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case RRTILE7875: s->picnum += 3; - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case RRTILE7640: s->picnum += 2; - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case RRTILE7595: case RRTILE7704: s->picnum = RRTILE7705; - S_PlayActorSound(495, i); + S_PlayActorSound(495, targ); break; case RRTILE8579: s->picnum = RRTILE5014; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7441: s->picnum = RRTILE5016; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7534: s->picnum = RRTILE5029; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7545: s->picnum = RRTILE5030; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7547: s->picnum = RRTILE5031; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7574: s->picnum = RRTILE5032; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7575: s->picnum = RRTILE5033; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7578: s->picnum = RRTILE5034; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7478: s->picnum = RRTILE5035; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8525: s->picnum = RRTILE5036; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8537: s->picnum = RRTILE5062; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8215: s->picnum = RRTILE5064; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8216: s->picnum = RRTILE5065; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8217: s->picnum = RRTILE5066; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8218: s->picnum = RRTILE5067; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8220: s->picnum = RRTILE5068; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8221: s->picnum = RRTILE5069; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8312: s->picnum = RRTILE5071; - S_PlayActorSound(472, i); + S_PlayActorSound(472, targ); break; case RRTILE8395: s->picnum = RRTILE5072; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8423: s->picnum = RRTILE5073; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE3462: s->picnum = RRTILE5074; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case UWHIP: s->picnum = RRTILE5075; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8608: s->picnum = RRTILE5083; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8609: s->picnum = RRTILE5084; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8567: case RRTILE8568: @@ -1684,23 +1691,23 @@ void checkhitsprite_r(int i, int sn) case RRTILE8570: case RRTILE8571: s->picnum = RRTILE5082; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8640: s->picnum = RRTILE5085; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8611: s->picnum = RRTILE5086; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case TECHLIGHTBUST2: s->picnum = TECHLIGHTBUST4; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8497: s->picnum = RRTILE5076; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8162: case RRTILE8163: @@ -1709,9 +1716,9 @@ void checkhitsprite_r(int i, int sn) case RRTILE8166: case RRTILE8167: case RRTILE8168: - changespritestat(i, STAT_MISC); + changespritestat(targ, STAT_MISC); s->picnum = RRTILE5063; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8589: case RRTILE8590: @@ -1720,224 +1727,224 @@ void checkhitsprite_r(int i, int sn) case RRTILE8593: case RRTILE8594: case RRTILE8595: - changespritestat(i, STAT_MISC); + changespritestat(targ, STAT_MISC); s->picnum = RRTILE8588; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE3497: s->picnum = RRTILE5076; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE3498: s->picnum = RRTILE5077; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE3499: s->picnum = RRTILE5078; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8503: s->picnum = RRTILE5079; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7901: s->picnum = RRTILE5080; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7696: s->picnum = RRTILE7697; - S_PlayActorSound(DUKE_SHUCKS, i); + S_PlayActorSound(DUKE_SHUCKS, targ); break; case RRTILE7806: s->picnum = RRTILE5043; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7885: case RRTILE7890: s->picnum = RRTILE5045; - S_PlayActorSound(495, i); - fi.hitradius(i, 10, 0, 0, 1, 1); + S_PlayActorSound(495, targ); + fi.hitradius(targ, 10, 0, 0, 1, 1); break; case RRTILE7886: s->picnum = RRTILE5046; - S_PlayActorSound(495, i); - fi.hitradius(i, 10, 0, 0, 1, 1); + S_PlayActorSound(495, targ); + fi.hitradius(targ, 10, 0, 0, 1, 1); break; case RRTILE7887: s->picnum = RRTILE5044; - S_PlayActorSound(GLASS_HEAVYBREAK, i); - fi.hitradius(i, 10, 0, 0, 1, 1); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + fi.hitradius(targ, 10, 0, 0, 1, 1); break; case RRTILE7900: s->picnum = RRTILE5047; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7906: s->picnum = RRTILE5048; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7912: case RRTILE7913: s->picnum = RRTILE5049; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8047: s->picnum = RRTILE5050; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8596: s->picnum = RRTILE8598; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8059: s->picnum = RRTILE5051; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8060: s->picnum = RRTILE5052; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8222: s->picnum = RRTILE5053; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8223: s->picnum = RRTILE5054; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8224: s->picnum = RRTILE5055; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8370: s->picnum = RRTILE5056; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8371: s->picnum = RRTILE5057; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8372: s->picnum = RRTILE5058; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8373: s->picnum = RRTILE5059; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8396: s->picnum = RRTILE5038; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8397: s->picnum = RRTILE5039; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8398: s->picnum = RRTILE5040; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8399: s->picnum = RRTILE5041; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8385: s->picnum = RRTILE8386; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8387: s->picnum = RRTILE8388; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8389: s->picnum = RRTILE8390; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8391: s->picnum = RRTILE8392; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE7553: s->picnum = RRTILE5035; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8475: s->picnum = RRTILE5075; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8498: s->picnum = RRTILE5077; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8499: s->picnum = RRTILE5078; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE2445: s->picnum = RRTILE2450; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE2123: s->picnum = RRTILE2124; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case RRTILE3773: s->picnum = RRTILE8651; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case RRTILE7533: s->picnum = RRTILE5035; - S_PlayActorSound(495, i); - fi.hitradius(i, 10, 0, 0, 1, 1); + S_PlayActorSound(495, targ); + fi.hitradius(targ, 10, 0, 0, 1, 1); break; case RRTILE8394: s->picnum = RRTILE5072; - S_PlayActorSound(495, i); + S_PlayActorSound(495, targ); break; case RRTILE8461: case RRTILE8462: s->picnum = RRTILE5074; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8679: s->picnum = RRTILE8680; - S_PlayActorSound(DUKE_SHUCKS, i); - fi.hitradius(i, 10, 0, 0, 1, 1); + S_PlayActorSound(DUKE_SHUCKS, targ); + fi.hitradius(targ, 10, 0, 0, 1, 1); if (s->lotag != 0) { - short j; - for (j = 0; j < MAXSPRITES; j++) + DukeSpriteIterator it; + while (auto act = it.Next()) { - if (sprite[j].picnum == RRTILE8679 && sprite[j].pal == 4) + if (act->s.picnum == RRTILE8679 && act->s.pal == 4) { - if (sprite[j].lotag == s->lotag) - sprite[j].picnum = RRTILE8680; + if (act->s.lotag == s->lotag) + act->s.picnum = RRTILE8680; } } } break; case RRTILE3584: s->picnum = RRTILE8681; - S_PlayActorSound(495, i); - fi.hitradius(i, 250, 0, 0, 1, 1); + S_PlayActorSound(495, targ); + fi.hitradius(targ, 250, 0, 0, 1, 1); break; case RRTILE8682: s->picnum = RRTILE8683; - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case RRTILE8099: if (s->lotag == 5) { - short j; s->lotag = 0; s->picnum = RRTILE5087; - S_PlayActorSound(340, i); - for (j = 0; j < MAXSPRITES; j++) + S_PlayActorSound(340, targ); + DukeSpriteIterator it; + while (auto act = it.Next()) { - if (sprite[j].picnum == RRTILE8094) - sprite[j].picnum = RRTILE5088; + if (act->s.picnum == RRTILE8094) + act->s.picnum = RRTILE5088; } } break; @@ -1947,13 +1954,13 @@ void checkhitsprite_r(int i, int sn) s->picnum = RRTILE2451; if (s->lotag != 0) { - short j; - for (j = 0; j < MAXSPRITES; j++) + DukeSpriteIterator it; + while (auto act = it.Next()) { - if (sprite[j].picnum == RRTILE2431 && sprite[j].pal == 4) + if (act->s.picnum == RRTILE2431 && act->s.pal == 4) { - if (s->lotag == sprite[j].lotag) - sprite[j].picnum = RRTILE2451; + if (s->lotag == act->s.lotag) + act->s.picnum = RRTILE2451; } } } @@ -1964,27 +1971,27 @@ void checkhitsprite_r(int i, int sn) s->picnum = RRTILE2455; break; case RRTILE2455: - S_PlayActorSound(SQUISHED, i); - fi.guts(&sprite[i], RRTILE2465, 3, myconnectindex); - deletesprite(i); + S_PlayActorSound(SQUISHED, targ); + fi.guts(targ, RRTILE2465, 3, myconnectindex); + deletesprite(targ); break; case RRTILE2451: if (s->pal != 4) { - S_PlayActorSound(SQUISHED, i); + S_PlayActorSound(SQUISHED, targ); if (s->lotag != 0) { - short j; - for (j = 0; j < MAXSPRITES; j++) + DukeSpriteIterator it; + while (auto act = it.Next()) { - if (sprite[j].picnum == RRTILE2451 && sprite[j].pal == 4) + if (act->s.picnum == RRTILE2451 && act->s.pal == 4) { - if (s->lotag == sprite[j].lotag) + if (s->lotag == act->s.lotag) { - fi.guts(&sprite[i], RRTILE2460, 12, myconnectindex); - fi.guts(&sprite[i], RRTILE2465, 3, myconnectindex); - sprite[j].xrepeat = 0; - sprite[j].yrepeat = 0; + fi.guts(targ, RRTILE2460, 12, myconnectindex); + fi.guts(targ, RRTILE2465, 3, myconnectindex); + act->s.xrepeat = 0; + act->s.yrepeat = 0; s->xrepeat = 0; s->yrepeat = 0; } @@ -1993,15 +2000,15 @@ void checkhitsprite_r(int i, int sn) } else { - fi.guts(&sprite[i], RRTILE2460, 12, myconnectindex); - fi.guts(&sprite[i], RRTILE2465, 3, myconnectindex); + fi.guts(targ, RRTILE2460, 12, myconnectindex); + fi.guts(targ, RRTILE2465, 3, myconnectindex); s->xrepeat = 0; s->yrepeat = 0; } } break; case RRTILE2437: - S_PlayActorSound(439, i); + S_PlayActorSound(439, targ); break; } @@ -2021,8 +2028,8 @@ void checkhitsprite_r(int i, int sn) break; case RRTILE2030: s->picnum = RRTILE2034; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case RRTILE2893: case RRTILE2915: @@ -2043,30 +2050,30 @@ void checkhitsprite_r(int i, int sn) s->picnum = RRTILE3216; break; } - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case RRTILE2156: case RRTILE2158: case RRTILE2160: case RRTILE2175: s->picnum++; - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); break; case RRTILE2137: case RRTILE2151: case RRTILE2152: - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); s->picnum++; for (k = 0; k < 6; k++) - EGS(s->sectnum, s->x, s->y, s->z - (8 << 8), SCRAP6 + (krand() & 15), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), i, 5); + EGS(s->sectnum, s->x, s->y, s->z - (8 << 8), SCRAP6 + (krand() & 15), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), targ, 5); break; case BOWLINGBALL: - sprite[sn].xvel = (s->xvel >> 1) + (s->xvel >> 2); - sprite[sn].ang -= (krand() & 16); - S_PlayActorSound(355, i); + pspr->xvel = (s->xvel >> 1) + (s->xvel >> 2); + pspr->ang -= (krand() & 16); + S_PlayActorSound(355, targ); break; case STRIPEBALL: @@ -2075,34 +2082,34 @@ void checkhitsprite_r(int i, int sn) case RRTILE3440 + 1: case HENSTAND: case HENSTAND + 1: - if (sprite[sn].picnum == QUEBALL || sprite[sn].picnum == STRIPEBALL) + if (pspr->picnum == QUEBALL || pspr->picnum == STRIPEBALL) { - sprite[sn].xvel = (s->xvel >> 1) + (s->xvel >> 2); - sprite[sn].ang -= (s->ang << 1) + 1024; - s->ang = getangle(s->x - sprite[sn].x, s->y - sprite[sn].y) - 512; + pspr->xvel = (s->xvel >> 1) + (s->xvel >> 2); + pspr->ang -= (s->ang << 1) + 1024; + s->ang = getangle(s->x - pspr->x, s->y - pspr->y) - 512; if (S_CheckSoundPlaying(POOLBALLHIT) < 2) - S_PlayActorSound(POOLBALLHIT, i); + S_PlayActorSound(POOLBALLHIT, targ); } - else if (sprite[sn].picnum == RRTILE3440 || sprite[sn].picnum == RRTILE3440 + 1) + else if (pspr->picnum == RRTILE3440 || pspr->picnum == RRTILE3440 + 1) { - sprite[sn].xvel = (s->xvel >> 1) + (s->xvel >> 2); - sprite[sn].ang -= ((s->ang << 1) + krand()) & 64; + pspr->xvel = (s->xvel >> 1) + (s->xvel >> 2); + pspr->ang -= ((s->ang << 1) + krand()) & 64; s->ang = (s->ang + krand()) & 16; - S_PlayActorSound(355, i); + S_PlayActorSound(355, targ); } - else if (sprite[sn].picnum == HENSTAND || sprite[sn].picnum == HENSTAND + 1) + else if (pspr->picnum == HENSTAND || pspr->picnum == HENSTAND + 1) { - sprite[sn].xvel = (s->xvel >> 1) + (s->xvel >> 2); - sprite[sn].ang -= ((s->ang << 1) + krand()) & 16; + pspr->xvel = (s->xvel >> 1) + (s->xvel >> 2); + pspr->ang -= ((s->ang << 1) + krand()) & 16; s->ang = (s->ang + krand()) & 16; - S_PlayActorSound(355, i); + S_PlayActorSound(355, targ); } else { if (krand() & 3) { s->xvel = 164; - s->ang = sprite[sn].ang; + s->ang = pspr->ang; } } break; @@ -2111,7 +2118,7 @@ void checkhitsprite_r(int i, int sn) case TREE2: case TIRE: case BOX: - switch (sprite[sn].picnum) + switch (pspr->picnum) { case RPG2: if (!isRRRA()) break; @@ -2124,11 +2131,11 @@ void checkhitsprite_r(int i, int sn) case COOLEXPLOSION1: case OWHIP: case UWHIP: - if (hittype[i].temp_data[0] == 0) + if (targ->temp_data[0] == 0) { s->cstat &= ~257; - hittype[i].temp_data[0] = 1; - fi.spawn(i, BURNING); + targ->temp_data[0] = 1; + spawn(targ, BURNING); } break; } @@ -2136,7 +2143,7 @@ void checkhitsprite_r(int i, int sn) case CACTUS: // case CACTUSBROKE: - switch (sprite[sn].picnum) + switch (pspr->picnum) { case RPG2: if (!isRRRA()) break; @@ -2151,8 +2158,8 @@ void checkhitsprite_r(int i, int sn) case UWHIP: for (k = 0; k < 64; k++) { - j = EGS(s->sectnum, s->x, s->y, s->z - (krand() % (48 << 8)), SCRAP6 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), i, 5); - sprite[j].pal = 8; + auto j = EGS(s->sectnum, s->x, s->y, s->z - (krand() % (48 << 8)), SCRAP6 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), targ, 5); + j->s.pal = 8; } if (s->picnum == CACTUS) @@ -2167,27 +2174,27 @@ void checkhitsprite_r(int i, int sn) case FANSPRITE: s->picnum = FANSPRITEBROKE; s->cstat &= (65535 - 257); - S_PlayActorSound(GLASS_HEAVYBREAK, i); - for (j = 0; j < 16; j++) RANDOMSCRAP(s, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + for (j = 0; j < 16; j++) RANDOMSCRAP(targ); break; case WATERFOUNTAIN: case WATERFOUNTAIN + 1: case WATERFOUNTAIN + 2: case WATERFOUNTAIN + 3: - fi.spawn(i, TOILETWATER); + spawn(targ, TOILETWATER); break; case SATELITE: case FUELPOD: case SOLARPANNEL: case ANTENNA: - if (actorinfo[SHOTSPARK1].scriptaddress && sprite[sn].extra != ScriptCode[actorinfo[SHOTSPARK1].scriptaddress]) + if (actorinfo[SHOTSPARK1].scriptaddress && pspr->extra != ScriptCode[actorinfo[SHOTSPARK1].scriptaddress]) { for (j = 0; j < 15; j++) EGS(s->sectnum, s->x, s->y, sector[s->sectnum].floorz - (12 << 8) - (j << 9), SCRAP1 + (krand() & 15), -8, 64, 64, - krand() & 2047, (krand() & 127) + 64, -(krand() & 511) - 256, i, 5); - fi.spawn(i, EXPLOSION2); - deletesprite(i); + krand() & 2047, (krand() & 127) + 64, -(krand() & 511) - 256, targ, 5); + spawn(targ, EXPLOSION2); + deletesprite(targ); } break; case RRTILE1824: @@ -2220,74 +2227,75 @@ void checkhitsprite_r(int i, int sn) case STATUEFLASH: case STATUE: if (s->picnum == BOTTLE10) - fi.lotsofmoney(&hittype[i], 4 + (krand() & 3)); + fi.lotsofmoney(targ, 4 + (krand() & 3)); else if (s->picnum == STATUE || s->picnum == STATUEFLASH) { - lotsofcolourglass(i, -1, 40); - S_PlayActorSound(GLASS_HEAVYBREAK, i); + lotsofcolourglass(targ, -1, 40); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); } else if (s->picnum == VASE) - lotsofglass(i, -1, 40); + lotsofglass(targ, -1, 40); - S_PlayActorSound(GLASS_BREAKING, i); + S_PlayActorSound(GLASS_BREAKING, targ); s->ang = krand() & 2047; - lotsofglass(i, -1, 8); - deletesprite(i); + lotsofglass(targ, -1, 8); + deletesprite(targ); break; case RRTILE2654: case RRTILE2656: case RRTILE3172: if (!isRRRA()) break; case BOTTLE7: - S_PlayActorSound(GLASS_BREAKING, i); - lotsofglass(i, -1, 10); - deletesprite(i); + S_PlayActorSound(GLASS_BREAKING, targ); + lotsofglass(targ, -1, 10); + deletesprite(targ); break; case FORCESPHERE: + { s->xrepeat = 0; - hittype[s->owner].temp_data[0] = 32; - hittype[s->owner].temp_data[1] = !hittype[s->owner].temp_data[1]; - hittype[s->owner].temp_data[2] ++; - fi.spawn(i, EXPLOSION2); + auto Owner = targ->GetOwner(); + if (Owner) + { + Owner->temp_data[0] = 32; + Owner->temp_data[1] = !Owner->temp_data[1]; + Owner->temp_data[2] ++; + } + spawn(targ, EXPLOSION2); break; + } case TOILET: s->picnum = TOILETBROKE; s->cstat |= (krand() & 1) << 2; s->cstat &= ~257; - fi.spawn(i, TOILETWATER); - S_PlayActorSound(GLASS_BREAKING, i); + spawn(targ, TOILETWATER); + S_PlayActorSound(GLASS_BREAKING, targ); break; case STALL: s->picnum = STALLBROKE; s->cstat |= (krand() & 1) << 2; s->cstat &= ~257; - fi.spawn(i, TOILETWATER); - S_PlayActorSound(GLASS_HEAVYBREAK, i); + spawn(targ, TOILETWATER); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case HYDRENT: s->picnum = BROKEFIREHYDRENT; - fi.spawn(i, TOILETWATER); + spawn(targ, TOILETWATER); - // for(k=0;k<5;k++) - // { - // j = EGS(s->sectnum,s->x,s->y,s->z-(krand()%(48<<8)),SCRAP3+(krand()&3),-8,48,48,krand()&2047,(krand()&63)+64,-(krand()&4095)-(s->zvel>>2),i,5); - // sprite[j].pal = 2; - // } - S_PlayActorSound(GLASS_HEAVYBREAK, i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); break; case GRATE1: s->picnum = BGRATE1; s->cstat &= (65535 - 256 - 1); - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case CIRCLEPANNEL: s->picnum = CIRCLEPANNELBROKE; s->cstat &= (65535 - 256 - 1); - S_PlayActorSound(VENT_BUST, i); + S_PlayActorSound(VENT_BUST, targ); break; case PIPE1: @@ -2305,9 +2313,10 @@ void checkhitsprite_r(int i, int sn) case PIPE5:s->picnum = PIPE5B; break; case PIPE6:s->picnum = PIPE6B; break; } - - j = fi.spawn(i, STEAM); - sprite[j].z = sector[s->sectnum].floorz - (32 << 8); + { + auto j = spawn(targ, STEAM); + j->s.z = sector[s->sectnum].floorz - (32 << 8); + } break; case CHAIR1: @@ -2324,90 +2333,90 @@ void checkhitsprite_r(int i, int sn) case POT1: case POT2: case POT3: - S_PlayActorSound(GLASS_HEAVYBREAK, i); - for (j = 0; j < 16; j++) RANDOMSCRAP(s, i); - deletesprite(i); + S_PlayActorSound(GLASS_HEAVYBREAK, targ); + for (j = 0; j < 16; j++) RANDOMSCRAP(targ); + deletesprite(targ); break; case PLAYERONWATER: - i = s->owner; - s = &sprite[i]; + targ = targ->GetOwner(); + if (!targ) break; + s = &targ->s; default: if ((s->cstat & 16) && s->hitag == 0 && s->lotag == 0 && s->statnum == 0) break; - if ((sprite[sn].picnum == SHRINKSPARK || sprite[sn].picnum == FREEZEBLAST || sprite[sn].owner != i) && s->statnum != 4) + if ((pspr->picnum == SHRINKSPARK || pspr->picnum == FREEZEBLAST || proj->GetOwner() != targ) && s->statnum != 4) { - if (badguy(&sprite[i]) == 1) + if (badguy(targ) == 1) { - if (sprite[sn].picnum == RPG) sprite[sn].extra <<= 1; - else if (isRRRA() && sprite[sn].picnum == RPG2) sprite[sn].extra <<= 1; + if (pspr->picnum == RPG) pspr->extra <<= 1; + else if (isRRRA() && pspr->picnum == RPG2) pspr->extra <<= 1; if ((s->picnum != DRONE)) - if (sprite[sn].picnum != FREEZEBLAST) + if (pspr->picnum != FREEZEBLAST) //if (actortype[s->picnum] == 0) //TRANSITIONAL. Cannot be done right with EDuke mess backing the engine. { - j = fi.spawn(sn, JIBS6); - if (sprite[sn].pal == 6) - sprite[j].pal = 6; - sprite[j].z += (4 << 8); - sprite[j].xvel = 16; - sprite[j].xrepeat = sprite[j].yrepeat = 24; - sprite[j].ang += 32 - (krand() & 63); + auto spawned = spawn(proj, JIBS6); + if (pspr->pal == 6) + spawned->s.pal = 6; + spawned->s.z += (4 << 8); + spawned->s.xvel = 16; + spawned->s.xrepeat = spawned->s.yrepeat = 24; + spawned->s.ang += 32 - (krand() & 63); } - j = sprite[sn].owner; + auto Owner = proj->GetOwner(); - if (j >= 0 && sprite[j].picnum == APLAYER && s->picnum != DRONE) - if (ps[sprite[j].yvel].curr_weapon == SHOTGUN_WEAPON) + if (Owner && Owner->s.picnum == APLAYER && s->picnum != DRONE) + if (ps[Owner->PlayerIndex()].curr_weapon == SHOTGUN_WEAPON) { - fi.shoot(i, BLOODSPLAT3); - fi.shoot(i, BLOODSPLAT1); - fi.shoot(i, BLOODSPLAT2); - fi.shoot(i, BLOODSPLAT4); + fi.shoot(targ, BLOODSPLAT3); + fi.shoot(targ, BLOODSPLAT1); + fi.shoot(targ, BLOODSPLAT2); + fi.shoot(targ, BLOODSPLAT4); } if (s->statnum == 2) { - changespritestat(i, 1); - hittype[i].timetosleep = SLEEPTIME; + changespritestat(targ, 1); + targ->timetosleep = SLEEPTIME; } } if (s->statnum != 2) { - if (sprite[sn].picnum == FREEZEBLAST && ((s->picnum == APLAYER && s->pal == 1) || (freezerhurtowner == 0 && sprite[sn].owner == i))) + if (pspr->picnum == FREEZEBLAST && ((s->picnum == APLAYER && s->pal == 1) || (freezerhurtowner == 0 && proj->GetOwner() == targ))) return; - hittype[i].picnum = sprite[sn].picnum; - hittype[i].extra += sprite[sn].extra; + targ->picnum = pspr->picnum; + targ->extra += pspr->extra; if (s->picnum != COW) - hittype[i].ang = sprite[sn].ang; - hittype[i].owner = sprite[sn].owner; + targ->ang = pspr->ang; + targ->SetHitOwner(proj->GetOwner()); } if (s->statnum == 10) { p = s->yvel; - if (ps[p].newowner >= 0) + if (ps[p].newOwner != nullptr) { - ps[p].newowner = -1; + ps[p].newOwner = nullptr; ps[p].posx = ps[p].oposx; ps[p].posy = ps[p].oposy; ps[p].posz = ps[p].oposz; updatesector(ps[p].posx, ps[p].posy, &ps[p].cursectnum); - setpal(&ps[p]); - StatIterator it(STAT_EFFECTOR); - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_EFFECTOR); + while (auto act = it.Next()) { - if (sprite[j].picnum == CAMERA1) sprite[j].yvel = 0; + if (act->s.picnum == CAMERA1) act->s.yvel = 0; } } - - if (sprite[hittype[i].owner].picnum != APLAYER) + auto Owner = targ->GetHitOwner(); + if (!Owner || Owner->s.picnum != APLAYER) if (ud.player_skill >= 3) - sprite[sn].extra += (sprite[sn].extra >> 1); + pspr->extra += (pspr->extra >> 1); } } @@ -2426,10 +2435,12 @@ void checksectors_r(int snum) int i = -1, oldz; struct player_struct* p; int hitscanwall; - short neartagsector, neartagwall, neartagsprite; + short neartagsector, neartagwall; + DDukeActor* neartagsprite; int neartaghitdist; p = &ps[snum]; + auto pact = p->GetActor(); switch (sector[p->cursectnum].lotag) { @@ -2456,7 +2467,7 @@ void checksectors_r(int snum) if (sector[p->cursectnum].lotag >= 10000) { if (snum == screenpeek || ud.coop == 1) - S_PlayActorSound(sector[p->cursectnum].lotag - 10000, p->i); + S_PlayActorSound(sector[p->cursectnum].lotag - 10000, pact); sector[p->cursectnum].lotag = 0; } break; @@ -2465,10 +2476,10 @@ void checksectors_r(int snum) //After this point the the player effects the map with space - if (chatmodeon || sprite[p->i].extra <= 0) return; + if (chatmodeon || p->GetActor()->s.extra <= 0) return; if (ud.cashman && PlayerInput(snum, SB_OPEN)) - fi.lotsofmoney(&hittype[p->i], 2); + fi.lotsofmoney(p->GetActor(), 2); if (!(PlayerInput(snum, SB_OPEN))) @@ -2476,7 +2487,7 @@ void checksectors_r(int snum) else if (!p->toggle_key_flag) { - neartagsprite = -1; + neartagsprite = nullptr; p->toggle_key_flag = 1; hitscanwall = -1; @@ -2487,20 +2498,20 @@ void checksectors_r(int snum) if (hitscanwall >= 0 && wall[hitscanwall].overpicnum == MIRROR && snum == screenpeek) if (numplayers == 1) { - if (S_CheckActorSoundPlaying(p->i, 27) == 0 && S_CheckActorSoundPlaying(p->i, 28) == 0 && S_CheckActorSoundPlaying(p->i, 29) == 0 - && S_CheckActorSoundPlaying(p->i, 257) == 0 && S_CheckActorSoundPlaying(p->i, 258) == 0) + if (S_CheckActorSoundPlaying(pact, 27) == 0 && S_CheckActorSoundPlaying(pact, 28) == 0 && S_CheckActorSoundPlaying(pact, 29) == 0 + && S_CheckActorSoundPlaying(pact, 257) == 0 && S_CheckActorSoundPlaying(pact, 258) == 0) { short snd = krand() % 5; if (snd == 0) - S_PlayActorSound(27, p->i); + S_PlayActorSound(27, pact); else if (snd == 1) - S_PlayActorSound(28, p->i); + S_PlayActorSound(28, pact); else if (snd == 2) - S_PlayActorSound(29, p->i); + S_PlayActorSound(29, pact); else if (snd == 3) - S_PlayActorSound(257, p->i); + S_PlayActorSound(257, pact); else if (snd == 4) - S_PlayActorSound(258, p->i); + S_PlayActorSound(258, pact); } return; } @@ -2508,9 +2519,9 @@ void checksectors_r(int snum) else { if (hitscanwall >= 0 && wall[hitscanwall].overpicnum == MIRROR) - if (wall[hitscanwall].lotag > 0 && S_CheckActorSoundPlaying(p->i, wall[hitscanwall].lotag) == 0 && snum == screenpeek) + if (wall[hitscanwall].lotag > 0 && S_CheckActorSoundPlaying(pact, wall[hitscanwall].lotag) == 0 && snum == screenpeek) { - S_PlayActorSound(wall[hitscanwall].lotag, p->i); + S_PlayActorSound(wall[hitscanwall].lotag, pact); return; } } @@ -2539,24 +2550,24 @@ void checksectors_r(int snum) } return; } - neartag(p->posx, p->posy, p->posz, sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 3); + neartag(p->posx, p->posy, p->posz, p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 3); } - if (p->newowner >= 0) - neartag(p->oposx, p->oposy, p->oposz, sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (p->newOwner != nullptr) + neartag(p->oposx, p->oposy, p->oposz, p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); else { - neartag(p->posx, p->posy, p->posz, sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); - if (neartagsprite == -1 && neartagwall == -1 && neartagsector == -1) - neartag(p->posx, p->posy, p->posz + (8 << 8), sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); - if (neartagsprite == -1 && neartagwall == -1 && neartagsector == -1) - neartag(p->posx, p->posy, p->posz + (16 << 8), sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); - if (neartagsprite == -1 && neartagwall == -1 && neartagsector == -1) + neartag(p->posx, p->posy, p->posz, p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (neartagsprite == nullptr && neartagwall == -1 && neartagsector == -1) + neartag(p->posx, p->posy, p->posz + (8 << 8), p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (neartagsprite == nullptr && neartagwall == -1 && neartagsector == -1) + neartag(p->posx, p->posy, p->posz + (16 << 8), p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 1); + if (neartagsprite == nullptr && neartagwall == -1 && neartagsector == -1) { - neartag(p->posx, p->posy, p->posz + (16 << 8), sprite[p->i].sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 3); - if (neartagsprite >= 0) + neartag(p->posx, p->posy, p->posz + (16 << 8), p->GetActor()->s.sectnum, p->angle.oang.asbuild(), &neartagsector, &neartagwall, &neartagsprite, &neartaghitdist, 1280L, 3); + if (neartagsprite != nullptr) { - switch (sprite[neartagsprite].picnum) + switch (neartagsprite->s.picnum) { case FEM10: case NAKED1: @@ -2564,36 +2575,38 @@ void checksectors_r(int snum) case TOUGHGAL: return; case COW: - hittype[neartagsprite].spriteextra = 1; + neartagsprite->spriteextra = 1; return; } } - neartagsprite = -1; + neartagsprite = nullptr; neartagwall = -1; neartagsector = -1; } } - if (p->newowner == -1 && neartagsprite == -1 && neartagsector == -1 && neartagwall == -1) - if (isanunderoperator(sector[sprite[p->i].sectnum].lotag)) - neartagsector = sprite[p->i].sectnum; + if (p->newOwner == nullptr && neartagsprite == nullptr && neartagsector == -1 && neartagwall == -1) + if (isanunderoperator(sector[p->GetActor()->s.sectnum].lotag)) + neartagsector = p->GetActor()->s.sectnum; if (neartagsector >= 0 && (sector[neartagsector].lotag & 16384)) return; - if (neartagsprite == -1 && neartagwall == -1) + if (neartagsprite == nullptr && neartagwall == -1) if (sector[p->cursectnum].lotag == 2) { - oldz = hitasprite(p->i, &neartagsprite); - if (oldz > 1280) neartagsprite = -1; + DDukeActor* hit; + oldz = hitasprite(p->GetActor(), &hit); + if (hit) neartagsprite = hit; + if (oldz > 1280) neartagsprite = nullptr; } - if (neartagsprite >= 0) + if (neartagsprite != nullptr) { - if (fi.checkhitswitch(snum, neartagsprite, 1)) return; + if (fi.checkhitswitch(snum, -1,neartagsprite)) return; - switch (sprite[neartagsprite].picnum) + switch (neartagsprite->s.picnum) { case RRTILE8448: if (!isRRRA()) return; @@ -2605,9 +2618,10 @@ void checksectors_r(int snum) if (numplayers == 1) { // This is from RedneckGDX - the version in RR Reconstruction looked like broken nonsense. - if (S_CheckSoundPlaying(neartagsprite, 445) || sound445done != 0) + if (S_CheckActorSoundPlaying(neartagsprite, 445) || sound445done != 0) { - if (!S_CheckSoundPlaying(neartagsprite, 445) && !S_CheckSoundPlaying(neartagsprite, 446) && !S_CheckSoundPlaying(neartagsprite, 447) && sound445done != 0) + if (!S_CheckActorSoundPlaying(neartagsprite, 445) && !S_CheckActorSoundPlaying(neartagsprite, 446) && + !S_CheckActorSoundPlaying(neartagsprite, 447) && sound445done != 0) { if ((krand() % 2) == 1) S_PlayActorSound(446, neartagsprite); @@ -2641,7 +2655,7 @@ void checksectors_r(int snum) case RRTILE8594: case RRTILE8595: if (!isRRRA()) return; - sprite[neartagsprite].extra = 60; + neartagsprite->s.extra = 60; S_PlayActorSound(235, neartagsprite); return; @@ -2651,7 +2665,7 @@ void checksectors_r(int snum) case RRTILE2122: if (p->last_pissed_time == 0) { - S_PlayActorSound(435, p->i); + S_PlayActorSound(435, pact); p->last_pissed_time = 26 * 220; p->transporter_hold = 29 * 2; @@ -2660,33 +2674,33 @@ void checksectors_r(int snum) p->holster_weapon = 1; p->weapon_pos = -1; } - if (sprite[p->i].extra <= (max_player_health - (max_player_health / 10))) + if (p->GetActor()->s.extra <= (max_player_health - (max_player_health / 10))) { - sprite[p->i].extra += max_player_health / 10; - p->last_extra = sprite[p->i].extra; + p->GetActor()->s.extra += max_player_health / 10; + p->last_extra = p->GetActor()->s.extra; } - else if (sprite[p->i].extra < max_player_health) - sprite[p->i].extra = max_player_health; + else if (p->GetActor()->s.extra < max_player_health) + p->GetActor()->s.extra = max_player_health; } - else if (S_CheckActorSoundPlaying(p->i, DUKE_GRUNT) == 0) - S_PlayActorSound(DUKE_GRUNT, p->i); + else if (S_CheckActorSoundPlaying(pact, DUKE_GRUNT) == 0) + S_PlayActorSound(DUKE_GRUNT, pact); return; case WATERFOUNTAIN: - if (hittype[neartagsprite].temp_data[0] != 1) + if (neartagsprite->temp_data[0] != 1) { - hittype[neartagsprite].temp_data[0] = 1; - sprite[neartagsprite].owner = p->i; + neartagsprite->temp_data[0] = 1; + neartagsprite->SetOwner(p->GetActor()); - if (sprite[p->i].extra < max_player_health) + if (p->GetActor()->s.extra < max_player_health) { - sprite[p->i].extra++; - S_PlayActorSound(DUKE_DRINKING, p->i); + p->GetActor()->s.extra++; + S_PlayActorSound(DUKE_DRINKING, pact); } } return; case PLUG: - S_PlayActorSound(SHORT_CIRCUIT, p->i); - sprite[p->i].extra -= 2 + (krand() & 3); + S_PlayActorSound(SHORT_CIRCUIT, pact); + p->GetActor()->s.extra -= 2 + (krand() & 3); SetPlayerPal(p, PalEntry(32, 48, 48, 64)); break; } @@ -2694,12 +2708,12 @@ void checksectors_r(int snum) if (!PlayerInput(snum, SB_OPEN)) return; - if (neartagwall == -1 && neartagsector == -1 && neartagsprite == -1) - if (abs(hits(p->i)) < 512) + if (neartagwall == -1 && neartagsector == -1 && neartagsprite == nullptr) + if (abs(hits(p->GetActor())) < 512) { if ((krand() & 255) < 16) - S_PlayActorSound(DUKE_SEARCH2, p->i); - else S_PlayActorSound(DUKE_SEARCH, p->i); + S_PlayActorSound(DUKE_SEARCH2, pact); + else S_PlayActorSound(DUKE_SEARCH, pact); return; } @@ -2708,7 +2722,7 @@ void checksectors_r(int snum) if (wall[neartagwall].lotag > 0 && fi.isadoorwall(wall[neartagwall].picnum)) { if (hitscanwall == neartagwall || hitscanwall == -1) - fi.checkhitswitch(snum, neartagwall, 0); + fi.checkhitswitch(snum, neartagwall, nullptr); return; } } @@ -2716,44 +2730,45 @@ void checksectors_r(int snum) if (neartagsector >= 0 && (sector[neartagsector].lotag & 16384) == 0 && isanearoperator(sector[neartagsector].lotag)) { short unk = 0; - SectIterator it(neartagsector); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(neartagsector); + while (auto act = it.Next()) { - if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) + if (act->s.picnum == ACTIVATOR || act->s.picnum == MASTERSWITCH) return; } if (haskey(neartagsector, snum)) - operatesectors(neartagsector, p->i); + operatesectors(neartagsector, p->GetActor()); else { - if (hittype[neartagsprite].spriteextra > 3) - S_PlayActorSound(99, p->i); + if (neartagsprite && neartagsprite->spriteextra > 3) + S_PlayActorSound(99, pact); else - S_PlayActorSound(419, p->i); + S_PlayActorSound(419, pact); FTA(41, p); } } - else if ((sector[sprite[p->i].sectnum].lotag & 16384) == 0) + else if ((sector[p->GetActor()->s.sectnum].lotag & 16384) == 0) { - if (isanunderoperator(sector[sprite[p->i].sectnum].lotag)) + if (isanunderoperator(sector[p->GetActor()->s.sectnum].lotag)) { - SectIterator it(sprite[p->i].sectnum); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(p->GetActor()->s.sectnum); + while (auto act = it.Next()) { - if (sprite[i].picnum == ACTIVATOR || sprite[i].picnum == MASTERSWITCH) return; + if (act->s.picnum == ACTIVATOR || act->s.picnum == MASTERSWITCH) + return; } if (haskey(neartagsector, snum)) - operatesectors(sprite[p->i].sectnum, p->i); + operatesectors(p->GetActor()->s.sectnum, p->GetActor()); else { - if (hittype[neartagsprite].spriteextra > 3) - S_PlayActorSound(99, p->i); + if (neartagsprite && neartagsprite->spriteextra > 3) + S_PlayActorSound(99, pact); else - S_PlayActorSound(419, p->i); + S_PlayActorSound(419, pact); FTA(41, p); } } - else fi.checkhitswitch(snum, neartagwall, 0); + else fi.checkhitswitch(snum, neartagwall, nullptr); } } } @@ -2820,8 +2835,8 @@ void dofurniture(int wl, int sect, int snum) var_C = 0; if (var_C) { - if (S_CheckActorSoundPlaying(ps[snum].i, 389) == 0) - S_PlayActorSound(389, ps[snum].i); + if (S_CheckActorSoundPlaying(ps[snum].GetActor(), 389) == 0) + S_PlayActorSound(389, ps[snum].GetActor()); for (i = startwall; i < endwall; i++) { x = wall[i].x; @@ -2884,14 +2899,13 @@ void dofurniture(int wl, int sect, int snum) void tearitup(int sect) { - int j; - SectIterator it(sect); - while ((j = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto act = it.Next()) { - if (sprite[j].picnum == DESTRUCTO) + if (act->s.picnum == DESTRUCTO) { - hittype[j].picnum = SHOTSPARK1; - hittype[j].extra = 1; + act->picnum = SHOTSPARK1; + act->extra = 1; } } } diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 8010bda7e..29ca33b6e 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -39,6 +39,7 @@ source as it is released. #include "g_input.h" #include "duke3d.h" +#include "dukeactor.h" #include "raze_music.h" #include "mapinfo.h" #include "raze_sound.h" @@ -52,9 +53,21 @@ CVAR(Bool, wt_commentary, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) BEGIN_DUKE_NS +// These are needed until real objects can be used for actors. +inline void* sndActor(DDukeActor* actor) +{ + return actor ? &actor->s : nullptr; +} + +inline DDukeActor* getSndActor(const void* source) +{ + // transitional conversation voodoo + return source ? &hittype[((spritetype*)source) - sprite] : nullptr; +} + TArray specialmusic; static FSoundID currentCommentarySound; -static int currentCommentarySprite; +static DDukeActor* currentCommentarySprite; // todo: GC this once actors become objects class DukeSoundEngine : public SoundEngine @@ -90,7 +103,7 @@ public: { UnloadSound(schan->SoundID); currentCommentarySound = 0; - sprite[currentCommentarySprite].picnum = DEVELOPERCOMMENTARY; + currentCommentarySprite->s.picnum = DEVELOPERCOMMENTARY; I_SetRelativeVolume(1.0f); } SoundEngine::SoundDone(schan); @@ -220,9 +233,9 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit } -inline bool S_IsAmbientSFX(int spriteNum) +inline bool S_IsAmbientSFX(DDukeActor* actor) { - return (sprite[spriteNum].picnum == MUSICANDSFX && sprite[spriteNum].lotag < 999); + return (actor->s.picnum == MUSICANDSFX && actor->s.lotag < 999); } //========================================================================== @@ -231,13 +244,13 @@ inline bool S_IsAmbientSFX(int spriteNum) // //========================================================================== -static int GetPositionInfo(int spriteNum, int soundNum, int sectNum, +static int GetPositionInfo(DDukeActor* actor, int soundNum, int sectNum, const vec3_t *cam, const vec3_t *pos, int *distPtr, FVector3 *sndPos) { // There's a lot of hackery going on here that could be mapped to rolloff and attenuation parameters. // However, ultimately rolloff would also just reposition the sound source so this can remain as it is. - auto sp = &sprite[spriteNum]; + auto sp = &actor->s; int orgsndist = 0, sndang = 0, sndist = 0, explosion = 0; auto const* snd = soundEngine->GetUserData(soundNum + 1); int userflags = snd ? snd[kFlags] : 0; @@ -293,7 +306,7 @@ static int GetPositionInfo(int spriteNum, int soundNum, int sectNum, void S_GetCamera(vec3_t** c, int32_t* ca, int32_t* cs) { - if (ud.camerasprite == -1) + if (ud.cameraactor == nullptr) { auto p = &ps[screenpeek]; if (c) *c = &p->pos; @@ -302,9 +315,9 @@ void S_GetCamera(vec3_t** c, int32_t* ca, int32_t* cs) } else { - if (c) *c = &sprite[ud.camerasprite].pos; - if (cs) *cs = sprite[ud.camerasprite].sectnum; - if (ca) *ca = sprite[ud.camerasprite].ang; + if (c) *c = &ud.cameraactor->s.pos; + if (cs) *cs = ud.cameraactor->s.sectnum; + if (ca) *ca = ud.cameraactor->s.ang; } } @@ -334,11 +347,12 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3] } else if (type == SOURCE_Actor) { - auto actor = (spritetype*)source; + auto aactor = getSndActor(source); + auto actor = aactor ? &aactor->s : nullptr; assert(actor != nullptr); if (actor != nullptr) { - GetPositionInfo(int(actor - sprite), chanSound - 1, camsect, campos, &actor->pos, nullptr, pos); + GetPositionInfo(aactor, chanSound - 1, camsect, campos, &actor->pos, nullptr, pos); /* if (vel) // DN3D does not properly maintain this. { @@ -395,7 +409,7 @@ void GameInterface::UpdateSounds(void) listener.Environment = nullptr; listener.valid = false; } - listener.ListenerObject = ud.camerasprite == -1 ? nullptr : &sprite[ud.camerasprite]; + listener.ListenerObject = ud.cameraactor == nullptr ? nullptr : &ud.cameraactor->s; soundEngine->SetListener(listener); } @@ -406,21 +420,19 @@ void GameInterface::UpdateSounds(void) // //========================================================================== -int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, EChanFlags flags) +int S_PlaySound3D(int sndnum, DDukeActor* actor, const vec3_t* pos, int channel, EChanFlags flags) { if (sndnum == GENERIC_AMBIENCE1 || sndnum == DUMPSTER_MOVE) { int a = 0; } auto const pl = &ps[myconnectindex]; - if (!soundEngine->isValidSoundId(sndnum+1) || !SoundEnabled() || (unsigned)spriteNum >= MAXSPRITES || !playrunning() || + if (!soundEngine->isValidSoundId(sndnum+1) || !SoundEnabled() || actor == nullptr || !playrunning() || (pl->timebeforeexit > 0 && pl->timebeforeexit <= REALGAMETICSPERSEC * 3)) return -1; sndnum = GetReplacementSound(sndnum); int userflags = S_GetUserFlags(sndnum); - auto sp = &sprite[spriteNum]; - if ((userflags & (SF_DTAG | SF_GLOBAL)) == SF_DTAG) { // Duke-Tag sound does not play in 3D. @@ -429,7 +441,7 @@ int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, ECh if (userflags & SF_TALK) { - if (snd_speech == 0 || (ud.multimode > 1 && sp->picnum == TILE_APLAYER && sp->yvel != screenpeek && ud.coop != 1)) return -1; + if (snd_speech == 0 || (ud.multimode > 1 && actor->s.picnum == TILE_APLAYER && actor->s.yvel != screenpeek && ud.coop != 1)) return -1; bool foundone = soundEngine->EnumerateChannels([&](FSoundChan* chan) { auto sid = chan->OrgID; @@ -443,8 +455,7 @@ int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, ECh // Fixes a problem with quake06.voc in E3L4. if (ud.multimode == 1) { - spriteNum = pl->i; - auto sp = &sprite[spriteNum]; + actor = pl->GetActor(); } } @@ -455,7 +466,7 @@ int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, ECh int32_t camsect; S_GetCamera(&campos, nullptr, &camsect); - GetPositionInfo(spriteNum, sndnum, camsect, campos, pos, &sndist, &sndpos); + GetPositionInfo(actor, sndnum, camsect, campos, pos, &sndist, &sndpos); int pitch = S_GetPitch(sndnum); bool explosion = ((userflags & (SF_GLOBAL | SF_DTAG)) == (SF_GLOBAL | SF_DTAG)) || ((sndnum == PIPEBOMB_EXPLODE || sndnum == LASERTRIP_EXPLODE || sndnum == RPG_EXPLODE)); @@ -468,7 +479,7 @@ int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, ECh } else { - if (sndist > 32767 && sp->picnum != MUSICANDSFX && (userflags & (SF_LOOP | SF_MSFX)) == 0) + if (sndist > 32767 && actor->s.picnum != MUSICANDSFX && (userflags & (SF_LOOP | SF_MSFX)) == 0) return -1; if (underwater && (userflags & SF_TALK) == 0) @@ -476,8 +487,8 @@ int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, ECh } bool is_playing = soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, sndnum+1); - if (is_playing && sp->picnum != MUSICANDSFX) - S_StopSound(sndnum, spriteNum); + if (is_playing && actor->s.picnum != MUSICANDSFX) + S_StopSound(sndnum, actor); int const repeatp = (userflags & SF_LOOP); @@ -494,7 +505,7 @@ int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, ECh else attenuation = (userflags & (SF_GLOBAL | SF_DTAG)) == SF_GLOBAL ? ATTN_NONE : ATTN_NORM; if (userflags & SF_LOOP) flags |= CHANF_LOOP; - auto chan = soundEngine->StartSound(SOURCE_Actor, &sprite[spriteNum], &sndpos, CHAN_AUTO, flags, sndnum+1, attenuation == ATTN_NONE? 0.8f : 1.f, attenuation, nullptr, S_ConvertPitch(pitch)); + auto chan = soundEngine->StartSound(SOURCE_Actor, sndActor(actor), &sndpos, CHAN_AUTO, flags, sndnum+1, attenuation == ATTN_NONE? 0.8f : 1.f, attenuation, nullptr, S_ConvertPitch(pitch)); return chan ? 0 : -1; } @@ -527,51 +538,46 @@ int S_PlaySound(int sndnum, int channel, EChanFlags flags, float vol) // //========================================================================== -int S_PlayActorSound(int soundNum, int spriteNum, int channel, EChanFlags flags) +int S_PlayActorSound(int soundNum, DDukeActor* actor, int channel, EChanFlags flags) { - return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, channel, flags) : - S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, channel, flags); + return (actor == nullptr ? S_PlaySound(soundNum, channel, flags) : + S_PlaySound3D(soundNum, actor, &actor->s.pos, channel, flags)); } -void S_RelinkActorSound(int from, int to) +void S_RelinkActorSound(DDukeActor* from, DDukeActor* to) { - FVector3 pos = GetSoundPos(&sprite[from].pos); - soundEngine->RelinkSound(SOURCE_Actor, &sprite[from], to == -1 ? nullptr : &sprite[to], &pos); + FVector3 pos = GetSoundPos(&from->s.pos); + soundEngine->RelinkSound(SOURCE_Actor, sndActor(from), sndActor(to), &pos); } -void S_StopSound(int sndNum, int sprNum, int channel) +void S_StopSound(int sndNum, DDukeActor* actor, int channel) { - if (sprNum < -1 || sprNum >= MAXSPRITES) return; - sndNum = GetReplacementSound(sndNum); - - if (sprNum == -1) soundEngine->StopSoundID(sndNum+1); + if (!actor) soundEngine->StopSoundID(sndNum+1); else { - if (channel == -1) soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum + 1); - else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], channel, -1); + if (channel == -1) soundEngine->StopSound(SOURCE_Actor, sndActor(actor), -1, sndNum + 1); + else soundEngine->StopSound(SOURCE_Actor, actor, channel, -1); // StopSound kills the actor reference so this cannot be delayed until ChannelEnded gets called. At that point the actor may also not be valid anymore. - if (S_IsAmbientSFX(sprNum) && sector[sprite[sprNum].sectnum].lotag < 3) // ST_2_UNDERWATER - hittype[sprNum].temp_data[0] = 0; + if (S_IsAmbientSFX(actor) && sector[actor->s.sectnum].lotag < 3) // ST_2_UNDERWATER + actor->temp_data[0] = 0; } } -void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset) +void S_ChangeSoundPitch(int soundNum, DDukeActor* actor, int pitchoffset) { - if (spriteNum < -1 || spriteNum >= MAXSPRITES) return; - soundNum = GetReplacementSound(soundNum); double expitch = pow(2, pitchoffset / 1200.); // I hope I got this right that ASS uses a linear scale where 1200 is a full octave. - if (spriteNum == -1) + if (!actor) { soundEngine->ChangeSoundPitch(SOURCE_Unattached, nullptr, CHAN_AUTO, expitch, soundNum+1); } else { - soundEngine->ChangeSoundPitch(SOURCE_Actor, &sprite[spriteNum], CHAN_AUTO, expitch, soundNum+1); + soundEngine->ChangeSoundPitch(SOURCE_Actor, sndActor(actor), CHAN_AUTO, expitch, soundNum+1); } } @@ -581,20 +587,19 @@ void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset) // //========================================================================== -int S_CheckActorSoundPlaying(int spriteNum, int soundNum, int channel) +int S_CheckActorSoundPlaying(DDukeActor* actor, int soundNum, int channel) { soundNum = GetReplacementSound(soundNum); - if (spriteNum == -1) return soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, soundNum+1); - if ((unsigned)spriteNum >= MAXSPRITES) return false; - return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, &sprite[spriteNum], channel, soundNum+1); + if (actor == nullptr) return soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, soundNum+1); + return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, sndActor(actor), channel, soundNum+1); } // Check if actor is playing any sound. -int S_CheckAnyActorSoundPlaying(int spriteNum) +int S_CheckAnyActorSoundPlaying(DDukeActor* actor) { - if ((unsigned)spriteNum >= MAXSPRITES) return false; - return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, &sprite[spriteNum], CHAN_AUTO, 0); + if (!actor) return false; + return soundEngine->IsSourcePlayingSomething(SOURCE_Actor, sndActor(actor), CHAN_AUTO, 0); } int S_CheckSoundPlaying(int soundNum) @@ -815,7 +820,7 @@ void StopCommentary() } } -bool StartCommentary(int tag, int sprnum) +bool StartCommentary(int tag, DDukeActor* actor) { if (wt_commentary && Commentaries.Size() > tag && Commentaries[tag].IsNotEmpty()) { @@ -833,7 +838,7 @@ bool StartCommentary(int tag, int sprnum) StopCommentary(); soundEngine->StartSound(SOURCE_None, nullptr, nullptr, CHAN_VOICE, CHANF_UI | CHANF_TRANSIENT | CHANF_OVERLAP, id, 1.f, 0.f); currentCommentarySound = id; - currentCommentarySprite = sprnum; + currentCommentarySprite = actor; I_SetRelativeVolume(0.25f); return true; } diff --git a/source/games/duke/src/sounds.h b/source/games/duke/src/sounds.h index 0bc7891bd..883496606 100644 --- a/source/games/duke/src/sounds.h +++ b/source/games/duke/src/sounds.h @@ -40,19 +40,19 @@ int S_DefineSound(unsigned index, const char* filename, int ps, int pe, int pr, void S_WorldTourMappingsForOldSounds(); int S_PlaySound(int num, int channel = CHAN_AUTO, EChanFlags flags = 0, float vol =0.8f); -int S_PlaySound3D(int num, int spriteNum, const vec3_t* pos, int channel = CHAN_AUTO, EChanFlags flags = 0); -int S_PlayActorSound(int soundNum, int spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0); -void S_RelinkActorSound(int from, int to); +int S_PlaySound3D(int num, DDukeActor* spriteNum, const vec3_t* pos, int channel = CHAN_AUTO, EChanFlags flags = 0); +int S_PlayActorSound(int soundNum, DDukeActor* spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0); +void S_RelinkActorSound(DDukeActor* from, DDukeActor* to); void S_MenuSound(void); -void S_StopSound(int sndNum, int sprNum = -1, int flags = -1); +void S_StopSound(int sndNum, DDukeActor* spr = nullptr, int flags = -1); int S_CheckSoundPlaying(int soundNum); inline int S_CheckSoundPlaying(int sprnum, int soundNum) { return S_CheckSoundPlaying(soundNum); } -int S_CheckActorSoundPlaying(int spriteNum, int soundNum, int channel = 0); -int S_CheckAnyActorSoundPlaying(int spriteNum); +int S_CheckActorSoundPlaying(DDukeActor* spriteNum, int soundNum, int channel = 0); +int S_CheckAnyActorSoundPlaying(DDukeActor* spriteNum); -void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset); +void S_ChangeSoundPitch(int soundNum, DDukeActor* spriteNum, int pitchoffset); int S_GetUserFlags(int sndnum); inline bool S_IsSoundValid(int num) @@ -72,7 +72,7 @@ void S_ContinueLevelMusic(void); void S_ParseDeveloperCommentary(); void StopCommentary(); -bool StartCommentary(int tag, int sprnum); +bool StartCommentary(int tag, DDukeActor* sprnum); extern TArray specialmusic; diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index 02f652df2..c68f061e8 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -48,11 +48,8 @@ BEGIN_DUKE_NS // //--------------------------------------------------------------------------- -short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, short s_ow, signed char s_ss) +DDukeActor* EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, DDukeActor* s_ow, signed char s_ss) { - //if (isRR() && s_ow < 0 && !force) // should never happen, the only owner-less spawn outside of map start is for the Holoduke, which is Duke only - //return 0; - int const i = insertsprite(whatsect, s_ss); if (i < 0) @@ -77,7 +74,6 @@ short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s s->ang = s_a; s->xvel = s_ve; s->zvel = s_zv; - s->owner = s_ow; s->xoffset = 0; s->yoffset = 0; s->yvel = 0; @@ -85,21 +81,30 @@ short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s s->pal = 0; s->lotag = 0; - act->picnum = sprite[s_ow].picnum; - act->lastvx = 0; act->lastvy = 0; act->timetosleep = 0; act->actorstayput = -1; act->extra = -1; - act->owner = s_ow; act->cgg = 0; act->movflag = 0; act->tempang = 0; act->dispicnum = 0; - act->floorz = hittype[s_ow].floorz; - act->ceilingz = hittype[s_ow].ceilingz; + act->SetHitOwner(s_ow); + act->SetOwner(s_ow); + + if (s_ow) + { + act->picnum = s_ow->s.picnum; + act->floorz = s_ow->floorz; + act->ceilingz = s_ow->ceilingz; + } + else + { + + } + memset(act->temp_data, 0, sizeof(act->temp_data)); if (actorinfo[s_pn].scriptaddress) { @@ -121,7 +126,7 @@ short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s spriteext[i] = {}; spritesmooth[i] = {}; - return(i); + return act; } @@ -131,18 +136,19 @@ short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s // //--------------------------------------------------------------------------- -int initspriteforspawn(int j, int pn, const std::initializer_list &excludes) +int initspriteforspawn(DDukeActor* actj, int pn, const std::initializer_list &excludes) { - int i; spritetype* sp; int* t; + int i; - if (j >= 0) + if (actj) { - i = EGS(sprite[j].sectnum, sprite[j].x, sprite[j].y, sprite[j].z, pn, 0, 0, 0, 0, 0, 0, j, 0); - hittype[i].picnum = sprite[j].picnum; - sp = &sprite[i]; - t = hittype[i].temp_data; + auto spawned = EGS(actj->s.sectnum, actj->s.x, actj->s.y, actj->s.z, pn, 0, 0, 0, 0, 0, 0, actj, 0); + spawned->picnum = actj->s.picnum; + sp = &spawned->s; + t = spawned->temp_data; + i = spawned->GetIndex(); } else { @@ -159,7 +165,8 @@ int initspriteforspawn(int j, int pn, const std::initializer_list &excludes act->bposy = sp->y; act->bposz = sp->z; - sp->owner = act->owner = i; + act->SetOwner(act); + act->SetHitOwner(act); act->cgg = 0; act->movflag = 0; act->tempang = 0; @@ -172,12 +179,13 @@ int initspriteforspawn(int j, int pn, const std::initializer_list &excludes act->actorstayput = -1; t[0] = t[1] = t[2] = t[3] = t[4] = t[5] = 0; + act->temp_actor = nullptr; if (sp->cstat & 48) if (!isIn(sp->picnum, excludes) && (sp->cstat & 48)) { if (sp->shade == 127) return i; - if (wallswitchcheck(i) && (sp->cstat & 16)) + if (wallswitchcheck(act) && (sp->cstat & 16)) { if (sp->picnum != TILE_ACCESSSWITCH && sp->picnum != TILE_ACCESSSWITCH2 && sp->pal) { @@ -227,19 +235,18 @@ int initspriteforspawn(int j, int pn, const std::initializer_list &excludes // //--------------------------------------------------------------------------- -void spawninitdefault(int j, int i) +void spawninitdefault(DDukeActor* actj, DDukeActor *act) { - auto act = &hittype[i]; auto sp = &act->s; auto sect = sp->sectnum; if (actorinfo[sp->picnum].scriptaddress) { - if (j == -1 && sp->lotag > ud.player_skill) + if (actj == nullptr && sp->lotag > ud.player_skill) { // make it go away... sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(act, STAT_MISC); return; } @@ -247,43 +254,43 @@ void spawninitdefault(int j, int i) if (sp->xrepeat == 0 || sp->yrepeat == 0) sp->xrepeat = sp->yrepeat = 1; - if (actorflag(i, SFLAG_BADGUY)) + if (actorflag(act, SFLAG_BADGUY)) { if (ud.monsters_off == 1) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(act, STAT_MISC); return; } - makeitfall(i); + makeitfall(act); - if (actorflag(i, SFLAG_BADGUYSTAYPUT)) + if (actorflag(act, SFLAG_BADGUYSTAYPUT)) act->actorstayput = sp->sectnum; - if (!isRR() || actorflag(i, SFLAG_KILLCOUNT)) // Duke is just like Doom - Bad guys always count as kill. + if (!isRR() || actorflag(act, SFLAG_KILLCOUNT)) // Duke is just like Doom - Bad guys always count as kill. ps[myconnectindex].max_actors_killed++; sp->clipdist = 80; - if (j >= 0) + if (actj) { - if (sprite[j].picnum == RESPAWN) - act->tempang = sp->pal = sprite[j].pal; - changespritestat(i, STAT_ACTOR); + if (actj->s.picnum == RESPAWN) + act->tempang = sp->pal = actj->s.pal; + changespritestat(act, STAT_ACTOR); } - else changespritestat(i, STAT_ZOMBIEACTOR); + else changespritestat(act, STAT_ZOMBIEACTOR); } else { sp->clipdist = 40; - sp->owner = i; - changespritestat(i, STAT_ACTOR); + act->SetOwner(act); + changespritestat(act, STAT_ACTOR); } act->timetosleep = 0; - if (j >= 0) - sp->ang = sprite[j].ang; + if (actj) + sp->ang = actj->s.ang; } } @@ -293,19 +300,20 @@ void spawninitdefault(int j, int i) // //--------------------------------------------------------------------------- -void spawntransporter(int j, int i, bool beam) +void spawntransporter(DDukeActor *actj, DDukeActor* acti, bool beam) { - if (j == -1) return; - auto sp = &sprite[i]; + if (actj == nullptr) return; + auto sp = &acti->s; + auto spj = &actj->s; if (beam) { sp->xrepeat = 31; sp->yrepeat = 1; - sp->z = sector[sprite[j].sectnum].floorz - (40 << 8); + sp->z = sector[spj->sectnum].floorz - (40 << 8); } else { - if (sprite[j].statnum == 4) + if (spj->statnum == 4) { sp->xrepeat = 8; sp->yrepeat = 8; @@ -314,19 +322,19 @@ void spawntransporter(int j, int i, bool beam) { sp->xrepeat = 48; sp->yrepeat = 64; - if (sprite[j].statnum == 10 || badguy(&sprite[j])) + if (spj->statnum == 10 || badguy(spj)) sp->z -= (32 << 8); } } sp->shade = -127; sp->cstat = 128 | 2; - sp->ang = sprite[j].ang; + sp->ang = spj->ang; sp->xvel = 128; - changespritestat(i, STAT_MISC); - ssp(i, CLIPMASK0); - setsprite(i, sp->x, sp->y, sp->z); + changespritestat(acti, STAT_MISC); + ssp(acti, CLIPMASK0); + setsprite(acti, sp->x, sp->y, sp->z); } //--------------------------------------------------------------------------- @@ -335,9 +343,9 @@ void spawntransporter(int j, int i, bool beam) // //--------------------------------------------------------------------------- -int spawnbloodpoolpart1(int j, int i) +int spawnbloodpoolpart1(DDukeActor *actj, DDukeActor* acti) { - auto sp = &sprite[i]; + auto sp = &acti->s; short s1 = sp->sectnum; updatesector(sp->x + 108, sp->y + 108, &s1); @@ -352,18 +360,18 @@ int spawnbloodpoolpart1(int j, int i) updatesector(sp->x - 108, sp->y + 108, &s1); if (s1 >= 0 && sector[s1].floorz != sector[sp->sectnum].floorz) { - sp->xrepeat = sp->yrepeat = 0; changespritestat(i, STAT_MISC); return true; + sp->xrepeat = sp->yrepeat = 0; changespritestat(acti, STAT_MISC); return true; } } - else { sp->xrepeat = sp->yrepeat = 0; changespritestat(i, STAT_MISC); return true; } + else { sp->xrepeat = sp->yrepeat = 0; changespritestat(acti, STAT_MISC); return true; } } - else { sp->xrepeat = sp->yrepeat = 0; changespritestat(i, STAT_MISC); return true; } + else { sp->xrepeat = sp->yrepeat = 0; changespritestat(acti, STAT_MISC); return true; } } - else { sp->xrepeat = sp->yrepeat = 0; changespritestat(i, STAT_MISC); return true; } + else { sp->xrepeat = sp->yrepeat = 0; changespritestat(acti, STAT_MISC); return true; } if (sector[sp->sectnum].lotag == 1) { - changespritestat(i, STAT_MISC); + changespritestat(acti, STAT_MISC); return true; } return false; @@ -375,11 +383,11 @@ int spawnbloodpoolpart1(int j, int i) // //--------------------------------------------------------------------------- -void initfootprint(int j, int i) +void initfootprint(DDukeActor* actj, DDukeActor* acti) { - auto sp = &sprite[i]; + auto sp = &acti->s; int sect = sp->sectnum; - if (j >= 0) + if (actj) { short s1; s1 = sp->sectnum; @@ -396,7 +404,7 @@ void initfootprint(int j, int i) updatesector(sp->x - 84, sp->y + 84, &s1); if (s1 >= 0 && sector[s1].floorz != sector[sp->sectnum].floorz) { - sp->xrepeat = sp->yrepeat = 0; changespritestat(i, STAT_MISC); return; + sp->xrepeat = sp->yrepeat = 0; changespritestat(acti, STAT_MISC); return; } } else { sp->xrepeat = sp->yrepeat = 0; return; } @@ -405,16 +413,16 @@ void initfootprint(int j, int i) } else { sp->xrepeat = sp->yrepeat = 0; return; } - sp->cstat = 32 + ((ps[sprite[j].yvel].footprintcount & 1) << 2); - sp->ang = sprite[j].ang; + sp->cstat = 32 + ((ps[actj->s.yvel].footprintcount & 1) << 2); + sp->ang = actj->s.ang; } sp->z = sector[sect].floorz; if (sector[sect].lotag != 1 && sector[sect].lotag != 2) sp->xrepeat = sp->yrepeat = 32; - insertspriteq(&hittype[i]); - changespritestat(i, STAT_MISC); + insertspriteq(acti); + changespritestat(acti, STAT_MISC); } //--------------------------------------------------------------------------- @@ -423,14 +431,14 @@ void initfootprint(int j, int i) // //--------------------------------------------------------------------------- -void initshell(int j, int i, bool isshell) +void initshell(DDukeActor* actj, DDukeActor* acti, bool isshell) { - auto sp = &sprite[i]; + auto sp = &acti->s; int sect = sp->sectnum; - auto spj = &sprite[j]; - auto t = hittype[i].temp_data; - if (j >= 0) + auto t = acti->temp_data; + if (actj) { + auto spj = &actj->s; short snum, a; if (spj->picnum == TILE_APLAYER) @@ -467,7 +475,7 @@ void initshell(int j, int i, bool isshell) sp->xrepeat = sp->yrepeat = isRR() && isshell? 2 : 4; - changespritestat(i, STAT_MISC); + changespritestat(acti, STAT_MISC); } } @@ -477,11 +485,11 @@ void initshell(int j, int i, bool isshell) // //--------------------------------------------------------------------------- -void initcrane(int j, int i, int CRANEPOLE) +void initcrane(DDukeActor* actj, DDukeActor* acti, int CRANEPOLE) { - auto sp = &sprite[i]; + auto sp = &acti->s; int sect = sp->sectnum; - auto t = hittype[i].temp_data; + auto t = acti->temp_data; sp->cstat |= 64 | 257; sp->picnum += 2; @@ -492,14 +500,13 @@ void initcrane(int j, int i, int CRANEPOLE) msy[tempwallptr] = sp->y; msx[tempwallptr + 2] = sp->z; - int s; - StatIterator it(STAT_DEFAULT); - while ((s = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_DEFAULT); + while (auto act = it.Next()) { - auto ss = &sprite[s]; + auto ss = &act->s; if (ss->picnum == CRANEPOLE && sp->hitag == (ss->hitag)) { - msy[tempwallptr + 2] = s; + msy[tempwallptr + 2] = ActorToScriptIndex(act); t[1] = ss->sectnum; @@ -514,15 +521,15 @@ void initcrane(int j, int i, int CRANEPOLE) ss->z = sp->z; ss->shade = sp->shade; - setsprite(s, ss->x, ss->y, ss->z); + setsprite(act, ss->pos); break; } } tempwallptr += 3; - sp->owner = -1; + acti->SetOwner(nullptr); sp->extra = 8; - changespritestat(i, 6); + changespritestat(acti, STAT_STANDABLE); } //--------------------------------------------------------------------------- @@ -531,15 +538,15 @@ void initcrane(int j, int i, int CRANEPOLE) // //--------------------------------------------------------------------------- -void initwaterdrip(int j, int i) +void initwaterdrip(DDukeActor* actj, DDukeActor* actor) { - auto sp = &sprite[i]; + auto sp = &actor->s; int sect = sp->sectnum; - auto t = hittype[i].temp_data; - if (j >= 0 && (sprite[j].statnum == 10 || sprite[j].statnum == 1)) + auto t = actor->temp_data; + if (actj && (actj->s.statnum == 10 || actj->s.statnum == 1)) { sp->shade = 32; - if (sprite[j].pal != 1) + if (actj->s.pal != 1) { sp->pal = 2; sp->z -= (18 << 8); @@ -547,9 +554,9 @@ void initwaterdrip(int j, int i) else sp->z -= (13 << 8); sp->ang = getangle(ps[connecthead].posx - sp->x, ps[connecthead].posy - sp->y); sp->xvel = 48 - (krand() & 31); - ssp(i, CLIPMASK0); + ssp(actor, CLIPMASK0); } - else if (j == -1) + else if (!actj) { sp->z += (4 << 8); t[0] = sp->z; @@ -557,7 +564,7 @@ void initwaterdrip(int j, int i) } sp->xrepeat = 24; sp->yrepeat = 24; - changespritestat(i, 6); + changespritestat(actor, STAT_STANDABLE); } @@ -567,26 +574,26 @@ void initwaterdrip(int j, int i) // //--------------------------------------------------------------------------- -int initreactor(int j, int i, bool isrecon) +int initreactor(DDukeActor* actj, DDukeActor* actor, bool isrecon) { - auto sp = &sprite[i]; + auto sp = &actor->s; int sect = sp->sectnum; - auto t = hittype[i].temp_data; + auto t = actor->temp_data; if (isrecon) { if (sp->lotag > ud.player_skill) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(actor, STAT_MISC); return true; } - if (!isRR() || actorflag(i, SFLAG_KILLCOUNT)) // Duke is just like Doom - Bad guys always count as kill. + if (!isRR() || actorflag(actor, SFLAG_KILLCOUNT)) // Duke is just like Doom - Bad guys always count as kill. ps[myconnectindex].max_actors_killed++; - hittype[i].temp_data[5] = 0; + actor->temp_data[5] = 0; if (ud.monsters_off == 1) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(actor, STAT_MISC); return false; } sp->extra = 130; @@ -599,13 +606,13 @@ int initreactor(int j, int i, bool isrecon) if (ud.multimode < 2 && sp->pal != 0) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(actor, STAT_MISC); return false; } sp->pal = 0; sp->shade = -17; - changespritestat(i, 2); + changespritestat(actor, 2); return false; } @@ -615,12 +622,12 @@ int initreactor(int j, int i, bool isrecon) // //--------------------------------------------------------------------------- -void spawneffector(int i) +void spawneffector(DDukeActor* actor) { - auto sp = &sprite[i]; + auto sp = &actor->s; int sect = sp->sectnum; - auto t = hittype[i].temp_data; - int j, startwall, endwall, x, y, d, s, clostest; + auto t = actor->temp_data; + int startwall, endwall, x, y, d, s, clostest; sp->yvel = sector[sect].extra; sp->cstat |= 32768; @@ -628,31 +635,34 @@ void spawneffector(int i) switch (sp->lotag) { - case 28: + case SE_28_LIGHTNING: if (!isRR()) t[5] = 65;// Delay for lightning break; - case 7: // Transporters!!!! - case 23:// XPTR END + case SE_7_TELEPORT: // Transporters!!!! + case SE_23_ONE_WAY_TELEPORT:// XPTR END if (sp->lotag != 23) { - for (j = 0; j < MAXSPRITES; j++) - if (sprite[j].statnum < MAXSTATUS && sprite[j].picnum == SECTOREFFECTOR && (sprite[j].lotag == 7 || sprite[j].lotag == 23) && i != j && sprite[j].hitag == sp->hitag) + DukeSpriteIterator it; + while (auto act2 = it.Next()) { - sp->owner = j; + if (act2->s.statnum < MAXSTATUS && act2->s.picnum == SECTOREFFECTOR && (act2->s.lotag == 7 || act2->s.lotag == 23) && actor != act2 && act2->s.hitag == sp->hitag) + { + actor->SetOwner(act2); break; } } - else sp->owner = i; + } + else actor->SetOwner(actor); t[4] = sector[sect].floorz == sp->z; sp->cstat = 0; - changespritestat(i, 9); + changespritestat(actor, STAT_TRANSPORT); return; - case 1: - sp->owner = -1; + case SE_1_PIVOT: + actor->SetOwner(nullptr); t[0] = 1; break; - case 18: + case SE_18_INCREMENTAL_SECTOR_RISE_FALL: if (sp->ang == 512) { @@ -670,10 +680,10 @@ void spawneffector(int i) sp->hitag <<= 2; break; - case 19: - sp->owner = -1; + case SE_19_EXPLOSION_LOWERS_CEILING: + actor->SetOwner(nullptr); break; - case 25: // Pistons + case SE_25_PISTON: // Pistons if (!isRR()) { t[3] = sector[sect].ceilingz; @@ -685,37 +695,36 @@ void spawneffector(int i) sector[sect].ceilingz = sp->z; setinterpolation(§or[sect].ceilingz); break; - case 35: + case SE_35: sector[sect].ceilingz = sp->z; break; - case 27: + case SE_27_DEMO_CAM: if (ud.recstat == 1) { sp->xrepeat = sp->yrepeat = 64; sp->cstat &= 32767; } break; - case 47: - case 48: + case SE_47_LIGHT_SWITCH: + case SE_48_LIGHT_SWITCH: if (!isRRRA()) break; - case 12: + case SE_12_LIGHT_SWITCH: t[1] = sector[sect].floorshade; t[2] = sector[sect].ceilingshade; break; - case 13: - + case SE_13_EXPLOSIVE: + { t[0] = sector[sect].ceilingz; t[1] = sector[sect].floorz; - if (abs(t[0] - sp->z) < abs(t[1] - sp->z)) - sp->owner = 1; - else sp->owner = 0; + bool ceiling = (abs(t[0] - sp->z) < abs(t[1] - sp->z)); + actor->spriteextra = ceiling; if (sp->ang == 512) { - if (sp->owner) + if (ceiling) sector[sect].ceilingz = sp->z; else sector[sect].floorz = sp->z; @@ -728,7 +737,7 @@ void spawneffector(int i) sector[sect].ceilingstat ^= 1; t[3] = 1; - if (!sp->owner && sp->ang == 512) + if (!ceiling && sp->ang == 512) { sector[sect].ceilingstat ^= 1; t[3] = 0; @@ -741,7 +750,7 @@ void spawneffector(int i) { startwall = sector[sect].wallptr; endwall = startwall + sector[sect].wallnum; - for (j = startwall; j < endwall; j++) + for (int j = startwall; j < endwall; j++) { int x = wall[j].nextsector; if (x >= 0) @@ -758,12 +767,12 @@ void spawneffector(int i) } break; - - case 17: - + } + case SE_17_WARP_ELEVATOR: + { t[2] = sector[sect].floorz; //Stopping loc - j = nextsectorneighborz(sect, sector[sect].floorz, -1, -1); + int j = nextsectorneighborz(sect, sector[sect].floorz, -1, -1); t[3] = sector[j].ceilingz; j = nextsectorneighborz(sect, sector[sect].ceilingz, 1, 1); @@ -776,13 +785,13 @@ void spawneffector(int i) } break; - - case 24: + } + case SE_24_CONVEYOR: sp->yvel <<= 1; - case 36: + case SE_36_PROJ_SHOOTER: break; - case 20: + case SE_20_STRETCH_BRIDGE: { int q; @@ -827,15 +836,14 @@ void spawneffector(int i) } - case 3: + case SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT: t[3] = sector[sect].floorshade; sector[sect].floorshade = sp->shade; sector[sect].ceilingshade = sp->shade; - sp->owner = sector[sect].ceilingpal << 8; - sp->owner |= sector[sect].floorpal; + actor->palvals = (sector[sect].ceilingpal << 8) | sector[sect].floorpal; //fix all the walls; @@ -851,7 +859,7 @@ void spawneffector(int i) } break; - case 31: + case SE_31_FLOOR_RISE_FALL: t[1] = sector[sect].floorz; // t[2] = sp->hitag; if (sp->ang != 1536) sector[sect].floorz = sp->z; @@ -865,7 +873,7 @@ void spawneffector(int i) setinterpolation(§or[sect].floorz); break; - case 32: + case SE_32_CEILING_RISE_FALL: t[1] = sector[sect].ceilingz; t[2] = sp->hitag; if (sp->ang != 1536) sector[sect].ceilingz = sp->z; @@ -880,15 +888,14 @@ void spawneffector(int i) break; - case 4: //Flashing lights + case SE_4_RANDOM_LIGHTS: //Flashing lights t[2] = sector[sect].floorshade; startwall = sector[sect].wallptr; endwall = startwall + sector[sect].wallnum; - sp->owner = sector[sect].ceilingpal << 8; - sp->owner |= sector[sect].floorpal; + actor->palvals = (sector[sect].ceilingpal << 8) | sector[sect].floorpal; for (s = startwall; s < endwall; s++) if (wall[s].shade > t[3]) @@ -896,11 +903,11 @@ void spawneffector(int i) break; - case 9: + case SE_9_DOWN_OPEN_DOOR_LIGHTS: if (sector[sect].lotag && labs(sector[sect].ceilingz - sp->z) > 1024) sector[sect].lotag |= 32768; //If its open - case 8: + case SE_8_UP_OPEN_DOOR_LIGHTS: //First, get the ceiling-floor shade t[0] = sector[sect].floorshade; @@ -934,49 +941,53 @@ void spawneffector(int i) t[3] = 1; //Take Out; break; - case 11://Pivitor rotater + case SE_11_SWINGING_DOOR://Pivitor rotater if (sp->ang > 1024) t[3] = 2; else t[3] = -2; - case 0: - case 2://Earthquakemakers - case 5://Boss Creature - case 6://Subway - case 14://Caboos - case 15://Subwaytype sliding door - case 16://That rotating blocker reactor thing - case 26://ESCELATOR - case 30://No rotational subways + case SE_0_ROTATING_SECTOR: + case SE_2_EARTHQUAKE://Earthquakemakers + case SE_5_BOSS://Boss Creature + case SE_6_SUBWAY://Subway + case SE_14_SUBWAY_CAR://Caboos + case SE_15_SLIDING_DOOR://Subwaytype sliding door + case SE_16_REACTOR://That rotating blocker reactor thing + case SE_26://ESCELATOR + case SE_30_TWO_WAY_TRAIN://No rotational subways if (sp->lotag == 0) { if (sector[sect].lotag == 30) { - if (sp->pal) sprite[i].clipdist = 1; - else sprite[i].clipdist = 0; + if (sp->pal) sp->clipdist = 1; + else sp->clipdist = 0; t[3] = sector[sect].floorz; - sector[sect].hitag = i; + sector[sect].hitag = ActorToScriptIndex(actor); } - for (j = 0; j < MAXSPRITES; j++) + DukeSpriteIterator it; + bool found = false; + while (auto act2 = it.Next()) { - if (sprite[j].statnum < MAXSTATUS) - if (sprite[j].picnum == SECTOREFFECTOR && - sprite[j].lotag == 1 && - sprite[j].hitag == sp->hitag) + auto spr = &act2->s; + if (spr->statnum < MAXSTATUS) + if (spr->picnum == SECTOREFFECTOR && + spr->lotag == SE_1_PIVOT && + spr->hitag == sp->hitag) { if (sp->ang == 512) { - sp->x = sprite[j].x; - sp->y = sprite[j].y; + sp->x = spr->x; + sp->y = spr->y; } + found = true; + actor->SetOwner(act2); break; } } - if (j == MAXSPRITES) + if (!found) { I_Error("Found lonely Sector Effector (lotag 0) at (%d,%d)\n", sp->x, sp->y); } - sp->owner = j; } startwall = sector[sect].wallptr; @@ -1003,9 +1014,9 @@ void spawneffector(int i) sp->extra = 0; else sp->extra = 1; - sector[sect].hitag = i; + sector[sect].hitag = ActorToScriptIndex(actor); - j = 0; + int j = 0; for (s = startwall; s < endwall; s++) { @@ -1024,7 +1035,7 @@ void spawneffector(int i) I_Error("Subway found no zero'd sectors with locators\nat (%d,%d).\n", sp->x, sp->y); } - sp->owner = -1; + actor->SetOwner(nullptr); t[0] = s; if (sp->lotag != 30) @@ -1054,34 +1065,36 @@ void spawneffector(int i) switch (sp->lotag) { - case 6: - case 14: - j = callsound(sect, i); + case SE_6_SUBWAY: + case SE_14_SUBWAY_CAR: + { + int j = callsound(sect, actor); if (j == -1) { if (!isRR()) j = SUBWAY; // Duke else if (sector[sp->sectnum].floorpal == 7) j = 456; else j = 75; } - hittype[i].lastvx = j; - case 30: + actor->lastvx = j; + } + case SE_30_TWO_WAY_TRAIN: if (numplayers > 1) break; - case 0: - case 1: - case 5: - case 11: - case 15: - case 16: - case 26: - setsectinterpolate(i); + case SE_0_ROTATING_SECTOR: + case SE_1_PIVOT: + case SE_5_BOSS: + case SE_11_SWINGING_DOOR: + case SE_15_SLIDING_DOOR: + case SE_16_REACTOR: + case SE_26: + setsectinterpolate(actor->s.sectnum); break; } - if ((!isRR() && sprite[i].lotag >= 40 && sprite[i].lotag <= 45) || - (isRRRA() && sprite[i].lotag >= 150 && sprite[i].lotag <= 155)) - changespritestat(i, STAT_RAROR); + if ((!isRR() && actor->s.lotag >= 40 && actor->s.lotag <= 45) || + (isRRRA() && actor->s.lotag >= 150 && actor->s.lotag <= 155)) + changespritestat(actor, STAT_RAROR); else - changespritestat(i, STAT_EFFECTOR); + changespritestat(actor, STAT_EFFECTOR); } @@ -1091,11 +1104,11 @@ void spawneffector(int i) // //--------------------------------------------------------------------------- -void lotsofglass(int i, int wallnum, int n) +void lotsofglass(DDukeActor *actor, int wallnum, int n) { int j, xv, yv, z, x1, y1, a; short sect; - auto sp = &sprite[i]; + auto sp = &actor->s; sect = -1; @@ -1104,7 +1117,7 @@ void lotsofglass(int i, int wallnum, int n) for (j = n - 1; j >= 0; j--) { a = sp->ang - 256 + (krand() & 511) + 1024; - EGS(sp->sectnum, sp->x, sp->y, sp->z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), 1024 - (krand() & 1023), i, 5); + EGS(sp->sectnum, sp->x, sp->y, sp->z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), 1024 - (krand() & 1023), &hittype[j], 5); } return; } @@ -1135,7 +1148,7 @@ void lotsofglass(int i, int wallnum, int n) if (z < -(32 << 8) || z >(32 << 8)) z = sp->z - (32 << 8) + (krand() & ((64 << 8) - 1)); a = sp->ang - 1024; - EGS(sp->sectnum, x1, y1, z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), -(krand() & 1023), i, 5); + EGS(sp->sectnum, x1, y1, z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), -(krand() & 1023), actor, 5); } } } @@ -1146,17 +1159,16 @@ void lotsofglass(int i, int wallnum, int n) // //--------------------------------------------------------------------------- -void spriteglass(int i, int n) +void spriteglass(DDukeActor* actor, int n) { - int j, k, a, z; - auto sp = &sprite[i]; + auto sp = &actor->s; - for (j = n; j > 0; j--) + for (int j = n; j > 0; j--) { - a = krand() & 2047; - z = sp->z - ((krand() & 16) << 8); - k = EGS(sp->sectnum, sp->x, sp->y, z, TILE_GLASSPIECES + (j % 3), krand() & 15, 36, 36, a, 32 + (krand() & 63), -512 - (krand() & 2047), i, 5); - sprite[k].pal = sprite[i].pal; + int a = krand() & 2047; + int z = sp->z - ((krand() & 16) << 8); + auto k = EGS(sp->sectnum, sp->x, sp->y, z, TILE_GLASSPIECES + (j % 3), krand() & 15, 36, 36, a, 32 + (krand() & 63), -512 - (krand() & 2047), actor, 5); + k->s.pal = sp->pal; } } @@ -1166,11 +1178,11 @@ void spriteglass(int i, int n) // //--------------------------------------------------------------------------- -void ceilingglass(int i, int sectnum, int n) +void ceilingglass(DDukeActor* actor, int sectnum, int n) { int j, xv, yv, z, x1, y1; int a, s, startwall, endwall; - auto sp = &sprite[i]; + auto sp = &actor->s; startwall = sector[sectnum].wallptr; endwall = startwall + sector[sectnum].wallnum; @@ -1189,7 +1201,7 @@ void ceilingglass(int i, int sectnum, int n) y1 += yv; a = krand() & 2047; z = sector[sectnum].ceilingz + ((krand() & 15) << 8); - EGS(sectnum, x1, y1, z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, (krand() & 31), 0, i, 5); + EGS(sectnum, x1, y1, z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, (krand() & 31), 0, actor, 5); } } } @@ -1200,20 +1212,20 @@ void ceilingglass(int i, int sectnum, int n) // //--------------------------------------------------------------------------- -void lotsofcolourglass(int i, int wallnum, int n) +void lotsofcolourglass(DDukeActor* actor, int wallnum, int n) { int j, xv, yv, z, x1, y1; short sect = -1; - int a, k; - auto sp = &sprite[i]; + int a;; + auto sp = &actor->s; if (wallnum < 0) { for (j = n - 1; j >= 0; j--) { a = krand() & 2047; - k = EGS(sp->sectnum, sp->x, sp->y, sp->z - (krand() & (63 << 8)), TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), 1024 - (krand() & 2047), i, 5); - sprite[k].pal = krand() & 15; + auto k = EGS(sp->sectnum, sp->x, sp->y, sp->z - (krand() & (63 << 8)), TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), 1024 - (krand() & 2047), actor, 5); + k->s.pal = krand() & 15; } return; } @@ -1235,8 +1247,8 @@ void lotsofcolourglass(int i, int wallnum, int n) if (z < -(32 << 8) || z >(32 << 8)) z = sp->z - (32 << 8) + (krand() & ((64 << 8) - 1)); a = sp->ang - 1024; - k = EGS(sp->sectnum, x1, y1, z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), -(krand() & 2047), i, 5); - sprite[k].pal = krand() & 7; + auto k = EGS(sp->sectnum, x1, y1, z, TILE_GLASSPIECES + (j % 3), -32, 36, 36, a, 32 + (krand() & 63), -(krand() & 2047), actor, 5); + k->s.pal = krand() & 7; } } diff --git a/source/games/duke/src/spawn_d.cpp b/source/games/duke/src/spawn_d.cpp index 052392f20..a6da2433d 100644 --- a/source/games/duke/src/spawn_d.cpp +++ b/source/games/duke/src/spawn_d.cpp @@ -45,12 +45,14 @@ int spawn_d(int j, int pn) { int x; - int i = initspriteforspawn(j, pn, { CRACK1, CRACK2, CRACK3, CRACK4, SPEAKER, LETTER, DUCK, TARGET, TRIPBOMB, VIEWSCREEN, VIEWSCREEN2 }); + auto actj = j < 0 ? nullptr : &hittype[j]; + int i = initspriteforspawn(actj, pn, { CRACK1, CRACK2, CRACK3, CRACK4, SPEAKER, LETTER, DUCK, TARGET, TRIPBOMB, VIEWSCREEN, VIEWSCREEN2 }); if (!(i & 0x1000000)) return i; i &= 0xffffff; - auto sp = &sprite[i]; - auto spj = &sprite[j]; - auto t = hittype[i].temp_data; + auto act = &hittype[i]; + auto sp = &act->s; + auto spj = j < 0 ? nullptr : &actj->s; + auto t = act->temp_data; int sect = sp->sectnum; @@ -61,7 +63,7 @@ int spawn_d(int j, int pn) case BOSS2STAYPUT: case BOSS3STAYPUT: case BOSS5STAYPUT: - hittype[i].actorstayput = sp->sectnum; + act->actorstayput = sp->sectnum; case FIREFLY: case BOSS5: if (sp->picnum != FIREFLY) @@ -94,26 +96,26 @@ int spawn_d(int j, int pn) if ((sp->lotag > ud.player_skill) || ud.monsters_off) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(act, STAT_MISC); break; } else { - makeitfall(i); + makeitfall(act); sp->cstat |= 257; ps[connecthead].max_actors_killed++; if (j >= 0) { - hittype[i].timetosleep = 0; - fi.check_fta_sounds(i); + act->timetosleep = 0; + check_fta_sounds_d(act); changespritestat(i, 1); } else changespritestat(i, 2); } return i; case FIREFLYFLYINGEFFECT: - sp->owner = j; + act->SetOwner(actj); changespritestat(i, STAT_MISC); sp->xrepeat = 16; sp->yrepeat = 16; @@ -121,8 +123,8 @@ int spawn_d(int j, int pn) case LAVAPOOLBUBBLE: if (spj->xrepeat < 30) return i; - sp->owner = j; - changespritestat(i, STAT_MISC); + act->SetOwner(actj); + changespritestat(i, STAT_MISC); sp->x += krand() % 512 - 256; sp->y += krand() % 512 - 256; sp->xrepeat = 16; @@ -146,7 +148,7 @@ int spawn_d(int j, int pn) switch(sp->picnum) { default: - spawninitdefault(j, i); + spawninitdefault(actj, act); break; case FOF: sp->xrepeat = sp->yrepeat = 0; @@ -219,7 +221,7 @@ int spawn_d(int j, int pn) break; case TRANSPORTERSTAR: case TRANSPORTERBEAM: - spawntransporter(j, i, sp->picnum == TRANSPORTERBEAM); + spawntransporter(actj, act, sp->picnum == TRANSPORTERBEAM); break; case FRAMEEFFECT1: @@ -249,7 +251,7 @@ int spawn_d(int j, int pn) sp->yrepeat = 0; } - if(j >= 0) sp->ang = hittype[j].temp_data[5]+512; + if(j >= 0) sp->ang = actj->temp_data[5]+512; changespritestat(i, STAT_MISC); break; @@ -279,7 +281,7 @@ int spawn_d(int j, int pn) case BLOODPOOL: case PUKE: - if (spawnbloodpoolpart1(j, i)) break; + if (spawnbloodpoolpart1(actj, act)) break; if(j >= 0 && sp->picnum != PUKE) { @@ -321,7 +323,7 @@ int spawn_d(int j, int pn) sp->z -= (16<<8); if(j >= 0 && spj->pal == 6) sp->pal = 6; - insertspriteq(&hittype[i]); + insertspriteq(act); changespritestat(i, STAT_MISC); break; @@ -336,14 +338,15 @@ int spawn_d(int j, int pn) sp->xrepeat=4; sp->yrepeat=5; - sp->owner = i; - sp->hitag = i; + act->SetOwner(act); + ud.bomb_tag = (ud.bomb_tag + 1) & 32767; + sp->hitag = ud.bomb_tag; sp->xvel = 16; - ssp(i,CLIPMASK0); - hittype[i].temp_data[0] = 17; - hittype[i].temp_data[2] = 0; - hittype[i].temp_data[5] = sp->ang; + ssp(act, CLIPMASK0); + act->temp_data[0] = 17; + act->temp_data[2] = 0; + act->temp_data[5] = sp->ang; case SPACEMARINE: if(sp->picnum == SPACEMARINE) @@ -462,7 +465,7 @@ int spawn_d(int j, int pn) case FOOTPRINTS2: case FOOTPRINTS3: case FOOTPRINTS4: - initfootprint(j, i); + initfootprint(actj, act); break; case FEM1: @@ -522,7 +525,7 @@ int spawn_d(int j, int pn) if(sp->picnum == RESPAWNMARKERRED) { sp->xrepeat = sp->yrepeat = 24; - if(j >= 0) sp->z = hittype[j].floorz; // -(1<<4); + if(j >= 0) sp->z = actj->floorz; // -(1<<4); } else { @@ -543,13 +546,13 @@ int spawn_d(int j, int pn) case BULLETHOLE: sp->xrepeat = sp->yrepeat = 3; sp->cstat = 16+(krand()&12); - insertspriteq(&hittype[i]); + insertspriteq(act); case MONEY: case MAIL: case PAPER: if( sp->picnum == MONEY || sp->picnum == MAIL || sp->picnum == PAPER ) { - hittype[i].temp_data[0] = krand()&2047; + act->temp_data[0] = krand()&2047; sp->cstat = krand()&12; sp->xrepeat = sp->yrepeat = 8; sp->ang = krand()&2047; @@ -559,7 +562,7 @@ int spawn_d(int j, int pn) case VIEWSCREEN: case VIEWSCREEN2: - sp->owner = i; + act->SetOwner(act); sp->lotag = 1; sp->extra = 1; changespritestat(i,6); @@ -567,7 +570,7 @@ int spawn_d(int j, int pn) case SHELL: //From the player case SHOTGUNSHELL: - initshell(j, i, sp->picnum == SHELL); + initshell(actj, act, sp->picnum == SHELL); break; case RESPAWN: @@ -683,11 +686,11 @@ int spawn_d(int j, int pn) break; case CRANE: - initcrane(j, i, CRANEPOLE); + initcrane(actj, act, CRANEPOLE); break; case WATERDRIP: - initwaterdrip(j, i); + initwaterdrip(actj, act); break; case TRASH: @@ -770,7 +773,7 @@ int spawn_d(int j, int pn) case PIGCOPDIVE: case COMMANDERSTAYPUT: case BOSS4STAYPUT: - hittype[i].actorstayput = sp->sectnum; + act->actorstayput = sp->sectnum; case BOSS1: case BOSS2: case BOSS3: @@ -858,7 +861,7 @@ int spawn_d(int j, int pn) } else { - makeitfall(i); + makeitfall(act); if(sp->picnum == RAT) { @@ -878,8 +881,8 @@ int spawn_d(int j, int pn) if(j >= 0) { - hittype[i].timetosleep = 0; - fi.check_fta_sounds(i); + act->timetosleep = 0; + check_fta_sounds_d(act); changespritestat(i,1); } else changespritestat(i,2); @@ -917,14 +920,14 @@ int spawn_d(int j, int pn) { if( spj->picnum == NUKEBARREL ) sp->pal = 8; - insertspriteq(&hittype[i]); + insertspriteq(act); } changespritestat(i,1); - getglobalz(i); + getglobalz(act); - j = (hittype[i].floorz-hittype[i].ceilingz)>>9; + j = (act->floorz-act->ceilingz)>>9; sp->yrepeat = j; sp->xrepeat = 25-(j>>1); @@ -933,15 +936,15 @@ int spawn_d(int j, int pn) break; case HEAVYHBOMB: - if(j >= 0) - sp->owner = j; - else sp->owner = i; + if(j >= 0) act->SetOwner(actj); + else act->SetOwner(act); + sp->xrepeat = sp->yrepeat = 9; sp->yvel = 4; case REACTOR2: case REACTOR: case RECON: - if (initreactor(j, i, sp->picnum == RECON)) return i; + if (initreactor(actj, act, sp->picnum == RECON)) return i; break; case FLAMETHROWERSPRITE: @@ -985,12 +988,12 @@ int spawn_d(int j, int pn) sp->lotag = 0; sp->z -= (32<<8); sp->zvel = -1024; - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); sp->cstat = krand()&4; } else { - sp->owner = i; + act->SetOwner(act); sp->cstat = 0; } @@ -1023,11 +1026,11 @@ int spawn_d(int j, int pn) sp->shade = -17; - if(j >= 0) changespritestat(i,1); + if(j >= 0) changespritestat(act, STAT_ACTOR); else { - changespritestat(i,2); - makeitfall(i); + changespritestat(act, STAT_ZOMBIEACTOR); + makeitfall(act); } break; @@ -1041,21 +1044,21 @@ int spawn_d(int j, int pn) case BOX: sp->cstat = 257; // Make it hitable sp->extra = 1; - changespritestat(i,6); + changespritestat(act, STAT_STANDABLE); break; case FLOORFLAME: sp->shade = -127; - changespritestat(i,6); + changespritestat(act, STAT_STANDABLE); break; case BOUNCEMINE: - sp->owner = i; + act->SetOwner(act); sp->cstat |= 1+256; //Make it hitable sp->xrepeat = sp->yrepeat = 24; sp->shade = -127; sp->extra = impact_damage<<2; - changespritestat(i,2); + changespritestat(act, STAT_ZOMBIEACTOR); break; case CAMERA1: @@ -1089,14 +1092,14 @@ int spawn_d(int j, int pn) sp->cstat = 16+128+2; sp->xrepeat=sp->yrepeat=1; sp->xvel = -8; - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); } case CEILINGSTEAM: - changespritestat(i,6); + changespritestat(i,STAT_STANDABLE); break; case SECTOREFFECTOR: - spawneffector(i); + spawneffector(act); break; @@ -1112,9 +1115,8 @@ int spawn_d(int j, int pn) } else sp->cstat = 1+256; sp->extra = impact_damage<<2; - sp->owner = i; - - changespritestat(i,6); + act->SetOwner(act); + changespritestat(act, STAT_STANDABLE); break; case CRACK1: @@ -1141,10 +1143,10 @@ int spawn_d(int j, int pn) } sp->pal = 0; - sp->owner = i; - changespritestat(i,6); + act->SetOwner(act); + changespritestat(act, STAT_STANDABLE); sp->xvel = 8; - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); break; case TOILET: @@ -1152,7 +1154,7 @@ int spawn_d(int j, int pn) sp->lotag = 1; sp->cstat |= 257; sp->clipdist = 8; - sp->owner = i; + act->SetOwner(act); break; case CANWITHSOMETHING: case CANWITHSOMETHING2: @@ -1172,15 +1174,15 @@ int spawn_d(int j, int pn) if(j >= 0) sp->xrepeat = sp->yrepeat = 32; sp->clipdist = 72; - makeitfall(i); - if(j >= 0) - sp->owner = j; - else sp->owner = i; + makeitfall(act); + if(j >= 0) act->SetOwner(actj); + else act->SetOwner(act); + case EGG: if( ud.monsters_off == 1 && sp->picnum == EGG ) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(act, STAT_MISC); } else { @@ -1190,12 +1192,12 @@ int spawn_d(int j, int pn) ps[connecthead].max_actors_killed++; } sp->cstat = 257|(krand()&4); - changespritestat(i,2); + changespritestat(act, STAT_ZOMBIEACTOR); } break; case TOILETWATER: sp->shade = -16; - changespritestat(i,6); + changespritestat(act, STAT_STANDABLE); break; } return i; diff --git a/source/games/duke/src/spawn_r.cpp b/source/games/duke/src/spawn_r.cpp index b04b9894a..22217de0a 100644 --- a/source/games/duke/src/spawn_r.cpp +++ b/source/games/duke/src/spawn_r.cpp @@ -40,19 +40,21 @@ int spawn_r(int j, int pn) { int x; - int i = initspriteforspawn(j, pn, { CRACK1, CRACK2, CRACK3, CRACK4 }); + auto actj = j < 0 ? nullptr : &hittype[j]; + int i = initspriteforspawn(actj, pn, { CRACK1, CRACK2, CRACK3, CRACK4 }); if (!(i & 0x1000000)) return i; i &= 0xffffff; - auto sp = &sprite[i]; - auto spj = &sprite[j]; - auto t = hittype[i].temp_data; + auto act = &hittype[i]; + auto sp = &act->s; + auto spj = j < 0? nullptr : &actj->s; + auto t = act->temp_data; int sect = sp->sectnum; switch(sp->picnum) { default: default_case: - spawninitdefault(j, i); + spawninitdefault(actj, act); break; case RRTILE280: case RRTILE281: @@ -152,17 +154,17 @@ int spawn_r(int j, int pn) if (!isRRRA()) goto default_case; sp->lotag = 1; sp->clipdist = 0; - sp->owner = i; + act->SetOwner(act); sp->extra = 0; - changespritestat(i,115); + changespritestat(act,115); break; case RRTILE8593: if (!isRRRA()) goto default_case; sp->lotag = 1; sp->clipdist = 0; - sp->owner = i; + act->SetOwner(act); sp->extra = 0; - changespritestat(i,122); + changespritestat(act,122); break; case RRTILE285: case RRTILE286: @@ -298,7 +300,7 @@ int spawn_r(int j, int pn) break; case TRANSPORTERSTAR: case TRANSPORTERBEAM: - spawntransporter(j, i, sp->picnum == TRANSPORTERBEAM); + spawntransporter(actj, act, sp->picnum == TRANSPORTERBEAM); break; case FRAMEEFFECT1: @@ -335,7 +337,7 @@ int spawn_r(int j, int pn) changespritestat(i, STAT_MISC); break; case BLOODPOOL: - if (spawnbloodpoolpart1(j, i)) break; + if (spawnbloodpoolpart1(actj, act)) break; if(j >= 0) { @@ -362,7 +364,7 @@ int spawn_r(int j, int pn) sp->z -= (16<<8); if(j >= 0 && spj->pal == 6) sp->pal = 6; - insertspriteq(&hittype[i]); + insertspriteq(act); changespritestat(i, STAT_MISC); break; @@ -436,7 +438,7 @@ int spawn_r(int j, int pn) case FOOTPRINTS2: case FOOTPRINTS3: case FOOTPRINTS4: - initfootprint(j, i); + initfootprint(actj, act); break; case FEM10: case NAKED1: @@ -556,7 +558,7 @@ int spawn_r(int j, int pn) if(sp->picnum == RESPAWNMARKERRED) { sp->xrepeat = sp->yrepeat = 8; - if(j >= 0) sp->z = hittype[j].floorz; + if(j >= 0) sp->z = actj->floorz; } else { @@ -576,11 +578,11 @@ int spawn_r(int j, int pn) case BULLETHOLE: sp->xrepeat = sp->yrepeat = 3; sp->cstat = 16+(krand()&12); - insertspriteq(&hittype[i]); + insertspriteq(act); case MONEY: if(sp->picnum == MONEY) { - hittype[i].temp_data[0] = krand()&2047; + act->temp_data[0] = krand()&2047; sp->cstat = krand()&12; sp->xrepeat = sp->yrepeat = 8; sp->ang = krand()&2047; @@ -590,7 +592,7 @@ int spawn_r(int j, int pn) case SHELL: //From the player case SHOTGUNSHELL: - initshell(j, i, sp->picnum == SHELL); + initshell(actj, act, sp->picnum == SHELL); break; case RESPAWN: sp->extra = 66-13; @@ -697,10 +699,10 @@ int spawn_r(int j, int pn) changespritestat(i, STAT_MISC); break; case CRANE: - initcrane(j, i, CRANEPOLE); + initcrane(actj, act, CRANEPOLE); break; case WATERDRIP: - initwaterdrip(j, i); + initwaterdrip(actj, act); break; case TRASH: @@ -783,7 +785,7 @@ int spawn_r(int j, int pn) case MINIONSTAYPUT: case COOTSTAYPUT: rrra_stayput: - hittype[i].actorstayput = sp->sectnum; + act->actorstayput = sp->sectnum; case BOULDER: case BOULDER1: case RAT: @@ -1029,7 +1031,7 @@ int spawn_r(int j, int pn) } else { - makeitfall(i); + makeitfall(act); if(sp->picnum == RAT) { @@ -1042,26 +1044,26 @@ int spawn_r(int j, int pn) sp->cstat |= 257; if(sp->picnum != 5501) - if (actorfella(i)) + if (actorfella(act)) ps[myconnectindex].max_actors_killed++; } if(j >= 0) { - hittype[i].timetosleep = 0; - fi.check_fta_sounds(i); - changespritestat(i,1); + act->timetosleep = 0; + check_fta_sounds_r(act); + changespritestat(act, STAT_ACTOR); + sp->shade = spj->shade; } - else changespritestat(i,2); + else changespritestat(act, STAT_ZOMBIEACTOR); - sp->shade = spj->shade; } break; case LOCATORS: // sp->xrepeat=sp->yrepeat=0; sp->cstat |= 32768; - changespritestat(i,7); + changespritestat(act, STAT_LOCATOR); break; case ACTIVATORLOCKED: @@ -1070,13 +1072,13 @@ int spawn_r(int j, int pn) sp->cstat |= 32768; if (sp->picnum == ACTIVATORLOCKED) sector[sect].lotag ^= 16384; - changespritestat(i,8); + changespritestat(act, STAT_ACTIVATOR); break; case DOORSHOCK: sp->cstat |= 1+256; sp->shade = -12; - changespritestat(i,6); + changespritestat(act, STAT_STANDABLE); break; case OOZ: @@ -1086,11 +1088,11 @@ int spawn_r(int j, int pn) if( spj->picnum == NUKEBARREL ) sp->pal = 8; - changespritestat(i,1); + changespritestat(act, STAT_STANDABLE); - getglobalz(i); + getglobalz(act); - j = (hittype[i].floorz-hittype[i].ceilingz)>>9; + j = (act->floorz-act->ceilingz)>>9; sp->yrepeat = j; sp->xrepeat = 25-(j>>1); @@ -1098,13 +1100,13 @@ int spawn_r(int j, int pn) break; case HEAVYHBOMB: - sp->owner = i; + act->SetOwner(act); sp->xrepeat = sp->yrepeat = 9; sp->yvel = 4; case REACTOR2: case REACTOR: case RECON: - if (initreactor(j, i, sp->picnum == RECON)) return i; + if (initreactor(actj, act, sp->picnum == RECON)) return i; break; case RPG2SPRITE: @@ -1158,19 +1160,19 @@ int spawn_r(int j, int pn) { sp->zvel = 0; } - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); sp->cstat = krand()&4; } else { - sp->owner = i; + act->SetOwner(act); sp->cstat = 0; } if( ( ud.multimode < 2 && sp->pal != 0) || (sp->lotag > ud.player_skill) ) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(act, STAT_MISC); break; } @@ -1196,11 +1198,11 @@ int spawn_r(int j, int pn) sp->shade = -17; - if(j >= 0) changespritestat(i,1); + if(j >= 0) changespritestat(act, STAT_ACTOR); else { - changespritestat(i,2); - makeitfall(i); + changespritestat(act, STAT_ZOMBIEACTOR); + makeitfall(act); } switch (sp->picnum) { @@ -1353,14 +1355,13 @@ int spawn_r(int j, int pn) sp->cstat = 16+128+2; sp->xrepeat=sp->yrepeat=1; sp->xvel = -8; - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); } case CEILINGSTEAM: - changespritestat(i,6); + changespritestat(act, STAT_STANDABLE); break; case SECTOREFFECTOR: - spawneffector(i); - + spawneffector(act); break; case SEENINE: @@ -1374,9 +1375,8 @@ int spawn_r(int j, int pn) } else sp->cstat = 1+256; sp->extra = impact_damage<<2; - sp->owner = i; - - changespritestat(i,6); + act->SetOwner(act); + changespritestat(act, STAT_STANDABLE); break; case CRACK1: @@ -1393,10 +1393,10 @@ int spawn_r(int j, int pn) } sp->pal = 0; - sp->owner = i; - changespritestat(i,6); + act->SetOwner(act); + changespritestat(act, STAT_STANDABLE); sp->xvel = 8; - ssp(i,CLIPMASK0); + ssp(act, CLIPMASK0); break; case EMPTYBIKE: @@ -1410,10 +1410,10 @@ int spawn_r(int j, int pn) sp->xrepeat = 18; sp->yrepeat = 18; sp->clipdist = mulscale7(sp->xrepeat,tilesiz[sp->picnum].x); - sp->owner = 100; + act->saved_ammo = 100; sp->cstat = 257; sp->lotag = 1; - changespritestat(i,1); + changespritestat(act, STAT_ACTOR); break; case EMPTYBOAT: if (!isRRRA()) goto default_case; @@ -1426,7 +1426,7 @@ int spawn_r(int j, int pn) sp->xrepeat = 32; sp->yrepeat = 32; sp->clipdist = mulscale7(sp->xrepeat,tilesiz[sp->picnum].x); - sp->owner = 20; + act->saved_ammo = 20; sp->cstat = 257; sp->lotag = 1; changespritestat(i,1); @@ -1439,7 +1439,7 @@ int spawn_r(int j, int pn) sp->lotag = 1; sp->cstat |= 257; sp->clipdist = 8; - sp->owner = i; + act->SetOwner(act); break; case CANWITHSOMETHING: case RUBBERCAN: @@ -1456,27 +1456,27 @@ int spawn_r(int j, int pn) if(j >= 0) sp->xrepeat = sp->yrepeat = 32; sp->clipdist = 72; - makeitfall(i); - if(j >= 0) - sp->owner = j; - else sp->owner = i; + makeitfall(act); + if(j >= 0) act->SetOwner(actj); + else act->SetOwner(act); + case EGG: if( ud.monsters_off == 1 && sp->picnum == EGG ) { sp->xrepeat = sp->yrepeat = 0; - changespritestat(i, STAT_MISC); + changespritestat(act, STAT_MISC); } else { if(sp->picnum == EGG) sp->clipdist = 24; sp->cstat = 257|(krand()&4); - changespritestat(i,2); + changespritestat(act, STAT_ZOMBIEACTOR); } break; case TOILETWATER: sp->shade = -16; - changespritestat(i,6); + changespritestat(act, STAT_STANDABLE); break; case RRTILE63: sp->cstat |= 32768; diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index d62fcae1f..2ab9b0038 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -13,7 +13,7 @@ BEGIN_DUKE_NS struct STATUSBARTYPE { short frag[MAXPLAYERS], got_access, last_extra, shield_amount, curr_weapon; - short ammo_amount[MAX_WEAPONS], holoduke_on; + short ammo_amount[MAX_WEAPONS]; unsigned char inven_icon, jetpack_on, heat_on; short firstaid_amount, steroids_amount, holoduke_amount, jetpack_amount; short heat_amount, scuba_amount, boot_amount; @@ -29,7 +29,13 @@ struct weaponhit short tempang, actorstayput, dispicnum; short timetosleep; int floorz, ceilingz, lastvx, lastvy, bposx, bposy, bposz, aflags; + union + { + int saved_ammo; + int palvals; + }; int temp_data[6]; + weaponhit* temp_actor, *seek_actor; spritetype& s; // direct reference to the corresponding sprite. static weaponhit* array(); // this is necessary to allow define inline functions referencing the global array inside the definition itself. @@ -41,7 +47,7 @@ struct weaponhit { cgg = spriteextra = 0; picnum = ang = extra = owner = movflag = tempang = actorstayput = dispicnum = timetosleep = 0; - floorz = ceilingz = lastvx = lastvy = bposx = bposy = bposz = aflags = 0; + floorz = ceilingz = lastvx = lastvy = bposx = bposy = bposz = aflags = saved_ammo = 0; memset(temp_data, 0, sizeof(temp_data)); } int GetIndex() const { return this - array(); } @@ -54,7 +60,7 @@ struct weaponhit inline void SetOwner(weaponhit* a) { - s.owner = a->GetIndex(); + s.owner = a? a->GetIndex() : -1; } // same for the 'hittype' owner - which is normally the shooter in an attack. @@ -65,10 +71,10 @@ struct weaponhit inline void SetHitOwner(weaponhit* a) { - owner = a->GetIndex(); + owner = a ? a->GetIndex() : -1; } - // The crane is a good example of an actor hijacking the 'owner' field for something other than an actual owner. Abstract this away. + // This used the Owner field - better move this to something more safe. inline bool IsActiveCrane() { return s.owner == -2; @@ -104,6 +110,8 @@ struct ActorInfo uint32_t scriptaddress; uint32_t flags; int aimoffset; + int falladjustz; + int gutsoffset; }; // for now just flags not related to actors, may get more info later. @@ -123,8 +131,8 @@ struct user_defs unsigned char user_pals[MAXPLAYERS]; short from_bonus; - short camerasprite, last_camsprite; short last_level, secretlevel; + short bomb_tag; int const_visibility; @@ -140,6 +148,8 @@ struct user_defs int player_skill, marker; //MapRecord* nextLevel; + DDukeActor* cameraactor; + }; struct player_orig @@ -167,7 +177,6 @@ struct player_struct FixedBitArray gotweapon; // Palette management uses indices into the engine's palette table now. - unsigned int palette; PalEntry pals; // this was a global variable originally. @@ -199,16 +208,16 @@ struct player_struct short ammo_amount[MAX_WEAPONS], frag, fraggedself; short curr_weapon, last_weapon, tipincs, wantweaponfire; - short holoduke_amount, newowner, hurt_delay, hbomb_hold_delay; + short holoduke_amount, hurt_delay, hbomb_hold_delay; short jumping_counter, airleft, knee_incs, access_incs; - short ftq, access_wallnum, access_spritenum; + short ftq, access_wallnum; short got_access, weapon_ang, firstaid_amount; short i, one_parallax_sectnum; short over_shoulder_on, fist_incs; short cheat_phase; - short dummyplayersprite, extra_extra8, quick_kick, last_quick_kick; + short extra_extra8, quick_kick, last_quick_kick; short heat_amount, timebeforeexit, customexitsound; - DDukeActor* actorsqu, *wackedbyactor, *on_crane, *holoduke_on, *somethingonplayer; + DDukeActor* actorsqu, *wackedbyactor, *on_crane, *holoduke_on, *somethingonplayer, *access_spritenum, *dummyplayersprite, *newOwner; short weaprecs[256], weapreccnt; unsigned int interface_toggle_flag; @@ -257,7 +266,7 @@ struct player_struct int drug_timer; int SeaSick; short MamaEnd; // raat609 - short MotoSpeed, moto_drink; + short moto_drink; float TiltStatus, oTiltStatus; short VBumpNow, VBumpTarget, TurbCount; short drug_stat[3]; // raat5f1..5 @@ -266,9 +275,8 @@ struct player_struct uint8_t hurt_delay2, nocheat; uint8_t OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround; uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud; - bool vehicle_turnl, vehicle_turnr, vehicle_backwards; - - int8_t crouch_toggle; + double vehForwardScale, vehReverseScale, MotoSpeed; + bool vehTurnLeft, vehTurnRight; // input stuff. InputPacket sync; diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 2a2454347..26c007f4f 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -98,12 +98,6 @@ static void processInputBits(PLAYERp const pp, ControlInfo* const hidInput) else RESET(Player[myconnectindex].Flags, PF_AUTO_AIM); } - - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) - { - // this shares a bit with another function so cannot be in the common code. - loc.actions |= SB_CROUCH_LOCK; - } } //--------------------------------------------------------------------------- diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 8131f6f95..90eb5b50d 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1521,7 +1521,7 @@ UpdatePlayerSpriteAngle(PLAYERp pp) void DoPlayerTurn(PLAYERp pp, float const avel, double const scaleAdjust) { - applylook(&pp->angle, avel, &pp->input.actions, scaleAdjust, pp->input.actions & (SB_CROUCH|SB_CROUCH_LOCK)); + applylook(&pp->angle, avel, &pp->input.actions, scaleAdjust); UpdatePlayerSpriteAngle(pp); } @@ -3788,53 +3788,14 @@ DoPlayerCrawl(PLAYERp pp) //#define PLAYER_STANDING_ROOM(pp) ((pp)->posz + PLAYER_CRAWL_HEIGHT - PLAYER_HEIGHT - PLAYER_RUN_CEILING_DIST) #define PLAYER_STANDING_ROOM Z(68) - if (TEST(pp->Flags, PF_LOCK_CRAWL)) + // Let off of crawl to get up + if (!(pp->input.actions & SB_CROUCH)) { - if (pp->input.actions & SB_CROUCH_LOCK) + if (labs(pp->loz - pp->hiz) >= PLAYER_STANDING_ROOM) { - if (pp->KeyPressBits & SB_CROUCH_LOCK) - { - //if (pp->hiz < PLAYER_STANDING_ROOM(pp)) - if (labs(pp->loz - pp->hiz) >= PLAYER_STANDING_ROOM) - { - pp->KeyPressBits&= ~SB_CROUCH_LOCK; - - RESET(pp->Flags, PF_CRAWLING); - DoPlayerBeginRun(pp); - return; - } - } - } - else - { - pp->KeyPressBits |= SB_CROUCH_LOCK; - } - - // Jump to get up - if (pp->input.actions & SB_JUMP) - { - if (labs(pp->loz - pp->hiz) >= PLAYER_STANDING_ROOM) - { - //pp->posz = pp->loz - PLAYER_HEIGHT; - - RESET(pp->Flags, PF_CRAWLING); - DoPlayerBeginRun(pp); - return; - } - } - - } - else - { - // Let off of crawl to get up - if (!(pp->input.actions & SB_CROUCH)) - { - if (labs(pp->loz - pp->hiz) >= PLAYER_STANDING_ROOM) - { - RESET(pp->Flags, PF_CRAWLING); - DoPlayerBeginRun(pp); - return; - } + RESET(pp->Flags, PF_CRAWLING); + DoPlayerBeginRun(pp); + return; } } @@ -6785,22 +6746,6 @@ DoPlayerRun(PLAYERp pp) pp->KeyPressBits |= SB_JUMP; } - // Crawl lock - if (pp->input.actions & SB_CROUCH_LOCK) - { - if (pp->KeyPressBits & SB_CROUCH_LOCK) - { - pp->KeyPressBits &= ~SB_CROUCH_LOCK; - SET(pp->Flags, PF_LOCK_CRAWL); - DoPlayerBeginCrawl(pp); - return; - } - } - else - { - pp->KeyPressBits |= SB_CROUCH_LOCK; - } - if (PlayerFlyKey()) { DoPlayerBeginFly(pp); diff --git a/source/sw/src/sbar.cpp b/source/sw/src/sbar.cpp index 763a1a242..ed855aee0 100644 --- a/source/sw/src/sbar.cpp +++ b/source/sw/src/sbar.cpp @@ -1082,8 +1082,6 @@ void DrawConString(int x, int y, const char* string, double alpha) void UpdateStatusBar() { - DSWStatusBar sbar; - if (hud_size <= Hud_Stbar) { UpdateFrame(); diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 05da7cb64..c14338a71 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -1,3 +1,9 @@ +DEFAULTLISTMENU +{ + Font "BigFont", "Untranslated" + LineSpacing 20 +} + //------------------------------------------------------------------------------------------- // // Main Memu @@ -608,11 +614,7 @@ OptionMenu "ActionControlsMenu" protected StaticText "" Control "$CNTRLMNU_JUMP" , "+jump" Control "$CNTRLMNU_CROUCH" , "+crouch" - ifgame(Duke, Nam, WW2GI, Redneck, RedneckRides, ShadowWarrior) - { - // Fixme: Make this work in all games - Control "$CNTRLMNU_TOGGLECROUCH" , "+toggle_crouch" - } + Control "$CNTRLMNU_TOGGLECROUCH" , "+toggle_crouch" ifgame(Witchaven, Witchaven2) { Control "$CNTRLMNU_FLYUP" , "+alt_fire" diff --git a/wadsrc/static/zscript/games/sw/ui/menu.zs b/wadsrc/static/zscript/games/sw/ui/menu.zs index 0793c04c8..7d3684fd7 100644 --- a/wadsrc/static/zscript/games/sw/ui/menu.zs +++ b/wadsrc/static/zscript/games/sw/ui/menu.zs @@ -88,6 +88,11 @@ class ListMenuItemSWTextItem : ListMenuItemTextItem if (child == 'none') mEnabled = -1; } + override bool Selectable() + { + return super.Selectable() && mFont == BigFont; + } + void InitDirect(double x, double y, int height, String hotkey, String text, Font font, int color, int color2, Name child, int param = 0) { Super.InitDirect(x, y, height, hotkey, text, font, color, color2, child, param); @@ -95,10 +100,9 @@ class ListMenuItemSWTextItem : ListMenuItemTextItem override void Draw(bool selected, ListMenuDescriptor desc) { - let gamefont = generic_ui ? NewSmallFont : BigFont; - int cr = generic_ui? Font.CR_RED : Font.CR_UNDEFINED; - double scalex = 1.; - + let gamefont = generic_ui ? NewSmallFont : mFont; + int cr = mColor != Font.CR_UNDEFINED? mColor : generic_ui? Font.CR_RED : Font.CR_UNDEFINED; + double scalex = generic_ui && mFont == SmallFont? 0.5 : 1.; // The font here is very bulky and may cause problems with localized content. Account for that by squashing the text if needed. int length = gamefont.StringWidth(mText); @@ -107,7 +111,7 @@ class ListMenuItemSWTextItem : ListMenuItemTextItem scalex = (315. - mXpos) / length; } - Screen.DrawText(BigFont, cr, mXpos, mYpos, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, !Selectable()? 0xff505050 : 0xffffffff, DTA_ScaleX, scalex); + Screen.DrawText(gamefont, cr, mXpos, mYpos, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, !super.Selectable()? 0xff505050 : 0xffffffff, DTA_ScaleX, scalex); } }