Files
oboe/Blades of Exile/tools/mathutil.cpp
Celtic Minstrel cf433e773d Well, at present the Windows code for the actual game almost compiles. The current goal is to undo all the things that Ormus did to make this job difficult.
Basically, remove as many as possible of the dependencies of the source files in the tools and classes folders on source files not in those folders.
(With the exception that files in the classes folder may depend on files in the tools folder.)

In this commit, several changes were made.
- Project file modified, may need further modification.
- Many files renamed to match the Mac version.
- #include statements for system headers changed to use <> instead of "" (some already did, but many didn't).
- xxx.h headers replaced with cxxx headers where appropriate.
- Most sound-related variables moved from globvars.cpp to soundvars.cpp.
- The files originally named graphutil and gutils have been merged.
- Changed TRUE/FALSE to true/false.
- Changed exlsound to soundtool and mostly removed dependencies on the main game files; the exception is that it still uses mainPtr (which probably can't be helped)
  and print_nums (which should probably be incorporated into the MessageBox string).
- Possibly other things that were forgotten.

For some reason this commit also includes changes recently committed into the branch for osx.

git-svn-id: http://openexile.googlecode.com/svn/trunk@121 4ebdad44-0ea0-11de-aab3-ff745001d230
2009-08-03 19:00:23 +00:00

70 lines
1.1 KiB
C++

/*
* mathutil.cpp
* BoE
*
* Created by Celtic Minstrel on 16/04/09.
*
*/
#include <cstdlib>
#include "mathutil.h"
short get_ran (short times,short min,short max){
long int store;
short i, to_ret = 0;
if(max < min) max = min;
for (i = 1; i < times + 1; i++) {
store = rand();
to_ret += min + (store % (max - min + 1));//min + (((store + 32767) * (max - min + 1)) / 65536);
}
return to_ret;
}
short s_pow(short x,short y){
return (short) pow((double) x, (double) y);
}
short s_sqrt(short val)
{
return (short) sqrt((double)(val));
}
short max(short a,short b){
if (a > b)
return a;
else return b;
}
short min(short a,short b){
if (a < b)
return a;
else return b;
}
short minmax(short min,short max,short k){
if (k < min)
return min;
if (k > max)
return max;
return k;
}
short move_to_zero(short val){
if (val < 0)
return val + 1;
if (val > 0)
return val - 1;
return val;
}
short gcd(short a, short b){ // Grabbed from Wikipedia and translated to C code
short t;
while(b != 0){
t = b;
b = a % b;
a = t;
}
return a;
}