From 6ab37ee4fb6b9b4947c555d60ae61bdb86d7f622 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:12:55 +0200 Subject: [PATCH] NPCs nearly working --- assets/converters.py | 6 ++-- src/npc.c | 68 -------------------------------------------- 2 files changed, 3 insertions(+), 71 deletions(-) diff --git a/assets/converters.py b/assets/converters.py index 0fdc733..bad536b 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -152,7 +152,7 @@ def convert_map(input, output, params, target): # Get the NPCs for object in ed_objgroup.objects: if object.get_data_type() == "point" and object.type == "NPC": - path = object.get_data() + path = [0, 0] if int(object.get_property("hasPath")): if object.get_property("path") in npc_paths: path = npc_paths[object.get_property("path")] @@ -211,8 +211,8 @@ def convert_map(input, output, params, target): map_struct += fxconv.u32(len(npcs)) npc_struct = fxconv.Structure() for i in npcs.values(): - npc_struct += fxconv.u32(i["path"][0]) - npc_struct += fxconv.u32(i["path"][1]) + npc_struct += fxconv.u32(i["position"][0]+i["path"][0]) + npc_struct += fxconv.u32(i["position"][1]+i["path"][1]) npc_struct += fxconv.u32(i["position"][0]) npc_struct += fxconv.u32(i["position"][1]) npc_struct += fxconv.u16(i["face"]) diff --git a/src/npc.c b/src/npc.c index a7559b2..31e2ff8 100644 --- a/src/npc.c +++ b/src/npc.c @@ -201,30 +201,6 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) { return 3; } -/*NPC *npc_create() { - // Use temp pointer to avoid breaking the whole npcRPG on failure - void *temp = realloc(npcRPG, (nbNPC + 1) * sizeof(NPC)); - if(temp == NULL) - return NULL; - npcRPG = temp; - nbNPC++; - NPC *npc = &npcRPG[nbNPC - 1]; - npc->xpath = malloc(2); - npc->ypath = malloc(2); - return npc; -}*/ - -/*void npc_remove(NPC *npc) { - uint32_t pos = ((uint32_t)npc - (uint32_t)npcRPG) / sizeof(NPC); - if(pos > nbNPC - 1) - return; - if(pos == nbNPC - 1) { - nbNPC--; - return; - } - memmove(npc, &npc[1], (nbNPC - pos - 1) * sizeof(NPC)); -}*/ - // Refactoring to make adding complexity cleaner void update_npcs([[maybe_unused]] Game *game) { for(uint32_t u = 0; u < game->map_level->nbNPC; u++) { @@ -253,50 +229,6 @@ void update_npc(NPC *npc) { npc->cury += vecY; } -/*void reload_npc(Game *game) { - if(npcRPG != NULL) { - free(npcRPG); - npcRPG = NULL; - } - - nbNPC = 0; - - for(uint32_t u = 0; u < game->map_level->nbextradata; u++) { - ExtraData *Data = &game->map_level->extradata[u]; - - if(strcmp(Data->type, "NPC") == 0) - { - nbNPC++; - } - } - - npcRPG = (NPC *)malloc(nbNPC * sizeof(NPC)); - if(npcRPG == NULL) - return; - int currentNPC = 0; - - for(uint32_t u = 0; u < game->map_level->nbextradata; u++) { - ExtraData *Data = &game->map_level->extradata[u]; - - if(strcmp(Data->type, "NPC") == 0) - { - npcRPG[currentNPC].curx = (float)Data->x; - npcRPG[currentNPC].cury = (float)Data->y; - npcRPG[currentNPC].x = Data->x; - npcRPG[currentNPC].y = Data->y; - npcRPG[currentNPC].dialogID = Data->dialogID; - npcRPG[currentNPC].currentPoint = 1; - npcRPG[currentNPC].hasPath = Data->hasPath; - npcRPG[currentNPC].path_length = Data->path_length; - npcRPG[currentNPC].xpath = Data->xpath; - npcRPG[currentNPC].ypath = Data->ypath; - npcRPG[currentNPC].paused = false; - npcRPG[currentNPC].face = Data->face; - currentNPC++; - } - } -}*/ - void npc_draw(Game *game) { Player *pl = &game->player; size_t i;