From ebf7b4a121391e692adc7f45376da20549db747f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 21 Dec 2022 22:06:34 +0100 Subject: [PATCH] - copy the CON defined info into the actual actors. Only using the strength value right now. --- source/core/actorinfo.h | 3 +- source/core/gamecontrol.cpp | 1 + source/core/gamestruct.h | 1 + source/core/namedef_custom.h | 1 + source/core/thingdef_properties.cpp | 12 +--- source/games/duke/src/duke3d.h | 1 + source/games/duke/src/game.cpp | 58 +++++++++++++++++++ source/games/duke/src/spawn.cpp | 9 +-- .../zscript/games/duke/actors/tripbomb.zs | 2 +- wadsrc/static/zscript/games/duke/dukeactor.zs | 2 + 10 files changed, 69 insertions(+), 21 deletions(-) diff --git a/source/core/actorinfo.h b/source/core/actorinfo.h index 5705b5393..2d7192719 100644 --- a/source/core/actorinfo.h +++ b/source/core/actorinfo.h @@ -25,10 +25,9 @@ struct FActorInfo PClassActor *Replacement = nullptr; PClassActor *Replacee = nullptr; DVector2 DefaultScale = { 0, 0 }; - int TypeNum = -1; + int TypeNum = -1; // game specific identifier. int DefaultFlags = 0; int DefaultCstat = 0; - int Health = 0; // not used yet - this will stand in if no CON defines a health value for Duke. FName DamageType = NAME_None; // damage type this item inflicts // these are temporary. Due to how Build games handle their tiles, we cannot look up the textures when scripts are being parsed. diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 321c7aba7..258949fb6 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1182,6 +1182,7 @@ int RunGame() D_CheckNetGame(); UpdateGenericUI(ui_generic); PClassActor::StaticInit(); + gi->FinalizeSetup(); MainLoop(); return 0; } diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index cd20bafba..b82ef5f00 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -67,6 +67,7 @@ struct GameInterface virtual ~GameInterface() {} virtual bool GenerateSavePic() { return false; } virtual void app_init() = 0; + virtual void FinalizeSetup() {} virtual void LoadTextureInfo(TilesetBuildInfo& info) {} virtual void SetupSpecialTextures(TilesetBuildInfo&) = 0; virtual void loadPalette() = 0; diff --git a/source/core/namedef_custom.h b/source/core/namedef_custom.h index 277ccb049..680880566 100644 --- a/source/core/namedef_custom.h +++ b/source/core/namedef_custom.h @@ -72,3 +72,4 @@ xx(spawnsound) xx(gutsoffset) xx(falladjustz) xx(aimoffset) +xx(strength) diff --git a/source/core/thingdef_properties.cpp b/source/core/thingdef_properties.cpp index 1cc703406..b40170cae 100644 --- a/source/core/thingdef_properties.cpp +++ b/source/core/thingdef_properties.cpp @@ -382,17 +382,7 @@ DEFINE_PROPERTY(spritesetindex, I, CoreActor) //========================================================================== // -//========================================================================== -DEFINE_PROPERTY(health, I, CoreActor) -{ - PROP_INT_PARM(i, 0); - bag.Info->ActorInfo()->Health = i; -} - -//========================================================================== -// -// This is a hack because the FTA sight flag has different defaults in -// Duke and RR. +// Sets up the flag defaults which differ between RR and Duke. // //========================================================================== DEFINE_PROPERTY(lookallarounddefault,0, DukeActor) diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 2913005e0..6100217f3 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -25,6 +25,7 @@ struct GameInterface : public ::GameInterface { const char* Name() override { return "Duke"; } void app_init() override; + void FinalizeSetup() override; void loadPalette() override; void SetupSpecialTextures(TilesetBuildInfo& info) override; bool GenerateSavePic() override; diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 5f8402919..8f7b0ecc5 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -44,6 +44,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "vm.h" #include "thingdef.h" #include "tilesetbuilder.h" +#include "concmd.h" BEGIN_DUKE_NS @@ -424,6 +425,63 @@ void GameInterface::app_init() S_ParseDeveloperCommentary(); } +void GameInterface::FinalizeSetup() +{ + for (int i = 0; i < MAXTILES; i++) + { + auto& actinf = gs.actorinfo[i]; + if (actinf.scriptaddress != 0) + { + int act = ScriptCode[actinf.scriptaddress + 1]; + int cmd = ScriptCode[actinf.scriptaddress + 4]; + auto info = spawnMap.CheckKey(i); + PClassActor* cls = nullptr; + + if (info != nullptr && info->basetex <= 0) + { + cls = info->cls; + } + else if (info == nullptr || info->basetex <= 0) + { + // No unique actor exists here. Since we need one, create a new class here, directly derived from DDukeActor. + auto newcls = (PClassActor*)RUNTIME_CLASS(DDukeActor)->CreateDerivedClass(FStringf("NewConActor%d", i), RUNTIME_CLASS(DDukeActor)->Size); + newcls->InitializeDefaults(); + spawnMap.Insert(i, { newcls, -1, -1, NO_SOUND, int8_t(0), int8_t(0), int16_t(0x8000) }); + cls = newcls; + GetDefaultByType(newcls)->spr.picnum = i; // make it show the right pic. + } + else + { + // the ugly case: This tries to replace a variant of a special actor. + // All of Duke's entries falling in this category are coded to not execute scripts at all with no possible override. + // this means that none of these actors can ever run its scripts. + + } + + // now copy all data over so that we don't have to do double maintenance. + if (cls) + { + cls->ActorInfo()->TypeNum = i; + GetDefaultByType(cls)->IntVar(NAME_strength) = ScriptCode[actinf.scriptaddress]; + if (actinf.enemyflags & EDukeFlags1::FromInt(1)) + { + auto def = static_cast(GetDefaultByType(cls)); + auto fb = (SFLAG_BADGUY | SFLAG_KILLCOUNT | SFLAG_BADGUYSTAYPUT); + auto check = (def->flags1 & (SFLAG_BADGUY | SFLAG_KILLCOUNT)); + // do not enable KILLCOUNT if it the base is a non-counting badguy. This is needed for RR's animals. + if (check == EDukeFlags1::FromInt(SFLAG_BADGUY)) fb &= ~SFLAG_KILLCOUNT; + def->flags1 = (def->flags1 & ~fb) | (actinf.enemyflags & fb); + } + + } + } + //ScriptCode[actinf.scriptaddress] = 0; // ignore strength values for hashing the script code. (later, we still need this.) + // todo: hash the entire script code and compare against precalculated value for the current game. + // If identical, remove all ScriptAddresses from the class list. + + } +} + void CallInitialize(DDukeActor* actor) { diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index f762829db..f3d0af58a 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -126,23 +126,19 @@ DDukeActor* CreateActor(sectortype* whatsectp, const DVector3& pos, PClassActor* if (gs.actorinfo[s_pn].scriptaddress) { auto sa = &ScriptCode[gs.actorinfo[s_pn].scriptaddress]; - act->spr.extra = sa[0]; act->curAction = &actions[sa[1]]; act->curMove = &moves[sa[2]]; act->spr.hitag = sa[3]; } else { - act->spr.extra = 0; act->spr.hitag = 0; } + act->spr.extra = act->IntVar(NAME_strength); if (show2dsector[act->sectno()]) act->spr.cstat2 |= CSTAT2_SPRITE_MAPPED; else act->spr.cstat2 &= ~CSTAT2_SPRITE_MAPPED; - act->sprext = {}; - act->spsmooth = {}; - return act; } @@ -234,16 +230,15 @@ bool initspriteforspawn(DDukeActor* act) if (act->spr.cstat & CSTAT_SPRITE_BLOCK) act->spr.cstat |= CSTAT_SPRITE_BLOCK_HITSCAN; + act->spr.extra = act->IntVar(NAME_strength); if (gs.actorinfo[s].scriptaddress) { - act->spr.extra = ScriptCode[gs.actorinfo[s].scriptaddress]; act->curAction = &actions[ScriptCode[gs.actorinfo[s].scriptaddress+1]]; act->curMove = &moves[ScriptCode[gs.actorinfo[s].scriptaddress+2]]; int s3 = ScriptCode[gs.actorinfo[s].scriptaddress+3]; if (s3 && act->spr.hitag == 0) act->spr.hitag = s3; } - else act->temp_data[1] = act->temp_data[4] = 0; return true; } diff --git a/wadsrc/static/zscript/games/duke/actors/tripbomb.zs b/wadsrc/static/zscript/games/duke/actors/tripbomb.zs index 4fd5cd0ff..4d2d7c203 100644 --- a/wadsrc/static/zscript/games/duke/actors/tripbomb.zs +++ b/wadsrc/static/zscript/games/duke/actors/tripbomb.zs @@ -13,7 +13,7 @@ class DukeTripBomb : DukeActor { pic "TRIPBOMB"; // Note: The trip bomb has its health defined through CON! Value is 100. Con-based definitions will take precendence. - health 100; + strength 100; +CHECKSLEEP; +HITRADIUS_FLAG2; +MOVEFTA_MAKESTANDABLE; diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 13e0555bc..c4b03ecf1 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -145,11 +145,13 @@ class DukeActor : CoreActor native meta int gutsoffset; meta int falladjustz; meta int aimoffset; + meta int strength; property prefix: none; property gutsoffset: gutsoffset; property falladjustz: falladjustz; property aimoffset: aimoffset; + property strength: strength; native void SetSpritesetImage(int index);