From 0c1eeebe76752175c377e310d0d888fd9b2ee2c1 Mon Sep 17 00:00:00 2001 From: Naudiz <31663251+nazjun@users.noreply.github.com> Date: Sat, 2 Apr 2022 16:36:05 -0400 Subject: [PATCH] Various neckonings --- source/GcLib/directx/DxObject.cpp | 8 +- source/GcLib/directx/DxText.cpp | 2 +- source/GcLib/directx/RenderObject.cpp | 1 + source/GcLib/directx/RenderObject.hpp | 4 + source/GcLib/gstd/GstdUtility.hpp | 48 ++++++++ source/GcLib/gstd/ScriptClient.cpp | 27 +++++ source/GcLib/gstd/ScriptClient.hpp | 4 + source/TouhouDanmakufu/Common/StgItem.cpp | 20 +++- source/TouhouDanmakufu/Common/StgItem.hpp | 2 +- source/TouhouDanmakufu/Common/StgShot.cpp | 109 +++++++++++++++++- source/TouhouDanmakufu/Common/StgShot.hpp | 5 +- .../TouhouDanmakufu/Common/StgStageScript.cpp | 88 +++++++++++++- .../TouhouDanmakufu/Common/StgStageScript.hpp | 4 + 13 files changed, 307 insertions(+), 15 deletions(-) diff --git a/source/GcLib/directx/DxObject.cpp b/source/GcLib/directx/DxObject.cpp index ec2a1b9e..d320e988 100644 --- a/source/GcLib/directx/DxObject.cpp +++ b/source/GcLib/directx/DxObject.cpp @@ -481,7 +481,9 @@ void DxScriptParticleListObject2D::SetRenderState() { graphics->SetTextureFilter(filterMin_, filterMag_, filterMip_); } void DxScriptParticleListObject2D::CleanUp() { - GetParticlePointer()->ClearInstance(); + ParticleRenderer2D* obj = GetParticlePointer(); + if (obj->GetAutoClearInstance()) + obj->ClearInstance(); } //**************************************************************************** @@ -524,7 +526,9 @@ void DxScriptParticleListObject3D::SetRenderState() { graphics->SetTextureFilter(filterMin_, filterMag_, filterMip_); } void DxScriptParticleListObject3D::CleanUp() { - GetParticlePointer()->ClearInstance(); + ParticleRenderer3D* obj = GetParticlePointer(); + if (obj->GetAutoClearInstance()) + obj->ClearInstance(); } //**************************************************************************** diff --git a/source/GcLib/directx/DxText.cpp b/source/GcLib/directx/DxText.cpp index 8f2e5804..0f84c2f0 100644 --- a/source/GcLib/directx/DxText.cpp +++ b/source/GcLib/directx/DxText.cpp @@ -178,7 +178,7 @@ bool DxCharGlyph::Create(UINT code, const Font& winFont, const DxFont* dxFont) { if (minAlphaEnableDist < widthBorder) destAlpha = 255; else if (minAlphaEnableDist == widthBorder) - destAlpha = count; + destAlpha = static_cast(count); else destAlpha = 0; //color = ColorAccess::SetColorA(color, ColorAccess::GetColorA(colorBorder)*count/255); diff --git a/source/GcLib/directx/RenderObject.cpp b/source/GcLib/directx/RenderObject.cpp index 3b3960ab..6ee2b2b9 100644 --- a/source/GcLib/directx/RenderObject.cpp +++ b/source/GcLib/directx/RenderObject.cpp @@ -1389,6 +1389,7 @@ void TrajectoryObject3D::AddPoint(const D3DXMATRIX& mat) { ParticleRendererBase::ParticleRendererBase() { countInstance_ = 0U; countInstancePrev_ = 0U; + autoClearInstance_ = true; instColor_ = 0xffffffff; instPosition_ = D3DXVECTOR3(0, 0, 0); instScale_ = D3DXVECTOR3(1, 1, 1); diff --git a/source/GcLib/directx/RenderObject.hpp b/source/GcLib/directx/RenderObject.hpp index 14a70652..08692d5d 100644 --- a/source/GcLib/directx/RenderObject.hpp +++ b/source/GcLib/directx/RenderObject.hpp @@ -363,6 +363,9 @@ namespace directx { void AddInstance(); void ClearInstance(); + void SetAutoClearInstance(bool clear) { autoClearInstance_ = clear; } + bool GetAutoClearInstance() { return autoClearInstance_; } + void SetInstanceColor(D3DCOLOR color) { instColor_ = color; } void SetInstanceColorRGB(int r, int g, int b); void SetInstanceColorRGB(D3DCOLOR color); @@ -388,6 +391,7 @@ namespace directx { size_t countInstance_; size_t countInstancePrev_; std::vector instanceData_; + bool autoClearInstance_; D3DCOLOR instColor_; D3DXVECTOR3 instPosition_; diff --git a/source/GcLib/gstd/GstdUtility.hpp b/source/GcLib/gstd/GstdUtility.hpp index 80cf7820..6ccc4d4d 100644 --- a/source/GcLib/gstd/GstdUtility.hpp +++ b/source/GcLib/gstd/GstdUtility.hpp @@ -430,6 +430,54 @@ namespace gstd { return DifferentialLinear; } }; + + class Kinematic { + public: + template + static inline T U_VAD(T v, T a, T d) { return sqrt(v * v - 2 * a * d); } + template + static inline T U_VAT(T v, T a, T t) { return v - a * t; } + template + static inline T U_VDT(T v, T d, T t) { return 2 * d / t - v; } + template + static inline T U_ADT(T a, T d, T t) { return d / t - a * t / 2; } + + template + static inline T V_UAD(T u, T a, T d) { return sqrt(u * u + 2 * a * d); } + template + static inline T V_UAT(T u, T a, T t) { return u + a * t; } + template + static inline T V_UDT(T u, T d, T t) { return 2 * d / t - u; } + template + static inline T V_ADT(T a, T d, T t) { return d / t + a * t / 2; } + + template + static inline T A_UVD(T u, T v, T d) { return (v * v - u * u) / (2 * d); } + template + static inline T A_UVT(T u, T v, T t) { return (v - u) / t; } + template + static inline T A_UDT(T u, T d, T t) { return 2 * (d - u * t) / (t * t); } + template + static inline T A_VDT(T v, T d, T t) { return 2 * (v * t - d) / (t * t); } + + template + static inline T D_UVA(T u, T v, T a) { return (v * v - u * u) / (2 * a); } + template + static inline T D_UVT(T u, T v, T t) { return t / 2 * (u + v); } + template + static inline T D_UAT(T u, T a, T t) { return u * t + a * t * t / 2; } + template + static inline T D_VAT(T v, T a, T t) { return v * t - a * t * t / 2; } + + template + static inline T T_UVA(T u, T v, T a) { return (v - u) / a; } + template + static inline T T_UVD(T u, T v, T d) { return 2 * d / (u + v); } + template + static inline T T_UAD(T u, T a, T d) { return (-u + sqrt(u * u + 2 * a * d)) / a; } + template + static inline T T_VAD(T v, T a, T d) { return (v - sqrt(v * v - 2 * a * d)) / a; } + }; }; #endif diff --git a/source/GcLib/gstd/ScriptClient.cpp b/source/GcLib/gstd/ScriptClient.cpp index de933f5c..f057ecce 100644 --- a/source/GcLib/gstd/ScriptClient.cpp +++ b/source/GcLib/gstd/ScriptClient.cpp @@ -141,6 +141,28 @@ static const std::vector commonFunction = { { "Interpolate_X_AngleR", ScriptClientBase::Func_Interpolate_X_Angle, 4 }, { "Interpolate_X_Array", ScriptClientBase::Func_Interpolate_X_Array, 3 }, + //Kinematics + { "Kinematic_U_VAD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_U_VAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_U_VDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_U_ADT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_UAD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_UAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_UDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_V_ADT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_UVD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_UVT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_UDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_A_VDT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_UVA", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_UVT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_UAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_D_VAT", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_UVA", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_UVD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_UAD", ScriptClientBase::Func_Kinematic, 3 }, + { "Kinematic_T_VAD", ScriptClientBase::Func_Kinematic, 3 }, + //Rotation { "Rotate2D", ScriptClientBase::Func_Rotate2D, 3 }, { "Rotate2D", ScriptClientBase::Func_Rotate2D, 5 }, @@ -1040,6 +1062,11 @@ value ScriptClientBase::Func_Interpolate_X_Array(script_machine* machine, int ar return _ScriptValueLerp(machine, &arr[from], &arr[to], x, lerpFunc); } +template +value ScriptClientBase::Func_Kinematic(script_machine* machine, int argc, const value* argv) { + return CreateFloatValue(funcKinematic(argv[0].as_float(), argv[1].as_float(), argv[2].as_float())); +} + value ScriptClientBase::Func_Rotate2D(script_machine* machine, int argc, const value* argv) { double pos[2] = { argv[0].as_float(), argv[1].as_float() }; double ang = argv[2].as_float(); diff --git a/source/GcLib/gstd/ScriptClient.hpp b/source/GcLib/gstd/ScriptClient.hpp index f946477c..d198b2ad 100644 --- a/source/GcLib/gstd/ScriptClient.hpp +++ b/source/GcLib/gstd/ScriptClient.hpp @@ -266,6 +266,10 @@ namespace gstd { DNH_FUNCAPI_DECL_(Func_Interpolate_X_Angle); DNH_FUNCAPI_DECL_(Func_Interpolate_X_Array); + //Math functions; kinematics + template + DNH_FUNCAPI_DECL_(Func_Kinematic); + //Math functions; rotation DNH_FUNCAPI_DECL_(Func_Rotate2D); DNH_FUNCAPI_DECL_(Func_Rotate3D); diff --git a/source/TouhouDanmakufu/Common/StgItem.cpp b/source/TouhouDanmakufu/Common/StgItem.cpp index d7880b38..2dca6165 100644 --- a/source/TouhouDanmakufu/Common/StgItem.cpp +++ b/source/TouhouDanmakufu/Common/StgItem.cpp @@ -291,15 +291,29 @@ void StgItemManager::CancelCollectItems() { bCancelToPlayer_ = true; } -std::vector StgItemManager::GetItemIdInCircle(int cx, int cy, int radius, int* itemType) { - int rr = radius * radius; +std::vector StgItemManager::GetItemIdInCircle(int cx, int cy, int* radius, int* itemType) { + int r = radius ? *radius : 0; + int rr = r * r; + + int rect_x1 = cx - r; + int rect_y1 = cy - r; + int rect_x2 = cx + r; + int rect_y2 = cy + r; std::vector res; for (ref_unsync_ptr& obj : listObj_) { if (obj->IsDeleted()) continue; if (itemType != nullptr && (*itemType != obj->GetItemType())) continue; - if (Math::HypotSq(cx - obj->GetPositionX(), cy - obj->GetPositionY()) <= rr) + int sx = obj->GetPositionX(); + int sy = obj->GetPositionY(); + + bool bInCircle = radius == nullptr; + if (!bInCircle) { + bool bPassAABB = (sx > rect_x1 && sy > rect_y1) && (sx < rect_x2&& sy < rect_y2); + bInCircle = bPassAABB && Math::HypotSq(cx - sx, cy - sy) <= rr; + } + if (bInCircle) res.push_back(obj->GetObjectID()); } diff --git a/source/TouhouDanmakufu/Common/StgItem.hpp b/source/TouhouDanmakufu/Common/StgItem.hpp index 31659189..22006ab2 100644 --- a/source/TouhouDanmakufu/Common/StgItem.hpp +++ b/source/TouhouDanmakufu/Common/StgItem.hpp @@ -92,7 +92,7 @@ class StgItemManager { void CollectItemsInCircle(const DxCircle& circle); void CancelCollectItems(); - std::vector GetItemIdInCircle(int cx, int cy, int radius, int* itemType); + std::vector GetItemIdInCircle(int cx, int cy, int* radius, int* itemType); bool IsDefaultBonusItemEnable() { return bDefaultBonusItemEnable_; } void SetDefaultBonusItemEnable(bool bEnable) { bDefaultBonusItemEnable_ = bEnable; } diff --git a/source/TouhouDanmakufu/Common/StgShot.cpp b/source/TouhouDanmakufu/Common/StgShot.cpp index beb1973c..10e86a6f 100644 --- a/source/TouhouDanmakufu/Common/StgShot.cpp +++ b/source/TouhouDanmakufu/Common/StgShot.cpp @@ -164,12 +164,14 @@ void StgShotManager::AddShot(ref_unsync_ptr obj) { listObj_.push_back(obj); } -void StgShotManager::DeleteInCircle(int typeDelete, int typeTo, int typeOwner, int cx, int cy, int* radius) { +size_t StgShotManager::DeleteInCircle(int typeDelete, int typeTo, int typeOwner, int cx, int cy, int* radius) { int r = radius ? *radius : 0; int rr = r * r; DxRect rcBox(cx - r, cy - r, cx + r, cy + r); + size_t res = 0; + for (ref_unsync_ptr& obj : listObj_) { if (obj->IsDeleted()) continue; if ((typeOwner != StgShotObject::OWNER_NULL) && (obj->GetOwnerType() != typeOwner)) continue; @@ -179,6 +181,13 @@ void StgShotManager::DeleteInCircle(int typeDelete, int typeTo, int typeOwner, i int sy = obj->GetPositionY(); if (radius == nullptr || (rcBox.IsPointIntersected(sx, sy) && Math::HypotSq(cx - sx, cy - sy) <= rr)) { + if (obj->GetObjectType() == TypeObject::Shot) + ++res; + else { + StgLaserObject* laser = dynamic_cast(obj.get()); + res += floor(laser->GetLength() / laser->GetItemDistance()); + } + if (typeTo == TO_TYPE_IMMEDIATE) obj->DeleteImmediate(); else if (typeTo == TO_TYPE_FADE) @@ -187,6 +196,63 @@ void StgShotManager::DeleteInCircle(int typeDelete, int typeTo, int typeOwner, i obj->ConvertToItem(); } } + + return res; +} +size_t StgShotManager::DeleteInRegularPolygon(int typeDelete, int typeTo, int typeOwner, int cx, int cy, int* radius, int edges, double angle) { + int r = radius ? *radius : 0; + + int rect_x1 = cx - r; + int rect_y1 = cy - r; + int rect_x2 = cx + r; + int rect_y2 = cy + r; + + size_t res = 0; + + for (ref_unsync_ptr& obj : listObj_) { + if (obj->IsDeleted()) continue; + if ((typeOwner != StgShotObject::OWNER_NULL) && (obj->GetOwnerType() != typeOwner)) continue; + if (typeDelete == DEL_TYPE_SHOT && obj->IsSpellResist()) continue; + + int sx = obj->GetPositionX(); + int sy = obj->GetPositionY(); + + bool bInPolygon = radius == nullptr; + if (!bInPolygon && ((sx > rect_x1 && sy > rect_y1) && (sx < rect_x2 && sy < rect_y2))) { + float f = GM_PI / (float)edges; + float cf = cosf(f); + float dx = sx - cx; + float dy = sy - cy; + float dist = hypotf(dy, dx); + + bInPolygon = dist <= r; + if (bInPolygon) { + double r_apothem = r * cf; + bInPolygon = dist <= r_apothem; + if (!bInPolygon) { + double ang = fmod(Math::NormalizeAngleRad(atan2(dy, dx)) - Math::DegreeToRadian(angle), 2 * f); + bInPolygon = dist <= (r_apothem / cos(ang - f)); + } + } + } + if (bInPolygon) { + if (obj->GetObjectType() == TypeObject::Shot) + ++res; + else { + StgLaserObject* laser = dynamic_cast(obj.get()); + res += floor(laser->GetLength() / laser->GetItemDistance()); + } + + if (typeTo == TO_TYPE_IMMEDIATE) + obj->DeleteImmediate(); + else if (typeTo == TO_TYPE_FADE) + obj->SetFadeDelete(); + else if (typeTo == TO_TYPE_ITEM) + obj->ConvertToItem(); + } + } + + return res; } std::vector StgShotManager::GetShotIdInCircle(int typeOwner, int cx, int cy, int* radius) { @@ -210,6 +276,47 @@ std::vector StgShotManager::GetShotIdInCircle(int typeOwner, int cx, int cy return res; } +std::vector StgShotManager::GetShotIdInRegularPolygon(int typeOwner, int cx, int cy, int* radius, int edges, double angle) { + int r = radius ? *radius : 0; + int rr = r * r; + + int rect_x1 = cx - r; + int rect_y1 = cy - r; + int rect_x2 = cx + r; + int rect_y2 = cy + r; + + std::vector res; + for (ref_unsync_ptr& obj : listObj_) { + if (obj->IsDeleted()) continue; + if ((typeOwner != StgShotObject::OWNER_NULL) && (obj->GetOwnerType() != typeOwner)) continue; + + int sx = obj->GetPositionX(); + int sy = obj->GetPositionY(); + + bool bInPolygon = radius == nullptr; + if (!bInPolygon && ((sx > rect_x1 && sy > rect_y1) && (sx < rect_x2 && sy < rect_y2))) { + float f = GM_PI / (float)edges; + float cf = cosf(f); + float dx = sx - cx; + float dy = sy - cy; + float dist = hypotf(dy, dx); + + bInPolygon = dist <= r; + if (bInPolygon) { + double r_apothem = r * cf; + bInPolygon = dist <= r_apothem; + if (!bInPolygon) { + double ang = fmod(Math::NormalizeAngleRad(atan2(dy, dx)) - Math::DegreeToRadian(angle), 2 * f); + bInPolygon = dist <= (r_apothem / cos(ang - f)); + } + } + } + if (bInPolygon) + res.push_back(obj->GetObjectID()); + } + + return res; +} size_t StgShotManager::GetShotCount(int typeOwner) { size_t res = 0; diff --git a/source/TouhouDanmakufu/Common/StgShot.hpp b/source/TouhouDanmakufu/Common/StgShot.hpp index 333e5fae..d76f2eaa 100644 --- a/source/TouhouDanmakufu/Common/StgShot.hpp +++ b/source/TouhouDanmakufu/Common/StgShot.hpp @@ -93,8 +93,10 @@ class StgShotManager { filterMag_ = mag; } - void DeleteInCircle(int typeDelete, int typeTo, int typeOwner, int cx, int cy, int* radius); + size_t DeleteInCircle(int typeDelete, int typeTo, int typeOwner, int cx, int cy, int* radius); + size_t DeleteInRegularPolygon(int typeDelete, int typeTo, int typeOwner, int cx, int cy, int* radius, int edges, double angle); std::vector GetShotIdInCircle(int typeOwner, int cx, int cy, int* radius); + std::vector GetShotIdInRegularPolygon(int typeOwner, int cx, int cy, int* radius, int edges, double angle); size_t GetShotCount(int typeOwner); size_t GetShotCountAll() { return listObj_.size(); } @@ -537,6 +539,7 @@ class StgLaserObject : public StgShotObject { void SetInvalidLength(float start, float end) { invalidLengthStart_ = start; invalidLengthEnd_ = end; } void SetItemDistance(float dist) { itemDistance_ = std::max(dist, 0.1f); } + float GetItemDistance() { return itemDistance_; } }; //******************************************************************* diff --git a/source/TouhouDanmakufu/Common/StgStageScript.cpp b/source/TouhouDanmakufu/Common/StgStageScript.cpp index c6990443..5b46f4f4 100644 --- a/source/TouhouDanmakufu/Common/StgStageScript.cpp +++ b/source/TouhouDanmakufu/Common/StgStageScript.cpp @@ -310,6 +310,7 @@ static const std::vector stgStageFunction = { //STG共通関数:弾 { "DeleteShotAll", StgStageScript::Func_DeleteShotAll, 2 }, { "DeleteShotInCircle", StgStageScript::Func_DeleteShotInCircle, 5 }, + { "DeleteShotInRegularPolygon", StgStageScript::Func_DeleteShotInRegularPolygon, 7 }, { "CreateShotA1", StgStageScript::Func_CreateShotA1, 6 }, { "CreateShotA2", StgStageScript::Func_CreateShotA2, 8 }, //Deprecated, exists for compatibility { "CreateShotA2", StgStageScript::Func_CreateShotA2, 9 }, @@ -328,6 +329,8 @@ static const std::vector stgStageFunction = { { "GetAllShotID", StgStageScript::Func_GetAllShotID, 1 }, { "GetShotIdInCircleA1", StgStageScript::Func_GetShotIdInCircleA1, 3 }, { "GetShotIdInCircleA2", StgStageScript::Func_GetShotIdInCircleA2, 4 }, + { "GetShotIdInRegularPolygonA1", StgStageScript::Func_GetShotIdInRegularPolygonA1, 5 }, + { "GetShotIdInRegularPolygonA2", StgStageScript::Func_GetShotIdInRegularPolygonA2, 6 }, { "GetShotCount", StgStageScript::Func_GetShotCount, 1 }, { "SetShotAutoDeleteClip", StgStageScript::Func_SetShotAutoDeleteClip, 4 }, { "GetShotDataInfoA1", StgStageScript::Func_GetShotDataInfoA1, 3 }, @@ -347,6 +350,7 @@ static const std::vector stgStageFunction = { { "SetDefaultBonusItemEnable", StgStageScript::Func_SetDefaultBonusItemEnable, 1 }, { "LoadItemData", StgStageScript::Func_LoadItemData, 1 }, { "ReloadItemData", StgStageScript::Func_ReloadItemData, 1 }, + { "GetAllItemID", StgStageScript::Func_GetAllItemID, 0 }, { "GetItemIdInCircleA1", StgStageScript::Func_GetItemIdInCircleA1, 3 }, { "GetItemIdInCircleA2", StgStageScript::Func_GetItemIdInCircleA2, 4 }, { "SetItemAutoDeleteClip", StgStageScript::Func_SetItemAutoDeleteClip, 4 }, @@ -1477,9 +1481,9 @@ gstd::value StgStageScript::Func_DeleteShotAll(gstd::script_machine* machine, in case TYPE_ITEM:typeTo = StgShotManager::TO_TYPE_ITEM; break; } - stageController->GetShotManager()->DeleteInCircle(typeDel, typeTo, StgShotObject::OWNER_ENEMY, 0, 0, nullptr); + size_t res = stageController->GetShotManager()->DeleteInCircle(typeDel, typeTo, StgShotObject::OWNER_ENEMY, 0, 0, nullptr); - return value(); + return script->CreateIntValue(res); } gstd::value StgStageScript::Func_DeleteShotInCircle(gstd::script_machine* machine, int argc, const gstd::value* argv) { StgStageScript* script = (StgStageScript*)machine->data; @@ -1503,9 +1507,37 @@ gstd::value StgStageScript::Func_DeleteShotInCircle(gstd::script_machine* machin case TYPE_ITEM:typeTo = StgShotManager::TO_TYPE_ITEM; break; } - stageController->GetShotManager()->DeleteInCircle(typeDel, typeTo, StgShotObject::OWNER_ENEMY, posX, posY, &radius); + size_t res = stageController->GetShotManager()->DeleteInCircle(typeDel, typeTo, StgShotObject::OWNER_ENEMY, posX, posY, &radius); - return value(); + return script->CreateIntValue(res); +} +gstd::value StgStageScript::Func_DeleteShotInRegularPolygon(gstd::script_machine* machine, int argc, const gstd::value* argv) { + StgStageScript* script = (StgStageScript*)machine->data; + StgStageController* stageController = script->stageController_; + + int typeDel = argv[0].as_int(); + int typeTo = argv[1].as_int(); + int posX = argv[2].as_float(); + int posY = argv[3].as_float(); + int radius = argv[4].as_float(); + int edges = argv[5].as_int(); + double angle = argv[6].as_float(); + + switch (typeDel) { + case TYPE_ALL:typeDel = StgShotManager::DEL_TYPE_ALL; break; + case TYPE_SHOT:typeDel = StgShotManager::DEL_TYPE_SHOT; break; + case TYPE_CHILD:typeDel = StgShotManager::DEL_TYPE_CHILD; break; + } + + switch (typeTo) { + case TYPE_IMMEDIATE:typeTo = StgShotManager::TO_TYPE_IMMEDIATE; break; + case TYPE_FADE:typeTo = StgShotManager::TO_TYPE_FADE; break; + case TYPE_ITEM:typeTo = StgShotManager::TO_TYPE_ITEM; break; + } + + size_t res = stageController->GetShotManager()->DeleteInRegularPolygon(typeDel, typeTo, StgShotObject::OWNER_ENEMY, posX, posY, &radius, edges, angle); + + return script->CreateIntValue(res); } gstd::value StgStageScript::Func_CreateShotA1(gstd::script_machine* machine, int argc, const gstd::value* argv) { StgStageScript* script = (StgStageScript*)machine->data; @@ -2068,6 +2100,43 @@ gstd::value StgStageScript::Func_GetShotIdInCircleA2(gstd::script_machine* machi std::vector listID = shotManager->GetShotIdInCircle(typeOwner, px, py, &radius); return script->CreateIntArrayValue(listID); } +gstd::value StgStageScript::Func_GetShotIdInRegularPolygonA1(gstd::script_machine* machine, int argc, const gstd::value* argv) { + StgStageScript* script = (StgStageScript*)machine->data; + StgStageController* stageController = script->stageController_; + + StgShotManager* shotManager = stageController->GetShotManager(); + int px = argv[0].as_float(); + int py = argv[1].as_float(); + int radius = argv[2].as_float(); + int edges = argv[3].as_int(); + double angle = argv[4].as_float(); + int typeOwner = script->GetScriptType() == TYPE_PLAYER ? StgShotObject::OWNER_PLAYER : StgShotObject::OWNER_ENEMY; + + std::vector listID = shotManager->GetShotIdInRegularPolygon(typeOwner, px, py, &radius, edges, angle); + return script->CreateIntArrayValue(listID); +} +gstd::value StgStageScript::Func_GetShotIdInRegularPolygonA2(gstd::script_machine* machine, int argc, const gstd::value* argv) { + StgStageScript* script = (StgStageScript*)machine->data; + StgStageController* stageController = script->stageController_; + + StgShotManager* shotManager = stageController->GetShotManager(); + int px = argv[0].as_float(); + int py = argv[1].as_float(); + int radius = argv[2].as_float(); + int edges = argv[3].as_int(); + double angle = argv[4].as_float(); + int target = argv[5].as_int(); + + int typeOwner = StgShotObject::OWNER_NULL; + switch (target) { + case TARGET_ALL:typeOwner = StgShotObject::OWNER_NULL; break; + case TARGET_PLAYER:typeOwner = StgShotObject::OWNER_PLAYER; break; + case TARGET_ENEMY:typeOwner = StgShotObject::OWNER_ENEMY; break; + } + + std::vector listID = shotManager->GetShotIdInRegularPolygon(typeOwner, px, py, &radius, edges, angle); + return script->CreateIntArrayValue(listID); +} gstd::value StgStageScript::Func_GetShotCount(gstd::script_machine* machine, int argc, const gstd::value* argv) { StgStageScript* script = (StgStageScript*)machine->data; StgStageController* stageController = script->stageController_; @@ -2422,6 +2491,13 @@ gstd::value StgStageScript::Func_ReloadItemData(gstd::script_machine* machine, i bool res = itemManager->LoadItemData(path, true); return script->CreateBooleanValue(res); } +gstd::value StgStageScript::Func_GetAllItemID(gstd::script_machine* machine, int argc, const gstd::value* argv) { + StgStageScript* script = (StgStageScript*)machine->data; + StgItemManager* itemManager = script->stageController_->GetItemManager(); + + std::vector listID = itemManager->GetItemIdInCircle(0, 0, nullptr, nullptr); + return script->CreateIntArrayValue(listID); +} gstd::value StgStageScript::Func_GetItemIdInCircleA1(gstd::script_machine* machine, int argc, const gstd::value* argv) { StgStageScript* script = (StgStageScript*)machine->data; StgItemManager* itemManager = script->stageController_->GetItemManager(); @@ -2430,7 +2506,7 @@ gstd::value StgStageScript::Func_GetItemIdInCircleA1(gstd::script_machine* machi int py = argv[1].as_float(); int radius = argv[2].as_float(); - std::vector listID = itemManager->GetItemIdInCircle(px, py, radius, nullptr); + std::vector listID = itemManager->GetItemIdInCircle(px, py, &radius, nullptr); return script->CreateIntArrayValue(listID); } gstd::value StgStageScript::Func_GetItemIdInCircleA2(gstd::script_machine* machine, int argc, const gstd::value* argv) { @@ -2442,7 +2518,7 @@ gstd::value StgStageScript::Func_GetItemIdInCircleA2(gstd::script_machine* machi int radius = argv[2].as_float(); int type = argv[3].as_int(); - std::vector listID = itemManager->GetItemIdInCircle(px, py, radius, &type); + std::vector listID = itemManager->GetItemIdInCircle(px, py, &radius, &type); return script->CreateIntArrayValue(listID); } gstd::value StgStageScript::Func_SetItemAutoDeleteClip(gstd::script_machine* machine, int argc, const gstd::value* argv) { diff --git a/source/TouhouDanmakufu/Common/StgStageScript.hpp b/source/TouhouDanmakufu/Common/StgStageScript.hpp index 629085ca..fe07ff96 100644 --- a/source/TouhouDanmakufu/Common/StgStageScript.hpp +++ b/source/TouhouDanmakufu/Common/StgStageScript.hpp @@ -258,6 +258,7 @@ class StgStageScript : public StgControlScript { //STG共通関数:弾 static gstd::value Func_DeleteShotAll(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_DeleteShotInCircle(gstd::script_machine* machine, int argc, const gstd::value* argv); + static gstd::value Func_DeleteShotInRegularPolygon(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_CreateShotA1(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_CreateShotA2(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_CreateShotOA1(gstd::script_machine* machine, int argc, const gstd::value* argv); @@ -275,6 +276,8 @@ class StgStageScript : public StgControlScript { DNH_FUNCAPI_DECL_(Func_GetAllShotID); static gstd::value Func_GetShotIdInCircleA1(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_GetShotIdInCircleA2(gstd::script_machine* machine, int argc, const gstd::value* argv); + static gstd::value Func_GetShotIdInRegularPolygonA1(gstd::script_machine* machine, int argc, const gstd::value* argv); + static gstd::value Func_GetShotIdInRegularPolygonA2(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_GetShotCount(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_SetShotAutoDeleteClip(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_GetShotDataInfoA1(gstd::script_machine* machine, int argc, const gstd::value* argv); @@ -294,6 +297,7 @@ class StgStageScript : public StgControlScript { static gstd::value Func_SetDefaultBonusItemEnable(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_LoadItemData(gstd::script_machine* machine, int argc, const gstd::value* argv); static gstd::value Func_ReloadItemData(gstd::script_machine* machine, int argc, const gstd::value* argv); + DNH_FUNCAPI_DECL_(Func_GetAllItemID); DNH_FUNCAPI_DECL_(Func_GetItemIdInCircleA1); DNH_FUNCAPI_DECL_(Func_GetItemIdInCircleA2); DNH_FUNCAPI_DECL_(Func_SetItemAutoDeleteClip);