123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- //@NOTE: DO NOT EDIT! enum values are overwritten from c++
- /// types of Inventory Location
- enum InventoryLocationType
- {
- UNKNOWN, ///< unknown, usually freshly created object
- GROUND, /// < ground
- ATTACHMENT, ///< attachment of another entity
- CARGO, ///< cargo of another entity
- HANDS, ///< hands of another entity
- PROXYCARGO, ///< cargo of a large object (building,...)
- VEHICLE,
- };
- //@NOTE: DO NOT EDIT! enum values are overwritten from c++
- /// flags for searching locations in inventory
- enum FindInventoryLocationType
- {
- ATTACHMENT, ///< ATT
- CARGO, ///< CGO
- HANDS, ///< HND
- PROXYCARGO, ///< PXY
- ANY_CARGO, ///< CGO | PXY
- ANY, ///< ATT | CGO | PXY | HND
- NO_SLOT_AUTO_ASSIGN ///< skips auto-assign test
- };
- //! InventoryLocation
- class InventoryLocation
- {
- /**
- * @fn IsValid
- * @brief verify current set inventory location
- * @return true if valid, false otherwise
- **/
- proto native bool IsValid();
- /**
- * @fn GetType
- * @brief returns type of InventoryLocation
- *
- * @see InventoryLocationType for known types of inventory locations
- **/
- proto native int GetType();
- /**
- * @fn GetParent
- * @brief returns parent of current inventory location
- *
- * Parent entity can be null if item is on ground.
- *
- * @return parent entity, null otherwise
- **/
- proto native EntityAI GetParent();
- /**
- * @fn GetItem
- * @brief returns item of current inventory location
- *
- * Item can be null if and only if this is a query for location
- * of item that is about to be created (new spawn).
- *
- * @return item
- **/
- proto native EntityAI GetItem();
- /**
- * @fn GetSlot
- * @brief returns slot id if current type is Attachment
- *
- * @NOTE: slot id is related to order of entries in DZ/data/config.cpp secton CfgSlots
- *
- * @return slot id if attachment, -1 otherwise
- **/
- proto native int GetSlot();
- /**
- * @fn GetIdx
- * @brief returns index of cargo if current type is Cargo / ProxyCargo
- * @return index or -1
- **/
- proto native int GetIdx();
- /**
- * @fn GetRow
- * @brief returns row of cargo if current type is Cargo / ProxyCargo
- * @return row or -1
- **/
- proto native int GetRow();
- /**
- * @fn GetCol
- * @brief returns column of cargo if current type is Cargo / ProxyCargo
- * @return index or -1
- **/
- proto native int GetCol();
- /**
- * @fn GetFlip
- * @brief returns flip status of cargo
- * @return true/false
- **/
- proto native bool GetFlip();
- /**
- * @fn GetPos
- * @brief returns position of item in world if type is Ground
- * @return position
- **/
- proto native vector GetPos();
- /**
- * @fn GetDir
- * @brief returns direction of item in world if type is Ground
- * @return position
- **/
- proto native void GetDir(out float dir[4]);
- /**
- * @fn SetGround
- * @brief sets current inventory location type to Ground with transformation mat
- * @param[in] e entity with this inventory location (null for new spawns)
- * @param[in] mat transformation matrix
- **/
- proto native void SetGround(EntityAI e, vector mat[4]);
- /**
- * @fn SetGroundEx
- * @brief sets current inventory location type to Ground with transformation mat
- * @param[in] e entity with this inventory location (null for new spawns)
- * @param[in] pos position vector
- * @param[in] dir direction quat
- **/
- proto native void SetGroundEx(EntityAI e, vector pos, float dir[4]);
- /**
- * @fn SetAttachment
- * @brief sets current inventory location type to Attachment with slot id set to <slotId>
- * @param[in] parent parent entity the item <e> will be attached to
- * @param[in] e entity with this inventory location (null for new spawns)
- * @param[in] slotId slot id where the item will be attached
- **/
- proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId);
-
- /**
- * @fn SetCargoAuto
- * @brief based on Cargo.IsProxyCargo uses SetProxyCargo or SetCargo respectively
- * @param[in] cargo cargo that will receive item <e> into cargo
- * @param[in] e entity with this inventory location (null for new spawns)
- * @param[in] row row of the cargo
- * @param[in] col column of the cargo
- **/
- proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip);
- /**
- * @fn SetCargo
- * @brief sets current inventory location type to Cargo with coordinates (idx, row, col)
- * @param[in] parent parent entity that will receive item <e> into cargo
- * @param[in] e entity with this inventory location (null for new spawns)
- * @param[in] idx index of cargo
- * @param[in] row row of the cargo
- * @param[in] col column of the cargo
- **/
- proto native void SetCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
- /**
- * @fn SetProxyCargo
- * @brief sets current inventory location type to ProxyCargo with coordinates (idx, row, col)
- * @NOTE: typical usage is in building-like dummy structures, where furniture with cargo is part
- * of the model, and is not a physical entity (like person or bag).
- * @param[in] parent parent entity that will receive item <e> into proxy cargo
- * @param[in] e entity with this inventory location (null for new spawns)
- * @param[in] idx index of cargo
- * @param[in] row row of the cargo
- * @param[in] col column of the cargo
- *
- **/
- proto native void SetProxyCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
- /**
- * @fn SetHands
- * @brief sets current inventory location type to Hands
- * @param[in] parent parent entity the item <e> will be attached to. this'd better be inherited from Person
- * @param[in] e entity with this inventory location (null for new spawns)
- **/
- proto native void SetHands(notnull EntityAI parent, EntityAI e);
-
- /**
- * @fn SetVehicle
- * brief sets current inventory location's GetParent
- * @param[in] idx index of seat
- **/
- proto native void SetVehicle(notnull EntityAI parent, EntityAI e, int idx);
-
- /**
- * @fn SetParent
- * brief sets current inventory location's GetParent
- **/
- proto native void SetParent(notnull EntityAI parent);
- /**
- * @fn SetItem
- * brief sets current inventory location's item
- **/
- proto native void SetItem(notnull EntityAI item);
- // direct set methods
- proto native void SetSlot(int slotId);
- proto native void SetIndex(int idx);
- proto native void SetRow(int row);
- proto native void SetCol(int col);
- proto native void SetFlip(bool flip);
- /**
- * @fn Reset
- **/
- proto native void Reset();
-
- proto native bool CompareLocationOnly(notnull InventoryLocation other);
- /**
- * @fn CollidesWith
- * @brief checks if inventory locations collides each with other
- **/
- proto native bool CollidesWith(notnull InventoryLocation rhs);
- /**
- * @fn Copy
- * @brief copies location data to another location
- *
- * @NOTE it copies all data (except enforce internal data)
- **/
- proto native InventoryLocation Copy(notnull InventoryLocation rhs);
- /**
- * @fn CopyLocationFrom
- * @brief copies location to another location without m_item member
- *
- * @NOTE it does NOT do a copy of m_item member!
- **/
- proto native InventoryLocation CopyLocationFrom(notnull InventoryLocation rhs, bool copyFlip);
-
- static string DumpToStringNullSafe(InventoryLocation loc)
- {
- if (loc)
- return loc.DumpToString();
- return "{ null }";
- }
-
- string DumpToString()
- {
- string res = "{ type=" + typename.EnumToString(InventoryLocationType, GetType());
- switch (GetType())
- {
- case InventoryLocationType.UNKNOWN:
- {
- break;
- }
- case InventoryLocationType.GROUND:
- {
- res = res + " item=" + Object.GetDebugName(GetItem());
- vector pos = GetPos();
- float dir[4];
- GetDir(dir);
- res = res + " pos=(" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")";
- res = res + " dir=(" + dir[0] + ", " + dir[1] + ", " + dir[2] + ", " + dir[3] + ")";
- break;
- }
- case InventoryLocationType.ATTACHMENT:
- {
- res = res + " item=" + Object.GetDebugName(GetItem());
- res = res + " parent=" + Object.GetDebugName(GetParent());
- res = res + " slot=" + GetSlot();
- break;
- }
- case InventoryLocationType.CARGO:
- {
- res = res + " item=" + Object.GetDebugName(GetItem());
- res = res + " parent=" + Object.GetDebugName(GetParent());
- res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
- break;
- }
- case InventoryLocationType.HANDS:
- {
- res = res + " item=" + Object.GetDebugName(GetItem());
- res = res + " parent=" + Object.GetDebugName(GetParent());
- break;
- }
- case InventoryLocationType.PROXYCARGO:
- {
- res = res + " item=" + Object.GetDebugName(GetItem());
- res = res + " parent=" + Object.GetDebugName(GetParent());
- res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
- break;
- }
- case InventoryLocationType.VEHICLE:
- {
- res = res + " item=" + Object.GetDebugName(GetItem());
- res = res + " parent=" + Object.GetDebugName(GetParent());
- res = res + " idx=" + GetIdx();
- break;
- }
- default:
- {
- res = res + "??";
- break;
- }
- }
- res = res + " }";
- return res;
- }
- bool ReadFromContext(ParamsReadContext ctx)
- {
- EntityAI parent;
- EntityAI item;
- int type = 0;
- int idx = -1;
- int row = -1;
- int col = -1;
- bool flp = false;
- if (!ctx.Read(type))
- return false;
- switch (type)
- {
- case InventoryLocationType.UNKNOWN:
- {
- break;
- }
- case InventoryLocationType.GROUND:
- {
- if (!ctx.Read(item))
- return false;
- vector pos;
- if (!ctx.Read(pos))
- return false;
- float dir[4];
- if (!ctx.Read(dir))
- return false;
-
- if (!item)
- {
- #ifdef ENABLE_LOGGING
- #ifdef SERVER
- Debug.Log(string.Format("Item=%1 does not exist on server!", Object.GetDebugName(item)), "GROUND" , "n/a", "ReadFromContext", this.ToString() );
- #endif
- #endif
- break; // parent or item is possibly not spawned in bubble yet
- }
- SetGroundEx(item, pos, dir);
- break;
- }
- case InventoryLocationType.ATTACHMENT:
- {
- if (!ctx.Read(parent))
- return false;
- if (!ctx.Read(item))
- return false;
- int slot;
- if (!ctx.Read(slot))
- return false;
-
- if (!parent || !item)
- {
- #ifdef ENABLE_LOGGING
- #ifdef SERVER
- Debug.Log(string.Format("Parent=%1 or Item=%2 does not exist on server!", Object.GetDebugName(parent), Object.GetDebugName(item)), "ATTACHMENT" , "n/a", "ReadFromContext", this.ToString() );
- #endif
- #endif
- break; // parent or item is possibly not spawned in bubble yet
- }
- SetAttachment(parent, item, slot);
- break;
- }
- case InventoryLocationType.CARGO:
- {
- if (!ctx.Read(parent))
- return false;
- if (!ctx.Read(item))
- return false;
- if (!ctx.Read(idx))
- return false;
- if (!ctx.Read(row))
- return false;
- if (!ctx.Read(col))
- return false;
- if (!ctx.Read(flp))
- return false;
-
- if (!parent || !item)
- {
- #ifdef ENABLE_LOGGING
- #ifdef SERVER
- Debug.Log(string.Format("Parent=%1 or Item=%2 does not exist on server!", Object.GetDebugName(parent), Object.GetDebugName(item)), "CARGO" , "n/a", "ReadFromContext", this.ToString() );
- #endif
- #endif
- break; // parent or item is possibly not spawned in bubble yet
- }
- SetCargo(parent, item, idx, row, col, flp);
- break;
- }
- case InventoryLocationType.HANDS:
- {
- if (!ctx.Read(parent))
- return false;
- if (!ctx.Read(item))
- return false;
-
- if (!parent || !item)
- {
- #ifdef ENABLE_LOGGING
- #ifdef SERVER
- Debug.Log(string.Format("Parent=%1 or Item=%2 does not exist on server!", Object.GetDebugName(parent), Object.GetDebugName(item)), "HANDS" , "n/a", "ReadFromContext", this.ToString() );
- #endif
- #endif
- break; // parent or item is possibly not spawned in bubble yet
- }
- SetHands(parent, item);
- break;
- }
- case InventoryLocationType.PROXYCARGO:
- {
- if (!ctx.Read(parent))
- return false;
- if (!ctx.Read(item))
- return false;
- if (!ctx.Read(idx))
- return false;
- if (!ctx.Read(row))
- return false;
- if (!ctx.Read(col))
- return false;
- if (!ctx.Read(flp))
- return false;
-
- if (!parent || !item)
- {
- #ifdef ENABLE_LOGGING
- #ifdef SERVER
- Debug.Log(string.Format("Parent=%1 or Item=%2 does not exist on server!", Object.GetDebugName(parent), Object.GetDebugName(item)), "PROXYCARGO" , "n/a", "ReadFromContext", this.ToString() );
- #endif
- #endif
- break; // parent or item is possibly not spawned in bubble yet
- }
- SetProxyCargo(parent, item, idx, row, col, flp);
- break;
- }
- case InventoryLocationType.VEHICLE:
- {
- if (!ctx.Read(parent))
- return false;
- if (!ctx.Read(item))
- return false;
- if (!ctx.Read(idx))
- return false;
-
- if (!parent || !item)
- {
- #ifdef ENABLE_LOGGING
- #ifdef SERVER
- Debug.Log(string.Format("Parent=%1 or Item=%2 does not exist on server!", Object.GetDebugName(parent), Object.GetDebugName(item)), "VEHICLE" , "n/a", "ReadFromContext", this.ToString() );
- #endif
- #endif
- break; // parent or item is possibly not spawned in bubble yet
- }
- SetVehicle(parent, item, idx);
- break;
- }
- default:
- {
- ErrorEx("ReadFromContext - really unknown location type, this should not happen, type=" + type);
- return false;
- }
- }
- return true;
- }
- bool WriteToContext(ParamsWriteContext ctx)
- {
- if (!ctx.Write(GetType()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed to write type");
- return false;
- }
- switch (GetType())
- {
- case InventoryLocationType.UNKNOWN:
- {
- break;
- }
- case InventoryLocationType.GROUND:
- {
- if (!ctx.Write(GetItem()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=item");
- return false;
- }
- vector pos = GetPos();
- if (!ctx.Write(pos))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=pos");
- return false;
- }
- float dir[4];
- GetDir(dir);
- if (!ctx.Write(dir))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=dir");
- return false;
- }
- break;
- }
- case InventoryLocationType.ATTACHMENT:
- {
- if (!ctx.Write(GetParent()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=parent");
- return false;
- }
- if (!ctx.Write(GetItem()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=item");
- return false;
- }
- if (!ctx.Write(GetSlot()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=slot");
- return false;
- }
- break;
- }
- case InventoryLocationType.CARGO:
- {
- if (!ctx.Write(GetParent()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=parent");
- return false;
- }
- if (!ctx.Write(GetItem()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=item");
- return false;
- }
- if (!ctx.Write(GetIdx()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=idx");
- return false;
- }
- if (!ctx.Write(GetRow()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=row");
- return false;
- }
- if (!ctx.Write(GetCol()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=col");
- return false;
- }
- if (!ctx.Write(GetFlip()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=flp");
- return false;
- }
- break;
- }
- case InventoryLocationType.HANDS:
- {
- if (!ctx.Write(GetParent()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=parent");
- return false;
- }
- if (!ctx.Write(GetItem()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=item");
- return false;
- }
- break;
- }
- case InventoryLocationType.PROXYCARGO:
- {
- if (!ctx.Write(GetParent()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=parent");
- return false;
- }
- if (!ctx.Write(GetItem()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=item");
- return false;
- }
- if (!ctx.Write(GetIdx()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=idx");
- return false;
- }
- if (!ctx.Write(GetRow()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=row");
- return false;
- }
- if (!ctx.Write(GetCol()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=col");
- return false;
- }
- if (!ctx.Write(GetFlip()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=flp");
- return false;
- }
- break;
- }
-
- case InventoryLocationType.VEHICLE:
- {
- if (!ctx.Write(GetParent()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed VHC, arg=parent");
- return false;
- }
- if (!ctx.Write(GetItem()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed VHC, arg=item");
- return false;
- }
- if (!ctx.Write(GetIdx()))
- {
- Error("InventoryLocation::WriteToContext - cannot write to context! failed VHC, arg=idx");
- return false;
- }
- break;
- }
- default:
- {
- Error("WriteToContext - really unknown location type, this should not happen, type=" + GetType());
- return false;
- }
- }
- return true;
- }
- };
- bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
- {
- if (loc)
- {
- if (!ctx.Write(true))
- {
- Error("OptionalLocationWriteToContext - cannot write 1 to context!");
- return false;
- }
- return loc.WriteToContext(ctx);
- }
- else
- {
- if (!ctx.Write(false))
- {
- Error("OptionalLocationWriteToContext - cannot write 0 to context!");
- return false;
- }
- }
- return true;
- }
- bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
- {
- bool present = false;
- if (!ctx.Read(present))
- {
- Error("OptionalLocationReadFromContext - cannot read bool from context!");
- return false;
- }
-
- if (!present)
- return true;
- loc = new InventoryLocation();
- if (!loc.ReadFromContext(ctx))
- {
- Error("OptionalLocationReadFromContext - cannot read (present) inventorylocation from context!");
- return false;
- }
- return true;
- }
|