From 579c4152d2ef9667eda54806f2701cbb07673c8b Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Mon, 21 Feb 2022 18:27:03 -0600 Subject: [PATCH] Added GetTerrainDef and Sector variant of GetFloorTerrain. - GetTerrainDef takes the raw number of the Terrains[] index. Can return null. - GetFloorTerrain (Sector) gets the defs from the position given (either Sector.Floor or Sector.Ceiling). --- src/gamedata/r_defs.h | 3 +++ src/playsim/p_sectors.cpp | 10 ++++++++++ src/scripting/vmthunks.cpp | 13 +++++++++++++ wadsrc/static/zscript/constants.zs | 3 +++ wadsrc/static/zscript/mapdata.zs | 2 ++ 5 files changed, 31 insertions(+) diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 57e87e32e..2aa79a1fd 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -37,6 +37,7 @@ #include "r_data/r_translate.h" #include "texmanip.h" #include "fcolormap.h" +#include "p_terrain.h" #include "hwrenderer/data/buffers.h" @@ -1769,6 +1770,8 @@ void TransferSpecial(sector_t *self, sector_t *model); void GetSpecial(sector_t *self, secspecial_t *spec); void SetSpecial(sector_t *self, const secspecial_t *spec); int GetTerrain(const sector_t *, int pos); +FTerrainDef *GetFloorTerrain_S(const sector_t* sec, int pos); +FTerrainDef *GetTerrainDef(const unsigned int num); void CheckPortalPlane(sector_t *sector, int plane); void AdjustFloorClip(const sector_t *sector); void SetColor(sector_t *sector, int color, int desat); diff --git a/src/playsim/p_sectors.cpp b/src/playsim/p_sectors.cpp index 5459792ed..e3963272b 100644 --- a/src/playsim/p_sectors.cpp +++ b/src/playsim/p_sectors.cpp @@ -938,6 +938,16 @@ int GetTerrain(const sector_t *sector, int pos) return sector->terrainnum[pos] >= 0 ? sector->terrainnum[pos] : TerrainTypes[sector->GetTexture(pos)]; } +FTerrainDef *GetFloorTerrain_S(const sector_t* sec, int pos) +{ + return &Terrains[GetTerrain(sec, pos)]; +} + +FTerrainDef *GetTerrainDef(const unsigned int num) +{ + return (num >= 0 && num < Terrains.Size()) ? &Terrains[num] : nullptr; +} + //===================================================================================== // // diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index b32be00a2..e35dd43bf 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -470,6 +470,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, GetTerrain, GetTerrain) ACTION_RETURN_INT(GetTerrain(self, pos)); } +DEFINE_ACTION_FUNCTION_NATIVE(_Sector, GetFloorTerrain, GetFloorTerrain_S) +{ + PARAM_SELF_STRUCT_PROLOGUE(sector_t); + PARAM_INT(pos); + ACTION_RETURN_POINTER(GetFloorTerrain_S(self, pos)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_Sector, GetTerrainDef, GetTerrainDef) +{ + PARAM_SELF_STRUCT_PROLOGUE(sector_t); + PARAM_UINT(floorterrain); + ACTION_RETURN_POINTER(GetTerrainDef(floorterrain)); +} DEFINE_ACTION_FUNCTION_NATIVE(_Sector, CheckPortalPlane, CheckPortalPlane) { diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index de7eab3d9..458363fc4 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -1021,6 +1021,9 @@ enum EFindFloorCeiling FFCF_NOCEILING = 64, FFCF_RESTRICTEDPORTAL = 128, // current values in the iterator's return are through a restricted portal type (i.e. some features are blocked.) FFCF_NODROPOFF = 256, // Caller does not need a dropoff (saves some time when checking portals) + FFCF_NONSOLID = 512, // [MC] Include non-solids + FFCF_NOSOLIDS = 1024, // [MC] Ignore solid + FFCF_SWIMMABLE = 2048, // [MC] Search for swimmables }; enum ERaise diff --git a/wadsrc/static/zscript/mapdata.zs b/wadsrc/static/zscript/mapdata.zs index f0cfce1c0..8b296d994 100644 --- a/wadsrc/static/zscript/mapdata.zs +++ b/wadsrc/static/zscript/mapdata.zs @@ -452,6 +452,8 @@ struct Sector native play native void GetSpecial(out SecSpecial spec); native void SetSpecial( SecSpecial spec); native int GetTerrain(int pos); + native TerrainDef GetTerrainDef(uint floorterrain); // Gets the terraindef from the number (such as an actor's floorterrain). May return null! + native TerrainDef GetFloorTerrain(int pos); // Gets the terraindef from floor/ceiling (see EPlane const). native void CheckPortalPlane(int plane); native double, Sector HighestCeilingAt(Vector2 a); native double, Sector LowestFloorAt(Vector2 a);