| 1 |
+ |
#include <time.h> |
| 2 |
+ |
|
| 3 |
|
#include "Daodan_BSL.h" |
| 4 |
|
#include "BFW_ScriptingLanguage.h" |
| 5 |
|
|
| 6 |
+ |
#include "dSFMT\dSFMT.h" |
| 7 |
+ |
|
| 8 |
|
uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 9 |
|
{ |
| 10 |
|
if (numargs < 2) |
| 69 |
|
return 0; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
+ |
uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 73 |
+ |
{ |
| 74 |
+ |
if (numargs < 2) |
| 75 |
+ |
return 1; |
| 76 |
+ |
|
| 77 |
+ |
int32_t start = 0; |
| 78 |
+ |
int32_t end = 0; |
| 79 |
+ |
|
| 80 |
+ |
if (args[0].value_int32 == args[1].value_int32) |
| 81 |
+ |
return 1; |
| 82 |
+ |
else if (args[0].value_int32 > args[1].value_int32) |
| 83 |
+ |
{ |
| 84 |
+ |
start = args[1].value_int32; |
| 85 |
+ |
end = args[0].value_int32; |
| 86 |
+ |
} |
| 87 |
+ |
else |
| 88 |
+ |
{ |
| 89 |
+ |
start = args[0].value_int32; |
| 90 |
+ |
end = args[1].value_int32; |
| 91 |
+ |
} |
| 92 |
+ |
|
| 93 |
+ |
ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1)); |
| 94 |
+ |
ret->type = sl_int32; |
| 95 |
+ |
return 0; |
| 96 |
+ |
} |
| 97 |
+ |
|
| 98 |
|
void SLrDaodan_Initalize() |
| 99 |
|
{ |
| 100 |
|
SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); |
| 102 |
|
|
| 103 |
|
SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); |
| 104 |
|
SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); |
| 105 |
+ |
|
| 106 |
+ |
dsfmt_gv_init_gen_rand((uint32_t)time(NULL)); |
| 107 |
+ |
SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand); |
| 108 |
|
} |