Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
inventorylocation.c
Go to the documentation of this file.
1//@NOTE: DO NOT EDIT! enum values are overwritten from c++
13
14//@NOTE: DO NOT EDIT! enum values are overwritten from c++
26
29{
35 proto native bool IsValid();
42 proto native int GetType();
51 proto native EntityAI GetParent();
61 proto native EntityAI GetItem();
70 proto native int GetSlot();
76 proto native int GetIdx();
82 proto native int GetRow();
88 proto native int GetCol();
94 proto native bool GetFlip();
100 proto native vector GetPos();
106 proto native void GetDir(out float dir[4]);
107
114 proto native void SetGround(EntityAI e, vector mat[4]);
122 proto native void SetGroundEx(EntityAI e, vector pos, float dir[4]);
130 proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId);
131
140 proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip);
141
151 proto native void SetCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
164 proto native void SetProxyCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
171 proto native void SetHands(notnull EntityAI parent, EntityAI e);
172
178 proto native void SetVehicle(notnull EntityAI parent, EntityAI e, int idx);
179
184 proto native void SetParent(notnull EntityAI parent);
189 proto native void SetItem(notnull EntityAI item);
190
191 // direct set methods
192 proto native void SetSlot(int slotId);
193 proto native void SetIndex(int idx);
194 proto native void SetRow(int row);
195 proto native void SetCol(int col);
196 proto native void SetFlip(bool flip);
197
201 proto native void Reset();
202
203 proto native bool CompareLocationOnly(notnull InventoryLocation other);
204
209 proto native bool CollidesWith(notnull InventoryLocation rhs);
210
217 proto native InventoryLocation Copy(notnull InventoryLocation rhs);
224 proto native InventoryLocation CopyLocationFrom(notnull InventoryLocation rhs, bool copyFlip);
225
226 static string DumpToStringNullSafe(InventoryLocation loc)
227 {
228 if (loc)
229 return loc.DumpToString();
230 return "{ null }";
231 }
232
233 string DumpToString()
234 {
235 string res = "{ type=" + typename.EnumToString(InventoryLocationType, GetType());
236 switch (GetType())
237 {
238 case InventoryLocationType.UNKNOWN:
239 {
240 break;
241 }
242 case InventoryLocationType.GROUND:
243 {
244 res = res + " item=" + Object.GetDebugName(GetItem());
245 vector pos = GetPos();
246 float dir[4];
247 GetDir(dir);
248 res = res + " pos=(" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")";
249 res = res + " dir=(" + dir[0] + ", " + dir[1] + ", " + dir[2] + ", " + dir[3] + ")";
250 break;
251 }
252 case InventoryLocationType.ATTACHMENT:
253 {
254 res = res + " item=" + Object.GetDebugName(GetItem());
255 res = res + " parent=" + Object.GetDebugName(GetParent());
256 res = res + " slot=" + GetSlot();
257 break;
258 }
259 case InventoryLocationType.CARGO:
260 {
261 res = res + " item=" + Object.GetDebugName(GetItem());
262 res = res + " parent=" + Object.GetDebugName(GetParent());
263 res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
264 break;
265 }
266 case InventoryLocationType.HANDS:
267 {
268 res = res + " item=" + Object.GetDebugName(GetItem());
269 res = res + " parent=" + Object.GetDebugName(GetParent());
270 break;
271 }
272 case InventoryLocationType.PROXYCARGO:
273 {
274 res = res + " item=" + Object.GetDebugName(GetItem());
275 res = res + " parent=" + Object.GetDebugName(GetParent());
276 res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
277 break;
278 }
279 case InventoryLocationType.VEHICLE:
280 {
281 res = res + " item=" + Object.GetDebugName(GetItem());
282 res = res + " parent=" + Object.GetDebugName(GetParent());
283 res = res + " idx=" + GetIdx();
284 break;
285 }
286 default:
287 {
288 res = res + "??";
289 break;
290 }
291 }
292 res = res + " }";
293 return res;
294 }
295
296 bool ReadFromContext(ParamsReadContext ctx)
297 {
298 EntityAI parent;
299 EntityAI item;
300 int type = 0;
301 int idx = -1;
302 int row = -1;
303 int col = -1;
304 bool flp = false;
305 if (!ctx.Read(type))
306 return false;
307
308 switch (type)
309 {
310 case InventoryLocationType.UNKNOWN:
311 {
312 break;
313 }
314 case InventoryLocationType.GROUND:
315 {
316 if (!ctx.Read(item))
317 return false;
318 vector pos;
319 if (!ctx.Read(pos))
320 return false;
321
322 float dir[4];
323 if (!ctx.Read(dir))
324 return false;
325
326 if (!item)
327 {
328#ifdef ENABLE_LOGGING
329#ifdef SERVER
330 Debug.Log(string.Format("Item=%1 does not exist on server!", Object.GetDebugName(item)), "GROUND" , "n/a", "ReadFromContext", this.ToString() );
331#endif
332#endif
333 break; // parent or item is possibly not spawned in bubble yet
334 }
335
336 SetGroundEx(item, pos, dir);
337 break;
338 }
339 case InventoryLocationType.ATTACHMENT:
340 {
341 if (!ctx.Read(parent))
342 return false;
343 if (!ctx.Read(item))
344 return false;
345 int slot;
346 if (!ctx.Read(slot))
347 return false;
348
349 if (!parent || !item)
350 {
351#ifdef ENABLE_LOGGING
352#ifdef SERVER
353 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() );
354#endif
355#endif
356 break; // parent or item is possibly not spawned in bubble yet
357 }
358
359 SetAttachment(parent, item, slot);
360 break;
361 }
362 case InventoryLocationType.CARGO:
363 {
364 if (!ctx.Read(parent))
365 return false;
366 if (!ctx.Read(item))
367 return false;
368 if (!ctx.Read(idx))
369 return false;
370 if (!ctx.Read(row))
371 return false;
372 if (!ctx.Read(col))
373 return false;
374 if (!ctx.Read(flp))
375 return false;
376
377 if (!parent || !item)
378 {
379#ifdef ENABLE_LOGGING
380#ifdef SERVER
381 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() );
382#endif
383#endif
384 break; // parent or item is possibly not spawned in bubble yet
385 }
386
387 SetCargo(parent, item, idx, row, col, flp);
388 break;
389 }
390 case InventoryLocationType.HANDS:
391 {
392 if (!ctx.Read(parent))
393 return false;
394 if (!ctx.Read(item))
395 return false;
396
397 if (!parent || !item)
398 {
399#ifdef ENABLE_LOGGING
400#ifdef SERVER
401 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() );
402#endif
403#endif
404 break; // parent or item is possibly not spawned in bubble yet
405 }
406
407 SetHands(parent, item);
408 break;
409 }
410 case InventoryLocationType.PROXYCARGO:
411 {
412 if (!ctx.Read(parent))
413 return false;
414 if (!ctx.Read(item))
415 return false;
416 if (!ctx.Read(idx))
417 return false;
418 if (!ctx.Read(row))
419 return false;
420 if (!ctx.Read(col))
421 return false;
422 if (!ctx.Read(flp))
423 return false;
424
425 if (!parent || !item)
426 {
427#ifdef ENABLE_LOGGING
428#ifdef SERVER
429 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() );
430#endif
431#endif
432 break; // parent or item is possibly not spawned in bubble yet
433 }
434
435 SetProxyCargo(parent, item, idx, row, col, flp);
436 break;
437 }
438 case InventoryLocationType.VEHICLE:
439 {
440 if (!ctx.Read(parent))
441 return false;
442 if (!ctx.Read(item))
443 return false;
444 if (!ctx.Read(idx))
445 return false;
446
447 if (!parent || !item)
448 {
449#ifdef ENABLE_LOGGING
450#ifdef SERVER
451 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() );
452#endif
453#endif
454 break; // parent or item is possibly not spawned in bubble yet
455 }
456
457 SetVehicle(parent, item, idx);
458 break;
459 }
460 default:
461 {
462 ErrorEx("ReadFromContext - really unknown location type, this should not happen, type=" + type);
463 return false;
464 }
465 }
466 return true;
467 }
468
469 bool WriteToContext(ParamsWriteContext ctx)
470 {
471 if (!ctx.Write(GetType()))
472 {
473 Error("InventoryLocation::WriteToContext - cannot write to context! failed to write type");
474 return false;
475 }
476
477 switch (GetType())
478 {
479 case InventoryLocationType.UNKNOWN:
480 {
481 break;
482 }
483 case InventoryLocationType.GROUND:
484 {
485 if (!ctx.Write(GetItem()))
486 {
487 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=item");
488 return false;
489 }
490
491 vector pos = GetPos();
492 if (!ctx.Write(pos))
493 {
494 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=pos");
495 return false;
496 }
497
498 float dir[4];
499 GetDir(dir);
500 if (!ctx.Write(dir))
501 {
502 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=dir");
503 return false;
504 }
505
506 break;
507 }
508 case InventoryLocationType.ATTACHMENT:
509 {
510 if (!ctx.Write(GetParent()))
511 {
512 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=parent");
513 return false;
514 }
515 if (!ctx.Write(GetItem()))
516 {
517 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=item");
518 return false;
519 }
520 if (!ctx.Write(GetSlot()))
521 {
522 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=slot");
523 return false;
524 }
525 break;
526 }
527 case InventoryLocationType.CARGO:
528 {
529 if (!ctx.Write(GetParent()))
530 {
531 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=parent");
532 return false;
533 }
534 if (!ctx.Write(GetItem()))
535 {
536 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=item");
537 return false;
538 }
539 if (!ctx.Write(GetIdx()))
540 {
541 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=idx");
542 return false;
543 }
544 if (!ctx.Write(GetRow()))
545 {
546 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=row");
547 return false;
548 }
549 if (!ctx.Write(GetCol()))
550 {
551 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=col");
552 return false;
553 }
554 if (!ctx.Write(GetFlip()))
555 {
556 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=flp");
557 return false;
558 }
559 break;
560 }
561 case InventoryLocationType.HANDS:
562 {
563 if (!ctx.Write(GetParent()))
564 {
565 Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=parent");
566 return false;
567 }
568 if (!ctx.Write(GetItem()))
569 {
570 Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=item");
571 return false;
572 }
573 break;
574 }
575 case InventoryLocationType.PROXYCARGO:
576 {
577 if (!ctx.Write(GetParent()))
578 {
579 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=parent");
580 return false;
581 }
582 if (!ctx.Write(GetItem()))
583 {
584 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=item");
585 return false;
586 }
587 if (!ctx.Write(GetIdx()))
588 {
589 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=idx");
590 return false;
591 }
592 if (!ctx.Write(GetRow()))
593 {
594 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=row");
595 return false;
596 }
597 if (!ctx.Write(GetCol()))
598 {
599 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=col");
600 return false;
601 }
602 if (!ctx.Write(GetFlip()))
603 {
604 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=flp");
605 return false;
606 }
607
608 break;
609 }
610
611 case InventoryLocationType.VEHICLE:
612 {
613 if (!ctx.Write(GetParent()))
614 {
615 Error("InventoryLocation::WriteToContext - cannot write to context! failed VHC, arg=parent");
616 return false;
617 }
618 if (!ctx.Write(GetItem()))
619 {
620 Error("InventoryLocation::WriteToContext - cannot write to context! failed VHC, arg=item");
621 return false;
622 }
623 if (!ctx.Write(GetIdx()))
624 {
625 Error("InventoryLocation::WriteToContext - cannot write to context! failed VHC, arg=idx");
626 return false;
627 }
628 break;
629 }
630 default:
631 {
632 Error("WriteToContext - really unknown location type, this should not happen, type=" + GetType());
633 return false;
634 }
635 }
636 return true;
637 }
638};
639
641{
642 if (loc)
643 {
644 if (!ctx.Write(true))
645 {
646 Error("OptionalLocationWriteToContext - cannot write 1 to context!");
647 return false;
648 }
649 return loc.WriteToContext(ctx);
650 }
651 else
652 {
653 if (!ctx.Write(false))
654 {
655 Error("OptionalLocationWriteToContext - cannot write 0 to context!");
656 return false;
657 }
658 }
659 return true;
660}
661
663{
664 bool present = false;
665 if (!ctx.Read(present))
666 {
667 Error("OptionalLocationReadFromContext - cannot read bool from context!");
668 return false;
669 }
670
671 if (!present)
672 return true;
673
674 loc = new InventoryLocation();
675 if (!loc.ReadFromContext(ctx))
676 {
677 Error("OptionalLocationReadFromContext - cannot read (present) inventorylocation from context!");
678 return false;
679 }
680 return true;
681}
eBleedingSourceType GetType()
represents base for cargo storage for entities
Definition cargo.c:7
Definition debug.c:2
InventoryLocation.
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
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
@ VEHICLE
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
EntityAI GetItem()