From a541cf1976e5f5b3bb56bec420ac6edf1f410c3a Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 10 Dec 2015 10:05:00 +0000 Subject: [PATCH] Allow mod to handle floats. --- src/battle/ai.h | 2 +- src/battle/bullets.h | 2 +- src/battle/player.h | 2 +- src/system/util.c | 4 ++-- src/system/widgets.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/battle/ai.h b/src/battle/ai.h index 991957a..dc45dd1 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TURN_SPEED 4 #define TURN_THRESHOLD 2 -extern int mod(int n, int x); +extern float mod(float n, float x); extern int getDistance(int x1, int y1, int x2, int y2); extern void fireGuns(Entity *owner); extern void fireMissile(Entity *owner); diff --git a/src/battle/bullets.h b/src/battle/bullets.h index 5a2841a..f88940f 100644 --- a/src/battle/bullets.h +++ b/src/battle/bullets.h @@ -36,7 +36,7 @@ extern long lookup(char *name); extern char *readFile(char *filename); extern float getAngle(int x1, int y1, int x2, int y2); extern void addMissileEngineEffect(Bullet *b); -extern int mod(int n, int x); +extern float mod(float n, float x); extern void addMissileExplosion(Bullet *b); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); diff --git a/src/battle/player.h b/src/battle/player.h index 6478364..c03caa8 100644 --- a/src/battle/player.h +++ b/src/battle/player.h @@ -29,7 +29,7 @@ extern void applyFighterThrust(void); extern void applyFighterBrakes(void); extern int getDistance(int x1, int y1, int x2, int y2); extern void addHudMessage(SDL_Color c, char *format, ...); -extern int mod(int n, int x); +extern float mod(float n, float x); extern void playSound(int id); extern void failMission(void); extern float getAngle(int x1, int y1, int x2, int y2); diff --git a/src/system/util.c b/src/system/util.c index 8282828..862642d 100644 --- a/src/system/util.c +++ b/src/system/util.c @@ -20,9 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "util.h" -int mod(int n, int x) +float mod(float n, float x) { - return ((n % x) + x) % x; + return fmod(fmod(n, x) + x, x); } int rrnd(int low, int high) diff --git a/src/system/widgets.h b/src/system/widgets.h index b889086..a3444f6 100644 --- a/src/system/widgets.h +++ b/src/system/widgets.h @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern char *readFile(char *filename); extern long lookup(char *name); -extern int mod(int n, int x); +extern float mod(float n, float x); extern void blit(SDL_Texture *texture, int x, int y, int centered); extern SDL_Texture *getTexture(char *filename); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);