| 1 | #include "Library/Placement/PlacementFunction.h" |
| 2 | |
| 3 | #include "Library/Area/AreaInitInfo.h" |
| 4 | #include "Library/Base/StringUtil.h" |
| 5 | #include "Library/LiveActor/ActorInitInfo.h" |
| 6 | #include "Library/Math/Axis.h" |
| 7 | #include "Library/Math/MathUtil.h" |
| 8 | #include "Library/Placement/PlacementId.h" |
| 9 | #include "Library/Placement/PlacementInfo.h" |
| 10 | #include "Library/Yaml/ByamlIter.h" |
| 11 | #include "Library/Yaml/ByamlUtil.h" |
| 12 | |
| 13 | namespace al { |
| 14 | |
| 15 | bool isValidInfo(const PlacementInfo& placementInfo) { |
| 16 | return placementInfo.getPlacementIter().isValid(); |
| 17 | } |
| 18 | |
| 19 | bool isPlaced(const ActorInitInfo& initInfo) { |
| 20 | return isValidInfo(placementInfo: *initInfo.placementInfo); |
| 21 | } |
| 22 | |
| 23 | void getObjectName(const char** name, const ActorInitInfo& initInfo) { |
| 24 | getObjectName(name, placementInfo: *initInfo.placementInfo); |
| 25 | } |
| 26 | |
| 27 | void getObjectName(const char** name, const PlacementInfo& placementInfo) { |
| 28 | tryGetObjectName(name, placementInfo); |
| 29 | } |
| 30 | |
| 31 | bool tryGetObjectName(const char** name, const ActorInitInfo& initInfo) { |
| 32 | return tryGetObjectName(name, placementInfo: *initInfo.placementInfo); |
| 33 | } |
| 34 | |
| 35 | bool tryGetObjectName(const char** name, const PlacementInfo& placementInfo) { |
| 36 | const char* obj = "" ; |
| 37 | if (tryGetStringArg(arg: &obj, initInfo: placementInfo, key: "UnitConfigName" )) { |
| 38 | *name = obj; |
| 39 | return true; |
| 40 | } |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | bool isObjectName(const ActorInitInfo& initInfo, const char* name) { |
| 45 | return isObjectName(placementInfo: *initInfo.placementInfo, name); |
| 46 | } |
| 47 | |
| 48 | bool isObjectName(const PlacementInfo& placementInfo, const char* name) { |
| 49 | const char* obj; |
| 50 | return tryGetObjectName(name: &obj, placementInfo) && isEqualString(str1: obj, str2: name); |
| 51 | } |
| 52 | |
| 53 | bool isObjectNameSubStr(const ActorInitInfo& initInfo, const char* name) { |
| 54 | return isObjectNameSubStr(placementInfo: *initInfo.placementInfo, name); |
| 55 | } |
| 56 | |
| 57 | bool isObjectNameSubStr(const PlacementInfo& placementInfo, const char* name) { |
| 58 | const char* obj; |
| 59 | return tryGetObjectName(name: &obj, placementInfo) && isEqualSubString(str: obj, subStr: name); |
| 60 | } |
| 61 | |
| 62 | void getClassName(const char** name, const ActorInitInfo& initInfo) { |
| 63 | getClassName(name, placementInfo: *initInfo.placementInfo); |
| 64 | } |
| 65 | |
| 66 | void getClassName(const char** name, const PlacementInfo& placementInfo) { |
| 67 | tryGetClassName(name, placementInfo); |
| 68 | } |
| 69 | |
| 70 | bool tryGetClassName(const char** name, const ActorInitInfo& initInfo) { |
| 71 | return tryGetClassName(name, placementInfo: *initInfo.placementInfo); |
| 72 | } |
| 73 | |
| 74 | bool tryGetClassName(const char** name, const PlacementInfo& placementInfo) { |
| 75 | PlacementInfo unitConfig; |
| 76 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &unitConfig, placementInfo, key: "UnitConfig" )) |
| 77 | return false; |
| 78 | return tryGetStringArg(arg: name, initInfo: unitConfig, key: "ParameterConfigName" ); |
| 79 | } |
| 80 | |
| 81 | bool isClassName(const ActorInitInfo& initInfo, const char* name) { |
| 82 | return isClassName(placementInfo: *initInfo.placementInfo, name); |
| 83 | } |
| 84 | |
| 85 | bool isClassName(const PlacementInfo& placementInfo, const char* name) { |
| 86 | const char* className = nullptr; |
| 87 | return tryGetClassName(name: &className, placementInfo) && isEqualString(str1: className, str2: name); |
| 88 | } |
| 89 | |
| 90 | void getDisplayName(const char** name, const ActorInitInfo& initInfo) { |
| 91 | getDisplayName(name, placementInfo: *initInfo.placementInfo); |
| 92 | } |
| 93 | |
| 94 | void getDisplayName(const char** name, const PlacementInfo& placementInfo) { |
| 95 | tryGetDisplayName(name, placementInfo); |
| 96 | } |
| 97 | |
| 98 | bool tryGetDisplayName(const char** name, const ActorInitInfo& initInfo) { |
| 99 | return tryGetDisplayName(name, placementInfo: *initInfo.placementInfo); |
| 100 | } |
| 101 | |
| 102 | bool tryGetDisplayName(const char** name, const PlacementInfo& placementInfo) { |
| 103 | PlacementInfo unitConfig; |
| 104 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &unitConfig, placementInfo, key: "UnitConfig" )) |
| 105 | return false; |
| 106 | return tryGetStringArg(arg: name, initInfo: unitConfig, key: "DisplayName" ); |
| 107 | } |
| 108 | |
| 109 | void getPlacementTargetFile(const char** targetFile, const PlacementInfo& placementInfo) { |
| 110 | PlacementInfo unitConfig; |
| 111 | getPlacementInfoByKey(outPlacementInfo: &unitConfig, placementInfo, key: "UnitConfig" ); |
| 112 | tryGetStringArg(arg: targetFile, initInfo: unitConfig, key: "PlacementTargetFile" ); |
| 113 | } |
| 114 | |
| 115 | void getTrans(sead::Vector3f* trans, const ActorInitInfo& initInfo) { |
| 116 | getTrans(trans, placementInfo: *initInfo.placementInfo); |
| 117 | } |
| 118 | |
| 119 | void getTrans(sead::Vector3f* trans, const PlacementInfo& placementInfo) { |
| 120 | tryGetTrans(trans, placementInfo); |
| 121 | } |
| 122 | |
| 123 | void multZoneMtx(sead::Vector3f* trans, const PlacementInfo& placementInfo) { |
| 124 | sead::Matrix34f mtx; |
| 125 | if (tryGetZoneMatrixTR(matrix: &mtx, placementInfo)) |
| 126 | trans->mul(m: mtx); |
| 127 | } |
| 128 | |
| 129 | bool tryGetTrans(sead::Vector3f* trans, const ActorInitInfo& initInfo) { |
| 130 | return tryGetTrans(trans, placementInfo: *initInfo.placementInfo); |
| 131 | } |
| 132 | |
| 133 | bool tryGetTrans(sead::Vector3f* trans, const PlacementInfo& placementInfo) { |
| 134 | if (!tryGetArgV3f(arg: trans, placementInfo, key: "Translate" )) |
| 135 | return false; |
| 136 | multZoneMtx(trans, placementInfo); |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | void getRotate(sead::Vector3f* rotate, const PlacementInfo& placementInfo) { |
| 141 | tryGetRotate(rotate, placementInfo); |
| 142 | } |
| 143 | |
| 144 | bool tryGetRotate(sead::Vector3f* rotate, const ActorInitInfo& initInfo) { |
| 145 | return tryGetRotate(rotate, placementInfo: *initInfo.placementInfo); |
| 146 | } |
| 147 | |
| 148 | template <typename T> |
| 149 | inline void getRotation(sead::Vector3f* v, const sead::Matrix34f& n) { |
| 150 | T abs = sead::MathCalcCommon<T>::abs(n.m[2][0]); |
| 151 | |
| 152 | // making sure pitch stays within bounds, setting roll to 0 otherwise |
| 153 | if ((1.0f - abs) < sead::MathCalcCommon<T>::epsilon() * 10) { |
| 154 | const T a12 = n.m[0][1]; |
| 155 | const T a13 = n.m[0][2]; |
| 156 | const T a31 = n.m[2][0]; |
| 157 | |
| 158 | v->x = 0.0f; |
| 159 | v->y = (a31 / abs) * (-sead::numbers::pi_v<T> / 2); |
| 160 | v->z = std::atan2(-a12, -(a31 * a13)); |
| 161 | } else { |
| 162 | const T a11 = n.m[0][0]; |
| 163 | const T a21 = n.m[1][0]; |
| 164 | const T a31 = n.m[2][0]; |
| 165 | const T a32 = n.m[2][1]; |
| 166 | const T a33 = n.m[2][2]; |
| 167 | |
| 168 | v->x = std::atan2(a32, a33); |
| 169 | v->y = std::asin(-a31); |
| 170 | v->z = std::atan2(a21, a11); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | bool tryGetRotate(sead::Vector3f* rotate, const PlacementInfo& placementInfo) { |
| 175 | if (!tryGetArgV3f(arg: rotate, placementInfo, key: "Rotate" )) |
| 176 | return false; |
| 177 | |
| 178 | sead::Matrix34f mtx; |
| 179 | if (tryGetZoneMatrixTR(matrix: &mtx, placementInfo)) { |
| 180 | sead::Matrix34f rot, rot2; |
| 181 | sead::Vector3f vec1 = {sead::Mathf::deg2rad(deg: rotate->x), sead::Mathf::deg2rad(deg: rotate->y), |
| 182 | sead::Mathf::deg2rad(deg: rotate->z)}; |
| 183 | rot.makeRT(r: vec1, t: sead::Vector3f::zero); |
| 184 | rot2 = mtx * rot; |
| 185 | |
| 186 | getRotation<f32>(v: rotate, n: rot2); |
| 187 | rotate->set(x_: sead::Mathf::rad2deg(rad: rotate->x), y_: sead::Mathf::rad2deg(rad: rotate->y), |
| 188 | z_: sead::Mathf::rad2deg(rad: rotate->z)); |
| 189 | } |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | bool tryGetZoneMatrixTR(sead::Matrix34f* matrix, const PlacementInfo& placementInfo) { |
| 194 | ByamlIter zone = placementInfo.getZoneIter(); |
| 195 | if (!zone.isValid()) |
| 196 | return false; |
| 197 | |
| 198 | sead::Vector3f translate = sead::Vector3f::zero; |
| 199 | if (!tryGetByamlV3f(&translate, zone, "Translate" )) |
| 200 | return false; |
| 201 | |
| 202 | sead::Vector3f rotate = sead::Vector3f::zero; |
| 203 | if (!tryGetByamlV3f(&rotate, zone, "Rotate" )) |
| 204 | return false; |
| 205 | |
| 206 | matrix->makeRT(r: {sead::Mathf::rad2deg(rad: rotate.x), sead::Mathf::rad2deg(rad: rotate.y), |
| 207 | sead::Mathf::rad2deg(rad: rotate.z)}, |
| 208 | t: translate); |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | void getQuat(sead::Quatf* quat, const ActorInitInfo& initInfo) { |
| 213 | tryGetQuat(quat, initInfo); |
| 214 | } |
| 215 | |
| 216 | void getQuat(sead::Quatf* quat, const PlacementInfo& placementInfo) { |
| 217 | tryGetQuat(quat, placementInfo); |
| 218 | } |
| 219 | |
| 220 | bool tryGetQuat(sead::Quatf* quat, const ActorInitInfo& initInfo) { |
| 221 | return tryGetQuat(quat, placementInfo: *initInfo.placementInfo); |
| 222 | } |
| 223 | |
| 224 | bool tryGetQuat(sead::Quatf* quat, const PlacementInfo& placementInfo) { |
| 225 | sead::Vector3f rotate = sead::Vector3f::zero; |
| 226 | if (!tryGetRotate(rotate: &rotate, placementInfo)) { |
| 227 | *quat = sead::Quatf::unit; |
| 228 | return false; |
| 229 | } |
| 230 | quat->setRPY(roll: sead::Mathf::deg2rad(deg: rotate.x), pitch: sead::Mathf::deg2rad(deg: rotate.y), |
| 231 | yaw: sead::Mathf::deg2rad(deg: rotate.z)); |
| 232 | return true; |
| 233 | } |
| 234 | |
| 235 | void getScale(sead::Vector3f* scale, const PlacementInfo& placementInfo) { |
| 236 | tryGetScale(scale, placementInfo); |
| 237 | } |
| 238 | |
| 239 | void getScale(f32* x, f32* y, f32* z, const PlacementInfo& placementInfo) { |
| 240 | sead::Vector3f scale = {0.0f, 0.0f, 0.0f}; |
| 241 | tryGetScale(scale: &scale, placementInfo); |
| 242 | |
| 243 | if (x) |
| 244 | *x = scale.x; |
| 245 | if (y) |
| 246 | *y = scale.y; |
| 247 | if (z) |
| 248 | *z = scale.z; |
| 249 | } |
| 250 | |
| 251 | bool tryGetScale(sead::Vector3f* scale, const ActorInitInfo& initInfo) { |
| 252 | return tryGetScale(scale, placementInfo: *initInfo.placementInfo); |
| 253 | } |
| 254 | |
| 255 | bool tryGetScale(sead::Vector3f* scale, const PlacementInfo& placementInfo) { |
| 256 | return tryGetArgV3f(arg: scale, placementInfo, key: "Scale" ); |
| 257 | } |
| 258 | |
| 259 | void getSide(sead::Vector3f* side, const ActorInitInfo& initInfo) { |
| 260 | tryGetSide(side, initInfo); |
| 261 | } |
| 262 | |
| 263 | void getSide(sead::Vector3f* side, const PlacementInfo& placementInfo) { |
| 264 | tryGetSide(side, placementInfo); |
| 265 | } |
| 266 | |
| 267 | bool tryGetSide(sead::Vector3f* side, const ActorInitInfo& initInfo) { |
| 268 | return tryGetSide(side, placementInfo: *initInfo.placementInfo); |
| 269 | } |
| 270 | |
| 271 | bool tryGetSide(sead::Vector3f* side, const PlacementInfo& placementInfo) { |
| 272 | sead::Quatf quat = sead::Quatf::unit; |
| 273 | if (!tryGetQuat(quat: &quat, placementInfo)) |
| 274 | return false; |
| 275 | calcQuatSide(out: side, quat); |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | void getUp(sead::Vector3f* up, const ActorInitInfo& initInfo) { |
| 280 | tryGetUp(up, initInfo); |
| 281 | } |
| 282 | |
| 283 | void getUp(sead::Vector3f* up, const PlacementInfo& placementInfo) { |
| 284 | tryGetUp(up, placementInfo); |
| 285 | } |
| 286 | |
| 287 | bool tryGetUp(sead::Vector3f* up, const ActorInitInfo& initInfo) { |
| 288 | return tryGetUp(up, placementInfo: *initInfo.placementInfo); |
| 289 | } |
| 290 | |
| 291 | bool tryGetUp(sead::Vector3f* up, const PlacementInfo& placementInfo) { |
| 292 | sead::Quatf quat = sead::Quatf::unit; |
| 293 | if (!tryGetQuat(quat: &quat, placementInfo)) |
| 294 | return false; |
| 295 | calcQuatUp(out: up, quat); |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | void getFront(sead::Vector3f* front, const ActorInitInfo& initInfo) { |
| 300 | tryGetFront(front, initInfo); |
| 301 | } |
| 302 | |
| 303 | void getFront(sead::Vector3f* front, const PlacementInfo& placementInfo) { |
| 304 | tryGetFront(front, placementInfo); |
| 305 | } |
| 306 | |
| 307 | bool tryGetFront(sead::Vector3f* front, const ActorInitInfo& initInfo) { |
| 308 | return tryGetFront(front, placementInfo: *initInfo.placementInfo); |
| 309 | } |
| 310 | |
| 311 | bool tryGetFront(sead::Vector3f* front, const PlacementInfo& placementInfo) { |
| 312 | sead::Quatf quat = sead::Quatf::unit; |
| 313 | if (!tryGetQuat(quat: &quat, placementInfo)) |
| 314 | return false; |
| 315 | calcQuatFront(out: front, quat); |
| 316 | return true; |
| 317 | } |
| 318 | |
| 319 | bool tryGetLocalAxis(sead::Vector3f* dir, const ActorInitInfo& initInfo, s32 axis) { |
| 320 | return tryGetLocalAxis(dir, placementInfo: *initInfo.placementInfo, axis); |
| 321 | } |
| 322 | |
| 323 | bool tryGetLocalAxis(sead::Vector3f* dir, const PlacementInfo& placementInfo, s32 axis) { |
| 324 | switch ((Axis)(axis + 1)) { |
| 325 | case Axis::X: |
| 326 | return tryGetSide(side: dir, placementInfo); |
| 327 | case Axis::Y: |
| 328 | return tryGetUp(up: dir, placementInfo); |
| 329 | case Axis::Z: |
| 330 | return tryGetFront(front: dir, placementInfo); |
| 331 | default: |
| 332 | return false; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | bool tryGetLocalSignAxis(sead::Vector3f* dir, const ActorInitInfo& initInfo, s32 axis) { |
| 337 | return tryGetLocalSignAxis(dir, placementInfo: *initInfo.placementInfo, axis); |
| 338 | } |
| 339 | |
| 340 | bool tryGetLocalSignAxis(sead::Vector3f* dir, const PlacementInfo& placementInfo, s32 axis) { |
| 341 | switch ((Axis)sead::Mathi::abs(x: axis)) { |
| 342 | case Axis::X: |
| 343 | tryGetSide(side: dir, placementInfo); |
| 344 | break; |
| 345 | case Axis::Y: |
| 346 | tryGetUp(up: dir, placementInfo); |
| 347 | break; |
| 348 | case Axis::Z: |
| 349 | tryGetFront(front: dir, placementInfo); |
| 350 | break; |
| 351 | default: |
| 352 | return false; |
| 353 | } |
| 354 | if (axis < 0) |
| 355 | *dir *= -1; |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | bool tryGetMatrixTR(sead::Matrix34f* matrix, const ActorInitInfo& initInfo) { |
| 360 | return tryGetMatrixTR(matrix, placementInfo: *initInfo.placementInfo); |
| 361 | } |
| 362 | |
| 363 | bool tryGetMatrixTR(sead::Matrix34f* matrix, const PlacementInfo& placementInfo) { |
| 364 | sead::Vector3f trans = sead::Vector3f::zero; |
| 365 | sead::Vector3f rotate = sead::Vector3f::zero; |
| 366 | if (!tryGetTrans(trans: &trans, placementInfo)) |
| 367 | return false; |
| 368 | if (!tryGetRotate(rotate: &rotate, placementInfo)) |
| 369 | return false; |
| 370 | matrix->makeRT(r: {sead::Mathf::deg2rad(deg: rotate.x), sead::Mathf::deg2rad(deg: rotate.y), |
| 371 | sead::Mathf::deg2rad(deg: rotate.z)}, |
| 372 | t: trans); |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | bool tryGetMatrixTRS(sead::Matrix34f* matrix, const ActorInitInfo& initInfo) { |
| 377 | return tryGetMatrixTRS(matrix, placementInfo: *initInfo.placementInfo); |
| 378 | } |
| 379 | |
| 380 | bool tryGetMatrixTRS(sead::Matrix34f* matrix, const PlacementInfo& placementInfo) { |
| 381 | sead::Vector3f trans = sead::Vector3f::zero; |
| 382 | sead::Vector3f rotate = sead::Vector3f::zero; |
| 383 | sead::Vector3f scale = sead::Vector3f::ones; |
| 384 | if (!tryGetTrans(trans: &trans, placementInfo)) |
| 385 | return false; |
| 386 | if (!tryGetRotate(rotate: &rotate, placementInfo)) |
| 387 | return false; |
| 388 | if (!tryGetScale(scale: &scale, placementInfo)) |
| 389 | return false; |
| 390 | matrix->makeSRT(s: scale, |
| 391 | r: {sead::Mathf::deg2rad(deg: rotate.x), sead::Mathf::deg2rad(deg: rotate.y), |
| 392 | sead::Mathf::deg2rad(deg: rotate.z)}, |
| 393 | t: trans); |
| 394 | return true; |
| 395 | } |
| 396 | |
| 397 | bool tryGetInvertMatrixTR(sead::Matrix34f* matrix, const ActorInitInfo& initInfo) { |
| 398 | return tryGetInvertMatrixTR(matrix, placementInfo: *initInfo.placementInfo); |
| 399 | } |
| 400 | |
| 401 | bool tryGetInvertMatrixTR(sead::Matrix34f* matrix, const PlacementInfo& placementInfo) { |
| 402 | sead::Matrix34f mtx; |
| 403 | if (!tryGetMatrixTR(matrix: &mtx, placementInfo)) |
| 404 | return false; |
| 405 | matrix->setInverse(mtx); |
| 406 | return true; |
| 407 | } |
| 408 | |
| 409 | void calcMatrixMultParent(sead::Matrix34f* matrix, const ActorInitInfo& initInfo1, |
| 410 | const ActorInitInfo& initInfo2) { |
| 411 | calcMatrixMultParent(matrix, placementInfo1: *initInfo1.placementInfo, placementInfo2: *initInfo2.placementInfo); |
| 412 | } |
| 413 | |
| 414 | void calcMatrixMultParent(sead::Matrix34f* matrix, const PlacementInfo& placementInfo1, |
| 415 | const PlacementInfo& placementInfo2) { |
| 416 | sead::Matrix34f mtx1; |
| 417 | mtx1.makeIdentity(); |
| 418 | tryGetMatrixTR(matrix: &mtx1, placementInfo: placementInfo1); |
| 419 | sead::Matrix34f mtx2; |
| 420 | mtx2.makeIdentity(); |
| 421 | tryGetMatrixTR(matrix: &mtx2, placementInfo: placementInfo2); |
| 422 | matrix->setMul(a: mtx2, b: mtx1); |
| 423 | } |
| 424 | |
| 425 | void getArg(s32* arg, const ActorInitInfo& initInfo, const char* key) { |
| 426 | getArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 427 | } |
| 428 | |
| 429 | void getArg(s32* arg, const PlacementInfo& placementInfo, const char* key) { |
| 430 | tryGetArg(arg, placementInfo, key); |
| 431 | } |
| 432 | |
| 433 | bool tryGetArg(s32* arg, const ActorInitInfo& initInfo, const char* key) { |
| 434 | return tryGetArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 435 | } |
| 436 | |
| 437 | bool tryGetArg(s32* arg, const PlacementInfo& placementInfo, const char* key) { |
| 438 | return placementInfo.getPlacementIter().tryGetIntByKey(val: arg, key); |
| 439 | } |
| 440 | |
| 441 | void getArg(f32* arg, const ActorInitInfo& initInfo, const char* key) { |
| 442 | getArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 443 | } |
| 444 | |
| 445 | void getArg(f32* arg, const PlacementInfo& placementInfo, const char* key) { |
| 446 | tryGetArg(arg, placementInfo, key); |
| 447 | } |
| 448 | |
| 449 | bool tryGetArg(f32* arg, const ActorInitInfo& initInfo, const char* key) { |
| 450 | return tryGetArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 451 | } |
| 452 | |
| 453 | bool tryGetArg(f32* arg, const PlacementInfo& placementInfo, const char* key) { |
| 454 | return placementInfo.getPlacementIter().tryGetFloatByKey(val: arg, key); |
| 455 | } |
| 456 | |
| 457 | void getArg(bool* arg, const ActorInitInfo& initInfo, const char* key) { |
| 458 | getArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 459 | } |
| 460 | |
| 461 | void getArg(bool* arg, const PlacementInfo& placementInfo, const char* key) { |
| 462 | tryGetArg(arg, placementInfo, key); |
| 463 | } |
| 464 | |
| 465 | bool tryGetArg(bool* arg, const ActorInitInfo& initInfo, const char* key) { |
| 466 | return tryGetArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 467 | } |
| 468 | |
| 469 | bool tryGetArg(bool* arg, const PlacementInfo& placementInfo, const char* key) { |
| 470 | return placementInfo.getPlacementIter().tryGetBoolByKey(val: arg, key); |
| 471 | } |
| 472 | |
| 473 | s32 getArgS32(const ActorInitInfo& actorInitInfo, const char* key) { |
| 474 | s32 arg = 0; |
| 475 | getArg(arg: &arg, initInfo: actorInitInfo, key); |
| 476 | return arg; |
| 477 | } |
| 478 | |
| 479 | f32 getArgF32(const ActorInitInfo& actorInitInfo, const char* key) { |
| 480 | f32 arg = 0.0f; |
| 481 | getArg(arg: &arg, initInfo: actorInitInfo, key); |
| 482 | return arg; |
| 483 | } |
| 484 | |
| 485 | void getArgV3f(sead::Vector3f* arg, const ActorInitInfo& actorInitInfo, const char* key) { |
| 486 | tryGetArgV3f(arg, actorInitInfo, key); |
| 487 | } |
| 488 | |
| 489 | void getArgV3f(sead::Vector3f* arg, const PlacementInfo& placementInfo, const char* key) { |
| 490 | tryGetArgV3f(arg, placementInfo, key); |
| 491 | } |
| 492 | |
| 493 | bool tryGetArgV3f(sead::Vector3f* arg, const ActorInitInfo& actorInitInfo, const char* key) { |
| 494 | return tryGetArgV3f(arg, placementInfo: *actorInitInfo.placementInfo, key); |
| 495 | } |
| 496 | |
| 497 | bool tryGetArgV3f(sead::Vector3f* arg, const PlacementInfo& placementInfo, const char* key) { |
| 498 | return tryGetByamlV3f(arg, placementInfo.getPlacementIter(), key); |
| 499 | } |
| 500 | |
| 501 | bool isArgBool(const ActorInitInfo& initInfo, const char* key) { |
| 502 | bool arg = false; |
| 503 | getArg(arg: &arg, initInfo, key); |
| 504 | return arg; |
| 505 | } |
| 506 | |
| 507 | bool isArgBool(const PlacementInfo& placementInfo, const char* key) { |
| 508 | bool arg = false; |
| 509 | getArg(arg: &arg, placementInfo, key); |
| 510 | return arg; |
| 511 | } |
| 512 | |
| 513 | bool isArgString(const ActorInitInfo& initInfo, const char* key, const char* arg) { |
| 514 | return isArgString(placementInfo: *initInfo.placementInfo, key, arg); |
| 515 | } |
| 516 | |
| 517 | bool isArgString(const PlacementInfo& placementInfo, const char* key, const char* arg) { |
| 518 | return isEqualString(str1: getStringArg(placementInfo, key), str2: arg); |
| 519 | } |
| 520 | |
| 521 | void getStringArg(const char** arg, const ActorInitInfo& initInfo, const char* key) { |
| 522 | getStringArg(arg, placementInfo: *initInfo.placementInfo, key); |
| 523 | } |
| 524 | |
| 525 | void getStringArg(const char** arg, const PlacementInfo& placementInfo, const char* key) { |
| 526 | tryGetStringArg(arg, initInfo: placementInfo, key); |
| 527 | } |
| 528 | |
| 529 | void getStringArg(const char** arg, const AreaInitInfo& initInfo, const char* key) { |
| 530 | getStringArg(arg, placementInfo: (const PlacementInfo&)initInfo, key); |
| 531 | } |
| 532 | |
| 533 | const char* getStringArg(const ActorInitInfo& initInfo, const char* key) { |
| 534 | return getStringArg(placementInfo: *initInfo.placementInfo, key); |
| 535 | } |
| 536 | |
| 537 | const char* getStringArg(const PlacementInfo& placementInfo, const char* key) { |
| 538 | const char* str = "" ; |
| 539 | if (!placementInfo.getPlacementIter().tryGetStringByKey(string: &str, key) || isEqualString(str1: "" , str2: str)) |
| 540 | return nullptr; |
| 541 | return str; |
| 542 | } |
| 543 | |
| 544 | const char* getStringArg(const AreaInitInfo& initInfo, const char* key) { |
| 545 | return getStringArg(placementInfo: (const PlacementInfo&)initInfo, key); |
| 546 | } |
| 547 | |
| 548 | bool tryGetStringArg(const char** arg, const ActorInitInfo& initInfo, const char* key) { |
| 549 | return tryGetStringArg(arg, initInfo: *initInfo.placementInfo, key); |
| 550 | } |
| 551 | |
| 552 | bool tryGetStringArg(const char** arg, const PlacementInfo& initInfo, const char* key) { |
| 553 | const char* str = "" ; |
| 554 | if (!initInfo.getPlacementIter().tryGetStringByKey(string: &str, key) || isEqualString(str1: "" , str2: str)) |
| 555 | return false; |
| 556 | *arg = str; |
| 557 | return true; |
| 558 | } |
| 559 | |
| 560 | bool tryGetStringArg(const char** arg, const AreaInitInfo& initInfo, const char* key) { |
| 561 | return tryGetStringArg(arg, initInfo: (const PlacementInfo&)initInfo, key); |
| 562 | } |
| 563 | |
| 564 | bool tryGetArgV2f(sead::Vector2f* arg, const ActorInitInfo& initInfo, const char* key) { |
| 565 | return tryGetArgV2f(arg, initInfo: *initInfo.placementInfo, key); |
| 566 | } |
| 567 | |
| 568 | bool tryGetArgV2f(sead::Vector2f* arg, const PlacementInfo& initInfo, const char* key) { |
| 569 | return tryGetByamlV2f(arg, initInfo.getPlacementIter(), key); |
| 570 | } |
| 571 | |
| 572 | bool tryGetArgColor(sead::Color4f* arg, const ActorInitInfo& initInfo, const char* key) { |
| 573 | return tryGetArgColor(arg, initInfo: *initInfo.placementInfo, key); |
| 574 | } |
| 575 | |
| 576 | bool tryGetArgColor(sead::Color4f* arg, const PlacementInfo& initInfo, const char* key) { |
| 577 | return tryGetByamlColor(arg, initInfo.getPlacementIter(), key); |
| 578 | } |
| 579 | |
| 580 | void getLayerConfigName(const char** name, const ActorInitInfo& initInfo) { |
| 581 | getLayerConfigName(name, initInfo: *initInfo.placementInfo); |
| 582 | } |
| 583 | |
| 584 | void getLayerConfigName(const char** name, const PlacementInfo& initInfo) { |
| 585 | return getStringArg(arg: name, placementInfo: initInfo, key: "LayerConfigName" ); |
| 586 | } |
| 587 | |
| 588 | bool tryGetZoneNameIfExist(const char** name, const PlacementInfo& placementInfo) { |
| 589 | PlacementId id; |
| 590 | getPlacementId(placementId: &id, placementInfo); |
| 591 | if (!id.getUnitConfigName()) |
| 592 | return false; |
| 593 | *name = id.getUnitConfigName(); |
| 594 | return true; |
| 595 | } |
| 596 | |
| 597 | void getPlacementId(PlacementId* placementId, const PlacementInfo& placementInfo) { |
| 598 | tryGetPlacementId(placementId, placementInfo); |
| 599 | } |
| 600 | |
| 601 | bool tryGetBoolArgOrFalse(const ActorInitInfo& initInfo, const char* key) { |
| 602 | bool val = false; |
| 603 | if (!tryGetArg(arg: &val, initInfo, key)) |
| 604 | return false; |
| 605 | return val; |
| 606 | } |
| 607 | |
| 608 | s32 getCountPlacementInfo(const PlacementInfo& placementInfo) { |
| 609 | return placementInfo.getPlacementIter().getSize(); |
| 610 | } |
| 611 | |
| 612 | void getPlacementInfoByKey(PlacementInfo* outPlacementInfo, const PlacementInfo& placementInfo, |
| 613 | const char* key) { |
| 614 | tryGetPlacementInfoByKey(outPlacementInfo, placementInfo, key); |
| 615 | } |
| 616 | |
| 617 | bool tryGetPlacementInfoByKey(PlacementInfo* outPlacementInfo, const PlacementInfo& placementInfo, |
| 618 | const char* key) { |
| 619 | ByamlIter iter; |
| 620 | if (!placementInfo.getPlacementIter().tryGetIterByKey(iter: &iter, key)) |
| 621 | return false; |
| 622 | outPlacementInfo->set(placement_iter: iter, zone_iter: placementInfo.getZoneIter()); |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | void getPlacementInfoByIndex(PlacementInfo* outPlacementInfo, const PlacementInfo& placementInfo, |
| 627 | s32 index) { |
| 628 | tryGetPlacementInfoByIndex(outPlacementInfo, placementInfo, index); |
| 629 | } |
| 630 | |
| 631 | bool tryGetPlacementInfoByIndex(PlacementInfo* outPlacementInfo, const PlacementInfo& placementInfo, |
| 632 | s32 index) { |
| 633 | ByamlIter iter; |
| 634 | if (!placementInfo.getPlacementIter().tryGetIterByIndex(iter: &iter, index)) |
| 635 | return false; |
| 636 | outPlacementInfo->set(placement_iter: iter, zone_iter: placementInfo.getZoneIter()); |
| 637 | return true; |
| 638 | } |
| 639 | |
| 640 | void getPlacementInfoAndKeyNameByIndex(PlacementInfo* outPlacementInfo, const char** outKey, |
| 641 | const PlacementInfo& placementInfo, s32 index) { |
| 642 | tryGetPlacementInfoAndKeyNameByIndex(outPlacementInfo, outKey, placementInfo, index); |
| 643 | } |
| 644 | |
| 645 | bool tryGetPlacementInfoAndKeyNameByIndex(PlacementInfo* outPlacementInfo, const char** outKey, |
| 646 | const PlacementInfo& placementInfo, s32 index) { |
| 647 | ByamlIter iter; |
| 648 | if (!placementInfo.getPlacementIter().tryGetIterAndKeyNameByIndex(iter: &iter, key: outKey, index)) |
| 649 | return false; |
| 650 | outPlacementInfo->set(placement_iter: iter, zone_iter: placementInfo.getZoneIter()); |
| 651 | return true; |
| 652 | } |
| 653 | |
| 654 | PlacementId* createPlacementId(const ActorInitInfo& initInfo) { |
| 655 | return createPlacementId(placementInfo: *initInfo.placementInfo); |
| 656 | } |
| 657 | |
| 658 | PlacementId* createPlacementId(const PlacementInfo& placementInfo) { |
| 659 | PlacementId* id = new PlacementId(); |
| 660 | id->init(info: placementInfo); |
| 661 | return id; |
| 662 | } |
| 663 | |
| 664 | bool tryGetPlacementId(PlacementId* placementId, const ActorInitInfo& initInfo) { |
| 665 | return tryGetPlacementId(placementId, placementInfo: *initInfo.placementInfo); |
| 666 | } |
| 667 | |
| 668 | bool tryGetPlacementId(PlacementId* placementId, const PlacementInfo& placementInfo) { |
| 669 | return placementId->init(info: placementInfo); |
| 670 | } |
| 671 | |
| 672 | void getPlacementId(PlacementId* placementId, const ActorInitInfo& initInfo) { |
| 673 | getPlacementId(placementId, placementInfo: *initInfo.placementInfo); |
| 674 | } |
| 675 | |
| 676 | bool isEqualPlacementId(const PlacementId& placementId, const PlacementId& otherPlacementId) { |
| 677 | return PlacementId::isEqual(selfId: placementId, otherId: otherPlacementId); |
| 678 | } |
| 679 | |
| 680 | bool isEqualPlacementId(const PlacementInfo& placementInfo, |
| 681 | const PlacementInfo& otherPlacementInfo) { |
| 682 | PlacementId id1; |
| 683 | if (!tryGetPlacementId(placementId: &id1, placementInfo)) |
| 684 | return false; |
| 685 | PlacementId id2; |
| 686 | if (!tryGetPlacementId(placementId: &id2, placementInfo: otherPlacementInfo)) |
| 687 | return false; |
| 688 | return isEqualPlacementId(placementId: id1, otherPlacementId: id2); |
| 689 | } |
| 690 | |
| 691 | bool isExistRail(const ActorInitInfo& initInfo, const char* linkName) { |
| 692 | PlacementInfo info; |
| 693 | return tryGetRailIter(railPlacementInfo: &info, placementInfo: *initInfo.placementInfo, linkName); |
| 694 | } |
| 695 | |
| 696 | bool tryGetRailIter(PlacementInfo* railPlacementInfo, const PlacementInfo& placementInfo, |
| 697 | const char* linkName) { |
| 698 | if (!tryGetLinksInfo(railPlacementInfo, placementInfo, linkName)) |
| 699 | return false; |
| 700 | return railPlacementInfo->getPlacementIter().isTypeContainer(); |
| 701 | } |
| 702 | |
| 703 | bool tryGetLinksInfo(PlacementInfo* railPlacementInfo, const PlacementInfo& placementInfo, |
| 704 | const char* linkName) { |
| 705 | PlacementInfo links; |
| 706 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links" )) |
| 707 | return false; |
| 708 | PlacementInfo link; |
| 709 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &link, placementInfo: links, key: linkName)) |
| 710 | return false; |
| 711 | if (!tryGetPlacementInfoByIndex(outPlacementInfo: railPlacementInfo, placementInfo: link, index: 0)) |
| 712 | return false; |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | bool tryGetMoveParameterRailIter(PlacementInfo* railPlacementInfo, |
| 717 | const PlacementInfo& placementInfo) { |
| 718 | return tryGetRailIter(railPlacementInfo, placementInfo, linkName: "RailWithMoveParameter" ); |
| 719 | } |
| 720 | |
| 721 | bool tryGetRailPointPos(sead::Vector3f* railPoint, const PlacementInfo& placementInfo) { |
| 722 | return tryGetTrans(trans: railPoint, placementInfo); |
| 723 | } |
| 724 | |
| 725 | void getRailPointHandlePrev(sead::Vector3f* railPoint, const PlacementInfo& placementInfo) { |
| 726 | tryGetRailPointHandlePrev(railPoint, placementInfo); |
| 727 | } |
| 728 | |
| 729 | bool tryGetRailPointHandlePrev(sead::Vector3f* railPoint, const PlacementInfo& placementInfo) { |
| 730 | PlacementInfo controlPoints; |
| 731 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &controlPoints, placementInfo, key: "ControlPoints" )) |
| 732 | return false; |
| 733 | PlacementInfo controlPoint; |
| 734 | if (!tryGetPlacementInfoByIndex(outPlacementInfo: &controlPoint, placementInfo: controlPoints, index: 0)) |
| 735 | return false; |
| 736 | if (!tryGetByamlV3f(railPoint, controlPoint.getPlacementIter())) |
| 737 | return false; |
| 738 | multZoneMtx(trans: railPoint, placementInfo); |
| 739 | return true; |
| 740 | } |
| 741 | |
| 742 | void getRailPointHandleNext(sead::Vector3f* railPoint, const PlacementInfo& placementInfo) { |
| 743 | tryGetRailPointHandleNext(railPoint, placementInfo); |
| 744 | } |
| 745 | |
| 746 | bool tryGetRailPointHandleNext(sead::Vector3f* railPoint, const PlacementInfo& placementInfo) { |
| 747 | PlacementInfo controlPoints; |
| 748 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &controlPoints, placementInfo, key: "ControlPoints" )) |
| 749 | return false; |
| 750 | PlacementInfo controlPoint; |
| 751 | if (!tryGetPlacementInfoByIndex(outPlacementInfo: &controlPoint, placementInfo: controlPoints, index: 1)) |
| 752 | return false; |
| 753 | if (!tryGetByamlV3f(railPoint, controlPoint.getPlacementIter())) |
| 754 | return false; |
| 755 | multZoneMtx(trans: railPoint, placementInfo); |
| 756 | return true; |
| 757 | } |
| 758 | |
| 759 | bool isExistGraphRider(const ActorInitInfo& initInfo) { |
| 760 | PlacementInfo info; |
| 761 | return tryGetRailIter(railPlacementInfo: &info, placementInfo: *initInfo.placementInfo, linkName: "Rail" ); |
| 762 | } |
| 763 | |
| 764 | s32 calcLinkChildNum(const ActorInitInfo& initInfo, const char* linkName) { |
| 765 | return calcLinkChildNum(placementInfo: *initInfo.placementInfo, linkName); |
| 766 | } |
| 767 | |
| 768 | s32 calcLinkChildNum(const PlacementInfo& placementInfo, const char* linkName) { |
| 769 | PlacementInfo links; |
| 770 | PlacementInfo link; |
| 771 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links" )) |
| 772 | return false; |
| 773 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &link, placementInfo: links, key: linkName)) |
| 774 | return false; |
| 775 | return link.getPlacementIter().getSize(); |
| 776 | } |
| 777 | |
| 778 | bool isExistLinkChild(const ActorInitInfo& initInfo, const char* linkName, s32 index) { |
| 779 | return isExistLinkChild(placementInfo: *initInfo.placementInfo, linkName, index); |
| 780 | } |
| 781 | |
| 782 | bool isExistLinkChild(const PlacementInfo& placementInfo, const char* linkName, s32 index) { |
| 783 | return calcLinkChildNum(placementInfo, linkName) > index; |
| 784 | } |
| 785 | |
| 786 | bool isExistLinkChild(const AreaInitInfo& initInfo, const char* linkName, s32 index) { |
| 787 | return isExistLinkChild(placementInfo: (const PlacementInfo&)initInfo, linkName, index); |
| 788 | } |
| 789 | |
| 790 | s32 calcLinkNestNum(const ActorInitInfo& initInfo, const char* linkName) { |
| 791 | return calcLinkNestNum(placementInfo: *initInfo.placementInfo, linkName); |
| 792 | } |
| 793 | |
| 794 | s32 calcLinkNestNum(const PlacementInfo& placementInfo, const char* linkName) { |
| 795 | PlacementInfo links; |
| 796 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links" )) |
| 797 | return 0; |
| 798 | PlacementInfo link = links; |
| 799 | s32 depth = 0; |
| 800 | while (tryGetPlacementInfoByKey(outPlacementInfo: &link, placementInfo: links, key: linkName) && |
| 801 | link.getPlacementIter().getSize() != 0) { |
| 802 | PlacementInfo item; |
| 803 | getPlacementInfoByIndex(outPlacementInfo: &item, placementInfo: link, index: 0); |
| 804 | getPlacementInfoByKey(outPlacementInfo: &links, placementInfo: item, key: "Links" ); |
| 805 | depth++; |
| 806 | } |
| 807 | return depth; |
| 808 | } |
| 809 | |
| 810 | void getLinksInfo(PlacementInfo* linkPlacementInfo, const PlacementInfo& placementInfo, |
| 811 | const char* linkName) { |
| 812 | getLinksInfoByIndex(linkPlacementInfo, placementInfo, linkName, index: 0); |
| 813 | } |
| 814 | |
| 815 | void getLinksInfoByIndex(PlacementInfo* linkPlacementInfo, const PlacementInfo& placementInfo, |
| 816 | const char* linkName, s32 index) { |
| 817 | PlacementInfo links; |
| 818 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links" )) |
| 819 | return; |
| 820 | PlacementInfo link; |
| 821 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &link, placementInfo: links, key: linkName)) |
| 822 | return; |
| 823 | getPlacementInfoByIndex(outPlacementInfo: linkPlacementInfo, placementInfo: link, index); |
| 824 | } |
| 825 | |
| 826 | void getLinksInfo(PlacementInfo* linkPlacementInfo, const ActorInitInfo& initInfo, |
| 827 | const char* linkName) { |
| 828 | getLinksInfo(linkPlacementInfo, placementInfo: *initInfo.placementInfo, linkName); |
| 829 | } |
| 830 | |
| 831 | void getLinksInfoByIndex(PlacementInfo* linkPlacementInfo, const ActorInitInfo& initInfo, |
| 832 | const char* linkName, s32 index) { |
| 833 | getLinksInfoByIndex(linkPlacementInfo, placementInfo: *initInfo.placementInfo, linkName, index); |
| 834 | } |
| 835 | |
| 836 | bool tryGetLinksInfo(PlacementInfo* linkPlacementInfo, const ActorInitInfo& initInfo, |
| 837 | const char* linkName) { |
| 838 | return tryGetLinksInfo(railPlacementInfo: linkPlacementInfo, placementInfo: *initInfo.placementInfo, linkName); |
| 839 | } |
| 840 | |
| 841 | void getLinksMatrix(sead::Matrix34f* matrix, const ActorInitInfo& initInfo, const char* linkName) { |
| 842 | getLinksMatrixByIndex(matrix, initInfo, linkName, index: 0); |
| 843 | } |
| 844 | |
| 845 | void getLinksMatrixByIndex(sead::Matrix34f* matrix, const ActorInitInfo& initInfo, |
| 846 | const char* linkName, s32 index) { |
| 847 | PlacementInfo info; |
| 848 | getLinksInfoByIndex(linkPlacementInfo: &info, initInfo, linkName, index); |
| 849 | tryGetMatrixTR(matrix, placementInfo: info); |
| 850 | } |
| 851 | |
| 852 | void getLinkTR(sead::Vector3f* trans, sead::Vector3f* rotate, const PlacementInfo& placementInfo, |
| 853 | const char* linkName) { |
| 854 | PlacementInfo info; |
| 855 | getLinksInfo(linkPlacementInfo: &info, placementInfo, linkName); |
| 856 | getTrans(trans, placementInfo: info); |
| 857 | getRotate(rotate, placementInfo: info); |
| 858 | } |
| 859 | |
| 860 | void getLinkTR(sead::Vector3f* trans, sead::Vector3f* rotate, const ActorInitInfo& initInfo, |
| 861 | const char* linkName) { |
| 862 | getLinkTR(trans, rotate, placementInfo: *initInfo.placementInfo, linkName); |
| 863 | } |
| 864 | |
| 865 | void getLinkTR(sead::Vector3f* trans, sead::Vector3f* rotate, const AreaInitInfo& initInfo, |
| 866 | const char* linkName) { |
| 867 | getLinkTR(trans, rotate, placementInfo: (const PlacementInfo&)initInfo, linkName); |
| 868 | } |
| 869 | |
| 870 | void getLinksQT(sead::Quatf* quat, sead::Vector3f* trans, const ActorInitInfo& initInfo, |
| 871 | const char* linkName) { |
| 872 | getLinksQT(quat, trans, placementInfo: *initInfo.placementInfo, linkName); |
| 873 | } |
| 874 | |
| 875 | void getLinksQT(sead::Quatf* quat, sead::Vector3f* trans, const PlacementInfo& placementInfo, |
| 876 | const char* linkName) { |
| 877 | PlacementInfo info; |
| 878 | getLinksInfo(linkPlacementInfo: &info, placementInfo, linkName); |
| 879 | if (quat) |
| 880 | getQuat(quat, placementInfo: info); |
| 881 | if (trans) |
| 882 | getTrans(trans, placementInfo: info); |
| 883 | } |
| 884 | |
| 885 | bool tryGetLinksQT(sead::Quatf* quat, sead::Vector3f* trans, const ActorInitInfo& initInfo, |
| 886 | const char* linkName) { |
| 887 | PlacementInfo info; |
| 888 | if (!tryGetLinksInfo(linkPlacementInfo: &info, initInfo, linkName)) |
| 889 | return false; |
| 890 | bool success = true; |
| 891 | if (quat) |
| 892 | success &= tryGetQuat(quat, placementInfo: info); |
| 893 | if (trans) |
| 894 | success &= tryGetTrans(trans, placementInfo: info); |
| 895 | return success; |
| 896 | } |
| 897 | |
| 898 | bool tryGetLinksQTS(sead::Quatf* quat, sead::Vector3f* trans, sead::Vector3f* scale, |
| 899 | const ActorInitInfo& initInfo, const char* linkName) { |
| 900 | PlacementInfo info; |
| 901 | if (!tryGetLinksInfo(linkPlacementInfo: &info, initInfo, linkName)) |
| 902 | return false; |
| 903 | bool success = true; |
| 904 | if (quat) |
| 905 | success &= tryGetQuat(quat, placementInfo: info); |
| 906 | if (trans) |
| 907 | success &= tryGetTrans(trans, placementInfo: info); |
| 908 | if (scale) |
| 909 | success &= tryGetScale(scale, placementInfo: info); |
| 910 | return success; |
| 911 | } |
| 912 | |
| 913 | bool tryGetLinksMatrixTR(sead::Matrix34f* matrix, const ActorInitInfo& initInfo, |
| 914 | const char* linkName) { |
| 915 | PlacementInfo info; |
| 916 | if (!tryGetLinksInfo(railPlacementInfo: &info, placementInfo: *initInfo.placementInfo, linkName)) |
| 917 | return false; |
| 918 | return tryGetMatrixTR(matrix, placementInfo: info); |
| 919 | } |
| 920 | |
| 921 | bool tryGetLinksMatrixTR(sead::Matrix34f* matrix, const AreaInitInfo& initInfo, |
| 922 | const char* linkName) { |
| 923 | PlacementInfo info; |
| 924 | if (!tryGetLinksInfo(railPlacementInfo: &info, placementInfo: (const PlacementInfo&)initInfo, linkName)) |
| 925 | return false; |
| 926 | return tryGetMatrixTR(matrix, placementInfo: info); |
| 927 | } |
| 928 | |
| 929 | bool tryGetLinksMatrixTRS(sead::Matrix34f* matrix, const ActorInitInfo& initInfo, |
| 930 | const char* linkName) { |
| 931 | PlacementInfo info; |
| 932 | if (!tryGetLinksInfo(railPlacementInfo: &info, placementInfo: *initInfo.placementInfo, linkName)) |
| 933 | return false; |
| 934 | return tryGetMatrixTRS(matrix, placementInfo: info); |
| 935 | } |
| 936 | |
| 937 | bool tryGetLinksTrans(sead::Vector3f* trans, const ActorInitInfo& initInfo, const char* linkName) { |
| 938 | return tryGetLinksQT(quat: nullptr, trans, initInfo, linkName); |
| 939 | } |
| 940 | |
| 941 | bool tryGetLinksTrans(sead::Vector3f* trans, const PlacementInfo& placementInfo, |
| 942 | const char* linkName) { |
| 943 | PlacementInfo info; |
| 944 | if (!tryGetLinksInfo(railPlacementInfo: &info, placementInfo, linkName)) |
| 945 | return false; |
| 946 | if (!trans) |
| 947 | return false; |
| 948 | return tryGetTrans(trans, placementInfo: info); |
| 949 | } |
| 950 | |
| 951 | bool tryGetLinksQuat(sead::Quatf* quat, const ActorInitInfo& initInfo, const char* linkName) { |
| 952 | return tryGetLinksQT(quat, trans: nullptr, initInfo, linkName); |
| 953 | } |
| 954 | |
| 955 | bool tryGetLinksTR(sead::Vector3f* trans, sead::Vector3f* rotate, const ActorInitInfo& initInfo, |
| 956 | const char* linkName) { |
| 957 | PlacementInfo info; |
| 958 | if (!tryGetLinksInfo(linkPlacementInfo: &info, initInfo, linkName)) |
| 959 | return false; |
| 960 | getTrans(trans, placementInfo: info); |
| 961 | getRotate(rotate, placementInfo: info); |
| 962 | return true; |
| 963 | } |
| 964 | |
| 965 | void getChildTrans(sead::Vector3f* trans, const PlacementInfo& placementInfo, |
| 966 | const char* linkName) { |
| 967 | PlacementInfo info; |
| 968 | getLinksInfo(linkPlacementInfo: &info, placementInfo, linkName); |
| 969 | getTrans(trans, placementInfo: info); |
| 970 | } |
| 971 | |
| 972 | void getChildTrans(sead::Vector3f* trans, const ActorInitInfo& initInfo, const char* linkName) { |
| 973 | getChildTrans(trans, placementInfo: *initInfo.placementInfo, linkName); |
| 974 | } |
| 975 | |
| 976 | void getChildTrans(sead::Vector3f* trans, const AreaInitInfo& initInfo, const char* linkName) { |
| 977 | getChildTrans(trans, placementInfo: (const PlacementInfo&)initInfo, linkName); |
| 978 | } |
| 979 | |
| 980 | void getChildLinkT(sead::Vector3f* trans, const ActorInitInfo& initInfo, const char* linkName, |
| 981 | s32 index) { |
| 982 | PlacementInfo info; |
| 983 | getLinksInfoByIndex(linkPlacementInfo: &info, initInfo, linkName, index); |
| 984 | getTrans(trans, placementInfo: info); |
| 985 | } |
| 986 | |
| 987 | void getChildLinkTR(sead::Vector3f* trans, sead::Vector3f* rotate, const ActorInitInfo& initInfo, |
| 988 | const char* linkName, s32 index) { |
| 989 | PlacementInfo info; |
| 990 | getLinksInfoByIndex(linkPlacementInfo: &info, initInfo, linkName, index); |
| 991 | getTrans(trans, placementInfo: info); |
| 992 | getRotate(rotate, placementInfo: info); |
| 993 | } |
| 994 | |
| 995 | s32 calcMatchNameLinkCount(const PlacementInfo& placementInfo, const char* linkName) { |
| 996 | PlacementInfo links; |
| 997 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links" )) |
| 998 | return 0; |
| 999 | s32 numItems = links.getPlacementIter().getSize(); |
| 1000 | s32 count = 0; |
| 1001 | for (s32 i = 0; i < numItems; ++i) { |
| 1002 | PlacementInfo item; |
| 1003 | const char* key = nullptr; |
| 1004 | getPlacementInfoAndKeyNameByIndex(outPlacementInfo: &item, outKey: &key, placementInfo: links, index: i); |
| 1005 | if (isMatchString(key, {.str: linkName})) |
| 1006 | count++; |
| 1007 | } |
| 1008 | return count; |
| 1009 | } |
| 1010 | |
| 1011 | s32 calcLinkCountClassName(const PlacementInfo& placementInfo, const char* linkName) { |
| 1012 | PlacementInfo links; |
| 1013 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links" )) |
| 1014 | return false; |
| 1015 | s32 numItems = links.getPlacementIter().getSize(); |
| 1016 | s32 count = 0; |
| 1017 | for (s32 i = 0; i < numItems; ++i) { |
| 1018 | PlacementInfo item; |
| 1019 | getPlacementInfoByIndex(outPlacementInfo: &item, placementInfo: links, index: i); |
| 1020 | PlacementInfo first; |
| 1021 | getPlacementInfoByIndex(outPlacementInfo: &first, placementInfo: item, index: 0); |
| 1022 | |
| 1023 | const char* className = nullptr; |
| 1024 | if (tryGetClassName(name: &className, placementInfo: first) && isEqualString(str1: className, str2: linkName)) |
| 1025 | count++; |
| 1026 | } |
| 1027 | return count; |
| 1028 | } |
| 1029 | |
| 1030 | bool tryGetZoneMatrixTR(sead::Matrix34f* matrix, const ActorInitInfo& initInfo) { |
| 1031 | return tryGetZoneMatrixTR(matrix, placementInfo: *initInfo.placementInfo); |
| 1032 | } |
| 1033 | |
| 1034 | bool tryGetDisplayOffset(sead::Vector3f* offset, const ActorInitInfo& initInfo) { |
| 1035 | return tryGetDisplayOffset(offset, placementInfo: *initInfo.placementInfo); |
| 1036 | } |
| 1037 | |
| 1038 | bool tryGetDisplayOffset(sead::Vector3f* offset, const PlacementInfo& placementInfo) { |
| 1039 | PlacementInfo info; |
| 1040 | if (!tryGetPlacementInfoByKey(outPlacementInfo: &info, placementInfo, key: "UnitConfig" )) |
| 1041 | return false; |
| 1042 | |
| 1043 | if (!tryGetArgV3f(arg: offset, placementInfo: info, key: "DisplayTranslate" )) |
| 1044 | return false; |
| 1045 | |
| 1046 | sead::Matrix34f tr = sead::Matrix34f::ident; |
| 1047 | if (!tryGetMatrixTR(matrix: &tr, placementInfo)) |
| 1048 | return false; |
| 1049 | offset->rotate(m: tr); |
| 1050 | |
| 1051 | sead::Matrix34f mtx = sead::Matrix34f::ident; |
| 1052 | if (tryGetZoneMatrixTR(matrix: &mtx, placementInfo)) |
| 1053 | offset->rotate(m: mtx); |
| 1054 | return true; |
| 1055 | } |
| 1056 | |
| 1057 | bool tryGetChildDisplayOffset(sead::Vector3f* offset, const ActorInitInfo& initInfo, |
| 1058 | const char* linkName) { |
| 1059 | PlacementInfo info; |
| 1060 | return tryGetLinksInfo(linkPlacementInfo: &info, initInfo, linkName) && tryGetDisplayOffset(offset, placementInfo: info); |
| 1061 | } |
| 1062 | |
| 1063 | bool tryGetDisplayRotate(sead::Vector3f* rotate, const ActorInitInfo& initInfo) { |
| 1064 | PlacementInfo info; |
| 1065 | getPlacementInfoByKey(outPlacementInfo: &info, placementInfo: *initInfo.placementInfo, key: "UnitConfig" ); |
| 1066 | return tryGetArgV3f(arg: rotate, placementInfo: info, key: "DisplayRotate" ); |
| 1067 | } |
| 1068 | |
| 1069 | bool tryGetDisplayScale(sead::Vector3f* scale, const ActorInitInfo& initInfo) { |
| 1070 | PlacementInfo info; |
| 1071 | getPlacementInfoByKey(outPlacementInfo: &info, placementInfo: *initInfo.placementInfo, key: "UnitConfig" ); |
| 1072 | return tryGetArgV3f(arg: scale, placementInfo: info, key: "DisplayScale" ); |
| 1073 | } |
| 1074 | |
| 1075 | } // namespace al |
| 1076 | |
| 1077 | namespace alPlacementFunction { |
| 1078 | |
| 1079 | s32 getCameraId(const al::ActorInitInfo& initInfo) { |
| 1080 | s32 id = -1; |
| 1081 | if (!al::tryGetArg(arg: &id, initInfo, key: "CameraId" )) |
| 1082 | return -1; |
| 1083 | return id; |
| 1084 | } |
| 1085 | |
| 1086 | bool getLinkGroupId(al::PlacementId* groupId, const al::ActorInitInfo& initInfo, |
| 1087 | const char* linkName) { |
| 1088 | al::PlacementInfo info; |
| 1089 | if (al::tryGetLinksInfo(linkPlacementInfo: &info, initInfo, linkName) && al::tryGetPlacementId(placementId: groupId, placementInfo: info)) |
| 1090 | return true; |
| 1091 | return false; |
| 1092 | } |
| 1093 | |
| 1094 | bool isEnableLinkGroupId(const al::ActorInitInfo& initInfo, const char* linkName) { |
| 1095 | al::PlacementId id; |
| 1096 | return getLinkGroupId(groupId: &id, initInfo, linkName); |
| 1097 | } |
| 1098 | |
| 1099 | bool isEnableGroupClipping(const al::ActorInitInfo& initInfo) { |
| 1100 | return isEnableLinkGroupId(initInfo, linkName: "GroupClipping" ); |
| 1101 | } |
| 1102 | |
| 1103 | bool getClippingGroupId(al::PlacementId* groupId, const al::ActorInitInfo& initInfo) { |
| 1104 | return getLinkGroupId(groupId, initInfo, linkName: "GroupClipping" ); |
| 1105 | } |
| 1106 | |
| 1107 | al::PlacementId* createClippingViewId(const al::PlacementInfo& placementInfo) { |
| 1108 | al::PlacementId* id = new al::PlacementId(); |
| 1109 | al::PlacementInfo info; |
| 1110 | if (al::tryGetLinksInfo(railPlacementInfo: &info, placementInfo, linkName: "ViewGroup" )) |
| 1111 | id->init(info); |
| 1112 | return id; |
| 1113 | } |
| 1114 | |
| 1115 | bool getClippingViewId(al::PlacementId* viewId, const al::PlacementInfo& placementInfo) { |
| 1116 | al::PlacementInfo info; |
| 1117 | if (al::tryGetLinksInfo(railPlacementInfo: &info, placementInfo, linkName: "ViewGroup" ) && |
| 1118 | al::tryGetPlacementId(placementId: viewId, placementInfo: info)) |
| 1119 | return true; |
| 1120 | return false; |
| 1121 | } |
| 1122 | |
| 1123 | bool getClippingViewId(al::PlacementId* viewId, const al::ActorInitInfo& initInfo) { |
| 1124 | return getClippingViewId(viewId, placementInfo: *initInfo.placementInfo); |
| 1125 | } |
| 1126 | |
| 1127 | void getModelName(const char** modelName, const al::ActorInitInfo& initInfo) { |
| 1128 | getModelName(modelName, placementInfo: *initInfo.placementInfo); |
| 1129 | } |
| 1130 | |
| 1131 | void getModelName(const char** modelName, const al::PlacementInfo& placementInfo) { |
| 1132 | tryGetModelName(modelName, placementInfo); |
| 1133 | } |
| 1134 | |
| 1135 | bool tryGetModelName(const char** modelName, const al::PlacementInfo& placementInfo) { |
| 1136 | return tryGetStringArg(arg: modelName, initInfo: placementInfo, key: "ModelName" ) || |
| 1137 | tryGetStringArg(arg: modelName, initInfo: placementInfo, key: "ArchiveName" ); |
| 1138 | } |
| 1139 | |
| 1140 | bool tryGetModelName(const char** modelName, const al::ActorInitInfo& initInfo) { |
| 1141 | return tryGetModelName(modelName, placementInfo: *initInfo.placementInfo); |
| 1142 | } |
| 1143 | |
| 1144 | } // namespace alPlacementFunction |
| 1145 | |