- Introduced new functionality for staging and managing fixed map items, including the ability to build block chains and find candidates for item interactions. - Updated the main application logic to utilize staged item block chains for improved item finding and grabbing mechanics. - Added weight attribute to shape type information, allowing for more nuanced item interactions based on weight. - Enhanced collision tests to cover new item handling scenarios, including gravity sweeps and item grabbing. - Implemented additional tests for entity dispatch entries and fixed map items to ensure robustness of item spawning and movement logic. - Improved type flags loading to validate weight against binary data, ensuring consistency in item attributes.
183 lines
11 KiB
C++
183 lines
11 KiB
C++
#include "remorse/combat_tactics.h"
|
|
#include "remorse/entity_dispatch_entry.h"
|
|
#include "remorse/file_system.h"
|
|
#include "remorse/flex_archive.h"
|
|
#include "remorse/fixed_map.h"
|
|
#include "remorse/glob_archive.h"
|
|
#include "remorse/palette.h"
|
|
#include "remorse/runtime.h"
|
|
#include "remorse/type_flags.h"
|
|
#include "remorse/usecode_archive.h"
|
|
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
remorse::installCrashDiagnostics();
|
|
const std::filesystem::path manifestPath = argc > 1
|
|
? std::filesystem::path(argv[1])
|
|
: remorse::defaultManifestPath(std::filesystem::current_path());
|
|
|
|
const auto manifest = remorse::loadExportManifestSummary(manifestPath);
|
|
if (!manifest) {
|
|
std::cerr << "Could not read export manifest: " << manifestPath.string() << '\n';
|
|
return 2;
|
|
}
|
|
|
|
remorse::printStartupReport(*manifest);
|
|
remorse::ProcessKernel kernel;
|
|
remorse::u16 groupCounts[32]{};
|
|
auto* entry = kernel.createProcess(1, groupCounts);
|
|
std::cout << "Registered process ID: " << (entry ? entry->bytes[0x02] : 0) << '\n';
|
|
for (int index = 0; index < 3; ++index) {
|
|
kernel.createProcess(1, groupCounts);
|
|
}
|
|
kernel.createSystemTimerProcess(1, groupCounts);
|
|
kernel.createKeyboardProcess(1, groupCounts);
|
|
kernel.createKeyDaemonProcess(1, groupCounts);
|
|
kernel.terminateProcess(3, groupCounts);
|
|
kernel.clearTerminatedProcesses();
|
|
auto* reused = kernel.createStandProcess(1, 1, groupCounts);
|
|
std::cout << "Reused Stand process ID: " << (reused ? reused->base.bytes[0x02] : 0) << '\n';
|
|
remorse::NpcBehaviorServices npcServices{
|
|
[](remorse::u16, void*) { return false; },
|
|
[](remorse::u16, void*) -> remorse::u16 { return 0; },
|
|
[](remorse::u16, remorse::u16, void*) { return false; },
|
|
[](remorse::u16, void*) { return false; },
|
|
[](remorse::u16, remorse::u16, void*) {},
|
|
nullptr
|
|
};
|
|
struct ScanContext {
|
|
remorse::StandProcessEntry* standing;
|
|
remorse::NpcBehaviorServices* npcServices;
|
|
remorse::u32 timerTick;
|
|
int hostCallbacks = 0;
|
|
} scanContext{reused, &npcServices, 0};
|
|
for (int tick = 0; tick < 100; ++tick) {
|
|
kernel.deliverSystemTimerEvent();
|
|
}
|
|
scanContext.timerTick = kernel.systemTimerTick();
|
|
const remorse::u32 schedulerElapsed = kernel.runTimedSchedulerPass(1, [](remorse::EntityDispatchEntryBase& process, void* context) {
|
|
auto& scan = *static_cast<ScanContext*>(context);
|
|
if (process.bytes[0] == 0x0f && process.bytes[1] == 0x1f) {
|
|
remorse::StandProcess::run(*scan.standing, *scan.npcServices, scan.timerTick);
|
|
} else {
|
|
++scan.hostCallbacks;
|
|
}
|
|
}, &scanContext);
|
|
kernel.refreshActiveGroup(groupCounts);
|
|
remorse::EntityDispatchEntry::incrementGroupId(*entry, kernel, groupCounts);
|
|
std::cout << "Advanced process group: " << static_cast<int>(kernel.activeGroup()) << '\n';
|
|
std::cout << "Scheduler scan host callbacks: " << scanContext.hostCallbacks << '\n';
|
|
std::cout << "Scheduler pass elapsed ticks: " << schedulerElapsed << '\n';
|
|
std::cout << "StandProcess Run sleep ticks: " << static_cast<int>(reused->base.bytes[0x0e]) << '\n';
|
|
|
|
const auto gameDataRoot = remorse::findGameDataRoot(std::filesystem::current_path());
|
|
std::cout << "Game data root: " << (gameDataRoot ? gameDataRoot->path.string() : "not found") << '\n';
|
|
if (gameDataRoot) {
|
|
std::optional<remorse::StagedFixedMapItem> firstStagedItem;
|
|
std::optional<remorse::StagedItemBlockChains> stagedBlockChains;
|
|
std::optional<std::vector<remorse::StagedFixedMapItem>> stagedMapItems;
|
|
const auto palettePath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "GAMEPAL.PAL");
|
|
const auto paletteBytes = palettePath ? remorse::readBinaryFile(*palettePath) : std::nullopt;
|
|
std::cout << "GAMEPAL.PAL bytes: " << (paletteBytes ? paletteBytes->size() : 0) << '\n';
|
|
const auto palette = palettePath ? remorse::loadPalette256(*palettePath) : std::nullopt;
|
|
std::cout << "GAMEPAL.PAL colors: " << (palette ? palette->colors.size() : 0) << '\n';
|
|
|
|
const auto combatPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "COMBAT.DAT");
|
|
const auto combatArchive = combatPath ? remorse::loadFlexArchive(*combatPath) : std::nullopt;
|
|
std::cout << "COMBAT.DAT populated entries: " << (combatArchive ? combatArchive->populatedEntries.size() : 0) << '\n';
|
|
const auto combatTactics = combatPath ? remorse::loadCombatTactics(*combatPath) : std::nullopt;
|
|
std::cout << "COMBAT.DAT tactics: " << (combatTactics ? combatTactics->size() : 0) << '\n';
|
|
|
|
const auto fixedPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "FIXED.DAT");
|
|
const auto fixedArchive = fixedPath ? remorse::loadFixedMapArchive(*fixedPath) : std::nullopt;
|
|
std::cout << "FIXED.DAT maps: " << (fixedArchive ? fixedArchive->mapCount : 0) << '\n';
|
|
if (fixedArchive) {
|
|
for (remorse::u32 index = 0; index < fixedArchive->mapCount; ++index) {
|
|
const auto map = remorse::loadFixedMap(*fixedArchive, index);
|
|
if (map && !map->entries.empty()) {
|
|
std::cout << "FIXED.DAT first non-empty map: " << index << '\n';
|
|
std::cout << "FIXED.DAT first non-empty entries: " << map->entries.size() << '\n';
|
|
const auto items = remorse::stageFixedMapItems(*map);
|
|
if (items && !items->empty()) {
|
|
firstStagedItem = items->front();
|
|
stagedBlockChains = remorse::buildStagedItemBlockChains(*items);
|
|
stagedMapItems = *items;
|
|
struct ItemScanContext {
|
|
remorse::ProcessKernel* kernel;
|
|
remorse::u16 (*groups)[32];
|
|
remorse::u16 releaseEventItem = 0;
|
|
} itemScan{&kernel, &groupCounts};
|
|
auto* itemProcess = kernel.createItemProcess(kernel.activeGroup(), items->front().itemNumber, groupCounts);
|
|
const remorse::u16 itemProcessId = static_cast<remorse::u16>(
|
|
itemProcess->bytes[2] | (static_cast<remorse::u16>(itemProcess->bytes[3]) << 8));
|
|
kernel.scanRunnableProcesses(kernel.activeGroup(), [](remorse::EntityDispatchEntryBase& process, void* context) {
|
|
auto& scan = *static_cast<ItemScanContext*>(context);
|
|
if (process.bytes[0] == 0x2f && process.bytes[1] == 0x10) {
|
|
remorse::ItemProcess::run(process, *scan.kernel, *scan.groups,
|
|
[](remorse::u16 itemNumber, remorse::u32 eventMask, remorse::u16 eventId, void* releaseContext) {
|
|
if (eventMask == 0x200 && eventId == 9) {
|
|
static_cast<ItemScanContext*>(releaseContext)->releaseEventItem = itemNumber;
|
|
}
|
|
}, &scan);
|
|
}
|
|
}, &itemScan, kernel.systemTimerTick());
|
|
kernel.refreshActiveGroup(groupCounts);
|
|
std::cout << "Staged retail item shape: " << items->front().data.shape << '\n';
|
|
std::cout << "ItemProcess release event boundary item: " << itemScan.releaseEventItem << '\n';
|
|
std::cout << "ItemProcess terminated: " << (kernel.processAt(itemProcessId) == nullptr) << '\n';
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
const auto globPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "GLOB.FLX");
|
|
const auto globObjects = globPath ? remorse::loadGlobObjects(*globPath) : std::nullopt;
|
|
std::cout << "GLOB.FLX objects: " << (globObjects ? globObjects->size() : 0) << '\n';
|
|
|
|
const auto typeFlagPath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "TYPEFLAG.DAT");
|
|
const auto typeFlags = typeFlagPath ? remorse::loadTypeFlags(*typeFlagPath) : std::nullopt;
|
|
std::cout << "TYPEFLAG.DAT shapes: " << (typeFlags ? typeFlags->size() : 0) << '\n';
|
|
if (firstStagedItem && typeFlags && firstStagedItem->data.shape < typeFlags->size()) {
|
|
const auto area = remorse::itemFindAreaAroundItem(
|
|
*firstStagedItem, (*typeFlags)[firstStagedItem->data.shape]);
|
|
std::cout << "Staged item ItemFind blocks: " << remorse::itemFindBlockOrder(area).size() << '\n';
|
|
if (stagedBlockChains) {
|
|
std::cout << "Staged item ItemFind candidates: " <<
|
|
remorse::itemFindCandidateOrder(area, *stagedBlockChains).size() << '\n';
|
|
}
|
|
if (stagedMapItems) {
|
|
const auto matches = remorse::itemFindZMatches(*firstStagedItem, *stagedMapItems, *typeFlags, 3);
|
|
std::cout << "Staged item ItemFind Z matches (script-free): " <<
|
|
(matches ? matches->size() : 0) << '\n';
|
|
const auto grabCandidates = remorse::itemGrabSearchCandidates(
|
|
*firstStagedItem, *stagedMapItems, *typeFlags);
|
|
const auto grabActions = remorse::planItemGrabActions(
|
|
*firstStagedItem, *stagedMapItems, *typeFlags);
|
|
std::cout << "Staged item Item_Grab candidates: " <<
|
|
(grabCandidates ? grabCandidates->size() : 0) << '\n';
|
|
std::cout << "Staged item Item_Grab planned actions: " <<
|
|
(grabActions ? grabActions->size() : 0) << '\n';
|
|
}
|
|
}
|
|
|
|
const auto usecodePath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("USECODE") / "EUSECODE.FLX");
|
|
const auto usecodeArchive = usecodePath ? remorse::loadFlexArchive(*usecodePath) : std::nullopt;
|
|
const auto eventClass = usecodeArchive ? remorse::loadUsecodeClass(*usecodeArchive, 0x361) : std::nullopt;
|
|
const auto eventBody = eventClass ? remorse::readUsecodeEventBody(*eventClass, 0x0a) : std::nullopt;
|
|
std::cout << "EUSECODE EVENT slot 0x0a body bytes: " << (eventBody ? eventBody->bytes.size() : 0) << '\n';
|
|
if (firstStagedItem && typeFlags && usecodeArchive && firstStagedItem->data.shape < typeFlags->size()) {
|
|
const auto& item = *firstStagedItem;
|
|
const remorse::UsecodeItemIdentity identity{item.itemNumber, item.data.shape,
|
|
item.data.flags, item.data.quality, (*typeFlags)[item.data.shape].family, false};
|
|
const remorse::UsecodeClassBases bases{0, 0x800, 0x900};
|
|
const auto itemClass = remorse::loadUsecodeClass(*usecodeArchive,
|
|
remorse::selectUsecodeClassId(identity, bases));
|
|
std::cout << "Staged item USECODE class: " << (itemClass ? itemClass->name : "not present") << '\n';
|
|
}
|
|
}
|
|
return 0;
|
|
}
|