From 87cd419883f7086a9d948997d8725ce95935d6ce Mon Sep 17 00:00:00 2001 From: johns <> Date: Thu, 27 Apr 2000 00:41:34 +0000 Subject: [PATCH] ground attack should now work --- action/action_attack.cpp | 26 +++++++++++++++++++++----- action/actions.cpp | 1 + action/command.cpp | 3 ++- include/unit.h | 1 + ui/botpanel.cpp | 5 ++--- unit/unit.cpp | 13 +++++++++++++ 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/action/action_attack.cpp b/action/action_attack.cpp index 299470802..1dcfe2f45 100644 --- a/action/action_attack.cpp +++ b/action/action_attack.cpp @@ -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; } diff --git a/action/actions.cpp b/action/actions.cpp index c62f616b7..7910a888c 100644 --- a/action/actions.cpp +++ b/action/actions.cpp @@ -165,6 +165,7 @@ local void HandleUnitAction(Unit* unit) break; case UnitActionAttack: + case UnitActionAttackGround: HandleActionAttack(unit); break; diff --git a/action/command.cpp b/action/command.cpp index 96ab89a05..1d42917d2 100644 --- a/action/command.cpp +++ b/action/command.cpp @@ -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 } diff --git a/include/unit.h b/include/unit.h index e863f7656..60069e0b1 100644 --- a/include/unit.h +++ b/include/unit.h @@ -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 diff --git a/ui/botpanel.cpp b/ui/botpanel.cpp index ad09917d8..4abfaa0d3 100644 --- a/ui/botpanel.cpp +++ b/ui/botpanel.cpp @@ -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 diff --git a/unit/unit.cpp b/unit/unit.cpp index 2c69c1803..fba2dc34e 100644 --- a/unit/unit.cpp +++ b/unit/unit.cpp @@ -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:\"");