- Enhanced isometric_controls_tests.cpp to include assertions for controller fire attempt suppression under various conditions. - Added tests for the Usecode interpreter in usecode_vm_tests.cpp, verifying script execution and stack manipulation. - Introduced a new PowerShell script, clean-old-build-artifacts.ps1, to facilitate the cleanup of old build artifacts in specified directories.
176 lines
6.8 KiB
C++
176 lines
6.8 KiB
C++
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <vector>
|
|
|
|
#include "remorse/compat.h"
|
|
|
|
namespace remorse {
|
|
|
|
struct ShapeTypeInfo;
|
|
struct WorldRect;
|
|
struct GlobObject;
|
|
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;
|
|
FixedMapEntry data;
|
|
};
|
|
|
|
constexpr u16 liveItemEtherealFlag = 0x0800;
|
|
|
|
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<StagedFixedMapItem> findTeleportEgg(
|
|
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes, u8 eggId);
|
|
std::optional<StagedFixedMapItem> findNearbyActiveTeleportEgg(const StagedFixedMapItem& origin,
|
|
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes,
|
|
u8 currentMapNumber);
|
|
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);
|
|
|
|
struct NpcAnimationState {
|
|
u16 lastAnimation = 0xffff;
|
|
u8 frame = 0;
|
|
u8 moreFlags = 0;
|
|
u8 direction = 0;
|
|
};
|
|
|
|
class LiveFixedMapItems {
|
|
public:
|
|
explicit LiveFixedMapItems(std::vector<StagedFixedMapItem> items,
|
|
std::vector<StagedContainedFixedMapItem> containedItems = {});
|
|
bool initializeAvatar();
|
|
bool teleportAvatar(const StagedFixedMapItem& egg, u8 mapNumber);
|
|
const StagedFixedMapItem* findItem(u16 itemNumber) const;
|
|
const std::vector<StagedFixedMapItem>& mapItems() const noexcept { return items_; }
|
|
const NpcAnimationState* findNpcAnimation(u16 itemNumber) const;
|
|
NpcAnimationState* editNpcAnimation(u16 itemNumber);
|
|
u16 containedParent(u16 itemNumber) const;
|
|
std::vector<u16> containedChildren(u16 parentItemNumber) const;
|
|
std::optional<StagedFixedMapItem> nearestItem(s32 worldX, s32 worldY, s32 maxDistance) const;
|
|
std::optional<std::vector<u16>> sweepCandidateIds(const WorldRect& area, u16 excludedItemNumber) const;
|
|
std::optional<u16> allocateItem(StagedFixedMapItem item);
|
|
bool insertItem(StagedFixedMapItem item);
|
|
bool pushItemToEtherealVoid(u16 itemNumber);
|
|
std::optional<u16> popItemFromEtherealVoid();
|
|
std::optional<u16> popItemToCoords(u16 x, u16 y, u8 z);
|
|
bool destroyItem(u16 itemNumber);
|
|
bool canCreateItemAt(u16 shape, u16 x, u16 y, u8 z,
|
|
const std::vector<ShapeTypeInfo>& shapes) const;
|
|
bool moveItemIntoContainer(u16 itemNumber, u16 containerItemNumber,
|
|
const std::vector<ShapeTypeInfo>& shapes);
|
|
bool moveContainedItemToWorld(u16 itemNumber, u16 x, u16 y, u8 z);
|
|
bool releaseItem(u16 itemNumber, const ProcessKernel& kernel);
|
|
std::optional<std::vector<u16>> hatchGlobEgg(u16 eggItemNumber, const GlobObject& glob,
|
|
const std::vector<ShapeTypeInfo>& shapes);
|
|
bool isGlobHatched(u16 eggItemNumber) const;
|
|
bool setItemShape(u16 itemNumber, u16 shape);
|
|
bool setItemFrame(u16 itemNumber, u8 frame);
|
|
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:
|
|
bool unlinkContainedItem(u16 itemNumber);
|
|
void refreshContainerQuality(u16 parentItemNumber);
|
|
bool insertContainedItemAtHead(u16 parentItemNumber, u16 itemNumber);
|
|
std::vector<StagedFixedMapItem> items_;
|
|
std::optional<StagedFixedMapItem> avatar_;
|
|
std::vector<NpcAnimationState> npcAnimations_;
|
|
std::vector<bool> allocatedIds_;
|
|
std::vector<bool> destroyedIds_;
|
|
std::vector<bool> hatchedGlobIds_;
|
|
std::vector<u16> parentById_;
|
|
std::vector<std::optional<FixedMapEntry>> containedItemData_;
|
|
std::vector<u16> containedNextById_;
|
|
std::vector<u16> containedHeadById_;
|
|
std::vector<u16> containedTailById_;
|
|
std::vector<u16> freeItemIds_;
|
|
std::vector<u16> etherealStack_;
|
|
u16 nextFreeItemNumber_ = 0x100;
|
|
};
|
|
|
|
} // namespace remorse
|