* Sets the action the given unit will execute. * * @param u The Unit to set the action for. * @param action The action. */
| 495 | * @param action The action. |
| 496 | */ |
| 497 | void Unit_SetAction(Unit *u, ActionType action) |
| 498 | { |
| 499 | const ActionInfo *ai; |
| 500 | |
| 501 | if (u == NULL) return; |
| 502 | if (u->actionID == ACTION_DESTRUCT || u->actionID == ACTION_DIE || action == ACTION_INVALID) return; |
| 503 | |
| 504 | ai = &g_table_actionInfo[action]; |
| 505 | |
| 506 | switch (ai->switchType) { |
| 507 | case 0: |
| 508 | if (u->currentDestination.x != 0 || u->currentDestination.y != 0) { |
| 509 | u->nextActionID = action; |
| 510 | return; |
| 511 | } |
| 512 | /* FALL-THROUGH */ |
| 513 | case 1: |
| 514 | u->actionID = action; |
| 515 | u->nextActionID = ACTION_INVALID; |
| 516 | u->currentDestination.x = 0; |
| 517 | u->currentDestination.y = 0; |
| 518 | u->o.script.delay = 0; |
| 519 | Script_Reset(&u->o.script, g_scriptUnit); |
| 520 | u->o.script.variables[0] = action; |
| 521 | Script_Load(&u->o.script, u->o.type); |
| 522 | return; |
| 523 | |
| 524 | case 2: |
| 525 | u->o.script.variables[0] = action; |
| 526 | Script_LoadAsSubroutine(&u->o.script, u->o.type); |
| 527 | return; |
| 528 | |
| 529 | default: return; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Adds the specified unit to the specified team. |
no test coverage detected