mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
npc : npc_remove correct et npc_remove_pos
This commit is contained in:
parent
77d3cc9c9b
commit
66c579db60
3 changed files with 33 additions and 6 deletions
12
src/game.c
12
src/game.c
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "npc.h"
|
|
||||||
#include "mapdata.h"
|
#include "mapdata.h"
|
||||||
|
#include "npc.h"
|
||||||
|
|
||||||
#include <gint/cpu.h>
|
#include <gint/cpu.h>
|
||||||
#include <gint/display.h>
|
#include <gint/display.h>
|
||||||
|
@ -201,11 +201,19 @@ void game_get_inputs(Game *game) {
|
||||||
mynpc->x = player->x;
|
mynpc->x = player->x;
|
||||||
mynpc->y = player->x;
|
mynpc->y = player->x;
|
||||||
mynpc->hasPath = 0;
|
mynpc->hasPath = 0;
|
||||||
mynpc->face = 0;
|
mynpc->face = 1;
|
||||||
mynpc->paused = 0;
|
mynpc->paused = 0;
|
||||||
mynpc->has_dialog = 0;
|
mynpc->has_dialog = 0;
|
||||||
|
mynpc->xpath = NULL;
|
||||||
|
mynpc->ypath = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(keydown(KEY_F2)) {
|
||||||
|
npc_remove_pos(0);
|
||||||
|
/*while(keydown(KEY_F2)) {
|
||||||
|
clearevents();
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
/* Display Debug Information on screen */
|
/* Display Debug Information on screen */
|
||||||
#if DEBUGMODE
|
#if DEBUGMODE
|
||||||
|
|
21
src/npc.c
21
src/npc.c
|
@ -29,15 +29,30 @@ NPC *npc_create() {
|
||||||
void npc_remove(NPC *npc) {
|
void npc_remove(NPC *npc) {
|
||||||
uint32_t pos = (uint32_t)npc - (uint32_t)npc_stack;
|
uint32_t pos = (uint32_t)npc - (uint32_t)npc_stack;
|
||||||
|
|
||||||
if(pos == npc_count) {
|
if(pos >= NPC_STACK_SIZE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(npc->xpath)
|
||||||
|
free(npc->xpath);
|
||||||
|
if(npc->ypath)
|
||||||
|
free(npc->ypath);
|
||||||
|
|
||||||
|
if(pos == NPC_STACK_SIZE) {
|
||||||
|
if(npc_count)
|
||||||
npc_count--;
|
npc_count--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memmove(npc, npc + sizeof(NPC), sizeof(NPC) * (npc_count - pos));
|
uint32_t move_size = sizeof(NPC) * (npc_count - pos);
|
||||||
|
if(move_size + pos > NPC_STACK_SIZE)
|
||||||
|
move_size = NPC_STACK_SIZE - pos;
|
||||||
|
|
||||||
return;
|
memmove(npc, (void *)(npc + sizeof(NPC)), move_size);
|
||||||
|
if(npc_count)
|
||||||
|
npc_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void npc_remove_pos(uint32_t pos) { npc_remove(&npc_stack[pos]); }
|
||||||
|
|
||||||
float length(float x, float y) { return sqrtf(x * x + y * y); }
|
float length(float x, float y) { return sqrtf(x * x + y * y); }
|
||||||
|
|
||||||
int npc_clear_path(NPC *npc) {
|
int npc_clear_path(NPC *npc) {
|
||||||
|
|
|
@ -28,6 +28,10 @@ NPC *npc_create();
|
||||||
* Consider this as a free */
|
* Consider this as a free */
|
||||||
void npc_remove(NPC *npc);
|
void npc_remove(NPC *npc);
|
||||||
|
|
||||||
|
/* Pops the NPC at pos from the NPC stack
|
||||||
|
* Consider this as a free*/
|
||||||
|
void npc_remove_pos(uint32_t pos);
|
||||||
|
|
||||||
/* Frees then malloc()s a new path to npc
|
/* Frees then malloc()s a new path to npc
|
||||||
* Useful if you want to safely edit a path */
|
* Useful if you want to safely edit a path */
|
||||||
int npc_clear_path(NPC *npc);
|
int npc_clear_path(NPC *npc);
|
||||||
|
|
Loading…
Reference in a new issue