MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Structure_CalculateHitpointsMax

Function Structure_CalculateHitpointsMax

src/structure.c:623–658  ·  view source on GitHub ↗

* Calculate the power usage and production, and the credits storage. * * @param h The house to calculate the numbers for. */

Source from the content-addressed store, hash-verified

621 * @param h The house to calculate the numbers for.
622 */
623void Structure_CalculateHitpointsMax(House *h)
624{
625 PoolFindStruct find;
626 uint16 power = 0;
627
628 if (h == NULL) return;
629
630 if (h->index == g_playerHouseID) House_UpdateRadarState(h);
631
632 if (h->powerUsage == 0) {
633 power = 256;
634 } else {
635 power = min(h->powerProduction * 256 / h->powerUsage, 256);
636 }
637
638 find.houseID = h->index;
639 find.index = 0xFFFF;
640 find.type = 0xFFFF;
641
642 while (true) {
643 const StructureInfo *si;
644 Structure *s;
645
646 s = Structure_Find(&find);
647 if (s == NULL) return;
648 if (s->o.type == STRUCTURE_SLAB_1x1 || s->o.type == STRUCTURE_SLAB_2x2 || s->o.type == STRUCTURE_WALL) continue;
649
650 si = &g_table_structureInfo[s->o.type];
651
652 s->hitpointsMax = si->o.hitpoints * power / 256;
653 s->hitpointsMax = max(s->hitpointsMax, si->o.hitpoints / 2);
654
655 if (s->hitpointsMax >= s->o.hitpoints) continue;
656 Structure_Damage(s, 1, 0);
657 }
658}
659
660/**
661 * Set the state for the given structure.

Callers 1

GameLoop_HouseFunction · 0.85

Calls 3

House_UpdateRadarStateFunction · 0.85
Structure_FindFunction · 0.85
Structure_DamageFunction · 0.85

Tested by

no test coverage detected