From fcb73347c202aff56fd61a8da20507164cdf506c Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 18 May 2024 23:43:34 +0200 Subject: [PATCH] feat: dump iw4 accuracy graphs --- .../IW4/AssetDumpers/AssetDumperWeapon.cpp | 47 +++++++++++++++++++ .../Game/IW4/AssetDumpers/AssetDumperWeapon.h | 1 + 2 files changed, 48 insertions(+) diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp index c3b1dcc5..41e55a2d 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp @@ -5,6 +5,7 @@ #include "Game/IW4/InfoString/InfoStringFromStructConverter.h" #include "Game/IW4/InfoString/WeaponFields.h" #include "Game/IW4/ObjConstantsIW4.h" +#include "Weapon/AccuracyGraphWriter.h" #include #include @@ -219,6 +220,23 @@ namespace IW4 { } }; + + GenericAccuracyGraph ConvertAccuracyGraph(const char* graphName, const vec2_t* originalKnots, const unsigned originalKnotCount) + { + GenericAccuracyGraph graph; + + graph.name = graphName; + graph.knots.resize(originalKnotCount); + + for (auto i = 0u; i < originalKnotCount; i++) + { + auto& knot = graph.knots[i]; + knot.x = originalKnots[i][0]; + knot.y = originalKnots[i][1]; + } + + return graph; + } } // namespace IW4 void AssetDumperWeapon::CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef) @@ -354,6 +372,33 @@ InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo* as return converter.Convert(); } +void AssetDumperWeapon::DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) +{ + auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); + const auto weapon = asset->Asset(); + const auto* weapDef = weapon->weapDef; + + if (!weapDef) + return; + + if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsAiGraph( + context, + ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount)); + } + + if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsPlayerGraph(context, + ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, + weapDef->originalAiVsPlayerAccuracyGraphKnots, + weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); + } +} + bool AssetDumperWeapon::ShouldDump(XAssetInfo* asset) { return true; @@ -381,4 +426,6 @@ void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset); + static void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset); protected: bool ShouldDump(XAssetInfo* asset) override;