summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2020-05-12 18:16:23 -0400
committergumi <git@gumi.ca>2020-07-20 11:06:48 -0400
commit619ec9cab33d944be272e075bcc57b5c86e39e1b (patch)
tree8a21556d9d9ddd05ea6f341d1aa72d6c10d170a2
parentd320a2838d91ba7088978c131333e51bfd482d5b (diff)
downloadserverdata-619ec9cab33d944be272e075bcc57b5c86e39e1b.tar.gz
serverdata-619ec9cab33d944be272e075bcc57b5c86e39e1b.tar.bz2
serverdata-619ec9cab33d944be272e075bcc57b5c86e39e1b.tar.xz
serverdata-619ec9cab33d944be272e075bcc57b5c86e39e1b.zip
add bitwise abstraction functions
-rw-r--r--npc/functions/bitwise.txt23
-rw-r--r--npc/scripts.conf1
2 files changed, 24 insertions, 0 deletions
diff --git a/npc/functions/bitwise.txt b/npc/functions/bitwise.txt
new file mode 100644
index 00000000..58ad8b5c
--- /dev/null
+++ b/npc/functions/bitwise.txt
@@ -0,0 +1,23 @@
+/**
+ * gets a bitmasked value in a variable
+ *
+ * @arg 0 - the variable
+ * @arg 1 - mask
+ * @arg 2 - shift
+ */
+function script bitwise_get {
+ return (getarg(0) & getarg(1)) >> getarg(2, 0);
+}
+
+/**
+ * sets a bitmasked value in a variable
+ *
+ * @arg 0 - the target variable
+ * @arg 1 - mask
+ * @arg 2 - shift
+ * @arg 3 - new value
+ * @return a reference to the variable
+ */
+function script bitwise_set {
+ return set(getarg(0), (getarg(0) & ~(getarg(1))) | (getarg(3, 0) << getarg(2, 0)));
+}
diff --git a/npc/scripts.conf b/npc/scripts.conf
index d15eaef7..f0e48c98 100644
--- a/npc/scripts.conf
+++ b/npc/scripts.conf
@@ -13,6 +13,7 @@
"npc/functions/math.txt",
"npc/functions/warp.txt",
"npc/functions/gender.txt",
+"npc/functions/bitwise.txt",
// Misc functions
"npc/functions/main.txt",