Skip to content

Commit

Permalink
Fixed groups orders get lost after MapEd resave
Browse files Browse the repository at this point in the history
git-svn-id: svn://localhost/trunk@4265 a386ff7f-d321-c144-bb17-e251d28fee14
  • Loading branch information
Kromster80 committed Dec 1, 2012
1 parent 554c64e commit 4c07c60
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions Bugreports/Buglist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
+ Archers behave badly when you tell them to attack directly (houses and units)
+ Saving a game or a map in MapEd with a name ending/starting in a space crashes with "Invalid file name"
+ In maps with elevated terrain near the top it is not possible to see units standing on the top few rows
+ MapEd did not saved Group orders (sendGroup and AttackPosition)
Armour smithy has shields as 2nd ouput, armour workshop has shields as 1st output. Would make sense to match them (note: simpply swapping in KM_ResourceHouses causes game logic to be swapped with GUI)
Armour smithy has iron as 1st input, weapon smithy has iron as 2nd input (iron/coal swapped). Would make sense to match them (note: simpply swapping in KM_ResourceHouses causes game logic to be swapped with GUI)
Better understanding of coop missions in lobby (don't require user to set teams and AI players, don't reveal map in preview, etc.)
Expand Down
2 changes: 2 additions & 0 deletions KM_InterfaceMapEditor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ procedure TKMapEdInterface.Create_Unit_Page;
Button_ArmyDec.OnClickEither := Unit_ArmyChange2;
Button_ArmyFood.OnClick := Unit_ArmyChange1;
Button_ArmyInc.OnClickEither := Unit_ArmyChange2;

//todo: add Group order (see MapEdOrder field)
end;


Expand Down
7 changes: 6 additions & 1 deletion KM_MapEditor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ implementation
uses KM_PlayersCollection, KM_RenderAux, KM_AIFields;


{ TKMDeposits }
function TKMDeposits.GetAmount(aMat: TRawDeposit; aIndex: Integer): Integer;
begin
Result := fAreaAmount[aMat, aIndex];
Expand All @@ -89,6 +90,8 @@ function TKMDeposits.GetLocation(aMat: TRawDeposit; aIndex: Integer): TKMPointF;
begin
Result := fAreaLoc[aMat, aIndex];
end;


//Check whether deposit exist and do proper action
//TileIsWater is used to make an area from whole water body - not only connected fish
function TKMDeposits.TileDepositExists(aMat: TRawDeposit; X,Y: Word) : Boolean;
Expand All @@ -99,6 +102,7 @@ function TKMDeposits.TileDepositExists(aMat: TRawDeposit; X,Y: Word) : Boolean;
Result := TileDeposit(aMat,X,Y) > 0;
end;


//Get tile resource deposit
function TKMDeposits.TileDeposit(aMat: TRawDeposit; X,Y: Word): Byte;
var
Expand All @@ -120,6 +124,7 @@ function TKMDeposits.TileDeposit(aMat: TRawDeposit; X,Y: Word): Byte;
end;
end;


procedure TKMDeposits.FloodFill(const aMat: array of TRawDeposit);
var
R: TRawDeposit;
Expand Down Expand Up @@ -252,7 +257,7 @@ constructor TKMMapEditor.Create;

fDeposits := TKMDeposits.Create;

fVisibleLayers := [mlObjects, mlHouses, mlUnits, mlDeposits, mlDefences];
fVisibleLayers := [mlObjects, mlHouses, mlUnits, mlDeposits];

for I := Low(fRevealers) to High(fRevealers) do
fRevealers[I] := TKMPointTagList.Create;
Expand Down
53 changes: 36 additions & 17 deletions KM_MissionScript.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TMissionParserStandard = class(TMissionParserCommon)
constructor Create(aMode:TMissionParsingMode; aPlayersRemap:TPlayerArray; aStrictParsing:boolean); overload;
function LoadMission(const aFileName: string):boolean; overload; override;

procedure SaveDATFile(const aFileName: String);
procedure SaveDATFile(const aFileName: string);
end;


Expand Down Expand Up @@ -375,20 +375,20 @@ function TMissionParserInfo.LoadMapInfo(const aFileName:string):boolean;
{ TMissionParserStandard }
//Mode affect how certain parameters are loaded a bit differently
constructor TMissionParserStandard.Create(aMode: TMissionParsingMode; aStrictParsing: boolean);
var i:integer;
var I: Integer;
begin
inherited Create(aStrictParsing);
fParsingMode := aMode;

for i:=0 to High(fRemap) do
fRemap[i] := i;
for I := 0 to High(fRemap) do
fRemap[I] := I;

fRemapCount := MAX_PLAYERS;
end;


