|
3 | 3 |
|
4 | 4 | #include <SpawnManagerClass.h>
|
5 | 5 | #include <ParticleSystemClass.h>
|
| 6 | +#include <Conversions.h> |
6 | 7 |
|
7 | 8 | #include <Ext/Anim/Body.h>
|
8 | 9 | #include <Ext/Bullet/Body.h>
|
@@ -338,6 +339,97 @@ void TechnoExt::ExtData::EatPassengers()
|
338 | 339 | }
|
339 | 340 | }
|
340 | 341 |
|
| 342 | +void TechnoExt::ExtData::UpdateTiberiumEater() |
| 343 | +{ |
| 344 | + const auto pEaterType = this->TypeExtData->TiberiumEaterType.get(); |
| 345 | + |
| 346 | + if (!pEaterType) |
| 347 | + return; |
| 348 | + |
| 349 | + const int transDelay = pEaterType->TransDelay; |
| 350 | + |
| 351 | + if (transDelay && this->TiberiumEater_Timer.InProgress()) |
| 352 | + return; |
| 353 | + |
| 354 | + const auto pThis = this->OwnerObject(); |
| 355 | + const auto pOwner = pThis->Owner; |
| 356 | + bool active = false; |
| 357 | + const bool displayCash = pEaterType->Display && pThis->IsClearlyVisibleTo(HouseClass::CurrentPlayer); |
| 358 | + int facing = pThis->PrimaryFacing.Current().GetFacing<8>(); |
| 359 | + |
| 360 | + if (facing >= 7) |
| 361 | + facing = 0; |
| 362 | + else |
| 363 | + facing++; |
| 364 | + |
| 365 | + const int cellCount = static_cast<int>(pEaterType->Cells.size()); |
| 366 | + |
| 367 | + for (int idx = 0; idx < cellCount; idx++) |
| 368 | + { |
| 369 | + const auto& cellOffset = pEaterType->Cells[idx]; |
| 370 | + const auto pos = TechnoExt::GetFLHAbsoluteCoords(pThis, CoordStruct { cellOffset.X, cellOffset.Y, 0 }, false); |
| 371 | + const auto pCell = MapClass::Instance.TryGetCellAt(pos); |
| 372 | + |
| 373 | + if (!pCell) |
| 374 | + continue; |
| 375 | + |
| 376 | + if (const int contained = pCell->GetContainedTiberiumValue()) |
| 377 | + { |
| 378 | + const int tiberiumIdx = pCell->GetContainedTiberiumIndex(); |
| 379 | + const int tiberiumValue = TiberiumClass::Array[tiberiumIdx]->Value; |
| 380 | + const int tiberiumAmount = static_cast<int>(static_cast<double>(contained) / tiberiumValue); |
| 381 | + const int amount = pEaterType->AmountPerCell > 0 ? std::min(pEaterType->AmountPerCell.Get(), tiberiumAmount) : tiberiumAmount; |
| 382 | + pCell->ReduceTiberium(amount); |
| 383 | + const float multiplier = pEaterType->CashMultiplier * (1.0f + pOwner->NumOrePurifiers * RulesClass::Instance->PurifierBonus); |
| 384 | + const int value = static_cast<int>(std::round(amount * tiberiumValue * multiplier)); |
| 385 | + pOwner->TransactMoney(value); |
| 386 | + active = true; |
| 387 | + |
| 388 | + if (displayCash) |
| 389 | + { |
| 390 | + auto cellCoords = pCell->GetCoords(); |
| 391 | + cellCoords.Z = std::max(pThis->Location.Z, cellCoords.Z); |
| 392 | + FlyingStrings::AddMoneyString(value, pOwner, pEaterType->DisplayToHouse, cellCoords, pEaterType->DisplayOffset); |
| 393 | + } |
| 394 | + |
| 395 | + const auto& anims = pEaterType->Anims_Tiberiums[tiberiumIdx].GetElements(pEaterType->Anims); |
| 396 | + const int animCount = static_cast<int>(anims.size()); |
| 397 | + |
| 398 | + if (animCount == 0) |
| 399 | + continue; |
| 400 | + |
| 401 | + AnimTypeClass* pAnimType = nullptr; |
| 402 | + |
| 403 | + switch (animCount) |
| 404 | + { |
| 405 | + case 1: |
| 406 | + pAnimType = anims[0]; |
| 407 | + break; |
| 408 | + |
| 409 | + case 8: |
| 410 | + pAnimType = anims[facing]; |
| 411 | + break; |
| 412 | + |
| 413 | + default: |
| 414 | + pAnimType = anims[ScenarioClass::Instance->Random.RandomRanged(0, animCount - 1)]; |
| 415 | + break; |
| 416 | + } |
| 417 | + |
| 418 | + if (pAnimType) |
| 419 | + { |
| 420 | + const auto pAnim = GameCreate<AnimClass>(pAnimType, pos); |
| 421 | + AnimExt::SetAnimOwnerHouseKind(pAnim, pThis->Owner, nullptr, false, true); |
| 422 | + |
| 423 | + if (pEaterType->AnimMove) |
| 424 | + pAnim->SetOwnerObject(pThis); |
| 425 | + } |
| 426 | + } |
| 427 | + } |
| 428 | + |
| 429 | + if (active && transDelay) |
| 430 | + this->TiberiumEater_Timer.Start(pEaterType->TransDelay); |
| 431 | +} |
| 432 | + |
341 | 433 | void TechnoExt::ExtData::UpdateShield()
|
342 | 434 | {
|
343 | 435 | auto const pTypeExt = this->TypeExtData;
|
|
0 commit comments