From 822a8b2ea2d92d3d305af4bc11c6e58f6641aa28 Mon Sep 17 00:00:00 2001 From: avolkov Date: Fri, 2 Jul 2010 16:43:11 +0000 Subject: [PATCH] Split new_ship() into three functions for better readability git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3549 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/uqm/tactrans.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/sc2/src/uqm/tactrans.c b/sc2/src/uqm/tactrans.c index e88439129..9fe565e4a 100644 --- a/sc2/src/uqm/tactrans.c +++ b/sc2/src/uqm/tactrans.c @@ -43,6 +43,8 @@ #include "libs/mathlib.h" +static void cleanup_dead_ship (ELEMENT *ElementPtr); + static BOOLEAN dittyIsPlaying; @@ -285,20 +287,21 @@ readyForBattleEnd (COUNT side) #endif /* defined (NETPLAY) */ } +static void +preprocess_dead_ship (ELEMENT *DeadShipPtr) +{ + ProcessSound ((SOUND)~0, NULL); + (void)DeadShipPtr; // unused argument +} + void -new_ship (ELEMENT *DeadShipPtr) +cleanup_dead_ship (ELEMENT *DeadShipPtr) { STARSHIP *DeadStarShipPtr; ProcessSound ((SOUND)~0, NULL); GetElementStarShip (DeadShipPtr, &DeadStarShipPtr); - if (!(DeadShipPtr->state_flags & PLAYER_SHIP)) - { - if (DeadShipPtr->life_span) /* must be pre-processing */ - return; - } - else { // Ship explosion has finished, or ship has just warped out // if DeadStarShipPtr->crew_level != 0 @@ -360,12 +363,24 @@ new_ship (ELEMENT *DeadShipPtr) DeadShipPtr->life_span = MusicStarted ? (ONE_SECOND * 3) / BATTLE_FRAME_RATE : 1; DeadShipPtr->death_func = new_ship; - DeadShipPtr->preprocess_func = new_ship; + DeadShipPtr->preprocess_func = preprocess_dead_ship; + DeadShipPtr->state_flags &= ~DISAPPEARING; + // XXX: this increment was originally done by another piece of code + // just below this one. I am almost sure it is not needed, but it + // keeps the original framecount. + ++DeadShipPtr->life_span; SetElementStarShip (DeadShipPtr, DeadStarShipPtr); } +} - if (DeadShipPtr->life_span || !readyForBattleEnd ( - DeadStarShipPtr->playerNr)) +void +new_ship (ELEMENT *DeadShipPtr) +{ + STARSHIP *DeadStarShipPtr; + + GetElementStarShip (DeadShipPtr, &DeadStarShipPtr); + + if (!readyForBattleEnd (DeadStarShipPtr->playerNr)) { DeadShipPtr->state_flags &= ~DISAPPEARING; ++DeadShipPtr->life_span; @@ -579,7 +594,7 @@ ship_death (ELEMENT *ShipPtr) ShipPtr->state_flags &= ~DISAPPEARING; ShipPtr->state_flags |= FINITE_LIFE | NONSOLID; ShipPtr->postprocess_func = PostProcessStatus; - ShipPtr->death_func = new_ship; + ShipPtr->death_func = cleanup_dead_ship; ShipPtr->hTarget = 0; ZeroVelocityComponents (&ShipPtr->velocity); if (ShipPtr->crew_level) /* only happens for shofixti self-destruct */ @@ -871,7 +886,7 @@ flee_preprocess (ELEMENT *ElementPtr) } else { - ElementPtr->death_func = new_ship; + ElementPtr->death_func = cleanup_dead_ship; ElementPtr->crew_level = 0; ElementPtr->life_span = HYPERJUMP_LIFE + 1;