hedgewars/uGears.pas
changeset 11703 607e2e43acf0
parent 11702 08cbd57ffb1a
child 11705 4b2179d9516c
equal deleted inserted replaced
11702:08cbd57ffb1a 11703:607e2e43acf0
   737         AddGear(rx + snowLeft, LongInt(LAND_HEIGHT) + ry - 1300, gtFlake, 0, _0, _0, 0)
   737         AddGear(rx + snowLeft, LongInt(LAND_HEIGHT) + ry - 1300, gtFlake, 0, _0, _0, 0)
   738         end
   738         end
   739 end;
   739 end;
   740 
   740 
   741 // sort clans horizontally (bubble-sort, because why not)
   741 // sort clans horizontally (bubble-sort, because why not)
   742 procedure SortHHsByColor();
   742 procedure SortHHsByClan();
   743 var n, newn, i, j, k, p: LongInt;
   743 var n, newn, i, j, k, p: LongInt;
   744     ar, clar: array[0..Pred(cMaxHHs)] of PHedgehog;
   744     ar, clar: array[0..Pred(cMaxHHs)] of PHedgehog;
   745     Count, clCount: Longword;
   745     Count, clCount: Longword;
   746     tmpX, tmpY: hwFloat;
   746     tmpX, tmpY: hwFloat;
   747     hh1, hh2: PHedgehog;
   747     hh1, hh2: PHedgehog;
   781             ar[Count]:= clar[i];
   781             ar[Count]:= clar[i];
   782             inc(Count);
   782             inc(Count);
   783             end;
   783             end;
   784         end;
   784         end;
   785 
   785 
       
   786 
       
   787 // bubble-sort hog array
   786 n:= Count - 1;
   788 n:= Count - 1;
   787 
   789 
   788 repeat
   790 repeat
   789     newn:= 0;
   791     newn:= 0;
   790     for i:= 1 to n do
   792     for i:= 1 to n do
   809 
   811 
   810 procedure AssignHHCoords;
   812 procedure AssignHHCoords;
   811 var i, t, p, j: LongInt;
   813 var i, t, p, j: LongInt;
   812     ar: array[0..Pred(cMaxHHs)] of PHedgehog;
   814     ar: array[0..Pred(cMaxHHs)] of PHedgehog;
   813     Count: Longword;
   815     Count: Longword;
       
   816     divide, sectionDivide: boolean;
   814 begin
   817 begin
   815 if (GameFlags and gfPlaceHog) <> 0 then
   818 if (GameFlags and gfPlaceHog) <> 0 then
   816     PlacingHogs:= true;
   819     PlacingHogs:= true;
   817 // in divided-teams mode, slice map into vertical stripes of identical length and spawn one clan in each slice
   820 
   818 // this code is only for 2-clans and fort-mode games
   821 divide:= ((GameFlags and gfDivideTeams) <> 0);
   819 if ((ClansCount = 2) or ((GameFlags and gfForts) <> 0)) and ((GameFlags and gfDivideTeams) <> 0) then
   822 sectionDivide:= divide and ((GameFlags and gfForts) <> 0);
       
   823 
       
   824 // TODO: there might be a smarter way to decide if dividing clans into equal-width map sections makes sense
       
   825 // e.g. by checking if there is enough spawn area in each section
       
   826 if divide and (not sectionDivide) then
       
   827     sectionDivide:= (ClansCount = 2);
       
   828 
       
   829 // in section-divide mode, divide the map into equal-width sections and put each clan in one of them
       
   830 if sectionDivide then
   820     begin
   831     begin
   821     t:= 0;
   832     t:= 0;
   822     for p:= 0 to (ClansCount - 1) do
   833     for p:= 0 to (ClansCount - 1) do
   823         begin
   834         begin
   824         with ClansArray[p]^ do
   835         with ClansArray[p]^ do
   898                     Gear^.State:= Gear^.State and (not gsttmpFlag);
   909                     Gear^.State:= Gear^.State and (not gsttmpFlag);
   899                     AddFileLog('Carved a hole for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')')
   910                     AddFileLog('Carved a hole for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')')
   900                     end;
   911                     end;
   901 
   912 
   902 
   913 
   903 // divided teams: in non-fort-modes with more than 2 clans, sort the hedgehogs from left to right by color
   914 // divided teams: sort the hedgehogs from left to right by clan and shuffle clan members
   904 if (ClansCount > 2) and ((GameFlags and gfForts) = 0) and ((GameFlags and gfDivideTeams) <> 0) then
   915 // let's do this even after a possible section-divide, because some hogs may have spawned randomly on flowers
   905     begin
   916 if divide then
   906     SortHHsByColor();
   917     SortHHsByClan();
   907     end;
       
   908 end;
   918 end;
   909 
   919 
   910 
   920 
   911 {procedure AmmoFlameWork(Ammo: PGear);
   921 {procedure AmmoFlameWork(Ammo: PGear);
   912 var t: PGear;
   922 var t: PGear;