diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 30aaba59..cf37082a 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -9,67 +9,6 @@ #include "Generic.h" #include "NpcAct.h" -NPC_TABLE *gNpcTable; - -BOOL LoadNpcTable(const char *path) -{ - FILE *fp; - int n; - int num; - size_t size; - - size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not - if (size == INVALID_FILE_SIZE) - return FALSE; - - num = (int)(size / 0x18); - - gNpcTable = (NPC_TABLE*)malloc(num * sizeof(NPC_TABLE)); - if (gNpcTable == NULL) - return FALSE; - - fp = fopen(path, "rb"); - if (fp == NULL) - { - free(gNpcTable); - gNpcTable = NULL; - return FALSE; - } - - for (n = 0; n < num; ++n) // bits - fread(&gNpcTable[n].bits, 2, 1, fp); - for (n = 0; n < num; ++n) // life - fread(&gNpcTable[n].life, 2, 1, fp); - for (n = 0; n < num; ++n) // surf - fread(&gNpcTable[n].surf, 1, 1, fp); - for (n = 0; n < num; ++n) // destroy_voice - fread(&gNpcTable[n].destroy_voice, 1, 1, fp); - for (n = 0; n < num; ++n) // hit_voice - fread(&gNpcTable[n].hit_voice, 1, 1, fp); - for (n = 0; n < num; ++n) // size - fread(&gNpcTable[n].size, 1, 1, fp); - for (n = 0; n < num; ++n) // exp - fread(&gNpcTable[n].exp, 4, 1, fp); - for (n = 0; n < num; ++n) // damage - fread(&gNpcTable[n].damage, 4, 1, fp); - for (n = 0; n < num; ++n) // hit - fread(&gNpcTable[n].hit, 4, 1, fp); - for (n = 0; n < num; ++n) // view - fread(&gNpcTable[n].view, 4, 1, fp); - - fclose(fp); - return TRUE; -} - -void ReleaseNpcTable(void) -{ - if (gNpcTable != NULL) - { - free(gNpcTable); - gNpcTable = NULL; - } -} - // Npc function table const NPCFUNCTION gpNpcFuncTbl[361] = { ActNpc000, @@ -434,3 +373,64 @@ const NPCFUNCTION gpNpcFuncTbl[361] = { ActNpc359, ActNpc360, }; + +NPC_TABLE *gNpcTable; + +BOOL LoadNpcTable(const char *path) +{ + FILE *fp; + int n; + size_t size; + int num; + + size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not + if (size == INVALID_FILE_SIZE) + return FALSE; + + num = (int)(size / 0x18); + + gNpcTable = (NPC_TABLE*)malloc(num * sizeof(NPC_TABLE)); + if (gNpcTable == NULL) + return FALSE; + + fp = fopen(path, "rb"); + if (fp == NULL) + { + free(gNpcTable); + gNpcTable = NULL; + return FALSE; + } + + for (n = 0; n < num; ++n) // bits + fread(&gNpcTable[n].bits, 2, 1, fp); + for (n = 0; n < num; ++n) // life + fread(&gNpcTable[n].life, 2, 1, fp); + for (n = 0; n < num; ++n) // surf + fread(&gNpcTable[n].surf, 1, 1, fp); + for (n = 0; n < num; ++n) // destroy_voice + fread(&gNpcTable[n].destroy_voice, 1, 1, fp); + for (n = 0; n < num; ++n) // hit_voice + fread(&gNpcTable[n].hit_voice, 1, 1, fp); + for (n = 0; n < num; ++n) // size + fread(&gNpcTable[n].size, 1, 1, fp); + for (n = 0; n < num; ++n) // exp + fread(&gNpcTable[n].exp, 4, 1, fp); + for (n = 0; n < num; ++n) // damage + fread(&gNpcTable[n].damage, 4, 1, fp); + for (n = 0; n < num; ++n) // hit + fread(&gNpcTable[n].hit, 4, 1, fp); + for (n = 0; n < num; ++n) // view + fread(&gNpcTable[n].view, 4, 1, fp); + + fclose(fp); + return TRUE; +} + +void ReleaseNpcTable(void) +{ + if (gNpcTable != NULL) + { + free(gNpcTable); + gNpcTable = NULL; + } +}