Skip to content

Commit 2bb1d53

Browse files
authored
custom levels: cell-info and buzzer-info lumps (#3324)
Adds two new lump types: `cell-info` and `buzzer-info`. `cell-info` takes a `game-task` enum value and defines an `eco-info` lump for power cells. `buzzer-info` takes a `game-task` enum value and an integer and automatically calculates the required value for the buzzer task with the formula `task + buzzer * (1 << 16)`.
1 parent 076f8aa commit 2bb1d53

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

custom_levels/jak1/test-zone/test-zone.jsonc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
"double_sided_collide": false,
2222

2323
// available res-lump tag types:
24-
// value types: int32, uint32, enum-int32, enum-uint32, float, meters (1 meter = 4096.0 units), degrees (65536.0 = 360°)
24+
// integer types: int32, uint32, enum-int32, enum-uint32
25+
// float types: float, meters (1 meter = 4096.0 units), degrees (65536.0 = 360°)
2526
// vector types: vector (normal floats), vector4m (meters), vector3m (meters with w set to 1.0), vector-vol (normal floats with w in meters), movie-pos (meters with w in degrees)
26-
// special types: eco-info, water-height
27+
// special types: eco-info, cell-info, buzzer-info, water-height
2728
//
2829
// examples:
2930
//
@@ -44,6 +45,12 @@
4445
//
4546
// adds an eco-info tag:
4647
// "eco-info": ["eco-info", "(pickup-type health)", 2]
48+
//
49+
// adds a cell-info tag:
50+
// "eco-info": ["cell-info", "(game-task training-gimmie)"]
51+
//
52+
// adds a buzzer-info tag:
53+
// "eco-info": ["buzzer-info", "(game-task training-buzzer)", 5]
4754

4855
// The base actor id for your custom level. If you have multiple levels this should be unique!
4956
"base_id": 100,
@@ -93,7 +100,8 @@
93100
"quat": [0, 0, 0, 1], // quaternion
94101
"bsphere": [-21.6238, 19.3496, 17.1191, 10], // bounding sphere
95102
"lump": {
96-
"name": "test-fuel-cell"
103+
"name": "test-fuel-cell",
104+
"eco-info": ["cell-info", "(game-task none)"]
97105
}
98106
},
99107

goalc/build_level/common/Entity.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ u64 get_enum_val(const std::string& val, decompiler::DecompilerTypeSystem& dts)
8484
return parse_enum(enum_def, rest);
8585
}
8686

87+
u64 get_enum_or_int(const nlohmann::json& value, decompiler::DecompilerTypeSystem& dts) {
88+
if (value.is_string()) {
89+
return get_enum_val(value.get<std::string>(), dts);
90+
} else {
91+
ASSERT(value.is_number());
92+
return value.get<int>();
93+
}
94+
}
8795
template <typename T>
8896
std::vector<T> enum_from_json(const nlohmann::json& json, decompiler::DecompilerTypeSystem& dts) {
8997
std::vector<T> result;
@@ -98,6 +106,7 @@ static std::unordered_map<std::string,
98106
const nlohmann::json&,
99107
decompiler::DecompilerTypeSystem&)>>
100108
lump_map = {
109+
// integers
101110
{"int32",
102111
[](const std::string& name,
103112
const nlohmann::json& json,
@@ -140,6 +149,7 @@ static std::unordered_map<std::string,
140149
}
141150
return std::make_unique<ResUint32>(name, data, -1000000000.0000);
142151
}},
152+
// special lumps
143153
{"eco-info",
144154
[](const std::string& name,
145155
const nlohmann::json& json,
@@ -148,7 +158,29 @@ static std::unordered_map<std::string,
148158
// pickup-type
149159
data.push_back(static_cast<s32>(get_enum_val(json[1].get<std::string>(), dts)));
150160
// amount
151-
data.push_back(json[2].get<int>());
161+
data.push_back(static_cast<s32>(get_enum_or_int(json[2], dts)));
162+
return std::make_unique<ResInt32>(name, data, -1000000000.0000);
163+
}},
164+
{"cell-info",
165+
[](const std::string& name,
166+
const nlohmann::json& json,
167+
decompiler::DecompilerTypeSystem& dts) {
168+
std::vector<s32> data;
169+
// (pickup-type fuel-cell)
170+
data.push_back(6);
171+
data.push_back(static_cast<s32>(get_enum_or_int(json[1], dts)));
172+
return std::make_unique<ResInt32>(name, data, -1000000000.0000);
173+
}},
174+
{"buzzer-info",
175+
[](const std::string& name,
176+
const nlohmann::json& json,
177+
decompiler::DecompilerTypeSystem& dts) {
178+
std::vector<s32> data;
179+
// (pickup-type buzzer)
180+
data.push_back(8);
181+
auto task = static_cast<s32>(get_enum_val(json[1].get<std::string>(), dts));
182+
auto buzzer = json[2].get<int>();
183+
data.push_back(task + (buzzer * (1 << 16)));
152184
return std::make_unique<ResInt32>(name, data, -1000000000.0000);
153185
}},
154186
{"water-height",
@@ -170,6 +202,7 @@ static std::unordered_map<std::string,
170202
}
171203
return std::make_unique<ResFloat>(name, data, -1000000000.0000);
172204
}},
205+
// vectors
173206
{"vector",
174207
[](const std::string& name,
175208
const nlohmann::json& json,
@@ -225,6 +258,7 @@ static std::unordered_map<std::string,
225258
}
226259
return std::make_unique<ResVector>(name, data, -1000000000.0000);
227260
}},
261+
// floats
228262
{"float",
229263
[](const std::string& name,
230264
const nlohmann::json& json,

0 commit comments

Comments
 (0)