diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-06-08 19:54:40 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-06-08 19:54:40 -0300 |
| commit | eaa3536c027a4f7c1b879b78ab0ecdefcdb4833d (patch) | |
| tree | 03f851e558656f8fc36fdb982c28fbc09cef8dac /src/operate.cc | |
| parent | ab9f606371a1df23e9cacbffa0811db7a9e50100 (diff) | |
| download | game-eaa3536c027a4f7c1b879b78ab0ecdefcdb4833d.tar.gz game-eaa3536c027a4f7c1b879b78ab0ecdefcdb4833d.zip | |
impl `TCreature::Move` which was absolute hell + some tidying up
Diffstat (limited to 'src/operate.cc')
| -rw-r--r-- | src/operate.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/operate.cc b/src/operate.cc new file mode 100644 index 0000000..ef1ba01 --- /dev/null +++ b/src/operate.cc @@ -0,0 +1,82 @@ +#include "operate.hh" + +#include "stubs.hh" + +// TODO(fusion): This could have been a simple return value. +void CheckContainerDestination(Object Obj, Object Con){ + Object Help = Con; + while(Help != NONE && !Help.getObjectType().isMapContainer()){ + if(Help == Obj){ + throw CROSSREFERENCE; + } + Help = Help.getContainer(); + } + + ObjectType ConType = Con.getObjectType(); + if(!ConType.getFlag(CHEST)){ + int ConObjects = CountObjectsInContainer(Con); + int ConCapacity = (int)ConType.getAttribute(CAPACITY); + if(ConObjects >= ConCapacity){ + throw CONTAINERFULL; + } + } +} + +void CheckInventoryDestination(Object Obj, Object Con, bool Split){ + ObjectType ObjType = Obj.getObjectType(); + int ConPosition = GetObjectBodyPosition(Con); + bool HandContainer = ConPosition == INVENTORY_RIGHTHAND + || ConPosition == INVENTORY_LEFTHAND; + + if(!HandContainer && ConPosition != INVENTORY_AMMO){ + if(!ObjType.getFlag(CLOTHES)){ + throw WRONGPOSITION; + } + + int ObjPosition = (int)ObjType.getAttribute(BODYPOSITION); + if(ObjPosition == 0){ + throw WRONGPOSITION2; + }else if(ObjPosition != ConPosition){ + throw WRONGCLOTHES; + } + } + + uint32 CreatureID = GetObjectCreatureID(Con); + if(ObjType.isTwoHanded() && HandContainer){ + Object RightHand = GetBodyObject(CreatureID, INVENTORY_RIGHTHAND); + if(RightHand != NONE && RightHand != Obj){ + throw HANDSNOTFREE; + } + + Object LeftHand = GetBodyObject(CreatureID, INVENTORY_LEFTHAND); + if(LeftHand != NONE && LeftHand != Obj){ + throw HANDSNOTFREE; + } + + return; + } + + if(GetBodyObject(CreatureID, ConPosition) != NONE){ + throw NOROOM; + } + + if(HandContainer){ + for(int Position = INVENTORY_HAND_FIRST; + Position <= INVENTORY_HAND_LAST; + Position += 1){ + Object Other = GetBodyObject(CreatureID, Position); + if(Other != NONE){ + ObjectType OtherType = Other.getObjectType(); + if(OtherType.isTwoHanded()){ + throw HANDBLOCKED; + } + + if(Split || Other != Obj){ + if(OtherType.isWeapon() && ObjType.isWeapon()){ + throw ONEWEAPONONLY; + } + } + } + } + } +} |
