Skip to content

Commit

Permalink
Merge pull request #618 from Wargus/animation_vector
Browse files Browse the repository at this point in the history
Animation rewrite
  • Loading branch information
Jarod42 authored Mar 3, 2024
2 parents cc89828 + 8666b7a commit 88ced16
Show file tree
Hide file tree
Showing 45 changed files with 207 additions and 258 deletions.
8 changes: 4 additions & 4 deletions src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ void AnimateActionAttack(CUnit &unit, COrder &order)
// No animation.
// So direct fire missile.
// FIXME : wait a little.
if (unit.Type->Animations && unit.Type->Animations->RangedAttack && unit.IsAttackRanged(order.GetGoal(), order.GetGoalPos())) {
UnitShowAnimation(unit, unit.Type->Animations->RangedAttack);
if (unit.Type->Animations && !unit.Type->Animations->RangedAttack.empty() && unit.IsAttackRanged(order.GetGoal(), order.GetGoalPos())) {
UnitShowAnimation(unit, &unit.Type->Animations->RangedAttack);
} else {
if (!unit.Type->Animations || !unit.Type->Animations->Attack) {
if (!unit.Type->Animations || unit.Type->Animations->Attack.empty()) {
order.OnAnimationAttack(unit);
return;
}
UnitShowAnimation(unit, unit.Type->Animations->Attack);
UnitShowAnimation(unit, &unit.Type->Animations->Attack);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/action/action_board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void COrder_Board::Execute(CUnit &unit) /* override */
if (this->WaitForTransporter(unit)) {
this->State = State_EnterTransporter;
} else {
UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, &unit.Type->Animations->Still);
}
break;

Expand Down
10 changes: 5 additions & 5 deletions src/action/action_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ bool COrder_Build::StartBuilding(CUnit &unit, CUnit &ontop)

// We need somebody to work on it.
if (!type.BoolFlag[BUILDEROUTSIDE_INDEX].value) {
UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, &unit.Type->Animations->Still);
unit.Remove(build);
this->State = State_BuildFromInside;
if (unit.Selected) {
Expand All @@ -402,10 +402,10 @@ static void AnimateActionBuild(CUnit &unit)
if (animations == nullptr) {
return ;
}
if (animations->Build) {
UnitShowAnimation(unit, animations->Build);
} else if (animations->Repair) {
UnitShowAnimation(unit, animations->Repair);
if (!animations->Build.empty()) {
UnitShowAnimation(unit, &animations->Build);
} else if (!animations->Repair.empty()) {
UnitShowAnimation(unit, &animations->Repair);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/action/action_die.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ static bool AnimateActionDie(CUnit &unit)
if (animations == nullptr) {
return false;
}
if (animations->Death[unit.DamagedType]) {
UnitShowAnimation(unit, animations->Death[unit.DamagedType]);
if (!animations->Death[unit.DamagedType].empty()) {
UnitShowAnimation(unit, &animations->Death[unit.DamagedType]);
return true;
} else if (animations->Death[ANIMATIONS_DEATHTYPES]) {
UnitShowAnimation(unit, animations->Death[ANIMATIONS_DEATHTYPES]);
} else if (!animations->Death[ANIMATIONS_DEATHTYPES].empty()) {
UnitShowAnimation(unit, &animations->Death[ANIMATIONS_DEATHTYPES]);
return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/action/action_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ int DoActionMove(CUnit &unit)
Vec2i posd; // movement in tile.
int d;

if (unit.Moving != 1 && (unit.Type->Animations->Move != unit.Anim.CurrAnim || !unit.Anim.Wait)) {
if (unit.Moving != 1 && (&unit.Type->Animations->Move != unit.Anim.CurrAnim || !unit.Anim.Wait)) {
if (unit.Anim.Unbreakable && unit.Moving > 1) {
// subtile movement, we're finished, but inside an unbreakable animation that we have to finish
int m = UnitShowAnimationScaled(unit, unit.Type->Animations->Move, 1) >> 1;
int m = UnitShowAnimationScaled(unit, &unit.Type->Animations->Move, 1) >> 1;
applyResidualDisplacementCorrection(&unit.IX, m);
applyResidualDisplacementCorrection(&unit.IY, m);
if (unit.Anim.Unbreakable) {
Expand Down Expand Up @@ -248,7 +248,7 @@ int DoActionMove(CUnit &unit)
}

unit.pathFinderData->output.Cycles++;// reset have to be manualy controlled by caller.
int move = UnitShowAnimationScaled(unit, unit.Type->Animations->Move, Map.Field(unit.Offset)->getCost());
int move = UnitShowAnimationScaled(unit, &unit.Type->Animations->Move, Map.Field(unit.Offset)->getCost());

bool reached_next_tile = false;
if (posd.x) {
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_repair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool COrder_Repair::RepairUnit(const CUnit &unit, CUnit &goal)
*/
static void AnimateActionRepair(CUnit &unit)
{
UnitShowAnimation(unit, unit.Type->Animations->Repair);
UnitShowAnimation(unit, &unit.Type->Animations->Repair);
}

void COrder_Repair::Execute(CUnit &unit) /* override */
Expand Down
2 changes: 1 addition & 1 deletion src/action/action_research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void COrder_Research::Execute(CUnit &unit) /* override */
const CUnitType &type = *unit.Type;


UnitShowAnimation(unit, type.Animations->Research ? type.Animations->Research : type.Animations->Still);
UnitShowAnimation(unit, !type.Animations->Research.empty() ? &type.Animations->Research : &type.Animations->Still);
if (unit.Wait) {
unit.Wait--;
return ;
Expand Down
4 changes: 2 additions & 2 deletions src/action/action_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ int COrder_Resource::StartGathering(CUnit &unit)
*/
static void AnimateActionHarvest(CUnit &unit)
{
Assert(unit.Type->Animations->Harvest[unit.CurrentResource]);
UnitShowAnimation(unit, unit.Type->Animations->Harvest[unit.CurrentResource]);
Assert(!unit.Type->Animations->Harvest[unit.CurrentResource].empty());
UnitShowAnimation(unit, &unit.Type->Animations->Harvest[unit.CurrentResource]);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/action/action_spellcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ static void AnimateActionSpellCast(CUnit &unit, COrder_SpellCast &order)
{
const CAnimations *animations = unit.Type->Animations;

if (!animations || (!animations->Attack && !animations->SpellCast)) {
if (!animations || (animations->Attack.empty() && animations->SpellCast.empty())) {
// if don't have animations just cast spell
order.OnAnimationAttack(unit);
return;
}
if (animations->SpellCast) {
UnitShowAnimation(unit, animations->SpellCast);
if (!animations->SpellCast.empty()) {
UnitShowAnimation(unit, &animations->SpellCast);
} else {
UnitShowAnimation(unit, animations->Attack);
UnitShowAnimation(unit, &animations->Attack);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/action/action_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,15 @@ void COrder_Still::Execute(CUnit &unit) /* override */
{
// If unit is not bunkered and removed, wait
if (unit.Removed
&& (unit.Container == nullptr || unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false)) {
return ;
&& (unit.Container == nullptr
|| unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false)) {
return;
}
this->Finished = false;

switch (this->State) {
case SUB_STILL_STANDBY:
UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, &unit.Type->Animations->Still);
break;
case SUB_STILL_ATTACK: // attacking unit in attack range.
AnimateActionAttack(unit, *this);
Expand Down
6 changes: 3 additions & 3 deletions src/action/action_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ static bool CanHandleOrder(const CUnit &unit, COrder *order)

static void AnimateActionTrain(CUnit &unit)
{
if (unit.Type->Animations->Train) {
UnitShowAnimation(unit, unit.Type->Animations->Train);
if (!unit.Type->Animations->Train.empty()) {
UnitShowAnimation(unit, &unit.Type->Animations->Train);
} else {
UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, &unit.Type->Animations->Still);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/action/action_upgradeto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static void AnimateActionUpgradeTo(CUnit &unit)
{
CAnimations &animations = *unit.Type->Animations;

UnitShowAnimation(unit, animations.Upgrade ? animations.Upgrade : animations.Still);
UnitShowAnimation(unit, !animations.Upgrade.empty() ? &animations.Upgrade : &animations.Still);
}

void COrder_UpgradeTo::Execute(CUnit &unit) /* override */
Expand Down
2 changes: 1 addition & 1 deletion src/action/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool COrder::IsWaiting(CUnit &unit)
unit.Waiting = 1;
unit.WaitBackup = unit.Anim;
}
UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, &unit.Type->Animations->Still);
unit.Wait--;
return true;
}
Expand Down
Loading

0 comments on commit 88ced16

Please sign in to comment.