aboutsummaryrefslogtreecommitdiff
path: root/src/moveuse.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-06-13 03:35:56 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-06-13 03:35:56 -0300
commit15b40c7915fca14e537534ae9ba03f3add965943 (patch)
treede3ee3c61962b300bd7457cc81845e7891c4b896 /src/moveuse.cc
parent7d298e5a4119df0910daa070af1d23567a83e90c (diff)
downloadgame-15b40c7915fca14e537534ae9ba03f3add965943.tar.gz
game-15b40c7915fca14e537534ae9ba03f3add965943.zip
more work on `operate.cc`
Diffstat (limited to 'src/moveuse.cc')
-rw-r--r--src/moveuse.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/moveuse.cc b/src/moveuse.cc
new file mode 100644
index 0000000..f11fffa
--- /dev/null
+++ b/src/moveuse.cc
@@ -0,0 +1,56 @@
+#include "operate.hh"
+
+// NOTE(fusion): Oh no.
+void ChangeObject(Object Obj, ObjectType NewType, uint32 Value){
+ if(!Obj.exists()){
+ error("ChangeObject: Übergebenes Objekt existiert nicht (1, NewType=%d).\n", NewType.TypeID);
+ return;
+ }
+
+ Object Con = Obj.getContainer();
+ while(true){
+ if(!Obj.exists()){
+ error("ChangeObject: Übergebenes Objekt existiert nicht (2, NewType=%d).\n", NewType.TypeID);
+ return;
+ }
+
+ try{
+ // NOTE(fusion): `Change` requires CUMULATIVE objects to have AMOUNT
+ // equal to one or it fails with `SPLITOBJECT`.
+ ObjectType ObjType = Obj.getObjectType();
+ if(ObjType.getFlag(CUMULATIVE)){
+ uint32 Amount = Obj.getAttribute(AMOUNT);
+ if(Amount > 1){
+ Move(0, Obj, Con, Amount - 1, true, NONE);
+ }
+ }
+
+ Change(Obj, NewType, Value);
+ return;
+ }catch(RESULT r){
+ if(!Obj.exists()){
+ error("ChangeObject: Übergebenes Objekt existiert nicht (3, NewType=%d).\n", NewType.TypeID);
+ return;
+ }
+
+ if(r == CONTAINERFULL){
+ Con = GetMapContainer(Obj);
+ }else if(r == TOOHEAVY){
+ Object MapCon = GetMapContainer(Obj);
+ Move(0, Obj, MapCon, -1, true, NONE);
+ }else if(r == NOROOM){
+ if(!Obj.getObjectType().getFlag(CUMULATIVE)
+ || Obj.getAttribute(AMOUNT) <= 1){
+ throw;
+ }
+
+ // TODO(fusion): Why do we use `Con` with `GetMapContainer` here?
+ uint32 Amount = Obj.getAttribute(AMOUNT);
+ Object MapCon = GetMapContainer(Con);
+ Move(0, Obj, MapCon, Amount - 1, true, NONE);
+ }else{
+ throw;
+ }
+ }
+ }
+}