summaryrefslogtreecommitdiff
path: root/ZAPD/ZRoom/Commands/SetObjectList.cpp
blob: 935332fd66b32b99e7de3d1db336933f84bf542c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "SetObjectList.h"
#include "../ZRoom.h"
#include "../ObjectList.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"

using namespace std;

SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
	objects = vector<uint16_t>();
	uint8_t objectCnt = rawData[rawDataIndex + 1];
	segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
	uint32_t currentPtr = segmentOffset;

	for (uint8_t i = 0; i < objectCnt; i++)
	{
		uint16_t objectIndex = BitConverter::ToInt16BE(rawData, currentPtr);
		objects.push_back(objectIndex);
		currentPtr += 2;
	}

	if (segmentOffset != 0)
		zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
}

string SetObjectList::GenerateExterns()
{
	return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
}

string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress)
{
	string sourceOutput = "";

	sourceOutput += StringHelper::Sprintf("%s 0x%02X, (u32)%sObjectList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), objects.size(), zRoom->GetName().c_str(), segmentOffset);

	string declaration = "";

	for (size_t i = 0; i < objects.size(); i++)
	{
		uint16_t objectIndex = objects[i];
		declaration += StringHelper::Sprintf("\t%s,", ObjectList[objectIndex].c_str());

		if (i < objects.size() - 1)
			declaration += "\n";
	}

	zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16",
		StringHelper::Sprintf("%sObjectList0x%06X", zRoom->GetName().c_str(), segmentOffset), objects.size(), declaration);

	return sourceOutput;
}

int32_t SetObjectList::GetRawDataSize()
{
	return ZRoomCommand::GetRawDataSize() + (objects.size() * 2);
}

string SetObjectList::GetCommandCName()
{
	return "SCmdObjectList";
}

RoomCommand SetObjectList::GetRoomCommand()
{
	return RoomCommand::SetObjectList;
}