MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Unit_SetAction

Function Unit_SetAction

src/unit.c:497–531  ·  view source on GitHub ↗

* Sets the action the given unit will execute. * * @param u The Unit to set the action for. * @param action The action. */

Source from the content-addressed store, hash-verified

495 * @param action The action.
496 */
497void 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.

Callers 15

Scenario_Load_UnitFunction · 0.85
Map_MakeExplosionFunction · 0.85
Map_Bloom_ExplodeSpecialFunction · 0.85
GameLoop_UnitFunction · 0.85
Unit_CreateFunction · 0.85
Unit_SetPositionFunction · 0.85
Unit_Deviation_DecreaseFunction · 0.85
Unit_DeviateFunction · 0.85
Unit_MoveFunction · 0.85
Unit_DamageFunction · 0.85

Calls 3

Script_ResetFunction · 0.85
Script_LoadFunction · 0.85
Script_LoadAsSubroutineFunction · 0.85

Tested by

no test coverage detected