From: Lukas Krickl Date: Sun, 22 Feb 2026 08:20:00 +0000 (+0100) Subject: engine: wip utility functions X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=07763cd89c030aa256f2fb060f97c2cc19f04447;p=lrts%2F.git engine: wip utility functions --- diff --git a/src/lrts.h b/src/lrts.h index 4e5d9c9..704d0a1 100644 --- a/src/lrts.h +++ b/src/lrts.h @@ -36,9 +36,10 @@ #endif -#include "t_actor.c" +#include "t_unit.c" #include "u_rand.c" #include "n_conn.c" +#include "u_math.c" #endif diff --git a/src/t_actor.c b/src/t_actor.c deleted file mode 100644 index d948cdd..0000000 --- a/src/t_actor.c +++ /dev/null @@ -1 +0,0 @@ -#include "t_actor.h" diff --git a/src/t_actor.h b/src/t_actor.h deleted file mode 100644 index 224053e..0000000 --- a/src/t_actor.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef T_ACTOR_H__ -#define T_ACTOR_H__ - -enum t_actor_flags { - T_ACTOR_F_NONE = 0 -}; - -/** - * Character stats - */ -struct t_stats { - /** - * base stats - */ - short str; - short wis; - short agi; - short vit; - - /* resistances */ - short poison_res; - short fire_res; - short holy_res; - short chaos_res; - - /* damage stats */ - unsigned int physical_damage; - unsigned int magic_damage; - - /* misc */ - unsigned char tohit; -}; - -/* current actor state - * this struct mostly contains - * mutable variables related to an actor - */ -struct t_actor_state { - int hp; - int mp; - int level; - int xp; -}; - -enum t_actor_type { - T_ACTOR_TYPE_PLAYER, - T_ACTOR_TYPE_PET -}; - -struct t_actor { - unsigned int id; - enum t_actor_type type; - - unsigned short faction_id; - - struct t_stats stats; - struct t_actor_state state; -}; - - -#endif diff --git a/src/t_command.h b/src/t_command.h new file mode 100644 index 0000000..c059cf1 --- /dev/null +++ b/src/t_command.h @@ -0,0 +1,33 @@ +#ifndef T_COMMAND_H__ +#define T_COMMAND_H__ + +/** + * A command is an order for a unit. + * each unit has a command queue. + */ + +#define T_COMMANDS_MAX 8 + +enum t_command_type { + T_COMMAND_NONE = 0 +}; + +enum t_command_flags { + T_COMMAND_F_NONE = 0 +}; + +struct t_command { + enum t_command_type type; + enum t_command_flags flags; +}; + +/** + * This is a comamnd buffer + * It wraps around and keeps track of the current command + */ +struct t_command_queue { + u8 current; + struct t_command buffer[T_COMMANDS_MAX]; +}; + +#endif diff --git a/src/t_unit.c b/src/t_unit.c new file mode 100644 index 0000000..a29f38e --- /dev/null +++ b/src/t_unit.c @@ -0,0 +1 @@ +#include "t_unit.h" diff --git a/src/t_unit.h b/src/t_unit.h new file mode 100644 index 0000000..6335bbe --- /dev/null +++ b/src/t_unit.h @@ -0,0 +1,44 @@ +#ifndef T_UNIT_H__ +#define T_UNIT_H__ + +#include "t_command.h" +#include "u_defs.h" + +enum t_unit_flags { + T_UNIT_F_NONE = 0 +}; + +enum t_unit_type { + T_UNIT_TYPE_NONE = 0 +}; + +/* unit damage type */ +enum t_unit_damage_type { + T_UNIT_SLASHING, + T_UNIT_PIERCING, + T_UNIT_SIEGE +}; + +struct t_unit { + unsigned int id; + enum t_unit_type type; + enum t_unit_flags flags; + + i16 view_radius; + + i16 hp; + i16 hp_max; + i16 armor; + + /* Unit damage type and damage range */ + i16 damage_min; + i16 damage_max; + enum t_unit_damage_type damage_type; + + /* a unit can be reistant to certain damage types */ + enum t_unit_damage_type res; + + struct t_command_queue commands; +}; + +#endif diff --git a/src/u_math.c b/src/u_math.c new file mode 100644 index 0000000..a1af48a --- /dev/null +++ b/src/u_math.c @@ -0,0 +1,31 @@ +#include "u_math.h" + +struct u_fp u_fp_add(struct u_fp a, struct u_fp b) { + struct u_fp c = U_FP(0, 0); + lrts_todo(""); + return c; +} + +struct u_fp u_fp_sub(struct u_fp a, struct u_fp b) { + struct u_fp c = U_FP(0, 0); + lrts_todo(""); + return c; +} + +struct u_fp u_fp_mul(struct u_fp a, struct u_fp b) { + struct u_fp c = U_FP(0, 0); + lrts_todo(""); + return c; +} + +struct u_fp u_fp_div(struct u_fp a, struct u_fp b) { + struct u_fp c = U_FP(0, 0); + lrts_todo(""); + return c; +} + +struct u_fp u_fp_mod(struct u_fp a, struct u_fp b) { + struct u_fp c = U_FP(0, 0); + lrts_todo(""); + return c; +} diff --git a/src/u_math.h b/src/u_math.h new file mode 100644 index 0000000..1ce953c --- /dev/null +++ b/src/u_math.h @@ -0,0 +1,21 @@ +#ifndef U_MATH_H__ +#define U_MATH_H__ + +#define U_FP(n, f) {n, f} + +/* fixed point number + * n: whole part + * f: fractional part + */ +struct u_fp { + u16 n; + u16 f; +}; + +struct u_fp u_fp_add(struct u_fp a, struct u_fp b); +struct u_fp u_fp_sub(struct u_fp a, struct u_fp b); +struct u_fp u_fp_mul(struct u_fp a, struct u_fp b); +struct u_fp u_fp_div(struct u_fp a, struct u_fp b); +struct u_fp u_fp_mod(struct u_fp a, struct u_fp b); + +#endif