summaryrefslogtreecommitdiff
path: root/src/functionrandom.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-31 00:13:13 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-31 00:13:13 -0700
commit55e6f570f5760e970c6523458914b5e4c63a6ce4 (patch)
treeae996d612c6c55b914a960139a618922bf7e4971 /src/functionrandom.cpp
parent3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df (diff)
downloadstage-55e6f570f5760e970c6523458914b5e4c63a6ce4.tar.gz
stage-55e6f570f5760e970c6523458914b5e4c63a6ce4.tar.bz2
stage-55e6f570f5760e970c6523458914b5e4c63a6ce4.tar.xz
stage-55e6f570f5760e970c6523458914b5e4c63a6ce4.zip
Random function added, other fixes.
Diffstat (limited to 'src/functionrandom.cpp')
-rw-r--r--src/functionrandom.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/functionrandom.cpp b/src/functionrandom.cpp
new file mode 100644
index 0000000..2665a14
--- /dev/null
+++ b/src/functionrandom.cpp
@@ -0,0 +1,30 @@
1#include "functionrandom.h"
2
3#include "gamestate.h"
4
5#include <stdlib.h>
6
7FunctionRandom::FunctionRandom()
8{
9}
10
11FunctionRandom::~FunctionRandom()
12{
13}
14
15void FunctionRandom::call( class GameState &gState )
16{
17 Variable vHigh = gState.popDeref();
18 Variable vLow = gState.popDeref();
19
20 if( vHigh.getType() != vLow.getType() )
21 throw Bu::ExceptionBase("Different types in random!");
22
23 if( vLow.getType() == Variable::tInt )
24 {
25 gState.push( Variable( (int64_t)(
26 (random()%(vHigh.getInt()-vLow.getInt()+1ll))+vLow.getInt()
27 ) ) );
28 }
29}
30