DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ MoveMaterialAttachmentToGround()

void MoveMaterialAttachmentToGround ( notnull EntityAI parent,
Man player,
notnull ItemBase attachment,
notnull InventoryLocation invloc,
string partName )
protected

The method does not care about the amount of materials that should be returned based on the cached quantity in the ConstructionMaterialData struct. If we start using this method for e.g. drop of materials that are not attached and locked to the construction parent then we need to change the method to handle the quantity accordingly

См. определение в файле ConstructionBase.c строка 1280

1281 {
1282 // 1) base drop position
1283 vector basePos;
1284 bool hasMemPoint = parent.MemoryPointExists(partName + "_materials");
1285 if (hasMemPoint)
1286 basePos = g_Game.ObjectModelToWorld(parent, parent.GetMemoryPointPos(partName + "_materials"));
1287 else if (player)
1288 basePos = player.GetPosition();
1289 else
1290 basePos = attachment.GetPosition();
1291
1292 // 2) capture everything we need BEFORE touching the entity
1293 string itemType = attachment.GetType();
1294 float health = attachment.GetHealth("", "Health");
1295 int total = attachment.GetQuantity();
1296 int stackMax = attachment.GetTargetQuantityMax(-1);
1297 if (stackMax <= 0)
1298 stackMax = 1;
1299
1300 // number of fresh entities needed to carry total at stackMax each
1301 int pileCount = Math.Ceil((float)total / stackMax);
1302 if (pileCount > MAX_MATERIAL_PILES)
1303 {
1304 ErrorEx(string.Format("MoveMaterialAttachmentToGround: pile count %1 exceeds cap %2 for %3 on part %4, truncating!", pileCount, MAX_MATERIAL_PILES, itemType, partName), ErrorExSeverity.INFO);
1305 pileCount = MAX_MATERIAL_PILES;
1306 }
1307
1308 // 3) spawn ALL units as fresh, cleanly-networked ground entities
1309 int remaining = total;
1310 for (int i = 0; i < pileCount; ++i)
1311 {
1312 int thisQty = stackMax;
1313 if (remaining < stackMax)
1314 thisQty = remaining;
1315
1316 float ang = i * 90 * Math.DEG2RAD;
1317 vector dropPos = basePos + Vector(Math.Cos(ang) * 0.45, 0, Math.Sin(ang) * 0.45);
1318
1319 ItemBase newItem = ItemBase.Cast(g_Game.CreateObjectEx(itemType, dropPos, ECE_PLACE_ON_SURFACE));
1320 if (!newItem)
1321 {
1322 ErrorEx("MoveMaterialAttachmentToGround: failed to create '" + itemType + "' on part " + partName + ", aborting drop!");
1323 return; //bail BEFORE deleting the original, so materials aren't lost
1324 }
1325
1326 newItem.SetQuantity(thisQty);
1327 newItem.SetHealth("", "Health", health);
1328 newItem.PlaceOnSurface();
1329
1330 remaining -= thisQty;
1331 }
1332
1333 // 4) remove the original - it never becomes a ground item, so it can never be a stale one
1334 attachment.Delete();
1335 }
const int ECE_PLACE_ON_SURFACE
Определения CentralEconomy.c:38
enum ConstructionMaterialType MAX_MATERIAL_PILES
DayZGame g_Game
Определения DayZGame.c:4074
override bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
Определения PileOfBricks.c:64
Определения EnMath.c:7
Определения EnConvert.c:119
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto float Ceil(float f)
Returns ceil of value.
static const float DEG2RAD
Определения EnMath.c:17

Перекрестные ссылки Math::Ceil(), Math::Cos(), Math::DEG2RAD, ECE_PLACE_ON_SURFACE, ErrorEx, g_Game, MAX_MATERIAL_PILES, ItemBase::SetQuantity(), Math::Sin() и Vector().

Используется в DropNonUsableMaterialsServer().