constructor TMissionParserStandard.Create(aMode: TMissionParsingMode; aPlayersRemap: TPlayerArray; aStrictParsing: Boolean);
var i:integer;
var I: Integer;
begin
inherited Create(aStrictParsing);
fParsingMode := aMode;
Expand All @@ -397,7 +397,7 @@ constructor TMissionParserStandard.Create(aMode: TMissionParsingMode; aPlayersRe
//and which players should be ignored
fRemap := aPlayersRemap;

for i:=0 to High(fRemap) do
for I := 0 to High(fRemap) do
inc(fRemapCount);
end;

Expand Down Expand Up @@ -687,7 +687,13 @@ function TMissionParserStandard.ProcessCommand(CommandType: TKMCommandType; P: a
ct_SendGroup: if fLastPlayer >= 0 then
begin
if fLastTroop <> nil then
fLastTroop.OrderWalk(KMPoint(P[0]+1, P[1]+1), TKMDirection(P[2]+1))
if fParsingMode = mpm_Editor then
begin
fLastTroop.MapEdOrder.Order := goWalkTo;
fLastTroop.MapEdOrder.Pos := KMPointDir(P[0]+1, P[1]+1, TKMDirection(P[2]+1));
end
else
fLastTroop.OrderWalk(KMPoint(P[0]+1, P[1]+1), TKMDirection(P[2]+1))
else
AddError('ct_SendGroup without prior declaration of Troop');
end;
Expand Down Expand Up @@ -735,8 +741,14 @@ function TMissionParserStandard.ProcessCommand(CommandType: TKMCommandType; P: a
//If target is nothing: move to position
//However, because the unit/house target may not have been created yet, this must be processed after everything else
if fLastTroop <> nil then
if fParsingMode = mpm_Editor then
begin
inc(fAttackPositionsCount);
fLastTroop.MapEdOrder.Order := goAttackUnit;
fLastTroop.MapEdOrder.Pos := KMPointDir(P[0]+1, P[1]+1, dir_NA);
end
else
begin
Inc(fAttackPositionsCount);
SetLength(fAttackPositions, fAttackPositionsCount+1);
fAttackPositions[fAttackPositionsCount-1].Group := fLastTroop;
fAttackPositions[fAttackPositionsCount-1].Target := KMPoint(P[0]+1,P[1]+1);
Expand Down Expand Up @@ -807,20 +819,22 @@ function TMissionParserStandard.ProcessCommand(CommandType: TKMCommandType; P: a
//Determine what we are attacking: House, Unit or just walking to some place
procedure TMissionParserStandard.ProcessAttackPositions;
var
i: integer;
I: Integer;
H: TKMHouse;
U: TKMUnit;
begin
for i:=0 to fAttackPositionsCount-1 do
with fAttackPositions[i] do
Assert((fParsingMode <> mpm_Editor) or (fAttackPositionsCount = 0), 'AttackPositions should be handled by MapEd');

for I := 0 to fAttackPositionsCount - 1 do
with fAttackPositions[I] do
begin
H := fPlayers.HousesHitTest(Target.X,Target.Y); //Attack house
if (H <> nil) and (not H.IsDestroyed) and (fPlayers.CheckAlliance(Group.Owner,H.Owner) = at_Enemy) then
H := fPlayers.HousesHitTest(Target.X, Target.Y); //Attack house
if (H <> nil) and (not H.IsDestroyed) and (fPlayers.CheckAlliance(Group.Owner, H.Owner) = at_Enemy) then
Group.OrderAttackHouse(H)
else
begin
U := fTerrain.UnitsHitTest(Target.X,Target.Y); //Chase/attack unit
if (U <> nil) and (not U.IsDeadOrDying) and (fPlayers.CheckAlliance(Group.Owner,U.Owner) = at_Enemy) then
U := fTerrain.UnitsHitTest(Target.X, Target.Y); //Chase/attack unit
if (U <> nil) and (not U.IsDeadOrDying) and (fPlayers.CheckAlliance(Group.Owner, U.Owner) = at_Enemy) then
Group.OrderAttackUnit(U)
else
Group.OrderWalk(Target); //Just move to position
Expand All @@ -830,7 +844,7 @@ procedure TMissionParserStandard.ProcessAttackPositions;


//Write out a KaM format mission file to aFileName
procedure TMissionParserStandard.SaveDATFile(const aFileName: String);
procedure TMissionParserStandard.SaveDATFile(const aFileName: string);
const
COMMANDLAYERS = 4;
var
Expand Down Expand Up @@ -886,7 +900,7 @@ procedure TMissionParserStandard.SaveDATFile(const aFileName: String);
AddData(OutData);
end;

procedure AddCommand(aCommand:TKMCommandType; aParams:array of integer); overload;
procedure AddCommand(aCommand:TKMCommandType; aParams: array of integer); overload;
begin
AddCommand(aCommand, cpt_Unknown, aParams);
end;
Expand Down Expand Up @@ -1109,6 +1123,11 @@ procedure TMissionParserStandard.SaveDATFile(const aFileName: String);
AddCommand(ct_SetGroup, [UnitTypeToIndex[Group.UnitType], Group.Position.X-1, Group.Position.Y-1, Byte(Group.Direction)-1, Group.UnitsPerRow, Group.MapEdCount]);
if Group.Condition = UNIT_MAX_CONDITION then
AddCommand(ct_SetGroupFood, []);

if Group.MapEdOrder.Order = goWalkTo then
AddCommand(ct_SendGroup, [Group.MapEdOrder.Pos.Loc.X-1, Group.MapEdOrder.Pos.Loc.Y-1, Byte(Group.MapEdOrder.Pos.Dir)-1]);
if Group.MapEdOrder.Order = goAttackUnit then
AddCommand(ct_AttackPosition, [Group.MapEdOrder.Pos.Loc.X-1, Group.MapEdOrder.Pos.Loc.Y-1]);
end;

AddData(''); //NL
Expand Down
6 changes: 6 additions & 0 deletions KM_UnitGroups.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ interface
goStorm //Run forward
);

TKMMapEdOrder = record
Order: TKMGroupOrder;
Pos: TKMPointDir;
end;

TKMUnitGroup = class
private
fID: Cardinal;
Expand Down Expand Up @@ -65,6 +70,7 @@ TKMUnitGroup = class
function GetDirection: TKMDirection;
function GetPosition: TKMPoint;
public
MapEdOrder: TKMMapEdOrder;

constructor Create(aID: Cardinal; aCreator: TKMUnitWarrior); overload;
constructor Create(aID: Cardinal; aOwner: TPlayerIndex; aUnitType: TUnitType; PosX, PosY: Word; aDir: TKMDirection; aUnitPerRow, aCount: Word); overload;
Expand Down

0 comments on commit 4c07c60

Please sign in to comment.