diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 390820a4d..173d08dd2 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -4484,7 +4484,7 @@ void handle_se27(DDukeActor* actor) { if (t[0] < 0) { - ud.camerasprite = actor->GetIndex(); + ud.cameraactor = actor; t[0]++; } else if (ud.recstat == 2 && ps[p].newowner == -1) @@ -4493,7 +4493,7 @@ void handle_se27(DDukeActor* actor) { if (x < (unsigned)sh) { - ud.camerasprite = actor->GetIndex(); + ud.cameraactor = actor; t[0] = 999; s->ang += getincangle(s->ang, getangle(ps[p].posx - s->x, ps[p].posy - s->y)) >> 3; s->yvel = 100 + ((s->z - ps[p].posz) / 257); @@ -4501,10 +4501,10 @@ void handle_se27(DDukeActor* actor) } else if (t[0] == 999) { - if (ud.camerasprite == actor->GetIndex()) + if (ud.cameraactor == actor) t[0] = 0; else t[0] = -10; - ud.camerasprite = actor->GetIndex(); + ud.cameraactor = actor; } } @@ -4514,10 +4514,10 @@ void handle_se27(DDukeActor* actor) if (t[0] == 999) { - if (ud.camerasprite == actor->GetIndex()) + if (ud.cameraactor == actor) t[0] = 0; else t[0] = -20; - ud.camerasprite = actor->GetIndex(); + ud.cameraactor = actor; } } } diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index ae7cadd48..ca2f7769d 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -424,7 +424,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) t1 = ScriptCode[actorinfo[APLAYER].scriptaddress + 2]; } - if (ud.camerasprite == -1 && ps[p].newowner == -1) + if (ud.cameraactor == nullptr && ps[p].newowner == -1) if (s->owner >= 0 && display_mirror == 0 && ps[p].over_shoulder_on == 0) if (ud.multimode < 2 || (ud.multimode > 1 && p == screenpeek)) { @@ -707,7 +707,7 @@ void animatesprites_d(int x, int y, int a, int smoothratio) if (Owner && Owner->statnum < MAXSTATUS) { if (Owner->picnum == APLAYER) - if (ud.camerasprite == -1) + if (ud.cameraactor == nullptr) if (screenpeek == Owner->yvel && display_mirror == 0) { t->owner = -1; diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index 43a77664c..c484bc69e 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -475,7 +475,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) t1 = ScriptCode[actorinfo[APLAYER].scriptaddress + 2]; } - if (ud.camerasprite == -1 && ps[p].newowner == -1) + if (ud.cameraactor == nullptr && ps[p].newowner == -1) if (s->owner >= 0 && display_mirror == 0 && ps[p].over_shoulder_on == 0) if (ud.multimode < 2 || (ud.multimode > 1 && p == screenpeek)) { @@ -940,7 +940,7 @@ void animatesprites_r(int x, int y, int a, int smoothratio) if (Owner && Owner->statnum < MAXSTATUS) { if (Owner->picnum == APLAYER) - if (ud.camerasprite == -1) + if (ud.cameraactor == nullptr) if (screenpeek == Owner->yvel && display_mirror == 0) { t->owner = -1; diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 08a282fff..ea3b5efdd 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; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 1cec095cb..48344b543 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -249,7 +249,7 @@ void drawoverlays(double smoothratio) MarkSectorSeen(pp->cursectnum); - if (ud.camerasprite == -1) + if (ud.cameraactor == nullptr) { if (automapMode != am_full) { @@ -299,7 +299,7 @@ void drawoverlays(double smoothratio) StatusBar->UpdateStatusBar(); - if (ps[myconnectindex].newowner == -1 && ud.camerasprite == -1) + if (ps[myconnectindex].newowner == -1 && 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); } diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index b9c833fa5..320e7b814 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -136,8 +136,8 @@ static void DoUserDef(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* 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: 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/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index 090a25efc..0b8b887db 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -291,7 +291,7 @@ void displayweapon_d(int snum, double smoothratio) gs = p->GetActor()->s.shade; if(gs > 24) gs = 24; - bool playerVars = p->newowner >= 0 || ud.camerasprite >= 0 || p->over_shoulder_on > 0 || (p->GetActor()->s.pal != 1 && p->GetActor()->s.extra <= 0); + bool playerVars = p->newowner >= 0 || 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); diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 83f4a09b3..b617f0873 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -136,7 +136,7 @@ void displayweapon_r(int snum, double smoothratio) gs = p->GetActor()->s.shade; if(gs > 24) gs = 24; - if(p->newowner >= 0 || ud.camerasprite >= 0 || p->over_shoulder_on > 0 || (p->GetActor()->s.pal != 1 && p->GetActor()->s.extra <= 0)) + if(p->newowner >= 0 || 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; diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 961866535..38340035c 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -39,7 +39,7 @@ inline int bossguy(spritetype const* const pSprite) inline int actorflag(DDukeActor * actor, int mask) { - return (((actorinfo[actor->s.picnum].flags/* ^ hittype[spritenum].flags*/) & mask) != 0); + return (((actorinfo[actor->s.picnum].flags) & mask) != 0); } inline int actorfella(DDukeActor* actor) @@ -68,9 +68,9 @@ 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) diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 5c729aa70..2f8cbe692 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -416,7 +416,7 @@ void resetprestat(int snum,int g) parallaxtype = 0; randomseed = 17L; paused = 0; - ud.camerasprite =-1; + ud.cameraactor =nullptr; tempwallptr = 0; camsprite =-1; earthquaketime = 0; diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 5db3fdea7..196d6d052 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -536,10 +536,11 @@ void prelevel_r(int g) 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); } } @@ -728,11 +729,11 @@ void prelevel_r(int g) 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 == spr->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 8e76837b8..287e9b0e3 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -518,16 +518,16 @@ void displayrooms(int snum, double 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); diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 1581423ca..63b7d43ce 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -1710,7 +1710,7 @@ void checksectors_d(int snum) spr->yvel = 1; //Using this camera if (snum == screenpeek) S_PlaySound(MONITOR_ACTIVE); - neartagsprite->s.owner = i; + neartagsprite->SetOwner(acti); neartagsprite->s.yvel = 1; camsprite = neartagsprite->GetIndex(); diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index cbec5aa24..f8a53cc55 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -2394,7 +2394,7 @@ void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj) targ->extra += pspr->extra; if (s->picnum != COW) targ->ang = pspr->ang; - targ->owner = pspr->owner; + targ->SetHitOwner(proj->GetOwner()); } if (s->statnum == 10) diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index cac603483..09215696d 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -293,7 +293,7 @@ static int GetPositionInfo(DDukeActor* actor, 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 +302,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; } } @@ -396,7 +396,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); } diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index a29fadc79..298eea42e 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -50,9 +50,6 @@ BEGIN_DUKE_NS 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) @@ -188,7 +185,7 @@ int initspriteforspawn(DDukeActor* actj, int pn, const std::initializer_listpicnum, 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) { diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 7ae22fc8c..80de7a2fd 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -74,7 +74,7 @@ struct weaponhit owner = a->GetIndex(); } - // This used the owner field - better move this to something more safe. + // This used the Owner field - better move this to something more safe. inline bool IsActiveCrane() { return palvals == -2; @@ -131,7 +131,6 @@ struct user_defs unsigned char user_pals[MAXPLAYERS]; short from_bonus; - short camerasprite, last_camsprite; short last_level, secretlevel; int const_visibility; @@ -148,6 +147,8 @@ struct user_defs int player_skill, marker; //MapRecord* nextLevel; + DDukeActor* cameraactor; + }; struct player_orig