unit references updated
This commit is contained in:
parent
6325d69f3e
commit
3406a2dc5e
2 changed files with 74 additions and 3 deletions
src/action
|
@ -57,7 +57,7 @@ local int WaitForTransporter(Unit* unit)
|
|||
{
|
||||
Unit* trans;
|
||||
|
||||
unit->Wait=1;
|
||||
unit->Wait=6;
|
||||
unit->Reset=1;
|
||||
|
||||
trans=unit->Command.Data.Move.Goal;
|
||||
|
@ -66,6 +66,21 @@ local int WaitForTransporter(Unit* unit)
|
|||
DebugLevel3("TRANSPORTER NOT REACHED %d,%d\n",unit->X,unit->Y);
|
||||
return 0;
|
||||
}
|
||||
#ifdef NEW_UNIT
|
||||
if( trans->Destroyed ) {
|
||||
DebugLevel0(__FUNCTION__": destroyed unit\n");
|
||||
if( !--trans->Refs ) {
|
||||
ReleaseUnit(trans);
|
||||
}
|
||||
unit->Command.Data.Move.Goal=trans=NoUnitP;
|
||||
return 0;
|
||||
} else if( trans->Removed ||
|
||||
!trans->HP || trans->Command.Action==UnitActionDie ) {
|
||||
--trans->Refs;
|
||||
unit->Command.Data.Move.Goal=trans=NoUnitP;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( MapDistanceToUnit(unit->X,unit->Y,trans)==1 ) {
|
||||
DebugLevel3("Enter transporter\n");
|
||||
|
@ -92,6 +107,21 @@ local void EnterTransporter(Unit* unit)
|
|||
unit->SubAction=0;
|
||||
|
||||
transporter=unit->Command.Data.Move.Goal;
|
||||
#ifdef NEW_UNIT
|
||||
if( transporter->Destroyed ) {
|
||||
DebugLevel0(__FUNCTION__": destroyed unit\n");
|
||||
if( !--transporter->Refs ) {
|
||||
ReleaseUnit(transporter);
|
||||
}
|
||||
return;
|
||||
} else if( transporter->Removed ||
|
||||
!transporter->HP || transporter->Command.Action==UnitActionDie ) {
|
||||
--transporter->Refs;
|
||||
return;
|
||||
}
|
||||
--transporter->Refs;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Find free slot in transporter.
|
||||
//
|
||||
|
@ -151,6 +181,9 @@ global void HandleActionBoard(Unit* unit)
|
|||
if( i==-1 ) {
|
||||
if( ++unit->SubAction==200 ) {
|
||||
unit->Command.Action=UnitActionStill;
|
||||
if( unit->Command.Data.Move.Goal ) {
|
||||
--unit->Command.Data.Move.Goal->Refs;
|
||||
}
|
||||
unit->SubAction=0;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -57,11 +57,34 @@ global void HandleActionDemolish(Unit* unit)
|
|||
// Move near to target.
|
||||
//
|
||||
case 0:
|
||||
// FIXME: RESET FIRST!!
|
||||
// FIXME: reset first!! why? (johns)
|
||||
err=HandleActionMove(unit);
|
||||
if( unit->Reset ) {
|
||||
goal=unit->Command.Data.Move.Goal;
|
||||
|
||||
#ifdef NEW_UNIT
|
||||
//
|
||||
// Target is dead, stop demolish
|
||||
//
|
||||
if( goal ) {
|
||||
if( goal->Destroyed ) {
|
||||
DebugLevel0(__FUNCTION__": destroyed unit\n");
|
||||
if( !--goal->Refs ) {
|
||||
ReleaseUnit(goal);
|
||||
}
|
||||
unit->Command.Data.Move.Goal=goal=NoUnitP;
|
||||
// FIXME: perhaps I should choose an alternative
|
||||
unit->Command.Action=UnitActionStill;
|
||||
return;
|
||||
} else if( goal->Removed || !goal->HP
|
||||
|| goal->Command.Action==UnitActionDie ) {
|
||||
--goal->Refs;
|
||||
unit->Command.Data.Move.Goal=goal=NoUnitP;
|
||||
// FIXME: perhaps I should choose an alternative
|
||||
unit->Command.Action=UnitActionStill;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Target is dead, stop demolish
|
||||
//
|
||||
|
@ -72,6 +95,7 @@ global void HandleActionDemolish(Unit* unit)
|
|||
unit->Command.Action=UnitActionStill;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Have reached target?
|
||||
|
@ -97,16 +121,30 @@ global void HandleActionDemolish(Unit* unit)
|
|||
// Demolish the target.
|
||||
//
|
||||
case 1:
|
||||
#ifdef NEW_UNIT
|
||||
goal=unit->Command.Data.Move.Goal;
|
||||
if( goal ) {
|
||||
--goal->Refs;
|
||||
}
|
||||
#endif
|
||||
|
||||
x=unit->X;
|
||||
y=unit->Y;
|
||||
DestroyUnit(unit);
|
||||
// FIXME: Must play explosion sound
|
||||
|
||||
//
|
||||
// Effect of the explosion on units.
|
||||
//
|
||||
n=SelectUnits(x-2,y-2, x+2, y+2,table);
|
||||
// FIXME: Don't hit flying units!
|
||||
for( i=0; i<n; ++i ) {
|
||||
HitUnit(table[i],DEMOLISH_DAMAGE);
|
||||
}
|
||||
|
||||
//
|
||||
// Terrain effect of the explosion
|
||||
//
|
||||
for( ix=x-2; ix<=x+2; ix++ ) {
|
||||
for( iy=y-2; iy<=y+2; iy++ ) {
|
||||
n=TheMap.Fields[ix+iy*TheMap.Width].Flags;
|
||||
|
|
Loading…
Add table
Reference in a new issue