@@ -71,27 +71,34 @@ ReplaceObjectUpgrade::~ReplaceObjectUpgrade( void )
7171void ReplaceObjectUpgrade::upgradeImplementation ( )
7272{
7373 const ReplaceObjectUpgradeModuleData *data = getReplaceObjectUpgradeModuleData ();
74+ const ThingTemplate* replacementTemplate = TheThingFactory->findTemplate (data->m_replaceObjectName );
7475
75- Object *me = getObject ();
76+ Bool oldObjectSelected;
77+ Int oldObjectSquadNumber;
78+ Matrix3D myMatrix;
79+ Team* myTeam = NULL ;
7680
77- Matrix3D myMatrix = *me->getTransformMatrix ();
78- Team *myTeam = me->getTeam ();// Team implies player. It is a subset.
79-
80- const ThingTemplate *replacementTemplate = TheThingFactory->findTemplate (data->m_replaceObjectName );
81- if ( replacementTemplate == NULL )
8281 {
83- DEBUG_ASSERTCRASH (replacementTemplate != NULL , (" No such object '%s' in ReplaceObjectUpgrade." , data->m_replaceObjectName .str () ) );
84- return ;
85- }
82+ Object* me = getObject ();
8683
87- Drawable* selectedDrawable = TheInGameUI->getFirstSelectedDrawable ();
88- Bool oldObjectSelected = selectedDrawable && selectedDrawable->getID () == me->getDrawable ()->getID ();
89- Int oldObjectSquadNumber = me->getControllingPlayer ()->getSquadNumberForObject (me);
84+ myMatrix = *me->getTransformMatrix ();
85+ myTeam = me->getTeam ();// Team implies player. It is a subset.
9086
91- // Remove us first since occupation of cells is apparently not a refcount, but a flag. If I don't remove, then the new
92- // thing will be placed, and then on deletion I will remove "his" marks.
93- TheAI->pathfinder ()->removeObjectFromPathfindMap ( me );
94- TheGameLogic->destroyObject (me);
87+ if (replacementTemplate == NULL )
88+ {
89+ DEBUG_ASSERTCRASH (replacementTemplate != NULL , (" No such object '%s' in ReplaceObjectUpgrade." , data->m_replaceObjectName .str ()));
90+ return ;
91+ }
92+
93+ Drawable* selectedDrawable = TheInGameUI->getFirstSelectedDrawable ();
94+ oldObjectSelected = selectedDrawable && selectedDrawable->getID () == me->getDrawable ()->getID ();
95+ oldObjectSquadNumber = me->getControllingPlayer ()->getSquadNumberForObject (me);
96+
97+ // Remove us first since occupation of cells is apparently not a refcount, but a flag. If I don't remove, then the new
98+ // thing will be placed, and then on deletion I will remove "his" marks.
99+ TheAI->pathfinder ()->removeObjectFromPathfindMap (me);
100+ TheGameLogic->destroyObject (me);
101+ }
95102
96103 Object *replacementObject = TheThingFactory->newObject (replacementTemplate, myTeam);
97104 replacementObject->setTransformMatrix (&myMatrix);
@@ -109,7 +116,7 @@ void ReplaceObjectUpgrade::upgradeImplementation( )
109116
110117 if ( replacementObject->getControllingPlayer () )
111118 {
112- replacementObject->getControllingPlayer ()->onStructureConstructionComplete (me , replacementObject, FALSE );
119+ replacementObject->getControllingPlayer ()->onStructureConstructionComplete (NULL , replacementObject, FALSE );
113120
114121 if (oldObjectSelected)
115122 {
0 commit comments