Skip to content

Commit

Permalink
wip: fix (!?) flame emitters and fx in savefile
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Aug 27, 2023
1 parent ce2618f commit d4a96ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/game/objects/traps/flame.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#define FLAME_ONFIRE_DAMAGE 5
#define FLAME_TOONEAR_DAMAGE 3

#include "log.h"


void Flame_Setup(OBJECT_INFO *obj)
{
obj->control = Flame_Control;
Expand Down Expand Up @@ -82,6 +85,7 @@ void Flame_Control(int16_t fx_num)
fx->counter = 100;

fx_num = Effect_Create(g_LaraItem->room_number);
LOG_DEBUG("? create flame: %d", fx_num);
if (fx_num != NO_ITEM) {
fx = &g_Effects[fx_num];
fx->frame_number = 0;
Expand All @@ -105,6 +109,7 @@ void FlameEmitter_Control(int16_t item_num)
if (Item_IsTriggerActive(item)) {
if (!item->data) {
int16_t fx_num = Effect_Create(item->room_number);
LOG_DEBUG("emitter %d create flame: %d", item_num, fx_num);
if (fx_num != NO_ITEM) {
FX_INFO *fx = &g_Effects[fx_num];
fx->pos.x = item->pos.x;
Expand All @@ -115,10 +120,12 @@ void FlameEmitter_Control(int16_t item_num)
fx->counter = 0;
}
item->data = (void *)(fx_num + 1);
LOG_DEBUG("emitter %d create item->data: %d", item_num, (int16_t)(size_t)item->data);
}
} else if (item->data) {
Sound_StopEffect(SFX_FIRE, NULL);
Effect_Kill((int16_t)(size_t)item->data - 1);
LOG_DEBUG("emitter %d kill flame: %d", item_num, (int16_t)(size_t)item->data - 1);
item->data = NULL;
}
}
21 changes: 17 additions & 4 deletions src/game/savegame/savegame_bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ static bool Savegame_BSON_LoadItems(struct json_array_s *items_arr)
int32_t flame_num =
json_object_get_int(item_obj, "flame_num", 0);
item->data = (void *)flame_num;
LOG_DEBUG("Load flame: %d", flame_num);
}
}
}
Expand Down Expand Up @@ -615,6 +616,11 @@ static bool SaveGame_BSON_LoadFx(struct json_array_s *fx_arr)
}
}

for (int16_t linknum = g_NextFxActive; linknum != NO_ITEM;
linknum = g_Effects[linknum].next_active) {
LOG_DEBUG("linknum: %d; next_active: %d; object_number: %d;", linknum, g_Effects[linknum].next_active, g_Effects[linknum].object_number);
}

return true;
}

Expand Down Expand Up @@ -1037,8 +1043,12 @@ static struct json_array_s *Savegame_BSON_DumpItems(void)
}

if (item->object_number == O_FLAME_EMITTER) {
if (item->data == NULL) {
LOG_DEBUG("NULL.");
}
int32_t flame_num = (int32_t)item->data;
json_object_append_int(item_obj, "flame_num", flame_num);
LOG_DEBUG("Save flame: %d", flame_num);
}
}

Expand All @@ -1052,18 +1062,21 @@ static struct json_array_s *SaveGame_BSON_DumpFx(void)
struct json_array_s *fx_arr = json_array_new();

// Reverse FX array before saving to save in proper order.
int16_t remap_effects[NUM_EFFECTS];
// int16_t remap_effects[NUM_EFFECTS];
int32_t fx_count = 0;
for (int16_t linknum = g_NextFxActive; linknum != NO_ITEM;
linknum = g_Effects[linknum].next_active) {
remap_effects[fx_count] = linknum;
LOG_DEBUG("linknum: %d; next_active: %d; object_number: %d;", linknum, g_Effects[linknum].next_active, g_Effects[linknum].object_number);
// remap_effects[fx_count] = linknum;
fx_count++;
}

for (int32_t i = fx_count - 1; i >= 0; i--) {
for (int32_t i = 0; i < fx_count; i++) {
struct json_object_s *fx_obj = json_object_new();

FX_INFO *fx = &g_Effects[remap_effects[i]];
FX_INFO *fx = &g_Effects[i];
LOG_DEBUG("Save g_Effects[i]: %d; object_number: %d;", i, g_Effects[i].object_number);

json_object_append_int(fx_obj, "x", fx->pos.x);
json_object_append_int(fx_obj, "y", fx->pos.y);
json_object_append_int(fx_obj, "z", fx->pos.z);
Expand Down

0 comments on commit d4a96ba

Please sign in to comment.