source: Daodan/src/Daodan_BSL.c@ 442

Last change on this file since 442 was 442, checked in by gumby, 15 years ago
File size: 4.8 KB
RevLine 
[440]1#include <time.h>
2
[439]3#include "Daodan_BSL.h"
4#include "BFW_ScriptingLanguage.h"
[441]5#include <stdio.h>
6#include "Oni.h"
7#include "Oni_Character.h"
[440]8#include "dSFMT\dSFMT.h"
9
[439]10uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
11{
12 if (numargs < 2)
13 return 1;
14 ret->value_int32 = args[0].value_int32 * args[1].value_int32;
15 ret->type = sl_int32;
16 return 0;
17}
18
[441]19uint16_t ONICALL bsl_getkills(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
20{
21
[442]22 int index;
23 if (numargs == 0) index = 0;
24 else index = args[0].value_int32;
25 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1670;
26 ret->value_int32 = *killcount;
27 ret->type = sl_int32;
28 return 0;
[441]29
[442]30}
[441]31
[442]32uint16_t ONICALL bsl_getdamage(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
33{
34
35 int index;
36 if (numargs == 0) index = 0;
37 else index = args[0].value_int32;
38 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1674;
39 ret->value_int32 = *killcount;
[441]40 ret->type = sl_int32;
41 return 0;
[442]42
[441]43}
44
[439]45uint16_t ONICALL bsl_mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
46{
47 if (numargs < 2)
48 return 1;
49
50 double val1;
51 double val2;
52
53 if (args[0].type == sl_int32)
54 val1 = args[0].value_int32;
55 else
56 val1 = args[0].value_float;
57
58 if (args[1].type == sl_int32)
59 val2 = args[1].value_int32;
60 else
61 val2 = args[1].value_float;
62
63 ret->value_float = (float)(val1 * val2);
64 ret->type = sl_float;
65 return 0;
66}
67
68uint16_t ONICALL bsl_int32div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
69{
70 if (numargs < 2)
71 return 1;
72 ret->value_int32 = args[0].value_int32 / args[1].value_int32;
73 ret->type = sl_int32;
74 return 0;
75}
76
77uint16_t ONICALL bsl_div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
78{
79 if (numargs < 2)
80 return 1;
81
82 double val1;
83 double val2;
84
85 if (args[0].type == sl_int32)
86 val1 = args[0].value_int32;
87 else
88 val1 = args[0].value_float;
89
90 if (args[1].type == sl_int32)
91 val2 = args[1].value_int32;
92 else
93 val2 = args[1].value_float;
94
95 ret->value_float = (float)(val1 / val2);
96 ret->type = sl_float;
97 return 0;
98}
[441]99uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
100{
101 if (numargs < 2)
102 return 1;
103
104 char output[255];
105 char temp[255];
106 int i = 1;
107 for(i; i < numargs; i++) {
108 sprintf(output, args[0].value_str32, args[i].value_str32);/*
109 if(args[i].type == sl_int32 || args[i].type == sl_bool) {
110 sprintf(temp, "%i",args[i].value_int32);
111 sprintf(output, args[0].value_str32, temp); }
112 else if(args[i].type == sl_float) {
113 sprintf(temp, "%f",args[i].value_float);
114 sprintf(output, args[0].value_str32, temp); }
115 else */
116 }
117
118 ret->value_str32 = output;
119 ret->type = sl_str32;
120 return 0;
121}
122
123
[440]124uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
125{
126 if (numargs < 2)
127 return 1;
128
129 int32_t start = 0;
130 int32_t end = 0;
131
132 if (args[0].value_int32 == args[1].value_int32)
133 return 1;
134 else if (args[0].value_int32 > args[1].value_int32)
135 {
136 start = args[1].value_int32;
137 end = args[0].value_int32;
138 }
139 else
140 {
141 start = args[0].value_int32;
142 end = args[1].value_int32;
143 }
144
145 ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1));
146 ret->type = sl_int32;
147 return 0;
148}
149
[441]150
[439]151void SLrDaodan_Initalize()
152{
153 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
154 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
155
156 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
157 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
[441]158
[440]159
[441]160 SLrScript_Command_Register_ReturnType("sprintf", "sprintf", "str1:format str2:value [str3:...]", sl_str32, bsl_sprintf);
161
[442]162 SLrScript_Command_Register_ReturnType("chr_getkills","Gets the number of kills a character has", "[chrindex:int]", sl_int32, bsl_getkills);
163 SLrScript_Command_Register_ReturnType("chr_getdamage","Gets the amount of damage a character has caused", "[chrindex:int]", sl_int32, bsl_getdamage);
[441]164
[440]165 dsfmt_gv_init_gen_rand((uint32_t)time(NULL));
166 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
[442]167
[439]168}
Note: See TracBrowser for help on using the repository browser.