MCPcopy Index your code
hub / github.com/OpenDUNE/OpenDUNE / Structure_BuildObject

Function Structure_BuildObject

src/structure.c:1442–1681  ·  view source on GitHub ↗

* Make the given Structure build an object. * * @param s The Structure. * @param objectType The type of the object to build or a special value (0xFFFD, 0xFFFE, 0xFFFF). * @return ??. */

Source from the content-addressed store, hash-verified

1440 * @return ??.
1441 */
1442bool Structure_BuildObject(Structure *s, uint16 objectType)
1443{
1444 const StructureInfo *si;
1445 const char *str;
1446 Object *o;
1447 ObjectInfo *oi;
1448
1449 if (s == NULL) return false;
1450
1451 si = &g_table_structureInfo[s->o.type];
1452
1453 if (!si->o.flags.factory) return false;
1454
1455 Structure_SetRepairingState(s, 0, NULL);
1456
1457 if (objectType == 0xFFFD) {
1458 Structure_SetUpgradingState(s, 1, NULL);
1459 return false;
1460 }
1461
1462 if (objectType == 0xFFFF || objectType == 0xFFFE) {
1463 uint16 upgradeCost = 0;
1464 uint32 buildable;
1465
1466 if (Structure_IsUpgradable(s) && si->o.hitpoints == s->o.hitpoints) {
1467 upgradeCost = (si->o.buildCredits + (si->o.buildCredits >> 15)) / 2;
1468 }
1469
1470 if (upgradeCost != 0 && s->o.type == STRUCTURE_HIGH_TECH && s->o.houseID == HOUSE_HARKONNEN) upgradeCost = 0;
1471 if (s->o.type == STRUCTURE_STARPORT) upgradeCost = 0;
1472
1473 buildable = Structure_GetBuildable(s);
1474
1475 if (buildable == 0) {
1476 s->objectType = 0;
1477 return false;
1478 }
1479
1480 if (s->o.type == STRUCTURE_CONSTRUCTION_YARD) {
1481 uint8 i;
1482
1483 g_factoryWindowConstructionYard = true;
1484
1485 for (i = 0; i < STRUCTURE_MAX; i++) {
1486 if ((buildable & (1 << i)) == 0) continue;
1487 g_table_structureInfo[i].o.available = 1;
1488 if (objectType != 0xFFFE) continue;
1489 s->objectType = i;
1490 return false;
1491 }
1492 } else {
1493 g_factoryWindowConstructionYard = false;
1494
1495 if (s->o.type == STRUCTURE_STARPORT) {
1496 uint8 linkedID = 0xFF;
1497 int16 availableUnits[UNIT_MAX];
1498 Unit *u;
1499 bool loop;

Callers 5

GameLoop_StructureFunction · 0.85
Structure_CreateFunction · 0.85
GUI_Widget_Picture_ClickFunction · 0.85

Calls 15

Structure_IsUpgradableFunction · 0.85
Structure_GetBuildableFunction · 0.85
Unit_AllocateFunction · 0.85
Unit_Get_ByIndexFunction · 0.85
Unit_FreeFunction · 0.85
Sprites_UnloadTilesFunction · 0.85
GUI_ChangeSelectionTypeFunction · 0.85
Timer_SetTimerFunction · 0.85
GUI_DisplayFactoryWindowFunction · 0.85
Sprites_LoadTilesFunction · 0.85

Tested by

no test coverage detected