* Set a new target, and rotate towards him if needed. * * Stack: 1 - An encoded tile of the unit/tile to target. * * @param script The script engine to operate on. * @return The new target. */
| 832 | * @return The new target. |
| 833 | */ |
| 834 | uint16 Script_Unit_SetTarget(ScriptEngine *script) |
| 835 | { |
| 836 | Unit *u; |
| 837 | uint16 target; |
| 838 | tile32 tile; |
| 839 | int8 orientation; |
| 840 | |
| 841 | u = g_scriptCurrentUnit; |
| 842 | |
| 843 | target = STACK_PEEK(1); |
| 844 | |
| 845 | if (target == 0 || !Tools_Index_IsValid(target)) { |
| 846 | u->targetAttack = 0; |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | tile = Tools_Index_GetTile(target); |
| 851 | |
| 852 | orientation = Tile_GetDirection(u->o.position, tile); |
| 853 | |
| 854 | u->targetAttack = target; |
| 855 | if (!g_table_unitInfo[u->o.type].o.flags.hasTurret) { |
| 856 | u->targetMove = target; |
| 857 | Unit_SetOrientation(u, orientation, false, 0); |
| 858 | } |
| 859 | Unit_SetOrientation(u, orientation, false, 1); |
| 860 | |
| 861 | return u->targetAttack; |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * Sets the action for the current unit. |
nothing calls this directly
no test coverage detected