From 0536d7d989e630cba7486502dcfd6b79004d6482 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 18:16:42 -0700 Subject: [PATCH 1/7] Lua: Add IsProjectile/CastToProjectile functions --- dlls/ff/ff_lualib_base.cpp | 4 ++++ dlls/ff/ff_lualib_globals.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/dlls/ff/ff_lualib_base.cpp b/dlls/ff/ff_lualib_base.cpp index 9028d0f72..59e38cb89 100644 --- a/dlls/ff/ff_lualib_base.cpp +++ b/dlls/ff/ff_lualib_base.cpp @@ -9,6 +9,7 @@ #include "ff_lualib.h" #include "ff_item_flag.h" #include "ff_triggerclip.h" +#include "ff_projectile_base.h" #include "ff_team.h" #include "triggers.h" @@ -87,6 +88,9 @@ void CFFLuaLib::InitBase(lua_State* L) .def("GetFriction", &CBaseEntity::GetFriction) .def("SetFriction", &CBaseEntity::SetFriction), + // CFFProjectileBase + class_("Projectile"), + // CFFInfoScript class_("InfoScript") .def("Drop", (void(CFFInfoScript::*)(float, float))&CFFInfoScript::Drop) diff --git a/dlls/ff/ff_lualib_globals.cpp b/dlls/ff/ff_lualib_globals.cpp index b1cd03ffd..eadb54086 100644 --- a/dlls/ff/ff_lualib_globals.cpp +++ b/dlls/ff/ff_lualib_globals.cpp @@ -187,6 +187,12 @@ namespace FFLib */ } + // is the entity a projectile + bool IsProjectile(CBaseEntity* pEntity) + { + return dynamic_cast< CFFProjectileBase * >( pEntity ) != NULL; + } + // is the entity a miniturret bool IsTurret( CBaseEntity *pEntity ) { @@ -676,6 +682,17 @@ namespace FFLib return dynamic_cast< CFFGrenadeBase * >( pEntity ); } + CFFProjectileBase *CastToProjectile( CBaseEntity *pEntity ) + { + if( !pEntity ) + return NULL; + + if( !IsProjectile( pEntity ) ) + return NULL; + + return dynamic_cast< CFFProjectileBase * >( pEntity ); + } + CBeam* CastToBeam(CBaseEntity* pEntity) { if( !pEntity ) @@ -3041,6 +3058,7 @@ void CFFLuaLib::InitGlobals(lua_State* L) def("CastToSentrygun", &FFLib::CastToSentrygun), def("CastToDetpack", &FFLib::CastToDetpack), def("CastToJumpPad", &FFLib::CastToJumpPad), + def("CastToProjectile", &FFLib::CastToProjectile), def("ConsoleToAll", &FFLib::ConsoleToAll), def("DeleteSchedule", &FFLib::DeleteSchedule), def("DropToFloor", &FFLib::DropToFloor), @@ -3075,6 +3093,7 @@ void CFFLuaLib::InitGlobals(lua_State* L) def("IsJumpPad", &FFLib::IsJumpPad), def("IsGrenade", &FFLib::IsGrenade), def("IsTurret", &FFLib::IsTurret), + def("IsProjectile", &FFLib::IsProjectile), //def("KillAndRespawnAllPlayers", &FFLib::KillAndRespawnAllPlayers), def("NumPlayers", &FF_NumPlayers), def("GetPlayers", &FFLib::GetPlayers), From 5cb3647428fe377b737aba7498e57663f9e25ec5 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 18:18:11 -0700 Subject: [PATCH 2/7] Lua: Add IsInfoScript function --- dlls/ff/ff_lualib_globals.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dlls/ff/ff_lualib_globals.cpp b/dlls/ff/ff_lualib_globals.cpp index eadb54086..eb36b1b4c 100644 --- a/dlls/ff/ff_lualib_globals.cpp +++ b/dlls/ff/ff_lualib_globals.cpp @@ -193,6 +193,12 @@ namespace FFLib return dynamic_cast< CFFProjectileBase * >( pEntity ) != NULL; } + // is entity an infoscript + bool IsInfoScript( CBaseEntity *pEntity ) + { + return IsOfClass( pEntity, CLASS_INFOSCRIPT ); + } + // is the entity a miniturret bool IsTurret( CBaseEntity *pEntity ) { @@ -3094,6 +3100,7 @@ void CFFLuaLib::InitGlobals(lua_State* L) def("IsGrenade", &FFLib::IsGrenade), def("IsTurret", &FFLib::IsTurret), def("IsProjectile", &FFLib::IsProjectile), + def("IsInfoScript", &FFLib::IsInfoScript), //def("KillAndRespawnAllPlayers", &FFLib::KillAndRespawnAllPlayers), def("NumPlayers", &FF_NumPlayers), def("GetPlayers", &FFLib::GetPlayers), From 06ad6d15b30828d0fec0a03232bfe9aec733c831 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 19:31:58 -0700 Subject: [PATCH 3/7] Lua: Add IsBuildable/CastToBuildable functions --- dlls/ff/ff_lualib_globals.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dlls/ff/ff_lualib_globals.cpp b/dlls/ff/ff_lualib_globals.cpp index eb36b1b4c..9b3025084 100644 --- a/dlls/ff/ff_lualib_globals.cpp +++ b/dlls/ff/ff_lualib_globals.cpp @@ -170,6 +170,12 @@ namespace FFLib return IsOfClass( pEntity, CLASS_MANCANNON ); } + // is entity a buildable + bool IsBuildable( CBaseEntity *pEntity ) + { + return IsDispenser(pEntity) || IsSentrygun(pEntity) || IsDetpack(pEntity) || IsJumpPad(pEntity); + } + // is the entity a grenade bool IsGrenade(CBaseEntity* pEntity) { @@ -787,6 +793,17 @@ namespace FFLib return dynamic_cast< CFFManCannon * >( pEntity ); } + CFFBuildableObject *CastToBuildable( CBaseEntity *pEntity ) + { + if( !pEntity ) + return NULL; + + if( !IsBuildable( pEntity ) ) + return NULL; + + return dynamic_cast< CFFBuildableObject * >( pEntity ); + } + bool AreTeamsAllied(CTeam* pTeam1, CTeam* pTeam2) { if(NULL == pTeam1 || NULL == pTeam2) @@ -3064,6 +3081,7 @@ void CFFLuaLib::InitGlobals(lua_State* L) def("CastToSentrygun", &FFLib::CastToSentrygun), def("CastToDetpack", &FFLib::CastToDetpack), def("CastToJumpPad", &FFLib::CastToJumpPad), + def("CastToBuildable", &FFLib::CastToBuildable), def("CastToProjectile", &FFLib::CastToProjectile), def("ConsoleToAll", &FFLib::ConsoleToAll), def("DeleteSchedule", &FFLib::DeleteSchedule), @@ -3097,6 +3115,7 @@ void CFFLuaLib::InitGlobals(lua_State* L) def("IsSentrygun", &FFLib::IsSentrygun), def("IsDetpack", &FFLib::IsDetpack), def("IsJumpPad", &FFLib::IsJumpPad), + def("IsBuildable", &FFLib::IsBuildable), def("IsGrenade", &FFLib::IsGrenade), def("IsTurret", &FFLib::IsTurret), def("IsProjectile", &FFLib::IsProjectile), From 4f079ed69baa89457a64445c16de0b94b2b208d6 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 19:36:35 -0700 Subject: [PATCH 4/7] Lua: Add function GetEntitiesInSphere(Vector center, float radius, bool ignore_walls) --- dlls/ff/ff_lualib_globals.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dlls/ff/ff_lualib_globals.cpp b/dlls/ff/ff_lualib_globals.cpp index 9b3025084..1040672d8 100644 --- a/dlls/ff/ff_lualib_globals.cpp +++ b/dlls/ff/ff_lualib_globals.cpp @@ -584,6 +584,32 @@ namespace FFLib return luatblEntities; } + luabind::adl::object GetEntitiesInSphere(const Vector& vecOrigin, float flRadius, bool bIgnoreWalls) + { + luabind::adl::object luatblEntities = luabind::newtable(_scriptman.GetLuaState()); + + int iTableKey = 1; + CBaseEntity *pEntity = NULL; + for( CEntitySphereQuery sphere( vecOrigin, flRadius ); ( pEntity = sphere.GetCurrentEntity() ) != NULL; sphere.NextEntity() ) + { + if( !pEntity ) + continue; + + if (!bIgnoreWalls) + { + trace_t tr; + UTIL_TraceLine( vecOrigin, pEntity->GetAbsOrigin(), MASK_SOLID, NULL, COLLISION_GROUP_NONE, &tr ); + + if( FF_TraceHitWorld( &tr ) ) + continue; + } + + luatblEntities[iTableKey++] = luabind::adl::object(_scriptman.GetLuaState(), pEntity); + } + + return luatblEntities; + } + CFFPlayer* GetPlayer(CBaseEntity *pEntity) { // ToFFPlayer checks for NULL & IsPlayer() @@ -3091,6 +3117,7 @@ void CFFLuaLib::InitGlobals(lua_State* L) def("GetEntity", &FFLib::GetEntity), def("GetEntityByName", &FFLib::GetEntityByName), def("GetEntitiesByName", &FFLib::GetEntitiesByName), + def("GetEntitiesInSphere", &FFLib::GetEntitiesInSphere), def("GetInfoScriptById", &FFLib::GetInfoScriptById), def("GetInfoScriptByName", &FFLib::GetInfoScriptByName), def("GetGrenade", &FFLib::GetGrenade), From c82f0ab7219bfb590dbc65d36ae5416e0cd91df0 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 19:37:12 -0700 Subject: [PATCH 5/7] Lua: Add collection filter flag CF.kJumpPad --- dlls/ff/ff_lualib_util.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dlls/ff/ff_lualib_util.cpp b/dlls/ff/ff_lualib_util.cpp index 4c26500be..8f3af633c 100644 --- a/dlls/ff/ff_lualib_util.cpp +++ b/dlls/ff/ff_lualib_util.cpp @@ -82,6 +82,7 @@ enum CollectionFilter CF_BUILDABLE_DISPENSER, CF_BUILDABLE_SENTRYGUN, CF_BUILDABLE_DETPACK, + CF_BUILDABLE_JUMPPAD, CF_TRACE_BLOCK_WALLS, @@ -410,6 +411,12 @@ bool PassesCollectionFilter( CBaseEntity *pEntity, bool *pbFlags ) return false; } + if( pbFlags[ CF_BUILDABLE_JUMPPAD ] ) + { + if( pEntity->Classify() != CLASS_MANCANNON ) + return false; + } + return true; } @@ -1004,7 +1011,8 @@ void CFFLuaLib::InitUtil(lua_State* L) value("kBuildables", CF_BUILDABLES), value("kDispenser", CF_BUILDABLE_DISPENSER), value("kSentrygun", CF_BUILDABLE_SENTRYGUN), - value("kDetpack", CF_BUILDABLE_DETPACK) + value("kDetpack", CF_BUILDABLE_DETPACK), + value("kJumpPad", CF_BUILDABLE_JUMPPAD) ] ]; }; From 63095295902222c10d703410a20dded66beca561 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 22:05:05 -0700 Subject: [PATCH 6/7] Lua: Expose gEntList as the global variable GlobalEntityList Usage: GlobalEntityList:FirstEntity() // get the first CBaseEntity in the GlobalEntityList GlobalEntityList:NextEntity(CBaseEntity current_entity) // get the next CBaseEntity in the list, after current_entity GlobalEntityList:NumEntities() // get the total number of entities --- dlls/ff/ff_lualib_base.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dlls/ff/ff_lualib_base.cpp b/dlls/ff/ff_lualib_base.cpp index 59e38cb89..95bb8bf5e 100644 --- a/dlls/ff/ff_lualib_base.cpp +++ b/dlls/ff/ff_lualib_base.cpp @@ -7,6 +7,7 @@ // includes #include "cbase.h" #include "ff_lualib.h" +#include "EntityList.h" #include "ff_item_flag.h" #include "ff_triggerclip.h" #include "ff_projectile_base.h" @@ -51,6 +52,11 @@ void CFFLuaLib::InitBase(lua_State* L) module(L) [ + class_("EntityList") + .def("FirstEntity", &CGlobalEntityList::FirstEnt) + .def("NextEntity", &CGlobalEntityList::NextEnt) + .def("NumEntities", &CGlobalEntityList::NumberOfEntities), + // CBaseEntity class_("BaseEntity") .def(tostring(self)) @@ -136,4 +142,6 @@ void CFFLuaLib::InitBase(lua_State* L) class_("TriggerClip") .def("SetClipFlags", &CFFTriggerClip::LUA_SetClipFlags) ]; + + (globals(L))["GlobalEntityList"] = &gEntList; }; From b2f24700a3a8b69be109e7a37888cf058464eff8 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 23 Mar 2015 22:06:34 -0700 Subject: [PATCH 7/7] Fix typo in CF.kInfoScripts (was CF.kInfoScipts) * CF.kInfoScipts will remain for backwards compatibility --- dlls/ff/ff_lualib_util.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dlls/ff/ff_lualib_util.cpp b/dlls/ff/ff_lualib_util.cpp index 8f3af633c..ea4c4e041 100644 --- a/dlls/ff/ff_lualib_util.cpp +++ b/dlls/ff/ff_lualib_util.cpp @@ -997,7 +997,8 @@ void CFFLuaLib::InitUtil(lua_State* L) value("kProjectiles", CF_PROJECTILES), value("kGrenades", CF_GRENADES), - value("kInfoScipts", CF_INFOSCRIPTS), + value("kInfoScipts", CF_INFOSCRIPTS), // typo; kept for backwards compatibility + value("kInfoScripts", CF_INFOSCRIPTS), value("kInfoScript_Carried", CF_INFOSCRIPT_CARRIED), value("kInfoScript_Dropped", CF_INFOSCRIPT_DROPPED),