NEW_ORDERS are now only supported, old code removed.

This commit is contained in:
johns 2001-03-25 22:06:45 +00:00
parent cb3d6232ef
commit 1fb8ed8766
3 changed files with 4 additions and 331 deletions

View file

@ -78,11 +78,7 @@ local int MoveToResource(Unit* unit,const Resource* resource)
switch( DoActionMove(unit) ) { // reached end-point?
case PF_UNREACHABLE:
#ifdef NEW_ORDERS
unit->Orders[0].Action=resource->Action;
#else
unit->Command.Action=resource->Action;
#endif
DebugCheck( unit->Orders[0].Action!=resource->Action );
return -1;
case PF_REACHED:
break;
@ -90,7 +86,6 @@ local int MoveToResource(Unit* unit,const Resource* resource)
return 0;
}
#ifdef NEW_ORDERS
goal=unit->Orders[0].Goal;
if( !goal ) { // Move checks for killed units.
@ -151,70 +146,6 @@ local int MoveToResource(Unit* unit,const Resource* resource)
goal->Data.Resource.Active++;
DebugLevel3Fn("+%d\n",goal->Data.Resource.Active);
#else
goal=unit->Command.Data.Move.Goal;
if( !goal ) { // Move checks for killed units.
// FIXME: perhaps we should choose an alternative
unit->SubAction=0;
unit->Command.Action=UnitActionStill;
return 0;
}
DebugCheck( !goal );
DebugCheck( unit->Wait!=1 );
DebugCheck( MapDistanceToUnit(unit->X,unit->Y,goal)!=1 );
//
// Target is dead, stop getting resources.
//
if( goal->Destroyed ) {
DebugLevel0Fn("Destroyed unit\n");
RefsDebugCheck( !goal->Refs );
if( !--goal->Refs ) {
ReleaseUnit(goal);
}
unit->Command.Data.Move.Goal=NoUnitP;
// FIXME: perhaps we should choose an alternative
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
return 0;
} else if( goal->Removed || !goal->HP
|| goal->Command.Action==UnitActionDie ) {
RefsDebugCheck( !goal->Refs );
--goal->Refs;
RefsDebugCheck( !goal->Refs );
unit->Command.Data.Move.Goal=NoUnitP;
// FIXME: perhaps we should choose an alternative
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
return 0;
}
unit->Command.Action=resource->Action;
//
// If resource is still under construction, wait!
//
if( goal->Command.Action==UnitActionBuilded ) {
DebugLevel2Fn("Invalid resource\n");
return 0;
}
RefsDebugCheck( !goal->Refs );
--goal->Refs;
RefsDebugCheck( !goal->Refs );
unit->Command.Data.Move.Goal=NoUnitP;
//
// Activate the resource
//
goal->Command.Data.Resource.Active++;
DebugLevel3Fn("+%d\n",goal->Command.Data.Resource.Active);
#endif
if( !goal->Frame ) { // show resource working
goal->Frame=resource->Frame;
CheckUnitToBeDrawn(goal);
@ -273,19 +204,11 @@ local int WaitInResource(Unit* unit,const Resource* resource)
// Remove what we can carry, FIXME: always this?
//
source->Value-=DEFAULT_INCOMES[resource->Cost];
#ifdef NEW_ORDERS
DebugLevel3Fn("-%d\n",source->Data.Resource.Active);
if( !--source->Data.Resource.Active ) {
source->Frame=0;
CheckUnitToBeDrawn(source);
}
#else
DebugLevel3Fn("-%d\n",source->Command.Data.Resource.Active);
if( !--source->Command.Data.Resource.Active ) {
source->Frame=0;
CheckUnitToBeDrawn(source);
}
#endif
if( IsSelected(source) ) {
MustRedraw|=RedrawInfoPanel;
}
@ -323,7 +246,6 @@ local int WaitInResource(Unit* unit,const Resource* resource)
} else {
DropOutOnSide(unit,LookingW,1,1);
}
#ifdef NEW_ORDERS
unit->Orders[0].Action=UnitActionStill;
unit->SubAction=0;
// should return 0, done below!
@ -331,7 +253,6 @@ local int WaitInResource(Unit* unit,const Resource* resource)
DropOutNearest(unit,depot->X+depot->Type->TileWidth/2
,depot->Y+depot->Type->TileHeight/2
,source->Type->TileWidth,source->Type->TileHeight);
ResetPath(unit->Orders[0]);
unit->Orders[0].Goal=depot;
RefsDebugCheck( !depot->Refs );
++depot->Refs;
@ -348,31 +269,6 @@ local int WaitInResource(Unit* unit,const Resource* resource)
}
unit->Wait=1;
return unit->Orders[0].Action==resource->Action;
#else
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
// should return 0, done below!
} else {
DropOutNearest(unit,depot->X+depot->Type->TileWidth/2
,depot->Y+depot->Type->TileHeight/2
,source->Type->TileWidth,source->Type->TileHeight);
ResetPath(unit->Command);
unit->Command.Data.Move.Goal=depot;
RefsDebugCheck( !depot->Refs );
++depot->Refs;
unit->Command.Data.Move.Range=1;
unit->Command.Data.Move.DX=-1;
unit->Command.Data.Move.DY=-1;
unit->Command.Action=resource->Action;
}
CheckUnitToBeDrawn(unit);
if( IsSelected(unit) ) {
UpdateButtonPanel();
}
unit->Wait=1;
return unit->Command.Action==resource->Action;
#endif
}
//
@ -401,11 +297,7 @@ local int MoveToDepot(Unit* unit,const Resource* resource)
switch( DoActionMove(unit) ) { // reached end-point?
case PF_UNREACHABLE:
#ifdef NEW_ORDERS
unit->Orders[0].Action=resource->Action;
#else
unit->Command.Action=resource->Action;
#endif
DebugCheck( unit->Orders[0].Action!=resource->Action );
return -1;
case PF_REACHED:
break;
@ -413,7 +305,6 @@ local int MoveToDepot(Unit* unit,const Resource* resource)
return 0;
}
#ifdef NEW_ORDERS
goal=unit->Orders[0].Goal;
if( !goal ) { // Move checks for killed units.
@ -460,64 +351,6 @@ local int MoveToDepot(Unit* unit,const Resource* resource)
RefsDebugCheck( !goal->Refs );
unit->Orders[0].Goal=NoUnitP;
#else
goal=unit->Command.Data.Move.Goal;
if( !goal ) { // Move checks for killed units.
// FIXME: perhaps we should choose an alternative
unit->SubAction=0;
unit->Command.Action=UnitActionStill;
return 0;
}
DebugCheck( !goal );
DebugCheck( unit->Wait!=1 );
DebugCheck( MapDistanceToUnit(unit->X,unit->Y,goal)!=1 );
//
// Target is dead, stop getting resources.
//
if( goal->Destroyed ) {
DebugLevel0Fn("Destroyed unit\n");
RefsDebugCheck( !goal->Refs );
if( !--goal->Refs ) {
ReleaseUnit(goal);
}
unit->Command.Data.Move.Goal=NoUnitP;
// FIXME: perhaps we should choose an alternative
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
return 0;
} else if( goal->Removed || !goal->HP
|| goal->Command.Action==UnitActionDie ) {
RefsDebugCheck( !goal->Refs );
--goal->Refs;
RefsDebugCheck( !goal->Refs );
unit->Command.Data.Move.Goal=NoUnitP;
// FIXME: perhaps we should choose an alternative
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
return 0;
}
unit->Command.Action=resource->Action;
//
// If depot is still under construction, wait!
//
if( goal->Command.Action==UnitActionBuilded ) {
DebugLevel2Fn("Invalid depot\n");
return 0;
}
RefsDebugCheck( !goal->Refs );
--goal->Refs;
RefsDebugCheck( !goal->Refs );
unit->Command.Data.Move.Goal=NoUnitP;
#endif
//
// Place unit inside the depot
//
@ -573,7 +406,6 @@ local int WaitInDepot(Unit* unit,const Resource* resource)
DebugLevel3Fn("Waiting\n");
if( !unit->Value ) {
#ifdef NEW_ORDERS
depot=resource->DepositOnMap(unit->X,unit->Y);
DebugCheck( !depot );
// Could be destroyed, but than we couldn't be in?
@ -588,7 +420,6 @@ local int WaitInDepot(Unit* unit,const Resource* resource)
DropOutNearest(unit,goal->X+goal->Type->TileWidth/2
,goal->Y+goal->Type->TileHeight/2
,depot->Type->TileWidth,depot->Type->TileHeight);
ResetPath(unit->Command);
unit->Orders[0].Goal=goal;
RefsDebugCheck( !goal->Refs );
++goal->Refs;
@ -601,35 +432,6 @@ local int WaitInDepot(Unit* unit,const Resource* resource)
CheckUnitToBeDrawn(unit);
unit->Wait=1;
return unit->Orders[0].Action==resource->Action;
#else
depot=resource->DepositOnMap(unit->X,unit->Y);
DebugCheck( !depot );
// Could be destroyed, but than we couldn't be in?
// FIXME: return to last position!
if( !(goal=resource->FindResource(unit->Player,unit->X,unit->Y)) ) {
DropOutOnSide(unit,LookingW
,depot->Type->TileWidth,depot->Type->TileHeight);
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
} else {
DropOutNearest(unit,goal->X+goal->Type->TileWidth/2
,goal->Y+goal->Type->TileHeight/2
,depot->Type->TileWidth,depot->Type->TileHeight);
ResetPath(unit->Command);
unit->Command.Data.Move.Goal=goal;
RefsDebugCheck( !goal->Refs );
++goal->Refs;
unit->Command.Data.Move.Range=1;
unit->Command.Data.Move.DX=-1;
unit->Command.Data.Move.DY=-1;
unit->Command.Action=resource->Action;
}
CheckUnitToBeDrawn(unit);
unit->Wait=1;
return unit->Command.Action==resource->Action;
#endif
}
//
@ -671,7 +473,6 @@ global void HandleActionResource(Unit* unit,const Resource* resource)
if( (ret=MoveToResource(unit,resource)) ) {
if( ret==-1 ) {
if( ++unit->SubAction==5 ) {
#ifdef NEW_ORDERS
unit->Orders[0].Action=UnitActionStill;
unit->SubAction=0;
if( unit->Orders[0].Goal ) {
@ -680,16 +481,6 @@ global void HandleActionResource(Unit* unit,const Resource* resource)
RefsDebugCheck( !unit->Orders[0].Goal->Refs );
unit->Orders[0].Goal=NoUnitP;
}
#else
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
if( unit->Command.Data.Move.Goal ) {
RefsDebugCheck(!unit->Command.Data.Move.Goal->Refs);
--unit->Command.Data.Move.Goal->Refs;
RefsDebugCheck(!unit->Command.Data.Move.Goal->Refs);
unit->Command.Data.Move.Goal=NoUnitP;
}
#endif
} else { // Do a little delay
unit->Wait*=unit->SubAction;
DebugLevel0Fn("Retring\n");
@ -720,7 +511,6 @@ global void HandleActionResource(Unit* unit,const Resource* resource)
if( (ret=MoveToDepot(unit,resource)) ) {
if( ret==-1 ) {
if( ++unit->SubAction==70 ) {
#ifdef NEW_ORDERS
unit->Orders[0].Action=UnitActionStill;
unit->SubAction=0;
if( unit->Orders[0].Goal ) {
@ -729,16 +519,6 @@ global void HandleActionResource(Unit* unit,const Resource* resource)
RefsDebugCheck( !unit->Orders[0].Goal->Refs );
unit->Orders[0].Goal=NoUnitP;
}
#else
unit->Command.Action=UnitActionStill;
unit->SubAction=0;
if( unit->Command.Data.Move.Goal ) {
RefsDebugCheck(!unit->Command.Data.Move.Goal->Refs);
--unit->Command.Data.Move.Goal->Refs;
RefsDebugCheck(!unit->Command.Data.Move.Goal->Refs);
unit->Command.Data.Move.Goal=NoUnitP;
}
#endif
} else { // Do a little delay
unit->Wait*=unit->SubAction-65;
DebugLevel0Fn("Retring\n");

View file

@ -51,16 +51,14 @@ global void HandleActionReturnGoods(Unit* unit)
type=unit->Type;
//
// Select target to return goods.
// Select target to return goods. FIXME: more races support
//
if( type==UnitTypeHumanWorkerWithGold || type==UnitTypeOrcWorkerWithGold ) {
#ifdef NEW_ORDERS
if( !(destu=FindGoldDeposit(unit,unit->X,unit->Y)) ) {
// No deposit -> can't return
unit->Orders[0].Action=UnitActionStill;
return;
}
ResetPath(unit->Orders[0]);
unit->Orders[0].Goal=destu;
RefsDebugCheck( !destu->Refs );
++destu->Refs;
@ -68,20 +66,6 @@ global void HandleActionReturnGoods(Unit* unit)
unit->Orders[0].X=unit->Orders[0].Y=-1;
unit->Orders[0].Action=UnitActionMineGold;
NewResetPath(unit);
#else
if( !(destu=FindGoldDeposit(unit,unit->X,unit->Y)) ) {
// No deposit -> can't return
unit->Command.Action=UnitActionStill;
return;
}
ResetPath(unit->Command);
unit->Command.Data.Move.Goal=destu;
RefsDebugCheck( !destu->Refs );
++destu->Refs;
unit->Command.Data.Move.Range=1;
unit->Command.Data.Move.DX=unit->Command.Data.Move.DY=-1;
unit->Command.Action=UnitActionMineGold;
#endif
unit->SubAction=65; // FIXME: hardcoded
DebugLevel3("Wait: %d\n",unit->Wait);
unit->Wait=1;
@ -89,13 +73,11 @@ global void HandleActionReturnGoods(Unit* unit)
}
if( type==UnitTypeHumanWorkerWithWood || type==UnitTypeOrcWorkerWithWood ) {
#ifdef NEW_ORDERS
if( !(destu=FindWoodDeposit(unit->Player,unit->X,unit->Y)) ) {
// No deposit -> can't return
unit->Orders[0].Action=UnitActionStill;
return;
}
ResetPath(unit->Orders[0]);
unit->Orders[0].Goal=destu;
RefsDebugCheck( !destu->Refs );
++destu->Refs;
@ -106,24 +88,6 @@ global void HandleActionReturnGoods(Unit* unit)
,UnitNumber(destu),unit->Orders[0].X,unit->Orders[0].Y);
unit->Orders[0].Action=UnitActionHarvest;
NewResetPath(unit);
#else
if( !(destu=FindWoodDeposit(unit->Player,unit->X,unit->Y)) ) {
// No deposit -> can't return
unit->Command.Action=UnitActionStill;
return;
}
ResetPath(unit->Command);
unit->Command.Data.Move.Goal=destu;
RefsDebugCheck( !destu->Refs );
++destu->Refs;
unit->Command.Data.Move.Range=1;
unit->Command.Data.Move.DX=-1;
unit->Command.Data.Move.DY=-1;
DebugLevel3("Return to %Zd=%d,%d\n"
,UnitNumber(destu)
,unit->Command.Data.Move.DX,unit->Command.Data.Move.DY);
unit->Command.Action=UnitActionHarvest;
#endif
unit->SubAction=128; // FIXME: Hardcoded
DebugLevel3("Wait: %d\n",unit->Wait);
unit->Wait=1;
@ -131,13 +95,11 @@ global void HandleActionReturnGoods(Unit* unit)
}
if( type==UnitTypeHumanTankerFull || type==UnitTypeOrcTankerFull ) {
#ifdef NEW_ORDERS
if( !(destu=FindOilDeposit(unit->Player,unit->X,unit->Y)) ) {
// No deposit -> can't return
unit->Orders[0].Action=UnitActionStill;
return;
}
ResetPath(unit->Orders[0]);
unit->Orders[0].Goal=destu;
RefsDebugCheck( !destu->Refs );
++destu->Refs;
@ -147,24 +109,6 @@ global void HandleActionReturnGoods(Unit* unit)
,UnitNumber(destu),unit->Orders[0].X,unit->Orders[0].Y);
unit->Orders[0].Action=UnitActionHaulOil;
NewResetPath(unit);
#else
if( !(destu=FindOilDeposit(unit->Player,unit->X,unit->Y)) ) {
// No deposit -> can't return
unit->Command.Action=UnitActionStill;
return;
}
ResetPath(unit->Command);
unit->Command.Data.Move.Goal=destu;
RefsDebugCheck( !destu->Refs );
++destu->Refs;
unit->Command.Data.Move.Range=1;
unit->Command.Data.Move.DX=-1;
unit->Command.Data.Move.DY=-1;
DebugLevel3("Return to %Zd=%d,%d\n"
,UnitNumber(destu)
,unit->Command.Data.Move.DX,unit->Command.Data.Move.DY);
unit->Command.Action=UnitActionHaulOil;
#endif
unit->SubAction=65; // FIXME: Hardcoded
DebugLevel3("Wait: %d\n",unit->Wait);
unit->Wait=1;

View file

@ -82,18 +82,10 @@ global void ActionStillGeneric(Unit* unit,int ground)
// FIXME: the frames are hardcoded they should be configurable
//
if( unit->State==1 && type->GoldMine ) {
#ifdef NEW_ORDERS
unit->Frame=!!unit->Data.Resource.Active;
#else
unit->Frame=!!unit->Command.Data.GoldMine.Active;
#endif
}
if( unit->State==1 && type->GivesOil ) {
#ifdef NEW_ORDERS
unit->Frame=unit->Data.Resource.Active ? 2 : 0;
#else
unit->Frame=unit->Command.Data.Resource.Active ? 2 : 0;
#endif
}
}
@ -136,24 +128,12 @@ global void ActionStillGeneric(Unit* unit,int ground)
if( x!=unit->X || y!=unit->Y ) {
if( CheckedCanMoveToMask(x,y,TypeMovementMask(type)) ) {
// FIXME: Don't use pathfinder for this, costs too much cpu.
#ifdef NEW_ORDERS
unit->Orders[0].Action=UnitActionMove;
ResetPath(unit->Orders[0]);
DebugCheck( unit->Orders[0].Goal );
unit->Orders[0].Goal=NoUnitP;
unit->Orders[0].RangeX=unit->Orders[0].RangeY=0;
unit->Orders[0].X=x;
unit->Orders[0].Y=y;
#else
unit->Command.Action=UnitActionMove;
ResetPath(unit->Command);
unit->Command.Data.Move.Goal=NoUnitP;
unit->Command.Data.Move.Range=0;
unit->Command.Data.Move.SX=unit->X;
unit->Command.Data.Move.SY=unit->Y;
unit->Command.Data.Move.DX=x;
unit->Command.Data.Move.DY=y;
#endif
}
}
// NOTE: critter couldn't attack automatic through the return
@ -173,34 +153,18 @@ global void ActionStillGeneric(Unit* unit,int ground)
CommandAttack(unit,goal->X,goal->Y,NULL,FlushCommands);
DebugLevel3Fn(" %Zd Attacking in range %d\n"
,UnitNumber(unit),unit->SubAction);
#ifdef NEW_ORDERS
unit->SavedOrder.Action=UnitActionAttack;
unit->SavedOrder.RangeX=unit->SavedOrder.RangeY=0;
unit->SavedOrder.X=unit->X;
unit->SavedOrder.Y=unit->Y;
unit->SavedOrder.Goal=NoUnitP;
ResetPath(unit->SavedOrder);
// FIXME: next isn't used: unit->SubAction|=2;
#else
unit->SavedCommand.Action=UnitActionAttack;
unit->SavedCommand.Data.Move.Range=0;
unit->SavedCommand.Data.Move.DX=unit->X;
unit->SavedCommand.Data.Move.DY=unit->Y;
unit->SavedCommand.Data.Move.Goal=NoUnitP;
ResetPath(unit->SavedCommand);
unit->SubAction|=2;
#endif
}
} else if( (goal=AttackUnitsInRange(unit)) ) {
DebugLevel3Fn(" %Zd #%d\n",UnitNumber(goal),goal->Refs);
//
// Old goal destroyed.
//
#ifdef NEW_ORDERS
temp=unit->Orders[0].Goal;
#else
temp=unit->Command.Data.Move.Goal;
#endif
if( temp && temp->Destroyed ) {
DebugLevel3Fn(" destroyed unit %Zd #%d\n"
,UnitNumber(temp),temp->Refs);
@ -208,11 +172,7 @@ global void ActionStillGeneric(Unit* unit,int ground)
if( !--temp->Refs ) {
ReleaseUnit(temp);
}
#ifdef NEW_ORDERS
unit->Orders[0].Goal=temp=NoUnitP;
#else
unit->Command.Data.Move.Goal=temp=NoUnitP;
#endif
}
if( !unit->SubAction || temp!=goal ) {
// New target.
@ -223,11 +183,8 @@ global void ActionStillGeneric(Unit* unit,int ground)
temp->Refs--;
RefsDebugCheck( !temp->Refs );
}
#ifdef NEW_ORDERS
unit->Orders[0].Goal=goal;
#else
unit->Command.Data.Move.Goal=goal;
#endif
RefsDebugCheck( !goal->Refs );
goal->Refs++;
unit->State=0;
unit->SubAction=1; // Mark attacking.
@ -242,11 +199,7 @@ global void ActionStillGeneric(Unit* unit,int ground)
}
if( unit->SubAction ) { // was attacking.
#ifdef NEW_ORDERS
if( (temp=unit->Orders[0].Goal) ) {
#else
if( (temp=unit->Command.Data.Move.Goal) ) {
#endif
if( temp->Destroyed ) {
RefsDebugCheck( !temp->Refs );
if( !--temp->Refs ) {
@ -257,11 +210,7 @@ global void ActionStillGeneric(Unit* unit,int ground)
temp->Refs--;
RefsDebugCheck( !temp->Refs );
}
#ifdef NEW_ORDERS
unit->Orders[0].Goal=NoUnitP;
#else
unit->Command.Data.Move.Goal=NoUnitP;
#endif
}
unit->SubAction=unit->State=0; // No attacking, restart
}