comparison src/libmlk-rpg/rpg/battle-entity-state-moving.c @ 384:c458441ff472

rpg: more asserts, const and cleanups
author David Demelier <markand@malikania.fr>
date Sun, 13 Feb 2022 11:34:19 +0100
parents b944cd41e8f9
children 8f59201dc76b
comparison
equal deleted inserted replaced
383:b944cd41e8f9 384:c458441ff472
21 #include <stdlib.h> 21 #include <stdlib.h>
22 22
23 #include <core/alloc.h> 23 #include <core/alloc.h>
24 #include <core/panic.h> 24 #include <core/panic.h>
25 25
26 #include "battle-entity-state-moving.h"
27 #include "battle-entity-state.h"
26 #include "battle-entity.h" 28 #include "battle-entity.h"
27 #include "battle-entity-state.h"
28 #include "battle-entity-state-moving.h"
29 #include "character.h" 29 #include "character.h"
30 #include "walksprite.h" 30 #include "walksprite.h"
31 31
32 #define SPEED 800 32 #define SPEED 800
33 #define SEC 1000 33 #define SEC 1000
68 68
69 void 69 void
70 battle_entity_state_moving_init(struct battle_entity_state_moving *mv, struct battle_entity *et, int dstx, int dsty) 70 battle_entity_state_moving_init(struct battle_entity_state_moving *mv, struct battle_entity *et, int dstx, int dsty)
71 { 71 {
72 assert(mv); 72 assert(mv);
73 assert(et); 73 assert(battle_entity_ok(et));
74 74
75 walksprite_init(&mv->ws, et->ch->sprites[CHARACTER_SPRITE_NORMAL], 40); 75 walksprite_init(&mv->ws, et->ch->sprites[CHARACTER_SPRITE_NORMAL], 40);
76 mv->x = dstx; 76 mv->x = dstx;
77 mv->y = dsty; 77 mv->y = dsty;
78 } 78 }
79 79
80 int 80 int
81 battle_entity_state_moving_update(struct battle_entity_state_moving *mv, struct battle_entity *et, unsigned int ticks) 81 battle_entity_state_moving_update(struct battle_entity_state_moving *mv, struct battle_entity *et, unsigned int ticks)
82 { 82 {
83 assert(mv); 83 assert(mv);
84 assert(et); 84 assert(battle_entity_ok(et));
85 85
86 int step_x, step_y, delta_x, delta_y; 86 int step_x, step_y, delta_x, delta_y;
87 87
88 delta_x = mv->x < et->x ? -1 : +1; 88 delta_x = mv->x < et->x ? -1 : +1;
89 delta_y = mv->y < et->y ? -1 : +1; 89 delta_y = mv->y < et->y ? -1 : +1;
112 } 112 }
113 113
114 void 114 void
115 battle_entity_state_moving(struct battle_entity *et, int dstx, int dsty) 115 battle_entity_state_moving(struct battle_entity *et, int dstx, int dsty)
116 { 116 {
117 assert(et); 117 assert(battle_entity_ok(et));
118 118
119 struct self *self; 119 struct self *self;
120 120
121 self = alloc_new0(sizeof (*self)); 121 self = alloc_new0(sizeof (*self));
122 self->state.data = self; 122 self->state.data = self;