* Sets the position of the given unit. * * @param u The Unit to set the position for. * @position The position. * @return True if and only if the position changed. */
| 844 | * @return True if and only if the position changed. |
| 845 | */ |
| 846 | bool Unit_SetPosition(Unit *u, tile32 position) |
| 847 | { |
| 848 | const UnitInfo *ui; |
| 849 | |
| 850 | if (u == NULL) return false; |
| 851 | |
| 852 | ui = &g_table_unitInfo[u->o.type]; |
| 853 | u->o.flags.s.isNotOnMap = false; |
| 854 | |
| 855 | u->o.position = Tile_Center(position); |
| 856 | |
| 857 | if (u->originEncoded == 0) Unit_FindClosestRefinery(u); |
| 858 | |
| 859 | u->o.script.variables[4] = 0; |
| 860 | |
| 861 | if (Unit_IsTileOccupied(u)) { |
| 862 | u->o.flags.s.isNotOnMap = true; |
| 863 | return false; |
| 864 | } |
| 865 | |
| 866 | u->currentDestination.x = 0; |
| 867 | u->currentDestination.y = 0; |
| 868 | u->targetMove = 0; |
| 869 | u->targetAttack = 0; |
| 870 | |
| 871 | if (g_map[Tile_PackTile(u->o.position)].isUnveiled) { |
| 872 | /* A new unit being delivered fresh from the factory; force a seenByHouses |
| 873 | * update and add it to the statistics etc. */ |
| 874 | u->o.seenByHouses &= ~(1 << u->o.houseID); |
| 875 | Unit_HouseUnitCount_Add(u, g_playerHouseID); |
| 876 | } |
| 877 | |
| 878 | if (u->o.houseID != g_playerHouseID || u->o.type == UNIT_HARVESTER || u->o.type == UNIT_SABOTEUR) { |
| 879 | Unit_SetAction(u, ui->actionAI); |
| 880 | } else { |
| 881 | Unit_SetAction(u, ui->o.actionsPlayer[3]); |
| 882 | } |
| 883 | |
| 884 | u->spriteOffset = 0; |
| 885 | |
| 886 | Unit_UpdateMap(1, u); |
| 887 | |
| 888 | return true; |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * Remove the Unit from the game, doing all required administration for it, like |
no test coverage detected