From 34e39dd2215f2edf5c23300e29580194fc0727b0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 24 Oct 2020 09:35:43 +0200 Subject: [PATCH] - pass spawner as an actor pointer to 'lotsofstuff'. Allows doing this without using sprite indices. --- source/games/duke/src/actors.cpp | 12 ++++++------ source/games/duke/src/actors_d.cpp | 12 ++++++------ source/games/duke/src/actors_r.cpp | 6 +++--- source/games/duke/src/dispatch.cpp | 8 ++++---- source/games/duke/src/duke3d.h | 6 +++--- source/games/duke/src/funct.h | 2 +- source/games/duke/src/gameexec.cpp | 10 +++++++--- source/games/duke/src/player_r.cpp | 2 +- source/games/duke/src/sectors.cpp | 1 + source/games/duke/src/sectors_d.cpp | 6 +++--- source/games/duke/src/sectors_r.cpp | 6 +++--- source/games/duke/src/spawn.cpp | 4 ++-- 12 files changed, 40 insertions(+), 35 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 2169f78f0..15fac999a 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -258,15 +258,15 @@ void insertspriteq(int i) // //--------------------------------------------------------------------------- -void lotsofstuff(spritetype* s, short n, int spawntype) +void lotsofstuff(DDukeActor* actor, int n, int spawntype) { - short i, j; - for (i = n; i > 0; i--) + auto s = &actor->s; + for (int i = n; i > 0; i--) { - short r1 = krand(), r2 = krand(); // using the RANDCORRECT version from RR. + int r1 = krand(), r2 = krand(); // using the RANDCORRECT version from RR. // TRANSITIONAL RedNukem sets the spawner as owner. - j = EGS(s->sectnum, s->x, s->y, s->z - (r2 % (47 << 8)), spawntype, -32, 8, 8, r1 & 2047, 0, 0, (short)0, 5); - sprite[j].cstat = krand() & 12; + auto j = EGS(s->sectnum, s->x, s->y, s->z - (r2 % (47 << 8)), spawntype, -32, 8, 8, r1 & 2047, 0, 0, actor, 5); + j->s.cstat = krand() & 12; } } diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 0d57798b2..03a91b408 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -630,19 +630,19 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un // //--------------------------------------------------------------------------- -void lotsofmoney_d(spritetype *s, short n) +void lotsofmoney_d(DDukeActor *actor, short n) { - lotsofstuff(s, n, MONEY); + lotsofstuff(actor, n, MONEY); } -void lotsofmail_d(spritetype *s, short n) +void lotsofmail_d(DDukeActor *actor, short n) { - lotsofstuff(s, n, MAIL); + lotsofstuff(actor, n, MAIL); } -void lotsofpaper_d(spritetype *s, short n) +void lotsofpaper_d(DDukeActor *actor, short n) { - lotsofstuff(s, n, PAPER); + lotsofstuff(actor, n, PAPER); } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 32304e89c..84d65ef74 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -453,9 +453,9 @@ int movesprite_ex_r(DDukeActor* actor, int xchange, int ychange, int zchange, un // //--------------------------------------------------------------------------- -void lotsoffeathers_r(spritetype *s, short n) +void lotsoffeathers_r(DDukeActor *actor, short n) { - lotsofstuff(s, n, MONEY); + lotsofstuff(actor, n, MONEY); } @@ -2468,7 +2468,7 @@ void rr_specialstats() s->lotag--; if (s->lotag < 0) { - lotsoffeathers_r(&sprite[i], (krand() & 3) + 4); + lotsoffeathers_r(&hittype[i], (krand() & 3) + 4); s->lotag = 84; } break; diff --git a/source/games/duke/src/dispatch.cpp b/source/games/duke/src/dispatch.cpp index ce6aca306..7bb7c404c 100644 --- a/source/games/duke/src/dispatch.cpp +++ b/source/games/duke/src/dispatch.cpp @@ -66,10 +66,10 @@ 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 lotsofmoney_d(spritetype* s, short n); -void lotsofmail_d(spritetype* s, short n); -void lotsofpaper_d(spritetype* s, short n); -void lotsoffeathers_r(spritetype* s, short n); +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); diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 240dbbc30..657a489c2 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -89,9 +89,9 @@ struct Dispatcher 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 (*lotsofmoney)(spritetype *s, short n); - void (*lotsofmail)(spritetype *s, short n); - void (*lotsofpaper)(spritetype *s, short n); + 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); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 9d0b56b5a..f1370db4d 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -44,7 +44,7 @@ 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 newextra, int playsound); void moveooz(int i, int seenine, int seeninedead, int ooz, int explosion); -void lotsofstuff(spritetype* s, short n, int spawntype); +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); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index fb605c1a6..0438c91d5 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -73,6 +73,7 @@ struct ParseState int* g_t; uint8_t killit_flag; spritetype* g_sp; + DDukeActor *g_ac; int* insptr; int parse(void); @@ -1888,12 +1889,12 @@ int ParseState::parse(void) break; case concmd_money: insptr++; - fi.lotsofmoney(g_sp,*insptr); + fi.lotsofmoney(g_ac,*insptr); insptr++; break; case concmd_mail: insptr++; - fi.lotsofmail(g_sp,*insptr); + fi.lotsofmail(g_ac,*insptr); insptr++; break; case concmd_sleeptime: @@ -1903,7 +1904,7 @@ int ParseState::parse(void) break; case concmd_paper: insptr++; - fi.lotsofpaper(g_sp,*insptr); + fi.lotsofpaper(g_ac,*insptr); insptr++; break; case concmd_addkills: @@ -3674,6 +3675,7 @@ void LoadActor(int i, int p, int x) 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]; auto addr = tileinfo[s.g_sp->picnum].loadeventscriptptr; if (addr == 0) return; @@ -3767,6 +3769,7 @@ void execute(int i,int p,int x) 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]; if (actorinfo[g_sp->picnum].scriptaddress == 0) return; s.insptr = &ScriptCode[4 + (actorinfo[g_sp->picnum].scriptaddress)]; @@ -3864,6 +3867,7 @@ void OnEvent(int iEventID, int p, int i, int x) 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.insptr = &ScriptCode[apScriptGameEvent[iEventID]]; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 11715a1bb..dbd4773b9 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -696,7 +696,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) { sprite[j].lotag = var90; sprite[j].hitag = 0; - fi.lotsofmoney(&sprite[j], (krand() & 3) + 1); + fi.lotsofmoney(&hittype[j], (krand() & 3) + 1); } } diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 00ced4835..f262f7b1c 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -36,6 +36,7 @@ source as it is released. #include "ns.h" #include "global.h" #include "sounds.h" +#include "dukeactor.h" using std::min; using std::max; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 9b678d882..7bbf5bcde 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -816,7 +816,7 @@ void checkhitwall_d(int spr, int dawallnum, int x, int y, int z, int atwith) case ATM: wal->picnum = ATMBROKE; - fi.lotsofmoney(&sprite[spr], 1 + (krand() & 7)); + fi.lotsofmoney(&hittype[spr], 1 + (krand() & 7)); S_PlayActorSound(GLASS_HEAVYBREAK, spr); break; @@ -1183,7 +1183,7 @@ void checkhitsprite_d(int i, int sn) case STATUEFLASH: case STATUE: if (s->picnum == BOTTLE10) - fi.lotsofmoney(&sprite[i], 4 + (krand() & 3)); + fi.lotsofmoney(&hittype[i], 4 + (krand() & 3)); else if (s->picnum == STATUE || s->picnum == STATUEFLASH) { lotsofcolourglass(i, -1, 40); @@ -1526,7 +1526,7 @@ void checksectors_d(int snum) if (chatmodeon || sprite[p->i].extra <= 0) return; if (ud.cashman && PlayerInput(snum, SB_OPEN)) - fi.lotsofmoney(&sprite[p->i], 2); + fi.lotsofmoney(&hittype[p->i], 2); if (p->newowner >= 0) { diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 35be670fe..553b8ff49 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -1245,7 +1245,7 @@ void checkhitwall_r(int spr, int dawallnum, int x, int y, int z, int atwith) case ATM: wal->picnum = ATMBROKE; - fi.lotsofmoney(&sprite[spr], 1 + (krand() & 7)); + fi.lotsofmoney(&hittype[spr], 1 + (krand() & 7)); S_PlayActorSound(GLASS_HEAVYBREAK, spr); break; @@ -2220,7 +2220,7 @@ void checkhitsprite_r(int i, int sn) case STATUEFLASH: case STATUE: if (s->picnum == BOTTLE10) - fi.lotsofmoney(&sprite[i], 4 + (krand() & 3)); + fi.lotsofmoney(&hittype[i], 4 + (krand() & 3)); else if (s->picnum == STATUE || s->picnum == STATUEFLASH) { lotsofcolourglass(i, -1, 40); @@ -2468,7 +2468,7 @@ void checksectors_r(int snum) if (chatmodeon || sprite[p->i].extra <= 0) return; if (ud.cashman && PlayerInput(snum, SB_OPEN)) - fi.lotsofmoney(&sprite[p->i], 2); + fi.lotsofmoney(&hittype[p->i], 2); if (!(PlayerInput(snum, SB_OPEN))) diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index 673a0df60..945510406 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -49,8 +49,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) { - if (isRRRA() && s_ow < 0) - return 0; + //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);