* Create a unit (and a carryall if needed). * * @param houseID The House of the new Unit. * @param typeID The type of the new Unit. * @param destination To where on the map this Unit should move. * @return The new created Unit, or NULL if something failed. */
| 1759 | * @return The new created Unit, or NULL if something failed. |
| 1760 | */ |
| 1761 | Unit *Unit_CreateWrapper(uint8 houseID, UnitType typeID, uint16 destination) |
| 1762 | { |
| 1763 | tile32 tile; |
| 1764 | House *h; |
| 1765 | int8 orientation; |
| 1766 | Unit *unit; |
| 1767 | Unit *carryall; |
| 1768 | |
| 1769 | tile = Tile_UnpackTile(Map_FindLocationTile(Tools_Random_256() & 3, houseID)); |
| 1770 | |
| 1771 | h = House_Get_ByIndex(houseID); |
| 1772 | |
| 1773 | { |
| 1774 | tile32 t; |
| 1775 | t.x = 0x2000; |
| 1776 | t.y = 0x2000; |
| 1777 | orientation = Tile_GetDirection(tile, t); |
| 1778 | } |
| 1779 | |
| 1780 | if (g_table_unitInfo[typeID].movementType == MOVEMENT_WINGER) { |
| 1781 | g_validateStrictIfZero++; |
| 1782 | unit = Unit_Create(UNIT_INDEX_INVALID, typeID, houseID, tile, orientation); |
| 1783 | g_validateStrictIfZero--; |
| 1784 | |
| 1785 | if (unit == NULL) return NULL; |
| 1786 | |
| 1787 | unit->o.flags.s.byScenario = true; |
| 1788 | |
| 1789 | if (destination != 0) { |
| 1790 | Unit_SetDestination(unit, destination); |
| 1791 | } |
| 1792 | |
| 1793 | return unit; |
| 1794 | } |
| 1795 | |
| 1796 | g_validateStrictIfZero++; |
| 1797 | carryall = Unit_Create(UNIT_INDEX_INVALID, UNIT_CARRYALL, houseID, tile, orientation); |
| 1798 | g_validateStrictIfZero--; |
| 1799 | |
| 1800 | if (carryall == NULL) { |
| 1801 | if (typeID == UNIT_HARVESTER && h->harvestersIncoming == 0) h->harvestersIncoming++; |
| 1802 | return NULL; |
| 1803 | } |
| 1804 | |
| 1805 | if (House_AreAllied(houseID, g_playerHouseID) || Unit_IsTypeOnMap(houseID, UNIT_CARRYALL)) { |
| 1806 | carryall->o.flags.s.byScenario = true; |
| 1807 | } |
| 1808 | |
| 1809 | tile.x = 0xFFFF; |
| 1810 | tile.y = 0xFFFF; |
| 1811 | |
| 1812 | g_validateStrictIfZero++; |
| 1813 | unit = Unit_Create(UNIT_INDEX_INVALID, typeID, houseID, tile, 0); |
| 1814 | g_validateStrictIfZero--; |
| 1815 | |
| 1816 | if (unit == NULL) { |
| 1817 | Unit_Remove(carryall); |
| 1818 | if (typeID == UNIT_HARVESTER && h->harvestersIncoming == 0) h->harvestersIncoming++; |
no test coverage detected