Crusader_Decomp/rebuild/remorse/include/remorse/fixed_map.h

118 lines
4.1 KiB
C
Raw Normal View History

#pragma once
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct ShapeTypeInfo;
class ProcessKernel;
struct FixedMapEntry {
u16 x = 0;
u16 y = 0;
u8 z = 0;
u16 shape = 0;
u8 frame = 0;
u16 flags = 0;
u16 quality = 0;
u8 npcNumber = 0;
u8 mapNumber = 0;
u16 next = 0;
};
struct FixedMap {
u32 index = 0;
std::vector<FixedMapEntry> entries;
};
struct StagedFixedMapItem {
u16 itemNumber = 0;
std::size_t recordIndex = 0;
FixedMapEntry data;
};
struct StagedContainedFixedMapItem {
u16 itemNumber = 0;
u16 parentItemNumber = 0;
std::size_t recordIndex = 0;
};
struct ItemFindArea {
u16 minX = 0;
u16 minY = 0;
u16 maxX = 0;
u16 maxY = 0;
};
struct StagedItemBlockChains {
std::vector<u16> heads;
std::vector<u16> next;
};
struct ItemFindZCandidate {
u16 itemNumber = 0;
u8 matchType = 0;
};
enum class ItemGrabActionKind {
Hurl,
CreateProcess
};
struct ItemGrabAction {
u16 itemNumber = 0;
ItemGrabActionKind kind = ItemGrabActionKind::Hurl;
};
struct FixedMapArchive {
u32 mapCount = 0;
std::vector<u8> bytes;
};
std::optional<FixedMapArchive> loadFixedMapArchive(const std::filesystem::path& path);
std::optional<FixedMap> loadFixedMap(const FixedMapArchive& archive, u32 mapIndex);
std::optional<std::vector<StagedFixedMapItem>> stageFixedMapItems(const FixedMap& map);
std::optional<std::vector<StagedContainedFixedMapItem>> stageContainedFixedMapItems(
const FixedMap& map, const std::vector<ShapeTypeInfo>& shapes);
std::optional<StagedFixedMapItem> nearestStagedFixedMapItem(
const std::vector<StagedFixedMapItem>& items, s32 worldX, s32 worldY, s32 maxDistance);
bool itemGrabCanCreateProcess(const StagedFixedMapItem& item);
bool itemFallStartsHurl(const ShapeTypeInfo& shape);
u8 classifyItemFindZMatch(const StagedFixedMapItem& origin, const ShapeTypeInfo& originShape,
const StagedFixedMapItem& candidate, const ShapeTypeInfo& candidateShape, u8 zMatchFlags);
ItemFindArea itemFindAreaAroundItem(const StagedFixedMapItem& origin, const ShapeTypeInfo& originShape);
std::vector<u16> itemFindBlockOrder(const ItemFindArea& area);
std::optional<StagedItemBlockChains> buildStagedItemBlockChains(const std::vector<StagedFixedMapItem>& items);
std::vector<u16> itemFindCandidateOrder(const ItemFindArea& area, const StagedItemBlockChains& chains);
std::optional<std::vector<ItemFindZCandidate>> itemFindZMatches(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes, u8 zMatchFlags);
std::optional<std::vector<ItemFindZCandidate>> itemGrabSearchCandidates(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes);
std::optional<std::vector<ItemGrabAction>> planItemGrabActions(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes);
std::optional<std::vector<u16>> dispatchStagedItemGrab(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes,
ProcessKernel& kernel, u16 (&groupCounts)[32], u32 timerTick);
class LiveFixedMapItems {
public:
explicit LiveFixedMapItems(std::vector<StagedFixedMapItem> items);
const StagedFixedMapItem* findItem(u16 itemNumber) const;
std::optional<StagedFixedMapItem> nearestItem(s32 worldX, s32 worldY, s32 maxDistance) const;
bool insertItem(StagedFixedMapItem item);
bool moveItem(u16 itemNumber, u16 x, u16 y, u8 z);
std::optional<std::vector<u16>> grabItem(u16 itemNumber, const std::vector<ShapeTypeInfo>& shapes,
ProcessKernel& kernel, u16 (&groupCounts)[32], u32 timerTick) const;
std::optional<std::vector<u16>> moveApprovedItem(u16 itemNumber, u16 x, u16 y, u8 z,
const std::vector<ShapeTypeInfo>& shapes, ProcessKernel& kernel,
u16 (&groupCounts)[32], u32 timerTick);
private:
std::vector<StagedFixedMapItem> items_;
};
} // namespace remorse