diff --git a/assets/converters.py b/assets/converters.py index da2c3f1..0fdc733 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -152,17 +152,25 @@ 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 = None + path = object.get_data() if int(object.get_property("hasPath")): if object.get_property("path") in npc_paths: path = npc_paths[object.get_property("path")] else: raise Exception("Path required but not found!") + dialog_id = 0 + has_dialog = 0 + try: + dialog_id = int(object.get_property("dialogID")) + has_dialog = 1 + except: + pass data = { "position": object.get_data(), "name": object.name, "needAction": int(object.get_property("needAction")), - "dialogID": int(object.get_property("dialogID")), + "dialogID": dialog_id, + "hasDialog": has_dialog, "face": FACES.index(object.get_property("face")), "path": path } @@ -200,10 +208,41 @@ def convert_map(input, output, params, target): map_struct += fxconv.ptr(walkable_data) # Load NPCs - map_struct += fxconv.u32(0) # TODO: NPC support in-game - map_struct += fxconv.ptr(bytes()) + 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]) + npc_struct += fxconv.u32(i["position"][1]) + npc_struct += fxconv.u16(i["face"]) + npc_struct += fxconv.u8(0) + npc_struct += fxconv.u8(i["hasDialog"]) + npc_struct += fxconv.u32(i["dialogID"]) + npc_struct += fxconv.u32(i["needAction"]) + npc_struct += fxconv.string(i["name"]) + npc_struct += fxconv.u32(len(i["path"]) > 2) + npc_struct += fxconv.u32(len(i["path"])//2) + npc_struct += fxconv.u32(0) + + xpath = bytes() + ypath = bytes() + x = True + for n in i["path"]: + if x: xpath += fxconv.u16(n) + else: ypath += fxconv.u16(n) + x = not x + + npc_struct += fxconv.ptr(xpath) + npc_struct += fxconv.ptr(ypath) + + npc_struct += fxconv.u32(0) # TODO: Type + npc_struct += fxconv.u8(0) # TODO: Group + npc_struct += fxconv.u8(0) # TODO: Hostile to + npc_struct += fxconv.u16(0) # TODO: Padding (what is it ?) + map_struct += fxconv.ptr(npc_struct) # Load signs - map_struct += fxconv.u32(len(signs)) # TODO: Sign support in-game + map_struct += fxconv.u32(len(signs)) sign_struct = fxconv.Structure() for i in signs.values(): sign_struct += fxconv.u32(i["position"][0]) diff --git a/src/game.c b/src/game.c index 9a5577c..e600ac6 100644 --- a/src/game.c +++ b/src/game.c @@ -24,7 +24,7 @@ void interaction_available(Game *game) { /*NPCs take priority over signs*/ for(uint32_t i = 0; i < game->map_level->nbNPC; i++) { - if(!game->map_level->npcs[i].has_dialogue) + if(!game->map_level->npcs[i].has_dialog) continue; /* simple distance check along X and Y axis */ diff --git a/src/game.h b/src/game.h index 306c464..4eea9f3 100644 --- a/src/game.h +++ b/src/game.h @@ -72,7 +72,8 @@ typedef struct { typedef struct { /* current coordinates of the NPC */ - float curx, cury; + uint32_t curx; /* Initialize them at runtime */ + uint32_t cury; /* Initialize them at runtime */ /* initial coordinates of the NPC (needed to get absolute coordinates of * path) */ @@ -83,7 +84,7 @@ typedef struct { uint8_t paused; - uint8_t has_dialogue; + uint8_t has_dialog; /* the ID of the first element of the dialog */ /* (to be aligned with "dialogs.json" IDs)*/ uint32_t dialogID; @@ -99,7 +100,7 @@ typedef struct { int16_t *xpath; int16_t *ypath; - int type; + int type : 32; uint8_t current_group; uint8_t hostile_to_group;