From 35ba63cb3e39a829200d8bc7f35782e67f304e07 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 14 Nov 2021 21:25:44 +0100 Subject: [PATCH] - another batch of smaller stuff. --- source/games/whaven/src/items.cpp | 4 ++-- source/games/whaven/src/potions.cpp | 11 ++++++----- source/games/whaven/src/precache.cpp | 15 ++++++++------- source/games/whaven/src/sound.cpp | 2 +- source/games/whaven/src/spellbooks.cpp | 6 +++--- source/games/whaven/src/weapons.cpp | 23 ++++++++++++----------- source/games/whaven/src/wh.h | 7 +++---- source/games/whaven/src/whani.cpp | 2 +- source/games/whaven/src/whmap.cpp | 2 +- source/games/whaven/src/whobj.cpp | 2 +- 10 files changed, 38 insertions(+), 36 deletions(-) diff --git a/source/games/whaven/src/items.cpp b/source/games/whaven/src/items.cpp index bba4f94e4..ba876790b 100644 --- a/source/games/whaven/src/items.cpp +++ b/source/games/whaven/src/items.cpp @@ -6,8 +6,8 @@ BEGIN_WH_NS Item items[MAXITEMS - ITEMSBASE]; -boolean isItemSprite(int i) { - return (sprite[i].detail & 0xFF) >= ITEMSBASE && (sprite[i].detail & 0xFF) < MAXITEMS; +boolean isItemSprite(DWHActor* actor) { + return (actor->s().detail & 0xFF) >= ITEMSBASE && (actor->s().detail & 0xFF) < MAXITEMS; } void InitItems() diff --git a/source/games/whaven/src/potions.cpp b/source/games/whaven/src/potions.cpp index 94b81c575..eccf6a165 100644 --- a/source/games/whaven/src/potions.cpp +++ b/source/games/whaven/src/potions.cpp @@ -136,16 +136,17 @@ void updatepotion(PLAYER& plr, int vial) { } } -void randompotion(int i) { +void randompotion(DWHActor* actor) { if ((krand() % 100) > 20) return; - auto spawnedactor = InsertActor(sprite[i].sectnum, (short)0); + auto& spr = actor->s(); + auto spawnedactor = InsertActor(spr.sectnum, (short)0); auto& spawned = spawnedactor->s(); - spawned.x = sprite[i].x; - spawned.y = sprite[i].y; - spawned.z = sprite[i].z - (12 << 8); + spawned.x = spr.x; + spawned.y = spr.y; + spawned.z = spr.z - (12 << 8); spawned.shade = -12; spawned.pal = 0; spawned.cstat = 0; diff --git a/source/games/whaven/src/precache.cpp b/source/games/whaven/src/precache.cpp index 17794fe83..a992ee6f7 100644 --- a/source/games/whaven/src/precache.cpp +++ b/source/games/whaven/src/precache.cpp @@ -9,18 +9,19 @@ void addTile(int num) markTileForPrecache(num, 0); } -void cachespritenum(int i) +void cachespritenum(DWHActor* actor) { + auto& spr = actor->s(); int maxc = 1; - if (sprite[i].picnum == RAT || sprite[i].picnum == GUARDIAN) + if (spr.picnum == RAT || spr.picnum == GUARDIAN) maxc = 15; - if (sprite[i].picnum == HANGMAN) + if (spr.picnum == HANGMAN) maxc = 40; - if (sprite[i].picnum == GRONHAL || sprite[i].picnum == GRONMU || sprite[i].picnum == GRONSW) + if (spr.picnum == GRONHAL || spr.picnum == GRONMU || spr.picnum == GRONSW) maxc = 19; - switch (sprite[i].picnum) + switch (spr.picnum) { case GOBLINSTAND: case GOBLIN: @@ -54,7 +55,7 @@ void cachespritenum(int i) maxc = 18; break; } - for (int j = sprite[i].picnum; j < (sprite[i].picnum + maxc); j++) + for (int j = spr.picnum; j < (spr.picnum + maxc); j++) addTile(j); } @@ -73,7 +74,7 @@ void precacheTiles() WHSpriteIterator it; while (auto itActor = it.Next()) { - cachespritenum(itActor->GetSpriteIndex()); + cachespritenum(itActor); } addTile(BAT); diff --git a/source/games/whaven/src/sound.cpp b/source/games/whaven/src/sound.cpp index a083d7835..09d335462 100644 --- a/source/games/whaven/src/sound.cpp +++ b/source/games/whaven/src/sound.cpp @@ -154,7 +154,7 @@ void GameInterface::UpdateSounds() listener.underwater = false; listener.Environment = 0; - listener.ListenerObject = &sprite[player[pyrn].spritenum]; + listener.ListenerObject = &player[pyrn].actor()->s(); soundEngine->SetListener(listener); soundEngine->UpdateSounds(I_GetTime()); } diff --git a/source/games/whaven/src/spellbooks.cpp b/source/games/whaven/src/spellbooks.cpp index d53768b78..592baa657 100644 --- a/source/games/whaven/src/spellbooks.cpp +++ b/source/games/whaven/src/spellbooks.cpp @@ -369,13 +369,13 @@ void nukespell(PLAYER& plr, short const j) { } } -void medusa(PLAYER& plr, short j) { - auto& spr = sprite[j]; +void medusa(PLAYER& plr, DWHActor* actor) { + auto& spr = actor->s(); if(spr.hitag <= 0) //don't freeze dead enemies return; - newstatus(j, FROZEN); + SetNewStatus(actor, FROZEN); int pic = spr.picnum; switch (spr.detail) { diff --git a/source/games/whaven/src/weapons.cpp b/source/games/whaven/src/weapons.cpp index 5cd87f067..558209d24 100644 --- a/source/games/whaven/src/weapons.cpp +++ b/source/games/whaven/src/weapons.cpp @@ -16,11 +16,12 @@ int dahand = 0; int oweapondrop, weapondrop; double osnakex, osnakey, snakex, snakey; -boolean checkmedusadist(int i, int x, int y, int z, int lvl) { +boolean checkmedusadist(DWHActor* actor, int x, int y, int z, int lvl) { + auto& spr = actor->s(); int attackdist = (isWh2() ? 8192 : 1024) + (lvl << 9); - if ((abs(x - sprite[i].x) + abs(y - sprite[i].y) < attackdist) - && (abs((z >> 8) - ((sprite[i].z >> 8) - (tileHeight(sprite[i].picnum) >> 1))) <= 120)) + if ((abs(x - spr.x) + abs(y - spr.y) < attackdist) + && (abs((z >> 8) - ((spr.z >> 8) - (tileHeight(spr.picnum) >> 1))) <= 120)) return true; else return false; @@ -1012,7 +1013,7 @@ void shootgun(PLAYER& plr, float ang, int guntype) { if (checkweapondist(pHitInfo.hitsprite, plr.x, plr.y, plr.z, plr.selectedgun)) { madeahit = true; - auto& hitspr = sprite[pHitInfo.hitsprite]; + auto& hitspr = hitActor->s(); switch (hitspr.detail) { @@ -1277,7 +1278,7 @@ void shootgun(PLAYER& plr, float ang, int guntype) { hitspr.hitag = 1; } if (krand() % 100 > 50) - medusa(plr, pHitInfo.hitsprite); + medusa(plr, hitActor); break; } @@ -1484,7 +1485,7 @@ void shootgun(PLAYER& plr, float ang, int guntype) { hitspr.hitag = 1; } if (krand() % 100 > 75) - medusa(plr, pHitInfo.hitsprite); + medusa(plr, hitActor); break; } @@ -1778,8 +1779,8 @@ void shootgun(PLAYER& plr, float ang, int guntype) { (bsin(spawned.ang) * TICSPERFRAME) << 3, 0, 4 << 8, 4 << 8, 0); spawned.backuploc(); } - if ((pHitInfo.hitsprite >= 0) && (sprite[pHitInfo.hitsprite].statnum < MAXSTATUS)) { - auto& hitspr = sprite[pHitInfo.hitsprite]; + if ((hitActor != nullptr) && (hitActor->s().statnum < MAXSTATUS)) { + auto& hitspr = hitActor->s(); switch (hitspr.detail) { case KURTTYPE: case KATIETYPE: @@ -1901,8 +1902,8 @@ void shootgun(PLAYER& plr, float ang, int guntype) { if (cansee(plr.x, plr.y, plr.z, plr.sector, spk.x, spk.y, spk.z - (tileHeight(spk.picnum) << 7), spk.sectnum)) { // distance check - if (checkmedusadist(i, plr.x, plr.y, plr.z, plr.lvl)) - medusa(plr, i); + if (checkmedusadist(itActor, plr.x, plr.y, plr.z, plr.lvl)) + medusa(plr, itActor); } break; } @@ -2260,7 +2261,7 @@ void shootgun(PLAYER& plr, float ang, int guntype) { if (cansee(plr.x, plr.y, plr.z, plr.sector, spk.x, spk.y, spk.z - (tileHeight(spk.picnum) << 7), spk.sectnum)) if ((isWh2() && itActor->GetPlayerOwner() != plr.playerNum()) - || checkmedusadist(j, plr.x, plr.y, plr.z, 12)) + || checkmedusadist(itActor, plr.x, plr.y, plr.z, 12)) nukespell(plr, j); break; } diff --git a/source/games/whaven/src/wh.h b/source/games/whaven/src/wh.h index 16710cedb..e150ea12e 100644 --- a/source/games/whaven/src/wh.h +++ b/source/games/whaven/src/wh.h @@ -307,7 +307,6 @@ extern int dahand; extern int oweapondrop, weapondrop; extern double osnakex, osnakey, snakex, snakey; -boolean checkmedusadist(int i, int x, int y, int z, int lvl); void autoweaponchange(PLAYER& plr, int dagun); void weaponchange(int snum); void plrfireweapon(PLAYER& plr); @@ -319,7 +318,7 @@ void swingdaweapon(PLAYER& plr); void swingdacrunch(PLAYER& plr, int daweapon); void swingdasound(int daweapon, boolean enchanted); -boolean isItemSprite(int i); +boolean isItemSprite(DWHActor* i); void InitItems(); void wepdatainit(); @@ -333,7 +332,7 @@ boolean changebook(PLAYER& plr, int i); boolean lvlspellcheck(PLAYER& plr); void speelbookprocess(PLAYER& plr); void nukespell(PLAYER& plr, short j); -void medusa(PLAYER& plr, short j); +void medusa(PLAYER& plr, DWHActor* j); void displayspelltext(PLAYER& plr); void orbpic(PLAYER& plr, int currentorb); @@ -345,7 +344,7 @@ void usapotion(PLAYER& plr); boolean potionspace(PLAYER& plr, int vial); void updatepotion(PLAYER& plr, int vial); void potionpic(PLAYER& plr, int currentpotion, int x, int y, int scale); -void randompotion(int i); +void randompotion(DWHActor* i); // whfx diff --git a/source/games/whaven/src/whani.cpp b/source/games/whaven/src/whani.cpp index 8e844de93..2f2295aa5 100644 --- a/source/games/whaven/src/whani.cpp +++ b/source/games/whaven/src/whani.cpp @@ -1425,7 +1425,7 @@ void animateobjs(PLAYER& plr) { else { switch (spr.picnum) { case FSHATTERBARREL + 2: - randompotion(i); + randompotion(actor); ChangeActorStat(actor, 0); break; case STAINGLASS1 + 6: diff --git a/source/games/whaven/src/whmap.cpp b/source/games/whaven/src/whmap.cpp index 89ee2a104..07f42681b 100644 --- a/source/games/whaven/src/whmap.cpp +++ b/source/games/whaven/src/whmap.cpp @@ -728,7 +728,7 @@ boolean prepareboard(const char* fname) { } - if(isItemSprite(i)) { + if(isItemSprite(actor)) { Item& item = items[(spr.detail & 0xFF) - ITEMSBASE]; if(item.sizx != -1 && item.sizy != -1) { spr.xrepeat = (uint8_t)item.sizx; diff --git a/source/games/whaven/src/whobj.cpp b/source/games/whaven/src/whobj.cpp index 6a721e3ae..e80ed5b7b 100644 --- a/source/games/whaven/src/whobj.cpp +++ b/source/games/whaven/src/whobj.cpp @@ -124,7 +124,7 @@ void processobjs(PLAYER& plr) { dz = abs((plr.z >> 8) - (tspr.z >> 8)); // z distance to sprite dh = tileHeight(tspr.picnum) >> 1; // height of sprite if (dx + dy < PICKDISTANCE && dz - dh <= getPickHeight()) { - if(isItemSprite(actor->GetSpriteIndex())) + if(isItemSprite(actor)) items[(tspr.detail & 0xFF) - ITEMSBASE].pickup(plr, actor); if (tspr.picnum >= EXPLOSTART && tspr.picnum <= EXPLOEND && actor->GetPlayerOwner() != plr.playerNum())