Skip to content

Commit

Permalink
destructible WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers authored and mjr4077au committed Nov 26, 2022
1 parent 1d4ae44 commit 4f98689
Show file tree
Hide file tree
Showing 10 changed files with 500 additions and 402 deletions.
22 changes: 15 additions & 7 deletions source/core/defparser.cpp
Expand Up @@ -2245,11 +2245,12 @@ static void parseSpawnClasses(FScanner& sc, FScriptPosition& pos)
}
while (!sc.CheckString("}"))
{
// This will need some reworking once we can use real textures.
int num = -1;
int base = -1;
FName basetex = NAME_None;
FName brokentex = NAME_None;
int sound = -1;
int basetex = -1;
int brokentex = -1;
FName sound = NAME_None;
FName cname;
sc.GetNumber(num, true);
sc.MustGetStringName("=");
Expand All @@ -2261,23 +2262,30 @@ static void parseSpawnClasses(FScanner& sc, FScriptPosition& pos)
else
{
sc.MustGetString();
basetex = sc.String;
basetex = TileFiles.tileForName(sc.String);
if (basetex < 0) Printf(TEXTCOLOR_RED "Unknown texture %s in definition for spawn ID # %d\n", num);
if (sc.CheckString(","))
{
sc.MustGetString();
brokentex = sc.String;
brokentex = TileFiles.tileForName(sc.String);
if (brokentex < 0) Printf(TEXTCOLOR_RED "Unknown texture %s in definition for spawn ID # %d\n", num);
if (sc.CheckString(","))
{
sc.MustGetString();
// sound = S_FindSound(sc.String); // todo
sound = sc.String;
#if 0
// Sound engine is not initialized here.
S_FindSound(sc.String).index();
if (sound <= 0) Printf(TEXTCOLOR_RED "Unknown sound %s in definition for spawn ID # %d\n", num);
#endif
}
}

}
}

// todo: check for proper base class
spawnMap.Insert(num, { cname, nullptr, base });
spawnMap.Insert(num, { cname, nullptr, base, basetex, brokentex, sound });
}
sc.SetCMode(false);
}
Expand Down
4 changes: 2 additions & 2 deletions source/core/gamecontrol.h
Expand Up @@ -276,8 +276,8 @@ struct SpawnRec
FName clsname;
PClass* cls;
int param;
FName basetex, brokentex;
int breaksound;
int basetex, brokentex;
FName breaksound;

PClass* Class(int pn)
{
Expand Down
5 changes: 5 additions & 0 deletions source/core/namedef_custom.h
Expand Up @@ -19,3 +19,8 @@ xx(DukeRespawnController)
xx(DukeActivator)
xx(DukeActivatorLocked)
xx(DukeLocator)
xx(DukeGenericDestructible)

xx(spawnstate)
xx(brokenstate)
xx(breaksound)
4 changes: 4 additions & 0 deletions source/games/duke/src/premap.cpp
Expand Up @@ -939,6 +939,10 @@ static TArray<DDukeActor*> spawnactors(SpawnSpriteDef& sprites)
}

auto sprt = &sprites.sprites[i];

if (sprt->picnum == 7220)
sprt->picnum = 8490;

auto info = spawnMap.CheckKey(sprt->picnum);
auto cls = info ? info->Class(sprt->picnum) : nullptr;;
auto actor = static_cast<DDukeActor*>(InsertActor(cls? cls : RUNTIME_CLASS(DDukeActor), sprt->sectp, sprt->statnum));
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/sectors_r.cpp
Expand Up @@ -1519,7 +1519,7 @@ void checkhitsprite_r(DDukeActor* targ, DDukeActor* proj)
targ->Destroy();
}
break;
case RRTILE1824:
case YELLOWBOTTLE:
if (!isRRRA()) break;
[[fallthrough]];
case BOTTLE1:
Expand Down
16 changes: 6 additions & 10 deletions source/games/duke/src/spawn.cpp
Expand Up @@ -47,18 +47,14 @@ void setFromSpawnRec(DDukeActor* act, SpawnRec* info)
{
if (info)
{
int basepicnum = info->param;
//int basepicnum = info->param;
//act->basepicnum = basepicnum;
if (info->basetex != NAME_None)
if (info->basetex > 0 && act->IsKindOf(NAME_DukeGenericDestructible))
{
act->spr.picnum = act->basepicnum = TileFiles.tileForName(info->basetex.GetChars());
// These fields are only temporary. Once we can work with proper engine types they need to go.
act->spr.detail = -1;
if (info->brokentex != NAME_None)
{
act->spr.detail = TileFiles.tileForName(info->brokentex.GetChars());
}
act->spr.inittype = info->breaksound;
// allow defining simple destructibles without actual actor definitions.
act->IntVar(NAME_spawnstate) = info->basetex;
act->IntVar(NAME_brokenstate) = info->brokentex;
act->IntVar(NAME_breaksound) = S_FindSound(info->breaksound.GetChars()).index();
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions source/games/duke/src/vmexports.cpp
Expand Up @@ -978,6 +978,30 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, floorflags, duke_floorflags)
ACTION_RETURN_INT(duke_floorflags(sect));
}

int duke_wallflags(walltype* wal)
{
return tileflags(wal->picnum);
}

DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, wallflags, duke_wallflags)
{
PARAM_PROLOGUE;
PARAM_POINTER(sect, walltype);
ACTION_RETURN_INT(duke_wallflags(sect));
}

int duke_ismirror(walltype* wal)
{
return wal->picnum == TILE_MIRROR || wal->overpicnum == TILE_MIRROR;
}

DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, ismirror, duke_ismirror)
{
PARAM_PROLOGUE;
PARAM_POINTER(wal, walltype);
ACTION_RETURN_BOOL(duke_ismirror(wal));
}

DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, addcycler, addcycler)
{
PARAM_PROLOGUE;
Expand Down Expand Up @@ -1093,6 +1117,18 @@ DEFINE_ACTION_FUNCTION_NATIVE(_tspritetype, setWeaponOrAmmoSprite, tspritetype_s
return 0;
}

// this must still work around the lack of proper texture support on the script side.
DEFINE_ACTION_FUNCTION(DDukeGenericDestructible, SetBroken)
{
PARAM_SELF_STRUCT_PROLOGUE(DDukeActor);
PARAM_INT(bust);
int tilenum = self->IntVar(bust ? NAME_brokenstate : NAME_spawnstate);
if (tilenum > 0) self->spr.picnum = tilenum;
ACTION_RETURN_BOOL(tilenum > 0);
}




void spawnguts(DDukeActor* origin, PClass* type, int count)
{
Expand Down

0 comments on commit 4f98689

Please sign in to comment.