* 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 ??. */
| 1440 | * @return ??. |
| 1441 | */ |
| 1442 | bool 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; |
no test coverage detected