ground attack should now work

This commit is contained in:
johns 2000-04-27 00:41:34 +00:00
parent e392522057
commit 87cd419883
6 changed files with 40 additions and 9 deletions

View file

@ -107,7 +107,19 @@ local void MoveToTarget(Unit* unit)
int wall;
int err;
err=HandleActionMove(unit);
if( unit->Command.Action==UnitActionAttackGround ) {
// FIXME: workaround for pathfinder problem
unit->Command.Data.Move.DX-=unit->Command.Data.Move.Range;
unit->Command.Data.Move.DY-=unit->Command.Data.Move.Range;
unit->Command.Data.Move.Range*=2;
err=HandleActionMove(unit);
unit->Command.Data.Move.Range/=2;
unit->Command.Data.Move.DX+=unit->Command.Data.Move.Range;
unit->Command.Data.Move.DY+=unit->Command.Data.Move.Range;
unit->Command.Action=UnitActionAttackGround;
} else {
err=HandleActionMove(unit);
}
// FIXME: Should handle new return codes here (for Fabrice)
if( unit->Reset ) {
@ -140,7 +152,8 @@ local void MoveToTarget(Unit* unit)
//
wall=0;
if( !goal && !(wall=WallOnMap(unit->Command.Data.Move.DX
,unit->Command.Data.Move.DY)) ) {
,unit->Command.Data.Move.DY))
&& unit->Command.Action!=UnitActionAttackGround ) {
goal=AttackUnitsInReactRange(unit);
if( goal ) {
#ifdef NEW_UNIT
@ -192,7 +205,8 @@ local void MoveToTarget(Unit* unit)
UnitHeadingFromDeltaXY(unit,goal->X-unit->X,goal->Y-unit->Y);
}
unit->SubAction++;
} else if( wall && MapDistance(unit->X,unit->Y
} else if( (wall || unit->Command.Action==UnitActionAttackGround)
&& MapDistance(unit->X,unit->Y
,unit->Command.Data.Move.DX,unit->Command.Data.Move.DY)
<=unit->Stats->AttackRange ) {
DebugLevel3("Attacking wall\n");
@ -202,6 +216,7 @@ local void MoveToTarget(Unit* unit)
,unit->Command.Data.Move.DY-unit->Y);
}
unit->SubAction=1;
return;
} else if( err ) {
unit->State=0;
unit->SubAction=0;
@ -233,8 +248,9 @@ local void AttackTarget(Unit* unit)
//
// Goal is "weak" or a wall.
//
if( !goal && WallOnMap(unit->Command.Data.Move.DX
,unit->Command.Data.Move.DY) ) {
if( !goal && (WallOnMap(unit->Command.Data.Move.DX
,unit->Command.Data.Move.DY)
|| unit->Command.Action==UnitActionAttackGround) ) {
DebugLevel3("attack a wall!!!!\n");
return;
}

View file

@ -165,6 +165,7 @@ local void HandleUnitAction(Unit* unit)
break;
case UnitActionAttack:
case UnitActionAttackGround:
HandleActionAttack(unit);
break;

View file

@ -300,7 +300,7 @@ global void CommandAttackGround(Unit* unit,int x,int y,int flush)
return;
}
command->Action=UnitActionAttack;
command->Action=UnitActionAttackGround;
command->Data.Move.Fast=1;
command->Data.Move.Goal=NoUnitP;
command->Data.Move.Range=unit->Stats->AttackRange;
@ -308,6 +308,7 @@ global void CommandAttackGround(Unit* unit,int x,int y,int flush)
command->Data.Move.SY=unit->Y;
command->Data.Move.DX=x;
command->Data.Move.DY=y;
// FIXME: pathfinder didn't support this kind of target
unit->SavedCommand.Action=UnitActionStill; // clear saved action
}

View file

@ -58,6 +58,7 @@ enum _unit_action_ {
UnitActionFollow, /// unit follows units
UnitActionMove, /// unit moves to position/unit
UnitActionAttack, /// unit attacks position/unit
UnitActionAttackGround, /// unit attacks ground
UnitActionDie, /// unit dies
UnitActionTrain, /// building is training

View file

@ -256,13 +256,12 @@ global void DrawButtonPanel(void)
v=IconSelected;
}
break;
/* FIXME: attackground and attack are both ActionAttack
case B_AttackGround:
if( Selected[0]->Command.Action==UnitActionAttack ) {
if( Selected[0]->Command.Action
==UnitActionAttackGround ) {
v=IconSelected;
}
break;
*/
// FIXME: must handle more actions

View file

@ -2812,6 +2812,19 @@ local void SaveCommand(const Command* command,FILE* file)
}
fprintf(file," %d",command->Data.Move.Range);
break;
case UnitActionAttackGround:
fprintf(file,"'attack-ground");
fprintf(file," (%d %d)"
,command->Data.Move.SX,command->Data.Move.SY);
fprintf(file," (%d %d)"
,command->Data.Move.DX,command->Data.Move.DY);
if( command->Data.Move.Goal ) {
ref=UnitReference(command->Data.Move.Goal);
fprintf(file," %s",ref);
free(ref);
}
fprintf(file," %d",command->Data.Move.Range);
break;
case UnitActionDie:
fprintf(file,"'die");
fprintf(file," \"FIXME:\"");