Skip to content

Commit 54fb74f

Browse files
committed
Adds Red Coin and Star Dev Tools and completes the CustomItem.
1 parent cc77dfb commit 54fb74f

11 files changed

Lines changed: 137 additions & 43 deletions

File tree

levels/bob/script.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ const LevelScript level_bob_entry[] = {
7676
LOAD_MODEL_FROM_GEO(MODEL_BOB_SEESAW_PLATFORM, bob_geo_000458),
7777
LOAD_MODEL_FROM_GEO(MODEL_BOB_BARS_GRILLS, bob_geo_000470),
7878

79-
LOAD_MODEL_FROM_GEO(MODEL_STAR, star_geo),
80-
LOAD_MODEL_FROM_GEO(MODEL_RED_COIN, red_coin_geo),
81-
8279
AREA(/*index*/ 1, bob_geo_000488),
8380
JUMP_LINK(script_func_local_1),
8481
JUMP_LINK(script_func_local_2),

src/engine/level_script.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,9 @@ static void level_cmd_place_object(void) {
463463
spawnInfo->behaviorScript = CMD_GET(void*, 20);
464464

465465
spawnInfo->model = gLoadedGraphNodes[model];
466-
466+
467467
spawnInfo->next = gAreas[sCurrAreaIndex].objectSpawnInfos;
468-
468+
469469
gAreas[sCurrAreaIndex].objectSpawnInfos = spawnInfo;
470470
}
471471

@@ -826,6 +826,7 @@ struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {
826826

827827
while (sScriptStatus == SCRIPT_RUNNING) {
828828
LevelScriptJumpTable[sCurrentCmd->type]();
829+
CALL_EVENT(LevelScriptExecute, sCurrentCmd->type);
829830
}
830831

831832
profiler_log_thread5_time(LEVEL_SCRIPT_EXECUTE);

src/game/macro_special_objects.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,29 @@ void spawn_macro_objects(s16 areaIndex, s16 *macroObjList) {
150150
if (((macroObject[MACRO_OBJ_PARAMS] >> 8) & RESPAWN_INFO_DONT_RESPAWN)
151151
!= RESPAWN_INFO_DONT_RESPAWN) {
152152
// Spawn the new macro object.
153-
newObj = spawn_object_abs_with_rot(
154-
&gMacroObjectDefaultParent, // Parent object
155-
0, // Unused
156-
preset.model, // Model ID
157-
preset.behavior, // Behavior address
158-
macroObject[MACRO_OBJ_X], // X-position
159-
macroObject[MACRO_OBJ_Y], // Y-position
160-
macroObject[MACRO_OBJ_Z], // Z-position
161-
0, // X-rotation
162-
convert_rotation(macroObject[MACRO_OBJ_Y_ROT]), // Y-rotation
163-
0 // Z-rotation
164-
);
165-
166-
newObj->oUnk1A8 = macroObject[MACRO_OBJ_PARAMS];
167-
newObj->oBehParams = ((macroObject[MACRO_OBJ_PARAMS] & 0x00FF) << 16)
168-
+ (macroObject[MACRO_OBJ_PARAMS] & 0xFF00);
169-
newObj->oBehParams2ndByte = macroObject[MACRO_OBJ_PARAMS] & 0x00FF;
170-
newObj->respawnInfoType = RESPAWN_INFO_TYPE_16;
171-
newObj->respawnInfo = macroObjList - 1;
172-
newObj->parentObj = newObj;
153+
CALL_CANCELLABLE_EVENT(SpawnMacroObject, preset.model, macroObject[MACRO_OBJ_X], macroObject[MACRO_OBJ_Y],
154+
macroObject[MACRO_OBJ_Z]) {
155+
newObj = spawn_object_abs_with_rot(
156+
&gMacroObjectDefaultParent, // Parent object
157+
0, // Unused
158+
preset.model, // Model ID
159+
preset.behavior, // Behavior address
160+
macroObject[MACRO_OBJ_X], // X-position
161+
macroObject[MACRO_OBJ_Y], // Y-position
162+
macroObject[MACRO_OBJ_Z], // Z-position
163+
0, // X-rotation
164+
convert_rotation(macroObject[MACRO_OBJ_Y_ROT]), // Y-rotation
165+
0 // Z-rotation
166+
);
167+
168+
newObj->oUnk1A8 = macroObject[MACRO_OBJ_PARAMS];
169+
newObj->oBehParams = ((macroObject[MACRO_OBJ_PARAMS] & 0x00FF) << 16)
170+
+ (macroObject[MACRO_OBJ_PARAMS] & 0xFF00);
171+
newObj->oBehParams2ndByte = macroObject[MACRO_OBJ_PARAMS] & 0x00FF;
172+
newObj->respawnInfoType = RESPAWN_INFO_TYPE_16;
173+
newObj->respawnInfo = macroObjList - 1;
174+
newObj->parentObj = newObj;
175+
}
173176
}
174177
}
175178
}

src/port/Rando/ActorBehavior/ActorBehavior.cpp

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include "port/hooks/list/PlayerEvent.h"
55
#include "port/mods/PortEnhancements.h"
66
#include "include/behavior_data.h"
7+
#include "port/hooks/list/EngineEvent.h"
8+
#include "include/level_commands.h"
9+
#include "assets/actors/star/geo.h"
10+
#include "assets/actors/coin/geo.h"
11+
static bool isInitialized = false;
712

813
// TODO: Need to possibly set behaviorArg to fix Star on Red Coin spawn behavior.
914
// - Star will spin on an alternate axis and be uncollectable.
@@ -17,35 +22,65 @@ void LogOutSpawns(std::string type, int16_t model, int16_t posX, int16_t posY, i
1722
SPDLOG_INFO("Type: {} | Model: {} | Position: {}", type, model, locationStr);
1823
}
1924

20-
void ModifySpawnedObject(bool* shouldCancel, struct SpawnInfo* spawnInfo) {
25+
// void ModifySpawnedObject(bool* shouldCancel, struct SpawnInfo* spawnInfo) {
26+
// RandoCheckId randoCheckId =
27+
// Rando::StaticData::GetCheckByLocation(spawnInfo->startPos[0], spawnInfo->startPos[1], spawnInfo->startPos[2]);
28+
// if (randoCheckId == RC_UNKNOWN || !Rando::StaticData::IsCheckShuffled(randoCheckId)) {
29+
// *(shouldCancel) = false;
30+
// return;
31+
// }
32+
//
33+
// RandoItemId randoItemId = Rando::StaticData::GetShuffledRandoItem(randoCheckId);
34+
// if (randoItemId == RI_UNKNOWN) {
35+
// return;
36+
// }
37+
//
38+
// int32_t modelId = Rando::StaticData::GetModelByRandoItem(randoItemId);
39+
// const BehaviorScript* behavior = Rando::StaticData::GetBehaviorByModel(modelId);
40+
//
41+
// CustomItem::Spawn(modelId, behavior, spawnInfo->startPos[0], spawnInfo->startPos[1], spawnInfo->startPos[2]);
42+
// *(shouldCancel) = true;
43+
// }
44+
45+
void ModifySpawnedObject(bool* shouldCancel, s16 x, s16 y, s16 z) {
2146
RandoCheckId randoCheckId =
22-
Rando::StaticData::GetCheckByLocation(spawnInfo->startPos[0], spawnInfo->startPos[1], spawnInfo->startPos[2]);
47+
Rando::StaticData::GetCheckByLocation(x, y, z);
2348
if (randoCheckId == RC_UNKNOWN || !Rando::StaticData::IsCheckShuffled(randoCheckId)) {
2449
*(shouldCancel) = false;
2550
return;
2651
}
2752

2853
RandoItemId randoItemId = Rando::StaticData::GetShuffledRandoItem(randoCheckId);
29-
if (randoItemId != RI_UNKNOWN) {
30-
spawnInfo->behaviorScript = segmented_to_virtual(
31-
Rando::StaticData::GetBehaviorByModel(Rando::StaticData::GetModelByRandoItem(randoItemId)));
32-
spawnInfo->model = NULL;
33-
spawnInfo->behaviorArg = (u32)randoItemId;
54+
if (randoItemId == RI_UNKNOWN) {
55+
return;
3456
}
35-
CustomItem::Spawn(spawnInfo);
57+
58+
int32_t modelId = Rando::StaticData::GetModelByRandoItem(randoItemId);
59+
const BehaviorScript* behavior = Rando::StaticData::GetBehaviorByModel(modelId);
60+
61+
CustomItem::Spawn(modelId, behavior, x, y, z);
3662
*(shouldCancel) = true;
3763
}
3864

3965
// Entry point for the module, run once on game boot
4066
void Rando::ActorBehavior::Init() {
41-
REGISTER_LISTENER(SpawnObject, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
42-
SpawnObject* ev = (SpawnObject*)event;
67+
// REGISTER_LISTENER(SpawnObject, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
68+
// SpawnObject* ev = (SpawnObject*)event;
69+
// if (!IS_RANDO(selectedFileNum)) {
70+
// return;
71+
// }
72+
// LogOutSpawns("Object", (int16_t)ev->spawnInfo->model, ev->spawnInfo->startPos[0], ev->spawnInfo->startPos[1],
73+
// ev->spawnInfo->startPos[2]);
74+
// ModifySpawnedObject(&event->cancelled, ev->spawnInfo);
75+
// });
76+
77+
REGISTER_LISTENER(SpawnMacroObject, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
78+
SpawnMacroObject* ev = (SpawnMacroObject*)event;
4379
if (!IS_RANDO(selectedFileNum)) {
4480
return;
4581
}
46-
LogOutSpawns("Object", (int16_t)ev->spawnInfo->model, ev->spawnInfo->startPos[0], ev->spawnInfo->startPos[1],
47-
ev->spawnInfo->startPos[2]);
48-
ModifySpawnedObject(&event->cancelled, ev->spawnInfo);
82+
LogOutSpawns("Object", (int16_t)ev->model, ev->posX, ev->posY, ev->posZ);
83+
ModifySpawnedObject(&event->cancelled, ev->posX, ev->posY, ev->posZ);
4984
});
5085

5186
REGISTER_LISTENER(SpawnStar, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
@@ -56,4 +91,17 @@ void Rando::ActorBehavior::Init() {
5691

5792
LogOutSpawns("Star", MODEL_STAR, ev->posX, ev->posY, ev->posZ);
5893
});
94+
95+
REGISTER_LISTENER(LevelScriptExecute, EVENT_PRIORITY_NORMAL, [](IEvent* event) {
96+
LevelScriptExecute* ev = (LevelScriptExecute*)event;
97+
if (isInitialized || ev->command != 36) {
98+
return;
99+
}
100+
101+
if (!isInitialized) {
102+
LOAD_MODEL_FROM_GEO(MODEL_STAR, star_geo);
103+
LOAD_MODEL_FROM_GEO(MODEL_RED_COIN, red_coin_geo);
104+
isInitialized = true;
105+
}
106+
});
59107
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#include "CustomItem.h"
22

3-
void CustomItem::Spawn(struct ::SpawnInfo* spawnInfo) {
4-
// TODO: Create and Spawn a Custom Item
3+
extern "C" {
4+
#include "game/object_list_processor.h"
5+
#include "include/behavior_data.h"
6+
#include "game/level_update.h"
7+
#include "game/object_helpers.h"
8+
}
9+
10+
void CustomItem::Spawn(u32 modelId, const BehaviorScript* behavior, s16 x, s16 y, s16 z) {
11+
spawn_object_abs_with_rot(&gMacroObjectDefaultParent, 0, modelId, behavior, x, y, z, 0, 0, 0);
512
}

src/port/Rando/CustomItem/CustomItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ extern "C" {
77

88
namespace CustomItem {
99

10-
void Spawn(struct ::SpawnInfo* spawnInfo);
10+
void Spawn(u32 modelId, const BehaviorScript* behavior, s16 x, s16 y, s16 z);
1111
}; // namespace CustomItem

src/port/Rando/Rando.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "Rando.h"
2+
#include <ship/Context.h>
23
#include "port/mods/PortEnhancements.h"
34
// #include "2s2h/GameInteractor/GameInteractor.h"
45
#include "ActorBehavior/ActorBehavior.h"
56
#include "MiscBehavior/MiscBehavior.h"
67
// #include "Rando/Spoiler/Spoiler.h"
78
// #include "Rando/CheckTracker/CheckTracker.h"
89
#include "port/ShipInit.hpp"
9-
// #include <ship/window/FileDropMgr.h>
10-
#include <ship/Context.h>
10+
1111

1212
int16_t selectedFileNum = 0;
1313

src/port/hooks/list/EngineEvent.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ DEFINE_EVENT(LevelScriptBeginArea,
2424
DEFINE_EVENT(GeoLayoutCallASM,
2525
GraphNodeFunc* func;
2626
int16_t* parameter;
27+
);
28+
29+
// new
30+
DEFINE_EVENT(LevelScriptExecute,
31+
u8 command;
2732
);

src/port/hooks/list/PlayerEvent.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ DEFINE_EVENT(SpawnObject,
1818
struct SpawnInfo *spawnInfo;
1919
);
2020

21+
DEFINE_EVENT(SpawnMacroObject,
22+
int16_t model;
23+
int16_t posX;
24+
int16_t posY;
25+
int16_t posZ;
26+
);
27+
2128
DEFINE_EVENT(SpawnStar,
2229
f32 posX;
2330
f32 posY;

src/port/mods/PortEnhancements.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ void PortEnhancements_Register() {
8282
REGISTER_EVENT(GeoLayoutCallASM);
8383
REGISTER_EVENT(LevelScriptCallLoop);
8484
REGISTER_EVENT(LevelScriptBeginArea);
85+
REGISTER_EVENT(LevelScriptExecute);
8586
REGISTER_EVENT(RenderPauseCourseOptions);
8687

8788
REGISTER_EVENT(PlayerHealthChange);
8889
REGISTER_EVENT(PlayerLivesChange);
8990
REGISTER_EVENT(SpawnObject);
91+
REGISTER_EVENT(SpawnMacroObject);
9092
REGISTER_EVENT(SpawnStar);
9193
REGISTER_EVENT(OnGameFileLoad);
9294
REGISTER_EVENT(OnGameFileSave);

0 commit comments

Comments
 (0)