mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Added "floor2" script function to work with ceil (#109)
Added the missing description of ceil to notes.txt. Disabled ceil marco in lib.math.h. Removed duplications in Utils.h.
This commit is contained in:
@@ -26,15 +26,14 @@ end
|
|||||||
return intp;
|
return intp;
|
||||||
end*/
|
end*/
|
||||||
|
|
||||||
procedure ceil(variable val) begin
|
/*procedure ceil(variable val) begin
|
||||||
variable intp;
|
variable intp;
|
||||||
intp := floor(val);
|
intp := floor(val);
|
||||||
if (abs(val-intp) > 0.0) then begin
|
if (abs(val-intp) > 0.0) then begin
|
||||||
intp++;
|
intp++;
|
||||||
end
|
end
|
||||||
return intp;
|
return intp;
|
||||||
end
|
end*/
|
||||||
|
|
||||||
|
|
||||||
procedure cap_number(variable num, variable min, variable max) begin
|
procedure cap_number(variable num, variable min, variable max) begin
|
||||||
if (num > max) then num := max;
|
if (num > max) then num := max;
|
||||||
|
|||||||
@@ -213,6 +213,7 @@
|
|||||||
#define critter_inven_obj2(obj, type) sfall_func2("critter_inven_obj2", obj, type)
|
#define critter_inven_obj2(obj, type) sfall_func2("critter_inven_obj2", obj, type)
|
||||||
#define display_stats sfall_func0("display_stats")
|
#define display_stats sfall_func0("display_stats")
|
||||||
#define exec_map_update_scripts sfall_func0("exec_map_update_scripts")
|
#define exec_map_update_scripts sfall_func0("exec_map_update_scripts")
|
||||||
|
#define floor2(value) sfall_func1("floor2", value)
|
||||||
#define get_cursor_mode sfall_func0("get_cursor_mode")
|
#define get_cursor_mode sfall_func0("get_cursor_mode")
|
||||||
#define get_flags(obj) sfall_func1("get_flags", obj)
|
#define get_flags(obj) sfall_func1("get_flags", obj)
|
||||||
#define get_ini_section(file, sect) sfall_func2("get_ini_section", file, sect)
|
#define get_ini_section(file, sect) sfall_func2("get_ini_section", file, sect)
|
||||||
|
|||||||
@@ -265,6 +265,9 @@ Some utility/math functions are available:
|
|||||||
> float exponent(float x)
|
> float exponent(float x)
|
||||||
- e^x
|
- e^x
|
||||||
|
|
||||||
|
> int ceil(float x)
|
||||||
|
- round x to the nearest integer that is not less than x
|
||||||
|
|
||||||
> int round(float x)
|
> int round(float x)
|
||||||
- round x to the nearest integer
|
- round x to the nearest integer
|
||||||
|
|
||||||
@@ -378,6 +381,10 @@ Some utility/math functions are available:
|
|||||||
- The file name is limited to 63 chars, including the extension
|
- The file name is limited to 63 chars, including the extension
|
||||||
- The section name is limited to 32 characters
|
- The section name is limited to 32 characters
|
||||||
|
|
||||||
|
> int sfall_func1("floor2", int/float value)
|
||||||
|
- works just like vanilla floor function, but returns correct integers for negative values
|
||||||
|
- vanilla floor function works exactly the same as ceil for negative values, much like trunc in C/C++
|
||||||
|
|
||||||
> int sfall_func1("item_weight", object)
|
> int sfall_func1("item_weight", object)
|
||||||
- gets the current weight of an object
|
- gets the current weight of an object
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "Objects.h"
|
#include "Objects.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include "Worldmap.h"
|
#include "Worldmap.h"
|
||||||
|
|
||||||
#include "Metarule.h"
|
#include "Metarule.h"
|
||||||
@@ -80,6 +81,7 @@ static const SfallMetarule metarules[] = {
|
|||||||
{"critter_inven_obj2", sf_critter_inven_obj2, 2, 2, {ARG_OBJECT, ARG_INT}},
|
{"critter_inven_obj2", sf_critter_inven_obj2, 2, 2, {ARG_OBJECT, ARG_INT}},
|
||||||
{"display_stats", sf_display_stats, 0, 0},
|
{"display_stats", sf_display_stats, 0, 0},
|
||||||
{"exec_map_update_scripts", sf_exec_map_update_scripts, 0, 0},
|
{"exec_map_update_scripts", sf_exec_map_update_scripts, 0, 0},
|
||||||
|
{"floor2", sf_floor2, 1, 1, {ARG_NUMBER}},
|
||||||
{"get_cursor_mode", sf_get_cursor_mode, 0, 0},
|
{"get_cursor_mode", sf_get_cursor_mode, 0, 0},
|
||||||
{"get_flags", sf_get_flags, 1, 1, {ARG_OBJECT}},
|
{"get_flags", sf_get_flags, 1, 1, {ARG_OBJECT}},
|
||||||
{"get_ini_section", sf_get_ini_section, 2, 2, {ARG_STRING, ARG_STRING}},
|
{"get_ini_section", sf_get_ini_section, 2, 2, {ARG_STRING, ARG_STRING}},
|
||||||
|
|||||||
@@ -345,5 +345,9 @@ void sf_message_str_game(OpcodeContext& ctx) {
|
|||||||
ctx.setReturn(msg);
|
ctx.setReturn(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sf_floor2(OpcodeContext& ctx) {
|
||||||
|
ctx.setReturn(static_cast<int>(floor(ctx.arg(0).asFloat())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,22 +57,18 @@ void __declspec() NegateFixHook();
|
|||||||
|
|
||||||
void sf_power(OpcodeContext&);
|
void sf_power(OpcodeContext&);
|
||||||
|
|
||||||
void sf_power(OpcodeContext&);
|
|
||||||
|
|
||||||
void sf_log(OpcodeContext&);
|
void sf_log(OpcodeContext&);
|
||||||
|
|
||||||
void sf_exponent(OpcodeContext&);
|
void sf_exponent(OpcodeContext&);
|
||||||
|
|
||||||
void sf_exponent(OpcodeContext&);
|
|
||||||
|
|
||||||
void sf_ceil(OpcodeContext&);
|
|
||||||
|
|
||||||
void sf_ceil(OpcodeContext&);
|
void sf_ceil(OpcodeContext&);
|
||||||
|
|
||||||
void sf_round(OpcodeContext&);
|
void sf_round(OpcodeContext&);
|
||||||
|
|
||||||
void sf_message_str_game(OpcodeContext&);
|
void sf_message_str_game(OpcodeContext&);
|
||||||
|
|
||||||
|
void sf_floor2(OpcodeContext&);
|
||||||
|
|
||||||
char* _stdcall Substring(const char* str, int pos, int length);
|
char* _stdcall Substring(const char* str, int pos, int length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user