feat: added npc poi for custom npcs

This commit is contained in:
2025-10-05 18:28:58 +01:00
parent e20e537e97
commit b8f47b8f61
5 changed files with 11 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ function V2f V2f_Scale(V2f x, F32 scale) {
} }
V2f NormaliseV2F(V2f x) { V2f NormaliseV2F(V2f x) {
F32 magnitude = sqrtf((x.x * x.x) + (x.y +x.y)); F32 magnitude = sqrtf((x.x * x.x) + (x.y * x.y));
if(magnitude > 0.0){ if(magnitude > 0.0){
F32 inverse = 1.0f/magnitude; F32 inverse = 1.0f/magnitude;
return V2F(x.x*inverse, x.y*inverse); return V2F(x.x*inverse, x.y*inverse);

View File

@@ -66,7 +66,7 @@ int main(int argc, char **argv)
World *world = M_ArenaPush(arena, World); World *world = M_ArenaPush(arena, World);
game->world = world; game->world = world;
world->random = Random_Seed(29237489723847); world->random = Random_Seed(29237489723847);
world->npcCount = 1023; world->npcCount = 100;
for(int i = 0; i < world->npcCount; i++) { for(int i = 0; i < world->npcCount; i++) {
NPC *npc1 = &world->npcs[i]; NPC *npc1 = &world->npcs[i];
npc1->collision.pos.x = 15; npc1->collision.pos.x = 15;

View File

@@ -10,6 +10,8 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
if(npc->waitTime > npc->maxWaitTime) { if(npc->waitTime > npc->maxWaitTime) {
npc->mode = NPC_ACTION_WALKING; npc->mode = NPC_ACTION_WALKING;
// TODO change targets to poi's rather than just random nodes // TODO change targets to poi's rather than just random nodes
// TODO choose either global POI's or use NPC custom poi if
// customPOI is true
do { do {
npc->targetNavNode = Random_U32(&world->random, 0, world->navMesh->nodeCount); npc->targetNavNode = Random_U32(&world->random, 0, world->navMesh->nodeCount);
} while(npc->targetNavNode == npc->currentNavNode); } while(npc->targetNavNode == npc->currentNavNode);
@@ -23,7 +25,7 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
npc->walkTimer = 0; npc->walkTimer = 0;
if(npc->path.nodeCount == npc->pathIndex+1){ if(npc->path.nodeCount == npc->pathIndex+1){
npc->mode = NPC_ACTION_WAITING; npc->mode = NPC_ACTION_WAITING;
npc->maxWaitTime = Random_F32(&world->random, 1, 2); npc->maxWaitTime = Random_F32(&world->random, 20, 140);
npc->waitTime = 0; npc->waitTime = 0;
npc->currentNavNode = npc->targetNavNode; npc->currentNavNode = npc->targetNavNode;
npc->pathIndex = 0; npc->pathIndex = 0;

View File

@@ -5,7 +5,7 @@
#include "npc_look.h" #include "npc_look.h"
#include "../core/types.h" #include "../core/types.h"
#define NPC_SPEED 0.1f #define NPC_SPEED 1.0f
typedef enum NPC_ACTION NPC_ACTION; typedef enum NPC_ACTION NPC_ACTION;
enum NPC_ACTION { enum NPC_ACTION {
@@ -23,6 +23,10 @@ struct NPC {
Str8 name; Str8 name;
NPC_LOOK look; NPC_LOOK look;
bool customPOI;
U32 customPOICount;
U32 npcPOI[16];
//// Actions //// Actions
NPC_ACTION mode; NPC_ACTION mode;
// How long they've been waiting // How long they've been waiting

View File

@@ -24,7 +24,7 @@ struct World {
//// NPCs //// NPCs
U32 npcCount; U32 npcCount;
NPC npcs[1024]; NPC npcs[128];
////Bandit ////Bandit
// The bandit the player is after. // The bandit the player is after.