From f194fb6c90a8ecef79a87186d1cb801fd0a8f857 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 23 Jan 2022 21:30:00 +0100 Subject: [PATCH] - added a name to tilenum function so that we can define picnums by name in scripted actors. --- source/core/textures/buildtiles.h | 16 ++++++++++++++++ source/core/thingdef_properties.cpp | 6 +++++- source/games/blood/src/blood.cpp | 1 + source/games/duke/src/game.cpp | 1 + source/games/exhumed/src/exhumed.cpp | 1 + source/games/sw/src/game.cpp | 1 + 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index 5dfe94d30..1160ca184 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -5,6 +5,7 @@ #include "image.h" #include "i_time.h" #include "intvec.h" +#include "name.h" // picanm[].sf: // |bit(1<<7) @@ -294,6 +295,21 @@ struct BuildTiles TArray addedArt; TArray maptilesadded; TMap cameratextures; + TMap nametoindex; + + void addName(const char* name, int index) + { + nametoindex.Insert(name, index); + } + + int tileForName(const char* name) + { + FName nm(name, true); + if (nm == NAME_None) return -1; + auto nmm = nametoindex.CheckKey(nm); + if (!nmm) return -1; + return *nmm; + } void Init(); // This cannot be a constructor because it needs the texture manager running. ~BuildTiles() diff --git a/source/core/thingdef_properties.cpp b/source/core/thingdef_properties.cpp index ba3166d09..2f5e6fcc6 100644 --- a/source/core/thingdef_properties.cpp +++ b/source/core/thingdef_properties.cpp @@ -316,7 +316,11 @@ static bool PointerCheck(PType *symtype, PType *checktype) DEFINE_PROPERTY(pic, S, CoreActor) { PROP_STRING_PARM(str, 0); - defaults->spr.picnum = 0; // todo + defaults->spr.picnum = TileFiles.tileForName(str); + if (defaults->spr.picnum == -1) + { + I_Error("Unknown texture name '%s'", str); + } bag.Info->ActorInfo()->DefaultCstat |= DEFF_PICNUM; } diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 18916cd0c..1204e9fad 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -499,6 +499,7 @@ static void SetTileNames() auto registerName = [](const char* name, int index) { TexMan.AddAlias(name, tileGetTexture(index)); + TileFiles.addName(name, index); }; #include "namelist.h" // Oh Joy! Plasma Pak changes the tile number of the title screen, but we preferably want mods that use the original one to display it. diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 229ce654d..daf267cc2 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -296,6 +296,7 @@ static void SetTileNames() auto registerName = [](const char* name, int index) { TexMan.AddAlias(name, tileGetTexture(index)); + TileFiles.addName(name, index); }; if (!isRR()) { diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index f48d90e72..64c7c71d2 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -493,6 +493,7 @@ static void SetTileNames() auto registerName = [](const char* name, int index) { TexMan.AddAlias(name, tileGetTexture(index)); + TileFiles.addName(name, index); }; #include "namelist.h" } diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index 9c68b8bb7..39a408cb1 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -215,6 +215,7 @@ static void SetTileNames() auto registerName = [](const char* name, int index) { TexMan.AddAlias(name, tileGetTexture(index)); + TileFiles.addName(name, index); }; #include "namelist.h" }