DayZ 1.24
Loading...
Searching...
No Matches
InventoryLocation.c
Go to the documentation of this file.
1//@NOTE: DO NOT EDIT! enum values are overwritten from c++
12
13//@NOTE: DO NOT EDIT! enum values are overwritten from c++
25
28{
105 proto native void GetDir(out float dir[4]);
106
121 proto native void SetGroundEx(EntityAI e, vector pos, float dir[4]);
130
140
150 proto native void SetCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
163 proto native void SetProxyCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
171
182
183 // direct set methods
189
194
196
202
217
219 {
220 if (loc)
221 return loc.DumpToString();
222 return "{ null }";
223 }
224
226 {
227 string res = "{ type=" + typename.EnumToString(InventoryLocationType, GetType());
228 switch (GetType())
229 {
230 case InventoryLocationType.UNKNOWN:
231 {
232 break;
233 }
234 case InventoryLocationType.GROUND:
235 {
236 res = res + " item=" + Object.GetDebugName(GetItem());
237 vector pos = GetPos();
238 float dir[4];
239 GetDir(dir);
240 res = res + " pos=(" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")";
241 res = res + " dir=(" + dir[0] + ", " + dir[1] + ", " + dir[2] + ", " + dir[3] + ")";
242 break;
243 }
244 case InventoryLocationType.ATTACHMENT:
245 {
246 res = res + " item=" + Object.GetDebugName(GetItem());
247 res = res + " parent=" + Object.GetDebugName(GetParent());
248 res = res + " slot=" + GetSlot();
249 break;
250 }
251 case InventoryLocationType.CARGO:
252 {
253 res = res + " item=" + Object.GetDebugName(GetItem());
254 res = res + " parent=" + Object.GetDebugName(GetParent());
255 res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
256 break;
257 }
258 case InventoryLocationType.HANDS:
259 {
260 res = res + " item=" + Object.GetDebugName(GetItem());
261 res = res + " parent=" + Object.GetDebugName(GetParent());
262 break;
263 }
264 case InventoryLocationType.PROXYCARGO:
265 {
266 res = res + " item=" + Object.GetDebugName(GetItem());
267 res = res + " parent=" + Object.GetDebugName(GetParent());
268 res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
269 break;
270 }
271 default:
272 {
273 res = res + "??";
274 break;
275 }
276 }
277 res = res + " }";
278 return res;
279 }
280
282 {
283 EntityAI parent;
285 int type = 0;
286 int idx = -1;
287 int row = -1;
288 int col = -1;
289 bool flp = false;
290 if (!ctx.Read(type))
291 return false;
292
293 switch (type)
294 {
295 case InventoryLocationType.UNKNOWN:
296 {
297 break;
298 }
299 case InventoryLocationType.GROUND:
300 {
301 if (!ctx.Read(item))
302 return false;
303 vector pos;
304 if (!ctx.Read(pos))
305 return false;
306
307 float dir[4];
308 if (!ctx.Read(dir))
309 return false;
310
311 if (!item)
312 {
313#ifdef DIAG_DEVELOPER
314#ifdef SERVER
315 Debug.Log(string.Format("Item=%1 does not exist on server!", Object.GetDebugName(item)), "GROUND", "n/a", "ReadFromContext", this.ToString());
316#endif
317#endif
318 break; // parent or item is not in bubble
319 }
320
321 SetGroundEx(item, pos, dir);
322 break;
323 }
324 case InventoryLocationType.ATTACHMENT:
325 {
326 if (!ctx.Read(parent))
327 return false;
328 if (!ctx.Read(item))
329 return false;
330 int slot;
331 if (!ctx.Read(slot))
332 return false;
333
334 if (!parent || !item)
335 {
336#ifdef DIAG_DEVELOPER
337#ifdef SERVER
338 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());
339#endif
340#endif
341 break; // parent or item is not in bubble
342 }
343
344 SetAttachment(parent, item, slot);
345 break;
346 }
347 case InventoryLocationType.CARGO:
348 {
349 if (!ctx.Read(parent))
350 return false;
351 if (!ctx.Read(item))
352 return false;
353 if (!ctx.Read(idx))
354 return false;
355 if (!ctx.Read(row))
356 return false;
357 if (!ctx.Read(col))
358 return false;
359 if (!ctx.Read(flp))
360 return false;
361
362 if (!parent || !item)
363 {
364#ifdef DIAG_DEVELOPER
365#ifdef SERVER
366 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());
367#endif
368#endif
369 break; // parent or item is not in bubble
370 }
371
372 SetCargo(parent, item, idx, row, col, flp);
373 break;
374 }
375 case InventoryLocationType.HANDS:
376 {
377 if (!ctx.Read(parent))
378 return false;
379 if (!ctx.Read(item))
380 return false;
381
382 if (!parent || !item)
383 {
384#ifdef DIAG_DEVELOPER
385#ifdef SERVER
386 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());
387#endif
388#endif
389 break; // parent or item is not in bubble
390 }
391
392 SetHands(parent, item);
393 break;
394 }
395 case InventoryLocationType.PROXYCARGO:
396 {
397 if (!ctx.Read(parent))
398 return false;
399 if (!ctx.Read(item))
400 return false;
401 if (!ctx.Read(idx))
402 return false;
403 if (!ctx.Read(row))
404 return false;
405 if (!ctx.Read(col))
406 return false;
407 if (!ctx.Read(flp))
408 return false;
409
410 if (!parent || !item)
411 {
412#ifdef DIAG_DEVELOPER
413#ifdef SERVER
414 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());
415#endif
416#endif
417 break; // parent or item is not in bubble
418 }
419
420 SetProxyCargo(parent, item, idx, row, col, flp);
421 break;
422 }
423 default:
424 {
425 ErrorEx("ReadFromContext - really unknown location type, this should not happen, type=" + type);
426 return false;
427 }
428 }
429 return true;
430 }
431
433 {
434 if (!ctx.Write(GetType()))
435 {
436 Error("InventoryLocation::WriteToContext - cannot write to context! failed to write type");
437 return false;
438 }
439
440 switch (GetType())
441 {
442 case InventoryLocationType.UNKNOWN:
443 {
444 break;
445 }
446 case InventoryLocationType.GROUND:
447 {
448 if (!ctx.Write(GetItem()))
449 {
450 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=item");
451 return false;
452 }
453
454 vector pos = GetPos();
455 if (!ctx.Write(pos))
456 {
457 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=pos");
458 return false;
459 }
460
461 float dir[4];
462 GetDir(dir);
463 if (!ctx.Write(dir))
464 {
465 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=dir");
466 return false;
467 }
468
469 break;
470 }
471 case InventoryLocationType.ATTACHMENT:
472 {
473 if (!ctx.Write(GetParent()))
474 {
475 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=parent");
476 return false;
477 }
478 if (!ctx.Write(GetItem()))
479 {
480 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=item");
481 return false;
482 }
483 if (!ctx.Write(GetSlot()))
484 {
485 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=slot");
486 return false;
487 }
488 break;
489 }
490 case InventoryLocationType.CARGO:
491 {
492 if (!ctx.Write(GetParent()))
493 {
494 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=parent");
495 return false;
496 }
497 if (!ctx.Write(GetItem()))
498 {
499 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=item");
500 return false;
501 }
502 if (!ctx.Write(GetIdx()))
503 {
504 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=idx");
505 return false;
506 }
507 if (!ctx.Write(GetRow()))
508 {
509 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=row");
510 return false;
511 }
512 if (!ctx.Write(GetCol()))
513 {
514 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=col");
515 return false;
516 }
517 if (!ctx.Write(GetFlip()))
518 {
519 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=flp");
520 return false;
521 }
522 break;
523 }
524 case InventoryLocationType.HANDS:
525 {
526 if (!ctx.Write(GetParent()))
527 {
528 Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=parent");
529 return false;
530 }
531 if (!ctx.Write(GetItem()))
532 {
533 Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=item");
534 return false;
535 }
536 break;
537 }
538 case InventoryLocationType.PROXYCARGO:
539 {
540 if (!ctx.Write(GetParent()))
541 {
542 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=parent");
543 return false;
544 }
545 if (!ctx.Write(GetItem()))
546 {
547 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=item");
548 return false;
549 }
550 if (!ctx.Write(GetIdx()))
551 {
552 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=idx");
553 return false;
554 }
555 if (!ctx.Write(GetRow()))
556 {
557 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=row");
558 return false;
559 }
560 if (!ctx.Write(GetCol()))
561 {
562 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=col");
563 return false;
564 }
565 if (!ctx.Write(GetFlip()))
566 {
567 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=flp");
568 return false;
569 }
570
571 break;
572 }
573 default:
574 {
575 Error("WriteToContext - really unknown location type, this should not happen, type=" + GetType());
576 return false;
577 }
578 }
579 return true;
580 }
581};
582
584{
585 if (loc)
586 {
587 if (!ctx.Write(true))
588 {
589 Error("OptionalLocationWriteToContext - cannot write 1 to context!");
590 return false;
591 }
592 return loc.WriteToContext(ctx);
593 }
594 else
595 {
596 if (!ctx.Write(false))
597 {
598 Error("OptionalLocationWriteToContext - cannot write 0 to context!");
599 return false;
600 }
601 }
602 return true;
603}
604
606{
607 bool present = false;
608 if (!ctx.Read(present))
609 {
610 Error("OptionalLocationReadFromContext - cannot read bool from context!");
611 return false;
612 }
613
614 if (!present)
615 return true;
616
617 loc = new InventoryLocation();
618 if (!loc.ReadFromContext(ctx))
619 {
620 Error("OptionalLocationReadFromContext - cannot read (present) inventorylocation from context!");
621 return false;
622 }
623 return true;
624}
FindInventoryLocationType
flags for searching locations in inventory
@ PROXYCARGO
cargo of a large object (building,...)
@ ANY
ATT | CGO | PXY | HND.
@ ANY_CARGO
CGO | PXY.
@ HANDS
hands of another entity
@ CARGO
cargo of another entity
@ NO_SLOT_AUTO_ASSIGN
skips auto-assign test
@ ATTACHMENT
< ground
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
InventoryLocationType
types of Inventory Location
@ UNKNOWN
unknown, usually freshly created object
@ GROUND
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
represents base for cargo storage for entities
Definition Cargo.c:7
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
InventoryLocation.
proto native void SetCol(int col)
proto native void SetIndex(int idx)
static string DumpToStringNullSafe(InventoryLocation loc)
proto native void SetSlot(int slotId)
proto native void SetGroundEx(EntityAI e, vector pos, float dir[4])
sets current inventory location type to Ground with transformation mat
proto native bool CollidesWith(notnull InventoryLocation rhs)
checks if inventory locations collides each with other
proto native void SetRow(int row)
proto native int GetSlot()
returns slot id if current type is Attachment
proto native EntityAI GetItem()
returns item of current inventory location
proto native void SetParent(notnull EntityAI parent)
proto native void SetCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip)
sets current inventory location type to Cargo with coordinates (idx, row, col)
proto native int GetIdx()
returns index of cargo if current type is Cargo / ProxyCargo
proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId)
sets current inventory location type to Attachment with slot id set to <slotId>
proto native void SetFlip(bool flip)
proto native vector GetPos()
returns position of item in world if type is Ground
proto native int GetCol()
returns column of cargo if current type is Cargo / ProxyCargo
proto native bool GetFlip()
returns flip status of cargo
proto native EntityAI GetParent()
returns parent of current inventory location
proto native InventoryLocation Copy(notnull InventoryLocation rhs)
copies location data to another location
bool WriteToContext(ParamsWriteContext ctx)
proto native void SetGround(EntityAI e, vector mat[4])
sets current inventory location type to Ground with transformation mat
proto native bool CompareLocationOnly(notnull InventoryLocation other)
proto native void SetItem(notnull EntityAI item)
proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip)
based on Cargo.IsProxyCargo uses SetProxyCargo or SetCargo respectively
proto native InventoryLocation CopyLocationFrom(notnull InventoryLocation rhs, bool copyFlip)
copies location to another location without m_item member
proto native int GetRow()
returns row of cargo if current type is Cargo / ProxyCargo
bool ReadFromContext(ParamsReadContext ctx)
proto native bool IsValid()
verify current set inventory location
proto native void Reset()
proto native int GetType()
returns type of InventoryLocation
proto native void SetHands(notnull EntityAI parent, EntityAI e)
sets current inventory location type to Hands
proto native void GetDir(out float dir[4])
returns direction of item in world if type is Ground
proto native void SetProxyCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip)
sets current inventory location type to ProxyCargo with coordinates (idx, row, col) @NOTE: typical us...
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
enum ShapeType ErrorEx