Collab_RPG/src/npc.h

81 lines
1.8 KiB
C
Raw Normal View History

#ifndef NPC_H
#define NPC_H
#include <stdbool.h>
#include <stdint.h>
#include "game.h"
#include "memory.h"
2024-07-29 11:36:11 +02:00
enum {
2024-07-21 02:42:50 +02:00
NPC_NONE = 0,
2024-07-29 11:36:11 +02:00
NPC_FRIENDLY = 1, // The player's team
NPC_HOSTILE = 2, // to the player
2024-07-21 02:42:50 +02:00
NPC_ALL = 3
2024-07-23 18:17:02 +02:00
};
2024-07-29 11:36:11 +02:00
typedef struct {
/* current coordinates of the NPC */
float curx, cury;
2024-07-29 11:36:11 +02:00
/* initial coordinates of the NPC (needed to get absolute coordinates of
* path) */
uint32_t x;
uint32_t y;
/* the ID of the first element of the dialog */
/* (to be aligned with "dialogs.json" IDs)*/
uint32_t dialogID;
/* the number of the target point of the path */
/* Note: it must keep the value 0 if NPC has no path assigned */
uint32_t currentPoint;
/* data of the path */
uint32_t hasPath;
uint32_t path_length;
int16_t *xpath;
int16_t *ypath;
2024-07-27 14:02:04 +02:00
int type;
2024-07-21 02:42:50 +02:00
2024-07-27 14:02:04 +02:00
int8_t current_group;
int8_t hostile_to_group;
2024-07-21 02:42:50 +02:00
/* is the current NPC in pause (during dialog) */
bool paused;
2024-07-27 14:02:04 +02:00
2024-07-26 17:01:51 +02:00
char *face;
} NPC;
2024-07-29 11:36:11 +02:00
// Frees then malloc()s a new path to npc
// Useful if you want to safely edit a path
int npc_clear_path(NPC *npc);
2024-07-29 11:36:11 +02:00
// Adds point x,y to the path of npc
// Won't work on static NPCs, use npc_clear_path before or make them on the heap
int npc_append_path(uint16_t x, uint16_t y, NPC *npc);
2024-07-29 11:36:11 +02:00
// Clears the NPCs path and creates a new one going to dest,
// avoiding non-walkable tiles
// Returns non-zero on failure
2024-07-27 14:02:04 +02:00
int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc);
2024-07-29 11:36:11 +02:00
// realloc()s npcRPG to adequate size and returns a pointer to the new element
// Returns NULL on failure
2024-07-27 14:02:04 +02:00
NPC *npc_create();
2024-07-29 11:36:11 +02:00
// Pops the NPC from npcRPG
2024-07-27 14:02:04 +02:00
void npc_remove(NPC *npc);
/* Draws the player player. This function should be called after drawing the
* map! */
void npc_draw(Game *game);
2024-07-21 02:42:50 +02:00
void update_npcs(Game *game);
void update_npc(NPC *npc);
void reload_npc(Game *game);
#endif